LADCPproc
author A.M. Thurnherr <athurnherr@yahoo.com>
Tue, 15 May 2012 19:20:40 +0000
changeset 10 196a179304ee
parent 9 48b2d27aaebf
child 11 d0af7f7aa23b
permissions -rwxr-xr-x
1.0beta
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     1
#!/usr/bin/perl
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     2
#======================================================================
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     3
#                    L A D C P P R O C 
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     4
#                    doc: Thu Sep 16 20:36:10 2010
10
196a179304ee 1.0beta
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 9
diff changeset
     5
#                    dlm: Wed Apr 18 05:23:48 2012
8
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 7
diff changeset
     6
#                    (c) 2010 A.M. Thurnherr
10
196a179304ee 1.0beta
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 9
diff changeset
     7
#                    uE-Info: 70 45 NIL 0 0 72 2 2 4 NIL ofnI
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     8
#======================================================================
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     9
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    10
$antsSummary = 'process LADCP data to get shear, time series';
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    11
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    12
# NOTES:
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    13
#   - the shear-method editing in this code is based on Eric Firing's merge.c
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    14
#   - as described in [LADCPproc.backscatter], there are three different codes 
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    15
#     for correcting echo amplitudes for attenuation loss & beam spreading
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    16
#   - comments starting with ## are taken verbatim from the original implementations
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    17
#   - the basic idea of the time lagging implemented in this code is similar
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    18
#     to the one implemented in Martin Visbeck's bestlag.m
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    19
#   - for SeaBird files:
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    20
#       - CTD elapsed time is estimated from recno * CTD{sampint}
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    21
#       - first elapsed time is added on output
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    22
#   - output elapsed time is from CTD to allow yoyo processing without loss of
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    23
#     time information
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    24
#   - CTD{elapsed} is undefined for records before instrument is in the water
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    25
#   - ITS-90 temp field in degC required
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    26
#   - salin field prequired
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    27
#   - pressure field in dbar required
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    28
#   - -i should be set to the number that's added to LADCP_elapsed to make the two
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    29
#     time series overplot nicely
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    30
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    31
# HISTORY:
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    32
#   Sep 16, 2010: - incepted
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    33
#   Oct 13, 2010: - first working version
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    34
#   Oct 14, 2010: - renamed from LADCPshear
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    35
#   Oct 19, 2010: - added -a)coustic backscatter profiles
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    36
#   Oct 20, 2010: - added -2)dary CTD sensors
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    37
#   Oct 23, 2010: - added magnetic-declination correction
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    38
#   Oct 26, 2010: - added tilt calculation
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    39
#   Dec  9, 2010: - added support for ASCII CTD files
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    40
#   Dec 10, 2010: - change -w) default to 120s
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    41
#                 - changed nshear output to 0 from nan when there are no samples
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    42
#   Dec 27, 2010: - changed sign of -l to accept lag output from [LADCP_w]
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    43
#   Jan 10, 2011: - -o => -k added new -o
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    44
#                 - added code to fill CTD sound vel gaps
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    45
#   Jan 22, 2011: - added -g) lat,lon
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    46
#                 - added -c)ompass corr
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    47
#   Jun 15, 2011: - added mean backscatter profile to default output
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    48
#   Jul  7, 2011: - added support for $BT_* processing parameters
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    49
#                 - replaced old per-bin acoustic backscatter profile output by
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    50
#                   acoustic backscatter depth-time-series
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    51
#                 - disabled seabed and acoustic backscatter code when not required (e.g. UL)
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    52
#                 - made non-diagnostic output terser
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    53
#   Jul 11, 2011: - changed default output to .tds and added -p)rofile option
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    54
#   Jul 14, 2011: - added -u)se D[eines1999][V[isbeck2004]]
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    55
#   Jul 15, 2011: - changed output bin# to 1-based in -a output
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    56
#                 - added T[hurnherr11] -u)se option
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    57
#                 - added $CTD{first_elapsed}
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    58
#   Jul 27, 2011: - replaced ndata by nsamp
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    59
#   Feb  5, 2012: - added profile max depth consistency check
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    60
#   Feb 19, 2912: - added elapsed time to shear profile output
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    61
#                 - replaced "nshear" output field by "nsamp"
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    62
#                 - BUG: bottom of profiles was incorrect when dc max depth > uc max depth
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    63
#                 - BUG: profile depth consistency check did not work for partial-depth yoyo casts
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    64
#   Apr 10, 2012: - changed default backscatter correction to Deines (1999)
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    65
#                 - improved and relaxed depth consistency check
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    66
#   Apr 11, 2012: - BUG: double comma that did not affect the output
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    67
#                 - BUG: code had assumed, but not ensured, that first CTD scan is valid
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    68
#   Apr 13, 2012: - removed -s argument from dependencies
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    69
#	Apr 17, 2012: - BAD BUG: magdec code call was bad and did not return correct value. ever.
10
196a179304ee 1.0beta
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 9
diff changeset
    70
#	Apr 18, 2012: - replaced Sv.n by Sv.nsamp
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    71
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    72
($ANTS)       = (`which list` =~ m{^(.*)/[^/]*$});
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    73
($PERL_TOOLS) = (`which mkProfile` =~ m{^(.*)/[^/]*$});
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    74
($LADCPPROC)  = ($0 =~ m{^(.*)/[^/]*$});
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    75
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    76
require "$ANTS/ants.pl";
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    77
require "$ANTS/libEOS83.pl";
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    78
require "$ANTS/libstats.pl";
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
    79
require "$LADCPPROC/LADCPproc.loadCTD";
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    80
require "$LADCPPROC/LADCPproc.bestLag";
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    81
require "$LADCPPROC/LADCPproc.BT";
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    82
require "$LADCPPROC/LADCPproc.backscatter";
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    83
require "$LADCPPROC/LADCPproc.UHcode";
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    84
require "$PERL_TOOLS/RDI_BB_Read.pl";
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    85
require "$PERL_TOOLS/RDI_Coords.pl";
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    86
require "$PERL_TOOLS/RDI_Utils.pl";
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    87
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    88
$antsParseHeader = 0;
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    89
&antsUsage('24a:b:c:df:g:i:kl:n:o:p:s:t:u:w:',2,
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    90
    '[use -2)dary CTD sensor pair]',
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    91
    '[require -4)-beam LADCP solutions]',
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    92
    '[-s)etup <file>] [-g)ps <lat,lon>]',
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    93
    '[-c)ompass-corr <offset,cos-fac,sin-fac>]',
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    94
    '[enable -p)PI editing]',
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    95
    '[-o)utput grid <resolution[5m]>]',
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    96
    '[-i)nitial LADCP time lag <guestimate>]',
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    97
    '[-l)ag LADCP <by>] [auto-lag -w)indow <size[120s]>] [-n) <auto-lag windows[20]]',
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    98
    '[correct echo amplitude -u)sing D[eines99]|V[isbeck04]|T[hurnherr11]|n[ocorr]',
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
    99
    '[-d)iagnostic screen output]',
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   100
    'output: [shear-p)rofile <file>] [-t)ime series <file>] [-f)lag <file>] [-b)ottom-track <file>]',
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   101
    '        [-a)coustic backscatter <dts-file] [bottom-trac-k) profs]',
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   102
    '<RDI file> <SeaBird file>');
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   103
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   104
$RDI_Coords::minValidVels = 4 if ($opt_4);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   105
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   106
&antsFloatOpt($opt_l);
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   107
&antsCardOpt(\$opt_w,120);
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   108
    # old default of -w 30 does not work if there are significant ambiguity-velocity
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   109
    # problems, as is the case, e.g., with 2010_DIMES_US2 station 142
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   110
    # old default of -w 60 did not work for DIMES_UK2 station 4 (DL), possibly again
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   111
    # related to ambiguity velocity
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   112
&antsCardOpt(\$opt_n,20);
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   113
#&antsFileOpt($opt_s);      # DON'T, AS THIS WILL ADD AN UNWANTED DEPENDCY
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   114
&antsFloatOpt($opt_i);
4
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   115
&antsCardOpt(\$opt_o,5);
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   116
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   117
if (defined($opt_u)) {
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   118
    croak("$0: cannot decode -u $opt_u\n")
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   119
        unless ($opt_u =~ /^[dDvVtTn]/);
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   120
} else {
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   121
    $opt_u = 'Deines99';
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   122
}
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   123
2
16726a31a399 pre IWISE
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 1
diff changeset
   124
if (defined($opt_g)) {
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   125
    ($CTD{lat},$CTD{lon}) = split(',',$opt_g);
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   126
    croak("$0: cannot decode -g $opt_g\n")
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   127
        unless numberp($CTD{lat}) && numberp($CTD{lon});
2
16726a31a399 pre IWISE
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 1
diff changeset
   128
}
16726a31a399 pre IWISE
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 1
diff changeset
   129
16726a31a399 pre IWISE
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 1
diff changeset
   130
if (defined($opt_c)) {
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   131
    ($CC_offset,$CC_cos_fac,$CC_sin_fac) = split(',',$opt_c);
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   132
    croak("$0: cannot decode -c $opt_c\n")
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   133
        unless numberp($CC_offset) && numberp($CC_cos_fac) && numberp($CC_sin_fac);
2
16726a31a399 pre IWISE
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 1
diff changeset
   134
}
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   135
    
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   136
$LADCP_file = &antsFileArg();
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   137
$CTD_file   = &antsFileArg();
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   138
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   139
&antsAddParams('LADCP_file',$LADCP_file,'CTD_file',$CTD_file);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   140
&antsActivateOut();
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   141
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   142
#----------------------------------------------------------------------
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   143
# Step 1: Read LADCP Data
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   144
#----------------------------------------------------------------------
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   145
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   146
print(STDERR "Reading LADCP data ($LADCP_file)...");
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   147
readData($LADCP_file,\%LADCP);
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   148
printf(STDERR "\n\t%d ensembles",scalar(@{$LADCP{ENSEMBLE}})) if ($opt_d);
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   149
print(STDERR "\n");
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   150
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   151
#----------------------------------------------------------------------
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   152
# Step 2: Set Processing Parameters
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   153
#----------------------------------------------------------------------
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   154
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   155
print(STDERR "Setting processing parameters...\n");
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   156
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   157
printf(STDERR "\tloading $LADCPPROC/LADCPproc.defaults...\n");
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   158
require "$LADCPPROC/LADCPproc.defaults";
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   159
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   160
if (defined($opt_s)) {
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   161
    print(STDERR "\tloading $opt_s...\n");
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   162
    require $opt_s;
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   163
}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   164
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   165
if ($LADCP{BLANKING_DISTANCE} == 0) {
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   166
    print(STDERR "\t\tBLANKING_DISTANCE == 0 => excluding all data from bin 1\n")
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   167
        if ($opt_d);
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   168
    $wbin_start = 2 unless ($wbin_start > 2);
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   169
    $ubin_start = 2 unless ($ubin_start > 2);
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   170
    $shbin_start = 2 unless ($shbin_start > 2);
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   171
    $BT_bin_start = 2 unless ($BT_bin_start > 2);
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   172
}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   173
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   174
&antsAddParams('ADCP_orientation',
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   175
        $LADCP{ENSEMBLE}[0]->{XDUCER_FACING_UP} ? 'uplooker' : 'downlooker');
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   176
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   177
$SHEAR_PREGRID_DZ = 20;
4
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   178
$GRID_DZ = $opt_o;
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   179
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   180
#----------------------------------------------------------------------
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   181
# Step 3: Read CTD data
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   182
#----------------------------------------------------------------------
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   183
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   184
print(STDERR "Reading CTD data ($CTD_file)...");
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   185
readCTD($CTD_file,\%CTD);
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   186
printf(STDERR "\n\t%d scans",scalar(@{$CTD{press}})) if ($opt_d);
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   187
print(STDERR "\n");
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   188
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   189
my($year)  = substr($LADCP{ENSEMBLE}[0]->{DATE},6,4);
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   190
my($month) = substr($LADCP{ENSEMBLE}[0]->{DATE},0,2);
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   191
my($day  ) = substr($LADCP{ENSEMBLE}[0]->{DATE},3,2);
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   192
my($magdec,$maginc,$h_strength,$v_strength) = split('\s+',`magdec $CTD{lon} $CTD{lat} $year $month $day`);
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   193
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   194
croak("$0: unknown magnetic declination\n")
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   195
	unless defined($magdec);
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   196
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   197
&antsAddParams('magnetic_declination',$magdec);
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   198
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   199
#----------------------------------------------------------------------
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   200
# Step 4: Pre-Process CTD & LADCP Data
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   201
#----------------------------------------------------------------------
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   202
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   203
printf(STDERR "Pre-processing data...");
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   204
printf(STDERR "\n\tCTD...") if ($opt_d);
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   205
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   206
#------------------------
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   207
# clean CTD pressure data
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   208
#------------------------
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   209
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   210
my($pSpikes) = 0;
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   211
for (my($r)=1; $r<@{$CTD{press}}; $r++) {
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   212
	$pSpikes++,$CTD{press}[$r]=nan
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   213
		if (abs($CTD{press}[$r]-$CTD{press}[$r-1])/$CTD{sampint} > 2);
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   214
}
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   215
print(STDERR "\n\t\t$pSpikes CTD pressure spikes removed")
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   216
	if ($pSpikes>0 && $opt_d);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   217
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   218
#-----------------------------------
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   219
# trim "preamble" without valid data
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   220
#-----------------------------------
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   221
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   222
my($r) = 0;
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   223
until (numberp($CTD{press}[$r]) && numberp($CTD{temp}[$r]) && numberp($CTD{salin}[$r])) { $r++ }
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   224
splice(@{$CTD{press}},0,$r);
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   225
splice(@{$CTD{temp}},0,$r);
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   226
splice(@{$CTD{salin}},0,$r);
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   227
print(STDERR "\n\t\t$r leading CTD scans without valid data removed")
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   228
	if ($r>0 && $opt_d);
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   229
7
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   230
#--------------------------------------------------
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   231
# calculate w and find deepest & shallowest records
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   232
#--------------------------------------------------
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   233
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   234
$CTD{maxpress} = -9e99;
7
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   235
$CTD{minpress} =  9e99;
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   236
for (my($r)=1; $r<@{$CTD{press}}-1; $r++) {
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   237
	$CTD{w}[$r] = 0.99*($CTD{press}[$r+1] - $CTD{press}[$r-1]) / (2*$CTD{sampint});
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   238
	if ($CTD{press}[$r] > $CTD{maxpress}) {
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   239
		$CTD{maxpress} = $CTD{press}[$r];
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   240
		$CTD{atbottom} = $r;
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   241
    }										
7
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   242
	if ($CTD{press}[$r] < $CTD{minpress}) {
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   243
		$CTD{minpress} = $CTD{press}[$r];
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   244
		$CTD{attop} = $r;
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   245
    }										
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   246
}
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   247
printf(STDERR "\n\t\tmin/max pressure [%d/%ddbar] at scans#%d/%d",
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   248
					$CTD{minpress},$CTD{maxpress},$CTD{attop},$CTD{atbottom})
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   249
	if $opt_d;
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   250
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   251
#----------------------------------------------------------------------
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   252
# Step 4b: Pre-Process LADCP Data
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   253
#----------------------------------------------------------------------
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   254
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   255
print(STDERR "\n\tLADCP...") if ($opt_d);
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   256
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   257
#-------------------------------------------
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   258
# transform to earth coordinates if required
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   259
#-------------------------------------------
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   260
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   261
$U = 0;		# velocity indices
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   262
$V = 1;
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   263
$W = 2;
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   264
$E = 3;
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   265
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   266
$LADCP{HEADING_BIAS} = -$magdec;
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   267
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   268
if ($LADCP{BEAM_COORDINATES}) {
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   269
	print(STDERR "\n\t\ttransforming beam to Earth coordinates...")
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   270
		if ($opt_d);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   271
	for (my($ens)=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   272
		$LADCP{ENSEMBLE}[$ens]->{TILT} = &angle_from_vertical($LADCP{ENSEMBLE}[$ens]->{PITCH},$LADCP{ENSEMBLE}[$ens]->{ROLL});
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   273
		for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   274
			@{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]} =
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   275
				velInstrumentToEarth(\%LADCP,$ens,velBeamToInstrument(\%LADCP,@{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]}));
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   276
			@{$LADCP{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$bin]} =					# fake it to fool ref_lr_w
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   277
				(0,0,0,defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$W]) ? 100 : 0);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   278
		}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   279
	}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   280
	$LADCP{BEAM_COORDINATES} = 0;
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   281
	$LADCP{EARTH_COORDINATES} = 1;
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   282
	unless ($opt_4) {
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   283
		print(STDERR "\n\t\t\t3-beam solutions: $RDI_Coords::threeBeam_1 $RDI_Coords::threeBeam_2 $RDI_Coords::threeBeam_3 $RDI_Coords::threeBeam_4\n")
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   284
			if ($opt_d);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   285
		&antsAddParams('3_beam_solutions',"$RDI_Coords::threeBeam_1 $RDI_Coords::threeBeam_2 $RDI_Coords::threeBeam_3 $RDI_Coords::threeBeam_4");
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   286
	}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   287
} elsif ($LADCP{EARTH_COORDINATES}) {
2
16726a31a399 pre IWISE
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 1
diff changeset
   288
	if ($opt_d) {
16726a31a399 pre IWISE
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 1
diff changeset
   289
		if ($opt_c) {
16726a31a399 pre IWISE
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 1
diff changeset
   290
			printf(STDERR "\n\t\tcalculating tilt and correcting for compass error and magnetic declination of %.1f deg...\n",$magdec);
16726a31a399 pre IWISE
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 1
diff changeset
   291
		} else {
16726a31a399 pre IWISE
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 1
diff changeset
   292
			printf(STDERR "\n\t\tcalculating tilt and correcting for magnetic declination of %.1f deg...\n",$magdec);
16726a31a399 pre IWISE
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 1
diff changeset
   293
		}
16726a31a399 pre IWISE
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 1
diff changeset
   294
	}
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   295
	for (my($ens)=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   296
		$LADCP{ENSEMBLE}[$ens]->{TILT} = &angle_from_vertical($LADCP{ENSEMBLE}[$ens]->{PITCH},$LADCP{ENSEMBLE}[$ens]->{ROLL});
2
16726a31a399 pre IWISE
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 1
diff changeset
   297
		my($hdg) = rad($LADCP{ENSEMBLE}[$ens]->{HEADING});
16726a31a399 pre IWISE
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 1
diff changeset
   298
		$LADCP{HEADING_BIAS} = ($CC_offset + $CC_cos_fac*cos($hdg) + $CC_sin_fac*sin($hdg)) - $magdec
16726a31a399 pre IWISE
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 1
diff changeset
   299
			if ($opt_c);
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   300
		for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   301
			@{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]} =
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   302
				velApplyHdgBias(\%LADCP,$ens,@{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]});
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   303
		}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   304
	}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   305
} else {
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   306
	croak("$0: can only handle beam or earth coordinates\n")
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   307
}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   308
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   309
#------------------------------------------------------
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   310
# construct a depth-vs-time "profile" from the raw data
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   311
#------------------------------------------------------
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   312
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   313
print(STDERR "\t\tconstructing profile time series...")
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   314
	if ($opt_d);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   315
	
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   316
($LADCP_start,$LADCP_end,$LADCP_bottom,$w_gap_time,$zErr,$maxz) =
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   317
    mk_prof(\%LADCP,0,undef,1,6,70,0.1,9999);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   318
croak("\n$LADCP_file: no good ensembles found\n")
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   319
    unless defined($LADCP_start);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   320
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   321
if ($opt_d) {
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   322
	printf(STDERR "\n\t\t\tStart of cast    : %s (#%5d) at %6.1fm\n",
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   323
	                    $LADCP{ENSEMBLE}[$LADCP_start]->{TIME},
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   324
	                    $LADCP{ENSEMBLE}[$LADCP_start]->{NUMBER},
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   325
	                    $LADCP{ENSEMBLE}[$LADCP_start]->{DEPTH});
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   326
	printf(STDERR "\t\t\tBottom of cast   : %s (#%5d) at %6.1fm\n",
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   327
	                    $LADCP{ENSEMBLE}[$LADCP_bottom]->{TIME},
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   328
	                    $LADCP{ENSEMBLE}[$LADCP_bottom]->{NUMBER},
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   329
	                    $LADCP{ENSEMBLE}[$LADCP_bottom]->{DEPTH});
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   330
	printf(STDERR "\t\t\tEnd of cast      : %s (#%5d) at %6.1fm",
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   331
	                    $LADCP{ENSEMBLE}[$LADCP_end]->{TIME},
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   332
	                    $LADCP{ENSEMBLE}[$LADCP_end]->{NUMBER},
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   333
	                    $LADCP{ENSEMBLE}[$LADCP_end]->{DEPTH});
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   334
}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   335
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   336
print(STDERR "\n");
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   337
8
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 7
diff changeset
   338
my($LADCP_prof_range) = $LADCP{ENSEMBLE}[$LADCP_bottom]->{DEPTH} -
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 7
diff changeset
   339
							min($LADCP{ENSEMBLE}[$LADCP_start]->{DEPTH},$LADCP{ENSEMBLE}[$LADCP_end]->{DEPTH});
7
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   340
croak(sprintf("$0: LADCP profile depth range (%dm) inconsistent with max CTD pressure range (%ddbar)\n",
8
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 7
diff changeset
   341
		$LADCP_prof_range,$CTD{maxpress}-$CTD{minpress}))
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 7
diff changeset
   342
	if (abs($LADCP_prof_range-($CTD{maxpress}-$CTD{minpress}))/(0.99*($CTD{maxpress}-$CTD{minpress})) > 0.2);
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   343
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   344
#----------------------------------------------------------------------
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   345
# Step 5: Add CTD to LADCP Data & correct velocities for sound speed
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   346
#	- {DEPTH} field is overwritten!
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   347
#----------------------------------------------------------------------
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   348
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   349
print(STDERR "Matching CTD to LADCP time series...");
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   350
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   351
$opt_l = defined($opt_l) ? -$opt_l : &lagLADCP2CTD();
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   352
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   353
print(STDERR "Associating CTD data with LADCP ensembles...");
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   354
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   355
for (my($min_depth)=9e99,my($ens)=$LADCP_start; $ens<=$LADCP_end; $ens++) {
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   356
	my($lastSvel); 
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   357
	my($r) = int(($LADCP{ENSEMBLE}[$ens]->{ELAPSED_TIME} - $opt_l) / $CTD{sampint});
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   358
	if ($r < 0 && $ens == $LADCP_start) {
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   359
		$r = int(($LADCP{ENSEMBLE}[++$ens]->{ELAPSED_TIME} - $opt_l) / $CTD{sampint})
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   360
			while ($r < 0);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   361
		printf(STDERR "\n\tCTD data begin with instrument already in water => skipping %ds of LADCP data",
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   362
			$LADCP{ENSEMBLE}[$ens]->{ELAPSED_TIME}-$LADCP{ENSEMBLE}[$LADCP_start]->{ELAPSED_TIME});
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   363
		$LADCP_start = $ens;
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   364
	}
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   365
	if ($r > $#{$CTD{press}}) {
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   366
		printf(STDERR "\n\tCTD data end while instrument is still in water => truncating %ds of LADCP data",
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   367
			$LADCP{ENSEMBLE}[$LADCP_end]->{ELAPSED_TIME}-$LADCP{ENSEMBLE}[$ens]->{ELAPSED_TIME})
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   368
				if ($opt_d);
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   369
		$LADCP_end = $ens - 1;
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   370
		last;
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   371
	}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   372
	my($dr);
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   373
	for ($dr=0; !numberp($CTD{press}[$r+$dr]); $dr--) {}
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   374
	$LADCP{ENSEMBLE}[$ens]->{DEPTH} = depth($CTD{press}[$r+$dr],$CTD{lat});
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   375
	if ($LADCP{ENSEMBLE}[$ens]->{DEPTH} < $min_depth) {
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   376
		$min_depth = $LADCP{ENSEMBLE}[$ens]->{DEPTH};
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   377
		$LADCP_top = $ens;
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   378
	}
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   379
	$LADCP{ENSEMBLE}[$ens]->{CTD_W} = $CTD{w}[$r];
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   380
	$LADCP{ENSEMBLE}[$ens]->{CTD_TEMP} = $CTD{temp}[$r];
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   381
	$LADCP{ENSEMBLE}[$ens]->{CTD_SVEL} = sVel($CTD{salin}[$r],$CTD{temp}[$r],$CTD{press}[$r+$dr]);
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   382
	if (numberp($LADCP{ENSEMBLE}[$ens]->{CTD_SVEL})) {
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   383
		$lastSvel = $LADCP{ENSEMBLE}[$ens]->{CTD_SVEL};
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   384
	} else {
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   385
		$LADCP{ENSEMBLE}[$ens]->{CTD_SVEL} = $lastSvel;
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   386
	}
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   387
	my($sscorr) = $LADCP{ENSEMBLE}[$ens]->{CTD_SVEL} / $LADCP{ENSEMBLE}[$ens]->{SPEED_OF_SOUND};
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   388
	for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   389
		next unless defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$W]);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   390
		$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$U] *= $sscorr;
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   391
		$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$V] *= $sscorr;
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   392
		$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$W] *= $sscorr;
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   393
    }
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   394
}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   395
9
48b2d27aaebf after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 8
diff changeset
   396
&antsAddParams('top_depth',round($LADCP{ENSEMBLE}[$LADCP_top]->{DEPTH}),
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   397
			   'bottom_depth',round($LADCP{ENSEMBLE}[$LADCP_bottom]->{DEPTH}),
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   398
			   'start_date',$LADCP{ENSEMBLE}[$LADCP_start]->{DATE},
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   399
			   'start_time',$LADCP{ENSEMBLE}[$LADCP_start]->{TIME},
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   400
			   'bottom_date',$LADCP{ENSEMBLE}[$LADCP_bottom]->{DATE},
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   401
			   'bottom_time',$LADCP{ENSEMBLE}[$LADCP_bottom]->{TIME},
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   402
			   'end_date',$LADCP{ENSEMBLE}[$LADCP_end]->{DATE},
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   403
			   'end_time',$LADCP{ENSEMBLE}[$LADCP_end]->{TIME});
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   404
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   405
print(STDERR "\n");
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   406
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   407
#----------------------------------------------------------------------
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   408
# Step 6: Calculate Acoustic Backscatter Profile
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   409
#----------------------------------------------------------------------
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   410
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   411
print(STDERR "Calculating acoustic backscatter profiles...");
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   412
mk_backscatter_profs($LADCP_start,$LADCP_end);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   413
print(STDERR "\n");
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   414
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   415
#----------------------------------------------------------------------
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   416
# Step 7: Find Seabed
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   417
#----------------------------------------------------------------------
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   418
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   419
if ($LADCP{ENSEMBLE}[$LADCP_start]->{XDUCER_FACING_DOWN}) {
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   420
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   421
	print(STDERR "Finding seabed...");
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   422
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   423
	print(STDERR "\n\tin acoustic backscatter profiles...") if ($opt_d);
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   424
	($water_depth,$sig_water_depth) =
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   425
		find_backscatter_seabed($LADCP{ENSEMBLE}[$LADCP_bottom]->{DEPTH});
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   426
	
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   427
	$min_hab = $water_depth - $LADCP{ENSEMBLE}[$LADCP_bottom]->{DEPTH};
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   428
	printf(STDERR "\n\twater depth      = %d(+-%.1f)m",$water_depth,$sig_water_depth);
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   429
	printf(STDERR "\n\tclosest approach = %dmab",$min_hab);
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   430
	
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   431
	print(STDERR "\n\tin RDI BT data...") if ($opt_d);
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   432
	($BT_water_depth,$sig_BT_water_depth) = 
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   433
		find_seabed(\%LADCP,$LADCP_bottom,$LADCP{BEAM_COORDINATES});
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   434
	
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   435
	if (defined($BT_water_depth)) {
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   436
		$min_hab = $BT_water_depth - $LADCP{ENSEMBLE}[$LADCP_bottom]->{DEPTH};
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   437
		printf(STDERR "\n\twater depth      = %d(+-%.1f)m",$BT_water_depth,$sig_BT_water_depth);
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   438
		printf(STDERR "\n\tclosest approach = %dmab",$min_hab);
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   439
#		$water_depth = $BT_water_depth; 							# assume BT data are better
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   440
#		$sig_water_depth = $sig_BT_water_depth; 					# (at least they are higher vertical resolution)
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   441
	}
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   442
	
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   443
	unless (defined($water_depth)) {
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   444
		print(STDERR "\n\tno seabed found\n");
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   445
		print(STDERR "\n\tunknown water depth => PPI editing disabled\n")
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   446
			if ($opt_d);
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   447
		$clip_margin = 0;
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   448
	}
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   449
	
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   450
	print(STDERR "\n");
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   451
	
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   452
} else { # UPLOOKER
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   453
	$water_depth = $sig_water_depth = $min_hab = nan;
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   454
	print(STDERR "Uplooker data => PPI editing disabled\n")
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   455
		if ($opt_d);
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   456
}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   457
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   458
#----------------------------------------------------------------------
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   459
# Step 8: Edit Data & also produce depth-time-series output vial callback
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   460
#----------------------------------------------------------------------
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   461
4
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   462
print(STDERR "Calculating shear profiles & producing time-depth-series (.tds) output...");
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   463
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   464
	#--------------------------------------------------------------------------------
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   465
	# callback routine to output .tds data, called once each for down-/upcasts after
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   466
	# shear has been gridded. Note that only the nominal (bin center) depth is known
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   467
	# for each sample in this version.
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   468
	
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   469
	sub outTDseries($)
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   470
	{
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   471
		my($downcast) = @_; # also use local @[uvw]sh_vals[][]
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   472
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   473
		if ($downcast) {
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   474
			my($mingi);
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   475
			for ($mingi=0; $mingi<@ush_vals; $mingi++) {
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   476
				last if @{$ush_vals[$mingi]};
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   477
	        }
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   478
			&antsAddParams('min_ens',$LADCP_start,'min_elapsed',$LADCP{ENSEMBLE}[$LADCP_start]->{ELAPSED_TIME}+$CTD{first_elapsed}-$opt_l,
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   479
						   'max_ens',$LADCP_end,'max_elapsed',$LADCP{ENSEMBLE}[$LADCP_end]->{ELAPSED_TIME}+$CTD{first_elapsed}-$opt_l,
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   480
						   'min_depth',depthOfGI($mingi),'max_depth',depthOfGI($#ens_vals));
4
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   481
			for (my($gi)=0; $gi<@ush_vals; $gi++) {
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   482
				for (my($i)=0; $i<@{$ush_vals[$gi]}; $i++){
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   483
					&antsOut($ens_vals[$gi][$i],$LADCP{ENSEMBLE}[$ens_vals[$gi][$i]]->{ELAPSED_TIME}+$CTD{first_elapsed}-$opt_l,
4
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   484
							 $downcast,depthOfGI($gi),$ush_vals[$gi][$i],$vsh_vals[$gi][$i],$wsh_vals[$gi][$i]);
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   485
				}
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   486
	        }
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   487
		} else {
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   488
			for (my($gi)=$#ush_vals; $gi>=0; $gi--) {
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   489
				for (my($i)=0; $i<@{$ush_vals[$gi]}; $i++) {
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   490
					&antsOut($ens_vals[$gi][$i],$LADCP{ENSEMBLE}[$ens_vals[$gi][$i]]->{ELAPSED_TIME}+$CTD{first_elapsed}-$opt_l,
4
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   491
							 $downcast,depthOfGI($gi),$ush_vals[$gi][$i],$vsh_vals[$gi][$i],$wsh_vals[$gi][$i]);
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   492
				}
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   493
	        }
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   494
	    }
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   495
	} # sub outDSseries
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   496
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   497
	#--------------------------------------------------------------------------------
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   498
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   499
@antsNewLayout = ('ens','elapsed','downcast','depth','u_z','v_z','w_z');
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   500
$commonParams = $antsCurParams;
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   501
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   502
&antsAddParams('ubin_start',$ubin_start,'ubin_end',$ubin_end,		# record processing params
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   503
			   'wbin_start',$wbin_start,'wbin_end',$wbin_end,
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   504
			   'shbin_start',$shbin_start,'shbin_end',$shbin_end,
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   505
			   'w_ref_bin',$w_ref_bin,'w_dif',$w_dif,
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   506
			   'wake_hd_dif',$wake_hd_dif,'wake_ang_min',$wake_ang_min,
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   507
			   'min_wake_w',$min_wake_w,'n_wake_bins',$n_wake_bins,
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   508
			   'e_max',$e_max,'min_cor',$min_cor,
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   509
			   'max_shdev',$max_shdev,'max_shdev_sum',$max_shdev_sum,
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   510
			   'water_depth',round($water_depth),'water_depth.sig',round($sig_water_depth),
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   511
			   'min_hab',round($min_hab),'PPI_editing_enabled',$PPI_editing_enabled,
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   512
			   'clip_margin',$clip_margin,'first_clip_bin',$first_clip_bin,
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   513
			   'Svbin_start',$Svbin_start,'Svbin_end',$Svbin_end,
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   514
			   'BT_bin_start',$BT_bin_start,'BT_bin_search_above',$BT_bin_search_above,
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   515
			   'BT_max_bin_spread',$BT_max_bin_spread,'BT_max_w_difference',$BT_max_w_difference,
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   516
);
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   517
if (defined($BT_min_depth)) {
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   518
	&antsAddParams('BT_min_depth',$BT_min_depth,'BT_max_depth',$BT_max_depth);
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   519
} else {
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   520
	&antsAddParams('BT_max_depth_error',$BT_max_depth_error);
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   521
}
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   522
$fullParams = $antsCurParams;
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   523
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   524
$LADCP_start = 1 if ($LADCP_start == 0);							# ensure that there is previous ensemble
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   525
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   526
print(STDERR "\n\tdowncast...") if ($opt_d);
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   527
edit_velocity($LADCP_start,$LADCP_bottom);							# downcast
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   528
calc_shear($LADCP_start,$LADCP_bottom,$SHEAR_PREGRID_DZ,0);			# pre-grid shear @SHEAR_PREGRID_DZm resolution
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   529
calc_shear($LADCP_start,$LADCP_bottom,$GRID_DZ,1);					# calculate final gridded shear profile
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   530
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   531
@dc_sh_n = @sh_n;													# save downcast results
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   532
@dc_ush_mu = @ush_mu; @dc_ush_sig = @ush_sig;
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   533
@dc_vsh_mu = @vsh_mu; @dc_vsh_sig = @vsh_sig;
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   534
@dc_wsh_mu = @wsh_mu; @dc_wsh_sig = @wsh_sig;
7
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   535
@dc_esh_mu = @esh_mu;
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   536
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   537
print(STDERR "\n\tupcast...") if ($opt_d);
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   538
edit_velocity($LADCP_end,$LADCP_bottom);							# upcast
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   539
calc_shear($LADCP_end,$LADCP_bottom,$SHEAR_PREGRID_DZ,0);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   540
calc_shear($LADCP_end,$LADCP_bottom,$GRID_DZ,1);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   541
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   542
@uc_sh_n = @sh_n;													# save upcast results
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   543
@uc_ush_mu = @ush_mu; @uc_ush_sig = @ush_sig;
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   544
@uc_vsh_mu = @vsh_mu; @uc_vsh_sig = @vsh_sig;
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   545
@uc_wsh_mu = @wsh_mu; @uc_wsh_sig = @wsh_sig;
7
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   546
@uc_esh_mu = @esh_mu;
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   547
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   548
print(STDERR "\n\tcombined...") if ($opt_d);
7
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   549
my($nsh) = (@dc_ush_mu > @uc_ush_mu) ? scalar(@dc_ush_mu) : scalar(@uc_ush_mu);
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   550
for (my($gi)=0; $gi<$nsh; $gi++) {
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   551
	if (($gi<@dc_ush_mu&&$dc_sh_n[$gi]>0) && ($gi<@uc_ush_mu&&$uc_sh_n[$gi]>0)) {
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   552
		$sh_n[$gi] = $dc_sh_n[$gi] + $uc_sh_n[$gi];
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   553
		$ush_mu[$gi] = ($dc_sh_n[$gi]*$dc_ush_mu[$gi] + $uc_sh_n[$gi]*$uc_ush_mu[$gi]) / $sh_n[$gi];
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   554
		$vsh_mu[$gi] = ($dc_sh_n[$gi]*$dc_vsh_mu[$gi] + $uc_sh_n[$gi]*$uc_vsh_mu[$gi]) / $sh_n[$gi];
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   555
		$wsh_mu[$gi] = ($dc_sh_n[$gi]*$dc_wsh_mu[$gi] + $uc_sh_n[$gi]*$uc_wsh_mu[$gi]) / $sh_n[$gi];
7
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   556
		$esh_mu[$gi] = ($dc_sh_n[$gi]*$dc_esh_mu[$gi] + $uc_sh_n[$gi]*$uc_esh_mu[$gi]) / $sh_n[$gi];
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   557
		$ush_sig[$gi] = sqrt(($dc_sh_n[$gi]*$dc_ush_sig[$gi]**2 + $uc_sh_n[$gi]*$uc_ush_sig[$gi]**2) / $sh_n[$gi]);
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   558
		$vsh_sig[$gi] = sqrt(($dc_sh_n[$gi]*$dc_vsh_sig[$gi]**2 + $uc_sh_n[$gi]*$uc_vsh_sig[$gi]**2) / $sh_n[$gi]);
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   559
		$wsh_sig[$gi] = sqrt(($dc_sh_n[$gi]*$dc_wsh_sig[$gi]**2 + $uc_sh_n[$gi]*$uc_wsh_sig[$gi]**2) / $sh_n[$gi]);
7
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   560
	} elsif ($gi < @dc_ush_mu && $dc_sh_n[$gi] > 0) {
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   561
		$sh_n[$gi] = $dc_sh_n[$gi];
7
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   562
		$ush_mu[$gi]  = $dc_ush_mu[$gi];  $vsh_mu[$gi]  = $dc_vsh_mu[$gi];  $wsh_mu[$gi]  = $dc_wsh_mu[$gi];  $esh_mu[$gi]  = $dc_esh_mu[$gi];
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   563
		$ush_sig[$gi] = $dc_ush_sig[$gi]; $vsh_sig[$gi] = $dc_vsh_sig[$gi]; $wsh_sig[$gi] = $dc_wsh_sig[$gi]; 
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   564
	} elsif ($gi < @uc_ush_mu && $uc_sh_n[$gi] > 0) {
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   565
		$sh_n[$gi] = $uc_sh_n[$gi];
7
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   566
		$ush_mu[$gi]  = $uc_ush_mu[$gi];  $vsh_mu[$gi]  = $uc_vsh_mu[$gi];  $wsh_mu[$gi]  = $uc_wsh_mu[$gi];  $esh_mu[$gi]  = $uc_esh_mu[$gi];
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   567
		$ush_sig[$gi] = $uc_ush_sig[$gi]; $vsh_sig[$gi] = $uc_vsh_sig[$gi]; $wsh_sig[$gi] = $uc_wsh_sig[$gi]; 
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   568
	} else {
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   569
		$sh_n[$gi] = 0;
7
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   570
		$ush_mu[$gi]  = $vsh_mu[$gi]  = $wsh_mu[$gi]  = $esh_mu[$gi]  = nan;
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   571
		$ush_sig[$gi] = $vsh_sig[$gi] = $wsh_sig[$gi] = nan;
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   572
	}
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   573
}
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   574
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   575
print(STDERR "\n");
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   576
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   577
#----------------------------------------------------------------------
1
54222c82435f after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
   578
# Step 9: Get bottom track profile
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   579
#----------------------------------------------------------------------
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   580
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   581
if ($LADCP{ENSEMBLE}[$LADCP_start]->{XDUCER_FACING_DOWN}) {
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   582
	print(STDERR "Getting BT profile...");
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   583
	getBTprof($LADCP_start,$LADCP_end);
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   584
	print(STDERR "\n");
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   585
}
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   586
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   587
#----------------------------------------------------------------------
4
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   588
# Step 10: Write Output Profiles if requested
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   589
#----------------------------------------------------------------------
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   590
4
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   591
if (defined($opt_p)) {
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   592
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   593
	print(STDERR "Writing shear profiles...");
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   594
	
7
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   595
	@antsNewLayout = ('depth','dc_elapsed','dc_nsamp','dc_u_z','dc_u_z.sig','dc_v_z','dc_v_z.sig','dc_w_z','dc_w_z.sig',
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   596
							  'uc_elapsed','uc_nsamp','uc_u_z','uc_u_z.sig','uc_v_z','uc_v_z.sig','uc_w_z','uc_w_z.sig',
10
196a179304ee 1.0beta
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 9
diff changeset
   597
							  'elapsed','nsamp','u_z','u_z.sig','v_z','v_z.sig','w_z','w_z.sig','Sv','Sv.nsamp');
4
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   598
							  
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   599
	&antsOut('EOF');
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   600
    close(STDOUT);
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   601
	open(STDOUT,">$opt_p") || croak("$opt_p: $!\n");
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   602
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   603
	$antsCurParams = $fullParams;
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   604
7
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   605
	for (my($gi)=0; $gi<$nsh; $gi++) {
4
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   606
		&antsOut(depthOfGI($gi),										# depth in center of bin
7
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   607
				 $dc_esh_mu[$gi],										# downcast
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   608
				 numberp($dc_sh_n[$gi])?$dc_sh_n[$gi]:0,
4
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   609
				 $dc_ush_mu[$gi],$dc_ush_sig[$gi],
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   610
				 $dc_vsh_mu[$gi],$dc_vsh_sig[$gi],
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   611
				 $dc_wsh_mu[$gi],$dc_wsh_sig[$gi],
7
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   612
				 $uc_esh_mu[$gi],										# upcast
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   613
				 numberp($uc_sh_n[$gi])?$uc_sh_n[$gi]:0,
4
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   614
				 $uc_ush_mu[$gi],$uc_ush_sig[$gi],
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   615
				 $uc_vsh_mu[$gi],$uc_vsh_sig[$gi],
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   616
				 $uc_wsh_mu[$gi],$uc_wsh_sig[$gi],
7
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 6
diff changeset
   617
				 $esh_mu[$gi],$sh_n[$gi],								# combined
4
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   618
				 $ush_mu[$gi],$ush_sig[$gi],
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   619
				 $vsh_mu[$gi],$vsh_sig[$gi],
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   620
				 $wsh_mu[$gi],$wsh_sig[$gi],
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   621
				 $nSv_prof[$gi]?$sSv_prof[$gi]/$nSv_prof[$gi]:nan,
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   622
				 $nSv_prof[$gi],
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   623
		);
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   624
	}
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   625
	
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   626
	print(STDERR "\n");
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 3
diff changeset
   627
} # if -p
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   628
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   629
#---------------------------------------
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   630
# Acoustic backscatter depth-time-series
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   631
#---------------------------------------
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   632
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   633
if (defined($opt_a)) {
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   634
	print(STDERR "Writing acoustic backscatter depth-time-series to <$opt_a>...");
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   635
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   636
	
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   637
	@antsNewLayout = ('ens','elapsed','CTD_depth','depth','bin','downcast',
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   638
					  'Sv_beam1','Sv_beam2','Sv_beam3','Sv_beam4','Sv.median');
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   639
	&antsOut('EOF');
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   640
    close(STDOUT);
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   641
	open(STDOUT,">$opt_a") || croak("$opt_a: $!\n");
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   642
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   643
	$antsCurParams = $commonParams;
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   644
	&antsAddParams('min_elapsed',$LADCP{ENSEMBLE}[$LADCP_start]->{ELAPSED_TIME}+$CTD{first_elapsed}-$opt_l,
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   645
				   'max_elapsed',$LADCP{ENSEMBLE}[$LADCP_end]->{ELAPSED_TIME}+$CTD{first_elapsed}-$opt_l,
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   646
				   'min_depth',$LADCP{ENSEMBLE}[$LADCP_top]->{XDUCER_FACING_UP} ?
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   647
	   					&depthOfBin($LADCP_top,$LADCP{N_BINS}-1) : $LADCP{ENSEMBLE}[$LADCP_top]->{DEPTH},
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   648
				   'max_depth',$LADCP{ENSEMBLE}[$LADCP_bottom]->{XDUCER_FACING_UP} ?
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   649
	   					$LADCP{ENSEMBLE}[$LADCP_bottom]->{DEPTH} : &depthOfBin($LADCP_bottom,$LADCP{N_BINS}-1)
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   650
	);
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   651
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   652
	for (my($ens)=$LADCP_start; $ens<=$LADCP_end; $ens++) {
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   653
		for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   654
			&antsOut($LADCP{ENSEMBLE}[$ens]->{NUMBER},
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   655
					 $LADCP{ENSEMBLE}[$ens]->{ELAPSED_TIME}+$CTD{first_elapsed}-$opt_l,
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   656
					 $LADCP{ENSEMBLE}[$ens]->{DEPTH},
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   657
					 &depthOfBin($ens,$bin),$bin+1,
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   658
					 ($ens <= $LADCP_bottom) ? 1 : 0,
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   659
					 @{$LADCP{ENSEMBLE}[$ens]->{SV}[$bin]},
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   660
					 median(@{$LADCP{ENSEMBLE}[$ens]->{SV}[$bin]})
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   661
			);
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   662
		}	 
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   663
	}
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   664
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   665
	print(STDERR "\n");
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   666
}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   667
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   668
#----------------------------------------------------------------------
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   669
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   670
if (defined($opt_t)) {
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   671
	print(STDERR "Writing time series to <$opt_t>...");
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   672
	
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   673
	@antsNewLayout = ('ens','elapsed','depth','CTD_w','LADCP_w');
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   674
	&antsOut('EOF');
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   675
	$antsCurParams = $commonParams;
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   676
	close(STDOUT);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   677
	open(STDOUT,">$opt_t") || croak("$opt_t: $!\n");
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   678
	
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   679
	for (my($ens)=$LADCP_start; $ens<=$LADCP_end; $ens++) {
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   680
		&antsOut($LADCP{ENSEMBLE}[$ens]->{NUMBER},
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   681
				 $LADCP{ENSEMBLE}[$ens]->{ELAPSED_TIME}+$CTD{first_elapsed}-$opt_l,
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   682
				 $LADCP{ENSEMBLE}[$ens]->{DEPTH},
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   683
				 $LADCP{ENSEMBLE}[$ens]->{CTD_W},
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   684
				 $LADCP{ENSEMBLE}[$ens]->{W});
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   685
	}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   686
	print(STDERR "\n");
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   687
}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   688
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   689
#----------------------------------------------------------------------
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   690
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   691
if (defined($opt_b)) {
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   692
	print(STDERR "Writing bottom-track data to <$opt_b>...");
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   693
	
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   694
	@antsNewLayout = ('depth','u','v','w','u.sig','v.sig','w.sig','nsamp');
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   695
	&antsOut('EOF');
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   696
	$antsCurParams = $commonParams;
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   697
	close(STDOUT);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   698
	open(STDOUT,">$opt_b") || croak("$opt_b: $!\n");
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   699
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   700
	my($skipped);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   701
	for (my($gi)=0; $gi<@BT_nsamp; $gi++) {
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   702
		$skipped = 1 if ($BT_nsamp[$gi] > 0);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   703
		next unless ($skipped);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   704
		&antsOut(depthOfGI($gi),$BTu[$gi],$BTv[$gi],$BTw[$gi],$BTu_sig[$gi],$BTv_sig[$gi],$BTw_sig[$gi],$BT_nsamp[$gi]);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   705
	}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   706
	print(STDERR "\n");
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   707
}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   708
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   709
#----------------------------------------------------------------------
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   710
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   711
if (defined($opt_f)) {
3
711dd29cb6dd post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 2
diff changeset
   712
	print(STDERR "Writing data flags to <$opt_f>...");
0
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   713
	
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   714
	@antsNewLayout = ('ens');
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   715
	for (my($i)=1; $i<=$LADCP{N_BINS}; $i++) {
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   716
		$antsNewLayout[$i] = "bin$i";
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   717
	}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   718
	&antsOut('EOF');
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   719
	$antsCurParams = $commonParams;
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   720
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   721
	close(STDOUT);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   722
	open(STDOUT,">$opt_f") || croak("$opt_f: $!\n");
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   723
	
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   724
	&antsPrintHeaders(STDOUT,@antsNewLayout);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   725
	for (my($ens)=$LADCP_start; $ens<=$LADCP_end; $ens++) {
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   726
		printf('%4d  ',$LADCP{ENSEMBLE}[$ens]->{NUMBER});
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   727
		for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   728
			printf("%02x ",$edit_flags[$ens][$bin]);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   729
		}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   730
		print($opt_R);
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   731
	}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   732
	
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   733
	print(STDERR "\n");
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   734
}
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   735
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   736
&antsExit();
de00d0f32431 initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   737