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