clear all
load apex_data

for i=1:N %for all files (pos, dat)
    file_i=int2str(i); %change i to string and store as file_i
    n=length(file_i); %check length of file_i
        if n==1 %if 1, 2, 3...9 (it doesn't know file names)
            name=['pos00',file_i]; %concatenates pos00 and i (pos001) and assigns to array name
            name2=['dat00',file_i]; %concatenates dat00 and i (dat001) and assigns to array name2
        elseif n==2 %if 10, 11, 12...99 
             name=['pos0',file_i]; %concatenates pos0 and i (pos010) and assigns to array name
             name2=['dat0',file_i]; %concatenates dat0 and i (dat010) and assigns to array name2
        else %if 100, 101, 102...999
             name=['pos',file_i]; %concatenates pos and i (pos100) and assigns to array name
             name2=['dat',file_i]; %concatenates dat and i (dat100) and assigns to array name2
        end           
    A=eval(name); %eval(pos001) - takes strings in pos001 (lat, lon, minutes) and changes to numbers, then assigns to array A
    B=eval(name2); %eval(dat001) - takes strings in dat001 (the 14 fields) and changes to numbers, then assigns to array B
    [mm nn]=size(B); %returns number of rows and columns in B (dat001)
    if i==1 %if this is the first time through
        %%%%%%%%%%%
        pos=A; %assign A to array pos
        dat=[B,zeros(mm,1)]; %assign B and zeros.... (?)
        serial=ones(size(A),1);
    else %if not the first time through
        pos=[pos;A]; %take what was in pos and append next A to it
        serial=[serial;ones(size(A),1)*i];
        AA=[B,(i-1)*5*ones(mm,1)];
        dat=[dat;AA];
    end
end
%plotting....
tt=datenum(2005,8,25)+(serial-1)*5;
t=datestr(tt, 'mm');
A=load('3866.dat');
I=find(dat<0);
dat(I)=NaN;
%%%%%%%%%%%%%%%%%%%%%%%
% figure(1) % plots trajectory w/ color according to month
% % plot(A(:,1),A(:,2),'k')
% hold on
% scatter(pos(:,1)-360,pos(:,2),5,str2num(tt),'filled');colorbar
% plot(pos(1,1)-360,pos(1,2),'k*')
% xlabel('Longitude')
% ylabel('Latitude')
% title('Surface positions of float [color=month of the year]')
% % title('Surface Positions of Float 0005')
% hold off
%%%%%%%%%%%%%%%%%%%%%%%
figure % plots trajectory w/ color according to increasing time
plot(A(:,1),A(:,2),'k')
hold on
scatter(pos(:,1)-360,pos(:,2),3,(tt),'filled');colorbar
cbar_axes=colorbar();
yTick=get(cbar_axes,'YTick')';
yLabel=datestr(yTick,'mm/dd/yy');
colorbar('YTickLabel',[]);colorbar('YTickLabel',yLabel);
xlabel('Longitude')
ylabel('Latitude')
title('Surface Positions of Float Through Time')
hold off