NCEPLIBS-g2  3.4.8
getgb2l.F90
Go to the documentation of this file.
1 
5 
36 SUBROUTINE getgb2l(LUGB, CINDEX, GFLD, IRET)
37  USE grib_mod
38  implicit none
39 
40  INTEGER, INTENT(IN) :: LUGB
41  CHARACTER(LEN = 1), INTENT(IN) :: CINDEX(*)
42  TYPE(gribfield) :: GFLD
43  INTEGER, INTENT(OUT) :: IRET
44 
45  INTEGER :: LSKIP, SKIP2
46  CHARACTER(LEN = 1):: CSIZE(4)
47  CHARACTER(LEN = 1), ALLOCATABLE :: CTEMP(:)
48  integer :: ilen, iofst, iskip, lread, ierr
49 
50  interface
51  subroutine gf_unpack2(cgrib, lcgrib, iofst, lencsec2, csec2, ierr)
52  character(len = 1), intent(in) :: cgrib(lcgrib)
53  integer, intent(in) :: lcgrib
54  integer, intent(inout) :: iofst
55  integer, intent(out) :: lencsec2
56  integer, intent(out) :: ierr
57  character(len = 1), pointer, dimension(:) :: csec2
58  end subroutine gf_unpack2
59  end interface
60 
61  ! Get info.
62  NULLIFY(gfld%local)
63  iret = 0
64  CALL g2_gbytec(cindex, lskip, 4 * 8, 4 * 8)
65  CALL g2_gbytec(cindex, skip2, 8 * 8, 4 * 8)
66 
67  ! Read and unpack local use section, if present.
68  IF (skip2 .NE. 0) THEN
69  iskip = lskip + skip2
70 
71  ! Get length of section.
72  CALL baread(lugb, iskip, 4, lread, csize)
73  CALL g2_gbytec(csize, ilen, 0, 32)
74  ALLOCATE(ctemp(ilen))
75 
76  ! Read in section.
77  CALL baread(lugb, iskip, ilen, lread, ctemp)
78  IF (ilen .NE. lread) THEN
79  iret = 97
80  DEALLOCATE(ctemp)
81  RETURN
82  ENDIF
83  iofst = 0
84  CALL gf_unpack2(ctemp, ilen, iofst, gfld%locallen, gfld%local, ierr)
85  IF (ierr .NE. 0) THEN
86  iret = 98
87  DEALLOCATE(ctemp)
88  RETURN
89  ENDIF
90  DEALLOCATE(ctemp)
91  ELSE
92  gfld%locallen = 0
93  ENDIF
94 END SUBROUTINE getgb2l
subroutine g2_gbytec(in, iout, iskip, nbits)
Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked a...
Definition: g2_gbytesc.F90:20
subroutine getgb2l(LUGB, CINDEX, GFLD, IRET)
This subroutine reads and unpacks a local use section from a GRIB2 message.
Definition: getgb2l.F90:37
subroutine gf_unpack2(cgrib, lcgrib, iofst, lencsec2, csec2, ierr)
Unpack Section 2 (Local Use Section) of a GRIB2 message.
Definition: gf_unpack2.F90:26
This Fortran module contains the declaration of derived type gribfield.
Definition: gribmod.F90:10