Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The following Fortran 77 program opens a file and reads vorticity and divergence (vo/d) spectral fields in GRIB format; it then calls INTUVP2 to create spectral U and /V fields. Because of the preliminary call to INTOUT, the U and /V fields are subsequently interpolated to grid-point fields with resolution 3deg 3 by 3deg 3 degrees without the need for a separate call to INTF. The function INTIN is not used here because the input fields are in GRIB format and are self-defining.

Subroutines PBOPEN, PBCLOSE, PBGRIB and PBWRITE handle pure binary input and output files.

 

Code Block
titleFortran 77
linenumberstrue
C 
C Copyright 2015 ECMWF.
C
C This software is licensed under the terms of the Apache Licence 
C Version 2.0 which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
C
C Unless required by applicable law or agreed to in writing, software
C distributed under the License is distributed on an "AS IS" BASIS,
C WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
C
C In applying this licence, ECMWF does not waive the privileges and immunities 
C granted to it by virtue of its status as an intergovernmental organisation 
C nor does it submit to any jurisdiction.
C

      PROGRAM SAMPLE4
CEXAMPLE_INTUVP2
      IMPLICIT NONE


C     Parameters
      INTEGER JPGRIB  INTV
 ! GRIB size (up to REAL REALV1/16 deg)
      CHARACTER*20 CHARVINTEGER JPBYTES  ! bytes/integer
      DIMENSIONPARAMETER INTV(4), REALV(4), CHARV(4)
C
JPGRIB = 33190420)
#ifdef INTEGER_8
      PARAMETER INTEGER(JPBYTES JPGRIB,= JPBYTES8)
C#else
      PARAMETER (JPGRIBJPBYTES = 70000004)
#endif

C
C     SetLocal JPBYTESvariables
 = 8 on a 64-bit machine.
 INTEGER      PARAMETER (JPBYTES = INTV(4)
C
       REAL     INTEGER IVOGRIB (JPGRIB), IDVGRIB REALV(JPGRIB4)
      CHARACTER*20 CHARV

     INTEGER IUGRIB (JPGRIB)CHARACTER*128 INFILE, IVGRIB (JPGRIB)
COUTFILE, ARG
      INTEGER IUNIT1INLEN, IUNIT2OUTLEN, IRECU1, INLENGU2, IERRIRET, IRET,J,NARGS
C
CN
      INTEGER  ExternalsIVOGRIB(JPGRIB), IDVGRIB(JPGRIB)
      INTEGER INTOUT, INTUVP2, IARGC
IUGRIB(JPGRIB), IVGRIB(JPGRIB)


C      LOGICAL ISSAME
CExternals
      CHARACTER*128INTEGER INFILEINTOUT, OUTFILEINTUVP2, CARG(4)IARGC


C **********************************************************************
C     ------------------------------------------------------------------


C     Pick up file names from command line.
C
      INFILE  = ' '
      NARGSOUTFILE = ' IARGC()'
      IF( NARGSIARGC().LTEQ.4 ) THEN
        DO N = print*1,'Usage: interpolation_example2 -i infile -o outfile'
 4, 2
           STOP
CALL GETARG(N,ARG)
        END  IF

   (ARG.EQ.'-i') THEN
    DO 101 J=1,NARGS
      CALL GETARG(J,CARG(J))
 101  CONTINUE
N+1,INFILE)
      DO 102 J=1,NARGS,2
   ELSEIF     IF(CARG(J)(ARG.EQ.'-io') THEN
            CALL INFILE=CARGGETARG(JN+1,OUTFILE)
        ELSEIF(CARG(J).EQ.'-o') THEN  ENDIF
        ENDDO
      ENDIF
      CALL OUTFILE=CARG(J+1)CHECK(
     _  INDEX(INFILE,' ').EQ.1 .OR.  ELSEINDEX(OUTFILE,' ').EQ.1,
     _   print*,'Usage: interpolationexample_example2intuvp2 -i infile -o outfile' )

      INTV  = STOP0
      REALV =  END IF
 102  CONTINUE

C **********************************************************************
0.
      CHARV = ''


C     SetDefine outputthe grid interval for the output
      REALV(1) = 3.0
      REALV(2) = 3.0
      IRET = INTOUT('grid', INTV, REALV, CHARV)
      IFCALL CHECK( IRET .NE.0, 0'INTOUT (grid) THENfailed')
      REALV  STOP 'grid setting INTOUT failed.'
      ENDIF
C= 0.


C     Open input and output files.
      CALL PBOPEN(IUNIT1U1, INFILE, 'r', IERRIRET)
      IFCALL CHECK( IERR IRET.NE. 0 ), STOP ' PBOPEN failed (r)')
      CALL PBOPEN(IUNIT2U2, OUTFILE, 'w', IERRIRET)
      CALL  IF ( IERR .NE. 0 ) STOP ' PBOPEN failed'
CCHECK(IRET.NE.0, 'PBOPEN failed (w)')


C     Start of loop on input vo/d pairs
      PRINT *, 'Start interpolation...'
      N = 0
 220  CONTINUE
      N = N + 1

C     Read vorticity. next vo/d pair
      CALL PBGRIB(IUNIT1U1, IVOGRIB, JPGRIB * JPBYTES, IRECINLEN, IERRIRET)
      IF ( IERR IRET.EQ. -1 ) GOTO 900THEN
      IF ( IERRIRET .NE.= 0
   ) STOP ' PBGRIB failed forGOTO vorticity'
C
C290
      ENDIF
      Read divergence.
CALL CHECK(IRET.NE.0, 'PBGRIB failed (vo)')

      CALL PBGRIB(IUNIT1U1, IDVGRIB, JPGRIB * JPBYTES, IRECINLEN, IERRIRET)
      IF ( IERR IRET.EQ. -1 )) THEN
        IRET = 0
        GOTO 900290
      ENDIF
    IF ( IERRCALL CHECK(IRET.NE. 0 ) STOP, ' PBGRIB failed for divergence'
C(d)')

C     CreateInterpolate
 U and V
    PRINT  WRITE(*,*) 'Interpolate Createvo/d Upair and V.'#', N
      INLENGOUTLEN = JPGRIB
      IRET = INTUVP2(IVOGRIB, IDVGRIB, JPGRIB, IUGRIB, IVGRIB, INLENGOUTLEN)
      IFCALL CHECK( IRET .NE. 0 ) THEN
        WRITE(*,*) ' INTUVP failed.'
        STOP
      ENDIF
C
C)

C     Write the new U and V productsu/v to file
      IF ( INLENG OUTLEN.GT. 0 ) THEN
        CALL PBWRITE(IUNIT2U2, IUGRIB, INLENG*JPBYTESOUTLEN, IERRIRET)
        IFCALL CHECK( IERR IRET.LT. (INLENG*JPBYTES) ) STOP ' OUTLEN,'PBWRITE failed (vo)')
        CALL PBWRITE(IUNIT2U2, IVGRIB, INLENG*JPBYTESOUTLEN, IERRIRET)
        IFCALL CHECK( IERR IRET.LT. (INLENG*JPBYTES) ) STOP ' OUTLEN,'PBWRITE failed (d)')
      ENDIF
C

C     Loop back for next vo/d Closedownpair
     900 GOTO CONTINUE220

C
C     Close input and output files. 
 290  CONTINUE
      CALL PBCLOSE(U1, IRET)
      CALL PBCLOSE(IUNIT1U2, IERRIRET)

      CALL PBCLOSE(IUNIT2, IERR)
C
      STOPPRINT *, 'Interpolated ', (N-1), ' vo/d pair(s).'
      END


C     ------------------------------------------------------------------


      SUBROUTINE CHECK(OOPS,MSG)
      IMPLICIT NONE
      LOGICAL OOPS
      CHARACTER MSG*(*)
      IF (OOPS) THEN
        PRINT *, MSG
        CALL EXIT(3)
      ENDIF
      END