% LADCP PROCESSING SOFTWARE   5.0
% Martin Visbeck, LDEO, April 2000
% master m-file, copy and edit for each station
%
% applied for OC369
clear
%load gopro

%%%%%%%%%%% User parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

LT_FLAG=1;                         % 1=manual time;2=gopro time
LG_FLAG=1;                         % 1=manual gps; 2=gopro gps
MD_FLAG=1;                         % 1=manual max d; 2=ctd max d

% Filenames
f.ladcpdo='../dn/wh_dn000.000';    % ladcp down file
f.ladcpup='../up/wh_up000.000';    % ladcp up file; leave blank if absent
p.down_sn=1411;                    % down instrument s/n
p.up_sn=1412;                      % up instrument s/n
p.ladcp_station=1;                 % LADCP station number
%f.ctd=['/oden/ctdladcp/'];        % ctd file; '' = use W for depth
%f.nav=['/oden/ctdladcp/'];        % nav file; ''
f.ctd=['e:\cbl\ladcp\ctd4ladcp\lctd051.01'];                       % ctd file; '' = use W for depth
f.nav=[' '];                       % nav file; ''
f.res=finddir;                     % base filename (without extension)
p.name=f.res;                      % station name

% start, deepest and end depth if W is used to find depth
if MD_FLAG==1
p.zpar=[2 2040.3 2];                 % p.zpar [startdepth, maxdepth (from CTD), enddepth]
elseif MD_FLAG==2
p.zpar=[5 max(dd) 5];  
end

% Parameter 
if LT_FLAG==1
p.time_start=[2002 09 04 23 28 37];% ladcp start down time [yr,mn,da,hr,mn,sc]
p.time_end=  [2002 09 05 01 15 37];% ladcp at surface time
elseif LT_FLAG==2
p.time_start= sdw;                 % ladcp start down time [yr,mn,da,hr,mn,sc]
p.time_end  = suw;                 % ladcp at surface time
end

% time offset if ADCP time was set incorrect
%p.timoff=0;

% 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
if LG_FLAG==1
p.poss=[79 3.1081 -161 -53.8511];
p.pose=[79 3.9280 -161 -52.3700];
elseif LT_FLAG==2
p.poss=[ctdlat3(1) sign(ctdlat3(1)).*ctdlat3(2) ctdlat3(3) sign(ctdlat3(3)).*ctdlat3(4)];
p.pose=[ctdlat4(1) sign(ctdlat4(1)).*ctdlat4(2) ctdlat4(3) sign(ctdlat4(3)).*ctdlat4(4)];
end

% 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);

% try to get bottom track out of water bins (for old RDI systems)
% p.btrk 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=300;

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

% Compass
p.rotup2down=0;                     % 1: use mean of 2 compass 2: use velocity

% 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;

% save all original data in work space set p.orig=1
p.orig=1;

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