title: Graphing in Fortran, Algorithm Assistance Needed
body: <p>I am trying to create a fortran program that will plot X,Y coordinates to the screen.  I have the program receive plots from an input file.  in the input file the first entry is the amount of points.  every line after that has an x value then a space then the corresponding y values.  I then have the program bubble sort the x values from smallest to greatest.  next i want to graph these values.  i want to graph them so that the scale of the x axis is xmax-xmin/#of points and the y axis is the same.  how would i go about printing a '*' for points as a dirty graph???  im not looking for the entire answer just some direction of how to form the algorithm for the write.  Listed below is the code that i have so far and a sample input file</p>
  
  <p>Input File</p>
  
  <pre><code> 10
   -4 16
   -3 9
   -2 4
   -1 1
   0 0
   1 1
   2 4
   3 9
   4 16
   5 25
  </code></pre>
  
  <p>Code</p>
  
  <pre><code> *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    
  </code></pre>