37subroutine cnv22(ifl1,ifl2,ipack,usemiss,imiss,table_ver)
43 integer,
intent(in) :: ifl1,ifl2,ipack
44 logical,
intent(in) :: usemiss
46 CHARACTER(len=1),
pointer,
dimension(:) :: cgrib
47 CHARACTER(len=8) :: ctemp
49 integer,
dimension(200) :: jids,jpdt,jgdt
50 integer :: listsec0(2)=(/0,2/)
51 integer :: igds(5)=(/0,0,0,0,0/),previgds(5)
52 integer :: idrstmpl(200)
53 integer :: currlen=1000000
55 logical :: unpack=.true.
56 logical :: open_grb=.false.
62 gfld%list_opt => null()
63 gfld%igdtmpl => null()
64 gfld%ipdtmpl => null()
65 gfld%coord_list => null()
66 gfld%idrtmpl => null()
70 allocate(cgrib(currlen))
84 call getgb2(ifl1,ifli1,jskp,jdisc,jids,jpdtn,jpdt,jgdtn,jgdt, &
85 unpack,jskp,gfld,iret)
88 print *,
' getgb2 error = ',iret
96 if (gfld%ifldnum == 1)
then
99 npoints=npoints+gfld%ngrdpts
102 if (newlen.gt.currlen)
then
105 call realloc(cgrib,currlen,newlen,is)
112 if (gfld%ifldnum == 1)
then
114 call gribend(cgrib,lcgrib,lengrib,ierr)
116 write(6,*)
' ERROR ending new GRIB2 message = ',ierr
120 call wryte(ifl2,lengrib,cgrib)
125 listsec0(1)=gfld%discipline
126 listsec0(2)=gfld%version
127 gfld%idsect(3) = table_ver
128 call gribcreate(cgrib,lcgrib,listsec0,gfld%idsect,ierr)
130 write(6,*)
' ERROR creating new GRIB2 field = ',ierr
142 igds(3)=gfld%numoct_opt
143 igds(4)=gfld%interp_opt
145 if (.NOT.
associated(gfld%list_opt)) &
146 allocate(gfld%list_opt(1))
147 if (gfld%ifldnum == 1)
then
148 call addgrid(cgrib,lcgrib,igds,gfld%igdtmpl,gfld%igdtlen, &
149 gfld%list_opt,gfld%num_opt,ierr)
151 if (gfld%igdtlen.ne.prevfld%igdtlen .OR. &
152 gfld%num_opt.ne.prevfld%num_opt .OR. &
153 any(igds.ne.previgds) .OR. &
154 any(gfld%igdtmpl(1:gfld%igdtlen).NE. &
155 prevfld%igdtmpl(1:prevfld%igdtlen)) .OR. &
156 any(gfld%list_opt(1:gfld%num_opt).NE. &
157 prevfld%list_opt(1:prevfld%num_opt)))
then
158 call addgrid(cgrib,lcgrib,igds,gfld%igdtmpl,gfld%igdtlen, &
159 gfld%list_opt,gfld%num_opt,ierr)
163 write(6,*)
' ERROR adding GRIB2 grid = ',ierr
175 (ipack.eq.2 .OR. ipack.eq.31 .OR. ipack.eq.32))
then
176 if (gfld%ibmap.eq.0 .OR. gfld%ibmap.eq.254)
then
179 rmiss=minval(gfld%fld(1:gfld%ngrdpts))
180 if (rmiss .lt. -9999.0)
then
186 if (.NOT. gfld%bmap(i))
then
192 call mkieee(rmiss,idrstmpl(8),1)
193 elseif (gfld%idrtnum.EQ.2 .OR. gfld%idrtnum.EQ.3)
then
194 idrstmpl(7)=gfld%idrtmpl(7)
195 idrstmpl(8)=gfld%idrtmpl(8)
196 idrstmpl(9)=gfld%idrtmpl(9)
204 if ((.NOT. usemiss) .AND. &
205 (gfld%idrtnum.EQ.2 .OR. gfld%idrtnum.EQ.3) .AND. &
206 (gfld%idrtmpl(7).EQ.1 .OR. gfld%idrtmpl(7).EQ.2))
then
207 call rdieee(gfld%idrtmpl(8),rmissp,1)
208 if (gfld%idrtmpl(7) .EQ. 2)
then
209 call rdieee(gfld%idrtmpl(9),rmisss,1)
213 allocate(gfld%bmap(gfld%ngrdpts))
215 if (gfld%fld(j).EQ.rmissp .OR. &
216 gfld%fld(j).EQ.rmisss)
then
233 elseif (ipack.eq.2)
then
236 elseif (ipack.eq.31.OR.ipack.eq.32)
then
239 idrstmpl(17)=mod(ipack,10)
240 elseif (ipack.eq.40 .OR. ipack.eq.41 .OR. &
241 ipack.eq.40000 .OR. ipack.eq.40010)
then
251 if (ctemp.eq.
'A PCP ') idrsnum=2
253 idrstmpl(2)=gfld%idrtmpl(2)
254 idrstmpl(3)=gfld%idrtmpl(3)
255 if (.NOT.
associated(gfld%coord_list)) &
256 allocate(gfld%coord_list(1))
257 if (gfld%ibmap.ne.0 .AND. gfld%ibmap.ne.254)
then
258 if (.NOT.
associated(gfld%bmap))
allocate(gfld%bmap(1))
263 call addfield(cgrib,lcgrib,gfld%ipdtnum,gfld%ipdtmpl, &
264 gfld%ipdtlen,gfld%coord_list,gfld%num_coord, &
265 idrsnum,idrstmpl,200, &
266 gfld%fld,gfld%ngrdpts,gfld%ibmap,gfld%bmap,ierr)
268 write(6,*)
' ERROR adding GRIB2 field = ',ierr
275 call gribend(cgrib,lcgrib,lengrib,ierr)
277 write(6,*)
' ERROR ending new GRIB2 message = ',ierr
278 if (
associated(cgrib))
deallocate(cgrib)
284 call wryte(ifl2,lengrib,cgrib)
287 if (
associated(cgrib))
deallocate(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 field and add them to a GRIB2 message.
subroutine getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, unpack, k, gfld, iret)
This is a legacy version of getgb2i2().