author | A.M. Thurnherr <athurnherr@yahoo.com> |
Sat, 24 Jul 2021 10:35:41 -0400 | |
changeset 56 | 8f120b9f795a |
parent 54 | 828e5466391b |
child 57 | 69e39fcb7f41 |
permissions | -rwxr-xr-x |
18 | 1 |
#!/usr/bin/perl |
2 |
#====================================================================== |
|
3 |
# L A D C P _ V K E |
|
4 |
# doc: Tue Oct 14 11:05:16 2014 |
|
56 | 5 |
# dlm: Sat Jul 24 09:44:26 2021 |
18 | 6 |
# (c) 2012 A.M. Thurnherr |
56 | 7 |
# uE-Info: 120 45 NIL 0 0 72 0 2 4 NIL ofnI |
18 | 8 |
#====================================================================== |
9 |
||
10 |
$antsSummary = 'calculate VKE from LADCP-derived vertical-velocity profiles'; |
|
11 |
||
43 | 12 |
# NOTES: |
13 |
# - LADCP_VKE takes either one .wspec file (produced by [LADCP_wspec] |
|
14 |
# and, possibly, post-processed) or any number of .wprof files (the |
|
15 |
# normal case) as input |
|
16 |
# - when .wprof files are supplied, [LADCP_wspec] is used to calculate |
|
17 |
# the corresponding VKE spectra |
|
18 |
# - when multiple .wprof files are supplied, the resulting spectra |
|
19 |
# are averaged |
|
20 |
# - the averaged spectra will only cover the windows that are present in |
|
21 |
# the final(!) .wprof input files |
|
22 |
||
23 |
# TODO: |
|
42 | 24 |
# ! verify that p0fit.slope.sig is correct (-x scale factor) |
25 |
||
18 | 26 |
# HISTORY: |
27 |
# Oct 14, 2014: - created from [LADCPfs] |
|
28 |
# Oct 15, 2014: - added parameterization output |
|
29 |
# Oct 17, 2014: - changed parameterization constant $c to 0.021 |
|
30 |
# Nov 6, 2014: - restored from backup and adapted to ANTS V6.0 |
|
31 |
# Nov 7, 2014: - changed parameterization constant $c to 0.0215 |
|
26
b89d4b01fcc5
after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
32 |
# Apr 16, 2015: - disabled output activation unless ANTS tools are available |
b89d4b01fcc5
after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
33 |
# - removed superfluous $ANTSBIN definition |
29 | 34 |
# May 18, 2015: - added -p)ulse <length> |
35 |
# Jun 11, 2015: - removed w_z code (yfname param requirement) |
|
36 |
# Jun 12, 2015: - adapted to &antsParam() |
|
37 |
# - BUG: %k.0 and %lambda.0 had been required erroneously (.1 are first ones to be used) |
|
38 |
# - made finescale limits optional |
|
39 |
# - renamed -b=>-l, -c=>-o, -s=>-i |
|
40 |
# Jun 14, 2015: - renamed -p=>-a |
|
41 |
# - added -p |
|
42 |
# - removed weird evals |
|
43 |
# Jun 15, 2015: - added plot & other mods |
|
44 |
# Jun 16, 2015: - define default outputs when STDOUT is a tty |
|
45 |
# - adapted to re-added pwrdens.0 in LADCP_wspec output |
|
46 |
# - modified plot label |
|
47 |
# Jun 17, 2015: - added eps.w to plot |
|
31 | 48 |
# Jul 30, 2015: - moved main label and made it blue |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
49 |
# Sep 28, 2015: - added a p0fit r test to ensure that correlation has the correct sign |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
50 |
# Oct 12, 2015: - BUG: plot was in landscape mode |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
51 |
# - added input run label(s) to plot |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
52 |
# - require ANTSlibs V6.2 for release |
33 | 53 |
# Oct 13, 2015: - adapted to [version.pl] |
54 |
# Nov 30, 2015: - BUG: -a was not allowed in usage |
|
55 |
# - added -f |
|
56 |
# Dec 27, 2015: - reduced minlim for eps to 1e-13 W/kg |
|
34 | 57 |
# Dec 29, 2015: - added 3rd consistency check (p0 limit) |
58 |
# Jan 25, 2016: - added software version %PARAM |
|
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
59 |
# Mar 7, 2016: - removed unused spectral normalization code |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
60 |
# - added latitude constraint for calculation of eps.w |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
61 |
# Mar 8, 2016: - renamed fs_pwr to pwr.fs for consistency |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
62 |
# - renamed eps.w to eps.VKE for consistency |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
63 |
# - changed default output filenames for -d and -u |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
64 |
# - removed ./ from figure label |
36 | 65 |
# - update ANTSlib to 6.3 |
41 | 66 |
# Mar 16, 2016: - adapted to gmt5 |
42 | 67 |
# Mar 17, 2016: - added version to plot |
68 |
# - added -k)e dissipation |
|
69 |
# - reduced eps scale |
|
70 |
# Mar 26, 2016: - added slope |
|
71 |
# Mar 27, 2016: - added slope stddev |
|
72 |
# - added opt_x |
|
73 |
# - re-designed QC checks |
|
74 |
# - added -z)ap |
|
75 |
# Mar 28, 2016: - made QC tests consistent with I08S observations based on p0fit.rms == 0.4 |
|
76 |
# - added support for w.nsamp.avg |
|
77 |
# - removed -z from LDCP_wspec |
|
78 |
# - reduced -z default to 1, because 2 noise should affect only shotest scales |
|
79 |
# Mar 29, 2016: - changed default of -x to 1 & removed from usage |
|
80 |
# - BUG: -l/-a did not work |
|
81 |
# - removed p0fit.nsamp from output (is constant) |
|
43 | 82 |
# Mar 30, 2016: - added support for multiple wprof input files |
83 |
# Mar 31, 2016: - standardized %PARAMs (got rid of old binpgrams:: params) |
|
84 |
# - added spectral averaging |
|
85 |
# - disabled -l/-a code (override bin size & pulse length) |
|
86 |
# - added removal of params on multiple files |
|
87 |
# - disabled code to create different plot/output names on -d/-u |
|
88 |
# - added -q)uatorial cutoff lat |
|
89 |
# Apr 1, 2016: - cosmetics |
|
90 |
# Apr 2, 2016: - added low-p0 power-law fit as alternative |
|
91 |
# Apr 3, 2016: - removed low-p0 power-law fit as it was not well thought out |
|
92 |
# - changed -l default from 1e-7 to 5e-8, which agrees better with GHP |
|
93 |
# solution without latiudinal dependency in case of 2016 I08S |
|
94 |
# - define own LADCP_wspec defaults here |
|
95 |
# - changed default of -q from 5 to 3 |
|
96 |
# Apr 6, 2016: - cosmetics |
|
44 | 97 |
# Apr 16, 2016: - assertion failed on I98S#153 => modify code to allow nans in LADCP_wspec |
98 |
# output |
|
99 |
# Apr 27, 2016: - cosmetics (usage message) |
|
48 | 100 |
# Aug 16, 2016: - increased -l default to 1.2e-7 based on UK2.5 SR1 repeat section |
101 |
# Sep 1, 2016: - changed -l to mean epsilon, and increased value to 1e-10 |
|
102 |
# - added %eps.minlim |
|
103 |
# Mar 13, 2017: - added -a)mbient <eps> |
|
104 |
# Mar 14, 2017: - disabled -a) by default, because -a 0 is clearly bad and |
|
105 |
# I have no evidence yet that -a something is better than -l 0 |
|
49 | 106 |
# Oct 17, 2017: - added default 'eps' field on -k |
107 |
# - added eps.ms field to files processed without -k |
|
108 |
# Dec 9, 2017: - added support for $antsSuppressCommonOptions |
|
109 |
# Apr 24, 2018: - BUG: output was one field too wide (filled with nans) because antsBufNFields was not reset |
|
110 |
# Apr 25, 2018: - added -y and removed spectral bins from default output |
|
54 | 111 |
# Sep 12, 2019: - disabled default -l cut-off (used to be 5e-11 W/kg) |
56 | 112 |
# Jul 1, 2021: - made %PARAMs more standard |
113 |
# Jul 23, 2021: - returned to published empirical calibration constant (20% difference is not significant) |
|
114 |
# - added calibration constant to output metadata |
|
115 |
# - changed opt_a default from nan to 0 (ambient mixing) |
|
116 |
# - BUG: -z default was only 1, which means that -k20 from LADCP_w_ocean applies; in |
|
117 |
# practice I found with A20 that there are the effective value is >60; which means |
|
118 |
# that this bug did not matter much in practice |
|
119 |
# - changed calibration constant back, because it makes sense, and because it is now |
|
120 |
# recorded in the meta-data |
|
121 |
# HISTORY END |
|
18 | 122 |
|
123 |
($ANTSLIB) = (`which ANTSlib` =~ m{^(.*)/[^/]*$}); |
|
33 | 124 |
($WCALC) = ($0 =~ m{^(.*)/[^/]*$}); |
125 |
$WCALC = '.' if ($WCALC eq ''); |
|
26
b89d4b01fcc5
after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
126 |
$ANTS_TOOLS_AVAILABLE = (`which list` ne ''); |
b89d4b01fcc5
after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
127 |
|
33 | 128 |
require "$WCALC/version.pl"; |
18 | 129 |
require "$ANTSLIB/ants.pl"; |
130 |
require "$ANTSLIB/libLADCP.pl"; |
|
29 | 131 |
require "$ANTSLIB/libGMT.pl"; |
43 | 132 |
&antsAddParams('LADCP_VKE::version',$VERSION); |
29 | 133 |
|
134 |
use FileHandle; |
|
135 |
use IPC::Open2; |
|
18 | 136 |
|
137 |
#---------------------------------------------------------------------- |
|
43 | 138 |
# Empirical constants & defaults |
42 | 139 |
#---------------------------------------------------------------------- |
140 |
||
43 | 141 |
#my($c) = 0.0215; # Thurnherr et al. (GRL 2015) |
56 | 142 |
my($c) = 0.026; # increased by 21% for V1.2beta7 |
43 | 143 |
$opt_q = 3; # Equatorial band: little more than a guess based on 2015 P16N |
54 | 144 |
$opt_l = 0; # [W/kg]; cutoff disabled Sep 12, 2019 |
56 | 145 |
$opt_a = 0; # assume background dissipation for samples that pass the tests but have eps below -l |
146 |
$opt_z = 50; # number of w_ocean samples to require (note that the .wprof inputs may have harsher limits) |
|
43 | 147 |
$opt_o = 0; # remove mean before calculating spectra |
148 |
$opt_s = 150; # surface layer to exclude from spectra |
|
149 |
$opt_g = 40; # max gap to interpolate over |
|
150 |
$opt_c_default = 100; # short-wavelength cutoff |
|
42 | 151 |
|
152 |
#---------------------------------------------------------------------- |
|
18 | 153 |
# Usage |
154 |
#---------------------------------------------------------------------- |
|
155 |
||
49 | 156 |
$antsSuppressCommonOptions = 1; |
157 |
&antsUsage('a:bc:de:f:g:i:k:l:mno:p:q:r:s:tuw:x:yz:',0, |
|
43 | 158 |
"[poly-o)rder <n[$opt_o]> to de-mean data; -1 to disable>] [apply cosine-t)aper]", |
29 | 159 |
'[-d)own/-u)pcast-only] [exclude -b)ottom window]', # LADCP_wspec options |
43 | 160 |
"[-s)urface <layer depth to exclude[${opt_s}m]>", |
161 |
"[-g)ap <max depth layer to fill with interpolation[${opt_g}m]>]", |
|
29 | 162 |
'[-w)indow <power-of-two input-records[32]>]', |
44 | 163 |
"[shortwave -c)utoff <kz or lambda[${opt_c_default}m]>]", # LADCP_VKE options |
48 | 164 |
"[e-q)uatorial cutoff <latitude[${opt_q}deg]>]", |
165 |
"[-l)ow-eps <cutoff[${opt_l} W/kg]>] [-a)mbient <eps[${opt_a} W/kg]>]", |
|
43 | 166 |
"[-z) ignore velocities derived from fewer than <N[$opt_z]> samples]", |
29 | 167 |
'[o-m)it spectral correction] [spectral-tilt-correction -r)ange <max[0m]>]', |
43 | 168 |
"[-e)ps-parameterization <constant[${c}s^-0.5]>", |
48 | 169 |
'[include microstructure -k)e dissipation <file:field> in _VKE plot]', |
49 | 170 |
'[-y) record spectra in output file]', |
48 | 171 |
'[write output -f)iles to <directory>]', |
172 |
'[write output filed with -i)ndividual spectra <basename>]', |
|
173 |
'[output -p)lot <ps-file[#_VKE.ps]>]', |
|
43 | 174 |
'[file...]'); |
29 | 175 |
|
43 | 176 |
#---------------------------------------------------------------------------- |
177 |
# Calculate VKE spectra with [LADCP_wspec] if input is a set of w_ocean files |
|
178 |
#---------------------------------------------------------------------------- |
|
42 | 179 |
|
43 | 180 |
my($widx_min) = 99; # sentinels |
181 |
my($widx_max) = -99; |
|
18 | 182 |
|
42 | 183 |
if (defined(fnrNoErr('dc_w'))) { # pre-process with LADCP_wspec when handed vertical-velocity input |
43 | 184 |
&antsInstallBufFull('eof'); # read first file |
185 |
&antsIn(); |
|
186 |
||
187 |
my($opts); # set up options to pass |
|
188 |
$opts .= ' -d' if ($opt_d); |
|
29 | 189 |
$opts .= ' -u' if ($opt_u); |
190 |
$opts .= ' -b' if ($opt_b); |
|
191 |
$opts .= ' -t' if ($opt_t); |
|
192 |
$opts .= " -s $opt_s" if defined($opt_s); |
|
193 |
$opts .= " -g $opt_g" if defined($opt_g); |
|
194 |
$opts .= " -w $opt_w" if defined($opt_w); |
|
195 |
$opts .= " -o $opt_o" if defined($opt_o); |
|
43 | 196 |
|
42 | 197 |
open2(\*FROMCLD,\*TOCLD,"LADCP_wspec $opts") || # spawn sub-process |
29 | 198 |
croak("LADCP_wspec $opts: $!\n"); |
43 | 199 |
print(TOCLD $antsOldHeaders); # feed already gobbled header |
200 |
for (my($r)=0; $r<@ants_; $r++) { # feed all .wprof records to LADCP_wspec |
|
201 |
print(TOCLD "@{$ants_[$r]}\n"); |
|
202 |
} |
|
203 |
||
204 |
for (my($bufi)=0; defined($ARGV[0]); $bufi++) { # multiple input files: loop until 2nd last |
|
205 |
$input_list .= "$P{profile_id}($P{run_label}) "; |
|
206 |
if ($bufi == 0) { # do once for mulitple files |
|
207 |
&antsAddParams('ADCP_bin_length','','ADCP_blanking_distance','', # delete most %PARAMs, leaving |
|
208 |
'ADCP_frequency','','ADCP_orientation','', # only potentially useful ones (from last file): |
|
56 | 209 |
'ADCP_pulse_length','','BT_bin_range_diff.max','', # %profile_id |
210 |
'BT_range.max','','BT_w_error.max','', # %water_depth |
|
211 |
'BT_w_discrepancy.rms','','CTD_time_lags','', # %lat |
|
43 | 212 |
'LADCP_firstBin','','LADCP_lastBin','', # %lon |
56 | 213 |
'LADCP_w_ocean::version','','SS_samp.min','', # %dnXX |
214 |
'SS_allowed_depth_range.max','','SS_signal.min','', |
|
215 |
'Sv_ref_bin','','TL_allowed_three_lag_spread.max','', |
|
216 |
'dc_pkg_accel.rms','','dc_tilt.rms','', |
|
217 |
'uc_pkg_accel.rms','','uc_tilt.rms','', |
|
218 |
'depth.max','','elapsed.max','','ens.max','', |
|
219 |
'depth.min','','elapsed.min','','ens.min','', |
|
43 | 220 |
'out_basename','','outgrid_dz','','run_label','', |
221 |
'outgrid_firstbin','','outgrid_lastbin','', |
|
222 |
'outgrid_minsamp','','per_bin_valid_frac_lim','', |
|
223 |
'processing_options','','refLr_firstBin','', |
|
224 |
'refLr_lastBin','','rms_w_reflr_err','', |
|
225 |
'rms_w_reflr_err_interior','', |
|
226 |
'sidelobe_editing','','surface_layer_depth','', |
|
56 | 227 |
'vessel_draft','','w_lim.max','', |
43 | 228 |
'water_depth.sig','','water_depth_from','', |
229 |
); |
|
230 |
} |
|
231 |
close(TOCLD); # close LADCP_VKE input |
|
232 |
my(@specrec); |
|
233 |
while (@specrec = &antsFileIn(FROMCLD)) { |
|
234 |
my($i) = ($specrec[$widxf]>0) ? $specrec[$widxf] : 0; |
|
235 |
@{$specbuf[$bufi][$i]} = @specrec; |
|
44 | 236 |
# print(STDERR "specrec[$i] = @specrec\n"); |
43 | 237 |
} |
238 |
close(FROMCLD); |
|
44 | 239 |
# printf(STDERR "windows up to %d buffered\n",$#{$specbuf[$bufi]}); |
43 | 240 |
|
241 |
$antsBufSkip = @ants_; |
|
242 |
&antsIn(); # read next .wprof file |
|
243 |
open2(\*FROMCLD,\*TOCLD,"LADCP_wspec $opts") || # process it |
|
244 |
croak("LADCP_wspec $opts: $!\n"); |
|
245 |
print(TOCLD $antsOldHeaders); |
|
246 |
for (my($r)=0; $r<@ants_; $r++) { |
|
247 |
print(TOCLD "@{$ants_[$r]}\n"); |
|
248 |
} |
|
249 |
} |
|
250 |
||
251 |
close(TOCLD); # connect stdout from LADCP_VKE to stdin |
|
29 | 252 |
open(STDIN,"<&FROMCLD") || croak("dup(FROMCLD): $!\n"); |
253 |
close(FROMCLD); |
|
43 | 254 |
<>; # clear EOF condition |
255 |
||
42 | 256 |
undef(%P); # shouldn't matter, because we'll get the same %PARAMs back |
257 |
undef(@antsLayout); # shouldn't matter, because it will get overwritten |
|
43 | 258 |
undef($antsOldHeaders); # forget those |
259 |
undef(@ants_); |
|
49 | 260 |
$antsBufNFields = 0; |
43 | 261 |
|
262 |
} elsif (defined(fnrNoErr('pwrdens.0'))) { |
|
263 |
croak("$0: -d, -u, -b, -w, -s meaningless when $0 used with spectral input\n") |
|
264 |
if ($opt_d || $opt_u || $opt_b || defined($opt_w) || defined($opt_s) || defined($opt_g)); |
|
29 | 265 |
} else { |
266 |
if ($ARGV[0]) { |
|
267 |
croak("$ARGV[0]: no such file or directory\n"); |
|
268 |
} else { |
|
269 |
croak("$0: empyt input\n"); |
|
270 |
} |
|
271 |
} |
|
18 | 272 |
|
29 | 273 |
#---------------------------------------------------------------------- |
43 | 274 |
# Handle LADCP_VKE usage & read spectra from final file |
275 |
# - spectra from previous files are in @specbuf |
|
29 | 276 |
#---------------------------------------------------------------------- |
277 |
||
43 | 278 |
$n_input_files = 1 + @specbuf; # number of input files provided |
279 |
||
56 | 280 |
&antsFloatOpt(\$opt_e,$c); # default parameterization |
281 |
&antsFloatOpt(\$opt_x,1); # spectral fit stddev scale factor |
|
282 |
||
43 | 283 |
&antsAddParams('LADCP_VKE::input_files.n',$n_input_files, |
48 | 284 |
'LADCP_VKE::wsamp.min',$opt_z, |
56 | 285 |
'LADCP_VKE::eps.minlim',$opt_l, |
286 |
'LADCP_VKE::calibration_constant',$opt_e); |
|
18 | 287 |
|
42 | 288 |
if (defined($opt_c)) { # shortwave cutoff supplied |
29 | 289 |
$lmin = ($opt_c < 1) ? 2*$PI/$opt_c : $opt_c; |
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
290 |
&antsAddParams('LADCP_VKE::shortwave_cutoff',2*$PI/$lmin); # ensure eps.VKE is calculated below |
42 | 291 |
} elsif (defined(antsParam('shortwave_cutoff'))) { # cutoff already applied |
29 | 292 |
$lmin = 2*$PI/antsParam('shortwave_cutoff'); |
42 | 293 |
} else { # use 100m default cutoff |
43 | 294 |
$lmin = $opt_c_default; |
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
295 |
&antsAddParams('LADCP_VKE::shortwave_cutoff',2*$PI/$lmin); # ensure eps.VKE is calculated below |
29 | 296 |
} |
42 | 297 |
$lmax = 9e99; # no longwave cutoff implemented yet |
29 | 298 |
|
42 | 299 |
&antsInstallBufFull(0); # load entire file |
29 | 300 |
&antsIn(); |
43 | 301 |
$P{run_label} = "$input_list$P{profile_id}($P{run_label})" |
302 |
if ($n_input_files > 1); |
|
303 |
||
304 |
my($Hbuf) = $antsOldHeaders; # save for later (used on -i) |
|
29 | 305 |
|
306 |
&antsRequireParam('profile_id'); |
|
307 |
&antsRequireParam('lambda.1'); |
|
308 |
&antsRequireParam('k.1'); |
|
309 |
&antsRequireParam('resolution_bandwidth'); |
|
310 |
&antsRequireParam('input_depth_resolution'); |
|
311 |
&antsRequireParam('output_depth_resolution'); |
|
312 |
&antsRequireParam('ADCP_bin_length'); |
|
313 |
&antsAddParams('ADCP_pulse_length',antsParam('ADCP_bin_length')) |
|
314 |
unless defined(antsParam('ADCP_pulse_length')); |
|
315 |
||
42 | 316 |
$imin = 0; # find frequency bin limits |
29 | 317 |
for ($nfreq=1; defined(antsParam("lambda.$nfreq")); $nfreq++) { |
318 |
$imin = $nfreq if ($imin==0 && antsParam("lambda.$nfreq")<=$lmax); |
|
319 |
$imax = $nfreq if (antsParam("lambda.$nfreq") >= $lmin); |
|
18 | 320 |
} |
321 |
croak("$0: <lambda.min=$lmin> < min(lambda)") |
|
322 |
unless defined($imax); |
|
323 |
||
324 |
$pg_fmin = fnr('pwrdens.0'); # first power field in spectra |
|
325 |
$fs_fmin = $pg_fmin + $imin; # first power field in finescale range |
|
326 |
$fs_fmax = $pg_fmin + $imax; # last power field in finescale range |
|
327 |
||
29 | 328 |
$widxf = fnr('widx'); |
43 | 329 |
$df = fnr('depth'); |
18 | 330 |
$mindf = fnr('depth.min'); |
331 |
$maxdf = fnr('depth.max'); |
|
42 | 332 |
$wsf = fnr('w.nsamp.avg'); |
43 | 333 |
$doff = fnr('nspec'); |
18 | 334 |
|
335 |
#---------------------------------------------------------------------- |
|
29 | 336 |
# Redirect STDOUT & create plot if STDOUT is a tty |
18 | 337 |
#---------------------------------------------------------------------- |
338 |
||
29 | 339 |
if (-t STDOUT) { |
33 | 340 |
$opt_f = '.' unless defined($opt_f); # output directory |
341 |
croak("$opt_f: not a directory\n") unless (-d $opt_f); |
|
342 |
||
29 | 343 |
my($id) = &antsRequireParam('profile_id'); |
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
344 |
|
43 | 345 |
# if ($opt_d) { |
346 |
# $opt_p = sprintf('%s/%03d_dc_VKE.ps',$opt_f,$id) unless defined($opt_p); |
|
347 |
# $outfile = sprintf('%s/%03d_dc.VKE',$opt_f,$id); |
|
348 |
# } elsif ($opt_u) { |
|
349 |
# $opt_p = sprintf('%s/%03d_uc_VKE.ps',$opt_f,$id) unless defined($opt_p); |
|
350 |
# $outfile = sprintf('%s/%03d_uc.VKE',$opt_f,$id); |
|
351 |
# } else { |
|
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
352 |
$opt_p = sprintf('%s/%03d_VKE.ps',$opt_f,$id) unless defined($opt_p); |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
353 |
$outfile = sprintf('%s/%03d.VKE',$opt_f,$id); |
43 | 354 |
# } |
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
355 |
$outfile =~ s@^./@@; |
29 | 356 |
open(STDOUT,">$outfile") || die("$outfile: $!\n"); |
33 | 357 |
} elsif (defined($opt_f)) { |
358 |
croak("-f can only be used without STDOUT redirection\n"); |
|
29 | 359 |
} |
360 |
||
361 |
#---------------------------------------------------------------------- |
|
362 |
# Library |
|
363 |
#---------------------------------------------------------------------- |
|
364 |
||
43 | 365 |
sub average_spectra($) |
366 |
{ |
|
367 |
my($r) = @_; |
|
368 |
for (my($f)=$fs_fmin-1; $f<=$fs_fmax; $f++) { # average w.nsamp.avg & spectral densities |
|
369 |
my($sum) = my($ns) = 0; |
|
370 |
if (numberp($ants_[$r][$f])) { # final file has valid spectra |
|
371 |
$sum = $ants_[$r][$f]; $ns = 1; # NB: nspec is correct even if it doesn't |
|
372 |
} |
|
373 |
my($wi) = ($ants_[$r][$widxf]>0) ? $ants_[$r][$widxf] : 0; # adjust for -1 |
|
374 |
for (my($bi)=0; $bi<@specbuf; $bi++) { # loop over all buffered files |
|
375 |
next unless @{$specbuf[$bi][$wi]}; # skip input files w/o valid spectra |
|
376 |
if (abs($specbuf[$bi][$wi][$df] - $ants_[$r][$df]) > 0) { # depth mismatch |
|
56 | 377 |
# die("assertion failed ($specbuf[$bi][$wi][$df] - $ants_[$r][$df] @ wi=$wi)") unless ($wi == 0); # only allowed in bottom window |
43 | 378 |
if (abs($specbuf[$bi][$wi][$df] - $ants_[$r][$df]) > |
379 |
abs($ants_[$r][$maxdf] - $ants_[$r][$mindf])) { |
|
56 | 380 |
printf(STDERR "WARNING: ignoring window #$wi from input file #%d because of depth mismatch\n",$bi+1) |
43 | 381 |
if ($f == $fs_fmin); |
382 |
next; |
|
383 |
} |
|
384 |
} |
|
44 | 385 |
if (numberp($specbuf[$bi][$wi][$f])) { |
386 |
$sum += $specbuf[$bi][$wi][$f]; $ns++; |
|
387 |
} |
|
43 | 388 |
$ants_[$r][$doff] += $specbuf[$bi][$wi][$doff] # update nspec once per input record |
389 |
if ($f == $fs_fmax); # ... but for all files |
|
390 |
} |
|
44 | 391 |
$ants_[$r][$f] = ($ns > 0) ? $sum/$ns : nan; # update averaged spectral density |
43 | 392 |
} |
393 |
} |
|
394 |
||
395 |
sub integrate_fs_power($) # integrate fs spectrum |
|
18 | 396 |
{ |
397 |
my($r) = @_; |
|
398 |
||
399 |
$ants_[$r][$fspwrf] = 0; |
|
400 |
for (my($f)=$fs_fmin; $f<=$fs_fmax; $f++) { |
|
29 | 401 |
$ants_[$r][$fspwrf] += $ants_[$r][$f]; |
18 | 402 |
} |
29 | 403 |
$ants_[$r][$fspwrf] *= antsParam('resolution_bandwidth'); |
18 | 404 |
} |
405 |
||
406 |
||
42 | 407 |
sub fit_universal_w_spec($) # vertical velocity => p0 |
18 | 408 |
{ |
409 |
my($r) = @_; |
|
410 |
my($nsamp) = $fs_fmax - $fs_fmin + 1; |
|
411 |
||
412 |
#--------------------------------------------------- |
|
413 |
# fit slope-2 line in log-log space (main estimator) |
|
414 |
#--------------------------------------------------- |
|
415 |
||
42 | 416 |
if ($nsamp >= 2) { # require min 2 wavenumber samples |
18 | 417 |
|
43 | 418 |
my($DOF) = 0; |
419 |
||
42 | 420 |
my($sumd,$sumx,$sumy) = (0,0,0); # fit kz^-2 power law |
421 |
for (my($f)=$fs_fmin; $f<=$fs_fmax; $f++) { |
|
18 | 422 |
my($i) = $f - $pg_fmin; |
29 | 423 |
$sumx += log10(antsParam("k.$i")); |
18 | 424 |
$sumy += log10($ants_[$r][$f]); |
43 | 425 |
$sumd += log10($ants_[$r][$f]) + 2*log10(antsRequireParam("k.$i")); |
18 | 426 |
} |
427 |
my($p0) = $sumd/$nsamp; |
|
428 |
$ants_[$r][$p0f] = 10**$p0; |
|
429 |
||
42 | 430 |
my($avgx) = $sumx/$nsamp; # avg for r calc |
18 | 431 |
my($avgy) = $sumy/$nsamp; |
42 | 432 |
my($sumsqerr,$sxx,$syy,$sxy,$sumsqxt,$sumx,$sumy,$sumwt) = # r, rms error, pwrlaw slope |
433 |
(0,0,0,0,0,0,0,0); |
|
18 | 434 |
for (my($f)=$fs_fmin; $f<=$fs_fmax; $f++) { |
42 | 435 |
my($i) = $f - $pg_fmin; |
436 |
my($x) = log10(&antsParam("k.$i")); |
|
437 |
my($y) = log10($ants_[$r][$f]); |
|
43 | 438 |
my($ysig) = $opt_x * $y / sqrt($ants_[$r][$doff]); |
42 | 439 |
my($xt) = $x - $avgx; $sxx += &SQR($xt); # correlation coeff (r) |
440 |
my($yt) = $y - $avgy; $syy += &SQR($yt); $sxy += $xt * $yt; |
|
441 |
my($wt) = 1 / &SQR($ysig); $sumwt += $wt; # slope (linear fit in log-log space) |
|
442 |
$sumx += $x * $wt; |
|
443 |
$sumy += $y * $wt; |
|
444 |
$sumsqerr += ($p0 - 2*$x - $y)**2; # rms error |
|
18 | 445 |
} |
42 | 446 |
my($midx) = $sumx / $sumwt; |
447 |
# print(STDERR "$sumx:$sumy:$sumwt\n"); |
|
448 |
# print(STDERR "$midx\n"); |
|
449 |
my($sumsqdx,$sumslp) = (0,0); |
|
450 |
for (my($f)=$fs_fmin; $f<=$fs_fmax; $f++) { |
|
451 |
my($i) = $f - $pg_fmin; |
|
452 |
my($x) = log10(&antsParam("k.$i")); |
|
453 |
my($y) = log10($ants_[$r][$f]); |
|
43 | 454 |
my($ysig) = $opt_x * $y / sqrt($ants_[$r][$doff]); |
42 | 455 |
my($dx) = ($x - $midx) / $ysig; |
456 |
$sumsqdx += &SQR($dx); |
|
457 |
$sumslp += $dx * $y / $ysig; |
|
458 |
} |
|
459 |
$ants_[$r][$rmsf] = sqrt($sumsqerr/$nsamp); |
|
460 |
$ants_[$r][$rf] = $sxy/(sqrt($sxx * $syy) + $SMALL_AMOUNT); |
|
461 |
$ants_[$r][$slpf] = $sumslp / $sumsqdx; |
|
462 |
$ants_[$r][$sslpf] = sqrt(1 / $sumsqdx); |
|
18 | 463 |
|
464 |
} else { |
|
465 |
&antsInfo("WARNING: no fit --- need min 2 samples"); |
|
466 |
} |
|
42 | 467 |
} |
468 |
||
469 |
#---------------------------------------------------------------------- |
|
470 |
# Load Dissipation Data |
|
471 |
#---------------------------------------------------------------------- |
|
472 |
||
473 |
my(@eps_ms,@depth_ms); # output variables |
|
474 |
if (defined($opt_k)) { |
|
475 |
my($file,$field) = split(':',$opt_k); |
|
49 | 476 |
$field = 'eps' unless defined($field); |
42 | 477 |
open(ADDF,"$file") || croak("$file: $!\n"); # open file |
478 |
my(@afl) = &antsFileLayout(ADDF); # read layout |
|
479 |
my($akf,$aef); |
|
480 |
for (my($f)=0; $f<=$#afl; $f++) { # find depth & eps fields |
|
481 |
$akf = $f if ($afl[$f] eq 'depth'); |
|
482 |
$aef = $f if ($afl[$f] eq $field); |
|
483 |
} |
|
484 |
croak("$file: fields 'depth' and '$field' required\n") |
|
485 |
unless defined($akf) && defined($aef); |
|
486 |
while (1) { # load entire profile |
|
487 |
my(@ar); |
|
488 |
last unless @ar = &antsFileIn(ADDF); |
|
489 |
next unless numberp($ar[$akf]) && numberp($ar[$aef]); |
|
490 |
push(@depth_ms,$ar[$akf]); push(@eps_ms,$ar[$aef]); |
|
491 |
} |
|
492 |
close(ADDF); |
|
18 | 493 |
} |
494 |
||
495 |
#---------------------------------------------------------------------- |
|
496 |
# Process File |
|
497 |
#---------------------------------------------------------------------- |
|
498 |
||
43 | 499 |
$fspwrf = &antsNewField('pwr.fs'); # derived fields |
18 | 500 |
|
42 | 501 |
$p0f = &antsNewField('p0'); # VKE density |
502 |
$rmsf = &antsNewField('p0fit.rms'); # rms misfit |
|
503 |
$rf = &antsNewField('p0fit.r'); # correlation coefficient |
|
504 |
$slpf = &antsNewField('p0fit.slope'); # power-law slope |
|
505 |
$sslpf = &antsNewField('p0fit.slope.sig'); # power-law slope stddev |
|
506 |
$wepsf = &antsNewField('eps.VKE'); # epsilon from VKE |
|
49 | 507 |
$msepsf = &antsNewField('eps.ms'); # externally supplied microstructure eps if available |
18 | 508 |
|
509 |
my(@outLayout) = @antsNewLayout; # save for later |
|
510 |
for ($f=0; $f<@outLayout; $f++) { # determine last spectral field in input |
|
511 |
$totf = $f if ($outLayout[$f] eq 'pwr.tot'); |
|
512 |
$tnsf = $f if ($outLayout[$f] eq 'pwr.tot.nsamp'); |
|
513 |
} |
|
514 |
croak("$0: cannot find fields 'pwr.tot' or 'pwr.tot.nsamp' in input\n") |
|
515 |
unless defined($totf) || defined($tnsf); |
|
29 | 516 |
$lsf = defined($tnsf) ? $tnsf : $totf; |
18 | 517 |
|
29 | 518 |
if ($opt_p) { # begin plot |
519 |
$xmin = (&antsParam('output_depth_resolution')>=350) ? 0.012 : 0.018; |
|
520 |
$xmax = 0.2; $ymin = 1; $ymax = 1e4; |
|
521 |
$plotsize = 13; |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
522 |
GMT_begin($opt_p,"-JX${plotsize}l","-R$xmin/$xmax/$ymin/$ymax",'-P -X6 -Y4'); # init plot |
29 | 523 |
GMT_psxy('-G25/255/25 -L'); |
524 |
printf(GMT "%f %f\n",$xmin,$xmin**(-2)*sqrt(2)); |
|
525 |
printf(GMT "%f %f\n",$xmax,$xmax**(-2)*sqrt(2)); |
|
526 |
printf(GMT "%f %f\n",$xmax,$xmax**(-2)/sqrt(2)); |
|
527 |
printf(GMT "%f %f\n",$xmin,$xmin**(-2)/sqrt(2)); |
|
528 |
} |
|
529 |
||
530 |
my(@sumPwr,@nPwr); |
|
531 |
my(@sumGoodPwr,@nGoodPwr); |
|
532 |
my($min_depth) = 9e99; |
|
533 |
my($max_depth) = -9e99; |
|
18 | 534 |
|
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
535 |
my($latM) = abs(&antsRequireParam('lat')); |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
536 |
&antsInfo("WARNING: low latitude-profile no epsilon estimated") |
43 | 537 |
unless ($latM > $opt_q); |
18 | 538 |
|
43 | 539 |
for (my($r)=0; $r<@ants_; $r++) { # loop over all windows |
540 |
||
541 |
if (numberp($ants_[$r][$pg_fmin])) { # there is a spectrum |
|
18 | 542 |
|
43 | 543 |
#-------------------------- |
544 |
# apply spectral correction |
|
545 |
#-------------------------- |
|
546 |
||
547 |
unless ($opt_m) { |
|
548 |
for (my($i)=0; $i<$nfreq; $i++) { # loop over wavenumbers |
|
549 |
$ants_[$r][$i+$pg_fmin] *= |
|
550 |
T_w(antsParam("k.$i"),antsParam('ADCP_bin_length'), |
|
551 |
antsParam('ADCP_pulse_length'),antsParam('input_depth_resolution'), |
|
552 |
$opt_r); |
|
553 |
} |
|
554 |
} |
|
555 |
||
556 |
#------------------------ |
|
557 |
# calculate fs quantities |
|
558 |
#------------------------ |
|
559 |
||
560 |
average_spectra($r); # average all avaiable spectra |
|
561 |
integrate_fs_power($r); # calculate total finescale power |
|
562 |
fit_universal_w_spec($r); # fit kz^-2 spectrum & calc stats |
|
563 |
||
564 |
if (numberp($ants_[$r][$p0f])) { # update min/max depth |
|
565 |
$min_depth = $ants_[$r][$mindf] if ($ants_[$r][$mindf] < $min_depth); |
|
566 |
$max_depth = $ants_[$r][$maxdf] if ($ants_[$r][$maxdf] > $max_depth); |
|
18 | 567 |
} |
568 |
||
43 | 569 |
} else { # no spectrum |
570 |
$ants_[$r][$fspwrf] = $ants_[$r][$p0f] = $ants_[$r][$rmsf] = |
|
571 |
$ants_[$r][$rf] = $ants_[$r][$slpf] = $ants_[$r][$sslpf] = nan; |
|
42 | 572 |
} |
573 |
||
574 |
#----------------------------------------------------------------------------------------------------- |
|
56 | 575 |
# eps.VKE QC Tests: |
42 | 576 |
# - the following limits were independently derived |
577 |
# p0fit.rms <= 0.4 primary filter used in Thurnherr et al. (GRL 2015) |
|
578 |
# -3 <= p0fit.slope <= -1 based largely on 2016 I08S data with sufficient/insufficient range |
|
579 |
# p0fit.r <= -0.5 based largely on 2016 I08S data with sufficient/insufficient range |
|
580 |
# w.nsamp.avg >= 50 based on observations in many data sets with weak backscatter, |
|
581 |
# including DoMORE, GO-SHIP P16S, GO-SHIP I08S |
|
582 |
# - then, I plotted slope & r vs. rms and found that rms = 0.4 corresponds to, on average |
|
583 |
# -3 <= p0fit.slope <= -1 |
|
584 |
# p0fit.r <= -0.4 |
|
585 |
# - in a plot of rms vs nsamp the limiting value of 0.4 is hit at 50 samples |
|
586 |
# |
|
54 | 587 |
# => SET OF MUTUALLY CONSISTENT CRITERIA |
42 | 588 |
# |
589 |
# Additional Empirical Filters: |
|
43 | 590 |
# - latitude > 3deg guess based on Thurnherr et al., 2015, Gregg et al., 2003, 2015 GO-SHIP P16N |
54 | 591 |
# - eps >= 5e-11 W/kg based on DIMES data, cutting where errors become > factor 2; DISABLED SEPTEMBER 2019 |
42 | 592 |
#----------------------------------------------------------------------------------------------------- |
593 |
||
48 | 594 |
if ($latM > $opt_q && # 1) not (too) equatorial |
595 |
$ants_[$r][$rmsf] <= 0.4 && # 2) rms spectra misfit <= 0.4 (as in Thurnherr et al., GRL 2015) |
|
596 |
$ants_[$r][$slpf]>=-3 && $ants_[$r][$slpf]<=-1 && # 3) slope consistent with -2 power law |
|
597 |
$ants_[$r][$rf] <= -0.4 && # 4) p and k_z are well correlated |
|
598 |
$ants_[$r][$wsf] >= $opt_z) { # 5) minimum # of samples |
|
599 |
if (($ants_[$r][$p0f]/$opt_e)**2 >= $opt_l) { # level is above eps.minlim (-l) |
|
600 |
$ants_[$r][$wepsf] = ($ants_[$r][$p0f] / $opt_e)**2; # => Thurnherr et al. (GRL 2015) |
|
601 |
} else { # level is below eps.minlim |
|
602 |
$ants_[$r][$wepsf] = $opt_a; # => set to arbitrary background value |
|
603 |
} |
|
604 |
} else { # failed any of checks 1-5 => nan |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
605 |
$ants_[$r][$wepsf] = nan; |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
606 |
} |
29 | 607 |
|
42 | 608 |
#------------------------------------------------- |
609 |
# average external microstructure eps, if supplied |
|
610 |
#------------------------------------------------- |
|
611 |
||
612 |
if (defined($opt_k)) { |
|
613 |
my($sum,$n) = (0,0); |
|
614 |
for (my($i)=0; $i<@eps_ms; $i++) { # linearly search all eps records |
|
615 |
next unless $depth_ms[$i] >= $ants_[$r][$mindf] && |
|
616 |
$depth_ms[$i] <= $ants_[$r][$maxdf]; |
|
617 |
$sum += $eps_ms[$i]; $n++; |
|
618 |
} |
|
619 |
$ants_[$r][$msepsf] = $n ? $sum / $n : nan; |
|
49 | 620 |
} else { |
621 |
$ants_[$r][$msepsf] = nan; |
|
622 |
} |
|
18 | 623 |
|
624 |
#--------------- |
|
625 |
# produce output |
|
626 |
#--------------- |
|
627 |
||
29 | 628 |
if (defined($opt_p)) { # plot current spectrum on -p & calc mean |
629 |
my($R) = 0; # RGB map |
|
630 |
my($G) = int(200*(1-$r/@ants_)); |
|
631 |
my($B) = ($r < @ants_/2) ? 150 : int(100+100*(1-$r/@ants_)); |
|
41 | 632 |
GMT_psxy("-W1,$R/$G/$B"); |
29 | 633 |
for (my($f)=$pg_fmin+1; $f<$pg_fmin+$nfreq; $f++) { # avg & plot high-quality spectra only |
634 |
next unless numberp($ants_[$r][$f]) && numberp($ants_[$r][$p0f]); # - omit zero wavenumber ($pg_fmin) |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
635 |
next unless numberp($ants_[$r][$wepsf]); |
29 | 636 |
my($k) = antsParam(sprintf("k.%d",$f-$pg_fmin)); |
637 |
printf(GMT "$k %g\n",$ants_[$r][$f]/$ants_[$r][$p0f]); |
|
638 |
$nGoodPwr[$f]++; |
|
639 |
$sumGoodPwr[$f] += $ants_[$r][$f]/$ants_[$r][$p0f]; |
|
640 |
} |
|
41 | 641 |
GMT_psxy("-W1,$R/$G/$B,."); # avg & plot all spectra with dots |
29 | 642 |
for (my($f)=$pg_fmin+1; $f<$pg_fmin+$nfreq; $f++) { |
643 |
next unless numberp($ants_[$r][$f]) && numberp($ants_[$r][$p0f]); |
|
644 |
my($k) = antsParam(sprintf("k.%d",$f-$pg_fmin)); |
|
645 |
printf(GMT "$k %g\n",$ants_[$r][$f]/$ants_[$r][$p0f]); |
|
646 |
$nPwr[$f]++; |
|
647 |
$sumPwr[$f] += $ants_[$r][$f]/$ants_[$r][$p0f]; |
|
648 |
} |
|
649 |
} |
|
650 |
||
651 |
||
652 |
if (defined($opt_i)) { # output current spectrum on -i |
|
18 | 653 |
open(STDOUT_DUP,">&",STDOUT) || croak("$0: cannot dup STDOUT\n"); |
654 |
@antsNewLayout = ('k','lambda','pwrdens','finescale','pwrdens_fit'); |
|
29 | 655 |
if ($ants_[$r][$widxf] > 0) { |
656 |
$ofname = sprintf("${opt_i}_%02d.wspec",$r+1); |
|
657 |
} else { |
|
658 |
$ofname = sprintf("${opt_i}_btm.wspec"); |
|
659 |
} |
|
18 | 660 |
open(STDOUT,">$ofname") || croak("$ofname: $!\n"); |
661 |
undef($antsOldHeaders); |
|
26
b89d4b01fcc5
after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
662 |
&antsActivateOut() if ($ANTS_TOOLS_AVAILABLE); |
18 | 663 |
|
664 |
my($saveParams) = $antsCurParams; # add all extra input fields as %PARAMs |
|
43 | 665 |
&antsAddParams('LADCP_VKE::depth.min',$ants_[$r][$mindf], |
666 |
'LADCP_VKE::depth.max',$ants_[$r][$maxdf]); |
|
18 | 667 |
for (my($f)=$lsf+1; $f<@outLayout; $f++) { |
43 | 668 |
&antsAddParams("LADCP_VKE::$outLayout[$f]",$ants_[$r][$f]); |
18 | 669 |
} |
670 |
||
29 | 671 |
for (my($f)=$pg_fmin+1; $f<$pg_fmin+$nfreq; $f++) { |
672 |
my($k) = antsParam(sprintf("k.%d",$f-$pg_fmin)); |
|
673 |
my($l) = antsParam(sprintf("lambda.%d",$f-$pg_fmin)); |
|
18 | 674 |
&antsOut($k,$l,$ants_[$r][$f], |
675 |
($f>=$fs_fmin && $f<=$fs_fmax), |
|
676 |
numberp($ants_[$r][$p0f]) ? $ants_[$r][$p0f] * $k**(-2) : nan); |
|
677 |
} |
|
678 |
||
679 |
&antsOut('EOF'); |
|
680 |
open(STDOUT,">&",STDOUT_DUP) || croak("$0: cannot restore STDOUT\n"); |
|
681 |
close(STDOUT_DUP); |
|
682 |
$antsCurParams = $saveParams; |
|
683 |
} |
|
684 |
} |
|
685 |
||
29 | 686 |
if (defined($opt_p)) { # complete plot |
687 |
if (@nPwr) { |
|
41 | 688 |
GMT_psxy('-W2,255/100/100,.'); # plot mean spectrum; dotted; entire range |
29 | 689 |
for (my($f)=$fs_fmin; $f<=$fs_fmax; $f++) { |
690 |
my($k) = antsParam(sprintf("k.%d",$f-$pg_fmin)); |
|
691 |
printf(GMT "$k %g\n",$sumPwr[$f]/$nPwr[$f]); |
|
692 |
} |
|
693 |
} |
|
694 |
||
695 |
if (@nGoodPwr) { |
|
41 | 696 |
GMT_psxy('-W1,255/100/100'); # plot mean spectrum; entire range |
29 | 697 |
for (my($f)=$pg_fmin+1; $f<$pg_fmin+$nfreq; $f++) { |
698 |
my($k) = antsParam(sprintf("k.%d",$f-$pg_fmin)); |
|
699 |
printf(GMT "$k %g\n",$sumGoodPwr[$f]/$nGoodPwr[$f]); |
|
700 |
} |
|
41 | 701 |
GMT_psxy('-W4,255/100/100'); # plot mean fs spectrum (heavy) |
29 | 702 |
for (my($f)=$fs_fmin; $f<=$fs_fmax; $f++) { |
703 |
my($k) = antsParam(sprintf("k.%d",$f-$pg_fmin)); |
|
704 |
printf(GMT "$k %g\n",$sumGoodPwr[$f]/$nGoodPwr[$f]); |
|
705 |
} |
|
706 |
} |
|
707 |
||
708 |
GMT_psbasemap('-Bf3a2:"Vertical Wavenumber [rad/m]":/' . # annotate axes |
|
709 |
'f3a1:"VKE/p@-0@- [m@+3@+s@+-1/2@+/(rad m@+-1@+)]":WeS'); |
|
710 |
GMT_setJ("-JX-${plotsize}l"); |
|
711 |
GMT_setR(sprintf('-R%f/%f/%f/%f',2*$PI/$xmax,2*$PI/$xmin,$ymin,$ymax)); |
|
712 |
GMT_psbasemap('-B3:"Vertical Wavelength [m]:N"'); |
|
713 |
||
30 | 714 |
GMT_unitcoords_logscale(); # print profile number |
43 | 715 |
GMT_pstext('-F+f14,Helvetica,blue+jTL -Gwhite'); |
716 |
if (defined($outfile)) { printf(GMT "0.02 0.98 $outfile [$P{run_label}] %s\n",antsParam('input_data')); } |
|
717 |
else { printf(GMT "0.02 0.98 %03d [$P{run_label}] %s\n",antsParam('profile_id'),antsParam('input_data')); } |
|
41 | 718 |
GMT_pstext('-F+f9,Helvetica,orange+jTR -N -Gwhite'); |
719 |
print(GMT "0.99 0.99 V$VERSION\n"); |
|
29 | 720 |
|
41 | 721 |
GMT_set('FONT_ANNOT_PRIMARY 10','MAP_ANNOT_OFFSET_PRIMARY 0.01c', # eps profile inset |
722 |
'FONT_LABEL 10','MAP_LABEL_OFFSET 0.2c'); |
|
29 | 723 |
$min_depth = 400 if ($min_depth > 1e4); |
724 |
$max_depth = 1500 if ($max_depth < 0); |
|
42 | 725 |
GMT_setR(sprintf("-R1e-11/1e-7/%d/%d",round($min_depth-250,500),round($max_depth+250,500))); |
29 | 726 |
GMT_setJ(sprintf('-JX%fl/-%f',$plotsize/2.2,$plotsize/2.2)); |
727 |
GMT_psbasemap('-X0.3 -Y0.3 -Bg1a1f3p:"@~e@~@-VKE@- [W kg@+-1@+]":/g1000a500f100:"Depth [m]":wEsN'); |
|
41 | 728 |
GMT_psxy(); |
29 | 729 |
for (my($r)=0; $r<@ants_; $r++) { |
42 | 730 |
my($R) = 0; my($G) = int(200*(1-$r/@ants_)); # calculate color ramp |
29 | 731 |
my($B) = ($r < @ants_/2) ? 150 : int(100+100*(1-$r/@ants_)); |
42 | 732 |
if (numberp($ants_[$r][$msepsf])) { # microstructure eps |
733 |
print(GMT "> -W1.5,DarkOrange2\n"); |
|
734 |
print(GMT "$ants_[$r][$msepsf] $ants_[$r][$mindf]\n"); |
|
735 |
print(GMT "$ants_[$r][$msepsf] $ants_[$r][$maxdf]\n"); |
|
736 |
} |
|
737 |
if (numberp($ants_[$r][$wepsf])) { |
|
738 |
print(GMT "> -W2,$R/$G/$B\n"); # plot eps.w in blue |
|
739 |
print(GMT "$ants_[$r][$wepsf] $ants_[$r][$mindf]\n"); |
|
740 |
print(GMT "$ants_[$r][$wepsf] $ants_[$r][$maxdf]\n"); |
|
741 |
} |
|
29 | 742 |
} |
743 |
GMT_end(); # finish plot |
|
744 |
} |
|
745 |
||
42 | 746 |
@antsNewLayout = @outLayout; # restore layout |
18 | 747 |
$antsOldHeaders = $Hbuf; |
748 |
$antsHeadersPrinted = 0; |
|
749 |
||
49 | 750 |
unless (defined($opt_y)) { # remove spectral bins from output |
751 |
splice(@antsNewLayout,$pg_fmin,$nfreq); |
|
752 |
for (my($r)=0; $r<@ants_; $r++) { |
|
753 |
splice(@{$ants_[$r]},$pg_fmin,$nfreq); |
|
754 |
} |
|
755 |
} |
|
756 |
||
757 |
&antsFlush(); # output results |
|
18 | 758 |
&antsExit(); |