LADCP_w
author A.M. Thurnherr <athurnherr@yahoo.com>
Sun, 02 Dec 2012 10:55:46 +0000
changeset 11 9e5eba6992f7
parent 10 7e76fdef8953
child 12 2adcd220b9b4
permissions -rwxr-xr-x
.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     1
#!/usr/bin/perl
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     2
#======================================================================
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     3
#                    L A D C P _ W 
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     4
#                    doc: Fri Dec 17 18:11:13 2010
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
     5
#                    dlm: Wed Oct 17 12:03:12 2012
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     6
#                    (c) 2010 A.M. Thurnherr
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
     7
#                    uE-Info: 121 63 NIL 0 0 72 2 2 4 NIL ofnI
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     8
#======================================================================
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     9
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    10
# TODO:
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
    11
#	  detection so that editing stats make sense
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    12
#	- own seabed detection (P403)
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    13
#	- make upcast-flag valid for yoyo casts
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    14
#	- make diagnostic output 3-beam field work for Earth coordinates
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    15
#	- remove water-depth from BT code, which is not really used and a bit of an outlier
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    16
#	  because mean and stddev are used instead of median/mad
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
    17
#	- read assumed ADCP soundspeed from data file, instead of assuming 1500m/s
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
    18
#	? use instrument tilt in sidelobe editing?
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    19
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    20
$antsSummary = 'calculate vertical velocities from LADCP & CTD time series';
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    21
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    22
# HISTORY:
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    23
#	Dec 17, 2010: - created from [mergeCTD+LADCP]
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    24
#	Dec 18, 2010: - made to work
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    25
#	Dec 19, 2010: - improved considerably
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    26
#	Dec 20, 2010: - onward
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    27
#				  - BUG: depth-binning was off by 1 bin?!
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    28
#				  - added binning correction for instrument tilt
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    29
#	Dec 21, 2010: - added -h (seafloor depth)
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    30
#	Dec 22, 2010: - BUG: had not applied soundspeed-correction to w
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    31
#				  - debugged opt_d
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    32
#	Dec 23, 2010: - continued implementation of soundspeed corrections
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    33
#	Dec 24, 2010: - added winch_w, wave_w
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    34
#				  - removed beampair velocities from code
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    35
#	Dec 25, 2010: - adapted for surface-wave correction in terms of acceleration (CTD_w_t)
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    36
#				  - removed elapsed_mismatch
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    37
#				  - removed winch_w, wave_w
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    38
#	Dec 26, 2010: - made -p output layout independent of -x to avoid Makefile problems
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    39
#	Dec 30, 2010: - cleaned up some
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    40
#				  - folded-in backscatter calculation from shear method
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    41
#				  - folded-in BT calculation from shear method
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    42
#	Dec 31, 2010: - added weighted mean w profile to output
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    43
#	Jan  2, 2010: - BUG: BT_w.mad could bomb with division by 0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    44
#				  - BUG: division by zero if no valid data
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    45
#	Jan  5, 2010: - adapted to allow for gaps in CTD time series
1
ee10850f757d pre IWISE
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
    46
#	Feb 16, 2011: - cosmetics
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    47
#	Jun 22, 2011: - cosmetics
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    48
#	Jun 23, 2011: - disabled error on large rms reflr w
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    49
#				  - added -l
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    50
#				  - removed CTD headers from output
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    51
#	Jun 26, 2011: - added -u
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    52
#				  - changed package correction from acceleration to velocity, because of
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    53
#					Stan's Antarctic data set where accelerations are zero but package effects are
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    54
#					there
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    55
#	Jul  2, 2011: - increased tilt default to 15 degrees
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    56
#	Jul  3, 2011: - replaced old package-velocity correction -x code by new beamvel correction
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    57
#				  - removed -p
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    58
#				  - replaced -d by residual (diagnostics) output
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    59
#	Jul  4, 2011: - saved a snapshot in [Jul_04_2011]
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    60
#				  - removed output of binned profile (but not calculation code, which is required for residual)
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    61
#				  - BUG: firstGoodEns or lastGoodEns could end up in a reflr_w gap when valid LADCP data begin
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    62
#						 or end with CTD in water
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    63
#				  - moved rarely used option -s to -k
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    64
#				  - added -s)kip <ens> option
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    65
#				  - had to very very slightly relax an assertion (by 1e-10 seconds...)
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
    66
#	Aug  3, 2011: - added -z)ap to truncate range, based on Stan's 2009 data set (017-019 most clearly)
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
    67
#				    obs that final 2 velocities are outliers; could be due to color bar, should check with
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
    68
#					residuals
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
    69
#	Sep 22, 2011: - removed (commented out) CTD acceleration
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
    70
#				  - added basename to Parameter File Matching
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
    71
#	Sep 23, 2011: - cosmetics (lots)
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
    72
#				  - added -d)
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
    73
#	Oct  6, 2011: - removed old commented-out code (CTD acceleration & old -x)
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
    74
#				  - renamed time-series field names
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
    75
#				  - added uncorrected reflr w to time-series output
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
    76
#	Oct 10, 2011: - BUG: LADCP_w in .tds output had not been soundspeed corrected
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
    77
#				  - removed -x
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
    78
#				  - added "false-positives" editing filter
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
    79
#	Oct 11, 2011: - adapted to the new parameter file, removing a few options
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
    80
#	Oct 12, 2011: - added surface-layer editing
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
    81
#				  - made %min/max_depth/elapsed more accurate
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
    82
#	Oct 13, 2011: - fiddled
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
    83
#	Oct 14, 2011: - renamed .prof fields from .N to .nsamp
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
    84
#				  - added %output_basename
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
    85
#				  - removed all ">" from open to allow use in pipelines
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
    86
#				  - made <run-label> argument optional
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
    87
#				  - replaced stdout output by $w_out
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
    88
#				  - renamed _out to out_; output_basename to out_basename
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
    89
#	Oct 15, 2011: - added editWOutliers()
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
    90
#				  - added step to remove single-ping noise
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    91
#	Oct 16, 2011: - BUG: ensemble and bin numbers in output files were off by 1
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    92
#	Oct 17, 2011: - added default run label
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    93
#				  - added out_BR
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    94
#				  - BUG: closed STDOUT caused problems with tee in plotting scripts
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    95
#				  - added %run_label
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    96
#				  - added PostProcess.sh
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    97
#	Oct 18, 2011: - BUG: %{min,max}_ens used ensemble indices, rather than numbers
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    98
#				  - disabled false-positives editing (removes too much good data on 2011_IWISE)
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    99
#	Oct 19, 2011: - BUG: time-series output included ensembles without valid w
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   100
#				  - increased post-process sleep time to 30s
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   101
#				  - added corr, Sv and echo_amplitude as new fields to w output
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   102
#	Oct 20, 2011: - added editFarBins()
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   103
#				  - added downcast flag to time-series output
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   104
#				  - added ensemble number to LADCP-time-series output
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   105
#	Oct 21, 2011: - BUG: Sv code was not enabled for uplooker data
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   106
#	Oct 24, 2011: - added code to copy %lat/%lon from CTD data
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   107
#				  - added %ADCP_freuquency, %ADCP_blanking_distance
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   108
#				  - %LADCP_bin_length => %ADCP_bin_length
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   109
#	Oct 26, 2011: - added $first_guess_timelag
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   110
#	Oct 27, 2011: - added w12, w34, ww (pitch/roll-weighted average) to full output
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   111
#				  - removed ww because it apparently does not improve the solutions
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   112
#				  - moved editTilt() to after time-series calculation to allow
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   113
#				    time matching to work even with strict tilt limit
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   114
#				  - added correctAttitude()
10
7e76fdef8953 version prior to carrying out separate dc-/uc- time lagging
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 6
diff changeset
   115
#	May 22, 2012: - adapted to ANTS V5
7e76fdef8953 version prior to carrying out separate dc-/uc- time lagging
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 6
diff changeset
   116
#	Oct 15, 2012: - added $edit_data_hook
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   117
#--- hg commit
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   118
#				  - separated dc/uc time lagging
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   119
#				  - removed support for TLhist
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   120
#	Oct 16, 2012: - added support for dc/uc only solutions
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   121
#	Oct 17, 2012: - renamed $edit_data_hook to $post_merge_hook
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   122
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   123
# CTD REQUIREMENTS
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   124
#	- elapsed		elapsed seconds; see note below
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   125
#	- depth
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   126
#	- ss			sound speed
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   127
#	- w				ddepth/dt
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   128
#	- temp			OPTIONAL; used for backscatter calculation (i.e. not very important)
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   129
#	- %lat/%lon		OPTIONAL
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   130
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   131
# NUMERICAL OPTIONS
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   132
#	- the first option in the list cannot be numerical!
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   133
#	- if need be, use -v 1 as a dummy option
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   134
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   135
# ELAPSED TIMES
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   136
#	- there are 2 different elapsed times used in this program:
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   137
#		1) elapsed based on firstgoodens in the LADCP time series
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   138
#		2) CTD elapsed time
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   139
#	- CTD elapsed time does not have to start with zero!
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   140
#	- do not use the Seabird elapsed field, which is only reported to
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   141
#	  3 significant digits, causing significant jitter in dt; however,
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   142
#	  at least up to 2010 Seabird simply calculates elapsed time by 
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   143
#	  assuming a 24Hz sampling rate and no record drop; therefore,
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   144
#	  it is best to calculate elapsed time as %RECNO/24
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   145
#	- the elapsed field of the output is the elapsed time from the CTD
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   146
#	  file; this is required in order to be able to compare the times
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   147
#	  from the uplooker and downlooker-derived vertical velocity
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   148
#	  profiles
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   149
#	- the .TL files use the LADCP elapsed time in output; as a result,
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   150
#	  the DL/UL .TL files have different time axes!
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   151
#	- as a result, a profile only starts with elapsed==0 if the CTD
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   152
#	  is turned on when the LADCP is already in the water
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   153
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   154
# OUTPUT NOTES
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   155
#	- residuals are calculated with respect to down-/upcast medians in binned profiles
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   156
#	- equivalence, assuming -o 10:
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   157
#		1) 004DL.prof dc_w depth
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   158
#		2) bindata -Sdowncast:1 -Fw.median,depth -n 20 depth 10 004DL.w
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   159
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   160
# VELOCITY AMBIGUITY ERRORS
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   161
#	- quite extensive tests with DIMES US2 station 146, which has a lot of
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   162
#	  ambiguity velocity errors, reveal that -m 1 catches those errors
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   163
#	  quite nicely
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   164
#	- even when the errors are not filtered with -m 1, they do not
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   165
#	  affect the w profiles, as long as the median bin values are used
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   166
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   167
($WCALC) 	  = ($0                =~ m{^(.*)/[^/]*$});
10
7e76fdef8953 version prior to carrying out separate dc-/uc- time lagging
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 6
diff changeset
   168
($ANTS) 	  = (`which ANTSlib`   =~ m{^(.*)/[^/]*$});
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   169
($PERL_TOOLS) = (`which mkProfile` =~ m{^(.*)/[^/]*$});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   170
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   171
require "$ANTS/ants.pl";
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   172
require "$ANTS/libstats.pl";
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   173
require "$WCALC/edit_data.pl";
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   174
require "$WCALC/time_series.pl";
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   175
require "$WCALC/time_lag.pl";
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   176
require "$WCALC/find_seabed.pl";
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   177
require "$WCALC/svel_corrections.pl";
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   178
require "$WCALC/acoustic_backscatter.pl";
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   179
require "$WCALC/bottom_tracking.pl";
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   180
require "$PERL_TOOLS/RDI_BB_Read.pl";
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   181
require "$PERL_TOOLS/RDI_Coords.pl";
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   182
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   183
use IO::Handle;
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   184
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   185
my($TINY) = 1e-16;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   186
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   187
#------
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   188
# Usage
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   189
#------
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   190
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   191
@ARGS = @ARGV;														# save opts & arguments
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   192
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   193
$antsParseHeader = 0;
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   194
&antsUsage('3:4a:b:c:e:g:h:i:k:m:n:o:qs:t:uv:w:x:',1,
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   195
	'[-v)erbosity <level[1]>]',
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   196
	'[-q)uick (no single-ping denoising)]',
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   197
    '[require -4)-beam solutions]',
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   198
	'[-c)orrelation <min[70]>] [-t)ilt <max[10deg]> [-e)rr-vel <max[0.1m/s]>]',
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   199
	'[-h water <depth>]',
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   200
	'[max LADCP time-series -g)ap <length[60s]>]',
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   201
	'[-m)ax vertical <velocity[1m/s]>',
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   202
	'[-a)djust CTD depth <by[0m]>]',
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   203
	'[-i)nitial CTD time offset <guestimate> [-u)se as final]]',
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   204
	'[calculate -n) <lags,lags[10,100]>] [lag -w)indow <sz,sz[240s,20s]>]',
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   205
	'[require top-3) lags to account for <frac[0.6]> of all]',
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   206
	'[valid LADCP -b)ins <bin[2],bin[*]>',
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   207
	'[-o)utput bin <resolution[10m]>] [-k) require <min[20]> samples]',
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   208
	'[e-x)ecute <perl-expr>]',
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   209
	'<station-id> [run-label]');
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   210
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   211
&antsUsageError() if ($opt_u && !defined($opt_i));
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   212
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   213
&antsCardOpt(\$opt_s,0);											# skip # initial ensembles
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   214
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   215
$STN = &antsCardArg();												# station id
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   216
if (@ARGV) {														# run label
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   217
	$RUN = $ARGV[0];
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   218
	shift;
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   219
} else {
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   220
	$RUN = 'default';
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   221
}
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   222
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   223
#-----------------------------
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   224
# Handle Processing Parameters
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   225
#-----------------------------
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   226
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   227
require "$WCALC/defaults.pl";										# load default/option parameters
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   228
require "$processing_param_file";									# load processing parameters
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   229
eval($opt_x) if defined($opt_x);									# eval cmd-line expression to override anything
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   230
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   231
croak("$0: \$out_basename undefined\n")								# all plotting routines use this
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   232
	unless defined($out_basename);
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   233
&antsAddParams('out_basename',$out_basename);
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   234
&antsAddParams('run_label',$RUN);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   235
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   236
$out_w 	    	= ">$out_w" 		 unless ($out_w =~ /^$|^\s*\|/);	# make sure O_CREAT is set unless it's a pipe
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   237
$out_BR 	    = ">$out_BR" 		 unless ($out_BR =~ /^$|^\s*\|/);
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   238
$out_TL 	    = ">$out_TL" 		 unless ($out_TL =~ /^$|^\s*\|/);
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   239
$out_LADCPtis  	= ">$out_LADCPtis"   unless ($out_LADCPtis =~ /^$|^\s*\|/);
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   240
$out_profile    = ">$out_profile" 	 unless ($out_profile =~ /^$|^\s*\|/);
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   241
$out_timeseries = ">$out_timeseries" unless ($out_timeseries =~ /^$|^\s*\|/);
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   242
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   243
#----------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   244
# Screen Logging
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   245
#	- warning levels:
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   246
#		0 probably unimportant, e.g. nonsensical parameters that probably won't affect solution
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   247
#		1 may be somewhat important
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   248
#		2 important
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   249
#----------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   250
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   251
open(LOGF,">$out_log") || croak("$out_log: $!\n")
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   252
	if defined($out_log);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   253
LOGF->autoflush(1);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   254
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   255
sub progress(@)
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   256
{
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   257
	printf(LOGF @_) if defined($out_log);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   258
	printf(STDERR @_) if ($verbosity_level > 1);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   259
}
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   260
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   261
sub info(@)
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   262
{
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   263
	printf(LOGF "\t",@_) if defined($out_log);
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   264
	print(STDERR ($verbosity_level > 1) ? "\t" : "$LADCP_file: ");
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   265
	printf(STDERR @_)  if ($verbosity_level > 0);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   266
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   267
	
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   268
sub warning(@)
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   269
{
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   270
	my($lvl,@msg) = @_;
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   271
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   272
	if (defined($out_log)) {
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   273
		print(LOGF "\nWARNING (level $lvl): ");
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   274
		printf(LOGF @msg);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   275
		print(LOGF "\n");
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   276
	}
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   277
	return if ($verbosity_level == 0);
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   278
	print(STDERR "\n") if ($verbosity_level > 1);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   279
	print(STDERR "WARNING (level $lvl): ");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   280
	printf(STDERR @msg);
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   281
	print(STDERR "\n") if ($verbosity_level > 1);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   282
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   283
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   284
sub debugmsg(@)
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   285
{ printf(STDERR @_) if ($verbosity_level > 2); }
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   286
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   287
#----------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   288
# Read LADCP data
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   289
#----------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   290
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   291
progress("Reading LADCP data from <$LADCP_file>...\n");
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   292
readData($LADCP_file,\%LADCP);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   293
progress("\t%d ensembles\n",scalar(@{$LADCP{ENSEMBLE}}));
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   294
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   295
croak("$LADCP_file: not enough LADCP bins ($LADCP{N_BINS}) for choice of -r\n")
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   296
	unless ($LADCP{N_BINS} >= $refLr_lastBin);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   297
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   298
croak("$0: first reference-layer bin outside valid range\n")
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   299
	unless ($refLr_firstBin>=1 && $refLr_firstBin<=$LADCP{N_BINS});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   300
croak("$0: last reference-layer bin outside valid range\n")
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   301
	unless ($refLr_lastBin>=1 && $refLr_lastBin<=$LADCP{N_BINS});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   302
croak("$0: first reference-layer bin > last reference-layer bin\n")
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   303
	unless ($refLr_firstBin <= $refLr_lastBin);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   304
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   305
$LADCP_lastBin = $LADCP{N_BINS}-1
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   306
	if ($LADCP_lastBin eq '*');
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   307
croak("$0: first valid LADCP bin outside valid range\n")
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   308
	unless ($LADCP_firstBin>=1 && $LADCP_firstBin<=$LADCP{N_BINS});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   309
croak("$0: last valid LADCP bin outside valid range\n")
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   310
	unless ($LADCP_lastBin>=1 && $LADCP_lastBin<=$LADCP{N_BINS});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   311
croak("$0: first valid LADCP bin > last valid LADCP bin\n")
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   312
	unless ($LADCP_firstBin <= $LADCP_lastBin);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   313
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   314
warning(0,"first reference-layer bin < first valid LADCP bin\n")
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   315
	unless ($refLr_firstBin >= $LADCP_firstBin);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   316
warning(0,"last reference-layer bin > last valid LADCP bin\n")
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   317
	unless ($refLr_lastBin <= $LADCP_lastBin);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   318
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   319
warning(1,"if at all, bin 1 should not be used for short blank-after-transmit values\n")
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   320
	if ($LADCP{BLANKING_DISTANCE}<$LADCP{BIN_LENGTH} && $refLr_firstBin==1);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   321
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   322
&antsAddParams('ADCP_bin_length',$LADCP{BIN_LENGTH},
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   323
			   'ADCP_frequency',$LADCP{BEAM_FREQUENCY},
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   324
			   'ADCP_blanking_distance',$LADCP{BLANKING_DISTANCE});
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   325
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   326
#------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   327
# Edit beam-velocity data
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   328
#	1) correlation threshold
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   329
#------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   330
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   331
if ($LADCP{BEAM_COORDINATES}) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   332
	progress("Editing beam-velocity data...\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   333
	$nvv = $cte = 0;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   334
	for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   335
		correctAttitude($ens,$pitch_bias,$roll_bias,$heading_bias);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   336
		$nvv += countValidBeamVels($ens);
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   337
		$cte += editCorr($ens,$min_correlation);
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   338
#		$pte += editTilt($ens,$max_tilt);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   339
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   340
	croak("$LADCP_file: no valid data\n") unless ($nvv > 0);
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   341
	progress("\tcorrelation threshold (-c %d counts): %d velocites removed (%d%% of total)\n",$min_correlation,$cte,round(100*$cte/$nvv));
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   342
#	progress("\tattitude threshold (-t %d deg): %d velocites removed (%d%% of total)\n",$max_tilt,$pte,round(100*$pte/$nvv));
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   343
} else {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   344
	progress("Editing velocity data...\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   345
	$nvv = $cte = 0;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   346
	for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   347
		$nvv += countValidBeamVels($ens);
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   348
		$cte += editCorr_Earthcoords($ens,$min_correlation);
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   349
#		$pte += editTilt($ens,$max_tilt);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   350
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   351
	croak("$LADCP_file: no valid data\n") unless ($nvv > 0);
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   352
	progress("\tcorrelation threshold (-c %d counts): %d velocites removed (%d%% of total)\n",$min_correlation,$cte,round(100*$cte/$nvv));
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   353
#	progress("\tattitude threshold (-t %d deg): %d velocites removed (%d%% of total)\n",$max_tilt,$pte,round(100*$pte/$nvv));
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   354
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   355
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   356
#-------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   357
# Calculate earth velocities
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   358
#	- this is done for all bins (not just valid ones), to allow
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   359
#	  useless possibility that invalid bins are used for reflr calcs
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   360
#	- also calculate separate beam-pair velocities
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   361
#	- the UNEDITED velocities are saved for the BT calculations
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   362
#	  (W is required, U & V are only used for stats that have not
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   363
#	  been very useful so far)
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   364
#-------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   365
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   366
if ($LADCP{BEAM_COORDINATES}) {
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   367
	my($dummy);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   368
	progress("Calculating earth-coordinate velocities...\n");
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   369
	progress("\tdiscarding velocities from beam $discard_velocities_from_beam\n")
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   370
		if ($discard_velocities_from_beam);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   371
	$nvw = 0;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   372
	for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   373
		for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   374
			undef($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$discard_velocities_from_beam-1])
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   375
				if ($discard_velocities_from_beam);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   376
			($LADCP{ENSEMBLE}[$ens]->{U}[$bin],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   377
			 $LADCP{ENSEMBLE}[$ens]->{V}[$bin],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   378
			 $LADCP{ENSEMBLE}[$ens]->{W}[$bin],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   379
			 $LADCP{ENSEMBLE}[$ens]->{ERRVEL}[$bin]) =
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   380
				velInstrumentToEarth(\%LADCP,$ens,
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   381
					velBeamToInstrument(\%LADCP,
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   382
										@{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]}));
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   383
			if (defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin])) {
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   384
				$per_bin_nsamp[$bin]++;
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   385
				$nvw++;
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   386
			}
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   387
			$LADCP{ENSEMBLE}[$ens]->{GIMBAL_PITCH} =
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   388
			 	gimbal_pitch($LADCP{ENSEMBLE}[$ens]->{PITCH},$LADCP{ENSEMBLE}[$ens]->{ROLL});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   389
			$LADCP{ENSEMBLE}[$ens]->{U_UNEDITED}[$bin] = $LADCP{ENSEMBLE}[$ens]->{U}[$bin];
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   390
			$LADCP{ENSEMBLE}[$ens]->{V_UNEDITED}[$bin] = $LADCP{ENSEMBLE}[$ens]->{V}[$bin];
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   391
			$LADCP{ENSEMBLE}[$ens]->{W_UNEDITED}[$bin] = $LADCP{ENSEMBLE}[$ens]->{W}[$bin];
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   392
			
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   393
			($dummy,$LADCP{ENSEMBLE}[$ens]->{W12}[$bin],
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   394
			 $dummy,$LADCP{ENSEMBLE}[$ens]->{W34}[$bin]) =
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   395
			 	velBeamToBPEarth(\%LADCP,$ens,@{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]});
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   396
		}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   397
	}
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   398
	progress("\t$nvw valid velocities in bins $LADCP_firstBin-$LADCP_lastBin\n");
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   399
	progress("\t3-beam solutions : $RDI_Coords::threeBeam_1 " .
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   400
								  "$RDI_Coords::threeBeam_2 " .
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   401
								  "$RDI_Coords::threeBeam_3 " .
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   402
								  "$RDI_Coords::threeBeam_4\n")
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   403
	    unless ($opt_4);
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   404
} else { # Earth Coordinates
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   405
	progress("Counting valid vertical velocities...\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   406
	$nvw = 0;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   407
	for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   408
		for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   409
			($LADCP{ENSEMBLE}[$ens]->{U}[$bin],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   410
			 $LADCP{ENSEMBLE}[$ens]->{V}[$bin],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   411
			 $LADCP{ENSEMBLE}[$ens]->{W}[$bin],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   412
			 $LADCP{ENSEMBLE}[$ens]->{ERRVEL}[$bin]) = @{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]};
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   413
			if (defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin])) {
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   414
				$per_bin_nsamp[$bin]++;
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   415
				$nvw++;
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   416
			}
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   417
			$LADCP{ENSEMBLE}[$ens]->{U_UNEDITED}[$bin] = $LADCP{ENSEMBLE}[$ens]->{U}[$bin];
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   418
			$LADCP{ENSEMBLE}[$ens]->{V_UNEDITED}[$bin] = $LADCP{ENSEMBLE}[$ens]->{V}[$bin];
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   419
			$LADCP{ENSEMBLE}[$ens]->{W_UNEDITED}[$bin] = $LADCP{ENSEMBLE}[$ens]->{W}[$bin];
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   420
		}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   421
	}
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   422
	progress("\t$nvw valid velocities in bins $LADCP_firstBin-$LADCP_lastBin\n");
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   423
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   424
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   425
croak("$LADCP_file: insufficient valid velocities\n") unless ($nvw > 1000);
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   426
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   427
#----------------------------------------------
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   428
# STEP: Edit earth-coordinate -velocity data
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   429
#	1) error-velocity threshold
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   430
#	2) vertical-velocity outliers
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   431
#	3) truncate range by deleting farthest valid velocities (disbled by default)
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   432
#----------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   433
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   434
progress("Editing earth-coordinate velocity data...\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   435
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   436
$evrm = $trrm = $worm = 0;
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   437
for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   438
	$evrm += editErrVel($ens,$max_allowed_errvel);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   439
	$worm += editWOutliers($ens,$per_ens_outliers_mad_limit);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   440
	$trrm += editTruncRange($ens,$truncate_farthest_valid_bins) if ($truncate_farthest_valid_bins > 0);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   441
}
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   442
progress("\terror-velocity threshold (-e %.1f m/s): %d velocites removed (%d%% of total in bins $LADCP_firstBin-$LADCP_lastBin)\n",
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   443
	$max_allowed_errvel,$evrm,round(100*$evrm/$nvw));
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   444
progress("\tvertical-velocity outliers ($per_ens_outliers_mad_limit x mad): %d velocites removed (%d%% of total in bins $LADCP_firstBin-$LADCP_lastBin)\n",
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   445
	$worm,round(100*$worm/$nvw));
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   446
progress("\trange truncation (-z %d bins): %d velocites removed (%d%% of total in bins $LADCP_firstBin-$LADCP_lastBin)\n",
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   447
	$truncate_farthest_valid_bins,$trrm,round(100*$trrm/$nvw))
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   448
		if ($truncate_farthest_valid_bins > 0);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   449
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   450
#----------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   451
# Calculate LADCP time series
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   452
#----------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   453
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   454
progress("Calculating LADCP time-series...\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   455
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   456
($firstGoodEns,$lastGoodEns,$LADCP_atbottom,$LADCP_w_gap_time) =
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   457
	calcLADCPts(\%LADCP,$opt_s,$refLr_firstBin,$refLr_lastBin,$max_LADCP_reflr_vel_gap);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   458
croak("$LADCP_file: no good ensembles\n")
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   459
	unless defined($firstGoodEns) && ($lastGoodEns-$firstGoodEns > 0);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   460
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   461
my($cast_duration) = $LADCP{ENSEMBLE}[$lastGoodEns]->{ELAPSED} -
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   462
				     $LADCP{ENSEMBLE}[$firstGoodEns]->{ELAPSED};
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   463
croak("$0: implausibly short cast ($cast_duration seconds)\n")
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   464
	unless ($cast_duration > 600);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   465
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   466
$LADCP{MEAN_DT} = $cast_duration / ($lastGoodEns-$firstGoodEns-1);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   467
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   468
progress("\tStart of cast     : %s (#%5d)\n",
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   469
					$LADCP{ENSEMBLE}[$firstGoodEns]->{TIME},
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   470
					$LADCP{ENSEMBLE}[$firstGoodEns]->{NUMBER});
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   471
progress("\tBottom of cast    : %s (#%5d) @ dz=%6dm\n",
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   472
					$LADCP{ENSEMBLE}[$LADCP_atbottom]->{TIME},
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   473
					$LADCP{ENSEMBLE}[$LADCP_atbottom]->{NUMBER},
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   474
					$LADCP{ENSEMBLE}[$LADCP_atbottom]->{DEPTH});
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   475
progress("\tEnd of cast       : %s (#%5d) @ dz=%6dm\n",
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   476
					$LADCP{ENSEMBLE}[$lastGoodEns]->{TIME},
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   477
					$LADCP{ENSEMBLE}[$lastGoodEns]->{NUMBER},
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   478
					$LADCP{ENSEMBLE}[$lastGoodEns]->{DEPTH});
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   479
progress("\tCast duration     : %.1f hours (pinging for %.1f hours)\n",
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   480
					$cast_duration / 3600,
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   481
					($LADCP{ENSEMBLE}[$#{$LADCP{ENSEMBLE}}]->{UNIX_TIME} -
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   482
						$LADCP{ENSEMBLE}[0]->{UNIX_TIME}) / 3600);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   483
progress("\tMean ping interval: %.1f seconds\n",$LADCP{MEAN_DT});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   484
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   485
if (defined($out_LADCPtis)) {
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   486
	progress("Writing LADCP-timeseries to <$out_LADCPtis>...\n");
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   487
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   488
	@antsNewLayout = ('ens','elapsed','reflr_w','reflr_w.stddev','reflr_w.nsamp','depth');
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   489
	open(STDOUT,"$out_LADCPtis") || croak("$out_LADCPtis: $!\n");
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   490
	for (my($ens)=$firstGoodEns; $ens<=$lastGoodEns; $ens++) {
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   491
		&antsOut($LADCP{ENSEMBLE}[$ens]->{NUMBER},
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   492
				 $LADCP{ENSEMBLE}[$ens]->{ELAPSED},
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   493
				 $LADCP{ENSEMBLE}[$ens]->{REFLR_W},
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   494
				 $LADCP{ENSEMBLE}[$ens]->{REFLR_W_STDDEV},
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   495
				 $LADCP{ENSEMBLE}[$ens]->{REFLR_W_NSAMP},
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   496
				 $LADCP{ENSEMBLE}[$ens]->{DEPTH});
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   497
	}
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   498
	&antsOut('EOF'); open(STDOUT,">&2");
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   499
}
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   500
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   501
#----------------------------------------------------------------------
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   502
# More editing
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   503
#	- this requires ${first,last}GoodEns to be known
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   504
#	- TILT field is set as a side-effect
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   505
#----------------------------------------------------------------------
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   506
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   507
progress("Editing additional earth-coordinate velocity data...\n");
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   508
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   509
my($first_bad_bin);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   510
for (my($bin)=$LADCP_firstBin-1; $bin<$LADCP_lastBin-1; $bin++) {
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   511
	next unless ($per_bin_nsamp[$bin]/($lastGoodEns-$firstGoodEns) < $per_bin_valid_frac_lim);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   512
	$first_bad_bin = $bin;
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   513
	last;
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   514
}
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   515
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   516
if (defined($first_bad_bin)) {
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   517
	$fprm = $pte = 0;
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   518
	for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   519
		$pte += editTilt($ens,$max_tilt);
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   520
		$fprm += editFarBins($ens,$first_bad_bin) if defined($first_bad_bin);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   521
	}
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   522
	progress("\tattitude threshold (max_tilt = %d deg): %d velocites removed (%d%% of total)\n",
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   523
		$max_tilt,$pte,round(100*$pte/$nvv));
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   524
	progress("\tvelocities beyond bin $first_bad_bin (<%d%% valid values): %d velocites removed (%d%% of total in bins $LADCP_firstBin-$LADCP_lastBin)\n",
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   525
		round(100*$per_bin_valid_frac_lim),$fprm,round(100*$fprm/$nvw));
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   526
}
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   527
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   528
#--------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   529
# Read CTD data
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   530
#--------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   531
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   532
progress("Reading CTD data from <$CTD_file>...\n");
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   533
open(STDIN,$CTD_file) || croak("$CTD_file: $!\n");
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   534
croak("$CTD_file: no data\n") unless (&antsIn());
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   535
undef($antsOldHeaders);
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   536
($CTD_elapsed,$CTD_depth,$CTD_svel,$CTD_w) = &fnr('elapsed','depth','ss','w');
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   537
$CTD_temp = &fnrNoErr('temp');
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   538
&antsAddParams('lat',$P{lat}) if defined($P{lat});
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   539
&antsAddParams('lon',$P{lon}) if defined($P{lon});
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   540
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   541
$CTD_maxdepth = -1;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   542
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   543
do {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   544
	croak("$0: cannot deal with non-numeric CTD elapsed time\n")
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   545
		unless &antsNumbers($CTD_elapsed);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   546
	push(@{$CTD{ELAPSED}},$ants_[0][$CTD_elapsed]);
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   547
	push(@{$CTD{DEPTH}},  $ants_[0][$CTD_depth]);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   548
	push(@{$CTD{SVEL}},   $ants_[0][$CTD_svel]);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   549
	push(@{$CTD{W}},      $ants_[0][$CTD_w]);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   550
	push(@{$CTD{TEMP}},	  $ants_[0][$CTD_temp]) if defined($CTD_temp);
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   551
	if ($ants_[0][$CTD_depth] > $CTD_maxdepth) {
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   552
		$CTD_maxdepth = $ants_[0][$CTD_depth];
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   553
		$CTD_atbottom = $#{$CTD{DEPTH}};
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   554
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   555
} while (&antsIn());
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   556
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   557
$CTD{DT} = ($CTD{ELAPSED}[$#{$CTD{ELAPSED}}] - $CTD{ELAPSED}[0]) / $#{$CTD{ELAPSED}};
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   558
progress("\t%d scans at %.1fHz\n",scalar(@{$CTD{DEPTH}}),1/$CTD{DT});
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   559
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   560
croak("$0: CTD start depth must be numeric\n")
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   561
	unless numberp($CTD{DEPTH}[0]);
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   562
$CTD_neg_press_offset = -1 * round($CTD{DEPTH}[0])
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   563
	if ($CTD{DEPTH}[0] < -$CTD_neg_press_offset);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   564
if ($CTD_neg_press_offset > 0) {
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   565
	progress("\tadding $CTD_neg_press_offset dbar offset to pressure data\n");
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   566
	for (my($i)=0; $i<@{$CTD{DEPTH}}; $i++) { $CTD{DEPTH}[$i] += $CTD_neg_press_offset; }
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   567
	$CTD_maxdepth += $CTD_neg_press_offset;
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   568
}
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   569
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   570
progress("\tstart depth = %.1fm\n",$CTD{DEPTH}[0]);
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   571
progress("\tmax depth   = %dm (# $CTD_atbottom)\n",$CTD_maxdepth);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   572
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   573
#--------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   574
# Construct sound-speed correction profile from CTD 1Hz downcast data
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   575
#	very simple algorithm that stores the last value found
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   576
#	in each 1m bin
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   577
#--------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   578
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   579
progress("Constructing sound-speed correction profile\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   580
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   581
my($scans_per_sec) = int(1/$CTD{DT}+0.5);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   582
for (my($s)=0; $s<=$CTD_atbottom; $s+=$scans_per_sec) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   583
	next unless ($CTD{DEPTH}[$s] >= 0 && numberp($CTD{SVEL}[$s]));
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   584
	$sVelProf[int($CTD{DEPTH}[$s])] = $CTD{SVEL}[$s];
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   585
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   586
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   587
#-------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   588
# Determine time lag
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   589
#-------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   590
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   591
if (defined($first_guess_timelag)) {
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   592
	progress("Setting initial time lag...\n");
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   593
	$CTD{TIME_LAG} = $first_guess_timelag;
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   594
	progress("\t-i => elapsed(CTD) ~ elapsed(LADCP) + %.1fs\n",$CTD{TIME_LAG});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   595
} else {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   596
	progress("Guestimating time lag...\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   597
	
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   598
	my($CTD_10pct_down) = 0;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   599
	my($LADCP_10pct_down) = $firstGoodEns;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   600
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   601
	$CTD_10pct_down++
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   602
		until ($CTD{DEPTH}[$CTD_10pct_down]-$CTD{DEPTH}[0] >= 0.1*($CTD_maxdepth-$CTD{DEPTH}[0]));
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   603
	$LADCP_10pct_down++
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   604
		until ($LADCP{ENSEMBLE}[$LADCP_10pct_down]->{DEPTH} >= 0.1*$LADCP{ENSEMBLE}[$LADCP_atbottom]->{DEPTH});
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   605
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   606
	$CTD{TIME_LAG} =
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   607
		$CTD{ELAPSED}[$CTD_10pct_down] - $LADCP{ENSEMBLE}[$LADCP_10pct_down]->{ELAPSED};
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   608
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   609
	progress("\telapsed(dz(CTD)=%.1fm) ~ elapsed(dz(LADCP)=%.1fm) + %.1fs\n",
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   610
	    $CTD{DEPTH}[$CTD_10pct_down]-$CTD{DEPTH}[0],$LADCP{ENSEMBLE}[$LADCP_10pct_down]->{DEPTH},$CTD{TIME_LAG});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   611
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   612
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   613
if ($opt_u) {
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   614
	progress("\tskipping time lagging (-u)\n");
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   615
} else {
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   616
	$CTD{TIME_LAG} =													# stage 1: dc/uc combined
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   617
		calc_lag($number_of_timelag_windows[0],$length_of_timelag_windows[0],int(1/$CTD{DT}+0.5),0);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   618
	croak("$0: Cannot proceed without valid lag!\n") unless defined($CTD{TIME_LAG});
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   619
	progress("\telapsed(CTD) ~ elapsed(LADCP) + %.2fs\n",$CTD{TIME_LAG});
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   620
	
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   621
	$CTD{TIME_LAG_DC} = calc_lag($number_of_timelag_windows[1],$length_of_timelag_windows[1],1,1);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   622
	progress("\tdowncast: elapsed(CTD) = elapsed(LADCP) + %.2fs\n",$CTD{TIME_LAG_DC})
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   623
		if defined($CTD{TIME_LAG_DC});
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   624
	$CTD{TIME_LAG_UC} = calc_lag($number_of_timelag_windows[1],$length_of_timelag_windows[1],1,-1);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   625
	progress("\tupcast  : elapsed(CTD) = elapsed(LADCP) + %.2fs\n",$CTD{TIME_LAG_UC})
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   626
		if defined($CTD{TIME_LAG_UC});
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   627
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   628
	croak("$0: Cannot proceed without either down- or upcast time-lag!\n")
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   629
		unless defined($CTD{TIME_LAG_DC}) || defined($CTD{TIME_LAG_UC});
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   630
	$CTD_time_lag_dc = $CTD{TIME_LAG_DC};									# if one lag is missing ...
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   631
	$CTD_time_lag_uc = $CTD{TIME_LAG_UC};									# use other for entire ...
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   632
	$CTD_time_lag_dc = $CTD_time_lag_uc unless defined($CTD_time_lag_dc);	# cast
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   633
	$CTD_time_lag_uc = $CTD_time_lag_dc unless defined($CTD_time_lag_uc);
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   634
}
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   635
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   636
&antsAddParams('CTD_time_lag_dc',$CTD{TIME_LAG_DC},'CTD_time_lag_uc',$CTD{TIME_LAG_UC});
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   637
undef($CTD{TIME_LAG}); 													# to avoid confusion
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   638
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   639
#------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   640
# Merge CTD with LADCP data
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   641
#	- after this step, reflr w is sound-speed corrected!!!
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   642
#------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   643
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   644
progress("Merging CTD with LADCP data...\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   645
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   646
for (my($skipped)=0,my($ens)=$firstGoodEns; $ens<=$lastGoodEns; $ens++) {
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   647
	my($scan) = ($ens < $LADCP_atbottom) ?
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   648
		int(($LADCP{ENSEMBLE}[$ens]->{ELAPSED} + $CTD_time_lag_dc - $CTD{ELAPSED}[0]) / $CTD{DT} + 0.5) :
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   649
		int(($LADCP{ENSEMBLE}[$ens]->{ELAPSED} + $CTD_time_lag_uc - $CTD{ELAPSED}[0]) / $CTD{DT} + 0.5);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   650
	if ($scan <= 0) {	# NB: must be <=, rather than <, or assertion below sometimes fails
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   651
		$skipped++;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   652
		$firstGoodEns = $ens+1;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   653
		next;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   654
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   655
	if ($skipped > 0) {
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   656
		$firstGoodEns++,$skipped++,next									# in gap
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   657
			unless defined($LADCP{ENSEMBLE}[$firstGoodEns]->{REFLR_W});
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   658
		info("$skipped initial LADCP ensembles skipped because CTD data begin with LADCP in water\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   659
		$skipped = 0;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   660
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   661
	if ($scan > $#{$CTD{ELAPSED}}) {
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   662
		while (!defined($LADCP{ENSEMBLE}[$ens-1]->{REFLR_W})) { $ens--; }	# in gap
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   663
		info(sprintf("%d final LADCP ensembles skipped because CTD data end with LADCP in water\n",
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   664
			$lastGoodEns-$ens+1));
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   665
		$lastGoodEns = $ens-1;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   666
		last;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   667
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   668
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   669
	if ($ens < $LADCP_atbottom) {
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   670
		die("assertion failed!\n" .
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   671
			"\ttest: abs($LADCP{ENSEMBLE}[$ens]->{ELAPSED} + $CTD_time_lag_dc - $CTD{ELAPSED}[$scan]) <= $CTD{DT}/2\n" .
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   672
			"\tens = $ens, scan = $scan\n" .
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   673
			sprintf("\tadjusted LADCP time = %f\n",$LADCP{ENSEMBLE}[$ens]->{ELAPSED} + $CTD_time_lag_dc) .
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   674
			sprintf("\tCTD($scan) time = %f\n",$CTD{ELAPSED}[$scan]) .
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   675
			"=> Did you use SeaBird elapsed time? Don't!"
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   676
	    ) unless (abs($LADCP{ENSEMBLE}[$ens]->{ELAPSED} + $CTD_time_lag_dc - $CTD{ELAPSED}[$scan]) <= $CTD{DT}/2 + 1e-10);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   677
	} else {
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   678
		die("assertion failed!\n" .
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   679
			"\ttest: abs($LADCP{ENSEMBLE}[$ens]->{ELAPSED} + $CTD_time_lag_uc - $CTD{ELAPSED}[$scan]) <= $CTD{DT}/2\n" .
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   680
			"\tens = $ens, scan = $scan\n" .
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   681
			sprintf("\tadjusted LADCP time = %f\n",$LADCP{ENSEMBLE}[$ens]->{ELAPSED} + $CTD_time_lag_uc) .
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   682
			sprintf("\tCTD($scan) time = %f\n",$CTD{ELAPSED}[$scan]) .
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   683
			"=> Did you use SeaBird elapsed time? Don't!"
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   684
	    ) unless (abs($LADCP{ENSEMBLE}[$ens]->{ELAPSED} + $CTD_time_lag_uc - $CTD{ELAPSED}[$scan]) <= $CTD{DT}/2 + 1e-10);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   685
	}
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   686
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   687
	$LADCP{ENSEMBLE}[$ens]->{CTD_ELAPSED} = $CTD{ELAPSED}[$scan];		# elapsed field for output
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   688
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   689
	if (defined($LADCP{ENSEMBLE}[$ens]->{REFLR_W})						# not a gap
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   690
			&& numberp($CTD{DEPTH}[$scan])) {
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   691
		$LADCP{ENSEMBLE}[$ens]->{REFLR_W_NOSSCORR} = $LADCP{ENSEMBLE}[$ens]->{REFLR_W};				
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   692
	    $LADCP{ENSEMBLE}[$ens]->{REFLR_W} *= $CTD{SVEL}[$scan]/1500; 	# correct for sound-speed variations at source
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   693
		croak(sprintf("\n$0: negative depth (%.1fm) in CTD file at elapsed(CTD) = %.1fs (use -a?)\n",
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   694
			$CTD{DEPTH}[$scan],$CTD{ELAPSED}[$scan]))
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   695
				unless ($CTD{DEPTH}[$scan] >= 0);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   696
		$LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH} = $CTD{DEPTH}[$scan];
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   697
		$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN} = $scan;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   698
		my($reflr_ocean_w) = $LADCP{ENSEMBLE}[$ens]->{REFLR_W} - $CTD{W}[$scan];
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   699
		if (abs($reflr_ocean_w) <= $max_allowed_w) {
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   700
			$sumWsq += &SQR($reflr_ocean_w);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   701
			$nWsq++;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   702
			if ($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH} > 100 &&
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   703
				$LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH} < $LADCP{ENSEMBLE}[$LADCP_atbottom]->{CTD_DEPTH}-100) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   704
					$sumWsqI += &SQR($reflr_ocean_w);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   705
					$nWsqI++;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   706
	        }
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   707
	    } else {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   708
	    	undef($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});					# DON'T USE THIS ENSEMBLE LATER
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   709
	    }
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   710
	} else{
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   711
	    undef($LADCP{ENSEMBLE}[$ens]->{REFLR_W});						# don't output in time-series file
10
7e76fdef8953 version prior to carrying out separate dc-/uc- time lagging
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 6
diff changeset
   712
	    undef($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});						# old DEPTH from calcLADCPts() must be removed
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   713
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   714
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   715
	
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   716
if ($nWsq > 0 && $nWsqI > 0) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   717
	&antsAddParams('rms_w_reflr_err',sqrt($sumWsq/$nWsq),'rms_w_reflr_err_interior',sqrt($sumWsqI/$nWsqI));
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   718
	progress("\t%.2f cm/s rms reference-layer w_ocean, %.2f cm/s away from boundaries\n",
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   719
						100*sqrt($sumWsq/$nWsq),100*sqrt($sumWsqI/$nWsqI));
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   720
	warning(0,"%.2f cm/s reference-layer w_ocean away from boundaries\n",100*sqrt($sumWsqI/$nWsqI))
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   721
		if (sqrt($sumWsqI/$nWsqI) > 0.05);
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   722
#	croak("$0: rms reference-layer w_ocean is too large\n")
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   723
#		unless (sqrt($sumWsqI/$nWsqI) < 0.07);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   724
} elsif ($nWsq > 0) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   725
	&antsAddParams('rms_w_reflr_err',sqrt($sumWsq/$nWsq),'rms_w_reflr_err_interior',nan);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   726
	progress("\t%.2f cm/s rms reference-layer w_ocean\n",100*sqrt($sumWsq/$nWsq));
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   727
} else {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   728
	croak("$0: no valid vertical velocities\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   729
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   730
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   731
#----------------------------------------------------------------------
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   732
# Calculate Volume Scattering Coefficients
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   733
#----------------------------------------------------------------------
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   734
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   735
progress("Calculating volume-scattering coefficients...\n");
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   736
calc_backscatter_profs($firstGoodEns,$lastGoodEns);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   737
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   738
#----------------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   739
# Remove data contaminated by sidelobe reflection from seabed and sea surface
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   740
#----------------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   741
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   742
if ($LADCP{ENSEMBLE}[$LADCP_atbottom]->{XDUCER_FACING_DOWN}) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   743
	&antsAddParams('ADCP_orientation','downlooker');
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   744
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   745
	if (numberp($opt_h)) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   746
		progress("Setting water depth (-h)\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   747
		$water_depth = $opt_h;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   748
		$sig_water_depth = 0;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   749
	} else {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   750
		progress("Finding seabed...\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   751
		($water_depth,$sig_water_depth) =
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   752
			find_backscatter_seabed($LADCP{ENSEMBLE}[$LADCP_atbottom]->{CTD_DEPTH});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   753
		($water_depth_BT,$sig_water_depth_BT) =
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   754
			find_seabed(\%LADCP,$LADCP_atbottom,$LADCP{BEAM_COORDINATES});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   755
		if (defined($water_depth_BT)) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   756
			my($dd) = abs($water_depth_BT - $water_depth);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   757
			warning(2,sprintf("Large RDI vs. own water-depth difference (%.1fm)\n",$dd))
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   758
				if ($dd > 5);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   759
		}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   760
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   761
	
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   762
	&antsAddParams('water_depth',$water_depth,'water_depth.sig',$sig_water_depth);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   763
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   764
	if (defined($water_depth)) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   765
		if (defined($water_depth_BT)) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   766
			progress("\t%.1f(%.1f) m water depth (%.1f(%.1f)m from BT)\n",
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   767
				$water_depth,$sig_water_depth,$water_depth_BT,$sig_water_depth_BT);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   768
		} else {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   769
			progress("\t%.1f(%.1f) m water depth\n",$water_depth,$sig_water_depth);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   770
		}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   771
		warning(1,sprintf("large uncertainty in water-depth estimation (%.1fm)\n",$sig_water_depth))
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   772
			if ($sig_water_depth > $LADCP{BIN_LENGTH});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   773
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   774
		progress("Editing data to remove sidelobe interference from seabed...\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   775
		($nvrm,$nerm) = editSideLobes($firstGoodEns,$lastGoodEns,$water_depth);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   776
		progress("\t$nvrm velocities from $nerm ensembles removed\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   777
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   778
	} else {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   779
		info("no seabed found in backscatter profiles --- no sidelobe editing done\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   780
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   781
	
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   782
} else {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   783
	&antsAddParams('ADCP_orientation','uplooker');
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   784
	progress("Editing data to remove sidelobe interference from sea surface...\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   785
	($nvrm,$nerm) = editSideLobes($firstGoodEns,$lastGoodEns,undef);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   786
	progress("\t$nvrm velocities from $nerm ensembles removed\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   787
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   788
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   789
#----------------------------------------------------------------------
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   790
# Data Editing after LADCP and CTD data have been merged
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   791
#	1) surface layer editing
10
7e76fdef8953 version prior to carrying out separate dc-/uc- time lagging
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 6
diff changeset
   792
#	2) user-supplied $edit_data_hook
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   793
#----------------------------------------------------------------------
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   794
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   795
progress("Removing data from instrument at surface...\n");
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   796
$nerm = editSurfLayer($firstGoodEns,$lastGoodEns,$surface_layer_depth);
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   797
progress("\t$nerm ensembles removed\n");
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   798
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   799
if (defined($post_merge_hook)) {
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   800
	progress("Executing user-supplied \$post_merge_hook...\n");
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   801
	&{$post_merge_hook}($firstGoodEns,$lastGoodEns);
10
7e76fdef8953 version prior to carrying out separate dc-/uc- time lagging
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 6
diff changeset
   802
}
7e76fdef8953 version prior to carrying out separate dc-/uc- time lagging
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 6
diff changeset
   803
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   804
#---------------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   805
# Depth-bin LADCP velocity data
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   806
#
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   807
# NOTES:
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   808
#	1) ensemble and bin numbers are saved for maximum flexibility
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   809
#	2) only ensemble/bins with valid vertical velocities are saved
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   810
#	3) applying the full soundspeed correction to w is pointless in
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   811
#	   practice, but hey!, CPU cycles are cheap; [in a cast in the Gulf of Mexico
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   812
#	   which has fairly pronounce soundspeed gradients, the max value of Kn
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   813
#	   is 1.00004160558372, which gives rise to a correction of less than 0.2mm/s
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   814
#	   at a winch+wave speed of 3m/s....]
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   815
#	4) as far as I can tell, the soundspeed correction for bin length also
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   816
#	   has only a minute effect
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   817
#---------------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   818
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   819
progress("Binning velocities...\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   820
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   821
my($min_depth) = 9e99;
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   822
my($max_depth) = 0;
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   823
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   824
progress("\tdowncast...\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   825
for ($ens=$firstGoodEns; $ens<$LADCP_atbottom; $ens++) {						# downcast
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   826
	unless (numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH})) {
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   827
		$firstGoodEns++ if ($ens == $firstGoodEns);								# start has been edited away
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   828
		next;
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   829
	}
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   830
	my(@bindepth) = calc_binDepths($ens);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   831
	for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   832
		next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   833
		$min_depth = $bindepth[$bin] if ($bindepth[$bin] < $min_depth);
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   834
		$max_depth = $bindepth[$bin] if ($bindepth[$bin] > $max_depth);
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   835
		$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] =
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   836
			sscorr_w($LADCP{ENSEMBLE}[$ens]->{W}[$bin],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   837
					 $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   838
					 $LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   839
					 $bindepth[$bin]);
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   840
		$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin] =
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   841
			sscorr_w($LADCP{ENSEMBLE}[$ens]->{W12}[$bin],
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   842
					 $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   843
					 $LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   844
					 $bindepth[$bin])
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   845
				if numberp($LADCP{ENSEMBLE}[$ens]->{W12}[$bin]);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   846
		$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin] =
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   847
			sscorr_w($LADCP{ENSEMBLE}[$ens]->{W34}[$bin],
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   848
					 $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   849
					 $LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   850
					 $bindepth[$bin])
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   851
				if numberp($LADCP{ENSEMBLE}[$ens]->{W34}[$bin]);
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   852
		$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_W}[$bin] =
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   853
			$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] + $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}];
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   854
		my($bi) = $bindepth[$bin]/$output_bin_size;
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   855
		push(@{$DNCAST{ENSEMBLE}[$bi]},$ens);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   856
		push(@{$DNCAST{ELAPSED}[$bi]},$CTD{ELAPSED}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}]);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   857
		push(@{$DNCAST{CTD_W}[$bi]},$CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}]);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   858
		push(@{$DNCAST{BIN}[$bi]},$bin);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   859
		push(@{$DNCAST{DEPTH}[$bi]},$bindepth[$bin]);
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   860
		push(@{$DNCAST{W}[$bi]},$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin]);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   861
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   862
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   863
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   864
for (my($bi)=0; $bi<=$#{$DNCAST{ENSEMBLE}}; $bi++) {							# bin data into profile
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   865
	$DNCAST{MEAN_DEPTH}[$bi]  	= avg(@{$DNCAST{DEPTH}[$bi]});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   866
	$DNCAST{MEAN_ELAPSED}[$bi]	= avg(@{$DNCAST{ELAPSED}[$bi]});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   867
	$DNCAST{MEDIAN_W}[$bi] 	  	= median(@{$DNCAST{W}[$bi]});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   868
	$DNCAST{MAD_W}[$bi]		  	= mad2($DNCAST{MEDIAN_W}[$bi],@{$DNCAST{W}[$bi]});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   869
	$DNCAST{N_SAMP}[$bi]		= @{$DNCAST{W}[$bi]};
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   870
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   871
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   872
progress("\tupcast...\n");														# upcast
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   873
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   874
my($realLastGoodEns);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   875
for ($ens=$LADCP_atbottom; $ens<=$lastGoodEns; $ens++) {		
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   876
	next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   877
	$realLastGoodEns = $ens;
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   878
	my(@bindepth) = calc_binDepths($ens);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   879
	for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   880
		next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   881
		$min_depth = $bindepth[$bin] if ($bindepth[$bin] < $min_depth);
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   882
		$max_depth = $bindepth[$bin] if ($bindepth[$bin] > $max_depth);
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   883
		$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] =
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   884
			sscorr_w($LADCP{ENSEMBLE}[$ens]->{W}[$bin],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   885
					 $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   886
					 $LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   887
					 $bindepth[$bin]);
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   888
		$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin] =
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   889
			sscorr_w($LADCP{ENSEMBLE}[$ens]->{W12}[$bin],
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   890
					 $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   891
					 $LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   892
					 $bindepth[$bin])
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   893
				if numberp($LADCP{ENSEMBLE}[$ens]->{W12}[$bin]);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   894
		$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin] =
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   895
			sscorr_w($LADCP{ENSEMBLE}[$ens]->{W34}[$bin],
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   896
					 $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   897
					 $LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   898
					 $bindepth[$bin])
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   899
				if numberp($LADCP{ENSEMBLE}[$ens]->{W34}[$bin]);
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   900
		$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_W}[$bin] =
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   901
			$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] + $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}];
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   902
		my($bi) = $bindepth[$bin]/$output_bin_size;
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   903
		push(@{$UPCAST{ENSEMBLE}[$bi]},$ens);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   904
		push(@{$UPCAST{ELAPSED}[$bi]},$CTD{ELAPSED}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}]);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   905
		push(@{$UPCAST{CTD_W}[$bi]},$CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}]);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   906
		push(@{$UPCAST{BIN}[$bi]},$bin);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   907
		push(@{$UPCAST{DEPTH}[$bi]},$bindepth[$bin]);
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   908
		push(@{$UPCAST{W}[$bi]},$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin]);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   909
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   910
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   911
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   912
for (my($bi)=0; $bi<=$#{$UPCAST{ENSEMBLE}}; $bi++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   913
	$UPCAST{MEAN_DEPTH}[$bi]  	= avg(@{$UPCAST{DEPTH}[$bi]});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   914
	$UPCAST{MEAN_ELAPSED}[$bi]	= avg(@{$UPCAST{ELAPSED}[$bi]});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   915
	$UPCAST{MEDIAN_W}[$bi] 	  	= median(@{$UPCAST{W}[$bi]});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   916
	$UPCAST{MAD_W}[$bi]		  	= mad2($UPCAST{MEDIAN_W}[$bi],@{$UPCAST{W}[$bi]});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   917
	$UPCAST{N_SAMP}[$bi]		= @{$UPCAST{W}[$bi]};
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   918
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   919
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   920
&antsAddParams('min_depth',$min_depth,'max_depth',$max_depth,					# plot area
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   921
			   'min_ens',$LADCP{ENSEMBLE}[$firstGoodEns]->{NUMBER},
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   922
			   'max_ens',$LADCP{ENSEMBLE}[$realLastGoodEns]->{NUMBER},
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   923
			   'min_elapsed',$LADCP{ENSEMBLE}[$firstGoodEns]->{CTD_ELAPSED},
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   924
			   'max_elapsed',$LADCP{ENSEMBLE}[$realLastGoodEns]->{CTD_ELAPSED});
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   925
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   926
#------------------------------------------------------------------------------------------------------
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   927
# remove single-ping noise
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   928
#	- based on observation that without this step raw velocities tend to be strongly vertically striped
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   929
#		=> residual CTD/LADCP mismatch errors & ADCP single-ping errors
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   930
#	- remove ensemble-median residual from all vertical velocities; new residual calculated below
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   931
#	- improves solution but can introduce errors in ensembles with strong outliers => median instead of
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   932
#	  mean, and outlier filter above
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   933
#------------------------------------------------------------------------------------------------------
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   934
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   935
unless ($opt_q) {
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   936
	progress("Removing single-ping residual noise...\n");
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   937
	
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   938
	my($fe) = defined($CTD{TIME_LAG_DC}) ? $firstGoodEns    : $LADCP_atbottom;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   939
	my($le) = defined($CTD{TIME_LAG_UC}) ? $realLastGoodEns : $LADCP_atbottom;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   940
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   941
	for ($ens=$fe; $ens<=$le; $ens++) {
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   942
		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   943
		my(@residuals) = ();
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   944
		my(@bindepth) = calc_binDepths($ens);
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   945
		for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   946
			next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   947
			my($bi) = $bindepth[$bin]/$output_bin_size;
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   948
			push(@residuals,
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   949
				$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] -
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   950
					(($ens < $LADCP_atbottom) ? $DNCAST{MEDIAN_W}[$bi]
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   951
											  : $UPCAST{MEDIAN_W}[$bi]));
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   952
		}
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   953
		$LADCP{ENSEMBLE}[$ens]->{MEDIAN_RESIDUAL_W} = median(@residuals);
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   954
		for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   955
			next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   956
			$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] -=
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   957
				$LADCP{ENSEMBLE}[$ens]->{MEDIAN_RESIDUAL_W};
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   958
		}
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   959
    }
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   960
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   961
    progress("\tre-calculating profile mad...\n");
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   962
    
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   963
	for (my($bi)=0; $bi<=$#{$DNCAST{ENSEMBLE}}; $bi++) {						# bin data
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   964
		for (my($i)=0; $i<@{$DNCAST{W}[$bi]}; $i++) {
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   965
			$DNCAST{W}[$bi][$i] -= $LADCP{ENSEMBLE}[$DNCAST{ENSEMBLE}[$bi][$i]]->{MEDIAN_RESIDUAL_W};
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   966
		}
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   967
		$DNCAST{MAD_W}[$bi] = mad2($DNCAST{MEDIAN_W}[$bi],@{$DNCAST{W}[$bi]});
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   968
	}
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   969
	for (my($bi)=0; $bi<=$#{$UPCAST{ENSEMBLE}}; $bi++) {
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   970
		for (my($i)=0; $i<@{$UPCAST{W}[$bi]}; $i++) {
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   971
			$UPCAST{W}[$bi][$i] -= $LADCP{ENSEMBLE}[$UPCAST{ENSEMBLE}[$bi][$i]]->{MEDIAN_RESIDUAL_W};
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   972
		}
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   973
		$UPCAST{MAD_W}[$bi] = mad2($UPCAST{MEDIAN_W}[$bi],@{$UPCAST{W}[$bi]});
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   974
	}
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   975
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   976
} # unless ($opt_q);
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   977
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   978
#-------------------------
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   979
# Output Per-Bin Resiudals
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   980
#-------------------------
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   981
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   982
if (defined($out_BR)) {
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   983
	my(@dc_nres,@uc_nres,@dc_bres,@uc_bres);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   984
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   985
	progress("Writing per-bin residual data to $out_BR...\n");
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   986
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   987
	for ($ens=$firstGoodEns; $ens<$LADCP_atbottom; $ens++) {						# downcast
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   988
		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   989
		my(@bindepth) = calc_binDepths($ens);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   990
		for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   991
			next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   992
			push(@{$dc_bres[$bin]},
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   993
					$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin]
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   994
					- $DNCAST{MEDIAN_W}[$bindepth[$bin]/$output_bin_size]);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   995
		}
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   996
	}
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   997
	for ($ens=$LADCP_atbottom; $ens<=$realLastGoodEns; $ens++) {					# upcast 
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   998
		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   999
		my(@bindepth) = calc_binDepths($ens);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1000
		for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1001
			next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1002
			push(@{$uc_bres[$bin]},
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1003
					$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin]
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1004
					- $UPCAST{MEDIAN_W}[$bindepth[$bin]/$output_bin_size]);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1005
		}
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1006
	}
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1007
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1008
	my($saveParams) = $antsCurParams;
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1009
	@antsNewLayout = ('bin','dc_residual','dc_residual.sig','dc_residual.nsamp',
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1010
						   ,'uc_residual','uc_residual.sig','uc_residual.nsamp');
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1011
	open(STDOUT,"$out_BR") || croak("$out_BR: $!\n");
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1012
	&antsAddParams('BR_max_bin',max(scalar(@dc_bres),scalar(@uc_bres)));
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1013
	for (my($bin)=0; $bin<max(scalar(@dc_bres),scalar(@uc_bres)); $bin++) {
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1014
		my($dc_avg) = avg(@{$dc_bres[$bin]});
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1015
		my($uc_avg) = avg(@{$uc_bres[$bin]});
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1016
		&antsOut($bin+1,$dc_avg,stddev2($dc_avg,@{$dc_bres[$bin]}),scalar(@{$dc_bres[$bin]}),
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1017
						$uc_avg,stddev2($uc_avg,@{$uc_bres[$bin]}),scalar(@{$uc_bres[$bin]}));
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1018
	}
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1019
	&antsOut('EOF'); open(STDOUT,">&2");
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1020
	$antsCurParams = $saveParams;
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1021
}
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1022
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1023
#--------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1024
# Calculate BT-referenced vertical-velocity profile
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1025
#--------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1026
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1027
if (defined($water_depth)) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1028
	progress("Calculating BT-referenced vertical velocities\n");
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1029
	calc_BTprof($firstGoodEns,$realLastGoodEns,$water_depth,$sig_water_depth);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1030
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1031
	my($sumSq) = my($n) = 0;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1032
	for (my($bi)=0; $bi<=$#{$BT{MEDIAN_W}}; $bi++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1033
		next unless defined($BT{MEDIAN_W}[$bi]);
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1034
		next unless ($BT{N_SAMP}[$bi]>=$min_w_nsamp && $DNCAST{N_SAMP}[$bi]>=$min_w_nsamp && $UPCAST{N_SAMP}[$bi]>=$min_w_nsamp);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1035
		$sumSq += ($BT{MEDIAN_W}[$bi] - $DNCAST{MEDIAN_W}[$bi]/2 - $UPCAST{MEDIAN_W}[$bi]/2)**2;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1036
		$n++;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1037
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1038
	if ($n > 0) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1039
		my($rms) = round(sqrt($sumSq/$n),0.001);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1040
		&antsAddParams('BT_rms_w_discrepancy',$rms);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1041
		progress("\t$rms m/s rms vertical-velocity discrepancy\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1042
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1043
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1044
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1045
#------------
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1046
# full output
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1047
#------------
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1048
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1049
# NB: residual field is calculated with respect to down-/upcast medians in -o-size bins
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1050
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1051
if (defined($out_w)) {
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1052
	progress("Writing vertical-velocity data to $out_w...\n");
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1053
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1054
	@antsNewLayout = ('ensemble','bin','elapsed','depth','CTD_depth','downcast',
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1055
					  'w','w12','w34','residual','CTD_w','LADCP_w','errvel',
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1056
					  'correlation','echo_amplitude','volume_scattering_coeff',
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1057
					  'pitch','roll','tilt','heading','3_beam','svel');
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1058
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1059
	open(STDOUT,"$out_w") || croak("$out_w: $!\n");
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
  1060
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
  1061
	if (defined($CTD{TIME_LAG_DC})) {
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
  1062
	  for ($ens=$firstGoodEns; $ens<$LADCP_atbottom; $ens++) {						# downcast
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1063
		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1064
		my(@bindepth) = calc_binDepths($ens);
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1065
		for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1066
			next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1067
			my($bi) = $bindepth[$bin]/$output_bin_size;
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1068
			&antsOut(
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1069
				$LADCP{ENSEMBLE}[$ens]->{NUMBER},$bin+1,
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1070
				$CTD{ELAPSED}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1071
				$bindepth[$bin],$LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},1,
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1072
				$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin],
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1073
				$LADCP{BEAM_COORDINATES} ? $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin] : nan,
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1074
				$LADCP{BEAM_COORDINATES} ? $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin] : nan,
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1075
				$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] - $DNCAST{MEDIAN_W}[$bi],
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1076
				$CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1077
				$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_W}[$bin],
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1078
				$LADCP{ENSEMBLE}[$ens]->{ERRVEL}[$bin],
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1079
				median(@{$LADCP{ENSEMBLE}[$ens]->{CORRELATION}[$bin]}),
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1080
				median(@{$LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin]}),
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1081
				$LADCP{ENSEMBLE}[$ens]->{SV}[$bin],
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1082
				$LADCP{ENSEMBLE}[$ens]->{PITCH},
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1083
				$LADCP{ENSEMBLE}[$ens]->{ROLL},
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1084
				$LADCP{ENSEMBLE}[$ens]->{TILT},
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1085
				$LADCP{ENSEMBLE}[$ens]->{HEADING},
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1086
				(defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][0]) + 			# only works for beam coords
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1087
				 defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][1]) +
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1088
				 defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][2]) +
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1089
				 defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][3])) < 4 ? 1 : 0,
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1090
				$CTD{SVEL}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1091
			);
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
  1092
		} # for $bin
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
  1093
	  } # for $ens
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
  1094
	} # if defined dc time lag
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1095
	
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
  1096
	if (defined($CTD{TIME_LAG_UC})) {
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
  1097
	  for ($ens=$LADCP_atbottom; $ens<=$realLastGoodEns; $ens++) {						# upcast 
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1098
		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1099
		my(@bindepth) = calc_binDepths($ens);
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1100
		for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1101
			next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1102
			my($bi) = $bindepth[$bin]/$output_bin_size;
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1103
			&antsOut(
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1104
				$LADCP{ENSEMBLE}[$ens]->{NUMBER},$bin+1,
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1105
				$CTD{ELAPSED}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1106
				$bindepth[$bin],$LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},0,
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1107
				$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin],
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1108
				$LADCP{BEAM_COORDINATES} ? $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin] : nan,
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1109
				$LADCP{BEAM_COORDINATES} ? $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin] : nan,
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1110
				$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] - $UPCAST{MEDIAN_W}[$bi],
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1111
				$CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1112
				$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_W}[$bin],
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1113
				$LADCP{ENSEMBLE}[$ens]->{ERRVEL}[$bin],
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1114
				median(@{$LADCP{ENSEMBLE}[$ens]->{CORRELATION}[$bin]}),
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1115
				median(@{$LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin]}),
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1116
				$LADCP{ENSEMBLE}[$ens]->{SV}[$bin],
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1117
				$LADCP{ENSEMBLE}[$ens]->{PITCH},
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1118
				$LADCP{ENSEMBLE}[$ens]->{ROLL},
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1119
				$LADCP{ENSEMBLE}[$ens]->{TILT},
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1120
				$LADCP{ENSEMBLE}[$ens]->{HEADING},
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1121
				(defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][0]) + 			# only works for beam coords
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1122
				 defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][1]) +
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1123
				 defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][2]) +
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1124
				 defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][3])) < 4 ? 1 : 0,
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1125
				$CTD{SVEL}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1126
			);
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
  1127
		} # for $bin
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
  1128
	  } # for $ens
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
  1129
	} # if defined uc time-lag
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1130
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1131
	&antsOut('EOF'); open(STDOUT,">&2");
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1132
}
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1133
	
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1134
#---------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1135
# Output profile
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1136
#---------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1137
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1138
if (defined($out_profile)) {
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1139
	progress("Writing vertical-velocity profiles to <$out_profile>...\n");
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1140
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1141
	@antsNewLayout = ('depth','dc_depth','dc_elapsed','dc_w','dc_w.mad','dc_w.nsamp',
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1142
							  'uc_depth','uc_elapsed','uc_w','uc_w.mad','uc_w.nsamp',
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1143
							  'elapsed','w','w.mad','w.nsamp',
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1144
	                          'BT_w','BT_w.mad','BT_w.nsamp');
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1145
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1146
	open(STDOUT,"$out_profile") || croak("$out_profile: $!\n");
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1147
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
  1148
	undef(%DNCAST) unless defined($CTD{TIME_LAG_DC});
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
  1149
	undef(%UPCAST) unless defined($CTD{TIME_LAG_UC});
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1150
	for (my($bi)=0; $bi<=max($#{$DNCAST{ENSEMBLE}},$#{$UPCAST{ENSEMBLE}},$#{$BT{NSAMP}}); $bi++) {
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1151
		&antsOut(($bi+0.5)*$output_bin_size,					# nominal depth
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1152
				 $DNCAST{MEAN_DEPTH}[$bi],$DNCAST{MEAN_ELAPSED}[$bi],
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1153
				 $DNCAST{N_SAMP}[$bi]>=$min_w_nsamp?$DNCAST{MEDIAN_W}[$bi]:nan,
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1154
				 $DNCAST{MAD_W}[$bi],$DNCAST{N_SAMP}[$bi],
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1155
				 $UPCAST{MEAN_DEPTH}[$bi],$UPCAST{MEAN_ELAPSED}[$bi],
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1156
				 $UPCAST{N_SAMP}[$bi]>=$min_w_nsamp?$UPCAST{MEDIAN_W}[$bi]:nan,
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1157
				 $UPCAST{MAD_W}[$bi],$UPCAST{N_SAMP}[$bi],
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1158
				 $DNCAST{MEAN_ELAPSED}[$bi]/2+$UPCAST{MEAN_ELAPSED}[$bi]/2,
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1159
				 $DNCAST{N_SAMP}[$bi]+$UPCAST{N_SAMP}[$bi]>=$min_w_nsamp ?
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1160
					($DNCAST{MEDIAN_W}[$bi]*$DNCAST{N_SAMP}[$bi]+$UPCAST{MEDIAN_W}[$bi]*$UPCAST{N_SAMP}[$bi]) / ($DNCAST{N_SAMP}[$bi]+$UPCAST{N_SAMP}[$bi]) :
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1161
					nan,
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1162
				 $DNCAST{N_SAMP}[$bi]+$UPCAST{N_SAMP}[$bi]>=$min_w_nsamp ?
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1163
					 ($DNCAST{MAD_W}[$bi]*$DNCAST{N_SAMP}[$bi]+$UPCAST{MAD_W}[$bi]*$UPCAST{N_SAMP}[$bi]) / ($DNCAST{N_SAMP}[$bi]+$UPCAST{N_SAMP}[$bi]) :
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1164
					 nan,
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1165
				 $DNCAST{N_SAMP}[$bi]+$UPCAST{N_SAMP}[$bi],
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1166
				 $BT{N_SAMP}[$bi]>=$min_w_nsamp?$BT{MEDIAN_W}[$bi]:nan,
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1167
				 $BT{MAD_W}[$bi],$BT{N_SAMP}[$bi]
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1168
		);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1169
	}
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1170
	&antsOut('EOF'); open(STDOUT,">&2");
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1171
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1172
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1173
#--------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1174
# write time-series output if requested
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1175
#--------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1176
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1177
if (defined($out_timeseries)) {
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1178
	progress("Writing time-series data to <$out_timeseries>...\n");
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1179
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1180
	@antsNewLayout = ('ens','elapsed','downcast',
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
  1181
					  'depth','xducer_sound_speed','pitch','gimbal_pitch','roll','tilt','heading',
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
  1182
					  'CTD_w','LADCP_reflr_w','LADCP_reflr_w_err','LADCP_reflr_w_nosscorr',
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
  1183
					  'reflr_ocean_w');
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1184
	open(STDOUT,"$out_timeseries") || croak("$out_timeseries: $!\n");
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1185
	 
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1186
	for ($ens=$firstGoodEns; $ens<=$realLastGoodEns; $ens++) {
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1187
		next unless defined($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
  1188
		my($reflr_oc_w) = defined($LADCP{ENSEMBLE}[$ens]->{REFLR_W})
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
  1189
			   		    ? $LADCP{ENSEMBLE}[$ens]->{REFLR_W} - $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}]
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
  1190
			   		    : undef;
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1191
		&antsOut($LADCP{ENSEMBLE}[$ens]->{NUMBER},
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1192
				 $CTD{ELAPSED}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1193
				 ($ens < $LADCP_atbottom) ? 1 : 0,
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1194
				 $LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1195
				 $CTD{SVEL}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1196
				 $LADCP{ENSEMBLE}[$ens]->{PITCH},
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1197
				 $LADCP{ENSEMBLE}[$ens]->{GIMBAL_PITCH},
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1198
				 $LADCP{ENSEMBLE}[$ens]->{ROLL},
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1199
				 $LADCP{ENSEMBLE}[$ens]->{TILT},
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1200
				 $LADCP{ENSEMBLE}[$ens]->{HEADING},
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1201
				 $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1202
				 $LADCP{ENSEMBLE}[$ens]->{REFLR_W},
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1203
				 $LADCP{ENSEMBLE}[$ens]->{REFLR_W_ERR},
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
  1204
				 $LADCP{ENSEMBLE}[$ens]->{REFLR_W_NOSSCORR},
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1205
				 $reflr_w);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1206
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1207
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1208
	&antsOut('EOF'); open(STDOUT,">&2");
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1209
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1210
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1211
system("{ sleep 30; ./PostProcess.sh $out_basename $RUN $data_subdir $plot_subdir $log_subdir; }&")
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1212
	if (-x 'PostProcess.sh');
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1213
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1214
exit(0);