Commit cdf35aa62a947e08da91df7a42671f0ebd553b77
1 parent
50dd7220
Exists in
master
and in
112 other branches
Votable parser: convert NaN numbers to null
Showing
2 changed files
with
18 additions
and
16 deletions
Show diff stats
php/classes/VOTableMgr.php
... | ... | @@ -302,45 +302,49 @@ class VOTableMgr { |
302 | 302 | case 'boolean': |
303 | 303 | case 'unsignedByte': |
304 | 304 | $b = $substr; |
305 | - $res = $b == "T" || $b == "t" || $b == "1"; | |
305 | + $res = $b == 'T' || $b == 't' || $b == '1'; | |
306 | 306 | break; |
307 | 307 | case 'char': |
308 | - $res = $row_size!=0 ? utf8_encode($substr) : NULL; | |
308 | + $res = $row_size !=0 ? utf8_encode($substr) : NULL; | |
309 | 309 | case 'unicodeChar': |
310 | - $res = $row_size!=0 ? utf8_encode(str_replace("\0", "", $substr)) : NULL; | |
310 | + $res = $row_size !=0 ? utf8_encode(str_replace("\0", '', $substr)) : NULL; | |
311 | 311 | break; |
312 | 312 | case 'short': |
313 | - $res = unpack("ss", $substr)["s"]; | |
313 | + $res = unpack('ss', $substr)['s']; | |
314 | + $res = is_nan($res) ? NULL : $res; | |
314 | 315 | break; |
315 | 316 | case 'int': |
316 | - $res = unpack("Ns", $substr)["s"]; | |
317 | + $res = unpack('Ns', $substr)['s']; | |
318 | + $res = is_nan($res) ? NULL : $res; | |
317 | 319 | break; |
318 | 320 | case 'long': |
319 | - $res = unpack("Js", $substr)["s"]; // /!\ J -> PHP 5.6 only | |
321 | + $res = unpack('Js', $substr)['s']; // /!\ J -> PHP 5.6 only | |
322 | + $res = is_nan($res) ? NULL : $res; | |
320 | 323 | break; |
321 | 324 | case 'float': |
322 | - $res = unpack("fs", $substr)["s"]; | |
323 | - | |
325 | + $res = unpack('fs', $substr)['s']; | |
324 | 326 | // If machine is little endian: |
325 | 327 | if($this->is_little_endian) { |
326 | - $res = unpack('f1f', strrev(pack('f', $res)))["f"]; | |
328 | + $res = unpack('f1f', strrev(pack('f', $res)))['f']; | |
327 | 329 | } |
330 | + $res = is_nan($res) ? NULL : $res; | |
328 | 331 | break; |
329 | 332 | case 'double': |
330 | - $res = unpack("ds", $substr)["s"]; | |
331 | - | |
333 | + $res = unpack('ds', $substr)['s']; | |
332 | 334 | // If machine is little endian: |
333 | 335 | if($this->is_little_endian) { |
334 | - $res = unpack('d1d', strrev(pack('d', $res)))["d"]; | |
336 | + $res = unpack('d1d', strrev(pack('d', $res)))['d']; | |
335 | 337 | } |
338 | + $res = is_nan($res) ? NULL : $res; | |
336 | 339 | break; |
337 | 340 | default: |
338 | 341 | $res = NULL; |
339 | - error_log("Unknown character: $data_type"); | |
342 | + error_log("Unknown datatype: $data_type"); | |
340 | 343 | break; |
341 | 344 | } |
342 | 345 | $this->c+=$row_size; |
343 | - return (string)$res; | |
346 | + return $res; | |
347 | + // return (string)$res; | |
344 | 348 | } |
345 | 349 | |
346 | 350 | |
... | ... |
php/epntap.php
... | ... | @@ -165,12 +165,10 @@ function getGranules() { |
165 | 165 | $names = ['dataproduct_type' => 'Type', 'access_estsize' => 'Size']; // default: pretty printed key name |
166 | 166 | $renderers = ['dataproduct_type' => 'type', 'time_min' => 'date', 'time_max' => 'date', 'access_estsize' => 'size', 'thumbnail_url' => 'img', 'access_url' => 'link', 'access_format' => 'format']; // default: text |
167 | 167 | $flexs = ['granule_uid' => 2]; // default: 1 |
168 | - // $types = ['boolean' => , 'integer']; // TODO see http://php.net/manual/fr/function.gettype.php | |
169 | 168 | |
170 | 169 | $fields = array(); |
171 | 170 | $columns = array(); |
172 | 171 | foreach($response['data'][0] as $key => $value) { |
173 | - error_log('Granule ' . $key . ' is ' . gettype($value)); | |
174 | 172 | $fields[] = ['name' => $key, 'type' => 'string']; |
175 | 173 | $columns[] = [ |
176 | 174 | 'dataIndex' => $key, |
... | ... |