192 subroutine gf_getfld(cgrib,lcgrib,ifldnum,unpack,expand,gfld,ierr)
196 character(len=1),
intent(in) :: cgrib(lcgrib)
197 integer,
intent(in) :: lcgrib,ifldnum
198 logical,
intent(in) :: unpack,expand
200 integer,
intent(out) :: ierr
208 character(len=4),
parameter :: grib=
'GRIB',c7777=
'7777'
209 character(len=4) :: ctemp
210 real,
pointer,
dimension(:) :: newfld
211 integer:: listsec0(2),igds(5)
212 integer iofst,ibeg,istart
214 logical*1,
pointer,
dimension(:) :: bmpsave
215 logical have3,have4,have5,have6,have7
218 subroutine gf_unpack1(cgrib,lcgrib,iofst,ids,idslen,ierr)
219 character(len=1),
intent(in) :: cgrib(lcgrib)
220 integer,
intent(in) :: lcgrib
221 integer,
intent(inout) :: iofst
222 integer,
pointer,
dimension(:) :: ids
223 integer,
intent(out) :: ierr,idslen
225 subroutine gf_unpack2(cgrib,lcgrib,iofst,lencsec2,csec2,ierr)
226 character(len=1),
intent(in) :: cgrib(lcgrib)
227 integer,
intent(in) :: lcgrib
228 integer,
intent(inout) :: iofst
229 integer,
intent(out) :: lencsec2
230 integer,
intent(out) :: ierr
231 character(len=1),
pointer,
dimension(:) :: csec2
233 subroutine gf_unpack3(cgrib,lcgrib,iofst,igds,igdstmpl,
234 & mapgridlen,ideflist,idefnum,ierr)
235 character(len=1),
intent(in) :: cgrib(lcgrib)
236 integer,
intent(in) :: lcgrib
237 integer,
intent(inout) :: iofst
238 integer,
pointer,
dimension(:) :: igdstmpl,ideflist
239 integer,
intent(out) :: igds(5)
240 integer,
intent(out) :: ierr,idefnum
242 subroutine gf_unpack4(cgrib,lcgrib,iofst,ipdsnum,ipdstmpl,
243 & mappdslen,coordlist,numcoord,ierr)
244 character(len=1),
intent(in) :: cgrib(lcgrib)
245 integer,
intent(in) :: lcgrib
246 integer,
intent(inout) :: iofst
247 real,
pointer,
dimension(:) :: coordlist
248 integer,
pointer,
dimension(:) :: ipdstmpl
249 integer,
intent(out) :: ipdsnum
250 integer,
intent(out) :: ierr,numcoord
252 subroutine gf_unpack5(cgrib,lcgrib,iofst,ndpts,idrsnum,
253 & idrstmpl,mapdrslen,ierr)
254 character(len=1),
intent(in) :: cgrib(lcgrib)
255 integer,
intent(in) :: lcgrib
256 integer,
intent(inout) :: iofst
257 integer,
intent(out) :: ndpts,idrsnum
258 integer,
pointer,
dimension(:) :: idrstmpl
259 integer,
intent(out) :: ierr
261 subroutine gf_unpack6(cgrib,lcgrib,iofst,ngpts,ibmap,bmap,ierr)
262 character(len=1),
intent(in) :: cgrib(lcgrib)
263 integer,
intent(in) :: lcgrib,ngpts
264 integer,
intent(inout) :: iofst
265 integer,
intent(out) :: ibmap
266 integer,
intent(out) :: ierr
267 logical*1,
pointer,
dimension(:) :: bmap
269 subroutine gf_unpack7(cgrib,lcgrib,iofst,igdsnum,igdstmpl,
270 & idrsnum,idrstmpl,ndpts,fld,ierr)
271 character(len=1),
intent(in) :: cgrib(lcgrib)
272 integer,
intent(in) :: lcgrib,ndpts,idrsnum,igdsnum
273 integer,
intent(inout) :: iofst
274 integer,
pointer,
dimension(:) :: idrstmpl,igdstmpl
275 integer,
intent(out) :: ierr
276 real,
pointer,
dimension(:) :: fld
288 nullify(gfld%list_opt,gfld%igdtmpl,gfld%ipdtmpl)
289 nullify(gfld%coord_list,gfld%idrtmpl,gfld%bmap,gfld%fld)
293 if (ifldnum.le.0)
then
294 print *,
'gf_getfld: Request for field number must be positive.'
303 ctemp=cgrib(j)//cgrib(j+1)//cgrib(j+2)//cgrib(j+3)
304 if (ctemp.eq.grib )
then
309 if (istart.eq.0)
then
310 print *,
'gf_getfld: Beginning characters GRIB not found.'
318 call g2_gbytec(cgrib,listsec0(1),iofst,8)
320 call g2_gbytec(cgrib,listsec0(2),iofst,8)
330 if (listsec0(2).ne.2)
then
331 print *,
'gf_getfld: can only decode GRIB edition 2.'
342 ctemp=cgrib(ipos)//cgrib(ipos+1)//cgrib(ipos+2)//cgrib(ipos+3)
343 if (ctemp.eq.c7777 )
then
346 if (ipos.ne.(istart+lengrib))
then
347 print *,
'gf_getfld: "7777" found, but not where expected.'
363 if ( (isecnum.lt.1).OR.(isecnum.gt.7) )
then
364 print *,
'gf_getfld: Unrecognized Section Encountered=',isecnum
371 if (isecnum.eq.1)
then
373 call gf_unpack1(cgrib,lcgrib,iofst,gfld%idsect,
374 & gfld%idsectlen,jerr)
384 if (isecnum.eq.2)
then
386 if (
associated(gfld%local))
deallocate(gfld%local)
387 call gf_unpack2(cgrib,lcgrib,iofst,gfld%locallen,
399 if (isecnum.eq.3)
then
401 if (
associated(gfld%igdtmpl))
deallocate(gfld%igdtmpl)
402 if (
associated(gfld%list_opt))
deallocate(gfld%list_opt)
403 call gf_unpack3(cgrib,lcgrib,iofst,igds,gfld%igdtmpl,
404 & gfld%igdtlen,gfld%list_opt,gfld%num_opt,jerr)
409 gfld%numoct_opt=igds(3)
410 gfld%interp_opt=igds(4)
421 if (isecnum.eq.4)
then
423 if (numfld.eq.ifldnum)
then
424 gfld%discipline=listsec0(1)
425 gfld%version=listsec0(2)
428 gfld%expanded=.false.
430 call gf_unpack4(cgrib,lcgrib,iofst,gfld%ipdtnum,
431 & gfld%ipdtmpl,gfld%ipdtlen,gfld%coord_list,
432 & gfld%num_coord,jerr)
445 if ((isecnum.eq.5).and.(numfld.eq.ifldnum))
then
447 call gf_unpack5(cgrib,lcgrib,iofst,gfld%ndpts,gfld%idrtnum,
448 & gfld%idrtmpl,gfld%idrtlen,jerr)
461 if (isecnum.eq.6)
then
465 call gf_unpack6(cgrib,lcgrib,iofst,gfld%ngrdpts,gfld%ibmap,
469 if (gfld%ibmap .eq. 254)
then
470 if (
associated(bmpsave) )
then
473 print *,
'gf_getfld: Previous bit-map specified,',
474 &
' but none exists,'
479 if (
associated(bmpsave) )
deallocate(bmpsave)
494 if ((isecnum.eq.7).and.(numfld.eq.ifldnum).and.unpack)
then
496 call gf_unpack7(cgrib,lcgrib,iofst,gfld%igdtnum,
497 & gfld%igdtmpl,gfld%idrtnum,
498 & gfld%idrtmpl,gfld%ndpts,
504 if ( gfld%ibmap .ne. 255 .AND.
associated(gfld%bmap) )
then
506 allocate(newfld(gfld%ngrdpts))
511 if ( gfld%bmap(j) )
then
512 newfld(j)=gfld%fld(n)
518 deallocate(gfld%fld);
522 gfld%expanded=.false.
528 print *,
'gf_getfld: return from gf_unpack7 = ',jerr
538 if (ipos.gt.(istart+lengrib))
then
539 print *,
'gf_getfld: "7777" not found at end of GRIB message.'
547 if (unpack.and.have3.and.have4.and.have5.and.have6.and.have7)
553 if ((.NOT.unpack).and.have3.and.have4.and.have5.and.have6)
562 print *,
'gf_getfld: GRIB message contained ',numlocal,
563 &
' different fields.'
564 print *,
'gf_getfld: The request was for the ',ifldnum,