--- a/LADCPintsh
+++ b/LADCPintsh
@@ -2,9 +2,9 @@
#======================================================================
# L A D C P I N T S H
# doc: Thu Oct 14 21:22:50 2010
-# dlm: Wed Oct 24 23:21:52 2012
+# dlm: Fri Jul 12 12:18:07 2013
# (c) 2010 A.M. Thurnherr & E. Firing
-# uE-Info: 132 48 NIL 0 0 72 2 2 4 NIL ofnI
+# uE-Info: 57 59 NIL 0 0 72 2 2 4 NIL ofnI
#======================================================================
$antsSummary = 'integrate LADCP shear';
@@ -51,6 +51,10 @@
# May 16, 2012: - adapted to ANTSlib V5.0
# May 25, 2012: - added code to read LDEO_IX bottom-track data
# Jun 14, 2012: - noticed that -b now works also with LDEO SADCP files :-); renamed -b option to -r
+# Jun 5, 2013: - BUG: code bombed when either UC or DC was missing
+# Jun 28, 2013: - adapated to new :: convention
+# - make sure LADCP DUL metadata are dealt with correctly
+# Jul 12, 2013: - clarified -u usage with better messages
($ANTS) = (`which ANTSlib` =~ m{^(.*)/[^/]*$});
require "$ANTS/ants.pl";
@@ -59,7 +63,7 @@
&antsUsage('dm:n:r:s:w:u:',0,
'[-d)ebug]',
'[-r)eference with <BT or SADCP file> [-m)in <samp[10]>]]',
- '[-u)plooker <binned shear file>]',
+ '[secondary -u)plooker <shear file>]',
'[min -n) <shear samp[10]>]',
'[output -s)hear-pro <file>]',
'[LADCP shear file]');
@@ -73,8 +77,10 @@
&antsFileOpt($opt_r); # reference velocity file
&antsFileOpt($opt_u); # UL shear file
-open(ULF,$opt_u) || croak("$opt_u: $!\n")
- if defined($opt_u);
+if (defined($opt_u)) {
+ open(ULF,$opt_u) || croak("$opt_u: $!\n");
+ %UL_P = &antsFileParams(ULF);
+}
#======================================================================
# Step 1: Read and Average Shear Data
@@ -93,7 +99,31 @@
}
-$depthF = fnr('depth'); # layout of [LADCPproc] output
+#--------------------
+# Handle Metadata
+#--------------------
+
+if (%UL_P) {
+ croak("$0: inconsistent vertical resolution\n")
+ unless ($P{LADCPproc::vertical_resolution} == $UL_P{LADCPproc::vertical_resolution});
+
+ unless ($P{LADCPproc::bin_length} == $UL_P{LADCPproc::bin_length}) {
+ &antsInfo("Warnining: different DL/UL bin lengths; derived spectra cannot be corrected");
+ &antsAddParams('LADCPproc::bin_length','',
+ 'LADCPproc::DL_bin_length',$P{LADCPproc::bin_length},
+ 'LADCPproc::UL_bin_length',$UL_P{LADCPproc::bin_length});
+ }
+}
+
+$depthF = fnrNoErr('depth'); # layout of [LADCPproc] output
+unless (defined($depthF)) {
+ if (defined($opt_u)) {
+ croak("No 'depth' field in primary shear file (extraneous -u?)\n");
+ } else {
+ croak("No 'depth' field in primary shear file\n");
+ }
+}
+
$dc_nshF = fnrNoErr('dc_nshear');
$dc_nshF = fnr('dc_nsamp') unless defined($dc_nshF);
$dc_uzF = fnr('dc_u_z');
@@ -127,7 +157,7 @@
@UL_ = &antsFileIn(ULF); # read UL shear data
undef($opt_u) unless (@UL_); # cheap trick
}
-
+
$depth[$r] = $ants_[0][$depthF]; ## depth grid values
croak("$opt_u: inconsistent depth record $r (DL: $depth[$r]; UL: $UL_[$depthF])\n")
if defined($opt_u) && ($UL_[$depthF] != $depth[$r]);
@@ -506,8 +536,10 @@
$dc_sumU += $dc_u[$r]; $dc_sumV += $dc_v[$r]; $dc_sumW += $dc_w[$r] if (@BT_w);
}
}
- $dc_refU = $dc_sumU / $dc_nSumVel; $dc_refV = $dc_sumV / $dc_nSumVel;
- $dc_refW = $dc_sumW / $dc_nSumVel if (@BT_w);
+ if ($dc_nSumVel) {
+ $dc_refU = $dc_sumU / $dc_nSumVel; $dc_refV = $dc_sumV / $dc_nSumVel;
+ $dc_refW = $dc_sumW / $dc_nSumVel if (@BT_w);
+ }
}
unless (defined($uc_refU)) {
my($uc_sumU,$uc_sumV,$uc_sumW,$uc_nSumVel);
@@ -517,8 +549,10 @@
$uc_sumU += $uc_u[$r]; $uc_sumV += $uc_v[$r]; $uc_sumW += $uc_w[$r] if (@BT_w);
}
}
- $uc_refU = $uc_sumU / $uc_nSumVel; $uc_refV = $uc_sumV / $uc_nSumVel;
- $uc_refW = $uc_sumW / $uc_nSumVel if (@BT_w);
+ if ($uc_nSumVel) {
+ $uc_refU = $uc_sumU / $uc_nSumVel; $uc_refV = $uc_sumV / $uc_nSumVel;
+ $uc_refW = $uc_sumW / $uc_nSumVel if (@BT_w);
+ }
}
for (my($r)=0; $r<@depth; $r++) { # reference velocities
@@ -537,16 +571,18 @@
# Determine X Factor
#======================================================================
-my($first_w,$last_w);
-for (my($r)=0; !defined($first_w) || !defined($last_w); $r++) {
- $first_w = $dc_w[$r] unless defined($first_w);
- $last_w = $uc_w[$r] unless defined($last_w);
+if ($dc_nSumVel && $uc_nSumVel) {
+ my($first_w,$last_w);
+ for (my($r)=0; !defined($first_w) || !defined($last_w); $r++) {
+ $first_w = $dc_w[$r] unless defined($first_w);
+ $last_w = $uc_w[$r] unless defined($last_w);
+ }
+
+ my($X_Factor) = 100 * abs($last_w-$first_w) / sqrt(@depth / $DZ);
+ &antsAddParams('X-Factor',$X_Factor);
+ printf(STDERR "X-Factor = %.1f\n",$X_Factor);
}
-my($X_Factor) = 100 * abs($last_w-$first_w) / sqrt(@depth / $DZ);
-&antsAddParams('X-Factor',$X_Factor);
-printf(STDERR "X-Factor = %.1f\n",$X_Factor);
-
#======================================================================
# Output Velocity Profile
#======================================================================
--- a/LADCPproc
+++ b/LADCPproc
@@ -2,9 +2,9 @@
#======================================================================
# L A D C P P R O C
# doc: Thu Sep 16 20:36:10 2010
-# dlm: Fri Mar 29 15:24:15 2013
+# dlm: Tue Jun 25 14:28:32 2013
# (c) 2010 A.M. Thurnherr
-# uE-Info: 97 66 NIL 0 0 72 10 2 4 NIL ofnI
+# uE-Info: 81 54 NIL 0 0 72 10 2 4 NIL ofnI
#======================================================================
# NOTES:
@@ -76,6 +76,9 @@
# Jun 13, 2012: - added CTD_depth to tds output
# Oct 28, 2012: - added -z
# Mar 16, 2013: - BUG: usage message had a -p)PI flag
+# Jun 5, 2013: - added $bad_beam support
+# Jun 25, 2013: - added %PARAMS used for spectral correction
+# - adapted to new ::-PARAM convention
($ANTS) = (`which ANTSlib` =~ m{^(.*)/[^/]*$});
($PERL_TOOLS) = (`which mkProfile` =~ m{^(.*)/[^/]*$});
@@ -149,7 +152,7 @@
$LADCP_file = &antsFileArg();
$CTD_file = &antsFileArg();
-&antsAddParams('LADCP_file',$LADCP_file,'CTD_file',$CTD_file);
+&antsAddParams('LADCPproc::LADCP_file',$LADCP_file,'LADCPproc::CTD_file',$CTD_file);
&antsActivateOut();
#----------------------------------------------------------------------
@@ -161,6 +164,8 @@
printf(STDERR "\n\t%d ensembles",scalar(@{$LADCP{ENSEMBLE}})) if ($opt_d);
print(STDERR "\n");
+&antsAddParams('LADCPproc::bin_length',$LADCP{BIN_LENGTH});
+
#----------------------------------------------------------------------
# Step 2: Set Processing Parameters
#----------------------------------------------------------------------
@@ -184,12 +189,14 @@
$BT_bin_start = 2 unless ($BT_bin_start > 2);
}
-&antsAddParams('ADCP_orientation',
- $LADCP{ENSEMBLE}[0]->{XDUCER_FACING_UP} ? 'uplooker' : 'downlooker');
+&antsAddParams('LADCPproc::instrument_orientation',
+ $LADCP{ENSEMBLE}[0]->{XDUCER_FACING_UP} ? 'UL' : 'DL');
$SHEAR_PREGRID_DZ = 20;
$GRID_DZ = $opt_o;
+&antsAddParams('LADCPproc::vertical_resolution',$GRID_DZ);
+
#----------------------------------------------------------------------
# Step 3: Read CTD data
#----------------------------------------------------------------------
@@ -269,6 +276,7 @@
#-------------------------------------------------
# transform to earth coordinates if required
+# - discard data from a particular beam if requested
# - save beam_vels for later (e.g. wake) editing
#-------------------------------------------------
@@ -280,11 +288,18 @@
$LADCP{HEADING_BIAS} = -$magdec;
if ($LADCP{BEAM_COORDINATES}) {
- print(STDERR "\n\t\ttransforming beam to Earth coordinates...")
- if ($opt_d);
+ if ($opt_d) {
+ print(STDERR "\n\t\ttransforming beam to Earth coordinates...");
+ print(STDERR "\n\t\t\tdiscarding data from beam $bad_beam...")
+ if ($bad_beam);
+ }
for (my($ens)=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
$LADCP{ENSEMBLE}[$ens]->{TILT} = &angle_from_vertical($LADCP{ENSEMBLE}[$ens]->{PITCH},$LADCP{ENSEMBLE}[$ens]->{ROLL});
for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
+ if ($bad_beam) {
+ undef($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$bad_beam-1]);
+ undef($LADCP{ENSEMBLE}[$ens]->{BT_VELOCITY}[$bin][$bad_beam-1]);
+ }
@{$LADCP{ENSEMBLE}[$ens]->{BEAM_VEL}[$bin]} = @{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]};
@{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]} =
velInstrumentToEarth(\%LADCP,$ens,velBeamToInstrument(\%LADCP,@{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]}));
@@ -300,7 +315,7 @@
unless ($opt_4) {
print(STDERR "\n\t\t\t3-beam solutions: $RDI_Coords::threeBeam_1 $RDI_Coords::threeBeam_2 $RDI_Coords::threeBeam_3 $RDI_Coords::threeBeam_4\n")
if ($opt_d);
- &antsAddParams('3_beam_solutions',"$RDI_Coords::threeBeam_1 $RDI_Coords::threeBeam_2 $RDI_Coords::threeBeam_3 $RDI_Coords::threeBeam_4");
+ &antsAddParams('LADCPproc::3_beam_solutions',"$RDI_Coords::threeBeam_1 $RDI_Coords::threeBeam_2 $RDI_Coords::threeBeam_3 $RDI_Coords::threeBeam_4");
}
} elsif ($LADCP{EARTH_COORDINATES}) {
if ($opt_d) {
@@ -431,14 +446,14 @@
}
}
-&antsAddParams('top_depth',round($LADCP{ENSEMBLE}[$LADCP_top]->{DEPTH}),
- 'bottom_depth',round($LADCP{ENSEMBLE}[$LADCP_bottom]->{DEPTH}),
- 'start_date',$LADCP{ENSEMBLE}[$LADCP_start]->{DATE},
- 'start_time',$LADCP{ENSEMBLE}[$LADCP_start]->{TIME},
- 'bottom_date',$LADCP{ENSEMBLE}[$LADCP_bottom]->{DATE},
- 'bottom_time',$LADCP{ENSEMBLE}[$LADCP_bottom]->{TIME},
- 'end_date',$LADCP{ENSEMBLE}[$LADCP_end]->{DATE},
- 'end_time',$LADCP{ENSEMBLE}[$LADCP_end]->{TIME});
+&antsAddParams('LADCPproc::min_depth',round($LADCP{ENSEMBLE}[$LADCP_top]->{DEPTH}),
+ 'LADCPproc::max_depth',round($LADCP{ENSEMBLE}[$LADCP_bottom]->{DEPTH}),
+ 'LADCPproc::start_date',$LADCP{ENSEMBLE}[$LADCP_start]->{DATE},
+ 'LADCPproc::start_time',$LADCP{ENSEMBLE}[$LADCP_start]->{TIME},
+ 'LADCPproc::bottom_date',$LADCP{ENSEMBLE}[$LADCP_bottom]->{DATE},
+ 'LADCPproc::bottom_time',$LADCP{ENSEMBLE}[$LADCP_bottom]->{TIME},
+ 'LADCPproc::end_date',$LADCP{ENSEMBLE}[$LADCP_end]->{DATE},
+ 'LADCPproc::end_time',$LADCP{ENSEMBLE}[$LADCP_end]->{TIME});
print(STDERR "\n");
@@ -521,9 +536,9 @@
for ($mingi=0; $mingi<@ush_vals; $mingi++) {
last if @{$ush_vals[$mingi]};
}
- &antsAddParams('min_ens',$LADCP_start,'min_elapsed',$LADCP{ENSEMBLE}[$LADCP_start]->{ELAPSED_TIME}+$CTD{first_elapsed}-$opt_l,
- 'max_ens',$LADCP_end,'max_elapsed',$LADCP{ENSEMBLE}[$LADCP_end]->{ELAPSED_TIME}+$CTD{first_elapsed}-$opt_l,
- 'min_depth',depthOfGI($mingi),'max_depth',depthOfGI($#ens_vals));
+ &antsAddParams('LADCPproc::min_ens',$LADCP_start,'LADCPproc::min_elapsed',$LADCP{ENSEMBLE}[$LADCP_start]->{ELAPSED_TIME}+$CTD{first_elapsed}-$opt_l,
+ 'LADCPproc::max_ens',$LADCP_end,'LADCPproc::max_elapsed',$LADCP{ENSEMBLE}[$LADCP_end]->{ELAPSED_TIME}+$CTD{first_elapsed}-$opt_l,
+ 'LADCPproc::min_depth',depthOfGI($mingi),'LADCPproc::max_depth',depthOfGI($#ens_vals));
for (my($gi)=0; $gi<@ush_vals; $gi++) {
for (my($i)=0; $i<@{$ush_vals[$gi]}; $i++){
&antsOut($ens_vals[$gi][$i],
@@ -551,25 +566,25 @@
$commonParams = $antsCurParams; # PARAMs added up to now are common to all output files
-&antsAddParams('ubin_start',$ubin_start,'ubin_end',$ubin_end, # record processing params
- 'wbin_start',$wbin_start,'wbin_end',$wbin_end,
- 'shbin_start',$shbin_start,'shbin_end',$shbin_end,
- 'w_ref_bin',$w_ref_bin,'w_dif',$w_dif,
- 'wake_hd_dif',$wake_hd_dif,'wake_ang_min',$wake_ang_min,
- 'min_wake_w',$min_wake_w,'n_wake_bins',$n_wake_bins,
- 'e_max',$e_max,'min_cor',$min_cor,
- 'max_shdev',$max_shdev,'max_shdev_sum',$max_shdev_sum,
- 'water_depth',round($water_depth),'water_depth.sig',round($sig_water_depth),
- 'min_hab',round($min_hab),'PPI_editing_enabled',$PPI_editing_enabled,
- 'clip_margin',$clip_margin,'first_clip_bin',$first_clip_bin,
- 'Svbin_start',$Svbin_start,'Svbin_end',$Svbin_end,
- 'BT_bin_start',$BT_bin_start,'BT_bin_search_above',$BT_bin_search_above,
- 'BT_max_bin_spread',$BT_max_bin_spread,'BT_max_w_difference',$BT_max_w_difference,
+&antsAddParams('LADCPproc::ubin_start',$ubin_start,'LADCPproc::ubin_end',$ubin_end, # record processing params
+ 'LADCPproc::wbin_start',$wbin_start,'LADCPproc::wbin_end',$wbin_end,
+ 'LADCPproc::shbin_start',$shbin_start,'LADCPproc::shbin_end',$shbin_end,
+ 'LADCPproc::w_ref_bin',$w_ref_bin,'LADCPproc::w_dif',$w_dif,
+ 'LADCPproc::wake_hd_dif',$wake_hd_dif,'LADCPproc::wake_ang_min',$wake_ang_min,
+ 'LADCPproc::min_wake_w',$min_wake_w,'LADCPproc::n_wake_bins',$n_wake_bins,
+ 'LADCPproc::e_max',$e_max,'LADCPproc::min_cor',$min_cor,
+ 'LADCPproc::max_shdev',$max_shdev,'LADCPproc::max_shdev_sum',$max_shdev_sum,
+ 'LADCPproc::water_depth',round($water_depth),'LADCPproc::water_depth.sig',round($sig_water_depth),
+ 'LADCPproc::min_hab',round($min_hab),'LADCPproc::PPI_editing_enabled',$PPI_editing_enabled,
+ 'LADCPproc::clip_margin',$clip_margin,'LADCPproc::first_clip_bin',$first_clip_bin,
+ 'LADCPproc::Svbin_start',$Svbin_start,'LADCPproc::Svbin_end',$Svbin_end,
+ 'LADCPproc::BT_bin_start',$BT_bin_start,'LADCPproc::BT_bin_search_above',$BT_bin_search_above,
+ 'LADCPproc::BT_max_bin_spread',$BT_max_bin_spread,'LADCPproc::BT_max_w_difference',$BT_max_w_difference,
);
if (defined($BT_min_depth)) {
- &antsAddParams('BT_min_depth',$BT_min_depth,'BT_max_depth',$BT_max_depth);
+ &antsAddParams('LADCPproc::BT_min_depth',$BT_min_depth,'LADCPproc::BT_max_depth',$BT_max_depth);
} else {
- &antsAddParams('BT_max_depth_error',$BT_max_depth_error);
+ &antsAddParams('LADCPproc::BT_max_depth_error',$BT_max_depth_error);
}
$fullParams = $antsCurParams;
@@ -693,11 +708,11 @@
open(STDOUT,">$opt_a") || croak("$opt_a: $!\n");
$antsCurParams = $commonParams;
- &antsAddParams('min_elapsed',$LADCP{ENSEMBLE}[$LADCP_start]->{ELAPSED_TIME}+$CTD{first_elapsed}-$opt_l,
- 'max_elapsed',$LADCP{ENSEMBLE}[$LADCP_end]->{ELAPSED_TIME}+$CTD{first_elapsed}-$opt_l,
- 'min_depth',$LADCP{ENSEMBLE}[$LADCP_top]->{XDUCER_FACING_UP} ?
+ &antsAddParams('LADCPproc::min_elapsed',$LADCP{ENSEMBLE}[$LADCP_start]->{ELAPSED_TIME}+$CTD{first_elapsed}-$opt_l,
+ 'LADCPproc::max_elapsed',$LADCP{ENSEMBLE}[$LADCP_end]->{ELAPSED_TIME}+$CTD{first_elapsed}-$opt_l,
+ 'LADCPproc::min_depth',$LADCP{ENSEMBLE}[$LADCP_top]->{XDUCER_FACING_UP} ?
&depthOfBin($LADCP_top,$LADCP{N_BINS}-1) : $LADCP{ENSEMBLE}[$LADCP_top]->{DEPTH},
- 'max_depth',$LADCP{ENSEMBLE}[$LADCP_bottom]->{XDUCER_FACING_UP} ?
+ 'LADCPproc::max_depth',$LADCP{ENSEMBLE}[$LADCP_bottom]->{XDUCER_FACING_UP} ?
$LADCP{ENSEMBLE}[$LADCP_bottom]->{DEPTH} : &depthOfBin($LADCP_bottom,$LADCP{N_BINS}-1)
);
--- a/LADCPproc.loadCTD
+++ b/LADCPproc.loadCTD
@@ -1,9 +1,9 @@
#======================================================================
# L A D C P P R O C . L O A D C T D
# doc: Thu Dec 9 18:39:01 2010
-# dlm: Tue Jan 8 15:33:54 2013
+# dlm: Tue Jun 25 14:42:50 2013
# (c) 2010 A.M. Thurnherr
-# uE-Info: 46 107 NIL 0 0 72 2 2 4 NIL ofnI
+# uE-Info: 25 0 NIL 0 0 72 2 2 4 NIL ofnI
#======================================================================
# HISTORY:
@@ -21,6 +21,7 @@
# - BUG: CTD_badval had not been considered when setting $CTD{first_elapsed}
# - BUG: CNV format error was not detected correctly any more
# Jan 8, 2013: - added CTD_ASCII_header_lines
+# Jun 25, 2013: - adapted to :: %PARAM convention
sub readCTD_ASCII($$)
{
@@ -95,18 +96,18 @@
$salinF = $1,next if ($hdr =~ /name (\d+) = sal00:/);
}
- &antsAddParams('start_time',$1),next # selected metadata
+ &antsAddParams('LADCPproc::CTD_start_time',$1),next # selected metadata
if ($hdr =~ /start_time = (.*)/);
- &antsAddParams('station',$1),next
+ &antsAddParams('LADCPproc::CTD_station',$1),next
if ($hdr =~ /Station\s*:\s*(.*)/);
- &antsAddParams('ship',$1),next
+ &antsAddParams('LADCPproc::ship',$1),next
if ($hdr =~ /Ship\s*:\s*(.*)\s*$/);
- &antsAddParams('cruise',$1),next
+ &antsAddParams('LADCPproc::cruise',$1),next
if ($hdr =~ /Cruise\s*:\s*(.*)\s*$/);
- &antsAddParams('time',$1),next
+ &antsAddParams('LADCPproc::CTD_time',$1),next
if ($hdr =~ /Time\s*:\s*(.*)/);
- &antsAddParams('date',$1),next
+ &antsAddParams('LADCPproc::CTD_date',$1),next
if ($hdr =~ /Date\s*:\s*(.*)/);
if ($hdr =~ /Latitude\s*[=:]\s*/) {
@@ -198,7 +199,7 @@
croak("$0: unknown longitude\n") unless defined($dtaR->{lon});
&antsAddParams('lon',$dtaR->{lon});
- &antsAddParams('CTD_sampfreq',1/$dtaR->{sampint});
+ &antsAddParams('LADCPproc::CTD_sampfreq',1/$dtaR->{sampint});
&antsAddParams('ITS',$P{ITS} = 90);
}