LADCP_w_ocean
author A.M. Thurnherr <athurnherr@yahoo.com>
Tue, 02 Feb 2016 14:55:24 +0000
changeset 34 e550db661c17
parent 33 866c881b3a4a
child 35 54b8bb450e5f
permissions -rwxr-xr-x
pre-Tampa
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
#======================================================================
31
d0ae3cb99021 DoMORE-2
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
     3
#                    L A D C P _ W _ O C E A N 
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     4
#                    doc: Fri Dec 17 18:11:13 2010
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
     5
#                    dlm: Wed Jan 27 20:55:29 2016
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     6
#                    (c) 2010 A.M. Thurnherr
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
     7
#                    uE-Info: 450 0 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:
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    11
#	- make upcast-flag valid for yoyo casts
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    12
#	- 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
    13
#	- 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
    14
#	  because mean and stddev are used instead of median/mad
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
    15
#	- 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
    16
#	? use instrument tilt in sidelobe editing?
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    17
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    18
$antsSummary = 'calculate vertical velocities from LADCP & CTD time series';
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
# HISTORY:
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    21
#	Dec 17, 2010: - created from [mergeCTD+LADCP]
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    22
#	Dec 18, 2010: - made to work
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    23
#	Dec 19, 2010: - improved considerably
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    24
#	Dec 20, 2010: - onward
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    25
#				  - BUG: depth-binning was off by 1 bin?!
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    26
#				  - added binning correction for instrument tilt
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    27
#	Dec 21, 2010: - added -h (seafloor depth)
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    28
#	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
    29
#				  - debugged opt_d
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    30
#	Dec 23, 2010: - continued implementation of soundspeed corrections
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    31
#	Dec 24, 2010: - added winch_w, wave_w
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    32
#				  - removed beampair velocities from code
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    33
#	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
    34
#				  - removed elapsed_mismatch
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    35
#				  - removed winch_w, wave_w
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    36
#	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
    37
#	Dec 30, 2010: - cleaned up some
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    38
#				  - folded-in backscatter calculation from shear method
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    39
#				  - folded-in BT calculation from shear method
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    40
#	Dec 31, 2010: - added weighted mean w profile to output
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    41
#	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
    42
#				  - BUG: division by zero if no valid data
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    43
#	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
    44
#	Feb 16, 2011: - cosmetics
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    45
#	Jun 22, 2011: - cosmetics
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    46
#	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
    47
#				  - added -l
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    48
#				  - removed CTD headers from output
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    49
#	Jun 26, 2011: - added -u
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    50
#				  - changed package correction from acceleration to velocity, because of
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    51
#					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
    52
#					there
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    53
#	Jul  2, 2011: - increased tilt default to 15 degrees
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    54
#	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
    55
#				  - removed -p
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    56
#				  - replaced -d by residual (diagnostics) output
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    57
#	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
    58
#				  - 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
    59
#				  - 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
    60
#						 or end with CTD in water
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    61
#				  - moved rarely used option -s to -k
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    62
#				  - added -s)kip <ens> option
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    63
#				  - 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
    64
#	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
    65
#				    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
    66
#					residuals
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
    67
#	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
    68
#				  - 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
    69
#	Sep 23, 2011: - cosmetics (lots)
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
    70
#				  - added -d)
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
    71
#	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
    72
#				  - renamed time-series field names
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
    73
#				  - 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
    74
#	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
    75
#				  - removed -x
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
    76
#				  - 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
    77
#	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
    78
#	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
    79
#				  - 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
    80
#	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
    81
#	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
    82
#				  - 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
    83
#				  - 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
    84
#				  - 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
    85
#				  - 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
    86
#				  - 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
    87
#	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
    88
#				  - added step to remove single-ping noise
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    89
#	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
    90
#	Oct 17, 2011: - added default run label
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    91
#				  - added out_BR
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    92
#				  - BUG: closed STDOUT caused problems with tee in plotting scripts
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    93
#				  - added %run_label
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    94
#				  - added PostProcess.sh
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    95
#	Oct 18, 2011: - BUG: %{min,max}_ens used ensemble indices, rather than numbers
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    96
#				  - disabled false-positives editing (removes too much good data on 2011_IWISE)
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    97
#	Oct 19, 2011: - BUG: time-series output included ensembles without valid w
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    98
#				  - increased post-process sleep time to 30s
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    99
#				  - added corr, Sv and echo_amplitude as new fields to w output
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   100
#	Oct 20, 2011: - added editFarBins()
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   101
#				  - added downcast flag to time-series output
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   102
#				  - added ensemble number to LADCP-time-series output
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   103
#	Oct 21, 2011: - BUG: Sv code was not enabled for uplooker data
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   104
#	Oct 24, 2011: - added code to copy %lat/%lon from CTD data
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   105
#				  - added %ADCP_freuquency, %ADCP_blanking_distance
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   106
#				  - %LADCP_bin_length => %ADCP_bin_length
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   107
#	Oct 26, 2011: - added $first_guess_timelag
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   108
#	Oct 27, 2011: - added w12, w34, ww (pitch/roll-weighted average) to full output
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   109
#				  - removed ww because it apparently does not improve the solutions
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   110
#				  - moved editTilt() to after time-series calculation to allow
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   111
#				    time matching to work even with strict tilt limit
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   112
#				  - added correctAttitude()
10
7e76fdef8953 version prior to carrying out separate dc-/uc- time lagging
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 6
diff changeset
   113
#	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
   114
#	Oct 15, 2012: - added $edit_data_hook
12
2adcd220b9b4 before attempting to implement piece-wise time-lagging
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 11
diff changeset
   115
#				  - HG COMMIT
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   116
#				  - separated dc/uc time lagging
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   117
#				  - removed support for TLhist
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   118
#	Oct 16, 2012: - added support for dc/uc only solutions
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   119
#	Oct 17, 2012: - renamed $edit_data_hook to $post_merge_hook
12
2adcd220b9b4 before attempting to implement piece-wise time-lagging
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 11
diff changeset
   120
#				  - HG COMMIT
2adcd220b9b4 before attempting to implement piece-wise time-lagging
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 11
diff changeset
   121
#	Feb 13, 2013: - BUG: CTD_neg_press_offset did not work for CTD time series with -ve starting depth
2adcd220b9b4 before attempting to implement piece-wise time-lagging
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 11
diff changeset
   122
#	Mar 23, 2013: - cosmetics
2adcd220b9b4 before attempting to implement piece-wise time-lagging
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 11
diff changeset
   123
#				  - HG COMMIT
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   124
#	Apr 22, 2013: - removed opt_? variable aliases
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   125
#	May  8, 2013: - replaced default run label (default to profiles) to make more readable directory structure
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   126
#	May 14, 2013: - opt_m => w_max_lim
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   127
#				  - BUG: time-series output had two messed-up fields
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   128
#	May 15, 2013: - added w12 and w34 (2-beam solutions) to profile output
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   129
#	May 16, 2013: - added CTD_w_tt to time-series & all-sample outputs
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   130
#			      - -a => -d (CTD depth offset)
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   131
#				  - implemented pressure-sensor acceleration correction (-a)
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   132
#				  - added re-gridding of full profile after ping-coherent error removal
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   133
#	Jun  5, 2013: - renamed $discard_velocities_from_beam to $bad_beam
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   134
#				  - BUG: $bad_beam did not discard BT_VELOCITY data
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   135
#	Jun  6, 2013: - BUG: error message had -a instead of -d
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   136
#	Sep  5, 2013: - BUG: w12/w34 do not work for earth-coordinate data, of course
15
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   137
#	Apr 17, 2014: - BUG: edit_tilt was never called when all recorded bins are valid
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   138
#	Apr 21, 2014: - updated comments
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   139
#	May 19, 2014: - began adding support for PPI filtering
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   140
#	May 20, 2014: - changed volume_scattering_coeff to Sv in output
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   141
#				  - added editPPI()
19
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
   142
#	Jul  6, 2014: - BUG: nan water depth had been interpreted as known
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
   143
#				  - BUG: sVelProf[] was not allowed to have any gaps
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
   144
#	Jul  9, 2014: - BUG: Jul 6 bug fixes had been applied to older
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
   145
#				  		 version
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   146
#				  - BUG: code meant to ensure gap-free svel profiles did not work correctly
19
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
   147
#	Jul 12, 2014: - finally made output files executable
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
   148
#	Apr  5, 2015: - added check for required software
21
cd001648ccba .prof layout change re-implemented
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 19
diff changeset
   149
#				  - BUG: removed dc/uc mean w fields from .prof again
23
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 21
diff changeset
   150
#	Apr  7, 2015: - made LADCP_w callable from installation directory
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 21
diff changeset
   151
#				  - BUG: -v default was wrong in usage message
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 21
diff changeset
   152
#				  - replaced 'ens' in output files by 'ensemble'
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
   153
#	Apr 16, 2015: - turned output specifies into lists (re-design of
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
   154
#					plotting sub-system)
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
   155
#				  - removed 30s sleep from PostProcess.sh call
26
b89d4b01fcc5 after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 25
diff changeset
   156
#				  - disabled active output when ANTS are not available
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   157
#				  - removed /bin/ksh requirement
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   158
#				  - BUG: error messages were not reported in the log file
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   159
#				  - made seabed detection code more flexible
28
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   160
#				  - made reference-layer w_ocean warning more severe
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   161
#				  - BUG: info() did not write anything into logfile when format string was used
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   162
#				  - BUG: LADCP_lastBin was set 1 too low
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   163
#	Apr 20, 2015: - improved comments
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   164
#				  - improved diagnostic messages (warning on missing CTD temp)
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   165
#				  - added support for empirical backscatter correction
29
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   166
#	Apr 21, 2015: - improved screen log output
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   167
#	Apr 22, 2015: - BUG: $realLastGoodEns could be undefined, breaking plotting routines
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   168
#	Apr 24, 2015: - removed @ARGS
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   169
#				  - added %profile_id
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   170
#	May 13, 2015: - loosened "insufficient valid velocities" test for short casts
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   171
#	May 15, 2015: - added $min_valid_vels
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   172
#				  - BUG: LADCP_atbottom could be less than firstGoodEns
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   173
#	May 18, 2015: - added %LADCP_pulse_length, %dnXX
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   174
#	May 20, 2015: - added $PROF as newer alternative to $STN
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   175
#				  - replaced "require ProcessingParams" by "do ProcessingParams"
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   176
#	Jun 15, 2015: - clarified warning message
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   177
#	Jul 26, 2015: - added %output_grid_dz %output_grid_minsamp for use by [LADCP_w_regrid]
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   178
# 				  - began work on support for [libGMT.pl]
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   179
#				  - -v usage message had wrong default
30
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
   180
#				  - added $outGrid_firstBin & $outGrid_lastBin
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
   181
#	Jul 28, 2015: - added GMT plot support for all @out_ lists
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
   182
#	Jul 29, 2015: - continue adaptation of code for new plotting system
31
d0ae3cb99021 DoMORE-2
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
   183
#	Jul 30, 2015: - cosmetics
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   184
#	Sep  3, 2015: - changed out_w to out_wsamp
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   185
#	Sep 26, 2015: - replaced numberp($water_depth) by defined($water_depth) for consistency
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   186
#				  - implemented secondary sidelobe editing
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   187
#				  - allow for -h <filename>
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   188
#				  - allow $ID as alias for $PROF and $STN
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   189
#	Sep 27, 2015: - BUG: -h filename was broken when water_depth is not known
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   190
#	Oct 12, 2015: - upgraded missing water-depth warnings to L2
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   191
#				  - added -V)ersion
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   192
#                 - require ANTSlibs V6.2 for release
33
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   193
#   Oct 13, 2015: - adapted to [version.pl]
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   194
#	Nov 25, 2015: - made warning disappear on setting $ANTS_TOOLS_AVAILABLE
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   195
#	Nov 27, 2015: - changed RDI_BB_READ.pl to RDI_PD0_IO.pl
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   196
#	Jan  4, 2016: - decreased default vertical resolution to 20m
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   197
#	Jan  5, 2016: - adapted to [ADCP_tools_lib.pl]
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   198
#	Jan 22, 2016: - updated for improved mean_residuals plot
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   199
#				  - added per-bin residual quality check
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   200
#	Jan 25, 2016: - added antsAddParams() with version number
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   201
#	Jan 26, 2016: - added %processing_params, many others
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   202
#				  - expunged -d
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   203
#				  - implemented outGrid_firstBin eq '*' (also lastBin)
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   204
#	Jan 27, 2016: - BUG: outGrid_lastBin eq '*' did not work
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   205
#				  - removed large ref-lr w warning
30
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
   206
# HISTORY END
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   207
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   208
# CTD REQUIREMENTS
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   209
#	- elapsed		elapsed seconds; see note below
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   210
#	- depth
19
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
   211
#	- ss			sound speed
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   212
#	- w				ddepth/dt
28
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   213
#	- temp			OPTIONAL; used for backscatter calculation
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   214
#	- %lat/%lon		OPTIONAL
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   215
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   216
# 2-BEAM SOLUTIONS
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   217
#	- for beam-coordinate data, two separate two-beam solutions (w12 & w34) are calculated
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   218
#	- discrepancies can be indicative of package wake effects (e.g. MIXET data)
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   219
#	- for earth-coordinate data, w12 and w34 are simply copies of w
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   220
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   221
# NUMERICAL OPTIONS
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   222
#	- the first option in the list cannot be numerical!
19
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
   223
#	- if need be, use -v 1 as a dummy option
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   224
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   225
# ELAPSED TIMES
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   226
#	- there are 2 different elapsed times used in this program:
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   227
#		1) elapsed based on firstgoodens in the LADCP time series
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   228
#		2) CTD elapsed time
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   229
#	- CTD elapsed time does not have to start with zero!
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   230
#	- 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
   231
#	  3 significant digits, causing significant jitter in dt; however,
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   232
#	  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
   233
#	  assuming a 24Hz sampling rate and no record drop; therefore,
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   234
#	  it is best to calculate elapsed time as %RECNO/24
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   235
#	- 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
   236
#	  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
   237
#	  from the uplooker and downlooker-derived vertical velocity
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   238
#	  profiles
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   239
#	- the .TL files use the LADCP elapsed time in output; as a result,
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   240
#	  the DL/UL .TL files have different time axes!
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   241
#	- 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
   242
#	  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
   243
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   244
# BINNED-PROFILE OUTPUT NOTES
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   245
#	- residuals are calculated with respect to down-/upcast medians
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   246
#	- w12 and w34 2-beam solutions are reported without considering
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   247
#	  -k (min samples)
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   248
#	- equivalence, assuming -o 10:
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   249
#		1) 004DL.prof dc_w depth
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   250
#		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
   251
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   252
# VELOCITY AMBIGUITY ERRORS
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   253
#	- 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
   254
#	  ambiguity velocity errors, reveal that -m 1 catches those errors
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   255
#	  quite nicely
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   256
#	- 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
   257
#	  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
   258
23
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 21
diff changeset
   259
($ANTS) 	  = (`which ANTSlib`   =~ m{^(.*)/[^/]*$});
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 21
diff changeset
   260
($ADCP_TOOLS) = (`which mkProfile` =~ m{^(.*)/[^/]*$});
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 21
diff changeset
   261
($WCALC) 	  = ($0                =~ m{^(.*)/[^/]*$});
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 21
diff changeset
   262
$WCALC = '.' if ($WCALC eq '');
33
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   263
$ANTS_TOOLS_AVAILABLE = (`which list 2>/dev/null` ne '');
23
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 21
diff changeset
   264
19
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
   265
die("$0: Generic Mapping Tools (GMT) required but not found (bad \$PATH?)\n")
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
   266
	unless (`which psxy` ne '');
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
   267
die("$0: ANTSlib required but not found (bad \$PATH?)\n")
23
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 21
diff changeset
   268
	unless ($ANTS ne '');
19
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
   269
die("$0: ADCP Tools required but not found (bad \$PATH?)\n")
23
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 21
diff changeset
   270
	unless ($ADCP_TOOLS ne '');
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   271
33
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   272
require "$WCALC/version.pl";
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   273
require "$WCALC/edit_data.pl";
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   274
require "$WCALC/time_series.pl";
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   275
require "$WCALC/time_lag.pl";
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   276
require "$WCALC/find_seabed.pl";
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   277
require "$WCALC/svel_corrections.pl";
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   278
require "$WCALC/acoustic_backscatter.pl";
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   279
require "$WCALC/bottom_tracking.pl";
33
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   280
require "$ANTS/ants.pl";
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   281
require "$ANTS/libstats.pl";
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   282
require "$ADCP_TOOLS/ADCP_tools_lib.pl";
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   283
&antsAddParams('LADCP_w_ocean',"Version $VERSION");
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   284
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   285
use IO::Handle;
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   286
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   287
my($TINY) = 1e-16;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   288
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   289
#------
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   290
# Usage
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   291
#------
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   292
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   293
$antsParseHeader = 0;
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   294
&antsUsage('3:4a:b:c:e:g:h:i:k:m:n:o:p:qs:t:uv:Vw:x:',0,
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   295
	'[print software -V)ersion] [-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
   296
	'[-q)uick (no single-ping denoising)]',
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   297
    '[require -4)-beam solutions] [apply beamvel-m)ask <file> if it exists]',
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   298
	'[valid LADCP -b)ins <bin[2],bin[*]>',
19
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
   299
	'[-c)orrelation <min[70]>] [-t)ilt <max[10deg]> [-e)rr-vel <max[0.1m/s]>]',
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   300
	'[-h water <depth|filename>]',
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   301
	'[max LADCP time-series -g)ap <length[60s]>]',
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   302
	'[-i)nitial CTD time offset <guestimate> [-u)se as final]]',
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   303
	'[calculate -n) <lags,lags[10,100]>] [lag -w)indow <sz,sz[240s,20s]>] [lag-p)iece <CTD_elapsed_min|+[,...]>]',
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   304
	'[require top-3) lags to account for <frac[0.6]> of all]',
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   305
	'[pressure-sensor -a)cceleration correction <residual/CTD_w_tt>]',
33
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   306
	'[-o)utput bin <resolution[20m]>] [-k) require <min[20]> samples]',
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   307
	'[e-x)ecute <perl-expr>]',
29
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   308
	'<profile-id> [run-label]');
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   309
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   310
	if ($opt_V) {
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   311
		printf(STDERR "+-------------------------+\n");
33
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   312
		printf(STDERR "| LADCP_w Software V%s   |\n",$VERSION);
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   313
		printf(STDERR "|(c) 2015- A.M. Thurnherr |\n");
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   314
		printf(STDERR "+-------------------------+\n");
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   315
		exit(0);
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   316
	}
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   317
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   318
	&antsUsageError() if ($opt_u && !defined($opt_i));
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   319
	&antsUsageError() unless (@ARGV==1 || @ARGV==2);
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   320
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   321
	&antsCardOpt(\$opt_s,0);												# skip # initial ensembles
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   322
	$opt_p = '+' unless defined($opt_p);									# separate uc/dc time lagging
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   323
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   324
	&antsFloatOpt(\$opt_a,1);												# pressure acceleration correction
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   325
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   326
	$ID = $PROF = $STN = &antsCardArg();									# station id ($STN for compatibility)
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   327
	if (@ARGV) {															# run label
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   328
		$RUN = $ARGV[0];
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   329
		shift;
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   330
	} else {
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   331
		$RUN = 'profiles';
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   332
	}
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   333
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   334
#-----------------------------
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   335
# 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
   336
#-----------------------------
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   337
require "$WCALC/defaults.pl";											# load default/option parameters
29
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   338
do "$processing_param_file";											# load processing parameters
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   339
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   340
$processing_options = "-k $opt_k -o $opt_o -c $opt_c -t $opt_t -e $opt_e -g $opt_g -3 $opt_3";
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   341
$processing_options .= "-i $opt_i" if defined($opt_i);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   342
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   343
if (defined($opt_x)) {													# eval cmd-line expression to override anything
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   344
	$processing_options .= " -x $opt_x";
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   345
	eval($opt_x);
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   346
}
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   347
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   348
if ($opt_4) {															# disallow 3-beam solutions
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   349
	$processing_options .= " -4";
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   350
	$RDI_Coords::minValidVels = 4;
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   351
}
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   352
	
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   353
($LADCP_firstBin,$LADCP_lastBin) = split(',',$opt_b);					# select valid bins
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   354
	croak("$0: cannot decode -b $opt_b\n")
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   355
    	unless (numberp($LADCP_firstBin) &&
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   356
        	    ($LADCP_lastBin eq '*' || numberp($LADCP_lastBin)));
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   357
$processing_options .= " -b $opt_b";
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   358
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   359
$outGrid_firstBin = $LADCP_firstBin if ($outGrid_firstBin eq '*');		# default bins to use in gridded output
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   360
$outGrid_lastBin  = $LADCP_lastBin  if ($outGrid_lastBin  eq '*');		# NB: can still be '*'!!!
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   361
        	    
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   362
@number_of_timelag_windows = split(',',$opt_n);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   363
	croak("$0: cannot decode -n $opt_n\n")
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   364
		unless numberp($number_of_timelag_windows[0]) && numberp($number_of_timelag_windows[1]);
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   365
$processing_options .= " -n $opt_n";
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   366
@length_of_timelag_windows = split(',',$opt_w);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   367
	croak("$0: cannot decode -w $opt_w\n")
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   368
		unless numberp($length_of_timelag_windows[0]) && numberp($length_of_timelag_windows[1]);
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   369
$processing_options .= " -w $opt_w";
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   370
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   371
croak("$0: \$out_basename undefined\n")									# all plotting routines use this
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   372
	unless defined($out_basename);
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   373
&antsAddParams('processing_options',$processing_options);
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
&antsAddParams('out_basename',$out_basename);
29
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   375
&antsAddParams('profile_id',$PROF,'run_label',$RUN);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   376
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   377
#----------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   378
# Screen Logging
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   379
#	- warning levels:
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   380
#		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
   381
#		1 may be somewhat important
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   382
#		2 important
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   383
#----------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   384
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   385
open(LOGF,">$out_log") || croak("$out_log: $!\n")
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   386
	if defined($out_log);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   387
LOGF->autoflush(1);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   388
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   389
sub progress(@)
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   390
{
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   391
	printf(LOGF @_) if defined($out_log);
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   392
	printf(STDERR @_) if ($opt_v > 1);
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   393
}
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   394
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   395
sub info(@)
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   396
{
28
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   397
	print(LOGF "\t"),printf(LOGF @_) if defined($out_log);
29
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   398
	printf(STDERR @_)  if ($opt_v > 1);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   399
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   400
	
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   401
sub warning(@)
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   402
{
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   403
	my($lvl,@msg) = @_;
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   404
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   405
	if (defined($out_log)) {
29
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   406
		print(LOGF "\nWARNING (L$lvl): ");
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   407
		printf(LOGF @msg);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   408
		print(LOGF "\n");
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   409
	}
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   410
	return if ($opt_v == 0);
29
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   411
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   412
	if ($opt_v == 1) {
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   413
		print(STDERR "$LADCP_file: WARNING (L$lvl): ");
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   414
		printf(STDERR @msg);
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   415
	} else {
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   416
		print(STDERR "\n-------------\nWARNING (L$lvl): ");
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   417
		printf(STDERR @msg);
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   418
		print(STDERR "-------------\n\n")
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   419
	}
0
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
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   422
sub error($)
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   423
{
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   424
	print(LOGF "ABORT: @_") if defined($out_log);
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   425
	croak("ABORT: @_");
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   426
}
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   427
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   428
sub debugmsg(@)
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   429
{ printf(STDERR @_) if ($opt_v > 2); }
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   430
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   431
#----------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   432
# Read LADCP data
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
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   435
progress("Reading LADCP data from <$LADCP_file>...\n");
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   436
readData($LADCP_file,\%LADCP);
19
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
   437
progress("\t%d ensembles\n",scalar(@{$LADCP{ENSEMBLE}}));
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   438
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   439
error("$LADCP_file: not enough LADCP bins ($LADCP{N_BINS}) for choice of -r\n")
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   440
	unless ($LADCP{N_BINS} >= $refLr_lastBin);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   441
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   442
error("$0: first reference-layer bin outside valid range\n")
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   443
	unless ($refLr_firstBin>=1 && $refLr_firstBin<=$LADCP{N_BINS});
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   444
error("$0: last reference-layer bin outside valid range\n")
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   445
	unless ($refLr_lastBin>=1 && $refLr_lastBin<=$LADCP{N_BINS});
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   446
error("$0: first reference-layer bin > last reference-layer bin\n")
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   447
	unless ($refLr_firstBin <= $refLr_lastBin);
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   448
&antsAddParams('refLr_firstBin',$refLr_firstBin,'refLr_lastBin',$refLr_lastBin);	
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   449
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   450
$LADCP_lastBin 	 = $LADCP{N_BINS} if ($LADCP_lastBin eq '*');
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   451
$outGrid_lastBin = $LADCP{N_BINS} if ($outGrid_lastBin eq '*');
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   452
error("$0: first valid LADCP bin outside valid range\n")
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   453
	unless ($LADCP_firstBin>=1 && $LADCP_firstBin<=$LADCP{N_BINS});
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   454
error("$0: last valid LADCP bin outside valid range\n")
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   455
	unless ($LADCP_lastBin>=1 && $LADCP_lastBin<=$LADCP{N_BINS});
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   456
error("$0: first valid LADCP bin > last valid LADCP bin\n")
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   457
	unless ($LADCP_firstBin <= $LADCP_lastBin);
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   458
&antsAddParams('LADCP_firstBin',$LADCP_firstBin,'LADCP_lastBin',$LADCP_lastBin);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   459
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   460
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
   461
	unless ($refLr_firstBin >= $LADCP_firstBin);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   462
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
   463
	unless ($refLr_lastBin <= $LADCP_lastBin);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   464
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   465
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
   466
	if ($LADCP{BLANKING_DISTANCE}<$LADCP{BIN_LENGTH} && $refLr_firstBin==1);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   467
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   468
&antsAddParams('ADCP_bin_length',$LADCP{BIN_LENGTH},
29
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   469
			   'ADCP_pulse_length',$LADCP{TRANSMITTED_PULSE_LENGTH},
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   470
			   'ADCP_frequency',$LADCP{BEAM_FREQUENCY},
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   471
			   'ADCP_blanking_distance',$LADCP{BLANKING_DISTANCE});
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   472
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   473
#------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   474
# Edit beam-velocity data
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   475
#	0) beam-vel mask on -m
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   476
#	1) correlation threshold
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   477
#------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   478
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   479
if ($LADCP{BEAM_COORDINATES}) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   480
	progress("Editing beam-velocity data...\n");
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   481
	
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   482
	if (defined($opt_m) && -r $opt_m) {
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   483
		progress("\tmasking beam velocities according to $opt_m:");
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   484
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   485
		my($nee) = 0;
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   486
		open(BVM,$opt_m) || die("$opt_m: $!\n");
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   487
		while (<BVM>) {
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   488
			s/#.*//;
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   489
			s/^\s*$//;
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   490
			next if ($_ eq '');
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   491
			my($fe,$te,$db) = split;
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   492
			die("$opt_m: cannot decode $_\n")
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   493
				unless (numberp($fe) && numberp($te) && $te>=$fe && $db>=1 && $db<=4);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   494
			die("$0: assertion failed")
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   495
				unless ($LADCP{ENSEMBLE}[$fe-1]->{NUMBER} == $fe &&
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   496
						$LADCP{ENSEMBLE}[$te-1]->{NUMBER} == $te);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   497
			for (my($ens)=$fe-1; $ens<=$te-1; $ens++) {
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   498
				$nee++;
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   499
				for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   500
					undef($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$db-1]);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   501
				}
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   502
			}
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   503
		}
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   504
		print(STDERR " $nee ensembles edited\n");
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   505
		close(BVM);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   506
	}
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   507
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   508
	$nvv = $cte = 0;
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   509
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   510
	if ($pitch_bias || $roll_bias || $heading_bias) {
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   511
		&antsAddParams('pitch_bias',$pitch_bias,
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   512
					   'roll_bias',$roll_bias,
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   513
					   'heading_bias',$heading_bias);
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   514
		for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   515
			correctAttitude($ens,$pitch_bias,$roll_bias,$heading_bias);
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   516
		}
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   517
	}
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   518
	for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   519
		$nvv += countValidBeamVels($ens);
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   520
		$cte += editCorr($ens,$opt_c);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   521
	}
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   522
	error("$LADCP_file: no valid data\n") unless ($nvv > 0);
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   523
	progress("\tcorrelation threshold (-c %d counts): %d velocites removed (%d%% of total)\n",$opt_c,$cte,round(100*$cte/$nvv));
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   524
#	progress("\tattitude threshold (-t %d deg): %d velocites removed (%d%% of total)\n",$opt_t,$pte,round(100*$pte/$nvv));
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   525
} else {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   526
	progress("Editing velocity data...\n");
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   527
	error("$LADCP_file: cannot apply beamvel-mask $opt_m to earth-coordinate data\n")
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   528
		if defined($opt_m);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   529
	$nvv = $cte = 0;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   530
	for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   531
		$nvv += countValidBeamVels($ens);
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   532
		$cte += editCorr_Earthcoords($ens,$opt_c);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   533
	}
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   534
	error("$LADCP_file: no valid data\n") unless ($nvv > 0);
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   535
	progress("\tcorrelation threshold (-c %d counts): %d velocites removed (%d%% of total)\n",$opt_c,$cte,round(100*$cte/$nvv));
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   536
#	progress("\tattitude threshold (-t %d deg): %d velocites removed (%d%% of total)\n",$opt_t,$pte,round(100*$pte/$nvv));
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   537
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   538
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   539
#-------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   540
# Calculate earth velocities
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   541
#	- 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
   542
#	  useless possibility that invalid bins are used for reflr calcs
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   543
#	- also calculate separate beam-pair velocities
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   544
#	- the UNEDITED velocities are saved for the BT calculations
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   545
#	  (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
   546
#	  been very useful so far)
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   547
#-------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   548
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   549
if ($LADCP{BEAM_COORDINATES}) {
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   550
	my($dummy);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   551
	progress("Calculating earth-coordinate velocities...\n");
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   552
	if ($bad_beam) {
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   553
		progress("\tdiscarding velocities from beam $bad_beam\n");
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   554
		&antsAddParams('bad_beam_discarded',$bad_beam);
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   555
	}
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   556
	$nvw = 0;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   557
	for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   558
		for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   559
			if ($bad_beam) {
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   560
				undef($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$bad_beam-1]);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   561
				undef($LADCP{ENSEMBLE}[$ens]->{BT_VELOCITY}[$bin][$bad_beam-1]);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   562
			}
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   563
			($LADCP{ENSEMBLE}[$ens]->{U}[$bin],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   564
			 $LADCP{ENSEMBLE}[$ens]->{V}[$bin],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   565
			 $LADCP{ENSEMBLE}[$ens]->{W}[$bin],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   566
			 $LADCP{ENSEMBLE}[$ens]->{ERRVEL}[$bin]) =
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   567
				velInstrumentToEarth(\%LADCP,$ens,
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   568
					velBeamToInstrument(\%LADCP,
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   569
										@{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]}));
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   570
			if (defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin])) {
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   571
				$per_bin_nsamp[$bin]++;
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   572
				$nvw++;
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   573
			}
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   574
			$LADCP{ENSEMBLE}[$ens]->{GIMBAL_PITCH} =
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   575
			 	gimbal_pitch($LADCP{ENSEMBLE}[$ens]->{PITCH},$LADCP{ENSEMBLE}[$ens]->{ROLL});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   576
			$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
   577
			$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
   578
			$LADCP{ENSEMBLE}[$ens]->{W_UNEDITED}[$bin] = $LADCP{ENSEMBLE}[$ens]->{W}[$bin];
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   579
			
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   580
			($dummy,$LADCP{ENSEMBLE}[$ens]->{W12}[$bin],
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   581
			 $dummy,$LADCP{ENSEMBLE}[$ens]->{W34}[$bin]) =
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   582
			 	velBeamToBPEarth(\%LADCP,$ens,@{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]});
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   583
		}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   584
	}
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   585
	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
   586
	progress("\t3-beam solutions : $RDI_Coords::threeBeam_1 " .
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   587
								  "$RDI_Coords::threeBeam_2 " .
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   588
								  "$RDI_Coords::threeBeam_3 " .
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   589
								  "$RDI_Coords::threeBeam_4\n")
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   590
	    unless ($opt_4);
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   591
} else { # Earth Coordinates
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   592
	progress("Counting valid vertical velocities...\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   593
	$nvw = 0;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   594
	for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   595
		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
   596
			($LADCP{ENSEMBLE}[$ens]->{U}[$bin],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   597
			 $LADCP{ENSEMBLE}[$ens]->{V}[$bin],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   598
			 $LADCP{ENSEMBLE}[$ens]->{W}[$bin],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   599
			 $LADCP{ENSEMBLE}[$ens]->{ERRVEL}[$bin]) = @{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]};
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   600
			if (defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin])) {
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   601
				$per_bin_nsamp[$bin]++;
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   602
				$nvw++;
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   603
			}
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   604
			$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
   605
			$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
   606
			$LADCP{ENSEMBLE}[$ens]->{W_UNEDITED}[$bin] = $LADCP{ENSEMBLE}[$ens]->{W}[$bin];
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   607
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   608
			$LADCP{ENSEMBLE}[$ens]->{W12}[$bin] = $LADCP{ENSEMBLE}[$ens]->{W34}[$bin] = $LADCP{ENSEMBLE}[$ens]->{W}[$bin];
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   609
		}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   610
	}
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   611
	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
   612
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   613
29
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   614
error("$LADCP_file: insufficient valid velocities\n") unless ($nvw >= $min_valid_vels);
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   615
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   616
#----------------------------------------------
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   617
# STEP: Edit earth-coordinate -velocity data
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   618
#	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
   619
#	2) vertical-velocity outliers
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   620
#	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
   621
#----------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   622
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   623
progress("Editing earth-coordinate velocity data...\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   624
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   625
&antsAddParams('per_ens_outliers_mad_limit',$per_ens_outliers_mad_limit)
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   626
&antsAddParams('farthest_valid_bins_truncated',$truncate_farthest_valid_bins)
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   627
	if ($truncate_farthest_valid_bins);
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   628
$evrm = $trrm = $worm = 0;
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   629
for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   630
	$evrm += editErrVel($ens,$opt_e);
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   631
	$worm += editWOutliers($ens,$per_ens_outliers_mad_limit);
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   632
	$trrm += editTruncRange($ens,$truncate_farthest_valid_bins) if ($truncate_farthest_valid_bins);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   633
}
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   634
progress("\terror-velocity threshold (-e %.2f m/s): %d velocites removed (%d%% of total in bins $LADCP_firstBin-$LADCP_lastBin)\n",
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   635
	$opt_e,$evrm,round(100*$evrm/$nvw));
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   636
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
   637
	$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
   638
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
   639
	$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
   640
		if ($truncate_farthest_valid_bins > 0);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   641
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
# Calculate LADCP time series
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   644
#----------------------------
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
progress("Calculating LADCP time-series...\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   647
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   648
($firstGoodEns,$lastGoodEns,$LADCP_atbottom,$LADCP_w_gap_time) =
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   649
	calcLADCPts(\%LADCP,$opt_s,$refLr_firstBin,$refLr_lastBin,$opt_g);
29
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   650
error("$LADCP_file: insufficient valid data\n")
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   651
	unless defined($firstGoodEns) && ($lastGoodEns>$firstGoodEns) && ($LADCP_atbottom>=$firstGoodEns);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   652
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   653
my($cast_duration) = $LADCP{ENSEMBLE}[$lastGoodEns]->{ELAPSED} -
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   654
				     $LADCP{ENSEMBLE}[$firstGoodEns]->{ELAPSED};
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   655
error("$0: implausibly short cast ($cast_duration seconds)\n")
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   656
	unless ($cast_duration > 600);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   657
29
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   658
my($year) = $LADCP{ENSEMBLE}[$firstGoodEns]->{YEAR} % 100;
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   659
&antsAddParams("dn$year",$LADCP{ENSEMBLE}[$firstGoodEns]->{DAYNO});
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   660
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   661
$LADCP{MEAN_DT} = $cast_duration / ($lastGoodEns-$firstGoodEns-1);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   662
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   663
progress("\tStart of cast     : %s (#%5d)\n",
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   664
					$LADCP{ENSEMBLE}[$firstGoodEns]->{TIME},
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   665
					$LADCP{ENSEMBLE}[$firstGoodEns]->{NUMBER});
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   666
progress("\tBottom of cast    : %s (#%5d) @ dz=%6dm\n",
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   667
					$LADCP{ENSEMBLE}[$LADCP_atbottom]->{TIME},
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   668
					$LADCP{ENSEMBLE}[$LADCP_atbottom]->{NUMBER},
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   669
					$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
   670
progress("\tEnd of cast       : %s (#%5d) @ dz=%6dm\n",
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   671
					$LADCP{ENSEMBLE}[$lastGoodEns]->{TIME},
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   672
					$LADCP{ENSEMBLE}[$lastGoodEns]->{NUMBER},
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   673
					$LADCP{ENSEMBLE}[$lastGoodEns]->{DEPTH});
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   674
progress("\tCast duration     : %.1f hours (pinging for %.1f hours)\n",
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   675
					$cast_duration / 3600,
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   676
					($LADCP{ENSEMBLE}[$#{$LADCP{ENSEMBLE}}]->{UNIX_TIME} -
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   677
						$LADCP{ENSEMBLE}[0]->{UNIX_TIME}) / 3600);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   678
progress("\tMean ping interval: %.1f seconds\n",$LADCP{MEAN_DT});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   679
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
   680
if (@out_LADCPtis) {
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
   681
	progress("Writing LADCP-timeseries to ");
23
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 21
diff changeset
   682
	@antsNewLayout = ('ensemble','elapsed','reflr_w','reflr_w.stddev','reflr_w.nsamp','depth');
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
   683
	
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
   684
	foreach my $of (@out_LADCP) {
26
b89d4b01fcc5 after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 25
diff changeset
   685
	    progress("<$of> ");
30
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
   686
		my($plot,$out) = ($of =~ /^([^\(]+)\(([^\)]+)\)$/);						# plot_sub(out_file)
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
   687
		if (defined($out)) {
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
   688
			require "$WCALC/${plot}.pl";
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
   689
			&{$plot}($out);
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
   690
			next;
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
   691
		}
26
b89d4b01fcc5 after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 25
diff changeset
   692
	    $of = ">$of" unless ($of =~ /^$|^\s*\|/);
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   693
		open(STDOUT,$of) || error("$of: $!\n");
26
b89d4b01fcc5 after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 25
diff changeset
   694
		undef($antsActiveHeader) unless ($ANTS_TOOLS_AVAILABLE);
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
   695
		for (my($ens)=$firstGoodEns; $ens<=$lastGoodEns; $ens++) {
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
   696
			&antsOut($LADCP{ENSEMBLE}[$ens]->{NUMBER},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
   697
					 $LADCP{ENSEMBLE}[$ens]->{ELAPSED},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
   698
					 $LADCP{ENSEMBLE}[$ens]->{REFLR_W},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
   699
					 $LADCP{ENSEMBLE}[$ens]->{REFLR_W_STDDEV},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
   700
					 $LADCP{ENSEMBLE}[$ens]->{REFLR_W_NSAMP},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
   701
					 $LADCP{ENSEMBLE}[$ens]->{DEPTH});
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
   702
		}
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
   703
	    &antsOut('EOF'); open(STDOUT,'>&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
   704
	}
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
   705
	progress("\n");
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   706
}
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   707
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   708
error("deepest depth is at end of cast (no upcast data)\n")
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   709
	if ($lastGoodEns-$LADCP_atbottom < 100);
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   710
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   711
#----------------------------------------------------------------------
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   712
# More editing
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   713
#	- this requires ${first,last}GoodEns to be known
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   714
#	- TILT field is set as a side-effect
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   715
#----------------------------------------------------------------------
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   716
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   717
progress("Editing additional earth-coordinate velocity data...\n");
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   718
&antsAddParams('per_bin_valid_frac_lim',$per_bin_valid_frac_lim);
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   719
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   720
my($first_bad_bin);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   721
for (my($bin)=$LADCP_firstBin-1; $bin<$LADCP_lastBin-1; $bin++) {
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   722
	next unless ($per_bin_nsamp[$bin]/($lastGoodEns-$firstGoodEns) < $per_bin_valid_frac_lim);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   723
	$first_bad_bin = $bin;
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   724
	last;
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   725
}
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   726
15
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   727
$fprm = $pte = 0;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   728
for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   729
	$pte += editTilt($ens,$opt_t);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   730
	$fprm += editFarBins($ens,$first_bad_bin) if defined($first_bad_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
   731
}
15
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   732
progress("\tattitude threshold (max_tilt = %d deg): %d velocites removed (%d%% of total)\n",
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   733
	$opt_t,$pte,round(100*$pte/$nvv));
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   734
progress("\tvelocities beyond bin $first_bad_bin (<%d%% valid values): %d velocites removed (%d%% of total in bins $LADCP_firstBin-$LADCP_lastBin)\n",
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   735
	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
   736
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   737
#--------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   738
# Read CTD data
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   739
#--------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   740
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   741
progress("Reading CTD data from <$CTD_file>...\n");
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   742
open(STDIN,$CTD_file) || error("$CTD_file: $!\n");
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   743
error("$CTD_file: no data\n") unless (&antsIn());
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   744
undef($antsOldHeaders);
28
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   745
19
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
   746
&antsAddParams('lat',$P{lat}) if defined($P{lat});
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   747
&antsAddParams('lon',$P{lon}) if defined($P{lon});
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   748
28
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   749
($CTD_elapsed,$CTD_depth,$CTD_svel,$CTD_w) = &fnr('elapsed','depth','ss','w');
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   750
$CTD_temp = &fnrNoErr('temp');
29
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   751
warning(0,"no CTD temperature --- using ADCP temperature instead => Sv degraded!\n",$s)
28
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   752
   unless defined($CTD_temp);
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   753
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   754
$CTD_maxdepth = -1;
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   755
do {																		# read data
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   756
	error("$0: cannot deal with non-numeric CTD elapsed time\n")
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   757
		unless &antsNumbers($CTD_elapsed);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   758
	push(@{$CTD{ELAPSED}},$ants_[0][$CTD_elapsed]);
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   759
	push(@{$CTD{DEPTH}},  $ants_[0][$CTD_depth]);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   760
	push(@{$CTD{SVEL}},   $ants_[0][$CTD_svel]);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   761
	push(@{$CTD{W}},      $ants_[0][$CTD_w]);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   762
	push(@{$CTD{TEMP}},	  $ants_[0][$CTD_temp]) if defined($CTD_temp);
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   763
	if ($ants_[0][$CTD_depth] > $CTD_maxdepth) {
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   764
		$CTD_maxdepth = $ants_[0][$CTD_depth];
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   765
		$CTD_atbottom = $#{$CTD{DEPTH}};
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   766
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   767
} while (&antsIn());
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   768
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   769
$CTD{DT} = ($CTD{ELAPSED}[$#{$CTD{ELAPSED}}] - $CTD{ELAPSED}[0]) / $#{$CTD{ELAPSED}};
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   770
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
   771
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   772
$CTD{W_t}[0]  = $CTD{W_t} [@{$CTD{ELAPSED}}] = nan;							# calculate w-derivatives
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   773
$CTD{W_tt}[0] = $CTD{W_tt}[@{$CTD{ELAPSED}}] = nan;
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   774
for (my($s)=1; $s<@{$CTD{ELAPSED}}-1; $s++) {								# centered differences for both
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   775
	$CTD{W_t} [$s] = ($CTD{W}[$s+1] - $CTD{W}[$s-1]) / (2*$CTD{DT});
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   776
	$CTD{W_tt}[$s] = ($CTD{W}[$s+1] + $CTD{W}[$s-1] - 2*$CTD{W}[$s]) / $CTD{DT}**2;
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   777
}
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   778
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   779
error("$0: CTD start depth must be numeric\n")
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   780
	unless numberp($CTD{DEPTH}[0]);
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   781
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   782
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
   783
progress("\tmax depth   = %dm (# $CTD_atbottom)\n",$CTD_maxdepth);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   784
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   785
#--------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   786
# Construct sound-speed correction profile from CTD 1Hz downcast data
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   787
#	very simple algorithm that stores the last value found
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   788
#	in each 1m bin
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   789
# For PPI filtering, a sound speed profile without gaps is required.
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   790
#--------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   791
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   792
progress("Constructing sound-speed correction profile\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   793
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   794
my($scans_per_sec) = int(1/$CTD{DT}+0.5);
15
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   795
my($min_depth) = 9e99;
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   796
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
   797
	next unless ($CTD{DEPTH}[$s] >= 0 && numberp($CTD{SVEL}[$s]));
19
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
   798
	my($d) = int($CTD{DEPTH}[$s]);
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
   799
	$min_depth = $d if ($d < $min_depth);
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
   800
	$sVelProf[$d] = $CTD{SVEL}[$s];
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   801
}
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   802
while ($min_depth > 0) {													# fill surface gap
15
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   803
	$sVelProf[$min_depth-1] = $sVelProf[$min_depth];
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   804
	$min_depth--;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   805
}
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   806
for (my($d)=$min_depth+1; $d<=$#sVelProf; $d++) {							# fill interior gaps
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   807
	$sVelProf[$d] = $sVelProf[$d-1]
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   808
		unless defined($sVelProf[$d]);
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   809
}
19
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
   810
	
18
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 17
diff changeset
   811
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   812
#-------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   813
# Determine time lag
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   814
#-------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   815
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   816
if (defined($opt_i)) {
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   817
	progress("Setting initial time lag...\n");
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   818
	$CTD{TIME_LAG} = $opt_i;
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   819
	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
   820
} else {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   821
	progress("Guestimating time lag...\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   822
	
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   823
	my($CTD_10pct_down) = 0;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   824
	my($LADCP_10pct_down) = $firstGoodEns;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   825
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   826
	$CTD_10pct_down++
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   827
		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
   828
	$LADCP_10pct_down++
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   829
		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
   830
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   831
	$CTD{TIME_LAG} =
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   832
		$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
   833
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   834
	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
   835
	    $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
   836
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   837
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   838
if ($opt_u) {
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   839
	progress("\tskipping time lagging (-u)\n");
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   840
} else {
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   841
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   842
	#------------------------
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   843
	# stage 1: 1Hz; full cast
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   844
	#------------------------
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   845
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   846
	$CTD{TIME_LAG} =														
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   847
		calc_lag($number_of_timelag_windows[0],$length_of_timelag_windows[0],
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   848
				 int(1/$CTD{DT}+0.5),$firstGoodEns,$lastGoodEns);
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   849
	error("$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
   850
	progress("\telapsed(CTD) ~ elapsed(LADCP) + %.2fs\n",$CTD{TIME_LAG});
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   851
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   852
	#---------------------------------
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   853
	# stage 2: piece-wise time lagging
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   854
	#---------------------------------
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   855
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   856
	my(@splits);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   857
	push(@splits,$firstGoodEns);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   858
	foreach my $s (split(/,/,$opt_p)) {
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   859
		if ($s eq '+') {
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   860
			push(@splits,$LADCP_atbottom);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   861
		} elsif (numberp($s)) {												# find ens for given LADCP elapsed time in min
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   862
			my($ela) = $s*60;
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   863
			my($ens) = $firstGoodEns + round($ela / $LADCP{MEAN_DT});		# first, guess
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   864
			while ($LADCP{ENSEMBLE}[$ens]->{ELAPSED} > $ela) { $ens--; }	# then, correct
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   865
			while ($LADCP{ENSEMBLE}[$ens]->{ELAPSED} < $ela) { $ens++; }
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   866
			push(@splits,$ens);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   867
		} else {
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   868
			warning(2,"ignoring non-numeric -p argument %s",$s);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   869
		}
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   870
    }
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   871
	push(@splits,$lastGoodEns);
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
   872
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   873
	my($valid_lag);															# determine piece-wise lags
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   874
	while (@splits > 1) {
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   875
		push(@CTD_tl_fromEns,$splits[0]);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   876
		push(@CTD_tl_toEns,$splits[1]);
29
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   877
		debugmsg("lag($splits[0],$splits[1]) = ");
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   878
		my($lag) = calc_lag($number_of_timelag_windows[1],$length_of_timelag_windows[1],
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   879
							1,$splits[0],$splits[1]);
29
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   880
		debugmsg("$lag\n");									
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   881
		if (defined($lag)) {
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   882
			progress("\tcast-piece: elapsed(CTD) = elapsed(LADCP) + %.2fs\n",$lag);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   883
			push(@CTD_time_lag,$lag);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   884
			$valid_lag = $#CTD_time_lag;
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   885
		} else {
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   886
			progress("\tcast-piece: time-lagging failed\n");
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   887
			push(@CTD_time_lag,nan);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   888
		}
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   889
		shift(@splits);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   890
	}
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   891
			
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   892
	error("$0: Cannot proceed without at least one lag!\n")					# fill failed lag with surrounding data
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   893
		unless defined($valid_lag);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   894
	while ($valid_lag < $#CTD_time_lag) {									# forward
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   895
		$CTD_time_lag[$valid_lag+1] = $CTD_time_lag[$valid_lag];
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   896
		$valid_lag++;
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   897
	}
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   898
	while ($valid_lag > 0) {												# backward
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   899
		$CTD_time_lag[$valid_lag-1] = $CTD_time_lag[$valid_lag]
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   900
			unless (numberp($CTD_time_lag[$valid_lag-1]));
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   901
		$valid_lag--;
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   902
	}
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   903
}
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   904
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   905
&antsAddParams('CTD_time_lags',"@CTD_time_lag");
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   906
undef($CTD{TIME_LAG}); 														# to avoid confusion, clear old 1Hz-based lag
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   907
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   908
#------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   909
# Merge CTD with LADCP data
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   910
#	- after this step, reflr w is sound-speed corrected!!!
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
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   913
progress("Merging CTD with LADCP data...\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   914
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   915
&antsAddParams('w_max_lim',$w_max_lim);
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   916
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   917
my($cli) = 0;																	# current-lag index
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   918
my($lag) = $CTD_time_lag[$cli];													# current lag
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   919
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   920
for (my($skipped)=0,my($ens)=$firstGoodEns; $ens<=$lastGoodEns; $ens++) {
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   921
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   922
	if ($ens > $CTD_tl_toEns[$cli]) {											# use correct lag piece
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   923
		$cli++;
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   924
		die("assertion failed!\n\ttest: \$cli(=$cli) <= \$#CTD_time_lag\n")
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   925
			unless ($cli <= $#CTD_time_lag);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   926
		$lag = $CTD_time_lag[$cli];
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   927
	}
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   928
	
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   929
	my($scan) = 
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   930
		int(($LADCP{ENSEMBLE}[$ens]->{ELAPSED} + $lag - $CTD{ELAPSED}[0]) / $CTD{DT} + 0.5);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   931
	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
   932
		$skipped++;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   933
		$firstGoodEns = $ens+1;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   934
		next;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   935
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   936
	if ($skipped > 0) {
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   937
		$firstGoodEns++,$skipped++,next											# in gap
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   938
			unless defined($LADCP{ENSEMBLE}[$firstGoodEns]->{REFLR_W});
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   939
		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
   940
		$skipped = 0;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   941
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   942
	if ($scan > $#{$CTD{ELAPSED}}) {
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   943
		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
   944
		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
   945
			$lastGoodEns-$ens+1));
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   946
		$lastGoodEns = $ens-1;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   947
		last;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   948
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   949
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   950
	$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
   951
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   952
	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
   953
			&& numberp($CTD{DEPTH}[$scan])) {
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
   954
		$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
   955
	    $LADCP{ENSEMBLE}[$ens]->{REFLR_W} *= $CTD{SVEL}[$scan]/1500; 	# correct for sound-speed variations at source
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   956
		error(sprintf("\n$0: negative depth (%.1fm) in CTD file at elapsed(CTD) = %.1fs (use -d?)\n",
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   957
			$CTD{DEPTH}[$scan],$CTD{ELAPSED}[$scan]))
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   958
				unless ($CTD{DEPTH}[$scan] >= 0);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   959
		$LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH} = $CTD{DEPTH}[$scan];
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   960
		$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN} = $scan;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   961
		my($reflr_ocean_w) = $LADCP{ENSEMBLE}[$ens]->{REFLR_W} - $CTD{W}[$scan];
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
   962
		if (abs($reflr_ocean_w) <= $w_max_lim) {
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   963
			$sumWsq += &SQR($reflr_ocean_w);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   964
			$nWsq++;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   965
			if ($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH} > 100 &&
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   966
				$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
   967
					$sumWsqI += &SQR($reflr_ocean_w);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   968
					$nWsqI++;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   969
	        }
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   970
	    } else {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   971
	    	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
   972
	    }
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   973
	} else{
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   974
	    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
   975
	    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
   976
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   977
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   978
	
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   979
if ($nWsq > 0 && $nWsqI > 0) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   980
	&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
   981
	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
   982
						100*sqrt($sumWsq/$nWsq),100*sqrt($sumWsqI/$nWsqI));
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   983
#	if (sqrt($sumWsqI/$nWsqI) > 0.05) {
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   984
#		warning(0,"%.2f cm/s (large) reference-layer w_ocean away from boundaries\n",100*sqrt($sumWsqI/$nWsqI));
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   985
#	} els
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   986
	if (sqrt($sumWsqI/$nWsqI) > 0.15) {
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
   987
		warning(2,"%.2f cm/s (implausibly large) reference-layer w_ocean away from boundaries\n",100*sqrt($sumWsqI/$nWsqI));
28
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   988
	}
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   989
} elsif ($nWsq > 0) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   990
	&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
   991
	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
   992
} else {
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
   993
	error("$0: no valid vertical velocities\n");
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   994
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   995
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   996
#----------------------------------------------------------------------
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   997
# Calculate Volume Scattering Coefficients
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   998
#----------------------------------------------------------------------
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   999
28
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
  1000
progress("Calculating volume-scattering coefficients (Sv)...\n");
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1001
calc_backscatter_profs($firstGoodEns,$lastGoodEns);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1002
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1003
if (@nSv) {
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1004
	progress("\tapplying empirical Sv correction\n");
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1005
	correct_backscatter($firstGoodEns,$lastGoodEns);
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1006
}
28
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
  1007
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1008
#----------------------------------------------------------------------------
28
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
  1009
# Find Seabed & Edit data
15
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
  1010
#	1) contaminated by sidelobe reflection from seabed and sea surface
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
  1011
#	2) PPI 
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1012
#----------------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1013
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1014
croak("$0: conflicting water-depth information provided by user\n")
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1015
	if defined($opt_h) && defined($water_depth);
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1016
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1017
if (defined($opt_h)) {
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1018
	if (numberp($opt_h)) {
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1019
		$water_depth = $opt_h;
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1020
	} elsif (-f $opt_h) {
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1021
		open(WDF,$opt_h) || croak("$opt_h: $_\n");
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1022
		$water_depth = &antsFileScanParam(WDF,'water_depth');
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1023
		close(WDF);
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1024
		undef($water_depth) unless numberp($water_depth);
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1025
	}
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1026
}
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1027
	
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1028
die("assertion failed (water_depth = $water_depth)")
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1029
	unless (!defined($water_depth) || numberp($water_depth));
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1030
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1031
if ($LADCP{ENSEMBLE}[$LADCP_atbottom]->{XDUCER_FACING_DOWN} && !defined($water_depth)) {
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1032
	progress("Finding seabed...\n");
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1033
	($water_depth,$sig_water_depth) =
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1034
		find_backscatter_seabed($LADCP{ENSEMBLE}[$LADCP_atbottom]->{CTD_DEPTH});
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1035
	($water_depth_BT,$sig_water_depth_BT) =
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1036
		find_seabed(\%LADCP,$LADCP_atbottom,$LADCP{BEAM_COORDINATES});
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1037
	if (defined($water_depth) && defined($water_depth_BT)) {
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1038
		my($dd) = abs($water_depth_BT - $water_depth);
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1039
		warning(0,sprintf("Large instrument vs. backscatter-derived water-depth difference (%.1fm)\n",$dd))
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1040
			if ($dd > 10);
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1041
	}
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1042
	if (!$SS_use_BT && !defined($water_depth) && defined($water_depth_BT)) {
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1043
		warning(1,"using water_depth from ADCP BT data\n");
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1044
		$SS_use_BT = 1;
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1045
	}
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1046
	if ($SS_use_BT) {
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1047
		&antsAddParams('water_depth_from','BT_data');
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1048
		$water_depth = $water_depth_BT;
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1049
		$sig_water_depth = $sig_water_depth_BT;
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1050
    } else {
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1051
		&antsAddParams('water_depth_from','echo_amplitudes');
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1052
	}
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1053
}
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1054
	
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1055
if (defined($water_depth)) {
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1056
	if (defined($water_depth_BT)) {
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1057
		progress("\t%.1f(%.1f) m water depth (%.1f(%.1f)m from ADCP BT data)\n",
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1058
			$water_depth,$sig_water_depth,$water_depth_BT,$sig_water_depth_BT);
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1059
	} else {
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1060
		progress("\t%.1f(%.1f) m water depth\n",$water_depth,$sig_water_depth);
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1061
	}
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1062
	warning(1,sprintf("large uncertainty in water-depth estimation (%.1fm)\n",$sig_water_depth))
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1063
		if ($sig_water_depth > $LADCP{BIN_LENGTH});
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1064
	&antsAddParams('water_depth',$water_depth,'water_depth.sig',$sig_water_depth);
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1065
} else {
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1066
	warning(2,"unknown water depth --- cannot edit sidelobes or PPI near the seabed\n");
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1067
	&antsAddParams('water_depth','unknown','water_depth.sig','nan');
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1068
}
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1069
	
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1070
if ($LADCP{ENSEMBLE}[$LADCP_atbottom]->{XDUCER_FACING_DOWN}) {				# DOWNLOOKER
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1071
	&antsAddParams('ADCP_orientation','downlooker');
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1072
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1073
	if (defined($water_depth)) {
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1074
		progress("Editing data to remove sidelobe interference from seabed...\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1075
		($nvrm,$nerm) = editSideLobes($firstGoodEns,$lastGoodEns,$water_depth);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1076
		progress("\t$nvrm velocities from $nerm ensembles removed\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1077
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1078
		if ($sidelobe_editing_DL_surface) {
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1079
			progress("Editing data to remove sidelobe interference from sea surface...\n");
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1080
			($nvrm,$nerm) = editSideLobes($firstGoodEns,$lastGoodEns,undef);
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1081
	        progress("\t$nvrm velocities from $nerm ensembles removed\n");
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1082
	        &antsAddParams('sidelobe_editing','surface+seabed','vessel_draft',$vessel_draft);
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1083
	    } else {
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1084
	        &antsAddParams('sidelobe_editing','seabed');
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1085
	    }
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1086
19
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
  1087
		if ($PPI_editing) {
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1088
			&antsAddParams('PPI_editing','seabed');
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1089
			&antsAddParams('PPI_extend_upper_limit',$PPI_extend_upper_limit)
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1090
				if numberp($PPI_extend_upper_limit);
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
  1091
			progress("Editing data to remove PPI from seabed...\n");
19
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
  1092
			  progress("\tConstructing depth-average soundspeed profile...\n");
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1093
			  die("assertion failed") unless defined($water_depth);
19
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
  1094
			  my($dz) = $water_depth - $#sVelProf;							# $#sVelProf = max_depth(profile) in meters
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
  1095
			  my($sum) = $dz * $sVelProf[$#sVelProf];
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
  1096
			  $DASSprof[$#sVelProf] = $sum/$dz;
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
  1097
			  for (my($d)=$#sVelProf-1; $d>=0; $d--) {
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
  1098
			  	die("assertion failed (d=$d, #sVelProf=$#sVelProf)") unless numberp($sVelProf[$d]);
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
  1099
			  	$sum += $sVelProf[$d];
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
  1100
			  	$dz++;
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
  1101
				$DASSprof[$d] = $sum/$dz;
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
  1102
			  }
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
  1103
			($nvrm,$nerm) = editPPI($firstGoodEns,$lastGoodEns,$water_depth);
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
  1104
	        progress("\t$nvrm velocities from $nerm ensembles removed\n");
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
  1105
	    }
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1106
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1107
	
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1108
} else {																	# UPLOOKER
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1109
	&antsAddParams('ADCP_orientation','uplooker');
15
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
  1110
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1111
	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
  1112
	($nvrm,$nerm) = editSideLobes($firstGoodEns,$lastGoodEns,undef);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1113
	progress("\t$nvrm velocities from $nerm ensembles removed\n");
15
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
  1114
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1115
	if ($sidelobe_editing_UL_seabed) {
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1116
		if (defined($water_depth)) {
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1117
			progress("Editing data to remove sidelobe interference from seabed...\n");
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1118
			($nvrm,$nerm) = editSideLobes($firstGoodEns,$lastGoodEns,$water_depth);
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1119
        	progress("\t$nvrm velocities from $nerm ensembles removed\n");
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1120
        } else {
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1121
			warning(2,"unknown water depth --- cannot edit UL data for sidelobe interference from seabed\n");
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
  1122
        }
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1123
        &antsAddParams('sidelobe_editing','surface+seabed','vessel_draft',$vessel_draft);
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1124
    } else {
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1125
        &antsAddParams('sidelobe_editing','surface','vessel_draft',$vessel_draft);
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1126
    } 
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
  1127
	if ($PPI_editing) {
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1128
		&antsAddParams('PPI_editing','surface');
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1129
		&antsAddParams('PPI_extend_upper_limit',$PPI_extend_upper_limit)
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1130
			if numberp($PPI_extend_upper_limit);
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
  1131
		progress("Editing data to remove PPI from sea surface...\n");
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
  1132
		  progress("\tConstructing depth-average soundspeed profile...\n");
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
  1133
		  $DASSprof[0] = my($sum) = 0;
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
  1134
		  for (my($d)=1; $d<=$#sVelProf; $d++) {
19
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
  1135
		  	die("assertion failed") unless numberp($sVelProf[$d]);
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
  1136
		  	$sum += $sVelProf[$d];
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
  1137
			$DASSprof[$d] = $sum/$d;
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
  1138
		  }
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
  1139
		($nvrm,$nerm) = editPPI($firstGoodEns,$lastGoodEns,undef);
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
  1140
	    progress("\t$nvrm velocities from $nerm ensembles removed\n");
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
  1141
	}
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1142
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1143
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1144
#----------------------------------------------------------------------
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1145
# 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
  1146
#	1) surface layer editing
19
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
  1147
#	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
  1148
#----------------------------------------------------------------------
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1149
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1150
progress("Removing data from instrument at surface...\n");
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1151
&antsAddParams('surface_layer_depth',$surface_layer_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
  1152
$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
  1153
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
  1154
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
  1155
if (defined($post_merge_hook)) {
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
  1156
	progress("Executing user-supplied \$post_merge_hook...\n");
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
  1157
	&{$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
  1158
}
7e76fdef8953 version prior to carrying out separate dc-/uc- time lagging
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 6
diff changeset
  1159
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1160
#----------------------------------------------------------------------
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1161
# apply pressure-sensor acceleration correction (-a)
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1162
#	- valid, but useless except for troubleshooting data sets (e.g. DIMES UK2)
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1163
#	- useless, because ping-coherent error removal below does same job but better
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1164
#	- it does not make sense to to use this with ping-coherent error removal enabled
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1165
#----------------------------------------------------------------------
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1166
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1167
if ($opt_a != 1) {
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1168
	progress("Applying pressure-sensor acceleration correction...\n");
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1169
	for ($ens=$firstGoodEns; $ens<=$lastGoodEns; $ens++) {
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1170
		next unless numberp($CTD{W_tt}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}]);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1171
		my($acorr) = $opt_a * $CTD{W_tt}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}];
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1172
		if (numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH})) {
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1173
			for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1174
				next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1175
				$LADCP{ENSEMBLE}[$ens]->{W}[$bin] -= $acorr;
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1176
	        }
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1177
	    }
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1178
		if (numberp($LADCP{ENSEMBLE}[$ens]->{REFLR_W})) {
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1179
			$LADCP{ENSEMBLE}[$ens]->{REFLR_W} -= $acorr;
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1180
		}
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1181
	}
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1182
}
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1183
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1184
#---------------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1185
# Depth-bin LADCP velocity data
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1186
#
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1187
# NOTES:
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1188
#	1) ensemble and bin numbers are saved for maximum flexibility
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1189
#	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
  1190
#	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
  1191
#	   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
  1192
#	   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
  1193
#	   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
  1194
#	   at a winch+wave speed of 3m/s....]
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1195
#	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
  1196
#	   has only a minute effect
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1197
#---------------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1198
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1199
progress("Creating binned profiles at ${opt_o}m resolution...\n");
30
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1200
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1201
&antsAddParams('outgrid_dz',$opt_o,'outgrid_minsamp',$opt_k);					# used by LADCP_w_regrid
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1202
&antsAddParams('outgrid_firstbin',$outGrid_firstBin,'outgrid_lastbin',$outGrid_lastBin);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1203
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1204
my($min_depth) = 9e99;
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1205
my($max_depth) = 0;
30
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1206
local($realLastGoodEns);
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1207
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1208
progress("\tdowncast...\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1209
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
  1210
	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
  1211
		$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
  1212
		next;
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1213
	}
29
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
  1214
	$realLastGoodEns = $ens;
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1215
	my(@bindepth) = calc_binDepths($ens);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1216
	for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1217
		next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
30
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1218
		next if ($bin<$outGrid_firstBin-1 || $bin>$outGrid_lastBin-1);
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1219
		$min_depth = $bindepth[$bin] if ($bindepth[$bin] < $min_depth);
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1220
		$max_depth = $bindepth[$bin] if ($bindepth[$bin] > $max_depth);
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1221
		$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] =
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1222
			sscorr_w($LADCP{ENSEMBLE}[$ens]->{W}[$bin],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1223
					 $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1224
					 $LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1225
					 $bindepth[$bin]);
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1226
		$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin] =
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1227
			sscorr_w($LADCP{ENSEMBLE}[$ens]->{W12}[$bin],
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1228
					 $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1229
					 $LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1230
					 $bindepth[$bin])
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1231
				if numberp($LADCP{ENSEMBLE}[$ens]->{W12}[$bin]);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1232
		$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin] =
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1233
			sscorr_w($LADCP{ENSEMBLE}[$ens]->{W34}[$bin],
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1234
					 $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1235
					 $LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1236
					 $bindepth[$bin])
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1237
				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
  1238
		$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
  1239
			$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] + $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}];
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1240
		my($bi) = $bindepth[$bin]/$opt_o;
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1241
		push(@{$DNCAST{ENSEMBLE}[$bi]},$ens);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1242
		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
  1243
		push(@{$DNCAST{CTD_W}[$bi]},$CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}]);
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1244
		push(@{$DNCAST{CTD_W_tt}[$bi]},$CTD{W_tt}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}]);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1245
		push(@{$DNCAST{BIN}[$bi]},$bin);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1246
		push(@{$DNCAST{DEPTH}[$bi]},$bindepth[$bin]);
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1247
		push(@{$DNCAST{W}[$bi]},$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin]);
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1248
		push(@{$DNCAST{W12}[$bi]},$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin]);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1249
		push(@{$DNCAST{W34}[$bi]},$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin]);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1250
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1251
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1252
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1253
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
  1254
	$DNCAST{MEAN_DEPTH}[$bi]  	= avg(@{$DNCAST{DEPTH}[$bi]});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1255
	$DNCAST{MEAN_ELAPSED}[$bi]	= avg(@{$DNCAST{ELAPSED}[$bi]});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1256
	$DNCAST{MEDIAN_W}[$bi] 	  	= median(@{$DNCAST{W}[$bi]});
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1257
	$DNCAST{MEDIAN_W12}[$bi]  	= median(@{$DNCAST{W12}[$bi]});
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1258
	$DNCAST{MEDIAN_W34}[$bi]  	= median(@{$DNCAST{W34}[$bi]});
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1259
	$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
  1260
	$DNCAST{N_SAMP}[$bi]		= @{$DNCAST{W}[$bi]};
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1261
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1262
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1263
progress("\tupcast...\n");														# upcast
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1264
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1265
for ($ens=$LADCP_atbottom; $ens<=$lastGoodEns; $ens++) {		
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1266
	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
  1267
	$realLastGoodEns = $ens;
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1268
	my(@bindepth) = calc_binDepths($ens);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1269
	for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1270
		next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
30
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1271
		next if ($bin<$outGrid_firstBin-1 || $bin>$outGrid_lastBin-1);
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1272
		$min_depth = $bindepth[$bin] if ($bindepth[$bin] < $min_depth);
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1273
		$max_depth = $bindepth[$bin] if ($bindepth[$bin] > $max_depth);
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1274
		$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] =
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1275
			sscorr_w($LADCP{ENSEMBLE}[$ens]->{W}[$bin],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1276
					 $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1277
					 $LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1278
					 $bindepth[$bin]);
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1279
		$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin] =
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1280
			sscorr_w($LADCP{ENSEMBLE}[$ens]->{W12}[$bin],
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1281
					 $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1282
					 $LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1283
					 $bindepth[$bin])
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1284
				if numberp($LADCP{ENSEMBLE}[$ens]->{W12}[$bin]);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1285
		$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin] =
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1286
			sscorr_w($LADCP{ENSEMBLE}[$ens]->{W34}[$bin],
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1287
					 $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1288
					 $LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1289
					 $bindepth[$bin])
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
  1290
				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
  1291
		$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
  1292
			$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] + $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}];
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1293
		my($bi) = $bindepth[$bin]/$opt_o;
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1294
		push(@{$UPCAST{ENSEMBLE}[$bi]},$ens);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1295
		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
  1296
		push(@{$UPCAST{CTD_W}[$bi]},$CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}]);
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1297
		push(@{$UPCAST{CTD_W_tt}[$bi]},$CTD{W_tt}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}]);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1298
		push(@{$UPCAST{BIN}[$bi]},$bin);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1299
		push(@{$UPCAST{DEPTH}[$bi]},$bindepth[$bin]);
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1300
		push(@{$UPCAST{W}[$bi]},$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin]);
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1301
		push(@{$UPCAST{W12}[$bi]},$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin]);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1302
		push(@{$UPCAST{W34}[$bi]},$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin]);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1303
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1304
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1305
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1306
for (my($bi)=0; $bi<=$#{$UPCAST{ENSEMBLE}}; $bi++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1307
	$UPCAST{MEAN_DEPTH}[$bi]  	= avg(@{$UPCAST{DEPTH}[$bi]});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1308
	$UPCAST{MEAN_ELAPSED}[$bi]	= avg(@{$UPCAST{ELAPSED}[$bi]});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1309
	$UPCAST{MEDIAN_W}[$bi] 	  	= median(@{$UPCAST{W}[$bi]});
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1310
	$UPCAST{MEDIAN_W12}[$bi]  	= median(@{$UPCAST{W12}[$bi]});
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1311
	$UPCAST{MEDIAN_W34}[$bi]  	= median(@{$UPCAST{W34}[$bi]});
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1312
	$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
  1313
	$UPCAST{N_SAMP}[$bi]		= @{$UPCAST{W}[$bi]};
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1314
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1315
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1316
&antsAddParams('min_depth',$min_depth,'max_depth',$max_depth,					# plot range limits
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1317
			   'min_ens',$LADCP{ENSEMBLE}[$firstGoodEns]->{NUMBER},
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1318
			   'max_ens',$LADCP{ENSEMBLE}[$realLastGoodEns]->{NUMBER},
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1319
			   'min_elapsed',$LADCP{ENSEMBLE}[$firstGoodEns]->{CTD_ELAPSED},
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1320
			   '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
  1321
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1322
#------------------------------------------------------------------------------------------------------
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1323
# remove ping-coherent errors
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1324
#	- error sources:
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1325
#		1) acceleration-dependence of Paroscientific pressure measurements; O(10cm/s) [IWISE 28]
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1326
#		2) residual CTD/LADCP mismatch errors; O(1cm/s) [Thurnherr, CWTMC 2011]
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1327
#		3) ADCP short-term variability; O(1cm/s) for vertical?
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1328
#	- two steps:
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1329
#		- remove ensemble-median residual from all ocean vertical velocities
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1330
#		- re-bin profiles
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1331
#		- calculate new residuals
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1332
#	- 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
  1333
#	  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
  1334
#------------------------------------------------------------------------------------------------------
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1335
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1336
unless ($opt_q) {
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1337
	progress("Removing ping-coherent errors...\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
  1338
	
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1339
	for ($ens=$firstGoodEns; $ens<=$lastGoodEns; $ens++) {
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1340
		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
11
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 10
diff changeset
  1341
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1342
		my(@residuals) = ();												# calc median of residuals
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1343
		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
  1344
		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
  1345
			next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
30
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1346
		    next if ($bin<$outGrid_firstBin-1 || $bin>$outGrid_lastBin-1);
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1347
			my($bi) = $bindepth[$bin]/$opt_o;
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1348
			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
  1349
				$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
  1350
					(($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
  1351
											  : $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
  1352
		}
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1353
		$LADCP{ENSEMBLE}[$ens]->{MEDIAN_RESIDUAL_W} = median(@residuals);	# NB: can be nan!
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1354
		
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1355
		for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {		# remove from ocean velocities
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1356
			next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);			# also ensures that MEDIAN_RESIDUAL_W is not 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
  1357
			$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
  1358
				$LADCP{ENSEMBLE}[$ens]->{MEDIAN_RESIDUAL_W};
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1359
			$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin] -=
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1360
				$LADCP{ENSEMBLE}[$ens]->{MEDIAN_RESIDUAL_W}
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1361
					if numberp($LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin]);
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1362
			$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin] -=
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1363
				$LADCP{ENSEMBLE}[$ens]->{MEDIAN_RESIDUAL_W}
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1364
					if numberp($LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$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
  1365
		}
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1366
		
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1367
		$LADCP{ENSEMBLE}[$ens]->{REFLR_W} -=								# reflr_ocean_w is calculated below
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1368
			$LADCP{ENSEMBLE}[$ens]->{MEDIAN_RESIDUAL_W}						# NB: this can be set to nan here
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1369
				if numberp($LADCP{ENSEMBLE}[$ens]->{REFLR_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
  1370
    }
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1371
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1372
	#------------------------------------------------------------
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1373
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1374
    progress("\tre-binning profile data...\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
  1375
    
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1376
	for (my($bi)=0; $bi<=$#{$DNCAST{ENSEMBLE}}; $bi++) {					# bin data
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1377
		for (my($i)=0; $i<@{$DNCAST{W}[$bi]}; $i++) {
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1378
			$DNCAST{W}  [$bi][$i] -= $LADCP{ENSEMBLE}[$DNCAST{ENSEMBLE}[$bi][$i]]->{MEDIAN_RESIDUAL_W};
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1379
			$DNCAST{W12}[$bi][$i] -= $LADCP{ENSEMBLE}[$DNCAST{ENSEMBLE}[$bi][$i]]->{MEDIAN_RESIDUAL_W};
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1380
			$DNCAST{W34}[$bi][$i] -= $LADCP{ENSEMBLE}[$DNCAST{ENSEMBLE}[$bi][$i]]->{MEDIAN_RESIDUAL_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
  1381
		}
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1382
		$DNCAST{MEDIAN_W}  [$bi] = median(@{$DNCAST{W}[$bi]});
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1383
		$DNCAST{MEDIAN_W12}[$bi] = median(@{$DNCAST{W12}[$bi]});
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1384
		$DNCAST{MEDIAN_W34}[$bi] = median(@{$DNCAST{W34}[$bi]});
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1385
		$DNCAST{MAD_W}	   [$bi] = mad2($DNCAST{MEDIAN_W}[$bi],@{$DNCAST{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
  1386
	}
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1387
	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
  1388
		for (my($i)=0; $i<@{$UPCAST{W}[$bi]}; $i++) {
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1389
			$UPCAST{W}  [$bi][$i] -= $LADCP{ENSEMBLE}[$UPCAST{ENSEMBLE}[$bi][$i]]->{MEDIAN_RESIDUAL_W};
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1390
			$UPCAST{W12}[$bi][$i] -= $LADCP{ENSEMBLE}[$UPCAST{ENSEMBLE}[$bi][$i]]->{MEDIAN_RESIDUAL_W};
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1391
			$UPCAST{W34}[$bi][$i] -= $LADCP{ENSEMBLE}[$UPCAST{ENSEMBLE}[$bi][$i]]->{MEDIAN_RESIDUAL_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
  1392
		}
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1393
		$UPCAST{MEDIAN_W}  [$bi] = median(@{$UPCAST{W}[$bi]});
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1394
		$UPCAST{MEDIAN_W12}[$bi] = median(@{$UPCAST{W12}[$bi]});
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1395
		$UPCAST{MEDIAN_W34}[$bi] = median(@{$UPCAST{W34}[$bi]});
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1396
		$UPCAST{MAD_W}	   [$bi] = mad2($UPCAST{MEDIAN_W}[$bi],@{$UPCAST{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
  1397
	}
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1398
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1399
} # unless ($opt_q);
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1400
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1401
#--------------------------------------------
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1402
# Calculate and Output Bin-Averaged Resiudals
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1403
#--------------------------------------------
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1404
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1405
if (@out_BR) {
31
d0ae3cb99021 DoMORE-2
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
  1406
	progress("Binning residuals...");
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1407
30
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1408
	local(@dc_bres,@uc_bres);
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1409
	for ($ens=$firstGoodEns; $ens<$LADCP_atbottom; $ens++) {						# downcast
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1410
		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1411
		my(@bindepth) = calc_binDepths($ens);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1412
		for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1413
			next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1414
			push(@{$dc_bres[$bin]},
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1415
					$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin]
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1416
					- $DNCAST{MEDIAN_W}[$bindepth[$bin]/$opt_o]);
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1417
		}
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1418
	}
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1419
	for ($ens=$LADCP_atbottom; $ens<=$realLastGoodEns; $ens++) {					# upcast 
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1420
		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1421
		my(@bindepth) = calc_binDepths($ens);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1422
		for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1423
			next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1424
			push(@{$uc_bres[$bin]},
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1425
					$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin]
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1426
					- $UPCAST{MEDIAN_W}[$bindepth[$bin]/$opt_o]);
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1427
		}
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1428
	}
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1429
	local(@dc_avg_bres,@uc_avg_bres,@dc_avg_bres_nsamp,@uc_avg_bres_nsamp);			# calc means/stddevs
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1430
	for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {		
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1431
		$dc_bres_nsamp[$bin] = @{$dc_bres[$bin]};
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1432
		if ($dc_bres_nsamp[$bin] > 0) {
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1433
			$dc_avg_bres[$bin] = avg(@{$dc_bres[$bin]}); 
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1434
			$dc_sig_bres[$bin] = stddev2($dc_avg_bres[$bin],@{$dc_bres[$bin]});
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1435
		} else {
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1436
			$dc_avg_bres[$bin] = nan;
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1437
			$dc_sig_bres[$bin] = nan;
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1438
		}
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1439
		$uc_bres_nsamp[$bin] = @{$uc_bres[$bin]};
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1440
		if ($uc_bres_nsamp[$bin] > 0) {
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1441
			$uc_avg_bres[$bin] = avg(@{$uc_bres[$bin]}); 
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1442
			$uc_sig_bres[$bin] = stddev2($uc_avg_bres[$bin],@{$uc_bres[$bin]});
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1443
		} else {
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1444
			$uc_avg_bres[$bin] = nan;
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1445
			$uc_sig_bres[$bin] = nan;
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1446
		}
30
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1447
	}
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1448
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1449
	local($uc_bres_max_nsamp,$dc_bres_max_nsamp) = (0,0);							# calc rms in block of well-determined bins
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1450
	for (my($bin)=$LADCP_firstBin; $bin<=$LADCP_lastBin-1; $bin++) {				# SKIP 1ST BIN!!!
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1451
		next if ($bin+1<$outGrid_firstBin || $bin+1>$outGrid_lastBin);				# skip bins not included in gridded output
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1452
		$dc_bres_max_nsamp = $dc_bres_nsamp[$bin]									# nsamp in best sampled bin
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1453
			if ($dc_bres_nsamp[$bin] > $dc_bres_max_nsamp);
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1454
		$uc_bres_max_nsamp = $uc_bres_nsamp[$bin]
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1455
			if ($uc_bres_nsamp[$bin] > $uc_bres_max_nsamp);
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1456
	}
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1457
	my($dc_sumsq,$uc_sumsq,$dc_n,$uc_n) = (0,0,0,0);								# calc rms residual
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1458
	for (my($bin)=$LADCP_firstBin; $bin<=$LADCP_lastBin-1; $bin++) {				# SKIP 1ST BIN
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1459
		next if ($bin+1<$outGrid_firstBin || $bin+1>$outGrid_lastBin);				# skip bins not included in gridded output
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1460
		if ($dc_bres_nsamp[$bin] >= $dc_bres_max_nsamp/3) {							# skip bins with < 1/3 max(nsamp)
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1461
			$dc_sumsq += $dc_avg_bres[$bin]**2;
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1462
			$dc_n++;
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1463
		}
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1464
		if ($uc_bres_nsamp[$bin] >= $uc_bres_max_nsamp/3) {
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1465
			$uc_sumsq += $uc_avg_bres[$bin]**2;
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1466
			$uc_n++;
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1467
		}
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1468
	}
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1469
	local($dc_bres_rms) = sqrt($dc_sumsq/$dc_n);
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1470
	local($uc_bres_rms) = sqrt($uc_sumsq/$uc_n);
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1471
	
30
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1472
	progress("\nWriting binned residuals to ");
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1473
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1474
	my($saveParams) = $antsCurParams;
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1475
	@antsNewLayout = ('bin','dc_residual','dc_residual.sig','dc_residual.nsamp',
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1476
						   ,'uc_residual','uc_residual.sig','uc_residual.nsamp');
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1477
	&antsAddParams('BR_max_bin',max(scalar(@dc_bres),scalar(@uc_bres)));
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1478
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1479
	foreach my $of (@out_BR) {
26
b89d4b01fcc5 after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 25
diff changeset
  1480
	    progress("<$of> ");
30
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1481
		my($plot,$out) = ($of =~ /^([^\(]+)\(([^\)]+)\)$/);						# plot_sub(out_file)
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1482
		if (defined($out)) {
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1483
			require "$WCALC/${plot}.pl";
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1484
			&{$plot}($out);
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1485
			next;
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1486
		}
26
b89d4b01fcc5 after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 25
diff changeset
  1487
	    $of = ">$of" unless ($of =~ /^$|^\s*\|/);
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
  1488
		open(STDOUT,$of) || error("$of: $!\n");
26
b89d4b01fcc5 after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 25
diff changeset
  1489
		undef($antsActiveHeader) unless ($ANTS_TOOLS_AVAILABLE);
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1490
		for (my($bin)=0; $bin<max(scalar(@dc_bres),scalar(@uc_bres)); $bin++) {
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1491
			&antsOut($bin+1,$dc_avg_bres[$bin],$dc_sig_bres[$bin],$dc_bres_nsamp[$bin],
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
  1492
							$uc_avg_bres[$bin],$uc_sig_bres[$bin],$uc_bres_nsamp[$bin]);
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1493
		}
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1494
	    &antsOut('EOF'); open(STDOUT,">&2");
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1495
	}
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1496
	$antsCurParams = $saveParams;
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1497
	progress("\n");
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1498
}
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1499
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1500
#--------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1501
# Calculate BT-referenced vertical-velocity profile
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1502
#--------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1503
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1504
if (defined($water_depth)) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1505
	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
  1506
	calc_BTprof($firstGoodEns,$realLastGoodEns,$water_depth,$sig_water_depth);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1507
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1508
	my($sumSq) = my($n) = 0;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1509
	for (my($bi)=0; $bi<=$#{$BT{MEDIAN_W}}; $bi++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1510
		next unless defined($BT{MEDIAN_W}[$bi]);
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1511
		next unless ($BT{N_SAMP}[$bi]>=$opt_k && $DNCAST{N_SAMP}[$bi]>=$opt_k && $UPCAST{N_SAMP}[$bi]>=$opt_k);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1512
		$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
  1513
		$n++;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1514
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1515
	if ($n > 0) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1516
		my($rms) = round(sqrt($sumSq/$n),0.001);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1517
		&antsAddParams('BT_rms_w_discrepancy',$rms);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1518
		progress("\t$rms m/s rms vertical-velocity discrepancy\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1519
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1520
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1521
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1522
#------------------------
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1523
# output all samples (-w)
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1524
#------------------------
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1525
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1526
# 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
  1527
31
d0ae3cb99021 DoMORE-2
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
  1528
if (@out_wsamp) {
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1529
	progress("Writing vertical-velocity data to ");
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1530
	@antsNewLayout = ('ensemble','bin','elapsed','depth','CTD_depth','downcast',
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1531
					  'w','w12','w34','residual','CTD_w','CTD_w_tt','LADCP_w','errvel',
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
  1532
					  'correlation','echo_amplitude','Sv',
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
  1533
					  'pitch','roll','tilt','heading','3_beam','svel');
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1534
31
d0ae3cb99021 DoMORE-2
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
  1535
	foreach my $of (@out_wsamp) {
26
b89d4b01fcc5 after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 25
diff changeset
  1536
	    progress("<$of> ");
30
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1537
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1538
		my($plot,$out) = ($of =~ /^([^\(]+)\(([^\)]+)\)$/);						# plot_sub(out_file)
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1539
		if (defined($out)) {
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1540
			require "$WCALC/${plot}.pl";
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1541
			&{$plot}($out);
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1542
			next;
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1543
		}
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1544
			
26
b89d4b01fcc5 after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 25
diff changeset
  1545
	    $of = ">$of" unless ($of =~ /^$|^\s*\|/);
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
  1546
		open(STDOUT,$of) || error("$of: $!\n");
26
b89d4b01fcc5 after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 25
diff changeset
  1547
		undef($antsActiveHeader) unless ($ANTS_TOOLS_AVAILABLE);
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1548
	    
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1549
		for ($ens=$firstGoodEns; $ens<$LADCP_atbottom; $ens++) {						# downcast
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1550
		  next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1551
		  my(@bindepth) = calc_binDepths($ens);
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1552
		  for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1553
			  next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1554
			  my($bi) = $bindepth[$bin]/$opt_o;
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1555
			  &antsOut(
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1556
				  $LADCP{ENSEMBLE}[$ens]->{NUMBER},$bin+1,
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1557
				  $CTD{ELAPSED}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1558
				  $bindepth[$bin],$LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},1,
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1559
				  $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1560
				  $LADCP{BEAM_COORDINATES} ? $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin] : nan,
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1561
				  $LADCP{BEAM_COORDINATES} ? $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin] : nan,
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1562
				  $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] - $DNCAST{MEDIAN_W}[$bi],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1563
				  $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1564
				  $CTD{W_tt}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1565
				  $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_W}[$bin],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1566
				  $LADCP{ENSEMBLE}[$ens]->{ERRVEL}[$bin],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1567
				  median(@{$LADCP{ENSEMBLE}[$ens]->{CORRELATION}[$bin]}),
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1568
				  median(@{$LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin]}),
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1569
				  $LADCP{ENSEMBLE}[$ens]->{SV}[$bin],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1570
				  $LADCP{ENSEMBLE}[$ens]->{PITCH},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1571
				  $LADCP{ENSEMBLE}[$ens]->{ROLL},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1572
				  $LADCP{ENSEMBLE}[$ens]->{TILT},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1573
				  $LADCP{ENSEMBLE}[$ens]->{HEADING},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1574
				  (defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][0]) +			  # only works for beam coords
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1575
				   defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][1]) +
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1576
				   defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][2]) +
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1577
				   defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][3])) < 4 ? 1 : 0,
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1578
				  $CTD{SVEL}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1579
			  );
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1580
		  } # for $bin
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1581
		} # for $ens
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1582
	  
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1583
		for ($ens=$LADCP_atbottom; $ens<=$realLastGoodEns; $ens++) {					  # upcast 
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1584
		  next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1585
		  my(@bindepth) = calc_binDepths($ens);
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1586
		  for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1587
			  next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1588
			  my($bi) = $bindepth[$bin]/$opt_o;
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1589
			  &antsOut(
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1590
				  $LADCP{ENSEMBLE}[$ens]->{NUMBER},$bin+1,
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1591
				  $CTD{ELAPSED}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1592
				  $bindepth[$bin],$LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},0,
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1593
				  $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1594
				  $LADCP{BEAM_COORDINATES} ? $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin] : nan,
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1595
				  $LADCP{BEAM_COORDINATES} ? $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin] : nan,
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1596
				  $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] - $UPCAST{MEDIAN_W}[$bi],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1597
				  $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1598
				  $CTD{W_tt}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1599
				  $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_W}[$bin],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1600
				  $LADCP{ENSEMBLE}[$ens]->{ERRVEL}[$bin],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1601
				  median(@{$LADCP{ENSEMBLE}[$ens]->{CORRELATION}[$bin]}),
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1602
				  median(@{$LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin]}),
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1603
				  $LADCP{ENSEMBLE}[$ens]->{SV}[$bin],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1604
				  $LADCP{ENSEMBLE}[$ens]->{PITCH},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1605
				  $LADCP{ENSEMBLE}[$ens]->{ROLL},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1606
				  $LADCP{ENSEMBLE}[$ens]->{TILT},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1607
				  $LADCP{ENSEMBLE}[$ens]->{HEADING},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1608
				  (defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][0]) +			  # only works for beam coords
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1609
				   defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][1]) +
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1610
				   defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][2]) +
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1611
				   defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][3])) < 4 ? 1 : 0,
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1612
				  $CTD{SVEL}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1613
			  );
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1614
		  } # for $bin
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1615
		} # for $ens
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1616
	
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1617
	    &antsOut('EOF'); open(STDOUT,">&2");
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1618
	}
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1619
	progress("\n");
2
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1620
}
a077ea2a9f36 post 2011_IWISE
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
  1621
	
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1622
#----------------------------
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1623
# Output depth-binned profile
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1624
#----------------------------
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1625
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1626
if (@out_profile) {
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1627
	progress("Writing vertical-velocity profiles to ");
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1628
	@antsNewLayout = ('depth','dc_depth','dc_elapsed','dc_w','dc_w.mad','dc_w.nsamp','dc_w12','dc_w34',
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1629
							  'uc_depth','uc_elapsed','uc_w','uc_w.mad','uc_w.nsamp','uc_w12','uc_w34',
19
1d49806c9f75 laptop copy
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 18
diff changeset
  1630
	                          'BT_w','BT_w.mad','BT_w.nsamp');
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1631
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1632
	foreach my $of (@out_profile) {
26
b89d4b01fcc5 after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 25
diff changeset
  1633
	    progress("<$of> ");
29
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
  1634
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
  1635
		my($plot,$out) = ($of =~ /^([^\(]+)\(([^\)]+)\)$/);						# plot_sub(out_file)
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
  1636
		if (defined($out)) {
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
  1637
			require "$WCALC/${plot}.pl";
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
  1638
			&{$plot}($out);
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
  1639
			next;
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
  1640
		}
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
  1641
			
c1ff35103176 a few days pre WHOI
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
  1642
	    $of = ">$of" unless ($of =~ /^$|^\s*\|/);								# pipe or file output
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
  1643
		open(STDOUT,$of) || error("$of: $!\n");
26
b89d4b01fcc5 after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 25
diff changeset
  1644
		undef($antsActiveHeader) unless ($ANTS_TOOLS_AVAILABLE);
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1645
	    
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1646
		for (my($bi)=0; $bi<=max($#{$DNCAST{ENSEMBLE}},$#{$UPCAST{ENSEMBLE}},$#{$BT{NSAMP}}); $bi++) {
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1647
			&antsOut(($bi+0.5)*$opt_o,					# nominal depth
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1648
					 $DNCAST{MEAN_DEPTH}[$bi],$DNCAST{MEAN_ELAPSED}[$bi],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1649
					 $DNCAST{N_SAMP}[$bi]>=$opt_k?$DNCAST{MEDIAN_W}[$bi]:nan,
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1650
					 $DNCAST{MAD_W}[$bi],$DNCAST{N_SAMP}[$bi],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1651
					 $DNCAST{MEDIAN_W12}[$bi],$DNCAST{MEDIAN_W34}[$bi],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1652
					 $UPCAST{MEAN_DEPTH}[$bi],$UPCAST{MEAN_ELAPSED}[$bi],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1653
					 $UPCAST{N_SAMP}[$bi]>=$opt_k?$UPCAST{MEDIAN_W}[$bi]:nan,
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1654
					 $UPCAST{MAD_W}[$bi],$UPCAST{N_SAMP}[$bi],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1655
					 $UPCAST{MEDIAN_W12}[$bi],$UPCAST{MEDIAN_W34}[$bi],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1656
					 $BT{N_SAMP}[$bi]>=$opt_k?$BT{MEDIAN_W}[$bi]:nan,
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1657
					 $BT{MAD_W}[$bi],$BT{N_SAMP}[$bi]
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1658
			);
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1659
		}
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1660
	    &antsOut('EOF'); open(STDOUT,">&2");
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1661
	}
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1662
	progress("\n");
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1663
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1664
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1665
#--------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1666
# write time-series output if requested
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1667
#--------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1668
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1669
if (@out_timeseries) {
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1670
	progress("Writing time-series data to ");
23
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 21
diff changeset
  1671
	@antsNewLayout = ('ensemble','elapsed','downcast',
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
  1672
					  'depth','xducer_sound_speed','pitch','gimbal_pitch','roll','tilt','heading',
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 12
diff changeset
  1673
					  'CTD_w','CTD_w_tt','LADCP_reflr_w','LADCP_reflr_w.sig',
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 2
diff changeset
  1674
					  'reflr_ocean_w');
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1675
					  
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1676
	foreach my $of (@out_timeseries) {
26
b89d4b01fcc5 after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 25
diff changeset
  1677
	    progress("<$of> ");
30
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1678
		my($plot,$out) = ($of =~ /^([^\(]+)\(([^\)]+)\)$/);						# plot_sub(out_file)
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1679
		if (defined($out)) {
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1680
			require "$WCALC/${plot}.pl";
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1681
			&{$plot}($out);
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1682
			next;
7fb67e771d85 LWplots expunged
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
  1683
		}
26
b89d4b01fcc5 after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 25
diff changeset
  1684
	    $of = ">$of" unless ($of =~ /^$|^\s*\|/);
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
  1685
		open(STDOUT,$of) || error("$of: $!\n");
26
b89d4b01fcc5 after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 25
diff changeset
  1686
		undef($antsActiveHeader) unless ($ANTS_TOOLS_AVAILABLE);
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1687
		 
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1688
		for ($ens=$firstGoodEns; $ens<=$realLastGoodEns; $ens++) {
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1689
			next unless defined($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1690
			my($reflr_oc_w) = defined($LADCP{ENSEMBLE}[$ens]->{REFLR_W})
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1691
							? $LADCP{ENSEMBLE}[$ens]->{REFLR_W} - $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}]
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1692
							: undef;
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1693
			&antsOut($LADCP{ENSEMBLE}[$ens]->{NUMBER},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1694
					 $CTD{ELAPSED}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1695
					 ($ens < $LADCP_atbottom) ? 1 : 0,
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1696
					 $LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1697
					 $CTD{SVEL}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1698
					 $LADCP{ENSEMBLE}[$ens]->{PITCH},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1699
					 $LADCP{ENSEMBLE}[$ens]->{GIMBAL_PITCH},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1700
					 $LADCP{ENSEMBLE}[$ens]->{ROLL},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1701
					 $LADCP{ENSEMBLE}[$ens]->{TILT},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1702
					 $LADCP{ENSEMBLE}[$ens]->{HEADING},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1703
					 $CTD{W}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1704
					 $CTD{W_tt}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1705
					 $LADCP{ENSEMBLE}[$ens]->{REFLR_W},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1706
					 $LADCP{ENSEMBLE}[$ens]->{REFLR_W_STDDEV},
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1707
					 $reflr_oc_w);
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1708
		}
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1709
	
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1710
	    &antsOut('EOF'); open(STDOUT,">&2");
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1711
	}
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1712
	progress("\n");
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1713
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
  1714
25
bd38f8bfb8e6 first step at re-designing plotting system
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 23
diff changeset
  1715
system("{ ./PostProcess.sh $out_basename $RUN $data_subdir $plot_subdir $log_subdir; }&")
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1716
	if (-x 'PostProcess.sh');
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1717
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
  1718
exit(0);