00001 ! Copyright 2005-2016 ECMWF
00002 ! This software is licensed under the terms of the Apache Licence Version 2.0
00003 ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
00004 !
00005 ! In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
00006 ! virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
00007 !
00008 !
00009 ! Description:
00010 ! How to use keys_iterator to get all the available
00011 ! keys in a message.
00012 !
00013 ! Author: Enrico Fucile
00014 !
00015 !
00016 program keys_iterator
00017 use grib_api
00018 implicit none
00019 character(len=20) :: name_space
00020 integer :: kiter,ifile,igrib,iret
00021 character(len=256) :: key
00022 character(len=256) :: value
00023 character(len=512) :: all
00024 integer :: grib_count
00025
00026 call grib_open_file(ifile, &
00027 '../../data/regular_latlon_surface.grib1','r')
00028
00029 ! Loop on all the messages in a file.
00030
00031 call grib_new_from_file(ifile,igrib, iret)
00032
00033 do while (iret /= GRIB_END_OF_FILE)
00034
00035 grib_count=grib_count+1
00036 write(*,*) '-- GRIB N. ',grib_count,' --'
00037
00038 ! valid name_spaces are ls and mars
00039 name_space='ls'
00040
00041 call grib_keys_iterator_new(igrib,kiter,name_space)
00042
00043 do
00044 call grib_keys_iterator_next(kiter, iret)
00045
00046 if (iret .ne. 1) exit
00047
00048 call grib_keys_iterator_get_name(kiter,key)
00049 call grib_get(igrib,trim(key),value)
00050 all=trim(key)
00051 write(*,*) trim(all)
00052
00053 end do
00054
00055 call grib_keys_iterator_delete(kiter)
00056 call grib_release(igrib)
00057 call grib_new_from_file(ifile,igrib, iret)
00058 end do
00059
00060
00061 call grib_close_file(ifile)
00062
00063 end program keys_iterator
00064