eccodes/examples/F90/multi_fortran.f90

71 lines
2.1 KiB
Fortran
Raw Normal View History

2020-01-28 14:32:34 +00:00
! (C) Copyright 2005- ECMWF.
2013-03-25 12:04:10 +00:00
!
! This software is licensed under the terms of the Apache Licence Version 2.0
! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
2017-02-06 16:45:30 +00:00
!
2013-03-25 12:04:10 +00:00
! In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
! virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
!
!
! Description: How to decode GRIB messages containing multiple
2013-03-25 12:04:10 +00:00
! fields. Try to turn on and off multi support to
! see the difference. Default is OFF.
! For all the tools (e.g., grib_ls etc) multi support is ON.
2013-03-25 12:04:10 +00:00
!
!
program multi
use eccodes
implicit none
2017-02-06 16:45:30 +00:00
2023-08-25 17:44:07 +00:00
integer :: iret
integer(kind=4) :: parameterCategory, parameterNumber, discipline
2023-08-25 17:44:07 +00:00
integer :: ifile, igrib, counter
2013-03-25 12:04:10 +00:00
call codes_open_file(ifile, '../../data/multi.grib2', 'r')
2013-03-25 12:04:10 +00:00
2023-08-25 17:44:07 +00:00
! Turn off support for multi-field messages
call codes_grib_multi_support_off()
2013-03-25 12:04:10 +00:00
2023-08-25 17:44:07 +00:00
! Turn on support for multi-field messages
call codes_grib_multi_support_on()
2013-03-25 12:04:10 +00:00
call codes_grib_new_from_file(ifile, igrib)
! Loop on all the messages in a file.
2013-03-25 12:04:10 +00:00
do while (igrib .ne. -1)
2013-03-25 12:04:10 +00:00
2023-08-25 17:44:07 +00:00
counter = counter + 1
! get as a integer*4
call codes_get(igrib, 'discipline', discipline)
write (*, *) 'discipline=', discipline
2013-03-25 12:04:10 +00:00
! get as a integer*4
call codes_get(igrib, 'parameterCategory', &
parameterCategory)
write (*, *) 'parameterCategory=', parameterCategory
2013-03-25 12:04:10 +00:00
! get as a integer*4
call codes_get(igrib, 'parameterNumber', &
parameterNumber)
write (*, *) 'parameterNumber=', parameterNumber
2013-03-25 12:04:10 +00:00
if (discipline .eq. 0 .and. parameterCategory .eq. 2) then
if (parameterNumber .eq. 2) then
write (*, *) "-------- u -------"
end if
if (parameterNumber .eq. 3) then
write (*, *) "-------- v -------"
end if
end if
2013-03-25 12:04:10 +00:00
call codes_release(igrib)
call codes_grib_new_from_file(ifile, igrib, iret)
2013-03-25 12:04:10 +00:00
end do
call codes_close_file(ifile)
2013-03-25 12:04:10 +00:00
2023-08-25 17:44:07 +00:00
write(*,*) 'Message count =',counter
2013-03-25 12:04:10 +00:00
end program multi