diff --git a/examples/F90/grib_get_keys.f90 b/examples/F90/grib_get_keys.f90 index 0c0e36694..3423062fa 100644 --- a/examples/F90/grib_get_keys.f90 +++ b/examples/F90/grib_get_keys.f90 @@ -26,98 +26,84 @@ program grib_get_keys real, dimension(:), allocatable :: values integer :: numberOfValues real :: average,min_val, max_val - integer :: is_missing, is_defined + integer :: is_missing call codes_open_file(ifile, & '../../data/reduced_latlon_surface.grib1','r') ! Loop on all the messages in a file. - + ! a new grib message is loaded from file ! igrib is the grib id to be used in subsequent calls call codes_grib_new_from_file(ifile,igrib, iret) - + LOOP: DO WHILE (iret /= CODES_END_OF_FILE) - !check if the value of the key is MISSING - is_missing=0; - call codes_is_missing(igrib,'Ni',is_missing); - if ( is_missing /= 1 ) then + !check if the value of the key is MISSING + is_missing=0; + call codes_is_missing(igrib,'Ni',is_missing); + if ( is_missing /= 1 ) then ! get as a integer call codes_get(igrib,'Ni',numberOfPointsAlongAParallel) write(*,*) 'numberOfPointsAlongAParallel=', & numberOfPointsAlongAParallel - else + else write(*,*) 'numberOfPointsAlongAParallel is missing' - endif - - !check for existence of keys - is_defined=0; - call codes_is_defined(igrib,'edition',is_defined); - if ( is_defined == 0 ) then - write(0,*) 'ERROR: An expected key was not defined!!' - call exit(1) - endif - call codes_is_defined(igrib,'ThisIsNoLoveSong',is_defined); - if ( is_defined == 1 ) then - write(0,*) 'ERROR: An unexpected key was defined!!' - call exit(1) - endif + endif - ! get as a integer - call codes_get(igrib,'Nj',numberOfPointsAlongAMeridian) - write(*,*) 'numberOfPointsAlongAMeridian=', & - numberOfPointsAlongAMeridian - - ! get as a real - call codes_get(igrib, 'latitudeOfFirstGridPointInDegrees', & + ! get as a integer + call codes_get(igrib,'Nj',numberOfPointsAlongAMeridian) + write(*,*) 'numberOfPointsAlongAMeridian=', & + numberOfPointsAlongAMeridian + + ! get as a real + call codes_get(igrib, 'latitudeOfFirstGridPointInDegrees', & latitudeOfFirstPointInDegrees) - write(*,*) 'latitudeOfFirstGridPointInDegrees=', & + write(*,*) 'latitudeOfFirstGridPointInDegrees=', & latitudeOfFirstPointInDegrees - - ! get as a real - call codes_get(igrib, 'longitudeOfFirstGridPointInDegrees', & - longitudeOfFirstPointInDegrees) - write(*,*) 'longitudeOfFirstGridPointInDegrees=', & - longitudeOfFirstPointInDegrees - - ! get as a real - call codes_get(igrib, 'latitudeOfLastGridPointInDegrees', & - latitudeOfLastPointInDegrees) - write(*,*) 'latitudeOfLastGridPointInDegrees=', & - latitudeOfLastPointInDegrees - - ! get as a real - call codes_get(igrib, 'longitudeOfLastGridPointInDegrees', & - longitudeOfLastPointInDegrees) - write(*,*) 'longitudeOfLastGridPointInDegrees=', & - longitudeOfLastPointInDegrees - - - ! get the size of the values array - call codes_get_size(igrib,'values',numberOfValues) - write(*,*) 'numberOfValues=',numberOfValues - - allocate(values(numberOfValues), stat=iret) - ! get data values - call codes_get(igrib,'values',values) - call codes_get(igrib,'min',min_val) ! can also be obtained through minval(values) - call codes_get(igrib,'max',max_val) ! can also be obtained through maxval(values) - call codes_get(igrib,'average',average) ! can also be obtained through maxval(values) - deallocate(values) + ! get as a real + call codes_get(igrib, 'longitudeOfFirstGridPointInDegrees', & + longitudeOfFirstPointInDegrees) + write(*,*) 'longitudeOfFirstGridPointInDegrees=', & + longitudeOfFirstPointInDegrees + + ! get as a real + call codes_get(igrib, 'latitudeOfLastGridPointInDegrees', & + latitudeOfLastPointInDegrees) + write(*,*) 'latitudeOfLastGridPointInDegrees=', & + latitudeOfLastPointInDegrees + + ! get as a real + call codes_get(igrib, 'longitudeOfLastGridPointInDegrees', & + longitudeOfLastPointInDegrees) + write(*,*) 'longitudeOfLastGridPointInDegrees=', & + longitudeOfLastPointInDegrees + + ! get the size of the values array + call codes_get_size(igrib,'values',numberOfValues) + write(*,*) 'numberOfValues=',numberOfValues + + allocate(values(numberOfValues), stat=iret) + ! get data values + call codes_get(igrib,'values',values) + call codes_get(igrib,'min',min_val) ! can also be obtained through minval(values) + call codes_get(igrib,'max',max_val) ! can also be obtained through maxval(values) + call codes_get(igrib,'average',average) ! can also be obtained through maxval(values) + + deallocate(values) - write(*,*)'There are ',numberOfValues, & + write(*,*)'There are ',numberOfValues, & ' average is ',average, & ' min is ', min_val, & ' max is ', max_val - call codes_release(igrib) - - call codes_grib_new_from_file(ifile,igrib, iret) + call codes_release(igrib) + call codes_grib_new_from_file(ifile,igrib, iret) + end do LOOP - + call codes_close_file(ifile) - + end program grib_get_keys diff --git a/examples/python/grib_get_keys.py b/examples/python/grib_get_keys.py index 22724a189..1a8ac4249 100644 --- a/examples/python/grib_get_keys.py +++ b/examples/python/grib_get_keys.py @@ -34,16 +34,14 @@ def example(): try: print ' %s: %s' % (key,codes_get(gid,key)) except CodesInternalError,err: - print 'Error with key="%s" : %s' % (key,err.msg) - - if codes_is_defined(gid,"A_very_silly_key"): raise Exception("Key was defined") - + print 'Error with key="%s" : %s' % (key,err.msg) + print 'There are %d values, average is %f, min is %f, max is %f' % ( - codes_get_size(gid,'values'), - codes_get(gid,'average'), - codes_get(gid,'min'), - codes_get(gid,'max') - ) + codes_get_size(gid,'values'), + codes_get(gid,'average'), + codes_get(gid,'min'), + codes_get(gid,'max') + ) codes_release(gid) diff --git a/fortran/eccodes_f77.h b/fortran/eccodes_f77.h index d92514961..0c9088151 100644 --- a/fortran/eccodes_f77.h +++ b/fortran/eccodes_f77.h @@ -67,8 +67,6 @@ external grib_get_string integer grib_is_missing external grib_is_missing - integer grib_is_defined - external grib_is_defined integer grib_set_string external grib_copy_namespace integer grib_copy_namespace diff --git a/python/test_general.py b/python/test_general.py index 53fb7f35e..6ff4674f4 100755 --- a/python/test_general.py +++ b/python/test_general.py @@ -136,11 +136,6 @@ def test(): new_Ni = grib_get(gid,"Ni") print "Set Ni back to its original value --> ",new_Ni assert Ni == new_Ni - - print "Check some keys to see if they are defined" - assert grib_is_defined(gid,"Ni") - assert grib_is_defined(gid,"edition") - assert not grib_is_defined(gid,"DarkThrone") #grib_multi_write(gid,multi) diff --git a/src/grib_handle.c b/src/grib_handle.c index 2f52fe6d4..c45a9e419 100644 --- a/src/grib_handle.c +++ b/src/grib_handle.c @@ -177,18 +177,15 @@ grib_handle* grib_new_handle ( grib_context* c ) static void check_definitions_version(grib_handle* h) { - /* Check version of definition files is compatible with the engine */ - int ret = 0; - long defs_file_version = 0; - if (grib_is_defined(h, "internalVersion")) { - ret = grib_get_long_internal(h, "internalVersion", &defs_file_version); - if (ret == GRIB_SUCCESS && (defs_file_version > LATEST_VERSION)) { - grib_context_log(h->context, GRIB_LOG_FATAL, - "Definition files version (%d) is greater than engine version (%d)!\n" - "These definition files are for a later version of the grib api engine.\n", - defs_file_version, LATEST_VERSION); + /* Check version of definition files is compatible with the engine */ + long defs_file_version = 0; + int ret = grib_get_long(h, "internalVersion", &defs_file_version); - } + if (ret == GRIB_SUCCESS && (defs_file_version > LATEST_VERSION)) { + grib_context_log(h->context, GRIB_LOG_FATAL, + "Definition files version (%d) is greater than engine version (%d)!\n" + "These definition files are for a later version of the grib api engine.\n", + defs_file_version, LATEST_VERSION); } }