% read_gps_daily % VOCALS 2008 :: 2008-10-16 :: Simon de Szoeke % Read the GPS ASCII data files. % Note: hhh=hour disp(['read_gps_day: ', cruise, ' ', year]); st2=[];jax1=1;jd_gps=[];jd1=[]; jd=sprintf('%03i',ddd); for jam=00:23 hr=sprintf('%02i',jam); dfl=[way_raw_data_flux, 'day',jd,'\gps0' year(3:4) jd hr '_raw.txt']; disp(dfl) flist=fopen(dfl); stx=[];temp=[]; if flist>0 dmp2=fgets(flist); while feof(flist)==0, temp=fscanf(flist,'%2f%2f%3f %*6c,%*6c,%*c,%f,%c,%f,%c,%f,%f,%f,%f,%*4c',[11,inf]); if length(temp)<11 temp=[temp;zeros(1,11-length(temp))']; end; stx=[stx temp]; % slow dmp2=fgets(flist); end; ii=find(stx(4,:)>0); stx=stx(:,ii); %remove bad line ($GPGGA) % % 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,:)>3e4); %find lines containing $GPRMC % ii=find(stx(4,:)>0); %stx=stx(:,ii); %remove bad line ($GPGGA) %0006148 $GPGGA,000006,5052.0627,S,05601.1112,W,1,10,1.0,12.7,M,10.0,M,,*7E %0006672 $GPRMC,000007,A,5052.0629,S,05601.1057,W,012.6,091.7,030308,002.4,E*74 % time_gpspsd=st2(1,:); % jd_gps=jd_gps(ii); glt=st2(4,:); gpslat_sign=st2(5,:); gln=st2(6,:); gpslon_sign=st2(7,:); gpsspeed1=st2(8,:).*.514; %convert to m/s gpshead1=st2(9,:); %deg % 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); ii=find(gpsspeed1>100);gpsspeed1(ii)=NaN; ii=find(gpshead1>400);gpshead1(ii)=NaN; if plotit figure; subplot(2,1,1) plot(gpslon1,gpslat1,'.');title(['JD',jd,' Hr',hr,' UTC Longitude/Latitude from PSD GPS. ', cruise, year]);xlabel('longitude in deg');ylabel('latitude in deg'); subplot(4,1,3) 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)'); subplot(3,1,4) plot(jd_gps,gpshead1,'.');title(['JD',jd,' Hr',hr,' UTC Course Over Ground from PSD GPS. ', cruise, year]);xlabel(['JD', year]);ylabel('COG (deg)'); orient tall if prtit; print('-djpeg90 ',[way_raw_images_flux '\PSD_GPS_track_COG_SOG_' num2str(ddd) '.jpg']); end 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'); if prtit; print('-djpeg90 ',[way_images_flux '\PSD_GPS_Ship_track_' num2str(ddd) '.jpg']); end 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)'); if prtit; print('-djpeg90 ',[way_images_flux '\PSD_GPS_SOG_' num2str(ddd) '.jpg']); end 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)'); if prtit; print('-djpeg90 ',[way_images_flux '\PSD_GPS_COG_' num2str(ddd) '.jpg']); end end