LADCPproc.shearmethod
author A.M. Thurnherr <athurnherr@yahoo.com>
Fri, 06 Mar 2015 15:51:10 -0500
changeset 32 9b972ce37c3b
parent 31 af03ca38fc2a
permissions -rw-r--r--
merged 1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     1
#======================================================================
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     2
#                    L A D C P P R O C . S H E A R M E T H O D 
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     3
#                    doc: Fri Sep 17 20:27:53 2010
31
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
     4
#                    dlm: Sun Jul 27 19:44:41 2014
30
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     5
#                    (c) 2010 A.M. Thurnherr & E. Firing
31
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
     6
#                    uE-Info: 338 65 NIL 0 0 72 2 2 4 NIL ofnI
30
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     7
#======================================================================
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     8
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     9
# PERLified functions from E. Firing's [merge.c], modified by A.M. Thurnherr
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    10
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    11
# NOTES:
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    12
#	- velocity integration removed
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    13
#	- percent-good flag removed (no point for single-ping ensembles)
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    14
#	- need the following per-ensemble fields from previous steps:
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    15
#		DEPTH
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    16
#		CTD_SVEL
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    17
#	- negative depths are not allowed (should not happen given DEPTH)
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    18
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    19
# WEIRDNESSES IN ERIC'S CODE:
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    20
#	- w reference layer in set_misc_flags is calculated without taking
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    21
#	  the ref layer bins into account
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    22
#	- u,v ref lr vels in set_wake_flag use w ref layer bins
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    23
#	- distance to bin 1 center is not sound-speed corrected [WEIRDNESS CORRECTED]
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    24
#	- $tilt calculation is wrong. I do not understand this comment in 2014.
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    25
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    26
# HISTORY:
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    27
#	Sep 17, 2010: - created
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    28
#	Oct 13, 2010: - first working version
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    29
#	Oct 14, 2010: - renamed from LADCPshear.UHcode
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    30
#	Oct 15, 2010: - added support for -pPI edit suppresion
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    31
#	Oct 19, 2010: - reversed semantics of -p
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    32
#	Oct 25, 2010: - added W_CTD_BIT, renamed W_BIT to W_OUTLIER_BIT
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    33
#	Oct 26, 2010: - added TILT_BIT
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    34
#	Dec 10, 2010: - modified assertion to allow processing of UL data
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    35
#	Jul 10, 2011: - added outTDseries() call
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    36
#	Jul 12, 2011: - replaced -p by $PPI_editing_enabled flag
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    37
#	Feb 19, 2012: - added elapsed time to binned shear output
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    38
#	Apr 11, 2012: - added MISSING_CTD_DATA_BIT
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    39
#	Sep 25, 2013: - added code to calc gridded lat/lon info
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    40
#	Nov 12, 2013: - BUG: correlation editing removed most (all?) 3-beam
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    41
#				         solutions
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    42
#				  - BUG: set_shear_flag() calculated shdev (slightly?)
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    43
#						 wrongly
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    44
#	Mar  4, 2014: - added support for missing PITCH/ROLL (TILT) & HEADING
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    45
#	Mar 21, 2014: - moved depthOfBin() to [LADCPproc.utils]
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    46
#	Jul 15, 2014: - BUG: occasional missing w values were used in w_ref calc;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    47
#					(potentially useless) tests for missing w were added wherever
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    48
#					edit_flags is tested or w is used; this change greatly
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    49
#					increase the number of shear samples available in case of
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    50
#					DoMORE1 tow-yo#1 data
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    51
#				  - disabled two assertions about depths of shear bins, one of
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    52
#				    which was violated by DoMORE1 uplooker data (apparently
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    53
#					valid data above the sea surface in the uplooker)
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    54
#	Jul 27, 2014: - renamed from [LADCPproc.UHmethod] because the code has
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    55
#					diverged quite a bit from the original mplementation. However,
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    56
#					the shear editing core remains as in the UH code
31
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
    57
#				  - added calculation of PACKAGE_VELOCITY (-v)
30
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    58
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    59
#======================================================================
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    60
# VELOCITY EDITING
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    61
#======================================================================
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    62
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    63
my($BADVEL_BIT)  	= 0x01;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    64
my($ERRVEL_BIT)  	= 0x02;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    65
my($CORREL_BIT)		= 0x04;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    66
my($W_OUTLIER_BIT) 	= 0x08;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    67
my($SHEAR_BIT) 		= 0x10;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    68
my($SIDELOBE_BIT)	= 0x20;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    69
my($WAKE_BIT)		= 0x40;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    70
my($PPI_BIT)		= 0x80;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    71
my($W_CTD_BIT)		= 0x100;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    72
my($TILT_BIT)		= 0x200;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    73
my($DELTA_TILT_BIT)	= 0x400;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    74
my($MISSING_CTD_DATA_BIT) = 0x800;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    75
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    76
my(%flag_count);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    77
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    78
sub set_wake_flag($$)
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    79
{
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    80
	my($ens,$De) = @_;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    81
	
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    82
	my($n) = 0;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    83
	my($uref) = my($vref) = my($wref) = 0;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    84
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    85
	for (my($bin)=$wbin_start-1; $bin<$wbin_end; $bin++) {		# calc crude ref lr vel from all data
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    86
		next if ($edit_flags[$ens][$bin] || $LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$W]==0);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    87
		$uref += $LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$U];
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    88
		$vref += $LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$V];
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    89
		$wref += $LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$W];
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    90
		$n++;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    91
	}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    92
	return if ($n==0);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    93
	$uref /= $n;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    94
	$vref /= $n;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    95
	$wref /= $n;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    96
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    97
	## if upward (=negative) velocity greater than minimum, calculate wake
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    98
	## 		heading and inclination
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    99
	if (defined($LADCP{ENSEMBLE}[$ens]->{HEADING}) && $wref<-$min_wake_w) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   100
		my($wake_hd) = 180 / 3.14159265358979 * atan2($uref,$vref);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   101
		my($speed) 	 = sqrt($uref*$uref + $vref*$vref);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   102
		my($wake_ang)= abs(180 / 3.14159265358979 * atan($speed/$wref));
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   103
		
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   104
		$wake_hd += 360
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   105
			if ($wake_hd < 0);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   106
		$LADCP{ENSEMBLE}[$ens]->{HEADING} += 360
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   107
			if ($LADCP{ENSEMBLE}[$ens]->{HEADING} < 0);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   108
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   109
		my($wake_mod) = $wake_hd % 90;		# % returns integer part of remainder, but that's sufficient
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   110
		my($adcp_mod) = $LADCP{ENSEMBLE}[$ens]->{HEADING} % 90;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   111
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   112
		if (((abs($wake_mod - $adcp_mod) < $wake_hd_dif) ||
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   113
             (abs($wake_mod - $adcp_mod) > (90 - $wake_hd_dif))) &&
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   114
			 ($wake_ang > $wake_ang_min)) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   115
			for (my($bin)=0; $bin<$n_wake_bins; $bin++) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   116
				$flag_count{$WAKE_BIT}[$bin]++;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   117
				$edit_flags[$ens][$bin] |= $WAKE_BIT;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   118
			}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   119
		}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   120
	} ## if ($wref < -min_wake_w)
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   121
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   122
	## This does not make a lot of sense, because it trims points
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   123
	## on only one side of the wake error, and that side depends
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   124
	## on whether the integration is forward or backward.
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   125
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   126
	if (($edit_flags[$ens+$De][0]&$WAKE_BIT) &&
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   127
		($edit_flags[$ens][0]&$WAKE_BIT == 0)) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   128
		for (my($bin)=0; $bin<$n_wake_bins; $bin++) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   129
			$flag_count{$WAKE_BIT}[$bin]++;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   130
			$edit_flags[$ens][$bin] |= $WAKE_BIT;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   131
		}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   132
	}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   133
}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   134
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   135
sub set_misc_flags($$)
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   136
{
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   137
	my($ens,$De) = @_;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   138
	my($ww) = my($n) = 0;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   139
	my($SLIfac) = 1 - cos(rad($LADCP{BEAM_ANGLE}));
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   140
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   141
	for (my($bin)=0; $bin<$w_ref_bin; $bin++) {				# ref-lr w
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   142
		next if ($edit_flags[$ens][$bin] || $LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$W]==0);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   143
		$ww += $LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$W];
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   144
		$n++;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   145
	}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   146
	$ww /= $n if ($n > 0);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   147
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   148
	for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   149
		next if ($edit_flags[$ens][$bin] || $LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$W]==0);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   150
         
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   151
		## We use the standard criterion for bottom interference; e.g. for
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   152
		## 30-degree beams, the last 15% of the profile is contaminated
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   153
		## by the sidelobe bounce.	1.5 bin length is added to allow for
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   154
		## the length of the bin and pulse, that is, contamination of part of a
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   155
		## bin.  Profiler tilt does not require a more stringent criterion.
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   156
		if ($LADCP{ENSEMBLE}[$ens]->{XDUCER_FACING_DOWN}) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   157
			if (numberp($water_depth) &&
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   158
				$water_depth - &depthOfBin($ens,$bin) <=
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   159
					$SLIfac * ($water_depth - $LADCP{ENSEMBLE}[$ens]->{DEPTH})
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   160
						+ 1.5 * $LADCP{BIN_LENGTH}) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   161
				$edit_flags[$ens][$bin] |= $SIDELOBE_BIT;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   162
				$flag_count{$SIDELOBE_BIT}++;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   163
			}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   164
		} else { ## upward-looking
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   165
			if (&depthOfBin($ens,$bin) <=
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   166
				$SLIfac * $LADCP{ENSEMBLE}[$ens]->{DEPTH}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   167
					+ 1.5 * $LADCP{BIN_LENGTH}) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   168
				$edit_flags[$ens][$bin] |= $SIDELOBE_BIT;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   169
				$flag_count{$SIDELOBE_BIT}++;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   170
			}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   171
		}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   172
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   173
		if ($ww != 0 &&
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   174
			abs($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$W] - $ww) > $w_dif) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   175
			$flag_count{$W_OUTLIER_BIT}++;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   176
			$edit_flags[$ens][$bin] |= $W_OUTLIER_BIT;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   177
		}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   178
	    
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   179
		if (abs($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$E]) > $e_max) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   180
			$flag_count{$ERRVEL_BIT}++;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   181
			$edit_flags[$ens][$bin] |= $ERRVEL_BIT;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   182
		}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   183
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   184
		my($nBadCorr) = 0;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   185
		for (my($beam)=0; $beam<=3; $beam++) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   186
			$nBadCorr++
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   187
				if ($LADCP{ENSEMBLE}[$ens]->{CORRELATION}[$bin][$beam] < $min_cor);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   188
        }
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   189
		if (abs($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$E]) > 0) {	# 4-beam solution
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   190
			if ($nBadCorr > 0) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   191
				$flag_count{$CORREL_BIT}++;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   192
				$edit_flags[$ens][$bin] |= $CORREL_BIT;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   193
			}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   194
		} else {														# 3-beam solution
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   195
			if ($nBadCorr > 1) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   196
				$flag_count{$CORREL_BIT}++;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   197
				$edit_flags[$ens][$bin] |= $CORREL_BIT;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   198
			}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   199
		}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   200
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   201
		if ($bin < $shbin_start-1 || $bin >= $shbin_end) {				# manually remove vels outside shear bin range
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   202
			$edit_flags[$ens][$bin] |= $BADVEL_BIT;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   203
			$flag_count{$BADVEL_BIT}++;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   204
		}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   205
	} # for ($bin=0...
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   206
}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   207
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   208
## The following is for editing out the second bottom bounce.
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   209
#	- in the UH code, tilt = max(pitch,roll)
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   210
#	- using the real tilt (here) implies that PPI editing is too conservative
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   211
#	  in case of large tilts
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   212
#	- since, however, the sound speed at the transducer is used instead
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   213
#	  of the mean soundspeed below the ADCP, the difference is unlikely
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   214
#	  to matter
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   215
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   216
sub set_PPI_flags($$)
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   217
{
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   218
	my($ens,$De) = @_;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   219
	my($clip_z0,$clip_z1);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   220
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   221
	my($dt_ping) = $LADCP{ENSEMBLE}[$ens]->{UNIX_TIME} - $LADCP{ENSEMBLE}[$ens-1]->{UNIX_TIME};
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   222
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   223
	if ($LADCP{ENSEMBLE}[$ens]->{XDUCER_FACING_DOWN}) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   224
		if (numberp($water_depth)) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   225
			$clip_z1 = $water_depth
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   226
						- $LADCP{ENSEMBLE}[$ens]->{CTD_SVEL}/2 * $dt_ping
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   227
							* cos(rad($LADCP{BEAM_ANGLE} + $LADCP{ENSEMBLE}[$ens]->{TILT}))
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   228
						+ $clip_margin;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   229
			$clip_z0 = $water_depth
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   230
						- $LADCP{ENSEMBLE}[$ens]->{CTD_SVEL}/2 * $dt_ping
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   231
							* cos(rad($LADCP{BEAM_ANGLE} - $LADCP{ENSEMBLE}[$ens]->{TILT}))
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   232
	                    - $clip_margin;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   233
	    }
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   234
	} else { # upward-looking
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   235
		$clip_z1 = $LADCP{ENSEMBLE}[$ens]->{CTD_SVEL}/2 * $dt_ping
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   236
						* cos(rad($LADCP{BEAM_ANGLE} - $LADCP{ENSEMBLE}[$ens]->{TILT}))
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   237
					+ $clip_margin;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   238
		$clip_z0 = $LADCP{ENSEMBLE}[$ens]->{CTD_SVEL}/2 * $dt_ping
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   239
						* cos(rad($LADCP{BEAM_ANGLE} + $LADCP{ENSEMBLE}[$ens]->{TILT}))
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   240
					- $clip_margin;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   241
	}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   242
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   243
	for (my($bin)=$first_clip_bin-1; $bin<$LADCP{N_BINS}; $bin++) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   244
		next if ($edit_flags[$ens][$bin] || $LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$W]==0);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   245
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   246
		my($dob) = depthOfBin($ens,$bin);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   247
		if (!defined($LADCP{ENSEMBLE}[$ens]->{TILT}) || ($dob>=$clip_z0 && $dob<=$clip_z1)) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   248
			$edit_flags[$ens][$bin] |= $PPI_BIT;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   249
			$flag_count{$PPI_BIT}++;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   250
		}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   251
	}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   252
}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   253
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   254
sub edit_velocity($$)
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   255
{
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   256
	my($start,$end) = @_;												# ensemble indices
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   257
	my($De) = $start<$end ? 1 : -1;										# downcast: De = 1; upcast: De = -1
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   258
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   259
	$flag_count{$WAKE_BIT} = $flag_count{$W_OUTLIER_BIT} = $flag_count{$ERRVEL_BIT} =
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   260
	$flag_count{$CORREL_BIT} = $flag_count{$SHEAR_BIT} = $flag_count{$BADVEL_BIT} =
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   261
	$flag_count{$SIDELOBE_BIT} = $flag_count{$PPI_BIT} = $flag_count{$W_CTD_BIT} =
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   262
	$flag_count{$TILT_BIT} = $flag_count{$DELTA_TILT_BIT} = $flag_count{$MISSING_CTD_DATA_BIT} = 0;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   263
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   264
	for (my($ens)=$start; $ens!=$end+$De; $ens+=$De) {					# loop over all ens from start to end
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   265
		next unless ($LADCP{ENSEMBLE}[$ens]->{W});
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   266
		if (abs($LADCP{ENSEMBLE}[$ens]->{CTD_W}-$LADCP{ENSEMBLE}[$ens]->{W}) > $w_max_err) {	# get rid of aliased vels (ambiguity)
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   267
			for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   268
				$edit_flags[$ens][$bin] |= $W_CTD_BIT;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   269
				$flag_count{$W_CTD_BIT}++;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   270
			}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   271
			next;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   272
		}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   273
		if (!defined($LADCP{ENSEMBLE}[$ens]->{TILT}) ||
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   274
			 $LADCP{ENSEMBLE}[$ens]->{TILT}>$max_tilt) {				# get rid ensembles with large tilt
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   275
			for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   276
				$edit_flags[$ens][$bin] |= $TILT_BIT;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   277
				$flag_count{$TILT_BIT}++;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   278
			}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   279
			next;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   280
		}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   281
		unless (numberp($LADCP{ENSEMBLE}[$ens]->{DEPTH}) &&				# get rid of ensembles with insufficient CTD info
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   282
				numberp($LADCP{ENSEMBLE}[$ens]->{CTD_SVEL})) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   283
			for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   284
				$edit_flags[$ens][$bin] |= $MISSING_CTD_DATA_BIT;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   285
				$flag_count{$MISSING_CTD_DATA_BIT}++;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   286
			}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   287
			next;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   288
		}																# get rid ensembles after large rotation
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   289
		if (defined($LADCP{ENSEMBLE}[$ens]->{TILT}) &&
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   290
			defined($LADCP{ENSEMBLE}[$ens-$De]->{TILT}) &&
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   291
			abs($LADCP{ENSEMBLE}[$ens]->{TILT}-$LADCP{ENSEMBLE}[$ens-$De]->{TILT}) > $max_delta_tilt) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   292
				for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   293
					$edit_flags[$ens][$bin] |= $DELTA_TILT_BIT;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   294
					$flag_count{$DELTA_TILT_BIT}++;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   295
				}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   296
	            next;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   297
		}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   298
		for (my($bin)=$shbin_start-1; $bin<$shbin_end; $bin++) {		# flag bad velocities
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   299
			$edit_flags[$ens][$bin] |= $BADVEL_BIT,$flag_count{$BADVEL_BIT}++
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   300
   				unless defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$W]);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   301
		}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   302
		set_wake_flag($ens,$De);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   303
		set_misc_flags($ens,$De);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   304
		set_PPI_flags($ens,$De)
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   305
			if $PPI_editing_enabled && ($clip_margin > 0);				# PPI editing is off by default
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   306
    }
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   307
}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   308
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   309
#==============================================================================
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   310
# CALCULATE VELOCITY SHEAR
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   311
#	- final output in @ush_mu,@vsh_mu,@wsh_mu,@ush_sig,@vsh_sig,@wsh_sig
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   312
#		NEW (ant): elapsed time output in @esh_mu
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   313
#				   lat/lon output in @lash_mu, @losh_mu
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   314
# 	- @sh_i0, @sh_i1, @dsh, @ush, @vsh, @wsh are defined "local" in &calc_shear
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   315
#==============================================================================
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   316
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   317
#----------------------------------------------------------------------
31
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
   318
# uv_to_shear(ens,calc_pkg_vel)
30
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   319
#	- sets @sh_i0, @sh_i1, @dsh, @ush, @vsh, @wsh for a given ensemble
31
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
   320
#	- also sets $LADCP{ENSEMBLE}[$ens]->{PACKAGE_VELOCITY} on -v
30
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   321
#----------------------------------------------------------------------
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   322
31
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
   323
sub uv_to_shear($$)
30
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   324
{
31
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
   325
	my($ens,$calc_pkg_vel) = @_;
30
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   326
	my($nvel) = 0;
31
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
   327
	my(@pu,@pv);
30
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   328
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   329
	@sh_i0 = @sh_i1 = ();
31
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
   330
	for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) { 								# select valid velocities
30
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   331
		next if ($edit_flags[$ens][$bin] || $LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$W]==0);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   332
		$nvel++;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   333
		push(@sh_i1,$bin) if (@sh_i0);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   334
		push(@sh_i0,$bin) if ($bin < $LADCP{N_BINS}-1);
31
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
   335
		if (defined($calc_pkg_vel)) {
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
   336
			my($ovgi) = int(&depthOfBin($ens,$bin) / $GRID_DZ);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
   337
			push(@pu,$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$U]-$ovu[$ovgi]);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
   338
			push(@pv,$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$V]-$ovv[$ovgi]);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
   339
		}
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
   340
    }
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
   341
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
   342
    if (defined($calc_pkg_vel)) {													# calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
   343
    	$LADCP{ENSEMBLE}[$ens]->{PACKAGE_VELOCITY}[$U] = avg(@pu);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
   344
    	$LADCP{ENSEMBLE}[$ens]->{PACKAGE_VELOCITY}[$V] = avg(@pv);
30
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   345
    }
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   346
	
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   347
	@dsh = ();
31
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
   348
	for (my($i)=0; $i<@sh_i1; $i++) {												# calc and bin shears
30
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   349
		my($d0) = &depthOfBin($ens,$sh_i0[$i]);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   350
		my($d1) = &depthOfBin($ens,$sh_i1[$i]);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   351
		next unless ($d0>=0 && $d1>=0);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   352
#		die("$0: assertion failed (ens=$ens i=$i depth=$LADCP{ENSEMBLE}[$ens]->{DEPTH} sh_i0[$i]=$sh_i0[$i] sh_i1[$i]=$sh_i1[$i] d0=$d0 d1=$d1)")
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   353
#			unless ($d0>=0 && $d1>=0);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   354
#		die("$0: assertion failed (ens=$ens i=$i sh_i0[$i]=$sh_i0[$i] sh_i1[$i]=$sh_i1[$i] d0=$d0 d1=$d1)")
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   355
#			unless (($LADCP{ENSEMBLE}[$ens]->{XDUCER_FACING_DOWN} && $d1-$d0>0) ||
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   356
#					($LADCP{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}   && $d1-$d0<0));
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   357
		$dsh[$i] = ($d1 + $d0) / 2;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   358
		$ush[$i] = ($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$sh_i1[$i]][$U] -
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   359
					$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$sh_i0[$i]][$U]) / ($d1-$d0);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   360
		$vsh[$i] = ($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$sh_i1[$i]][$V] -
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   361
					$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$sh_i0[$i]][$V]) / ($d1-$d0);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   362
		$wsh[$i] = ($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$sh_i1[$i]][$W] -
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   363
					$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$sh_i0[$i]][$W]) / ($d1-$d0);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   364
		$ens[$i] = $ens;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   365
	}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   366
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   367
	return $nvel;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   368
}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   369
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   370
# here ush_mu, sh_n, etc are still set from the pre-gridding pass
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   371
sub set_shear_flag($)
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   372
{
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   373
	my($ens) = @_;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   374
	my(@ibad,@ush_dev,@vsh_dev);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   375
	
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   376
	for (my($i)=0; $i<@dsh; $i++) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   377
		die("$0: assertion failed") unless numberp($dsh[$i]);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   378
		my($bsgi) = int($dsh[$i] / $SHEAR_PREGRID_DZ);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   379
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   380
		$ush_dev[$i] = $ush[$i] - $ush_mu[$bsgi];
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   381
		$vsh_dev[$i] = $vsh[$i] - $vsh_mu[$bsgi];
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   382
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   383
		push(@ibad,$i) if ($ush_sig[$i] > 0 &&
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   384
							(abs($ush_dev[$i]/$ush_sig[$i]) > $max_shdev ||
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   385
               				 abs($vsh_dev[$i]/$vsh_sig[$i]) > $max_shdev));
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   386
	} ## end of loop through shears
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   387
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   388
	## Look for internal glitches: a positive shear followed
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   389
	## immediately by a compensating negative shear, for
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   390
	## example.  When one is found, flag the common velocity
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   391
	## sample, and untag the two shears by setting each ibad
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   392
	## to -1.
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   393
	for (my($bi)=0; $bi<@ibad-1; $bi++) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   394
		next unless ($ibad[$bi]+1 == $ibad[$bi+1]);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   395
		
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   396
		my($i) = $ibad[$bi];
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   397
		my($bsgi) = int($dsh[$i] / $SHEAR_PREGRID_DZ);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   398
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   399
		if ($ush_sig[$bsgi] > 0 && $vsh_sig[$bsgi] > 0 && 
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   400
			sqrt(($ush_dev[$i]+$ush_dev[$i+1])**2/$ush_sig[$bsgi]**2) < $max_shdev_sum &&
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   401
			sqrt(($vsh_dev[$i]+$vsh_dev[$i+1])**2/$vsh_sig[$bsgi]**2) < $max_shdev_sum) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   402
				$flag_count{$SHEAR_BIT}++;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   403
				$edit_flags[$ens][$sh_i1[$i]] |= $SHEAR_BIT;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   404
				$ibad[$bi] = $ibad[$bi+1] = -1;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   405
		}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   406
	} ## end of first loop through bad shears
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   407
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   408
	## Now flag all remaining velocities involved in the shears
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   409
	## listed by ibad.
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   410
	for (my($bi)=0; $bi<@ibad; $bi++) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   411
		next if ($ibad[$bi] < 0);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   412
		$flag_count{$SHEAR_BIT} += 2;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   413
		$edit_flags[$ens][$sh_i0[$ibad[$bi]]] |= $SHEAR_BIT;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   414
		$edit_flags[$ens][$sh_i1[$ibad[$bi]]] |= $SHEAR_BIT;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   415
	}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   416
}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   417
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   418
sub calc_shear($$$$)
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   419
{
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   420
	my($start,$end,$grid_dz,$edit_shear) = @_;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   421
	my($De) = $start<$end ? 1 : -1;										# downcast: De = 1; upcast: De = -1
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   422
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   423
	local(@ush_vals,@vsh_vals,@wsh_vals,@ens_vals);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   424
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   425
	my($nvel,$nsh) = (0,0);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   426
	for (my($ens)=$start; $ens!=$end+$De; $ens+=$De) {					# loop over all ens from start to end
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   427
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   428
		local(@sh_i0,@sh_i1);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   429
		local(@dsh,@ush,@vsh,@wsh,@ens);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   430
31
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
   431
		uv_to_shear($ens,0);
30
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   432
		if ($edit_shear) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   433
			set_shear_flag($ens);
31
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 30
diff changeset
   434
			$nvel += uv_to_shear($ens,defined($opt_v));
30
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   435
			$nsh += @dsh;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   436
		}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   437
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   438
		for (my($i)=0; $i<@dsh; $i++) {									# save shears for binning calculations
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   439
			my($gi) = int($dsh[$i] / $grid_dz);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   440
			push(@{$ush_vals[$gi]},$ush[$i]);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   441
			push(@{$vsh_vals[$gi]},$vsh[$i]);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   442
			push(@{$wsh_vals[$gi]},$wsh[$i]);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   443
			push(@{$ens_vals[$gi]},$ens[$i]);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   444
        }			
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   445
	} # $ens loop
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   446
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   447
	outTDseries($De==1) if ($edit_shear);								# output depth-time time series
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   448
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   449
	@ush_mu  = @vsh_mu  = @wsh_mu  = @esh_mu = @lash_mu = @losh_mu = ();
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   450
	@ush_sig = @vsh_sig = @wsh_sig = ();
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   451
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   452
	for (my($gi)=0; $gi<@ush_vals; $gi++) {								# calc grid means & stddev
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   453
		my($sum_ush,$sum_vsh,$sum_wsh,$sum_esh,$sum_lash,$sum_losh);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   454
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   455
		$sh_n[$gi] = @{$ush_vals[$gi]};
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   456
		
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   457
		for (my($vi)=0; $vi<$sh_n[$gi]; $vi++) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   458
			$sum_ush += $ush_vals[$gi][$vi];
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   459
			$sum_vsh += $vsh_vals[$gi][$vi];
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   460
			$sum_wsh += $wsh_vals[$gi][$vi];
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   461
			$sum_esh += $LADCP{ENSEMBLE}[$ens_vals[$gi][$vi]]->{ELAPSED_TIME}+$CTD{first_elapsed}-$opt_l;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   462
			$sum_lash += $LADCP{ENSEMBLE}[$ens_vals[$gi][$vi]]->{CTD_LAT};
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   463
			$sum_losh += $LADCP{ENSEMBLE}[$ens_vals[$gi][$vi]]->{CTD_LON};
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   464
		}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   465
		$ush_mu[$gi] = $sh_n[$gi] ? $sum_ush/$sh_n[$gi] : nan;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   466
		$vsh_mu[$gi] = $sh_n[$gi] ? $sum_vsh/$sh_n[$gi] : nan;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   467
		$wsh_mu[$gi] = $sh_n[$gi] ? $sum_wsh/$sh_n[$gi] : nan;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   468
		$esh_mu[$gi] = $sh_n[$gi] ? $sum_esh/$sh_n[$gi] : nan;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   469
		$lash_mu[$gi] = $sh_n[$gi] ? $sum_lash/$sh_n[$gi] : nan;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   470
		$losh_mu[$gi] = $sh_n[$gi] ? $sum_losh/$sh_n[$gi] : nan;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   471
	}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   472
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   473
	for (my($gi)=0; $gi<@ush_vals; $gi++) {								# calc & grid stddevs
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   474
		my($sumsq_ush,$sumsq_vsh,$sumsq_wsh);
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   475
		for (my($vi)=0; $vi<$sh_n[$gi]; $vi++) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   476
			$sumsq_ush += ($ush_vals[$gi][$vi] - $ush_mu[$gi])**2;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   477
			$sumsq_vsh += ($vsh_vals[$gi][$vi] - $vsh_mu[$gi])**2;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   478
			$sumsq_wsh += ($wsh_vals[$gi][$vi] - $wsh_mu[$gi])**2;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   479
		}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   480
		$ush_sig[$gi] = $sh_n[$gi]>1 ? sqrt($sumsq_ush/($sh_n[$gi]-1)) : nan;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   481
		$vsh_sig[$gi] = $sh_n[$gi]>1 ? sqrt($sumsq_vsh/($sh_n[$gi]-1)) : nan;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   482
		$wsh_sig[$gi] = $sh_n[$gi]>1 ? sqrt($sumsq_wsh/($sh_n[$gi]-1)) : nan;
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   483
	}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   484
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   485
	if ($edit_shear && $opt_d) {
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   486
		print(STDERR "\n\t\t$nvel valid velocities");
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   487
		print(STDERR "\n\t\t$nsh valid shears");
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   488
		print(STDERR "\n\t\tflag counts:");
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   489
		print(STDERR "\n\t\t\tBADVEL_BIT     = $flag_count{$BADVEL_BIT}")
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   490
			if ($flag_count{$BADVEL_BIT});
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   491
		print(STDERR "\n\t\t\tERRVEL_BIT     = $flag_count{$ERRVEL_BIT}")
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   492
			if ($flag_count{$ERRVEL_BIT});
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   493
		print(STDERR "\n\t\t\tCORREL_BIT     = $flag_count{$CORREL_BIT}")
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   494
			if ($flag_count{$W_OUTLIER_BIT});
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   495
		print(STDERR "\n\t\t\tW_OUTLIER_BIT  = $flag_count{$W_OUTLIER_BIT}")
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   496
			if ($flag_count{$W_OUTLIER_BIT});
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   497
		print(STDERR "\n\t\t\tSHEAR_BIT      = $flag_count{$SHEAR_BIT}")
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   498
			if ($flag_count{$SIDELOBE_BIT});
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   499
	    print(STDERR "\n\t\t\tSIDELOBE_BIT   = $flag_count{$SIDELOBE_BIT}")
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   500
	    	if ($flag_count{$SIDELOBE_BIT});
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   501
		print(STDERR "\n\t\t\tWAKE_BIT       = $flag_count{$WAKE_BIT}")
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   502
			if ($flag_count{$WAKE_BIT});
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   503
	    print(STDERR "\n\t\t\tPPI_BIT        = $flag_count{$PPI_BIT}")
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   504
	    	if ($flag_count{$PPI_BIT});
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   505
	    printf(STDERR "\n\t\t\tW_CTD_BIT      = $flag_count{$W_CTD_BIT} (%d ensembles)",
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   506
														$flag_count{$W_CTD_BIT}/$LADCP{N_BINS})
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   507
			if ($flag_count{$W_CTD_BIT});
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   508
	    printf(STDERR "\n\t\t\tTILT_BIT       = $flag_count{$TILT_BIT} (%d ensembles)",
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   509
														$flag_count{$TILT_BIT}/$LADCP{N_BINS})
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   510
			if ($flag_count{$TILT_BIT});
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   511
	    printf(STDERR "\n\t\t\tDELTA_TILT_BIT = $flag_count{$DELTA_TILT_BIT} (%d ensembles)",
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   512
														$flag_count{$DELTA_TILT_BIT}/$LADCP{N_BINS})
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   513
			if ($flag_count{$DELTA_TILT_BIT});														
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   514
	    printf(STDERR "\n\t\t\tMISSING_CTD_DATA_BIT = $flag_count{$MISSING_CTD_DATA_BIT} (%d ensembles)",
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   515
														$flag_count{$MISSING_CTD_DATA_BIT}/$LADCP{N_BINS})
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   516
			if ($flag_count{$MISSING_CTD_DATA_BIT});														
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   517
	}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   518
}
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   519
8697ba5a88ec before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   520
1;