clear all
File=dir('os1607xa.csv'); % raw gps data from CALCOFI

File={File.name};
for ia=1:length(File)

    fileID = fopen(File{ia});
    
    %read in data
    data = textscan(fileID,'%s%s%f%f%f%f%f%f%f','delimiter',','); % looks for numbers (%f) and text strings (%s), mostly separated by commas 
    
    fclose(fileID);
    
    %Extract columns to use:

    day          = data{1};
    time          = data{2};
    lat      = data{3};
    lon        = data{4};
    
    
end
%% Converting gps into decimal degrees
%%don't have to do this in 1607 because I have converted lat and long with
%%VBA before
%{
first2 = floor(lat/100);
minutes = rem(lat, 100);
seconds=minutes./60;
LAT=first2+seconds;
first2q=floor(lon/100);
minutes2q=rem(lon,100);
seconds2q=minutes2q./60;
LON=first2q+seconds2q;
LON=LON.*-1;
%}
%% adding a modelled timestamp. Since we know the frequency at which the
%gps is recording, we can set an arbitrary timestamp
%don't need this in 1607 bcuz i don't have full data for 24 hrs of each day
%{
dates1 = datenum(2016,07,10,0,0,30:30:86400);
dates2 = datenum(2016,07,11,0,0,30:30:86400);
dates3 = datenum(2016,07,12,0,0,30:30:86400);
dates4 = datenum(2016,07,13,0,0,30:30:86400);
dates5 = datenum(2016,07,14,0,0,30:30:86400);
dates6 = datenum(2016,07,15,0,0,30:30:86400);
dates7 = datenum(2016,07,16,0,0,30:30:86400);
dates8 = datenum(2016,07,17,0,0,30:30:86400);
dates9 = datenum(2016,07,18,0,0,30:30:86400);
dates10 = datenum(2016,07,19,0,0,30:30:86400);
dates11 = datenum(2016,07,20,0,0,30:30:86400);
dates12 = datenum(2016,07,21,0,0,30:30:86400);
dates13 = datenum(2016,07,22,0,0,30:30:86400);
dates14 = datenum(2016,07,23,0,0,30:30:86400);
dates15 = datenum(2016,07,24,0,0,30:30:86400);
dates16 = datenum(2016,07,25,0,0,30:30:86400);
dates17 = datenum(2016,07,26,0,0,30:30:86400);
dates18 = datenum(2016,07,26,0,0,30:30:86400);
dd=[dates1'; dates2'; dates3'; dates4';dates5';dates6';dates7';dates8';dates9';dates10';dates11';dates12';dates13';dates14';dates15';dates16';dates17';dates18'];
timestamp=datestr(dd,31);
%%
ds=timestamp(1:10000,:);
%}

date=strcat(day,{' '},time);
dd=datenum(date,'ddmmyy HH:MM:SS');
all=[dd lat lon];
dlmwrite('gpsdata.csv',all,'delimiter', ',', 'precision', 15);

