LADCP_w
changeset 30 7fb67e771d85
parent 29 c1ff35103176
--- a/LADCP_w	Sun Jul 26 20:04:48 2015 +0000
+++ b/LADCP_w	Thu Jul 30 09:11:43 2015 +0000
@@ -2,9 +2,9 @@
 #======================================================================
 #                    L A D C P _ W 
 #                    doc: Fri Dec 17 18:11:13 2010
-#                    dlm: Sun Jul 26 17:11:01 2015
+#                    dlm: Wed Jul 29 06:58:27 2015
 #                    (c) 2010 A.M. Thurnherr
-#                    uE-Info: 1465 90 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 1356 92 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # TODO:
@@ -180,6 +180,10 @@
 #	Jul 26, 2015: - added %output_grid_dz %output_grid_minsamp for use by [LADCP_w_regrid]
 # 				  - began work on support for [libGMT.pl]
 #				  - -v usage message had wrong default
+#				  - added $outGrid_firstBin & $outGrid_lastBin
+#	Jul 28, 2015: - added GMT plot support for all @out_ lists
+#	Jul 29, 2015: - continue adaptation of code for new plotting system
+# HISTORY END
 
 # CTD REQUIREMENTS
 #	- elapsed		elapsed seconds; see note below
@@ -622,6 +626,12 @@
 	
 	foreach my $of (@out_LADCP) {
 	    progress("<$of> ");
+		my($plot,$out) = ($of =~ /^([^\(]+)\(([^\)]+)\)$/);						# plot_sub(out_file)
+		if (defined($out)) {
+			require "$WCALC/${plot}.pl";
+			&{$plot}($out);
+			next;
+		}
 	    $of = ">$of" unless ($of =~ /^$|^\s*\|/);
 		open(STDOUT,$of) || error("$of: $!\n");
 		undef($antsActiveHeader) unless ($ANTS_TOOLS_AVAILABLE);
@@ -1087,11 +1097,13 @@
 #---------------------------------------------------------------------------
 
 progress("Creating binned profiles at ${opt_o}m resolution...\n");
-&antsAddParams('output_grid_dz',$opt_o,'output_grid_minsamp',$opt_k);			# will be used by LADCP_w_regrid
+
+&antsAddParams('outgrid_dz',$opt_o,'outgrid_minsamp',$opt_k);					# used by LADCP_w_regrid
+&antsAddParams('outgrid_firstbin',$outGrid_firstBin,'outgrid_lastbin',$outGrid_lastBin);
 
 my($min_depth) = 9e99;
 my($max_depth) = 0;
-my($realLastGoodEns);
+local($realLastGoodEns);
 
 progress("\tdowncast...\n");
 for ($ens=$firstGoodEns; $ens<$LADCP_atbottom; $ens++) {						# downcast
@@ -1103,6 +1115,7 @@
 	my(@bindepth) = calc_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);
 		$min_depth = $bindepth[$bin] if ($bindepth[$bin] < $min_depth);
 		$max_depth = $bindepth[$bin] if ($bindepth[$bin] > $max_depth);
 		$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] =
@@ -1155,6 +1168,7 @@
 	my(@bindepth) = calc_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);
 		$min_depth = $bindepth[$bin] if ($bindepth[$bin] < $min_depth);
 		$max_depth = $bindepth[$bin] if ($bindepth[$bin] > $max_depth);
 		$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] =
@@ -1229,6 +1243,7 @@
 		my(@bindepth) = calc_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);
 			my($bi) = $bindepth[$bin]/$opt_o;
 			push(@residuals,
 				$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] -
@@ -1288,10 +1303,9 @@
 #-------------------------
 
 if (@out_BR) {
-	my(@dc_nres,@uc_nres,@dc_bres,@uc_bres);
+	progress("Binning residuals ");
 
-	progress("Writing per-bin residual data to ");
-
+	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);
@@ -1312,6 +1326,15 @@
 					- $UPCAST{MEDIAN_W}[$bindepth[$bin]/$opt_o]);
 		}
 	}
+	local(@dc_avg_bres,@uc_avg_bres);
+	for (my($bin)=0; $bin<max(scalar(@dc_bres),scalar(@uc_bres)); $bin++) {		# calc means/stddevs
+		$dc_avg_bres[$bin] = avg(@{$dc_bres[$bin]});
+		$uc_avg_bres[$bin] = avg(@{$uc_bres[$bin]});
+		$dc_sig_bres[$bin] = stddev2($dc_avg_bres[$bin],@{$dc_bres[$bin]}),scalar(@{$dc_bres[$bin]});
+		$uc_sig_bres[$bin] = stddev2($uc_avg_bres[$bin],@{$uc_bres[$bin]}),scalar(@{$uc_bres[$bin]});
+	}
+
+	progress("\nWriting binned residuals to ");
 
 	my($saveParams) = $antsCurParams;
 	@antsNewLayout = ('bin','dc_residual','dc_residual.sig','dc_residual.nsamp',
@@ -1320,14 +1343,18 @@
 
 	foreach my $of (@out_BR) {
 	    progress("<$of> ");
+		my($plot,$out) = ($of =~ /^([^\(]+)\(([^\)]+)\)$/);						# plot_sub(out_file)
+		if (defined($out)) {
+			require "$WCALC/${plot}.pl";
+			&{$plot}($out);
+			next;
+		}
 	    $of = ">$of" unless ($of =~ /^$|^\s*\|/);
 		open(STDOUT,$of) || error("$of: $!\n");
 		undef($antsActiveHeader) unless ($ANTS_TOOLS_AVAILABLE);
 		for (my($bin)=0; $bin<max(scalar(@dc_bres),scalar(@uc_bres)); $bin++) {
-			my($dc_avg) = avg(@{$dc_bres[$bin]});
-			my($uc_avg) = avg(@{$uc_bres[$bin]});
-			&antsOut($bin+1,$dc_avg,stddev2($dc_avg,@{$dc_bres[$bin]}),scalar(@{$dc_bres[$bin]}),
-							$uc_avg,stddev2($uc_avg,@{$uc_bres[$bin]}),scalar(@{$uc_bres[$bin]}));
+			&antsOut($bin+1,$dc_avg_bres[$bin],$dc_sig_bres[$bin],scalar(@{$dc_bres[$bin]}),
+							$uc_avg_bres[$bin],$uc_sig_bres[$bin],scalar(@{$uc_bres[$bin]}));
 		}
 	    &antsOut('EOF'); open(STDOUT,">&2");
 	}
@@ -1372,6 +1399,14 @@
 
 	foreach my $of (@out_w) {
 	    progress("<$of> ");
+
+		my($plot,$out) = ($of =~ /^([^\(]+)\(([^\)]+)\)$/);						# plot_sub(out_file)
+		if (defined($out)) {
+			require "$WCALC/${plot}.pl";
+			&{$plot}($out);
+			next;
+		}
+			
 	    $of = ">$of" unless ($of =~ /^$|^\s*\|/);
 		open(STDOUT,$of) || error("$of: $!\n");
 		undef($antsActiveHeader) unless ($ANTS_TOOLS_AVAILABLE);
@@ -1505,6 +1540,12 @@
 					  
 	foreach my $of (@out_timeseries) {
 	    progress("<$of> ");
+		my($plot,$out) = ($of =~ /^([^\(]+)\(([^\)]+)\)$/);						# plot_sub(out_file)
+		if (defined($out)) {
+			require "$WCALC/${plot}.pl";
+			&{$plot}($out);
+			next;
+		}
 	    $of = ">$of" unless ($of =~ /^$|^\s*\|/);
 		open(STDOUT,$of) || error("$of: $!\n");
 		undef($antsActiveHeader) unless ($ANTS_TOOLS_AVAILABLE);