listBins
changeset 43 b63fa355644c
parent 42 80d039881d2c
child 45 5767cbe470a0
equal deleted inserted replaced
42:80d039881d2c 43:b63fa355644c
     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: Sat Dec 23 16:10:11 2017
     5 #                    dlm: Tue Apr 10 08:41:50 2018
     6 #                    (c) 2006 A.M. Thurnherr
     6 #                    (c) 2006 A.M. Thurnherr
     7 #                    uE-Info: 104 28 NIL 0 0 72 0 2 4 NIL ofnI
     7 #                    uE-Info: 176 0 NIL 0 0 72 0 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:
    64 #				  - changed semantics to include all %-good fields of earth-coordinate data
    64 #				  - changed semantics to include all %-good fields of earth-coordinate data
    65 #					and also report total pcg (3+4 beam) in min_pcg
    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
    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
    67 #						 entire ensemble range; 2) pings-per-ensemble were not considered
    68 #				  - BUG: output layout was all messed up for non-valid velocities
    68 #				  - BUG: output layout was all messed up for non-valid velocities
       
    69 #	Feb  6, 2018: - added support for PD0_IO first_ens, last_ens
       
    70 #	Apr 10, 2018: - added day number to output
       
    71 #				  - added -l)ast bin
       
    72 #				  - activate output files
    69 
    73 
    70 # General Notes:
    74 # General Notes:
    71 #	- everything (e.g. beams) is numbered from 1
    75 #	- everything (e.g. beams) is numbered from 1
    72 #	- no support for BT data
    76 #	- no support for BT data
    73 
    77 
    99 #	pcg3	bad (>1 bad beam)
   103 #	pcg3	bad (>1 bad beam)
   100 #	pcg4	4-beam
   104 #	pcg4	4-beam
   101 
   105 
   102 use Getopt::Std;
   106 use Getopt::Std;
   103 
   107 
   104 $ADCP_tools_minVersion = 2.1;
   108 $ADCP_tools_minVersion = 2.2;
   105 ($ADCP_TOOLS) = ($0 =~ m{(.*/)[^/]+});
   109 ($ADCP_TOOLS) = ($0 =~ m{(.*/)[^/]+});
   106 require "$ADCP_TOOLS/ADCP_tools_lib.pl";
   110 require "$ADCP_TOOLS/ADCP_tools_lib.pl";
   107 
   111 
   108 die("Usage: $0 [-r)ange <first_ens,last_ens>] [-R)enumber ensembles] " .
   112 $antsMinLibVersion = 7.0;
       
   113 ($ANTS) = (`which ANTSlib` =~ m{^(.*)/[^/]*$});
       
   114 require "$ANTS/ants.pl";
       
   115 require "$ANTS/libconv.pl";
       
   116 
       
   117 die("Usage: $0 [-r)ange <first_ens,last_ens>] [-l)ast <bin>] [-R)enumber ensembles from 1] " .
   109 			  "[-o)utput <redirection[>bin%d.raw]>] " .
   118 			  "[-o)utput <redirection[>bin%d.raw]>] " .
   110 			  "[output -a)ll ens (not just those with good vels)] " .
   119 			  "[output -a)ll ens (not just those with good vels)] " .
   111 			  "[-M)agnetic <declination>] " .
   120 			  "[-M)agnetic <declination>] " .
   112 			  "[-S)oundspeed correction <salin|*,temp|*,depth|*> " .
   121 			  "[-S)oundspeed correction <salin|*,temp|*,depth|*> " .
       
   122 			  "[Instrument -T)ransformation Matrix <file>] " .
   113 			  "[-P)itch/Roll <bias/bias>] [-B)eamvel <bias/bias/bias/bias>] " .
   123 			  "[-P)itch/Roll <bias/bias>] [-B)eamvel <bias/bias/bias/bias>] " .
   114 		 	  "[require -4)-beam solutions] [-d)iscard <beam#>] " .
   124 		 	  "[require -4)-beam solutions] [-d)iscard <beam#>] " .
   115 		 	  "[-p)ct-good <min>] " .
   125 		 	  "[-p)ct-good <min>] " .
   116 			  "<RDI file>\n")
   126 			  "<RDI file>\n")
   117 	unless (&getopts("4aB:d:M:o:p:r:P:RS:") && @ARGV == 1);
   127 	unless (&getopts("4aB:d:l:M:o:p:r:P:RS:T:") && @ARGV == 1);
   118 
   128 
   119 ($P{pitch_bias},$P{roll_bias}) = split('[,/]',$opt_P);
   129 ($P{pitch_bias},$P{roll_bias}) = split('[,/]',$opt_P);
   120 ($P{velbias_b1},$P{velbias_b2},$P{velbias_b3},$P{velbias_b4}) = split('[,/]',$opt_B);
   130 ($P{velbias_b1},$P{velbias_b2},$P{velbias_b3},$P{velbias_b4}) = split('[,/]',$opt_B);
   121 
   131 
   122 die("$0: -4 and -d are mutually exclusive\n")
   132 die("$0: -4 and -d are mutually exclusive\n")
   139 	($SS_salin,$SS_temp,$SS_depth) = split(',',$opt_S);
   149 	($SS_salin,$SS_temp,$SS_depth) = split(',',$opt_S);
   140 	$variable_ssCorr = ($SS_salin eq '*' || $SS_temp eq '*' || $SS_depth eq '*');
   150 	$variable_ssCorr = ($SS_salin eq '*' || $SS_temp eq '*' || $SS_depth eq '*');
   141 } else {
   151 } else {
   142 	print(STDERR "WARNING: no soundspeed correction applied!\n");
   152 	print(STDERR "WARNING: no soundspeed correction applied!\n");
   143 }
   153 }
       
   154 
       
   155 loadInstrumentTransformation($opt_T)				# load instrument-transformation matrix
       
   156 	if (defined($opt_T));
   144 
   157 
   145 #----------------------------------------------------------------------
   158 #----------------------------------------------------------------------
   146 
   159 
   147 sub min(@)								# return minimum
   160 sub min(@)								# return minimum
   148 {
   161 {
   157 {
   170 {
   158 	my($b,$fe,$le) = @_;
   171 	my($b,$fe,$le) = @_;
   159 	my($out) = sprintf($opt_o,$b+1);
   172 	my($out) = sprintf($opt_o,$b+1);
   160 
   173 
   161 	open(P,"$out") || die("$out: $!\n");
   174 	open(P,"$out") || die("$out: $!\n");
       
   175 	print(P "#!/usr/bin/perl -S list\n");
       
   176 	chmod(0777&~umask,*P);																	# activate output
   162 	print(P "#ANTS#PARAMS# ");
   177 	print(P "#ANTS#PARAMS# ");
   163 	foreach my $k (keys(%P)) {
   178 	foreach my $k (keys(%P)) {
   164 		print(P "$k\{$P{$k}\} ");
   179 		print(P "$k\{$P{$k}\} ");
   165 	}
   180 	}
   166 	my($pct3b) = 100*$three_beam[$b]/(($le-$fe+1) * $dta{PINGS_PER_ENSEMBLE});
   181 	my($pct3b) = 100*$three_beam[$b]/(($le-$fe+1) * $dta{PINGS_PER_ENSEMBLE});
   176 				(defined($opt_S) ? ssCorr($dta{ENSEMBLE}[$fe],$SS_salin,$SS_temp,$SS_depth) : 1)
   191 				(defined($opt_S) ? ssCorr($dta{ENSEMBLE}[$fe],$SS_salin,$SS_temp,$SS_depth) : 1)
   177 	) unless ($variable_ssCorr);
   192 	) unless ($variable_ssCorr);
   178 	print( P "\n");
   193 	print( P "\n");
   179 
   194 
   180 	print(P "#ANTS#FIELDS# " .
   195 	print(P "#ANTS#FIELDS# " .
   181 			"{ensemble} {date} {time} {elapsed} " .
   196 			"{ensemble} {date} {time} {elapsed} {dn} " .
   182 			"{heading} {pitch} {roll} " .
   197 			"{heading} {pitch} {roll} " .
   183 			"{sig_heading} {sig_pitch} {sig_roll} " .
   198 			"{sig_heading} {sig_pitch} {sig_roll} " .
   184 			"{xmit_current} {xmit_voltage} " .
   199 			"{xmit_current} {xmit_voltage} " .
   185 			"{temp} " .
   200 			"{temp} " .
   186 			"{bv1} {bv2} {bv3} {bv4} {u} {v} {w} {err_vel} " .
   201 			"{bv1} {bv2} {bv3} {bv4} {u} {v} {w} {err_vel} " .
   199 		my($ssCorr) = defined($opt_S) ? ssCorr($dta{ENSEMBLE}[$e],$SS_salin,$SS_temp,$SS_depth) : 1;
   214 		my($ssCorr) = defined($opt_S) ? ssCorr($dta{ENSEMBLE}[$e],$SS_salin,$SS_temp,$SS_depth) : 1;
   200 		
   215 		
   201 		print(P "$dta{ENSEMBLE}[$e]->{NUMBER} ");
   216 		print(P "$dta{ENSEMBLE}[$e]->{NUMBER} ");
   202 		print(P "$dta{ENSEMBLE}[$e]->{DATE} ");
   217 		print(P "$dta{ENSEMBLE}[$e]->{DATE} ");
   203 		print(P "$dta{ENSEMBLE}[$e]->{TIME} ");
   218 		print(P "$dta{ENSEMBLE}[$e]->{TIME} ");
   204 		printf(P "%d ",$dta{ENSEMBLE}[$e]->{UNIX_TIME}-$t0);		# elapsed time
   219 		printf(P "%d ",$dta{ENSEMBLE}[$e]->{UNIX_TIME}-$t0);												# elapsed time
       
   220 		printf(P "%g ",str2dec_time($dta{ENSEMBLE}[$e]->{DATE},$dta{ENSEMBLE}[$e]->{TIME}));				# decimal day 
   205 		print(P defined($dta{ENSEMBLE}[$e]->{HEADING}) ? "$dta{ENSEMBLE}[$e]->{HEADING} " : 'nan ');
   221 		print(P defined($dta{ENSEMBLE}[$e]->{HEADING}) ? "$dta{ENSEMBLE}[$e]->{HEADING} " : 'nan ');
   206 		print(P defined($dta{ENSEMBLE}[$e]->{PITCH}) ? "$dta{ENSEMBLE}[$e]->{PITCH} " : 'nan ');
   222 		print(P defined($dta{ENSEMBLE}[$e]->{PITCH}) ? "$dta{ENSEMBLE}[$e]->{PITCH} " : 'nan ');
   207 		print(P defined($dta{ENSEMBLE}[$e]->{ROLL}) ? "$dta{ENSEMBLE}[$e]->{ROLL} " : 'nan ');
   223 		print(P defined($dta{ENSEMBLE}[$e]->{ROLL}) ? "$dta{ENSEMBLE}[$e]->{ROLL} " : 'nan ');
   208 		print(P "$dta{ENSEMBLE}[$e]->{HEADING_STDDEV} ");
   224 		print(P "$dta{ENSEMBLE}[$e]->{HEADING_STDDEV} ");
   209 		print(P "$dta{ENSEMBLE}[$e]->{PITCH_STDDEV} ");
   225 		print(P "$dta{ENSEMBLE}[$e]->{PITCH_STDDEV} ");
   263 #----------------------------------------------------------------------
   279 #----------------------------------------------------------------------
   264 
   280 
   265 $P{RDI_file} = $ifn;
   281 $P{RDI_file} = $ifn;
   266 $P{mag_decl} = $opt_M if defined($opt_M);
   282 $P{mag_decl} = $opt_M if defined($opt_M);
   267 
   283 
   268 readData($ifn,\%dta);
   284 readData($ifn,\%dta,$first_ens,$last_ens,$opt_l);
   269 printf(STDERR "%d complete ensembles...\n",scalar(@{$dta{ENSEMBLE}}));
   285 printf(STDERR "%d complete ensembles...\n",scalar(@{$dta{ENSEMBLE}}));
   270 $dta{HEADING_BIAS} = -$opt_M;						# magnetic declination
   286 $dta{HEADING_BIAS} = -$opt_M;						# magnetic declination
   271 
   287 
   272 if ($dta{BEAM_COORDINATES}) {						# coords
   288 if ($dta{BEAM_COORDINATES}) {						# coords
   273 	$beamCoords = 1;
   289 	$beamCoords = 1;