# HG changeset patch # User A.M. Thurnherr # Date 1295040702 0 # Node ID 29faa9e6226cb102ee50c2d4eb9db2c758e6bdda # Parent 7e43b24080af2907a65b2661fc1087e16846f6e8 after DIMES UK2 diff --git a/RDI_Coords.pl b/RDI_Coords.pl --- a/RDI_Coords.pl +++ b/RDI_Coords.pl @@ -1,9 +1,9 @@ #====================================================================== # R D I _ C O O R D S . P L # doc: Sun Jan 19 17:57:53 2003 -# dlm: Sun May 23 22:47:32 2010 +# dlm: Thu Dec 23 15:00:02 2010 # (c) 2003 A.M. Thurnherr -# uE-Info: 28 74 NIL 0 0 72 2 2 4 NIL ofnI +# uE-Info: 30 48 NIL 0 0 72 2 2 4 NIL ofnI #====================================================================== # RDI Workhorse Coordinate Transformations @@ -26,6 +26,8 @@ # May 19, 2009: - added &velBeamToVertical() # May 23, 2009: - debugged & renamed to &velBeamToBPEarth # May 23, 2010: - changed prototypes of rad() & deg() to conform to ANTS +# Dec 20, 2010: - cosmetics +# Dec 23, 3020: - added &velBeamToBPInstrument use strict; use POSIX; @@ -140,7 +142,7 @@ } # STATIC SCOPE #====================================================================== -# velBeamToBPEarth3(@) calculates the vertical- and horizontal vels +# velBeamToBPEarth(@) calculates the vertical- and horizontal vels # from the two beam pairs separately. Note that (w1+w2)/2 is # identical to the w estimated according to RDI without 3-beam # solutions. @@ -195,6 +197,48 @@ } } +#=================================================================== +# velBeamToBPInstrument(@) calculates the instrument-coordinate vels +# from the two beam pairs separately. +#=================================================================== + +{ # STATIC SCOPE + my($TwoCosBAngle,$TwoSinBAngle); + + sub velBeamToBPInstrument(@) + { + my($dta,$ens,$b1,$b2,$b3,$b4) = @_; + my($v12,$w12,$v34,$w34); + + unless (defined($TwoCosBAngle)) { + $TwoCosBAngle = 2 * cos(rad($dta->{BEAM_ANGLE})); + $TwoSinBAngle = 2 * sin(rad($dta->{BEAM_ANGLE})); + } + my($roll) = rad($dta->{ENSEMBLE}[$ens]->{ROLL}); + my($sr) = sin($roll); my($cr) = cos($roll); + my($pitch) = atan(tan(rad($dta->{ENSEMBLE}[$ens]->{PITCH})) * $cr); # gimbal pitch + my($sp) = sin($pitch); my($cp) = cos($pitch); + + # Sign convention: + # - refer to Coord manual Fig. 3 + # - v12 is horizontal velocity from beam1 to beam2 + # - w is +ve upward, regardless of instrument orientation + + if (defined($b1) && defined($b2)) { + $v12 = ($b1-$b2)/$TwoSinBAngle; + $w12 = ($b1+$b2)/$TwoCosBAngle; + $w12 *= -1 if ($dta->{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}); + } + if (defined($b3) && defined($b4)) { + $v34 = ($b3-$b4)/$TwoSinBAngle; + $w34 = ($b3+$b4)/$TwoCosBAngle; + $w34 *= -1 if ($dta->{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}); + } + + return ($v12,$w12,$v34,$w34); + } +} + #====================================================================== # velApplyHdgBias() applies the heading bias, which is used to correct # for magnetic declination for data recorded in Earth-coordinates ONLY. @@ -230,8 +274,8 @@ sub gimbal_pitch($$) # RDI coord trans manual { - my($tilt1,$tilt2) = @_; - return deg(atan(tan(rad($tilt1)) * cos(rad($tilt2)))); + my($RDI_pitch,$RDI_roll) = @_; + return deg(atan(tan(rad($RDI_pitch)) * cos(rad($RDI_roll)))); } # - angle from vertical is home grown and should be treated with caution @@ -247,9 +291,9 @@ sub angle_from_vertical($$) { - my($tilt1,$tilt2) = @_; - my($rad_pitch) = atan(tan(rad($tilt1)) * cos(rad($tilt2))); - return deg(acos(cos($rad_pitch) * cos(rad($tilt2)))); + my($RDI_pitch,$RDI_roll) = @_; + my($rad_pitch) = atan(tan(rad($RDI_pitch)) * cos(rad($RDI_roll))); + return deg(acos(cos($rad_pitch) * cos(rad($RDI_roll)))); } 1; diff --git a/RDI_Utils.pl b/RDI_Utils.pl --- a/RDI_Utils.pl +++ b/RDI_Utils.pl @@ -1,9 +1,9 @@ #====================================================================== # R D I _ U T I L S . P L # doc: Wed Feb 12 10:21:32 2003 -# dlm: Fri Dec 10 14:51:41 2010 +# dlm: Thu Dec 16 05:36:27 2010 # (c) 2003 A.M. Thurnherr -# uE-Info: 349 0 NIL 0 0 72 2 2 4 NIL ofnI +# uE-Info: 333 65 NIL 0 0 72 2 2 4 NIL ofnI #====================================================================== # miscellaneous RDI-specific utilities @@ -35,6 +35,7 @@ # Oct 20, 2010: - BUG: w is now not integrated any more across gaps longer than 5s # Dec 8, 2010: - changed missing w warning to happen only if gap is longer than 15s # Dec 10, 2010: - beautified gap warning +# Dec 16, 2010: - BUG: gaps at end caused mk_prof to throw away profile use strict; @@ -328,7 +329,12 @@ $dta->{ENSEMBLE}[$lastgood]->{UNIX_TIME}; # ... last good ens if ($dt > $max_gap) { - printf(STDERR "WARNING: %d-s gap too long, profile restarted at ensemble $e\n",$dt); + if ($dta->{ENSEMBLE}[$lastgood]->{UNIX_TIME} - + $dta->{ENSEMBLE}[$firstgood]->{UNIX_TIME} > 15*60) { + printf(STDERR "WARNING: %.1f-s gap too long, profile ended at ensemble $lastgood\n",$dt); + last; + } + printf(STDERR "WARNING: %.1f-s gap too long, profile restarted at ensemble $e\n",$dt); $firstgood = $lastgood = $e; $dta->{ENSEMBLE}[$e]->{ELAPSED_TIME} = 0; $z = $zErr = $maxz = 0; @@ -345,7 +351,7 @@ $z += $dta->{ENSEMBLE}[$lastgood]->{W} * $dt; # integrate $zErr += ($dta->{ENSEMBLE}[$lastgood]->{W_ERR} * $dt)**2; } elsif ($dt > 15) { - printf(STDERR "WARNING: long-ish w gap (dt=%ds)\n",$dt); + printf(STDERR "WARNING: long-ish w gap (dt=%.1fs)\n",$dt); } $dta->{ENSEMBLE}[$e]->{DEPTH} = $z; diff --git a/listEns b/listEns --- a/listEns +++ b/listEns @@ -2,9 +2,9 @@ #====================================================================== # L I S T E N S # doc: Sat Jan 18 18:41:49 2003 -# dlm: Sun Aug 15 10:29:12 2010 +# dlm: Wed Jan 5 06:09:49 2011 # (c) 2003 A.M. Thurnherr -# uE-Info: 34 35 NIL 0 0 72 2 2 4 NIL ofnI +# uE-Info: 191 73 NIL 0 0 72 2 2 4 NIL ofnI #====================================================================== # Print useful info from the ensemble list or dump ensembles to @@ -32,9 +32,11 @@ # Mar 2, 2009: - added # of valid bin-1 vels to non-ANTS output # Jul 30, 2009: - NaN => nan # Aug 15, 2010: - BUG: usage typo +# Dec 10, 2010: - changed ANTS output to time/date instead of UNIX time +# Jan 5, 2011: - added -b # Notes: -# - -E outputs data in earth coordinates +# - -E outputs data in earth coordinates, unless -b is set also # - -E output is always in ANTS format, ignoring -A # - no soundspeed correction @@ -45,16 +47,16 @@ die("Usage: $0 [-A)nts] [-Q)uiet (errcheck only)] " . "[-f)ields <[name=]FIELD[,...]>] " . - "[write -E)nsemples [-M)agnetic ] [min -p)ercent-good <#>]] " . + "[write -E)nsemples [-M)agnetic ] [min -p)ercent-good <#>] [keep -b)eam coords]] " . "[-r)ange ] [in-w)ater ensembles only] " . "\n") - unless (&Getopts("AE:f:M:p:Qr:w") && $#ARGV >= 0); + unless (&Getopts("AbE:f:M:p:Qr:w") && $#ARGV >= 0); print(STDERR "WARNING: magnetic declination not set!\n") if defined($opt_E) && !defined($opt_M); die("$0: illegal option combination\n") - if ($opt_Q && $opt_A) || ((defined($opt_M) || defined($opt_p)) && !defined($opt_E)); + if ($opt_Q && $opt_A) || ((defined($opt_M) || defined($opt_p) || defined($opt_b)) && !defined($opt_E)); ($first_ens,$last_ens) = split(',',$opt_r) if defined($opt_r); @@ -101,6 +103,9 @@ die("$ARGV[0]: only beam and earth coordinates implemented so far\n"); } + die("$ARGV[0]: -b only makes sense for beam-coordinate data\n") + if ($opt_b && !$beamCoords); + if ($opt_A) { # select output fmt: ANTS unless ($opt_Q) { printf("#ANTS#PARAMS# N_ensembles{%d}\n",scalar(@{$dta{ENSEMBLE}})); @@ -183,9 +188,10 @@ if ($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][2] < $opt_p); undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3]) if ($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][3] < $opt_p); - @v = velInstrumentToEarth(\%dta,$e, - velBeamToInstrument(\%dta, - @{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]})); + @v = $opt_b ? @{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]} : + velInstrumentToEarth(\%dta,$e, + velBeamToInstrument(\%dta, + @{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]})); } else { @v = velApplyHdgBias(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]}); } diff --git a/mkProfile b/mkProfile --- a/mkProfile +++ b/mkProfile @@ -2,9 +2,9 @@ #====================================================================== # M K P R O F I L E # doc: Sun Jan 19 18:55:26 2003 -# dlm: Fri Dec 10 14:52:16 2010 +# dlm: Wed Jan 5 01:05:50 2011 # (c) 2003 A.M. Thurnherr -# uE-Info: 231 0 NIL 0 0 72 2 2 4 NIL ofnI +# uE-Info: 233 47 NIL 0 0 72 2 2 4 NIL ofnI #====================================================================== # Make an LADCP Profile by Integrating W (similar to Firing's scan*). @@ -70,6 +70,8 @@ # - NaN => nan # Dec 8, 2010: - added zmax/zend labels to output # Dec 10, 2010: - made mkProfile exit with status 0 if no good ens found but -Q is set +# Dec 19, 2010: - finally made -A default and activated output file +# Jan 5, 2011: - made no-good-ensembles found test much more robust # NOTES: # - the battery values are based on transmission voltages (different @@ -93,7 +95,7 @@ $USAGE = "$0 @ARGV"; die("Usage: $0 " . - "[-A)nts] [-Q)uiet] [-F)ilter