1! Copyright 2005-2018 ECMWF.
2!
3! This software is licensed under the terms of the Apache Licence Version 2.0
4! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5!
6! In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
7! virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
8!
9!
10!  Description: how to get PL values.
11!
12!
13program get_pl
14  use grib_api
15  implicit none
16  integer                         :: infile
17  integer                         :: igrib
18  integer                         :: PLPresent, nb_pl
19  real, dimension(:), allocatable :: pl
20
21  call grib_open_file(infile, &
22       '../../data/reduced_gaussian_surface.grib1','r')
23
24  ! A new grib message is loaded from file
25  ! igrib is the grib id to be used in subsequent calls
26  call grib_new_from_file(infile,igrib)
27
28  ! get PLPresent to see if the 'pl' array is there
29  call grib_get(igrib,'PLPresent',PLPresent)
30  print*, "PLPresent= ", PLPresent
31  if (PLPresent == 1) then
32    call grib_get_size(igrib,'pl',nb_pl)
33    print*, "there are ", nb_pl, " PL values"
34    allocate(pl(nb_pl))
35    call grib_get(igrib,'pl',pl)
36    print*, "pl = ", pl
37    deallocate(pl)
38  else
39    print*, "There is no PL values in your GRIB message!"
40  end if
41  call grib_release(igrib)
42
43  call grib_close_file(infile)
44
45end program get_pl
46