Examples: add codes_get_double_elements for Python
@@ -24,14 +24,20 @@ def example():
gid = codes_grib_new_from_file(f)
values = codes_get_values(gid)
- for i in range(len(values)):
+ num_vals = len(values)
+ for i in range(num_vals):
print("%d %.10e" % (i + 1, values[i]))
- print('%d values found in %s' % (len(values), INPUT))
+ print('%d values found in %s' % (num_vals, INPUT))
for key in ('max', 'min', 'average'):
print('%s=%.10e' % (key, codes_get(gid, key)))
+ # Example of accessing specific elements from data values
+ # Get first, middle and last elements
+ indexes = [0, num_vals/2, num_vals-1]
+ elems = codes_get_double_elements(gid, 'values', indexes)
+
codes_release(gid)
f.close()
