whoosher version at beginning of FZ1
authorA.M. Thurnherr <ant@ldeo.columbia.edu>
Wed, 09 Jul 2014 15:19:27 -0400
changeset 16 29e867b3e070
parent 15 dfcb6bef9d42
child 17 fc83e436a800
whoosher version at beginning of FZ1
LADCP_w
LWplot_Sv
Plots/2014_P16_043.eps
defaults.pl
edit_data.pl
time_lag.pl
--- a/LADCP_w	Tue May 20 09:08:43 2014 +0000
+++ b/LADCP_w	Wed Jul 09 15:19:27 2014 -0400
@@ -2,9 +2,9 @@
 #======================================================================
 #                    L A D C P _ W 
 #                    doc: Fri Dec 17 18:11:13 2010
-#                    dlm: Mon May 19 22:21:35 2014
+#                    dlm: Wed May 21 08:50:29 2014
 #                    (c) 2010 A.M. Thurnherr
-#                    uE-Info: 932 27 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 680 96 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # TODO:
@@ -138,6 +138,9 @@
 #	Sep  5, 2013: - BUG: w12/w34 do not work for earth-coordinate data, of course
 #	Apr 17, 2014: - BUG: edit_tilt was never called when all recorded bins are valid
 #	Apr 21, 2014: - updated comments
+#	May 19, 2014: - began adding support for PPI filtering
+#	May 20, 2014: - changed volume_scattering_coeff to Sv in output
+#				  - added editPPI()
 
 # CTD REQUIREMENTS
 #	- elapsed		elapsed seconds; see note below
@@ -658,8 +661,7 @@
 # Construct sound-speed correction profile from CTD 1Hz downcast data
 #	very simple algorithm that stores the last value found
 #	in each 1m bin
-# For PPI filtering, a sound speed profile to the surface is required.
-# 	This is ensured by extrapolating the first value up to zero
+# For PPI filtering, a sound speed profile without gaps is required.
 #--------------------------------------------------------------------
 
 progress("Constructing sound-speed correction profile\n");
@@ -671,10 +673,15 @@
 	$min_depth = $s if ($s < $min_depth);
 	$sVelProf[int($CTD{DEPTH}[$s])] = $CTD{SVEL}[$s];
 }
-while ($min_depth > 0) {
+while ($min_depth > 0) {													# fill surface gap
 	$sVelProf[$min_depth-1] = $sVelProf[$min_depth];
 	$min_depth--;
 }
+for (my($d)=$min_depth+1; $d<=$#sVelProf; $d++) {							# fill interior gaps
+	$sVelProf[$d] = $sVelProf[$d-1]
+		unless defined($sVelProf[$d]);
+}
+	
 
 #-------------------
 # Determine time lag
@@ -904,16 +911,20 @@
 		($nvrm,$nerm) = editSideLobes($firstGoodEns,$lastGoodEns,$water_depth);
 		progress("\t$nvrm velocities from $nerm ensembles removed\n");
 
-		progress("Editing data to remove PPI from seabed...\n");
-		  progress("\tConstructing travel-time profile...\n");
-		  my($tt) = ($water_depth - $#sVelProf) / $sVelProf[$#sVelProf];  # $#sVelProf = max_depth(profile) in meters
-		  $ttProf[$#sVelProf] = $tt;
-		  for (my($d)=$#sVelProf-1; $d>=0; $d--) {
-			  $tt += 1 / $sVelProf[$d];
-			  $ttProf[$d] = $tt;
-          }
-		($nvrm,$nerm) = editPPI($firstGoodEns,$lastGoodEns,$water_depth);
-		progress("\t$nvrm velocities from $nerm ensembles removed\n");
+		if ($PPI_editing) {
+			progress("Editing data to remove PPI from seabed...\n");
+			  progress("\tConstructing depth-average soundspeed profile...\n");
+			  my($dz) = $water_depth - $#sVelProf;							# $#sVelProf = max_depth(profile) in meters
+			  my($sum) = $dz * $sVelProf[$#sVelProf];
+			  $DASSprof[$#sVelProf] = $sum/$dz;
+			  for (my($d)=$#sVelProf-1; $d>=0; $d--) {
+			  	$sum += $sVelProf[$d];
+			  	$dz++;
+				$DASSprof[$d] = $sum/$dz;
+			  }
+			($nvrm,$nerm) = editPPI($firstGoodEns,$lastGoodEns,$water_depth);
+	        progress("\t$nvrm velocities from $nerm ensembles removed\n");
+	    }
 	} else {
 		info("no seabed found in backscatter profiles --- cannot edit sidelobe or PPI\n");
 	}
@@ -925,16 +936,17 @@
 	($nvrm,$nerm) = editSideLobes($firstGoodEns,$lastGoodEns,undef);
 	progress("\t$nvrm velocities from $nerm ensembles removed\n");
 
-	progress("Editing data to remove PPI from sea surface...\n");
-	  progress("\tConstructing travel-time profile...\n");
-	  my($tt) = 0;
-	  $ttProf[0] = $tt;
-	  for (my($d)=1; $d<=$#sVelProf; $d++) {
-		  $tt += 1 / $sVelProf[$d];
-		  $ttProf[$d] = $tt;
-      }
-	($nvrm,$nerm) = editPPI($firstGoodEns,$lastGoodEns,undef);
-	progress("\t$nvrm velocities from $nerm ensembles removed\n");
+	if ($PPI_editing) {
+		progress("Editing data to remove PPI from sea surface...\n");
+		  progress("\tConstructing depth-average soundspeed profile...\n");
+		  $DASSprof[0] = my($sum) = 0;
+		  for (my($d)=1; $d<=$#sVelProf; $d++) {
+		  	$sum += $sVelProf[$d];
+			$DASSprof[$d] = $sum/$d;
+		  }
+		($nvrm,$nerm) = editPPI($firstGoodEns,$lastGoodEns,undef);
+	    progress("\t$nvrm velocities from $nerm ensembles removed\n");
+	}
 }
 
 #----------------------------------------------------------------------
@@ -1264,7 +1276,7 @@
 
 	@antsNewLayout = ('ensemble','bin','elapsed','depth','CTD_depth','downcast',
 					  'w','w12','w34','residual','CTD_w','CTD_w_tt','LADCP_w','errvel',
-					  'correlation','echo_amplitude','volume_scattering_coeff',
+					  'correlation','echo_amplitude','Sv',
 					  'pitch','roll','tilt','heading','3_beam','svel');
 
 	open(STDOUT,"$out_w") || croak("$out_w: $!\n");
--- a/LWplot_Sv	Tue May 20 09:08:43 2014 +0000
+++ b/LWplot_Sv	Wed Jul 09 15:19:27 2014 -0400
@@ -2,9 +2,9 @@
 #======================================================================
 #					 L W P L O T _ S V 
 #                    doc: Sat Oct 15 13:42:50 2011
-#                    dlm: Thu May 16 15:22:39 2013
+#                    dlm: Tue May 20 10:57:56 2014
 #                    (c) 2011 A.M. Thurnherr
-#                    uE-Info: 83 26 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 17 57 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -14,6 +14,7 @@
 #	Mar 12, 2012: - sh -> ksh as this does not work with /bin/sh on MacOSX 10.6.4
 #   Apr 12, 2012: - made re-entrant
 #	May 16, 2013: - adapted to file-layout changes
+#	May 20, 2013: - renamed volume_scattering_coeff to Sv
 
 #--------------------------------------------------
 # Usage
@@ -44,7 +45,7 @@
 done
 
 set -- $fields
-[ "$1" = ensemble -a "$4" = depth -a "${17}" = volume_scattering_coeff ] || {
+[ "$1" = ensemble -a "$4" = depth -a "${17}" = Sv ] || {
 	echo "$0: file layout error" >&2
 	exit 1
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plots/2014_P16_043.eps	Wed Jul 09 15:19:27 2014 -0400
@@ -0,0 +1,2039 @@
+%!PS-Adobe-2.0 EPSF-1.2
+%%Title: /tmp/80028.eps
+%%Creator: gnuplot 4.4 patchlevel 4
+%%CreationDate: Tue May 20 14:55:44 2014
+%%For:ant ant
+%%Pages: 1
+%%DocumentFonts: Helvetica
+%%BoundingBox: 57 82 748 725
%%HiResBoundingBox: 57.293998 82.850060 747.249938 724.517978
%%EndComments
+
+%%BeginProlog
+save countdictstack mark newpath /showpage {} def /setpagedevice /pop load def
+%%EndProlog
+%%Page 1 1
+/gnudict 256 dict def
+gnudict begin
+%
+% The following true/false flags may be edited by hand if desired.
+% The unit line width and grayscale image gamma correction may also be changed.
+%
+/Color true def
+/Blacktext false def
+/Solid true def
+/Dashlength 1 def
+/Landscape false def
+/Level1 false def
+/Rounded false def
+/ClipToBoundingBox false def
+/TransparentPatterns false def
+/gnulinewidth 15.000 def
+/userlinewidth gnulinewidth def
+/Gamma 1.0 def
+%
+/vshift -120 def
+/dl1 {
+  10.0 Dashlength mul mul
+  Rounded { currentlinewidth 0.75 mul sub dup 0 le { pop 0.01 } if } if
+} def
+/dl2 {
+  10.0 Dashlength mul mul
+  Rounded { currentlinewidth 0.75 mul add } if
+} def
+/hpt_ 31.5 def
+/vpt_ 31.5 def
+/hpt hpt_ def
+/vpt vpt_ def
+Level1 {} {
+/SDict 10 dict def
+systemdict /pdfmark known not {
+  userdict /pdfmark systemdict /cleartomark get put
+} if
+SDict begin [
+  /Title ()
+  /Subject (gnuplot plot)
+  /Creator (gnuplot 4.4 patchlevel 4)
+  /Author (ant)
+%  /Producer (gnuplot)
+%  /Keywords ()
+  /CreationDate (Tue May 20 14:55:44 2014)
+  /DOCINFO pdfmark
+end
+} ifelse
+/doclip {
+  ClipToBoundingBox {
+    newpath 50 50 moveto 770 50 lineto 770 770 lineto 50 770 lineto closepath
+    clip
+  } if
+} def
+%
+% Gnuplot Prolog Version 4.4 (August 2010)
+%
+%/SuppressPDFMark true def
+%
+/M {moveto} bind def
+/L {lineto} bind def
+/R {rmoveto} bind def
+/V {rlineto} bind def
+/N {newpath moveto} bind def
+/Z {closepath} bind def
+/C {setrgbcolor} bind def
+/f {rlineto fill} bind def
+/g {setgray} bind def
+/Gshow {show} def   % May be redefined later in the file to support UTF-8
+/vpt2 vpt 2 mul def
+/hpt2 hpt 2 mul def
+/Lshow {currentpoint stroke M 0 vshift R 
+	Blacktext {gsave 0 setgray show grestore} {show} ifelse} def
+/Rshow {currentpoint stroke M dup stringwidth pop neg vshift R
+	Blacktext {gsave 0 setgray show grestore} {show} ifelse} def
+/Cshow {currentpoint stroke M dup stringwidth pop -2 div vshift R 
+	Blacktext {gsave 0 setgray show grestore} {show} ifelse} def
+/UP {dup vpt_ mul /vpt exch def hpt_ mul /hpt exch def
+  /hpt2 hpt 2 mul def /vpt2 vpt 2 mul def} def
+/DL {Color {setrgbcolor Solid {pop []} if 0 setdash}
+ {pop pop pop 0 setgray Solid {pop []} if 0 setdash} ifelse} def
+/BL {stroke userlinewidth 2 mul setlinewidth
+	Rounded {1 setlinejoin 1 setlinecap} if} def
+/AL {stroke userlinewidth 2 div setlinewidth
+	Rounded {1 setlinejoin 1 setlinecap} if} def
+/UL {dup gnulinewidth mul /userlinewidth exch def
+	dup 1 lt {pop 1} if 10 mul /udl exch def} def
+/PL {stroke userlinewidth setlinewidth
+	Rounded {1 setlinejoin 1 setlinecap} if} def
+3.8 setmiterlimit
+% Default Line colors
+/LCw {1 1 1} def
+/LCb {0 0 0} def
+/LCa {0 0 0} def
+/LC0 {1 0 0} def
+/LC1 {0 1 0} def
+/LC2 {0 0 1} def
+/LC3 {1 0 1} def
+/LC4 {0 1 1} def
+/LC5 {1 1 0} def
+/LC6 {0 0 0} def
+/LC7 {1 0.3 0} def
+/LC8 {0.5 0.5 0.5} def
+% Default Line Types
+/LTw {PL [] 1 setgray} def
+/LTb {BL [] LCb DL} def
+/LTa {AL [1 udl mul 2 udl mul] 0 setdash LCa setrgbcolor} def
+/LT0 {PL [] LC0 DL} def
+/LT1 {PL [4 dl1 2 dl2] LC1 DL} def
+/LT2 {PL [2 dl1 3 dl2] LC2 DL} def
+/LT3 {PL [1 dl1 1.5 dl2] LC3 DL} def
+/LT4 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def
+/LT5 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC5 DL} def
+/LT6 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC6 DL} def
+/LT7 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC7 DL} def
+/LT8 {PL [2 dl1 2 dl2 2 dl1 2 dl2 2 dl1 2 dl2 2 dl1 4 dl2] LC8 DL} def
+/Pnt {stroke [] 0 setdash gsave 1 setlinecap M 0 0 V stroke grestore} def
+/Dia {stroke [] 0 setdash 2 copy vpt add M
+  hpt neg vpt neg V hpt vpt neg V
+  hpt vpt V hpt neg vpt V closepath stroke
+  Pnt} def
+/Pls {stroke [] 0 setdash vpt sub M 0 vpt2 V
+  currentpoint stroke M
+  hpt neg vpt neg R hpt2 0 V stroke
+ } def
+/Box {stroke [] 0 setdash 2 copy exch hpt sub exch vpt add M
+  0 vpt2 neg V hpt2 0 V 0 vpt2 V
+  hpt2 neg 0 V closepath stroke
+  Pnt} def
+/Crs {stroke [] 0 setdash exch hpt sub exch vpt add M
+  hpt2 vpt2 neg V currentpoint stroke M
+  hpt2 neg 0 R hpt2 vpt2 V stroke} def
+/TriU {stroke [] 0 setdash 2 copy vpt 1.12 mul add M
+  hpt neg vpt -1.62 mul V
+  hpt 2 mul 0 V
+  hpt neg vpt 1.62 mul V closepath stroke
+  Pnt} def
+/Star {2 copy Pls Crs} def
+/BoxF {stroke [] 0 setdash exch hpt sub exch vpt add M
+  0 vpt2 neg V hpt2 0 V 0 vpt2 V
+  hpt2 neg 0 V closepath fill} def
+/TriUF {stroke [] 0 setdash vpt 1.12 mul add M
+  hpt neg vpt -1.62 mul V
+  hpt 2 mul 0 V
+  hpt neg vpt 1.62 mul V closepath fill} def
+/TriD {stroke [] 0 setdash 2 copy vpt 1.12 mul sub M
+  hpt neg vpt 1.62 mul V
+  hpt 2 mul 0 V
+  hpt neg vpt -1.62 mul V closepath stroke
+  Pnt} def
+/TriDF {stroke [] 0 setdash vpt 1.12 mul sub M
+  hpt neg vpt 1.62 mul V
+  hpt 2 mul 0 V
+  hpt neg vpt -1.62 mul V closepath fill} def
+/DiaF {stroke [] 0 setdash vpt add M
+  hpt neg vpt neg V hpt vpt neg V
+  hpt vpt V hpt neg vpt V closepath fill} def
+/Pent {stroke [] 0 setdash 2 copy gsave
+  translate 0 hpt M 4 {72 rotate 0 hpt L} repeat
+  closepath stroke grestore Pnt} def
+/PentF {stroke [] 0 setdash gsave
+  translate 0 hpt M 4 {72 rotate 0 hpt L} repeat
+  closepath fill grestore} def
+/Circle {stroke [] 0 setdash 2 copy
+  hpt 0 360 arc stroke Pnt} def
+/CircleF {stroke [] 0 setdash hpt 0 360 arc fill} def
+/C0 {BL [] 0 setdash 2 copy moveto vpt 90 450 arc} bind def
+/C1 {BL [] 0 setdash 2 copy moveto
+	2 copy vpt 0 90 arc closepath fill
+	vpt 0 360 arc closepath} bind def
+/C2 {BL [] 0 setdash 2 copy moveto
+	2 copy vpt 90 180 arc closepath fill
+	vpt 0 360 arc closepath} bind def
+/C3 {BL [] 0 setdash 2 copy moveto
+	2 copy vpt 0 180 arc closepath fill
+	vpt 0 360 arc closepath} bind def
+/C4 {BL [] 0 setdash 2 copy moveto
+	2 copy vpt 180 270 arc closepath fill
+	vpt 0 360 arc closepath} bind def
+/C5 {BL [] 0 setdash 2 copy moveto
+	2 copy vpt 0 90 arc
+	2 copy moveto
+	2 copy vpt 180 270 arc closepath fill
+	vpt 0 360 arc} bind def
+/C6 {BL [] 0 setdash 2 copy moveto
+	2 copy vpt 90 270 arc closepath fill
+	vpt 0 360 arc closepath} bind def
+/C7 {BL [] 0 setdash 2 copy moveto
+	2 copy vpt 0 270 arc closepath fill
+	vpt 0 360 arc closepath} bind def
+/C8 {BL [] 0 setdash 2 copy moveto
+	2 copy vpt 270 360 arc closepath fill
+	vpt 0 360 arc closepath} bind def
+/C9 {BL [] 0 setdash 2 copy moveto
+	2 copy vpt 270 450 arc closepath fill
+	vpt 0 360 arc closepath} bind def
+/C10 {BL [] 0 setdash 2 copy 2 copy moveto vpt 270 360 arc closepath fill
+	2 copy moveto
+	2 copy vpt 90 180 arc closepath fill
+	vpt 0 360 arc closepath} bind def
+/C11 {BL [] 0 setdash 2 copy moveto
+	2 copy vpt 0 180 arc closepath fill
+	2 copy moveto
+	2 copy vpt 270 360 arc closepath fill
+	vpt 0 360 arc closepath} bind def
+/C12 {BL [] 0 setdash 2 copy moveto
+	2 copy vpt 180 360 arc closepath fill
+	vpt 0 360 arc closepath} bind def
+/C13 {BL [] 0 setdash 2 copy moveto
+	2 copy vpt 0 90 arc closepath fill
+	2 copy moveto
+	2 copy vpt 180 360 arc closepath fill
+	vpt 0 360 arc closepath} bind def
+/C14 {BL [] 0 setdash 2 copy moveto
+	2 copy vpt 90 360 arc closepath fill
+	vpt 0 360 arc} bind def
+/C15 {BL [] 0 setdash 2 copy vpt 0 360 arc closepath fill
+	vpt 0 360 arc closepath} bind def
+/Rec {newpath 4 2 roll moveto 1 index 0 rlineto 0 exch rlineto
+	neg 0 rlineto closepath} bind def
+/Square {dup Rec} bind def
+/Bsquare {vpt sub exch vpt sub exch vpt2 Square} bind def
+/S0 {BL [] 0 setdash 2 copy moveto 0 vpt rlineto BL Bsquare} bind def
+/S1 {BL [] 0 setdash 2 copy vpt Square fill Bsquare} bind def
+/S2 {BL [] 0 setdash 2 copy exch vpt sub exch vpt Square fill Bsquare} bind def
+/S3 {BL [] 0 setdash 2 copy exch vpt sub exch vpt2 vpt Rec fill Bsquare} bind def
+/S4 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt Square fill Bsquare} bind def
+/S5 {BL [] 0 setdash 2 copy 2 copy vpt Square fill
+	exch vpt sub exch vpt sub vpt Square fill Bsquare} bind def
+/S6 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt vpt2 Rec fill Bsquare} bind def
+/S7 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt vpt2 Rec fill
+	2 copy vpt Square fill Bsquare} bind def
+/S8 {BL [] 0 setdash 2 copy vpt sub vpt Square fill Bsquare} bind def
+/S9 {BL [] 0 setdash 2 copy vpt sub vpt vpt2 Rec fill Bsquare} bind def
+/S10 {BL [] 0 setdash 2 copy vpt sub vpt Square fill 2 copy exch vpt sub exch vpt Square fill
+	Bsquare} bind def
+/S11 {BL [] 0 setdash 2 copy vpt sub vpt Square fill 2 copy exch vpt sub exch vpt2 vpt Rec fill
+	Bsquare} bind def
+/S12 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt2 vpt Rec fill Bsquare} bind def
+/S13 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt2 vpt Rec fill
+	2 copy vpt Square fill Bsquare} bind def
+/S14 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt2 vpt Rec fill
+	2 copy exch vpt sub exch vpt Square fill Bsquare} bind def
+/S15 {BL [] 0 setdash 2 copy Bsquare fill Bsquare} bind def
+/D0 {gsave translate 45 rotate 0 0 S0 stroke grestore} bind def
+/D1 {gsave translate 45 rotate 0 0 S1 stroke grestore} bind def
+/D2 {gsave translate 45 rotate 0 0 S2 stroke grestore} bind def
+/D3 {gsave translate 45 rotate 0 0 S3 stroke grestore} bind def
+/D4 {gsave translate 45 rotate 0 0 S4 stroke grestore} bind def
+/D5 {gsave translate 45 rotate 0 0 S5 stroke grestore} bind def
+/D6 {gsave translate 45 rotate 0 0 S6 stroke grestore} bind def
+/D7 {gsave translate 45 rotate 0 0 S7 stroke grestore} bind def
+/D8 {gsave translate 45 rotate 0 0 S8 stroke grestore} bind def
+/D9 {gsave translate 45 rotate 0 0 S9 stroke grestore} bind def
+/D10 {gsave translate 45 rotate 0 0 S10 stroke grestore} bind def
+/D11 {gsave translate 45 rotate 0 0 S11 stroke grestore} bind def
+/D12 {gsave translate 45 rotate 0 0 S12 stroke grestore} bind def
+/D13 {gsave translate 45 rotate 0 0 S13 stroke grestore} bind def
+/D14 {gsave translate 45 rotate 0 0 S14 stroke grestore} bind def
+/D15 {gsave translate 45 rotate 0 0 S15 stroke grestore} bind def
+/DiaE {stroke [] 0 setdash vpt add M
+  hpt neg vpt neg V hpt vpt neg V
+  hpt vpt V hpt neg vpt V closepath stroke} def
+/BoxE {stroke [] 0 setdash exch hpt sub exch vpt add M
+  0 vpt2 neg V hpt2 0 V 0 vpt2 V
+  hpt2 neg 0 V closepath stroke} def
+/TriUE {stroke [] 0 setdash vpt 1.12 mul add M
+  hpt neg vpt -1.62 mul V
+  hpt 2 mul 0 V
+  hpt neg vpt 1.62 mul V closepath stroke} def
+/TriDE {stroke [] 0 setdash vpt 1.12 mul sub M
+  hpt neg vpt 1.62 mul V
+  hpt 2 mul 0 V
+  hpt neg vpt -1.62 mul V closepath stroke} def
+/PentE {stroke [] 0 setdash gsave
+  translate 0 hpt M 4 {72 rotate 0 hpt L} repeat
+  closepath stroke grestore} def
+/CircE {stroke [] 0 setdash 
+  hpt 0 360 arc stroke} def
+/Opaque {gsave closepath 1 setgray fill grestore 0 setgray closepath} def
+/DiaW {stroke [] 0 setdash vpt add M
+  hpt neg vpt neg V hpt vpt neg V
+  hpt vpt V hpt neg vpt V Opaque stroke} def
+/BoxW {stroke [] 0 setdash exch hpt sub exch vpt add M
+  0 vpt2 neg V hpt2 0 V 0 vpt2 V
+  hpt2 neg 0 V Opaque stroke} def
+/TriUW {stroke [] 0 setdash vpt 1.12 mul add M
+  hpt neg vpt -1.62 mul V
+  hpt 2 mul 0 V
+  hpt neg vpt 1.62 mul V Opaque stroke} def
+/TriDW {stroke [] 0 setdash vpt 1.12 mul sub M
+  hpt neg vpt 1.62 mul V
+  hpt 2 mul 0 V
+  hpt neg vpt -1.62 mul V Opaque stroke} def
+/PentW {stroke [] 0 setdash gsave
+  translate 0 hpt M 4 {72 rotate 0 hpt L} repeat
+  Opaque stroke grestore} def
+/CircW {stroke [] 0 setdash 
+  hpt 0 360 arc Opaque stroke} def
+/BoxFill {gsave Rec 1 setgray fill grestore} def
+/Density {
+  /Fillden exch def
+  currentrgbcolor
+  /ColB exch def /ColG exch def /ColR exch def
+  /ColR ColR Fillden mul Fillden sub 1 add def
+  /ColG ColG Fillden mul Fillden sub 1 add def
+  /ColB ColB Fillden mul Fillden sub 1 add def
+  ColR ColG ColB setrgbcolor} def
+/BoxColFill {gsave Rec PolyFill} def
+/PolyFill {gsave Density fill grestore grestore} def
+/h {rlineto rlineto rlineto gsave closepath fill grestore} bind def
+%
+% PostScript Level 1 Pattern Fill routine for rectangles
+% Usage: x y w h s a XX PatternFill
+%	x,y = lower left corner of box to be filled
+%	w,h = width and height of box
+%	  a = angle in degrees between lines and x-axis
+%	 XX = 0/1 for no/yes cross-hatch
+%
+/PatternFill {gsave /PFa [ 9 2 roll ] def
+  PFa 0 get PFa 2 get 2 div add PFa 1 get PFa 3 get 2 div add translate
+  PFa 2 get -2 div PFa 3 get -2 div PFa 2 get PFa 3 get Rec
+  gsave 1 setgray fill grestore clip
+  currentlinewidth 0.5 mul setlinewidth
+  /PFs PFa 2 get dup mul PFa 3 get dup mul add sqrt def
+  0 0 M PFa 5 get rotate PFs -2 div dup translate
+  0 1 PFs PFa 4 get div 1 add floor cvi
+	{PFa 4 get mul 0 M 0 PFs V} for
+  0 PFa 6 get ne {
+	0 1 PFs PFa 4 get div 1 add floor cvi
+	{PFa 4 get mul 0 2 1 roll M PFs 0 V} for
+ } if
+  stroke grestore} def
+%
+/languagelevel where
+ {pop languagelevel} {1} ifelse
+ 2 lt
+	{/InterpretLevel1 true def}
+	{/InterpretLevel1 Level1 def}
+ ifelse
+%
+% PostScript level 2 pattern fill definitions
+%
+/Level2PatternFill {
+/Tile8x8 {/PaintType 2 /PatternType 1 /TilingType 1 /BBox [0 0 8 8] /XStep 8 /YStep 8}
+	bind def
+/KeepColor {currentrgbcolor [/Pattern /DeviceRGB] setcolorspace} bind def
+<< Tile8x8
+ /PaintProc {0.5 setlinewidth pop 0 0 M 8 8 L 0 8 M 8 0 L stroke} 
+>> matrix makepattern
+/Pat1 exch def
+<< Tile8x8
+ /PaintProc {0.5 setlinewidth pop 0 0 M 8 8 L 0 8 M 8 0 L stroke
+	0 4 M 4 8 L 8 4 L 4 0 L 0 4 L stroke}
+>> matrix makepattern
+/Pat2 exch def
+<< Tile8x8
+ /PaintProc {0.5 setlinewidth pop 0 0 M 0 8 L
+	8 8 L 8 0 L 0 0 L fill}
+>> matrix makepattern
+/Pat3 exch def
+<< Tile8x8
+ /PaintProc {0.5 setlinewidth pop -4 8 M 8 -4 L
+	0 12 M 12 0 L stroke}
+>> matrix makepattern
+/Pat4 exch def
+<< Tile8x8
+ /PaintProc {0.5 setlinewidth pop -4 0 M 8 12 L
+	0 -4 M 12 8 L stroke}
+>> matrix makepattern
+/Pat5 exch def
+<< Tile8x8
+ /PaintProc {0.5 setlinewidth pop -2 8 M 4 -4 L
+	0 12 M 8 -4 L 4 12 M 10 0 L stroke}
+>> matrix makepattern
+/Pat6 exch def
+<< Tile8x8
+ /PaintProc {0.5 setlinewidth pop -2 0 M 4 12 L
+	0 -4 M 8 12 L 4 -4 M 10 8 L stroke}
+>> matrix makepattern
+/Pat7 exch def
+<< Tile8x8
+ /PaintProc {0.5 setlinewidth pop 8 -2 M -4 4 L
+	12 0 M -4 8 L 12 4 M 0 10 L stroke}
+>> matrix makepattern
+/Pat8 exch def
+<< Tile8x8
+ /PaintProc {0.5 setlinewidth pop 0 -2 M 12 4 L
+	-4 0 M 12 8 L -4 4 M 8 10 L stroke}
+>> matrix makepattern
+/Pat9 exch def
+/Pattern1 {PatternBgnd KeepColor Pat1 setpattern} bind def
+/Pattern2 {PatternBgnd KeepColor Pat2 setpattern} bind def
+/Pattern3 {PatternBgnd KeepColor Pat3 setpattern} bind def
+/Pattern4 {PatternBgnd KeepColor Landscape {Pat5} {Pat4} ifelse setpattern} bind def
+/Pattern5 {PatternBgnd KeepColor Landscape {Pat4} {Pat5} ifelse setpattern} bind def
+/Pattern6 {PatternBgnd KeepColor Landscape {Pat9} {Pat6} ifelse setpattern} bind def
+/Pattern7 {PatternBgnd KeepColor Landscape {Pat8} {Pat7} ifelse setpattern} bind def
+} def
+%
+%
+%End of PostScript Level 2 code
+%
+/PatternBgnd {
+  TransparentPatterns {} {gsave 1 setgray fill grestore} ifelse
+} def
+%
+% Substitute for Level 2 pattern fill codes with
+% grayscale if Level 2 support is not selected.
+%
+/Level1PatternFill {
+/Pattern1 {0.250 Density} bind def
+/Pattern2 {0.500 Density} bind def
+/Pattern3 {0.750 Density} bind def
+/Pattern4 {0.125 Density} bind def
+/Pattern5 {0.375 Density} bind def
+/Pattern6 {0.625 Density} bind def
+/Pattern7 {0.875 Density} bind def
+} def
+%
+% Now test for support of Level 2 code
+%
+Level1 {Level1PatternFill} {Level2PatternFill} ifelse
+%
+/Symbol-Oblique /Symbol findfont [1 0 .167 1 0 0] makefont
+dup length dict begin {1 index /FID eq {pop pop} {def} ifelse} forall
+currentdict end definefont pop
+end
+gnudict begin
+gsave
+doclip
+50 50 translate
+0.050 0.050 scale
+0 setgray
+newpath
+(Helvetica) findfont 360 scalefont setfont
+1.000 UL
+LTb
+1.000 UL
+LTa
+1980 13355 M
+11591 0 V
+stroke
+LTb
+1980 13355 M
+63 0 V
+11528 0 R
+-63 0 V
+-11744 0 R
+( 3400) Rshow
+1.000 UL
+LTb
+1.000 UL
+LTa
+1980 11037 M
+11591 0 V
+stroke
+LTb
+1980 11037 M
+63 0 V
+11528 0 R
+-63 0 V
+-11744 0 R
+( 3600) Rshow
+1.000 UL
+LTb
+1.000 UL
+LTa
+1980 8719 M
+11591 0 V
+stroke
+LTb
+1980 8719 M
+63 0 V
+11528 0 R
+-63 0 V
+-11744 0 R
+( 3800) Rshow
+1.000 UL
+LTb
+1.000 UL
+LTa
+1980 6400 M
+11591 0 V
+stroke
+LTb
+1980 6400 M
+63 0 V
+11528 0 R
+-63 0 V
+-11744 0 R
+( 4000) Rshow
+1.000 UL
+LTb
+1.000 UL
+LTa
+1980 4082 M
+11591 0 V
+stroke
+LTb
+1980 4082 M
+63 0 V
+11528 0 R
+-63 0 V
+-11744 0 R
+( 4200) Rshow
+1.000 UL
+LTb
+1.000 UL
+LTa
+1980 1764 M
+11591 0 V
+stroke
+LTb
+1980 1764 M
+63 0 V
+11528 0 R
+-63 0 V
+-11744 0 R
+( 4400) Rshow
+1.000 UL
+LTb
+1.000 UL
+LTa
+1980 1764 M
+0 11591 V
+stroke
+LTb
+1980 1764 M
+0 63 V
+0 11528 R
+0 -63 V
+0 -11888 R
+(-90) Cshow
+1.000 UL
+LTb
+1.000 UL
+LTa
+3912 1764 M
+0 11591 V
+stroke
+LTb
+3912 1764 M
+0 63 V
+0 11528 R
+0 -63 V
+0 -11888 R
+(-85) Cshow
+1.000 UL
+LTb
+1.000 UL
+LTa
+5844 1764 M
+0 10088 V
+0 1440 R
+0 63 V
+stroke
+LTb
+5844 1764 M
+0 63 V
+0 11528 R
+0 -63 V
+0 -11888 R
+(-80) Cshow
+1.000 UL
+LTb
+1.000 UL
+LTa
+7776 1764 M
+0 10088 V
+0 1440 R
+0 63 V
+stroke
+LTb
+7776 1764 M
+0 63 V
+0 11528 R
+0 -63 V
+0 -11888 R
+(-75) Cshow
+1.000 UL
+LTb
+1.000 UL
+LTa
+9707 1764 M
+0 10088 V
+0 1440 R
+0 63 V
+stroke
+LTb
+9707 1764 M
+0 63 V
+0 11528 R
+0 -63 V
+0 -11888 R
+(-70) Cshow
+1.000 UL
+LTb
+1.000 UL
+LTa
+11639 1764 M
+0 10088 V
+0 1440 R
+0 63 V
+stroke
+LTb
+11639 1764 M
+0 63 V
+0 11528 R
+0 -63 V
+0 -11888 R
+(-65) Cshow
+1.000 UL
+LTb
+1.000 UL
+LTa
+13571 1764 M
+0 11591 V
+stroke
+LTb
+13571 1764 M
+0 63 V
+0 11528 R
+0 -63 V
+0 -11888 R
+(-60) Cshow
+1.000 UL
+LTb
+1.000 UL
+LTb
+1980 13355 N
+0 -11591 V
+11591 0 V
+0 11591 V
+-11591 0 V
+Z stroke
+LCb setrgbcolor
+288 7559 M
+currentpoint gsave translate -270 rotate 0 0 M
+(Depth [m]) Cshow
+grestore
+LTb
+LCb setrgbcolor
+13930 7559 M
+currentpoint gsave translate -270 rotate 0 0 M
+() Cshow
+grestore
+LTb
+LCb setrgbcolor
+7775 864 M
+(Sv [dB]) Cshow
+LTb
+7775 13175 M
+() Cshow
+LCb setrgbcolor
+7775 13174 M
+() Cshow
+LTb
+468 792 M
+() Lshow
+1.000 UP
+1.000 UL
+LTb
+% Begin plot #1
+4.000 UL
+LT2
+LCb setrgbcolor
+11996 13112 M
+(vertical path) Rshow
+LT2
+12212 13112 M
+927 0 V
+1980 6968 M
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+% End plot #1
+% Begin plot #2
+stroke
+LT1
+LCb setrgbcolor
+11996 12752 M
+(along outer main-beam edge) Rshow
+LT1
+12212 12752 M
+927 0 V
+1980 5660 M
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+% End plot #2
+% Begin plot #3
+stroke
+LT4
+LCb setrgbcolor
+11996 12392 M
+(beam center, finite pulse length) Rshow
+LT4
+12212 12392 M
+927 0 V
+1980 6540 M
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+118 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+117 0 V
+% End plot #3
+% Begin plot #4
+stroke
+1.000 UL
+LT0
+LCb setrgbcolor
+11996 12032 M
+(Backscatter Coefficient) Rshow
+LT0
+12212 12032 M
+927 0 V
+5585 13355 M
+-10 -1 V
+1249 -10 V
+-1129 -14 V
+127 -10 V
+-163 -12 V
+224 -12 V
+182 -10 V
+262 -12 V
+-345 -12 V
+192 -12 V
+-325 -13 V
+-168 -11 V
+495 -11 V
+-589 -11 V
+519 -12 V
+-255 -11 V
+870 -12 V
+-881 -13 V
+168 -12 V
+-466 -10 V
+417 -11 V
+-561 -13 V
+580 -11 V
+64 -11 V
+-356 -12 V
+263 -11 V
+379 -13 V
+-1104 -11 V
+-333 -11 V
+355 -12 V
+691 -10 V
+-212 -12 V
+19 -12 V
+1007 -13 V
+-1284 -11 V
+128 -12 V
+591 -11 V
+-780 -11 V
+-114 -11 V
+495 -13 V
+-1221 -11 V
+1777 -12 V
+-919 -12 V
+599 -12 V
+126 -11 V
+-341 -11 V
+-558 -10 V
+469 -13 V
+55 -12 V
+780 -12 V
+-779 -11 V
+275 -12 V
+-89 -12 V
+-806 -12 V
+-176 -11 V
+1484 -11 V
+-1356 -12 V
+1467 -12 V
+-542 -12 V
+-383 -12 V
+439 -10 V
+-119 -12 V
+-398 -11 V
+292 -12 V
+-293 -11 V
+869 -12 V
+-14 -11 V
+-315 -13 V
+-382 -11 V
+969 -13 V
+-1062 -10 V
+922 -13 V
+-716 -11 V
+941 -11 V
+-701 -11 V
+-46 -13 V
+-505 -12 V
+1252 -12 V
+-694 -9 V
+-42 -13 V
+-484 -11 V
+355 -12 V
+380 -12 V
+118 -11 V
+-918 -12 V
+1006 -11 V
+-907 -12 V
+545 -12 V
+557 -10 V
+-618 -12 V
+-315 -12 V
+435 -11 V
+-306 -14 V
+-54 -10 V
+-122 -12 V
+468 -12 V
+-323 -11 V
+724 -12 V
+-907 -11 V
+-466 -10 V
+1199 -13 V
+-314 -11 V
+stroke 6099 12184 M
+352 -11 V
+-253 -13 V
+-11 -11 V
+-301 -12 V
+631 -12 V
+-1708 -11 V
+788 -13 V
+706 -10 V
+-240 -12 V
+156 -13 V
+81 -12 V
+-696 -10 V
+667 -12 V
+-431 -11 V
+196 -12 V
+-292 -10 V
+117 -12 V
+263 -12 V
+-269 -14 V
+-303 -10 V
+712 -12 V
+-562 -11 V
+914 -13 V
+-530 -9 V
+316 -13 V
+-373 -10 V
+-407 -13 V
+677 -11 V
+-729 -11 V
+50 -13 V
+716 -12 V
+-224 -11 V
+-623 -12 V
+876 -9 V
+-944 -13 V
+243 -12 V
+145 -12 V
+-515 -12 V
+654 -11 V
+-490 -11 V
+242 -13 V
+-562 -10 V
+134 -13 V
+722 -11 V
+-461 -11 V
+-493 -12 V
+1467 -12 V
+-451 -10 V
+-360 -14 V
+246 -10 V
+-107 -11 V
+282 -11 V
+-515 -12 V
+-60 -13 V
+266 -12 V
+538 -10 V
+-269 -13 V
+-380 -10 V
+341 -12 V
+92 -12 V
+-473 -12 V
+-353 -13 V
+353 -10 V
+-38 -10 V
+-19 -14 V
+-517 -10 V
+935 -12 V
+-505 -12 V
+-735 -12 V
+514 -12 V
+-87 -10 V
+404 -13 V
+223 -12 V
+-912 -9 V
+-331 -14 V
+-281 -10 V
+372 -12 V
+140 -13 V
+722 -11 V
+-1011 -11 V
+1366 -13 V
+-742 -9 V
+-527 -15 V
+64 -10 V
+314 -11 V
+-80 -12 V
+642 -12 V
+-952 -11 V
+493 -11 V
+235 -11 V
+-10 -14 V
+-625 -10 V
+359 -11 V
+385 -12 V
+461 -11 V
+-936 -13 V
+1256 -11 V
+-308 -11 V
+-295 -14 V
+-337 -9 V
+647 -12 V
+-230 -11 V
+403 -12 V
+-750 -13 V
+stroke 5364 10977 M
+-83 -11 V
+1153 -11 V
+-864 -14 V
+193 -9 V
+246 -12 V
+-243 -11 V
+162 -13 V
+-361 -11 V
+-110 -11 V
+604 -13 V
+11 -12 V
+-209 -10 V
+-75 -11 V
+724 -13 V
+-381 -12 V
+-512 -11 V
+108 -11 V
+-30 -12 V
+-300 -13 V
+965 -9 V
+-973 -11 V
+569 -12 V
+-226 -13 V
+-438 -12 V
+157 -12 V
+377 -12 V
+-393 -11 V
+1113 -11 V
+-523 -11 V
+218 -12 V
+-414 -11 V
+-80 -13 V
+-86 -10 V
+278 -13 V
+-101 -12 V
+609 -11 V
+-482 -11 V
+664 -11 V
+-644 -13 V
+682 -11 V
+-111 -12 V
+-123 -12 V
+-134 -11 V
+235 -12 V
+207 -11 V
+-394 -12 V
+-927 -10 V
+1052 -13 V
+196 -12 V
+-257 -12 V
+-200 -10 V
+647 -13 V
+-282 -10 V
+-537 -12 V
+-341 -13 V
+865 -11 V
+-14 -11 V
+-518 -11 V
+-314 -12 V
+218 -12 V
+977 -11 V
+-487 -11 V
+-270 -12 V
+411 -12 V
+-767 -12 V
+219 -12 V
+-202 -10 V
+489 -13 V
+993 -12 V
+-410 -10 V
+-980 -11 V
+-33 -14 V
+730 -10 V
+-840 -12 V
+1242 -11 V
+-1128 -13 V
+647 -10 V
+-512 -12 V
+-251 -11 V
+980 -13 V
+499 -11 V
+-699 -11 V
+177 -11 V
+196 -13 V
+535 -11 V
+-661 -12 V
+-372 -12 V
+694 -11 V
+259 -12 V
+6064 9935 L
+519 -11 V
+145 -13 V
+-291 -11 V
+1017 -11 V
+6253 9877 L
+598 -12 V
+1162 -12 V
+6139 9843 L
+1556 -12 V
+5777 9818 L
+143 -11 V
+2108 -11 V
+6799 9784 L
+49 -11 V
+1080 -12 V
+6699 9750 L
+652 -13 V
+-165 -11 V
+-940 -11 V
+996 -11 V
+-489 -13 V
+660 -10 V
+6388 9667 L
+-175 -10 V
+518 -12 V
+180 -13 V
+-773 -9 V
+-744 -13 V
+896 -11 V
+232 -12 V
+3 -13 V
+214 -10 V
+-271 -13 V
+521 -11 V
+-710 -11 V
+-165 -12 V
+1325 -12 V
+6179 9494 L
+-232 -11 V
+609 -12 V
+-11 -12 V
+223 -10 V
+-71 -13 V
+-308 -12 V
+1464 -12 V
+5875 9401 L
+535 -11 V
+-325 -11 V
+5025 9366 L
+953 -11 V
+321 -12 V
+5013 9332 L
+1446 -13 V
+-720 -9 V
+230 -13 V
+515 -12 V
+-617 -11 V
+-549 -12 V
+881 -12 V
+-905 -11 V
+598 -10 V
+-184 -14 V
+964 -12 V
+-877 -9 V
+498 -13 V
+29 -11 V
+-16 -14 V
+-562 -9 V
+924 -12 V
+-33 -10 V
+-440 -14 V
+198 -10 V
+-373 -14 V
+1730 -11 V
+-832 -13 V
+-228 -10 V
+206 -11 V
+-86 -11 V
+180 -13 V
+-392 -11 V
+-25 -12 V
+-382 -10 V
+359 -13 V
+-381 -12 V
+-344 -11 V
+1210 -11 V
+-430 -11 V
+26 -12 V
+165 -13 V
+-1 -10 V
+343 -13 V
+-668 -10 V
+-536 -13 V
+768 -11 V
+20 -11 V
+-141 -13 V
+-159 -11 V
+113 -10 V
+194 -12 V
+-68 -12 V
+-140 -13 V
+-282 -11 V
+384 -11 V
+615 -12 V
+-558 -11 V
+269 -11 V
+234 -13 V
+-446 -11 V
+-22 -13 V
+-363 -10 V
+93 -13 V
+952 -11 V
+6347 8625 L
+-46 -12 V
+196 -12 V
+237 -11 V
+-484 -13 V
+441 -9 V
+63 -13 V
+231 -12 V
+-813 -11 V
+1086 -11 V
+-449 -12 V
+25 -11 V
+31 -13 V
+-153 -11 V
+156 -9 V
+-849 -14 V
+427 -12 V
+801 -11 V
+-959 -12 V
+318 -11 V
+56 -12 V
+682 -10 V
+6272 8370 L
+-134 -12 V
+1203 -12 V
+6050 8335 L
+666 -12 V
+-627 -11 V
+378 -12 V
+-298 -11 V
+-137 -13 V
+351 -11 V
+156 -11 V
+244 -11 V
+5472 8232 L
+830 -14 V
+543 -11 V
+53 -11 V
+-72 -12 V
+-804 -13 V
+942 -10 V
+202 -12 V
+-496 -11 V
+-497 -12 V
+291 -11 V
+-74 -12 V
+-213 -12 V
+-322 -11 V
+122 -11 V
+-65 -12 V
+186 -11 V
+-129 -14 V
+877 -11 V
+-857 -11 V
+209 -11 V
+-349 -10 V
+196 -12 V
+-543 -13 V
+-123 -11 V
+779 -13 V
+4809 7928 L
+245 -10 V
+-219 -11 V
+-98 -12 V
+478 -11 V
+180 -12 V
+219 -12 V
+850 -12 V
+5057 7837 L
+-124 -11 V
+-31 -13 V
+558 -11 V
+-453 -11 V
+1011 -12 V
+-576 -13 V
+398 -11 V
+-492 -12 V
+88 -11 V
+671 -10 V
+-801 -11 V
+-75 -13 V
+124 -12 V
+-398 -12 V
+867 -10 V
+-408 -13 V
+-29 -12 V
+489 -11 V
+-579 -11 V
+-40 -12 V
+72 -12 V
+957 -12 V
+-940 -10 V
+441 -13 V
+-425 -12 V
+-119 -11 V
+188 -11 V
+-86 -12 V
+-394 -12 V
+536 -11 V
+-254 -11 V
+1127 -13 V
+-469 -11 V
+-44 -11 V
+-390 -11 V
+319 -13 V
+-24 -12 V
+-186 -11 V
+195 -12 V
+370 -11 V
+-791 -13 V
+945 -11 V
+-272 -11 V
+45 -11 V
+-18 -12 V
+-31 -13 V
+245 -11 V
+-202 -12 V
+399 -11 V
+-127 -11 V
+338 -11 V
+-209 -12 V
+-126 -12 V
+-976 -12 V
+1294 -11 V
+-853 -12 V
+869 -13 V
+-306 -9 V
+-282 -12 V
+530 -12 V
+-680 -11 V
+419 -12 V
+608 -13 V
+5652 7094 L
+836 -10 V
+331 -11 V
+5 -13 V
+225 -12 V
+-723 -11 V
+772 -11 V
+-20 -12 V
+-703 -11 V
+319 -12 V
+154 -12 V
+-67 -12 V
+-44 -11 V
+449 -13 V
+-379 -11 V
+701 -11 V
+-885 -11 V
+349 -12 V
+690 -13 V
+-115 -10 V
+-477 -11 V
+642 -13 V
+-762 -10 V
+-692 -12 V
+1884 -11 V
+6536 6805 L
+694 -11 V
+1530 -13 V
+7072 6771 L
+1514 -13 V
+7027 6748 L
+1178 -12 V
+-698 -10 V
+-745 -14 V
+1323 -10 V
+1202 -13 V
+8221 6678 L
+7055 6665 L
+793 -10 V
+1853 -12 V
+569 -11 V
+8247 6619 L
+1144 -12 V
+1277 -11 V
+7918 6585 L
+526 -12 V
+1471 -10 V
+667 -13 V
+1402 -12 V
+9490 6526 L
+-229 -11 V
+2649 -12 V
+9542 6492 L
+-603 -11 V
+675 -12 V
+-708 -12 V
+936 -12 V
+157 -11 V
+-720 -12 V
+167 -12 V
+8235 6399 L
+-770 -12 V
+922 -11 V
+112 -13 V
+673 -9 V
+7406 6340 L
+642 -11 V
+1604 -11 V
+333 -12 V
+8183 6296 L
+-156 -13 V
+-279 -13 V
+452 -9 V
+6557 6249 L
+1226 -12 V
+549 -11 V
+-148 -13 V
+-650 -10 V
+266 -14 V
+6746 6179 L
+1118 -12 V
+-235 -10 V
+6585 6145 L
+121 -13 V
+694 -10 V
+-805 -11 V
+-941 -14 V
+1650 -10 V
+6038 6075 L
+628 -10 V
+58 -12 V
+-148 -12 V
+5332 6029 L
+791 -12 V
+-454 -12 V
+-83 -10 V
+469 -12 V
+-252 -12 V
+36 -12 V
+185 -11 V
+955 -13 V
+-576 -11 V
+-799 -11 V
+-169 -11 V
+574 -12 V
+52 -12 V
+-13 -12 V
+-117 -11 V
+353 -12 V
+362 -12 V
+-545 -11 V
+21 -11 V
+328 -12 V
+-730 -12 V
+771 -12 V
+19 -13 V
+-145 -10 V
+-470 -13 V
+-378 -9 V
+486 -12 V
+-32 -13 V
+-148 -12 V
+262 -11 V
+-389 -10 V
+-396 -12 V
+85 -13 V
+-271 -10 V
+759 -12 V
+-326 -13 V
+-9 -11 V
+-308 -11 V
+-122 -12 V
+610 -11 V
+-8 -13 V
+-260 -10 V
+-358 -12 V
+143 -14 V
+47 -11 V
+248 -11 V
+-355 -11 V
+-151 -10 V
+517 -14 V
+148 -9 V
+-466 -13 V
+-34 -12 V
+486 -13 V
+94 -8 V
+-134 -12 V
+28 -12 V
+-921 -13 V
+391 -9 V
+224 -14 V
+404 -11 V
+-790 -13 V
+492 -9 V
+-376 -13 V
+-90 -11 V
+166 -13 V
+41 -10 V
+-29 -12 V
+877 -10 V
+-563 -13 V
+-434 -10 V
+-286 -14 V
+-73 -11 V
+74 -15 V
+348 -7 V
+-283 -13 V
+782 -10 V
+-621 -14 V
+1174 -10 V
+-436 -12 V
+4734 5103 L
+726 -14 V
+-516 -11 V
+-310 -13 V
+885 -10 V
+-408 -12 V
+369 -11 V
+-91 -12 V
+-371 -11 V
+-73 -12 V
+678 -12 V
+-610 -12 V
+45 -9 V
+-16 -14 V
+310 -11 V
+-406 -13 V
+810 -10 V
+-850 -12 V
+388 -11 V
+-87 -10 V
+-368 -13 V
+624 -13 V
+-681 -12 V
+540 -11 V
+-191 -9 V
+-256 -13 V
+383 -11 V
+141 -12 V
+25 -13 V
+297 -12 V
+-161 -11 V
+-284 -12 V
+-237 -11 V
+-325 -12 V
+667 -11 V
+-779 -11 V
+780 -12 V
+32 -11 V
+-508 -13 V
+332 -10 V
+112 -12 V
+720 -12 V
+-954 -11 V
+-397 -12 V
+672 -12 V
+-477 -11 V
+49 -13 V
+-149 -8 V
+146 -13 V
+-117 -12 V
+3751 4521 L
+-356 -12 V
+2042 -10 V
+4431 4489 L
+700 -14 V
+-187 -11 V
+23 -12 V
+-20 -11 V
+-793 -13 V
+-303 -12 V
+516 -9 V
+377 -13 V
+-16 -13 V
+281 -8 V
+-180 -15 V
+-208 -11 V
+-384 -12 V
+-74 -11 V
+600 -10 V
+408 -12 V
+-503 -14 V
+155 -8 V
+162 -15 V
+-291 -10 V
+226 -12 V
+-198 -12 V
+-2 -10 V
+529 -12 V
+-937 -13 V
+372 -10 V
+52 -14 V
+9 -11 V
+-8 -10 V
+-277 -10 V
+134 -12 V
+-118 -12 V
+315 -12 V
+856 -12 V
+4316 4079 L
+333 -9 V
+514 -11 V
+-420 -12 V
+179 -12 V
+1 -11 V
+49 -12 V
+109 -11 V
+-776 -11 V
+899 -12 V
+-265 -12 V
+-15 -12 V
+315 -12 V
+-609 -12 V
+878 -11 V
+-653 -12 V
+-545 -10 V
+415 -12 V
+530 -13 V
+-296 -11 V
+527 -12 V
+-644 -12 V
+407 -11 V
+-594 -13 V
+218 -10 V
+202 -12 V
+279 -12 V
+-317 -11 V
+615 -13 V
+-604 -11 V
+1204 -11 V
+-619 -13 V
+-822 -10 V
+109 -12 V
+184 -11 V
+402 -12 V
+-131 -11 V
+192 -11 V
+282 -11 V
+4560 3629 L
+682 -10 V
+-1 -13 V
+170 -12 V
+-133 -12 V
+394 -12 V
+370 -10 V
+4882 3549 L
+-376 -13 V
+666 -11 V
+665 -12 V
+-280 -11 V
+-81 -12 V
+160 -11 V
+577 -11 V
+4712 3456 L
+181 -13 V
+630 -9 V
+-409 -15 V
+-431 -10 V
+1486 -12 V
+20 -11 V
+936 -11 V
+5766 3364 L
+-794 -13 V
+962 -12 V
+3 -12 V
+-759 -10 V
+729 -14 V
+436 -9 V
+4599 3281 L
+1675 -11 V
+-715 -10 V
+-564 -13 V
+-84 -13 V
+-83 -11 V
+766 -13 V
+-83 -10 V
+4460 3189 L
+1019 -14 V
+-715 -9 V
+-92 -12 V
+32 -13 V
+-134 -12 V
+-29 -11 V
+469 -10 V
+3780 3097 L
+949 -14 V
+-486 -10 V
+258 -13 V
+471 -11 V
+-358 -12 V
+-81 -10 V
+995 -12 V
+4254 3004 L
+-27 -13 V
+22 -11 V
+-57 -12 V
+747 -12 V
+209 -11 V
+-707 -10 V
+590 -12 V
+-418 -12 V
+-280 -12 V
+621 -11 V
+-230 -12 V
+-59 -10 V
+118 -13 V
+-431 -10 V
+424 -13 V
+-323 -13 V
+88 -11 V
+724 -11 V
+-542 -12 V
+27 -11 V
+210 -12 V
+-347 -11 V
+579 -13 V
+-634 -13 V
+-110 -11 V
+1720 -10 V
+4821 2689 L
+-143 -10 V
+21 -11 V
+16 -12 V
+-62 -13 V
+497 -11 V
+-156 -11 V
+184 -11 V
+172 -12 V
+-485 -12 V
+-271 -12 V
+191 -12 V
+-746 -12 V
+762 -11 V
+-111 -12 V
+198 -10 V
+-7 -12 V
+-447 -12 V
+430 -12 V
+0 -13 V
+355 -10 V
+-677 -12 V
+246 -10 V
+-321 -11 V
+-66 -14 V
+199 -12 V
+605 -12 V
+-694 -11 V
+332 -10 V
+24 -12 V
+-35 -12 V
+-101 -12 V
+-265 -11 V
+206 -12 V
+361 -11 V
+-300 -12 V
+756 -9 V
+-792 -12 V
+2 -13 V
+-185 -11 V
+-374 -13 V
+806 -11 V
+-936 -10 V
+-128 -13 V
+422 -11 V
+795 -12 V
+-179 -11 V
+12 -13 V
+-886 -12 V
+44 -11 V
+-590 -10 V
+523 -13 V
+861 -11 V
+-861 -11 V
+463 -13 V
+-86 -11 V
+-151 -12 V
+79 -10 V
+-666 -13 V
+55 -12 V
+1397 -10 V
+4031 1983 L
+615 -12 V
+-474 -12 V
+825 -12 V
+-99 -9 V
+-99 -13 V
+-533 -12 V
+1429 -12 V
+4674 1889 L
+150 -10 V
+-354 -12 V
+416 -12 V
+76 -10 V
+485 -13 V
+3921 1820 L
+1953 -11 V
+-726 -10 V
+-199 -12 V
+291 -12 V
+-473 -11 V
+% End plot #4
+stroke
+LTb
+1980 13355 N
+0 -11591 V
+11591 0 V
+0 11591 V
+-11591 0 V
+Z stroke
+1.000 UP
+1.000 UL
+LTb
+stroke
+grestore
+end
+showpage
+%%Trailer
+cleartomark countdictstack exch sub { end } repeat restore
+%%EOF
--- a/defaults.pl	Tue May 20 09:08:43 2014 +0000
+++ b/defaults.pl	Wed Jul 09 15:19:27 2014 -0400
@@ -1,9 +1,9 @@
 #======================================================================
 #                    D E F A U L T S . P L 
 #                    doc: Tue Oct 11 17:11:21 2011
-#                    dlm: Thu Sep  5 22:46:45 2013
+#                    dlm: Wed May 21 12:59:09 2014
 #                    (c) 2011 A.M. Thurnherr
-#                    uE-Info: 37 55 NIL 0 0 72 0 2 4 NIL ofnI
+#                    uE-Info: 233 0 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -23,7 +23,6 @@
 #	Oct 27, 2011: - modified ProcessingParam file loading
 #				  - added ${pitch,roll,heading}_bias
 #	Oct 11, 2012: - added .TL output to defaults
-#--- hg commit
 #	Oct 15, 2012: - removed support for TLhist
 #	Apr 22, 2013: - removed option variable aliases
 #	May 14, 2013: - opt_m => w_max_lim
@@ -35,6 +34,8 @@
 #	Jun  5, 2013: - made ProcessingParams (without .profiles) default file
 #	Sep  5, 2013: - also allow ProcessingParams.default
 #				  - added LWplot_spec to default output
+#	May 20, 2014: - added support for $PPI_editing
+#	May 21, 2014: - added $PPI_extend_upper_limit
 
 # Variable Names:
 #	- variables that are only used in a particular library are
@@ -213,6 +214,23 @@
 
 $surface_layer_depth = 25;
 
+
+# PPI editing as described in [edit_data.pl]
+#	- enabled by default for WH150 data
+#	- 2014 CLIVAR P16 #47 has a slight discontinuity at 4000m; this
+#	  discontinuity is there without PPI filtering but gets slightly
+#	  worse with PPI filtering. Setting $PPI_extend_upper_limit to 
+#	  1.03-1.05 partially removes the discontinuity but the profile
+#	  never gets better than the profile wihtout PPI editing. Note
+#	  the only reason why the upper PPI should be extended is if the
+#	  recorded ping intervals are inaccurate as the upper limit is
+#	  set by the shortest acoustic path between the ADCP and the 
+#	  seabed.
+
+$PPI_editing = ($LADCP{BEAM_FREQUENCY} < 300);
+
+#$PPI_extend_upper_limit = 1.03;		# arbitrarily increase calculated max dist from seabed by 3%
+
 #======================================================================
 # Time Lagging
 #======================================================================
--- a/edit_data.pl	Tue May 20 09:08:43 2014 +0000
+++ b/edit_data.pl	Wed Jul 09 15:19:27 2014 -0400
@@ -1,9 +1,9 @@
 #======================================================================
 #                    E D I T _ D A T A . P L 
 #                    doc: Sat May 22 21:35:55 2010
-#                    dlm: Mon May 19 22:24:40 2014
+#                    dlm: Wed May 21 13:00:35 2014
 #                    (c) 2010 A.M. Thurnherr
-#                    uE-Info: 285 28 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 339 74 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -28,6 +28,8 @@
 #	Oct 15, 2012: - BUG: editSurfLayer() counted also ensembles without CTD depth
 #	Nov 12, 2013: - added comments on editCorr_Earthcoords()
 #	Mar  4, 2013: - added support for missing PITCH/ROLL (TILT) & HEADING
+#	May 20, 2014: - added editPPI()
+#	May 21, 2014: - got it to work correctly
 
 # NOTES:
 #	- editCorr_Earthcoords() is overly conservative and removed most
@@ -241,11 +243,12 @@
 }
 
 #======================================================================
-# ($nvrm,$nerm) = editSideLobes($fromEns,$toEns,$range)
+# ($nvrm,$nerm) = editSideLobes($fromEns,$toEns,$water_depth)
 #
 # NOTES:
 #	1) When this code is executed the sound speed is known. No attempt is made to correct for
 #	   along-beam soundspeed variation, but the soundspeed at the transducer is accounted for.
+#	2) for UL, water_depth == undef
 #======================================================================
 
 sub editSideLobes($$$)
@@ -278,31 +281,103 @@
 
 
 #======================================================================
-# ($nvrm,$nerm) = editPPI($fromEns,$toEns,$range)
+# ($nvrm,$nerm) = editPPI($fromEns,$toEns,$water_depth)
 #
 # NOTES:
-#	1) When this code is executed the travel-time profile (@ttProf at 1m resolution)
-#	   has been constructed.
+#	- for UL, water_depth == undef; for DL water_depth is always defined,
+#	  or else editPPI is not called
+#	- when this code is executed a suitable UL or DL depth-average-soundspeed
+#	  profile (@DASSprof at 1m resolution) is available
+#	- PPI layer is defined by the shortest and longest acoustic paths
+#	  between transducer and seabed that contribute significantly to the
+#	  backscatter
+#		- shortest path (shallow limit):
+#			- distance to seabed => sidelobe
+#			- min_lim = water_depth - DASSprof[CTD_depth]*DeltaT/2
+#		- longest path (deep limit):
+#			- outer edge of main lobe of one of the beams (depending on 
+#			  instrument tilt)
+#			- nominal half-beam apertures at half peak signal strength
+#			  (-3dB), RDI BB Primer, pp. 35f (2ND COLUMN)
+#				WH1200	1.4		2.4
+#				WH600	1.5		2.5
+#				WH300	2.2		3.7
+#				WH150	4.0		6.7
+#				WH75	5.0	    8.4
+#			- for WH150, Fig. 23 indicates that half-beam-width 
+#			  at -5dB (<1% peak signal strength) is about 5/3 of same
+#			  at -3dB => PPI limit choice (3rd column above)
+#		- [Plots/2014_P16_043.eps]:
+#			- mean tilt of 2 degrees included in effects
+#			- finite pulse length means that there actually
+#			  is less elapsed time between the end of the sending
+#			  and the beginning of the reception than the ping
+#			  interval suggests; without it, the PPI peak depth
+#			  does not agree with the prediction
+#			- note that there is no PPI effect possible above
+#			  the dark blue line --- this is a hard limit
+#			  (I checked ping interval to within 0.001,
+#			  water depth is known better than 2m, sound
+#			  speed is accurately accounted for (as indicated
+#			  by the cyan line), so the variability above
+#			  is due to background variability, which is
+#			  consistent with the shape of the curve outside
+#			  the PPI layer
+#		  	=> PPI peak can be tightly bracketed but care has to
+#			   be taken to account for finite beam width & 
+#			   instrument beam_tilt = max(|pitch|,|roll|)
+#	- while the upper limit of the PPI layer is unambiguous, this
+#	  is only true if the recorded ping intervals are accurate
+#		- 2014 CLIVAR P16 #47 shows a slight discontinuity in dc_w near
+#		  the middle of the upper PPI layer (4000m)
+#		- the discontinuity is slightly more pronounced with PPI editing
+#	      enabled
+#		- setting $PPI_extend_upper_limit = 1.03 (or 1.04, 1.05, 1.1)
+#		  reduces the discontinuity to the level without PPI filtering, but
+#		  not any better
+#		- overall I am not convinced that the discontinuity is related
+#		  to PPI; therefore, $PPI_extend_upper_limit is not set by default
 #======================================================================
 
+{ my($bha);					# beam half aperture (static scope)
+
 sub editPPI($$$)
 {
 	my($fe,$te,$wd) = @_;	# first & last ens to process, water depth for downlooker
 	my($nvrm) = 0;			# of velocities removed
 	my($nerm) = 0;			# of ensembles affected
+
+	unless (defined($bha)) {
+		if    ($LADCP{BEAM_FREQUENCY} == 1200) { $bha = 2.4; }
+		elsif ($LADCP{BEAM_FREQUENCY} ==  600) { $bha = 2.5; }
+		elsif ($LADCP{BEAM_FREQUENCY} ==  300) { $bha = 3.7; }
+		elsif ($LADCP{BEAM_FREQUENCY} ==  150) { $bha = 6.7; }
+		elsif ($LADCP{BEAM_FREQUENCY} ==   75) { $bha = 8.4; }
+		else { croak("$0: unexpected transducer frequency $LADCP{BEAM_FREQUENCY}\n"); }
+	}
+	
 	for (my($e)=$fe; $e<=$te; $e++) {
 		next unless numberp($LADCP{ENSEMBLE}[$e]->{CTD_DEPTH});
-		my($range) = $LADCP{ENSEMBLE}[$e]->{XDUCER_FACING_UP}
-				   ? $LADCP{ENSEMBLE}[$e]->{CTD_DEPTH}
-				   : $wd - $LADCP{ENSEMBLE}[$e]->{CTD_DEPTH};
-		my($sscorr) = $CTD{SVEL}[$LADCP{ENSEMBLE}[$e]->{CTD_SCAN}] / 1500;
-		my($goodBins) =   ($range - $sscorr*$LADCP{DISTANCE_TO_BIN1_CENTER}) * cos(rad($LADCP{BEAM_ANGLE}))
-						/ ($sscorr*$LADCP{BIN_LENGTH})
-						- 1.5;
+		next unless ($e > 0);
+		
+		my($delta_t)   = $LADCP{ENSEMBLE}[$e]->{UNIX_TIME} - $LADCP{ENSEMBLE}[$e-1]->{UNIX_TIME};
+		my($dz_max)    = $DASSprof[int($LADCP{ENSEMBLE}[$e]->{CTD_DEPTH})]*$delta_t / 2;
+		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);
+
+		$dz_max *= $PPI_extend_upper_limit
+			if numberp($PPI_extend_upper_limit);
 
 		my($dirty) = 0;
-		for (my($bin)=int($goodBins); $bin<$LADCP{N_BINS}; $bin++) { 	# NB: 2 good bins implies that bin 2 is bad
-			next unless ($bin>=0 && defined($LADCP{ENSEMBLE}[$e]->{W}[$bin]));
+		for (my($bin)=$LADCP_firstBin-1; $bin<$LADCP_lastBin; $bin++) {
+			next unless (defined($LADCP{ENSEMBLE}[$e]->{W}[$bin]));
+			if (defined($wd)) {															# DL
+				next unless ($bd[$bin] >= $wd-$dz_max && $bd[$bin] <= $wd-$dz_min);
+			} else {																	# UL
+				next unless ($bd[$bin] <= $dz_max && $bd[$bin] >= $dz_min);
+			}
 			$dirty = 1;
 			$nvrm++;
 			undef($LADCP{ENSEMBLE}[$e]->{W}[$bin]);
@@ -313,6 +388,8 @@
 	return ($nvrm,$nerm);
 }
 
+} # static scope for $bha
+
 
 #======================================================================
 # $nerm = editSurfLayer($fromEns,$toEns,$surface_layer_depth)
--- a/time_lag.pl	Tue May 20 09:08:43 2014 +0000
+++ b/time_lag.pl	Wed Jul 09 15:19:27 2014 -0400
@@ -1,9 +1,9 @@
 #======================================================================
 #                    T I M E _ L A G . P L 
 #                    doc: Fri Dec 17 21:59:07 2010
-#                    dlm: Thu Apr 17 08:54:30 2014
+#                    dlm: Fri May 23 09:24:38 2014
 #                    (c) 2010 A.M. Thurnherr
-#                    uE-Info: 74 0 NIL 0 0 72 0 2 4 NIL ofnI
+#                    uE-Info: 54 59 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -51,6 +51,7 @@
 #	Apr 22, 2013: - replaced $max_allowed_w by $opt_m, $TL_required_top_three_fraction by $opt_3
 #	May 14, 2013: - opt_m => w_max_lim
 #	Mar  3, 2014: - BUG: var-name typo
+#	May 23, 2014: - BUG: $s range check required in mad_w()
 
 # DIFFICULT STATIONS:
 #	NBP0901#131		this requires the search-radius doubling heuristic
@@ -68,6 +69,7 @@
 	my($LADCP_mean_w,$CTD_mean_w,$nsamp) = (0,0,0);
 	for (my($e)=$fe; $e<=$le; $e++) {			# first, calculate mean w in window
 		my($s) = int(($LADCP{ENSEMBLE}[$e]->{ELAPSED} + $CTD{TIME_LAG} - $CTD{ELAPSED}[0]) / $CTD{DT} + 0.5);
+		next unless ($s>=0 && $s<=$#{$CTD{ELAPSED}});
 		die("assertion failed\n" .
 			"\ttest: abs($LADCP{ENSEMBLE}[$e]->{ELAPSED} + $CTD{TIME_LAG} - $CTD{ELAPSED}[$s]) <= $CTD{DT}/2\n" .
 			"\te = $e, s = $s, ensemble = $LADCP{ENSEMBLE}[$e]->{NUMBER}"