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