more off;

%f.ladcpup = sprintf('/../LADCP_new/raw/SL%03d000.000',stn);
f.ladcpdo = sprintf('/../LADCP_new/raw/MA%03d000.000',stn);
f.res = sprintf('/../LADCP_new/processed/OUTPACE_%03d',stn); % output filename

f.checkpoints = sprintf('/../LADCP_new/checkpoints/log_%03d.cnv',stn);
f.ctd = sprintf('/../LADCP_new/raw/out_c_%03d.cnv',stn);   
%=========================================================================
% RDI PARAMETERS for OUTPACE : WH300 downlooker only 
% restrict inversion to one instrument only 1: up+dn, 2:dn only  3:up only
p.up_dn_looker=2; %WH300 downlooker only

if stn<80   % 8m bin  and 176cm blank for WH300 sampling 
p.edit_mask_up_bins = []; % Bin1 is used with weight p.weighbin1=0.1
ps.dz=8  ;% set vertical resolution of inversion to  8 m for LADCP only or LADCP constraint with S150 & S38 
elseif stn>80 % 4m bin and 0 cm blank for WH300 from 80 to 103; later 103: 8m bin , blank 0
 p.edit_mask_dn_bins = [1];%  suppress Bin1 in downlooker 
 %ps.dz=4  ;% set vertical resolution of inversion to 4m , for WH300  4m bin sampling , only or constraint byS150 
 ps.dz=8  ;% set vertical resolution of inversion to 8m , for WH300  4m bin sampling  constraint by S38
end

p.cut=5;  % Atalante draft around 5.5m
p.pglim=20;  %%20% for Pgood min
p.elim=0.2; 
p.vlim=1; 
p.wlim=0.08;
p.timoff=0   %% LADCP time offset correction ( in decimal day)
p.orig=0;
p.weighbin1=0.1; % weight used for Bin1 
p.tiltmax=[22 4];
p.name='Herve';
p.maxbinrange=0;
p.ts_save=0;
p.cm_save=0;
p.pg_save=3;  %%3
p.xmv_min=0;
% Bottomtrack parameters
%p.btrk_ts=5;
%p.bottomdist=1 ;
if stn==87 || stn==91 || stn==95 || stn==99 || stn==163
p.btrk_mode=3; %bottom was visible on those stations
else
p.btrk_mode=0; % no bottom track as bottom is never reached
end
;
%% SADCP
p.sadcp =0 % SDACP available : 38, 150 , or 0 if no SADCP constraint
ps.sadcpfac=0  % 1 to 5 as weight for normal SADCP constraint , 0 if you want to compare SADCP profile against non constraint LADCP 
if p.sadcp==150 && stn<92
    f.sadcp=sprintf('/../LADCP_new/raw/OUTPACE_SADCP150East.mat')
elseif p.sadcp==150 && stn>91 && stn<152
    f.sadcp=sprintf('/../LADCP_new/raw/OUTPACE_SADCP150West.mat')%Sadcp 150khz file name and path
elseif p.sadcp==150  && stn>153
    f.sadcp=sprintf('/../LADCP_new/raw/OUTPACE_SADCP150LDC.mat')%Sadcp 150khz file name and path
elseif p.sadcp==38 && stn<92 
f.sadcp=sprintf('/../LADCP_new/raw/OUTPACE_SADCP38East.mat') %Sadcp 38khz file name and path
elseif p.sadcp==38 && stn>91 && stn<152
f.sadcp=sprintf('/../LADCP_new/raw/OUTPACE_SADCP38West.mat') %Sadcp 38khz file name and path
elseif p.sadcp==38  && stn>151
f.sadcp=sprintf('/../LADCP_new/raw/OUTPACE_SADCP38LDC.mat') %Sadcp 38khz file name and path
end


p.year=0; %shift for SADCP date 
p.sadcp_time_offset=0;
%p.sadcp_time_offset=-7200/86400;% Sadcp is in UTC +2on SOMBA cruise, need to retrieve 2hrs

%% CTD PARAMETERS
p.ctd=1; % CTD file used for Plotfinal
f.ctd_header_lines = 303; %%%290;
f.ctd_fields_per_line = 80;
f.ctd_pressure_field = 1;
f.ctd_temperature_field = 2;
f.ctd_salinity_field = 3;
if stn==33 || stn==67 || stn==83 || stn==91  || stn==110  || stn==163 || stn==165 || stn==190 || stn==211 
f.ctd_time_field = 6;    % IMPORTANT : 6 for elapsed, 7 for Year day %%%%%%%%%%%%%%%%%%%%%%%%%%
f.ctd_time_base = 0;     % IMPORTANT : 0 for elapsed, 1 for Year day %%%%%%%%%%%%%%%%%%%%%%%
else
f.ctd_time_field = 7;    % IMPORTANT : 6 for elapsed, 7 for Year day %%%%%%%%%%%%%%%%%%%%%%%%%%
f.ctd_time_base = 1;     % IMPORTANT : 0 for elapsed, 1 for Year day %%%%%%%%%%%%%%%%%%%%%%% 
end
%% navigation parameters 
f.nav = f.ctd;
f.nav_header_lines = 303 ;
f.nav_fields_per_line = 80;
f.nav_time_field =f.ctd_time_field ;
f.nav_lat_field = 4;
f.nav_lon_field = 5;
f.nav_time_base =f.ctd_time_base ; % for year month day julian time ( NOT gregorian!)
p.navtime_av = 1/60/24; % averaging GPS navigation on x minutes
p.drot=nan; % magnetic declination if known (11E in New Caledonia) or computed from old WWM model
%==========================================================================
%GENERAL PARAMAETERS
p.ladcp_station = stn;
p.cruise_id = 'OUTPACE';
% choose PLots title and Plots save according to process type 
if p.sadcp==150 && ps.sadcpfac > 0
   p.name = sprintf('%s S150+Ladcp, cast #%d',p.cruise_id,p.ladcp_station);
   p.saveplot_png = [1 2 3 4 9 11 12 14];
elseif p.sadcp==150 && ps.sadcpfac==0
   p.name = sprintf('%s Ladcp(comp.to S150),cast %d',p.cruise_id,p.ladcp_station);
   %p.saveplot_png = [1 2 3 4 9 11 12 14];
elseif p.sadcp==38 && ps.sadcpfac >0
    p.name = sprintf('%s S38+Ladcp cast #%d',p.cruise_id,p.ladcp_station);
     p.saveplot_png = [1 2 3 4 9 11 12 14];
elseif p.sadcp==38 && ps.sadcpfac==0
   p.name = sprintf('%s Ladcp(comp.to S38),cast %d',p.cruise_id,p.ladcp_station);    
   
   %p.saveplot_png = [1 2 3 4 9 11 12 14];
elseif p.sadcp==0  
p.name = sprintf('%s  Ladcp only cast #%d',p.cruise_id,p.ladcp_station);
p.saveplot_png = [1:4 11 12 14];
end
%p.saveplo_pngt = [];
p.saveplot = [];

p.checkpoints = [1];

%eval(sprintf('save %s_data.mat d',f.res));