我正在尝试创建一个将 X,Y 坐标绘制到屏幕上的 fortran 程序。我让程序从输入文件中接收绘图。在输入文件中,第一个条目是点数。之后的每一行都有一个 x 值,然后是一个空格,然后是相应的 y 值。然后我让程序对 x 值从最小到最大进行冒泡排序。接下来我想绘制这些值。我想绘制它们以使 x 轴的比例为 xmax-xmin/#of 点并且 y 轴相同。我将如何将点打印为“*”作为脏图???我不是在寻找完整的答案,只是寻找如何形成写入算法的一些方向。下面列出的是我到目前为止的代码和一个示例输入文件
输入文件
10
-4 16
-3 9
-2 4
-1 1
0 0
1 1
2 4
3 9
4 16
5 25
代码
*START OF CODE
PROGRAM MAIN
*DECLARATIONS
INTEGER EXISTS, DONE, POINTS, USED, I, E
REAL XSTEP, YSTEP, XMIN, XMAX, YMIN, YMAX
REAL X(100), Y(100), A, B
CHARACTER INNAME*30, OUTNAME*30
LOGICAL MORE
CHARACTER (70) LINE
*INITIALIZATIONS
INNAME='NULL.DOC'
EXISTS=0
DONE=0
POINTS=0
USED=0
I=0
E=0
MORE = .TRUE.
A=0
B=0
XSTEP = 0
YSTEP = 0
XMIN=0
XMAX=0
YMIN=0
YMAX=0
*CLEAR THE ARRAYS
DO I=1,100
X(I)=0
Y(I)=0
END DO
I=0
*FORMATS
5 FORMAT(' ','POINT #', I3, ' X=', F5.2,' Y=', F5.2)
10 FORMAT(' ','XMIN=',F5.2, ' XMAX=', F5.2)
15 FORMAT(' ','YMIN=',F5.2, ' YMAX=', F5.2)
20 FORMAT(' ','X STEP=',F5.2, ' Y STEP=', F5.2)
*MAIN CODE
****************************************************************
*PROMPT FOR NAME OF FILE AND INPUT
PRINT *,'PLEASE INPUT A FILE NAME INCLUDING AN EXTENSION'
PRINT *,'ENTER QUIT OR Q TO EXIT'
READ (*,*) INNAME
*OPEN IF(0)
IF(INNAME.EQ.'Q'.OR.INNAME.EQ.'QUIT')THEN
PRINT *,'GOODBYE'
ELSE
*TEST FOR FILE
INQUIRE(FILE=INNAME, EXIST=EXISTS)
*IF EXIST=FALSE, DISPLAY MESSAGE
IF(.NOT.EXISTS) THEN
PRINT *,'FILE DOES NOT EXIST, PLEASE TRY AGAIN'
*ELSE EXIST=TRUE, OPEN (UNIT=1)
ELSE
OPEN(UNIT=1, FILE=INNAME, STATUS='OLD')
END IF
*************************************************************
*ASK CHOICES FOR OUTPUT
PRINT *,'PLEASE ENTER A NAME FOR AN OUTPUT FILE W/ EXTENSION'
PRINT *,'ENTER QUIT OR Q TO EXIT'
READ(*,*)OUTNAME
IF(OUTNAME.EQ.'Q'.OR.OUTNAME.EQ.'QUIT')THEN
PRINT *,'GOODBYE'
ELSE
*************************************************************
*CHECK IF DONE (IF 1)
IF(DONE.EQ.0)THEN
*OPEN THE OUTPUT FILE DO(2)
DO WHILE(USED.EQ.0)
INQUIRE(FILE=OUTNAME,EXIST=EXISTS)
*OPEN IF(2) FOR IF FILE ALREADY EXISTS
IF(EXISTS.EQ.1)THEN
OPEN(UNIT=2,FILE=OUTNAME,STATUS='OLD')
*END IF FOR IF FILE ALREADY EXISTS AMD OPEN IF DID NOT EXIST,
ELSE
OPEN(UNIT=2,FILE=OUTNAME,STATUS='NEW')
*END IF (2)
END IF
*READ IN 1 INTEGER (MAXIMUM VALUE OF 100) FOR # OF POINTS IN FILE
READ(1,*, END=111),POINTS
*READ IN X AND Y VALUES WITH MAX OF 100
DO I=1, POINTS
READ(1,*,END=111) X(I),Y(I)
END DO
*SORT POINTS
E = POINTS - 1
MORE = .TRUE.
DO WHILE (MORE .EQ. .TRUE.)
MORE = .FALSE.
DO I=1, E
IF(X(I).GT.X(I+1)) THEN
MORE = .TRUE.
A=X(I)
B=y(I)
X(I)=X(I+1)
Y(I)=Y(I+1)
X(I+1)=A
Y(I+1)=B
END IF
END DO
E=E-1
END DO
*FIND MIN AND MAX OF X AND Y
I=1
XMIN = X(I)
XMAX = X(POINTS)
YMIN = Y(I)
YMAX = Y(I)
DO I=1, POINTS
IF(Y(I) .LT. YMIN) THEN
YMIN = Y(I)
END IF
IF(Y(I) .GT. YMAX) THEN
YMAX = Y(I)
END IF
END DO
*fIND X AND Y STEPS
XSTEP = (XMAX-XMIN)/POINTS
YSTEP = (YMAX-YMIN)/POINTS
*PRINT TO THE OUTPUT FILE
DO I=1, POINTS
WRITE(2,5)I,X(I),Y(I)
END DO
WRITE(2,10)XMIN,XMAX
WRITE(2,15)YMIN,YMAX
WRITE(2,20)XSTEP,YSTEP
*PRINT GRAPH
*END DO (2)
END DO
*END IF (1)
END IF
*END IF QUIT(S)
END IF
END IF
*CLOSE THE FILES
CLOSE(UNIT=1)
CLOSE(UNIT=2)
111 PRINT * , 'The Program Has Now Ended'
*STOP
STOP
*END
END