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