clear all
%%%% transform output from Leica GEO system


%%%%%% UNDER CONSTRUCTION %%%%%%

%%% USES latlon2KML
addpath D:\madeschipper\SURVEY\Matlab  %% location latlon2KML

clear
filenameRAW.name='BlueLoggerRD66.txt';
fid = fopen(filenameRAW.name);

 for i=1:20      % skip header lines   
         tline = fgetl(fid); 
 end    

gi=0;
for i=1:200000                % Arbitrary high number
          
    tline = fgetl(fid); 
      if length(tline) >= 50
         gi=gi+1;

tline = strrep(tline, ',', '.');  % replace the old decimal seperator (comma's) into points 
%%% tline info: GPSTime Date Easting Northing 
[ a b c d  ] = strread(tline, '%s %s %s %s  ', 'delimiter',' ');

%%% GPS TIME in UTC hh:mm:ss.decss
     timehr=str2num(a{:,:}(1:2)); %% GPS time 
     timemin=str2num(a{:,:}(4:5));
     timesec=str2num(a{:,:}(7:8));
GPStime(gi,1)=timehr*3600+timemin*60+timesec; %%GPS time in sec after midnight

X_East(gi,1)=str2num(c{:,:}); %% east
      
Y_North(gi,1)=str2num(d{:,:}); %% north
     
     else    
        break
     end
      
end    


fclose(fid);

%%%% STORE DATA in single Matrix

 GPSdata(:,1)=X_East; 
 GPSdata(:,2)=Y_North;
 GPSdata(:,3)=GPStime;   %in sec after midnight

eval([filenameRAW.name(1:end-4) '=GPSdata;' ]); % rewrite to bluelogger unique name

eval(['save(''' filenameRAW.name(1:end-4) '.mat'', ''' filenameRAW.name(1:end-4) ''')'])

