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