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 3 by 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 INTV
JPGRIB   ! GRIB size (up to REAL REALV1/16 deg)
      CHARACTER*20 CHARVINTEGER JPBYTES  ! bytes/integer
      DIMENSIONPARAMETER INTV(4), REALV(4), CHARV(4)
CJPGRIB = 33190420)
#ifdef INTEGER_8
      PARAMETER INTEGER(JPBYTES JPGRIB,= JPBYTES8)
C#else
      PARAMETER (JPGRIBJPBYTES = 70000004)
C#endif


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

      CHARACTER*128 INFILE, OUTFILE, 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
C
Externals
      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
         print*,'Usage: interpolation_example2 -i infile -o outfile'
DO N = 1, 4, 2
           STOP
CALL GETARG(N,ARG)
         END IF

   (ARG.EQ.'-i') THEN
    DO 101 J=1,NARGS
      CALL GETARG(J,CARG(J)N+1,INFILE)
 101  CONTINUE

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

      INTV  STOP
= 0
      REALV = 0.
   END  IF
 102CHARV = CONTINUE

C **********************************************************************

''


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 CHECK(IRET.NE.0, 'PBOPEN IFfailed ( IERR .NE. 0 ) STOP ' PBOPEN failed'
Cw)')


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  Closedown
 900  CONTINUE
Cback for next vo/d pair
      GOTO 220


C     Close
 input290 and output files. CONTINUE
      CALL PBCLOSE(IUNIT1U1, IERRIRET)
      CALL PBCLOSE(IUNIT2U2, IERRIRET)

      PRINT *, 'Interpolated ', (N-1), ' vo/d pair(s).'
      END


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


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