author | A.M. Thurnherr <athurnherr@yahoo.com> |
Mon, 08 Mar 2021 12:07:26 -0500 | |
changeset 54 | 828e5466391b |
parent 52 | 4ccccbf69dfd |
child 56 | 8f120b9f795a |
child 58 | 7688bec6fe87 |
permissions | -rwxr-xr-x |
18 | 1 |
#!/usr/bin/perl |
2 |
#====================================================================== |
|
29 | 3 |
# L A D C P _ W _ C T D |
18 | 4 |
# doc: Mon Nov 3 17:34:19 2014 |
54 | 5 |
# dlm: Fri Jun 26 13:07:13 2020 |
18 | 6 |
# (c) 2014 A.M. Thurnherr |
54 | 7 |
# uE-Info: 144 14 NIL 0 0 72 2 2 4 NIL ofnI |
18 | 8 |
#====================================================================== |
9 |
||
10 |
$antsSummary = 'pre-process SBE 9plus CTD data for LADCP_w'; |
|
11 |
||
12 |
# HISTORY: |
|
13 |
# Nov 3, 2014: - created |
|
14 |
# Nov 4, 2014: - improved |
|
15 |
# Nov 6, 2014: - BUG: sound speed was not calculated correctly |
|
16 |
# - added -a |
|
17 |
# - added conductivity & temperature editing |
|
18 |
# Nov 7, 2014: - loosened outlier editing |
|
19 |
# - added no-valid-data error message |
|
20 |
# - modified binning criterion to allow any sampling |
|
21 |
# frequency (not just divisors of 24) |
|
28
b07b23485336
after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
26
diff
changeset
|
22 |
# Apr 17, 2015: - added in-situ temperature to output |
29 | 23 |
# Apr 23, 2015: - had to losen unrealistic-soundspeed criterion |
24 |
# because of DUK2#45 |
|
25 |
# May 13, 2015: - BUG: did not work with casts beginning at depth |
|
26 |
# - added errors when editing edits too much |
|
27 |
# May 14, 2015: - BUG: depth was wrong for partial-depth casts |
|
28 |
# - BUG: $badval had not been handled correctly |
|
29 |
# - BUG: editing errors were too tight |
|
30 |
# Jun 16, 2015: - added STDOUT redirection (default output file) on tty stdout |
|
31 |
# - added -p)lot option |
|
32 |
# Jun 17, 2015: - added cond to std output |
|
33 |
# - added conductivity spike filter (different from pressure) |
|
34 |
# Jun 18, 2015: - renamed from SBE_w |
|
35 |
# Jun 19, 2015: - added press & salin to make output suitable for u/v processing |
|
36 |
# - removed a couple of data assertions |
|
37 |
# Jul 20, 2015: - allow for non-numeric -i |
|
31 | 38 |
# Aug 17, 2015: - modified plots |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
39 |
# Sep 21, 2015: - added lat/lon to output if available in input |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
40 |
# Sep 22, 2015: - added error on non-numeric station information |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
41 |
# - changed plot output name |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
42 |
# Sep 23, 2015: - added -o |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
43 |
# - improved pressure editing |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
44 |
# - modified editing algorithm, primarily reducing temperature resolution |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
45 |
# from 0.1deg to 1deg and finding contiguous range up to single gap in histogram |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
46 |
# (requring halving of resolution) |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
47 |
# Oct 12, 2015: - require ANTSlibs V6.2 for release |
33 | 48 |
# Oct 13, 2015: - added code to deal with CNV files with wrong number of scans in header |
49 |
# Oct 13, 2015: - adapted to [version.pl] |
|
34 | 50 |
# Jan 25, 2016: - added software version %PARAM |
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
51 |
# Feb 16, 2016: - BUG: %sampling_interval was erroenously called %sampling_frequency |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
52 |
# Feb 19, 2016: - improved on-surface data detection (conductivity <= 10mS/cm) |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
53 |
# - BUG: temperatures < 0 were not allowed |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
54 |
# - temperature histogram resolution increased from 1degC to 0.5degC for no good reason |
39 | 55 |
# Mar 13, 2016: - added simple ASCII file format |
56 |
# - BUG: Layout error when input had no lat/lon |
|
40 | 57 |
# - added lon to simple ASCII format |
41 | 58 |
# Mar 16, 2016: - adapted to gmt5 |
42 | 59 |
# Mar 19, 2016: - added support for $VERB environment var |
60 |
# - added $libSBE_quiet flag |
|
43 | 61 |
# Mar 30, 2016: - added station number of ASCII format |
62 |
# Mar 31, 2016: - changed version %PARAM |
|
47
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
63 |
# May 26, 2016: - renamed w[.raw] to CTD_w[.raw] |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
64 |
# - added winch_w |
48 | 65 |
# Jul 29, 2016: - change w_CTD plot label to reflect sign convention |
49 | 66 |
# Oct 3, 2017: - cosmetics |
67 |
# - added -q to suppress plots when generating 1Hz files |
|
68 |
# Dec 9, 2017: - added $antsSuppressCommonOptions = 1; |
|
69 |
# Dec 17, 2017: - added dependencies |
|
70 |
# Mar 8, 2018: - made error messages work with -v |
|
71 |
# - renamed -l)owpass option to -c)utoff |
|
72 |
# - added new -l)atitude |
|
73 |
# Mar 9, 2018: - changed -l) to location (include lon as well) |
|
74 |
# May 22, 2018: - added code to remove initial at surface interval |
|
75 |
# Jul 24, 2018: - improved CTD load error message |
|
76 |
# Oct 4, 2018: - minor improvement in log |
|
77 |
# - BUG: profiles collected with LOTS of wave heave (AAIW 2005, 004) |
|
78 |
# failed the contiguous pressure test at 2dbar resolution |
|
79 |
# => increased to 3dbar |
|
80 |
# Oct 5, 2018: - BUG: previous bug "fix" did not solve a real problem, because |
|
81 |
# problem with AAIW data is lack of pressure resolution |
|
82 |
# => returned to 2dbar |
|
83 |
# - added plotting errors |
|
84 |
# - improved log message |
|
85 |
# - BUG: initial in-air scans were not handled correctly (nscans not updated) |
|
51
0f6d9e64cc4f
before adding dropped-scan correction to LADCP_w_CTD
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
49
diff
changeset
|
86 |
# Mar 25, 2019: - changed error message to allow creating 1Hz from 4Hz file (SBE19) |
0f6d9e64cc4f
before adding dropped-scan correction to LADCP_w_CTD
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
49
diff
changeset
|
87 |
# - BUG: ITS was not set. How is this possible????? |
0f6d9e64cc4f
before adding dropped-scan correction to LADCP_w_CTD
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
49
diff
changeset
|
88 |
# Apr 21, 2019: - modified code to allow production of 24Hz files (previous code required |
0f6d9e64cc4f
before adding dropped-scan correction to LADCP_w_CTD
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
49
diff
changeset
|
89 |
# min 2 samples per bin, allowing for max 12Hz sampling rate) |
52 | 90 |
# Aug 27, 2019: - began adding correction for dropped CTD scans |
91 |
# Aug 28, 2019: - made it work |
|
54 | 92 |
# - added -g |
93 |
# Aug 30, 2019: - renamed -g to -m)odulo error correction (not) |
|
94 |
# - added -f)ill missing data |
|
95 |
# Jun 26, 2020: - added salinity -b)ias correction |
|
48 | 96 |
|
97 |
# NOTES: |
|
98 |
# w_CTD is positive during the downcast to make the sign of the apparent |
|
99 |
# water velocity consistent with w_ocean |
|
18 | 100 |
|
33 | 101 |
($ANTS) = (`which ANTSlib` =~ m{^(.*)/[^/]*$}); |
102 |
($WCALC) = ($0 =~ m{^(.*)/[^/]*$}); |
|
103 |
$WCALC = '.' if ($WCALC eq ''); |
|
18 | 104 |
|
33 | 105 |
require "$WCALC/version.pl"; |
18 | 106 |
require "$ANTS/ants.pl"; |
107 |
require "$ANTS/fft.pl"; |
|
47
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
108 |
require "$ANTS/libstats.pl"; |
49 | 109 |
require "$ANTS/libconv.pl"; |
29 | 110 |
require "$ANTS/libGMT.pl"; |
18 | 111 |
require "$ANTS/libSBE.pl"; |
112 |
require "$ANTS/libEOS83.pl"; |
|
43 | 113 |
&antsAddParams('LADCP_w_CTD::version',$VERSION); |
18 | 114 |
|
115 |
$antsParseHeader = 0; # usage |
|
49 | 116 |
$antsSuppressCommonOptions = 1; |
54 | 117 |
$IS = &antsLoadModel('`','.nminterp','linear'); |
118 |
&antsUsage("ab:c:fgi:l:morp:qs:v:w:$IS_opts",1, |
|
18 | 119 |
'[-v)erbosity <level[0]>]', |
120 |
'[use -a)lternate sensor pair]', |
|
54 | 121 |
'[correct -S)alinity <bias>]', |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
122 |
'[-r)etain all data (no editing)] [allow infinite -o)utliers]', |
54 | 123 |
'[suppress CTD -m)odulo error correction]', |
18 | 124 |
'[-s)ampling <rate[6Hz]>]', |
49 | 125 |
'[lowpass w_CTD -c)utoff <limit[2s]>] [-w)inch-speed <granularity[10s]>]', |
126 |
'[profile -i)d <id>] [station -l)ocation <lat/lon>]', |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
127 |
'[-p)lot_basenames <[%03d_w_CTD.ps],[%03d_sspd.ps]>]', |
49 | 128 |
'[-q)uiet (no plots)]', |
54 | 129 |
'[-f)ill gaps with linear interpolation]', |
18 | 130 |
'<SBE CNV file>'); |
54 | 131 |
&antsUsageError() unless defined($IS); |
18 | 132 |
|
49 | 133 |
&antsFloatOpt(\$opt_c,2); # default low-pass cutoff for w_CTD |
134 |
&antsCardOpt(\$opt_s,6); # default output sampling rate (Hz) |
|
47
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
135 |
&antsFloatOpt(\$opt_w,10); # winch velocity granularity |
54 | 136 |
&antsFloatOpt(\$opt_b,0); # salinity bias |
42 | 137 |
&antsCardOpt(\$opt_v,$ENV{VERB}); # support VERB env variable |
18 | 138 |
|
139 |
$CNVfile = $ARGV[0]; # open CNV file |
|
140 |
open(F,&antsFileArg()); |
|
49 | 141 |
&antsAddDeps($CNVfile); |
28
b07b23485336
after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
26
diff
changeset
|
142 |
&antsActivateOut(); # activate ANTS file |
18 | 143 |
|
54 | 144 |
&antsAddParams('salinity_bias_corrected',$opt_b) |
145 |
if ($opt_b != 0); |
|
146 |
||
18 | 147 |
#---------------------------------------------------------------------- |
148 |
# Read Data |
|
149 |
#---------------------------------------------------------------------- |
|
150 |
||
49 | 151 |
sub _croak(@) |
152 |
{ |
|
153 |
print(STDERR "\n") if ($opt_v); |
|
154 |
croak(@_); |
|
155 |
} |
|
156 |
||
18 | 157 |
print(STDERR "Reading $CNVfile...") if ($opt_v); |
158 |
||
39 | 159 |
chomp($rec = <F>); |
49 | 160 |
_croak("$CNVfile: no data\n") |
39 | 161 |
unless defined($rec); |
18 | 162 |
|
39 | 163 |
if ($rec =~ /^\*/) { # SBE CNV file |
42 | 164 |
$libSBE_quiet = 1; # suppress diagnostic messages |
39 | 165 |
($nfields,$nscans,$sampint,$badval,$ftype,$lat,$lon) = # decode SBE header |
166 |
SBE_parseHeader(F,0,0); # SBE field names, no time check |
|
167 |
||
51
0f6d9e64cc4f
before adding dropped-scan correction to LADCP_w_CTD
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
49
diff
changeset
|
168 |
_croak("$CNVfile: insufficient time resolution ($sampint s) for ${opt_s}Hz time series\n") |
54 | 169 |
if (1/$sampint/$opt_s < 1); |
49 | 170 |
|
171 |
if (defined($opt_l)) { # set/override station location with -l |
|
172 |
my($slat,$slon) = split('[,/]',$opt_l); |
|
173 |
$lat = GMT2deg($slat); |
|
174 |
$lon = GMT2deg($slon); |
|
175 |
_croak("$0: cannot decode -l $opt_l\n") |
|
176 |
unless numberp($lat) && numberp($lon); |
|
177 |
} |
|
178 |
_croak("$CNVfile: no latitude in header => -l required\n") |
|
39 | 179 |
unless numberp($lat); |
49 | 180 |
|
181 |
&antsAddParams('lat',$lat); |
|
182 |
&antsAddParams('lon',$lon); |
|
39 | 183 |
|
51
0f6d9e64cc4f
before adding dropped-scan correction to LADCP_w_CTD
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
49
diff
changeset
|
184 |
$pressF = fnrNoErr('prdM'); # pressure; SBE19plus |
0f6d9e64cc4f
before adding dropped-scan correction to LADCP_w_CTD
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
49
diff
changeset
|
185 |
$pressF = fnr('prDM') unless defined($pressF); # SBE 9plus |
39 | 186 |
|
187 |
if ($opt_a) { # temp/cond alternate sensor pair |
|
188 |
$tempF = fnr('t190C'); |
|
51
0f6d9e64cc4f
before adding dropped-scan correction to LADCP_w_CTD
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
49
diff
changeset
|
189 |
&antsAddParams('ITS',90); |
39 | 190 |
$condF = fnrNoErr('c1S/m'); |
191 |
if (defined($condF)) { |
|
192 |
$condHistRes = 20; # 0.2 S/m bins |
|
193 |
} else { |
|
194 |
$condF = fnr('c1mS/cm'); |
|
195 |
$condHistRes = 2; # 2.0 mS/cm bins |
|
196 |
} |
|
197 |
} else { # primary sensor pair |
|
51
0f6d9e64cc4f
before adding dropped-scan correction to LADCP_w_CTD
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
49
diff
changeset
|
198 |
$tempF = fnrNoErr('tv290C'); # SBE 19plus |
0f6d9e64cc4f
before adding dropped-scan correction to LADCP_w_CTD
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
49
diff
changeset
|
199 |
$tempF = fnr('t090C') unless defined($tempF); # SBE 9plus |
0f6d9e64cc4f
before adding dropped-scan correction to LADCP_w_CTD
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
49
diff
changeset
|
200 |
&antsAddParams('ITS',90); |
39 | 201 |
$condF = fnrNoErr('c0S/m'); |
202 |
if (defined($condF)) { |
|
203 |
$condHistRes = 20; |
|
204 |
} else { |
|
205 |
$condF = fnr('c0mS/cm'); |
|
206 |
$condHistRes = 2; |
|
207 |
} |
|
18 | 208 |
} |
52 | 209 |
|
54 | 210 |
unless ($opt_m) { # set up correction for dropped scans |
211 |
$systimeF = &fnrNoErr('timeY'); |
|
212 |
$xmerrF = &fnrNoErr('modError'); |
|
213 |
if (defined($systimeF) && defined($xmerrF)) { |
|
214 |
$fill_gaps = 1; |
|
215 |
} else { |
|
216 |
print(STDERR "\n\n") if ($opt_v > 1); |
|
217 |
print(STDERR "WARNING: timeY and/or modError missing from $CNVfile -- cannot correct for CTD modulo errors\n"); |
|
218 |
} |
|
219 |
} |
|
39 | 220 |
|
221 |
$latF = &fnrNoErr('lat'); # GPS data if available (to make files useful for u/v processing) |
|
222 |
$lonF = &fnrNoErr('lon'); |
|
223 |
||
224 |
&antsInstallBufFull(0); # read entire CNV file |
|
225 |
&SBEin(F,$ftype,$nfields,$nscans,$badval); |
|
226 |
||
227 |
if (@ants_ != $nscans) { |
|
228 |
if ($opt_v > 1) { |
|
49 | 229 |
printf(STDERR "\n\nWARNING: $CNVfile has wrong number of scans in header (%d instead of %d)\n",$nscans,scalar(@ants_)); |
39 | 230 |
} else { |
49 | 231 |
printf(STDERR "WARNING: $CNVfile has wrong number of scans in header (%d instead of %d)\n",$nscans,scalar(@ants_)); |
39 | 232 |
} |
233 |
$nscans = @ants_; |
|
18 | 234 |
} |
43 | 235 |
} else { # simple CSV ASCII file format: |
236 |
($lat,$lon,$station) = split(',',$rec); |
|
49 | 237 |
_croak("$CNVfile: ASCII file format error (1st rec must be lat,lon[,id])\n") # header: lat,lon[,station] |
40 | 238 |
unless numberp($lat) && numberp($lon) && |
239 |
$lat>=-90 && $lat<=90 && |
|
240 |
$lon>=-360 && $lon<=360; |
|
43 | 241 |
&antsAddParams('station',$station) if defined($station); |
40 | 242 |
&antsAddParams('lat',$lat,'lon',$lon); |
39 | 243 |
$sampint = 1/24; $condHistRes = 2; # assumptions: 24Hz |
244 |
&antsAddParams('ITS',90,'cond.unit','mS/cm'); # ITS-90, mS/cm |
|
245 |
$pressF = 1; $tempF = 2; $condF = 3; # Layout: scan press temp cond |
|
246 |
for ($nscans=0; <F>; $nscans++) { |
|
247 |
chomp; |
|
248 |
@{$ants_[$nscans]} = split(','); # CSV format |
|
49 | 249 |
_croak(sprintf("$CNVfile: unexpected scan #$ants_[$nscans][0] (%d expected)\n",$nscans+1)) |
39 | 250 |
unless ($ants_[$nscans][0] == $nscans+1); |
251 |
$ants_[$nscans][$pressF] = nan unless defined($ants_[$nscans][$pressF]); # missing values |
|
252 |
$ants_[$nscans][$tempF] = nan unless defined($ants_[$nscans][$tempF]); |
|
253 |
$ants_[$nscans][$condF] = nan unless defined($ants_[$nscans][$condF]); |
|
33 | 254 |
} |
255 |
} |
|
256 |
||
52 | 257 |
printf(STDERR "\n\t%d scans (%d minutes)",$nscans,round($nscans*$sampint/60)) |
49 | 258 |
if ($opt_v > 1); |
18 | 259 |
printf(STDERR "\n") if ($opt_v); |
260 |
||
261 |
#---------------------------------------------------------------------- |
|
52 | 262 |
# Fill gaps in CTD time series due to dropped scans (modulo errors) |
263 |
#---------------------------------------------------------------------- |
|
264 |
||
265 |
if ($fill_gaps) { |
|
54 | 266 |
print(STDERR "Correcting for CTD modulo errors and clock jitter/drift...") if ($opt_v); |
52 | 267 |
|
268 |
my($scans_filled) = 0; |
|
269 |
my($scans_replaced) = 0; |
|
270 |
my($scans_deleted) = 0; |
|
271 |
||
272 |
for (my($scan)=30; $scan<@ants_; $scan++) { # start a bit more than 1 second into the cast |
|
273 |
next if ($ants_[$scan][$systimeF] == $ants_[$scan-1][$systimeF]); # skip forward to next systime second |
|
274 |
||
54 | 275 |
if ($ants_[$scan][$systimeF] > $ants_[$scan-1][$systimeF]+1) { # gap spans at least one full second |
276 |
print(STDERR "\n\n") if ($opt_v > 1); |
|
277 |
printf(STDERR "WARNING: %d full seconds of data missing at elapsed %d s\n", |
|
278 |
$ants_[$scan][$systimeF]-$ants_[$scan-1][$systimeF]-1, |
|
279 |
$ants_[$scan-1][$systimeF]-$ants_[0][$systimeF]); |
|
280 |
my(@splicescan); # scan to splice in |
|
281 |
$splicescan[$systimeF] = $ants_[$scan-1][$systimeF] + 1; |
|
282 |
$splicescan[$xmerrF] = $ants_[$scan-1][$xmerrF]; |
|
283 |
for (my($i)=0; $i<24; $i++) { |
|
284 |
splice(@ants_,$scan,0,\@splicescan); |
|
285 |
$scans_filled++; |
|
286 |
} |
|
287 |
} |
|
52 | 288 |
|
289 |
my($second_start) = $scan - 1; # backtrack to beginning of second |
|
290 |
my($scans_this_sec) = 1; |
|
291 |
while ($ants_[$second_start-1][$systimeF] == $ants_[$second_start][$systimeF]) { |
|
292 |
$second_start--; $scans_this_sec++; |
|
293 |
} |
|
294 |
die("\nscan = $scan, second_start = $second_start, st = $ants_[$second_start][$systimeF]") |
|
295 |
unless ($second_start > 0); |
|
296 |
||
297 |
while ($scans_this_sec > 24) { # CTD clock running fast => remove scans |
|
298 |
splice(@ants_,$scan-1,1); |
|
299 |
$scans_deleted++; $scans_this_sec--; $scan--; |
|
300 |
} |
|
301 |
||
302 |
my($gap_len) = 24 - $scans_this_sec; # gap length in this second only |
|
303 |
die("gap_len = $gap_len at scan#$scan") unless ($gap_len >= 0); |
|
304 |
||
305 |
my($ngaps) = 0; # gaps between end of previous and beginning of next section |
|
306 |
for (my($s)=$second_start; $s<=$scan; $s++) { |
|
307 |
$ngaps++ if ($ants_[$s][$xmerrF] > $ants_[$s-1][$xmerrF]); |
|
308 |
} |
|
309 |
||
310 |
my(@splicescan); # scan to splice in |
|
311 |
$splicescan[$systimeF] = $ants_[$second_start][$systimeF]; |
|
312 |
$splicescan[$xmerrF] = $ants_[$second_start][$xmerrF]; |
|
313 |
||
314 |
if ($ngaps==0 && $gap_len>0) { # clock drift => add scan |
|
315 |
# print(STDERR "adding $gap_len scans to make up for clock drift starting at scan $scan-1 (ss = $second_start) (st = $splicescan[$systimeF])\n"); |
|
316 |
for (my($i)=0; $i<$gap_len; $i++) { # fill gap |
|
317 |
splice(@ants_,$scan-1,0,\@splicescan); |
|
318 |
$scans_filled++; $scan++; |
|
319 |
} |
|
320 |
} elsif ($ngaps == 1) { # single gap => fill it |
|
321 |
my($gap_location) = $second_start; # find it |
|
322 |
while ($ants_[$gap_location][$xmerrF] == $ants_[$second_start-1][$xmerrF]) { |
|
323 |
$gap_location++; |
|
324 |
} |
|
325 |
die('INTERNAL ERROR') unless ($gap_location <= $scan); |
|
326 |
# print(STDERR "filling $gap_len gap starting at scan $gap_location (ss = $second_start) (st = $splicescan[$systimeF])\n"); |
|
327 |
for (my($i)=0; $i<$gap_len; $i++) { # fill gap |
|
328 |
splice(@ants_,$gap_location,0,\@splicescan); |
|
329 |
$scans_filled++; $scan++; |
|
330 |
} |
|
331 |
} else { # multiple gaps => delete data |
|
332 |
my($last_gap); |
|
333 |
for (my($s)=$second_start; $s<$scan; $s++) { # replace ambiguous data scans |
|
334 |
next if ($ants_[$s][$xmerrF] == $ants_[$second_start-1][$xmerrF]); |
|
335 |
last if ($ants_[$s][$xmerrF] == $ants_[$scan][$xmerrF]); |
|
336 |
splice(@ants_,$s,1,\@splicescan); # replace |
|
337 |
$scans_replaced++; |
|
338 |
$last_gap = $s; |
|
339 |
} |
|
340 |
for (my($i)=0; $i<$gap_len; $i++) { # fill gaps |
|
341 |
splice(@ants_,$last_gap+1,0,\@splicescan); |
|
342 |
$scans_filled++; $scan++; |
|
343 |
} |
|
344 |
} |
|
345 |
||
346 |
my($scans_this_sec) = 0; |
|
347 |
die("$ants_[$second_start][$systimeF]==$ants_[$second_start-1][$systimeF]+1") |
|
348 |
unless ($ants_[$second_start][$systimeF]==$ants_[$second_start-1][$systimeF]+1); |
|
349 |
for (my($i)=0; $ants_[$second_start+$i][$systimeF]==$ants_[$second_start-1][$systimeF]+1; $i++) { |
|
350 |
$scans_this_sec++; |
|
351 |
} |
|
352 |
die("\n$scans_this_sec scans in second $ants_[$second_start][$systimeF] at scans $second_start .. $scan-1 (gap_len $gap_len, $ngaps gaps)\n") |
|
353 |
unless ($scans_this_sec == 24); |
|
354 |
} # for ($scan |
|
355 |
||
356 |
# my($sts) = 1; |
|
357 |
# for (my($scan)=1; $scan<@ants_; $scan++) { |
|
358 |
# $sts++,next if ($ants_[$scan][$systimeF] == $ants_[$scan-1][$systimeF]); |
|
54 | 359 |
# printf(STDERR "%s seconds of data missing after scan %d\n", |
360 |
# $ants_[$scan][$systimeF]-$ants_[$scan-1][$systimeF]-1,$scan-1) |
|
361 |
# if ($ants_[$scan][$systimeF]-$ants_[$scan-1][$systimeF]-1 != 0); |
|
52 | 362 |
# printf(STDERR "sts = $sts beginning at scan %d (st = $ants_[$scan-1][$systimeF])\n",$scan-$sts) |
363 |
# unless ($sts == 24); |
|
364 |
# $sts = 1; |
|
365 |
# } |
|
366 |
||
367 |
&antsAddParams('gaps_scans_filled',$scans_filled, |
|
368 |
'scans_removed',$scans_deleted, |
|
369 |
'gap_scans_cleared',$scans_replaced); |
|
370 |
||
371 |
if ($opt_v>1 && $scans_filled) { |
|
372 |
printf(STDERR "\n\t%d scans removed (clock drift)",$scans_deleted); |
|
373 |
printf(STDERR "\n\t%d scans added (gaps & clock drift)",$scans_filled); |
|
374 |
printf(STDERR "\n\t%d scans cleared (gap clusters)",$scans_replaced); |
|
375 |
} |
|
376 |
printf(STDERR "\n") if ($opt_v); |
|
377 |
} # if ($fill_gaps |
|
378 |
||
379 |
#---------------------------------------------------------------------- |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
380 |
# Redirect STDOUT to %.6Hz & create %_w_CTD.ps,%_sspd.ps if STDOUT is a tty |
29 | 381 |
#---------------------------------------------------------------------- |
382 |
||
383 |
$id = defined($opt_i) ? $opt_i : &antsParam('station'); |
|
49 | 384 |
_croak("$CNVfile: no station information in header => -i required\n") |
29 | 385 |
unless defined($id); |
49 | 386 |
_croak("$CNVfile: non-numeric station information <$id> in header => -i required\n") |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
387 |
unless numberp($id); |
29 | 388 |
|
389 |
if (-t STDOUT) { |
|
390 |
if (numberp($id)) { |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
391 |
$opt_p = '%03d_w_CTD.ps,%03d_sspd.ps' |
29 | 392 |
unless defined($opt_p); |
393 |
$outfile = sprintf('%03d.%dHz',$id,$opt_s); |
|
394 |
} else { |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
395 |
$opt_p = '%s_w_CTD.ps,%s_sspd.ps' |
29 | 396 |
unless defined($opt_p); |
397 |
$outfile = sprintf('%s.%dHz',$id,$opt_s); |
|
398 |
} |
|
399 |
open(STDOUT,">$outfile") || die("$outfile: $!\n"); |
|
400 |
} |
|
401 |
||
49 | 402 |
undef($opt_p) if $opt_q; # suppress all plots on -q |
403 |
||
29 | 404 |
#---------------------------------------------------------------------- |
18 | 405 |
# Edit Data |
406 |
# - pressure outliers & spikes |
|
407 |
# - conductivity outliers & spikes |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
408 |
# - max_bin+1 is returned to ensure full range |
18 | 409 |
#---------------------------------------------------------------------- |
410 |
||
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
411 |
sub validRange($) |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
412 |
{ |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
413 |
my($guess_bin) = @_; |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
414 |
my($min_bin,$max_bin); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
415 |
|
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
416 |
die("assertion failed") unless ($hist[$guess_bin]); |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
417 |
for ($max_bin=$guess_bin; $hist[$max_bin]; $max_bin++) { } |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
418 |
for ($min_bin=$guess_bin; $hist[$min_bin]; $min_bin--) { } |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
419 |
return ($min_bin,$max_bin+1); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
420 |
} |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
421 |
|
18 | 422 |
unless ($opt_r) { |
423 |
print(STDERR "Editing Data...") if ($opt_v); |
|
424 |
||
425 |
#---------------------------------------- |
|
49 | 426 |
# trim initial scans with |
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
427 |
# - nan pressure |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
428 |
# - nan conductivity |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
429 |
# - conductivity <= 10 mS/cm |
18 | 430 |
#---------------------------------------- |
431 |
my($trimmed) = 0; # trim leading nan pressures |
|
432 |
shift(@ants_),$trimmed++ |
|
42 | 433 |
# ,printf(STDERR "-> p=$ants_[0][$pressF] c=$ants_[0][$condF]\n") |
39 | 434 |
until !@ants_ || |
435 |
numberp($ants_[0][$pressF]) && |
|
436 |
numberp($ants_[0][$condF]) && |
|
437 |
(($P{'cond.unit'} eq 'mS/cm' && $ants_[0][$condF] > 10) || |
|
438 |
($P{'cond.unit'} eq 'S/m' && $ants_[0][$condF] > 1)); |
|
49 | 439 |
_croak("\n$CNVfile: no valid scans (wrong conductivity units?)\n") |
440 |
unless (@ants_); |
|
441 |
$nscans -= $trimmed; |
|
442 |
printf(STDERR "\n\t%d initial in-air scans trimmed",$trimmed) if ($opt_v > 1); |
|
18 | 443 |
my($lvp) = $ants_[0][$pressF]; |
29 | 444 |
my($lvc) = $ants_[0][$condF]; |
18 | 445 |
|
49 | 446 |
#------------------------------------------------------------------------- |
18 | 447 |
# edit pressure outliers outside contiguous range |
49 | 448 |
# - 2dbar resolution increased to 3dbar because of 2005 AAIW profile 004 |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
449 |
# - histogram shifted by 100dbar to allow for negative values |
49 | 450 |
#------------------------------------------------------------------------- |
451 |
my($press_rez) = 2; |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
452 |
my($outliers) = my($modeSamp) = 0; my($modeBin,$min,$max); local(@hist); |
18 | 453 |
for (my($s)=0; $s<$nscans; $s++) { |
52 | 454 |
$ants_[$s][$pressF] = nan unless defined($ants_[$s][$pressF]); |
29 | 455 |
next unless ($ants_[$s][$pressF]>=-100 && $ants_[$s][$pressF]<=6500); |
49 | 456 |
my($b) = ($ants_[$s][$pressF]+100) / $press_rez; |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
457 |
$hist[$b]++; |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
458 |
next unless ($hist[$b] > $modeSamp); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
459 |
$modeSamp = $hist[$b]; $modeBin = $b; |
18 | 460 |
} |
49 | 461 |
printf(STDERR "\n\tvalid pressure guess: %d dbar (%d samples)",$press_rez*$modeBin-100,$modeSamp) |
33 | 462 |
if ($opt_v > 1); |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
463 |
($min,$max) = validRange($modeBin); |
49 | 464 |
$min = $press_rez*$min-100; $max = $press_rez*$max-100; |
18 | 465 |
for (my($s)=0; $s<$nscans; $s++) { |
52 | 466 |
next unless numberp($ants_[$s][$pressF]); |
18 | 467 |
if ($ants_[$s][$pressF] > $max) { $outliers++; $ants_[$s][$pressF] = nan; } |
468 |
if ($ants_[$s][$pressF] < $min) { $outliers++; $ants_[$s][$pressF] = nan; } |
|
469 |
} |
|
470 |
&antsAddParams("pressure_outliers",sprintf("%d",$outliers)); |
|
471 |
printf(STDERR "\n\tcontinuous pressure range: %d..%d dbar (%d outliers removed)",$min,$max,$outliers) if ($opt_v > 1); |
|
49 | 472 |
_croak("$CNVfile: pressure editing removed too many 'outliers'\n") |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
473 |
unless ($opt_o || $outliers < 100); |
18 | 474 |
|
475 |
#---------------------------------------------------- |
|
476 |
# edit conductivity outliers outside contiguous range |
|
477 |
#---------------------------------------------------- |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
478 |
$outliers = $modeSamp = 0; |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
479 |
undef(@hist); |
18 | 480 |
for (my($s)=0; $s<$nscans; $s++) { |
52 | 481 |
$ants_[$s][$condF] = nan unless defined($ants_[$s][$condF]); |
18 | 482 |
next unless ($ants_[$s][$condF] > 0); |
483 |
my($b) = $ants_[$s][$condF]*$condHistRes; # 1/10 S/m histogram resolution (1 mS/cm) |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
484 |
$hist[$b]++; |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
485 |
next unless ($hist[$b] > $modeSamp); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
486 |
$modeSamp = $hist[$b]; $modeBin = $b; |
18 | 487 |
} |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
488 |
($min,$max) = validRange($modeBin); |
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
489 |
$min /= $condHistRes; $max /= $condHistRes; |
18 | 490 |
for (my($s)=0; $s<$nscans; $s++) { |
52 | 491 |
next unless numberp($ants_[$s][$condF]); |
18 | 492 |
if ($ants_[$s][$condF] > $max) { $outliers++; $ants_[$s][$condF] = nan; } |
493 |
if ($ants_[$s][$condF] < $min) { $outliers++; $ants_[$s][$condF] = nan; } |
|
494 |
} |
|
495 |
&antsAddParams("conductivity_outliers",sprintf("%d",$outliers)); |
|
496 |
printf(STDERR "\n\tcontinuous conductivity range: %.1f..%.1f S/m (%d outliers removed)",$min,$max,$outliers) if ($opt_v > 1); |
|
49 | 497 |
_croak("$CNVfile: conductivity editing removed too many 'outliers'\n") |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
498 |
unless ($opt_o || $outliers/$nscans < 0.4); |
18 | 499 |
|
500 |
#---------------------------------------------------- |
|
501 |
# edit temperature outliers outside contiguous range |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
502 |
# - Stan's NBP0901 profiles require resolution of 1deg |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
503 |
# - otherwise 0.2deg seems to be fine |
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
504 |
# - however, on Feb 19, 2016 it was found that the |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
505 |
# resolution had been left at 1degC without any |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
506 |
# apparent adverse effects |
18 | 507 |
#---------------------------------------------------- |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
508 |
$outliers = $modeSamp = 0; |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
509 |
undef(@hist); |
18 | 510 |
for (my($s)=0; $s<$nscans; $s++) { |
52 | 511 |
$ants_[$s][$tempF] = nan unless defined($ants_[$s][$tempF]); |
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
512 |
next unless ($ants_[$s][$tempF] >= -10); |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
513 |
my($b) = ($ants_[$s][$tempF] + 10) * 0.5; |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
514 |
$hist[$b]++; |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
515 |
next unless ($hist[$b] > $modeSamp); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
516 |
$modeSamp = $hist[$b]; $modeBin = $b; |
18 | 517 |
} |
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
518 |
# printf(STDERR "\n\ttemperature mode: %.1f degC (%d samples)",$modeBin/0.5-10,$modeSamp) |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
519 |
# if ($opt_v > 1); |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
520 |
($min,$max) = validRange($modeBin); |
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
521 |
$min = ($min / 0.5) - 10; |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
522 |
$max = ($max / 0.5) - 10; |
18 | 523 |
for (my($s)=0; $s<$nscans; $s++) { |
52 | 524 |
next unless numberp($ants_[$s][$tempF]); |
18 | 525 |
if ($ants_[$s][$tempF] > $max) { $outliers++; $ants_[$s][$tempF] = nan; } |
526 |
if ($ants_[$s][$tempF] < $min) { $outliers++; $ants_[$s][$tempF] = nan; } |
|
527 |
} |
|
528 |
&antsAddParams("temperature_outliers",sprintf("%d",$outliers)); |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
529 |
printf(STDERR "\n\tcontinuous temperature range: %.1f..%.1f degC (%d outliers removed)",$min,$max,$outliers) |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
530 |
if ($opt_v > 1); |
49 | 531 |
_croak("$CNVfile: temperature editing removed too many 'outliers'\n") |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
532 |
unless ($opt_o || $outliers/$nscans < 0.4); |
18 | 533 |
|
534 |
#---------------------------------------- |
|
535 |
# edit pressure spikes based on gradients |
|
536 |
#---------------------------------------- |
|
537 |
||
29 | 538 |
for (my($s)=1; $s<$nscans; $s++) { # calculate pressure gradients (across gaps) |
18 | 539 |
if (numberp($ants_[$s][$pressF])) { |
540 |
$dp[$s-1] = $ants_[$s][$pressF] - $lvp; |
|
541 |
$lvp = $ants_[$s][$pressF]; |
|
542 |
} else { |
|
543 |
$dp[$s-1] = nan; |
|
544 |
} |
|
545 |
} |
|
546 |
||
547 |
my($ns1,$ns2) = (0,0); |
|
548 |
for (my($s)=0; $s<$nscans-2; $s++) { # consecutive large pressure gradients of opposite sign |
|
549 |
if (($dp[$s]*$dp[$s+1] < 0) && # tests return false if either of the dps is not defined |
|
550 |
(abs($dp[$s]) > 10) && |
|
551 |
(abs($dp[$s+1]) > 10)) { |
|
552 |
$ants_[$s+1][$pressF] = nan; |
|
553 |
$dp[$s] = $dp[$s+1] = undef; |
|
554 |
$ns1++; |
|
555 |
} |
|
556 |
} |
|
557 |
for (my($s)=0; $s<$nscans-3; $s++) { # 3 consecutive large pressure gradients of opposite sign |
|
558 |
if (($dp[$s]>2 && $dp[$s+1]<-4 && $dp[$s+2]>2) || |
|
559 |
($dp[$s]<-2 && $dp[$s+1]>4 && $dp[$s+2]<-2)) { |
|
560 |
$ants_[$s+1][$pressF] = $ants_[$s+2][$pressF] = nan; |
|
561 |
$dp[$s] = $dp[$s+1] = $dp[$s+2] = undef; |
|
562 |
$ns2+=2; |
|
563 |
} |
|
564 |
} |
|
565 |
&antsAddParams("pressure_spikes_removed",sprintf("%d+%d",$ns1,$ns2)); |
|
49 | 566 |
printf(STDERR "\n\t%d+%d pressure spikes removed",$ns1,$ns2) if ($opt_v>1 && $ns1+$ns2>0); |
18 | 567 |
|
29 | 568 |
#-------------------------------------------------- |
569 |
# edit conductivity spikes based on large gradients |
|
570 |
# - $lvc = $ants_[0] is guaranteed numeric here |
|
571 |
#-------------------------------------------------- |
|
572 |
||
573 |
my($nv) = my($ns) = my($last_dcond) = my($lvcs) = 0; |
|
574 |
my($run_start) = my($run_dcond) = 0; |
|
575 |
for (my($s)=1; $s<$nscans; $s++) { # calculate conductivity gradients (across gaps) |
|
576 |
next unless numberp($ants_[$s][$condF]); |
|
577 |
||
578 |
my($dcond) = $ants_[$s][$condF] - $lvc; # integrate gradient across runs |
|
579 |
# print(STDERR "ldc/dc/rdc: $last_dcond/$dcond/$run_dcond\n"); |
|
580 |
if ($last_dcond*$dcond >= 0) { # run is continuing (gradient does not change sign) |
|
581 |
$run_dcond += $dcond; |
|
582 |
} else { # run has ended |
|
583 |
# print(STDERR "new run at $lvcs (run_dcond = $last_dcond)\n"); |
|
584 |
$run_start = $lvcs; |
|
585 |
$run_dcond = $dcond; |
|
586 |
} |
|
587 |
||
588 |
if (abs($run_dcond) <= 0.02) { # small integrated gradient => okay |
|
589 |
$lvc = $ants_[$s][$condF]; # update stored previous values |
|
590 |
$lvcs = $s; |
|
591 |
$last_dcond = $dcond; |
|
592 |
next; # process next scan |
|
593 |
} |
|
594 |
||
595 |
# print(STDERR "large gradient ($ants_[$run_start][$condF]-$ants_[$s][$condF], $run_dcond) run $run_start-$s\n"); |
|
596 |
my($i); |
|
597 |
my($max_spike_length) = 24; |
|
598 |
for ($i=$s; $i<=$run_start+$max_spike_length && $i<$nscans-1; $i++) { # large gradient => check whether values return within 10s |
|
599 |
next unless (numberp($ants_[$i][$condF]) && |
|
600 |
numberp($ants_[$i+1][$condF])); |
|
601 |
last if ((abs($ants_[$i][$condF]-$ants_[$run_start][$condF]) <= 0.005) && # 2 vals to avoid large gradients |
|
602 |
(abs($ants_[$i+1][$condF]-$ants_[$run_start][$condF]) <= 0.005)); |
|
603 |
} |
|
604 |
||
605 |
if ($i>$run_start+$max_spike_length || $i==$nscans-1) { # values don't return => leave data alone |
|
606 |
# print(STDERR "values don't return => new run at $s\n"); |
|
607 |
$run_start = $s; $run_dcond = 0; |
|
608 |
$lvc = $ants_[$run_start][$condF]; # start new run |
|
609 |
$lvcs = $run_start; |
|
610 |
$last_dcond = 0; |
|
611 |
next; # process next scan |
|
612 |
} |
|
613 |
||
614 |
$ns++; |
|
615 |
for (my($j)=$run_start+1; $j<$i; $j++) { # values return => remove bad spike |
|
616 |
$ants_[$j][$condF] = nan; |
|
617 |
$nv++; |
|
618 |
} |
|
619 |
# print(STDERR "values return at $i ($ants_[$i][$condF]) => deleted $run_start+1-$i; new run\n"); |
|
620 |
$run_start = $i; $run_dcond = 0; |
|
621 |
$lvc = $ants_[$run_start][$condF]; |
|
622 |
$lvcs = $run_start; |
|
623 |
$last_dcond = 0; |
|
624 |
} |
|
625 |
&antsAddParams("conductivity_spikes_removed",$ns); |
|
626 |
printf(STDERR "\n\t%d conductivity values removed from %d spikes",$nv,$ns) if ($opt_v > 1); |
|
627 |
||
18 | 628 |
printf(STDERR "\n") if ($opt_v); |
629 |
||
630 |
} # if $opt_r |
|
631 |
||
632 |
#---------------------------------------------------------------------- |
|
633 |
# Correcting for pressure bias |
|
634 |
#---------------------------------------------------------------------- |
|
635 |
||
636 |
print(STDERR "Correcting for pressure bias...") if ($opt_v); |
|
637 |
||
638 |
my($minP) = 9e99; |
|
639 |
for (my($s)=0; $s<$nscans; $s++) { |
|
640 |
$minP = $ants_[$s][$pressF] |
|
641 |
if numberp($ants_[$s][$pressF]) && ($ants_[$s][$pressF] < $minP); |
|
642 |
} |
|
49 | 643 |
_croak("$CNVfile: no valid CTD pressure data below 25dbar\n") |
18 | 644 |
unless ($minP < 9e99); |
29 | 645 |
|
646 |
if ($minP < 25) { |
|
647 |
&antsAddParams('pressure_bias',$minP); |
|
648 |
printf(STDERR "\n\tsubtracting %.1f dbar",$minP) if ($opt_v > 1); |
|
649 |
for (my($s)=0; $s<$nscans; $s++) { |
|
650 |
$ants_[$s][$pressF] -= $minP |
|
651 |
if numberp($ants_[$s][$pressF]); |
|
652 |
} |
|
653 |
} else { |
|
654 |
printf(STDERR "\n\tpartial-depth cast below %.1f dbar (no correction applied)",$minP) if ($opt_v > 1); |
|
18 | 655 |
} |
656 |
printf(STDERR "\n") if ($opt_v); |
|
657 |
||
658 |
#---------------------------------------------------------------------- |
|
49 | 659 |
# Removing Initial At-Surface Data |
660 |
#---------------------------------------------------------------------- |
|
661 |
||
662 |
print(STDERR "Removing intial at-surface data...") if ($opt_v); |
|
663 |
||
664 |
my($trimmed) = 0; |
|
665 |
while ($ants_[$trimmed][$pressF] < 0.5) { $trimmed++; } |
|
666 |
for (my($r)=$trimmed; $r<$nscans; $r++) { |
|
667 |
$ants_[$r][$elapsedF] -= $ants_[$trimmed][$elapsedF]; |
|
668 |
} |
|
669 |
splice(@ants_,0,$trimmed); |
|
670 |
$nscans -= $trimmed; |
|
671 |
||
672 |
&antsAddParams('surface_data_trimmed',int($trimmed*$sampint)); |
|
673 |
&antsAddParams('cast_duration',int($nscans*$sampint)); |
|
674 |
||
675 |
printf(STDERR "\n\t%d seconds of data trimmed",int($trimmed*$sampint)) if ($opt_v > 1); |
|
676 |
||
677 |
printf(STDERR "\n") if ($opt_v); |
|
678 |
||
679 |
#---------------------------------------------------------------------- |
|
54 | 680 |
# Fill Missing Data With Linear Interpolation |
681 |
#---------------------------------------------------------------------- |
|
682 |
||
683 |
if ($opt_f) { |
|
684 |
print(STDERR "Filling CTD time-series data gaps...") if ($opt_v); |
|
685 |
||
686 |
for (my($f)=0; $f<@antsLayout; $f++) { |
|
687 |
&ISInit($f,-1); |
|
688 |
} |
|
689 |
||
690 |
my($interpolated) = 0; |
|
691 |
my($not_interpolated) = 0; |
|
692 |
||
693 |
for (my($s)=0; $s<@ants_; $s++) { |
|
694 |
for (my($f)=0; $f<@antsLayout; $f++) { |
|
695 |
if (numberp($ants_[$s][$f])) { |
|
696 |
$lastValid[$f] = $f; |
|
697 |
next; |
|
698 |
} |
|
699 |
$not_interpolated++,next unless defined($lastValid[$f]); |
|
700 |
my($iv) = interpolate(-1,100,$f,$lastValid[$f],$s); |
|
701 |
$not_interpolated++,next unless numberp($iv); |
|
702 |
$ants_[$s][$f] = $iv; |
|
703 |
$interpolated++; |
|
704 |
} |
|
705 |
} |
|
706 |
||
707 |
if ($opt_v > 1) { |
|
708 |
print(STDERR "\n\t$interpolated values interpolated"); |
|
709 |
print(STDERR "\n\t$not_interpolated non-interpolatable missing values left"); |
|
710 |
} |
|
711 |
||
712 |
printf(STDERR "\n") if ($opt_v); |
|
713 |
} # if ($opt_f |
|
714 |
||
715 |
#---------------------------------------------------------------------- |
|
18 | 716 |
# Binning data |
717 |
#---------------------------------------------------------------------- |
|
718 |
||
719 |
my($sps) = round(1 / $sampint / $opt_s); |
|
720 |
print(STDERR "Creating ${opt_s}Hz time series ($sps samples per bin)...") if ($opt_v); |
|
35
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
721 |
&antsAddParams('sampling_interval',1/$opt_s); |
54b8bb450e5f
Version 1.2 finished. Out for testing to Jay Hooper.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
722 |
&antsAddParams('sampling_frequency',$opt_s); |
18 | 723 |
|
724 |
my(@press,@temp,@cond); |
|
725 |
my($sp,$np,$st,$nt,$sc,$nc); |
|
726 |
||
727 |
$sp = $st = $sc = $np = $nt = $nc = 0; |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
728 |
$slat = $slon = $nGPS = 0; |
18 | 729 |
for (my($rec)=1,my($s)=0; $s<$nscans; $s++) { |
730 |
if ($s*$sampint > $rec/$opt_s) { |
|
731 |
$rec++; |
|
732 |
push(@press,$np>0?$sp/$np:nan); |
|
733 |
push(@temp, $nt>0?$st/$nt:nan); |
|
734 |
push(@cond, $nc>0?$sc/$nc:nan); |
|
735 |
$sp = $st = $sc = $np = $nt = $nc = 0; |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
736 |
if (defined($latF)) { |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
737 |
push(@lat,$nGPS>0?$slat/$nGPS:nan); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
738 |
push(@lon,$nGPS>0?$slon/$nGPS:nan); |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
739 |
$slat = $slon = $nGPS = 0; |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
740 |
} |
18 | 741 |
} |
742 |
$sp+=$ants_[$s][$pressF],$np++ if numberp($ants_[$s][$pressF]); |
|
743 |
$st+=$ants_[$s][$tempF],$nt++ if numberp($ants_[$s][$tempF]); |
|
744 |
$sc+=$ants_[$s][$condF],$nc++ if numberp($ants_[$s][$condF]); |
|
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
745 |
if (defined($latF) && numberp($ants_[$s][$latF])) { |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
746 |
$slat += $ants_[$s][$latF]; |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
747 |
$slon += $ants_[$s][$lonF]; |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
748 |
$nGPS++; |
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
749 |
} |
18 | 750 |
} |
751 |
||
752 |
printf(STDERR "\n") if ($opt_v); |
|
753 |
||
754 |
#---------------------------------------------------------------------- |
|
755 |
# Calculating derived quantities |
|
756 |
#---------------------------------------------------------------------- |
|
757 |
||
758 |
print(STDERR "Calculating vertical package velocity & sound speed...") if ($opt_v); |
|
759 |
||
29 | 760 |
my($maxP) = -9e99; my($atBtm); |
761 |
my($min_sspd) = 9e99; my($max_sspd) = -9e99; |
|
18 | 762 |
for (my($r)=0; $r<@press; $r++) { |
29 | 763 |
$maxP=$press[$r],$atBtm=$r if ($press[$r] > $maxP); |
18 | 764 |
$elapsed[$r] = $r/$opt_s; |
765 |
$depth[$r] = &depth($press[$r],$lat); |
|
39 | 766 |
# print(STDERR "depth[$r] = depth($press[$r],$lat) = $depth[$r]\n"); |
29 | 767 |
$salin[$r] = &salin($cond[$r],$temp[$r],$press[$r]); |
54 | 768 |
$salin[$r] -= $opt_b; |
29 | 769 |
$sspd[$r] = &sVel($salin[$r],$temp[$r],$press[$r]); |
770 |
$min_sspd = $sspd[$r] if ($sspd[$r] < $min_sspd); |
|
771 |
$max_sspd = $sspd[$r] if ($sspd[$r] > $max_sspd); |
|
18 | 772 |
} |
773 |
||
774 |
$w[0] = nan; |
|
775 |
for (my($r)=1; $r<@depth-1; $r++) { |
|
776 |
$w[$r] = numbersp($depth[$r-1],$depth[$r+1]) |
|
777 |
? ($depth[$r+1] - $depth[$r-1]) * $opt_s |
|
778 |
: nan; |
|
779 |
} |
|
780 |
push(@w,nan); |
|
781 |
||
782 |
printf(STDERR "\n") if ($opt_v); |
|
783 |
||
784 |
#---------------------------------------------------------------------- |
|
785 |
# Low-pass filter velocity data |
|
786 |
# - interpolate missing vertical velocities first |
|
787 |
#---------------------------------------------------------------------- |
|
788 |
||
49 | 789 |
if ($opt_c > 0) { |
18 | 790 |
print(STDERR "Low-pass filtering vertical package velocity...") if ($opt_v); |
49 | 791 |
&antsAddParams('w_lowpass_cutoff',$opt_c); |
18 | 792 |
|
793 |
my($trimmed) = 0; |
|
794 |
shift(@w),shift(@depth),shift(@elapsed),shift(@sspd),$trimmed++ |
|
795 |
until numberp($w[0]); |
|
796 |
my($interpolated) = 0; |
|
797 |
for ($r=1; $r<@w; $r++) { |
|
798 |
next if numberp($w[$r]); |
|
799 |
my($lv) = $r-1; |
|
800 |
for ($nv=$r+1; $nv<@depth && !numberp($w[$nv]); $nv++) {} |
|
801 |
if ($nv < @depth) { |
|
802 |
while ($r < $nv) { |
|
803 |
$w[$r] = $w[$lv] + ($r-$lv)/($nv-$lv) * ($w[$nv]-$w[$lv]); |
|
804 |
$interpolated++; |
|
805 |
$r++; |
|
806 |
} |
|
807 |
||
808 |
} else { |
|
809 |
$trimmed += @w-$r; |
|
810 |
splice(@w,$r); splice(@depth,$r); |
|
811 |
splice(@elapsed,$r); splice(@sspd,$r); |
|
812 |
} |
|
813 |
} |
|
814 |
&antsAddParams('w_interpolated',$interpolated); |
|
815 |
printf(STDERR "\n\t%d/%d vertical velocities trimmed/interpolated",$trimmed,$interpolated) if ($opt_v > 1); |
|
816 |
||
817 |
||
818 |
#-------------------- |
|
819 |
# Zero Pad Data |
|
820 |
#-------------------- |
|
821 |
||
822 |
for ($pot=1; $pot<@w; $pot<<=1) {} # determine power of two |
|
823 |
||
824 |
for ($r=0; $r<@w; $r++) { # copy data |
|
825 |
$fftbuf[2*$r] = $w[$r]; |
|
826 |
$fftbuf[2*$r+1] = 0; |
|
827 |
} |
|
49 | 828 |
printf(STDERR "\n\tzero-padded %d scans",$pot-$r) if ($opt_v > 1); |
18 | 829 |
while ($r < $pot) { # pad with zeroes |
830 |
$fftbuf[2*$r] = $fftbuf[2*$r+1] = 0; |
|
831 |
$r++; |
|
832 |
} |
|
833 |
||
834 |
#-------------------- |
|
835 |
# Low-Pass Filter |
|
836 |
#-------------------- |
|
837 |
||
838 |
@fco = &FOUR1(-1,@fftbuf); # forward FFT |
|
839 |
$n = @fco/2; |
|
840 |
for (my($ip)=2; $ip<=$n; $ip+=2) { # +ve freq fco |
|
841 |
my($in) = 2*$n-$ip; # -ve freq fco |
|
842 |
my($f) = $ip/2/$n*$opt_s; # frequency |
|
843 |
$fco[$ip] = $fco[$ip+1] = $fco[$in] = $fco[$in+1] = 0 |
|
49 | 844 |
if ($f > 1/$opt_c); # low-pass filter |
18 | 845 |
} |
846 |
@w_lp = &FOUR1(1,@fco); # inverse FFT |
|
847 |
||
848 |
printf(STDERR "\n") if ($opt_v); |
|
849 |
} else { |
|
850 |
@w_lp = @w; |
|
851 |
} |
|
852 |
||
47
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
853 |
#---------------------------------------- |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
854 |
# Estimate winch speed |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
855 |
#---------------------------------------- |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
856 |
|
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
857 |
print(STDERR "Estimating winch velocity...") if ($opt_v); |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
858 |
&antsAddParams('winch_velocity_granularity',$opt_w); |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
859 |
|
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
860 |
my($from_r) = 0; my($to_r); # step 1: bin average in time |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
861 |
for (my($from_r)=my($to_r)=0; $from_r<@elapsed; $from_r=$to_r+1) { |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
862 |
my($sumw) = $w_lp[2*$from_r]/@w_lp; my($n) = 1; |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
863 |
for ($to_r=$from_r+1; $to_r<@elapsed && $elapsed[$to_r]-$elapsed[$from_r]<$opt_w; $to_r++) { |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
864 |
$sumw += $w_lp[2*$to_r]/@w_lp; $n++; |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
865 |
} |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
866 |
$winch[$from_r] = $sumw/$n; |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
867 |
} |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
868 |
|
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
869 |
my($pwinch) = $winch[0]; |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
870 |
for (my($to_r),my($from_r)=0; $from_r<@elapsed; ) { # step 2: fill after median filtering |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
871 |
for ($to_r=$from_r+1; $to_r<@elapsed && !defined($winch[$to_r]); $to_r++) {} |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
872 |
my($nwinch) = $to_r<@elapsed ? $winch[$to_r] : $winch[$from_r]; |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
873 |
my($winch) = median($pwinch,$winch[$from_r],$nwinch); |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
874 |
$pwinch = $winch[$from_r]; $winch[$from_r] = $winch; |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
875 |
while (++$from_r < $to_r) { $winch[$from_r] = $winch[$from_r-1]; } |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
876 |
} |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
877 |
|
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
878 |
printf(STDERR "\n") if ($opt_v); |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
879 |
|
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
880 |
#---------------------------------------- |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
881 |
# Plot Data |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
882 |
#---------------------------------------- |
18 | 883 |
|
29 | 884 |
if (defined($opt_p)) { |
885 |
print(STDERR "Plotting data...\n") if ($opt_v); |
|
886 |
my(@pfmt) = split(',',$opt_p); |
|
49 | 887 |
_croak("$0: cannot decode -p $opt_p\n") |
29 | 888 |
unless (@pfmt == 2); |
889 |
||
890 |
my($xmin) = $elapsed[0]/60; |
|
891 |
my($xmax) = $elapsed[$#elapsed]/60; |
|
892 |
my($ymin) = -3; my($ymax) = 3; |
|
893 |
my($plotsize) = '13c'; |
|
49 | 894 |
|
895 |
_croak(sprintf("%s: invalid region of interest (-R$xmin/$xmax/$ymin/$ymax)\n",sprintf($pfmt[0],$id))) |
|
896 |
unless ($xmax > $xmin && $ymax > $ymin); |
|
31 | 897 |
GMT_begin(sprintf($pfmt[0],$id),"-JX${plotsize}","-R$xmin/$xmax/$ymin/$ymax",'-X6 -Y4 -P'); |
41 | 898 |
GMT_psxy('-W1,coral'); |
29 | 899 |
for ($r=0; $r<@w; $r++) { |
900 |
printf(GMT "%f %f\n",$elapsed[$r]/60,$w_lp[2*$r]/@w_lp); |
|
41 | 901 |
GMT_psxy('-W1,SeaGreen') if ($r == $atBtm); |
29 | 902 |
} |
47
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
903 |
GMT_psxy('-W1,magenta'); |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
904 |
for ($r=0; $r<@w; $r++) { |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
905 |
printf(GMT "%f %f\n",$elapsed[$r]/60,$winch[$r]); |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
906 |
} |
48 | 907 |
GMT_psbasemap('-Bg60a30f5:"Elapsed Time [min]":/g1a1f0.1:"Downward Package Velocity [ms@+-1@+]":WeSn'); |
29 | 908 |
GMT_unitcoords(); |
47
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
909 |
GMT_pstext('-F+f14,Helvetica,coral+jBR'); print(GMT "0.98 0.96 dc\n"); |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
910 |
GMT_pstext('-F+f14,Helvetica,SeaGreen+jBR'); print(GMT "0.98 0.93 uc\n"); |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
911 |
GMT_pstext('-F+f14,Helvetica,magenta+jBR'); print(GMT "0.98 0.89 winch\n"); |
41 | 912 |
GMT_pstext('-F+f14,Helvetica,blue+jTL -N'); |
913 |
if (defined($outfile)) { printf(GMT "0.01 1.06 $outfile\n",$id); } |
|
914 |
else { printf(GMT "0.01 1.06 %03d\n",$id); } |
|
29 | 915 |
GMT_end(); |
916 |
||
917 |
my($xmin) = round($min_sspd-3,5); |
|
918 |
my($xmax) = round($max_sspd+3,5); |
|
919 |
my($ymin) = 0; my($ymax) = round($depth[$atBtm]+70,100); |
|
920 |
my($plotsize) = '13c'; |
|
49 | 921 |
_croak(sprintf("%s: invalid region of interest (-R$xmin/$xmax/$ymin/$ymax)\n",sprintf($pfmt[1],$id))) |
922 |
unless ($xmax > $xmin && $ymax > $ymin); |
|
31 | 923 |
GMT_begin(sprintf($pfmt[1],$id),"-JX${plotsize}/-${plotsize}","-R$xmin/$xmax/$ymin/$ymax",'-X6 -Y4 -P'); |
29 | 924 |
GMT_psbasemap('-Bg10a10f1:"Speed of Sound [m/s]":/g1000a500f100:"Depth [m]":WeSn'); |
41 | 925 |
GMT_psxy('-W2,coral'); |
29 | 926 |
for ($r=0; $r<@w; $r++) { |
927 |
printf(GMT "%f %f\n",$sspd[$r],$depth[$r]); |
|
41 | 928 |
GMT_psxy('-W1.5,SeaGreen') if ($r == $atBtm); |
29 | 929 |
} |
930 |
GMT_unitcoords(); |
|
47
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
931 |
GMT_pstext('-F+f14,Helvetica,coral+jTR'); print(GMT "0.98 0.02 dc\n"); |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
932 |
GMT_pstext('-F+f14,Helvetica,SeaGreen+jTR'); print(GMT "0.98 0.06 uc\n"); |
41 | 933 |
GMT_pstext('-F+f14,Helvetica,blue+jTL -N'); |
934 |
if (defined($outfile)) { printf(GMT "0.01 -0.06 $outfile\n",$id); } |
|
935 |
else { printf(GMT "0.01 -0.06 %03d\n",$id); } |
|
29 | 936 |
GMT_end(); |
937 |
} |
|
938 |
||
939 |
#---------------------------------------------------------------------- |
|
940 |
||
18 | 941 |
print(STDERR "Writing output...\n") if ($opt_v); |
942 |
||
47
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
943 |
@antsNewLayout = ('elapsed','press','temp','cond','depth','salin','sspd','w_CTD.raw','w_CTD','w_winch','lat','lon'); |
18 | 944 |
for ($r=0; $r<@w; $r++) { |
32
6041a20feb39
V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
31
diff
changeset
|
945 |
&antsOut($elapsed[$r],$press[$r],$temp[$r],$cond[$r],$depth[$r],$salin[$r], |
47
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
946 |
$sspd[$r],$w[$r],$w_lp[2*$r]/@w_lp,$winch[$r], |
2ccb81b7cea5
version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
947 |
$lat[$r],$lon[$r]); |
18 | 948 |
} |
949 |
||
950 |
exit(0); # don't flush @ants_ |