This commit is contained in:
Enrico Fucile 2015-02-10 17:57:14 +00:00
commit eb07787412
7 changed files with 65 additions and 78 deletions

View File

@ -87,7 +87,7 @@ int main(int argc,char* argv[])
}
/* we need to instruct ecCodes to unpack the data values */
/*CODES_CHECK(codes_set_long(h,"unpack",1),0);*/
CODES_CHECK(codes_set_long(h,"unpack",1),0);
/* loop over the keys */
while(codes_keys_iterator_next(kiter))

View File

@ -53,7 +53,7 @@ integer :: kiter
call codes_keys_iterator_next(kiter, iret)
! loop over keys
do while (iret == 1)
do while (iret == CODES_SUCCESS)
! print key name
call codes_keys_iterator_get_name(kiter,key)
@ -62,7 +62,7 @@ integer :: kiter
! get next key
call codes_keys_iterator_next(kiter, iret)
end do
end do
! delete key iterator
call grib_keys_iterator_delete(kiter)

View File

@ -32,29 +32,29 @@ program keys_iterator
do while (iret /= CODES_END_OF_FILE)
grib_count=grib_count+1
write(*,*) '-- GRIB N. ',grib_count,' --'
grib_count=grib_count+1
write(*,*) '-- GRIB N. ',grib_count,' --'
! valid name_spaces are ls and mars
name_space='ls'
! valid name_spaces are ls and mars
name_space='ls'
call codes_keys_iterator_new(igrib,kiter,name_space)
call codes_keys_iterator_new(igrib,kiter,name_space)
do
call codes_keys_iterator_next(kiter, iret)
do
call codes_keys_iterator_next(kiter, iret)
if (iret .ne. 1) exit
if (iret .ne. CODES_SUCCESS) exit
call codes_keys_iterator_get_name(kiter,key)
call codes_get(igrib,trim(key),value)
all1=trim(key)// ' = ' // trim(value)
write(*,*) trim(all1)
call codes_keys_iterator_get_name(kiter,key)
call codes_get(igrib,trim(key),value)
all1=trim(key)// ' = ' // trim(value)
write(*,*) trim(all1)
end do
end do
call codes_keys_iterator_delete(kiter)
call codes_release(igrib)
call codes_new_from_file(ifile,igrib, iret)
call codes_keys_iterator_delete(kiter)
call codes_release(igrib)
call codes_new_from_file(ifile,igrib, iret)
end do

View File

@ -36,37 +36,33 @@ program keys_iterator
do while (igrib .ne. -1)
grib_count=grib_count+1
write(*,'("-- GRIB N.",I4," --")') grib_count
grib_count=grib_count+1
write(*,'("-- GRIB N.",I4," --")') grib_count
! valid name_spaces are ls and mars
call codes_keys_iterator_new(igrib,kiter,'ls')
! valid name_spaces are ls and mars
call codes_keys_iterator_new(igrib,kiter,'ls')
if (kiter .eq. -1) then
print *, 'invalid key iterator'
endif
if (kiter .eq. -1) then
print *, 'invalid key iterator'
endif
do
do
call codes_keys_iterator_next(kiter, iret)
call codes_keys_iterator_next(kiter, iret)
if (iret .ne. CODES_SUCCESS) exit
if (iret .eq. 0) exit
call codes_keys_iterator_get_name(kiter,key)
call codes_keys_iterator_get_name(kiter,key)
call codes_get(igrib,key,value)
all='|'//trim(key)//'|'//' = '//'|'//trim(value)//'|'
write(*,*) trim(all)
call codes_get(igrib,key,value)
all='|'//trim(key)//'|'//' = '//'|'//trim(value)//'|'
write(*,*) trim(all)
end do
call codes_keys_iterator_delete(kiter)
call codes_release(igrib)
call codes_new_from_file(ifile,igrib, iret)
end do
call codes_keys_iterator_delete(kiter)
call codes_release(igrib)
call codes_new_from_file(ifile,igrib, iret)
end do
call codes_close_file(ifile)
end program keys_iterator

View File

@ -1637,23 +1637,18 @@
!> Advance to the next keys iterator value.
!>
!> In case of error, if the status parameter (optional) is not given, the program will
!> exit with an error message.\n Otherwise the error message can be
!> gathered with @ref grib_get_error_string.
!>
!> @param iterid keys iterator id created with @ref grib_keys_iterator_new
!> @param status GRIB_SUCCESS if OK, integer value on error
!> @param iterid keys iterator id created with @ref grib_keys_iterator_new
!> @param status GRIB_SUCCESS if next iterator exists, integer value if no more elements to iterate on
subroutine grib_keys_iterator_next ( iterid , status)
integer(kind=kindOfInt), intent(in) :: iterid
integer(kind=kindOfInt),optional, intent(out) :: status
integer(kind=kindOfInt), intent(out) :: status
integer(kind=kindOfInt) :: iret
iret = grib_f_keys_iterator_next ( iterid )
if (present(status)) then
status = iret
else
call grib_check(iret,'grib_keys_iterator_next','')
status = GRIB_SUCCESS
iret = grib_f_keys_iterator_next ( iterid )
if (iret == 0) then
! no more elements
status = GRIB_END
endif
end subroutine grib_keys_iterator_next
@ -1668,7 +1663,6 @@
subroutine grib_keys_iterator_delete ( iterid , status)
integer(kind=kindOfInt), intent(in) :: iterid
integer(kind=kindOfInt),optional, intent(out) :: status
integer(kind=kindOfInt) :: iret
iret = grib_f_keys_iterator_delete ( iterid )
@ -1691,7 +1685,6 @@
integer(kind=kindOfInt), intent(in) :: iterid
character(LEN=*), intent(out) :: name
integer(kind=kindOfInt),optional, intent(out) :: status
integer(kind=kindOfInt) :: iret
iret = grib_f_keys_iterator_get_name ( iterid, name )
@ -1713,7 +1706,6 @@
subroutine grib_keys_iterator_rewind ( iterid, status )
integer(kind=kindOfInt), intent(in) :: iterid
integer(kind=kindOfInt),optional, intent(out) :: status
integer(kind=kindOfInt) :: iret
iret = grib_f_keys_iterator_rewind ( iterid )
@ -1737,7 +1729,6 @@
integer(kind=kindOfInt),optional, intent(out) :: status
integer(kind=kindOfInt) :: iret
iret=grib_f_dump ( gribid )
if (present(status)) then
status = iret
@ -1871,9 +1862,9 @@
integer(kind=kindOfInt) :: iret
iret=grib_f_get_long ( gribid, key, value )
if (iret /= 0) then
call grib_f_write_on_fail(gribid)
endif
if (iret /= 0) then
call grib_f_write_on_fail(gribid)
endif
if (present(status)) then
status = iret
else
@ -1892,22 +1883,22 @@
!> @param is_missing 0->not missing, 1->missing
!> @param status GRIB_SUCCESS if OK, integer value on error
subroutine grib_is_missing(gribid,key,is_missing,status)
integer(kind=kindOfInt), intent(in) :: gribid
character(len=*), intent(in) :: key
integer(kind = kindOfInt), intent(out) :: is_missing
integer(kind=kindOfInt),optional, intent(out) :: status
integer(kind=kindOfInt) :: iret
integer(kind=kindOfInt), intent(in) :: gribid
character(len=*), intent(in) :: key
integer(kind = kindOfInt), intent(out) :: is_missing
integer(kind=kindOfInt),optional, intent(out) :: status
integer(kind=kindOfInt) :: iret
iret=grib_f_is_missing ( gribid, key, is_missing )
if (iret /= 0) then
if (iret /= 0) then
call grib_f_write_on_fail(gribid)
endif
endif
if (present(status)) then
status = iret
else
call grib_check(iret,'grib_is_missing',key)
endif
end subroutine grib_is_missing
end subroutine grib_is_missing
!> Check if a key is DEFINED.
!>
@ -1927,15 +1918,15 @@
integer(kind=kindOfInt) :: iret
iret=grib_f_is_defined( gribid, key, is_defined )
if (iret /= 0) then
if (iret /= 0) then
call grib_f_write_on_fail(gribid)
endif
endif
if (present(status)) then
status = iret
else
call grib_check(iret,'grib_is_defined',key)
endif
end subroutine grib_is_defined
end subroutine grib_is_defined
!> Get the real(4) value of a key from a grib message.
!>

View File

@ -530,7 +530,7 @@ def grib_iterator_next(iterid):
def grib_keys_iterator_new(gribid,namespace=None):
"""
@brief Create a new iterator on the keys.
The keys iterator can be navigated to give all the key names which
can then be used to get or set the key values with \ref grib_get or
\ref grib_set.
@ -539,13 +539,13 @@ def grib_keys_iterator_new(gribid,namespace=None):
\ref grib_skip_read_only, \ref grib_skip_duplicates,
\ref grib_skip_coded,\ref grib_skip_computed.
If namespace is a non empty string only the keys belonging to
that namespace are returned. Available namespaces are "ls" (to get the same
default keys as the grib_ls and "mars" to get the keys used by mars.
that namespace are returned. Example namespaces are "ls" (to get the same
default keys as the grib_ls) and "mars" to get the keys used by mars.
\b Examples: \ref iterator.py "iterator.py"
@param gribid id of the grib loaded in memory
@param namespace the namespace of the keys to search for (all the keys if empty)
@param namespace the namespace of the keys to search for (all the keys if None)
@return keys iterator id to be used in the keys iterator functions
@exception GribInternalError
"""

View File

@ -47,7 +47,7 @@ grib_keys_iterator* grib_keys_iterator_new(grib_handle* h,unsigned long filter_
ki->handle = h;
ki->name_space = NULL;
if (name_space != NULL)
if (name_space != NULL && strlen(name_space) > 0)
ki->name_space = grib_context_strdup(h->context,name_space);
ki->at_start = 1;