44 integer,
intent(in) :: lugb
46 integer,
intent(out) :: iret
48 character(len = 1),
allocatable,
dimension(:) :: cgrib
49 integer :: listsec0(2)
53 integer :: ierr, is, lcgrib, lengrib
56 igds = (/0, 0, 0, 0, 0/)
63 if (
associated(gfld%local) .AND. gfld%locallen .gt. 0)
then
64 lcgrib = lcgrib + gfld%locallen * 4
67 lcgrib = lcgrib + 512 + 512 + 512
69 if (gfld%ibmap .eq. 0)
then
70 lcgrib = lcgrib + gfld%ngrdpts
73 lcgrib = lcgrib + gfld%ngrdpts * 4
76 print *,
'putgb2 lugb ', lugb,
' lcgrib ', lcgrib
80 allocate(cgrib(lcgrib), stat = is)
82 print *,
'putgb2: cannot allocate memory. ', is
87 listsec0(1) = gfld%discipline
88 listsec0(2) = gfld%version
89 if (
associated(gfld%idsect))
then
90 call gribcreate(cgrib, lcgrib, listsec0, gfld%idsect, ierr)
92 write(6, *)
'putgb2: ERROR creating new GRIB2 field = ', ierr
95 print *,
'putgb2: No Section 1 info available. '
102 if (
associated(gfld%local) .AND. gfld%locallen .gt. 0)
then
103 call addlocal(cgrib, lcgrib, gfld%local, gfld%locallen, ierr)
104 if (ierr .ne. 0)
then
105 write(6, *)
'putgb2: ERROR adding local info = ', ierr
110 igds(1) = gfld%griddef
111 igds(2) = gfld%ngrdpts
112 igds(3) = gfld%numoct_opt
113 igds(4) = gfld%interp_opt
114 igds(5) = gfld%igdtnum
115 if (
associated(gfld%igdtmpl))
then
116 call addgrid(cgrib, lcgrib, igds, gfld%igdtmpl, gfld%igdtlen, &
117 ilistopt, gfld%num_opt, ierr)
118 if (ierr .ne. 0)
then
119 write(6, *)
'putgb2: ERROR adding grid info = ', ierr
122 print *,
'putgb2: No GDT info available. '
129 if (
associated(gfld%ipdtmpl) .AND. &
130 associated(gfld%idrtmpl) .AND. &
131 associated(gfld%fld))
then
132 call addfield(cgrib, lcgrib, gfld%ipdtnum, gfld%ipdtmpl, &
133 gfld%ipdtlen, coordlist, gfld%num_coord, &
134 gfld%idrtnum, gfld%idrtmpl, gfld%idrtlen, &
135 gfld%fld, gfld%ngrdpts, gfld%ibmap, gfld%bmap, &
137 if (ierr .ne. 0)
then
138 write(6, *)
'putgb2: ERROR adding data field = ', ierr
141 print *,
'putgb2: Missing some field info. '
148 call gribend(cgrib, lcgrib, lengrib, ierr)
149 call wryte(lugb, lengrib, cgrib)
subroutine addfield(cgrib, lcgrib, ipdsnum, ipdstmpl, ipdstmplen, coordlist, numcoord, idrsnum, idrstmpl, idrstmplen, fld, ngrdpts, ibmap, bmap, ierr)
Pack up Sections 4 through 7 for a given field and add them to a GRIB2 message.
subroutine addgrid(cgrib, lcgrib, igds, igdstmpl, igdstmplen, ideflist, idefnum, ierr)
Add a Grid Definition Section (Section 3) to a GRIB2 message.
subroutine addlocal(cgrib, lcgrib, csec2, lcsec2, ierr)
Add a Local Use Section (Section 2) to a GRIB2 message.
subroutine gribcreate(cgrib, lcgrib, listsec0, listsec1, ierr)
This subroutine initializes a new GRIB2 message and packs GRIB2 sections 0 (Indicator Section) and 1 ...
subroutine gribend(cgrib, lcgrib, lengrib, ierr)
Finalize a GRIB2 message after all grids and fields have been added.
This Fortran module contains the declaration of derived type gribfield.
subroutine putgb2(lugb, gfld, iret)
This subroutine packs a single field into a grib2 message and writes out that message to the file ass...