before implementing WBWens (PD0 writing)
authorA.M. Thurnherr <athurnherr@yahoo.com>
Mon, 25 Nov 2013 17:27:35 +0000
changeset 13 b176da8559b3
parent 12 0f89b1523648
child 14 8c79b38a7086
before implementing WBWens (PD0 writing)
RDI_Coords.pl
listBins
listEns
--- a/RDI_Coords.pl
+++ b/RDI_Coords.pl
@@ -1,9 +1,9 @@
 #======================================================================
 #                    R D I _ C O O R D S . P L 
 #                    doc: Sun Jan 19 17:57:53 2003
-#                    dlm: Sun Jan 15 20:04:13 2012
+#                    dlm: Wed Aug  7 11:18:51 2013
 #                    (c) 2003 A.M. Thurnherr
-#                    uE-Info: 33 74 NIL 0 0 72 0 2 4 NIL ofnI
+#                    uE-Info: 199 23 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 # RDI Workhorse Coordinate Transformations
@@ -31,6 +31,8 @@
 #	Jan 22, 2011: - made velApplyHdgBias calculate sin/cos every time to allow
 #				    per-ensemble corrections
 #	Jan 15, 2012: - replaced defined(@...) by (@...) to get rid of warning
+#	Aug  7, 2013: - BUG: &velBeamToBPInstrument did not return any val unless
+#						 all beam velocities are defined
 
 use strict;
 use POSIX;
@@ -159,9 +161,6 @@
 		my($dta,$ens,$b1,$b2,$b3,$b4) = @_;
 		my($v12,$w12,$v34,$w34);
 
-		return (undef,undef,undef,undef)
-			unless defined($b1) && defined($b2) && defined($b3) && defined($b4);
-
 		unless (defined($TwoCosBAngle)) {
 			$TwoCosBAngle = 2 * cos(rad($dta->{BEAM_ANGLE}));
 			$TwoSinBAngle = 2 * sin(rad($dta->{BEAM_ANGLE}));
@@ -196,6 +195,9 @@
         	$v34 = $v34_ic*$cp + $w34_ic*$sp + $w12_ic*$sr;
 		}
 
+		$v12=$w12=undef unless (defined($b1) && defined($b2));
+		$v34=$w34=undef unless (defined($b3) && defined($b4));
+
 		return ($v12,$w12,$v34,$w34);
 	}
 }
--- a/listBins
+++ b/listBins
@@ -2,9 +2,9 @@
 #======================================================================
 #                    L I S T B I N S 
 #                    doc: Fri Aug 25 15:57:05 2006
-#                    dlm: Mon Apr 29 11:50:06 2013
+#                    dlm: Wed Aug  7 10:04:28 2013
 #                    (c) 2006 A.M. Thurnherr
-#                    uE-Info: 108 20 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 48 46 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # Split data file into per-bin time series.
@@ -45,6 +45,7 @@
 #	Aug 22, 2010: - added -R
 #	Apr 29, 2013: - cosmetics
 #				  - added warning on missing -S
+#	Aug  7, 2013: - BUG: -w did not respect -d
 
 # General Notes:
 #	- everything (e.g. beams) is numbered from 1
@@ -271,15 +272,14 @@
 		$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][1] -= $P{velbias_b2};
 		$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][2] -= $P{velbias_b3};
 		$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3] -= $P{velbias_b4};
+		if (defined($opt_d)) {
+			undef($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][$opt_d-1]);
+			undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][$opt_d-1]);
+		}
 		if ($opt_w) {
 			@{$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b]} =
 				velBeamToBPEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]});
 		}
-
-		if (defined($opt_d)) {
-			undef($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][$opt_d-1]);
-			undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][$opt_d-1]);
-		}
 		for (my($i)=0; $i<4; $i++) {
 			if ($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][$i] < $opt_p) {
 				undef($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][$i]);
--- a/listEns
+++ b/listEns
@@ -2,9 +2,9 @@
 #======================================================================
 #                    L I S T E N S 
 #                    doc: Sat Jan 18 18:41:49 2003
-#                    dlm: Fri Apr 12 10:37:10 2013
+#                    dlm: Wed Aug  7 10:38:17 2013
 #                    (c) 2003 A.M. Thurnherr
-#                    uE-Info: 39 49 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 215 0 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # Print useful info from the ensemble list or dump ensembles to
@@ -37,6 +37,11 @@
 #	May 12, 2011: - disabled error exit on built-in-test errors when ensembles are dumped to stdout
 #	Mar 20, 2013: - removed DATA_FORMAT stuff
 #	Apr 12, 2013: - added bin number to -E output
+#	Aug  7, 2013: - added -d, -4
+#				  - added w12, w34 to -E output
+#				  - added sounspeed correction warning
+#				  - changed -E from prefix to suffix
+#				  - added active header line to -E output
 
 # Notes:
 #	- -E outputs data in earth coordinates, unless -b is set also
@@ -50,10 +55,13 @@
 
 die("Usage: $0 [-A)nts] [-Q)uiet (errcheck only)] " .
 			  "[-f)ields <[name=]FIELD[,...]>] " .
-			  "[write -E)nsemples <pref> [-M)agnetic <declination>] [min -p)ercent-good <#>] [keep -b)eam coords]] " .
+			  "[require -4)-beam solutions] [-d)iscard <beam#>] " .
+			  "[write -E)nsemples <.suff> [-M)agnetic <declination>] [min -p)ercent-good <#>] [keep -b)eam coords]] " .
 			  "[-r)ange <first_ens,last_ens>] [in-w)ater ensembles only] " .
 			  "<RDI file...>\n")
-	unless (&Getopts("AbE:f:M:p:Qr:w") && $#ARGV >= 0);
+	unless (&Getopts("4Abd:E:f:M:p:Qr:w") && $#ARGV >= 0);
+
+print(STDERR "WARNING: no soundspeed correction applied!\n");
 
 print(STDERR "WARNING: magnetic declination not set!\n")
 	if defined($opt_E) && !defined($opt_M);
@@ -61,6 +69,9 @@
 die("$0: illegal option combination\n")
 	if ($opt_Q && $opt_A) || ((defined($opt_M) || defined($opt_p) || defined($opt_b)) && !defined($opt_E));
 
+die("$0: -4 and -d are mutually exclusive\n")
+	if ($opt_4 && defined($opt_d));
+
 ($first_ens,$last_ens) = split(',',$opt_r)
 	if defined($opt_r);
 
@@ -84,6 +95,8 @@
 #	print(STDERR "\@addFields = @addFields\n");
 }
 
+$RDI_Coords::minValidVels = 4 if ($opt_4);			# no 3-beam solutions
+
 #----------------------------------------------------------------------
 # MAIN
 #----------------------------------------------------------------------
@@ -149,9 +162,10 @@
 		{
 			my($e) = @_;
 			my($b,$i);
-			my($file) = "$opt_E.$dta{ENSEMBLE}[$e]->{NUMBER}";
+			my($file) = "$dta{ENSEMBLE}[$e]->{NUMBER}$opt_E";
 		
 			open(P,">$file") || die("$file: $!\n");
+			print(P "#!/usr/bin/perl -S list\n");
 			print(P "#ANTS#PARAMS# " .
 					"BT_u{$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[0]} " .
 					"BT_v{$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[1]} " .
@@ -165,10 +179,11 @@
 					"BT_amp2{$dta{ENSEMBLE}[$e]->{BT_AMPLITUDE}[1]} " .
 					"BT_amp3{$dta{ENSEMBLE}[$e]->{BT_AMPLITUDE}[2]} " .
 					"BT_amp4{$dta{ENSEMBLE}[$e]->{BT_AMPLITUDE}[3]} " .
+					"soundspeed_correction{NONE!} " .
 					"\n"
 			);
 			print(P "#ANTS#FIELDS# " .
-					"{bin} {dz} {u} {v} {w} {e} {cor1} {cor2} {cor3} {cor4} " .
+					"{bin} {dz} {u} {v} {w} {e} {w12} {w34} {cor1} {cor2} {cor3} {cor4} " .
 					"{amp1} {amp2} {amp3} {amp4} "
 			);
 			if ($beamCoords) {
@@ -179,18 +194,20 @@
 			print(P "$addLayout\n");
 			    
 			for (my($b)=0; $b<$dta{N_BINS}; $b++) {
-				my(@v);
+				my(@v,$w12,$w34);
 				my($dz) = $dta{DISTANCE_TO_BIN1_CENTER} + $b*$dta{BIN_LENGTH};
 		
 				if ($beamCoords) {
 					undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0])
-						if ($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0] < $opt_p);
+						if (($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0] < $opt_p) || ($opt_d == 1));
 					undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][1])
-						if ($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][1] < $opt_p);
+						if (($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][1] < $opt_p) || ($opt_d == 2));
 					undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][2])
-						if ($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][2] < $opt_p);
+						if (($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][2] < $opt_p) || ($opt_d == 3));
 					undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3])
-						if ($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][3] < $opt_p);
+						if (($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][3] < $opt_p) || ($opt_d == 4));
+					($dummy,$w12,$dummy,$w34) =
+						velBeamToBPEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]});
 					@v = $opt_b ? @{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]} :
 							velInstrumentToEarth(\%dta,$e,
 								velBeamToInstrument(\%dta,
@@ -199,12 +216,14 @@
 					@v = velApplyHdgBias(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]});
 				}
 		
-				$v[0] = nan unless defined($v[0]);
-				$v[1] = nan unless defined($v[1]);
-				$v[2] = nan unless defined($v[2]);
-				$v[3] = nan unless defined($v[3]);
+				$v[0] = nan unless defined($v[0]);		# u
+				$v[1] = nan unless defined($v[1]);		# v
+				$v[2] = nan unless defined($v[2]);		# w
+				$v[3] = nan unless defined($v[3]);		# err_vel
+				$w12 = nan unless defined($w12);		# w from beams 1&2
+				$w34 = nan unless defined($w34);		# w from beams 3&4
 				my(@out) = (
-					$b,$dz,$v[0],$v[1],$v[2],$v[3],
+					$b,$dz,$v[0],$v[1],$v[2],$v[3],$w12,$w34,
 					@{$dta{ENSEMBLE}[$e]->{CORRELATION}[$b]},
 					@{$dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b]},
 					@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]}
@@ -214,7 +233,7 @@
 					$fn = $f unless defined($fn);
 					push(@out,eval("\$dta{ENSEMBLE}[$e]->{$fn}$fi"));
 				}
-				for ($i=0; $i<17+@addFields; $i++) {
+				for ($i=0; $i<19+@addFields; $i++) {
 					$out[$i] = nan unless defined($out[$i]);
 				}
 				print(P "@out\n");