author | A.M. Thurnherr <athurnherr@yahoo.com> |
Thu, 12 May 2016 10:54:28 -0400 | |
changeset 44 | 515c353a31bd |
parent 43 | 567b03b9ce8d |
child 46 | cc6c4309828a |
permissions | -rwxr-xr-x |
29 | 1 |
#!/usr/bin/perl |
2 |
#====================================================================== |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
3 |
# L A D C P _ W _ P O S T P R O C |
29 | 4 |
# doc: Fri Apr 24 17:15:59 2015 |
44 | 5 |
# dlm: Thu Apr 14 15:42:51 2016 |
29 | 6 |
# (c) 2015 A.M. Thurnherr |
44 | 7 |
# uE-Info: 65 40 NIL 0 0 72 2 2 4 NIL ofnI |
29 | 8 |
#====================================================================== |
9 |
||
10 |
$antsSummary = 'edit and re-grid LADCP vertical-velocity samples'; |
|
11 |
||
12 |
# HISTORY: |
|
13 |
# Apr 24, 2015: - created |
|
14 |
# Apr 25, 2015: - maded gridding work |
|
15 |
# Apr 26, 2015: - made editing work |
|
16 |
# Apr 27, 2015: - added -p |
|
17 |
# May 5, 2015: - modified Editfile syntax to use parens() |
|
18 |
# May 7, 2015: - allow leading whitespace before Editfile labels |
|
19 |
# May 17, 2015: - removed warning about missing ./Editfile |
|
20 |
# May 18, 2015: - added important %PARAMs for dual-head data |
|
21 |
# - updated to libV6.1 |
|
22 |
# May 19, 2015: - added hab to output |
|
23 |
# - allow setting %PARAMS in Editfile |
|
24 |
# May 20, 2015: - Editfile => EditParams |
|
25 |
# Jun 18, 2015: - added -i |
|
26 |
# - implemented default output on -t stdout |
|
27 |
# - changed to libGMT.pl |
|
28 |
# - removed dead -d option |
|
30 | 29 |
# Jul 26, 2015: - adapted for %outgrid_* |
30 |
# Jul 27, 2015: - B-t)rack <wprof> |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
31 |
# Sep 21, 2015: - added valid_bins() |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
32 |
# - replaced -t by -b |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
33 |
# - BUG: -k default was wrong |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
34 |
# - added error message output to EditParams |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
35 |
# Sep 22, 2015: - added output_resolution() |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
36 |
# Sep 24, 2015: - BUG: -k did not work any more |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
37 |
# - BUG: some plot commands were exectuted even without -p |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
38 |
# - BUG: wprof plot did not respect -k |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
39 |
# - BUG: typo in mad output |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
40 |
# Sep 26, 2015: - allow $ID as alias for $STN and $PROF |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
41 |
# Sep 27, 2015: - adapted to 'unknown' %water_depth |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
42 |
# Oct 12, 2015: - improved EditParams handling |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
43 |
# - BUG: single-profile plot did not work any more |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
44 |
# - BUG: wrong single-profile bin size warning produced |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
45 |
# - BUG: -o /-k code was wrong |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
46 |
# - BUG: plot was in landscape mode |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
47 |
# - added run-label(s) to plot |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
48 |
# - require ANTSlibs V6.2 for release |
33 | 49 |
# Oct 13, 2015: - adapted to [version.pl] |
34 | 50 |
# Jan 20, 2016: - added dc_w.diff, uc_w.diff for dual-head profiles |
51 |
# Jan 21, 2016: - added %_wcorr.ps plot output |
|
52 |
# - added correlation-based QC to wprof plot |
|
53 |
# Jan 22, 2016: - added output -d)ir option |
|
54 |
# Jan 24, 2016: - BUG: uc_/dc_corr returned single nan on failure |
|
55 |
# Jan 25, 2016: - added software version %PARAM |
|
56 |
# Jan 26, 2016: - added -v |
|
57 |
# Jan 30, 2016: - added -w |
|
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
58 |
# Feb 14, 2016: - BUG: all bins were off by 1! (-v, inherited limits) |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
59 |
# Mar 1, 2016: - added required ADCP sampling %PARAMs to dual-head |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
60 |
# output |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
61 |
# Mar 7, 2016: - BUG: correlation stats were defined/used for single-head data |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
62 |
# - removed good_bins() from library as -v allows more control |
41 | 63 |
# Mar 16, 2016: - adapted to gmt5 |
43 | 64 |
# Mar 31, 2016: - changed version %PARAM |
44 | 65 |
# Apr 14, 2016: - added profile id to warning messages |
29 | 66 |
|
33 | 67 |
($ANTS) = (`which ANTSlib` =~ m{^(.*)/[^/]*$}); |
68 |
($WCALC) = ($0 =~ m{^(.*)/[^/]*$}); |
|
69 |
$WCALC = '.' if ($WCALC eq ''); |
|
29 | 70 |
|
71 |
die("$0: ANTSlib required but not found (bad \$PATH?)\n") |
|
72 |
unless ($ANTS ne ''); |
|
73 |
||
33 | 74 |
require "$WCALC/version.pl"; |
29 | 75 |
require "$ANTS/ants.pl"; |
76 |
require "$ANTS/libstats.pl"; |
|
77 |
require "$ANTS/libGMT.pl"; |
|
43 | 78 |
&antsAddParams('LADCP_w_postproc::version',$VERSION); |
29 | 79 |
|
34 | 80 |
&antsUsage('b:d:i:k:l:o:p:v:w:',1, |
29 | 81 |
'[profile -i)d <id>]', |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
82 |
'[-o)utput bin <resolution>] [-k) require <min> samples]', |
34 | 83 |
'[-v)alid bins <DL first>,<DL last>[,<UL first>,<UL_last>]', |
84 |
'[-w) <DL_dc_field>,<DL_uc_field>[,<UL_dc_field>,<UL_uc_field>]', |
|
85 |
'[-s)urface-layer <limit[300m]>]', |
|
86 |
'[ouptput -d)ir <name>]', |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
87 |
'[-p)lot <[%03d_wprof.eps]> [-b)t <wprof>]]', |
34 | 88 |
'<DL.wsamp file> [UL.wsamp file] (or only <UL.wsamp file>)'); |
89 |
||
90 |
$dual_head = (@ARGV==1); # single or dual head |
|
91 |
||
92 |
$id = defined($opt_i) ? $opt_i : &antsParam('profile_id'); # ensure profile id |
|
93 |
croak("$0: no profile_id in first file => -i required\n") |
|
94 |
unless defined($id); |
|
95 |
||
96 |
if (defined($opt_d)) { # different output directory |
|
97 |
croak("$opt_d: no such directory\n") |
|
98 |
unless (-d "$opt_d"); |
|
99 |
} |
|
100 |
||
101 |
&antsCardOpt(\$opt_s,300); # surface layer depth limit |
|
29 | 102 |
|
34 | 103 |
if (defined($opt_v)) { # bin ranges with valid data to use |
104 |
($fvBin,$lvBin,$UL_fvBin,$UL_lvBin) = split(/,/,$opt_v); |
|
105 |
croak("$0: cannot decode -v $opt_v\n") |
|
106 |
unless (defined($lvBin) && (!$dual_head || defined($UL_lvBin))); |
|
107 |
$fvBin = &antsRequireParam('LADCP_firstBin') if ($fvBin eq '*'); # corresponding UL values set below |
|
108 |
$lvBin = &antsRequireParam('LADCP_lastBin') if ($lvBin eq '*'); |
|
109 |
&antsAddParams('DL_first_valid_bin',$fvBin, |
|
110 |
'DL_last_valid_bin', $lvBin); |
|
111 |
} else { |
|
112 |
&antsAddParams('DL_first_valid_bin',&antsRequireParam('outgrid_firstbin'), |
|
113 |
'DL_last_valid_bin',&antsRequireParam('outgrid_lastbin')); |
|
114 |
} |
|
29 | 115 |
|
34 | 116 |
if (defined($opt_w)) { # vertical-velocity fields to use |
117 |
($Ddwf,$Duwf,$Udwf,$Uuwf) = split(/,/,$opt_w); # DL dc, DL uc, ... |
|
118 |
croak("$0: cannot decode -w $opt_w\n") |
|
119 |
unless (defined($Duwf) && (!$dual_head || defined($Uuwf))); |
|
120 |
&antsAddParams('DL_dc_w_field',$Ddwf,'DL_uc_w_field',$Duwf, |
|
121 |
'UL_dc_w_field',$Udwf,'UL_uc_w_field',$Uuwf); |
|
122 |
} else { |
|
123 |
($Ddwf,$Duwf,$Udwf,$Uuwf) = ('w','w','w','w'); |
|
124 |
} |
|
125 |
||
126 |
if (defined($opt_o)) { # output grid resolution |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
127 |
$opt_o_override = 1; |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
128 |
&antsCardOpt($opt_o); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
129 |
} else { |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
130 |
$opt_o = &antsRequireParam('outgrid_dz'); |
30 | 131 |
} |
29 | 132 |
|
34 | 133 |
if (defined($opt_k)) { # minimum number of required samples |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
134 |
$opt_k_override = 1; |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
135 |
&antsCardOpt($opt_k); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
136 |
} else { |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
137 |
$opt_k = &antsRequireParam('outgrid_minsamp'); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
138 |
$opt_k *= 2 if ($dual_head); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
139 |
} |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
140 |
|
29 | 141 |
#---------------------------------------------------------------------- |
34 | 142 |
# Redirect STDOUT to %.wprof & create plots if STDOUT is a tty |
29 | 143 |
#---------------------------------------------------------------------- |
144 |
||
145 |
if (-t STDOUT) { |
|
34 | 146 |
$opt_p = defined($opt_d) ? "$opt_d/%03d_wprof.ps,$opt_d/%03d_wcorr.ps" |
147 |
: '%03d_wprof.ps,%03d_wcorr.ps' |
|
148 |
unless defined($opt_p); |
|
149 |
$outfile = defined($opt_d) ? sprintf('%s/%03d.wprof',$opt_d,$id) |
|
150 |
: sprintf('%03d.wprof',$id); |
|
29 | 151 |
open(STDOUT,">$outfile") || die("$outfile: $!\n"); |
152 |
} |
|
153 |
||
34 | 154 |
croak("$0: -b only makes sense when plots are produced\n") |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
155 |
if $opt_b && !defined($opt_p); |
30 | 156 |
|
29 | 157 |
#---------------------------------------------------------------------- |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
158 |
# EditParams Library |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
159 |
# |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
160 |
# output_resolution(dz) output_resolution(40) |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
161 |
# bad_range[_dc|_uc](field,min_val,max_val) bad_range_uc('depth',3500,3600) |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
162 |
# |
29 | 163 |
#---------------------------------------------------------------------- |
164 |
||
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
165 |
my(@brFnr,@brMin,@brMax,@brDUc); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
166 |
my(@gbFirst,@gbLast); |
29 | 167 |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
168 |
sub output_resolution($) |
29 | 169 |
{ |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
170 |
my($dz) = @_; |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
171 |
$opt_o = $dz; |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
172 |
$opt_o_override = 1; |
29 | 173 |
} |
174 |
||
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
175 |
sub bad_range($$$) |
29 | 176 |
{ |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
177 |
push(@brFnr,&fnr(shift)); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
178 |
push(@brMin,shift); push(@brMax,shift); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
179 |
$brMin[$#brMin] = -9e99 if ($brMin[$#brMin] eq '*'); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
180 |
$brMax[$#brMax] = 9e99 if ($brMax[$#brMax] eq '*'); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
181 |
push(@brDUc,2); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
182 |
} |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
183 |
|
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
184 |
sub bad_range_dc($$$) |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
185 |
{ |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
186 |
push(@brFnr,&fnr(shift)); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
187 |
push(@brMin,shift); push(@brMax,shift); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
188 |
$brMin[$#brMin] = -9e99 if ($brMin[$#brMin] eq '*'); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
189 |
$brMax[$#brMax] = 9e99 if ($brMax[$#brMax] eq '*'); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
190 |
push(@brDUc,1); |
29 | 191 |
} |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
192 |
|
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
193 |
sub bad_range_uc($$$) |
29 | 194 |
{ |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
195 |
push(@brFnr,&fnr(shift)); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
196 |
push(@brMin,shift); push(@brMax,shift); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
197 |
$brMin[$#brMin] = -9e99 if ($brMin[$#brMin] eq '*'); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
198 |
$brMax[$#brMax] = 9e99 if ($brMax[$#brMax] eq '*'); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
199 |
push(@brDUc,0); |
29 | 200 |
} |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
201 |
|
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
202 |
#---------------------------------------------------------------------- |
29 | 203 |
|
204 |
sub isBad() |
|
205 |
{ |
|
206 |
for (my($f)=0; $f<$antsBufNFields; $f++) { |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
207 |
for (my($i)=0; $i<@gbFirst; $i++) { # good bin range |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
208 |
return 1 if ($ants_[0][$bF] < $gbFirst[$i] || |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
209 |
$ants_[0][$bF] > $gbLast[$i]); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
210 |
} |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
211 |
|
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
212 |
for (my($i)=0; $i<@brFnr; $i++) { # bad ranges |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
213 |
next unless ($brFnr[$i] == $f); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
214 |
next unless ($brDUc[$i]==2 || $brDUc[$i]==$ants_[0][$dcF]); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
215 |
return 1 if ($ants_[0][$f] >= $brMin[$i] && |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
216 |
$ants_[0][$f] <= $brMax[$i]); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
217 |
} |
29 | 218 |
} |
219 |
return 0; |
|
220 |
} |
|
221 |
||
222 |
#---------------------------------------------------------------------- |
|
34 | 223 |
# Main Program |
29 | 224 |
#---------------------------------------------------------------------- |
225 |
||
34 | 226 |
sub dc_corr() |
227 |
{ |
|
228 |
my($n) = 0; |
|
229 |
my($ax,$ay) = (0,0); |
|
230 |
||
231 |
for (my($bi)=int($opt_s/$opt_o); $bi<@DL_dc_median; $bi++) { |
|
232 |
next unless numberp($DL_dc_median[$bi]) && numberp($UL_dc_median[$bi]); |
|
233 |
$n++; |
|
234 |
$ax += $DL_dc_median[$bi]; |
|
235 |
$ay += $UL_dc_median[$bi]; |
|
236 |
} |
|
237 |
return (nan,nan,nan) unless ($n > 2); |
|
238 |
$ax /= $n; |
|
239 |
$ay /= $n; |
|
240 |
||
241 |
my($syy,$sxy,$sxx) = (0,0,0); |
|
242 |
for (my($bi)=int($opt_s/$opt_o); $bi<@DL_dc_median; $bi++) { |
|
243 |
next unless numberp($DL_dc_median[$bi]) && numberp($UL_dc_median[$bi]); |
|
244 |
my($xt) = $DL_dc_median[$bi] - $ax; |
|
245 |
my($yt) = $UL_dc_median[$bi] - $ay; |
|
246 |
$sxx += $xt * $xt; |
|
247 |
$syy += $yt * $yt; |
|
248 |
$sxy += $xt * $yt; |
|
249 |
} |
|
250 |
my($R) = $sxy/(sqrt($sxx * $syy) + 1e-16); |
|
251 |
my($esig) = sqrt(($R**2)*$sxx/$n); |
|
252 |
my($rsig) = sqrt((1-$R**2)*$sxx/$n); |
|
253 |
return ($R,$esig,$rsig); |
|
254 |
} |
|
255 |
||
256 |
sub uc_corr(@) |
|
257 |
{ |
|
258 |
my($n) = 0; |
|
259 |
my($ax,$ay) = (0,0); |
|
260 |
||
261 |
for (my($bi)=int($opt_s/$opt_o); $bi<@DL_dc_median; $bi++) { |
|
262 |
next unless numberp($DL_uc_median[$bi]) && numberp($UL_uc_median[$bi]); |
|
263 |
$n++; |
|
264 |
$ax += $DL_uc_median[$bi]; |
|
265 |
$ay += $UL_uc_median[$bi]; |
|
266 |
} |
|
267 |
return (nan,nan,nan) unless ($n > 2); |
|
268 |
$ax /= $n; |
|
269 |
$ay /= $n; |
|
270 |
||
271 |
my($syy,$sxy,$sxx) = (0,0,0); |
|
272 |
for (my($bi)=int($opt_s/$opt_o); $bi<@DL_dc_median; $bi++) { |
|
273 |
next unless numberp($DL_uc_median[$bi]) && numberp($UL_uc_median[$bi]); |
|
274 |
my($xt) = $DL_uc_median[$bi] - $ax; |
|
275 |
my($yt) = $UL_uc_median[$bi] - $ay; |
|
276 |
$sxx += $xt * $xt; |
|
277 |
$syy += $yt * $yt; |
|
278 |
$sxy += $xt * $yt; |
|
279 |
} |
|
280 |
my($R) = $sxy/(sqrt($sxx * $syy) + 1e-16); |
|
281 |
my($esig) = sqrt(($R**2)*$sxx/$n); |
|
282 |
my($rsig) = sqrt((1-$R**2)*$sxx/$n); |
|
283 |
return ($R,$esig,$rsig); |
|
284 |
} |
|
285 |
||
286 |
#---------------------------------------------------------------------- |
|
287 |
||
288 |
$dcwF = &fnr($Ddwf); $ucwF = &fnr($Duwf); |
|
29 | 289 |
$eF = &fnr('elapsed'); |
290 |
$dF = &fnr('depth'); |
|
30 | 291 |
$bF = &fnr('bin'); |
29 | 292 |
$dcF = &fnr('downcast'); |
293 |
||
294 |
$first_label = &antsRequireParam('run_label'); |
|
295 |
$bin_length = &antsRequireParam('ADCP_bin_length'); |
|
296 |
$pulse_length = &antsRequireParam('ADCP_pulse_length'); |
|
297 |
$blanking_dist = &antsRequireParam('ADCP_blanking_distance'); |
|
298 |
($dayNoP,$dn) = &antsFindParam('dn\d\d'); |
|
299 |
croak("$0: cannot determine day number\n") |
|
300 |
unless defined($dayNoP); |
|
301 |
||
34 | 302 |
if (defined($opt_p)) { |
303 |
($sumPF,$corrPF) = split(/,/,$opt_p); |
|
304 |
croak("$0: cannot decode -p $opt_p\n") |
|
305 |
unless (length($corrPF)>0); |
|
306 |
} |
|
307 |
||
29 | 308 |
my($R,$R2); |
34 | 309 |
if (defined($opt_p)) { # begin summary plot |
41 | 310 |
$xmin = -0.1; $x2min = -700; |
311 |
$xmax = 0.35; $x2max = 500; |
|
29 | 312 |
$ymin = 0; |
313 |
$ymax = antsParam('water_depth'); |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
314 |
$ymax = antsRequireParam('max_depth') unless numberp($ymax); |
29 | 315 |
$plotsize = 13; |
316 |
$R = "-R$xmin/$xmax/$ymin/$ymax"; |
|
317 |
$R2 = "-R$x2min/$x2max/$ymin/$ymax"; |
|
34 | 318 |
GMT_begin(sprintf($sumPF,$id),"-JX$plotsize/-$plotsize",$R,'-P -X6 -Y4'); |
41 | 319 |
GMT_psxy('-W0.5'); |
29 | 320 |
print(GMT "0 $ymin\n0 $ymax"); |
321 |
GMT_psxy('-L -G200'); |
|
322 |
print(GMT "0.07 $ymin\n0.07 $ymax\n0.18 $ymax\n0.18 $ymin\n"); |
|
323 |
GMT_setR($R2); |
|
41 | 324 |
GMT_psxy('-W0.5'); |
29 | 325 |
print(GMT ">\n50 $ymin\n50 $ymax\n"); |
41 | 326 |
print(GMT ">\n250 $ymin\n250 $ymax\n"); |
327 |
print(GMT ">\n450 $ymin\n450 $ymax\n"); |
|
29 | 328 |
GMT_setR($R); |
30 | 329 |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
330 |
if (defined($opt_b)) { |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
331 |
open(BT,$opt_b) || croak("$opt_b: $!\n"); |
30 | 332 |
@BTL = &antsFileLayout(BT); |
333 |
my($BTwf,$BTdf,$BTmf,$BTnf); |
|
334 |
for (my($f)=0; $f<=$#BTL; $f++) { |
|
335 |
$BTdf = $f if ($BTL[$f] eq 'depth'); |
|
336 |
$BTwf = $f if ($BTL[$f] eq 'BT_w'); |
|
337 |
$BTmf = $f if ($BTL[$f] eq 'BT_w.mad'); |
|
338 |
$BTnf = $f if ($BTL[$f] eq 'BT_w.nsamp'); |
|
339 |
} |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
340 |
croak("$opt_b: file-layout error\n") |
30 | 341 |
unless defined($BTdf) && defined($BTwf) && |
342 |
defined($BTmf) && defined($BTnf); |
|
41 | 343 |
GMT_psxy('-W1.5'); |
30 | 344 |
while (@BT = &antsFileIn(BT)) { |
345 |
next unless numberp($BT[$BTwf]); |
|
346 |
printf(GMT "%f %f\n",$BT[$BTwf],$BT[$BTdf]); |
|
347 |
} |
|
348 |
} |
|
29 | 349 |
} |
350 |
||
351 |
$min_depth = 9e99; # sentinels |
|
352 |
$max_depth = -9e99; |
|
353 |
||
34 | 354 |
$curF = $P{PATHNAME}; # current input file (sentinel) |
29 | 355 |
$filt = 0; |
34 | 356 |
for ($r=0; &antsIn(); $r++) { |
357 |
if ($P{PATHNAME} ne $curF) { # 2nd file (UL data) |
|
29 | 358 |
$curF = $P{PATHNAME}; |
359 |
||
34 | 360 |
$dcwF = &fnr($Udwf); $ucwF = &fnr($Uuwf); |
361 |
||
44 | 362 |
&antsInfo("WARNING: #$id: inconsistent %%outgrid_dz in profile #$id") # consistency checks |
30 | 363 |
if (defined($P{outgrid_dz}) && $P{outgrid_dz}!=$opt_o &&!$opt_o_override); |
44 | 364 |
&antsInfo("WARNING: inconsistent %%outgrid_minsamp in profile #$id") |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
365 |
if defined($P{outgrid_minsamp}) && !$opt_k_override && |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
366 |
(( $dual_head && $P{outgrid_minsamp}*2!=$opt_k) || |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
367 |
(!$dual_head && $P{outgrid_minsamp}!=$opt_k)); |
29 | 368 |
|
34 | 369 |
if (defined($opt_v)) { |
370 |
$fvBin = &antsRequireParam('LADCP_firstBin') if ($UL_fvBin eq '*'); # valid bin ranges |
|
371 |
$lvBin = &antsRequireParam('LADCP_lastBin') if ($UL_lvBin eq '*'); |
|
372 |
&antsAddParams('UL_first_valid_bin',$fvBin, |
|
373 |
'UL_last_valid_bin', $lvBin); |
|
374 |
} else { |
|
375 |
&antsAddParams('UL_first_valid_bin',&antsRequireParam('outgrid_firstbin'), |
|
376 |
'UL_last_valid_bin',&antsRequireParam('outgrid_lastbin')); |
|
377 |
} |
|
378 |
||
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
379 |
for (my($bi)=0; $bi<=$#dcw1; $bi++) { # calc DL median profile (before reading UL data) |
34 | 380 |
$DL_dc_median[$bi] = median(@{$dcw1[$bi]}); |
381 |
$DL_uc_median[$bi] = median(@{$ucw1[$bi]}); |
|
382 |
} |
|
383 |
||
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
384 |
# |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
385 |
# ADCP bin length, pulse length, and blanking distance for dual head casts |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
386 |
# with inconsistent values: |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
387 |
# bin length: use smaller value, which will lead to smaller spectral correction |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
388 |
# pulse length: same |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
389 |
# blanking distance: use smaller value, which is conservative e.g. for filters for ringing |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
390 |
# |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
391 |
my($warned); |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
392 |
unless (round($bin_length) == round($P{ADCP_bin_length})) { |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
393 |
unless ($warned) { |
44 | 394 |
&antsInfo("WARNING: inconsistent ADCP sampling parameters in profile #$id --- using conservative values"); |
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
395 |
$warned = 1; |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
396 |
} |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
397 |
$bin_length = min($bin_length,$P{ADCP_bin_length}); |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
398 |
} |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
399 |
unless (round($pulse_length) == round($P{ADCP_pulse_length})) { |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
400 |
unless ($warned) { |
44 | 401 |
&antsInfo("WARNING: inconsistent ADCP sampling parameters in profile #$id --- using conservative values"); |
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
402 |
$warned = 1; |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
403 |
} |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
404 |
$pulse_length = min($pulse_length,$P{ADCP_pulse_length}); |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
405 |
} |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
406 |
unless (round($blanking_dist) == round($P{ADCP_blanking_distance})) { |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
407 |
unless ($warned) { |
44 | 408 |
&antsInfo("WARNING: inconsistent ADCP sampling parameters in profile #$id --- using conservative values"); |
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
409 |
$warned = 1; |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
410 |
} |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
411 |
$blanking_dist = min($blanking_dist,$P{ADCP_blanking_distance}); |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
412 |
} |
29 | 413 |
|
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
414 |
$PROF = $STN = $ID = $id; $RUN = antsRequireParam('run_label'); # set variables for editing |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
415 |
undef(@rngMin); undef(@rngMax); undef(@bins); |
34 | 416 |
unless ($return = do "./EditParams") { # man perlfunc |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
417 |
croak("./EditParams: $@\n") if ($@); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
418 |
} |
29 | 419 |
|
34 | 420 |
if (defined($opt_p)) { # 2nd file in dual-head profile => plot 1st |
41 | 421 |
GMT_psxy('-W1,coral,-'); |
29 | 422 |
for (my($bi)=0; $bi<=$#dcw1; $bi++) { |
34 | 423 |
printf(GMT "%f %f\n",$DL_dc_median[$bi],($bi+0.5)*$opt_o); |
29 | 424 |
} |
41 | 425 |
GMT_psxy('-W1,SeaGreen,-'); |
29 | 426 |
for (my($bi)=0; $bi<=$#ucw1; $bi++) { |
34 | 427 |
printf(GMT "%f %f\n",$DL_uc_median[$bi],($bi+0.5)*$opt_o); |
29 | 428 |
} |
429 |
undef(@dcw1); undef(@ucw1); |
|
430 |
} |
|
34 | 431 |
} # of 2nd file started |
432 |
||
433 |
if (defined($opt_v)) { # explicit ranges of validity given |
|
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
434 |
next if ($ants_[0][$bF]<$fvBin || # => apply them |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
435 |
$ants_[0][$bF]>$lvBin); |
34 | 436 |
} else { # no range of valid bins given |
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
437 |
next if ($ants_[0][$bF]<$P{outgrid_firstbin} || # => use values from [LADCP_w_ocean] |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
438 |
$ants_[0][$bF]>$P{outgrid_lastbin}); |
29 | 439 |
} |
34 | 440 |
|
441 |
$filt++,next if &isBad(); # additional editing |
|
442 |
||
443 |
$min_depth = $ants_[0][$dF] if ($ants_[0][$dF] < $min_depth); # update depth limits |
|
29 | 444 |
$max_depth = $ants_[0][$dF] if ($ants_[0][$dF] > $max_depth); |
34 | 445 |
|
29 | 446 |
my($bi) = $ants_[0][$dF]/$opt_o; |
34 | 447 |
if ($ants_[0][$dcF]) { # downcast |
448 |
push(@{$dcw[$bi]},$ants_[0][$dcwF]); # vertical velocity |
|
449 |
push(@{$dcw1[$bi]},$ants_[0][$dcwF]) if ($dual_head); # single-instrument w |
|
450 |
push(@{$dce[$bi]},$ants_[0][$eF]); # elapsed time |
|
451 |
} else { # upcast |
|
452 |
push(@{$ucw[$bi]},$ants_[0][$ucwF]); |
|
453 |
push(@{$ucw1[$bi]},$ants_[0][$ucwF]) if ($dual_head); |
|
29 | 454 |
push(@{$uce[$bi]},$ants_[0][$eF]); |
455 |
} |
|
34 | 456 |
} # file-read loop |
457 |
||
458 |
if ($dual_head) { |
|
459 |
for (my($bi)=0; $bi<=$#dcw1; $bi++) { # calc UL median & difference profiles |
|
460 |
$UL_dc_median[$bi] = median(@{$dcw1[$bi]}); |
|
461 |
$UL_uc_median[$bi] = median(@{$ucw1[$bi]}); |
|
462 |
$dc_diff[$bi] = numberp($DL_dc_median[$bi]) && numberp($UL_dc_median[$bi]) |
|
463 |
? $DL_dc_median[$bi] - $UL_dc_median[$bi] : nan; |
|
464 |
$uc_diff[$bi] = numberp($DL_uc_median[$bi]) && numberp($UL_uc_median[$bi]) |
|
465 |
? $DL_uc_median[$bi] - $UL_uc_median[$bi] : nan; |
|
466 |
} |
|
29 | 467 |
|
34 | 468 |
($dc_R,$dc_esig,$dc_rsig) = &dc_corr(); # correlation statistics |
469 |
($uc_R,$uc_esig,$uc_rsig) = &uc_corr(); |
|
470 |
&antsAddParams('dc_R',$dc_R,'uc_R',$uc_R, |
|
471 |
'dc_explained_stddev',$dc_esig,'uc_explained_stddev',$uc_esig, |
|
472 |
'dc_residual_stddev',$dc_rsig,'uc_residual_stddev',$uc_rsig); |
|
473 |
||
474 |
if (defined($opt_p)) { # plot 2nd-instrument profiles |
|
41 | 475 |
GMT_psxy('-W1,coral,.'); |
34 | 476 |
for (my($bi)=0; $bi<=$#dcw1; $bi++) { |
477 |
printf(GMT "%f %f\n",$UL_dc_median[$bi],($bi+0.5)*$opt_o); |
|
478 |
} |
|
41 | 479 |
GMT_psxy('-W1,SeaGreen,.'); |
34 | 480 |
for (my($bi)=0; $bi<=$#ucw1; $bi++) { |
481 |
printf(GMT "%f %f\n",$UL_uc_median[$bi],($bi+0.5)*$opt_o); |
|
482 |
} |
|
29 | 483 |
} |
484 |
} |
|
485 |
||
486 |
&antsInfo("%d measurements edited (%d%% of total)",$filt,round(100*$filt/$r)) |
|
487 |
if ($filt > 0); |
|
488 |
||
489 |
#---------------------------------------------------------------------- |
|
34 | 490 |
# Average and Output Profiles, Add to Summary Plot |
29 | 491 |
#---------------------------------------------------------------------- |
492 |
||
37 | 493 |
if ($dual_head) { # dual-head output |
34 | 494 |
@antsNewLayout = ('depth','hab', |
495 |
'dc_elapsed','dc_w','dc_w.mad','dc_w.nsamp', |
|
496 |
'uc_elapsed','uc_w','uc_w.mad','uc_w.nsamp', |
|
37 | 497 |
'dc_w.diff','uc_w.diff'); # DL-UL differences |
498 |
&antsAddParams('profile_id',$id,'lat',$P{lat},'lon',$P{lon}); # selected %PARAMs |
|
29 | 499 |
&antsAddParams($dayNoP,$dn,'run_label',"$first_label & $P{run_label}"); |
30 | 500 |
&antsAddParams('outgrid_dz',$opt_o,'outgrid_minsamp',$opt_k); |
29 | 501 |
&antsAddParams('min_depth',round($min_depth),'max_depth',round($max_depth)); |
502 |
&antsAddParams('water_depth',$P{water_depth},'water_depth.sig',$P{water_depth.sig}); |
|
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
503 |
&antsAddParams('ADCP_bin_length',$bin_length,'ADCP_pulse_length',$pulse_length); |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
504 |
&antsAddParams('ADCP_blanking_distance',$blanking_dist); |
29 | 505 |
undef($antsOldHeaders); |
34 | 506 |
} else { |
37 | 507 |
@antsNewLayout = ('depth','hab', # single-head output |
34 | 508 |
'dc_elapsed','dc_w','dc_w.mad','dc_w.nsamp', |
509 |
'uc_elapsed','uc_w','uc_w.mad','uc_w.nsamp'); |
|
29 | 510 |
} |
511 |
||
37 | 512 |
#&antsInfo("WARNING: unknown water depth (no height-above-bottom)") |
513 |
# unless numberp($P{water_depth}); |
|
29 | 514 |
|
515 |
my(@dcwm,@ucwm,@dcns,@ucns,@dcwmad,@ucwmad); |
|
516 |
for (my($bi)=0; $bi<=max($#dcw,$#ucw); $bi++) { |
|
517 |
$dcwm[$bi] = median(@{$dcw[$bi]}); |
|
518 |
$ucwm[$bi] = median(@{$ucw[$bi]}); |
|
519 |
$dcns[$bi] = @{$dcw[$bi]}; |
|
520 |
$ucns[$bi] = @{$ucw[$bi]}; |
|
521 |
$dcwmad[$bi] = mad2($dcwm[$bi],@{$dcw[$bi]}); |
|
522 |
$ucwmad[$bi] = mad2($ucwm[$bi],@{$ucw[$bi]}); |
|
523 |
push(@{$out[$bi]}, |
|
524 |
($bi+0.5)*$opt_o, |
|
525 |
(numberp($P{water_depth}) ? $P{water_depth}-($bi+0.5)*$opt_o : nan), |
|
526 |
avg(@{$dce[$bi]}), |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
527 |
(($dcns[$bi]>=$opt_k)?$dcwm[$bi]:nan),(($dcns[$bi]>=$opt_k)?$dcwmad[$bi]:nan), |
29 | 528 |
scalar(@{$dcw[$bi]}), |
529 |
avg(@{$uce[$bi]}), |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
530 |
(($ucns[$bi]>=$opt_k)?$ucwm[$bi]:nan),(($ucns[$bi]>=$opt_k)?$ucwmad[$bi]:nan), |
29 | 531 |
scalar(@{$ucw[$bi]})); |
34 | 532 |
push(@{$out[$bi]},$dc_diff[$bi],$uc_diff[$bi]) |
533 |
if ($dual_head); |
|
29 | 534 |
&antsOut(@{$out[$bi]}); |
535 |
} |
|
536 |
||
34 | 537 |
if (defined($opt_p)) { # complete summary plot |
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
538 |
if ($dual_head) { |
41 | 539 |
GMT_psxy('-W1,100/100/255'); # surface layer limit |
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
540 |
print(GMT "-0.1 $opt_s\n0.07 $opt_s\n"); |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
541 |
if ($dc_R < 0.3 || !numberp($dc_R)) { # correlation statistics |
44 | 542 |
&antsInfo("WARNING: low dc correlation (r = %.1f) between UL and DL data in profile #$id",$dc_R); |
41 | 543 |
GMT_pstext('-F+f12,Helvetica,white+jBL -Gred'); |
544 |
} elsif ($dc_R < 0.5) { GMT_pstext('-F+f12,Helvetica,black+jBL -Gyellow'); } |
|
545 |
else { GMT_pstext('-F+f12,Helvetica,black+jBL -Ggreen'); } |
|
546 |
printf(GMT "%f %f %.1f\n",-0.07,0.94*$ymax,$dc_R); |
|
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
547 |
} |
41 | 548 |
GMT_pstext('-F+f12,Helvetica,coral+jBL'); |
549 |
printf(GMT "%f %f dc\n",-0.095,0.94*$ymax); |
|
550 |
printf(GMT "%f %f [%.1f/%.1f cm/s @~s@~\@-e/r\@-]\n", |
|
551 |
0.02,0.94*$ymax,100*$dc_esig,100*$dc_rsig) if ($dual_head); |
|
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
552 |
if ($dual_head) { |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
553 |
if ($uc_R < 0.3 || !numberp($uc_R)) { |
44 | 554 |
&antsInfo("WARNING: low uc correlation (r = %.1f) between UL and DL data in profile #$id",$uc_R); |
41 | 555 |
GMT_pstext('-F+f12,Helvetica,white+jBL -Gred'); |
556 |
} elsif ($uc_R < 0.5) { GMT_pstext('-F+f12,Helvetica,black+jBL -Gyellow'); } |
|
557 |
else { GMT_pstext('-F+f12,Helvetica,black+jBL -Ggreen'); } |
|
558 |
printf(GMT "%f %f %.1f\n",-0.07,0.98*$ymax,$uc_R); |
|
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
559 |
} |
41 | 560 |
GMT_pstext('-F+f12,Helvetica,SeaGreen+jBL'); |
561 |
printf(GMT "%f %f uc\n",-0.095,0.98*$ymax); |
|
562 |
printf(GMT "%f %f [%.1f/%.1f cm/s @~s@~\@-e/r\@-]\n", |
|
563 |
0.02,0.98*$ymax,100*$uc_esig,100*$uc_rsig) if ($dual_head); |
|
34 | 564 |
|
29 | 565 |
GMT_setR($R); |
566 |
||
41 | 567 |
GMT_psxy('-W1.5,coral'); # median profiles |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
568 |
for (my($bi)=0; $bi<=$#dcw; $bi++) { |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
569 |
printf(GMT "%f %f\n",(($dcns[$bi]>=$opt_k)?$dcwm[$bi]:nan),($bi+0.5)*$opt_o); |
29 | 570 |
} |
41 | 571 |
GMT_psxy('-W1.5,SeaGreen'); |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
572 |
for (my($bi)=0; $bi<=$#ucw; $bi++) { |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
573 |
printf(GMT "%f %f\n",(($ucns[$bi]>=$opt_k)?$ucwm[$bi]:nan),($bi+0.5)*$opt_o); |
29 | 574 |
} |
575 |
||
41 | 576 |
GMT_psxy('-Sc0.1 -Gcoral'); # m.a.d. profiles |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
577 |
for (my($bi)=0; $bi<=$#dcw; $bi++) { |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
578 |
printf(GMT "%f %f\n",(($dcns[$bi]>=$opt_k)?$dcwmad[$bi]:nan),($bi+0.5)*$opt_o); |
29 | 579 |
} |
41 | 580 |
GMT_psxy('-Sc0.1 -GSeaGreen'); |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
581 |
for (my($bi)=0; $bi<=$#ucw; $bi++) { |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
582 |
printf(GMT "%f %f\n",(($ucns[$bi]>=$opt_k)?$ucwmad[$bi]:nan),($bi+0.5)*$opt_o); |
29 | 583 |
} |
584 |
||
585 |
GMT_setR($R2); |
|
41 | 586 |
GMT_psxy('-W0.7,coral'); |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
587 |
for (my($bi)=0; $bi<=$#dcw; $bi++) { # number of samples |
29 | 588 |
printf(GMT "%f %f\n",$dcns[$bi],($bi+0.5)*$opt_o); |
589 |
} |
|
41 | 590 |
GMT_psxy('-W0.7,SeaGreen'); |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
591 |
for (my($bi)=0; $bi<=$#dcw; $bi++) { |
29 | 592 |
printf(GMT "%f %f\n",$ucns[$bi],($bi+0.5)*$opt_o); |
593 |
} |
|
594 |
||
41 | 595 |
GMT_psbasemap('-Bf10a1000-950:" # of Samples":N'); |
596 |
GMT_psbasemap('-Ba2000-1550N'); GMT_psbasemap('-Ba1000-750N'); |
|
29 | 597 |
|
598 |
$depth_tics = ($ymax-$ymin< 1000) ? 'f10a100' : 'f100a500'; |
|
599 |
GMT_setR($R); |
|
600 |
GMT_psbasemap('-Bf0.01a10-10.05:"Vertical Velocity [m/s] ":/' . |
|
601 |
$depth_tics . ':"Depth [m]":WeS'); |
|
602 |
GMT_psbasemap('-Ba10-9.95S'); GMT_psbasemap('-Ba10-9.85S'); |
|
603 |
||
604 |
GMT_setR('-R0/1/0/1'); |
|
41 | 605 |
GMT_pstext('-F+f14,Helvetica,blue+jTL -N'); |
606 |
if (defined($outfile)) { print(GMT "0.01 -0.06 $outfile [$P{run_label}]\n"); } |
|
607 |
else { printf(GMT "0.01 -0.06 %03d\n [$P{run_label}]",$id); } |
|
608 |
GMT_pstext('-F+f12,Helvetica+jMR'); |
|
609 |
print(GMT '0.62 0.98 m.a.d.'); |
|
610 |
GMT_pstext('-F+f9,Helvetica,orange+jTR -N -Gwhite'); |
|
611 |
print(GMT "0.99 0.01 V$VERSION\n"); |
|
612 |
||
29 | 613 |
GMT_end(); |
34 | 614 |
|
615 |
if ($dual_head) { # correlation plot |
|
616 |
my($mwm) = 0.05; # max(|w|) for axes |
|
617 |
for (my($bi)=0; $bi<@DL_dc_median; $bi++) { |
|
618 |
next unless numberp($DL_dc_median[$bi]) && numberp($UL_dc_median[$bi]); |
|
619 |
$mwm = abs($DL_dc_median[$bi]) if abs($DL_dc_median[$bi]) > $mwm; |
|
620 |
$mwm = abs($UL_dc_median[$bi]) if abs($UL_dc_median[$bi]) > $mwm; |
|
621 |
} |
|
622 |
for (my($bi)=0; $bi<@DL_uc_median; $bi++) { |
|
623 |
next unless numberp($DL_uc_median[$bi]) && numberp($UL_uc_median[$bi]); |
|
624 |
$mwm = abs($DL_uc_median[$bi]) if abs($DL_uc_median[$bi]) > $mwm; |
|
625 |
$mwm = abs($UL_uc_median[$bi]) if abs($UL_uc_median[$bi]) > $mwm; |
|
626 |
} |
|
627 |
$mwm = int(100*$mwm+0.9999) / 100; |
|
628 |
$R = "-R-$mwm/$mwm/-$mwm/$mwm"; |
|
629 |
||
630 |
GMT_begin(sprintf($corrPF,$id),"-JX$plotsize/$plotsize",$R,'-P -X6 -Y4'); |
|
631 |
GMT_psxy('-Ggrey80 -L'); |
|
632 |
printf(GMT "%g %g\n%g %g\n%g %g\n%g %g\n%g %g\n%g %g\n", |
|
633 |
-$mwm, -$mwm+0.01, |
|
634 |
-$mwm, -$mwm, |
|
635 |
-$mwm+0.01, -$mwm, |
|
636 |
$mwm, $mwm-0.01, |
|
637 |
$mwm, $mwm, |
|
638 |
$mwm-0.01, $mwm); |
|
639 |
||
41 | 640 |
GMT_psxy('-W2,grey50'); |
34 | 641 |
print(GMT "-$mwm -$mwm\n$mwm $mwm\n"); |
41 | 642 |
GMT_psxy('-Sc0.12c -Gcoral -W0.3,blue'); |
34 | 643 |
for (my($bi)=0; $bi<@DL_dc_median; $bi++) { |
644 |
next unless numberp($DL_dc_median[$bi]) && numberp($UL_dc_median[$bi]); |
|
645 |
my($depth) = ($bi+0.5)*$opt_o; |
|
646 |
last if ($depth > $opt_s); |
|
647 |
print(GMT "$DL_dc_median[$bi] $UL_dc_median[$bi]\n"); |
|
648 |
} |
|
41 | 649 |
GMT_psxy('-Sc0.12c -Gcoral'); |
34 | 650 |
for (my($bi)=0; $bi<@DL_dc_median; $bi++) { |
651 |
next unless numberp($DL_dc_median[$bi]) && numberp($UL_dc_median[$bi]); |
|
652 |
my($depth) = ($bi+0.5)*$opt_o; |
|
653 |
next unless ($depth > $opt_s); |
|
654 |
print(GMT "$DL_dc_median[$bi] $UL_dc_median[$bi]\n"); |
|
655 |
} |
|
41 | 656 |
GMT_psxy('-Sc0.12c -GSeaGreen -W0.3,blue'); |
34 | 657 |
for (my($bi)=0; $bi<@DL_uc_median; $bi++) { |
658 |
next unless numberp($DL_uc_median[$bi]) && numberp($UL_uc_median[$bi]); |
|
659 |
my($depth) = ($bi+0.5)*$opt_o; |
|
660 |
last if ($depth > $opt_s); |
|
661 |
print(GMT "$DL_uc_median[$bi] $UL_uc_median[$bi]\n"); |
|
662 |
} |
|
41 | 663 |
GMT_psxy('-Sc0.12c -GSeaGreen'); |
34 | 664 |
for (my($bi)=0; $bi<@DL_uc_median; $bi++) { |
665 |
next unless numberp($DL_uc_median[$bi]) && numberp($UL_uc_median[$bi]); |
|
666 |
my($depth) = ($bi+0.5)*$opt_o; |
|
667 |
next unless ($depth > $opt_s); |
|
668 |
print(GMT "$DL_uc_median[$bi] $UL_uc_median[$bi]\n"); |
|
669 |
} |
|
41 | 670 |
GMT_pstext('-F+f14,Helvetica,blue+jTL -N'); |
671 |
if (defined($outfile)) { printf(GMT "%f %f $outfile [$P{run_label}]\n",-$mwm,1.1*$mwm); } |
|
672 |
else { printf(GMT "%f %f %03d\n [$P{run_label}]",$id,-$mwm,1.1*$wmw); } |
|
34 | 673 |
GMT_psbasemap('-Bf0.01a0.05:"DL Vertical Velocity [m/s]":/f0.01a0.05:"UL Vertical Velocity [m/s]":WeSn'); |
674 |
GMT_end(); |
|
675 |
||
676 |
} # if dual_head |
|
677 |
||
29 | 678 |
} |
679 |
||
680 |
&antsExit(0); |