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