00001 ! Copyright 2005-2014 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: how to set key values. 00010 ! 00011 ! 00012 ! Author: Anne Fouilloux 00013 ! 00014 ! 00015 program set 00016 use grib_api 00017 implicit none 00018 integer(kind = 4) :: centre, date 00019 integer :: infile,outfile 00020 integer :: igrib 00021 00022 00023 centre = 80 00024 call current_date(date) 00025 call grib_open_file(infile, & 00026 '../../data/regular_latlon_surface_constant.grib1','r') 00027 00028 call grib_open_file(outfile, & 00029 'out.grib1','w') 00030 00031 ! a new grib message is loaded from file 00032 ! igrib is the grib id to be used in subsequent calls 00033 call grib_new_from_file(infile,igrib) 00034 00035 call grib_set(igrib,'date',date) 00036 ! set centre as a integer */ 00037 call grib_set(igrib,'centre',centre) 00038 00039 ! check if it is correct in the actual GRIB message 00040 00041 call check_settings(igrib) 00042 00043 ! write modified message to a file 00044 call grib_write(igrib,outfile) 00045 00046 call grib_release(igrib) 00047 00048 call grib_close_file(infile) 00049 00050 call grib_close_file(outfile) 00051 00052 contains 00053 00054 !====================================== 00055 subroutine current_date(date) 00056 integer, intent(out) :: date 00057 00058 integer :: val_date(8) 00059 call date_and_time ( values = val_date) 00060 00061 date = val_date(1)* 10000 + val_date(2)*100 + val_date(3) 00062 end subroutine current_date 00063 !====================================== 00064 subroutine check_settings(gribid) 00065 use grib_api 00066 implicit none 00067 integer, intent(in) :: gribid 00068 00069 integer(kind = 4) :: int_value 00070 character(len = 10) :: string_value 00071 00072 ! get centre as a integer 00073 call grib_get(gribid,'centre',int_value) 00074 write(*,*) "get centre as a integer - centre = ",int_value 00075 00076 ! get centre as a string 00077 call grib_get(gribid,'centre',string_value) 00078 write(*,*) "get centre as a string - centre = ",string_value 00079 00080 ! get date as a string 00081 call grib_get(gribid,'dataDate',string_value) 00082 write(*,*) "get date as a string - date = ",string_value 00083 00084 end subroutine check_settings 00085 end program set