author | A.M. Thurnherr <athurnherr@yahoo.com> |
Fri, 05 Aug 2016 11:02:51 -0400 | |
changeset 47 | 2ccb81b7cea5 |
parent 44 | 515c353a31bd |
child 48 | d9309804b6cf |
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 |
|
44 | 5 |
# dlm: Wed Apr 27 19:03:02 2016 |
18 | 6 |
# (c) 2012 A.M. Thurnherr |
44 | 7 |
# uE-Info: 99 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) |
|
18 | 100 |
|
101 |
($ANTSLIB) = (`which ANTSlib` =~ m{^(.*)/[^/]*$}); |
|
33 | 102 |
($WCALC) = ($0 =~ m{^(.*)/[^/]*$}); |
103 |
$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
|
104 |
$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
|
105 |
|
33 | 106 |
require "$WCALC/version.pl"; |
18 | 107 |
require "$ANTSLIB/ants.pl"; |
108 |
require "$ANTSLIB/libLADCP.pl"; |
|
29 | 109 |
require "$ANTSLIB/libGMT.pl"; |
43 | 110 |
&antsAddParams('LADCP_VKE::version',$VERSION); |
29 | 111 |
|
112 |
use FileHandle; |
|
113 |
use IPC::Open2; |
|
18 | 114 |
|
115 |
#---------------------------------------------------------------------- |
|
43 | 116 |
# Empirical constants & defaults |
42 | 117 |
#---------------------------------------------------------------------- |
118 |
||
43 | 119 |
#my($c) = 0.0215; # Thurnherr et al. (GRL 2015) |
120 |
my($c) = 0.026; # increased by 20% for V1.2beta7 |
|
121 |
$opt_q = 3; # Equatorial band: little more than a guess based on 2015 P16N |
|
122 |
$opt_l = 5e-8; # low-p0 tail; visually estimated from Fig. 2 of Thurnherr et al. (GRL 2015) |
|
123 |
$opt_z = 1; # number of w_ocean samples to require |
|
124 |
$opt_o = 0; # remove mean before calculating spectra |
|
125 |
$opt_s = 150; # surface layer to exclude from spectra |
|
126 |
$opt_g = 40; # max gap to interpolate over |
|
127 |
$opt_c_default = 100; # short-wavelength cutoff |
|
42 | 128 |
|
129 |
#---------------------------------------------------------------------- |
|
18 | 130 |
# Usage |
131 |
#---------------------------------------------------------------------- |
|
132 |
||
43 | 133 |
&antsUsage('bc:de:f:g:i:k:l:mno:p:q:r:s:tuw:x:z:',0, |
134 |
"[poly-o)rder <n[$opt_o]> to de-mean data; -1 to disable>] [apply cosine-t)aper]", |
|
29 | 135 |
'[-d)own/-u)pcast-only] [exclude -b)ottom window]', # LADCP_wspec options |
43 | 136 |
"[-s)urface <layer depth to exclude[${opt_s}m]>", |
137 |
"[-g)ap <max depth layer to fill with interpolation[${opt_g}m]>]", |
|
29 | 138 |
'[-w)indow <power-of-two input-records[32]>]', |
44 | 139 |
"[shortwave -c)utoff <kz or lambda[${opt_c_default}m]>]", # LADCP_VKE options |
43 | 140 |
"[e-q)uatorial cutoff <latitude[${opt_q}deg]>] [-l)ow-p0 <cutoff[${opt_l}m^2/s^2/(rad/m)]>]", |
141 |
"[-z) ignore velocities derived from fewer than <N[$opt_z]> samples]", |
|
29 | 142 |
'[o-m)it spectral correction] [spectral-tilt-correction -r)ange <max[0m]>]', |
43 | 143 |
# '[-l) override ADCP bin <length>] [-a) override pulse <length>]', |
144 |
"[-e)ps-parameterization <constant[${c}s^-0.5]>", |
|
145 |
'[-k)e dissipation <file:field>]', |
|
33 | 146 |
'[output -f)iles in <dir>]', |
29 | 147 |
'[output -i)ndividual spectra <basename>]', |
43 | 148 |
'[output -p)lot <ps-file>]', |
149 |
'[file...]'); |
|
29 | 150 |
|
43 | 151 |
#---------------------------------------------------------------------------- |
152 |
# Calculate VKE spectra with [LADCP_wspec] if input is a set of w_ocean files |
|
153 |
#---------------------------------------------------------------------------- |
|
42 | 154 |
|
43 | 155 |
my($widx_min) = 99; # sentinels |
156 |
my($widx_max) = -99; |
|
18 | 157 |
|
42 | 158 |
if (defined(fnrNoErr('dc_w'))) { # pre-process with LADCP_wspec when handed vertical-velocity input |
43 | 159 |
&antsInstallBufFull('eof'); # read first file |
160 |
&antsIn(); |
|
161 |
||
162 |
my($opts); # set up options to pass |
|
163 |
$opts .= ' -d' if ($opt_d); |
|
29 | 164 |
$opts .= ' -u' if ($opt_u); |
165 |
$opts .= ' -b' if ($opt_b); |
|
166 |
$opts .= ' -t' if ($opt_t); |
|
167 |
$opts .= " -s $opt_s" if defined($opt_s); |
|
168 |
$opts .= " -g $opt_g" if defined($opt_g); |
|
169 |
$opts .= " -w $opt_w" if defined($opt_w); |
|
170 |
$opts .= " -o $opt_o" if defined($opt_o); |
|
43 | 171 |
|
42 | 172 |
open2(\*FROMCLD,\*TOCLD,"LADCP_wspec $opts") || # spawn sub-process |
29 | 173 |
croak("LADCP_wspec $opts: $!\n"); |
43 | 174 |
print(TOCLD $antsOldHeaders); # feed already gobbled header |
175 |
# if (defined($opt_l) || defined($opt_a)) { # override bin size and/or pulse length |
|
176 |
# &antsAddParams('ADCP_bin_length',$opt_l) if defined($opt_l); |
|
177 |
# &antsAddParams('ADCP_pulse_length',$opt_a) if defined($opt_a); |
|
178 |
# print(TOCLD $antsCurParams); |
|
179 |
# } |
|
180 |
for (my($r)=0; $r<@ants_; $r++) { # feed all .wprof records to LADCP_wspec |
|
181 |
print(TOCLD "@{$ants_[$r]}\n"); |
|
182 |
} |
|
183 |
||
184 |
for (my($bufi)=0; defined($ARGV[0]); $bufi++) { # multiple input files: loop until 2nd last |
|
185 |
$input_list .= "$P{profile_id}($P{run_label}) "; |
|
186 |
if ($bufi == 0) { # do once for mulitple files |
|
187 |
&antsAddParams('ADCP_bin_length','','ADCP_blanking_distance','', # delete most %PARAMs, leaving |
|
188 |
'ADCP_frequency','','ADCP_orientation','', # only potentially useful ones (from last file): |
|
189 |
'ADCP_pulse_length','','BT_max_bin_range_diff','', # %profile_id |
|
190 |
'BT_max_range','','BT_max_w_error','', # %water_depth |
|
191 |
'BT_rms_w_discrepancy','','CTD_time_lags','', # %lat |
|
192 |
'LADCP_firstBin','','LADCP_lastBin','', # %lon |
|
193 |
'LADCP_w_ocean::version','','SS_min_samp','', # %dnXX |
|
194 |
'SS_max_allowed_depth_range','','SS_min_signal','', |
|
195 |
'Sv_ref_bin','','TL_max_allowed_three_lag_spread','', |
|
196 |
'dc_rms_accel_pkg','','dc_rms_tilt','', |
|
197 |
'uc_rms_accel_pkg','','uc_rms_tilt','', |
|
198 |
'max_depth','','max_elapsed','','max_ens','', |
|
199 |
'min_depth','','min_elapsed','','min_ens','', |
|
200 |
'out_basename','','outgrid_dz','','run_label','', |
|
201 |
'outgrid_firstbin','','outgrid_lastbin','', |
|
202 |
'outgrid_minsamp','','per_bin_valid_frac_lim','', |
|
203 |
'processing_options','','refLr_firstBin','', |
|
204 |
'refLr_lastBin','','rms_w_reflr_err','', |
|
205 |
'rms_w_reflr_err_interior','', |
|
206 |
'sidelobe_editing','','surface_layer_depth','', |
|
207 |
'vessel_draft','','w_max_lim','', |
|
208 |
'water_depth.sig','','water_depth_from','', |
|
209 |
); |
|
210 |
} |
|
211 |
close(TOCLD); # close LADCP_VKE input |
|
212 |
my(@specrec); |
|
213 |
while (@specrec = &antsFileIn(FROMCLD)) { |
|
214 |
my($i) = ($specrec[$widxf]>0) ? $specrec[$widxf] : 0; |
|
215 |
@{$specbuf[$bufi][$i]} = @specrec; |
|
44 | 216 |
# print(STDERR "specrec[$i] = @specrec\n"); |
43 | 217 |
} |
218 |
close(FROMCLD); |
|
44 | 219 |
# printf(STDERR "windows up to %d buffered\n",$#{$specbuf[$bufi]}); |
43 | 220 |
|
221 |
$antsBufSkip = @ants_; |
|
222 |
&antsIn(); # read next .wprof file |
|
223 |
open2(\*FROMCLD,\*TOCLD,"LADCP_wspec $opts") || # process it |
|
224 |
croak("LADCP_wspec $opts: $!\n"); |
|
225 |
print(TOCLD $antsOldHeaders); |
|
226 |
# print(TOCLD $antsCurParams) |
|
227 |
# if defined($opt_l) || defined($opt_a); |
|
228 |
for (my($r)=0; $r<@ants_; $r++) { |
|
229 |
print(TOCLD "@{$ants_[$r]}\n"); |
|
230 |
} |
|
231 |
} |
|
232 |
||
233 |
close(TOCLD); # connect stdout from LADCP_VKE to stdin |
|
29 | 234 |
open(STDIN,"<&FROMCLD") || croak("dup(FROMCLD): $!\n"); |
235 |
close(FROMCLD); |
|
43 | 236 |
<>; # clear EOF condition |
237 |
||
42 | 238 |
undef(%P); # shouldn't matter, because we'll get the same %PARAMs back |
239 |
undef(@antsLayout); # shouldn't matter, because it will get overwritten |
|
43 | 240 |
undef($antsOldHeaders); # forget those |
241 |
undef(@ants_); |
|
242 |
||
243 |
} elsif (defined(fnrNoErr('pwrdens.0'))) { |
|
244 |
# croak("$0: -a, -l, -d, -u, -b, -w, -s meaningless when $0 used with spectral input\n") |
|
245 |
# if ($opt_d || $opt_u || $opt_b || defined($opt_w) || |
|
246 |
# defined($opt_s) || defined($opt_g)) || defined($opt_a) || defined($opt_l); |
|
247 |
croak("$0: -d, -u, -b, -w, -s meaningless when $0 used with spectral input\n") |
|
248 |
if ($opt_d || $opt_u || $opt_b || defined($opt_w) || defined($opt_s) || defined($opt_g)); |
|
29 | 249 |
} else { |
250 |
if ($ARGV[0]) { |
|
251 |
croak("$ARGV[0]: no such file or directory\n"); |
|
252 |
} else { |
|
253 |
croak("$0: empyt input\n"); |
|
254 |
} |
|
255 |
} |
|
18 | 256 |
|
29 | 257 |
#---------------------------------------------------------------------- |
43 | 258 |
# Handle LADCP_VKE usage & read spectra from final file |
259 |
# - spectra from previous files are in @specbuf |
|
29 | 260 |
#---------------------------------------------------------------------- |
261 |
||
43 | 262 |
$n_input_files = 1 + @specbuf; # number of input files provided |
263 |
||
264 |
&antsAddParams('LADCP_VKE::input_files.n',$n_input_files, |
|
265 |
'LADCP_VKE::wsamp.min',$opt_z); |
|
18 | 266 |
|
42 | 267 |
&antsFloatOpt(\$opt_e,$c); # default parameterization |
268 |
&antsFloatOpt(\$opt_x,1); # spectral fit stddev scale factor |
|
18 | 269 |
|
42 | 270 |
if (defined($opt_c)) { # shortwave cutoff supplied |
29 | 271 |
$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
|
272 |
&antsAddParams('LADCP_VKE::shortwave_cutoff',2*$PI/$lmin); # ensure eps.VKE is calculated below |
42 | 273 |
} elsif (defined(antsParam('shortwave_cutoff'))) { # cutoff already applied |
29 | 274 |
$lmin = 2*$PI/antsParam('shortwave_cutoff'); |
42 | 275 |
} else { # use 100m default cutoff |
43 | 276 |
$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
|
277 |
&antsAddParams('LADCP_VKE::shortwave_cutoff',2*$PI/$lmin); # ensure eps.VKE is calculated below |
29 | 278 |
} |
42 | 279 |
$lmax = 9e99; # no longwave cutoff implemented yet |
29 | 280 |
|
42 | 281 |
&antsInstallBufFull(0); # load entire file |
29 | 282 |
&antsIn(); |
43 | 283 |
$P{run_label} = "$input_list$P{profile_id}($P{run_label})" |
284 |
if ($n_input_files > 1); |
|
285 |
||
286 |
my($Hbuf) = $antsOldHeaders; # save for later (used on -i) |
|
29 | 287 |
|
288 |
&antsRequireParam('profile_id'); |
|
289 |
&antsRequireParam('lambda.1'); |
|
290 |
&antsRequireParam('k.1'); |
|
291 |
&antsRequireParam('resolution_bandwidth'); |
|
292 |
&antsRequireParam('input_depth_resolution'); |
|
293 |
&antsRequireParam('output_depth_resolution'); |
|
294 |
&antsRequireParam('ADCP_bin_length'); |
|
295 |
&antsAddParams('ADCP_pulse_length',antsParam('ADCP_bin_length')) |
|
296 |
unless defined(antsParam('ADCP_pulse_length')); |
|
297 |
||
42 | 298 |
$imin = 0; # find frequency bin limits |
29 | 299 |
for ($nfreq=1; defined(antsParam("lambda.$nfreq")); $nfreq++) { |
300 |
$imin = $nfreq if ($imin==0 && antsParam("lambda.$nfreq")<=$lmax); |
|
301 |
$imax = $nfreq if (antsParam("lambda.$nfreq") >= $lmin); |
|
18 | 302 |
} |
303 |
croak("$0: <lambda.min=$lmin> < min(lambda)") |
|
304 |
unless defined($imax); |
|
305 |
||
306 |
$pg_fmin = fnr('pwrdens.0'); # first power field in spectra |
|
307 |
$fs_fmin = $pg_fmin + $imin; # first power field in finescale range |
|
308 |
$fs_fmax = $pg_fmin + $imax; # last power field in finescale range |
|
309 |
||
29 | 310 |
$widxf = fnr('widx'); |
43 | 311 |
$df = fnr('depth'); |
18 | 312 |
$mindf = fnr('depth.min'); |
313 |
$maxdf = fnr('depth.max'); |
|
42 | 314 |
$wsf = fnr('w.nsamp.avg'); |
43 | 315 |
$doff = fnr('nspec'); |
18 | 316 |
|
317 |
#---------------------------------------------------------------------- |
|
29 | 318 |
# Redirect STDOUT & create plot if STDOUT is a tty |
18 | 319 |
#---------------------------------------------------------------------- |
320 |
||
29 | 321 |
if (-t STDOUT) { |
33 | 322 |
$opt_f = '.' unless defined($opt_f); # output directory |
323 |
croak("$opt_f: not a directory\n") unless (-d $opt_f); |
|
324 |
||
29 | 325 |
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
|
326 |
|
43 | 327 |
# if ($opt_d) { |
328 |
# $opt_p = sprintf('%s/%03d_dc_VKE.ps',$opt_f,$id) unless defined($opt_p); |
|
329 |
# $outfile = sprintf('%s/%03d_dc.VKE',$opt_f,$id); |
|
330 |
# } elsif ($opt_u) { |
|
331 |
# $opt_p = sprintf('%s/%03d_uc_VKE.ps',$opt_f,$id) unless defined($opt_p); |
|
332 |
# $outfile = sprintf('%s/%03d_uc.VKE',$opt_f,$id); |
|
333 |
# } else { |
|
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
334 |
$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
|
335 |
$outfile = sprintf('%s/%03d.VKE',$opt_f,$id); |
43 | 336 |
# } |
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
337 |
$outfile =~ s@^./@@; |
29 | 338 |
open(STDOUT,">$outfile") || die("$outfile: $!\n"); |
33 | 339 |
} elsif (defined($opt_f)) { |
340 |
croak("-f can only be used without STDOUT redirection\n"); |
|
29 | 341 |
} |
342 |
||
343 |
#---------------------------------------------------------------------- |
|
344 |
# Library |
|
345 |
#---------------------------------------------------------------------- |
|
346 |
||
43 | 347 |
sub average_spectra($) |
348 |
{ |
|
349 |
my($r) = @_; |
|
350 |
for (my($f)=$fs_fmin-1; $f<=$fs_fmax; $f++) { # average w.nsamp.avg & spectral densities |
|
351 |
my($sum) = my($ns) = 0; |
|
352 |
if (numberp($ants_[$r][$f])) { # final file has valid spectra |
|
353 |
$sum = $ants_[$r][$f]; $ns = 1; # NB: nspec is correct even if it doesn't |
|
354 |
} |
|
355 |
my($wi) = ($ants_[$r][$widxf]>0) ? $ants_[$r][$widxf] : 0; # adjust for -1 |
|
356 |
for (my($bi)=0; $bi<@specbuf; $bi++) { # loop over all buffered files |
|
357 |
next unless @{$specbuf[$bi][$wi]}; # skip input files w/o valid spectra |
|
358 |
if (abs($specbuf[$bi][$wi][$df] - $ants_[$r][$df]) > 0) { # depth mismatch |
|
359 |
die("assertion failed") unless ($wi == 0); # only allowed in bottom window |
|
360 |
if (abs($specbuf[$bi][$wi][$df] - $ants_[$r][$df]) > |
|
361 |
abs($ants_[$r][$maxdf] - $ants_[$r][$mindf])) { |
|
362 |
printf(STDERR "WARNING: ignoring bottom window from input file #%d because of depth mismatch\n",$bi+1) |
|
363 |
if ($f == $fs_fmin); |
|
364 |
next; |
|
365 |
} |
|
366 |
} |
|
44 | 367 |
# print(STDERR "specbuf[$bi][$wi][$f] = $specbuf[$bi][$wi][$f]\n"); |
368 |
if (numberp($specbuf[$bi][$wi][$f])) { |
|
369 |
$sum += $specbuf[$bi][$wi][$f]; $ns++; |
|
370 |
} |
|
43 | 371 |
$ants_[$r][$doff] += $specbuf[$bi][$wi][$doff] # update nspec once per input record |
372 |
if ($f == $fs_fmax); # ... but for all files |
|
373 |
} |
|
44 | 374 |
$ants_[$r][$f] = ($ns > 0) ? $sum/$ns : nan; # update averaged spectral density |
43 | 375 |
} |
376 |
} |
|
377 |
||
378 |
sub integrate_fs_power($) # integrate fs spectrum |
|
18 | 379 |
{ |
380 |
my($r) = @_; |
|
381 |
||
382 |
$ants_[$r][$fspwrf] = 0; |
|
383 |
for (my($f)=$fs_fmin; $f<=$fs_fmax; $f++) { |
|
29 | 384 |
$ants_[$r][$fspwrf] += $ants_[$r][$f]; |
18 | 385 |
} |
29 | 386 |
$ants_[$r][$fspwrf] *= antsParam('resolution_bandwidth'); |
18 | 387 |
} |
388 |
||
389 |
||
42 | 390 |
sub fit_universal_w_spec($) # vertical velocity => p0 |
18 | 391 |
{ |
392 |
my($r) = @_; |
|
393 |
my($nsamp) = $fs_fmax - $fs_fmin + 1; |
|
394 |
||
395 |
#--------------------------------------------------- |
|
396 |
# fit slope-2 line in log-log space (main estimator) |
|
397 |
#--------------------------------------------------- |
|
398 |
||
42 | 399 |
if ($nsamp >= 2) { # require min 2 wavenumber samples |
18 | 400 |
|
43 | 401 |
my($DOF) = 0; |
402 |
||
403 |
||
42 | 404 |
my($sumd,$sumx,$sumy) = (0,0,0); # fit kz^-2 power law |
405 |
for (my($f)=$fs_fmin; $f<=$fs_fmax; $f++) { |
|
18 | 406 |
my($i) = $f - $pg_fmin; |
29 | 407 |
$sumx += log10(antsParam("k.$i")); |
18 | 408 |
$sumy += log10($ants_[$r][$f]); |
43 | 409 |
$sumd += log10($ants_[$r][$f]) + 2*log10(antsRequireParam("k.$i")); |
18 | 410 |
} |
411 |
my($p0) = $sumd/$nsamp; |
|
412 |
$ants_[$r][$p0f] = 10**$p0; |
|
413 |
||
42 | 414 |
my($avgx) = $sumx/$nsamp; # avg for r calc |
18 | 415 |
my($avgy) = $sumy/$nsamp; |
42 | 416 |
my($sumsqerr,$sxx,$syy,$sxy,$sumsqxt,$sumx,$sumy,$sumwt) = # r, rms error, pwrlaw slope |
417 |
(0,0,0,0,0,0,0,0); |
|
18 | 418 |
for (my($f)=$fs_fmin; $f<=$fs_fmax; $f++) { |
42 | 419 |
my($i) = $f - $pg_fmin; |
420 |
my($x) = log10(&antsParam("k.$i")); |
|
421 |
my($y) = log10($ants_[$r][$f]); |
|
43 | 422 |
my($ysig) = $opt_x * $y / sqrt($ants_[$r][$doff]); |
42 | 423 |
my($xt) = $x - $avgx; $sxx += &SQR($xt); # correlation coeff (r) |
424 |
my($yt) = $y - $avgy; $syy += &SQR($yt); $sxy += $xt * $yt; |
|
425 |
my($wt) = 1 / &SQR($ysig); $sumwt += $wt; # slope (linear fit in log-log space) |
|
426 |
$sumx += $x * $wt; |
|
427 |
$sumy += $y * $wt; |
|
428 |
$sumsqerr += ($p0 - 2*$x - $y)**2; # rms error |
|
18 | 429 |
} |
42 | 430 |
my($midx) = $sumx / $sumwt; |
431 |
# print(STDERR "$sumx:$sumy:$sumwt\n"); |
|
432 |
# print(STDERR "$midx\n"); |
|
433 |
my($sumsqdx,$sumslp) = (0,0); |
|
434 |
for (my($f)=$fs_fmin; $f<=$fs_fmax; $f++) { |
|
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($dx) = ($x - $midx) / $ysig; |
440 |
$sumsqdx += &SQR($dx); |
|
441 |
$sumslp += $dx * $y / $ysig; |
|
442 |
} |
|
443 |
$ants_[$r][$rmsf] = sqrt($sumsqerr/$nsamp); |
|
444 |
$ants_[$r][$rf] = $sxy/(sqrt($sxx * $syy) + $SMALL_AMOUNT); |
|
445 |
$ants_[$r][$slpf] = $sumslp / $sumsqdx; |
|
446 |
$ants_[$r][$sslpf] = sqrt(1 / $sumsqdx); |
|
18 | 447 |
|
448 |
} else { |
|
449 |
&antsInfo("WARNING: no fit --- need min 2 samples"); |
|
450 |
} |
|
42 | 451 |
} |
452 |
||
453 |
#---------------------------------------------------------------------- |
|
454 |
# Load Dissipation Data |
|
455 |
#---------------------------------------------------------------------- |
|
456 |
||
457 |
my(@eps_ms,@depth_ms); # output variables |
|
458 |
if (defined($opt_k)) { |
|
459 |
my($file,$field) = split(':',$opt_k); |
|
460 |
open(ADDF,"$file") || croak("$file: $!\n"); # open file |
|
461 |
my(@afl) = &antsFileLayout(ADDF); # read layout |
|
462 |
my($akf,$aef); |
|
463 |
for (my($f)=0; $f<=$#afl; $f++) { # find depth & eps fields |
|
464 |
$akf = $f if ($afl[$f] eq 'depth'); |
|
465 |
$aef = $f if ($afl[$f] eq $field); |
|
466 |
} |
|
467 |
croak("$file: fields 'depth' and '$field' required\n") |
|
468 |
unless defined($akf) && defined($aef); |
|
469 |
while (1) { # load entire profile |
|
470 |
my(@ar); |
|
471 |
last unless @ar = &antsFileIn(ADDF); |
|
472 |
next unless numberp($ar[$akf]) && numberp($ar[$aef]); |
|
473 |
push(@depth_ms,$ar[$akf]); push(@eps_ms,$ar[$aef]); |
|
474 |
} |
|
475 |
close(ADDF); |
|
18 | 476 |
} |
477 |
||
478 |
#---------------------------------------------------------------------- |
|
479 |
# Process File |
|
480 |
#---------------------------------------------------------------------- |
|
481 |
||
43 | 482 |
$fspwrf = &antsNewField('pwr.fs'); # derived fields |
18 | 483 |
|
42 | 484 |
$p0f = &antsNewField('p0'); # VKE density |
485 |
$rmsf = &antsNewField('p0fit.rms'); # rms misfit |
|
486 |
$rf = &antsNewField('p0fit.r'); # correlation coefficient |
|
487 |
$slpf = &antsNewField('p0fit.slope'); # power-law slope |
|
488 |
$sslpf = &antsNewField('p0fit.slope.sig'); # power-law slope stddev |
|
489 |
$wepsf = &antsNewField('eps.VKE'); # epsilon from VKE |
|
490 |
$msepsf = &antsNewField('eps.ms') # externally supplied microstructure eps |
|
491 |
if defined($opt_k); |
|
18 | 492 |
|
493 |
my(@outLayout) = @antsNewLayout; # save for later |
|
494 |
for ($f=0; $f<@outLayout; $f++) { # determine last spectral field in input |
|
495 |
$totf = $f if ($outLayout[$f] eq 'pwr.tot'); |
|
496 |
$tnsf = $f if ($outLayout[$f] eq 'pwr.tot.nsamp'); |
|
497 |
} |
|
498 |
croak("$0: cannot find fields 'pwr.tot' or 'pwr.tot.nsamp' in input\n") |
|
499 |
unless defined($totf) || defined($tnsf); |
|
29 | 500 |
$lsf = defined($tnsf) ? $tnsf : $totf; |
18 | 501 |
|
29 | 502 |
if ($opt_p) { # begin plot |
503 |
$xmin = (&antsParam('output_depth_resolution')>=350) ? 0.012 : 0.018; |
|
504 |
$xmax = 0.2; $ymin = 1; $ymax = 1e4; |
|
505 |
$plotsize = 13; |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
506 |
GMT_begin($opt_p,"-JX${plotsize}l","-R$xmin/$xmax/$ymin/$ymax",'-P -X6 -Y4'); # init plot |
29 | 507 |
GMT_psxy('-G25/255/25 -L'); |
508 |
printf(GMT "%f %f\n",$xmin,$xmin**(-2)*sqrt(2)); |
|
509 |
printf(GMT "%f %f\n",$xmax,$xmax**(-2)*sqrt(2)); |
|
510 |
printf(GMT "%f %f\n",$xmax,$xmax**(-2)/sqrt(2)); |
|
511 |
printf(GMT "%f %f\n",$xmin,$xmin**(-2)/sqrt(2)); |
|
512 |
} |
|
513 |
||
514 |
my(@sumPwr,@nPwr); |
|
515 |
my(@sumGoodPwr,@nGoodPwr); |
|
516 |
my($min_depth) = 9e99; |
|
517 |
my($max_depth) = -9e99; |
|
18 | 518 |
|
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
519 |
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
|
520 |
&antsInfo("WARNING: low latitude-profile no epsilon estimated") |
43 | 521 |
unless ($latM > $opt_q); |
18 | 522 |
|
43 | 523 |
for (my($r)=0; $r<@ants_; $r++) { # loop over all windows |
524 |
||
525 |
if (numberp($ants_[$r][$pg_fmin])) { # there is a spectrum |
|
18 | 526 |
|
43 | 527 |
#-------------------------- |
528 |
# apply spectral correction |
|
529 |
#-------------------------- |
|
530 |
||
531 |
unless ($opt_m) { |
|
532 |
for (my($i)=0; $i<$nfreq; $i++) { # loop over wavenumbers |
|
533 |
$ants_[$r][$i+$pg_fmin] *= |
|
534 |
T_w(antsParam("k.$i"),antsParam('ADCP_bin_length'), |
|
535 |
antsParam('ADCP_pulse_length'),antsParam('input_depth_resolution'), |
|
536 |
$opt_r); |
|
537 |
} |
|
538 |
} |
|
539 |
||
540 |
#------------------------ |
|
541 |
# calculate fs quantities |
|
542 |
#------------------------ |
|
543 |
||
544 |
average_spectra($r); # average all avaiable spectra |
|
545 |
integrate_fs_power($r); # calculate total finescale power |
|
546 |
fit_universal_w_spec($r); # fit kz^-2 spectrum & calc stats |
|
547 |
||
548 |
if (numberp($ants_[$r][$p0f])) { # update min/max depth |
|
549 |
$min_depth = $ants_[$r][$mindf] if ($ants_[$r][$mindf] < $min_depth); |
|
550 |
$max_depth = $ants_[$r][$maxdf] if ($ants_[$r][$maxdf] > $max_depth); |
|
18 | 551 |
} |
552 |
||
43 | 553 |
} else { # no spectrum |
554 |
$ants_[$r][$fspwrf] = $ants_[$r][$p0f] = $ants_[$r][$rmsf] = |
|
555 |
$ants_[$r][$rf] = $ants_[$r][$slpf] = $ants_[$r][$sslpf] = nan; |
|
42 | 556 |
} |
557 |
||
558 |
#----------------------------------------------------------------------------------------------------- |
|
559 |
# QC Tests: |
|
560 |
# - the following limits were independently derived |
|
561 |
# p0fit.rms <= 0.4 primary filter used in Thurnherr et al. (GRL 2015) |
|
562 |
# -3 <= p0fit.slope <= -1 based largely on 2016 I08S data with sufficient/insufficient range |
|
563 |
# p0fit.r <= -0.5 based largely on 2016 I08S data with sufficient/insufficient range |
|
564 |
# w.nsamp.avg >= 50 based on observations in many data sets with weak backscatter, |
|
565 |
# including DoMORE, GO-SHIP P16S, GO-SHIP I08S |
|
566 |
# - then, I plotted slope & r vs. rms and found that rms = 0.4 corresponds to, on average |
|
567 |
# -3 <= p0fit.slope <= -1 |
|
568 |
# p0fit.r <= -0.4 |
|
569 |
# - in a plot of rms vs nsamp the limiting value of 0.4 is hit at 50 samples |
|
570 |
# |
|
571 |
# => FULL SET OF MUTUALLY CONSISTENT CRITERIA |
|
572 |
# |
|
573 |
# Additional Empirical Filters: |
|
43 | 574 |
# - latitude > 3deg guess based on Thurnherr et al., 2015, Gregg et al., 2003, 2015 GO-SHIP P16N |
575 |
# - p0 > 5x10^-8 m^s/s^2/(rad/m) based on Fig.2 in Thurnherr et al., 2015 |
|
42 | 576 |
#----------------------------------------------------------------------------------------------------- |
577 |
||
43 | 578 |
if ($latM > $opt_q && # 1) not (too) equatorial |
42 | 579 |
$ants_[$r][$rmsf] <= 0.4 && # 2) rms spectra misfit <= 0.4 (as in Thurnherr et al., GRL 2015) |
580 |
$ants_[$r][$slpf]>=-3 && $ants_[$r][$slpf]<=-1 && # 3) slope consistent with -2 power law |
|
581 |
$ants_[$r][$rf] <= -0.4 && # 4) p and k_z are well correlated |
|
43 | 582 |
$ants_[$r][$wsf] >= $opt_z) { # 5) minimum # of samples |
583 |
# if (defined($opt_l)) { # 6) suppress low-p0 tail on -l |
|
584 |
$ants_[$r][$wepsf] = ($ants_[$r][$p0f] >= $opt_l) |
|
585 |
? ($ants_[$r][$p0f] / $opt_e)**2 # Thurnherr et al. (GRL 2015) |
|
586 |
: nan; # suppress low-p0 samples |
|
587 |
# } else { # -l not set |
|
588 |
# my($lp0) = log10($ants_[$r][$p0f]); |
|
589 |
# if ($lp0 >= -6.5) { # Thurnherr et al. (GRL 2015) |
|
590 |
# $ants_[$r][$wepsf] = ($ants_[$r][$p0f] / $opt_e)**2; |
|
591 |
# } else { # low-p0 power-law fit |
|
592 |
# my($leps) = 0.56*$lp0 - 6.06; |
|
593 |
# $ants_[$r][$wepsf] = 10**$leps; |
|
594 |
# } # if log10(p0) > -6.5 |
|
595 |
# } # if -l |
|
596 |
} else { # failed any of checks 1-5 |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
597 |
$ants_[$r][$wepsf] = nan; |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
598 |
} |
29 | 599 |
|
42 | 600 |
#------------------------------------------------- |
601 |
# average external microstructure eps, if supplied |
|
602 |
#------------------------------------------------- |
|
603 |
||
604 |
if (defined($opt_k)) { |
|
605 |
my($sum,$n) = (0,0); |
|
606 |
for (my($i)=0; $i<@eps_ms; $i++) { # linearly search all eps records |
|
607 |
next unless $depth_ms[$i] >= $ants_[$r][$mindf] && |
|
608 |
$depth_ms[$i] <= $ants_[$r][$maxdf]; |
|
609 |
$sum += $eps_ms[$i]; $n++; |
|
610 |
} |
|
611 |
$ants_[$r][$msepsf] = $n ? $sum / $n : nan; |
|
29 | 612 |
} |
18 | 613 |
|
614 |
#--------------- |
|
615 |
# produce output |
|
616 |
#--------------- |
|
617 |
||
29 | 618 |
if (defined($opt_p)) { # plot current spectrum on -p & calc mean |
619 |
my($R) = 0; # RGB map |
|
620 |
my($G) = int(200*(1-$r/@ants_)); |
|
621 |
my($B) = ($r < @ants_/2) ? 150 : int(100+100*(1-$r/@ants_)); |
|
41 | 622 |
GMT_psxy("-W1,$R/$G/$B"); |
29 | 623 |
for (my($f)=$pg_fmin+1; $f<$pg_fmin+$nfreq; $f++) { # avg & plot high-quality spectra only |
624 |
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
|
625 |
next unless numberp($ants_[$r][$wepsf]); |
29 | 626 |
my($k) = antsParam(sprintf("k.%d",$f-$pg_fmin)); |
627 |
printf(GMT "$k %g\n",$ants_[$r][$f]/$ants_[$r][$p0f]); |
|
628 |
$nGoodPwr[$f]++; |
|
629 |
$sumGoodPwr[$f] += $ants_[$r][$f]/$ants_[$r][$p0f]; |
|
630 |
} |
|
41 | 631 |
GMT_psxy("-W1,$R/$G/$B,."); # avg & plot all spectra with dots |
29 | 632 |
for (my($f)=$pg_fmin+1; $f<$pg_fmin+$nfreq; $f++) { |
633 |
next unless numberp($ants_[$r][$f]) && numberp($ants_[$r][$p0f]); |
|
634 |
my($k) = antsParam(sprintf("k.%d",$f-$pg_fmin)); |
|
635 |
printf(GMT "$k %g\n",$ants_[$r][$f]/$ants_[$r][$p0f]); |
|
636 |
$nPwr[$f]++; |
|
637 |
$sumPwr[$f] += $ants_[$r][$f]/$ants_[$r][$p0f]; |
|
638 |
} |
|
639 |
} |
|
640 |
||
641 |
||
642 |
if (defined($opt_i)) { # output current spectrum on -i |
|
18 | 643 |
open(STDOUT_DUP,">&",STDOUT) || croak("$0: cannot dup STDOUT\n"); |
644 |
@antsNewLayout = ('k','lambda','pwrdens','finescale','pwrdens_fit'); |
|
29 | 645 |
if ($ants_[$r][$widxf] > 0) { |
646 |
$ofname = sprintf("${opt_i}_%02d.wspec",$r+1); |
|
647 |
} else { |
|
648 |
$ofname = sprintf("${opt_i}_btm.wspec"); |
|
649 |
} |
|
18 | 650 |
open(STDOUT,">$ofname") || croak("$ofname: $!\n"); |
651 |
undef($antsOldHeaders); |
|
26
b89d4b01fcc5
after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
652 |
&antsActivateOut() if ($ANTS_TOOLS_AVAILABLE); |
18 | 653 |
|
654 |
my($saveParams) = $antsCurParams; # add all extra input fields as %PARAMs |
|
43 | 655 |
&antsAddParams('LADCP_VKE::depth.min',$ants_[$r][$mindf], |
656 |
'LADCP_VKE::depth.max',$ants_[$r][$maxdf]); |
|
18 | 657 |
for (my($f)=$lsf+1; $f<@outLayout; $f++) { |
43 | 658 |
&antsAddParams("LADCP_VKE::$outLayout[$f]",$ants_[$r][$f]); |
18 | 659 |
} |
660 |
||
29 | 661 |
for (my($f)=$pg_fmin+1; $f<$pg_fmin+$nfreq; $f++) { |
662 |
my($k) = antsParam(sprintf("k.%d",$f-$pg_fmin)); |
|
663 |
my($l) = antsParam(sprintf("lambda.%d",$f-$pg_fmin)); |
|
18 | 664 |
&antsOut($k,$l,$ants_[$r][$f], |
665 |
($f>=$fs_fmin && $f<=$fs_fmax), |
|
666 |
numberp($ants_[$r][$p0f]) ? $ants_[$r][$p0f] * $k**(-2) : nan); |
|
667 |
} |
|
668 |
||
669 |
&antsOut('EOF'); |
|
670 |
open(STDOUT,">&",STDOUT_DUP) || croak("$0: cannot restore STDOUT\n"); |
|
671 |
close(STDOUT_DUP); |
|
672 |
$antsCurParams = $saveParams; |
|
673 |
} |
|
674 |
} |
|
675 |
||
29 | 676 |
if (defined($opt_p)) { # complete plot |
677 |
if (@nPwr) { |
|
41 | 678 |
GMT_psxy('-W2,255/100/100,.'); # plot mean spectrum; dotted; entire range |
29 | 679 |
for (my($f)=$fs_fmin; $f<=$fs_fmax; $f++) { |
680 |
my($k) = antsParam(sprintf("k.%d",$f-$pg_fmin)); |
|
681 |
printf(GMT "$k %g\n",$sumPwr[$f]/$nPwr[$f]); |
|
682 |
} |
|
683 |
} |
|
684 |
||
685 |
if (@nGoodPwr) { |
|
41 | 686 |
GMT_psxy('-W1,255/100/100'); # plot mean spectrum; entire range |
29 | 687 |
for (my($f)=$pg_fmin+1; $f<$pg_fmin+$nfreq; $f++) { |
688 |
my($k) = antsParam(sprintf("k.%d",$f-$pg_fmin)); |
|
689 |
printf(GMT "$k %g\n",$sumGoodPwr[$f]/$nGoodPwr[$f]); |
|
690 |
} |
|
41 | 691 |
GMT_psxy('-W4,255/100/100'); # plot mean fs spectrum (heavy) |
29 | 692 |
for (my($f)=$fs_fmin; $f<=$fs_fmax; $f++) { |
693 |
my($k) = antsParam(sprintf("k.%d",$f-$pg_fmin)); |
|
694 |
printf(GMT "$k %g\n",$sumGoodPwr[$f]/$nGoodPwr[$f]); |
|
695 |
} |
|
696 |
} |
|
697 |
||
698 |
GMT_psbasemap('-Bf3a2:"Vertical Wavenumber [rad/m]":/' . # annotate axes |
|
699 |
'f3a1:"VKE/p@-0@- [m@+3@+s@+-1/2@+/(rad m@+-1@+)]":WeS'); |
|
700 |
GMT_setJ("-JX-${plotsize}l"); |
|
701 |
GMT_setR(sprintf('-R%f/%f/%f/%f',2*$PI/$xmax,2*$PI/$xmin,$ymin,$ymax)); |
|
702 |
GMT_psbasemap('-B3:"Vertical Wavelength [m]:N"'); |
|
703 |
||
30 | 704 |
GMT_unitcoords_logscale(); # print profile number |
43 | 705 |
GMT_pstext('-F+f14,Helvetica,blue+jTL -Gwhite'); |
706 |
if (defined($outfile)) { printf(GMT "0.02 0.98 $outfile [$P{run_label}] %s\n",antsParam('input_data')); } |
|
707 |
else { printf(GMT "0.02 0.98 %03d [$P{run_label}] %s\n",antsParam('profile_id'),antsParam('input_data')); } |
|
41 | 708 |
GMT_pstext('-F+f9,Helvetica,orange+jTR -N -Gwhite'); |
709 |
print(GMT "0.99 0.99 V$VERSION\n"); |
|
29 | 710 |
|
41 | 711 |
GMT_set('FONT_ANNOT_PRIMARY 10','MAP_ANNOT_OFFSET_PRIMARY 0.01c', # eps profile inset |
712 |
'FONT_LABEL 10','MAP_LABEL_OFFSET 0.2c'); |
|
29 | 713 |
$min_depth = 400 if ($min_depth > 1e4); |
714 |
$max_depth = 1500 if ($max_depth < 0); |
|
42 | 715 |
GMT_setR(sprintf("-R1e-11/1e-7/%d/%d",round($min_depth-250,500),round($max_depth+250,500))); |
29 | 716 |
GMT_setJ(sprintf('-JX%fl/-%f',$plotsize/2.2,$plotsize/2.2)); |
717 |
GMT_psbasemap('-X0.3 -Y0.3 -Bg1a1f3p:"@~e@~@-VKE@- [W kg@+-1@+]":/g1000a500f100:"Depth [m]":wEsN'); |
|
41 | 718 |
GMT_psxy(); |
29 | 719 |
for (my($r)=0; $r<@ants_; $r++) { |
42 | 720 |
my($R) = 0; my($G) = int(200*(1-$r/@ants_)); # calculate color ramp |
29 | 721 |
my($B) = ($r < @ants_/2) ? 150 : int(100+100*(1-$r/@ants_)); |
42 | 722 |
if (numberp($ants_[$r][$msepsf])) { # microstructure eps |
723 |
print(GMT "> -W1.5,DarkOrange2\n"); |
|
724 |
print(GMT "$ants_[$r][$msepsf] $ants_[$r][$mindf]\n"); |
|
725 |
print(GMT "$ants_[$r][$msepsf] $ants_[$r][$maxdf]\n"); |
|
726 |
} |
|
727 |
if (numberp($ants_[$r][$wepsf])) { |
|
728 |
print(GMT "> -W2,$R/$G/$B\n"); # plot eps.w in blue |
|
729 |
print(GMT "$ants_[$r][$wepsf] $ants_[$r][$mindf]\n"); |
|
730 |
print(GMT "$ants_[$r][$wepsf] $ants_[$r][$maxdf]\n"); |
|
731 |
} |
|
29 | 732 |
} |
733 |
GMT_end(); # finish plot |
|
734 |
} |
|
735 |
||
42 | 736 |
@antsNewLayout = @outLayout; # restore layout |
18 | 737 |
$antsOldHeaders = $Hbuf; |
738 |
$antsHeadersPrinted = 0; |
|
739 |
||
740 |
&antsFlush(); # output record with results |
|
741 |
&antsExit(); |