listBins
changeset 37 40d85448debf
parent 36 515b06dae59c
child 40 6a46e9d31106
equal deleted inserted replaced
36:515b06dae59c 37:40d85448debf
     1 #!/usr/bin/perl
     1 #!/usr/bin/perl
     2 #======================================================================
     2 #======================================================================
     3 #                    L I S T B I N S 
     3 #                    L I S T B I N S 
     4 #                    doc: Fri Aug 25 15:57:05 2006
     4 #                    doc: Fri Aug 25 15:57:05 2006
     5 #                    dlm: Thu Jun  9 19:09:47 2016
     5 #                    dlm: Fri Jan 27 17:41:10 2017
     6 #                    (c) 2006 A.M. Thurnherr
     6 #                    (c) 2006 A.M. Thurnherr
     7 #                    uE-Info: 332 0 NIL 0 0 72 10 2 4 NIL ofnI
     7 #                    uE-Info: 68 81 NIL 0 0 72 2 2 4 NIL ofnI
     8 #======================================================================
     8 #======================================================================
     9 
     9 
    10 # Split data file into per-bin time series.
    10 # Split data file into per-bin time series.
    11 
    11 
    12 # HISTORY:
    12 # HISTORY:
    58 #	Jan 31, 2016: - started debugging the obviously wrong Earth2Beam() transformation
    58 #	Jan 31, 2016: - started debugging the obviously wrong Earth2Beam() transformation
    59 #	Feb 29, 2016: - continued debugging; removed debugging code
    59 #	Feb 29, 2016: - continued debugging; removed debugging code
    60 #   Mar 17, 2016: - adapted to new Getopt library
    60 #   Mar 17, 2016: - adapted to new Getopt library
    61 #	Jun  9, 2016: - minor improvements
    61 #	Jun  9, 2016: - minor improvements
    62 #				  - BUG: velBeamToEarth() has new interface
    62 #				  - BUG: velBeamToEarth() has new interface
       
    63 #	Jan 27, 2017: - BUG: earth-coordinate label was wrong
       
    64 #				  - changed semantics to include all %-good fields of earth-coordinate data
       
    65 #					and also report total pcg (3+4 beam) in min_pcg
       
    66 #				  - BUG: 3-beam %ages were incorrect: 1) they were based on goodvels instead of the
       
    67 #						 entire ensemble range; 2) pings-per-ensemble were not considered
       
    68 #				  - BUG: output layout was all messed up for non-valid velocities
    63 
    69 
    64 # General Notes:
    70 # General Notes:
    65 #	- everything (e.g. beams) is numbered from 1
    71 #	- everything (e.g. beams) is numbered from 1
    66 #	- no support for BT data
    72 #	- no support for BT data
    67 
    73 
    84 #	- min_pcg does not have to decrease monotonically with distance,
    90 #	- min_pcg does not have to decrease monotonically with distance,
    85 #	  at least when 3-beam solutions are allowed and when -p is used to
    91 #	  at least when 3-beam solutions are allowed and when -p is used to
    86 #	  edit the data
    92 #	  edit the data
    87 #	- non-monotonic min_pcg is particularly obvious with the DYNAMUCK BM_ADCP
    93 #	- non-monotonic min_pcg is particularly obvious with the DYNAMUCK BM_ADCP
    88 #	  data, where one of the beams performed much worse than the others
    94 #	  data, where one of the beams performed much worse than the others
       
    95 
       
    96 # %-good of earth-coordinate data:
       
    97 #	pcg1	3-beam (correlation threshold)
       
    98 #	pcg2	bad (errvel threshold)
       
    99 #	pcg3	bad (>1 bad beam)
       
   100 #	pcg4	4-beam
    89 
   101 
    90 use Getopt::Std;
   102 use Getopt::Std;
    91 
   103 
    92 $ADCP_tools_minVersion = 1.4;
   104 $ADCP_tools_minVersion = 1.4;
    93 ($ADCP_TOOLS) = ($0 =~ m{(.*/)[^/]+});
   105 ($ADCP_TOOLS) = ($0 =~ m{(.*/)[^/]+});
   149 	open(P,"$out") || die("$out: $!\n");
   161 	open(P,"$out") || die("$out: $!\n");
   150 	print(P "#ANTS#PARAMS# ");
   162 	print(P "#ANTS#PARAMS# ");
   151 	foreach my $k (keys(%P)) {
   163 	foreach my $k (keys(%P)) {
   152 		print(P "$k\{$P{$k}\} ");
   164 		print(P "$k\{$P{$k}\} ");
   153 	}
   165 	}
   154 	my($pct3b);
   166 	my($pct3b) = 100*$three_beam[$b]/(($le-$fe+1) * $dta{PINGS_PER_ENSEMBLE});
   155 #	if ($beamCoords) {
   167 	die("assertion failed: gv[$b] = $good_vels[$b]; 3b = $three_beam[$b]; ens=$fe..$le; ")
   156 		$pct3b = ($good_vels[$b] > 0) ? 100*$three_beam[$b]/$good_vels[$b] : nan;
   168 		if ($pct3b > 100);
   157 		printf(STDERR "%02d:%.0f%%/%.0f%% ",$b+1,100*$good_vels[$b]/($le-$fe+1),$pct3b);
   169 	printf(STDERR "%02d:%.0f%%/%.0f%% ",$b+1,100*$good_vels[$b]/($le-$fe+1),$pct3b);
   158 #	} else {
       
   159 #		printf(STDERR "%02d:%.0f%% ",$b+1,100*$good_vels[$b]/($le-$fe+1));
       
   160 #	}
       
   161 
   170 
   162 	printf(P "pct_3_beam{%.0f} ",$pct3b);
   171 	printf(P "pct_3_beam{%.0f} ",$pct3b);
   163 	printf(P "pct_good_vels{%.0f} ",100*$good_vels[$b]/($le-$fe+1));
   172 	printf(P "pct_good_vels{%.0f} ",100*$good_vels[$b]/($le-$fe+1));
   164 	printf(P "bin{%d}",$b+1);
   173 	printf(P "bin{%d}",$b+1);
   165 	printf(P " soundspeed_correction{%s}",defined($opt_S) ? $opt_S : 'NONE!');
   174 	printf(P " soundspeed_correction{%s}",defined($opt_S) ? $opt_S : 'NONE!');
   221 			printf(P defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][3]) ? "%g " : "nan ",
   230 			printf(P defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][3]) ? "%g " : "nan ",
   222 						$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][3]);
   231 						$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][3]);
   223 		} else {
   232 		} else {
   224 			print(P "nan nan nan nan ");
   233 			print(P "nan nan nan nan ");
   225 			print(P "nan nan nan nan ");
   234 			print(P "nan nan nan nan ");
       
   235 			print(P "nan nan nan nan ");
   226 		}
   236 		}
   227 		print(P "@{$dta{ENSEMBLE}[$e]->{CORRELATION}[$b]} ");
   237 		print(P "@{$dta{ENSEMBLE}[$e]->{CORRELATION}[$b]} ");
   228 		print(P "@{$dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b]} ");
   238 		print(P "@{$dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b]} ");
       
   239 		if ($dta{ENSEMBLE}[$e]->{GOOD_VEL}[$b]) {
       
   240 			print(P "@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]} ");
       
   241 		} else {
       
   242 			print(P "nan nan nan nan ");
       
   243 		}
   229 		if ($beamCoords) {
   244 		if ($beamCoords) {
   230 			print(P "@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]} ");
       
   231 			printf(P "%d ",$dta{ENSEMBLE}[$e]->{THREE_BEAM}[$b]);
   245 			printf(P "%d ",$dta{ENSEMBLE}[$e]->{THREE_BEAM}[$b]);
   232 			printf(P "%s ",min(@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]}));
   246 			printf(P "%s ",min(@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]}));
   233 		} else {
   247 		} else {
   234 			print(P "nan nan nan nan ");
   248 			if ($dta{ENSEMBLE}[$e]->{GOOD_VEL}[$b]) {
   235 			print(P "$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0] ");
   249 				print(P "$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0] ");
   236 			print(P "nan ");
   250 			} else {
       
   251 				print(P "nan ");
       
   252 			}
       
   253 			printf(P "%g ",$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0]+$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][3]);
   237 		}
   254 		}
   238 		printf(P "%g ",$dz[$b]*$ssCorr) if ($variable_ssCorr);
   255 		printf(P "%g ",$dz[$b]*$ssCorr) if ($variable_ssCorr);
   239 		print(P "\n");
   256 		print(P "\n");
   240 	}
   257 	}
   241 	close(P);
   258 	close(P);
   375 	printf(STDERR "3-Beam     : %d %d %d %d\n",$RDI_Coords::threeBeam_1,
   392 	printf(STDERR "3-Beam     : %d %d %d %d\n",$RDI_Coords::threeBeam_1,
   376 											   $RDI_Coords::threeBeam_2,
   393 											   $RDI_Coords::threeBeam_2,
   377 											   $RDI_Coords::threeBeam_3,
   394 											   $RDI_Coords::threeBeam_3,
   378 											   $RDI_Coords::threeBeam_4);
   395 											   $RDI_Coords::threeBeam_4);
   379 	
   396 	
   380 	print(STDERR "Good/3-beam: ");
   397 }
   381 } else {
   398 print(STDERR "Good/3-Beam: ");
   382 	print(STDERR "Good       : ");
       
   383 }
       
   384 for ($b=$firstBin; $b<=$lastBin; $b++) {				# generate output
   399 for ($b=$firstBin; $b<=$lastBin; $b++) {				# generate output
   385 	dumpBin($b,$fe,$le);
   400 	dumpBin($b,$fe,$le);
   386 }
   401 }
   387 print(STDERR "\n");
   402 print(STDERR "\n");
   388 
   403