grib_api: keys_iterator_fortran.F

- Main Page
- Modules
- Files
- Related Pages
- Examples

# keys_iterator_fortran.F

keys_iterator_fortran.F How to get the names of all the keys defined in a message and how to iterate through them.

    00001 C Copyright 2005-2015 ECMWF
    00002 C This software is licensed under the terms of the Apache Licence Version 2.0
    00003 C which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
    00004 C
    00005 C In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
    00006 C virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
    00007 C
    00008 C
    00009 C  Fortran 77 Implementation: keys_iterator
    00010 C
    00011 C  Description:
    00012 C  Example on how to use keys_iterator functions and the
    00013 C  grib_keys_iterator structure to get all the available
    00014 C  keys in a message.
    00015 C
    00016 C  Author: Enrico Fucile
    00017 C
    00018 C
    00019 C
    00020       program keys_iterator
    00021       implicit none
    00022       include 'grib_api_f77.h'
    00023       character*20 name_space
    00024       integer kiter,ifile,igrib,iret
    00025       character*256 key
    00026       character*256 value
    00027       character*512 all
    00028       integer len,strlen
    00029       integer grib_count
    00030       len=256
    00031
    00032       ifile=5
    00033
    00034       call grib_check(grib_open_file(ifile,
    00035      X'../../data/regular_latlon_surface.grib1','r'))
    00036
    00037       grib_count=0
    00038 C     Loop on all the messages in a file.
    00039   10  iret=grib_new_from_file(ifile,igrib)
    00040       if (igrib .eq. -1 )  then
    00041         if (iret .ne.0) then
    00042            call grib_check(iret)
    00043         endif
    00044         stop
    00045       endif
    00046
    00047       grib_count=grib_count+1
    00048       write(*,'("-- GRIB N.",I4," --")') grib_count
    00049
    00050 C     valid name_spaces are ls and mars
    00051       name_space='ls'
    00052 C     name_space=' ' to get all the keys */
    00053 C     name_space=' '
    00054
    00055       call grib_check(
    00056      Xgrib_keys_iterator_new(igrib,kiter,name_space))
    00057 C     call grib_check(grib_keys_iterator_skip_read_only(kiter))
    00058 C     call grib_check(grib_keys_iterator_skip_function(kiter))
    00059 C     call grib_check(grib_keys_iterator_skip_not_coded(kiter))
    00060
    00061   20  if (grib_keys_iterator_next(kiter) .ne. 1) goto 10
    00062
    00063       call grib_check(grib_keys_iterator_get_name(kiter,key))
    00064       call grib_check(grib_get_string(igrib,key,value))
    00065       all='|' // trim(key)//'|' //  ' = ' //'|' //  trim(value) // '|'
    00066       write(*,*) trim(all)
    00067
    00068       goto 20
    00069
    00070       call grib_check(grib_keys_iterator_delete(kiter))
    00071
    00072       call grib_check(grib_release(igrib))
    00073
    00074       call grib_check(grib_close_file(ifile))
    00075
    00076       end
    00077