close all;
clear all;

DELIMITER = ',';
HEADERLINES = 1;

% Import the file
newData1 = importdata('acm_raw.csv', DELIMITER, HEADERLINES);

% Create new variables in the base workspace from those fields.
vars = fieldnames(newData1);
for i = 1:length(vars)
    assignin('base', vars{i}, newData1.(vars{i}));
end
%remove empty column
%newData1.data=newData1.data(:,2:end);

%Rover Timestamp (ISO601),Timestamp,Vehicle Heading (degrees),Voltage (V),Tilt X (degrees),
%Tilt Y (degrees),Northing (cm/sec),Easting (cm/sec),Temp (C)

RoverHeading=newData1.data(:,1);
Voltage=newData1.data(:,2);
TiltX=newData1.data(:,3);
TiltY=newData1.data(:,4);
Northing=newData1.data(:,5);
Easting=newData1.data(:,6);
Temp=newData1.data(:,7);
ACMTime=newData1.textdata(2:end,1);
[date,time]=strtok(ACMTime,'T');
time=strtok(time,'T');
ACMdatetime=strcat(date,',',time);

%Average Data
Time=zeros(size(ACMTime,1),6);
for i= 1:size(ACMdatetime,1),
    [hr,mn,sc]=strread(char(time(i,:)),'%d%d%f','delimiter',':');
     [yr,mth,dy]=strread(char(date(i)),'%d%d%d','delimiter','-');
     [ss,ds]=strread(num2str(sc),'%d%d','delimiter','.');
      Time(i,:)=[yr,mth,dy,hr,mn,ss];
end
break;

[index,j]=find(abs(diff(Time(:,5)))>=1);

NorthAve=[];
EastAve=[];
ACMAveTime=[];
for i= 1:size(index),
    if i==1
        NorthAve=mean(Northing(1:index(i)));
        EastAve=mean(Easting(1:index(i)));
        ACMAveTime=ACMdatetime(index(i));
    else
        NorthAve=[NorthAve;mean(Northing(index(i-1)+1:index(i)))];
        EastAve=[EastAve;mean(Easting(index(i-1)+1:index(i)))];
        ACMAveTime=[ACMAveTime;ACMdatetime(index(i))];
    end
end
NorthAve=[NorthAve;mean(Northing(index(i)+1:end))];
EastAve=[EastAve;mean(Easting(index(i)+1:end))];
ACMAveTime=[ACMAveTime;ACMdatetime(end)];

%
CurrentTS=timeseries(NorthAve,ACMAveTime);


%Calc mag and dir of current
CurrentMag=sqrt((NorthAve.^2)+(EastAve.^2));
CurrentDir=atan2(NorthAve,EastAve);%rad
[u,v] = pol2cart(CurrentDir,CurrentMag);
%feather(u,v);
y=ones(size(CurrentDir,1),1);
figure;
quiver(datenum(ACMAveTime),y,u,v);
datetick('x',0,'keepticks');

s=input('enter the experiment date:','s');
filename=strcat(s,'.mat');


[index,j]=find(abs(diff(Time(:,5)))>=1);

TempAve=[];
ACMAveTime=[];
for i= 1:size(index),
    if i==1
        TempAve=mean(Temp(1:index(i)));
        ACMAveTime=ACMdatetime(index(i));
    else
        TempAve=[TempAve;mean(Temp(index(i-1)+1:index(i)))];
        ACMAveTime=[ACMAveTime;ACMdatetime(index(i))];
    end
end
TempAve=[TempAve;mean(Temp(index(i)+1:end))];
ACMAveTime=[ACMAveTime;ACMdatetime(end)];
TempTS=timeseries(TempAve,ACMAveTime);
plot(TempTS,'r');
%

