LADCPproc.utils
author A.M. Thurnherr <athurnherr@yahoo.com>
Fri, 06 Mar 2015 15:51:10 -0500
changeset 32 9b972ce37c3b
parent 31 af03ca38fc2a
permissions -rw-r--r--
merged 1

#======================================================================
#                    L A D C P P R O C . U T I L S 
#                    doc: Fri Mar 21 15:16:59 2014
#                    dlm: Sun Jul 27 17:00:57 2014
#                    (c) 2014 A.M. Thurnherr
#                    uE-Info: 14 49 NIL 0 0 72 2 2 4 NIL ofnI
#======================================================================

# HISTORY:
#	Mar 21, 2014: - created
#				  - added rangeToBin()
#	Mar 27, 2014: - added rangeToBinAlongBeam()
#	Jul 27, 2014: - improved comments
#				  - moved depthOfGI() here from [LADCPproc.backscatter]

#----------------------------------------------------------------------
# calculate depth of particular bin in particular ensemble
# 	in contrast to the original UH code:
#		- the distance to the first bin is soundspeed-corrected
#		- instrument tilt is considered
#----------------------------------------------------------------------

sub depthOfBin($$)
{
	sub dzToBin($$)
	{
		my($ens,$bin) = @_;
		my($sscorr) = $LADCP{ENSEMBLE}[$ens]->{CTD_SVEL} / $LADCP{ENSEMBLE}[$ens]->{SPEED_OF_SOUND};
		my($tlcorr) = cos(rad($LADCP{ENSEMBLE}[$ens]->{TILT}));
		return $sscorr*$tlcorr * ($LADCP{DISTANCE_TO_BIN1_CENTER} + $bin*$LADCP{BIN_LENGTH});
	}

	my($ens,$bin) = @_;
	return $LADCP{ENSEMBLE}[$ens]->{XDUCER_FACING_UP} ?
		   $LADCP{ENSEMBLE}[$ens]->{DEPTH} - &dzToBin($ens,$bin) :
		   $LADCP{ENSEMBLE}[$ens]->{DEPTH} + &dzToBin($ens,$bin);
}

#----------------------------------------------------------------------
# calculate along-beam distance between transducer and center of
# particular bin in particular ensemble
#	- used for acoustic backscatter correction
#----------------------------------------------------------------------

sub rangeToBin($$)
{
	my($ens,$bin) = @_;
	my($sscorr) = $LADCP{ENSEMBLE}[$ens]->{CTD_SVEL} / $LADCP{ENSEMBLE}[$ens]->{SPEED_OF_SOUND};
	return $sscorr * ($LADCP{DISTANCE_TO_BIN1_CENTER} + $bin*$LADCP{BIN_LENGTH}) / cos(rad($LADCP{BEAM_ANGLE}));
}

#----------------------------------------------------------------------------
# calculate depth of particular bin of particular beam in particular ensemble
#	- used to map acoustic backscatter of different beams correctly when
#	  instrument tilt is large
#----------------------------------------------------------------------------

sub depthOfBinAlongBeam($$$)
{
	sub dzToBinAlongBeam($$$)
	{
		my($ens,$bin,$beam) = @_;
		my($sscorr) = $LADCP{ENSEMBLE}[$ens]->{CTD_SVEL} / $LADCP{ENSEMBLE}[$ens]->{SPEED_OF_SOUND};

		my($pitch) = $LADCP{ENSEMBLE}[$ens]->{PITCH} + $pitch_offset;
		my($roll)  = $LADCP{ENSEMBLE}[$ens]->{ROLL}  + $roll_offset;

		if ($beam == 0) 	{ $roll  += $LADCP{BEAM_ANGLE}; }
		elsif ($beam == 1) 	{ $roll  -= $LADCP{BEAM_ANGLE}; }
		elsif ($beam == 2) 	{ $pitch += $LADCP{BEAM_ANGLE}; }
		else 				{ $pitch -= $LADCP{BEAM_ANGLE}; }

		my($tlcorr) = cos(rad(&angle_from_vertical($pitch,$roll)));
		
		return $sscorr*$tlcorr * ($LADCP{DISTANCE_TO_BIN1_CENTER} + $bin*$LADCP{BIN_LENGTH});
	}

	my($ens,$bin,$beam) = @_;
	return $LADCP{ENSEMBLE}[$ens]->{XDUCER_FACING_UP} ?
		   $LADCP{ENSEMBLE}[$ens]->{DEPTH} - &dzToBinAlongBeam($ens,$bin,$beam) :
		   $LADCP{ENSEMBLE}[$ens]->{DEPTH} + &dzToBinAlongBeam($ens,$bin,$beam);
}

#---------------------------------------------------------------------------
# return center depth corresponding to particular grid index (in shear grid)
#---------------------------------------------------------------------------

sub depthOfGI($) { return $_[0]*$GRID_DZ + $GRID_DZ/2; }		# depth corresponding to particular grid index

#----------------------------------------------------------------------
# return ocean velocity (u,v,w) at a given depth
#----------------------------------------------------------------------

sub oceanVel($)
{
	
}



1;