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