93 subroutine getfield(cgrib,lcgrib,ifldnum,igds,igdstmpl,igdslen,
94 & ideflist,idefnum,ipdsnum,ipdstmpl,ipdslen,
95 & coordlist,numcoord,ndpts,idrsnum,idrstmpl,
96 & idrslen,ibmap,bmap,fld,ierr)
98 character(len=1),
intent(in) :: cgrib(lcgrib)
99 integer,
intent(in) :: lcgrib,ifldnum
100 integer,
intent(out) :: igds(*),igdstmpl(*),ideflist(*)
101 integer,
intent(out) :: ipdsnum,ipdstmpl(*)
102 integer,
intent(out) :: idrsnum,idrstmpl(*)
103 integer,
intent(out) :: ndpts,ibmap,idefnum,numcoord
104 integer,
intent(out) :: ierr
105 logical*1,
intent(out) :: bmap(*)
106 real,
intent(out) :: fld(*),coordlist(*)
108 character(len=4),
parameter :: grib=
'GRIB',c7777=
'7777'
109 character(len=4) :: ctemp
110 integer:: listsec0(2)
111 integer iofst,ibeg,istart
113 logical have3,have4,have5,have6,have7
125 if (ifldnum.le.0)
then
126 print *,
'getfield: Request for field number must be positive.'
135 ctemp=cgrib(j)//cgrib(j+1)//cgrib(j+2)//cgrib(j+3)
136 if (ctemp.eq.grib )
then
141 if (istart.eq.0)
then
142 print *,
'getfield: Beginning characters GRIB not found.'
150 call g2_gbytec(cgrib,listsec0(1),iofst,8)
152 call g2_gbytec(cgrib,listsec0(2),iofst,8)
162 if (listsec0(2).ne.2)
then
163 print *,
'getfield: can only decode GRIB edition 2.'
174 ctemp=cgrib(ipos)//cgrib(ipos+1)//cgrib(ipos+2)//cgrib(ipos+3)
175 if (ctemp.eq.c7777 )
then
178 if (ipos.ne.(istart+lengrib))
then
179 print *,
'getfield: "7777" found, but not where expected.'
197 if (isecnum.eq.3)
then
199 call unpack3(cgrib,lcgrib,iofst,igds,igdstmpl,igdslen,
200 & ideflist,idefnum,jerr)
212 if (isecnum.eq.4)
then
214 if (numfld.eq.ifldnum)
then
216 call unpack4(cgrib,lcgrib,iofst,ipdsnum,ipdstmpl,ipdslen,
217 & coordlist,numcoord,jerr)
230 if ((isecnum.eq.5).and.(numfld.eq.ifldnum))
then
232 call unpack5(cgrib,lcgrib,iofst,ndpts,idrsnum,idrstmpl,
246 if (isecnum.eq.6)
then
248 call unpack6(cgrib,lcgrib,iofst,igds(2),ibmap,bmap,jerr)
260 if ((isecnum.eq.7).and.(numfld.eq.ifldnum))
then
261 if (idrsnum.eq.0)
then
262 call simunpack(cgrib(ipos+5),lensec-6,idrstmpl,ndpts,fld)
264 elseif (idrsnum.eq.2.or.idrsnum.eq.3)
then
265 call comunpack(cgrib(ipos+5),lensec-6,lensec,idrsnum,
266 & idrstmpl,ndpts,fld,ier)
267 if ( ier .ne. 0 )
then
272 elseif (idrsnum.eq.50)
then
273 call simunpack(cgrib(ipos+5),lensec-6,idrstmpl,ndpts-1,
276 call rdieee(ieee,fld(1),1)
278 elseif (idrsnum.eq.40 .OR. idrsnum.eq.40000)
then
279 call jpcunpack(cgrib(ipos+5),lensec-5,idrstmpl,ndpts,fld)
281 elseif (idrsnum.eq.41 .OR. idrsnum.eq.40010)
then
282 call pngunpack(cgrib(ipos+5),lensec-5,idrstmpl,ndpts,fld)
285 print *,
'getfield: Data Representation Template ',idrsnum,
286 &
' not yet implemented.'
296 if (ipos.gt.(istart+lengrib))
then
297 print *,
'getfield: "7777" not found at end of GRIB message.'
302 if (have3.and.have4.and.have5.and.have6.and.have7)
return
310 print *,
'getfield: GRIB message contained ',numlocal,
311 &
' different fields.'
312 print *,
'getfield: The request was for the ',ifldnum,
351 subroutine unpack3(cgrib,lcgrib,iofst,igds,igdstmpl,
352 & mapgridlen,ideflist,idefnum,ierr)
356 character(len=1),
intent(in) :: cgrib(lcgrib)
357 integer,
intent(in) :: lcgrib
358 integer,
intent(inout) :: iofst
359 integer,
intent(out) :: igds(*),igdstmpl(*),ideflist(*)
360 integer,
intent(out) :: ierr,idefnum
362 integer,
allocatable :: mapgrid(:)
363 integer :: mapgridlen,ibyttem
382 if (igds(1).eq.0)
then
384 allocate(mapgrid(lensec))
404 nbits=iabs(mapgrid(i))*8
405 if ( mapgrid(i).ge.0 )
then
406 call g2_gbytec(cgrib,igdstmpl(i),iofst,nbits)
409 call g2_gbytec(cgrib,igdstmpl(i),iofst+1,nbits-1)
410 if (isign.eq.1) igdstmpl(i)=-igdstmpl(i)
413 ibyttem=ibyttem+iabs(mapgrid(i))
425 do i=mapgridlen+1,newmapgridlen
426 nbits=iabs(mapgrid(i))*8
427 if ( mapgrid(i).ge.0 )
then
428 call g2_gbytec(cgrib,igdstmpl(i),iofst,nbits)
431 call g2_gbytec(cgrib,igdstmpl(i),iofst+1,nbits-1)
432 if (isign.eq.1) igdstmpl(i)=-igdstmpl(i)
435 ibyttem=ibyttem+iabs(mapgrid(i))
437 mapgridlen=newmapgridlen
444 if ( igds(3).ne.0 )
then
446 idefnum=(lensec-14-ibyttem)/igds(3)
447 call g2_gbytesc(cgrib,ideflist,iofst,nbits,0,idefnum)
448 iofst=iofst+(nbits*idefnum)
452 if(
allocated(mapgrid) )
deallocate(mapgrid)
480 subroutine unpack4(cgrib,lcgrib,iofst,ipdsnum,ipdstmpl,mappdslen,
481 & coordlist,numcoord,ierr)
485 character(len=1),
intent(in) :: cgrib(lcgrib)
486 integer,
intent(in) :: lcgrib
487 integer,
intent(inout) :: iofst
488 real,
intent(out) :: coordlist(*)
489 integer,
intent(out) :: ipdsnum,ipdstmpl(*)
490 integer,
intent(out) :: ierr,numcoord
492 real(4),
allocatable :: coordieee(:)
493 integer,
allocatable :: mappds(:)
502 allocate(mappds(lensec))
520 nbits=iabs(mappds(i))*8
521 if ( mappds(i).ge.0 )
then
522 call g2_gbytec(cgrib,ipdstmpl(i),iofst,nbits)
525 call g2_gbytec(cgrib,ipdstmpl(i),iofst+1,nbits-1)
526 if (isign.eq.1) ipdstmpl(i)=-ipdstmpl(i)
540 do i=mappdslen+1,newmappdslen
541 nbits=iabs(mappds(i))*8
542 if ( mappds(i).ge.0 )
then
543 call g2_gbytec(cgrib,ipdstmpl(i),iofst,nbits)
546 call g2_gbytec(cgrib,ipdstmpl(i),iofst+1,nbits-1)
547 if (isign.eq.1) ipdstmpl(i)=-ipdstmpl(i)
551 mappdslen=newmappdslen
557 if ( numcoord .ne. 0 )
then
558 allocate (coordieee(numcoord))
559 call g2_gbytesc(cgrib,coordieee,iofst,32,0,numcoord)
560 call rdieee(coordieee,coordlist,numcoord)
561 deallocate (coordieee)
562 iofst=iofst+(32*numcoord)
564 if(
allocated(mappds) )
deallocate(mappds)
588 subroutine unpack5(cgrib,lcgrib,iofst,ndpts,idrsnum,idrstmpl,
593 character(len=1),
intent(in) :: cgrib(lcgrib)
594 integer,
intent(in) :: lcgrib
595 integer,
intent(inout) :: iofst
596 integer,
intent(out) :: ndpts,idrsnum,idrstmpl(*)
597 integer,
intent(out) :: ierr
600 integer,
allocatable :: mapdrs(:)
609 allocate(mapdrs(lensec))
627 nbits=iabs(mapdrs(i))*8
628 if ( mapdrs(i).ge.0 )
then
629 call g2_gbytec(cgrib,idrstmpl(i),iofst,nbits)
632 call g2_gbytec(cgrib,idrstmpl(i),iofst+1,nbits-1)
633 if (isign.eq.1) idrstmpl(i)=-idrstmpl(i)
647 do i=mapdrslen+1,newmapdrslen
648 nbits=iabs(mapdrs(i))*8
649 if ( mapdrs(i).ge.0 )
then
650 call g2_gbytec(cgrib,idrstmpl(i),iofst,nbits)
653 call g2_gbytec(cgrib,idrstmpl(i),iofst+1,nbits-1)
654 if (isign.eq.1) idrstmpl(i)=-idrstmpl(i)
658 mapdrslen=newmapdrslen
660 if(
allocated(mapdrs) )
deallocate(mapdrs)
683 subroutine unpack6(cgrib,lcgrib,iofst,ngpts,ibmap,bmap,ierr)
685 character(len=1),
intent(in) :: cgrib(lcgrib)
686 integer,
intent(in) :: lcgrib,ngpts
687 integer,
intent(inout) :: iofst
688 integer,
intent(out) :: ibmap
689 integer,
intent(out) :: ierr
690 logical*1,
intent(out) :: bmap(ngpts)
692 integer :: intbmap(ngpts)
703 call g2_gbytesc(cgrib,intbmap,iofst,1,0,ngpts)
707 if (intbmap(j).eq.0) bmap(j)=.false.
709 elseif (ibmap.eq.254)
then
711 elseif (ibmap.eq.255)
then
714 print *,
'unpack6: Predefined bitmap ',ibmap,
' not recognized.'