From bc44bd572f218643fac58cc15663f5d49f464c37 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Mon, 20 May 2024 09:42:44 -0600 Subject: [PATCH 1/6] cleanup of some code --- src/g2create.F90 | 335 ++++++++++++++++++++++++----------------------- 1 file changed, 168 insertions(+), 167 deletions(-) diff --git a/src/g2create.F90 b/src/g2create.F90 index bcba805b..153a1d45 100644 --- a/src/g2create.F90 +++ b/src/g2create.F90 @@ -180,38 +180,38 @@ end subroutine gribcreate !> - 10 Error packing data field. !> !> @author Stephen Gilbert @date 2000-05-02 -subroutine addfield(cgrib,lcgrib,ipdsnum,ipdstmpl,ipdstmplen, & - coordlist,numcoord,idrsnum,idrstmpl, & - idrstmplen,fld,ngrdpts,ibmap,bmap,ierr) +subroutine addfield(cgrib, lcgrib, ipdsnum, ipdstmpl, ipdstmplen, & + coordlist, numcoord, idrsnum, idrstmpl, & + idrstmplen, fld, ngrdpts, ibmap, bmap, ierr) use pdstemplates use drstemplates implicit none logical :: match - character(len=1),intent(inout) :: cgrib(lcgrib) - integer,intent(in) :: ipdsnum,ipdstmpl(*) - integer,intent(in) :: idrsnum,numcoord,ipdstmplen,idrstmplen - integer,intent(in) :: lcgrib,ngrdpts,ibmap - real,intent(in) :: coordlist(numcoord) + character(len=1), intent(inout) :: cgrib(lcgrib) + integer, intent(in) :: ipdsnum, ipdstmpl(*) + integer, intent(in) :: idrsnum, numcoord, ipdstmplen, idrstmplen + integer, intent(in) :: lcgrib, ngrdpts, ibmap + real, intent(in) :: coordlist(numcoord) real(kind = 4) :: coordlist_4(numcoord) - real,target,intent(in) :: fld(ngrdpts) - integer,intent(out) :: ierr - integer,intent(inout) :: idrstmpl(*) - logical*1,intent(in) :: bmap(ngrdpts) + real, target, intent(in) :: fld(ngrdpts) + integer, intent(out) :: ierr + integer, intent(inout) :: idrstmpl(*) + logical*1, intent(in) :: bmap(ngrdpts) - character(len=4),parameter :: grib='GRIB',c7777='7777' + character(len=4), parameter :: grib='GRIB', c7777='7777' character(len=4):: ctemp - character(len=1),allocatable :: cpack(:) - real,pointer,dimension(:) :: pfld + character(len=1), allocatable :: cpack(:) + real, pointer, dimension(:) :: pfld real(4) :: coordieee(numcoord), re00, tmpre00(1) - integer(4) :: ire00,allones - integer :: mappds(ipdstmplen),intbmap(ngrdpts),mapdrs(idrstmplen) - integer,parameter :: zero=0,one=1,four=4,five=5,six=6,seven=7 - integer,parameter :: minsize=50000 - integer iofst,ibeg,lencurr,len,mappdslen,mapdrslen,lpos3 - integer width,height,ndpts - integer lensec3,lensec4,lensec5,lensec6,lensec7 - logical issec3,needext,isprevbmap + integer(4) :: ire00, allones + integer :: mappds(ipdstmplen), intbmap(ngrdpts), mapdrs(idrstmplen) + integer, parameter :: zero=0, one=1, four=4, five=5, six=6, seven=7 + integer, parameter :: minsize=50000 + integer iofst, ibeg, lencurr, len, mappdslen, mapdrslen, lpos3 + integer width, height, ndpts + integer lensec3, lensec4, lensec5, lensec6, lensec7 + logical issec3, needext, isprevbmap integer :: nbits, newlen, nsize, lcpack, left integer :: ibmprev, ilen, ioctet, iscan, isecnum, itemp integer :: i, jj, kk, mm @@ -219,106 +219,106 @@ subroutine addfield(cgrib,lcgrib,ipdsnum,ipdstmpl,ipdstmplen, & real (kind = 4) :: tmpfld(1) allones = int(Z'FFFFFFFF') - ierr=0 + ierr = 0 - ! Check to see if beginning of GRIB message exists - match=.true. - do i=1,4 - if(cgrib(i) /= grib(i:i)) then - match=.false. + ! Check to see if beginning of GRIB message exists. + match = .true. + do i = 1, 4 + if (cgrib(i) /= grib(i:i)) then + match = .false. endif enddo if (.not. match) then - print *,'addfield: GRIB not found in given message.' - print *,'addfield: Call to routine gribcreate required to initialize GRIB messge.' - ierr=1 + print *, 'addfield: GRIB not found in given message.' + print *, 'addfield: Call to routine gribcreate required to initialize GRIB messge.' + ierr = 1 return endif - ! Get current length of GRIB message - call g2_gbytec(cgrib,lencurr,96,32) + ! Get current length of GRIB message. + call g2_gbytec1(cgrib, lencurr, 96, 32) - ! Check to see if GRIB message is already complete - ctemp=cgrib(lencurr-3)//cgrib(lencurr-2)//cgrib(lencurr-1) //cgrib(lencurr) - if (ctemp.eq.c7777) then - print *,'addfield: GRIB message already complete. Cannot add new section.' - ierr=2 + ! Check to see if GRIB message is already complete. + ctemp = cgrib(lencurr-3) // cgrib(lencurr - 2) // cgrib(lencurr - 1) // cgrib(lencurr) + if (ctemp .eq. c7777) then + print *, 'addfield: GRIB message already complete. Cannot add new section.' + ierr = 2 return endif - ! Loop through all current sections of the GRIB message to - ! find the last section number. - issec3=.false. - isprevbmap=.false. - len=16 ! length of Section 0 + ! Loop through all current sections of the GRIB message to find the + ! last section number. + issec3 = .false. + isprevbmap = .false. + len = 16 ! length of Section 0 do ! Get number and length of next section - iofst=len*8 - call g2_gbytec(cgrib,ilen,iofst,32) - iofst=iofst+32 - call g2_gbytec(cgrib,isecnum,iofst,8) - iofst=iofst+8 + iofst = len * 8 + call g2_gbytec(cgrib, ilen, iofst, 32) + iofst = iofst + 32 + call g2_gbytec(cgrib, isecnum, iofst, 8) + iofst = iofst + 8 ! Check if previous Section 3 exists and save location of ! the section 3 in case needed later. - if (isecnum.eq.3) then - issec3=.true. - lpos3=len+1 - lensec3=ilen + if (isecnum .eq. 3) then + issec3 = .true. + lpos3 = len + 1 + lensec3 = ilen endif ! Check if a previous defined bitmap exists - if (isecnum.eq.6) then - call g2_gbytec(cgrib,ibmprev,iofst,8) - iofst=iofst+8 - if ((ibmprev.ge.0).and.(ibmprev.le.253)) isprevbmap=.true. + if (isecnum .eq. 6) then + call g2_gbytec(cgrib, ibmprev, iofst, 8) + iofst = iofst + 8 + if ((ibmprev .ge. 0) .and. (ibmprev .le. 253)) isprevbmap = .true. endif - len=len+ilen + len = len + ilen ! Exit loop if last section reached - if (len.eq.lencurr) exit + if (len .eq. lencurr) exit ! If byte count for each section does not match current ! total length, then there is a problem. - if (len.gt.lencurr) then - print *,'addfield: Section byte counts don''t add to total.' - print *,'addfield: Sum of section byte counts = ',len - print *,'addfield: Total byte count in Section 0 = ',lencurr - ierr=3 + if (len .gt. lencurr) then + print *, 'addfield: Section byte counts don''t add to total.' + print *, 'addfield: Sum of section byte counts = ', len + print *, 'addfield: Total byte count in Section 0 = ', lencurr + ierr = 3 return endif enddo - ! Sections 4 through 7 can only be added after section 3 or 7. - if ((isecnum.ne.3) .and. (isecnum.ne.7)) then - print *,'addfield: Sections 4-7 can only be added after', & + ! Sections 4 through 7 can only be added after section 3 or 7. + if ((isecnum .ne. 3) .and. (isecnum .ne. 7)) then + print *, 'addfield: Sections 4-7 can only be added after', & ' Section 3 or 7.' - print *,'addfield: Section ',isecnum,' was the last found in', & + print *, 'addfield: Section ', isecnum, ' was the last found in', & ' given GRIB message.' - ierr=4 + ierr = 4 return - ! Sections 4 through 7 can only be added if section 3 was previously defined. - elseif (.not.issec3) then - print *,'addfield: Sections 4-7 can only be added if Section', & + ! Sections 4 through 7 can only be added if section 3 was previously defined. + elseif (.not. issec3) then + print *, 'addfield: Sections 4-7 can only be added if Section', & ' 3 was previously included.' - print *,'addfield: Section 3 was not found in given GRIB message.' - print *,'addfield: Call to routine addgrid required', & + print *, 'addfield: Section 3 was not found in given GRIB message.' + print *, 'addfield: Call to routine addgrid required', & ' to specify Grid definition.' - ierr=6 + ierr = 6 return endif - ! Add Section 4 - Product Definition Section - ibeg=lencurr*8 ! Calculate offset for beginning of section 4 - iofst=ibeg+32 ! leave space for length of section - call g2_sbytec(cgrib,four,iofst,8) ! Store section number (4) - iofst=iofst+8 - call g2_sbytec(cgrib,numcoord,iofst,16) ! Store num of coordinate values - iofst=iofst+16 - call g2_sbytec(cgrib,ipdsnum,iofst,16) ! Store Prod Def Template num. - iofst=iofst+16 - - ! Get Product Definition Template - call getpdstemplate(ipdsnum,mappdslen,mappds,needext,iret) - if (iret.ne.0) then - ierr=5 + ! Add Section 4 - Product Definition Section. + ibeg = lencurr * 8 ! Calculate offset for beginning of section 4 + iofst = ibeg + 32 ! leave space for length of section + call g2_sbytec(cgrib, four, iofst, 8) ! Store section number (4) + iofst = iofst+8 + call g2_sbytec(cgrib, numcoord, iofst, 16) ! Store num of coordinate values + iofst = iofst+16 + call g2_sbytec(cgrib, ipdsnum, iofst, 16) ! Store Prod Def Template num. + iofst = iofst+16 + + ! Get Product Definition Template. + call getpdstemplate(ipdsnum, mappdslen, mappds, needext, iret) + if (iret .ne. 0) then + ierr = 5 return endif @@ -327,21 +327,21 @@ subroutine addfield(cgrib,lcgrib,ipdsnum,ipdstmpl,ipdstmplen, & ! depending on data specified in the "static" part of the ! template. if (needext) then - call extpdstemplate(ipdsnum,ipdstmpl,mappdslen,mappds) + call extpdstemplate(ipdsnum, ipdstmpl, mappdslen, mappds) endif ! Pack up each input value in array ipdstmpl into the ! the appropriate number of octets, which are specified in ! corresponding entries in array mappds. - do i=1,mappdslen - nbits=iabs(mappds(i))*8 - if ((mappds(i).ge.0).or.(ipdstmpl(i).ge.0)) then - call g2_sbytec(cgrib,ipdstmpl(i),iofst,nbits) + do i = 1, mappdslen + nbits = iabs(mappds(i)) * 8 + if ((mappds(i) .ge. 0).or.(ipdstmpl(i) .ge. 0)) then + call g2_sbytec(cgrib, ipdstmpl(i), iofst, nbits) else - call g2_sbytec(cgrib,one,iofst,1) - call g2_sbytec(cgrib,iabs(ipdstmpl(i)),iofst+1,nbits-1) + call g2_sbytec(cgrib, one, iofst, 1) + call g2_sbytec(cgrib, iabs(ipdstmpl(i)), iofst + 1, nbits - 1) endif - iofst=iofst+nbits + iofst = iofst+nbits enddo ! Add Optional list of vertical coordinate values @@ -357,73 +357,73 @@ subroutine addfield(cgrib,lcgrib,ipdsnum,ipdstmpl,ipdstmplen, & ! Calculate length of section 4 and store it in octets ! 1-4 of section 4. - lensec4=(iofst-ibeg)/8 - call g2_sbytec(cgrib,lensec4,ibeg,32) + lensec4 = (iofst-ibeg)/8 + call g2_sbytec1(cgrib, lensec4, ibeg, 32) ! Pack Data using appropriate algorithm ! Get Data Representation Template - call getdrstemplate(idrsnum,mapdrslen,mapdrs,needext,iret) - if (iret.ne.0) then - ierr=5 + call getdrstemplate(idrsnum, mapdrslen, mapdrs, needext, iret) + if (iret .ne. 0) then + ierr = 5 return endif ! contract data field, removing data at invalid grid points, ! if bit-map is provided with field. - if (ibmap.eq.0 .OR. ibmap.eq.254) then - allocate(pfld(max(2,ngrdpts))) - ndpts=0; - do jj=1,ngrdpts - intbmap(jj)=0 + if (ibmap .eq. 0 .OR. ibmap .eq. 254) then + allocate(pfld(max(2, ngrdpts))) + ndpts = 0; + do jj = 1, ngrdpts + intbmap(jj) = 0 if (bmap(jj)) then - intbmap(jj)=1 - ndpts=ndpts+1 - pfld(ndpts)=fld(jj); + intbmap(jj) = 1 + ndpts = ndpts + 1 + pfld(ndpts) = fld(jj); endif enddo - if(ndpts==0 .and. ngrdpts>0) then - pfld(1)=0 + if (ndpts == 0 .and. ngrdpts > 0) then + pfld(1) = 0 endif else - ndpts=ngrdpts; + ndpts = ngrdpts; pfld=>fld; endif - lcpack=0 - nsize=ndpts*4 - if (nsize .lt. minsize) nsize=minsize - allocate(cpack(nsize),stat=istat) + lcpack = 0 + nsize = ndpts*4 + if (nsize .lt. minsize) nsize = minsize + allocate(cpack(nsize), stat = istat) if (idrsnum.eq.0) then ! Simple Packing - call simpack(pfld,ndpts,idrstmpl,cpack,lcpack) + call simpack(pfld, ndpts, idrstmpl, cpack, lcpack) elseif (idrsnum.eq.2.or.idrsnum.eq.3) then ! Complex Packing - call cmplxpack(pfld,ndpts,idrsnum,idrstmpl,cpack,lcpack) + call cmplxpack(pfld, ndpts, idrsnum, idrstmpl, cpack, lcpack) elseif (idrsnum.eq.50) then ! Sperical Harmonic Simple Packing - call simpack(pfld(2),ndpts-1,idrstmpl,cpack,lcpack) + call simpack(pfld(2), ndpts-1, idrstmpl, cpack, lcpack) tmpfld(1) = real(pfld(1), 4) call mkieee(tmpfld, tmpre00, 1) ! ensure RE(0,0) value is IEEE format re00 = tmpre00(1) ire00 = transfer(re00, ire00) idrstmpl(5) = ire00 elseif (idrsnum.eq.51) then ! Sperical Harmonic Complex Packing - call getpoly(cgrib(lpos3),lensec3,jj,kk,mm) + call getpoly(cgrib(lpos3), lensec3, jj, kk, mm) if (jj.ne.0 .AND. kk.ne.0 .AND. mm.ne.0) then - call specpack(pfld,ndpts,jj,kk,mm,idrstmpl,cpack,lcpack) + call specpack(pfld, ndpts, jj, kk, mm, idrstmpl, cpack, lcpack) else - print *,'addfield: Cannot pack DRT 5.51.' + print *, 'addfield: Cannot pack DRT 5.51.' ierr=9 return endif elseif (idrsnum.eq.40 .OR. idrsnum.eq.40000) then ! JPEG2000 encoding if (ibmap.eq.255) then - call getdim(cgrib(lpos3),lensec3,width,height,iscan) + call getdim(cgrib(lpos3), lensec3, width, height, iscan) if (width.eq.0 .OR. height.eq.0) then width=ndpts height=1 elseif (width.eq.allones .OR. height.eq.allones) then width=ndpts height=1 - elseif (ibits(iscan,5,1) .eq. 1) then ! Scanning mode: bit 3 + elseif (ibits(iscan, 5, 1) .eq. 1) then ! Scanning mode: bit 3 itemp=width width=height height=itemp @@ -432,27 +432,27 @@ subroutine addfield(cgrib,lcgrib,ipdsnum,ipdstmpl,ipdstmplen, & width=ndpts height=1 endif - if(width<1 .or. height<1) then + if (width<1 .or. height<1) then ! Special case: bitmask off everywhere. - write(0,*) 'Warning: bitmask off everywhere.' - write(0,*) ' Pretend one point in jpcpack to avoid crash.' + write(0, *) 'Warning: bitmask off everywhere.' + write(0, *) ' Pretend one point in jpcpack to avoid crash.' width=1 height=1 endif lcpack=nsize - !print *,'w,h=',width,height - call jpcpack(pfld,width,height,idrstmpl,cpack,lcpack) + !print *, 'w, h=', width, height + call jpcpack(pfld, width, height, idrstmpl, cpack, lcpack) elseif (idrsnum.eq.41 .OR. idrsnum.eq.40010) then ! PNG encoding if (ibmap.eq.255) then - call getdim(cgrib(lpos3),lensec3,width,height,iscan) + call getdim(cgrib(lpos3), lensec3, width, height, iscan) if (width.eq.0 .OR. height.eq.0) then width=ndpts height=1 elseif (width.eq.allones .OR. height.eq.allones) then width=ndpts height=1 - elseif (ibits(iscan,5,1) .eq. 1) then ! Scanning mode: bit 3 + elseif (ibits(iscan, 5, 1) .eq. 1) then ! Scanning mode: bit 3 itemp=width width=height height=itemp @@ -461,11 +461,11 @@ subroutine addfield(cgrib,lcgrib,ipdsnum,ipdstmpl,ipdstmplen, & width=ndpts height=1 endif - !print *,'png size ',width,height - call pngpack(pfld,width,height,idrstmpl,cpack,lcpack) - !print *,'png packed' + !print *, 'png size ', width, height + call pngpack(pfld, width, height, idrstmpl, cpack, lcpack) + !print *, 'png packed' else - print *,'addfield: Data Representation Template 5.',idrsnum, & + print *, 'addfield: Data Representation Template 5.', idrsnum, & ' not yet implemented.' ierr=7 return @@ -474,7 +474,7 @@ subroutine addfield(cgrib,lcgrib,ipdsnum,ipdstmpl,ipdstmplen, & deallocate(pfld) endif if (lcpack .lt. 0) then - if(allocated(cpack))deallocate(cpack) + if (allocated(cpack))deallocate(cpack) ierr=10 return endif @@ -482,23 +482,23 @@ subroutine addfield(cgrib,lcgrib,ipdsnum,ipdstmpl,ipdstmplen, & ! Add Section 5 - Data Representation Section ibeg=iofst ! Calculate offset for beginning of section 5 iofst=ibeg+32 ! leave space for length of section - call g2_sbytec(cgrib,five,iofst,8) ! Store section number (5) + call g2_sbytec(cgrib, five, iofst, 8) ! Store section number (5) iofst=iofst+8 - call g2_sbytec(cgrib,ndpts,iofst,32) ! Store num of actual data points + call g2_sbytec(cgrib, ndpts, iofst, 32) ! Store num of actual data points iofst=iofst+32 - call g2_sbytec(cgrib,idrsnum,iofst,16) ! Store Data Repr. Template num. + call g2_sbytec(cgrib, idrsnum, iofst, 16) ! Store Data Repr. Template num. iofst=iofst+16 ! Pack up each input value in array idrstmpl into the ! the appropriate number of octets, which are specified in ! corresponding entries in array mapdrs. - do i=1,mapdrslen + do i=1, mapdrslen nbits=iabs(mapdrs(i))*8 if ((mapdrs(i).ge.0).or.(idrstmpl(i).ge.0)) then - call g2_sbytec(cgrib,idrstmpl(i),iofst,nbits) + call g2_sbytec(cgrib, idrstmpl(i), iofst, nbits) else - call g2_sbytec(cgrib,one,iofst,1) - call g2_sbytec(cgrib,iabs(idrstmpl(i)),iofst+1,nbits-1) + call g2_sbytec(cgrib, one, iofst, 1) + call g2_sbytec(cgrib, iabs(idrstmpl(i)), iofst+1, nbits-1) endif iofst=iofst+nbits enddo @@ -506,26 +506,26 @@ subroutine addfield(cgrib,lcgrib,ipdsnum,ipdstmpl,ipdstmplen, & ! Calculate length of section 5 and store it in octets ! 1-4 of section 5. lensec5=(iofst-ibeg)/8 - call g2_sbytec(cgrib,lensec5,ibeg,32) + call g2_sbytec(cgrib, lensec5, ibeg, 32) ! Add Section 6 - Bit-Map Section ibeg=iofst ! Calculate offset for beginning of section 6 iofst=ibeg+32 ! leave space for length of section - call g2_sbytec(cgrib,six,iofst,8) ! Store section number (6) + call g2_sbytec(cgrib, six, iofst, 8) ! Store section number (6) iofst=iofst+8 - call g2_sbytec(cgrib,ibmap,iofst,8) ! Store Bit Map indicator + call g2_sbytec(cgrib, ibmap, iofst, 8) ! Store Bit Map indicator iofst=iofst+8 ! Store bitmap, if supplied if (ibmap.eq.0) then - call g2_sbytesc(cgrib,intbmap,iofst,1,0,ngrdpts) ! Store BitMap + call g2_sbytesc(cgrib, intbmap, iofst, 1, 0, ngrdpts) ! Store BitMap iofst=iofst+ngrdpts endif ! If specifying a previously defined bit-map, make sure ! one already exists in the current GRIB message. if ((ibmap.eq.254).and.(.not.isprevbmap)) then - print *,'addfield: Requested previously defined bitmap, ', & + print *, 'addfield: Requested previously defined bitmap, ', & ' but one does not exist in the current GRIB message.' ierr=8 return @@ -533,36 +533,37 @@ subroutine addfield(cgrib,lcgrib,ipdsnum,ipdstmpl,ipdstmplen, & ! Calculate length of section 6 and store it in octets ! 1-4 of section 6. Pad to end of octect, if necessary. - left=8-mod(iofst,8) + left=8-mod(iofst, 8) if (left.ne.8) then - call g2_sbytec(cgrib,zero,iofst,left) ! Pad with zeros to fill Octet + call g2_sbytec(cgrib, zero, iofst, left) ! Pad with zeros to fill Octet iofst=iofst+left endif lensec6=(iofst-ibeg)/8 - call g2_sbytec(cgrib,lensec6,ibeg,32) + call g2_sbytec(cgrib, lensec6, ibeg, 32) - ! Add Section 7 - Data Section - ibeg=iofst ! Calculate offset for beginning of section 7 - iofst=ibeg+32 ! leave space for length of section - call g2_sbytec(cgrib,seven,iofst,8) ! Store section number (7) - iofst=iofst+8 + ! Add Section 7 - Data Section. + ibeg = iofst ! Calculate offset for beginning of section 7 + iofst = ibeg + 32 ! leave space for length of section + call g2_sbytec(cgrib, seven, iofst, 8) ! Store section number (7) + iofst = iofst + 8 + ! Store Packed Binary Data values, if non-constant field - if (lcpack.ne.0) then - ioctet=iofst/8 - cgrib(ioctet+1:ioctet+lcpack)=cpack(1:lcpack) - iofst=iofst+(8*lcpack) + if (lcpack .ne. 0) then + ioctet = iofst / 8 + cgrib(ioctet + 1:ioctet + lcpack) = cpack(1:lcpack) + iofst = iofst + (8 * lcpack) endif ! Calculate length of section 7 and store it in octets ! 1-4 of section 7. - lensec7=(iofst-ibeg)/8 - call g2_sbytec(cgrib,lensec7,ibeg,32) + lensec7 = (iofst - ibeg) / 8 + call g2_sbytec(cgrib, lensec7, ibeg, 32) - if(allocated(cpack) )deallocate(cpack) + if (allocated(cpack)) deallocate(cpack) - ! Update current byte total of message in Section 0 - newlen=lencurr+lensec4+lensec5+lensec6+lensec7 - call g2_sbytec(cgrib,newlen,96,32) + ! Update current byte total of message in Section 0. + newlen = lencurr + lensec4 + lensec5 + lensec6 + lensec7 + call g2_sbytec(cgrib, newlen, 96, 32) return end subroutine addfield From 05ae97b1f59642c2e3cdb2778993b06d751a1f31 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Mon, 20 May 2024 09:47:25 -0600 Subject: [PATCH 2/6] cleanup of some code --- src/g2create.F90 | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/g2create.F90 b/src/g2create.F90 index 153a1d45..ff504172 100644 --- a/src/g2create.F90 +++ b/src/g2create.F90 @@ -64,7 +64,7 @@ subroutine gribcreate(cgrib, lcgrib, listsec0, listsec1, ierr) integer, parameter :: mapsec1len = 13 integer, parameter :: mapsec1(mapsec1len) = (/ 2, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1 /) integer lensec0, iofst, ibeg - + ierr = 0 #ifdef LOGGING @@ -218,6 +218,25 @@ subroutine addfield(cgrib, lcgrib, ipdsnum, ipdstmpl, ipdstmplen, & integer :: iret, istat real (kind = 4) :: tmpfld(1) + interface + subroutine g2_gbytec(in, iout, iskip, nbits) + character*1, intent(in) :: in(*) + integer, intent(inout) :: iout(*) + integer, intent(in) :: iskip, nbits + end subroutine g2_gbytec + subroutine g2_gbytec1(in, siout, iskip, nbits) + character*1, intent(in) :: in(*) + integer, intent(inout) :: siout + integer, intent(in) :: iskip, nbits + end subroutine g2_gbytec1 + subroutine g2_gbytec81(in, siout, iskip, nbits) + character*1, intent(in) :: in(*) + integer (kind = 8), intent(inout) :: siout + integer, intent(in) :: iskip, nbits + integer (kind = 8) :: iout(1) + end subroutine g2_gbytec81 + end interface + allones = int(Z'FFFFFFFF') ierr = 0 @@ -254,9 +273,9 @@ subroutine addfield(cgrib, lcgrib, ipdsnum, ipdstmpl, ipdstmplen, & do ! Get number and length of next section iofst = len * 8 - call g2_gbytec(cgrib, ilen, iofst, 32) + call g2_gbytec1(cgrib, ilen, iofst, 32) iofst = iofst + 32 - call g2_gbytec(cgrib, isecnum, iofst, 8) + call g2_gbytec1(cgrib, isecnum, iofst, 8) iofst = iofst + 8 ! Check if previous Section 3 exists and save location of ! the section 3 in case needed later. @@ -267,7 +286,7 @@ subroutine addfield(cgrib, lcgrib, ipdsnum, ipdstmpl, ipdstmplen, & endif ! Check if a previous defined bitmap exists if (isecnum .eq. 6) then - call g2_gbytec(cgrib, ibmprev, iofst, 8) + call g2_gbytec1(cgrib, ibmprev, iofst, 8) iofst = iofst + 8 if ((ibmprev .ge. 0) .and. (ibmprev .le. 253)) isprevbmap = .true. endif From e59dc798edec985a3e6d1efc1a990d2d4190ddb8 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Mon, 20 May 2024 09:53:57 -0600 Subject: [PATCH 3/6] cleanup of some code --- src/g2create.F90 | 93 +++++++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 40 deletions(-) diff --git a/src/g2create.F90 b/src/g2create.F90 index ff504172..98f93a3c 100644 --- a/src/g2create.F90 +++ b/src/g2create.F90 @@ -235,6 +235,16 @@ subroutine g2_gbytec81(in, siout, iskip, nbits) integer, intent(in) :: iskip, nbits integer (kind = 8) :: iout(1) end subroutine g2_gbytec81 + subroutine g2_sbytec(out, in, iskip, nbits) + character*1, intent(inout) :: out(*) + integer, intent(in) :: in(*) + integer, intent(in) :: iskip, nbits + end subroutine g2_sbytec + subroutine g2_sbytec1(out, in, iskip, nbits) + character*1, intent(inout) :: out(*) + integer, intent(in) :: in + integer, intent(in) :: iskip, nbits + end subroutine g2_sbytec1 end interface allones = int(Z'FFFFFFFF') @@ -277,6 +287,7 @@ end subroutine g2_gbytec81 iofst = iofst + 32 call g2_gbytec1(cgrib, isecnum, iofst, 8) iofst = iofst + 8 + ! Check if previous Section 3 exists and save location of ! the section 3 in case needed later. if (isecnum .eq. 3) then @@ -284,6 +295,7 @@ end subroutine g2_gbytec81 lpos3 = len + 1 lensec3 = ilen endif + ! Check if a previous defined bitmap exists if (isecnum .eq. 6) then call g2_gbytec1(cgrib, ibmprev, iofst, 8) @@ -291,8 +303,10 @@ end subroutine g2_gbytec81 if ((ibmprev .ge. 0) .and. (ibmprev .le. 253)) isprevbmap = .true. endif len = len + ilen + ! Exit loop if last section reached if (len .eq. lencurr) exit + ! If byte count for each section does not match current ! total length, then there is a problem. if (len .gt. lencurr) then @@ -306,8 +320,7 @@ end subroutine g2_gbytec81 ! Sections 4 through 7 can only be added after section 3 or 7. if ((isecnum .ne. 3) .and. (isecnum .ne. 7)) then - print *, 'addfield: Sections 4-7 can only be added after', & - ' Section 3 or 7.' + print *, 'addfield: Sections 4-7 can only be added after Section 3 or 7.' print *, 'addfield: Section ', isecnum, ' was the last found in', & ' given GRIB message.' ierr = 4 @@ -327,12 +340,12 @@ end subroutine g2_gbytec81 ! Add Section 4 - Product Definition Section. ibeg = lencurr * 8 ! Calculate offset for beginning of section 4 iofst = ibeg + 32 ! leave space for length of section - call g2_sbytec(cgrib, four, iofst, 8) ! Store section number (4) - iofst = iofst+8 - call g2_sbytec(cgrib, numcoord, iofst, 16) ! Store num of coordinate values - iofst = iofst+16 - call g2_sbytec(cgrib, ipdsnum, iofst, 16) ! Store Prod Def Template num. - iofst = iofst+16 + call g2_sbytec1(cgrib, four, iofst, 8) ! Store section number (4) + iofst = iofst + 8 + call g2_sbytec1(cgrib, numcoord, iofst, 16) ! Store num of coordinate values + iofst = iofst + 16 + call g2_sbytec1(cgrib, ipdsnum, iofst, 16) ! Store Prod Def Template num. + iofst = iofst + 16 ! Get Product Definition Template. call getpdstemplate(ipdsnum, mappdslen, mappds, needext, iret) @@ -357,8 +370,8 @@ end subroutine g2_gbytec81 if ((mappds(i) .ge. 0).or.(ipdstmpl(i) .ge. 0)) then call g2_sbytec(cgrib, ipdstmpl(i), iofst, nbits) else - call g2_sbytec(cgrib, one, iofst, 1) - call g2_sbytec(cgrib, iabs(ipdstmpl(i)), iofst + 1, nbits - 1) + call g2_sbytec1(cgrib, one, iofst, 1) + call g2_sbytec1(cgrib, iabs(ipdstmpl(i)), iofst + 1, nbits - 1) endif iofst = iofst+nbits enddo @@ -500,40 +513,40 @@ end subroutine g2_gbytec81 ! Add Section 5 - Data Representation Section ibeg=iofst ! Calculate offset for beginning of section 5 - iofst=ibeg+32 ! leave space for length of section - call g2_sbytec(cgrib, five, iofst, 8) ! Store section number (5) - iofst=iofst+8 - call g2_sbytec(cgrib, ndpts, iofst, 32) ! Store num of actual data points - iofst=iofst+32 - call g2_sbytec(cgrib, idrsnum, iofst, 16) ! Store Data Repr. Template num. - iofst=iofst+16 + iofst=ibeg + 32 ! leave space for length of section + call g2_sbytec1(cgrib, five, iofst, 8) ! Store section number (5) + iofst=iofst + 8 + call g2_sbytec1(cgrib, ndpts, iofst, 32) ! Store num of actual data points + iofst=iofst + 32 + call g2_sbytec1(cgrib, idrsnum, iofst, 16) ! Store Data Repr. Template num. + iofst = iofst + 16 ! Pack up each input value in array idrstmpl into the ! the appropriate number of octets, which are specified in ! corresponding entries in array mapdrs. do i=1, mapdrslen - nbits=iabs(mapdrs(i))*8 - if ((mapdrs(i).ge.0).or.(idrstmpl(i).ge.0)) then + nbits =iabs(mapdrs(i)) * 8 + if ((mapdrs(i) .ge. 0) .or. (idrstmpl(i) .ge. 0)) then call g2_sbytec(cgrib, idrstmpl(i), iofst, nbits) else - call g2_sbytec(cgrib, one, iofst, 1) - call g2_sbytec(cgrib, iabs(idrstmpl(i)), iofst+1, nbits-1) + call g2_sbytec1(cgrib, one, iofst, 1) + call g2_sbytec1(cgrib, iabs(idrstmpl(i)), iofst+1, nbits-1) endif - iofst=iofst+nbits + iofst = iofst + nbits enddo ! Calculate length of section 5 and store it in octets ! 1-4 of section 5. - lensec5=(iofst-ibeg)/8 - call g2_sbytec(cgrib, lensec5, ibeg, 32) + lensec5 = (iofst - ibeg) / 8 + call g2_sbytec1(cgrib, lensec5, ibeg, 32) - ! Add Section 6 - Bit-Map Section - ibeg=iofst ! Calculate offset for beginning of section 6 - iofst=ibeg+32 ! leave space for length of section - call g2_sbytec(cgrib, six, iofst, 8) ! Store section number (6) - iofst=iofst+8 - call g2_sbytec(cgrib, ibmap, iofst, 8) ! Store Bit Map indicator - iofst=iofst+8 + ! Add Section 6 - Bit-Map Section. + ibeg = iofst ! Calculate offset for beginning of section 6 + iofst = ibeg + 32 ! leave space for length of section + call g2_sbytec1(cgrib, six, iofst, 8) ! Store section number (6) + iofst=iofst + 8 + call g2_sbytec1(cgrib, ibmap, iofst, 8) ! Store Bit Map indicator + iofst = iofst + 8 ! Store bitmap, if supplied if (ibmap.eq.0) then @@ -552,18 +565,18 @@ end subroutine g2_gbytec81 ! Calculate length of section 6 and store it in octets ! 1-4 of section 6. Pad to end of octect, if necessary. - left=8-mod(iofst, 8) - if (left.ne.8) then - call g2_sbytec(cgrib, zero, iofst, left) ! Pad with zeros to fill Octet - iofst=iofst+left + left = 8 - mod(iofst, 8) + if (left .ne. 8) then + call g2_sbytec1(cgrib, zero, iofst, left) ! Pad with zeros to fill Octet + iofst = iofst + left endif - lensec6=(iofst-ibeg)/8 - call g2_sbytec(cgrib, lensec6, ibeg, 32) + lensec6 = (iofst - ibeg) / 8 + call g2_sbytec1(cgrib, lensec6, ibeg, 32) ! Add Section 7 - Data Section. ibeg = iofst ! Calculate offset for beginning of section 7 iofst = ibeg + 32 ! leave space for length of section - call g2_sbytec(cgrib, seven, iofst, 8) ! Store section number (7) + call g2_sbytec1(cgrib, seven, iofst, 8) ! Store section number (7) iofst = iofst + 8 ! Store Packed Binary Data values, if non-constant field @@ -576,13 +589,13 @@ end subroutine g2_gbytec81 ! Calculate length of section 7 and store it in octets ! 1-4 of section 7. lensec7 = (iofst - ibeg) / 8 - call g2_sbytec(cgrib, lensec7, ibeg, 32) + call g2_sbytec1(cgrib, lensec7, ibeg, 32) if (allocated(cpack)) deallocate(cpack) ! Update current byte total of message in Section 0. newlen = lencurr + lensec4 + lensec5 + lensec6 + lensec7 - call g2_sbytec(cgrib, newlen, 96, 32) + call g2_sbytec1(cgrib, newlen, 96, 32) return end subroutine addfield From e7f68dbe3ee07af21c4a78722861e17169f7fdf4 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Mon, 20 May 2024 11:26:31 -0600 Subject: [PATCH 4/6] more cleanup --- src/g2create.F90 | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/g2create.F90 b/src/g2create.F90 index 98f93a3c..dccec988 100644 --- a/src/g2create.F90 +++ b/src/g2create.F90 @@ -65,6 +65,19 @@ subroutine gribcreate(cgrib, lcgrib, listsec0, listsec1, ierr) integer, parameter :: mapsec1(mapsec1len) = (/ 2, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1 /) integer lensec0, iofst, ibeg + interface + subroutine g2_sbytec(out, in, iskip, nbits) + character*1, intent(inout) :: out(*) + integer, intent(in) :: in(*) + integer, intent(in) :: iskip, nbits + end subroutine g2_sbytec + subroutine g2_sbytec1(out, in, iskip, nbits) + character*1, intent(inout) :: out(*) + integer, intent(in) :: in + integer, intent(in) :: iskip, nbits + end subroutine g2_sbytec1 + end interface + ierr = 0 #ifdef LOGGING @@ -84,7 +97,7 @@ subroutine gribcreate(cgrib, lcgrib, listsec0, listsec1, ierr) cgrib(2) = grib(2:2) cgrib(3) = grib(3:3) cgrib(4) = grib(4:4) - call g2_sbytec(cgrib, ZERO, 32, 16) ! reserved for future use + call g2_sbytec1(cgrib, ZERO, 32, 16) ! reserved for future use call g2_sbytec(cgrib, listsec0(1), 48, 8) ! Discipline call g2_sbytec(cgrib, listsec0(2), 56, 8) ! GRIB edition number lensec0 = 16 ! bytes (octets) @@ -92,7 +105,7 @@ subroutine gribcreate(cgrib, lcgrib, listsec0, listsec1, ierr) ! Pack Section 1 - Identification Section. ibeg = lensec0 * 8 ! Calculate offset for beginning of section 1 iofst = ibeg + 32 ! leave space for length of section - call g2_sbytec(cgrib, ONE, iofst, 8) ! Store section number ( 1 ) + call g2_sbytec1(cgrib, ONE, iofst, 8) ! Store section number ( 1 ) iofst = iofst + 8 ! Pack up each input value in array listsec1 into the the @@ -107,11 +120,11 @@ subroutine gribcreate(cgrib, lcgrib, listsec0, listsec1, ierr) ! Calculate length of section 1 and store it in octets 1-4 of ! section 1. lensec1 = (iofst - ibeg) / 8 - call g2_sbytec(cgrib, lensec1, ibeg, 32) + call g2_sbytec1(cgrib, lensec1, ibeg, 32) ! Put current byte total of message into Section 0. - call g2_sbytec(cgrib, ZERO, 64, 32) - call g2_sbytec(cgrib, lensec0 + lensec1, 96, 32) + call g2_sbytec1(cgrib, ZERO, 64, 32) + call g2_sbytec1(cgrib, lensec0 + lensec1, 96, 32) end subroutine gribcreate !> Pack up Sections 4 through 7 for a field and add them to a From 80c128971bf40e4f584e77d45945075e5be9ab12 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Mon, 20 May 2024 11:29:52 -0600 Subject: [PATCH 5/6] more cleanup --- src/g2create.F90 | 67 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/src/g2create.F90 b/src/g2create.F90 index dccec988..356d4413 100644 --- a/src/g2create.F90 +++ b/src/g2create.F90 @@ -674,6 +674,35 @@ subroutine addgrid(cgrib, lcgrib, igds, igdstmpl, igdstmplen, & logical needext integer :: i, ilen, iret, isecnum, nbits + interface + subroutine g2_gbytec(in, iout, iskip, nbits) + character*1, intent(in) :: in(*) + integer, intent(inout) :: iout(*) + integer, intent(in) :: iskip, nbits + end subroutine g2_gbytec + subroutine g2_gbytec1(in, siout, iskip, nbits) + character*1, intent(in) :: in(*) + integer, intent(inout) :: siout + integer, intent(in) :: iskip, nbits + end subroutine g2_gbytec1 + subroutine g2_gbytec81(in, siout, iskip, nbits) + character*1, intent(in) :: in(*) + integer (kind = 8), intent(inout) :: siout + integer, intent(in) :: iskip, nbits + integer (kind = 8) :: iout(1) + end subroutine g2_gbytec81 + subroutine g2_sbytec(out, in, iskip, nbits) + character*1, intent(inout) :: out(*) + integer, intent(in) :: in(*) + integer, intent(in) :: iskip, nbits + end subroutine g2_sbytec + subroutine g2_sbytec1(out, in, iskip, nbits) + character*1, intent(inout) :: out(*) + integer, intent(in) :: in + integer, intent(in) :: iskip, nbits + end subroutine g2_sbytec1 + end interface + ierr = 0 #ifdef LOGGING @@ -694,7 +723,7 @@ subroutine addgrid(cgrib, lcgrib, igds, igdstmpl, igdstmplen, & enddo ! Get current length of GRIB message. - call g2_gbytec(cgrib, lencurr, 96, 32) + call g2_gbytec1(cgrib, lencurr, 96, 32) ! Check to see if GRIB message is already complete. ctemp = cgrib(lencurr - 3) // cgrib(lencurr - 2) // cgrib(lencurr & @@ -712,9 +741,9 @@ subroutine addgrid(cgrib, lcgrib, igds, igdstmpl, igdstmplen, & do ! Get length and section number of next section. iofst = len * 8 - call g2_gbytec(cgrib, ilen, iofst, 32) + call g2_gbytec1(cgrib, ilen, iofst, 32) iofst = iofst + 32 - call g2_gbytec(cgrib, isecnum, iofst, 8) + call g2_gbytec1(cgrib, isecnum, iofst, 8) len = len + ilen ! Exit loop if last section reached. @@ -745,7 +774,7 @@ subroutine addgrid(cgrib, lcgrib, igds, igdstmpl, igdstmplen, & ! Add Section 3 - Grid Definition Section. ibeg = lencurr * 8 ! Calculate offset for beginning of section 3 iofst = ibeg + 32 ! leave space for length of section - call g2_sbytec(cgrib, THREE, iofst, 8) ! Store section number (3) + call g2_sbytec1(cgrib, THREE, iofst, 8) ! Store section number (3) iofst = iofst + 8 call g2_sbytec(cgrib, igds(1), iofst, 8) ! Store source of Grid def. iofst = iofst + 8 @@ -761,7 +790,7 @@ subroutine addgrid(cgrib, lcgrib, igds, igdstmpl, igdstmplen, & if (igds(1) .eq. 0) then call g2_sbytec(cgrib, igds(5), iofst, 16) ! Store Grid Def Template num. else - call g2_sbytec(cgrib, 65535, iofst, 16) ! Store missing value as Grid Def Template num. + call g2_sbytec1(cgrib, 65535, iofst, 16) ! Store missing value as Grid Def Template num. endif iofst = iofst + 16 @@ -793,8 +822,8 @@ subroutine addgrid(cgrib, lcgrib, igds, igdstmpl, igdstmplen, & if ((mapgrid(i) .ge. 0) .or. (igdstmpl(i) .ge. 0)) then call g2_sbytec(cgrib, igdstmpl(i), iofst, nbits) else - call g2_sbytec(cgrib, ONE, iofst, 1) - call g2_sbytec(cgrib, iabs(igdstmpl(i)), iofst + 1, nbits & + call g2_sbytec1(cgrib, ONE, iofst, 1) + call g2_sbytec1(cgrib, iabs(igdstmpl(i)), iofst + 1, nbits & - 1) endif iofst = iofst + nbits @@ -811,11 +840,11 @@ subroutine addgrid(cgrib, lcgrib, igds, igdstmpl, igdstmplen, & ! Calculate length of section 3 and store it in octets 1-4 of ! section 3. lensec3 = (iofst - ibeg) / 8 - call g2_sbytec(cgrib, lensec3, ibeg, 32) + call g2_sbytec1(cgrib, lensec3, ibeg, 32) ! Update current byte total of message in Section 0. - call g2_sbytec(cgrib, lencurr + lensec3, 96, 32) + call g2_sbytec1(cgrib, lencurr + lensec3, 96, 32) end subroutine addgrid !> Add a [Local Use Section (Section @@ -869,7 +898,7 @@ subroutine addlocal(cgrib, lcgrib, csec2, lcsec2, ierr) endif ! Get current length of GRIB message. - call g2_gbytec(cgrib, lencurr, 96, 32) + call g2_gbytec1(cgrib, lencurr, 96, 32) ! Check to see if GRIB message is already complete ctemp = cgrib(lencurr - 3) // cgrib(lencurr - 2) // cgrib(lencurr - 1) // cgrib(lencurr) @@ -885,9 +914,9 @@ subroutine addlocal(cgrib, lcgrib, csec2, lcsec2, ierr) do ! Get section number and length of next section. iofst = len * 8 - call g2_gbytec(cgrib, ilen, iofst, 32) + call g2_gbytec1(cgrib, ilen, iofst, 32) iofst = iofst + 32 - call g2_gbytec(cgrib, isecnum, iofst, 8) + call g2_gbytec1(cgrib, isecnum, iofst, 8) len = len + ilen ! Exit loop if last section reached if (len .eq. lencurr) exit @@ -914,17 +943,17 @@ subroutine addlocal(cgrib, lcgrib, csec2, lcsec2, ierr) ! Add Section 2 - Local Use Section. ibeg = lencurr * 8 ! Calculate offset for beginning of section 2 iofst = ibeg + 32 ! leave space for length of section - call g2_sbytec(cgrib, two, iofst, 8) ! Store section number (2) + call g2_sbytec1(cgrib, two, iofst, 8) ! Store section number (2) istart = lencurr + 5 cgrib(istart + 1:istart + lcsec2) = csec2(1:lcsec2) ! Calculate length of section 2 and store it in octets 1-4 of ! section 2. lensec2 = lcsec2 + 5 ! bytes - call g2_sbytec(cgrib, lensec2, ibeg, 32) + call g2_sbytec1(cgrib, lensec2, ibeg, 32) ! Update current byte total of message in Section 0. - call g2_sbytec(cgrib, lencurr+lensec2, 96, 32) + call g2_sbytec1(cgrib, lencurr + lensec2, 96, 32) end subroutine addlocal @@ -972,7 +1001,7 @@ subroutine gribend(cgrib, lcgrib, lengrib, ierr) endif ! Get current length of GRIB message. - call g2_gbytec(cgrib, lencurr, 96, 32) + call g2_gbytec1(cgrib, lencurr, 96, 32) ! Loop through all current sections of the GRIB message to ! find the last section number. @@ -980,9 +1009,9 @@ subroutine gribend(cgrib, lcgrib, lengrib, ierr) do ! Get number and length of next section. iofst = len * 8 - call g2_gbytec(cgrib, ilen, iofst, 32) + call g2_gbytec1(cgrib, ilen, iofst, 32) iofst = iofst + 32 - call g2_gbytec(cgrib, isecnum, iofst, 8) + call g2_gbytec1(cgrib, isecnum, iofst, 8) len = len + ilen ! Exit loop if last section reached. @@ -1015,5 +1044,5 @@ subroutine gribend(cgrib, lcgrib, lengrib, ierr) ! Update current byte total of message in Section 0. lengrib = lencurr + 4 - call g2_sbytec(cgrib, lengrib, 96, 32) + call g2_sbytec1(cgrib, lengrib, 96, 32) end subroutine gribend From bbbf475836ee1a94a0540031209881324b785c4e Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Mon, 20 May 2024 11:36:38 -0600 Subject: [PATCH 6/6] more cleanup --- src/g2get.F90 | 87 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 34 deletions(-) diff --git a/src/g2get.F90 b/src/g2get.F90 index 1cc7311c..1ca6dfcb 100644 --- a/src/g2get.F90 +++ b/src/g2get.F90 @@ -67,6 +67,25 @@ subroutine gb_info(cgrib, lcgrib, listsec0, listsec1, & integer :: nbits, lensec1, lensec0, lensec, lenposs, lengrib, j integer :: i, ipos, isecnum + interface + subroutine g2_gbytec(in, iout, iskip, nbits) + character*1, intent(in) :: in(*) + integer, intent(inout) :: iout(*) + integer, intent(in) :: iskip, nbits + end subroutine g2_gbytec + subroutine g2_gbytec1(in, siout, iskip, nbits) + character*1, intent(in) :: in(*) + integer, intent(inout) :: siout + integer, intent(in) :: iskip, nbits + end subroutine g2_gbytec1 + subroutine g2_gbytec81(in, siout, iskip, nbits) + character*1, intent(in) :: in(*) + integer (kind = 8), intent(inout) :: siout + integer, intent(in) :: iskip, nbits + integer (kind = 8) :: iout(1) + end subroutine g2_gbytec81 + end interface + ierr = 0 numlocal = 0 numfields = 0 @@ -94,7 +113,7 @@ subroutine gb_info(cgrib, lcgrib, listsec0, listsec1, & call g2_gbytec(cgrib, listsec0(2), iofst, 8) ! GRIB edition number iofst = iofst+8 iofst = iofst + 32 - call g2_gbytec(cgrib, lengrib, iofst, 32) ! Length of GRIB message + call g2_gbytec1(cgrib, lengrib, iofst, 32) ! Length of GRIB message iofst = iofst + 32 listsec0(3) = lengrib lensec0 = 16 @@ -108,9 +127,9 @@ subroutine gb_info(cgrib, lcgrib, listsec0, listsec1, & endif ! Unpack Section 1 - Identification Section. - call g2_gbytec(cgrib, lensec1, iofst, 32) ! Length of Section 1 + call g2_gbytec1(cgrib, lensec1, iofst, 32) ! Length of Section 1 iofst = iofst + 32 - call g2_gbytec(cgrib, isecnum, iofst, 8) ! Section number ( 1 ) + call g2_gbytec1(cgrib, isecnum, iofst, 8) ! Section number ( 1 ) iofst = iofst + 8 if (isecnum .ne. 1) then print *, 'gb_info: Could not find section 1.' @@ -142,9 +161,9 @@ subroutine gb_info(cgrib, lcgrib, listsec0, listsec1, & exit endif iofst = (ipos - 1) * 8 - call g2_gbytec(cgrib, lensec, iofst, 32) ! Get Length of Section + call g2_gbytec1(cgrib, lensec, iofst, 32) ! Get Length of Section iofst = iofst + 32 - call g2_gbytec(cgrib, isecnum, iofst, 8) ! Get Section number + call g2_gbytec1(cgrib, isecnum, iofst, 8) ! Get Section number iofst = iofst + 8 ipos = ipos+lensec ! Update beginning of section pointer if (ipos .gt. (istart + lengrib)) then @@ -296,7 +315,7 @@ subroutine gribinfo(cgrib, lcgrib, listsec0, listsec1, & call g2_gbytec(cgrib, listsec0(2), iofst, 8) ! GRIB edition number iofst = iofst + 8 iofst = iofst + 32 - call g2_gbytec(cgrib, lengrib, iofst, 32) ! Length of GRIB message + call g2_gbytec1(cgrib, lengrib, iofst, 32) ! Length of GRIB message iofst = iofst + 32 listsec0(3) = lengrib lensec0 = 16 @@ -310,9 +329,9 @@ subroutine gribinfo(cgrib, lcgrib, listsec0, listsec1, & endif ! Unpack Section 1 - Identification Section. - call g2_gbytec(cgrib, lensec1, iofst, 32) ! Length of Section 1 + call g2_gbytec1(cgrib, lensec1, iofst, 32) ! Length of Section 1 iofst = iofst + 32 - call g2_gbytec(cgrib, isecnum, iofst, 8) ! Section number (1) + call g2_gbytec1(cgrib, isecnum, iofst, 8) ! Section number (1) iofst = iofst + 8 if (isecnum .ne. 1) then print *, 'gribinfo: Could not find section 1.' @@ -346,9 +365,9 @@ subroutine gribinfo(cgrib, lcgrib, listsec0, listsec1, & exit endif iofst = (ipos - 1) * 8 - call g2_gbytec(cgrib, lensec, iofst, 32) ! Get Length of Section + call g2_gbytec1(cgrib, lensec, iofst, 32) ! Get Length of Section iofst = iofst + 32 - call g2_gbytec(cgrib, isecnum, iofst, 8) ! Get Section number + call g2_gbytec1(cgrib, isecnum, iofst, 8) ! Get Section number iofst = iofst + 8 ipos = ipos + lensec ! Update beginning of section pointer if (ipos .gt. (istart + lengrib)) then @@ -364,9 +383,9 @@ subroutine gribinfo(cgrib, lcgrib, listsec0, listsec1, & if (lenposs .gt. maxsec2len) maxsec2len = lenposs elseif (isecnum .eq. 3) then iofst = iofst + 8 ! skip source of grid def. - call g2_gbytec(cgrib, ngdpts, iofst, 32) ! Get Num of Grid Points + call g2_gbytec1(cgrib, ngdpts, iofst, 32) ! Get Num of Grid Points iofst = iofst + 32 - call g2_gbytec(cgrib, nbyte, iofst, 8) ! Get Num octets for opt. list + call g2_gbytec1(cgrib, nbyte, iofst, 8) ! Get Num octets for opt. list iofst = iofst + 8 if (ngdpts .gt. maxgridpts) maxgridpts = ngdpts lenposs = lensec - 14 @@ -377,7 +396,7 @@ subroutine gribinfo(cgrib, lcgrib, listsec0, listsec1, & endif elseif (isecnum .eq. 4) then numfields = numfields + 1 - call g2_gbytec(cgrib, numcoord, iofst, 16) ! Get Num of Coord Values + call g2_gbytec1(cgrib, numcoord, iofst, 16) ! Get Num of Coord Values iofst = iofst + 16 if (numcoord .ne. 0) then if (numcoord .gt. maxcoordlist) maxcoordlist = numcoord @@ -567,7 +586,7 @@ subroutine getfield(cgrib, lcgrib, ifldnum, igds, igdstmpl, & call g2_gbytec(cgrib, listsec0(2), iofst, 8) ! GRIB edition number iofst = iofst + 8 iofst = iofst + 32 - call g2_gbytec(cgrib, lengrib, iofst, 32) ! Length of GRIB message + call g2_gbytec1(cgrib, lengrib, iofst, 32) ! Length of GRIB message iofst = iofst + 32 lensec0 = 16 ipos = istart + lensec0 @@ -599,9 +618,9 @@ subroutine getfield(cgrib, lcgrib, ifldnum, igds, igdstmpl, & endif ! Get length of Section and Section number iofst = (ipos - 1) * 8 - call g2_gbytec(cgrib, lensec, iofst, 32) ! Get Length of Section + call g2_gbytec1(cgrib, lensec, iofst, 32) ! Get Length of Section iofst = iofst + 32 - call g2_gbytec(cgrib, isecnum, iofst, 8) ! Get Section number + call g2_gbytec1(cgrib, isecnum, iofst, 8) ! Get Section number iofst = iofst + 8 ! If found Section 3, unpack the GDS info using the appropriate @@ -788,7 +807,7 @@ subroutine unpack3(cgrib, lcgrib, iofst, igds, igdstmpl, & ierr = 0 - call g2_gbytec(cgrib, lensec, iofst, 32) ! Get Length of Section + call g2_gbytec1(cgrib, lensec, iofst, 32) ! Get Length of Section iofst = iofst + 32 iofst = iofst + 8 ! skip section number @@ -827,7 +846,7 @@ subroutine unpack3(cgrib, lcgrib, iofst, igds, igdstmpl, & if (mapgrid(i) .ge. 0) then call g2_gbytec(cgrib, igdstmpl(i), iofst, nbits) else - call g2_gbytec(cgrib, isign, iofst, 1) + call g2_gbytec1(cgrib, isign, iofst, 1) call g2_gbytec(cgrib, igdstmpl(i), iofst + 1, nbits-1) if (isign .eq. 1) igdstmpl(i) = -igdstmpl(i) endif @@ -847,7 +866,7 @@ subroutine unpack3(cgrib, lcgrib, iofst, igds, igdstmpl, & if (mapgrid(i) .ge. 0) then call g2_gbytec(cgrib, igdstmpl(i), iofst, nbits) else - call g2_gbytec(cgrib, isign, iofst, 1) + call g2_gbytec1(cgrib, isign, iofst, 1) call g2_gbytec(cgrib, igdstmpl(i), iofst + 1, nbits - & 1) if (isign .eq. 1) igdstmpl(i) = -igdstmpl(i) @@ -920,14 +939,14 @@ subroutine unpack4(cgrib, lcgrib, iofst, ipdsnum, ipdstmpl, & ierr = 0 - call g2_gbytec(cgrib, lensec, iofst, 32) ! Get Length of Section + call g2_gbytec1(cgrib, lensec, iofst, 32) ! Get Length of Section iofst = iofst + 32 iofst = iofst + 8 ! skip section number allocate(mappds(lensec)) - call g2_gbytec(cgrib, numcoord, iofst, 16) ! Get num of coordinate values + call g2_gbytec1(cgrib, numcoord, iofst, 16) ! Get num of coordinate values iofst = iofst + 16 - call g2_gbytec(cgrib, ipdsnum, iofst, 16) ! Get Prod. Def Template num. + call g2_gbytec1(cgrib, ipdsnum, iofst, 16) ! Get Prod. Def Template num. iofst = iofst + 16 ! Get Product Definition Template. call getpdstemplate(ipdsnum, mappdslen, mappds, needext, iret) @@ -944,7 +963,7 @@ subroutine unpack4(cgrib, lcgrib, iofst, ipdsnum, ipdstmpl, & if (mappds(i).ge.0) then call g2_gbytec(cgrib, ipdstmpl(i), iofst, nbits) else - call g2_gbytec(cgrib, isign, iofst, 1) + call g2_gbytec1(cgrib, isign, iofst, 1) call g2_gbytec(cgrib, ipdstmpl(i), iofst + 1, nbits-1) if (isign.eq.1) ipdstmpl(i) = -ipdstmpl(i) endif @@ -963,7 +982,7 @@ subroutine unpack4(cgrib, lcgrib, iofst, ipdsnum, ipdstmpl, & if (mappds(i).ge.0) then call g2_gbytec(cgrib, ipdstmpl(i), iofst, nbits) else - call g2_gbytec(cgrib, isign, iofst, 1) + call g2_gbytec1(cgrib, isign, iofst, 1) call g2_gbytec(cgrib, ipdstmpl(i), iofst + 1, nbits-1) if (isign.eq.1) ipdstmpl(i) = -ipdstmpl(i) endif @@ -1028,14 +1047,14 @@ subroutine unpack5(cgrib, lcgrib, iofst, ndpts, idrsnum, & ierr = 0 - call g2_gbytec(cgrib, lensec, iofst, 32) ! Get Length of Section + call g2_gbytec1(cgrib, lensec, iofst, 32) ! Get Length of Section iofst = iofst + 32 iofst = iofst + 8 ! skip section number allocate(mapdrs(lensec)) - call g2_gbytec(cgrib, ndpts, iofst, 32) ! Get num of data points + call g2_gbytec1(cgrib, ndpts, iofst, 32) ! Get num of data points iofst = iofst + 32 - call g2_gbytec(cgrib, idrsnum, iofst, 16) ! Get Data Rep Template Num. + call g2_gbytec1(cgrib, idrsnum, iofst, 16) ! Get Data Rep Template Num. iofst = iofst + 16 ! Gen Data Representation Template call getdrstemplate(idrsnum, mapdrslen, mapdrs, needext, iret) @@ -1052,7 +1071,7 @@ subroutine unpack5(cgrib, lcgrib, iofst, ndpts, idrsnum, & if (mapdrs(i).ge.0) then call g2_gbytec(cgrib, idrstmpl(i), iofst, nbits) else - call g2_gbytec(cgrib, isign, iofst, 1) + call g2_gbytec1(cgrib, isign, iofst, 1) call g2_gbytec(cgrib, idrstmpl(i), iofst + 1, nbits-1) if (isign.eq.1) idrstmpl(i) = -idrstmpl(i) endif @@ -1070,7 +1089,7 @@ subroutine unpack5(cgrib, lcgrib, iofst, ndpts, idrsnum, & if (mapdrs(i).ge.0) then call g2_gbytec(cgrib, idrstmpl(i), iofst, nbits) else - call g2_gbytec(cgrib, isign, iofst, 1) + call g2_gbytec1(cgrib, isign, iofst, 1) call g2_gbytec(cgrib, idrstmpl(i), iofst + 1, nbits - 1) if (isign.eq.1) idrstmpl(i) = -idrstmpl(i) endif @@ -1122,7 +1141,7 @@ subroutine unpack6(cgrib, lcgrib, iofst, ngpts, ibmap, bmap, ierr) iofst = iofst + 32 ! skip Length of Section iofst = iofst + 8 ! skip section number - call g2_gbytec(cgrib, ibmap, iofst, 8) ! Get bit-map indicator + call g2_gbytec1(cgrib, ibmap, iofst, 8) ! Get bit-map indicator iofst = iofst + 8 if (ibmap.eq.0) then ! Unpack bitmap @@ -1305,7 +1324,7 @@ subroutine getlocal(cgrib, lcgrib, localnum, csec2, lcsec2, ierr) call g2_gbytec(cgrib, listsec0(2), iofst, 8) ! GRIB edition number iofst = iofst + 8 iofst = iofst + 32 - call g2_gbytec(cgrib, lengrib, iofst, 32) ! Length of GRIB message + call g2_gbytec1(cgrib, lengrib, iofst, 32) ! Length of GRIB message iofst = iofst + 32 lensec0 = 16 ipos = istart + lensec0 @@ -1337,9 +1356,9 @@ subroutine getlocal(cgrib, lcgrib, localnum, csec2, lcsec2, ierr) ! Get length of Section and Section number iofst = (ipos - 1) * 8 - call g2_gbytec(cgrib, lensec, iofst, 32) ! Get Length of Section + call g2_gbytec1(cgrib, lensec, iofst, 32) ! Get Length of Section iofst = iofst + 32 - call g2_gbytec(cgrib, isecnum, iofst, 8) ! Get Section number + call g2_gbytec1(cgrib, isecnum, iofst, 8) ! Get Section number iofst = iofst + 8 ! If found the requested occurrence of Section 2, @@ -1575,7 +1594,7 @@ end subroutine g2_gbytec1 ! Check to see if we are at end of GRIB message. ctemp = cgrib(ipos) // cgrib(ipos + 1) // cgrib(ipos + 2) // cgrib(ipos + 3) if (ctemp .eq. c7777 ) then - ipos = ipos+4 + ipos = ipos + 4 ! If end of GRIB message not where expected, issue error if (ipos .ne. (istart + lengrib)) then print *, 'gettemplates: "7777" found, but not where expected.'