procit=0;

if procit
   
%%------------------------------------------------------   
%% requires a 'missiondata' file in the directory to be processed
%% example file is below...
%% insert missionID and load this file in each directory
%% ship head, bearing to auv, dist to auv (km)
%% longitude west should be positive --
%% will be converted to negative by bearing.m
%
%% startrng includes ship head, bearing to auv, dist to auv (km)
%
%% edit these six lines...
%
%
%missionID='2000.238.17';
%surveydate='25 August 2000'; %for graph title
%
%% degrees can be DD.DDDD or DD MM.MMM 
%% must be consistent within one set of bearings
%
%shipstart=[34 30.00 122 59.99] ;
%startrng =[0 180 400] ;          
%
% shipend=[46.5 120.0] ;% endrng=[90 0 500]   ;         
%
% end of example mission data
% --------------------------------------------------



clear all;
% load ctd_section;
% Test yoyo
%our new file instead of mission.mat

load biolum_section; %t=T; s=S; Depth=depth;
OBS=obs;F=f;Bioflow=bioflow;Biolum=biolum;Biotemp=biotemp;

tempswitch = 0; %from  vehicle =0, from biolum =1

missions ;%contains missionID, surveydate, and list of directories.

% missiondata ;%contains missionID, surveydate, lat lon, also can override tempswitch

if (tempswitch)
   disp('Using biolum temp...');
   else
      disp('Using auv temp...');
end%if
   
titl=['AUV Bioluminescence survey line, 'surveydate]; %surveydate from missiondata
%% Estimate transect distance


 minZ=3;
 %values used in bearing.m are loaded from missiondata
% ep([1 3])=bearing(shipstart,startrng);
% ep([2 4])=bearing(shipend,endrng)


% assume vehicle speed of 1 m/s
epochsec=time;
dist2 = (max(epochsec)-min(epochsec))/1000;
[dist phas]=sw_dist(ILAT([1 length(ILAT)]),ILON([1 length(ILON)]),'km');

disp(['Distance from Epochsec : ' num2str(dist2) ' km']);
disp(['Distance from LatLong  : ' num2str(dist) ' km']);

tdist = linspace(0,dist,length(F));
idist = linspace(0,dist,200);
iZ = [minZ:1:max(Depth)]';
AX = [0 dist min(iZ) max(iZ)]; 

%% Choose interpolation method
delaunay=1;
jgbgrid=0; 
   
if delaunay 
   disp('Using griddata (Delaunay)...'); meth='linear';
   gT = griddata(tdist,Depth,t,idist,iZ,meth);
   gS = griddata(tdist,Depth,s,idist,iZ,meth);
   gF = griddata(tdist,Depth,F,idist,iZ,meth);
   gOBS = griddata(tdist,Depth,OBS,idist,iZ,meth);
   gbiolum = griddata(tdist,Depth,Biolum,idist,iZ,meth);
   gbioflow = griddata(tdist,Depth,Bioflow,idist,iZ,meth);
   gbiotemp= griddata(tdist,Depth,Biotemp,idist,iZ,meth);

end %if delaunay
end %if procit
 %% Plot locations
phx=.12;
y1=1.05-.23-phx; y2=y1-phx-.04; y3=y2-phx-.04; y4=y3-phx-.04; y5=y4-phx-.04;
x1=.08; 
pw=.93; %plot width

P1=[x1 y1 pw phx]; P2=[x1 y2 pw phx]; 
P3=[x1 y3 pw phx]; P4=[x1 y4 pw phx];
P5=[x1 y5 pw phx];

% old alignment
% y1=1-.23-phx; y2=y1-phx-.05; y3=y2-phx-.05;
% x1=.08; pw=.4; x2=x1+pw+.08;
% P1=[x1 y1 pw phx]; P2=[x1 y2 pw phx]; P3=[x1 y3 pw phx];
% P4=[x2 y1 pw phx]; P5=[x2 y2 pw phx]; P6=[x2 y3 pw phx];

figure(1); clf; giffig_wide

%% little MAP
mapP = [x1+.05 y1+phx+.01 .08 .13];
axes('position', mapP);
% load transect_endpoints; 
 plot_transectA(ep);
tl=get(gca,'Ticklength'); set(gca,'Ticklength',tl*3);
% axes('position',P1);axes('position',P2);axes('position',P3);
% axes('position',P4);axes('position',P5);axes('position',P6);


 axes('position',P1);
 if tempswitch
    pcolor(idist,iZ,gbiotemp);
 else
    pcolor(idist,iZ,gT); 
 end%if
 shading interp; 
 % caxis([8.9 12.7]); 
 cb=colorbar; p=get(cb,'position'); set(cb,'position',p.*[1 1 .2 1]);
 % set(cb,'YTick',[]) % removes label
 set(gca,'ydir','reverse','Tickdir','out','XtickLabel',[]); 
 % xlabel('Distance along transect (km)'); 
 ylabel('Depth (m)');
 if tempswitch
   title(['Biolum temp (' setstr(176) 'C)']); 
else
  title(['Temperature (' setstr(176) 'C)']); 
 end%if
 % title(['Temperature: observed [min max] = [' num2str([min(t) max(t)]) ']']);
 hold on; 
 p=plot(tdist,Depth,'k.'); set(p,'markersize',1);
 
 axes('position',P2);
 pcolor(idist,iZ,gS); shading interp;
 % imagesc(idist,iZ,gS);
 % caxis([33.6 34]); 
 cb=colorbar; p=get(cb,'position'); set(cb,'position',p.*[1 1 .2 1]);
 % set(cb,'YTick',[]) % removes label
 set(gca,'ydir','reverse','Xticklabel',[],'tickdir','out'); 
 % xlabel('Distance along transect (km)'); 
 ylabel('Depth (m)'); 
 title(['Salinity (psu)']);
% title(['Salinity: observed [min max] = [' num2str([min(s) max(s)]) ']']);
hold on; 
%p=plot(tdist,Depth,'k.'); set(p,'markersize',4);
 
 axes('position',P3); 
 pcolor(idist,iZ,gF); shading interp; 
 % caxis([8.9 12.7]); 
 cb=colorbar; p=get(cb,'position'); set(cb,'position',p.*[1 1 .2 1]);
  set(gca,'ydir','reverse','Xticklabel',[],'tickdir','out'); 
% xlabel('Distance along transect (km)'); 
 ylabel('Depth (m)'); 
 title('Fluorometer (volts)');
 hold on; 
 %p=plot(tdist,Depth,'k.'); set(p,'markersize',4);
 
 axes('position',P4);
 pcolor(idist,iZ,gbiolum); shading interp; 
 % caxis([8.9 12.7]); 
 cb=colorbar; p=get(cb,'position'); set(cb,'position',p.*[1 1 .2 1]);
 set(gca,'ydir','reverse','Tickdir','out','XTickLabel',[]);
 % xlabel('Distance along transect (km)'); 
 ylabel('Depth (m)'); title('Biolum (counts)') 
 % title(['Biolum: observed [min max] = [' num2str([min(biolum) max(biolum)]) ']']);
 hold on; 
 set(gca,'ydir','reverse','Tickdir','out');
 
 axes('position',P5);
 pcolor(idist,iZ,gOBS); shading interp; 
 % caxis([8.9 12.7]); 
 cb=colorbar; p=get(cb,'position'); set(cb,'position',p.*[1 1 .2 1]);
 set(gca,'ydir','reverse','Tickdir','out');
xlabel('Distance along transect (km)'); 
 ylabel('Depth (m)'); title('OBS (volts)');
hold on; 
 %p=plot(tdist,Depth,'k.'); set(p,'markersize',4)
 %puts data marks on top
 %p=plot(tdist,Depth,'k.'); set(p,'markersize',4);
 
 % axes('position',P6);
 % %pcolor(idist,iZ,gbioflow); shading interp; 
 % caxis([8.9 12.7]); 
 % cb=colorbar; p=get(cb,'position'); set(cb,'position',p.*[1 1 .2 1]);
 % set(gca,'ydir','reverse','Tickdir','out');
 % xlabel('Distance along transect (km)'); ylabel('Depth (m)');
 % title('Biolum flow');
 % %title(['pH: observed [min max] = [' num2str([min(ph) max(ph)]) ']']);
 % hold on; p=plot(tdist,Depth,'k.'); set(p,'markersize',4);
% 
frame
txt=text(.3,.92,titl); set(txt,'fontweight','bold','fontsize',18);
txt=text(.5,.88,['Mission ID: ' missionID]); set(txt,'fontsize',12)
% txt=text(.7,.85,['(Straightened out zig-zag mission)']); set(txt,'fontsize',10)


return

