mirror of https://github.com/ecmwf/eccodes.git
ECC-117: Eliminate function codes_is_defined (Part 1)
This commit is contained in:
parent
22e641ba08
commit
5b36903347
|
@ -26,98 +26,84 @@ program grib_get_keys
|
||||||
real, dimension(:), allocatable :: values
|
real, dimension(:), allocatable :: values
|
||||||
integer :: numberOfValues
|
integer :: numberOfValues
|
||||||
real :: average,min_val, max_val
|
real :: average,min_val, max_val
|
||||||
integer :: is_missing, is_defined
|
integer :: is_missing
|
||||||
|
|
||||||
call codes_open_file(ifile, &
|
call codes_open_file(ifile, &
|
||||||
'../../data/reduced_latlon_surface.grib1','r')
|
'../../data/reduced_latlon_surface.grib1','r')
|
||||||
|
|
||||||
! Loop on all the messages in a file.
|
! Loop on all the messages in a file.
|
||||||
|
|
||||||
! a new grib message is loaded from file
|
! a new grib message is loaded from file
|
||||||
! igrib is the grib id to be used in subsequent calls
|
! igrib is the grib id to be used in subsequent calls
|
||||||
call codes_grib_new_from_file(ifile,igrib, iret)
|
call codes_grib_new_from_file(ifile,igrib, iret)
|
||||||
|
|
||||||
LOOP: DO WHILE (iret /= CODES_END_OF_FILE)
|
LOOP: DO WHILE (iret /= CODES_END_OF_FILE)
|
||||||
|
|
||||||
!check if the value of the key is MISSING
|
!check if the value of the key is MISSING
|
||||||
is_missing=0;
|
is_missing=0;
|
||||||
call codes_is_missing(igrib,'Ni',is_missing);
|
call codes_is_missing(igrib,'Ni',is_missing);
|
||||||
if ( is_missing /= 1 ) then
|
if ( is_missing /= 1 ) then
|
||||||
! get as a integer
|
! get as a integer
|
||||||
call codes_get(igrib,'Ni',numberOfPointsAlongAParallel)
|
call codes_get(igrib,'Ni',numberOfPointsAlongAParallel)
|
||||||
write(*,*) 'numberOfPointsAlongAParallel=', &
|
write(*,*) 'numberOfPointsAlongAParallel=', &
|
||||||
numberOfPointsAlongAParallel
|
numberOfPointsAlongAParallel
|
||||||
else
|
else
|
||||||
write(*,*) 'numberOfPointsAlongAParallel is missing'
|
write(*,*) 'numberOfPointsAlongAParallel is missing'
|
||||||
endif
|
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
|
|
||||||
|
|
||||||
! get as a integer
|
! get as a integer
|
||||||
call codes_get(igrib,'Nj',numberOfPointsAlongAMeridian)
|
call codes_get(igrib,'Nj',numberOfPointsAlongAMeridian)
|
||||||
write(*,*) 'numberOfPointsAlongAMeridian=', &
|
write(*,*) 'numberOfPointsAlongAMeridian=', &
|
||||||
numberOfPointsAlongAMeridian
|
numberOfPointsAlongAMeridian
|
||||||
|
|
||||||
! get as a real
|
! get as a real
|
||||||
call codes_get(igrib, 'latitudeOfFirstGridPointInDegrees', &
|
call codes_get(igrib, 'latitudeOfFirstGridPointInDegrees', &
|
||||||
latitudeOfFirstPointInDegrees)
|
latitudeOfFirstPointInDegrees)
|
||||||
write(*,*) 'latitudeOfFirstGridPointInDegrees=', &
|
write(*,*) 'latitudeOfFirstGridPointInDegrees=', &
|
||||||
latitudeOfFirstPointInDegrees
|
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, &
|
' average is ',average, &
|
||||||
' min is ', min_val, &
|
' min is ', min_val, &
|
||||||
' max is ', max_val
|
' max is ', max_val
|
||||||
|
|
||||||
call codes_release(igrib)
|
call codes_release(igrib)
|
||||||
|
|
||||||
call codes_grib_new_from_file(ifile,igrib, iret)
|
|
||||||
|
|
||||||
|
call codes_grib_new_from_file(ifile,igrib, iret)
|
||||||
|
|
||||||
end do LOOP
|
end do LOOP
|
||||||
|
|
||||||
call codes_close_file(ifile)
|
call codes_close_file(ifile)
|
||||||
|
|
||||||
end program grib_get_keys
|
end program grib_get_keys
|
||||||
|
|
|
@ -34,16 +34,14 @@ def example():
|
||||||
try:
|
try:
|
||||||
print ' %s: %s' % (key,codes_get(gid,key))
|
print ' %s: %s' % (key,codes_get(gid,key))
|
||||||
except CodesInternalError,err:
|
except CodesInternalError,err:
|
||||||
print 'Error with key="%s" : %s' % (key,err.msg)
|
print 'Error with key="%s" : %s' % (key,err.msg)
|
||||||
|
|
||||||
if codes_is_defined(gid,"A_very_silly_key"): raise Exception("Key was defined")
|
|
||||||
|
|
||||||
print 'There are %d values, average is %f, min is %f, max is %f' % (
|
print 'There are %d values, average is %f, min is %f, max is %f' % (
|
||||||
codes_get_size(gid,'values'),
|
codes_get_size(gid,'values'),
|
||||||
codes_get(gid,'average'),
|
codes_get(gid,'average'),
|
||||||
codes_get(gid,'min'),
|
codes_get(gid,'min'),
|
||||||
codes_get(gid,'max')
|
codes_get(gid,'max')
|
||||||
)
|
)
|
||||||
|
|
||||||
codes_release(gid)
|
codes_release(gid)
|
||||||
|
|
||||||
|
|
|
@ -67,8 +67,6 @@
|
||||||
external grib_get_string
|
external grib_get_string
|
||||||
integer grib_is_missing
|
integer grib_is_missing
|
||||||
external grib_is_missing
|
external grib_is_missing
|
||||||
integer grib_is_defined
|
|
||||||
external grib_is_defined
|
|
||||||
integer grib_set_string
|
integer grib_set_string
|
||||||
external grib_copy_namespace
|
external grib_copy_namespace
|
||||||
integer grib_copy_namespace
|
integer grib_copy_namespace
|
||||||
|
|
|
@ -136,11 +136,6 @@ def test():
|
||||||
new_Ni = grib_get(gid,"Ni")
|
new_Ni = grib_get(gid,"Ni")
|
||||||
print "Set Ni back to its original value --> ",new_Ni
|
print "Set Ni back to its original value --> ",new_Ni
|
||||||
assert Ni == 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)
|
#grib_multi_write(gid,multi)
|
||||||
|
|
||||||
|
|
|
@ -177,18 +177,15 @@ grib_handle* grib_new_handle ( grib_context* c )
|
||||||
|
|
||||||
static void check_definitions_version(grib_handle* h)
|
static void check_definitions_version(grib_handle* h)
|
||||||
{
|
{
|
||||||
/* Check version of definition files is compatible with the engine */
|
/* Check version of definition files is compatible with the engine */
|
||||||
int ret = 0;
|
long defs_file_version = 0;
|
||||||
long defs_file_version = 0;
|
int ret = grib_get_long(h, "internalVersion", &defs_file_version);
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue