author | Andreas Thurnherr <ant@ldeo.columbia.edu> |
Mon, 12 Sep 2022 12:41:42 -0400 | |
changeset 52 | cab17f0c5e88 |
parent 51 | 14ce2387de5e |
permissions | -rw-r--r-- |
10 | 1 |
#====================================================================== |
2 |
# L I B S B E . P L |
|
3 |
# doc: Mon Nov 3 12:42:14 2014 |
|
51
14ce2387de5e
improved libSBE.pl
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
38
diff
changeset
|
4 |
# dlm: Mon Jun 27 18:37:05 2022 |
10 | 5 |
# (c) 2014 A.M. Thurnherr |
51
14ce2387de5e
improved libSBE.pl
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
38
diff
changeset
|
6 |
# uE-Info: 29 33 NIL 0 0 72 2 2 4 NIL ofnI |
10 | 7 |
#====================================================================== |
8 |
||
9 |
# HISTORY: |
|
10 |
# Nov 3, 2014: - exported from [importCNV] |
|
21 | 11 |
# Jun 16, 2015: - cosmetics |
12 |
# Jun 17, 2015: - ensured numeric retvals of SBE_parseheader are returned as numbers |
|
13 |
# Jun 18, 2015: - BUG: binary code had several bugs |
|
23
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
14 |
# Sep 29, 2015: - added potemp and sigma standard field names |
28 | 15 |
# Mar 19, 2016: - BUG: conductivity unit checking on input had multiple bugs |
16 |
# - solution for files with multiple conductivity units: ignore |
|
38 | 17 |
# all conductivities with units not equal to the first cond var |
28 | 18 |
# - added $libSBE_quiet to suppress diagnostic messages |
29
f41d125405a6
version after ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
28
diff
changeset
|
19 |
# May 31, 2016: - made successfully decoding lat/lon optional |
30 | 20 |
# Mar 10, 2017: - made lat/lon decoding more flexible |
36 | 21 |
# Mar 3, 2018: - adapted SBE37 fields (multiple changes) |
22 |
# - added default field name for sound speed (sspd) |
|
23 |
# Mar 8, 2018: - BUG: SBE_parseHeader() did not correctly detect missing lat/lon |
|
24 |
# - suppressed warnings in SBE_parseHeader() |
|
38 | 25 |
# Apr 23, 2018: - BUG: header lat/lon was incorrectly parsed when there was no space |
26 |
# before hemisphere |
|
27 |
# Jan 3, 2019: - BUG: SBE_parseHeader() did not correctly detect missing lat/lon |
|
51
14ce2387de5e
improved libSBE.pl
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
38
diff
changeset
|
28 |
# Jun 27, 2022: - BUG: ASCII data files can have format anomalies (missing space) on |
14ce2387de5e
improved libSBE.pl
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
38
diff
changeset
|
29 |
# bad data |
10 | 30 |
|
31 |
#---------------------------------------------------------------------- |
|
32 |
# fname_SBE2std($) |
|
33 |
# - standardize field names (also adds correct unit %PARAMs) |
|
34 |
#---------------------------------------------------------------------- |
|
35 |
||
36 |
sub fname_SBE2std($) |
|
37 |
{ |
|
38 |
$_ = $_[0]; |
|
39 |
||
40 |
return 'lat' if /^lat/; |
|
41 |
return 'lon' if /^lon/; |
|
36 | 42 |
return 'press' if /^pr[dD]M/; |
43 |
return 'sspd' if /^sv[dD]M/; |
|
10 | 44 |
return 'depth' if /^depSM/; |
45 |
return 'O2' if /^sbeox0/; |
|
46 |
return 'alt_O2' if /^sbeox1/; |
|
47 |
return 'salin' if /^sal00/; |
|
48 |
return 'alt_salin' if /^sal11/; |
|
49 |
return 'elapsed' if /^timeS/; |
|
36 | 50 |
return 'time_jday' if /^timeJV2/; |
23
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
51 |
return 'sigma0' if /^sigma.*00/; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
52 |
return 'alt_sigma0' if /^sigma.*11/; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
53 |
return 'rho0' if /^density00/; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
54 |
return 'alt_rho0' if /^density11/; |
10 | 55 |
|
56 |
if (/^t090/) { # temperatures with different scales |
|
28 | 57 |
return undef |
10 | 58 |
if defined($P{ITS}) && ($P{ITS} != 90); |
59 |
&antsAddParams('ITS',90); $P{ITS} = 90; |
|
60 |
return 'temp'; |
|
61 |
} elsif (/^t068/) { |
|
28 | 62 |
return undef |
10 | 63 |
if defined($P{ITS}) && ($P{ITS} != 68); |
64 |
&antsAddParams('ITS',68); $P{ITS} = 68; |
|
65 |
return 'temp'; |
|
66 |
} |
|
67 |
||
68 |
if (/^t190/) { |
|
28 | 69 |
return undef |
10 | 70 |
if defined($P{ITS}) && ($P{ITS} != 90); |
71 |
&antsAddParams('ITS',90); $P{ITS} = 90; |
|
72 |
return 'alt_temp'; |
|
73 |
} elsif (/^t168/) { |
|
28 | 74 |
return undef |
10 | 75 |
if defined($P{ITS}) && ($P{ITS} != 68); |
76 |
&antsAddParams('ITS',68); $P{ITS} = 68; |
|
77 |
return 'alt_temp'; |
|
78 |
} |
|
79 |
||
23
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
80 |
if (/^potemp090/) { # potential temperatures with different scales |
28 | 81 |
return undef |
23
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
82 |
if defined($P{ITS}) && ($P{ITS} != 90); |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
83 |
&antsAddParams('ITS',90); $P{ITS} = 90; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
84 |
return 'theta0'; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
85 |
} elsif (/^potemp068/) { |
28 | 86 |
return undef |
23
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
87 |
if defined($P{ITS}) && ($P{ITS} != 68); |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
88 |
&antsAddParams('ITS',68); $P{ITS} = 68; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
89 |
return 'theta0'; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
90 |
} |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
91 |
|
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
92 |
if (/^potemp190/) { |
28 | 93 |
return undef |
23
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
94 |
if defined($P{ITS}) && ($P{ITS} != 90); |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
95 |
&antsAddParams('ITS',90); $P{ITS} = 90; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
96 |
return 'alt_theta0'; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
97 |
} elsif (/^potemp168/) { |
28 | 98 |
return undef |
23
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
99 |
if defined($P{ITS}) && ($P{ITS} != 68); |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
100 |
&antsAddParams('ITS',68); $P{ITS} = 68; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
101 |
return 'alt_theta0'; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
102 |
} |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
103 |
|
36 | 104 |
if (m{^c0S/m} || m{^cond0S/m}) { # conductivity with different units |
28 | 105 |
return undef |
106 |
if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'S/m'); |
|
107 |
&antsAddParams('cond.unit','S/m'); |
|
10 | 108 |
return 'cond'; |
36 | 109 |
} elsif (m{^c0mS/cm} || m{^cond0mS/cm}) { |
28 | 110 |
return undef |
111 |
if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'mS/cm'); |
|
112 |
&antsAddParams('cond.unit','mS/cm'); |
|
10 | 113 |
return 'cond'; |
114 |
} |
|
115 |
||
36 | 116 |
if (m{^c1S/m} || m{^cond1S/m}) { |
28 | 117 |
return undef |
118 |
if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'S/m'); |
|
119 |
&antsAddParams('cond.unit','S/m'); |
|
10 | 120 |
return 'alt_cond'; |
36 | 121 |
} elsif (m{^c1mS/cm} || m{^cond1mS/cm}) { |
28 | 122 |
return undef |
123 |
if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'mS/cm'); |
|
124 |
&antsAddParams('cond.unit','mS/cm'); |
|
10 | 125 |
return 'alt_cond'; |
126 |
} |
|
127 |
||
128 |
return $_; |
|
129 |
} |
|
130 |
||
131 |
# same as above but leaving names in place (only setting %PARAMs) |
|
132 |
sub fname_SBE($) |
|
133 |
{ |
|
134 |
$_ = $_[0]; |
|
135 |
||
136 |
if (/^t090/) { # temperatures with different scales |
|
28 | 137 |
return undef |
10 | 138 |
if defined($P{ITS}) && ($P{ITS} != 90); |
139 |
&antsAddParams('ITS',90); $P{ITS} = 90; |
|
140 |
} elsif (/^t068/) { |
|
28 | 141 |
return undef |
10 | 142 |
if defined($P{ITS}) && ($P{ITS} != 68); |
143 |
&antsAddParams('ITS',68); $P{ITS} = 68; |
|
144 |
} |
|
145 |
||
146 |
if (/^t190/) { |
|
28 | 147 |
return undef |
10 | 148 |
if defined($P{ITS}) && ($P{ITS} != 90); |
149 |
&antsAddParams('ITS',90); $P{ITS} = 90; |
|
150 |
} elsif (/^t168/) { |
|
28 | 151 |
return undef |
10 | 152 |
if defined($P{ITS}) && ($P{ITS} != 68); |
153 |
&antsAddParams('ITS',68); $P{ITS} = 68; |
|
154 |
} |
|
155 |
||
23
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
156 |
if (/^potemp090/) { |
28 | 157 |
return undef |
23
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
158 |
if defined($P{ITS}) && ($P{ITS} != 90); |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
159 |
&antsAddParams('ITS',90); $P{ITS} = 90; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
160 |
} elsif (/^potemp068/) { |
28 | 161 |
return undef |
23
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
162 |
if defined($P{ITS}) && ($P{ITS} != 68); |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
163 |
&antsAddParams('ITS',68); $P{ITS} = 68; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
164 |
} |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
165 |
|
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
166 |
if (/^potemp190/) { |
28 | 167 |
return undef |
23
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
168 |
if defined($P{ITS}) && ($P{ITS} != 90); |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
169 |
&antsAddParams('ITS',90); $P{ITS} = 90; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
170 |
} elsif (/^potemp168/) { |
28 | 171 |
return undef |
23
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
172 |
if defined($P{ITS}) && ($P{ITS} != 68); |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
173 |
&antsAddParams('ITS',68); $P{ITS} = 68; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
174 |
} |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
175 |
|
36 | 176 |
if (m{^c0S/m} || m{^cond0S/m}) { # conductivity with different units |
28 | 177 |
return undef |
178 |
if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'S/m'); |
|
179 |
&antsAddParams('cond.unit','S/m'); |
|
36 | 180 |
} elsif (m{^c0mS/cm} || m{^cond0mS/cm}) { |
28 | 181 |
return undef |
182 |
if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'mS/cm'); |
|
183 |
&antsAddParams('cond.unit','mS/cm'); |
|
10 | 184 |
} |
185 |
||
36 | 186 |
if (m{^c1S/m} || m{^cond1S/m}) { |
28 | 187 |
return undef |
188 |
if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'S/m'); |
|
189 |
&antsAddParams('cond.unit','S/m'); |
|
36 | 190 |
} elsif (m{^c1mS/cm} || m{^cond1mS/cm}) { |
28 | 191 |
return undef |
192 |
if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'mS/cm'); |
|
193 |
&antsAddParams('cond.unit','mS/cm'); |
|
10 | 194 |
} |
195 |
||
196 |
return $_; |
|
197 |
} |
|
198 |
||
199 |
#---------------------------------------------------------------------- |
|
200 |
# SBE_checkTime($$) |
|
201 |
# - make sure all times are (roughly) the same |
|
202 |
#---------------------------------------------------------------------- |
|
203 |
||
204 |
{ # static scope |
|
205 |
my($target_month,$target_day,$target_year,$target_time); |
|
206 |
||
207 |
sub SBE_checkTime($$) |
|
208 |
{ |
|
209 |
return unless $_[1]; |
|
210 |
my($mo,$dy,$yr,$tm) = split('\s+',$_[0]); |
|
211 |
||
212 |
unless (defined($target_month)) { |
|
213 |
$target_month = $mo; |
|
214 |
$target_day = $dy; |
|
215 |
$target_year = $yr; |
|
216 |
$target_time = $tm; |
|
217 |
return; |
|
218 |
} |
|
219 |
||
220 |
croak("$0: inconsistent dates in header ($target_month $target_day $target_year vs $mo $dy $yr)\n") |
|
221 |
unless ($target_month eq $mo && $target_day == $dy && $target_year == $yr); |
|
222 |
croak("$0: inconsistent times in header ($target_time vs $tm)\n") |
|
223 |
unless (abs(frac_day(split(':',$target_time))-frac_day(split(':',$tm))) < 1/60/24); |
|
224 |
} |
|
225 |
||
226 |
} # static scope |
|
227 |
||
228 |
#---------------------------------------------------------------------- |
|
229 |
# sub SBE_parseHeader(FP,std-field-names,time-check) |
|
230 |
# - parse header information |
|
28 | 231 |
# - set @ignore_input_fields with fields with inconsistent units |
10 | 232 |
#---------------------------------------------------------------------- |
233 |
||
28 | 234 |
my(@ignore_input_fields); # in reverse order!!! |
235 |
||
10 | 236 |
sub SBE_parseHeader($$$) |
237 |
{ |
|
238 |
my($FP,$sfn,$tc) = @_; |
|
239 |
my($hdr,$nfields,$nrecs,$deg,$min,$NS,$EW,$lat,$lon,$sampint,$badval,$ftype); |
|
240 |
||
241 |
while (1) { # parse header |
|
242 |
chomp($hdr = <$FP>); |
|
243 |
$hdr =~ s/\r*$//; |
|
244 |
die("$0: unexpected EOF (format error)\n") unless defined($hdr); |
|
245 |
last if ($hdr eq '*END*'); |
|
246 |
||
247 |
$nfields = $',next if ($hdr =~ /nquan = /); # Layout |
|
248 |
$nrecs = $',next if ($hdr =~ /nvalues = /); |
|
249 |
if ($hdr =~ /name (\d+) = ([^:]+):/) { |
|
28 | 250 |
my($fn) = $sfn ? fname_SBE2std($2) : fname_SBE($2); |
251 |
if (defined($fn)) { |
|
252 |
push(@antsNewLayout,$fn); |
|
253 |
} else { |
|
254 |
unshift(@ignore_input_fields,$1); |
|
255 |
&antsInfo("CNV input field \#$1 ($2) ignored, because of unit inconsistency") |
|
256 |
unless defined($libSBE_quiet); |
|
257 |
} |
|
10 | 258 |
} |
259 |
||
21 | 260 |
SBE_checkTime($1,$tc),next # sanity time check |
10 | 261 |
if ($hdr =~ /NMEA UTC \(Time\) = (.*)/); |
262 |
SBE_checkTime($1,$tc),next |
|
263 |
if ($hdr =~ /System UpLoad Time = (.*)/); |
|
264 |
||
265 |
&antsAddParams('CNV_File',$1),next # selected metadata |
|
266 |
if ($hdr =~ /FileName = (.*)$/); |
|
267 |
SBE_checkTime($1,$tc),&antsAddParams('start_time',$1),next |
|
268 |
if ($hdr =~ /start_time = (.*)/); |
|
269 |
||
270 |
&antsAddParams('station',$1),next |
|
271 |
if ($hdr =~ /Station\s*:\s*(.*)/); |
|
272 |
&antsAddParams('ship',$1),next |
|
273 |
if ($hdr =~ /Ship\s*:\s*(.*)/); |
|
274 |
&antsAddParams('cruise',$1),next |
|
275 |
if ($hdr =~ /Cruise\s*:\s*(.*)/); |
|
276 |
&antsAddParams('time',$1),next |
|
277 |
if ($hdr =~ /Time\s*:\s*(.*)/); |
|
278 |
&antsAddParams('date',$1),next |
|
279 |
if ($hdr =~ /Date\s*:\s*(.*)/); |
|
280 |
||
281 |
if (($hdr =~ /Latitude\s*[:=]\s*/) && !defined($lat)) { |
|
36 | 282 |
# ($deg,$min,$NS) = split(/\s+/,$'); |
283 |
($deg,$min,$NS) = ($' =~ m{([^\s]+)\s+(\d+\.\d*)\s*([NS])}); |
|
29
f41d125405a6
version after ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
28
diff
changeset
|
284 |
if ($NS eq 'N' || $NS eq 'S') { |
f41d125405a6
version after ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
28
diff
changeset
|
285 |
$lat = $deg + $min/60; |
f41d125405a6
version after ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
28
diff
changeset
|
286 |
$lat *= -1 if ($NS eq 'S'); |
36 | 287 |
} elsif (!defined($NS) && defined($deg) && abs($deg)<=90 && ($min >= 0) && ($min <= 60)) { |
30 | 288 |
$lat = $deg + $min/60; |
29
f41d125405a6
version after ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
28
diff
changeset
|
289 |
} else { |
36 | 290 |
# print(STDERR "$0: WARNING: cannot decode latitude ($')\n"); |
29
f41d125405a6
version after ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
28
diff
changeset
|
291 |
$lat = nan; |
f41d125405a6
version after ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
28
diff
changeset
|
292 |
} |
10 | 293 |
&antsAddParams('lat',$lat); |
294 |
next; |
|
295 |
} |
|
296 |
if (($hdr =~ /Longitude\s*[:=]\s*/) && !defined($lon)) { |
|
36 | 297 |
# ($deg,$min,$EW) = split(/\s+/,$'); |
298 |
($deg,$min,$EW) = ($' =~ m{([^\s]+)\s+(\d+\.\d*)\s*([EW])}); |
|
29
f41d125405a6
version after ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
28
diff
changeset
|
299 |
if ($EW eq 'E' || $EW eq 'W') { |
f41d125405a6
version after ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
28
diff
changeset
|
300 |
$lon = $deg + $min/60; |
f41d125405a6
version after ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
28
diff
changeset
|
301 |
$lon *= -1 if ($EW eq 'W'); |
36 | 302 |
} elsif (!defined($EW) && defined($deg) && abs($deg)<=360 && ($min >= 0) && ($min <= 60)) { |
30 | 303 |
$lon = $deg + $min/60; |
29
f41d125405a6
version after ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
28
diff
changeset
|
304 |
} else { |
36 | 305 |
# print(STDERR "$0: WARNING: cannot decode longitude ($')\n"); |
29
f41d125405a6
version after ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
28
diff
changeset
|
306 |
$lon= nan; |
f41d125405a6
version after ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
28
diff
changeset
|
307 |
} |
10 | 308 |
&antsAddParams('lon',$lon); |
309 |
next; |
|
310 |
} |
|
311 |
||
312 |
if ($hdr =~ /interval = seconds: /) { |
|
313 |
$sampint = 1*$'; |
|
314 |
&antsAddParams('sampling_frequency',1/$sampint); |
|
315 |
next; |
|
316 |
} |
|
317 |
if ($hdr =~ /interval = decibars: /) { |
|
318 |
$sampint = 1*$'; |
|
319 |
&antsAddParams('sampling_press_interval',$sampint); |
|
320 |
next; |
|
321 |
} |
|
322 |
||
323 |
$badval = $',next |
|
324 |
if ($hdr =~ /bad_flag = /); |
|
325 |
$ftype = $',next |
|
326 |
if ($hdr =~ /file_type = /); |
|
327 |
} |
|
328 |
||
329 |
croak("$0: cannot determine file layout\n") |
|
330 |
unless (@antsNewLayout && defined($nfields) && defined($nrecs)); |
|
331 |
croak("$0: cannot determine missing value\n") |
|
332 |
unless defined($badval); |
|
333 |
||
38 | 334 |
$lat = nan unless defined($lat); |
335 |
$lon = nan unless defined($lon); |
|
336 |
||
10 | 337 |
@antsLayout = @antsNewLayout; |
38 | 338 |
return (1*$nfields,1*$nrecs,1*$sampint,1*$badval,$ftype,$lat,$lon); |
10 | 339 |
} |
340 |
||
341 |
#---------------------------------------------------------------------- |
|
342 |
# SBEin($$) |
|
343 |
# - read SBE CTD data |
|
344 |
#---------------------------------------------------------------------- |
|
345 |
||
346 |
{ my(@dta); my($nextR)=0; # static scope |
|
347 |
||
348 |
sub SBEin($$$$$) |
|
349 |
{ |
|
350 |
my($FP,$ftype,$nf,$nr,$bad) = @_; |
|
351 |
my(@add); |
|
352 |
||
353 |
splice(@ants_,0,$antsBufSkip); # shift buffers |
|
354 |
||
355 |
if ($ftype eq 'ascii') { |
|
356 |
until ($#ants_>=0 && &antsBufFull()) { |
|
357 |
return undef unless (@add = &antsFileIn($FP)); |
|
51
14ce2387de5e
improved libSBE.pl
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
38
diff
changeset
|
358 |
if (@add == $nf) { |
14ce2387de5e
improved libSBE.pl
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
38
diff
changeset
|
359 |
for (my($f)=0; $f<=$nf; $f++) { |
14ce2387de5e
improved libSBE.pl
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
38
diff
changeset
|
360 |
$add[$f] = nan if ($add[$f] == $bad); |
14ce2387de5e
improved libSBE.pl
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
38
diff
changeset
|
361 |
} |
14ce2387de5e
improved libSBE.pl
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
38
diff
changeset
|
362 |
} else { |
14ce2387de5e
improved libSBE.pl
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
38
diff
changeset
|
363 |
&antsInfo(sprintf("CNV scan#%d: bad format",$nextR+1)) |
14ce2387de5e
improved libSBE.pl
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
38
diff
changeset
|
364 |
unless defined($libSBE_quiet); |
14ce2387de5e
improved libSBE.pl
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
38
diff
changeset
|
365 |
for (my($f)=0; $f<=$nf; $f++) { |
14ce2387de5e
improved libSBE.pl
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
38
diff
changeset
|
366 |
$add[$f] = nan; |
14ce2387de5e
improved libSBE.pl
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
38
diff
changeset
|
367 |
} |
10 | 368 |
} |
28 | 369 |
foreach my $sf (@ignore_input_fields) { |
370 |
splice(@add,$sf,1); |
|
371 |
} |
|
10 | 372 |
push(@ants_,[@add]); |
373 |
} |
|
374 |
} elsif ($ftype eq 'binary') { |
|
375 |
unless (@dta) { # read binary data once |
|
376 |
my($fbits) = 8 * length(pack('f',0)); |
|
377 |
croak(sprintf("$0: incompatible native CPU float representation (%d instead of 32bits)\n",fbits)) |
|
378 |
unless ($fbits == 32); |
|
379 |
my($dta); |
|
380 |
croak("$0: can't read binary data\n") |
|
381 |
unless (read($FP,$dta,4*$nf*$nr) == 4*$nf*$nr); |
|
382 |
print(STDERR "WARNING: extraneous data at EOF\n") |
|
383 |
unless eof($FP); |
|
384 |
$dta = pack('V*',unpack('N*',$dta)) # big-endian CPU |
|
385 |
if (unpack('h*', pack('s', 1)) =~ /01/); # c.f. perlport(1) |
|
386 |
@dta = unpack("f*",$dta); |
|
387 |
for ($r=0; $r<$nr; $r++) { |
|
388 |
for ($f=0; $f<$nf; $f++) { |
|
21 | 389 |
$dta[$r*$nf+$f] = nan if ($dta[$r*$nf+$f] == $bad); |
10 | 390 |
} |
391 |
} |
|
392 |
} |
|
393 |
until ($#ants_>=0 && &antsBufFull()) { # copy next out |
|
394 |
return undef unless ($nextR < $nr); |
|
21 | 395 |
@add = @dta[$nextR*$nf..($nextR+1)*$nf-1]; |
28 | 396 |
foreach my $sf (@ignore_input_fields) { |
397 |
splice(@add,$sf,1); |
|
398 |
} |
|
10 | 399 |
push(@ants_,[@add]); |
400 |
} |
|
401 |
} else { |
|
402 |
croak("$0: unknown file type $ftype\n"); |
|
403 |
} |
|
404 |
||
51
14ce2387de5e
improved libSBE.pl
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
38
diff
changeset
|
405 |
$nextR++; |
10 | 406 |
return $#ants_+1; # ok |
407 |
} |
|
408 |
||
409 |
} # static scope |
|
410 |
||
411 |
#---------------------------------------------------------------------- |
|
412 |
||
413 |
1; # return true |