49 subroutine addgrid(cgrib, lcgrib, igds, igdstmpl, igdstmplen, &
50 ideflist, idefnum, ierr)
54 character(len = 1),
intent(inout) :: cgrib(lcgrib)
55 integer,
intent(in) :: igds(*), igdstmpl(*), ideflist(idefnum)
56 integer,
intent(in) :: lcgrib, idefnum, igdstmplen
57 integer,
intent(out) :: ierr
59 character(len = 4),
parameter :: grib =
'GRIB', c7777 =
'7777'
60 character(len = 4):: ctemp
61 integer:: mapgrid(igdstmplen)
62 integer,
parameter :: ONE = 1, three = 3
63 integer lensec3, iofst, ibeg, lencurr, len, mapgridlen
65 integer :: i, ilen, iret, isecnum, nbits
70 print *,
'addgrid lcgrib ', lcgrib,
' igdstmplen ', igdstmplen,
' idefnum ', idefnum
75 if (cgrib(i) /= grib(i:i))
then
76 print *,
'addgrid: GRIB not found in given message.'
77 print *,
'addgrid: Call to routine gribcreate required', &
78 ' to initialize GRIB messge.'
79 10
format(
'"', 4a1,
'" /= "GRIB"')
90 ctemp = cgrib(lencurr - 3) // cgrib(lencurr - 2) // cgrib(lencurr &
91 - 1) // cgrib(lencurr)
92 if (ctemp .eq. c7777)
then
93 print *,
'addgrid: GRIB message already complete. Cannot', &
111 if (len .eq. lencurr)
exit
115 if (len .gt. lencurr)
then
116 print *,
'addgrid: Section byte counts don''t add to total.'
117 print *,
'addgrid: Sum of section byte counts = ', len
118 print *,
'addgrid: Total byte count in Section 0 = ', lencurr
125 if ((isecnum .ne. 1) .and. (isecnum .ne. 2) .and. &
126 (isecnum .ne. 7))
then
127 print *,
'addgrid: Section 3 can only be added after Section', &
129 print *,
'addgrid: Section ', isecnum, &
130 ' was the last found in given GRIB message.'
142 call g2_sbytec(cgrib, igds(2), iofst, 32)
151 if (igds(1) .eq. 0)
then
152 call g2_sbytec(cgrib, igds(5), iofst, 16)
159 if (igds(1) .eq. 0)
then
162 if (iret .ne. 0)
then
182 nbits = iabs(mapgrid(i)) * 8
183 if ((mapgrid(i) .ge. 0) .or. (igdstmpl(i) .ge. 0))
then
184 call g2_sbytec(cgrib, igdstmpl(i), iofst, nbits)
187 call g2_sbytec(cgrib, iabs(igdstmpl(i)), iofst + 1, nbits &
190 iofst = iofst + nbits
195 if (igds(3) .ne. 0)
then
197 call g2_sbytesc(cgrib, ideflist, iofst, nbits, 0, idefnum)
198 iofst = iofst + (nbits * idefnum)
203 lensec3 = (iofst - ibeg) / 8
208 call g2_sbytec(cgrib, lencurr + lensec3, 96, 32)
subroutine addgrid(cgrib, lcgrib, igds, igdstmpl, igdstmplen, ideflist, idefnum, ierr)
Add a Grid Definition Section (Section 3) to a GRIB2 message.
subroutine g2_gbytec(in, iout, iskip, nbits)
Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked a...
subroutine g2_sbytec(out, in, iskip, nbits)
Put arbitrary size values into a packed bit string, taking the low order bits from each value in the ...
subroutine g2_sbytesc(out, in, iskip, nbits, nskip, n)
Put arbitrary size values into a packed bit string, taking the low order bits from each value in the ...
This Fortran module contains info on all the available GRIB2 Grid Definition Templates used in [Secti...
subroutine getgridtemplate(number, nummap, map, needext, iret)
Get the grid template information for a specified Grid Definition Template.
subroutine extgridtemplate(number, list, nummap, map)
Generate the remaining octet map for a given Grid Definition Template, if required.