File: test_iterator.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 (42 lines) | stat: -rwxr-xr-x 906 bytes parent folder | download
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
#!/usr/bin/env python

import sys
from gribapi import *
import profile

def main():
    infile = sys.argv[1]
    fid = open(infile,"r")
    count = grib_count_in_file(fid)

    for i in range(count):
        gid = grib_new_from_file(fid)
        nval = grib_get_size(gid,"values")
        iterid = grib_iterator_new(gid,0)

        missingValue = grib_get_double(gid,"missingValue")

        i=0
        while 1:
            result = grib_iterator_next(iterid)
            if not result: break

            [lat,lon,value] = result

            sys.stdout.write("- %d - lat=%.6f lon=%.6f value=" % (i,lat,lon))

            if value == missingValue:
                print("missing")
            else:
                print("%.6f" % value)

            i += 1

        grib_iterator_delete(iterid)
        grib_release(gid)

    fid.close()

if __name__ == "__main__":
    #profile.run('main()')
    main()