C----------------------------------------------------------
C
C1000&---------------------
      PARAMETER(IF=51,JF=51,KF=51)
      PARAMETER (NF=224,NF2=224,NF3=224)
      PARAMETER (NF2S=NF+NF2,NFM=NF2S+NF3)
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)  
      COMMON /XYZ/ X(IF),Y(JF),Z(KF),U(IF,JF,KF),V(IF,JF,KF,3)
      COMMON /EL/EL(NFM,3,3)
      COMMON /USURF/USURF(NFM,3)
      DIMENSION NP(NFM,3,3),NPIN(NFM,3,3)
      DIMENSION NXR(IF,JF,KF),NXL(IF,JF,KF)
      DIMENSION NYR(IF,JF,KF),NYL(IF,JF,KF)
      DIMENSION NZR(IF,JF,KF),NZL(IF,JF,KF)
      DIMENSION INNC(IF,JF,KF)
      DIMENSION INNER(IF,JF,KF)
      DIMENSION ALPHAR(IF,JF,KF),ALPHAL(IF,JF,KF),BETAR(IF,JF,KF),
     &          BETAL(IF,JF,KF),GAMMAR(IF,JF,KF),GAMMAL(IF,JF,KF)
C
      DATA F,OMEGA/0.0,1.5/
      DATA A,B,C,D/0.3,0.05,0.3,0.0/
      DATA XXX,YYY,ZZZ/2.0,2.0,2.0/
      DATA UINFTY,USIDE,UOUT,UBOUND/1000,20.0,20.0,20.0/
      DATA CK1,CK2/1000.0,1.0/
      DATA NAMAX/500/
C
C
      IC=(IF+1)/2
      JC=(JF+1)/2
      KC=(KF+1)/2
C
      DO I=1,IF
        X(I)=XXX*FLOAT(I-IC)/FLOAT(IF-1)+0.02
      ENDDO
      DO J=1,JF
        Y(J)=YYY*FLOAT(J-JC)/FLOAT(JF-1)+0.02
      ENDDO
      DO K=1,KF
        Z(K)=ZZZ*FLOAT(K-KC)/FLOAT(KF-1)+0.02
      ENDDO
C
      open(2, file='KIRETU1.DAT', status='unknown',blank='null')
      read(2,*) NF0
      read(2,'(7F12.7)') (((EL(N,J,K),N=1,NF),J=1,3),K=1,3)
      CLOSE(2)
      open(2, file='KIRETU2.DAT', status='unknown',blank='null')
      read(2,*) NF0
      read(2,'(7F12.7)') (((EL(N,J,K),N=NF+1,NF2S),J=1,3),K=1,3)
      CLOSE(2)
      open(2, file='KIRETU3.DAT', status='unknown',blank='null')
      read(2,*) NF0
      read(2,'(7F12.7)') (((EL(N,J,K),N=NF2S+1,NFM),J=1,3),K=1,3)
      CLOSE(2)
C
      XMAX=-10000.D0
      YMAX=-10000.D0
      ZMAX=-10000.D0
      XMIN=10000.D0
      YMIN=10000.D0
      ZMIN=10000.D0
      DO J=1,3
      DO N=1,NFM
      XMAX=MAX(XMAX,EL(N,J,1))
      YMAX=MAX(YMAX,EL(N,J,2))
      ZMAX=MAX(ZMAX,EL(N,J,3))
      XMIN=MIN(XMIN,EL(N,J,1))
      YMIN=MIN(YMIN,EL(N,J,2))
      ZMIN=MIN(ZMIN,EL(N,J,3))
      ENDDO
      ENDDO
      WRITE(6,*) XMAX,YMAX,ZMAX
      WRITE(6,*) XMIN,YMIN,ZMIN
      DO J=1,3
      DO N=1,NFM
      EL(N,J,1)=EL(N,J,1)-(XMAX+XMIN)*0.5D0
      EL(N,J,2)=EL(N,J,2)-(YMAX+YMIN)*0.5D0
      EL(N,J,3)=EL(N,J,3)-(ZMAX+ZMIN)*0.5D0
      ENDDO
      ENDDO
      DO K=1,3
      DO J=1,3
      DO N=1,NFM
      EL(N,J,K)=EL(N,J,K)*1.5D0/(XMAX-XMIN)
      ENDDO
      ENDDO
      ENDDO
C
      WRITE(6,*) 'CHECK 1'
C
      DO K=1,KF
      DO J=1,IF
      DO I=1,IF
      ALPHAR(I,J,K)=1.0
      ALPHAL(I,J,K)=1.0
      BETAR(I,J,K)=1.0
      BETAL(I,J,K)=1.0
      GAMMAR(I,J,K)=1.0
      GAMMAL(I,J,K)=1.0
      ENDDO
      ENDDO
      ENDDO
C
      DO 101 K=1,KF
      DO 101 J=1,JF
      Y0=Y(J)
      Z0=Z(K)
      ISURF=0
C
      DO 101 N=1,NFM
      X1=EL(N,1,1)
      Y1=EL(N,1,2)
      Z1=EL(N,1,3)
      X2=EL(N,2,1)
      Y2=EL(N,2,2)
      Z2=EL(N,2,3)
      X3=EL(N,3,1)
      Y3=EL(N,3,2)
      Z3=EL(N,3,3)
C
      A21=(Z2-Z1)*(Y1+Y2-2.0*Y0)+(Y1-Y2)*(Z1+Z2-2.0*Z0)
      A32=(Z3-Z2)*(Y2+Y3-2.0*Y0)+(Y2-Y3)*(Z2+Z3-2.0*Z0)
      A31=(Z1-Z3)*(Y3+Y1-2.0*Y0)+(Y3-Y1)*(Z3+Z1-2.0*Z0)
      IF (((A21.GE.0.0).AND.(A32.GE.0.0).AND.(A31.GE.0.0)).OR.
     &    ((A21.LE.0.0).AND.(A32.LE.0.0).AND.(A31.LE.0.0))) THEN
        I=0
  100   I=I+1
            AY=Y0-Y1
            BY=Y3-Y1
            CY=Y2-Y1
            DZ=Z0-Z1
            EZ=Z3-Z1
            FZ=Z2-Z1
            X0=X1+(AY*FZ-CY*DZ)*(X3-X1)/(BY*FZ-CY*EZ)
     &           +(AY*EZ-BY*DZ)*(X2-X1)/(CY*EZ-BY*FZ)

            IF (I.LT.IF.AND.X(I).LT.X0.AND.X(I+1).GE.X0) THEN
C              WRITE(6,*) 'X(I),X0,X(I+1)',X(I),X0,X(I+1)
              XSURF=X0-X(I)
                ALPHAR(I,J,K)=XSURF/(X(I+1)-X(I))
                NXR(I,J,K)=N
            ENDIF
       IF (I.GT.1.AND.X(I).GT.X0.AND.X(I-1).LE.X0) THEN
              XSURF=X(I)-X0
                ALPHAL(I,J,K)=XSURF/(X(I)-X(I-1))
                NXL(I,J,K)=N
            ENDIF
            IF (I.LT.IF) GO TO 100
       ENDIF
  101 CONTINUE
C
C
      WRITE(6,*) 'CHECK 3'
C
C
      DO 201 K=1,KF
      DO 201 I=1,IF
      Z0=Z(K)
      X0=X(I)
C     JSURF=0
      DO 201 N=1,NFM
      X1=EL(N,1,1)
      Y1=EL(N,1,2)
      Z1=EL(N,1,3)
      X2=EL(N,2,1)
      Y2=EL(N,2,2)
      Z2=EL(N,2,3)
      X3=EL(N,3,1)
      Y3=EL(N,3,2)
      Z3=EL(N,3,3)
C
      A21=(X2-X1)*(Z1+Z2-2.0*Z0)+(Z1-Z2)*(X1+X2-2.0*X0)
      A32=(X3-X2)*(Z2+Z3-2.0*Z0)+(Z2-Z3)*(X2+X3-2.0*X0)
      A31=(X1-X3)*(Z3+Z1-2.0*Z0)+(Z3-Z1)*(X3+X1-2.0*X0)
      IF (((A21.GE.0.0).AND.(A32.GE.0.0).AND.(A31.GE.0.0)).OR.
     &    ((A21.LE.0.0).AND.(A32.LE.0.0).AND.(A31.LE.0.0))) THEN
        J=0
  200   J=J+1
            AZ=Z0-Z1
            BZ=Z3-Z1
            CZ=Z2-Z1
            DX=X0-X1
            EX=X3-X1
            FX=X2-X1 
            Y0=Y1+(AZ*FX-CZ*DX)*(Y3-Y1)/(BZ*FX-CZ*EX)
     &           +(AZ*EX-BZ*DX)*(Y2-Y1)/(CZ*EX-BZ*FX)


            IF (J.LT.JF.AND.Y(J).LT.Y0.AND.Y(J+1).GE.Y0) THEN
              YSURF=Y0-Y(J)
                BETAR(I,J,K)=YSURF/(Y(J+1)-Y(J))
                NYR(I,J,K)=N
              ENDIF
            IF (J.GT.1.AND.Y(J).GT.Y0.AND.Y(J-1).LE.Y0) THEN
              YSURF=Y(J)-Y0
                BETAL(I,J,K)=YSURF/(Y(J)-Y(J-1))
                NYL(I,J,K)=N
            ENDIF
            IF (J.LT.JF) GO TO 200
      ENDIF
  201 CONTINUE
C      ENDDO
C      ENDDO
C      ENDDO
C
C
      WRITE(6,*) 'CHECK 4'
C
C
      DO 301 J=1,JF
      DO 301 I=1,IF
      X0=X(I)
      Y0=Y(J)
C     KSURF=0
      DO 301 N=1,NFM
      X1=EL(N,1,1)
      Y1=EL(N,1,2)
      Z1=EL(N,1,3)
      X2=EL(N,2,1)
      Y2=EL(N,2,2)
      Z2=EL(N,2,3)
      X3=EL(N,3,1)
      Y3=EL(N,3,2)
      Z3=EL(N,3,3)
C
      A21=(Y2-Y1)*(X1+X2-2.0*X0)+(X1-X2)*(Y1+Y2-2.0*Y0)
      A32=(Y3-Y2)*(X2+X3-2.0*X0)+(X2-X3)*(Y2+Y3-2.0*Y0)
      A31=(Y1-Y3)*(X3+X1-2.0*X0)+(X3-X1)*(Y3+Y1-2.0*Y0)
      IF (((A21.GE.0.0).AND.(A32.GE.0.0).AND.(A31.GE.0.0)).OR.
     &    ((A21.LE.0.0).AND.(A32.LE.0.0).AND.(A31.LE.0.0))) THEN
        K=0
  300   K=K+1

            AX=X0-X1
            BX=X3-X1
            CX=X2-X1
            DY=Y0-Y1
            EY=Y3-Y1
            FY=Y2-Y1 
            Z0=Z1+(AX*FY-CX*DY)*(Z3-Z1)/(BX*FY-CX*EY)
     &         +(AX*EY-BX*DY)*(Z2-Z1)/(CX*EY-BX*FY)

            IF (K.LT.KF.AND.Z(K).LT.Z0.AND.Z(K+1).GE.Z0) THEN
              ZSURF=Z0-Z(K)
                GAMMAR(I,J,K)=ZSURF/(Z(K+1)-Z(K))
                NZR(I,J,K)=N
            ENDIF
            IF (K.GT.1.AND.Z(K).GT.Z0.AND.Z(K-1).LE.Z0) THEN
              ZSURF=Z(K)-Z0
                GAMMAL(I,J,K)=ZSURF/(Z(K)-Z(K-1))
                NZL(I,J,K)=N
            ENDIF
            IF (K.LT.KF) GO TO 300
      ENDIF
  301 CONTINUE
C      ENDDO
C      ENDDO
C      ENDDO
C
C-------------------------------------
C     Find inner points
C
      DO K=1,KF
      DO J=1,JF
      I=0
      INPT=1
    1 I=I+1
      IF (INPT.EQ.1.AND.
     &(ALPHAR(I,J,K).LT.1.0).AND.(ALPHAL(I+1,J,K).LT.1.0)) THEN
      INPT=2
      ELSEIF (INPT.EQ.2.AND.
     &(ALPHAR(I,J,K).LT.1.0).AND.(ALPHAL(I+1,J,K).LT.1.0)) THEN
      INPT=1
      ENDIF
      IF (INPT.EQ.2) THEN
C     WRITE(6,*) 'I,J,K=',I,J,K
      INNER(I+1,J,K)=0
      ENDIF
      IF (I.LT.IF-1) GO TO 1
      ENDDO
      ENDDO
      DO K=1,KF
      DO J=1,JF
      DO I=1,IF
      INNC(I,J,K)=INNER(I,J,K)
      INNER(I,J,K)=1
      ENDDO
      ENDDO
      ENDDO
C
      DO K=1,KF
      DO I=1,IF
      J=0
      INPT=1
    2 J=J+1
      IF (INPT.EQ.1.AND.
     &(BETAR(I,J,K).LT.1.0).AND.(BETAL(I,J+1,K).LT.1.0)) THEN
      INPT=2
      ELSEIF (INPT.EQ.2.AND.
     &(BETAR(I,J,K).LT.1.0).AND.(BETAL(I,J+1,K).LT.1.0)) THEN
      INPT=1
      ENDIF
      IF (INPT.EQ.2) THEN
      INNER(I,J+1,K)=0
      ENDIF
      IF (J.LT.JF-1) GO TO 2
      ENDDO
      ENDDO
C
      DO K=1,KF
      DO J=1,JF
      DO I=1,IF
      INNC(I,J,K)=INNC(I,J,K)+INNER(I,J,K)
      INNER(I,J,K)=1
      ENDDO
      ENDDO
      ENDDO
C
      DO J=1,JF
      DO I=1,IF
      K=0
      INPT=1
    3 K=K+1
      IF (INPT.EQ.1.AND.
     &(GAMMAR(I,J,K).LT.1.0).AND.(GAMMAL(I,J,K+1).LT.1.0)) THEN
      INPT=2
      ELSEIF (INPT.EQ.2.AND.
     &(GAMMAR(I,J,K).LT.1.0).AND.(GAMMAL(I,J,K+1).LT.1.0)) THEN
      INPT=1
      ENDIF
      IF (INPT.EQ.2) THEN
      INNER(I,J,K+1)=0
      ENDIF
      IF (K.LT.KF-1) GO TO 3
      ENDDO
      ENDDO
C
      DO K=1,KF
      DO J=1,JF
      DO I=1,IF
      INNC(I,J,K)=INNC(I,J,K)+INNER(I,J,K)
      ENDDO
      ENDDO
      ENDDO
      DO K=1,KF
      DO J=1,JF
      DO I=1,IF
      INNER(I,J,K)=MIN(1,(INNC(I,J,K)*3)/3)
      ENDDO
      ENDDO
      ENDDO
C
C-------------------------------------
C     Find most neighboring point to the surface
C
      DO M=1,3
      DO N=1,NFM
      DLMIN=10000.0
      DLMININ=10000.0
      XL=EL(N,M,1)
      YL=EL(N,M,2)
      ZL=EL(N,M,3)
      IC=1+INT(FLOAT(IF-1)*(XL+1.0D0)/2.0D0)
      JC=1+INT(FLOAT(JF-1)*(YL+1.0D0)/2.0D0)
      KC=1+INT(FLOAT(KF-1)*(ZL+1.0D0)/2.0D0)
C     IF (M.EQ.1.AND.MOD(N,10).EQ.0) THEN
C     write(6,*) 'N=',N,'IC=',IC,'JC=',JC,'KC=',KC
C     ENDIF
      DO K=MAX(1,KC-5),MIN(KF,KC+5)
      DO J=MAX(1,JC-5),MIN(JF,JC+5)
      DO I=MAX(1,IC-5),MIN(IF,IC+5)
      DLX=X(I)-XL
      DLY=Y(J)-YL
      DLZ=Z(K)-ZL
      DL=SQRT(DLX*DLX+DLY*DLY+DLZ*DLZ)
      IF (INNER(I,J,K).EQ.1.AND.DL.LT.DLMIN) THEN
C     IF (M.EQ.1.AND.MOD(N,10).EQ.0) THEN
C     write(6,*) 'N=',N,'I=',I,'J=',J,'K=',K
C     ENDIF
      DLMIN=DL
      IMIN=I
      JMIN=J
      KMIN=K
      ENDIF
      IF (INNER(I,J,K).EQ.0.AND.DL.LT.DLMININ) THEN
C     IF (M.EQ.1.AND.MOD(N,10).EQ.0) THEN
C     write(6,*) 'N=',N,'I=',I,'J=',J,'K=',K
C     ENDIF
      DLMININ=DL
      IMININ=I
      JMININ=J
      KMININ=K
      ENDIF
      ENDDO
      ENDDO
      ENDDO
      NP(N,M,1)=IMIN
      NP(N,M,2)=JMIN
      NP(N,M,3)=KMIN
      NPIN(N,M,1)=IMININ
      NPIN(N,M,2)=JMININ
      NPIN(N,M,3)=KMININ
      ENDDO
      ENDDO
C
      DO K=1,KF
      DO J=1,JF
      DO I=1,IF
        U(I,J,K)=USIDE
      ENDDO
      ENDDO
      ENDDO
C
C
      DO J=1,JF
      DO I=1,IF
        U(I,J,1)=USIDE
        U(I,J,KF)=USIDE
      ENDDO
      ENDDO
C
      DO K=1,KF
      DO I=1,IF
        U(I,1,K)=USIDE
        U(I,JF,K)=USIDE
      ENDDO
      ENDDO
C
      DO K=1,KF
      DO J=1,JF
        U(1,J,K)=UINFTY
        U(IF,J,K)=UOUT
      ENDDO
      ENDDO
C
      WRITE(6,*) 'CHECK 5'
C
C
      NA=0
   10 NA=NA+1
      RMAX=0.0
C
      DO II=2,IF-1
      I=II
      IF (MOD(NA,2).EQ.0) I=IF+1-I
      DO JJ=1,JF
      J=JJ
      IF (MOD(NA,2).EQ.0) J=JF+1-J
      DO KK=1,KF
      K=KK
      IF (MOD(NA,2).EQ.0) K=KF+1-K
C
      IM1=I-1
C     IF (I.EQ.1) IM1=2
      IP1=I+1
C     IF (I.EQ.IF) IP1=IF-1
      JM1=J-1
      IF (J.EQ.1) JM1=2
      JP1=J+1
      IF (J.EQ.JF) JP1=JF-1
      KM1=K-1
      IF (K.EQ.1) KM1=2
      KP1=K+1
      IF (K.EQ.KF) KP1=KF-1
C
      UCENTER=U(I,J,K)
      UIP=U(IP1,J,K)
      UIM=U(IM1,J,K)
      UJP=U(I,JP1,K)
      UJM=U(I,JM1,K)
      UKP=U(I,J,KP1)
      UKM=U(I,J,KM1)
C
      INXYZ=INNER(I,J,K)
      ALR=ALPHAR(I,J,K)
      ALL=ALPHAL(I,J,K)
      BER=BETAR(I,J,K)
      BEL=BETAL(I,J,K)
      GAR=GAMMAR(I,J,K)
      GAL=GAMMAL(I,J,K)
      IF (INXYZ.EQ.1) THEN
      CKXL=ALL*(CK1-CK2)+CK2
      CKXR=ALR*(CK1-CK2)+CK2
      CKYL=BEL*(CK1-CK2)+CK2
      CKYR=BER*(CK1-CK2)+CK2
      CKZL=GAL*(CK1-CK2)+CK2
      CKZR=GAR*(CK1-CK2)+CK2
      ENDIF
      IF (INXYZ.EQ.0) THEN
      CKXL=ALL*(CK2-CK1)+CK1
      CKXR=ALR*(CK2-CK1)+CK1
      CKYL=BEL*(CK2-CK1)+CK1
      CKYR=BER*(CK2-CK1)+CK1
      CKZL=GAL*(CK2-CK1)+CK1
      CKZR=GAR*(CK2-CK1)+CK1
      ENDIF
      DXR=ABS(X(IP1)-X(I))
      DXL=ABS(X(I)-X(IM1))
      DYR=ABS(Y(JP1)-Y(J))
      DYL=ABS(Y(J)-Y(JM1))
      DZR=ABS(Z(KP1)-Z(K))
      DZL=ABS(Z(K)-Z(KM1))
      XFRAC=(DXR+DXL)*0.5
      YFRAC=(DYR+DYL)*0.5
      ZFRAC=(DZR+DZL)*0.5
      DFDX=CKXR*(UIP-UCENTER)/DXR-CKXL*(UCENTER-UIM)/DXL
      DFDY=CKYR*(UJP-UCENTER)/DYR-CKYL*(UCENTER-UJM)/DYL
      DFDZ=CKZR*(UKP-UCENTER)/DZR-CKZL*(UCENTER-UKM)/DZL
      RESIDUE=2.0D0*(DFDX/XFRAC+DFDY/YFRAC+DFDZ/ZFRAC)
      C0=2.0*(1.0/(DXR*DXL)*(CKXL+CKXR)
     &       +1.0/(DYR*DYL)*(CKYR+CKYL)
     &       +1.0/(DZR*DZL)*(CKZR+CKZL))
      U(I,J,K)=U(I,J,K)+OMEGA*RESIDUE/C0
      DXLR=DXL/DXR
      DYLR=DYL/DYR
      DZLR=DZL/DZR
      V(I,J,K,1)=((UIP-UCENTER)*DXLR+(UCENTER-UIM)/DXLR)/XFRAC
      V(I,J,K,2)=((UJP-UCENTER)*DYLR+(UCENTER-UJM)/DYLR)/YFRAC
      V(I,J,K,3)=((UKP-UCENTER)*DZLR+(UCENTER-UKM)/DZLR)/ZFRAC
      RMAX=MAX(RMAX,ABS(RESIDUE))
C
      ENDDO
      ENDDO
      ENDDO
C
      FIJKF=FLOAT(IF*JF*KF)
C     IF (NA.EQ.1) RMAX1=RMAX
C     RMAX=RMAX/RMAX1
      WRITE(6,20) NA, RMAX/FIJKF
      OPEN(11,FILE='OUTPUT.DAT', STATUS='UNKNOWN', BLANK='NULL')
      WRITE(11,20) NA,RMAX/FIJKF
      CLOSE(11)
   20 FORMAT(5X,'NA=',I3,5X,'RMAX=',F12.9)
C
      IF (NA.LT.NAMAX .AND.RMAX.GT.1.0D-7) GO TO 10
C
      DO M=1,3
      DO N=1,NFM
      USURF(N,M)=(U(NP(N,M,1),NP(N,M,2),NP(N,M,3))
     &           +U(NPIN(N,M,1),NPIN(N,M,2),NPIN(N,M,3)))*0.5
      ENDDO
      ENDDO
C
      OPEN(11,FILE='MKIRETU.DAT',FORM='UNFORMATTED')
      CALL FIELDVIEW1
      CLOSE(11)
      OPEN(11,FILE='OKIRETU1.DAT',FORM='UNFORMATTED')
      CALL FIELDVIEW2(1,NF)
      CLOSE(11)
      OPEN(11,FILE='OKIRETU2.DAT',FORM='UNFORMATTED')
      CALL FIELDVIEW2(NF+1,NF2S)
      CLOSE(11)
      OPEN(11,FILE='OKIRETU3.DAT',FORM='UNFORMATTED')
      CALL FIELDVIEW2(NF2S+1,NFM)
      CLOSE(11)
  111  FORMAT(7I9)
  112  FORMAT(7F10.5)
C
      STOP
      END
C
      SUBROUTINE FIELDVIEW1
      PARAMETER (IF=51,JF=51,KF=51)
      PARAMETER (NFU=(IF-1)*(JF-1)*(KF-1))
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      COMMON /XYZ/ X(IF),Y(JF),Z(KF),U(IF,JF,KF),V(IF,JF,KF,3)
      DIMENSION NODE(IF,JF,KF),NU(NFU,8)
C
      DO K=1,KF
      DO J=1,JF
      DO I=1,IF
      NODE(I,J,K)=I+ IF*(J-1) + IF*JF*(K-1)
      ENDDO
      ENDDO
      ENDDO
C
      DO K=1,KF-1
      DO J=1,JF-1
      DO I=1,IF-1
      N=I+(IF-1)*(J-1)+(IF-1)*(JF-1)*(K-1)
      NU(N,1)=NODE(I,J,K)
      NU(N,2)=NODE(I+1,J,K)
      NU(N,3)=NODE(I,J,K+1)
      NU(N,4)=NODE(I+1,J,K+1)
      NU(N,5)=NODE(I,J+1,K)
      NU(N,6)=NODE(I+1,J+1,K)
      NU(N,7)=NODE(I,J+1,K+1)
      NU(N,8)=NODE(I+1,J+1,K+1)
      ENDDO
      ENDDO
      ENDDO
      WRITE(11,600) 'FIELDVIEW 1 1'
      WRITE(11,600) 'Boundary Table'
      WRITE(11,601) 0
      WRITE(11,*)
      WRITE(11,600) 'Variable Names'
      WRITE(11,601) 4
      WRITE(11,600) 'U-Velocity; Velocity'
      WRITE(11,600) 'V-Velocity'
      WRITE(11,600) 'W-Velocity'
      WRITE(11,600) 'Pressure'
      WRITE(11,*)
      WRITE(11,600) 'Nodes'
      WRITE(11,601) IF*JF*KF
C
      DO K=1,KF
      DO J=1,JF
      DO I=1,IF
      WRITE(11,*) REAL(X(I)),REAL(Y(J)),
     &            REAL(Z(K))
      ENDDO
      ENDDO
      ENDDO
C
      WRITE(11,*)
      WRITE(11,600) 'Boundary Faces'
      WRITE(11,*) 0
      WRITE(11,*)
      WRITE(11,600) 'Elements'
      DO N=1,NFU
      WRITE(11,*) 2,1,NU(N,1),NU(N,2),NU(N,3),
     &NU(N,4),NU(N,5),NU(N,6),NU(N,7),NU(N,8)
      ENDDO
      WRITE(11,*)
      WRITE(11,600) 'Variables'
      WRITE(11,*) REAL(V)
      WRITE(11,*) REAL(U)
  600 FORMAT(A)
  601 FORMAT(I8)
      RETURN
      END
C
      SUBROUTINE FIELDVIEW2(NSTR,NEND)
      PARAMETER (IF=51,JF=51,KF=51)
      PARAMETER (NF=224,NF2=224,NF3=224)
      PARAMETER (NF2S=NF+NF2,NFM=NF2S+NF3)
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      COMMON /EL/EL(NFM,3,3)
      COMMON /USURF/USURF(NFM,3)
      DIMENSION VSURF(NFM,3)
      DO M=1,3
      DO N=1,NFM
      VSURF(N,M)=0.0D0
      ENDDO
      ENDDO
C
      NNF=NEND-NSTR+1
      WRITE(11,600) 'FIELDVIEW 1 1'
      WRITE(11,600) 'Boundary Table'
      WRITE(11,601) 1
      WRITE(11,600) '1 wall boundary'
      WRITE(11,*)
      WRITE(11,600) 'Variable Names'
      WRITE(11,601) 4
      WRITE(11,600) 'U-Velocity; Velocity'
      WRITE(11,600) 'V-Velocity'
      WRITE(11,600) 'W-Velocity'
      WRITE(11,600) 'Pressure'
      WRITE(11,*)
      WRITE(11,600) 'Nodes'
      WRITE(11,601) 6*NNF
      DO N=NSTR,NEND
      WRITE(11,*) REAL(EL(N,1,1)),REAL(EL(N,1,2)),
     &            REAL(EL(N,1,3))
      WRITE(11,*) REAL(EL(N,1,1)),REAL(EL(N,1,2)),
     &            REAL(EL(N,1,3))
      WRITE(11,*) REAL(EL(N,2,1)),REAL(EL(N,2,2)),
     &            REAL(EL(N,2,3))
      WRITE(11,*) REAL(EL(N,2,1)),REAL(EL(N,2,2)),
     &            REAL(EL(N,2,3))
      WRITE(11,*) REAL(EL(N,3,1)),REAL(EL(N,3,2)),
     &            REAL(EL(N,3,3))
      WRITE(11,*) REAL(EL(N,3,1)),REAL(EL(N,3,2)),
     &            REAL(EL(N,3,3))
      ENDDO
      WRITE(11,*)
      WRITE(11,600) 'Boundary Faces'
      WRITE(11,601) NNF
      DO N=1,NNF
      WRITE(11,*) 1,3,1+(N-1)*6,4+(N-1)*6,6+(N-1)*6
      ENDDO
      WRITE(11,*)
      WRITE(11,600) 'Elements'
      DO N=1,NNF
      WRITE(11,*) 3,1,1+(N-1)*6,2+(N-1)*6,3+(N-1)*6,
     &           4+(N-1)*6,5+(N-1)*6,6+(N-1)*6
      ENDDO
      WRITE(11,*)
      WRITE(11,600) 'Variables'
      DO NN=1,3
      DO N=NSTR,NEND
      WRITE(11,*) REAL(VSURF(N,1)),REAL(VSURF(N,1)),
     &            REAL(VSURF(N,2)),REAL(VSURF(N,2)),
     &            REAL(VSURF(N,3)),REAL(VSURF(N,3))
      ENDDO
      ENDDO
      DO N=NSTR,NEND
      WRITE(11,*) REAL(USURF(N,1)),REAL(USURF(N,1)),
     &            REAL(USURF(N,2)),REAL(USURF(N,2)),
     &            REAL(USURF(N,3)),REAL(USURF(N,3))
      ENDDO
  600 FORMAT(A)
  601 FORMAT(I5)
      RETURN
      END
