author | A.M. Thurnherr <athurnherr@yahoo.com> |
Tue, 08 Mar 2016 15:54:18 +0000 | |
changeset 25 | 47b4a3600f5a |
parent 23 | a4fef65fd959 |
child 28 | db6c3d13f8be |
permissions | -rwxr-xr-x |
10 | 1 |
#====================================================================== |
2 |
# L I B S B E . P L |
|
3 |
# doc: Mon Nov 3 12:42:14 2014 |
|
23
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
4 |
# dlm: Tue Sep 29 11:01:30 2015 |
10 | 5 |
# (c) 2014 A.M. Thurnherr |
23
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
6 |
# uE-Info: 45 54 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 |
10 | 15 |
|
16 |
#---------------------------------------------------------------------- |
|
17 |
# fname_SBE2std($) |
|
18 |
# - standardize field names (also adds correct unit %PARAMs) |
|
19 |
#---------------------------------------------------------------------- |
|
20 |
||
21 |
sub fname_SBE2std($) |
|
22 |
{ |
|
23 |
$_ = $_[0]; |
|
24 |
||
25 |
return 'lat' if /^lat/; |
|
26 |
return 'lon' if /^lon/; |
|
27 |
return 'press' if /^prDM/; |
|
28 |
return 'depth' if /^depSM/; |
|
29 |
return 'O2' if /^sbeox0/; |
|
30 |
return 'alt_O2' if /^sbeox1/; |
|
31 |
return 'salin' if /^sal00/; |
|
32 |
return 'alt_salin' if /^sal11/; |
|
33 |
return 'elapsed' if /^timeS/; |
|
23
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
34 |
return 'sigma0' if /^sigma.*00/; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
35 |
return 'alt_sigma0' if /^sigma.*11/; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
36 |
return 'rho0' if /^density00/; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
37 |
return 'alt_rho0' if /^density11/; |
10 | 38 |
|
39 |
if (/^t090/) { # temperatures with different scales |
|
40 |
croak("$0: inconsistent temperature scales\n") |
|
41 |
if defined($P{ITS}) && ($P{ITS} != 90); |
|
42 |
&antsAddParams('ITS',90); $P{ITS} = 90; |
|
43 |
return 'temp'; |
|
44 |
} elsif (/^t068/) { |
|
45 |
croak("$0: inconsistent temperature scales\n") |
|
46 |
if defined($P{ITS}) && ($P{ITS} != 68); |
|
47 |
&antsAddParams('ITS',68); $P{ITS} = 68; |
|
48 |
return 'temp'; |
|
49 |
} |
|
50 |
||
51 |
if (/^t190/) { |
|
52 |
croak("$0: inconsistent temperature scales\n") |
|
53 |
if defined($P{ITS}) && ($P{ITS} != 90); |
|
54 |
&antsAddParams('ITS',90); $P{ITS} = 90; |
|
55 |
return 'alt_temp'; |
|
56 |
} elsif (/^t168/) { |
|
57 |
croak("$0: inconsistent temperature scales\n") |
|
58 |
if defined($P{ITS}) && ($P{ITS} != 68); |
|
59 |
&antsAddParams('ITS',68); $P{ITS} = 68; |
|
60 |
return 'alt_temp'; |
|
61 |
} |
|
62 |
||
23
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
63 |
if (/^potemp090/) { # potential temperatures with different scales |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
64 |
croak("$0: inconsistent temperature scales\n") |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
65 |
if defined($P{ITS}) && ($P{ITS} != 90); |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
66 |
&antsAddParams('ITS',90); $P{ITS} = 90; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
67 |
return 'theta0'; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
68 |
} elsif (/^potemp068/) { |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
69 |
croak("$0: inconsistent temperature scales\n") |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
70 |
if defined($P{ITS}) && ($P{ITS} != 68); |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
71 |
&antsAddParams('ITS',68); $P{ITS} = 68; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
72 |
return 'theta0'; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
73 |
} |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
74 |
|
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
75 |
if (/^potemp190/) { |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
76 |
croak("$0: inconsistent temperature scales\n") |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
77 |
if defined($P{ITS}) && ($P{ITS} != 90); |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
78 |
&antsAddParams('ITS',90); $P{ITS} = 90; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
79 |
return 'alt_theta0'; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
80 |
} elsif (/^potemp168/) { |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
81 |
croak("$0: inconsistent temperature scales\n") |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
82 |
if defined($P{ITS}) && ($P{ITS} != 68); |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
83 |
&antsAddParams('ITS',68); $P{ITS} = 68; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
84 |
return 'alt_theta0'; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
85 |
} |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
86 |
|
10 | 87 |
if (m{^c0S/m}) { # conductivity with different units |
88 |
croak("$0: inconsistent conductivity units\n") |
|
89 |
if defined($P{cond.unit}) && ($P{cond.unit} ne 'S/m'); |
|
90 |
&antsAddParams('cond.unit','S/m'); $P{cond.unit} = 'S/m'; |
|
91 |
return 'cond'; |
|
92 |
} elsif (m{^c0mS/cm}) { |
|
93 |
croak("$0: inconsistent conductivity units\n") |
|
94 |
if defined($P{cond.unit}) && ($P{cond.unit} != 'mS/cm'); |
|
95 |
&antsAddParams('cond.unit','mS/cm'); $P{cond.unit} = 'mS/cm'; |
|
96 |
return 'cond'; |
|
97 |
} |
|
98 |
||
99 |
if (m{^c1S/m}) { |
|
100 |
croak("$0: inconsistent conductivity units\n") |
|
101 |
if defined($P{cond.unit}) && ($P{cond.unit} != 'S/m'); |
|
102 |
&antsAddParams('cond.unit','S/m'); $P{cond.unit} = 'S/m'; |
|
103 |
return 'alt_cond'; |
|
104 |
} elsif (m{^c1mS/cm}) { |
|
105 |
croak("$0: inconsistent conductivity units\n") |
|
106 |
if defined($P{cond.unit}) && ($P{cond.unit} != 'mS/cm'); |
|
107 |
&antsAddParams('cond.unit','mS/cm'); $P{cond.unit} = 'mS/cm'; |
|
108 |
return 'alt_cond'; |
|
109 |
} |
|
110 |
||
111 |
return $_; |
|
112 |
} |
|
113 |
||
114 |
# same as above but leaving names in place (only setting %PARAMs) |
|
115 |
sub fname_SBE($) |
|
116 |
{ |
|
117 |
$_ = $_[0]; |
|
118 |
||
119 |
if (/^t090/) { # temperatures with different scales |
|
120 |
croak("$0: inconsistent temperature scales\n") |
|
121 |
if defined($P{ITS}) && ($P{ITS} != 90); |
|
122 |
&antsAddParams('ITS',90); $P{ITS} = 90; |
|
123 |
} elsif (/^t068/) { |
|
124 |
croak("$0: inconsistent temperature scales\n") |
|
125 |
if defined($P{ITS}) && ($P{ITS} != 68); |
|
126 |
&antsAddParams('ITS',68); $P{ITS} = 68; |
|
127 |
} |
|
128 |
||
129 |
if (/^t190/) { |
|
130 |
croak("$0: inconsistent temperature scales\n") |
|
131 |
if defined($P{ITS}) && ($P{ITS} != 90); |
|
132 |
&antsAddParams('ITS',90); $P{ITS} = 90; |
|
133 |
} elsif (/^t168/) { |
|
134 |
croak("$0: inconsistent temperature scales\n") |
|
135 |
if defined($P{ITS}) && ($P{ITS} != 68); |
|
136 |
&antsAddParams('ITS',68); $P{ITS} = 68; |
|
137 |
} |
|
138 |
||
23
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
139 |
if (/^potemp090/) { |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
140 |
croak("$0: inconsistent temperature scales\n") |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
141 |
if defined($P{ITS}) && ($P{ITS} != 90); |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
142 |
&antsAddParams('ITS',90); $P{ITS} = 90; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
143 |
} elsif (/^potemp068/) { |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
144 |
croak("$0: inconsistent temperature scales\n") |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
145 |
if defined($P{ITS}) && ($P{ITS} != 68); |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
146 |
&antsAddParams('ITS',68); $P{ITS} = 68; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
147 |
} |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
148 |
|
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
149 |
if (/^potemp190/) { |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
150 |
croak("$0: inconsistent temperature scales\n") |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
151 |
if defined($P{ITS}) && ($P{ITS} != 90); |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
152 |
&antsAddParams('ITS',90); $P{ITS} = 90; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
153 |
} elsif (/^potemp168/) { |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
154 |
croak("$0: inconsistent temperature scales\n") |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
155 |
if defined($P{ITS}) && ($P{ITS} != 68); |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
156 |
&antsAddParams('ITS',68); $P{ITS} = 68; |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
157 |
} |
a4fef65fd959
V6.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
158 |
|
10 | 159 |
if (m{^c0S/m}) { # conductivity with different units |
160 |
croak("$0: inconsistent conductivity units\n") |
|
161 |
if defined($P{cond.unit}) && ($P{cond.unit} ne 'S/m'); |
|
162 |
&antsAddParams('cond.unit','S/m'); $P{cond.unit} = 'S/m'; |
|
163 |
} elsif (m{^c0mS/cm}) { |
|
164 |
croak("$0: inconsistent conductivity units\n") |
|
165 |
if defined($P{cond.unit}) && ($P{cond.unit} != 'mS/cm'); |
|
166 |
&antsAddParams('cond.unit','mS/cm'); $P{cond.unit} = 'mS/cm'; |
|
167 |
} |
|
168 |
||
169 |
if (m{^c1S/m}) { |
|
170 |
croak("$0: inconsistent conductivity units\n") |
|
171 |
if defined($P{cond.unit}) && ($P{cond.unit} != 'S/m'); |
|
172 |
&antsAddParams('cond.unit','S/m'); $P{cond.unit} = 'S/m'; |
|
173 |
} elsif (m{^c1mS/cm}) { |
|
174 |
croak("$0: inconsistent conductivity units\n") |
|
175 |
if defined($P{cond.unit}) && ($P{cond.unit} != 'mS/cm'); |
|
176 |
&antsAddParams('cond.unit','mS/cm'); $P{cond.unit} = 'mS/cm'; |
|
177 |
} |
|
178 |
||
179 |
return $_; |
|
180 |
} |
|
181 |
||
182 |
#---------------------------------------------------------------------- |
|
183 |
# SBE_checkTime($$) |
|
184 |
# - make sure all times are (roughly) the same |
|
185 |
#---------------------------------------------------------------------- |
|
186 |
||
187 |
{ # static scope |
|
188 |
my($target_month,$target_day,$target_year,$target_time); |
|
189 |
||
190 |
sub SBE_checkTime($$) |
|
191 |
{ |
|
192 |
return unless $_[1]; |
|
193 |
my($mo,$dy,$yr,$tm) = split('\s+',$_[0]); |
|
194 |
||
195 |
unless (defined($target_month)) { |
|
196 |
$target_month = $mo; |
|
197 |
$target_day = $dy; |
|
198 |
$target_year = $yr; |
|
199 |
$target_time = $tm; |
|
200 |
return; |
|
201 |
} |
|
202 |
||
203 |
croak("$0: inconsistent dates in header ($target_month $target_day $target_year vs $mo $dy $yr)\n") |
|
204 |
unless ($target_month eq $mo && $target_day == $dy && $target_year == $yr); |
|
205 |
croak("$0: inconsistent times in header ($target_time vs $tm)\n") |
|
206 |
unless (abs(frac_day(split(':',$target_time))-frac_day(split(':',$tm))) < 1/60/24); |
|
207 |
} |
|
208 |
||
209 |
} # static scope |
|
210 |
||
211 |
#---------------------------------------------------------------------- |
|
212 |
# sub SBE_parseHeader(FP,std-field-names,time-check) |
|
213 |
# - parse header information |
|
214 |
#---------------------------------------------------------------------- |
|
215 |
||
216 |
sub SBE_parseHeader($$$) |
|
217 |
{ |
|
218 |
my($FP,$sfn,$tc) = @_; |
|
219 |
my($hdr,$nfields,$nrecs,$deg,$min,$NS,$EW,$lat,$lon,$sampint,$badval,$ftype); |
|
220 |
||
221 |
while (1) { # parse header |
|
222 |
chomp($hdr = <$FP>); |
|
223 |
$hdr =~ s/\r*$//; |
|
224 |
die("$0: unexpected EOF (format error)\n") unless defined($hdr); |
|
225 |
last if ($hdr eq '*END*'); |
|
226 |
||
227 |
$nfields = $',next if ($hdr =~ /nquan = /); # Layout |
|
228 |
$nrecs = $',next if ($hdr =~ /nvalues = /); |
|
229 |
if ($hdr =~ /name (\d+) = ([^:]+):/) { |
|
230 |
$antsNewLayout[$1] = $sfn ? fname_SBE2std($2) : fname_SBE($2); |
|
231 |
next; |
|
232 |
} |
|
233 |
||
21 | 234 |
SBE_checkTime($1,$tc),next # sanity time check |
10 | 235 |
if ($hdr =~ /NMEA UTC \(Time\) = (.*)/); |
236 |
SBE_checkTime($1,$tc),next |
|
237 |
if ($hdr =~ /System UpLoad Time = (.*)/); |
|
238 |
||
239 |
&antsAddParams('CNV_File',$1),next # selected metadata |
|
240 |
if ($hdr =~ /FileName = (.*)$/); |
|
241 |
SBE_checkTime($1,$tc),&antsAddParams('start_time',$1),next |
|
242 |
if ($hdr =~ /start_time = (.*)/); |
|
243 |
||
244 |
&antsAddParams('station',$1),next |
|
245 |
if ($hdr =~ /Station\s*:\s*(.*)/); |
|
246 |
&antsAddParams('ship',$1),next |
|
247 |
if ($hdr =~ /Ship\s*:\s*(.*)/); |
|
248 |
&antsAddParams('cruise',$1),next |
|
249 |
if ($hdr =~ /Cruise\s*:\s*(.*)/); |
|
250 |
&antsAddParams('time',$1),next |
|
251 |
if ($hdr =~ /Time\s*:\s*(.*)/); |
|
252 |
&antsAddParams('date',$1),next |
|
253 |
if ($hdr =~ /Date\s*:\s*(.*)/); |
|
254 |
||
255 |
if (($hdr =~ /Latitude\s*[:=]\s*/) && !defined($lat)) { |
|
256 |
($deg,$min,$NS) = split(/\s+/,$'); |
|
257 |
croak("$0: cannot decode latitude ($')\n") |
|
258 |
unless ($NS eq 'N' || $NS eq 'S'); |
|
259 |
$lat = $deg + $min/60; |
|
260 |
$lat *= -1 if ($NS eq 'S'); |
|
261 |
&antsAddParams('lat',$lat); |
|
262 |
next; |
|
263 |
} |
|
264 |
if (($hdr =~ /Longitude\s*[:=]\s*/) && !defined($lon)) { |
|
265 |
($deg,$min,$EW) = split(/\s+/,$'); |
|
266 |
croak("$0: cannot decode longitude ($')\n") |
|
267 |
unless ($EW eq 'E' || $EW eq 'W'); |
|
268 |
$lon = $deg + $min/60; |
|
269 |
$lon *= -1 if ($EW eq 'W'); |
|
270 |
&antsAddParams('lon',$lon); |
|
271 |
next; |
|
272 |
} |
|
273 |
||
274 |
if ($hdr =~ /interval = seconds: /) { |
|
275 |
$sampint = 1*$'; |
|
276 |
&antsAddParams('sampling_frequency',1/$sampint); |
|
277 |
next; |
|
278 |
} |
|
279 |
if ($hdr =~ /interval = decibars: /) { |
|
280 |
$sampint = 1*$'; |
|
281 |
&antsAddParams('sampling_press_interval',$sampint); |
|
282 |
next; |
|
283 |
} |
|
284 |
||
285 |
$badval = $',next |
|
286 |
if ($hdr =~ /bad_flag = /); |
|
287 |
$ftype = $',next |
|
288 |
if ($hdr =~ /file_type = /); |
|
289 |
} |
|
290 |
||
291 |
croak("$0: cannot determine file layout\n") |
|
292 |
unless (@antsNewLayout && defined($nfields) && defined($nrecs)); |
|
293 |
croak("$0: cannot determine missing value\n") |
|
294 |
unless defined($badval); |
|
295 |
||
296 |
@antsLayout = @antsNewLayout; |
|
21 | 297 |
return (1*$nfields,1*$nrecs,1*$sampint,1*$badval,$ftype,1*$lat,1*$lon); |
10 | 298 |
} |
299 |
||
300 |
#---------------------------------------------------------------------- |
|
301 |
# SBEin($$) |
|
302 |
# - read SBE CTD data |
|
303 |
#---------------------------------------------------------------------- |
|
304 |
||
305 |
{ my(@dta); my($nextR)=0; # static scope |
|
306 |
||
307 |
sub SBEin($$$$$) |
|
308 |
{ |
|
309 |
my($FP,$ftype,$nf,$nr,$bad) = @_; |
|
310 |
my(@add); |
|
311 |
||
312 |
splice(@ants_,0,$antsBufSkip); # shift buffers |
|
313 |
||
314 |
if ($ftype eq 'ascii') { |
|
315 |
until ($#ants_>=0 && &antsBufFull()) { |
|
316 |
return undef unless (@add = &antsFileIn($FP)); |
|
317 |
for (my($f)=0; $f<$nf; $f++) { |
|
318 |
$add[$f] = nan if ($add[$f] == $bad); |
|
319 |
} |
|
320 |
push(@ants_,[@add]); |
|
321 |
} |
|
322 |
} elsif ($ftype eq 'binary') { |
|
323 |
unless (@dta) { # read binary data once |
|
324 |
my($fbits) = 8 * length(pack('f',0)); |
|
325 |
croak(sprintf("$0: incompatible native CPU float representation (%d instead of 32bits)\n",fbits)) |
|
326 |
unless ($fbits == 32); |
|
327 |
my($dta); |
|
328 |
croak("$0: can't read binary data\n") |
|
329 |
unless (read($FP,$dta,4*$nf*$nr) == 4*$nf*$nr); |
|
330 |
print(STDERR "WARNING: extraneous data at EOF\n") |
|
331 |
unless eof($FP); |
|
332 |
$dta = pack('V*',unpack('N*',$dta)) # big-endian CPU |
|
333 |
if (unpack('h*', pack('s', 1)) =~ /01/); # c.f. perlport(1) |
|
334 |
@dta = unpack("f*",$dta); |
|
335 |
for ($r=0; $r<$nr; $r++) { |
|
336 |
for ($f=0; $f<$nf; $f++) { |
|
21 | 337 |
$dta[$r*$nf+$f] = nan if ($dta[$r*$nf+$f] == $bad); |
10 | 338 |
} |
339 |
} |
|
340 |
} |
|
341 |
until ($#ants_>=0 && &antsBufFull()) { # copy next out |
|
342 |
return undef unless ($nextR < $nr); |
|
21 | 343 |
@add = @dta[$nextR*$nf..($nextR+1)*$nf-1]; |
10 | 344 |
push(@ants_,[@add]); |
345 |
$nextR++; |
|
346 |
} |
|
347 |
} else { |
|
348 |
croak("$0: unknown file type $ftype\n"); |
|
349 |
} |
|
350 |
||
351 |
return $#ants_+1; # ok |
|
352 |
} |
|
353 |
||
354 |
} # static scope |
|
355 |
||
356 |
#---------------------------------------------------------------------- |
|
357 |
||
358 |
1; # return true |