RDI_Utils.pl
changeset 10 c835cd613f3e
parent 8 7ad053ea1742
child 11 9c3b147b4372
equal deleted inserted replaced
9:9470ce05c10d 10:c835cd613f3e
     1 #======================================================================
     1 #======================================================================
     2 #                    R D I _ U T I L S . P L 
     2 #                    R D I _ U T I L S . P L 
     3 #                    doc: Wed Feb 12 10:21:32 2003
     3 #                    doc: Wed Feb 12 10:21:32 2003
     4 #                    dlm: Wed Sep 21 18:48:23 2011
     4 #                    dlm: Wed Mar 27 14:45:02 2013
     5 #                    (c) 2003 A.M. Thurnherr
     5 #                    (c) 2003 A.M. Thurnherr
     6 #                    uE-Info: 378 0 NIL 0 0 72 2 2 4 NIL ofnI
     6 #                    uE-Info: 43 51 NIL 0 0 72 2 2 4 NIL ofnI
     7 #======================================================================
     7 #======================================================================
     8 
     8 
     9 # miscellaneous RDI-specific utilities
     9 # miscellaneous RDI-specific utilities
    10 
    10 
    11 # History:
    11 # History:
    37 #	Dec 10, 2010: - beautified gap warning
    37 #	Dec 10, 2010: - beautified gap warning
    38 #	Dec 16, 2010: - BUG: gaps at end caused mk_prof to throw away profile
    38 #	Dec 16, 2010: - BUG: gaps at end caused mk_prof to throw away profile
    39 #	May 12, 2011: - added code to skip ensembles with built-in-test errors in mk_prof()
    39 #	May 12, 2011: - added code to skip ensembles with built-in-test errors in mk_prof()
    40 #				  - immediately disabled this code becasue it does appear to make matters worse
    40 #				  - immediately disabled this code becasue it does appear to make matters worse
    41 #	Sep 21, 2011: - added calculation of RMS heave acceleration
    41 #	Sep 21, 2011: - added calculation of RMS heave acceleration
       
    42 #	Mar 27, 2013: - BUG: 3-beam solutions were not used in ref_lr_w
       
    43 #				  - disabled apparently unused code
    42 
    44 
    43 use strict;
    45 use strict;
    44 
    46 
    45 #======================================================================
    47 #======================================================================
    46 # fake_BT_RANGE(dta ptr)
    48 # fake_BT_RANGE(dta ptr)
   247 					 $dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][2] > 0 ||
   249 					 $dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][2] > 0 ||
   248 					 $dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][3] < 100);
   250 					 $dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][3] < 100);
   249 			@v = @{$dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i]};
   251 			@v = @{$dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i]};
   250 			# NB: no need to apply heading bias, as long as we only use w!
   252 			# NB: no need to apply heading bias, as long as we only use w!
   251 		}
   253 		}
   252 		next if (!defined($v[3]) || abs($v[3]) > $max_e);
   254 ###		next if (!defined($v[3]) || abs($v[3]) > $max_e);		# disallow 3-beam solutions
       
   255 		next if (defined($v[3]) && abs($v[3]) > $max_e);		# allow 3-beam solutions
   253 
   256 
   254 		if (defined($v[2])) {							# valid w
   257 		if (defined($v[2])) {							# valid w
   255 			$vel[2] += $v[2]; $n[2]++;
   258 			$vel[2] += $v[2]; $n[2]++;
   256 			$vel[3] += $v[3], $n[3]++ if defined($v[3]);
   259 			$vel[3] += $v[3], $n[3]++ if defined($v[3]);
   257 			push(@w,$v[2]); 							# for stderr test
   260 			push(@w,$v[2]); 							# for stderr test
   258 		}
   261 		}
   259 		
   262 		
   260 		if ($dta->{BEAM_COORDINATES}) {
   263 #	The following code calculates beam-averaged ref-lr velocities.
   261 			$bv[0] += $dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0], $bn[0]++
   264 #	I do not recall what this was implemented for. Disabled Mar 27, 2013.
   262 				if defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0]);
   265 #
   263 			$bv[1] += $dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][1], $bn[1]++
   266 #		if ($dta->{BEAM_COORDINATES}) {
   264 				if defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][1]);
   267 #			$bv[0] += $dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0], $bn[0]++
   265 			$bv[2] += $dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][2], $bn[2]++
   268 #				if defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0]);
   266 				if defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][2]);
   269 #			$bv[1] += $dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][1], $bn[1]++
   267 			$bv[3] += $dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][3], $bn[3]++
   270 #				if defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][1]);
   268 	            if defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][3]);
   271 #			$bv[2] += $dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][2], $bn[2]++
   269 	    }
   272 #				if defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][2]);
       
   273 #			$bv[3] += $dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][3], $bn[3]++
       
   274 #	            if defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][3]);
       
   275 #	    }
   270 	}
   276 	}
   271 
   277 
   272 	my($w) = $n[2] ? $vel[2]/$n[2] : undef;				# w uncertainty
   278 	my($w) = $n[2] ? $vel[2]/$n[2] : undef;				# w uncertainty
   273 	my($sumsq) = 0;
   279 	my($sumsq) = 0;
   274 	for ($i=0; $i<=$#w; $i++) {
   280 	for ($i=0; $i<=$#w; $i++) {
   281 
   287 
   282 	if (defined($w)) {									# valid w
   288 	if (defined($w)) {									# valid w
   283 		$dta->{ENSEMBLE}[$ens]->{W} = $w;
   289 		$dta->{ENSEMBLE}[$ens]->{W} = $w;
   284 		$dta->{ENSEMBLE}[$ens]->{W_ERR} = $stderr;
   290 		$dta->{ENSEMBLE}[$ens]->{W_ERR} = $stderr;
   285 	}
   291 	}
   286 	if ($dta->{BEAM_COORDINATES}) {
   292 #	The following code calculates beam-averaged ref-lr velocities.
   287 		$dta->{ENSEMBLE}[$ens]->{V1} = $bn[0]>=2 ? $bv[0]/$bn[0] : undef;
   293 #	I do not recall what this was implemented for. Disabled Mar 27, 2013.
   288 		$dta->{ENSEMBLE}[$ens]->{V2} = $bn[1]>=2 ? $bv[1]/$bn[1] : undef;
   294 #
   289 		$dta->{ENSEMBLE}[$ens]->{V3} = $bn[2]>=2 ? $bv[2]/$bn[2] : undef;
   295 #	if ($dta->{BEAM_COORDINATES}) {
   290 	    $dta->{ENSEMBLE}[$ens]->{V4} = $bn[3]>=2 ? $bv[3]/$bn[3] : undef;
   296 #		$dta->{ENSEMBLE}[$ens]->{V1} = $bn[0]>=2 ? $bv[0]/$bn[0] : undef;
   291 	}
   297 #		$dta->{ENSEMBLE}[$ens]->{V2} = $bn[1]>=2 ? $bv[1]/$bn[1] : undef;
       
   298 #		$dta->{ENSEMBLE}[$ens]->{V3} = $bn[2]>=2 ? $bv[2]/$bn[2] : undef;
       
   299 #	    $dta->{ENSEMBLE}[$ens]->{V4} = $bn[3]>=2 ? $bv[3]/$bn[3] : undef;
       
   300 #	}
   292 }
   301 }
   293 
   302 
   294 
   303 
   295 sub mk_prof($$$$$$$$)										# make profile
   304 sub mk_prof($$$$$$$$)										# make profile
   296 {
   305 {