after DIMES UK2
authorA.M. Thurnherr <ant@ldeo.columbia.edu>
Fri, 14 Jan 2011 21:31:42 +0000
changeset 5 29faa9e6226c
parent 4 7e43b24080af
child 6 603221e51c6f
after DIMES UK2
RDI_Coords.pl
RDI_Utils.pl
listEns
mkProfile
--- 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 May 23 22:47:32 2010
+#                    dlm: Thu Dec 23 15:00:02 2010
 #                    (c) 2003 A.M. Thurnherr
-#                    uE-Info: 28 74 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 30 48 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # RDI Workhorse Coordinate Transformations
@@ -26,6 +26,8 @@
 #	May 19, 2009: - added &velBeamToVertical()
 #	May 23, 2009: - debugged & renamed to &velBeamToBPEarth
 #	May 23, 2010: - changed prototypes of rad() & deg() to conform to ANTS
+#	Dec 20, 2010: - cosmetics
+#	Dec 23, 3020: - added &velBeamToBPInstrument
 
 use strict;
 use POSIX;
@@ -140,7 +142,7 @@
 } # STATIC SCOPE
 
 #======================================================================
-# velBeamToBPEarth3(@) calculates the vertical- and horizontal vels
+# velBeamToBPEarth(@) calculates the vertical- and horizontal vels
 # from the two beam pairs separately. Note that (w1+w2)/2 is 
 # identical to the w estimated according to RDI without 3-beam 
 # solutions.
@@ -195,6 +197,48 @@
 	}
 }
 
+#===================================================================
+# velBeamToBPInstrument(@) calculates the instrument-coordinate vels
+# from the two beam pairs separately.
+#===================================================================
+
+{ # STATIC SCOPE
+	my($TwoCosBAngle,$TwoSinBAngle);
+
+	sub velBeamToBPInstrument(@)
+	{
+		my($dta,$ens,$b1,$b2,$b3,$b4) = @_;
+		my($v12,$w12,$v34,$w34);
+
+		unless (defined($TwoCosBAngle)) {
+			$TwoCosBAngle = 2 * cos(rad($dta->{BEAM_ANGLE}));
+			$TwoSinBAngle = 2 * sin(rad($dta->{BEAM_ANGLE}));
+		}
+		my($roll)  = rad($dta->{ENSEMBLE}[$ens]->{ROLL});							
+		my($sr) = sin($roll); my($cr) = cos($roll);
+		my($pitch) = atan(tan(rad($dta->{ENSEMBLE}[$ens]->{PITCH})) * $cr);	# gimbal pitch
+		my($sp) = sin($pitch); my($cp) = cos($pitch);
+
+		# Sign convention:
+		#	- refer to Coord manual Fig. 3
+		#	- v12 is horizontal velocity from beam1 to beam2
+		#	- w is +ve upward, regardless of instrument orientation
+
+		if (defined($b1) && defined($b2)) {
+			$v12 = ($b1-$b2)/$TwoSinBAngle;
+			$w12 = ($b1+$b2)/$TwoCosBAngle;
+			$w12 *= -1 if ($dta->{ENSEMBLE}[$ens]->{XDUCER_FACING_UP});
+		}
+		if (defined($b3) && defined($b4)) {
+			$v34 = ($b3-$b4)/$TwoSinBAngle;
+			$w34 = ($b3+$b4)/$TwoCosBAngle;
+			$w34 *= -1 if ($dta->{ENSEMBLE}[$ens]->{XDUCER_FACING_UP});
+		}
+
+		return ($v12,$w12,$v34,$w34);
+	}
+}
+
 #======================================================================
 # velApplyHdgBias() applies the heading bias, which is used to correct
 # for magnetic declination for data recorded in Earth-coordinates ONLY.
@@ -230,8 +274,8 @@
 
 sub gimbal_pitch($$)	# RDI coord trans manual
 {
-	my($tilt1,$tilt2) = @_;
-	return deg(atan(tan(rad($tilt1)) * cos(rad($tilt2))));
+	my($RDI_pitch,$RDI_roll) = @_;
+	return deg(atan(tan(rad($RDI_pitch)) * cos(rad($RDI_roll))));
 }
 
 # - angle from vertical is home grown and should be treated with caution
@@ -247,9 +291,9 @@
 
 sub angle_from_vertical($$)
 {
-	my($tilt1,$tilt2) = @_;
-	my($rad_pitch) = atan(tan(rad($tilt1)) * cos(rad($tilt2)));
-	return deg(acos(cos($rad_pitch) * cos(rad($tilt2))));
+	my($RDI_pitch,$RDI_roll) = @_;
+	my($rad_pitch) = atan(tan(rad($RDI_pitch)) * cos(rad($RDI_roll)));
+	return deg(acos(cos($rad_pitch) * cos(rad($RDI_roll))));
 }
 
 1;
--- 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: Fri Dec 10 14:51:41 2010
+#                    dlm: Thu Dec 16 05:36:27 2010
 #                    (c) 2003 A.M. Thurnherr
-#                    uE-Info: 349 0 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 333 65 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # miscellaneous RDI-specific utilities
@@ -35,6 +35,7 @@
 #	Oct 20, 2010: - BUG: w is now not integrated any more across gaps longer than 5s
 #	Dec  8, 2010: - changed missing w warning to happen only if gap is longer than 15s
 #	Dec 10, 2010: - beautified gap warning
+#	Dec 16, 2010: - BUG: gaps at end caused mk_prof to throw away profile
 
 use strict;
 
@@ -328,7 +329,12 @@
 				  $dta->{ENSEMBLE}[$lastgood]->{UNIX_TIME}; # ... last good ens
 	
 		if ($dt > $max_gap) {
-			printf(STDERR "WARNING: %d-s gap too long, profile restarted at ensemble $e\n",$dt);
+			if ($dta->{ENSEMBLE}[$lastgood]->{UNIX_TIME} -
+			    $dta->{ENSEMBLE}[$firstgood]->{UNIX_TIME} > 15*60) {
+					printf(STDERR "WARNING: %.1f-s gap too long, profile ended at ensemble $lastgood\n",$dt);
+					last;
+			}
+			printf(STDERR "WARNING: %.1f-s gap too long, profile restarted at ensemble $e\n",$dt);
 			$firstgood = $lastgood = $e;
 			$dta->{ENSEMBLE}[$e]->{ELAPSED_TIME} = 0;
 			$z = $zErr = $maxz = 0;
@@ -345,7 +351,7 @@
 			$z += $dta->{ENSEMBLE}[$lastgood]->{W} * $dt;			# integrate
 			$zErr += ($dta->{ENSEMBLE}[$lastgood]->{W_ERR} * $dt)**2;
 		} elsif ($dt > 15) {
-	       	printf(STDERR "WARNING: long-ish w gap (dt=%ds)\n",$dt);
+	       	printf(STDERR "WARNING: long-ish w gap (dt=%.1fs)\n",$dt);
 		}
 	
 		$dta->{ENSEMBLE}[$e]->{DEPTH} = $z;
--- a/listEns
+++ b/listEns
@@ -2,9 +2,9 @@
 #======================================================================
 #                    L I S T E N S 
 #                    doc: Sat Jan 18 18:41:49 2003
-#                    dlm: Sun Aug 15 10:29:12 2010
+#                    dlm: Wed Jan  5 06:09:49 2011
 #                    (c) 2003 A.M. Thurnherr
-#                    uE-Info: 34 35 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 191 73 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # Print useful info from the ensemble list or dump ensembles to
@@ -32,9 +32,11 @@
 #	Mar  2, 2009: - added # of valid bin-1 vels to non-ANTS output
 #	Jul 30, 2009: - NaN => nan
 #	Aug 15, 2010: - BUG: usage typo
+#	Dec 10, 2010: - changed ANTS output to time/date instead of UNIX time
+#	Jan  5, 2011: - added -b
 
 # Notes:
-#	- -E outputs data in earth coordinates
+#	- -E outputs data in earth coordinates, unless -b is set also
 #	- -E output is always in ANTS format, ignoring -A
 #	- no soundspeed correction
 
@@ -45,16 +47,16 @@
 
 die("Usage: $0 [-A)nts] [-Q)uiet (errcheck only)] " .
 			  "[-f)ields <[name=]FIELD[,...]>] " .
-			  "[write -E)nsemples <pref> [-M)agnetic <declination>] [min -p)ercent-good <#>]] " .
+			  "[write -E)nsemples <pref> [-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("AE:f:M:p:Qr:w") && $#ARGV >= 0);
+	unless (&Getopts("AbE:f:M:p:Qr:w") && $#ARGV >= 0);
 
 print(STDERR "WARNING: magnetic declination not set!\n")
 	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_E));
+	if ($opt_Q && $opt_A) || ((defined($opt_M) || defined($opt_p) || defined($opt_b)) && !defined($opt_E));
 
 ($first_ens,$last_ens) = split(',',$opt_r)
 	if defined($opt_r);
@@ -101,6 +103,9 @@
 		die("$ARGV[0]: only beam and earth coordinates implemented so far\n");
 	}
 
+	die("$ARGV[0]: -b only makes sense for beam-coordinate data\n")
+		if ($opt_b && !$beamCoords);
+
 	if ($opt_A) {										# select output fmt: ANTS
 		unless ($opt_Q) {
 			printf("#ANTS#PARAMS# N_ensembles{%d}\n",scalar(@{$dta{ENSEMBLE}}));
@@ -183,9 +188,10 @@
 						if ($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][2] < $opt_p);
 					undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3])
 						if ($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][3] < $opt_p);
-					@v = velInstrumentToEarth(\%dta,$e,
-							velBeamToInstrument(\%dta,
-								@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]}));
+					@v = $opt_b ? @{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]} :
+							velInstrumentToEarth(\%dta,$e,
+								velBeamToInstrument(\%dta,
+									@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]}));
 				} else {
 					@v = velApplyHdgBias(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]});
 				}
--- 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: Fri Dec 10 14:52:16 2010
+#                    dlm: Wed Jan  5 01:05:50 2011
 #                    (c) 2003 A.M. Thurnherr
-#                    uE-Info: 231 0 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 233 47 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # Make an LADCP Profile by Integrating W (similar to Firing's scan*).
@@ -70,6 +70,8 @@
 #				  - NaN => nan
 #	Dec  8, 2010: - added zmax/zend labels to output
 #	Dec 10, 2010: - made mkProfile exit with status 0 if no good ens found but -Q is set
+#	Dec 19, 2010: - finally made -A default and activated output file
+#	Jan  5, 2011: - made no-good-ensembles found test much more robust
 
 # NOTES:
 #	- the battery values are based on transmission voltages (different
@@ -93,7 +95,7 @@
 
 $USAGE = "$0 @ARGV";
 die("Usage: $0 " .
-	"[-A)nts] [-Q)uiet] [-F)ilter <script>] " .
+	"[-Q)uiet] [-F)ilter <script>] " .
 	"[-s)uppress checkensemble()] " .
 	"[require -4)-beam solutions] " .
 	"[-r)ef-layer <bin|1,bin|6>] [-n) vels <min|2>] " .
@@ -105,9 +107,6 @@
 	"<RDI file>\n")
 		unless (&Getopts("4AB:F:M:Qd:r:n:e:c:g:f:m:s") && @ARGV == 1);
 
-die("$0: -Q and -A are mutually exclusive\n")
-	if ($opt_Q && $opt_A);
-
 $RDI_Coords::minValidVels = 4 if ($opt_4);			# no 3-beam solutions
 
 require $opt_F if defined($opt_F);					# load filter
@@ -226,12 +225,12 @@
 ($firstgood,$lastgood,$atbottom,$w_gap_time,$zErr,$maxz) =
 	mk_prof(\%dta,!$opt_s,$opt_F,$minb,$maxb,$opt_c,$opt_e,$opt_m);
 
-unless (defined($firstgood)) {
+unless (($atbottom > $firstgood) && ($lastgood > $atbottom)) {
 	if ($opt_Q) {
-		print(STDERR "$ARGV[0]: no good ensembles found\n");
+		print(STDERR "$ARGV[0]: no valid cast data found\n");
 		exit(0);
     } else {
-		die("$ARGV[0]: no good ensembles found\n");
+		die("$ARGV[0]: no valid cast data found\n");
 	}
 }
 
@@ -688,129 +687,134 @@
 printf(STDERR "net rotations        : [%d]/%d/%d/[%d]\n",$prerot,$dnrot,$uprot,$postrot);
 printf(STDERR "rms pitch/roll       : %.1f/%.1f\n",$dnprrms,$upprrms);
 
-if ($opt_A) {												# ANTS format
-	print("#ANTS# [] $USAGE\n");
-	$uFields = "{u} {u_err} {v} {v_err} {x} {x_err} {y} {y_err}"
-		if defined($opt_M);
-	print("#ANTS#FIELDS# {ens} {time} {elapsed} {secno} {downcast} " .
-						"{w} {w_err} {depth} {depth_err} {depth_BT} " .
-						"{pitchroll} {rotation} " .
-		  				"$uFields $addFields\n");
+exit(0) if ($opt_Q);
+
+#----------------------------------------------------------------------
+# output profile in active ANTS format
+#----------------------------------------------------------------------
+
+print("#!/usr/bin/perl -S list\n");		
+chmod(0777&~umask,*STDOUT);
+
+print("#ANTS# [] $USAGE\n");
+$uFields = "{u} {u_err} {v} {v_err} {x} {x_err} {y} {y_err}"
+	if defined($opt_M);
+print("#ANTS#FIELDS# {ens} {time} {elapsed} {secno} {downcast} " .
+					"{w} {w_err} {depth} {depth_err} {depth_BT} " .
+					"{pitchroll} {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}} " .
-			 "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_pitchroll{%.1f} " .
-  	   "downcast_rms_pitchroll{%.1f} " .
-		 "upcast_rms_pitchroll{%.1f} " .
-				 "rms_rotation{%.2f} " .
-		 "deployment_rotations{%d} " .
-		   "downcast_rotations{%d} " .
-		     "upcast_rotations{%d} " .
-		   "recovery_rotations{%d} " .
-				    "bin1_dist{%.1f} " .
-				   "bin_length{%.1f} " .
-		  				 "\n",
-				($dta{ENSEMBLE}[$#{$dta{ENSEMBLE}}]->{UNIX_TIME} -
-						$dta{ENSEMBLE}[0]->{UNIX_TIME}),
-				$dta{ENSEMBLE}[$lastgood]->{ELAPSED_TIME},
-				$gb+1,
-				$dta{DISTANCE_TO_BIN1_CENTER} + $gb*$dta{BIN_LENGTH},
-				$dta{ENSEMBLE}[$atbottom]->{DEPTH},
-				$dta{ENSEMBLE}[$lastgood]->{DEPTH} -
-					$dta{ENSEMBLE}[$firstgood]->{DEPTH},
-				$dta{DISTANCE_TO_BIN1_CENTER} +
-					$min_good_bins*$dta{BIN_LENGTH},
-				scalar(@{$dta{ENSEMBLE}}),
-				$w_gap_time,$wErr,$prrms,$dnprrms,$upprrms,$rotrms,
-				$prerot,$dnrot,$uprot,$postrot,
-				$dta{DISTANCE_TO_BIN1_CENTER},
-				$dta{BIN_LENGTH},
-		  );
-	printf("#ANTS#PARAMS# magnetic_declination{$opt_M} " .
-							   	  "uv_gap_time{%d} " .
-						    	       "mean_u{%.4f} " .
-							         "stderr_u{%.4f} " .
-							               "dx{%d} " .
-							           "dx_err{%d} " .
-							           "mean_v{%.4f} " .
-							         "stderr_v{%.4f} " .
-							               "dy{%d} " .
-							           "dy_err{%d}\n",
-		$uv_gap_time,
-		$dta{ENSEMBLE}[$lastgood]->{X} /
+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}} " .
+		 "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_pitchroll{%.1f} " .
+   "downcast_rms_pitchroll{%.1f} " .
+	 "upcast_rms_pitchroll{%.1f} " .
+			 "rms_rotation{%.2f} " .
+	 "deployment_rotations{%d} " .
+	   "downcast_rotations{%d} " .
+		 "upcast_rotations{%d} " .
+	   "recovery_rotations{%d} " .
+				"bin1_dist{%.1f} " .
+			   "bin_length{%.1f} " .
+					 "\n",
+			($dta{ENSEMBLE}[$#{$dta{ENSEMBLE}}]->{UNIX_TIME} -
+					$dta{ENSEMBLE}[0]->{UNIX_TIME}),
 			$dta{ENSEMBLE}[$lastgood]->{ELAPSED_TIME},
-		$uErr, $dta{ENSEMBLE}[$lastgood]->{X}, $x_err,
-		$dta{ENSEMBLE}[$lastgood]->{Y} /
-			$dta{ENSEMBLE}[$lastgood]->{ELAPSED_TIME},
-		$vErr, $dta{ENSEMBLE}[$lastgood]->{Y}, $y_err,
-	) if defined ($opt_M);
-	print("#ANTS#PARAMS# start_lat{$s_lat} start_lon{$s_lon} " .
-						  "end_lat{$e_lat} end_lon{$e_lon} " .
-						      "lat{$lat} lon{$lon}\n")
-		if defined($lat);
-	if ($dta{TIME_BETWEEN_PINGS} == 0) {
-		 print("#ANTS#PARAMS# pinging_rate{staggered}\n");
-	} else {
-		 printf("#ANTS#PARAMS# pinging_rate{%.2f}\n",
-			1/$dta{TIME_BETWEEN_PINGS});
-    }		
-    printf("#ANTS#PARAMS# drift_x{%d} drift_y{%d} " .
-						 "drift_u{%.3f} drift_v{%.3f} " .
-		   "\n",$ddx,$ddy,$du,$dv) if defined($ddx);
-	if (defined($water_depth)) {
-		printf("#ANTS#PARAMS# water_depth{%d} sig-water_depth{%d}\n",
-					$water_depth,$sig_wd);
-	} else {
-		print("#ANTS#PARAMS# water_depth{nan} sig-water_depth{nan}\n");
-	}
+			$gb+1,
+			$dta{DISTANCE_TO_BIN1_CENTER} + $gb*$dta{BIN_LENGTH},
+			$dta{ENSEMBLE}[$atbottom]->{DEPTH},
+			$dta{ENSEMBLE}[$lastgood]->{DEPTH} -
+				$dta{ENSEMBLE}[$firstgood]->{DEPTH},
+			$dta{DISTANCE_TO_BIN1_CENTER} +
+				$min_good_bins*$dta{BIN_LENGTH},
+			scalar(@{$dta{ENSEMBLE}}),
+			$w_gap_time,$wErr,$prrms,$dnprrms,$upprrms,$rotrms,
+			$prerot,$dnrot,$uprot,$postrot,
+			$dta{DISTANCE_TO_BIN1_CENTER},
+			$dta{BIN_LENGTH},
+	  );
+printf("#ANTS#PARAMS# magnetic_declination{$opt_M} " .
+							  "uv_gap_time{%d} " .
+								   "mean_u{%.4f} " .
+								 "stderr_u{%.4f} " .
+									   "dx{%d} " .
+								   "dx_err{%d} " .
+								   "mean_v{%.4f} " .
+								 "stderr_v{%.4f} " .
+									   "dy{%d} " .
+								   "dy_err{%d}\n",
+	$uv_gap_time,
+	$dta{ENSEMBLE}[$lastgood]->{X} /
+		$dta{ENSEMBLE}[$lastgood]->{ELAPSED_TIME},
+	$uErr, $dta{ENSEMBLE}[$lastgood]->{X}, $x_err,
+	$dta{ENSEMBLE}[$lastgood]->{Y} /
+		$dta{ENSEMBLE}[$lastgood]->{ELAPSED_TIME},
+	$vErr, $dta{ENSEMBLE}[$lastgood]->{Y}, $y_err,
+) if defined ($opt_M);
+print("#ANTS#PARAMS# start_lat{$s_lat} start_lon{$s_lon} " .
+					  "end_lat{$e_lat} end_lon{$e_lon} " .
+						  "lat{$lat} lon{$lon}\n")
+	if defined($lat);
+if ($dta{TIME_BETWEEN_PINGS} == 0) {
+	 print("#ANTS#PARAMS# pinging_rate{staggered}\n");
+} else {
+	 printf("#ANTS#PARAMS# pinging_rate{%.2f}\n",
+		1/$dta{TIME_BETWEEN_PINGS});
+}	    
+printf("#ANTS#PARAMS# drift_x{%d} drift_y{%d} " .
+					 "drift_u{%.3f} drift_v{%.3f} " .
+	   "\n",$ddx,$ddy,$du,$dv) if defined($ddx);
+if (defined($water_depth)) {
+	printf("#ANTS#PARAMS# water_depth{%d} sig-water_depth{%d}\n",
+				$water_depth,$sig_wd);
+} else {
+	print("#ANTS#PARAMS# water_depth{nan} sig-water_depth{nan}\n");
 }
 
 sub p($) { print(defined($_[0])?"$_[0] ":"nan "); }
 sub pb($) { print($_[0]?"1 ":"0 "); }
 
-unless ($opt_Q) {										# write profile
-	for ($e=$firstgood; $e<=$lastgood; $e++) {
-		p($dta{ENSEMBLE}[$e]->{NUMBER});
-		p($dta{ENSEMBLE}[$e]->{UNIX_TIME});
-		p($dta{ENSEMBLE}[$e]->{ELAPSED_TIME});
-		p($dta{ENSEMBLE}[$e]->{SECNO});
-		pb($dta{ENSEMBLE}[$e]->{UNIX_TIME} < $dta{ENSEMBLE}[$atbottom]->{UNIX_TIME});
-		p($dta{ENSEMBLE}[$e]->{W});
-		p($dta{ENSEMBLE}[$e]->{W_ERR});
-		p($dta{ENSEMBLE}[$e]->{DEPTH});
-		p($dta{ENSEMBLE}[$e]->{DEPTH_ERR});
-		p($dta{ENSEMBLE}[$e]->{DEPTH_BT});
-		p($dta{ENSEMBLE}[$e]->{PITCHROLL});
-		p($dta{ENSEMBLE}[$e]->{ROTATION});
-		if (defined($opt_M)) {
-			p($dta{ENSEMBLE}[$e]->{U}); p($dta{ENSEMBLE}[$e]->{U_ERR});
-			p($dta{ENSEMBLE}[$e]->{V}); p($dta{ENSEMBLE}[$e]->{V_ERR});
-			p($dta{ENSEMBLE}[$e]->{X}); p($dta{ENSEMBLE}[$e]->{X_ERR});
-			p($dta{ENSEMBLE}[$e]->{Y}); p($dta{ENSEMBLE}[$e]->{Y_ERR});
-	    }
-		if (defined(@f)) {
-			foreach $f (@f) {
-				my($fn,$fi) = ($f =~ m{([^[]*)(\[.*)});
-				$fn = $f unless defined($fn);
-				p(eval("\$dta{ENSEMBLE}[$e]->{$fn}$fi"));
-			}
+for ($e=$firstgood; $e<=$lastgood; $e++) {
+	p($dta{ENSEMBLE}[$e]->{NUMBER});
+	p($dta{ENSEMBLE}[$e]->{UNIX_TIME});
+	p($dta{ENSEMBLE}[$e]->{ELAPSED_TIME});
+	p($dta{ENSEMBLE}[$e]->{SECNO});
+	pb($dta{ENSEMBLE}[$e]->{UNIX_TIME} < $dta{ENSEMBLE}[$atbottom]->{UNIX_TIME});
+	p($dta{ENSEMBLE}[$e]->{W});
+	p($dta{ENSEMBLE}[$e]->{W_ERR});
+	p($dta{ENSEMBLE}[$e]->{DEPTH});
+	p($dta{ENSEMBLE}[$e]->{DEPTH_ERR});
+	p($dta{ENSEMBLE}[$e]->{DEPTH_BT});
+	p($dta{ENSEMBLE}[$e]->{PITCHROLL});
+	p($dta{ENSEMBLE}[$e]->{ROTATION});
+	if (defined($opt_M)) {
+		p($dta{ENSEMBLE}[$e]->{U}); p($dta{ENSEMBLE}[$e]->{U_ERR});
+		p($dta{ENSEMBLE}[$e]->{V}); p($dta{ENSEMBLE}[$e]->{V_ERR});
+		p($dta{ENSEMBLE}[$e]->{X}); p($dta{ENSEMBLE}[$e]->{X_ERR});
+		p($dta{ENSEMBLE}[$e]->{Y}); p($dta{ENSEMBLE}[$e]->{Y_ERR});
+	}
+	if (defined(@f)) {
+		foreach $f (@f) {
+			my($fn,$fi) = ($f =~ m{([^[]*)(\[.*)});
+			$fn = $f unless defined($fn);
+			p(eval("\$dta{ENSEMBLE}[$e]->{$fn}$fi"));
 		}
-		print("\n");
 	}
+	print("\n");
 }
 
 exit(0);