def example():
f = open(INPUT,'rb')
count = 1
while 1:
gid = codes_grib_new_from_file(f)
if gid is None: break
print ("\n\n-- GRIB %d --" % (count))
# codes_dump should only be used for diagnostic purposes.
#
# To process the data and grib headers, you will have to use
# codes_get and request the decoding of the keys you need,
# e.g. the date, the time, the parameter, the "level".
#
# codes_dump(gid)
#
# Replace this call to codes_dump with calls to codes_get
# for each key/value pair needed, e.g.:
#
# idate = codes_get(gid,'date')
edition = codes_get(gid,'edition')
shortName = codes_get(gid,'shortName')
date = codes_get(gid,'date')
time = codes_get(gid,'time')
levType = codes_get(gid,'typeOfLevel')
level = codes_get(gid,'level')
print("Edition=%d Parameter=%s typeOfLevel=%s level=%d date=%d time=%d\n" %
(edition, shortName, levType, level, date, time))
#print (edition, shortName, levType, level, date, time)
values = codes_get_array(gid,'values')
print("First 20 values:\n----------------\n")
for i in range(20):
print("%.4f" % (values[i]))
maximum = codes_get(gid,'max')
minimum = codes_get(gid,'min')
average = codes_get(gid,'average')
print("max = %.4f min = %.4f average = %.4f\n" % (maximum, minimum, average))
codes_release(gid)
count += 1
f.close() |