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

# print_data_fortran.F

print_data_fortran.F How to print all the data from a grib message.

    00001 C Copyright 2005-2018 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 C
    00008 C  Fortran 77  Implementation: print_data_fortran
    00009 C
    00010 C  Description: prints all the data contained in a grib file
    00011 C
    00012 C  Author: Enrico Fucile
    00013 C
    00014 C
    00015 C
    00016       program print_data_fortran
    00017       implicit none
    00018       integer maxNumberOfValues
    00019       parameter( maxNumberOfValues = 100000 )
    00020       include 'grib_api_f77.h'
    00021       integer ifile
    00022       integer iret
    00023       integer igrib
    00024       integer i
    00025       real*8 values(maxNumberOfValues)
    00026       integer*4 numberOfValues
    00027       real*8 average
    00028       real*8 max
    00029       real*8 min
    00030       character*256 error
    00031       integer*4 size
    00032
    00033       size=maxNumberOfValues
    00034       ifile=5
    00035
    00036       iret=grib_open_file(ifile
    00037      X,'../../data/constant_field.grib1','r')
    00038       call grib_check(iret)
    00039
    00040 C     a new grib message is loaded from file
    00041 C     igrib is the grib id to be used in subsequent calls
    00042       call grib_check( grib_new_from_file(ifile,igrib) )
    00043
    00044
    00045 C     get the size of the values array
    00046       call grib_check(grib_get_size(igrib,'values',numberOfValues))
    00047       if ( numberOfValues .gt. maxNumberOfValues ) then
    00048         write(*,*)'ERROR: maxNumberOfValues too small numberOfValues=',
    00049      XnumberOfValues
    00050             stop
    00051       endif
    00052
    00053 C     get data values
    00054       call grib_check(grib_get_real8_array(igrib,'values',values,size))
    00055       if ( size .ne. numberOfValues ) then
    00056         write(*,*) 'ERROR: wrong numberOfValues'
    00057         stop
    00058       endif
    00059
    00060       do i=1,numberOfValues
    00061         write(*,*)'  ',i,values(i)
    00062       enddo
    00063
    00064       average =average / numberOfValues
    00065
    00066       write(*,*)numberOfValues,' values found '
    00067
    00068       call grib_check(grib_get_real8(igrib,'max',max))
    00069       write(*,*) 'max=',max
    00070       call grib_check(grib_get_real8(igrib,'min',min))
    00071       write(*,*) 'min=',min
    00072       call grib_check(grib_get_real8(igrib,'average',average))
    00073       write(*,*) 'average=',average
    00074
    00075       call grib_check(grib_release(igrib))
    00076
    00077       call grib_check(grib_close_file(ifile))
    00078
    00079       end