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

# print_data.f90

How to print all the data contained in a grib file.

    00001 ! 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 !
    00008 !
    00009 !  Description: prints all the data contained in a grib file
    00010 !
    00011 !
    00012 !  Author: Anne Fouilloux
    00013 !
    00014 !
    00015 program print_data
    00016 use grib_api
    00017 implicit none
    00018 integer            :: ifile
    00019 integer            :: iret
    00020 integer            :: igrib
    00021 integer            :: i
    00022 real(kind=8), dimension(:), allocatable       :: values
    00023 integer(kind=4)    :: numberOfValues
    00024 real(kind=8)       :: average
    00025 real(kind=8)       :: max
    00026 real(kind=8)       :: min
    00027 character(len=256) :: error
    00028
    00029 call grib_open_file(ifile, &
    00030            '../../data/constant_field.grib1','r')
    00031
    00032 !     a new grib message is loaded from file
    00033 !     igrib is the grib id to be used in subsequent calls
    00034       call grib_new_from_file(ifile,igrib)
    00035
    00036
    00037 !     get the size of the values array
    00038       call grib_get_size(igrib,'values',numberOfValues)
    00039
    00040 !     get data values
    00041   print*, 'number of values ', numberOfValues
    00042   allocate(values(numberOfValues), stat=iret)
    00043
    00044   call grib_get(igrib,'values',values)
    00045
    00046   do i=1,numberOfValues
    00047     write(*,*)'  ',i,values(i)
    00048   enddo
    00049
    00050
    00051   write(*,*)numberOfValues,' values found '
    00052
    00053   call grib_get(igrib,'max',max)
    00054   write(*,*) 'max=',max
    00055   call grib_get(igrib,'min',min)
    00056   write(*,*) 'min=',min
    00057   call grib_get(igrib,'average',average)
    00058   write(*,*) 'average=',average
    00059
    00060   call grib_release(igrib)
    00061
    00062   call grib_close_file(ifile)
    00063
    00064   deallocate(values)
    00065
    00066 end program print_data