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: Mon Nov 3 19:35:53 2014 |
4 # dlm: Thu Jun 18 10:17:03 2015 |
5 # (c) 2014 A.M. Thurnherr |
5 # (c) 2014 A.M. Thurnherr |
6 # uE-Info: 83 13 NIL 0 0 72 2 2 4 NIL ofnI |
6 # uE-Info: 13 49 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 |
|
12 # Jun 17, 2015: - ensured numeric retvals of SBE_parseheader are returned as numbers |
|
13 # Jun 18, 2015: - BUG: binary code had several bugs |
11 |
14 |
12 #---------------------------------------------------------------------- |
15 #---------------------------------------------------------------------- |
13 # fname_SBE2std($) |
16 # fname_SBE2std($) |
14 # - standardize field names (also adds correct unit %PARAMs) |
17 # - standardize field names (also adds correct unit %PARAMs) |
15 #---------------------------------------------------------------------- |
18 #---------------------------------------------------------------------- |
177 if ($hdr =~ /name (\d+) = ([^:]+):/) { |
180 if ($hdr =~ /name (\d+) = ([^:]+):/) { |
178 $antsNewLayout[$1] = $sfn ? fname_SBE2std($2) : fname_SBE($2); |
181 $antsNewLayout[$1] = $sfn ? fname_SBE2std($2) : fname_SBE($2); |
179 next; |
182 next; |
180 } |
183 } |
181 |
184 |
182 SBE_checkTime($1,$tc),next # sanity time check |
185 SBE_checkTime($1,$tc),next # sanity time check |
183 if ($hdr =~ /NMEA UTC \(Time\) = (.*)/); |
186 if ($hdr =~ /NMEA UTC \(Time\) = (.*)/); |
184 SBE_checkTime($1,$tc),next |
187 SBE_checkTime($1,$tc),next |
185 if ($hdr =~ /System UpLoad Time = (.*)/); |
188 if ($hdr =~ /System UpLoad Time = (.*)/); |
186 |
189 |
187 &antsAddParams('CNV_File',$1),next # selected metadata |
190 &antsAddParams('CNV_File',$1),next # selected metadata |
240 unless (@antsNewLayout && defined($nfields) && defined($nrecs)); |
243 unless (@antsNewLayout && defined($nfields) && defined($nrecs)); |
241 croak("$0: cannot determine missing value\n") |
244 croak("$0: cannot determine missing value\n") |
242 unless defined($badval); |
245 unless defined($badval); |
243 |
246 |
244 @antsLayout = @antsNewLayout; |
247 @antsLayout = @antsNewLayout; |
245 return ($nfields,$nrecs,$sampint,$badval,$ftype,$lat,$lon); |
248 return (1*$nfields,1*$nrecs,1*$sampint,1*$badval,$ftype,1*$lat,1*$lon); |
246 } |
249 } |
247 |
250 |
248 #---------------------------------------------------------------------- |
251 #---------------------------------------------------------------------- |
249 # SBEin($$) |
252 # SBEin($$) |
250 # - read SBE CTD data |
253 # - read SBE CTD data |
280 $dta = pack('V*',unpack('N*',$dta)) # big-endian CPU |
283 $dta = pack('V*',unpack('N*',$dta)) # big-endian CPU |
281 if (unpack('h*', pack('s', 1)) =~ /01/); # c.f. perlport(1) |
284 if (unpack('h*', pack('s', 1)) =~ /01/); # c.f. perlport(1) |
282 @dta = unpack("f*",$dta); |
285 @dta = unpack("f*",$dta); |
283 for ($r=0; $r<$nr; $r++) { |
286 for ($r=0; $r<$nr; $r++) { |
284 for ($f=0; $f<$nf; $f++) { |
287 for ($f=0; $f<$nf; $f++) { |
285 @add[$f] = $dta[$r*$nf+$f] == $bad ? nan : $dta[$r*$nf+$f]; |
288 $dta[$r*$nf+$f] = nan if ($dta[$r*$nf+$f] == $bad); |
286 } |
289 } |
287 } |
290 } |
288 } |
291 } |
289 until ($#ants_>=0 && &antsBufFull()) { # copy next out |
292 until ($#ants_>=0 && &antsBufFull()) { # copy next out |
290 return undef unless ($nextR < $nr); |
293 return undef unless ($nextR < $nr); |
291 @add = $dta[$nextR*$nf..($nextR+1)*$nr+$nf]; |
294 @add = @dta[$nextR*$nf..($nextR+1)*$nf-1]; |
292 push(@ants_,[@add]); |
295 push(@ants_,[@add]); |
293 $nextR++; |
296 $nextR++; |
294 } |
297 } |
295 } else { |
298 } else { |
296 croak("$0: unknown file type $ftype\n"); |
299 croak("$0: unknown file type $ftype\n"); |