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 copy a message in memory
00010 !
00011 !
00012 ! Author: Anne Fouilloux
00013 !
00014 !
00015 program copy
00016 use grib_api
00017 implicit none
00018 integer :: err, centre
00019 integer(kind=kindOfSize) :: byte_size
00020 integer :: infile,outfile
00021 integer :: igrib_in,iret
00022 integer :: igrib_out
00023 character(len=1), dimension(:), allocatable :: message
00024
00025
00026 call grib_open_file(infile,'../../data/constant_field.grib1','r')
00027 call grib_open_file(outfile,'out.grib1','w')
00028
00029 ! a new grib message is loaded from file
00030 ! igrib is the grib id to be used in subsequent calls
00031 call grib_new_from_file(infile,igrib_in)
00032
00033 call grib_get_message_size(igrib_in, byte_size)
00034 allocate(message(byte_size), stat=err)
00035
00036 call grib_copy_message(igrib_in,message)
00037
00038 call grib_new_from_message(igrib_out, message)
00039
00040 centre=80
00041 call grib_set(igrib_out,"centre",centre)
00042
00043 ! write messages to a file
00044 call grib_write(igrib_out,outfile)
00045
00046 call grib_release(igrib_out)
00047
00048 call grib_release(igrib_in)
00049
00050 call grib_close_file(infile)
00051 call grib_close_file(outfile)
00052 deallocate(message)
00053
00054 end program copy