author | A.M. Thurnherr <athurnherr@yahoo.com> |
Thu, 30 Jul 2015 09:11:43 +0000 | |
changeset 30 | 7fb67e771d85 |
parent 29 | c1ff35103176 |
child 31 | d0ae3cb99021 |
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 |
|
30 | 5 |
# dlm: Mon Jul 27 18:06:57 2015 |
18 | 6 |
# (c) 2012 A.M. Thurnherr |
30 | 7 |
# uE-Info: 392 80 NIL 0 0 72 2 2 4 NIL ofnI |
18 | 8 |
#====================================================================== |
9 |
||
10 |
$antsSummary = 'calculate VKE from LADCP-derived vertical-velocity profiles'; |
|
29 | 11 |
$antsMinLibVersion = 6.1; |
18 | 12 |
|
13 |
# HISTORY: |
|
14 |
# Oct 14, 2014: - created from [LADCPfs] |
|
15 |
# Oct 15, 2014: - added parameterization output |
|
16 |
# Oct 17, 2014: - changed parameterization constant $c to 0.021 |
|
17 |
# Nov 6, 2014: - restored from backup and adapted to ANTS V6.0 |
|
18 |
# 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
|
19 |
# 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
|
20 |
# - removed superfluous $ANTSBIN definition |
29 | 21 |
# May 18, 2015: - added -p)ulse <length> |
22 |
# Jun 11, 2015: - removed w_z code (yfname param requirement) |
|
23 |
# Jun 12, 2015: - adapted to &antsParam() |
|
24 |
# - BUG: %k.0 and %lambda.0 had been required erroneously (.1 are first ones to be used) |
|
25 |
# - made finescale limits optional |
|
26 |
# - renamed -b=>-l, -c=>-o, -s=>-i |
|
27 |
# Jun 14, 2015: - renamed -p=>-a |
|
28 |
# - added -p |
|
29 |
# - removed weird evals |
|
30 |
# Jun 15, 2015: - added plot & other mods |
|
31 |
# Jun 16, 2015: - define default outputs when STDOUT is a tty |
|
32 |
# - adapted to re-added pwrdens.0 in LADCP_wspec output |
|
33 |
# - modified plot label |
|
34 |
# Jun 17, 2015: - added eps.w to plot |
|
18 | 35 |
|
36 |
($ANTSLIB) = (`which ANTSlib` =~ m{^(.*)/[^/]*$}); |
|
26
b89d4b01fcc5
after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
37 |
$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
|
38 |
|
18 | 39 |
require "$ANTSLIB/ants.pl"; |
40 |
require "$ANTSLIB/libLADCP.pl"; |
|
29 | 41 |
require "$ANTSLIB/libGMT.pl"; |
42 |
||
43 |
use FileHandle; |
|
44 |
use IPC::Open2; |
|
18 | 45 |
|
46 |
#---------------------------------------------------------------------- |
|
47 |
# Usage |
|
48 |
#---------------------------------------------------------------------- |
|
49 |
||
29 | 50 |
my($c) = 0.0215; # Thurnherr et al. (GRL 2015) |
51 |
||
52 |
&antsUsage('bc:de:g:i:l:mno:p:r:s:tuw:',0, |
|
53 |
'[poly-o)rder <n[0]> to de-mean data; -1 to disable>] [apply cosine-t)aper]', |
|
54 |
'[-d)own/-u)pcast-only] [exclude -b)ottom window]', # LADCP_wspec options |
|
55 |
'[-s)urface <layer depth to exclude[150m]>', |
|
56 |
'[-g)ap <max depth layer to fill with interpolation[40m]>]', |
|
57 |
'[-w)indow <power-of-two input-records[32]>]', |
|
58 |
'[shortwave -c)utoff <kz or lambda[100m]>]', # LADCP_VKE options |
|
59 |
'[o-m)it spectral correction] [spectral-tilt-correction -r)ange <max[0m]>]', |
|
60 |
'[-l) override ADCP bin <length>] [-a) override pulse <length>]', |
|
61 |
"[-e)ps-parameterization <scale[$c]>", |
|
62 |
'[output -i)ndividual spectra <basename>]', |
|
63 |
'[output -p)lot <ps-file>', |
|
64 |
'[file]'); |
|
65 |
||
66 |
#---------------------------------------------------------------------- |
|
67 |
# Calculate VKE spectra with [LADCP_wspec] if input is a w_ocean file |
|
68 |
#---------------------------------------------------------------------- |
|
18 | 69 |
|
29 | 70 |
if (defined(fnrNoErr('dc_w'))) { # pre-process with LADCP_wspec when handed vertical-velocity input |
71 |
my($opts); |
|
72 |
$opts .= ' -d' if ($opt_d); |
|
73 |
$opts .= ' -u' if ($opt_u); |
|
74 |
$opts .= ' -b' if ($opt_b); |
|
75 |
$opts .= ' -t' if ($opt_t); |
|
76 |
$opts .= " -s $opt_s" if defined($opt_s); |
|
77 |
$opts .= " -g $opt_g" if defined($opt_g); |
|
78 |
$opts .= " -w $opt_w" if defined($opt_w); |
|
79 |
$opts .= " -o $opt_o" if defined($opt_o); |
|
80 |
open2(\*FROMCLD,\*TOCLD,"LADCP_wspec $opts") || # spawn sub-process |
|
81 |
croak("LADCP_wspec $opts: $!\n"); |
|
82 |
open(STDIN,"<&FROMCLD") || croak("dup(FROMCLD): $!\n"); |
|
83 |
close(FROMCLD); |
|
84 |
print(TOCLD $antsOldHeaders); undef($antsOldHeaders); # feed already gobbled header & first record to child |
|
85 |
print(TOCLD $antsPeekBuffer); undef($antsPeekBuffer); |
|
86 |
undef(%P); # shouldn't matter, because we'll get the same %PARAMs back |
|
87 |
undef(@antsLayout); # shouldn't matter, because it will get overwritten |
|
88 |
while (<>) { print(TOCLD $_); } # feed remaining data |
|
89 |
close(TOCLD); |
|
90 |
} elsif (defined(fnrNoErr('pwrdens.1'))) { |
|
91 |
croak("$0: -d, -u, -b, -w, -s meaningless when $0 used with spectral input\n") |
|
92 |
if ($opt_d || $opt_u || $opt_b || defined($opt_w) || |
|
93 |
defined($opt_s) || defined($opt_g)); |
|
94 |
} else { |
|
95 |
if ($ARGV[0]) { |
|
96 |
croak("$ARGV[0]: no such file or directory\n"); |
|
97 |
} else { |
|
98 |
croak("$0: empyt input\n"); |
|
99 |
} |
|
100 |
} |
|
18 | 101 |
|
29 | 102 |
#---------------------------------------------------------------------- |
103 |
# Handle LADCP_VKE usage & read data |
|
104 |
#---------------------------------------------------------------------- |
|
105 |
||
106 |
&antsAddParams('ADCP_bin_length',$opt_l) # override bin length |
|
107 |
if defined($opt_l); |
|
108 |
&antsAddParams('ADCP_pulse_length',$opt_a) # override pulse length |
|
109 |
if defined($opt_a); |
|
18 | 110 |
|
111 |
&antsFloatOpt(\$opt_e,$c); # default parameterization |
|
112 |
||
29 | 113 |
if (defined($opt_c)) { # shortwave cutoff supplied |
114 |
$lmin = ($opt_c < 1) ? 2*$PI/$opt_c : $opt_c; |
|
115 |
&antsAddParams('LADCP_VKE::shortwave_cutoff',2*$PI/$lmin); # ensure eps.w is calculated below |
|
116 |
} elsif (defined(antsParam('shortwave_cutoff'))) { # cutoff already applied |
|
117 |
$lmin = 2*$PI/antsParam('shortwave_cutoff'); |
|
118 |
} else { # use 100m default cutoff |
|
119 |
$lmin = 100; |
|
120 |
&antsAddParams('LADCP_VKE::shortwave_cutoff',2*$PI/$lmin); # ensure eps.w is calculated below |
|
121 |
} |
|
122 |
$lmax = 9e99; # no longwave cutoff implemented yet |
|
123 |
||
124 |
&antsInstallBufFull(0); # load entire file |
|
125 |
&antsIn(); |
|
126 |
my($Hbuf) = $antsOldHeaders; # save for later |
|
127 |
||
128 |
&antsRequireParam('profile_id'); |
|
129 |
&antsRequireParam('lambda.1'); |
|
130 |
&antsRequireParam('k.1'); |
|
131 |
&antsRequireParam('resolution_bandwidth'); |
|
132 |
&antsRequireParam('input_depth_resolution'); |
|
133 |
&antsRequireParam('output_depth_resolution'); |
|
134 |
&antsRequireParam('ADCP_bin_length'); |
|
135 |
&antsAddParams('ADCP_pulse_length',antsParam('ADCP_bin_length')) |
|
136 |
unless defined(antsParam('ADCP_pulse_length')); |
|
137 |
||
18 | 138 |
$imin = 0; # find frequency bin limits |
29 | 139 |
for ($nfreq=1; defined(antsParam("lambda.$nfreq")); $nfreq++) { |
140 |
$imin = $nfreq if ($imin==0 && antsParam("lambda.$nfreq")<=$lmax); |
|
141 |
$imax = $nfreq if (antsParam("lambda.$nfreq") >= $lmin); |
|
18 | 142 |
} |
143 |
croak("$0: <lambda.min=$lmin> < min(lambda)") |
|
144 |
unless defined($imax); |
|
145 |
||
146 |
$pg_fmin = fnr('pwrdens.0'); # first power field in spectra |
|
147 |
$fs_fmin = $pg_fmin + $imin; # first power field in finescale range |
|
148 |
$fs_fmax = $pg_fmin + $imax; # last power field in finescale range |
|
149 |
||
29 | 150 |
$widxf = fnr('widx'); |
18 | 151 |
$mindf = fnr('depth.min'); |
152 |
$maxdf = fnr('depth.max'); |
|
153 |
||
154 |
#---------------------------------------------------------------------- |
|
29 | 155 |
# Redirect STDOUT & create plot if STDOUT is a tty |
18 | 156 |
#---------------------------------------------------------------------- |
157 |
||
29 | 158 |
if (-t STDOUT) { |
159 |
my($id) = &antsRequireParam('profile_id'); |
|
160 |
$opt_p = sprintf('%03d_VKE.ps',$id) |
|
161 |
unless defined($opt_p); |
|
162 |
$outfile = sprintf('%03d.VKE',$id); |
|
163 |
open(STDOUT,">$outfile") || die("$outfile: $!\n"); |
|
164 |
} |
|
165 |
||
166 |
#---------------------------------------------------------------------- |
|
167 |
# Library |
|
168 |
#---------------------------------------------------------------------- |
|
169 |
||
170 |
sub integrate_fs_power($) # integrate fs spectrum |
|
18 | 171 |
{ |
172 |
my($r) = @_; |
|
173 |
||
174 |
$ants_[$r][$fspwrf] = 0; |
|
175 |
for (my($f)=$fs_fmin; $f<=$fs_fmax; $f++) { |
|
29 | 176 |
$ants_[$r][$fspwrf] += $ants_[$r][$f]; |
18 | 177 |
} |
29 | 178 |
$ants_[$r][$fspwrf] *= antsParam('resolution_bandwidth'); |
18 | 179 |
} |
180 |
||
181 |
||
29 | 182 |
sub normalize_spectral_power($) # scale pwrdens by p0 |
183 |
{ |
|
184 |
my($r) = @_; |
|
185 |
||
186 |
for (my($f)=$fs_fmin; $f<=$fs_fmax; $f++) { |
|
187 |
$ants_[$r][$f] /= $ants_[$r][$p0f]; |
|
188 |
} |
|
189 |
} |
|
190 |
||
191 |
||
192 |
sub fit_universal_w_spec($) # vertical velocity => p0 |
|
18 | 193 |
{ |
194 |
my($r) = @_; |
|
195 |
my($nsamp) = $fs_fmax - $fs_fmin + 1; |
|
196 |
||
197 |
#--------------------------------------------------- |
|
198 |
# fit slope-2 line in log-log space (main estimator) |
|
199 |
#--------------------------------------------------- |
|
200 |
||
29 | 201 |
if ($nsamp >= 2) { # require min 2 wavenumber samples |
18 | 202 |
|
203 |
my($sumd,$sumx,$sumy) = (0,0,0); |
|
29 | 204 |
for (my($f)=$fs_fmin; $f<=$fs_fmax; $f++) { # loop over wavenumbers |
18 | 205 |
my($i) = $f - $pg_fmin; |
29 | 206 |
$sumd += log10($ants_[$r][$f]) + 2*log10(antsRequireParam("k.$i")); |
207 |
$sumx += log10(antsParam("k.$i")); |
|
18 | 208 |
$sumy += log10($ants_[$r][$f]); |
209 |
} |
|
210 |
my($p0) = $sumd/$nsamp; |
|
211 |
$ants_[$r][$p0f] = 10**$p0; |
|
212 |
||
29 | 213 |
my($avgx) = $sumx/$nsamp; # avg for r calc |
18 | 214 |
my($avgy) = $sumy/$nsamp; |
215 |
||
29 | 216 |
my($sumsq,$sxx,$syy,$sxy) = (0,0,0,0); # calc rms misfit & correlation coeff |
18 | 217 |
for (my($f)=$fs_fmin; $f<=$fs_fmax; $f++) { |
218 |
my($i) = $f - $pg_fmin; |
|
29 | 219 |
my($xt) = log10(antsParam("k.$i")) - $avgx; |
18 | 220 |
my($yt) = log10($ants_[$r][$f]) - $avgy; |
29 | 221 |
$sumsq += ($p0 - 2*log10(antsParam("k.$i")) - log10($ants_[$r][$f]))**2; |
18 | 222 |
$sxx += $xt * $xt; $syy += $yt * $yt; $sxy += $xt * $yt; |
223 |
} |
|
224 |
$ants_[$r][$rmsf] = sqrt($sumsq/$nsamp); |
|
225 |
$ants_[$r][$rf] = $sxy/(sqrt($sxx * $syy) + $SMALL_AMOUNT); |
|
226 |
||
227 |
} else { |
|
228 |
&antsInfo("WARNING: no fit --- need min 2 samples"); |
|
229 |
} |
|
230 |
$ants_[$r][$sampf] = $nsamp; |
|
231 |
} |
|
232 |
||
233 |
#---------------------------------------------------------------------- |
|
234 |
# Process File |
|
235 |
#---------------------------------------------------------------------- |
|
236 |
||
237 |
$fspwrf = &antsNewField('fs_pwr'); # derived fields |
|
238 |
||
29 | 239 |
$p0f = &antsNewField('p0'); # VKE parameterization |
240 |
$rmsf = &antsNewField('p0fit.rms'); |
|
241 |
$sampf = &antsNewField('p0fit.nsamp'); |
|
242 |
$rf = &antsNewField('p0fit.r'); |
|
243 |
$wepsf = &antsNewField('eps.w'); |
|
18 | 244 |
|
245 |
my(@outLayout) = @antsNewLayout; # save for later |
|
246 |
for ($f=0; $f<@outLayout; $f++) { # determine last spectral field in input |
|
247 |
$totf = $f if ($outLayout[$f] eq 'pwr.tot'); |
|
248 |
$tnsf = $f if ($outLayout[$f] eq 'pwr.tot.nsamp'); |
|
249 |
} |
|
250 |
croak("$0: cannot find fields 'pwr.tot' or 'pwr.tot.nsamp' in input\n") |
|
251 |
unless defined($totf) || defined($tnsf); |
|
29 | 252 |
$lsf = defined($tnsf) ? $tnsf : $totf; |
18 | 253 |
|
29 | 254 |
if ($opt_p) { # begin plot |
255 |
$xmin = (&antsParam('output_depth_resolution')>=350) ? 0.012 : 0.018; |
|
256 |
$xmax = 0.2; $ymin = 1; $ymax = 1e4; |
|
257 |
$plotsize = 13; |
|
258 |
GMT_begin($opt_p,"-JX${plotsize}l","-R$xmin/$xmax/$ymin/$ymax",'-X6 -Y4'); # init plot |
|
259 |
GMT_psxy('-G25/255/25 -L'); |
|
260 |
printf(GMT "%f %f\n",$xmin,$xmin**(-2)*sqrt(2)); |
|
261 |
printf(GMT "%f %f\n",$xmax,$xmax**(-2)*sqrt(2)); |
|
262 |
printf(GMT "%f %f\n",$xmax,$xmax**(-2)/sqrt(2)); |
|
263 |
printf(GMT "%f %f\n",$xmin,$xmin**(-2)/sqrt(2)); |
|
264 |
} |
|
265 |
||
266 |
my(@sumPwr,@nPwr); |
|
267 |
my(@sumGoodPwr,@nGoodPwr); |
|
268 |
my($min_depth) = 9e99; |
|
269 |
my($max_depth) = -9e99; |
|
18 | 270 |
|
271 |
for (my($r)=0; $r<@ants_; $r++) { # loop over all windows |
|
272 |
||
273 |
#-------------------------- |
|
274 |
# apply spectral correction |
|
275 |
#-------------------------- |
|
276 |
||
29 | 277 |
unless ($opt_m) { |
18 | 278 |
for (my($i)=0; $i<$nfreq; $i++) { # loop over wavenumbers |
29 | 279 |
$ants_[$r][$i+$pg_fmin] *= |
280 |
T_w(antsParam("k.$i"),antsParam('ADCP_bin_length'), |
|
281 |
antsParam('ADCP_pulse_length'),antsParam('input_depth_resolution'), |
|
282 |
$opt_r); |
|
18 | 283 |
} |
284 |
} |
|
285 |
||
286 |
#------------------------ |
|
287 |
# calculate fs quantities |
|
288 |
#------------------------ |
|
289 |
||
29 | 290 |
integrate_fs_power($r); # calculate total finescale power |
291 |
fit_universal_w_spec($r); # fit kz^-2 spectrum |
|
292 |
# normalize_spectral_power($r); # normalize by p0 (even w/o shortwave cutoff) |
|
293 |
||
294 |
$ants_[$r][$wepsf] = $ants_[$r][$rmsf] <= 0.4 ? # do not calc eps unless good fit |
|
295 |
($ants_[$r][$p0f] / $opt_e)**2 : nan; |
|
296 |
||
297 |
if (numberp($ants_[$r][$p0f])) { # update min/max depth |
|
298 |
$min_depth = $ants_[$r][$mindf] if ($ants_[$r][$mindf] < $min_depth); |
|
299 |
$max_depth = $ants_[$r][$maxdf] if ($ants_[$r][$maxdf] > $max_depth); |
|
300 |
} |
|
18 | 301 |
|
302 |
#--------------- |
|
303 |
# produce output |
|
304 |
#--------------- |
|
305 |
||
29 | 306 |
if (defined($opt_p)) { # plot current spectrum on -p & calc mean |
307 |
my($R) = 0; # RGB map |
|
308 |
my($G) = int(200*(1-$r/@ants_)); |
|
309 |
my($B) = ($r < @ants_/2) ? 150 : int(100+100*(1-$r/@ants_)); |
|
310 |
GMT_psxy("-W8,$R/$G/$B"); |
|
311 |
for (my($f)=$pg_fmin+1; $f<$pg_fmin+$nfreq; $f++) { # avg & plot high-quality spectra only |
|
312 |
next unless numberp($ants_[$r][$f]) && numberp($ants_[$r][$p0f]); # - omit zero wavenumber ($pg_fmin) |
|
313 |
next if ($ants_[$r][$rmsf] > 0.4); |
|
314 |
my($k) = antsParam(sprintf("k.%d",$f-$pg_fmin)); |
|
315 |
printf(GMT "$k %g\n",$ants_[$r][$f]/$ants_[$r][$p0f]); |
|
316 |
$nGoodPwr[$f]++; |
|
317 |
$sumGoodPwr[$f] += $ants_[$r][$f]/$ants_[$r][$p0f]; |
|
318 |
} |
|
319 |
GMT_psxy("-W4,$R/$G/$B,."); # avg & plot all spectra with dots |
|
320 |
for (my($f)=$pg_fmin+1; $f<$pg_fmin+$nfreq; $f++) { |
|
321 |
next unless numberp($ants_[$r][$f]) && numberp($ants_[$r][$p0f]); |
|
322 |
my($k) = antsParam(sprintf("k.%d",$f-$pg_fmin)); |
|
323 |
printf(GMT "$k %g\n",$ants_[$r][$f]/$ants_[$r][$p0f]); |
|
324 |
$nPwr[$f]++; |
|
325 |
$sumPwr[$f] += $ants_[$r][$f]/$ants_[$r][$p0f]; |
|
326 |
} |
|
327 |
} |
|
328 |
||
329 |
||
330 |
if (defined($opt_i)) { # output current spectrum on -i |
|
18 | 331 |
open(STDOUT_DUP,">&",STDOUT) || croak("$0: cannot dup STDOUT\n"); |
332 |
@antsNewLayout = ('k','lambda','pwrdens','finescale','pwrdens_fit'); |
|
29 | 333 |
if ($ants_[$r][$widxf] > 0) { |
334 |
$ofname = sprintf("${opt_i}_%02d.wspec",$r+1); |
|
335 |
} else { |
|
336 |
$ofname = sprintf("${opt_i}_btm.wspec"); |
|
337 |
} |
|
18 | 338 |
open(STDOUT,">$ofname") || croak("$ofname: $!\n"); |
339 |
undef($antsOldHeaders); |
|
26
b89d4b01fcc5
after implementing new schemes for plotting and active files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
340 |
&antsActivateOut() if ($ANTS_TOOLS_AVAILABLE); |
18 | 341 |
|
342 |
my($saveParams) = $antsCurParams; # add all extra input fields as %PARAMs |
|
343 |
&antsAddParams('binpgrams::depth.min',$ants_[$r][$mindf], |
|
344 |
'binpgrams::depth.max',$ants_[$r][$maxdf]); |
|
345 |
for (my($f)=$lsf+1; $f<@outLayout; $f++) { |
|
346 |
&antsAddParams($outLayout[$f],$ants_[$r][$f]); |
|
347 |
} |
|
348 |
||
29 | 349 |
for (my($f)=$pg_fmin+1; $f<$pg_fmin+$nfreq; $f++) { |
350 |
my($k) = antsParam(sprintf("k.%d",$f-$pg_fmin)); |
|
351 |
my($l) = antsParam(sprintf("lambda.%d",$f-$pg_fmin)); |
|
18 | 352 |
&antsOut($k,$l,$ants_[$r][$f], |
353 |
($f>=$fs_fmin && $f<=$fs_fmax), |
|
354 |
numberp($ants_[$r][$p0f]) ? $ants_[$r][$p0f] * $k**(-2) : nan); |
|
355 |
} |
|
356 |
||
357 |
&antsOut('EOF'); |
|
358 |
open(STDOUT,">&",STDOUT_DUP) || croak("$0: cannot restore STDOUT\n"); |
|
359 |
close(STDOUT_DUP); |
|
360 |
$antsCurParams = $saveParams; |
|
361 |
} |
|
362 |
} |
|
363 |
||
29 | 364 |
if (defined($opt_p)) { # complete plot |
365 |
if (@nPwr) { |
|
366 |
GMT_psxy('-W10,255/100/100,.'); # plot mean spectrum; dotted; entire range |
|
367 |
for (my($f)=$fs_fmin; $f<=$fs_fmax; $f++) { |
|
368 |
my($k) = antsParam(sprintf("k.%d",$f-$pg_fmin)); |
|
369 |
printf(GMT "$k %g\n",$sumPwr[$f]/$nPwr[$f]); |
|
370 |
} |
|
371 |
} |
|
372 |
||
373 |
if (@nGoodPwr) { |
|
374 |
GMT_psxy('-W4/255/100/100'); # plot mean spectrum; entire range |
|
375 |
for (my($f)=$pg_fmin+1; $f<$pg_fmin+$nfreq; $f++) { |
|
376 |
my($k) = antsParam(sprintf("k.%d",$f-$pg_fmin)); |
|
377 |
printf(GMT "$k %g\n",$sumGoodPwr[$f]/$nGoodPwr[$f]); |
|
378 |
} |
|
379 |
GMT_psxy('-W16/255/100/100'); # plot mean fs spectrum (heavy) |
|
380 |
for (my($f)=$fs_fmin; $f<=$fs_fmax; $f++) { |
|
381 |
my($k) = antsParam(sprintf("k.%d",$f-$pg_fmin)); |
|
382 |
printf(GMT "$k %g\n",$sumGoodPwr[$f]/$nGoodPwr[$f]); |
|
383 |
} |
|
384 |
} |
|
385 |
||
386 |
GMT_psbasemap('-Bf3a2:"Vertical Wavenumber [rad/m]":/' . # annotate axes |
|
387 |
'f3a1:"VKE/p@-0@- [m@+3@+s@+-1/2@+/(rad m@+-1@+)]":WeS'); |
|
388 |
GMT_setJ("-JX-${plotsize}l"); |
|
389 |
GMT_setR(sprintf('-R%f/%f/%f/%f',2*$PI/$xmax,2*$PI/$xmin,$ymin,$ymax)); |
|
390 |
GMT_psbasemap('-B3:"Vertical Wavelength [m]:N"'); |
|
391 |
||
30 | 392 |
GMT_unitcoords_logscale(); # print profile number |
29 | 393 |
GMT_pstext(); |
394 |
if (defined($outfile)) { printf(GMT "0.98 0.98 14 0 0 TR $outfile %s\n",antsParam('input_data')); } |
|
395 |
else { printf(GMT "0.98 0.98 14 0 0 TR %03d %s\n",antsParam('profile_id'),antsParam('input_data')); } |
|
396 |
||
397 |
GMT_set('ANNOT_FONT_SIZE_PRIMARY 10','ANNOT_OFFSET_PRIMARY 0.01c', # eps profile inset |
|
398 |
'LABEL_FONT_SIZE 10','LABEL_OFFSET 0'); |
|
399 |
$min_depth = 400 if ($min_depth > 1e4); |
|
400 |
$max_depth = 1500 if ($max_depth < 0); |
|
401 |
GMT_setR(sprintf("-R5e-12/1e-7/%d/%d",round($min_depth-250,500),round($max_depth+250,500))); |
|
402 |
GMT_setJ(sprintf('-JX%fl/-%f',$plotsize/2.2,$plotsize/2.2)); |
|
403 |
GMT_psbasemap('-X0.3 -Y0.3 -Bg1a1f3p:"@~e@~@-VKE@- [W kg@+-1@+]":/g1000a500f100:"Depth [m]":wEsN'); |
|
404 |
GMT_psxy('-M'); |
|
405 |
for (my($r)=0; $r<@ants_; $r++) { |
|
406 |
next unless numberp($ants_[$r][$wepsf]); |
|
407 |
my($R) = 0; my($G) = int(200*(1-$r/@ants_)); |
|
408 |
my($B) = ($r < @ants_/2) ? 150 : int(100+100*(1-$r/@ants_)); |
|
409 |
print(GMT "> -W12,$R/$G/$B\n"); |
|
410 |
print(GMT "$ants_[$r][$wepsf] $ants_[$r][$mindf]\n"); |
|
411 |
print(GMT "$ants_[$r][$wepsf] $ants_[$r][$maxdf]\n"); |
|
412 |
} |
|
413 |
||
414 |
GMT_end(); # finish plot |
|
415 |
} |
|
416 |
||
18 | 417 |
@antsNewLayout = @outLayout; |
418 |
$antsOldHeaders = $Hbuf; |
|
419 |
$antsHeadersPrinted = 0; |
|
420 |
||
421 |
&antsFlush(); # output record with results |
|
422 |
&antsExit(); |