plotxt(3f) - [M_datapac:LINE_PLOT] generate a line printer run
sequence plot for the terminal (71 characters wide)
SUBROUTINE PLOTXT(X,N)
REAL(kind=wp),intent(in) :: X(:)
INTEGER,intent(in) :: N
PLOTXT(3f) yields a narrow-width (71-character) plot of x(i) versus i.
Its narrow width makes it appropriate for use on a terminal.
Values in the vertical axis vector (X) which are equal to or in excess
of 10.0**10 will not be plotted.
This convention greatly simplifies the problem of plotting when some
elements in the vector X are 'missing data', or when we purposely
want to ignore certain elements in the vector X for plotting purposes
(that is, we do not want certain elements in X to be plotted). To
cause specific elements in X to be ignored, we replace the elements
beforehand (by, for example, use of the REPLAC(3f) subroutine) by
some large value (like, say, 10.0**10) and they will subsequently be
ignored in the PLOTXT(3f) subroutine.
Note that the storage requirements for this (and the other) terminal
plot subroutiness are very small. This is due to the 'one line at a
time' algorithm employed for the plot.
X The vector of (unsorted or sorted) observations to be plotted
vertically.
N The integer number of observations in the vector X.
A narrow-width (71-character) terminal plot of X(I) versus I.
The body of the plot (not counting axis values
and margins) is 25 rows (lines) and 49 columns.
Sample program:
program demo_plotxt
use M_datapac, only : plotxt
implicit none
! call plotxt(x,y)
end program demo_plotxt
Results:
The original DATAPAC library was written by James Filliben of the
Statistical Engineering Division, National Institute of Standards
and Technology.
John Urban, 2022.05.31
CC0-1.0
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | X(:) | |||
integer, | intent(in) | :: | N |
SUBROUTINE PLOTXT(X,N) REAL(kind=wp),intent(in) :: X(:) INTEGER,intent(in) :: N REAL(kind=wp) :: ai, ailabl, aim1, aimax, aimin, airow, aiwidt, anumcm, anumlm, anumr, anumrm, cutoff, delai, delx, hold REAL(kind=wp) :: xlable, xlower, xmax, xmin REAL(kind=wp) :: xupper, xwidth INTEGER :: i, icol, icolmx, irow, ixdel, numcol, numlab, numr25, numr50, numr75, numrow CHARACTER(len=4) :: iline CHARACTER(len=4) :: iaxisc CHARACTER(len=4) :: sbnam1 , sbnam2 CHARACTER(len=4) :: alph11 , alph12 , alph21 , alph22 CHARACTER(len=4) :: blank , hyphen , alphai , alphax DIMENSION iline(72) , ailabl(10) DATA sbnam1 , sbnam2/'PLOT' , 'XT '/ DATA alph11 , alph12/'FIRS' , 'T '/ DATA alph21 , alph22/'SECO' , 'ND '/ DATA blank , hyphen , alphai , alphax/' ' , '-' , 'I' , 'X'/ ! cutoff = (10.0_wp**10) - 1000.0_wp ! ! CHECK THE INPUT ARGUMENTS FOR ERRORS ! IF ( N<1 ) THEN WRITE (G_IO,99010) WRITE (G_IO,99011) WRITE (G_IO,99012) alph21 , alph22 , sbnam1 , sbnam2 WRITE (G_IO,99001) N 99001 FORMAT (' is non-negative (with value = ',I0,')') WRITE (G_IO,99010) RETURN ELSE IF ( N==1 ) THEN WRITE (G_IO,99010) WRITE (G_IO,99011) WRITE (G_IO,99012) alph21 , alph22 , sbnam1 , sbnam2 WRITE (G_IO,99002) N 99002 FORMAT (' has the value 1') WRITE (G_IO,99010) RETURN ELSE ! hold = X(1) DO i = 2 , N IF ( X(i)/=hold ) GOTO 50 ENDDO WRITE (G_IO,99010) WRITE (G_IO,99011) WRITE (G_IO,99012) alph11 , alph12 , sbnam1 , sbnam2 WRITE (G_IO,99003) hold 99003 FORMAT (' ','has all elements = ',E15.8) WRITE (G_IO,99010) RETURN ENDIF ! 50 DO i = 1 , N IF ( X(i)<cutoff ) GOTO 100 ENDDO WRITE (G_IO,99010) WRITE (G_IO,99011) WRITE (G_IO,99012) alph11 , alph12 , sbnam1 , sbnam2 WRITE (G_IO,99004) 99004 FORMAT (' ','has all elements in excess of the cutoff') WRITE (G_IO,99005) cutoff 99005 FORMAT (' ','value of ',E15.8) WRITE (G_IO,99010) RETURN ENDIF ! !-----START POINT----------------------------------------------------- ! ! DEFINE THE NUMBER OF ROWS AND COLUMNS WITHIN THE PLOT-- ! THIS HAS BEEN SET TO 25 ROWS AND 49 COLUMNS. ! 100 numrow = 25 numcol = 49 anumr = numrow anumrm = numrow - 1 anumcm = numcol - 1 numr25 = (numrow/4) + 1 numr50 = (numrow/2) + 1 numr75 = 3*(numrow/4) + 1 ixdel = (numcol-1)/4 numlab = 5 anumlm = numlab - 1 ! ! WRITE OUT THE TOP HORIZONTAL AXIS OF THE PLOT, AND SKIP 1 LINE ! FOR A MARGIN WITHIN THE PLOT. ! WRITE (G_IO,99006) 99006 FORMAT (' ') WRITE (G_IO,99007) 99007 FORMAT (' The following is a plot of X(I) (vertically) versus I (horizontally)') DO icol = 1 , numcol iline(icol) = hyphen ENDDO DO icol = 1 , numcol , ixdel iline(icol) = alphai ENDDO WRITE (G_IO,99013) (iline(i),i=1,numcol) WRITE (G_IO,99014) blank ! ! DETERMINE THE MIN AND MAX VALUES OF X, AND OF I. ! xmin = X(1) xmax = X(1) aimin = 1 aimax = N DO i = 1 , N IF ( X(i)<cutoff ) THEN IF ( X(i)<xmin ) xmin = X(i) IF ( X(i)>xmax ) xmax = X(i) ENDIF ENDDO delx = xmax - xmin delai = aimax - aimin xwidth = delx/anumrm aiwidt = delai/anumcm ! ! DETERMINE AND WRITE OUT THE PLOT POSITIONS ONE LINE AT A TIME. ! DO irow = 1 , numrow DO icol = 1 , numcol iline(icol) = blank ENDDO airow = irow xupper = xmax + (1.5_wp-airow)*xwidth xlable = xmax + (1.0_wp-airow)*xwidth xlower = xmax + (0.5_wp-airow)*xwidth IF ( irow==numrow ) xlable = xmin DO i = 1 , N ai = i IF ( X(i)<cutoff ) THEN IF ( xlower<=X(i) .AND. X(i)<xupper ) THEN icol = ((ai-aimin)/aiwidt) + 1.5_wp iline(icol) = alphax ENDIF ENDIF ENDDO icolmx = 1 DO icol = 1 , numcol IF ( iline(icol)==alphax ) icolmx = icol ENDDO iaxisc = alphai IF ( irow==1 .OR. irow==numrow ) iaxisc = hyphen IF ( irow==numr25 .OR. irow==numr50 .OR. irow==numr75 ) iaxisc = hyphen WRITE (G_IO,99008) xlable , iaxisc , (iline(icol),icol=1,icolmx) 99008 FORMAT (' ',E14.7,1X,A1,2X,50A1) ENDDO ! ! SKIP 1 LINE FOR A BOTTOM MARGIN WITHIN THE PLOT, WRITE OUT THE ! BOTTOM HORIZONTAL AXIS, AND WRITE OUT THE X AXIS LABELS. ! WRITE (G_IO,99014) blank DO icol = 1 , numcol iline(icol) = hyphen ENDDO DO icol = 1 , numcol , ixdel iline(icol) = alphai ENDDO WRITE (G_IO,99013) (iline(icol),icol=1,numcol) DO i = 1 , numlab aim1 = i - 1 ailabl(i) = aimin + (aim1/anumlm)*delai ENDDO WRITE (G_IO,99009) (ailabl(i),i=1,numlab) 99009 FORMAT (' ',9X,5E12.4) 99010 FORMAT (' ','**********************************************************************') 99011 FORMAT (' ',' FATAL ERROR ') 99012 FORMAT (' ','The ',A4,A4,' input argument to the ',A4,A4,' subroutine') 99013 FORMAT (' ',18X,54A1) 99014 FORMAT (' ',15X,A1) END SUBROUTINE PLOTXT