V1.3beta1
authorA.M. Thurnherr <athurnherr@yahoo.com>
Wed, 25 May 2016 12:14:29 -0400
changeset 46 cc6c4309828a
parent 45 6d49c7420a6c
child 47 2ccb81b7cea5
V1.3beta1
HISTORY
LADCP_w_ocean
LADCP_w_postproc
acoustic_backscatter.pl
bottom_tracking.pl
dump_residual_profiles.pl
edit_data.pl
find_seabed.pl
plot_acceleration_residuals.pl
plot_attitude_biases_w.pl
plot_attitude_residuals.pl
plot_backscatter.pl
plot_correlation.pl
plot_residual_profs.pl
plot_residuals.pl
plot_time_lags.pl
plot_wprof.pl
plot_wsamp.pl
svel_corrections.pl
version.pl
--- a/HISTORY	Thu May 19 09:38:56 2016 -0400
+++ b/HISTORY	Wed May 25 12:14:29 2016 -0400
@@ -1,9 +1,9 @@
 ======================================================================
                     H I S T O R Y 
                     doc: Mon Oct 12 16:09:24 2015
-                    dlm: Thu May 19 00:51:48 2016
+                    dlm: Wed May 25 12:14:13 2016
                     (c) 2015 A.M. Thurnherr
-                    uE-Info: 158 56 NIL 0 0 72 3 2 4 NIL ofnI
+                    uE-Info: 172 19 NIL 0 0 72 3 2 4 NIL ofnI
 ======================================================================
 
 ----------------------------------------------------------------------
@@ -100,6 +100,8 @@
 	Mar 29, 2016: V1.2beta6
 		- update antsMinLib to 6.6, perl-tools to 1.5 [version.pl]
 		- updated howto
+		- exported [default_paths.pl] from [defaults.pl]
+
 
 	Mar 30, 2016: V1.2beta7
 		- updated [version.pl] [.hg/hgrc]
@@ -156,3 +158,15 @@
 			- [plot_residual_profs.pl]
 		- removed assumption of 1500m/s ADCP soundspeed setting (various files)
 		- added correct w12, w34 for earth velocity data
+
+	May 19, 2016:
+		- updated to ADCP_tools V1.6 (coord trans interface change)
+
+	May 24: 2016:
+		- implemented bin-depth caching
+		- improved LADCP_w_postproc plot
+		- improved various plots (esp. for partial-depth casts)
+
+	May 25, 2016:
+		- updated version to V1.3beta1 [version.pl] [.hg/hgrc]
+		- published
--- a/LADCP_w_ocean	Thu May 19 09:38:56 2016 -0400
+++ b/LADCP_w_ocean	Wed May 25 12:14:29 2016 -0400
@@ -2,9 +2,9 @@
 #======================================================================
 #                    L A D C P _ W _ O C E A N 
 #                    doc: Fri Dec 17 18:11:13 2010
-#                    dlm: Thu May 19 00:57:30 2016
+#                    dlm: Tue May 24 16:33:29 2016
 #                    (c) 2010 A.M. Thurnherr
-#                    uE-Info: 1879 0 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 1868 26 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # TODO:
@@ -249,6 +249,8 @@
 #				  - expunged super-confusing $realLastGoodEns
 #				  - removed assumption of default 1500m/s sspd setting during acquisition
 #				  - added w12, w34 for earth-coordinates
+#   May 19, 2016: - updated to ADCP_tools V1.6
+#	May 24, 2016: - calc_binDepths() -> binDepths()
 # HISTORY END
 
 # CTD REQUIREMENTS
@@ -262,8 +264,8 @@
 # 2-BEAM SOLUTIONS
 #	- both for beam- and earth-coordinate data, two separate two-beam
 #	  solutions (w12 & w34) are calculated:
-#		- w12 corresponds to pitch axis
-#		- w34 corresponds to roll axis
+#		- w12 corresponds to ROLL axis (plotted with dashed lines)
+#		- w34 corresponds to PITCH axis (plotted with dotted lines)
 #	- the 2-beam solutions are largely independent of each other
 #		=> key for detecting data problems, such as package wakes
 
@@ -637,9 +639,7 @@
 			 $LADCP{ENSEMBLE}[$ens]->{V}[$bin],
 			 $LADCP{ENSEMBLE}[$ens]->{W}[$bin],
 			 $LADCP{ENSEMBLE}[$ens]->{ERRVEL}[$bin]) =
-				velInstrumentToEarth(\%LADCP,$ens,
-					velBeamToInstrument(\%LADCP,
-										@{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]}));
+				velBeamToEarth(\%LADCP,$ens,@{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]});
 			if (defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin])) {
 				$per_bin_nsamp[$bin]++;
 				$nvw++;
@@ -1335,7 +1335,7 @@
 		next;
 	}
 	$realLastGoodEns = $ens;
-	my(@bindepth) = calc_binDepths($ens);
+	my(@bindepth) = binDepths($ens);
 	for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 		next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
 		next if ($bin<$outGrid_firstBin-1 || $bin>$outGrid_lastBin-1);
@@ -1398,7 +1398,7 @@
 for ($ens=$LADCP_atbottom; $ens<=$lastGoodEns; $ens++) {
 	next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
 	$realLastGoodEns = $ens;
-	my(@bindepth) = calc_binDepths($ens);
+	my(@bindepth) = binDepths($ens);
 	for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 		next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
 		next if ($bin<$outGrid_firstBin-1 || $bin>$outGrid_lastBin-1);
@@ -1477,7 +1477,7 @@
 		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
 
 		my(@residuals) = ();												# calc median of residuals
-		my(@bindepth) = calc_binDepths($ens);
+		my(@bindepth) = binDepths($ens);
 		for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 			next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
 		    next if ($bin<$outGrid_firstBin-1 || $bin>$outGrid_lastBin-1);
@@ -1546,7 +1546,7 @@
 		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
 
 		my($sum) = my($n) = 0;														# calculate rms residual
-		my(@bindepth) = calc_binDepths($ens);
+		my(@bindepth) = binDepths($ens);
 		for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 			next unless ($bin+1>=$outGrid_firstBin && $bin+1<=$outGrid_lastBin);
 		  	next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
@@ -1573,7 +1573,7 @@
 			next;
 		}
 		$realLastGoodEns = $ens;
-		my(@bindepth) = calc_binDepths($ens);
+		my(@bindepth) = binDepths($ens);
 		for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 			next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
 			next if ($bin<$outGrid_firstBin-1 || $bin>$outGrid_lastBin-1);
@@ -1600,7 +1600,7 @@
 	for ($ens=$LADCP_atbottom; $ens<=$lastGoodEns; $ens++) {	    
 		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
 		$realLastGoodEns = $ens;
-		my(@bindepth) = calc_binDepths($ens);
+		my(@bindepth) = binDepths($ens);
 		for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 			next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
 			next if ($bin<$outGrid_firstBin-1 || $bin>$outGrid_lastBin-1);
@@ -1642,7 +1642,7 @@
 
 for ($ens=$firstGoodEns; $ens<$LADCP_atbottom; $ens++) {
 	next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
-	my(@bindepth) = calc_binDepths($ens);
+	my(@bindepth) = binDepths($ens);
 	for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 		next unless ($bin+1>=$outGrid_firstBin && $bin+1<=$outGrid_lastBin);
 		next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
@@ -1659,7 +1659,7 @@
 
 for ($ens=$LADCP_atbottom; $ens<=$lastGoodEns; $ens++) {
 	next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
-	my(@bindepth) = calc_binDepths($ens);
+	my(@bindepth) = binDepths($ens);
 	for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 		next unless ($bin+1>=$outGrid_firstBin && $bin+1<=$outGrid_lastBin);
 		next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
@@ -1686,7 +1686,7 @@
 	local(@dc_bres,@uc_bres);
 	for ($ens=$firstGoodEns; $ens<$LADCP_atbottom; $ens++) {						# DOWNCAST
 		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
-		my(@bindepth) = calc_binDepths($ens);
+		my(@bindepth) = binDepths($ens);
 		for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 			next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
 			push(@{$dc_bres[$bin]},
@@ -1696,7 +1696,7 @@
 	}
 	for ($ens=$LADCP_atbottom; $ens<=$lastGoodEns; $ens++) {						# UPCAST 
 		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
-		my(@bindepth) = calc_binDepths($ens);
+		my(@bindepth) = binDepths($ens);
 		for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 			next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
 			push(@{$uc_bres[$bin]},
@@ -1827,7 +1827,7 @@
 	    
 		for ($ens=$firstGoodEns; $ens<$LADCP_atbottom; $ens++) {						# downcast
 		  next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
-		  my(@bindepth) = calc_binDepths($ens);
+		  my(@bindepth) = binDepths($ens);
 		  for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 			  next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
 			  my($bi) = $bindepth[$bin]/$opt_o;
@@ -1865,7 +1865,7 @@
 	  
 		for ($ens=$LADCP_atbottom; $ens<=$lastGoodEns; $ens++) {					  # upcast 
 		  next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
-		  my(@bindepth) = calc_binDepths($ens);
+		  my(@bindepth) = binDepths($ens);
 		  for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 			  next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
 			  my($bi) = $bindepth[$bin]/$opt_o;
--- a/LADCP_w_postproc	Thu May 19 09:38:56 2016 -0400
+++ b/LADCP_w_postproc	Wed May 25 12:14:29 2016 -0400
@@ -2,9 +2,9 @@
 #======================================================================
 #                    L A D C P _ W _ P O S T P R O C 
 #                    doc: Fri Apr 24 17:15:59 2015
-#                    dlm: Thu Apr 14 15:42:51 2016
+#                    dlm: Tue May 24 22:48:51 2016
 #                    (c) 2015 A.M. Thurnherr
-#                    uE-Info: 65 40 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 602 50 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 $antsSummary = 'edit and re-grid LADCP vertical-velocity samples';
@@ -63,6 +63,7 @@
 #	Mar 16, 2016: - adapted to gmt5
 #   Mar 31, 2016: - changed version %PARAM
 #	Apr 14, 2016: - added profile id to warning messages
+#	May 24, 2016: - improved plot
 
 ($ANTS)  = (`which ANTSlib` =~ m{^(.*)/[^/]*$});
 ($WCALC) = ($0              =~ m{^(.*)/[^/]*$});
@@ -309,9 +310,11 @@
 if (defined($opt_p)) {												# begin summary plot
 	$xmin = -0.1; $x2min = -700;
 	$xmax = 0.35; $x2max =	500;
-	$ymin =  0;
+	$ymin = antsParam('min_depth');
+	$ymin = round($ymin-25,50);
 	$ymax = antsParam('water_depth');
 	$ymax = antsRequireParam('max_depth') unless numberp($ymax);
+	$ymax = round($ymax+25,50);
 	$plotsize = 13;
 	$R	= "-R$xmin/$xmax/$ymin/$ymax";
 	$R2 = "-R$x2min/$x2max/$ymin/$ymax";
@@ -535,33 +538,6 @@
 }
 
 if (defined($opt_p)) {																# complete summary plot
-	if ($dual_head) {
-		GMT_psxy('-W1,100/100/255');												# surface layer limit
-			print(GMT "-0.1 $opt_s\n0.07 $opt_s\n");
-		if ($dc_R < 0.3 || !numberp($dc_R)) {										# correlation statistics
-			&antsInfo("WARNING: low dc correlation (r = %.1f) between UL and DL data in profile #$id",$dc_R);
-			GMT_pstext('-F+f12,Helvetica,white+jBL -Gred');
-		} elsif ($dc_R < 0.5) { 	GMT_pstext('-F+f12,Helvetica,black+jBL -Gyellow'); }
-		else {						GMT_pstext('-F+f12,Helvetica,black+jBL -Ggreen'); }
-	        printf(GMT "%f %f %.1f\n",-0.07,0.94*$ymax,$dc_R);
-	}
-	GMT_pstext('-F+f12,Helvetica,coral+jBL');
-		printf(GMT "%f %f dc\n",-0.095,0.94*$ymax);
-		printf(GMT "%f %f [%.1f/%.1f cm/s @~s@~\@-e/r\@-]\n",
-			0.02,0.94*$ymax,100*$dc_esig,100*$dc_rsig) if ($dual_head);
-	if ($dual_head) {
-		if ($uc_R < 0.3 || !numberp($uc_R)) {
-			&antsInfo("WARNING: low uc correlation (r = %.1f) between UL and DL data in profile #$id",$uc_R);
-			GMT_pstext('-F+f12,Helvetica,white+jBL -Gred');
-		} elsif ($uc_R < 0.5) { 	GMT_pstext('-F+f12,Helvetica,black+jBL -Gyellow'); }
-		else {						GMT_pstext('-F+f12,Helvetica,black+jBL -Ggreen'); }
-	        printf(GMT "%f %f %.1f\n",-0.07,0.98*$ymax,$uc_R);
-	}
-	GMT_pstext('-F+f12,Helvetica,SeaGreen+jBL');
-		printf(GMT "%f %f uc\n",-0.095,0.98*$ymax);
-		printf(GMT "%f %f [%.1f/%.1f cm/s @~s@~\@-e/r\@-]\n",
-			0.02,0.98*$ymax,100*$uc_esig,100*$uc_rsig) if ($dual_head);
-
 	GMT_setR($R);
 
 	GMT_psxy('-W1.5,coral');														# median profiles
@@ -573,7 +549,7 @@
 		printf(GMT "%f %f\n",(($ucns[$bi]>=$opt_k)?$ucwm[$bi]:nan),($bi+0.5)*$opt_o);
 	}
 
-	GMT_psxy('-Sc0.1 -Gcoral');												# m.a.d. profiles
+	GMT_psxy('-Sc0.1 -Gcoral');														# m.a.d. profiles
 	for (my($bi)=0; $bi<=$#dcw; $bi++) {
 		printf(GMT "%f %f\n",(($dcns[$bi]>=$opt_k)?$dcwmad[$bi]:nan),($bi+0.5)*$opt_o);
 	}
@@ -585,11 +561,13 @@
 	GMT_setR($R2);
 	GMT_psxy('-W0.7,coral');
 	for (my($bi)=0; $bi<=$#dcw; $bi++) {											# number of samples
-		printf(GMT "%f %f\n",$dcns[$bi],($bi+0.5)*$opt_o);
+		if ($dcns[$bi]) { printf(GMT "%f %f\n",$dcns[$bi],($bi+0.5)*$opt_o); }
+		else 			{ print(GMT "nan nan\n"); }
 	}
 	GMT_psxy('-W0.7,SeaGreen');
 	for (my($bi)=0; $bi<=$#dcw; $bi++) {
-		printf(GMT "%f %f\n",$ucns[$bi],($bi+0.5)*$opt_o);
+		if ($ucns[$bi]) { printf(GMT "%f %f\n",$ucns[$bi],($bi+0.5)*$opt_o); }
+		else 			{ print(GMT "nan nan\n"); }
 	}
 
 	GMT_psbasemap('-Bf10a1000-950:"                                                  # of Samples":N');
@@ -601,14 +579,39 @@
 						$depth_tics . ':"Depth [m]":WeS');
 	GMT_psbasemap('-Ba10-9.95S'); GMT_psbasemap('-Ba10-9.85S');
 
-	GMT_setR('-R0/1/0/1');
+	if ($dual_head) {
+		GMT_psxy('-W1,100/100/255');												# surface layer limit
+			print(GMT "-0.1 $opt_s\n0.07 $opt_s\n");
+		GMT_unitcoords();
+		if ($dc_R < 0.3 || !numberp($dc_R)) {										# correlation statistics
+			&antsInfo("WARNING: low dc correlation (r = %.1f) between UL and DL data in profile #$id",$dc_R);
+			GMT_pstext('-F+f12,Helvetica,coral+jTL -Gred');
+		} elsif ($dc_R < 0.5) { 	GMT_pstext('-F+f12,Helvetica,coral+jTL -Gyellow'); }
+		else {						GMT_pstext('-F+f12,Helvetica,coral+jTL -Gwhite'); }
+	        printf(GMT "%f %f r = %.1f\n",0.64,0.01,$dc_R);
+	}
+	GMT_pstext('-F+f12,Helvetica,coral+jTR -Gwhite');
+		printf(GMT "%f %f [%.1f/%.1f cm/s @~s@~\@-e/r\@-]\n",
+			0.99,0.01,100*$dc_esig,100*$dc_rsig) if ($dual_head);
+	if ($dual_head) {
+		if ($uc_R < 0.3 || !numberp($uc_R)) {
+			&antsInfo("WARNING: low uc correlation (r = %.1f) between UL and DL data in profile #$id",$uc_R);
+			GMT_pstext('-F+f12,Helvetica,SeaGreen+jTL -Gred');
+		} elsif ($uc_R < 0.5) { 	GMT_pstext('-F+f12,Helvetica,SeaGreen+jTL -Gyellow'); }
+		else {						GMT_pstext('-F+f12,Helvetica,SeaGreen+jTL -Gwhite'); }
+	        printf(GMT "%f %f r = %.1f\n",0.64,0.05,$uc_R);
+	}
+	GMT_pstext('-F+f12,Helvetica,SeaGreen+jTR -Gwhite');
+		printf(GMT "%f %f [%.1f/%.1f cm/s @~s@~\@-e/r\@-]\n",
+			0.99,0.05,100*$uc_esig,100*$uc_rsig) if ($dual_head);
+
 	GMT_pstext('-F+f14,Helvetica,blue+jTL -N');
 	if (defined($outfile)) { print(GMT "0.01 -0.06 $outfile [$P{run_label}]\n"); }
 	else { 					printf(GMT "0.01 -0.06 %03d\n [$P{run_label}]",$id); }
 	GMT_pstext('-F+f12,Helvetica+jMR');
 		print(GMT '0.62 0.98 m.a.d.');
-	GMT_pstext('-F+f9,Helvetica,orange+jTR -N -Gwhite');
-		print(GMT "0.99 0.01 V$VERSION\n");
+	GMT_pstext('-F+f9,Helvetica,orange+jBR -N -Gwhite');
+		print(GMT "0.99 0.99 V$VERSION\n");
         
 	GMT_end();
 
--- a/acoustic_backscatter.pl	Thu May 19 09:38:56 2016 -0400
+++ b/acoustic_backscatter.pl	Wed May 25 12:14:29 2016 -0400
@@ -1,9 +1,9 @@
 #======================================================================
 #                    A C O U S T I C _ B A C K S C A T T E R . P L 
 #                    doc: Wed Oct 20 13:02:27 2010
-#                    dlm: Wed May 18 20:36:57 2016
+#                    dlm: Tue May 24 16:34:24 2016
 #                    (c) 2010 A.M. Thurnherr
-#                    uE-Info: 30 36 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 212 0 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -28,6 +28,7 @@
 #	Jan 26, 2016: - added %PARAMs
 #	Mar 26, 2016: - BUG: nSv was declared local to this scope even though it is used outside
 #	May 18, 2016: - improved logging
+#   May 24, 2016: - calc_binDepths() -> binDepths()
 
 #----------------------------------------------------------------------
 # Volume Scattering Coefficient, following Deines (IEEE 1999)
@@ -92,7 +93,7 @@
 	my($cosBeamAngle) = cos(rad($LADCP{BEAM_ANGLE}));
 	for (my($ens)=$LADCP_start; $ens<=$LADCP_end; $ens++) {
 		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
-		my(@bd) = calc_binDepths($ens);
+		my(@bd) = binDepths($ens);
 		for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 			my($depth) = int($bd[$bin]);
 			next if ($depth<0 || !defined($LADCP{ENSEMBLE}[$ens]->{TILT}));
@@ -199,7 +200,7 @@
 
     for (my($ens)=$LADCP_start; $ens<=$LADCP_end; $ens++) {		# correct Sv data
 		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
-		my(@bd) = calc_binDepths($ens);
+		my(@bd) = binDepths($ens);
 		for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 			next unless numberp($LADCP{ENSEMBLE}[$ens]->{SV}[$bin]);
 			my($depth) = int($bd[$bin]);
@@ -208,7 +209,6 @@
 				$LADCP{ENSEMBLE}[$ens]->{SV}[$bin] -= # $dSvProf[int($depth/100)][$bin];
 					linterp($depth,100*int($depth/100),100*int($depth/100)+100,
 							$dSvProf[int($depth/100)][$bin],$dSvProf[int($depth/100)+1][$bin]);
-##???			die unless ($LADCP{ENSEMBLE}[$ens]->{SV}[$bin] < 0);							
 			} else {
 				$LADCP{ENSEMBLE}[$ens]->{SV}[$bin] = nan;
 			}
--- a/bottom_tracking.pl	Thu May 19 09:38:56 2016 -0400
+++ b/bottom_tracking.pl	Wed May 25 12:14:29 2016 -0400
@@ -1,9 +1,9 @@
 #======================================================================
 #                    B O T T O M _ T R A C K I N G . P L 
 #                    doc: Wed Oct 20 21:05:37 2010
-#                    dlm: Tue Jan 26 15:25:14 2016
+#                    dlm: Tue May 24 16:34:43 2016
 #                    (c) 2010 A.M. Thurnherr
-#                    uE-Info: 16 33 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 116 5 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -14,6 +14,7 @@
 #	Apr 22, 2013: - replace output_bin_size by opt_o
 #	Mar  4, 2014: - removed old unused code
 #	Jan 26, 2016: - added %PARAMs
+#   May 24, 2016: - calc_binDepths() -> binDepths()
 
 # This code is essentially identical to the one used in LADCPproc. Differences:
 #	1) velocity editing is simpler: no wake editing, no PPI editing, no shear
@@ -60,7 +61,7 @@
 	$nBTfound++;
 	my($seafloor_bin) = round(avg(@ea_max_bin));
 
-	my(@bd) = calc_binDepths($ens);
+	my(@bd) = binDepths($ens);
 	$nBTdepthFlag++,return									# BT range inconsistent with water depth
 		unless (abs($wd-$bd[$seafloor_bin]) < max($sig_wd,$LADCP{BIN_LENGTH}));
 
--- a/dump_residual_profiles.pl	Thu May 19 09:38:56 2016 -0400
+++ b/dump_residual_profiles.pl	Wed May 25 12:14:29 2016 -0400
@@ -1,14 +1,15 @@
 #======================================================================
 #                    D U M P _ R E S I D U A L _ P R O F I L E S . P L 
 #                    doc: Thu Mar 24 07:55:07 2016
-#                    dlm: Tue Mar 29 13:43:56 2016
+#                    dlm: Tue May 24 16:35:30 2016
 #                    (c) 2016 A.M. Thurnherr
-#                    uE-Info: 11 30 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 46 24 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
 #	Mar 24, 2016: - created from [plot_residuals.pl]
 #	Mar 29, 2016: - cleaned up
+#   May 24, 2016: - calc_binDepths() -> binDepths()
 
 sub dump_residual_profiles($)
 {
@@ -42,7 +43,7 @@
 					   'CTD_accel',	$CTD{W_t}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}],
 					   'ADCP_tilt',	$LADCP{ENSEMBLE}[$ens]->{TILT});
 
-	  	my(@bindepth) = calc_binDepths($ens);
+	  	my(@bindepth) = binDepths($ens);
 		for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 			next unless ($bin+1>=$outGrid_firstBin && $bin+1<=$outGrid_lastBin);
 		  	next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
--- a/edit_data.pl	Thu May 19 09:38:56 2016 -0400
+++ b/edit_data.pl	Wed May 25 12:14:29 2016 -0400
@@ -1,9 +1,9 @@
 #======================================================================
 #                    E D I T _ D A T A . P L 
 #                    doc: Sat May 22 21:35:55 2010
-#                    dlm: Wed May 18 22:34:15 2016
+#                    dlm: Tue May 24 16:36:37 2016
 #                    (c) 2010 A.M. Thurnherr
-#                    uE-Info: 269 0 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 374 18 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -34,6 +34,7 @@
 #	Sep 26, 2015: - added $vessel_draft to editSideLobes
 #	Jan 23, 2016: - added &editBadTimeLagging()
 #	May 18, 2016: - removed assumption of 1500m/s soundspeed setting
+#   May 24, 2016: - calc_binDepths() -> binDepths()
 
 # NOTES:
 #	- editCorr_Earthcoords() is overly conservative and removed most
@@ -370,7 +371,7 @@
 		my($beam_tilt) = max(abs($LADCP{ENSEMBLE}[$e]->{GIMBAL_PITCH}),
 							 abs($LADCP{ENSEMBLE}[$e]->{ROLL}));
 		my($dz_min)    = $dz_max * cos(rad($LADCP{BEAM_ANGLE} + $beam_tilt + $bha));
-		my(@bd) = calc_binDepths($e);
+		my(@bd) = binDepths($e);
 
 		$dz_max *= $PPI_extend_upper_limit
 			if numberp($PPI_extend_upper_limit);
--- a/find_seabed.pl	Thu May 19 09:38:56 2016 -0400
+++ b/find_seabed.pl	Wed May 25 12:14:29 2016 -0400
@@ -1,9 +1,9 @@
 #======================================================================
 #                    F I N D _ S E A B E D . P L 
 #                    doc: Sun May 23 20:26:11 2010
-#                    dlm: Wed May 18 22:38:53 2016
+#                    dlm: Thu May 19 10:40:55 2016
 #                    (c) 2010 A.M. Thurnherr
-#                    uE-Info: 22 0 NIL 0 0 72 0 2 4 NIL ofnI
+#                    uE-Info: 18 46 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -15,6 +15,7 @@
 #				  - renamed $SS_min_allowed_hab to *_range
 #	Jan 26, 2016: - added %PARAMs
 #	May 18, 2016: - removed assumption of 1500m/s soundspeed setting
+#	May 19, 2016: - updated to ADCP_tools V1.6
 
 # NOTES:
 #	1) BT range is corrected for sound speed at the transducer. This is not
@@ -51,11 +52,8 @@
 					 defined($d->{ENSEMBLE}[$i]->{BT_RANGE}[2]) &&
 					 defined($d->{ENSEMBLE}[$i]->{BT_RANGE}[3]));
 
-		my(@BT) = $beamCoords
-				? velInstrumentToEarth($d,$i,
-					velBeamToInstrument($d,
-						@{$d->{ENSEMBLE}[$i]->{BT_VELOCITY}}))
-				: velApplyHdgBias($d,$i,@{$d->{ENSEMBLE}[$i]->{BT_VELOCITY}});
+		my(@BT) = $beamCoords ? velBeamToEarth($d,$i,@{$d->{ENSEMBLE}[$i]->{BT_VELOCITY}})
+							  : velApplyHdgBias($d,$i,@{$d->{ENSEMBLE}[$i]->{BT_VELOCITY}});
 		next unless (abs($BT[3]) < 0.05);
 		$d->{ENSEMBLE}[$i]->{DEPTH_BT} =
 			 $d->{ENSEMBLE}[$i]->{BT_RANGE}[0]/4 +
--- a/plot_acceleration_residuals.pl	Thu May 19 09:38:56 2016 -0400
+++ b/plot_acceleration_residuals.pl	Wed May 25 12:14:29 2016 -0400
@@ -1,14 +1,21 @@
 #======================================================================
 #                    P L O T _ A C C E L E R A T I O N _ R E S I D U A L S . P L 
 #                    doc: Tue May 17 21:40:08 2016
-#                    dlm: Wed May 18 19:43:18 2016
+#                    dlm: Tue May 24 16:37:53 2016
 #                    (c) 2016 A.M. Thurnherr
-#                    uE-Info: 46 37 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 55 24 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
 #	May 17, 2016: - created from [plot_attitude_biases.pl]
 #	May 18, 2016: - made work
+#	May 19, 2016: - improved
+#   May 24, 2016: - calc_binDepths() -> binDepths()
+
+# IMPORTANT NOTE:
+#	- the variables prefixed with p/r refer to beam-pairs 1,2 and 3,4 respectively,
+#	  i.e. the p variables correspond to the roll plane and the r variables
+#	  	   correspond to the pitch plane
 
 require "$ANTS/libGMT.pl";
 
@@ -36,7 +43,7 @@
 	#-------------------------------------------------------
 	# Bin-Average & Create Histogram from Beampair Residuals 
 	#	- use 0.1 m/s^3
-	#	- also calculate mean/rms pitch
+	#	- also calculate mean/rms w_tt
 	#-------------------------------------------------------
 
 	my(@pHistDC,@rHistDC,@pSumDC,@rSumDC,$pHistDC,$rHistDC,$pSumDC,$rSumDC);
@@ -45,7 +52,7 @@
 	my(@w_ttSumDC,@w_ttSumUC);
 	for (my($e)=$firstGoodEns; $e<=$lastGoodEns; $e++) {
 		next unless numberp($LADCP{ENSEMBLE}[$e]->{CTD_DEPTH});
-		my(@bindepth) = calc_binDepths($e);
+		my(@bindepth) = binDepths($e);
 
 		for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 			next if ($bindepth[$bin] <= $excluded_surf_layer);
@@ -114,7 +121,7 @@
 					$i*$bin_size+$xmin+$xo3+($bin_size/2),$ymin+$hist_height*$pHistUC[$i]/$mode);
 		}
 
-	# DC PITCH
+	# DC BEAMS 1,2
 	GMT_psxy('-Ey0.2/2,coral');
 		for (my($i)=0; $i<@pHistDC; $i++) {
 			next unless ($pHistDC[$i] >= $min_fat);
@@ -137,7 +144,7 @@
 			printf(GMT ">\n%f %f\n%f %f\n",$xmin,$pSumDC/$pHistDC,$xmax,$pSumDC/$pHistDC);		# 	bias
 	}
 
-	# DC ROLL
+	# DC BEAMS 3,4
 	GMT_psxy('-Ey0.2/2,coral');															
 		for (my($i)=0; $i<@rHistDC; $i++) {
 			next unless ($rHistDC[$i] >= $min_fat);
@@ -160,7 +167,7 @@
 			printf(GMT ">\n%f %f\n%f %f\n",$xmin,$rSumDC/$rHistDC,$xmax,$rSumDC/$rHistDC);
 	}
 
-	# UC PITCH
+	# UC BEAMS 1,2
 	GMT_psxy('-Ey0.2/2,SeaGreen');													
 		for (my($i)=0; $i<@pHistUC; $i++) {
 			next unless ($pHistUC[$i] >= $min_fat);
@@ -183,7 +190,7 @@
 			printf(GMT ">\n%f %f\n%f %f\n",$xmin,$pSumUC/$pHistUC,$xmax,$pSumUC/$pHistUC);
 	}
 
-	# UC ROLL
+	# UC BEAMS 3,4
 	GMT_psxy('-Ey0.2/2,SeaGreen');													
 		for (my($i)=0; $i<@rHistUC; $i++) {
 			next unless ($rHistUC[$i] >= $min_fat);
--- a/plot_attitude_biases_w.pl	Thu May 19 09:38:56 2016 -0400
+++ b/plot_attitude_biases_w.pl	Wed May 25 12:14:29 2016 -0400
@@ -1,9 +1,9 @@
 #======================================================================
 #                    P L O T _ A T T I T U D E _ B I A S E S _ W . P L 
 #                    doc: Sun May 15 16:08:59 2016
-#                    dlm: Wed May 18 19:43:55 2016
+#                    dlm: Tue May 24 16:38:31 2016
 #                    (c) 2016 A.M. Thurnherr
-#                    uE-Info: 41 37 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 15 31 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -12,6 +12,13 @@
 #	May 17, 2016: - renamed from [plot_attitude_biases.pl]
 #   May 18, 2016: - added version
 #				  - expunged $realLastGoodEns
+#	May 19, 2016: - added notes about wrong beam plane
+#   May 24, 2016: - calc_binDepths() -> binDepths()
+
+# IMPORTANT NOTE:
+#   - the variables prefixed with p/r refer to beam-pairs 1,2 and 3,4 respectively,
+#     i.e. the p variables correspond to the roll plane and the r variables
+#          correspond to the pitch plane
 
 require "$ANTS/libGMT.pl";
 
@@ -40,7 +47,7 @@
 	my(@pValsDC,@rValsDC,@pValsUC,@rValsUC,$mode);
 	for (my($e)=$firstGoodEns; $e<=$lastGoodEns; $e++) {
 		next unless numberp($LADCP{ENSEMBLE}[$e]->{CTD_DEPTH});
-		my(@bindepth) = calc_binDepths($e);
+		my(@bindepth) = binDepths($e);
 		for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 			next if ($bindepth[$bin] <= $excluded_surf_layer);
 			next unless ($bin+1>=$outGrid_firstBin && $bin+1<=$outGrid_lastBin);
@@ -81,14 +88,14 @@
 	GMT_psxy('-W4,CornflowerBlue');
 		print(GMT "$xmin 0\n$xmax 0\n");
 
-	# DC PITCH
+	# DC BEAMS 1,2
 	GMT_psxy('-Ey0.2/2,coral');
-		for (my($i)=0; $i<2*round($opt_t); $i++) {
+		for (my($i)=0; $i<2*round($opt_t); $i++) {										# error bars
 			next unless ($pHistDC[$i] >= $min_fat);
 			my($minLim,$maxLim) = &bootstrap($btstrp_ndraw,0.95,\&avg,@{$pValsDC[$i]});	# 95% bootstrap conf limits
 			printf(GMT "%f %f %f\n",$i-round($opt_t)-0.3,($maxLim+$minLim)/2,($maxLim-$minLim)/2);
 		}
-	GMT_psxy('-Ey0.2/1,coral');															# dc pitch
+	GMT_psxy('-Ey0.2/1,coral');
 		for (my($i)=0; $i<2*round($opt_t); $i++) {
 			next unless ($pHistDC[$i]>=$min_thin && $pHistDC[$i]<$min_fat);
 			my($minLim,$maxLim) = &bootstrap($btstrp_ndraw,0.95,\&avg,@{$pValsDC[$i]});	# 95% bootstrap conf limits
@@ -115,7 +122,8 @@
 					$i-round($opt_t)-0.3+0.5,$ymin+0.03*$pHistDC[$i]/$mode);
 		}
 
-	GMT_psxy('-Ey0.2/2,coral');															# dc roll
+	# DC BEAMS 3,4
+	GMT_psxy('-Ey0.2/2,coral');															
 		for (my($i)=0; $i<2*round($opt_t); $i++) {
 			next unless ($rHistDC[$i] >= $min_fat);
 			my($minLim,$maxLim) = &bootstrap($btstrp_ndraw,0.95,\&avg,@{$rValsDC[$i]});
@@ -148,7 +156,8 @@
 					$i-round($opt_t)-0.1+0.5,$ymin+0.03*$rHistDC[$i]/$mode);
 		}
 
-	GMT_psxy('-Ey0.2/2,SeaGreen');													# uc pitch
+	# UC BEAMS 1,2
+	GMT_psxy('-Ey0.2/2,SeaGreen');													
 		for (my($i)=0; $i<2*round($opt_t); $i++) {
 			next unless ($pHistUC[$i] >= $min_fat);
 			my($minLim,$maxLim) = &bootstrap($btstrp_ndraw,0.95,\&avg,@{$pValsUC[$i]});
@@ -181,7 +190,8 @@
 					$i-round($opt_t)+0.1+0.5,$ymin+0.03*$pHistUC[$i]/$mode);
 		}
 
-	GMT_psxy('-Ey0.2/2,SeaGreen');													# uc roll
+	# UC BEAMS 3,4
+	GMT_psxy('-Ey0.2/2,SeaGreen');													
 		for (my($i)=0; $i<2*round($opt_t); $i++) {
 			next unless ($rHistUC[$i] >= $min_fat);
 			my($minLim,$maxLim) = &bootstrap($btstrp_ndraw,0.95,\&avg,@{$rValsUC[$i]});
--- a/plot_attitude_residuals.pl	Thu May 19 09:38:56 2016 -0400
+++ b/plot_attitude_residuals.pl	Wed May 25 12:14:29 2016 -0400
@@ -1,9 +1,9 @@
 #======================================================================
 #                    P L O T _ A T T I T U D E _ R E S I D U A L S . P L 
 #                    doc: Sun May 15 16:08:59 2016
-#                    dlm: Wed May 18 19:44:19 2016
+#                    dlm: Tue May 24 16:39:01 2016
 #                    (c) 2016 A.M. Thurnherr
-#                    uE-Info: 45 37 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 54 24 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -13,6 +13,13 @@
 #				  - added pitch/roll means
 #	May 18, 2016: - added version
 #                 - expunged $realLastGoodEns
+#	May 19, 2016: - added notes about beam planes
+#   May 24, 2016: - calc_binDepths() -> binDepths()
+
+# IMPORTANT NOTE:
+#   - the variables prefixed with p/r refer to beam-pairs 1,2 and 3,4 respectively,
+#     i.e. the p variables correspond to the roll plane and the r variables
+#          correspond to the pitch plane
 
 require "$ANTS/libGMT.pl";
 
@@ -20,7 +27,7 @@
 {
 	my($pfn) = @_;																	# plot file name
 
-	my($xmin) = -round($opt_t);														# full pitch range 
+	my($xmin) = -round($opt_t);														# full tilt range 
 	my($xmax) =  round($opt_t);
 	my($ymin) =  -0.03;
 	my($ymax) =   0.03;
@@ -44,7 +51,7 @@
 	my(@pitchSumDC,@rollSumDC,@pitchSumUC,@rollSumUC);
 	for (my($e)=$firstGoodEns; $e<=$lastGoodEns; $e++) {
 		next unless numberp($LADCP{ENSEMBLE}[$e]->{CTD_DEPTH});
-		my(@bindepth) = calc_binDepths($e);
+		my(@bindepth) = binDepths($e);
 
 		for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 			next if ($bindepth[$bin] <= $excluded_surf_layer);
@@ -52,13 +59,13 @@
 			next unless numberp($LADCP{ENSEMBLE}[$e]->{SSCORRECTED_OCEAN_W12}[$bin]) &&
 						numberp($LADCP{ENSEMBLE}[$e]->{SSCORRECTED_OCEAN_W34}[$bin]);
 
-			my($pi) = int($LADCP{ENSEMBLE}[$e]->{GIMBAL_PITCH}+$opt_t);			# pitch/roll indices
+			my($pi) = int($LADCP{ENSEMBLE}[$e]->{GIMBAL_PITCH}+$opt_t);							# pitch/roll indices
 			my($ri) = int($LADCP{ENSEMBLE}[$e]->{ROLL}+$opt_t);
 			my($bi) = $bindepth[$bin]/$opt_o;
 
-			if ($e < $LADCP_atbottom) {											# downcast
-				$pitchSumDC += $LADCP{ENSEMBLE}[$e]->{GIMBAL_PITCH};	$pHistDC++; 
-				$rollSumDC  += $LADCP{ENSEMBLE}[$e]->{ROLL};			$rHistDC++;
+			if ($e < $LADCP_atbottom) {															# downcast
+				$pitchSumDC  += $LADCP{ENSEMBLE}[$e]->{GIMBAL_PITCH};	$pHistDC++; 
+				$rollSumDC += $LADCP{ENSEMBLE}[$e]->{ROLL};				$rHistDC++;
 				$pSumDC += $LADCP{ENSEMBLE}[$e]->{SSCORRECTED_OCEAN_W12}[$bin] - $DNCAST{MEDIAN_W}[$bi]; 
 				$rSumDC += $LADCP{ENSEMBLE}[$e]->{SSCORRECTED_OCEAN_W34}[$bin] - $DNCAST{MEDIAN_W}[$bi]; 
 			 	push(@{$pValsDC[$pi]},$LADCP{ENSEMBLE}[$e]->{SSCORRECTED_OCEAN_W12}[$bin] - $DNCAST{MEDIAN_W}[$bi]);
@@ -67,7 +74,7 @@
 				$rSumDC[$ri] += $LADCP{ENSEMBLE}[$e]->{SSCORRECTED_OCEAN_W34}[$bin] - $DNCAST{MEDIAN_W}[$bi]; $rHistDC[$ri]++;
 				$mode = $pHistDC[$pi] if ($pHistDC[$pi] > $mode);
 				$mode = $rHistDC[$ri] if ($rHistDC[$ri] > $mode);
-			} else { 																# upcast
+			} else { 																			# upcast
 				$pitchSumUC += $LADCP{ENSEMBLE}[$e]->{GIMBAL_PITCH};	$pHistUC++; 
 				$rollSumUC  += $LADCP{ENSEMBLE}[$e]->{ROLL};			$rHistUC++;
 				$pSumUC += $LADCP{ENSEMBLE}[$e]->{SSCORRECTED_OCEAN_W12}[$bin] - $UPCAST{MEDIAN_W}[$bi]; 
@@ -93,17 +100,17 @@
 	GMT_psxy('-W4,CornflowerBlue');
 		print(GMT "$xmin 0\n$xmax 0\n");
 
-	# DC PITCH
-	GMT_psxy('-Ey0.2/2,coral');
+	# DC BEAMS 1,2
+	GMT_psxy('-Ey0.2/2,coral');																	# error bars
 		for (my($i)=0; $i<2*round($opt_t); $i++) {
 			next unless ($pHistDC[$i] >= $min_fat);
 			my($minLim,$maxLim) = &bootstrap($btstrp_ndraw,0.95,\&avg,@{$pValsDC[$i]});			# 95% bootstrap conf limits
 			printf(GMT "%f %f %f\n",$i-round($opt_t)-0.3,($maxLim+$minLim)/2,($maxLim-$minLim)/2);
 		}
-	GMT_psxy('-Ey0.2/1,coral');																	# dc pitch
+	GMT_psxy('-Ey0.2/1,coral');
 		for (my($i)=0; $i<2*round($opt_t); $i++) {
 			next unless ($pHistDC[$i]>=$min_thin && $pHistDC[$i]<$min_fat);
-			my($minLim,$maxLim) = &bootstrap($btstrp_ndraw,0.95,\&avg,@{$pValsDC[$i]});			# 95% bootstrap conf limits
+			my($minLim,$maxLim) = &bootstrap($btstrp_ndraw,0.95,\&avg,@{$pValsDC[$i]});
 			printf(GMT "%f %f %f\n",$i-round($opt_t)-0.3,($maxLim+$minLim)/2,($maxLim-$minLim)/2);
 		}
 	GMT_psxy('-Sc0.15 -Gcoral');
@@ -115,7 +122,7 @@
 	if ($pHistDC) {
 		GMT_psxy('-W1,coral,8_2:0');															# averages (lines)
 			printf(GMT ">\n%f %f\n%f %f\n",$xmin,$pSumDC/$pHistDC,$xmax,$pSumDC/$pHistDC);		# 	bias
-			printf(GMT ">\n%f %f\n%f %f\n",$pitchSumDC/$pHistDC,$ymin,$pitchSumDC/$pHistDC,$ymax);# pitch
+			printf(GMT ">\n%f %f\n%f %f\n",$pitchSumDC/$pHistDC,$ymin,$pitchSumDC/$pHistDC,$ymax);# roll
 	}
 	GMT_psxy('-W2,coral,8_2:0');
 		for (my($i)=0; $i<2*round($opt_t); $i++) {
@@ -128,7 +135,7 @@
 					$i-round($opt_t)-0.3+0.5,$ymin+$hist_height*$pHistDC[$i]/$mode);
 		}
 
-	# DC ROLL
+	# DC BEAMS 3,4
 	GMT_psxy('-Ey0.2/2,coral');															
 		for (my($i)=0; $i<2*round($opt_t); $i++) {
 			next unless ($rHistDC[$i] >= $min_fat);
@@ -163,7 +170,7 @@
 					$i-round($opt_t)-0.1+0.5,$ymin+$hist_height*$rHistDC[$i]/$mode);
 		}
 
-	# UC PITCH
+	# UC BEAMS 1,2
 	GMT_psxy('-Ey0.2/2,SeaGreen');													
 		for (my($i)=0; $i<2*round($opt_t); $i++) {
 			next unless ($pHistUC[$i] >= $min_fat);
@@ -198,7 +205,7 @@
 					$i-round($opt_t)+0.1+0.5,$ymin+$hist_height*$pHistUC[$i]/$mode);
 		}
 
-	# UC ROLL
+	# UC BEAMS 3,4
 	GMT_psxy('-Ey0.2/2,SeaGreen');													
 		for (my($i)=0; $i<2*round($opt_t); $i++) {
 			next unless ($rHistUC[$i] >= $min_fat);
--- a/plot_backscatter.pl	Thu May 19 09:38:56 2016 -0400
+++ b/plot_backscatter.pl	Wed May 25 12:14:29 2016 -0400
@@ -1,9 +1,9 @@
 #======================================================================
 #                    P L O T _ B A C K S C A T T E R . P L 
 #                    doc: Tue Jul 28 13:21:09 2015
-#                    dlm: Wed May 18 19:44:28 2016
+#                    dlm: Tue May 24 23:09:58 2016
 #                    (c) 2015 A.M. Thurnherr
-#                    uE-Info: 40 41 NIL 0 0 72 0 2 4 NIL ofnI
+#                    uE-Info: 61 38 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -12,6 +12,8 @@
 #   Mar 16, 2016: - adapted to gmt5
 #   May 18, 2016: - added version
 #                 - expunged $realLastGoodEns
+#   May 24, 2016: - calc_binDepths() -> binDepths()
+#				  - fixed for partial-depth casts
 
 require "$ANTS/libGMT.pl";
 
@@ -23,10 +25,10 @@
 
 	my($xmin) = $P{min_ens}-0.5;
 	my($xmax) = $P{max_ens}+0.5;
-	my($ymin) = 0;
+	my($ymin) = round(antsParam('min_depth')-25,50);
 	my($ymax) = ($P{water_depth} > 0) ?
-				round($P{water_depth} + 25) :
-				round($P{max_depth} + $P{ADCP_bin_length});
+				round($P{water_depth}+25,50) :
+				round($P{max_depth}+$P{ADCP_bin_length}+25,50);
 
 	my($ens_width) = 10 / ($P{max_ens} - $P{min_ens} + 1);
 	my($bin_length) = 10 * $P{ADCP_bin_length} / 
@@ -39,7 +41,7 @@
 	GMT_psxy("$C -Sr");
 		for ($ens=$firstGoodEns; $ens<=$lastGoodEns; $ens++) {
 		  next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
-		  my(@bindepth) = calc_binDepths($ens);
+		  my(@bindepth) = binDepths($ens);
 		  for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 			  next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
 			  my($bi) = $bindepth[$bin]/$opt_o;
@@ -55,19 +57,17 @@
 		print(GMT "$xmin $ymax\n$xmax $ymax\n$xmax $P{water_depth}\n $xmin $P{water_depth}\n");
 	}
 
+	my($depth_tics) = ($ymax-$ymin < 1000) ? 'f10a100' : 'f100a500';					# AXES
+	my($ens_tics) =   ($xmax-$xmin < 4000) ? 'f50a500' : 'f500a2000';
+	GMT_psxy("-B$ens_tics:'Ensemble [#]':/$depth_tics:'Depth [m]':WeSn");
+		 
 	GMT_unitcoords();																	# LABELS
 	GMT_pstext('-F+f9,Helvetica,orange+jTR -N -Gwhite');
         print(GMT "0.99 0.01 V$VERSION\n");
 	GMT_pstext('-F+f14,Helvetica,blue+jTL -N');
 		print(GMT "0.01 -0.06 $P{out_basename} $P{run_label}\n");
 
-	my($depth_tics) = ($ymax < 1000 ) ? 'f10a100' : 'f100a500';							# AXES
-	my($ens_tics) =   ($ymax < 1000 ) ? 'f50a500' : 'f500a2000';
-	GMT_setR($R);
-	GMT_psbasemap("-B$ens_tics:'Ensemble [#]':/$depth_tics:'Depth [m]':WeSn");
-		 
 	GMT_setAnnotFontSize(7);															# SCALE BAR
-#	GMT_psscale("-E -D8/2/3/0.4 $C -B/:S\@-v\@-:");
 	GMT_psscale("-Dn0.85/0.1+w3/0.4+e $C -B/:S\@-v\@-:");
 
 	GMT_end();																			# FINISH PLOT
--- a/plot_correlation.pl	Thu May 19 09:38:56 2016 -0400
+++ b/plot_correlation.pl	Wed May 25 12:14:29 2016 -0400
@@ -1,9 +1,9 @@
 #======================================================================
 #                    P L O T _ C O R R E L A T I O N . P L 
 #                    doc: Tue Jul 28 13:21:09 2015
-#                    dlm: Wed May 18 19:44:36 2016
+#                    dlm: Tue May 24 23:10:09 2016
 #                    (c) 2015 A.M. Thurnherr
-#                    uE-Info: 40 41 NIL 0 0 72 0 2 4 NIL ofnI
+#                    uE-Info: 67 38 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -12,6 +12,8 @@
 #   Mar 16, 2016: - adapted to gmt5
 #   May 18, 2016: - added version
 #                 - expunged $realLastGoodEns
+#   May 24, 2016: - calc_binDepths() -> binDepths()
+#				  - fixed for partial-depth casts
 
 require "$ANTS/libGMT.pl";
 
@@ -23,10 +25,10 @@
 
 	my($xmin) = $P{min_ens}-0.5;
 	my($xmax) = $P{max_ens}+0.5;
-	my($ymin) = 0;
+	my($ymin) = round(antsParam('min_depth')-25,50);
 	my($ymax) = ($P{water_depth} > 0) ?
-				round($P{water_depth} + 25) :
-				round($P{max_depth} + $P{ADCP_bin_length});
+				round($P{water_depth}+25,50) :
+				round($P{max_depth}+$P{ADCP_bin_length}+25,50);
 
 	my($ens_width) = 10 / ($P{max_ens} - $P{min_ens} + 1);
 	my($bin_length) = 10 * $P{ADCP_bin_length} / 
@@ -39,7 +41,7 @@
 	GMT_psxy("$C -Sr");
 		for ($ens=$firstGoodEns; $ens<=$lastGoodEns; $ens++) {
 		  next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
-		  my(@bindepth) = calc_binDepths($ens);
+		  my(@bindepth) = binDepths($ens);
 		  for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 			  next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
 			  my($bi) = $bindepth[$bin]/$opt_o;
@@ -61,8 +63,8 @@
 	GMT_pstext('-F+f14,Helvetica,blue+jTL -N');
 		print(GMT "0.01 -0.06 $P{out_basename} $P{run_label}\n");
 
-	my($depth_tics) = ($ymax < 1000 ) ? 'f10a100' : 'f100a500';							# AXES
-	my($ens_tics) =   ($ymax < 1000 ) ? 'f50a500' : 'f500a2000';
+	my($depth_tics) = ($ymax-$ymin < 1000) ? 'f10a100' : 'f100a500';					# AXES
+	my($ens_tics) =   ($xmax-$xmin < 4000) ? 'f50a500' : 'f500a2000';
 	GMT_setR($R);
 	GMT_psbasemap("-B$ens_tics:'Ensemble [#]':/$depth_tics:'Depth [m]':WeSn");
 		 
--- a/plot_residual_profs.pl	Thu May 19 09:38:56 2016 -0400
+++ b/plot_residual_profs.pl	Wed May 25 12:14:29 2016 -0400
@@ -1,13 +1,14 @@
 #======================================================================
 #                    P L O T _ R E S I D U A L _ P R O F S . P L 
 #                    doc: Wed May 18 18:43:33 2016
-#                    dlm: Wed May 18 21:43:53 2016
+#                    dlm: Tue May 24 22:02:28 2016
 #                    (c) 2016 A.M. Thurnherr
-#                    uE-Info: 48 29 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 77 0 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
 #   May 18, 2016: - created from [plot_mean_residuals.pl]
+#	May 24, 2016: - improved
 
 require "$ANTS/libGMT.pl";
 
@@ -50,15 +51,16 @@
 
 	my($xmin) = -0.05;
 	my($xmax) =  0.05;
-	my($ymin) =  0;
-	my($ymax) = ($P{water_depth} > 0) ? round($P{water_depth} + 25) :
-	                                    round($P{max_depth}   + 25);
+	my($ymin) = round(antsParam('min_depth')-25,50);
+	my($ymax) = ($P{water_depth} > 0) ?
+				round($P{water_depth}+25,50) :
+				round($P{max_depth}+$P{ADCP_bin_length}+25,50);
 	                                              
 	my($R) = "-R$xmin/$xmax/$ymin/$ymax";
 	my($depth_tics) = ($ymax < 1000 ) ? 'f10a100g100' : 'f100a500g500';
 	GMT_begin($pfn,'-JX10/-10',$R,"-P -Bf0.005a0.02g0.01:'Residual Vertical Velocity [m/s]':/$depth_tics:'Depth [m]':WeSn");
 
-	GMT_psxy('-W4,CornflowerBlue');													# zero line
+	GMT_psxy('-W2,CornflowerBlue');													# zero line
 		printf(GMT "0 $ymin\n0 $ymax\n");
 
 	GMT_psxy('-W1,coral,8_2:0'); my($r12DC) = plotDC('MEAN_RESIDUAL12',$opt_k);		# dc residual12 (pitch plane)
@@ -72,18 +74,22 @@
 	GMT_pstext('-F+f14,Helvetica,blue+jBL -N');										# profile id
 		print(GMT "0.0 -0.03 $P{out_basename} $P{run_label}\n");
 
-	if ($r12DC >= $red_light) { 		GMT_pstext('-F+f12,Helvetica-Bold,coral+jBL -Gred'); }	# rms residuals
+	GMT_pstext('-F+f12,Helvetica-Bold,black+jBL -Gwhite'); 							# rms residuals
+		print(GMT "0.01 0.89 beams <1,2>\n");
+	if ($r12DC >= $red_light) { 		GMT_pstext('-F+f12,Helvetica-Bold,coral+jBL -Gred'); }	
 	elsif ($r12DC >= $yellow_light) { 	GMT_pstext('-F+f12,Helvetica-Bold,coral+jBL -Gyellow'); }
 	else {								GMT_pstext('-F+f12,Helvetica-Bold,coral+jBL -Gwhite'); }
-		printf(GMT "0.01 0.93 %.1f mm/s rms\n",1000*$r12DC);
+		printf(GMT "0.01 0.935 %.1f mm/s rms\n",1000*$r12DC);
 	if ($r12UC >= $red_light) { 		GMT_pstext('-F+f12,Helvetica-Bold,SeaGreen+jBL -Gred'); }
 	elsif ($r12UC >= $yellow_light) { 	GMT_pstext('-F+f12,Helvetica-Bold,SeaGreen+jBL -Gyellow'); }
 	else {								GMT_pstext('-F+f12,Helvetica-Bold,SeaGreen+jBL -Gwhite'); }
 		printf(GMT "0.01 0.98 %.1f mm/s rms\n",1000*$r12UC);
+	GMT_pstext('-F+f12,Helvetica-Bold,black+jBR -Gwhite');
+		print(GMT "0.99 0.89 beams <3,4>\n");
 	if ($r34DC >= $red_light) { 		GMT_pstext('-F+f12,Helvetica-Bold,coral+jBR -Gred'); }
 	elsif ($r34DC >= $yellow_light) { 	GMT_pstext('-F+f12,Helvetica-Bold,coral+jBR -Gyellow'); }
 	else {								GMT_pstext('-F+f12,Helvetica-Bold,coral+jBR -Gwhite'); }
-		printf(GMT "0.99 0.93 %.1f mm/s rms\n",1000*$r34DC);
+		printf(GMT "0.99 0.935 %.1f mm/s rms\n",1000*$r34DC);
 	if ($r34UC >= $red_light) { 		GMT_pstext('-F+f12,Helvetica-Bold,SeaGreen+jBR -Gred'); }
 	elsif ($r34UC >= $yellow_light) { 	GMT_pstext('-F+f12,Helvetica-Bold,SeaGreen+jBR -Gyellow'); }
 	else {								GMT_pstext('-F+f12,Helvetica-Bold,SeaGreen+jBR -Gwhite'); }
--- a/plot_residuals.pl	Thu May 19 09:38:56 2016 -0400
+++ b/plot_residuals.pl	Wed May 25 12:14:29 2016 -0400
@@ -1,9 +1,9 @@
 #======================================================================
 #                    P L O T _ R E S I D U A L S . P L 
 #                    doc: Tue Jul 28 13:21:09 2015
-#                    dlm: Wed May 18 19:44:44 2016
+#                    dlm: Tue May 24 23:10:20 2016
 #                    (c) 2015 A.M. Thurnherr
-#                    uE-Info: 55 43 NIL 0 0 72 0 2 4 NIL ofnI
+#                    uE-Info: 83 38 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -14,6 +14,8 @@
 #	Mar 16, 2016: - adapted to gmt5
 #   May 18, 2016: - added version
 #                 - expunged $realLastGoodEns
+#   May 24, 2016: - calc_binDepths() -> binDepths()
+#				  - fixed for partial-depth casts
 
 require "$ANTS/libGMT.pl";
 
@@ -25,10 +27,10 @@
 
 	my($xmin) = $P{min_ens}-0.5;
 	my($xmax) = $P{max_ens}+0.5;
-	my($ymin) = 0;
+	my($ymin) = round(antsParam('min_depth')-25,50);
 	my($ymax) = ($P{water_depth} > 0) ?
-				round($P{water_depth} + 25) :
-				round($P{max_depth} + $P{ADCP_bin_length});
+				round($P{water_depth}+25,50) :
+				round($P{max_depth}+$P{ADCP_bin_length}+25,50);
 
 	my($ens_width) = 10 / ($P{max_ens} - $P{min_ens} + 1);
 	my($bin_length) = 10 * $P{ADCP_bin_length} / 
@@ -41,7 +43,7 @@
 	GMT_psxy("$C -Sr");
 		for ($ens=$firstGoodEns; $ens<$LADCP_atbottom; $ens++) {						# downcast
 		  next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
-		  my(@bindepth) = calc_binDepths($ens);
+		  my(@bindepth) = binDepths($ens);
 		  for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 			  next unless ($bin+1>=$outGrid_firstBin && $bin+1<=$outGrid_lastBin);
 			  next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
@@ -54,7 +56,7 @@
         }
 		for ($ens=$LADCP_atbottom; $ens<=$lastGoodEns; $ens++) {					  # upcast 
 		  next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
-		  my(@bindepth) = calc_binDepths($ens);
+		  my(@bindepth) = binDepths($ens);
 		  for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 			  next unless ($bin+1>=$outGrid_firstBin && $bin+1<=$outGrid_lastBin);
 			  next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
@@ -77,14 +79,13 @@
 	GMT_pstext('-F+f14,Helvetica,blue+jTL -N');
 		print(GMT "0.01 -0.06 $P{out_basename} $P{run_label}\n");
 
-	my($depth_tics) = ($ymax < 1000 ) ? 'f10a100' : 'f100a500';							# AXES
-	my($ens_tics) =   ($ymax < 1000 ) ? 'f50a500' : 'f500a2000';
+	my($depth_tics) = ($ymax-$ymin < 1000) ? 'f10a100' : 'f100a500';					# AXES
+	my($ens_tics) =   ($xmax-$xmin < 4000) ? 'f50a500' : 'f500a2000';
 	GMT_setR($R);
 	GMT_psbasemap("-B$ens_tics:'Ensemble [#]':/$depth_tics:'Depth [m]':WeSn");
 
 	GMT_setAnnotFontSize(7);															# SCALE BAR
-#	GMT_psscale("-E -D8/2/3/0.4 $C -B/:residuals:");
-	GMT_psscale("-Dn0.83/0.1+w3/0.4+e $C -B/:residuals:");
+	GMT_psscale("-Dn0.83/0.1+w3/0.4+e $C -B/:w\@-residual\@-:");
 		 
 	GMT_end();																			# FINISH PLOT
 }
--- a/plot_time_lags.pl	Thu May 19 09:38:56 2016 -0400
+++ b/plot_time_lags.pl	Wed May 25 12:14:29 2016 -0400
@@ -1,9 +1,9 @@
 #======================================================================
 #                    P L O T _ T I M E _ L A G S . P L 
 #                    doc: Tue Jul 28 13:21:09 2015
-#                    dlm: Wed May 18 12:58:17 2016
+#                    dlm: Tue May 24 22:11:30 2016
 #                    (c) 2015 A.M. Thurnherr
-#                    uE-Info: 51 28 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 59 81 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -11,6 +11,8 @@
 #   Jan 26, 2016: - added return on no data to plot
 #	Mar 16, 2016: - adapted to gmt5
 #   May 18, 2016: - added version
+#	May 24, 2016: - fixed for partial-depth casts
+
 
 require "$ANTS/libGMT.pl";
 
@@ -53,7 +55,8 @@
 		print(GMT "0.01 1.06 $P{out_basename} $P{run_label}\n");
 
 	GMT_setR($R);
-	GMT_end('-Bf1a30:"Elapsed Time [min]":/f1a5:"Best Offset [scans]":WeSn');			# FINISH PLOT
+	my($elapsed_tics) = ($xmax-$xmin < 45) ? 'f1a5' : 'f1a30';
+	GMT_end("-B$elapsed_tics:'Elapsed Time [min]':/f1a5:'Best Offset [CTD records]':WeSn");	# FINISH PLOT
 }
 
 1; # return true on require
--- a/plot_wprof.pl	Thu May 19 09:38:56 2016 -0400
+++ b/plot_wprof.pl	Wed May 25 12:14:29 2016 -0400
@@ -1,9 +1,9 @@
 #======================================================================
 #                    P L O T _ W P R O F . P L 
 #                    doc: Sun Jul 26 11:08:50 2015
-#                    dlm: Thu May 19 01:00:27 2016
+#                    dlm: Tue May 24 22:31:14 2016
 #                    (c) 2015 A.M. Thurnherr
-#                    uE-Info: 76 36 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 19 51 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -14,6 +14,9 @@
 #	Mar 17, 2016: - improved
 #	May 18, 2016: - replaced rms tilt by mean tilt with traffic background
 #				  - added plot_wprof_ymin tweakable
+#	May 24, 2016: - BUG: ymin did not work for nsamp
+#				  - fixed for partial-depth profiles
+#				  - suppress plotting of nsamp == 0
 
 # Tweakables:
 #
@@ -25,8 +28,7 @@
 require "$ANTS/libGMT.pl";
 
 sub setR1() { GMT_setR("-R$plot_wprof_xmin/0.35/$plot_wprof_ymin/$plot_wprof_ymax"); }
-#sub setR2() { GMT_setR("-R-200/200/0/$plot_wprof_ymax"); }
-sub setR2() { GMT_setR("-R-450/350/0/$plot_wprof_ymax"); }
+sub setR2() { GMT_setR("-R-450/350/$plot_wprof_ymin/$plot_wprof_ymax"); }
 
 sub plotDC($$)
 {
@@ -72,19 +74,19 @@
 
 	$plot_wprof_xmin = -0.1
 		unless defined($plot_wprof_xmin);		
-	$plot_wprof_ymin = 0
+	$plot_wprof_ymin = round(antsParam('min_depth')-25,50)
 		unless defined($plot_wprof_ymin);		
 	$plot_wprof_ymax = ($P{water_depth} > 0) ?
-					   round($P{water_depth} + 25) :
-					   round($P{max_depth} 	 + 25)
+					   round($P{water_depth}+25,50) :
+					   round($P{max_depth}+25,50)
 		unless defined($plot_wprof_ymax);					  	
 	$plot_wprof_xtics = "-0.05 0.05 0.15"
 		unless defined($plot_wprof_xtics);
 
-	GMT_begin($pfn,'-JX10/-10',"-R$plot_wprof_xmin/0.35/0/$plot_wprof_ymax",'-P');		# START PLOT
+	GMT_begin($pfn,'-JX10/-10',"-R$plot_wprof_xmin/0.35/$plot_wprof_ymin/$plot_wprof_ymax",'-P');		# START PLOT
 
 	GMT_psxy('-G200'); 																	# MAD background
-		print(GMT "0.07 0\n 0.07 $plot_wprof_ymax\n0.18 $plot_wprof_ymax\n0.18 0\n");
+		print(GMT "0.07 $plot_wprof_ymin\n 0.07 $plot_wprof_ymax\n0.18 $plot_wprof_ymax\n0.18 $plot_wprof_ymin\n");
 
 	if ($P{water_depth} > 0) {															# SEABED
 		GMT_psxy('-G204/153/102');
@@ -112,9 +114,9 @@
 	GMT_psxy('-Sc0.1c -Gblack');		plotBT('MAD_W',0);	
 
 	setR2();																			# SAMPLES
-	GMT_psxy('-W0.7,coral');			plotDC('N_SAMP',0);
-	GMT_psxy('-W0.7,SeaGreen');			plotUC('N_SAMP',0);	
-	GMT_psxy('-W0.7,black');			plotBT('N_SAMP',0);	
+	GMT_psxy('-W0.7,coral');			plotDC('N_SAMP',1);
+	GMT_psxy('-W0.7,SeaGreen');			plotUC('N_SAMP',1);	
+	GMT_psxy('-W0.7,black');			plotBT('N_SAMP',1);	
 	
 	GMT_unitcoords();																	# LABELS
 	GMT_pstext('-F+f14,Helvetica,blue+jTL -N');
@@ -173,7 +175,7 @@
 	}
 		printf(GMT "0.89 1.125 %.1fm\@+2\@+/s\n",$P{uc_rms_accel_pkg});
 		
-	my($depth_tics) = ($plot_wprof_ymax < 1000 ) ? 'f10a100' : 'f100a500';				# AXES
+	my($depth_tics) = ($plot_wprof_ymax-$plot_prof_ymin < 1000 ) ? 'f10a100' : 'f100a500';				# AXES
 	setR1();
 	GMT_psbasemap("-Bf0.01:'':/$depth_tics:'Depth [m]':WeS");
 	foreach my $t (split('\s+',$plot_wprof_xtics)) {
--- a/plot_wsamp.pl	Thu May 19 09:38:56 2016 -0400
+++ b/plot_wsamp.pl	Wed May 25 12:14:29 2016 -0400
@@ -1,9 +1,9 @@
 #======================================================================
 #                    P L O T _ W S A M P . P L 
 #                    doc: Tue Jul 28 13:21:09 2015
-#                    dlm: Wed May 18 19:44:53 2016
+#                    dlm: Tue May 24 23:10:28 2016
 #                    (c) 2015 A.M. Thurnherr
-#                    uE-Info: 43 41 NIL 0 0 72 0 2 4 NIL ofnI
+#                    uE-Info: 73 38 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -15,6 +15,8 @@
 #	Mar 16, 2016: - adapted to gmt5
 #   May 18, 2016: - added version
 #                 - expunged $realLastGoodEns
+#   May 24, 2016: - calc_binDepths() -> binDepths()
+#				  - fixed for partial-depth profiles
 
 require "$ANTS/libGMT.pl";
 
@@ -26,10 +28,11 @@
 
 	my($xmin) = $P{min_ens}-0.5;
 	my($xmax) = $P{max_ens}+0.5;
-	my($ymin) = 0;
+	my($ymin) = round(antsParam('min_depth')-25,50);
 	my($ymax) = ($P{water_depth} > 0) ?
-				round($P{water_depth} + 25) :
-				round($P{max_depth} + $P{ADCP_bin_length});
+				round($P{water_depth}+25,50) :
+				round($P{max_depth}+$P{ADCP_bin_length}+25,50);
+
 
 	my($ens_width) = 10 / ($P{max_ens} - $P{min_ens} + 1);
 	my($bin_length) = 10 * $P{ADCP_bin_length} / 
@@ -42,7 +45,7 @@
 	GMT_psxy("$C -Sr");
 		for ($ens=$firstGoodEns; $ens<=$lastGoodEns; $ens++) {
 		  next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
-		  my(@bindepth) = calc_binDepths($ens);
+		  my(@bindepth) = binDepths($ens);
 		  for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
 			  next unless ($bin+1>=$outGrid_firstBin && $bin+1<=$outGrid_lastBin);
 			  next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
@@ -66,14 +69,13 @@
 	GMT_pstext('-F+f14,Helvetica,blue+jTL -N');
 		print(GMT "0.01 -0.06 $P{out_basename} [$P{run_label}]\n");
 
-	my($depth_tics) = ($ymax < 1000 ) ? 'f10a100' : 'f100a500';							# AXES
-	my($ens_tics) =   ($ymax < 1000 ) ? 'f50a500' : 'f500a2000';
+	my($depth_tics) = ($ymax-$ymin < 1000) ? 'f10a100' : 'f100a500';					# AXES
+	my($ens_tics) =   ($xmax-$xmin < 4000) ? 'f50a500' : 'f500a2000';
 	GMT_setR($R);
 	GMT_psbasemap("-B$ens_tics:'Ensemble [#]':/$depth_tics:'Depth [m]':WeSn");
 		 
 	GMT_setAnnotFontSize(7);															# SCALE BAR
-#	GMT_psscale("-E -D8/2/3/0.4 $C -B/:w:");
-	GMT_psscale("-Dn0.85/0.1+w3/0.4+e $C -B/:w:");
+	GMT_psscale("-Dn0.85/0.1+w3/0.4+e $C -B/:w\@-ocean\@-:");
 
 	GMT_end();																			# FINISH PLOT
 }
--- a/svel_corrections.pl	Thu May 19 09:38:56 2016 -0400
+++ b/svel_corrections.pl	Wed May 25 12:14:29 2016 -0400
@@ -1,9 +1,9 @@
 #======================================================================
 #                    S V E L _ C O R R E C T I O N S . P L 
 #                    doc: Thu Dec 30 01:35:18 2010
-#                    dlm: Thu May 19 00:51:30 2016
+#                    dlm: Tue May 24 16:44:07 2016
 #                    (c) 2010 A.M. Thurnherr
-#                    uE-Info: 19 65 NIL 0 0 72 0 2 4 NIL ofnI
+#                    uE-Info: 116 64 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -17,6 +17,8 @@
 #	May 12, 2016: - removed unused lines of code
 #	May 18, 2016: - removed assumption of 1500m/s soundspeed setting
 #				  - made sscorr_w return nan on undef'd input vel
+#   May 24, 2016: - calc_binDepths() -> binDepths()
+#				  - added caching to binDepths
 
 # NOTES:
 #	In an effort to track down the scale bias, NBP0901 stn 160 was reprocessed with various
@@ -41,10 +43,14 @@
 	return ($wObs*$sVelProf[$dBin]/$ssADCP - $wCTD) / $Kn;		# full correction
 }
 
-sub calc_binDepths($)											# see RDI Coord Trans manual sec. 4.2
+sub binDepths($)												# see RDI Coord Trans manual sec. 4.2
 {
 	my($ens) = @_;
-	my(@bindz);
+
+	return @{$LADCP{ENSEMBLE}[$ens]->{BIN_DEPTHS}}				# cached result
+		if (@{$LADCP{ENSEMBLE}[$ens]->{BIN_DEPTHS}});
+
+	my(@bindz);													# if not cached => calculate
 
 	# if the following assertion fails, the entire code needs to be searched for
 	# each call of calc_binDepths() needs to be protected by a test
@@ -104,11 +110,10 @@
 	                    $bindz[$bin-1] + $LADCP{BIN_LENGTH}*$Kn*$avgss/$LADCP{ENSEMBLE}[$ens]->{SPEED_OF_SOUND}*cos(rad($LADCP{ENSEMBLE}[$ens]->{TILT}));
     }
 
-    my(@bindepth);
-    for (my($i)=0; $i<@bindz; $i++) {
-    	$bindepth[$i] = $LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH} + $bindz[$i];
+    for (my($i)=0; $i<@bindz; $i++) {							# cache result
+    	$LADCP{ENSEMBLE}[$ens]->{BIN_DEPTHS}[$i] = $LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH} + $bindz[$i];
     }
-	return @bindepth;
+	return @{$LADCP{ENSEMBLE}[$ens]->{BIN_DEPTHS}};				# return result
 }
 
 1;
--- a/version.pl	Thu May 19 09:38:56 2016 -0400
+++ b/version.pl	Wed May 25 12:14:29 2016 -0400
@@ -1,9 +1,9 @@
 #======================================================================
 #                    V E R S I O N . P L 
 #                    doc: Tue Oct 13 10:40:57 2015
-#                    dlm: Thu May 12 13:50:14 2016
+#                    dlm: Wed May 25 12:12:54 2016
 #                    (c) 2015 A.M. Thurnherr
-#                    uE-Info: 23 21 NIL 0 0 72 0 2 4 NIL ofnI
+#                    uE-Info: 24 20 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -16,12 +16,13 @@
 #	Mar 30, 2016: - V1.2beta7
 #	Apr 16, 2016: - V1.2beta8
 #	May 12, 2016: - V1.2
+#	May 19, 2016: - updated ADCP tools to V1.6
 
 #$VERSION = '1.1';				# Jan  4, 2016
 #$VERSION = '1.2';				# May 12, 2016
 
-$VERSION = '1.3beta';
+$VERSION = '1.3beta1';
 
 $antsMinLibVersion 		= 6.6;
-$ADCP_tools_minVersion 	= 1.5;
+$ADCP_tools_minVersion 	= 1.6;	# May 19, 2016 (RDI_Coords with bin interpolation)