CMAX: [Version 1.0 (6/22/93)]
CMAX: ----------------------------------------------------
CMAX: Transformation of FILLUP from fillup.f
CMAX: ----------------------------------------------------
      SUBROUTINE fillup(z,im,jm)
C  FILLS IN MISSING VALUES IN A SMOOTH ARRAY
      INTEGER IM
      INTEGER JM
      LOGICAL AGAIN
      LOGICAL DATA
      INTEGER I
      INTEGER IN
      INTEGER J
      INTEGER JN
      INTEGER N
      INTEGER NDI (8)
      INTEGER NDJ (8)
      INTEGER NNGHBR
      REAL PTOTAL
      DIMENSION Z (IM, JM)
!hpf$ distribute ndi(block)
!hpf$ distribute ndj(block)
!hpf$ distribute z(block,block)
      DATA NDI / 0, - 1, - 1, - 1, 0, 1, 1, 1 /
      DATA NDJ / - 1, - 1, 0, 1, 1, 1, 0, - 1 /
      DATA SPVAL / 0.0 /
C  SCAN THE ARRAY, LOOKING FOR SPECIAL VALUES
  100 CONTINUE
      again = .FALSE.
      data = .FALSE.
      DO 7004 j = 1 , jm
        DO 7002 i = 1 , im
          IF (z(i,j) .EQ. spval) THEN
C  TRY TO FILL A SPECIAL VALUE
            nnghbr = 0
            ptotal = 0.0
C  SCAN THE NEIGHBORS OF THE SPECIAL POINT
            DO 7000 n = 1 , 8
              in = mod(i + ndi(n) + im - 1,im) + 1
              jn = max(min(j + ndj(n),jm),1)
              IF (z(in,jn) .NE. spval) THEN
                nnghbr = nnghbr + 1
                ptotal = ptotal + z(in,jn)
              ENDIF
  200         CONTINUE
 7000       CONTINUE
            IF (nnghbr .NE. 0) THEN
              z(i,j) = ptotal / nnghbr
            ELSE
              again = .TRUE.
            ENDIF
          ELSE
C  MARK THE FACT THAT THERE IS AT LEAST ONE USEABLE DATA VALUE
            data = .TRUE.
          ENDIF
  400     CONTINUE
 7002   CONTINUE
 7004 CONTINUE
C  TEST WHETHER TO MAKE ANOTHER PASS
      IF (.NOT.data) THEN
        again = .FALSE.
        WRITE( 6,900 ) 
      ENDIF
      IF (again) THEN
        GOTO 100
      ENDIF
      RETURN
900   FORMAT ('0FILLUP: ** ERROR ** -  ARRAY TO BE FILLED IS VOID')
      END
