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 create a multi field message in memory and write 00010 ! it in a file. The multi field messages can be created 00011 ! only in grib edition 2. 00012 ! 00013 ! 00014 ! 00015 program multi_write 00016 use grib_api 00017 implicit none 00018 integer :: infile,outfile 00019 integer :: in_gribid,iret 00020 integer :: multi_gribid 00021 integer :: step,startsection 00022 00023 ! multi field messages can be created only in edition 2 00024 call grib_open_file(infile,'../../data/sample.grib2','r') 00025 00026 call grib_open_file(outfile,'multi_created.grib2','w') 00027 00028 ! a grib message is loaded from file 00029 ! in_gribid is the grib id to be used in subsequent calls 00030 call grib_new_from_file(infile,in_gribid) 00031 00032 startsection=4 00033 do step=0,240,12 00034 00035 call grib_set(in_gribid,"step",step) 00036 call grib_multi_append(in_gribid,startsection,multi_gribid) 00037 00038 enddo 00039 00040 ! write messages to a file 00041 call grib_multi_write(multi_gribid,outfile) 00042 00043 call grib_close_file(infile) 00044 call grib_close_file(outfile) 00045 00046 end program multi_write