File: keys_iterator_fortran.F

package info (click to toggle)
eccodes 2.44.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 150,248 kB
  • sloc: cpp: 163,056; ansic: 26,308; sh: 21,602; f90: 6,854; perl: 6,363; python: 5,087; java: 2,226; javascript: 1,427; yacc: 854; fortran: 543; lex: 359; makefile: 285; xml: 183; awk: 66
file content (78 lines) | stat: -rw-r--r-- 2,157 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
C (C) Copyright 2005- ECMWF.
C
C This software is licensed under the terms of the Apache Licence Version 2.0
C which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
C 
C In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
C virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
C
C
C
C  Fortran 77 Implementation: keys_iterator
C
C  Description:
C  Example on how to use keys_iterator functions and the
C  grib_keys_iterator structure to get all the available
C  keys in a message.
C
C
C
C
      program keys_iterator
      implicit none
      include 'grib_api_fortran.h'
      character*20 name_space
      integer kiter,ifile,igrib,iret
      character*256 key
      character*256 value
      character*512 all
      integer len,strlen
      integer grib_count
      len=256

      ifile=5

      call grib_check(grib_open_file(ifile,
     X'../data/regular_latlon_surface.grib1','r'))

C     Loop on all the messages in a file.
  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(*,*) '-- GRIB N. ',grib_count,' --'

C     valid name_spaces are ls and mars
      name_space='ls'
C     name_space=' ' to get all the keys */
C     name_space=' '

      strlen = index(name_space,' ') - 1
      call grib_check(
     Xgrib_keys_iterator_new(igrib,kiter,name_space(1:strlen)))
C     call grib_check(grib_keys_iterator_skip_read_only(kiter))
C     call grib_check(grib_keys_iterator_skip_function(kiter))
C     call grib_check(grib_keys_iterator_skip_not_coded(kiter))

  20  if (grib_keys_iterator_next(kiter) .ne. 1) goto 10

      call grib_check(grib_keys_iterator_get_name(kiter,key,strlen))
      call grib_check(grib_get_string(igrib,key(1:strlen),value))
      all=key// ' = ' // value
      write(*,*) all

      goto 20

      call grib_check(grib_keys_iterator_delete(kiter))

      call grib_check(grib_release(igrib))

      call grib_check(grib_close_file(ifile))

      end