% LADCP PROCESSING SOFTWARE   6.ah
% Martin Visbeck, LDEO, 2002
% master m-file, copy and edit for each station

cb65vals

tic


% file names
 % ctd file to read depth from SEABIRD CTD file
 %wendy f.ctd=' ';  % uses W to obtain ADCP depth
% f.ctd='../demo-data4/ctddata.004';
% nav file with continous navigation data
  f.nav=' ';  
 %f.nav='../demo-data4/ctddata.004';
 % RDI raw data files
 f.ladcpdo='../dn/wh_dn000.000';
 p.down_sn=1411;
 % RDI raw data files empty means use only down looking instrument
 f.ladcpup='../up/wh_up000.000';
 p.up_sn=1412;
 % set to f.ladcpup=' '; if only down looking instrument is used
 % results should be written to this base filename (without extension)
% f.res=finddir;                     % base filename (without extension)
f.res=f.res;
p.name=f.res;                      % station name
%f.res='../demo-data4/demo4';

% parameter 

 % station name
 p.name='cb65';
 p.ladcp_station=20;

 % start and end time
 % [year, month, day, hour, minute, second]
 p.time_start=p.time_start;% ladcp start down time [yr,mn,da,hr,mn,sc]
p.time_end= p.time_end;% ladcp at surface time
%p.time_start=[1997 8 5 11 15 15];
% p.time_end=[1997 8 5 13 50 50];

 % start and end GPS position (needs to be quite accurate <20m)
 % [degrees N, minutes N, degrees E, minutes E]
 % for west and south derees use minus sign on BOTH degree and minute
 p.poss=p.poss;
p.pose=p.pose;
%p.poss=[-58,-42.93, -44,-30.36];
% p.pose=[-58,-41.59, -44,-32.19]; 

 % magnetic deviation angle in degree (as given on chart)
 %p.drot=0;
 p.drot=magdev(p.poss(1)+p.poss(2)/60, p.poss(3)+p.poss(4)/60);

 % start, deepest and end depth if W is used to find depth
 % p.zpar [startdepth, maxdepth (from CTD), enddepth]
 %p.zpar=[0 NaN 0];  
 %p.zpar=[10 NaN 10];  
 p.zpar=p.zpar;                 % p.zpar [startdepth, maxdepth (from CTD), enddepth]
%p.zpar=[10 2439 10];  

 % try to get bottom track out of water bins (for old RDI systems)
 % p.btrk_ts is in dB to detect bottom above bin1 level (for own btm track)
 % p.btrk_range gives maximum distance for bottom track
 % mode = 1 :   use only RDI bottom track
 %        2 :   use only own bottom track
 %        3 :   use RDI, if existent, own else (default)
 %        0 :   use not bottom track at all
 p.btrk_mode = 3;
 %p.btrk_ts=10;
 %p.btrk_range=200;

 % minimum % good
 p.pglim=0.0; 
 % maximum error velocity  [m/s]
 p.elim=0.2; 
 % maximum difference between W per profile [m/s]
 p.wlim=0.08;

 % p.rotup2down=0;  1: use down compass 2: use velocity
 p.rotup2down=1;

% inverse solve parameter
 % solve down and up individually
 ps.down_up=1;
 % resulting velocity profile vertical resolution (here 20m)
 ps.dz=20;
 
 % pre average the data to dz of p.dz
 p.avdz=ps.dz;

% process the data, plot some results and save ascii files
 laproc

% plot compass 
% plotcomp

