ascfa = 1/300; %arrow scale factor pltBound = [-122.5 -121.5 36.5 37.1]; [ax,sc]= mercat(pltBound(1:2),pltBound(3:4)); lgtxt={};lh = 1; lontxt ={'-122.5';'-122.25';'-122.0';'-121.75';'-121.5'}; fname = 'C:\Temp\coast'; coast=load(fname); dnames = {'MBARI3','MBARI4','MBARI5','MBARI6'}; cols = {'b.','r.','g.','c.'}; arcols = {'b-','r-','g-','c-'}; for driftctr = 1:length(dnames) dname=char(dnames(driftctr)); fname = sprintf('D:\\script\\drifters\\%s\\%s_comp',dname,dname); fid = fopen(fname); %burn the header token = '#'; trash = fgetl(fid); while strncmp(trash,token,1) trash = fgetl(fid); end k=1; while ~feof(fid) try %if there are weird characters from the drifter or dropped points from ecopuck lose the line temp=fgetl(fid); data(:,k) = strread(temp,'%f',42,'delimiter',','); if strcmp(dname,'MBARI5') if data(2,k) > 234.709 & data(2,k) < 235.709 if data(40,k)<25 data(40,k)=99.999; end end end k = k+1;temp = ''; catch temp = ''; end end fclose(fid); %throw out where we did not get gps goodgpsind = find(data(41,:)~=0&data(41,:)~=-999);%both lat and long are bad when it goes out if ~isempty(goodgpsind) data = data(:,goodgpsind); %find where salinity values are saltwater or greater/otherwise its on the ship and who cares deployind = find(data(40,:)>=25); if ~isempty(deployind) data = data(:,deployind); %find the end and beginning points of deployment enddep = find(diff(deployind)>1); if ~isempty(enddep)%if only deployed once with no end begdep = [1 enddep+1]; else begdep = 1; end numdep = length(begdep); %number of deployments coastlon=coast(:,2);coastlat=coast(:,1); coastlatind=find(coastlat>=36&coastlat<=37.5); coastlon=coastlon(coastlatind);coastlat=coastlat(coastlatind); h=figure; plot(coastlon,coastlat,'k-','linewidth',1); xlabel('Longitude [deg]');ylabel('Latitude [deg]'); hold on; set(gca,'DataAspectRatio',[1,sc,1],'PlotBoxAspectRatio',[1,1/ax,1]); for dep = 1:numdep if dep ~= numdep plot(data(42,begdep(dep):enddep(dep)),data(41,begdep(dep):enddep(dep)),'g-'); plot(data(42,begdep(dep)),data(41,begdep(dep)),'k.'); % show where initially deployed elseif jul2date(data(2,end),data(1,end))<=(now-1/4) plot(data(42,begdep(dep):end),data(41,begdep(dep):end),'g-'); plot(data(42,begdep(dep)),data(41,begdep(dep)),'k.'); % show where initially deployed else plot(data(42,begdep(dep):end),data(41,begdep(dep):end),'r.'); plot(data(42,begdep(dep)),data(41,begdep(dep)),'k.'); % show where initially deployed numpos = length(data(42,begdep(dep):end)); if numpos >= 2 % make sure we have two readings to plot last known movements [X,Y,U,V,truedir,vel,dist]=calcdirvel(jul2date(data(2,end-1:end),data(1,end-1:end)),... data(42,end-1:end),data(41,end-1:end)); arrowplot(X,Y,U,V*sc,ascfa); plot(data(42,end-1:end),data(41,end-1:end),'b.'); axis(pltBound) set(gca,'xtick',([-122.5 -122.25 -122.0 -121.75 -121.5 ])); set(gca,'xticklabel',lontxt); arrowleg('ll',10,'cm/s',ascfa); text(-122.475,37.02,sprintf('Velocity:%2.2f cm/s',vel),'fontweight','bold'); text(-122.475,36.98,sprintf('Bearing:%3.2f degrees',truedir),'fontweight','bold'); text(-122.475,36.94,sprintf('Longitude:%3.4f',data(42,end)),'fontweight','bold'); text(-122.475,36.90,sprintf('Latitude:%3.4f',data(41,end)),'fontweight','bold'); text(-122.475,37.06,sprintf('Last Sample:%s [GMT]',datestr(jul2date(data(2,end),data(1,end)))),'fontweight','bold'); if ~exist('hh') hh=figure; fid2 = fopen('C:\Temp\drift.init','wt'); plot(coastlon,coastlat,'k-','linewidth',1); set(gca,'DataAspectRatio',[1,sc,1],'PlotBoxAspectRatio',[1,1/ax,1]); xlabel('Longitude [deg]');ylabel('Latitude [deg]'); else figure(hh); hold on; end hold on; %lghan(lh)=plot(data(42,end-1:end),data(41,end-1:end),'k'); lghan(lh)=arrowplot(X,Y,U,V*sc,ascfa,char(arcols(driftctr))); plot(data(42,end-1:end),data(41,end-1:end),'k.') set(lghan(lh),'LineWidth',1.25) lgtxt(lh) = cellstr(dname); lh= lh+1; figure(h); fprintf(fid2,'%s,%s,%3.4f | %3.4f,%2.2f,%2.4f,%2.2f,%3.2f\n',dname,datestr(jul2date(data(2,end),data(1,end))),data(42,end),data(41,end),data(39,end),data(40,end),truedir,vel); end % if numpos end % if dep end % for dep title(dname); set(gcf,'PaperPosition',[.25 2.5 4.5 3.25]); setfontsize(7); writegif(sprintf('C:\\Temp\\%s',dname)); %saveas(h,sprintf('C:\\Temp\\%s.png',dname)); data=[];begdep=[];enddep=[]; end end end if exist('hh') figure(hh); axis(pltBound); set(gca,'xtick',([-122.5 -122.25 -122.0 -121.75 -121.5 ])); set(gca,'xticklabel',lontxt); alh=arrowleg('ll',10,'cm/s',ascfa); set(alh,'LineWidth',1.25) legend(lghan,lgtxt,4); title('Currently Deployed Drifters AOSNII 2003'); set(gcf,'PaperPosition',[.25 2.5 4.5 3.25]); setfontsize(7); writegif('C:\\Temp\\compositedrift'); fclose(fid2); %saveas(hh,'C:\\Temp\\compositedrift.png'); end exit;