1! 2! Copyright 2005-2018 ECMWF. 3! 4! This software is licensed under the terms of the Apache Licence Version 2.0 5! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. 6! 7! In applying this licence, ECMWF does not waive the privileges and immunities granted to it by 8! virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. 9! 10! Description: how to get values using keys. 11! 12program read_message 13use grib_api 14implicit none 15 integer :: ifile,ofile 16 integer :: iret,igrib 17 integer , dimension(50000) :: buffer 18 integer(kind=kindOfSize_t) :: len1 19 integer :: step,level 20 21 call grib_open_file(ifile,'../../data/index.grib','r') 22 call grib_open_file(ofile,'out.readmsg.grib','w') 23 24! a grib message is read from file into buffer 25 len1=size(buffer)*4 26 call grib_read_from_file(ifile,buffer,len1,iret) 27 28 do while (iret/=GRIB_END_OF_FILE) 29 30! a new grib message is created from buffer 31 call grib_new_from_message(igrib,buffer) 32 33! get as a integer 34 call grib_get(igrib,'step', step) 35 write(*,*) 'step=',step 36 37 call grib_get(igrib,'level',level) 38 write(*,*) 'level=',level 39 40 call grib_release(igrib) 41 42 call grib_write_bytes(ofile,buffer,len1) 43 44! a grib message is read from file into buffer 45 len1=size(buffer)*4 46 call grib_read_from_file(ifile,buffer,len1,iret) 47 48 enddo 49 50 call grib_close_file(ifile) 51 call grib_close_file(ofile) 52 53end program read_message 54 55