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