📄 getfield.f
字号:
endif endif ! ! If found Section 7, check to see if this field is the ! one requested. ! if ((isecnum.eq.7).and.(numfld.eq.ifldnum)) then if (idrsnum.eq.0) then call simunpack(cgrib(ipos+5),lensec-6,idrstmpl,ndpts,fld) have7=.true. elseif (idrsnum.eq.2.or.idrsnum.eq.3) then call comunpack(cgrib(ipos+5),lensec-6,lensec,idrsnum, & idrstmpl,ndpts,fld,ier) if ( ier .ne. 0 ) then ierr=14 return endif have7=.true. elseif (idrsnum.eq.50) then call simunpack(cgrib(ipos+5),lensec-6,idrstmpl,ndpts-1, & fld(2)) ieee=idrstmpl(5) call rdieee(ieee,fld(1),1) have7=.true. else print *,'getfield: Data Representation Template ',idrsnum, & ' not yet implemented.' ierr=9 return endif endif ! ! Check to see if we read pass the end of the GRIB ! message and missed the terminator string '7777'. ! ipos=ipos+lensec ! Update beginning of section pointer if (ipos.gt.(istart+lengrib)) then print *,'getfield: "7777" not found at end of GRIB message.' ierr=7 return endif if (have3.and.have4.and.have5.and.have6.and.have7) return enddo!! If exited from above loop, the end of the GRIB message was reached! before the requested field was found.! print *,'getfield: GRIB message contained ',numlocal, & ' different fields.' print *,'getfield: The request was for the ',ifldnum, & ' field.' ierr=6 return end subroutine unpack3(cgrib,lcgrib,iofst,igds,igdstmpl, & mapgridlen,ideflist,idefnum,ierr)!$$$ SUBPROGRAM DOCUMENTATION BLOCK! . . . .! SUBPROGRAM: unpack3 ! PRGMMR: Gilbert ORG: W/NP11 DATE: 2000-05-26!! ABSTRACT: This subroutine unpacks Section 3 (Grid Definition Section)! starting at octet 6 of that Section. !! PROGRAM HISTORY LOG:! 2000-05-26 Gilbert!! USAGE: CALL unpack3(cgrib,lcgrib,lensec,iofst,igds,igdstmpl,! & mapgridlen,ideflist,idefnum,ierr)! INPUT ARGUMENT LIST:! cgrib - Character array that contains the GRIB2 message! lcgrib - Length (in bytes) of GRIB message array cgrib.! iofst - Bit offset of the beginning of Section 3.!! OUTPUT ARGUMENT LIST: ! iofst - Bit offset at the end of Section 3, returned.! igds - Contains information read from the appropriate GRIB Grid ! Definition Section 3 for the field being returned.! Must be dimensioned >= 5.! igds(1)=Source of grid definition (see Code Table 3.0)! igds(2)=Number of grid points in the defined grid.! igds(3)=Number of octets needed for each ! additional grid points definition. ! Used to define number of! points in each row ( or column ) for! non-regular grids. ! = 0, if using regular grid.! igds(4)=Interpretation of list for optional points ! definition. (Code Table 3.11)! igds(5)=Grid Definition Template Number (Code Table 3.1)! igdstmpl - Contains the data values for the specified Grid Definition! Template ( NN=igds(5) ). Each element of this integer ! array contains an entry (in the order specified) of Grid! Defintion Template 3.NN! mapgridlen- Number of elements in igdstmpl(). i.e. number of entries! in Grid Defintion Template 3.NN ( NN=igds(5) ).! ideflist - (Used if igds(3) .ne. 0) This array contains the! number of grid points contained in each row ( or column ).! (part of Section 3)! idefnum - (Used if igds(3) .ne. 0) The number of entries! in array ideflist. i.e. number of rows ( or columns )! for which optional grid points are defined.! ierr - Error return code.! 0 = no error! 5 = "GRIB" message contains an undefined Grid Definition! Template.!! REMARKS: Uses Fortran 90 module gridtemplates.!! ATTRIBUTES:! LANGUAGE: Fortran 90! MACHINE: IBM SP!!$$$ use gridtemplates character(len=1),intent(in) :: cgrib(lcgrib) integer,intent(in) :: lcgrib integer,intent(inout) :: iofst integer,intent(out) :: igds(*),igdstmpl(*),ideflist(*) integer,intent(out) :: ierr,idefnum integer,allocatable :: mapgrid(:) integer :: mapgridlen,ibyttem logical needext ierr=0 call gbyte(cgrib,lensec,iofst,32) ! Get Length of Section iofst=iofst+32 iofst=iofst+8 ! skip section number call gbyte(cgrib,igds(1),iofst,8) ! Get source of Grid def. iofst=iofst+8 call gbyte(cgrib,igds(2),iofst,32) ! Get number of grid pts. iofst=iofst+32 call gbyte(cgrib,igds(3),iofst,8) ! Get num octets for opt. list iofst=iofst+8 call gbyte(cgrib,igds(4),iofst,8) ! Get interpret. for opt. list iofst=iofst+8 call gbyte(cgrib,igds(5),iofst,16) ! Get Grid Def Template num. iofst=iofst+16 if (igds(1).eq.0) then! if (igds(1).eq.0.OR.igds(1).eq.255) then ! FOR ECMWF TEST ONLY allocate(mapgrid(lensec)) ! Get Grid Definition Template call getgridtemplate(igds(5),mapgridlen,mapgrid,needext, & iret) if (iret.ne.0) then ierr=5 return endif else! igdstmpl=-1 mapgridlen=0 needext=.false. endif ! ! Unpack each value into array igdstmpl from the ! the appropriate number of octets, which are specified in ! corresponding entries in array mapgrid. ! ibyttem=0 do i=1,mapgridlen nbits=iabs(mapgrid(i))*8 if ( mapgrid(i).ge.0 ) then call gbyte(cgrib,igdstmpl(i),iofst,nbits) else call gbyte(cgrib,isign,iofst,1) call gbyte(cgrib,igdstmpl(i),iofst+1,nbits-1) if (isign.eq.1) igdstmpl(i)=-igdstmpl(i) endif iofst=iofst+nbits ibyttem=ibyttem+iabs(mapgrid(i)) enddo ! ! Check to see if the Grid Definition Template needs to be ! extended. ! The number of values in a specific template may vary ! depending on data specified in the "static" part of the ! template. ! if ( needext ) then call extgridtemplate(igds(5),igdstmpl,newmapgridlen,mapgrid) ! Unpack the rest of the Grid Definition Template do i=mapgridlen+1,newmapgridlen nbits=iabs(mapgrid(i))*8 if ( mapgrid(i).ge.0 ) then call gbyte(cgrib,igdstmpl(i),iofst,nbits) else call gbyte(cgrib,isign,iofst,1) call gbyte(cgrib,igdstmpl(i),iofst+1,nbits-1) if (isign.eq.1) igdstmpl(i)=-igdstmpl(i) endif iofst=iofst+nbits ibyttem=ibyttem+iabs(mapgrid(i)) enddo mapgridlen=newmapgridlen endif ! ! Unpack optional list of numbers defining number of points ! in each row or column, if included. This is used for non regular ! grids. ! if ( igds(3).ne.0 ) then nbits=igds(3)*8 idefnum=(lensec-14-ibyttem)/igds(3) call gbytes(cgrib,ideflist,iofst,nbits,0,idefnum) iofst=iofst+(nbits*idefnum) else idefnum=0 endif if( allocated(mapgrid) ) deallocate(mapgrid) return ! End of Section 3 processing end subroutine unpack4(cgrib,lcgrib,iofst,ipdsnum,ipdstmpl,mappdslen, & coordlist,numcoord,ierr)!$$$ SUBPROGRAM DOCUMENTATION BLOCK! . . . .! SUBPROGRAM: unpack4 ! PRGMMR: Gilbert ORG: W/NP11 DATE: 2000-05-26!! ABSTRACT: This subroutine unpacks Section 4 (Product Definition Section)! starting at octet 6 of that Section. !! PROGRAM HISTORY LOG:! 2000-05-26 Gilbert!! USAGE: CALL unpack4(cgrib,lcgrib,iofst,ipdsnum,ipdstmpl,mappdslen,! & coordlist,numcoord,ierr)! INPUT ARGUMENT LIST:! cgrib - Character array that contains the GRIB2 message! lcgrib - Length (in bytes) of GRIB message array cgrib.! iofst - Bit offset of the beginning of Section 4.!! OUTPUT ARGUMENT LIST: ! iofst - Bit offset of the end of Section 4, returned.! ipdsnum - Product Definition Template Number ( see Code Table 4.0)! ipdstmpl - Contains the data values for the specified Product Definition! Template ( N=ipdsnum ). Each element of this integer! array contains an entry (in the order specified) of Product! Defintion Template 4.N! mappdslen- Number of elements in ipdstmpl(). i.e. number of entries! in Product Defintion Template 4.N ( N=ipdsnum ).! coordlist- Array containg floating point values intended to document! the vertical discretisation associated to model data! on hybrid coordinate vertical levels. (part of Section 4)! numcoord - number of values in array coordlist.! ierr - Error return code.! 0 = no error! 5 = "GRIB" message contains an undefined Product Definition! Template.!! REMARKS: Uses Fortran 90 module pdstemplates.!! ATTRIBUTES:! LANGUAGE: Fortran 90! MACHINE: IBM SP!!$$$ use pdstemplates character(len=1),intent(in) :: cgrib(lcgrib) integer,intent(in) :: lcgrib integer,intent(inout) :: iofst
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -