%compares bottles with profiles
%read bottle
clear all
p_calib=0;
o2_params
direps=[diro2 '/Figs'];

ibil=1; iflo=2; inat=3; ialex=4; ibad=5; %(Billy Kessler / Florent Gasparin / Sophie Cravatte)
smpname={'Bil','Flo','Nat','Alex','Bad'};
csmp={'blue','green','red','cyan','black'};

giprel=NaN*ones(22,200);%sampler name
giprel(:,1)=ibil;
giprel(:,2)=iflo;
giprel(:,3)=inat;
giprel(1:5,4)=iflo;
giprel(6:nbtl,4)=inat;
giprel(:,5)=ibil;
giprel(:,6)=inat;
giprel(:,7)=iflo;
giprel(:,8)=ibil;
giprel(:,9)=inat;
giprel(:,10)=inat;
giprel(:,11)=iflo;
giprel(:,12)=ibil;
giprel(:,13)=ibil;
giprel(6:11,13)=iflo;
giprel(:,14)=iflo; %Entrainement avec Alex
giprel(:,15)=inat;
giprel(:,16)=ibil;
giprel(:,17)=iflo;
giprel(:,18)=inat;
giprel(:,19)=ibil;
giprel(:,21)=inat;
giprel(:,22)=ibil;
giprel(:,23)=inat;
giprel(:,24)=ibil;
giprel(:,25)=iflo;
giprel(:,26)=inat;
giprel(:,27)=ibil;
giprel(:,28)=inat;
giprel(:,29)=iflo;
giprel(:,30)=ibad;
giprel(:,31)=ibil;
giprel(:,32)=iflo;
giprel(:,33)=inat;
giprel(:,34)=ialex;giprel(1:10,34)=inat;
giprel(:,36)=iflo;
giprel(:,37)=iflo;
giprel(:,38)=ibil;
giprel(:,39)=ibil;
giprel(:,40)=inat;
giprel(:,41)=ibil;
giprel(:,42)=inat;
giprel(:,43)=iflo;
giprel(:,44)=inat;
giprel(:,45)=ibil;
giprel(:,46)=ibil;giprel(14:22,46)=iflo;
giprel(:,47)=iflo;
giprel(:,48)=inat;giprel(22,48)=ibil;
giprel(:,49)=ibil;giprel(5:22,49)=iflo;
giprel(:,50)=inat;
giprel(:,51)=ibil;
giprel(:,52)=ibil;giprel(4:22,52)=iflo;
giprel(:,53)=iflo;
giprel(:,54)=inat;
giprel(:,55)=ibil;
giprel(:,56)=iflo;giprel(8:22,56)=inat;
giprel(:,57)=ibil;giprel([3,6,8],57)=ibad; %because CO2 taken before
giprel(:,58)=inat;
giprel(:,59)=ibil;
giprel(:,60)=ibil; %note that Cast 13 also counts above 1000m
giprel(:,61)=ialex;
giprel(:,62)=ibil;
giprel(:,63)=ialex;
giprel(:,64)=ibil;
giprel(:,65)=iflo;
giprel(:,66)=inat;
giprel(:,67)=ibil;
giprel(:,68)=iflo;
giprel(:,69)=inat;
giprel(:,70)=ibil;
giprel(:,71)=iflo;
giprel(:,72)=inat;
giprel(:,73)=ibil;
giprel(:,74)=iflo;
giprel(:,75)=inat;
giprel(:,76)=inat;giprel(8:22,76)=ibil;
giprel(:,77)=inat;
giprel(:,78)=ibil;
giprel(:,79)=iflo;
giprel(:,80)=iflo; %no stat 81 (goflo only)
giprel(:,82)=iflo;%[2,5,9,13,18]
giprel([4,7,11,16,21],82)=inat;

istat=44;
p_stat_60_cast_13=0

%%%%%%%%%%%%%%
% MAIN PROGRAM BEGINS
%%%%%%%%%%%%%%
%ctd files
fnamectd = strcat(dirctd, lower(cruiseName), '-all_ctd.nc');
%name for excel sheet
nfsample = sprintf('%s%s_O2_Stations_%03d_a_%03d.%s',diro2,cruiseName,...
  10*floor((istat-1)/10)+1,10*(1+floor((istat-1)/10)), excelExtension)
ishiftsheet=10*floor((istat-1)/10); %sheet index corresponding to the station within Excel file
if p_stat_60_cast_13 %just to get 60/cast 13 for upper 1000m
    ishiftsheet=49; %to shift excel sheets in each excel file
    gicast2get(60)=[13];%which cast to get from each station
end

figure(1);clf
[btlid,btlsal,btlsampid,btlo2kg,btlo2ml,btlpres,istat0] = ...
   read_xls_o2(nfsample,istat-ishiftsheet,nbtl);
if istat0~=istat
    error('check station number in excel file and excel sheets')
end

%ncdisp(fnamectd)
pres=ncread(fnamectd,'PRES');
oxctd1=ncread(fnamectd,'DO12');
oxctd2=ncread(fnamectd,'DO22');
gicast=ncread(fnamectd,'PROFILE');
icastctd=istat*100+gicast2get(istat); %cast label to find the right profile (hydro)
iprofile=find(gicast==icastctd);
hdlctd1=plot(oxctd1(:,iprofile),pres(:,iprofile),'c-');hold on; set(gca,'ydir','rev');
hdlctd2=plot(oxctd2(:,iprofile),pres(:,iprofile),'m-');set(gca,'ydir','rev');
hold on; grid on
ichgn=min(find(diff(giprel(:,istat))));
hdlsmp=plot(btlo2kg,btlpres,'x','color',csmp{giprel(1,istat)});
text(btlo2kg,btlpres,num2str(btlid),'verticalalignment','bot','horizontalalignment','left');
legend([hdlctd1,hdlctd2,hdlsmp],'RAW CTD1','RAW CTD 2',smpname{giprel(1,istat)},'location','southeast')
if ~isempty(ichgn) %2 samplers only
    iprel2=giprel(1+min(find(diff(giprel(:,istat)))),istat);
    gismp2=find(giprel(:,istat)==iprel2);
    hdl2=plot(btlo2kg(gismp2),btlpres(gismp2),'x','color',csmp{iprel2});
    hdlsmp=[hdlsmp,hdl2];
    legend([hdlctd1,hdlctd2,hdlsmp],'RAW CTD1','RAW CTD 2',smpname{giprel(1,istat)},...
        smpname{iprel2},'location','southeast')
end
set(gca,'ylim',[0,100*ceil(max(pres(:,iprofile))/100)])
ylabel('Pressure')
xlabel('O_2 \mumol kg^{-1}')
title(sprintf('PANDORA station %03d cast %02d',istat,gicast2get(istat)))
set(gcf,'paperorientation','portrait')
set(gcf,'paperunits','inch')
set(gcf,'Paperposition', [0.3 0.5 8 10])
fprname=sprintf('%s/oxygstat%d.eps',direps,istat);
exportfig(1,fprname,'color','cmyk','width',8,'height',10,'fontmode','fixed','fontsize',12);

