File: test_extra.py

package info (click to toggle)
eccodes 2.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 480,184 kB
  • sloc: ansic: 163,815; makefile: 21,266; sh: 8,507; python: 6,026; f90: 5,762; perl: 2,891; yacc: 818; lex: 356; cpp: 305; fortran: 116; awk: 66
file content (47 lines) | stat: -rwxr-xr-x 965 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python

from __future__ import print_function
from .gribapi import *
import sys

input=sys.argv[1]

fid = open(input,"r")
oid = open("test","w")

while 1:
    gid = grib_new_from_file(fid)
    if gid is None: break

    print (grib_get(gid,"centre"))
    print (grib_get(gid,"centre",int))
    print (grib_get(gid,"centre",float))
    print (grib_get(gid,"centre",str))

    print ("Nvalues = ",grib_get_size(gid,"values"))

    values = grib_get_array(gid,"values")
    print (values[:10])
    values = values * 2

    grib_set_double_array(gid,"values",values)

    values = grib_get_array(gid,"values")
    print (values[:10])
    values = values / 2

    grib_set_double_array(gid,"values",[1])

    values = grib_get_values(gid)
    print (values[:10])

    print (grib_get(gid,"bitsPerValue"))
    grib_set(gid,"bitsPerValue",10)
    print (grib_get(gid,"bitsPerValue"))

    grib_write(gid,oid)

    grib_release(gid)

oid.close()
fid.close()