after partial adaptation to RTI files
authorAndreas Thurnherr <ant@ldeo.columbia.edu>
Wed, 26 Jun 2019 09:19:24 -0400
changeset 48 cdc74ebada81
parent 46 777cd0f2456a
child 49 8f4fbdaf0102
after partial adaptation to RTI files
RDI_PD0_IO.pl
RDI_Utils.pl
listBins
listHdr
mkProfile
--- a/RDI_PD0_IO.pl
+++ b/RDI_PD0_IO.pl
@@ -1,9 +1,9 @@
 #======================================================================
 #                    R D I _ P D 0 _ I O . P L 
 #                    doc: Sat Jan 18 14:54:43 2003
-#                    dlm: Tue Jun 12 19:10:08 2018
+#                    dlm: Thu Jun 13 22:13:12 2019
 #                    (c) 2003 A.M. Thurnherr
-#					 uE-Info: 115 72 NIL 0 0 72 2 2 4 NIL ofnI
+#					 uE-Info: 116 45 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 	
 # Read RDI PD0 binary data files (*.[0-9][0-9][0-9])
@@ -58,7 +58,7 @@
 #	Mar  4, 2014: - added support for DATA_SOURCE_ID
 #	Apr 24, 2014: - added debug statements to log %-GOOD values
 #	May  6, 2014: - loosened input format checks
-#	May  7, 2014: - removed BT_present flag
+#	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
@@ -112,7 +112,9 @@
 #	Apr 30, 2018: - added support for repeated ensembles
 #				  - added warning on wrong ensemble length
 #	Jun  9, 2018: - removed double \n from warnings
-#	Jun 12, 2018: - BUG: IMPed files did not pass the garbage detection 
+#	Jun 12, 2018: - BUG: IMPed files did not pass the garbage detection
+#	Jun 13, 2019: - adapted reading routines to RTI files (free order of data types)
+#				  - removed old BT_PRESENT code
 	
 # FIRMWARE VERSIONS:
 #	It appears that different firmware versions generate different file
@@ -189,7 +191,6 @@
 #	CORRELATION_DATA_BYTES			scalar		?
 #	ECHO_INTENSITY_DATA_BYTES		scalar		?
 #	PERCENT_GOOD_DATA_BYTES 		scalar		?
-#	BT_PRESENT						bool		NUMBER_OF_DATA_TYPES == 7
 #	BT_DATA_BYTES					scalar		undefined, ? if BT_PRESENT
 #	CPU_FW_VER						scalar		0--255
 #	CPU_FW_REV						scalar		0--255
@@ -440,9 +441,9 @@
     }
 }
 
-sub WBRhdr(@)
+sub WBRhdr($)
 {
-	my($dta,$checkFmt) = @_;
+	my($dta) = @_;
 	my($start_ens,$buf,$hid,$did,$Ndt,$B,$W,$i,$dummy,$id,@WBRofs);
 	my($B1,$B2,$B3,$B4,$B5,$B6,$B7,$W1,$W2,$W3,$W4,$W5);
 	my($BT_dt);
@@ -477,14 +478,6 @@
 		$dta->{PRODUCER} = sprintf('unknown (0x%02X)');
 	}
 
-	if ($checkFmt) {
-		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);
-	}
-					  
 	sysread(WBRF,$buf,2*$dta->{NUMBER_OF_DATA_TYPES})
 		== 2*$dta->{NUMBER_OF_DATA_TYPES}
 			|| die("$WBRcfn: $!");
@@ -497,17 +490,6 @@
 	$dta->{HEADER_BYTES}					= $WBRofs[0];
 	$dta->{FIXED_LEADER_BYTES}				= $WBRofs[1] - $WBRofs[0];
 	$dta->{VARIABLE_LEADER_BYTES}			= $WBRofs[2] - $WBRofs[1];
-    if ($checkFmt) {
-		$dta->{VELOCITY_DATA_BYTES} 			= $WBRofs[3] - $WBRofs[2];
-		$dta->{CORRELATION_DATA_BYTES}			= $WBRofs[4] - $WBRofs[3];
-		$dta->{ECHO_INTENSITY_DATA_BYTES}		= $WBRofs[5] - $WBRofs[4];
-		if ($dta->{BT_PRESENT}) {
-			$dta->{PERCENT_GOOD_DATA_BYTES} 	= $WBRofs[6] - $WBRofs[5];
-			$dta->{BT_DATA_BYTES}				= $dta->{ENSEMBLE_BYTES} - 4 - $WBRofs[6];
-		} else {
-			$dta->{PERCENT_GOOD_DATA_BYTES} 	= $dta->{ENSEMBLE_BYTES} - 4 - $WBRofs[5];
-	    }
-    }
 
 	if ($dta->{FIXED_LEADER_BYTES} == 42) { 			# Eric Firing's old instrument I used in 2004
 		$dta->{INSTRUMENT_TYPE} = 'BB150';
@@ -539,46 +521,6 @@
 	sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!");
 	$dta->{SPEED_OF_SOUND} = unpack('v',$buf);
 	
-	#----------------------------------
-	# Check Data Format of 1st Ensemble
-	#----------------------------------
-
-	if ($checkFmt) {
-		sysseek(WBRF,$start_ens+$WBRofs[2],0) || die("$WBRcfn: $!");
-		sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!");
-		$id = unpack('v',$buf);
-		$id == 0x0100 || printf(STDERR $FmtErr."\n",$WBRcfn,"Velocity Data",$id,1);
-	
-		sysseek(WBRF,$start_ens+$WBRofs[3],0) || die("$WBRcfn: $!");
-		sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!");
-		$id = unpack('v',$buf);
-		$id == 0x0200 || printf(STDERR $FmtErr."\n",$WBRcfn,"Correlation Data",$id,1);
-	    
-		sysseek(WBRF,$start_ens+$WBRofs[4],0) || die("$WBRcfn: $!");
-		sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!");
-		$id = unpack('v',$buf);
-		$id == 0x0300 || printf(STDERR $FmtErr."\n",$WBRcfn,"Echo Intensity",$id,1);
-	
-		sysseek(WBRF,$start_ens+$WBRofs[5],0) || die("$WBRcfn: $!");
-		sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!");
-		$id = unpack('v',$buf);
-		$id == 0x0400 || printf(STDERR $FmtErr."\n",$WBRcfn,"Percent-Good Data",$id,1);
-	
-		if ($dta->{BT_PRESENT}) {
-			for ($BT_dt=6; $BT_dt<$dta->{NUMBER_OF_DATA_TYPES}; $BT_dt++) { 									# scan until BT found
-				sysseek(WBRF,$start_ens+$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});
-			}
-	    }
-    }
-
 	#--------------------
 	# FIXED LEADER
 	#--------------------
@@ -696,39 +638,6 @@
 		$dta->{WIDE_BANDWIDTH}	 = ($W5 == 0);
     }
 
-	#-----------------------
-	# 1st ENSEMBLE, BT Setup
-	#-----------------------
-
-	if ($dta->{BT_PRESENT}) {
-		sysseek(WBRF,$start_ens+$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},
-		 $dta->{BT_MIN_PERCENT_GOOD},$dta->{BT_MODE},
-		 $dta->{BT_MAX_ERROR_VELOCITY}) = unpack('vvvCCCCv',$buf);
-		 
-		$id == 0x0600 ||
-			printf(STDERR $FmtErr."\n",$WBRcfn,"Bottom Track",$id,0,tell(WBRF));
-	
-		$dta->{BT_MAX_ERROR_VELOCITY} =
-			$dta->{BT_MAX_ERROR_VELOCITY} ? $dta->{BT_MAX_ERROR_VELOCITY} / 1000
-										  : undef;
-	
-		sysseek(WBRF,28,1) || die("$WBRcfn: $!");
-		sysread(WBRF,$buf,6) == 6 || die("$WBRcfn: $!");
-		($dta->{BT_RL_MIN_SIZE},$dta->{BT_RL_NEAR},$dta->{BT_RL_FAR})
-			= unpack('vvv',$buf);
-	
-		$dta->{BT_RL_MIN_SIZE} /= 10;
-		$dta->{BT_RL_NEAR} /= 10;
-		$dta->{BT_RL_FAR} /= 10;
-	    
-		sysseek(WBRF,20,1) || die("$WBRcfn: $!");		# skip data
-		sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!");
-	    $dta->{BT_MAX_TRACKING_DEPTH} = unpack('v',$buf) / 10;
-    }
-    
     return $dta;
 }
 
@@ -744,7 +653,7 @@
 	my($fn,$dta,$fe,$le,$lb) = @_;
 	$WBRcfn = $fn;
     open(WBRF,$WBRcfn) || die("$WBRcfn: $!\n");
-    WBRhdr($dta,1) || die("$WBRcfn: Insufficient Data\n");
+    WBRhdr($dta) || die("$WBRcfn: Insufficient Data\n");
     $lb = $dta->{N_BINS}
 		unless (numberp($lb) && $lb>=1 && $lb<=$dta->{N_BINS});
 	WBRens($lb,$dta->{FIXED_LEADER_BYTES},\@{$dta->{ENSEMBLE}},$fe,$le);
@@ -755,8 +664,9 @@
 sub WBRens(@)
 {
 	my($nbins,$fixed_leader_bytes,$E,$fe,$le) = @_;
-	my($start_ens,$B1,$B2,$B3,$B4,$I,$id,$bin,$beam,$buf,$dummy,@dta,$i,$cs,@WBRofs);
-	my($ens,$ensNo,$dayStart,$ens_length,$hid,$did,$ndt,$el);
+	my($B1,$B2,$B3,$B4,$I,$bin,$beam,$dummy,@dta,$i,$cs);
+	my($ens,$ensNo,$dayStart,$ens_length,$hid,$did,$el);
+	local our($ndt,$buf,$id,$start_ens,@WBRofs);
 
     sysseek(WBRF,0,0) || die("$WBRcfn: $!");
 ENSEMBLE:
@@ -997,13 +907,14 @@
 
 		my($ndata) = $nbins * 4;
 
-		sysseek(WBRF,$start_ens+$WBRofs[2],0) || die("$WBRcfn: $!");
+		my($vel_di) = WBRdtaIndex(0x0100);
+		die("no velocity data in ensemble #$ensNo\n")
+			unless defined($vel_di);
+		
+		sysseek(WBRF,$start_ens+$WBRofs[$vel_di],0) || die("$WBRcfn: $!");
 		sysread(WBRF,$buf,2+$ndata*2) == 2+$ndata*2 || die("$WBRcfn: $!");
 		($id,@dta) = unpack("vv$ndata",$buf);
 
-		$id == 0x0100 ||
-			die(sprintf($FmtErr,$WBRcfn,"Velocity Data",$id,$ensNo));
-		
 		for ($i=0,$bin=0; $bin<$nbins; $bin++) {
 			for ($beam=0; $beam<4; $beam++,$i++) {
 				${$E}[$ens]->{VELOCITY}[$bin][$beam] =
@@ -1016,13 +927,14 @@
 		# Correlation Data
 		#--------------------
 
-		sysseek(WBRF,$start_ens+$WBRofs[3],0) || die("$WBRcfn: $!");
+		my($corr_di) = WBRdtaIndex(0x0200);
+		die("no correlation data in ensemble #$ensNo\n")
+			unless defined($corr_di);
+		
+		sysseek(WBRF,$start_ens+$WBRofs[$corr_di],0) || die("$WBRcfn: $!");
 		sysread(WBRF,$buf,2+$ndata) == 2+$ndata || die("$WBRcfn: $!");
 		($id,@dta) = unpack("vC$ndata",$buf);
 
-		$id == 0x0200 ||
-			die(sprintf($FmtErr,$WBRcfn,"Correlation Data",$id,$ensNo));
-		
 		for ($i=0,$bin=0; $bin<$nbins; $bin++) {
 			for ($beam=0; $beam<4; $beam++,$i++) {
 				${$E}[$ens]->{CORRELATION}[$bin][$beam] = $dta[$i]
@@ -1034,7 +946,11 @@
 		# Echo Intensity Data
 		#--------------------
 
-		sysseek(WBRF,$start_ens+$WBRofs[4],0) || die("$WBRcfn: $!");
+		my($echo_di) = WBRdtaIndex(0x0300);
+		die("no echo intensity data in ensemble #$ensNo\n")
+			unless defined($echo_di);
+		
+		sysseek(WBRF,$start_ens+$WBRofs[$echo_di],0) || die("$WBRcfn: $!");
 		sysread(WBRF,$buf,2+$ndata) == 2+$ndata || die("$WBRcfn: $!");
 		($id,@dta) = unpack("vC$ndata",$buf);
 
@@ -1051,7 +967,11 @@
 		# Percent Good Data
 		#--------------------
 
-		sysseek(WBRF,$start_ens+$WBRofs[5],0) || die("$WBRcfn: $!");
+		my($pctg_di) = WBRdtaIndex(0x0400);
+		die("no percent good data in ensemble #$ensNo\n")
+			unless defined($pctg_di);
+		
+		sysseek(WBRF,$start_ens+$WBRofs[$pctg_di],0) || die("$WBRcfn: $!");
 		sysread(WBRF,$buf,2+$ndata) == 2+$ndata || die("$WBRcfn: $!");
 		($id,@dta) = unpack("vC$ndata",$buf);
 
@@ -1069,19 +989,11 @@
 		#	- scan through remaining data types
 		#-----------------------------------------
 
-		my($nxt);
-		for ($nxt=6; $nxt<$ndt; $nxt++) {										# scan until BT found
-			sysseek(WBRF,$start_ens+$WBRofs[$nxt],0) || die("$WBRcfn: $!");
-			sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!");
-			$id = unpack('v',$buf);
-			last if ($id == 0x0600);
-		}
-
-		if ($nxt == $ndt) {														# no BT found => next ens
-#			sysseek(WBRF,4,1) || die("$WBRcfn: $!");							# skip over remainder of ensemble
+		my($bt_di) = WBRdtaIndex(0x0600);
+		unless (defined($pctg_di)) {											# no BT found => next ens
 			sysseek(WBRF,$start_ens+$ens_length+2,0) || die("$WBRcfn: $!");
 			next;
-		}
+        }		
 
 		sysseek(WBRF,14,1) || die("$WBRcfn: $!");								# BT range, velocity, corr, %-good, ...
 		sysread(WBRF,$buf,28) == 28 || die("$WBRcfn: $!");
@@ -1144,6 +1056,20 @@
 	} # ens loop
 }
 
+sub WBRdtaIndex($)
+{
+	my($trgid) = @_;
+	our($ndt,$buf,$id,$start_ens,@WBRofs);
+	
+	for (my($di)=2; $di<$ndt; $di++) {
+		sysseek(WBRF,$start_ens+$WBRofs[$di],0) || die("$WBRcfn: $!");
+		sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!");
+		$id = unpack('v',$buf);
+		return $di if ($id == $trgid);
+    }
+    return undef;
+}
+
 #----------------------------------------------------------------------
 # writeData(output_file_name,^data) WBPens(nbins,fixed_leader_bytes,^data)
 #	- writeData() copies file previously read with readData() to output_file_name
--- a/RDI_Utils.pl
+++ b/RDI_Utils.pl
@@ -1,9 +1,9 @@
 #======================================================================
 #                    R D I _ U T I L S . P L 
 #                    doc: Wed Feb 12 10:21:32 2003
-#                    dlm: Sat Jun  9 12:11:01 2018
+#                    dlm: Wed Jun 26 09:05:05 2019
 #                    (c) 2003 A.M. Thurnherr
-#                    uE-Info: 61 58 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 300 27 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 # miscellaneous RDI-specific utilities
@@ -59,6 +59,12 @@
 #	Nov 27, 2017: - BUG: profile-restart heuristic did not work with P6#001
 #	Mar 18, 2018: - added -ve dt consistency check
 #	Jun  9, 2018: - added support for ENV{NO_GAP_WARNINGS}
+#	Jun 16, 2019: - adapted (partiall) to support RTI ADCPs:
+#					- made ambiguity_velocity() return nan (missing TL_distance)
+#					- skip missing velocities in reference-layer calculation
+#					- disable %-good screening with $min_pctg == 0
+# 	Jun 26, 2019: - increased short-gap in mk_prof from 5s to 6s to allow processing
+#					of RTi test file with 5s ensembles
 
 use strict;
 
@@ -271,6 +277,7 @@
 sub ambiguity_velocity($$$$)
 {
 	my($xd_freq,$beam_angle,$speed_of_sound,$TL_distance) = @_;
+	return 'nan' unless ($TL_distance > 0);
 	my($lambda) = $speed_of_sound / (1000*$xd_freq);
 	my($D) = $speed_of_sound * cos(rad($beam_angle)) / 2;
 	return $lambda * $D / (4 * $TL_distance);
@@ -290,6 +297,7 @@
 	my($w,$e,$nvi,$vi12,$vi43,@vbp,@velbp,@nbp,$w12,$w34,@w12,@w34);
 
 	for ($i=$rl_b0; $i<=$rl_b1; $i++) {
+		next unless defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i]);
 		undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0])
 			if ($dta->{ENSEMBLE}[$ens]->{CORRELATION}[$i][0] < $min_corr);
 		undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][1])
@@ -311,10 +319,12 @@
 			@v = velInstrumentToEarth($dta,$ens,@vi);
 			@vbp = velBeamToBPEarth($dta,$ens,@{$dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i]});
 		} else {
-			next if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][0] > 0 ||
-					 $dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][1] > 0 ||
-					 $dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][2] > 0 ||
-					 $dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][3] < $min_pctg);
+			if ($min_pctg > 0) {
+				next if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][0] > 0 ||
+						 $dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][1] > 0 ||
+						 $dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][2] > 0 ||
+	                     $dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][3] < $min_pctg);
+            }
 			@v = @{$dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i]};
 		}
 		next if (defined($v[3]) && abs($v[3]) > $max_e);		# allow 3-beam solutions
@@ -496,7 +506,7 @@
 		# The current ensemble has a valid w
 		#-----------------------------------
 
-		if ($dt < 5) {												# no or short gap
+		if ($dt < 6) {												# no or short gap
 			$z += $dta->{ENSEMBLE}[$lastgood]->{W} * $dt;			# integrate w to get depth
 			$zErr += ($dta->{ENSEMBLE}[$lastgood]->{W_ERR} * $dt)**2;
 			$rms_heave_accel_ssq += (($dta->{ENSEMBLE}[$e]->{W}-$dta->{ENSEMBLE}[$lastgood]->{W})/$dt)**2;
--- 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: Wed Aug 29 07:23:21 2018
+#                    dlm: Thu Jun 13 22:17:02 2019
 #                    (c) 2006 A.M. Thurnherr
-#                    uE-Info: 136 20 NIL 0 0 72 0 2 4 NIL ofnI
+#                    uE-Info: 75 58 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 # Split data file into per-bin time series.
@@ -71,6 +71,8 @@
 #				  - added -l)ast bin
 #				  - activate output files
 #	Aug 29, 2018: - added error message on -r decoding failures
+#	Jun 13, 2018: - adpated to RTI files (disabled BIT error check)
+#				  - BUG: dn did not have sufficient digits
 
 # General Notes:
 #	- everything (e.g. beams) is numbered from 1
@@ -221,7 +223,7 @@
 		print(P "$dta{ENSEMBLE}[$e]->{DATE} ");
 		print(P "$dta{ENSEMBLE}[$e]->{TIME} ");
 		printf(P "%d ",$dta{ENSEMBLE}[$e]->{UNIX_TIME}-$t0);												# elapsed time
-		printf(P "%g ",str2dec_time($dta{ENSEMBLE}[$e]->{DATE},$dta{ENSEMBLE}[$e]->{TIME}));				# decimal day 
+		printf(P "%.5f ",str2dec_time($dta{ENSEMBLE}[$e]->{DATE},$dta{ENSEMBLE}[$e]->{TIME}));				# decimal day 
 		print(P defined($dta{ENSEMBLE}[$e]->{HEADING}) ? "$dta{ENSEMBLE}[$e]->{HEADING} " : 'nan ');
 		print(P defined($dta{ENSEMBLE}[$e]->{PITCH}) ? "$dta{ENSEMBLE}[$e]->{PITCH} " : 'nan ');
 		print(P defined($dta{ENSEMBLE}[$e]->{ROLL}) ? "$dta{ENSEMBLE}[$e]->{ROLL} " : 'nan ');
@@ -326,8 +328,8 @@
 
 	die("3-beams used in ensemble #$dta{ENSEMBLE}[$e]->{NUMBER}\n")
 		if ($dta{ENSEMBLE}[$e]->{N_BEAMS_USED} < 4);
-	die("BIT error in ensemble $dta{ENSEMBLE}[$e]->{NUMBER}\n")
-		if defined($dta{ENSEMBLE}[$e]->{BUILT_IN_TEST_ERROR});
+#	die("BIT error in ensemble $dta{ENSEMBLE}[$e]->{NUMBER}\n")
+#		if defined($dta{ENSEMBLE}[$e]->{BUILT_IN_TEST_ERROR});
 	die("Low gain in ensemble #$dta{ENSEMBLE}[$e]->{NUMBER}\n")
         if ($dta{ENSEMBLE}[$e]->{LOW_GAIN});
 
--- a/listHdr
+++ b/listHdr
@@ -2,9 +2,9 @@
 #======================================================================
 #                    L I S T H D R 
 #                    doc: Sat Jan 18 18:41:49 2003
-#                    dlm: Tue Mar 20 12:18:03 2018
+#                    dlm: Thu Jun 13 21:56:00 2019
 #                    (c) 2003 A.M. Thurnherr
-#                    uE-Info: 74 9 NIL 0 0 72 10 2 4 NIL ofnI
+#                    uE-Info: 46 51 NIL 0 0 72 10 2 4 NIL ofnI
 #======================================================================
 
 # Print useful info from the RDI BB header
@@ -43,6 +43,7 @@
 #	Aug  7, 2017: - added LAG_LENGTH
 #				  - added AMBIGUITY_VELOCITY
 #	Aug  8, 2017: - added -l)ong listing
+# 	Jun 13, 2019: - removed BT_PRESENT flag support
 
 use Getopt::Std;
 
@@ -140,8 +141,6 @@
 			if defined($hdr{ECHO_INTENSITY_DATA_BYTES});
 		printf("\tPERCENT_GOOD_DATA_BYTES\t\t= %3d bytes\n",$hdr{PERCENT_GOOD_DATA_BYTES})
 			if defined($hdr{PERCENT_GOOD_DATA_BYTES});
-		printf("\tBT_DATA_BYTES\t\t\t= %3d bytes\n",$hdr{BT_DATA_BYTES})
-	        if ($hdr{BT_PRESENT});
 	}
 
 	print("    Coordinate System:\n");
@@ -208,7 +207,7 @@
 
 #----------------------------------------------------------------------
 
-	if ($hdr{BT_PRESENT}) {
+	if (defined($hdr{BT_MODE})) {
 		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: Tue May  1 10:12:56 2018
+#                    dlm: Thu Apr 18 16:28:13 2019
 #                    (c) 2003 A.M. Thurnherr
-#                    uE-Info: 395 0 NIL 0 0 72 0 2 4 NIL ofnI
+#                    uE-Info: 98 54 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 # Make an LADCP Profile by Integrating W (similar to Firing's scan*).
@@ -95,6 +95,7 @@
 #	Oct 13, 2017: - added instrument orientation
 #	Apr  2, 2018: - BUG: velBeamToInstrument() used old usage
 #	Apr 24, 2018: - BUG: bin1 was used even with zero blanking
+#	Apr 18, 2019: - added coord-transformation %PARAMs
 
 # NOTES:
 #	- the battery values are based on transmission voltages (different
@@ -722,34 +723,37 @@
 					"{pitch} {roll} {tilt} {hdg} {rotation} " .
 					"$uFields $addFields\n");
 
-printf("#ANTS#PARAMS# date{$dta{ENSEMBLE}[$firstgood]->{DATE}} " .
-			   "start_time{$dta{ENSEMBLE}[$firstgood]->{TIME}} " .
-			  "bottom_time{$dta{ENSEMBLE}[$atbottom]->{TIME}} " .
-				 "end_time{$dta{ENSEMBLE}[$lastgood]->{TIME}} " .
-	  "bottom_xmit_voltage{$dta{ENSEMBLE}[$atbottom]->{ADC_XMIT_VOLTAGE}} " .
-	  "bottom_xmit_current{$dta{ENSEMBLE}[$atbottom]->{ADC_XMIT_CURRENT}} " .
-				 "PD0_file{$ARGV[0]} " .
-		 "pinging_duration{%.1f} " .
-			"cast_duration{%.1f} " .
-		   "0.8_valid_bins{%.1f} " .
-		  "0.8_valid_range{%.1f} " .
-				"max_depth{%.1f} " .
-			  "depth_error{%.1f} " .
-				  "min_range{%d} " .
-				"n_ensembles{%d} " .
-                 "w_gap_time{%d} " .
-				 "stderr_w{%.4f} " .
-				 "rms_tilt{%.1f} " .
-		"downcast_rms_tilt{%.1f} " .
-          "upcast_rms_tilt{%.1f} " .
-			 "rms_rotation{%.2f} " .
-	   "deployment_rotations{%d} " .
-		 "downcast_rotations{%d} " .
-		   "upcast_rotations{%d} " .
-         "recovery_rotations{%d} " .
-   "rms_heave_acceleration{%.2f} " .
-				"bin1_dist{%.1f} " .
-			   "bin_length{%.1f} " .
+printf(     "#ANTS#PARAMS# date{$dta{ENSEMBLE}[$firstgood]->{DATE}} " .
+			        "start_time{$dta{ENSEMBLE}[$firstgood]->{TIME}} " .
+			       "bottom_time{$dta{ENSEMBLE}[$atbottom]->{TIME}} " .
+		   		      "end_time{$dta{ENSEMBLE}[$lastgood]->{TIME}} " .
+	       "bottom_xmit_voltage{$dta{ENSEMBLE}[$atbottom]->{ADC_XMIT_VOLTAGE}} " .
+	       "bottom_xmit_current{$dta{ENSEMBLE}[$atbottom]->{ADC_XMIT_CURRENT}} " .
+	    			  "PD0_file{$ARGV[0]} " .
+      "RDI_Coords::minValidVels{$RDI_Coords::minValidVels} " .
+        "RDI_Coords::binMapping{$RDI_Coords::binMapping} " .
+"RDI_Coords::beamTransformation{$RDI_Coords::beamTransformation} " .
+			  "pinging_duration{%.1f} " .
+				 "cast_duration{%.1f} " .
+				"0.8_valid_bins{%.1f} " .
+			   "0.8_valid_range{%.1f} " .
+					 "max_depth{%.1f} " .
+				   "depth_error{%.1f} " .
+				     "min_range{%d} " .
+				   "n_ensembles{%d} " .
+				    "w_gap_time{%d} " .
+					  "stderr_w{%.4f} " .
+					  "rms_tilt{%.1f} " .
+			 "downcast_rms_tilt{%.1f} " .
+			   "upcast_rms_tilt{%.1f} " .
+				  "rms_rotation{%.2f} " .
+   		  "deployment_rotations{%d} " .
+		    "downcast_rotations{%d} " .
+		   	  "upcast_rotations{%d} " .
+			"recovery_rotations{%d} " .
+		"rms_heave_acceleration{%.2f} " .
+					 "bin1_dist{%.1f} " .
+                    "bin_length{%.1f} " .
 					 "\n",
 			($dta{ENSEMBLE}[$#{$dta{ENSEMBLE}}]->{UNIX_TIME} -
 					$dta{ENSEMBLE}[0]->{UNIX_TIME}),