      program keys_iterator
      include 'grib_api_f77.h'
      character*20 name_space
      integer kiter,ifile,igrib,iret
      character*256 key, value
      character*512 all
      integer len,strlen
      integer grib_count
      len=256
      
      open(10,file='output.txt')

      ifile=15
      call grib_check(grib_open_file(ifile,'ecm.grib','r'))

      grib_count=0
  10  iret=grib_new_from_file(ifile,igrib)
      if (igrib .eq. -1 )  then
        if (iret .ne.0) then
           call grib_check(iret)
        endif
        stop
      endif
      grib_count=grib_count+1
      write(10,'("-- GRIB N.",I4," --")') grib_count

      name_space='ls'
C      name_space='mars'

      call grib_check(
     Xgrib_keys_iterator_new(igrib,kiter,name_space))
  20  if (grib_keys_iterator_next(kiter) .ne. 1) goto 10

      call grib_check(grib_keys_iterator_get_name(kiter,key))
      call grib_check(grib_get_string(igrib,key,value))
      all= trim(key)//':' // trim(value)
C     betette a parameter megnevezeset es erteket is egy
C     character tipusu valtozoba
      
      write(10,*) trim(all)
      goto 20

      call grib_check(grib_keys_iterator_delete(kiter))
      call grib_check(grib_release(igrib))
      call grib_check(grib_close_file(ifile))

      close(10)
      end
      