00001 ! Copyright 2005-2007 ECMWF 00002 ! 00003 ! Licensed under the GNU Lesser General Public License which 00004 ! incorporates the terms and conditions of version 3 of the GNU 00005 ! General Public License. 00006 ! See LICENSE and gpl-3.0.txt for details. 00007 ! 00008 ! 00009 ! Description: How to decode grib messages containing multiple 00010 ! fields. Try to turn on and off multi support to 00011 ! see the difference. Default is OFF. 00012 ! For all the tools defalut is multi support ON. 00013 ! 00014 ! 00015 ! Author: Enrico Fucile 00016 ! 00017 ! 00018 program multi 00019 use grib_api 00020 implicit none 00021 00022 integer :: iret 00023 character(len = 256) :: error 00024 integer(kind = 4) :: parameterCategory,parameterNumber,discipline 00025 integer :: ifile,igrib 00026 00027 call grib_open_file(ifile, & 00028 '../../data/multi.grib2','r') 00029 00030 ! turn on support for multi fields messages */ 00031 call grib_multi_support_on() 00032 00033 ! turn off support for multi fields messages */ 00034 ! call grib_multi_support_off() 00035 00036 call grib_new_from_file(ifile,igrib, iret) 00037 ! Loop on all the messages in a file. 00038 00039 do while (iret /= GRIB_END_OF_FILE) 00040 00041 ! get as a integer*4 00042 call grib_get(igrib,'discipline',discipline) 00043 write(*,*) 'discipline=',discipline 00044 00045 ! get as a integer*4 00046 call grib_get(igrib,'parameterCategory', & 00047 parameterCategory) 00048 write(*,*) 'parameterCategory=',parameterCategory 00049 00050 ! get as a integer*4 00051 call grib_get(igrib,'parameterNumber', & 00052 parameterNumber) 00053 write(*,*) 'parameterNumber=',parameterNumber 00054 00055 if ( discipline .eq. 0 .and. parameterCategory .eq. 2) then 00056 if (parameterNumber .eq. 2) then 00057 write(*,*) "-------- u -------" 00058 endif 00059 if (parameterNumber .eq. 3) then 00060 write(*,*) "-------- v -------" 00061 endif 00062 endif 00063 00064 call grib_release(igrib) 00065 call grib_new_from_file(ifile,igrib, iret) 00066 00067 end do 00068 call grib_close_file(ifile) 00069 00070 end program multi 00071