ascfa = 1/300; %arrow scale factor pltBound = [-122.5 -121.5 36.5 37.5]; [ax,sc]= mercat(pltBound(1:2),pltBound(3:4)); fname = 'C:\Temp\coast'; coast=load(fname); dnames = {'MBARI3','MBARI4','MBARI6'}; 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',','); k = k+1;temp = ''; catch temp = ''; end end fclose(fid); %throw out where we did not get gps goodgpsind = find(data(41,:)~=0);%both lat and long are bad when it goes out data = data(:,goodgpsind); %find where salinity values are saltwater or greater/otherwise its on the ship and who cares deployind = find(data(40,:)>=25); 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 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 > 3 % 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) arrowleg('ll',10,'cm/s',ascfa); text(-122.39,37.4,sprintf('Velocity:%2.2f cm/s',vel),'fontweight','bold'); text(-122.39,37.36,sprintf('Bearing:%3.2f degrees',truedir),'fontweight','bold'); text(-122.39,37.32,sprintf('Last Report Time:%s [GMT]',datestr(jul2date(data(2,end),data(1,end)))),'fontweight','bold'); text(-122.39,37.28,sprintf('Longitude:%3.3f Latitude:%3.3f',data(42,end),data(41,end)),'fontweight','bold'); end % if numpos end % if dep end % for dep title(dname); saveas(h,sprintf('C:\\Temp\\%s.png',dname)); data=[];begdep=[];enddep=[]; end exit;