RDI_Coords.pl
changeset 41 d7ab920c1de6
parent 39 3bddaa514ef5
child 43 b63fa355644c
equal deleted inserted replaced
40:6a46e9d31106 41:d7ab920c1de6
     1 #======================================================================
     1 #======================================================================
     2 #                    R D I _ C O O R D S . P L 
     2 #                    R D I _ C O O R D S . P L 
     3 #                    doc: Sun Jan 19 17:57:53 2003
     3 #                    doc: Sun Jan 19 17:57:53 2003
     4 #                    dlm: Thu Oct 12 21:01:19 2017
     4 #                    dlm: Mon Nov 27 07:13:25 2017
     5 #                    (c) 2003 A.M. Thurnherr
     5 #                    (c) 2003 A.M. Thurnherr
     6 #                    uE-Info: 260 20 NIL 0 0 72 10 2 4 NIL ofnI
     6 #                    uE-Info: 58 62 NIL 0 0 72 10 2 4 NIL ofnI
     7 #======================================================================
     7 #======================================================================
     8 
     8 
     9 # RDI Workhorse Coordinate Transformations
     9 # RDI Workhorse Coordinate Transformations
    10 
    10 
    11 # HISTORY:
    11 # HISTORY:
    52 #				  - BUG: v34 sign was inconsistent with RDI coord manual
    52 #				  - BUG: v34 sign was inconsistent with RDI coord manual
    53 #	Jun  8, 2016: - added $ens as arg to velInstrumentToBeam() for consistency
    53 #	Jun  8, 2016: - added $ens as arg to velInstrumentToBeam() for consistency
    54 #	Jul  7, 2016: - added velEarthToBPw() with algorithm debugged and verified
    54 #	Jul  7, 2016: - added velEarthToBPw() with algorithm debugged and verified
    55 #					by Paul Wanis from TRDI
    55 #					by Paul Wanis from TRDI
    56 #	Oct 12, 2017: - documentation
    56 #	Oct 12, 2017: - documentation
       
    57 #	Nov 26, 2017: - BUG: velBeamtoBPEarth() did not respect missing values
       
    58 #	Nov 27, 2017: - BUG: numbersp() from [antslib.pl] was used
    57 
    59 
    58 use strict;
    60 use strict;
    59 use POSIX;
    61 use POSIX;
    60 
    62 
    61 my($PI) = 3.14159265358979;
    63 my($PI) = 3.14159265358979;
   365 		# Sign convention:
   367 		# Sign convention:
   366 		#	- refer to Coord manual Fig. 3
   368 		#	- refer to Coord manual Fig. 3
   367 		#	- v12 is horizontal velocity from beam1 to beam2, i.e. westward for upward-looking ADCP
   369 		#	- v12 is horizontal velocity from beam1 to beam2, i.e. westward for upward-looking ADCP
   368 		#	  with beam 3 pointing north (heading = 0)
   370 		#	  with beam 3 pointing north (heading = 0)
   369 
   371 
   370 		my($v12_ic) = ($b1-$b2)/$TwoSinBAngle;									# instrument coords
   372 		my($v12_ic,$w12_ic,$v34_ic,$w34_ic,$w_ic);
   371 		my($v34_ic) = ($b4-$b3)/$TwoSinBAngle;									# consistent with RDI Coords
   373 	    
   372 		my($w12_ic) = ($b1+$b2)/$TwoCosBAngle;
   374 		if (numberp($b1) && numberp($b2)) {
   373 		my($w34_ic) = ($b3+$b4)/$TwoCosBAngle;
   375 			$v12_ic = ($b1-$b2)/$TwoSinBAngle;									# instrument coords...
   374 		my($w_ic) = ($w12_ic+$w34_ic) / 2;
   376 			$w12_ic = ($b1+$b2)/$TwoCosBAngle; 									# consistent with RDI convention
       
   377 		}
       
   378 		if (numberp($b3) && numberp($b4)) {
       
   379 			$v34_ic = ($b4-$b3)/$TwoSinBAngle;
       
   380 			$w34_ic = ($b3+$b4)/$TwoCosBAngle;
       
   381 		}
   375 	    
   382 	    
   376 		if ($ADCP->{ENSEMBLE}[$ens]->{XDUCER_FACING_DOWN}) {					# beampair Earth coords
   383 		if ($ADCP->{ENSEMBLE}[$ens]->{XDUCER_FACING_DOWN}) {					# beampair Earth coords
   377 			$v12 = $v12_ic*$cr 		+ $v34_ic*0			+ $w_ic*$sr;			# Lohrman et al. (1990) A1
   384 			if (numberp($w12_ic) && numberp($w34_ic)) {
   378 			$v34 = $v12_ic*$sp*$sr	+ $v34_ic*$cp		- $w_ic*$sp*$cr;		#	- defined for z upward => DL
   385 				$w_ic = ($w12_ic+$w34_ic) / 2;
   379 			$w12 =-$v12_ic*$cp*$sr	+ $v34_ic*$sp		+ $w12_ic*$cp*$cr;
   386 				$v12 = $v12_ic*$cr		+ $v34_ic*0 		+ $w_ic*$sr;		# Lohrman et al. (1990) A1
   380 			$w34 =-$v12_ic*$cp*$sr	+ $v34_ic*$sp		+ $w34_ic*$cp*$cr;
   387 				$v34 = $v12_ic*$sp*$sr	+ $v34_ic*$cp		- $w_ic*$sp*$cr;	#	- defined for z upward => DL
   381 		} else {																# RDI Coord trans manual
   388 				$w12 =-$v12_ic*$cp*$sr	+ $v34_ic*$sp		+ $w12_ic*$cp*$cr;
   382 			$v12 =-$v12_ic*$cr 		+ $v34_ic*0			- $w_ic*$sr;			# 	- as above with 1st & 3rd cols negated
   389 	            $w34 =-$v12_ic*$cp*$sr  + $v34_ic*$sp       + $w34_ic*$cp*$cr;
   383 			$v34 =-$v12_ic*$sp*$sr	+ $v34_ic*$cp		+ $w_ic*$sp*$cr;
   390 	        } elsif (numberp($w12_ic)) {
   384 			$w12 = $v12_ic*$cp*$sr	+ $v34_ic*$sp		- $w12_ic*$cp*$cr;
   391 				$v12 = $v12_ic*$cr		+ $w12_ic*$sr;	    
   385 			$w34 = $v12_ic*$cp*$sr	+ $v34_ic*$sp		- $w34_ic*$cp*$cr;
   392 				$w12 =-$v12_ic*$cp*$sr	+ $w12_ic*$cp*$cr;
   386 		}
   393 	        } elsif (numberp($w34_ic)) {
   387 
   394 				$v34 = $v34_ic*$cp		- $w34_ic*$sp*$cr;    
   388 		$v12=$w12=undef unless (defined($b1) && defined($b2));
   395 				$w34 = $v34_ic*$sp		+ $w34_ic*$cp*$cr;
   389 		$v34=$w34=undef unless (defined($b3) && defined($b4));
   396 	        }
       
   397 		} else {																
       
   398 			if (numberp($w12_ic) && numberp($w34_ic)) {
       
   399 				$w_ic = ($w12_ic+$w34_ic) / 2;
       
   400 				$v12 =-$v12_ic*$cr		+ $v34_ic*0 		- $w_ic*$sr;		#	- as above with 1st & 3rd cols negated
       
   401 				$v34 =-$v12_ic*$sp*$sr	+ $v34_ic*$cp		+ $w_ic*$sp*$cr;
       
   402 				$w12 = $v12_ic*$cp*$sr	+ $v34_ic*$sp		- $w12_ic*$cp*$cr;
       
   403 	            $w34 = $v12_ic*$cp*$sr  + $v34_ic*$sp       - $w34_ic*$cp*$cr;
       
   404 	        } elsif (numberp($w12_ic)) {
       
   405 				$v12 =-$v12_ic*$cr		- $w12_ic*$sr;		
       
   406 				$w12 = $v12_ic*$cp*$sr	- $w12_ic*$cp*$cr;
       
   407 	        } elsif (numberp($w34_ic)) {
       
   408 				$v34 = $v34_ic*$cp		+ $w34_ic*$sp*$cr;
       
   409 				$w34 = $v34_ic*$sp		- $w34_ic*$cp*$cr;
       
   410 	        }
       
   411 		}
   390 
   412 
   391 		return ($v12,$w12,$v34,$w34);
   413 		return ($v12,$w12,$v34,$w34);
   392 	}
   414 	}
   393 }
   415 }
   394 
   416