home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / cpmug / cpmug091.ark / TTYPLOT.FOR < prev    next >
Encoding:
Text File  |  1984-04-29  |  5.0 KB  |  171 lines

  1. C*********************************************************************
  2. C
  3. C Written by Victor De Pinto
  4. C Revised Jan. 25, 1982
  5. C
  6.       SUBROUTINE PLOT ( DAT )
  7. C
  8. C     This plotting routine makes magnitude and phase plots on any printer.
  9. C     Unity is full scale for both magnitude and phase.
  10. C
  11.       LOGICAL QFLG, PHAFLG, LOGFLG
  12.       REAL MAG
  13.       INTEGER FIRSTP, LASTP, NTH
  14.       DIMENSION DAT(2,1024)
  15. 1     WRITE (1,5)
  16. 5     FORMAT (' --PLOTTER MENU--  Select function:'/
  17.      X ' 1  PLOT REAL PART OF FILE '/
  18.      X ' 2  PLOT MAGNITUDE (LINEAR) '/
  19.      X ' 3  PLOT MAGNITUDE (LOGARITHMIC) '/
  20.      X ' 4  PLOT PHASE (LINEAR) AND MAGNITUDE (LINEAR) '/
  21.      X ' 5  PLOT PHASE (LINEAR) AND MAGNITUDE (LOGARITHMIC) '/
  22.      X ' 6  BACK TO MAIN MENU >> ')
  23.       READ (1,10) MENU
  24. 10    FORMAT (I2)
  25. C Setup flags and get dB scale if Logarithmic plot.
  26.       LOGFLG = .FALSE.
  27.       PHAFLG = .FALSE.
  28.       GO TO (35,35,15,20,12,11), MENU
  29.       GO TO 1
  30. 11    RETURN
  31. 12    PHAFLG = .TRUE.
  32. 15    LOGFLG = .TRUE.
  33.       WRITE (1,16)
  34. 16    FORMAT ('+0 dB is full scale.'/
  35.      X        ' Enter bottom scale decibels. >> ')
  36.       READ (1,506) BOTDB
  37.       BOTDB = ABS( BOTDB )
  38.       GO TO 35
  39. 20    PHAFLG = .TRUE.
  40. C
  41. C Tell the computer how many columns the printer has and take off
  42. C five to allow for printing the data point number.
  43. 35    WRITE (1,36)
  44. 36    FORMAT ('+How many columns on a printer line? (80-132) ')
  45.       READ (1,506) WIDTH
  46.       WIDTH = WIDTH - 5.0
  47. C
  48. C Get range of points to plot.
  49.       WRITE (1,37)
  50. 37    FORMAT ('+What is the first point to plot? (0-1023) ')
  51.       READ (1,40) FIRSTP
  52. 40    FORMAT (I4)
  53.       WRITE (1,45)
  54. 45    FORMAT ('+What is the last point to plot? (0-1023) ')
  55.       READ (1,40) LASTP
  56.       WRITE (1,50)
  57. 50    FORMAT ('+Every Nth point is plotted.
  58.      X ENTER N (normally 1): ')
  59.       READ (1,40) NTH
  60. C
  61.       GO TO (500,200,200,200,200), MENU
  62. C
  63. C Magnitude and phase plot.
  64. C Phase is plotted only if PHAFLG is true.
  65. C
  66. C Determine scale factor.
  67. 200   WRITE (1,220)
  68. 220   FORMAT (' Enter the full scale magnitude. (This will be
  69.      X determined'/
  70.      X ' automatically if a negative number is entered.) ')
  71.       READ (1,506) FSMAG
  72.       CALL READ (DAT)
  73.       IF ( FSMAG ) 250,250,265
  74. C Entry was minus, so determine full scale magnitude.
  75. 250   FSMAG = 0.0
  76.       DO 260 N=1,1024
  77.       T = DAT(1,N)**2 + DAT(2,N)**2
  78.       IF (T .GT. FSMAG) FSMAG = T
  79. 260   CONTINUE
  80.       FSMAG = SQRT( FSMAG )
  81. C
  82. 265   SCALE = 1.0 / FSMAG
  83. C
  84. C Do the plot.
  85. C
  86.       QFLG = .FALSE.
  87.       DO 295 N = FIRSTP,LASTP,NTH
  88.       IF (QFLG) GO TO 295
  89. C Compute magnitude.
  90.       MAG = SCALE *  SQRT( DAT(1,N+1)**2 + DAT(2,N+1)**2 )
  91.       IF ( .NOT. LOGFLG ) GO TO 275
  92. C Convert to decibels only if log plot.
  93. C First see if MAG is too small. If so, avoid Log function.
  94.       IF ( MAG .GE. 1E-30 ) GO TO 270
  95.       MAG = -600.0
  96.       GO TO 275
  97. 270   MAG = ( 20.0 * ALOG10(MAG) + BOTDB ) / BOTDB
  98. C
  99. 275   IF ( .NOT. PHAFLG ) GO TO 290
  100. C Compute normalized phase if phase was chosen.
  101.       TMP1 = DAT(1,N+1)
  102.       TMP2 = DAT(2,N+1)
  103.       IF (TMP1 .NE. 0.0 .OR. TMP2 .NE. 0.0) GO TO 280
  104.       PHASE = 0.0
  105.       GO TO 290
  106. 280   PHASE = ATAN2 ( TMP2, TMP1 )
  107.       PHASE = 0.5 + PHASE / 6.29
  108. C
  109. 290   CALL TTDRAW (N, MAG, PHASE, PHAFLG, WIDTH)
  110.       CALL QCHEK ( QFLG )
  111. 295   CONTINUE
  112.       WRITE (2,300)
  113. 300   FORMAT (' '//)
  114.       GO TO 1
  115. C
  116. C PLOT THE REAL PARTS OF A FILE.
  117. C
  118. 500   WRITE (1,501)
  119. 501   FORMAT (' This routine adds an offset to the real parts'/
  120.      X        ' of a file, then multiplies by a scale factor.'/
  121.      X        ' Full scale is 1.0'/
  122.      X        ' ENTER OFFSET <CR> SCALE:'/)
  123.       READ (1,506) FSET, SCALE
  124. 506   FORMAT (F10.0)
  125.       CALL READ (DAT)
  126. C Do the plot.
  127.       QFLG = .FALSE.
  128.       DO 520 N=FIRSTP,LASTP,NTH
  129.       IF ( QFLG ) GO TO 520
  130.       Y = SCALE * ( DAT(1,N+1) + FSET )
  131.       CALL TTDRAW (N, Y, Y, .FALSE., WIDTH)
  132.       CALL QCHEK ( QFLG )
  133. 520   CONTINUE
  134.       WRITE (2,300)
  135.       GO TO 1
  136.       END
  137. C
  138. C ******************************************************
  139.       SUBROUTINE TTDRAW (NUMBER, MAG, PHASE, PHAFLG, WIDTH)
  140. C Plots one data point on the system list device.
  141. C The point number is pointed first, then the plot character(s).
  142. C WIDTH is the full scale value.
  143.       REAL MAG
  144.       LOGICAL PHAFLG
  145.       INTEGER LINE (132)
  146.       DATA LINE, IPHASE / 132*' ', 1/
  147.       IF (MAG .GE. 0.0 .AND. MAG .LE. 1.0) GO TO 50
  148. C If MAG is offscale, print 'O' in the fifth position.
  149.       IMAG = 5
  150.       LINE (IMAG) = 'O'
  151.       GO TO 60
  152. C Compute the column to plot MAG.
  153. 50    IMAG = WIDTH * MAG + 1.0
  154.       LINE (IMAG) = '*'
  155. C
  156. 60    LENGTH = IMAG
  157.       IF ( .NOT. PHAFLG) GO TO 80
  158. C Plot phase only if PHAFLG is true.
  159. 70    IPHASE = 0.5 * WIDTH * PHASE + 1.0
  160.       LINE (IPHASE) = 'P'
  161.       IF (IPHASE .GT. IMAG) LENGTH = IPHASE
  162. C Print the line.
  163. 80    WRITE (2,85) NUMBER, ( LINE(K), K=1,LENGTH )
  164. 85    FORMAT (' ', I4, 132A1)
  165. C Clear the array.
  166.       LINE (IMAG) = ' '
  167.       LINE (IPHASE) = ' '
  168.       RETURN
  169.       END
  170.