disp(['read_gps_day_', cruise, '_', year]);
% Inputs data from ASCII data files
%  Note:  hhh=hour

st2=[];jax1=1;jd_gps=[];jd1=[];

for jam=0:23
    if jam<10,
       hr=['0',num2str(jam)];
    else
       hr=num2str(jam);
    end;

    if ddd<10,
       jd=['00',num2str(ddd)];
    elseif ddd<100,
       jd=['0',num2str(ddd)];
    else
       jd=num2str(ddd);
    end;

    dfl=[way_raw_data_flux, 'day',jd,'\gps0' year(3:4) jd hr '_raw.txt'];
    disp(dfl)
    flist=fopen(dfl);
    if flist>0
        
    %     temp =textscan(flist,'%f %6c %6c %c %f %c %f %c %f %f %f %f %4c %*[^\n]','delimiter', ',', 'headerlines', 1,  'emptyvalue', NaN);
        temp =textscan(flist,'%2f%2f%3f %6c %6c %c %f %c %f %c %f %f %f %f %4c %*[^\n]','delimiter', ', ', 'headerlines', 1,  'emptyvalue', NaN);

        stx=[temp{1,1}';temp{1,2}';temp{1,3}';temp{1,7}';double(temp{1,8}');temp{1,9}';double(temp{1,10}');temp{1,11}';temp{1,12}';...
                    temp{1,13}';temp{1,14}'];

        stx(2:10,any(isnan(stx),1))=NaN;      %put NaN into any rows containing NaNs (to remove bad lines, gap...), except JD

        [nr1,nl1]=size(stx);
        st2(:,jax1:jax1+nl1-1)=stx;
        jd1=ddd + (jam+(st2(1,jax1:jax1+nl1-1)+(st2(2,jax1:jax1+nl1-1)+st2(3,jax1:jax1+nl1-1)/1000)/60)/60)/24;
        jd_gps = [jd_gps jd1];
        jax1=jax1+nl1;
    
    else
        disp('file not found')
    end;
end;
ii=find(st2(10,:)>1e5);
time_gpspsd=st2(1,ii);
glt=st2(4,ii); 
gpslat_sign=st2(5,ii); 
gln=st2(6,ii); 
gpslon_sign=st2(7,ii); 
gpsspeed1=st2(8,ii).*.514;  %convert to m/s
gpshead1=st2(9,ii);  %deg
jdx=jd_gps(ii);jd_gps=[];jd_gps=jdx;
% jd_gps=ddd+((st2(1,:)-st2(1,1))/1000/60/60)/24;

bb=floor(glt/100);
glt=(glt-bb*100)/60;
glt=glt+bb;
ii=find(gpslat_sign==83);glt(ii)=-glt(ii);
gpslat1=glt;

bbn=floor(gln/100);
gln=(gln-bbn*100)/60;
gln=gln+bbn;
ii=find(gpslon_sign==87);gln(ii)=-gln(ii);
gpslon1=gln;

ii=find(abs(diff(gpslon1))>1);gpslon1(ii)=gpslon1(ii-1);
ii=find(abs(diff(gpslat1))>1);gpslat1(ii)=gpslat1(ii-1);


figure;plot(gpslon1,gpslat1,'.');title(['JD',jd,' Hr',hr,' UTC  Longitude/Latitude from PSD GPS. ', cruise, year]);xlabel('longitude in deg');ylabel('latitude in deg');  
    print('-djpeg90 ',[way_images_flux '\PSD_GPS_Ship_track_' num2str(ddd) '.jpg']);
figure;plot(jd_gps,gpsspeed1,'.');title(['JD',jd,' Hr',hr,' UTC  Speed Over Ground from PSD GPS. ', cruise, year]);xlabel(['JD', year]);ylabel('SOG (m/s)');
    print('-djpeg90 ',[way_images_flux '\PSD_GPS_SOG_' num2str(ddd) '.jpg']);
figure;plot(jd_gps,gpshead1,'.');title(['JD',jd,' Hr',hr,' UTC  Course Over Ground from PSD GPS. ', cruise, year]);xlabel(['JD', year]);ylabel('COG (deg)');  
    print('-djpeg90 ',[way_images_flux '\PSD_GPS_COG_' num2str(ddd) '.jpg']);
