version sent to P16N
authorA.M. Thurnherr <athurnherr@yahoo.com>
Mon, 23 Feb 2015 10:43:47 +0000
changeset 21 0b5bbe60131c
parent 19 e23a5fd2923a
child 22 051b45f1c571
version sent to P16N
RDI_PD0_IO.pl
listBins
listEns
listHdr
mkProfile
splitRDI
--- a/RDI_PD0_IO.pl
+++ b/RDI_PD0_IO.pl
@@ -1,9 +1,9 @@
 #======================================================================
-#                    R D I _ P D 0 _ I O . P L 
+#                    R D I _ B B _ R E A D . P L 
 #                    doc: Sat Jan 18 14:54:43 2003
-#                    dlm: Wed May  7 10:41:18 2014
+#                    dlm: Wed Oct 15 21:50:07 2014
 #                    (c) 2003 A.M. Thurnherr
-#                    uE-Info: 827 0 NIL 0 0 72 74 2 4 NIL ofnI
+#                    uE-Info: 65 77 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 # Read RDI BroadBand Binary Data Files (*.[0-9][0-9][0-9])
@@ -59,6 +59,10 @@
 #	Apr 24, 2014: - added debug statements to log %-GOOD values
 #	May  6, 2014: - loosened input format checks
 #	May  7, 2014: - removed BT_present flag
+#	Sep  6, 2014: - adapted WBRhdr to >7 data types
+#	Oct 15, 2014: - implemented work-around for readData() not recognizing
+#					incomplete ensemble at the end, which seems to imply that there is
+#				    a garbage final ensemble that passes the checksum test???
 
 # FIRMWARE VERSIONS:
 #	It appears that different firmware versions generate different file
@@ -332,11 +336,12 @@
 		= unpack('CCvCC',$buf);
 	$hid == 0x7f || die(sprintf($FmtErr,$WBRcfn,"Header",$hid,0));
 ##	$did == 0x7f || die(sprintf($FmtErr,$WBRcfn,"Data Source",$did,0));
-	printf(STDERR "\n$WBRcfn: WARNING: unexpected number of data types (%d)\n",
+	printf(STDERR "WARNING: unexpected number of data types (%d)\n",
 		$dta->{NUMBER_OF_DATA_TYPES})
 			unless ($dta->{NUMBER_OF_DATA_TYPES} == 6 ||
 					$dta->{NUMBER_OF_DATA_TYPES} == 7);
-	$dta->{BT_PRESENT} = ($dta->{NUMBER_OF_DATA_TYPES} == 7);
+##	$dta->{BT_PRESENT} = ($dta->{NUMBER_OF_DATA_TYPES} == 7);
+	$dta->{BT_PRESENT} = ($dta->{NUMBER_OF_DATA_TYPES} >= 7);
 					  
 	sysread(WBRF,$buf,2*$dta->{NUMBER_OF_DATA_TYPES})
 		== 2*$dta->{NUMBER_OF_DATA_TYPES}
@@ -399,11 +404,19 @@
 	$id = unpack('v',$buf);
 	$id == 0x0400 || die(sprintf($FmtErr,$WBRcfn,"Percent-Good Data",$id,1));
 
+	my($BT_dt);
 	if ($dta->{BT_PRESENT}) {
-		sysseek(WBRF,$WBRofs[6],0) || die("$WBRcfn: $!");
-		sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!");
-		$id = unpack('v',$buf);
-		$id == 0x0600 || die(sprintf($FmtErr,$WBRcfn,"Bottom Track",$id,1));
+		for ($BT_dt=6; $BT_dt<$dta->{NUMBER_OF_DATA_TYPES}; $BT_dt++) {										# scan until BT found
+			sysseek(WBRF,$WBRofs[$BT_dt],0) || die("$WBRcfn: $!");
+			sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!");
+			$id = unpack('v',$buf);
+			last if ($id == 0x0600);
+		}
+
+		if ($BT_dt == $dta->{NUMBER_OF_DATA_TYPES}) {
+			printf(STDERR "WARNING: no BT data found\n");die;
+			undef($dta->{BT_PRESENT});
+		}
     }
 
 	#--------------------
@@ -515,7 +528,7 @@
 	#-----------------------
 
 	if ($dta->{BT_PRESENT}) {
-		sysseek(WBRF,$WBRofs[6],0) || die("$WBRcfn: $!");
+		sysseek(WBRF,$WBRofs[$BT_dt],0) || die("$WBRcfn: $!");
 		sysread(WBRF,$buf,12) == 12 || die("$WBRcfn: $!");
 		($id,$dta->{BT_PINGS_PER_ENSEMBLE},$dta->{BT_DELAY_BEFORE_REACQUIRE},
 		 $dta->{BT_MIN_CORRELATION},$dta->{BT_MIN_EVAL_AMPLITUDE},
@@ -686,6 +699,8 @@
 			${$E}[$ens]->{SECONDS} += $B4/100;
 		}
 
+		pop(@{$E}),last if (${$E}[$ens]->{MONTH}>12);						# 10/15/2014; IWISE#145 UL ???
+
 		if ($fixed_leader_bytes == 58) {									# Explorer DVL
 			sysread(WBRF,$buf,14) == 14 || die("$WBRcfn: $!");
 			(${$E}[$ens]->{ERROR_STATUS_WORD},
@@ -829,7 +844,6 @@
 
 		next if ($nxt == $ndt);													# no BT found => next ens
 
-
 		sysseek(WBRF,14,1) || die("$WBRcfn: $!");								# BT config
 
 		sysread(WBRF,$buf,28) == 28 || die("$WBRcfn: $!");
--- 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: Tue Apr 22 12:39:09 2014
+#                    dlm: Mon Nov 24 19:46:05 2014
 #                    (c) 2006 A.M. Thurnherr
-#                    uE-Info: 50 45 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 284 0 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # Split data file into per-bin time series.
@@ -48,6 +48,7 @@
 #	Aug  7, 2013: - BUG: -w did not respect -d
 #   Mar  4, 2014: - added support for missing PITCH/ROLL/HEADING
 #	Apr 22, 2014: - BUG: extraneous semicolon
+#	Nov 24, 2014: - enabled -w always
 
 # General Notes:
 #	- everything (e.g. beams) is numbered from 1
@@ -82,9 +83,9 @@
 			  "[-P)itch/Roll <bias/bias>] [-B)eamvel <bias/bias/bias/bias>] " .
 		 	  "[require -4)-beam solutions] [-d)iscard <beam#>] " .
 		 	  "[-p)ct-good <min>] " .
-		 	  "[output -b)eam coordinates] [output two separate -w) estimates] " .
+		 	  "[output -b)eam coordinates] " .
 			  "<RDI file>\n")
-	unless (&Getopts("4abB:d:f:M:p:r:P:RS:w") && @ARGV == 1);
+	unless (&Getopts("4abB:d:f:M:p:r:P:RS:") && @ARGV == 1);
 
 ($P{pitch_bias},$P{roll_bias}) = split('[,/]',$opt_P);
 ($P{velbias_b1},$P{velbias_b2},$P{velbias_b3},$P{velbias_b4}) = split('[,/]',$opt_B);
@@ -158,7 +159,7 @@
 			"{xmit_current} {xmit_voltage} " .
 			"{temp} " .
 			($opt_b ? "{v1} {v2} {v3} {v4} " : "{u} {v} {w} {err_vel} ") .
-			($opt_w ? "{v12} {w12} {v34} {w34} " : "" ) .
+			"{v12} {w12} {v34} {w34} " .
 			"{corr1} {corr2} {corr3} {corr4} " .
 			"{amp1} {amp2} {amp3} {amp4} " .
 			($opt_b ? "{pcg1} {pcg2} {pcg3} {pcg4}" : "{3_beam} {min_pcg}")
@@ -194,19 +195,17 @@
 			} else {
 				printf(P "%g ",$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3] * $ssCorr);
 			}
-			if ($opt_w) {
-				printf(P defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][0]) ? "%g " : "nan ",
-							$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][0]);
-				printf(P defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][1]) ? "%g " : "nan ",
-							$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][1]);
-				printf(P defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][2]) ? "%g " : "nan ",
-							$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][2]);
-				printf(P defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][3]) ? "%g " : "nan ",
-							$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][3]);
-			}
+			printf(P defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][0]) ? "%g " : "nan ",
+						$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][0]);
+			printf(P defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][1]) ? "%g " : "nan ",
+						$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][1]);
+			printf(P defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][2]) ? "%g " : "nan ",
+						$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][2]);
+			printf(P defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][3]) ? "%g " : "nan ",
+						$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][3]);
 		} else {
 			print(P "nan nan nan nan ");
-			print(P "nan nan nan nan ") if ($opt_w);
+			print(P "nan nan nan nan ");
 		}
 		print(P "@{$dta{ENSEMBLE}[$e]->{CORRELATION}[$b]} ");
 		print(P "@{$dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b]} ");
@@ -280,10 +279,8 @@
 			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]});
-		}
+		@{$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b]} =
+			velBeamToBPEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]});
 		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: Tue Mar  4 12:56:36 2014
+#                    dlm: Mon Sep  8 19:22:44 2014
 #                    (c) 2003 A.M. Thurnherr
-#                    uE-Info: 46 64 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 244 0 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # Print useful info from the ensemble list or dump ensembles to
@@ -44,6 +44,7 @@
 #				  - added active header line to -E output
 #	Mar  4, 2014: - added partial support for DATA_SOURCE_ID
 #				  - added support for missing PITCH/ROLL/HEADING
+#	Sep  8, 2014: - added -B)T  
 
 # Notes:
 #	- -E outputs data in earth coordinates, unless -b is set also
@@ -58,10 +59,10 @@
 die("Usage: $0 [-A)nts] [-Q)uiet (errcheck only)] " .
 			  "[-f)ields <[name=]FIELD[,...]>] " .
 			  "[require -4)-beam solutions] [-d)iscard <beam#>] " .
-			  "[write -E)nsemples <.suff> [-M)agnetic <declination>] [min -p)ercent-good <#>] [keep -b)eam coords]] " .
+			  "[write -E)nsemples <.suff> [use -B)T] [-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("4Abd:E:f:M:p:Qr:w") && $#ARGV >= 0);
+	unless (&Getopts("4ABbd:E:f:M:p:Qr:w") && $#ARGV >= 0);
 
 print(STDERR "WARNING: no soundspeed correction applied!\n");
 
@@ -69,7 +70,7 @@
 	if defined($opt_E) && !defined($opt_M);
 
 die("$0: illegal option combination\n")
-	if ($opt_Q && $opt_A) || ((defined($opt_M) || defined($opt_p) || defined($opt_b)) && !defined($opt_E));
+	if ($opt_Q && $opt_A) || ((defined($opt_M) || defined($opt_p) || defined($opt_b) || $opt_B) && !defined($opt_E));
 
 die("$0: -4 and -d are mutually exclusive\n")
 	if ($opt_4 && defined($opt_d));
@@ -229,12 +230,26 @@
 				$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],$w12,$w34,
-					@{$dta{ENSEMBLE}[$e]->{CORRELATION}[$b]},
-					@{$dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b]},
-					@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]}
-				);
+
+				my(@out);
+				if ($opt_B) {
+					$v[0] = nan unless defined($dta{ENSEMBLE}[$e]->{BT_VELOCITY}[0]);
+					$v[1] = nan unless defined($dta{ENSEMBLE}[$e]->{BT_VELOCITY}[1]);
+					@out = (
+						$b,$dz,$v[0]-$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[0],
+						$v[1]-$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[1],$v[2],$v[3],$w12,$w34,
+						@{$dta{ENSEMBLE}[$e]->{CORRELATION}[$b]},
+						@{$dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b]},
+						@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]}
+					);
+				} else {
+					@out = (
+						$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]}
+					);
+				}
 				foreach my $f (@addFields) {
 					my($fn,$fi) = ($f =~ m{([^[]*)(\[.*)});
 					$fn = $f unless defined($fn);
--- a/listHdr
+++ b/listHdr
@@ -2,9 +2,9 @@
 #======================================================================
 #                    L I S T H D R 
 #                    doc: Sat Jan 18 18:41:49 2003
-#                    dlm: Thu Apr 24 14:50:23 2014
+#                    dlm: Sat Sep  6 16:43:30 2014
 #                    (c) 2003 A.M. Thurnherr
-#                    uE-Info: 33 81 NIL 0 0 72 8 2 4 NIL ofnI
+#                    uE-Info: 36 55 NIL 0 0 72 10 2 4 NIL ofnI
 #======================================================================
 
 # Print useful info from the RDI BB header
@@ -30,19 +30,41 @@
 #	Jul  9, 2008: - added output regarding available sensors
 #	Mar 20, 2013: - removed DATA_FORMAT stuff
 #	Mar 25, 2013: - added INSTRUMENT_TYPE stuff instead
-#	Apr 24, 2014: - BUG: USE_3_BEAM_ON_LOW_CORR was reported in water-track setup
+#   Apr 24, 2014: - BUG: USE_3_BEAM_ON_LOW_CORR was reported in water-track setup
+#   Jul 12, 2014: - BUG: did not work with multiple input files
+#                 - added -s)ummary option
+#	Sep  9, 2014: - adapted to files with >7 data types
 
+require 'getopts.pl';
 $0 =~ m{(.*/)[^/]+};
 require "$1RDI_BB_Read.pl";
 
-die("Usage: $0 <RDI file[...]>\n")
-	unless (@ARGV);
+die("Usage: $0 [-s)ummary] <RDI file[...]>\n")
+    unless (&Getopts('s' && @ARGV));
+
+if ($opt_s) {
+	print("#!/usr/bin/perl -S list\n");     
+	chmod(0777&~umask,*STDOUT);
+	print("#ANTS#FIELDS# {id} {serial_number} {transducer_frequency} {number_of_bins} {blanking_distance} {bin_length} {pulse_length}\n");
+}
 
 while (-f $ARGV[0]) {
-	print("$ARGV[0]:\n");
-	readHeader(@ARGV,\%hdr);
+	print("$ARGV[0]:\n") unless ($opt_s);
+	readHeader($ARGV[0],\%hdr);
+
+	if ($opt_s) {														# summary ANTS output
+		my($id) = $ARGV[0];
+		$id =~ s/00[0-9]\.000//;										# leave just deployment name for std RDI files
+		$id =~ s@^.*/([^/]+)@\1@;
+		printf("%s %d %d %d %g %d %.1f\n",
+			$id,$hdr{SERIAL_NUMBER},$hdr{BEAM_FREQUENCY},
+			$hdr{N_BINS},$hdr{BLANKING_DISTANCE},$hdr{BIN_LENGTH},
+			$hdr{TRANSMITTED_PULSE_LENGTH});
+		shift;
+		next;
+	}
+
 	shift;
-
 	print("    Instrument Characteristics:\n");
 
 	if (defined($hdr{SERIAL_NUMBER})) {
@@ -86,7 +108,7 @@
 	printf("\tECHO_INTENSITY_DATA_BYTES\t= %3d bytes\n",$hdr{ECHO_INTENSITY_DATA_BYTES});
 	printf("\tPERCENT_GOOD_DATA_BYTES\t\t= %3d bytes\n",$hdr{PERCENT_GOOD_DATA_BYTES});
 	printf("\tBT_DATA_BYTES\t\t\t= %3d bytes\n",$hdr{BT_DATA_BYTES})
-		if ($dta->{BT_PRESENT});
+		if ($hdr{BT_PRESENT});
 
 
 	print("    Coordinate System:\n");
@@ -155,7 +177,7 @@
 
 #----------------------------------------------------------------------
 
-	if ($hdr{NUMBER_OF_DATA_TYPES} == 7) {
+	if ($hdr{BT_PRESENT}) {
 		print("    Bottom-Track Setup:\n");
 		printf("\tBT_MODE\t\t\t\t= %d\n", 		$hdr{BT_MODE});
 		printf("\tBT_PINGS_PER_ENSEMBLE\t\t= %d\n",
--- a/mkProfile
+++ b/mkProfile
@@ -2,9 +2,9 @@
 #======================================================================
 #                    M K P R O F I L E 
 #                    doc: Sun Jan 19 18:55:26 2003
-#                    dlm: Sat May 24 22:50:02 2014
+#                    dlm: Wed Nov  5 13:02:59 2014
 #                    (c) 2003 A.M. Thurnherr
-#                    uE-Info: 797 76 NIL 0 0 72 10 2 4 NIL ofnI
+#                    uE-Info: 255 17 NIL 0 0 72 10 2 4 NIL ofnI
 #======================================================================
 
 # Make an LADCP Profile by Integrating W (similar to Firing's scan*).
@@ -251,12 +251,16 @@
 ($firstgood,$lastgood,$atbottom,$w_gap_time,$zErr,$maxz,$rms_heave_accel) =
 	mk_prof(\%dta,0,$opt_F,$minb,$maxb,$opt_c,$opt_e,$opt_g,$opt_p);
 
-unless (($atbottom > $firstgood) && ($lastgood > $atbottom)) {
+if ($lastgood == $atbottom) {
+	print(STDERR "$ARGV[0]: truncated file (ends at max depth)\n")
+} elsif (($atbottom > $firstgood) && ($lastgood > $atbottom)) {
+	# all good
+} else {
 	if ($opt_Q) {
 		print(STDERR "$ARGV[0]: no valid cast data found\n");
 		exit(0);
     } else {
-		die("$ARGV[0]: no valid cast data found\n");
+		die(sprintf("$ARGV[0]: no valid cast data found (firstgood=%d atbottom=%d lastgood=%d)\n",$firstgood,$atbottom,$lastgood));
 	}
 }
 
--- a/splitRDI
+++ b/splitRDI
@@ -2,9 +2,9 @@
 #======================================================================
 #                    S P L I T R D I 
 #                    doc: Sat Aug 21 22:20:27 2010
-#                    dlm: Wed Mar 19 16:35:45 2014
+#                    dlm: Sun Sep 14 17:47:48 2014
 #                    (c) 2010 A.M. Thurnherr
-#                    uE-Info: 36 43 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 54 0 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # split RDI files based on list of ensemble numbers (e.g. from yoyo -t)
@@ -14,6 +14,7 @@
 #	Jun 24, 2011: - replaced -b, -n by -o
 #   Feb 13, 2014: - updated doc
 #	Mar 19, 2014: - added -s)kip small files
+#	Sep 14, 2014: - added -f)irst 
 
 # NOTES:
 #   - it is assumed that the input file begins with ensemble #1
@@ -33,9 +34,10 @@
 
 die("Usage: $0 " .
 	"[-o)ut-file <fmt[e.g. 017%02dDL000.000]>] " .
+	"[-f)irst <cast #>] " .
 	"[require -m)in <ens> to produce output] " .
 	"<RDI file> <ens> <ens[...]>\n")
-		unless (&getopts('o:m:') && @ARGV>=3);
+		unless (&getopts('f:o:m:') && @ARGV>=3);
 
 $opt_o = substr($ARGV[0],0,3)					# default output filename format
 		 . '%02d'
@@ -60,7 +62,7 @@
 		die("$WBRcfn: file truncated");
 
 	if ($last_ens-$first_ens+1 > $opt_m) {		# produce file only if sufficient # of ensembles
-		$fn = sprintf($opt_o,$cnr++);
+		$fn = sprintf($opt_o,$opt_f+$cnr++);
 		open(F,">$fn") || die("$fn: $!\n");
 		syswrite(F,$buf,$nBytes) == $nBytes ||
 			die("$fn: $!\n");