1# 2# Copyright 2005-2018 ECMWF. 3# 4# This software is licensed under the terms of the Apache Licence Version 2.0 5# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. 6# 7# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by 8# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. 9# 10 11import traceback 12import sys 13 14from gribapi import * 15 16INPUT = '../../data/reduced_gaussian_lsm.grib1' 17VERBOSE = 1 # verbose error reporting 18 19 20def example(): 21 points = ((30, -20), (13, 234)) 22 23 f = open(INPUT) 24 gid = grib_new_from_file(f) 25 26 for lat, lon in points: 27 nearest = grib_find_nearest(gid, lat, lon)[0] 28 print lat, lon 29 print nearest.lat, nearest.lon, nearest.value, nearest.distance, nearest.index 30 31 four = grib_find_nearest(gid, lat, lon, is_lsm=False, npoints=4) 32 for i in range(len(four)): 33 print "- %d -" % i 34 print four[i] 35 36 print "-" * 100 37 38 grib_release(gid) 39 f.close() 40 41 42def main(): 43 try: 44 example() 45 except GribInternalError, err: 46 if VERBOSE: 47 traceback.print_exc(file=sys.stderr) 48 else: 49 print >>sys.stderr, err.msg 50 51 return 1 52 53if __name__ == "__main__": 54 sys.exit(main()) 55