1 #====================================================================== |
1 #====================================================================== |
2 # L I B S B E . P L |
2 # L I B S B E . P L |
3 # doc: Mon Nov 3 12:42:14 2014 |
3 # doc: Mon Nov 3 12:42:14 2014 |
4 # dlm: Fri Mar 10 09:46:42 2017 |
4 # dlm: Mon Apr 23 21:03:27 2018 |
5 # (c) 2014 A.M. Thurnherr |
5 # (c) 2014 A.M. Thurnherr |
6 # uE-Info: 20 55 NIL 0 0 72 2 2 4 NIL ofnI |
6 # uE-Info: 25 105 NIL 0 0 72 2 2 4 NIL ofnI |
7 #====================================================================== |
7 #====================================================================== |
8 |
8 |
9 # HISTORY: |
9 # HISTORY: |
10 # Nov 3, 2014: - exported from [importCNV] |
10 # Nov 3, 2014: - exported from [importCNV] |
11 # Jun 16, 2015: - cosmetics |
11 # Jun 16, 2015: - cosmetics |
16 # - solution for files with multiple conductivity units: ignore |
16 # - solution for files with multiple conductivity units: ignore |
17 # all conducitivities with units not equal to the first cond var |
17 # all conducitivities with units not equal to the first cond var |
18 # - added $libSBE_quiet to suppress diagnostic messages |
18 # - added $libSBE_quiet to suppress diagnostic messages |
19 # May 31, 2016: - made successfully decoding lat/lon optional |
19 # May 31, 2016: - made successfully decoding lat/lon optional |
20 # Mar 10, 2017: - made lat/lon decoding more flexible |
20 # Mar 10, 2017: - made lat/lon decoding more flexible |
|
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() |
|
25 # Apr 23, 2018: - BUG: header lat/lon was incorrectly parsed when there was no spaced before hemisphere |
21 |
26 |
22 #---------------------------------------------------------------------- |
27 #---------------------------------------------------------------------- |
23 # fname_SBE2std($) |
28 # fname_SBE2std($) |
24 # - standardize field names (also adds correct unit %PARAMs) |
29 # - standardize field names (also adds correct unit %PARAMs) |
25 #---------------------------------------------------------------------- |
30 #---------------------------------------------------------------------- |
28 { |
33 { |
29 $_ = $_[0]; |
34 $_ = $_[0]; |
30 |
35 |
31 return 'lat' if /^lat/; |
36 return 'lat' if /^lat/; |
32 return 'lon' if /^lon/; |
37 return 'lon' if /^lon/; |
33 return 'press' if /^prDM/; |
38 return 'press' if /^pr[dD]M/; |
|
39 return 'sspd' if /^sv[dD]M/; |
34 return 'depth' if /^depSM/; |
40 return 'depth' if /^depSM/; |
35 return 'O2' if /^sbeox0/; |
41 return 'O2' if /^sbeox0/; |
36 return 'alt_O2' if /^sbeox1/; |
42 return 'alt_O2' if /^sbeox1/; |
37 return 'salin' if /^sal00/; |
43 return 'salin' if /^sal00/; |
38 return 'alt_salin' if /^sal11/; |
44 return 'alt_salin' if /^sal11/; |
39 return 'elapsed' if /^timeS/; |
45 return 'elapsed' if /^timeS/; |
|
46 return 'time_jday' if /^timeJV2/; |
40 return 'sigma0' if /^sigma.*00/; |
47 return 'sigma0' if /^sigma.*00/; |
41 return 'alt_sigma0' if /^sigma.*11/; |
48 return 'alt_sigma0' if /^sigma.*11/; |
42 return 'rho0' if /^density00/; |
49 return 'rho0' if /^density00/; |
43 return 'alt_rho0' if /^density11/; |
50 return 'alt_rho0' if /^density11/; |
44 |
51 |
88 if defined($P{ITS}) && ($P{ITS} != 68); |
95 if defined($P{ITS}) && ($P{ITS} != 68); |
89 &antsAddParams('ITS',68); $P{ITS} = 68; |
96 &antsAddParams('ITS',68); $P{ITS} = 68; |
90 return 'alt_theta0'; |
97 return 'alt_theta0'; |
91 } |
98 } |
92 |
99 |
93 if (m{^c0S/m}) { # conductivity with different units |
100 if (m{^c0S/m} || m{^cond0S/m}) { # conductivity with different units |
94 return undef |
101 return undef |
95 if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'S/m'); |
102 if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'S/m'); |
96 &antsAddParams('cond.unit','S/m'); |
103 &antsAddParams('cond.unit','S/m'); |
97 return 'cond'; |
104 return 'cond'; |
98 } elsif (m{^c0mS/cm}) { |
105 } elsif (m{^c0mS/cm} || m{^cond0mS/cm}) { |
99 return undef |
106 return undef |
100 if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'mS/cm'); |
107 if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'mS/cm'); |
101 &antsAddParams('cond.unit','mS/cm'); |
108 &antsAddParams('cond.unit','mS/cm'); |
102 return 'cond'; |
109 return 'cond'; |
103 } |
110 } |
104 |
111 |
105 if (m{^c1S/m}) { |
112 if (m{^c1S/m} || m{^cond1S/m}) { |
106 return undef |
113 return undef |
107 if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'S/m'); |
114 if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'S/m'); |
108 &antsAddParams('cond.unit','S/m'); |
115 &antsAddParams('cond.unit','S/m'); |
109 return 'alt_cond'; |
116 return 'alt_cond'; |
110 } elsif (m{^c1mS/cm}) { |
117 } elsif (m{^c1mS/cm} || m{^cond1mS/cm}) { |
111 return undef |
118 return undef |
112 if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'mS/cm'); |
119 if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'mS/cm'); |
113 &antsAddParams('cond.unit','mS/cm'); |
120 &antsAddParams('cond.unit','mS/cm'); |
114 return 'alt_cond'; |
121 return 'alt_cond'; |
115 } |
122 } |
160 return undef |
167 return undef |
161 if defined($P{ITS}) && ($P{ITS} != 68); |
168 if defined($P{ITS}) && ($P{ITS} != 68); |
162 &antsAddParams('ITS',68); $P{ITS} = 68; |
169 &antsAddParams('ITS',68); $P{ITS} = 68; |
163 } |
170 } |
164 |
171 |
165 if (m{^c0S/m}) { # conductivity with different units |
172 if (m{^c0S/m} || m{^cond0S/m}) { # conductivity with different units |
166 return undef |
173 return undef |
167 if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'S/m'); |
174 if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'S/m'); |
168 &antsAddParams('cond.unit','S/m'); |
175 &antsAddParams('cond.unit','S/m'); |
169 } elsif (m{^c0mS/cm}) { |
176 } elsif (m{^c0mS/cm} || m{^cond0mS/cm}) { |
170 return undef |
177 return undef |
171 if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'mS/cm'); |
178 if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'mS/cm'); |
172 &antsAddParams('cond.unit','mS/cm'); |
179 &antsAddParams('cond.unit','mS/cm'); |
173 } |
180 } |
174 |
181 |
175 if (m{^c1S/m}) { |
182 if (m{^c1S/m} || m{^cond1S/m}) { |
176 return undef |
183 return undef |
177 if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'S/m'); |
184 if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'S/m'); |
178 &antsAddParams('cond.unit','S/m'); |
185 &antsAddParams('cond.unit','S/m'); |
179 } elsif (m{^c1mS/cm}) { |
186 } elsif (m{^c1mS/cm} || m{^cond1mS/cm}) { |
180 return undef |
187 return undef |
181 if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'mS/cm'); |
188 if defined($P{'cond.unit'}) && ($P{'cond.unit'} ne 'mS/cm'); |
182 &antsAddParams('cond.unit','mS/cm'); |
189 &antsAddParams('cond.unit','mS/cm'); |
183 } |
190 } |
184 |
191 |
266 if ($hdr =~ /Time\s*:\s*(.*)/); |
273 if ($hdr =~ /Time\s*:\s*(.*)/); |
267 &antsAddParams('date',$1),next |
274 &antsAddParams('date',$1),next |
268 if ($hdr =~ /Date\s*:\s*(.*)/); |
275 if ($hdr =~ /Date\s*:\s*(.*)/); |
269 |
276 |
270 if (($hdr =~ /Latitude\s*[:=]\s*/) && !defined($lat)) { |
277 if (($hdr =~ /Latitude\s*[:=]\s*/) && !defined($lat)) { |
271 ($deg,$min,$NS) = split(/\s+/,$'); |
278 # ($deg,$min,$NS) = split(/\s+/,$'); |
|
279 ($deg,$min,$NS) = ($' =~ m{([^\s]+)\s+(\d+\.\d*)\s*([NS])}); |
272 if ($NS eq 'N' || $NS eq 'S') { |
280 if ($NS eq 'N' || $NS eq 'S') { |
273 $lat = $deg + $min/60; |
281 $lat = $deg + $min/60; |
274 $lat *= -1 if ($NS eq 'S'); |
282 $lat *= -1 if ($NS eq 'S'); |
275 } elsif (!defined($NS) && abs($deg)<=90 && ($min >= 0) && ($min <= 60)) { |
283 } elsif (!defined($NS) && defined($deg) && abs($deg)<=90 && ($min >= 0) && ($min <= 60)) { |
276 $lat = $deg + $min/60; |
284 $lat = $deg + $min/60; |
277 } else { |
285 } else { |
278 print(STDERR "$0: WARNING: cannot decode latitude ($')\n"); |
286 # print(STDERR "$0: WARNING: cannot decode latitude ($')\n"); |
279 $lat = nan; |
287 $lat = nan; |
280 } |
288 } |
281 &antsAddParams('lat',$lat); |
289 &antsAddParams('lat',$lat); |
282 next; |
290 next; |
283 } |
291 } |
284 if (($hdr =~ /Longitude\s*[:=]\s*/) && !defined($lon)) { |
292 if (($hdr =~ /Longitude\s*[:=]\s*/) && !defined($lon)) { |
285 ($deg,$min,$EW) = split(/\s+/,$'); |
293 # ($deg,$min,$EW) = split(/\s+/,$'); |
|
294 ($deg,$min,$EW) = ($' =~ m{([^\s]+)\s+(\d+\.\d*)\s*([EW])}); |
286 if ($EW eq 'E' || $EW eq 'W') { |
295 if ($EW eq 'E' || $EW eq 'W') { |
287 $lon = $deg + $min/60; |
296 $lon = $deg + $min/60; |
288 $lon *= -1 if ($EW eq 'W'); |
297 $lon *= -1 if ($EW eq 'W'); |
289 } elsif (!defined($EW) && abs($deg)<=360 && ($min >= 0) && ($min <= 60)) { |
298 } elsif (!defined($EW) && defined($deg) && abs($deg)<=360 && ($min >= 0) && ($min <= 60)) { |
290 $lon = $deg + $min/60; |
299 $lon = $deg + $min/60; |
291 } else { |
300 } else { |
292 print(STDERR "$0: WARNING: cannot decode longitude ($')\n"); |
301 # print(STDERR "$0: WARNING: cannot decode longitude ($')\n"); |
293 $lon= nan; |
302 $lon= nan; |
294 } |
303 } |
295 &antsAddParams('lon',$lon); |
304 &antsAddParams('lon',$lon); |
296 next; |
305 next; |
297 } |
306 } |