after folding in EGU flight mods (empirical Sv correction)
authorA.M. Thurnherr <athurnherr@yahoo.com>
Mon, 20 Apr 2015 14:04:04 +0000
changeset 28 b07b23485336
parent 27 2053d8de8d6b
child 29 c1ff35103176
after folding in EGU flight mods (empirical Sv correction)
LADCP_w
Makefile
SBE_w
Sv.cpt
Sv_scale.skel
acoustic_backscatter.pl
defaults.pl
--- a/LADCP_w	Thu Apr 16 14:50:59 2015 +0000
+++ b/LADCP_w	Mon Apr 20 14:04:04 2015 +0000
@@ -2,9 +2,9 @@
 #======================================================================
 #                    L A D C P _ W 
 #                    doc: Fri Dec 17 18:11:13 2010
-#                    dlm: Thu Apr 16 14:27:45 2015
+#                    dlm: Mon Apr 20 14:01:10 2015
 #                    (c) 2010 A.M. Thurnherr
-#                    uE-Info: 162 60 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 167 78 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # TODO:
@@ -160,13 +160,19 @@
 #				  - removed /bin/ksh requirement
 #				  - BUG: error messages were not reported in the log file
 #				  - made seabed detection code more flexible
+#				  - made reference-layer w_ocean warning more severe
+#				  - BUG: info() did not write anything into logfile when format string was used
+#				  - BUG: LADCP_lastBin was set 1 too low
+#	Apr 20, 2015: - improved comments
+#				  - improved diagnostic messages (warning on missing CTD temp)
+#				  - added support for empirical backscatter correction
 
 # CTD REQUIREMENTS
 #	- elapsed		elapsed seconds; see note below
 #	- depth
 #	- ss			sound speed
 #	- w				ddepth/dt
-#	- temp			OPTIONAL; used for backscatter calculation (i.e. not very important)
+#	- temp			OPTIONAL; used for backscatter calculation
 #	- %lat/%lon		OPTIONAL
 
 # 2-BEAM SOLUTIONS
@@ -326,7 +332,7 @@
 
 sub info(@)
 {
-	printf(LOGF "\t",@_) if defined($out_log);
+	print(LOGF "\t"),printf(LOGF @_) if defined($out_log);
 	print(STDERR ($opt_v > 1) ? "\t" : "$LADCP_file: ");
 	printf(STDERR @_)  if ($opt_v > 0);
 }
@@ -374,7 +380,7 @@
 error("$0: first reference-layer bin > last reference-layer bin\n")
 	unless ($refLr_firstBin <= $refLr_lastBin);
 
-$LADCP_lastBin = $LADCP{N_BINS}-1
+$LADCP_lastBin = $LADCP{N_BINS}
 	if ($LADCP_lastBin eq '*');
 error("$0: first valid LADCP bin outside valid range\n")
 	unless ($LADCP_firstBin>=1 && $LADCP_firstBin<=$LADCP{N_BINS});
@@ -646,13 +652,16 @@
 open(STDIN,$CTD_file) || error("$CTD_file: $!\n");
 error("$CTD_file: no data\n") unless (&antsIn());
 undef($antsOldHeaders);
-($CTD_elapsed,$CTD_depth,$CTD_svel,$CTD_w) = &fnr('elapsed','depth','ss','w');
-$CTD_temp = &fnrNoErr('temp');
+
 &antsAddParams('lat',$P{lat}) if defined($P{lat});
 &antsAddParams('lon',$P{lon}) if defined($P{lon});
 
+($CTD_elapsed,$CTD_depth,$CTD_svel,$CTD_w) = &fnr('elapsed','depth','ss','w');
+$CTD_temp = &fnrNoErr('temp');
+warning(2,"no CTD temperature --- using ADCP temperature instead => Sv degraded!\n",$s)
+   unless defined($CTD_temp);
+
 $CTD_maxdepth = -1;
-
 do {																		# read data
 	error("$0: cannot deal with non-numeric CTD elapsed time\n")
 		unless &antsNumbers($CTD_elapsed);
@@ -886,8 +895,11 @@
 	&antsAddParams('rms_w_reflr_err',sqrt($sumWsq/$nWsq),'rms_w_reflr_err_interior',sqrt($sumWsqI/$nWsqI));
 	progress("\t%.2f cm/s rms reference-layer w_ocean, %.2f cm/s away from boundaries\n",
 						100*sqrt($sumWsq/$nWsq),100*sqrt($sumWsqI/$nWsqI));
-	warning(0,"%.2f cm/s reference-layer w_ocean away from boundaries\n",100*sqrt($sumWsqI/$nWsqI))
-		if (sqrt($sumWsqI/$nWsqI) > 0.05);
+	if (sqrt($sumWsqI/$nWsqI) > 0.05) {
+		warning(1,"%.2f cm/s reference-layer w_ocean away from boundaries\n",100*sqrt($sumWsqI/$nWsqI));
+	} elsif (sqrt($sumWsqI/$nWsqI) > 0.1) {
+		warning(2,"%.2f cm/s reference-layer w_ocean away from boundaries\n",100*sqrt($sumWsqI/$nWsqI));
+	}
 #	error("$0: rms reference-layer w_ocean is too large\n")
 #		unless (sqrt($sumWsqI/$nWsqI) < 0.07);
 } elsif ($nWsq > 0) {
@@ -901,11 +913,14 @@
 # Calculate Volume Scattering Coefficients
 #----------------------------------------------------------------------
 
-progress("Calculating volume-scattering coefficients...\n");
+progress("Calculating volume-scattering coefficients (Sv)...\n");
 calc_backscatter_profs($firstGoodEns,$lastGoodEns);
 
+progress("\tapplying empirical Sv correction\n");
+correct_backscatter($firstGoodEns,$lastGoodEns);
+
 #----------------------------------------------------------------------------
-# Edit data
+# Find Seabed & Edit data
 #	1) contaminated by sidelobe reflection from seabed and sea surface
 #	2) PPI 
 #----------------------------------------------------------------------------
@@ -929,7 +944,7 @@
 				if ($dd > 5);
 		}
 		if (!$SS_use_BT && !defined($water_depth) && defined($water_depth_BT)) {
-			warning(1,"using water_depth from BT data\n");
+			warning(1,"using water_depth from ADCP BT data\n");
 			$SS_use_BT = 1;
 		}
 		if ($SS_use_BT) {
@@ -943,7 +958,7 @@
 
 	if (numberp($water_depth)) {
 		if (numberp($water_depth_BT)) {
-			progress("\t%.1f(%.1f) m water depth (%.1f(%.1f)m from BT)\n",
+			progress("\t%.1f(%.1f) m water depth (%.1f(%.1f)m from ADCP BT data)\n",
 				$water_depth,$sig_water_depth,$water_depth_BT,$sig_water_depth_BT);
 		} else {
 			progress("\t%.1f(%.1f) m water depth\n",$water_depth,$sig_water_depth);
@@ -972,7 +987,7 @@
 	        progress("\t$nvrm velocities from $nerm ensembles removed\n");
 	    }
 	} else {
-		info("no seabed found in backscatter profiles --- cannot edit sidelobe or PPI\n");
+		info("no seabed found --- cannot edit sidelobe or PPI\n");
 	}
 	
 } else {
--- a/Makefile	Thu Apr 16 14:50:59 2015 +0000
+++ b/Makefile	Mon Apr 20 14:04:04 2015 +0000
@@ -1,9 +1,9 @@
 #======================================================================
 #                    M A K E F I L E 
 #                    doc: Mon Oct 17 13:29:27 2011
-#                    dlm: Sun Feb 19 13:12:09 2012
+#                    dlm: Fri Apr 17 11:26:13 2015
 #                    (c) 2011 A.M. Thurnherr
-#                    uE-Info: 10 19 NIL 0 0 72 0 2 4 NIL ofnI
+#                    uE-Info: 20 36 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 MAKE_DIR = /Data/Makefiles
@@ -16,7 +16,8 @@
 	mkCPT -oc polar -- -0.03 -0.02 -0.01 -0.005 0.005 0.01 0.02 0.03 > $@
 
 Sv.cpt:
-	mkCPT -o -- \#-90--60:2 > $@
+#	mkCPT -m255/255/255 -o -- \#-90--60:2 > $@
+	mkCPT -m255/255/255 -o -- \#-100--60:2 > $@
 
 corr.cpt:
 	mkCPT -no -- \#70-120:5 \#120-130:0.5 > $@
--- a/SBE_w	Thu Apr 16 14:50:59 2015 +0000
+++ b/SBE_w	Mon Apr 20 14:04:04 2015 +0000
@@ -2,9 +2,9 @@
 #======================================================================
 #                    S B E _ W 
 #                    doc: Mon Nov  3 17:34:19 2014
-#                    dlm: Thu Apr 16 10:29:18 2015
+#                    dlm: Fri Apr 17 10:06:21 2015
 #                    (c) 2014 A.M. Thurnherr
-#                    uE-Info: 24 0 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 23 55 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 $antsSummary = 'pre-process SBE 9plus CTD data for LADCP_w';
@@ -20,10 +20,9 @@
 #				  - added no-valid-data error message
 #				  - modified binning criterion to allow any sampling
 #					frequency (not just divisors of 24)
-#	Apr 16, 2015: - disabled output activation unless ANTS tools are available
+#	Apr 17, 2015: - added in-situ temperature to output
 
 ($ANTS) = (`which ANTSlib`   =~ m{^(.*)/[^/]*$});
-$ANTS_TOOLS_AVAILABLE = (`which list` ne '');
 
 require "$ANTS/ants.pl";
 require "$ANTS/fft.pl";
@@ -45,8 +44,7 @@
 
 $CNVfile = $ARGV[0];											# open CNV file
 open(F,&antsFileArg());
-&antsActivateOut()												# activate ANTS file
-	if ($ANTS_TOOLS_AVAILABLE);
+&antsActivateOut();												# activate ANTS file
 
 #----------------------------------------------------------------------
 # Read Data
@@ -359,9 +357,9 @@
 
 print(STDERR "Writing output...\n") if ($opt_v);
 
-@antsNewLayout = ('elapsed','depth','sspd','w.raw','w');
+@antsNewLayout = ('elapsed','depth','temp','sspd','w.raw','w');
 for ($r=0; $r<@w; $r++) {
-	&antsOut($elapsed[$r],$depth[$r],$sspd[$r],$w[$r],$w_lp[2*$r]/@w_lp);
+	&antsOut($elapsed[$r],$depth[$r],$temp[$r],$sspd[$r],$w[$r],$w_lp[2*$r]/@w_lp);
 }
 
 exit(0);															# don't flush @ants_
--- a/Sv.cpt	Thu Apr 16 14:50:59 2015 +0000
+++ b/Sv.cpt	Mon Apr 20 14:04:04 2015 +0000
@@ -1,31 +1,25 @@
-#======================================================================
-#                    S V . C P T 
-#                    doc: Wed Mar 27 18:24:12 2013
-#                    dlm: Wed Mar 27 18:26:24 2013
-#                    (c) 2013 A.M. Thurnherr
-#                    uE-Info: 28 33 NIL 0 0 72 0 2 4 NIL ofnI
-#======================================================================
-
-# HISTORY:
-#	Mar 27, 2013: - changed nan color from grey to white
-
-#ANTS# [10/19/11 ...vertical_velocity] mkCPT '-o' '--' '#-90--60:2'
+#ANTS# [04/17/15 ...vertical_velocity] mkCPT '-m255/255/255' '-o' '--' '#-100--60:2'
 #ANTS#FIELDS# {from_z} {from_R} {from_G} {from_B} {to_z} {to_R} {to_G} {to_B} 
--90	175	0	255	-88	175	0	255	L
--88	96	0	255	-86	96	0	255	
--86	16	0	255	-84	16	0	255	L
--84	0	64	255	-82	0	64	255
--82	0	143	255	-80	0	143	255	L
--80	0	223	255	-78	0	223	255
--78	0	255	207	-76	0	255	207	L
--76	0	255	128	-74	0	255	128
--74	0	255	48	-72	0	255	48	L
--72	32	255	0	-70	32	255	0
--70	112	255	0	-68	112	255	0	L
--68	191	255	0	-66	191	255	0
--66	255	239	0	-64	255	239	0	L
--64	255	159	0	-62	255	159	0
--62	255	80	0	-60	255	80	0	L
+-100	194	0	255	-98	194	0	255
+-98	134	0	255	-96	134	0	255
+-96	73	0	255	-94	73	0	255
+-94	12	0	255	-92	12	0	255
+-92	0	49	255	-90	0	49	255
+-90	0	109	255	-88	0	109	255
+-88	0	170	255	-86	0	170	255
+-86	0	231	255	-84	0	231	255
+-84	0	255	219	-82	0	255	219
+-82	0	255	158	-80	0	255	158
+-80	0	255	97	-78	0	255	97
+-78	0	255	36	-76	0	255	36
+-76	24	255	0	-74	24	255	0
+-74	85	255	0	-72	85	255	0
+-72	146	255	0	-70	146	255	0
+-70	206	255	0	-68	206	255	0
+-68	255	243	0	-66	255	243	0
+-66	255	182	0	-64	255	182	0
+-64	255	121	0	-62	255	121	0
+-62	255	61	0	-60	255	61	0
 B	255	0	255
 F	255	0	0
 N	255	255	255
--- a/Sv_scale.skel	Thu Apr 16 14:50:59 2015 +0000
+++ b/Sv_scale.skel	Mon Apr 20 14:04:04 2015 +0000
@@ -1,20 +1,20 @@
 PSL_font_encode 0 get 0 eq {ISOLatin1+_Encoding /Helvetica /Helvetica PSL_reencode PSL_font_encode 0 1 put} if
 0 setlinecap
 0 setlinejoin
-10 setmiterlimit
+3.32551 setmiterlimit
 944.882 59.0551 T
 
 %% PostScript produced by:
 %%GMT:  psscale -O -K -E -D8/2/3/0.4 -CSv.cpt -B/:Sv:
-%%PROJ: xy -90.00000000 -60.00000000 0.00000000 0.15748031 -90.000 -60.000 0.000 0.157 +xy +a=6378137.000 +b=6356752.314245
+%%PROJ: xy -100.00000000 -60.00000000 0.00000000 0.15748031 -100.000 -60.000 0.000 0.157 +xy +a=6378137.000 +b=6356752.314245
 0 A
 5 W
 47.2441 0 T 90 R
 V N 0 0 T 354 47 scale /DeviceRGB setcolorspace
-<< /ImageType 1 /Decode [0 1 0 1 0 1] /Width 15 /Height 1 /BitsPerComponent 8
-   /ImageMatrix [15 0 0 -1 0 1] /DataSource currentfile /ASCII85Decode filter /LZWDecode filter
+<< /ImageType 1 /Decode [0 1 0 1 0 1] /Width 20 /Height 1 /BitsPerComponent 8
+   /ImageMatrix [20 0 0 -1 0 1] /DataSource currentfile /ASCII85Decode filter /LZWDecode filter
 >> image
-J1JDGo)oIF!rrlShunEZ^C,Oti+NB5^d/>f6J(`4Hjr:B-ibA4~>
+J1uKaoJ?u?!sV$+!uL_4gC7.M>k$ABD?c\`QsaAg`&+M(8OHY.8":$*"$FB>TEkf~>
 U
 {1 0 1 C} FS
 O1
@@ -33,86 +33,111 @@
 354 0 M 0 47 D S
 1 W
 0 0 M 0 47 D S
-24 0 M 0 47 D S
-47 0 M 0 47 D S
+18 0 M 0 47 D S
+35 0 M 0 47 D S
+53 0 M 0 47 D S
 71 0 M 0 47 D S
-94 0 M 0 47 D S
-118 0 M 0 47 D S
+89 0 M 0 47 D S
+106 0 M 0 47 D S
+124 0 M 0 47 D S
 142 0 M 0 47 D S
-165 0 M 0 47 D S
-189 0 M 0 47 D S
+159 0 M 0 47 D S
+177 0 M 0 47 D S
+195 0 M 0 47 D S
 213 0 M 0 47 D S
-236 0 M 0 47 D S
-260 0 M 0 47 D S
+230 0 M 0 47 D S
+248 0 M 0 47 D S
+266 0 M 0 47 D S
 283 0 M 0 47 D S
-307 0 M 0 47 D S
-331 0 M 0 47 D S
+301 0 M 0 47 D S
+319 0 M 0 47 D S
+337 0 M 0 47 D S
 354 0 M 0 47 D S
 2 W
 0 0 M
 0 -24 D S
+0 0 M 29 F0 (-100) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
+0 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-100) Z U
+18 0 M
+0 -24 D S
+0 0 M 29 F0 (-98) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
+18 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-98) Z U
+35 0 M
+0 -24 D S
+0 0 M 29 F0 (-96) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
+35 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-96) Z U
+53 0 M
+0 -24 D S
+0 0 M 29 F0 (-94) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
+53 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-94) Z U
+71 0 M
+0 -24 D S
+0 0 M 29 F0 (-92) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
+71 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-92) Z U
+89 0 M
+0 -24 D S
 0 0 M 29 F0 (-90) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
-0 -94 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-90) Z U
-24 0 M
+89 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-90) Z U
+106 0 M
 0 -24 D S
 0 0 M 29 F0 (-88) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
-24 -94 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-88) Z U
-47 0 M
+106 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-88) Z U
+124 0 M
 0 -24 D S
 0 0 M 29 F0 (-86) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
-47 -94 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-86) Z U
-71 0 M
+124 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-86) Z U
+142 0 M
 0 -24 D S
 0 0 M 29 F0 (-84) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
-71 -94 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-84) Z U
-94 0 M
+142 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-84) Z U
+159 0 M
 0 -24 D S
 0 0 M 29 F0 (-82) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
-94 -94 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-82) Z U
-118 0 M
+159 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-82) Z U
+177 0 M
 0 -24 D S
 0 0 M 29 F0 (-80) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
-118 -94 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-80) Z U
-142 0 M
+177 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-80) Z U
+195 0 M
 0 -24 D S
 0 0 M 29 F0 (-78) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
-142 -94 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-78) Z U
-165 0 M
+195 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-78) Z U
+213 0 M
 0 -24 D S
 0 0 M 29 F0 (-76) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
-165 -94 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-76) Z U
-189 0 M
+213 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-76) Z U
+230 0 M
 0 -24 D S
 0 0 M 29 F0 (-74) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
-189 -94 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-74) Z U
-213 0 M
+230 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-74) Z U
+248 0 M
 0 -24 D S
 0 0 M 29 F0 (-72) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
-213 -94 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-72) Z U
-236 0 M
+248 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-72) Z U
+266 0 M
 0 -24 D S
 0 0 M 29 F0 (-70) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
-236 -94 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-70) Z U
-260 0 M
+266 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-70) Z U
+283 0 M
 0 -24 D S
 0 0 M 29 F0 (-68) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
-260 -94 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-68) Z U
-283 0 M
+283 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-68) Z U
+301 0 M
 0 -24 D S
 0 0 M 29 F0 (-66) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
-283 -94 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-66) Z U
-307 0 M
+301 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-66) Z U
+319 0 M
 0 -24 D S
 0 0 M 29 F0 (-64) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
-307 -94 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-64) Z U
-331 0 M
+319 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-64) Z U
+337 0 M
 0 -24 D S
 0 0 M 29 F0 (-62) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
-331 -94 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-62) Z U
+337 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-62) Z U
 354 0 M
 0 -24 D S
 0 0 M 29 F0 (-60) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
-354 -94 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-60) Z U
+354 -110 M V -90 R PSL_dim_w neg PSL_dim_h 2 div neg G 29 F0 (-60) Z U
 0 0 M 29 F0 (Sv) E /PSL_dim_w exch def FP pathbbox N /PSL_dim_h exch def pop /PSL_dim_d exch def pop
 402 24 M V -90 R PSL_dim_w 2 div neg 0 G 29 F0 (Sv) Z U
 -90 R -47.2441 0 T
--- a/acoustic_backscatter.pl	Thu Apr 16 14:50:59 2015 +0000
+++ b/acoustic_backscatter.pl	Mon Apr 20 14:04:04 2015 +0000
@@ -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: Thu Apr 16 14:40:22 2015
+#                    dlm: Mon Apr 20 13:56:56 2015
 #                    (c) 2010 A.M. Thurnherr
-#                    uE-Info: 141 0 NIL 0 0 72 0 2 4 NIL ofnI
+#                    uE-Info: 24 71 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -18,7 +18,10 @@
 #	Mar  4, 2014: - added support for missing PITCH/ROLL (TILT)
 #	Apr 17, 2014: - BUG: missing ;
 #	Nov  7, 2014: - BUG: calc_binDepths() was called without valid CTD depth
-#	Apr 16, 2015: - added min samp criterion for seabed search
+#				  - added $SS_use_BT, $SS_min_signal, $SS_min_samp
+#	Apr 20, 2015: - added comments
+#				  - removed SS_{min,max}_allowed_range from calc_backscatter_profs()
+#				  - added correct_backscatter() & linterp() from laptop
 
 #----------------------------------------------------------------------
 # Volume Scattering Coefficient, following Deines (IEEE 1999)
@@ -27,6 +30,11 @@
 #   - no sound-speed correction applied
 #   - R in bin center, instead of last quarter
 #   - transmit power assumes 33V batteries
+# EMPIRICAL FINDINGS (after applying the empirical correction)
+#  - Sv(WH300) ~ Sv(WH150)/1.4-34
+#      - based on DoMORE-1: 004, 005
+#      - identical instrument setup (0/8/8m)
+#      - 003, with higher scattering is somewhat different
 #----------------------------------------------------------------------
 
 # NB:
@@ -39,7 +47,7 @@
 sub Sv($$$$$)
 {
     my($temp,$PL,$Er,$R,$EA) = @_;
-    my($C)      = -143;                 # RDI Workhorse monitor
+    my($C)      = -143;                 # RDI WHM300 (from Deines)
     my($Ldbm)   = 10 * log10($PL);
     my($PdbW)   = 14.0;
     my($alpha)  = 0.069;
@@ -85,9 +93,9 @@
 			my($range_to_bin) = abs($bd[$bin] - $LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH})
 									/ cos(rad($LADCP{ENSEMBLE}[$ens]->{TILT}))
 									/ $cosBeamAngle;
-			next
-				if ($range_to_bin < $SS_min_allowed_range ||
-					$range_to_bin > $SS_max_allowed_range);
+#			next
+#				if ($range_to_bin < $SS_min_allowed_range ||
+#					$range_to_bin > $SS_max_allowed_range);
 			my($temp) = defined($CTD_temp)
 					  ? $CTD{TEMP}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}]
 					  : $LADCP{ENSEMBLE}[$ens]->{TEMPERATURE};
@@ -113,6 +121,77 @@
 }
 
 #----------------------------------------------------------------------
+# empirically adjust Sv in far bins for consistency with nearest
+# valid bin
+#	- based on bin-to-bin differences of 100m vertically averaged Sv
+#	  profiles
+#	- algorithm can leave artifacts in the near bins near bottom
+#	  turn-around (DM1#001)
+#----------------------------------------------------------------------
+
+sub linterp($$$$$)
+{
+	my($x,$mix,$max,$miy,$may) = @_;
+	return $miy + ($x-$mix)/($max-$mix)*($may-$miy);
+}
+
+$Sv_ref_bin = 1;  # bin 2 is slightly better than bin 5 => use closest bin as reference as originally intended
+				  # default setting choses first bin with data; do not set to values below 1
+
+sub correct_backscatter($$)
+{
+	my($LADCP_start,$LADCP_end) = @_;
+	my($bin) = $LADCP_firstBin-1;
+	my(@refSvProf,@refSvSamp,$depth,$i);
+
+RETRY:
+	for ($depth=0; $depth<@nSv; $depth++) {						# create reference profile
+		next unless ($nSv[$depth][$Sv_ref_bin-1] > 0);
+		$refSvProf[int($depth/100)] += $sSv[$depth][$Sv_ref_bin-1] / $nSv[$depth][$Sv_ref_bin-1];
+		$refSvSamp[int($depth/100)]++;
+    }
+    $Sv_ref_bin++,goto RETRY
+    	unless (@refSvSamp);
+
+	for ($i=0; $i<@refSvSamp; $i++) {
+		next unless ($refSvSamp[$i] > 0);
+		$refSvProf[$i] /= $refSvSamp[$i];
+	}
+	for ($i=0; $i<5; $i++) {									# extrapolate bottom value by 500m
+		push(@refSvProf,$refSvProf[$#refSvProf]);
+		push(@refSvSamp,$refSvSamp[$#refSvSamp]);
+	}
+	info("\tusing bin %d as reference\n",$Sv_ref_bin);
+
+	my(@dSvProf);												# create profiles for all bins
+	for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {	
+		my(@dSvSamp);									
+		for ($depth=0; $depth<@nSv; $depth++) {					# create Sv-difference profile for current bin
+			next unless ($nSv[$depth][$bin] > 0);
+			$dSvProf[int($depth/100)][$bin] += $sSv[$depth][$bin] / $nSv[$depth][$bin];
+			$dSvSamp[int($depth/100)]++;
+		}
+		for ($i=0; $i<@dSvSamp; $i++) {
+			next unless ($refSvSamp[$i] > 0) && ($dSvSamp[$i] > 0);
+			$dSvProf[$i][$bin] = $dSvProf[$i][$bin]/$dSvSamp[$i] - $refSvProf[$i];
+		}
+		$dSvProf[$i][$bin] = $dSvProf[$i-1][$bin];				# extrapolate 100m
+	}
+
+    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);
+		for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
+			next unless numberp($LADCP{ENSEMBLE}[$ens]->{SV}[$bin]);
+			my($depth) = int($bd[$bin]);
+			$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]);
+		}
+	}
+}
+
+#----------------------------------------------------------------------
 # determine location of seabed from backscatter profiles
 #	input:	depth below which seabed can possibly be (e.g. max CTD depth)
 #	output:	median/mad of estimated water depth
@@ -120,8 +199,8 @@
 
 sub find_backscatter_seabed($)
 {
-	my($search_below) = int($_[0]);								# grid index to begin search
-	my(@wdepth);												# list of water_depth indices
+	my($search_below) = int($_[0]);										# grid index to begin search
+	my(@wdepth,@Sv_rng);												# list of water_depth indices
 
 	for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) { 	# find backscatter min/max below $search_below in each bin
 		my($minSv,$maxSv,$depthmaxSv,$lastvalid) = (1e99,-1e99,-1,-1);
@@ -132,13 +211,18 @@
 			$minSv = $Sv if ($Sv < $minSv);
 			$maxSv = $Sv, $depthmaxSv = $depth if ($Sv > $maxSv);
 		}
-		if ($maxSv-$minSv>10 && $depthmax!=$lastvalid) { 		# ignore boundary maxima & scatter
+		if ($maxSv-$minSv >= $SS_min_signal) { 							# ignore scatter
+			push(@Sv_rng,round($maxSv-$minSv));
 			push(@wdepth,$depthmaxSv);
 		}
 	}
 
-	info("%d seabed samples found\n",scalar(@wdepth));
-	return (undef,undef) if (scalar(@wdepth) < $SS_min_samp);	# require min number of samples
+	if (@wdepth) {
+		info("%d bins with seabed signatures found (\@Sv_rng: @Sv_rng)\n",scalar(@wdepth));
+    } else {
+		info("no bins with seabed signatures found\n");
+    }
+	return (undef,undef) if (scalar(@wdepth) < $SS_min_samp);			# require min number of samples
 	
 	my($wd) = median(@wdepth);
 	return ($wd,mad2($wd,@wdepth));
--- a/defaults.pl	Thu Apr 16 14:50:59 2015 +0000
+++ b/defaults.pl	Mon Apr 20 14:04:04 2015 +0000
@@ -1,9 +1,9 @@
 #======================================================================
 #                    D E F A U L T S . P L 
 #                    doc: Tue Oct 11 17:11:21 2011
-#                    dlm: Thu Apr 16 14:40:08 2015
+#                    dlm: Mon Apr 20 13:51:17 2015
 #                    (c) 2011 A.M. Thurnherr
-#                    uE-Info: 256 2 NIL 0 0 72 0 2 4 NIL ofnI
+#                    uE-Info: 283 24 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -45,7 +45,7 @@
 #   Apr 16, 2015: - turned output specifies into lists (re-design of
 #                   plotting sub-system)
 #				  - croak -> error
-#				  - added $SS_use_BT
+#				  - added $SS_use_BT, $SS_min_signal, $SS_min_samp
 
 #======================================================================
 # Data Input 
@@ -252,34 +252,49 @@
 $SS_use_BT = 0;
 
 
-# Require at least 5 valid samples for seabed detection. Only for
-# $SS_use_BT == 0.
+# The following variable defines the minimum Sv signal in a bin (max - min)
+# required for reliable seabed detection. A limiting value of 40dB is
+# indicated based on GoM#13, where the seabed is only visible in the last 
+# bin (#25). 30dB is chosen as the default to allow for variability. 
+# This value may need to be changed for data not collected with WH300
+# instruments with 8m bins, and perhaps also for different types of
+# seafloor (soft sediments). To do this, set $SS_min_signal to a small value
+# (e.g. 10) and inspect the \@SV_rng values reported in the log files.
+# This parameter is only used when $SS_use_BT == 0.
 
-$SS_min_samp = 5;
+$SS_min_signal = 30;
 
 
-# Number of ensembles around bottom to search. Only for $SS_use_BT == 1.
+# Require at minimum nubmer of valid samples for seabed detection. Each
+# sample is a bin with a clear seabed maximum. With a proper setting
+# of $SS_min_signal, the algorithm is stable even with only a single
+# sample (GoM#13). However, a default of 3 required samples is chosen
+# to make seabed detection less sensitive to $SS_min_signal. 
+# This parameter is only used when $SS_use_BT == 0.
+
+$SS_min_samp = 3;
+
+
+# The following numbers define the valid range of height-above bottom
+# for seabed detection. For data collected with WH300 instruments and
+# 8m bins, the maximum range needs to be greater than 250m (based on 
+# GoM#13).
+
+$SS_min_allowed_range = 0;
+$SS_max_allowed_range = 350;
+
+
+# Number of ensembles around bottom to search. Only used with $SS_use_BT == 1.
 
 $SS_search_window_halfwidth = 200;	 
 
 
 # Maximum allowed distance of seabed from mode of distribution. 
-# Only for $SS_use_BT == 1.
+# Only used with $SS_use_BT == 1.
 
 $SS_max_allowed_depth_range = 10;
 
 
-# The following numbers define the valid range of height-above bottom
-# for seabed detection when $SS_use_BT == 1. If the the mean BT_RANGE of 
-# a given ens falls outside this range, the ensemble is ignored during 
-# seabed detection.
-# Also, bins falling outside this range are not considered during 
-# construction of accoustic backscatter profiles.
-
-$SS_min_allowed_range = 20;
-$SS_max_allowed_range = 150;
-
-
 #======================================================================
 # Bottom Tracking
 #	- at present, the ADCP BT data are ignored, i.e. "post-processed"