C*********************************************************************
C
C 1024 point signal processing utility program.
C
C Written by Victor De Pinto, 1979, 1980, 1981, 1982.
C Revised Jan. 27, 1982
C
      PROGRAM UTIL
      LOGICAL FN1(11), FN2(11), FLG
      DIMENSION DAT(2,1024)
      DATA FLG / .FALSE. /
      WRITE (1,2)
2     FORMAT (' Signal Processing Utility.  By Victor De Pinto.
     X  Jan. 27, 1982'//)
1     WRITE (1,100)
100   FORMAT (' --MAIN MENU--  Select function:'/
     X ' 1  WRITE FILE TO CRT'/
     X ' 2  CREATE REAL PULSE FILE'/
     X ' 3  WINDOW FUNCTIONS (MENU)'/
     X ' 4  ARITHMETIC FUNCTIONS (MENU)'/
     X ' 5  PRINT FILE ON PRINTER'/
     X ' 6  RMS VALUE OF REAL PARTS OF FILE'/
     X ' 7  MODIFY FILE'/
     X ' 8  TRANSLATE'/
     X ' 9  PLOT FUNCTIONS (MENU)'/
     X ' 10 RETURN TO OPERATING SYSTEM >> ' )
      READ (1,111) J
111   FORMAT (I2)
      GO TO (200,300,650,700,205,800,850,450,250,9999),J
      GO TO 1
C
C WRITE FILE TO CONSOLE
C
200   L = 1
      GO TO 209
C
C WRITE FILE TO LIST DEVICE
C
205   L = 2
C
209   WRITE (1,210)
210   FORMAT (' Data is printed point by point: Real and imaginary.'/
     x        ' To abort printout, type "Q" on console.'/
     x        ' ENTER INDEX OF FIRST POINT TO BE PRINTED: ')
      READ (1,211) IFIRST
211   FORMAT (I4)
      CALL READ ( DAT )
      DO 220 J=IFIRST,1023,3
      IF ( FLG ) GO TO 220
      IF (J .EQ. 1022) GO TO 212
      IF (J .EQ. 1023) GO TO 213
      WRITE (L,221) J, DAT(1,J+1), DAT(2,J+1), DAT(1,J+2), DAT(2,J+2),
     x DAT(1,J+3), DAT(2,J+3)
      GO TO 215
212   WRITE (L,221) J, DAT(1,J+1), DAT(2,J+1), DAT(1,J+2), DAT(2,J+2)
      GO TO 215
213   WRITE (L,221) J, DAT(1,J+1), DAT(2,J+1)
215   CALL QCHEK ( FLG )
220   CONTINUE
      FLG = .FALSE.
221   FORMAT (' ', I4, ': ', 6G12.4)
      IF (L .EQ. 2) GO TO 225
      WRITE (1,222)
222   FORMAT (' HIT RETURN FOR MENU')
      READ (1,111) J
      GO TO 1
225   WRITE (L,226)
226   FORMAT (' ')
      WRITE (1,226)
      GO TO 1
C
C CREATE A PULSE FILE
C
300   WRITE (1,10)
10    FORMAT (' This routine creates a file containing a real
     X pulse function.'/
     X        ' Index values range from 0 through 1023.')
      WRITE (1,7)
7     FORMAT (' ENTER FIRST INDEX OF PULSE: ')
      READ (1,8) ISTART
8     FORMAT (I4)
      WRITE (1,9)
9     FORMAT ('+ENTER LAST INDEX OF PULSE: ')
      READ (1,8) IEND
      WRITE (1,13)
13    FORMAT ('+ENTER AMPLITUDE: ')
      READ (1,6) SCALE
6     FORMAT (F10.0)
      DO 14 J=1,ISTART
      DAT(1,J) = 0.0
14    DAT(2,J) = 0.0
      DO 15 J=IEND,1024
      DAT(1,J) = 0.0
15    DAT(2,J) = 0.0
      DO 11 J=ISTART,IEND
      DAT(2,J+1) = 0.0
11    DAT(1,J+1) = SCALE
      WRITE (1,852)
      CALL NAME ( FN1 )
      CALL OPEN (3, FN1, 0)
      WRITE (3) DAT
      ENDFILE 3
      GO TO 1
C
C WINDOW
C
650   CALL WIND ( DAT )
      GO TO 1
C
C ARITHMETIC OPERATIONS TO FILES
C
700   CALL FCHAIN ( 'ARIT    COM', 0 )
      GO TO 1
C
C PLOTTING FUNCTIONS
C
250   CALL PLOT ( DAT )
      GO TO 1
C
C COMPUTE THE RMS LEVEL OF REAL PART OF A FILE
C
800   WRITE (1,801)
801   FORMAT (' THIS ROUTINE COMPUTES THE R.M.S. LEVEL
     X OF THE REAL PARTS OF A FILE.')
      CALL READ ( DAT )
      SUM=0.0
      DO 810 J=1,1024
810   SUM=SUM+DAT(1,J)**2
      RMS=SQRT( SUM/1024.0)
      WRITE (1,815) RMS
815   FORMAT (//' ** THE RMS LEVEL IS ', G14.7,' **'/)
      GO TO 1
C
C MODIFY CONTENTS OF A FILE
C
850   WRITE (1,851)
851   FORMAT (' Source filename,')
      CALL NAME ( FN1 )
      WRITE (1,852)
852   FORMAT (' Destination filename,')
      CALL NAME ( FN2 )
      CALL OPEN (3, FN1, 0)
      READ (3) DAT
      ENDFILE 3
854   WRITE (1,855)
855   FORMAT (' What point? (Back to menu if negative) ')
      READ (1,860) J
860   FORMAT (I4)
      IF (J.LT.0) GO TO 870
      WRITE (1,862) DAT(1,J+1), DAT(2,J+1)
862   FORMAT (' Present value is', 2G15.7)
      WRITE (1,865)
865   FORMAT (' ENTER REAL PART <CR> IMAGINARY PART:'/)
      READ (1,6) DAT(1,J+1), DAT(2,J+1)
      GO TO 854
870   CALL OPEN (3, FN2, 0)
      WRITE (3) DAT
      ENDFILE 3
      GO TO 1
C
C TRANSLATE
C
450   WRITE (1,455)
455   FORMAT (' Each data point is shifted circularly by N points.
     X Enter N:'/)
      READ (1,211) NX
      WRITE (1,851)
      CALL NAME ( FN1 )
      WRITE (1,852)
      CALL NAME ( FN2 )
      CALL OPEN (3, FN1, 0)
      READ (3) DAT
      ENDFILE 3
      DO 470 J=1,NX
      T1 = DAT(1,1024)
      T2 = DAT(2,1024)
      DO 465 K=1,1023
      INDEX = 1024 - K
      DAT(1,INDEX+1) = DAT(1,INDEX)
465   DAT(2,INDEX+1) = DAT(2,INDEX)
      DAT(1,1) = T1
470   DAT(2,1) = T2
      CALL OPEN (3, FN2, 0)
      WRITE (3) DAT
      ENDFILE 3
      GO TO 1
9999  E  N  D
