grib_api: iterator_fortran.F

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

# iterator_fortran.F

iterator_fortran.F How to use an iterator on latitude, longitude, values.

    00001 C Copyright 2005-2016 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: iterator_fortran
    00010 C
    00011 C  Description: how to use an iterator on lat/lon/values.
    00012 C
    00013 C
    00014 C  Author: Enrico Fucile
    00015 C
    00016 C
    00017 C
    00018       program iterator
    00019       implicit none
    00020       include 'grib_api_f77.h'
    00021       integer ifile
    00022       integer iret,iter
    00023       real*8 lat,lon,value,missingValue
    00024       integer n,flags
    00025       character*256 filename
    00026       character*256 error
    00027
    00028 C     Message identifier.
    00029       integer igrib
    00030
    00031       ifile=5
    00032
    00033       call grib_check(grib_open_file(ifile,
    00034      X'../../data/regular_latlon_surface.grib1','r'))
    00035
    00036 C     Loop on all the messages in a file.
    00037   10  iret=grib_new_from_file(ifile,igrib)
    00038       if (igrib .eq. -1 )  then
    00039         if (iret .ne.0) then
    00040            call grib_check(iret)
    00041         endif
    00042         stop
    00043       endif
    00044
    00045 C     get as a real8
    00046       call grib_check(grib_get_real8(igrib
    00047      X,'missingValue',missingValue))
    00048       write(*,*) 'missingValue=',missingValue
    00049
    00050 C     A new iterator on lat/lon/values is created from the message igrib
    00051       flags = 0
    00052       call grib_check(grib_iterator_new(igrib,iter,flags))
    00053
    00054       n = 0
    00055 C     Loop on all the lat/lon/values.
    00056   20  iret = grib_iterator_next(iter,lat,lon,value)
    00057       if ( iret .eq. 0 ) goto 30
    00058 C     You can now print lat and lon,
    00059       if ( value .eq. missingValue ) then
    00060 C     decide what to print if a missing value is found.
    00061         write(*,*) "- ",n," - lat=",lat," lon=",lon," value=missing"
    00062       else
    00063 C     or print the value if is not missing.
    00064         write(*,*) " ",n," lat=",lat," lon=",lon," value=",value
    00065       endif
    00066
    00067       n=n+1
    00068
    00069       goto 20
    00070   30  continue
    00071
    00072 C     At the end the iterator is deleted to free memory.
    00073       call grib_check(grib_iterator_delete(iter))
    00074
    00075       goto 10
    00076
    00077       call grib_check(grib_release(igrib))
    00078
    00079       call grib_check(grib_close_file(ifile))
    00080
    00081       end