C*****************************************************************
C
C Written by Victor De Pinto
C Revised Jan. 12, 1982
C
      PROGRAM ARIT
      LOGICAL FN1(11), FN2(11), FN3(11)
      DIMENSION DAT1 (2,1024), DAT2 (2,1024)
1     WRITE (1,2)
2     FORMAT (/' --ARITHMETIC FUNCTIONS MENU--'/
     X        ' This routine performs arithmetic functions on one'/
     X        ' or more source files and puts the result in the'/
     X        ' destination file. Select function:'/
     X ' 1  SUM FILES'/
     X ' 2  SUBTRACT SOURCE 2 FROM SOURCE 1'/
     X ' 3  MULTIPLY FILES'/
     X ' 4  DIVIDE SOURCE 1 BY SOURCE 2'/
     X ' 5  MULTIPLY FILE BY A CONSTANT'/
     X ' 6  CONJUGATE OF FILE'/
     X ' 7  MAGNITUDE SQUARED OF A FILE'/
     X ' 8  BACK TO MAIN MENU >> ')
6     FORMAT (' Source filename 1,')
5     FORMAT (' Source filename 2,')
7     FORMAT (' Destination filename,')
      READ (1,4) ICOM
4     FORMAT (I2)
      GO TO (3,3,3,3,60,60,60,999), ICOM
      GO TO 999
C READ ONE SOURCE FILE
60    WRITE (1,61)
61    FORMAT (' Source filename,')
      CALL NAME ( FN1 )
      WRITE (1,7)
      CALL NAME (FN3)
      CALL OPEN (3, FN1, 0)
      READ (3) DAT1
      ENDFILE 3
      GO TO (1,1,1,1,80,90,100,1), ICOM
C READ TWO SOURCE FILES
3     WRITE (1,6)
      CALL NAME( FN1 )
      WRITE (1,5)
      CALL NAME ( FN2 )
      WRITE (1,7)
      CALL NAME ( FN3 )
      CALL OPEN (3, FN1, 0)
      CALL OPEN (4, FN2, 0)
      READ (3) DAT1
      READ (4) DAT2
      ENDFILE 3
      ENDFILE 4
      GO TO (20,70,30,50,1,1,1,1), ICOM
C DIVIDE DAT1 BY DAT2. RESULT IN DAT2
50    DO 55 K=1,1024
      A = DAT1(1,K)
      B = DAT1(2,K)
      C = DAT2(1,K)
      D = DAT2(2,K)
      DEN = C**2 + D**2
      DAT2(1,K) = (A*C + B*D) / DEN
55    DAT2(2,K) = (B*C - A*D) / DEN
      GO TO 40
C SUM DAT1 + DAT2. RESULT IN DAT2.
20    DO 22 K=1,1024
      DAT2(1,K) = DAT1(1,K) + DAT2(1,K)
22    DAT2(2,K) = DAT1(2,K) + DAT2(2,K)
      GO TO 40
C MULTIPLY DAT1 X DAT2. RESULT IN DAT2.
30    DO 34 K=1,1024
      A = DAT1(1,K)
      B = DAT1(2,K)
      C = DAT2(1,K)
      D = DAT2(2,K)
      DAT2(1,K) = A*C - B*D
34    DAT2(2,K) = B*C + A*D
      GO TO 40
C SUBTRACT DAT2 FROM DAT1. RESULT IN DAT2.
70    DO 73 K=1,1024
      DAT2(1,K) = DAT1(1,K) - DAT2(1,K)
73    DAT2(2,K) = DAT1(2,K) - DAT2(2,K)
      GO TO 40
C MULTIPLY DAT1 BY A CONSTANT. RESULT IN DAT2.
80    WRITE (1,82)
82    FORMAT (' Enter the constant multiplier:')
      READ (1,84) C
84    FORMAT (F10.0)
      DO 86 K=1,1024
      DAT2(1,K) = DAT1(1,K) * C
86    DAT2(2,K) = DAT1(2,K) * C
      GO TO 40
C COMPLEX CONJUGATE OF DAT1. RESULT IN DAT2.
90    DO 95 K=1,1024
      DAT2(1,K) = DAT1(1,K)
95    DAT2(2,K) = -DAT1(2,K)
      GO TO 40
C MAGNITUDE SQUARED OF DAT1. RESULT IN DAT2.
100   DO 105 K=1,1024
      DAT2(2,K) = 0.0
105   DAT2(1,K) = DAT1(1,K)**2 + DAT1(2,K)**2
      GO TO 40
C WRITE DAT2 TO DISK AND GO TO MENU.
40    CALL OPEN (5, FN3, 0)
      WRITE (5) DAT2
      ENDFILE 5
      GO TO 1
C DONE. CHAIN BACK TO UTILITY.
999   CALL FCHAIN ( 'UTIL    COM', 0 )
      E  N  D
