C PROGRAM INV4 TO SUBTRACT TWO SETS OF GRID VALUES OF A FUNCTION
C DESCRIBING THE MODEL:  GRID1-GRID2=GRID3.
C
C MAIN INPUT DATA FILE READ FROM THE INTERACTIVE DEVICE (*):
C (1) 'GRID1','GRID2','GRID3',/
C     'GRID1','GRID2','GRID3'... NAMES OF THE INPUT AND OUTPUT
C             FILES DESCRIBED BELOW.
C     /...    OBLIGATORY SLASH TO ENABLE FUTURE COMPATIBLE EXTENSIONS.
C     DEFAULT: 'GRID3'='DIF.OUT'.
C
C INPUT FILES 'GRID1','GRID2':
C (1) TEXTG,IGROUP
C     IDENTIFICATION OF THE GROUP.
C     TEXTG...A STRING.  IF ITS FIRST CHARACTER IS 'I' OR 'S', THE
C             COMPUTED FUNCTION DESCRIBES A SURFACE.  OTHERWISE, IT
C             DESCRIBES A MATERIAL PARAMETER.
C     IGROUP..INDEX OF A SURFACE, OR OF A COMPLEX BLOCK.
C (2) TEXTF
C     THIS INPUT IS NOT PERFORMED FOR A SURFACE, I.E. IF THE FIRST
C     CHARACTER OF TEXTG (SEE ABOVE) IS 'I' OR 'S'.
C     TEXTF...STRING IDENTIFYING A MATERIAL PARAMETER.
C (3) K1,K2,K3
C     K1,K2,K3... INDICES OF COORDINATES.
C (4) N1,N2,N3
C     N1,N2,N3... NUMBERS OF GRID LINES.
C (5) X1(1),...,X1(N1)
C     THE GRID COORDINATES CORRESPONDING TO THE FIRST INDEPENDENT
C     VARIABLE.
C (6) X2(1),...,X2(N2)
C     THE GRID COORDINATES CORRESPONDING TO THE SECOND INDEPENDENT
C     VARIABLE.
C (7) X3(1),...,X3(N3)
C     THE GRID COORDINATES CORRESPONDING TO THE THIRD INDEPENDENT
C     VARIABLE.
C (8) (((W(I1,I2,I3),I1=1,N1),I2=1,N2),I3=1,N3)
C     THE VALUES OF FUNCTION W AT GRID POINTS. FUNCTION VALUE
C     W(I1,I2,I3) CORRESPONDS TO POINT (X1(I1),X2(I2),X3(I3)).
C
C OUTPUT FILE 'GRID3':
C (1) 'DIFFERENCES ............................' (A STRING)
C (2) (((D(I1,I2,I3),I1=1,N1),I2=1,N2),I3=1,N3)
C     DIFFERENCES OF FUNCTION VALUES.
C
C DATE: 1992, DECEMBER 31
C CODED BY LUDEK KLIMES
C
C-----------------------------------------------------------------------
C
C     FILENAMES:
      CHARACTER*80 FILE1,FILE2,FILE3
C
C     LOGICAL UNIT NUMBERS:
      INTEGER LU1,LU2,LU3
      PARAMETER (LU1=11)
      PARAMETER (LU2=12)
      PARAMETER (LU3=13)
C
C     AUXILIARY STORAGE LOCATIONS:
      CHARACTER*3 TEXT
      INTEGER MX
      PARAMETER (MX=100)
      INTEGER ICB,K1,K2,K3,N1,N2,N3,I1,I2,I3
      REAL X(MX,3),V1(MX),V2(MX)
C
C.......................................................................
C
C     OPENING DATA FILES AND READING THE INPUT DATA:
      WRITE(*,'(A)') ' ENTER NAMES OF INPUT AND OUTPUT FILES: '
      FILE1=' '
      FILE2=' '
      FILE3='DIF.OUT'
      READ(*,*) FILE1,FILE2,FILE3
      OPEN(LU1,FILE=FILE1,STATUS='OLD')
      OPEN(LU2,FILE=FILE2,STATUS='OLD')
      OPEN(LU3,FILE=FILE3)
      WRITE(*,'(A)') '+                                       '
C
      READ(LU1,*) TEXT,ICB
      READ(LU2,*) TEXT,I2
      IF(ICB.NE.I2) THEN
        PAUSE 'ERROR: DIFFERENT INDEX OF A FUNCTION'
        STOP
      END IF
      IF(TEXT(1:1).NE.'I'.AND.TEXT(1:1).NE.'S') THEN
        READ(LU1,*) TEXT
        READ(LU2,*) TEXT
      END IF
      READ(LU1,*) K1,K2,K3
      READ(LU2,*) I1,I2,I3
      IF(K1.NE.I1.OR.K2.NE.I2.OR.K3.NE.I3) THEN
        PAUSE 'ERROR: DIFFERENT INDICES OF COORDINATES'
        STOP
      END IF
      READ(LU1,*) N1,N2,N3
      READ(LU2,*) I1,I2,I3
      IF(N1.NE.I1.OR.N2.NE.I2.OR.N3.NE.I3) THEN
        PAUSE 'ERROR: DIFFERENT NUMBERS OF GRID LINES'
        STOP
      END IF
      IF(MAX0(N1,N2,N3).GT.MX) THEN
        PAUSE 'ERROR: TOO MANY GRID LINES'
        STOP
      END IF
      READ(LU1,*) (X(I1,K1),I1=1,N1)
      READ(LU2,*) (X(I1,K1),I1=1,N1)
      READ(LU1,*) (X(I2,K2),I2=1,N2)
      READ(LU2,*) (X(I2,K2),I2=1,N2)
      READ(LU1,*) (X(I3,K3),I3=1,N3)
      READ(LU2,*) (X(I3,K3),I3=1,N3)
      WRITE(LU3,'(A)') '''DIFFERENCES ............................'''
      DO 23 I3=1,N3
        DO 22 I2=1,N2
          READ(LU1,*) (V1(I1),I1=1,N1)
          READ(LU2,*) (V2(I1),I1=1,N1)
          DO 21 I1=1,N1
            V1(I1)=V1(I1)-V2(I1)
   21     CONTINUE
          WRITE(LU3,'(8F10.6)') (V1(I1),I1=1,N1)
   22   CONTINUE
        IF(N1.NE.1.AND.N2.NE.1) WRITE(LU3,*)
   23 CONTINUE
C
      STOP
      END
C
C=======================================================================
C
