Plotting Program, with Comments (actual Fortran code is in Bold)



       PROGRAM Plotter

       !### First, declare all the variables you are going to use: 
       
       CHARACTER*35 title
       CHARACTER*8 xtitle,ytitle
       REAL ymin,ymax,xdata(132),ydata(132)
       INTEGER i, npoints

       !### Then, open file & read the data:

       open(unit=9,name="sheet1Q10.dat",type="old") !Opens the data file and assigns unit number=9 to it.

       read(9,*)xtitle,ytitle  !Reads in the axis labels from unit=9 (data file).

       npoints=132  !The number of x,y points in the data file.

       do i=1,npoints                              !A 'do-loop' - it tells the computer to do everything between 'do' and 'enddo' 132 times.
            read(9,*)xdata(i),ydata(i)   !Reads in all the data - 2 numbers per line (x,y).
            print*,'Reading line #',i       !This will print to screen, letting you know what line it's currently reading.
       enddo                                     !The end of the do-loop.

       close(9)   !Closes the data file.

       !### Prepare some stuff for the graph:

       title='Temperature Vs. Mass in the Sun'

       !Set limits of graph to be plotted:
       
       xmin =0.0
       xmax=1.0
       ymin =3.0
       ymax=8.0

!========= Below is the code that calls the plotting program PgPlot ===========!
!=======For more info on PgPlot see: www.astro.caltech.edu/~tjp/pgplot/ =======!

       call PGBEGIN(0,'?',1,1)    !Opens PgPlot program.
       call pgsci(1)                      !Sets colour for the graph border (1=white, 2=red, 3=green, etc.)
       call pgenv(xmin,xmax,ymin,ymax,0,0)   !Makes PgPlot window. [0,0 = not square, draw box with coords] 
       call pgsci(1)                                            !Set colour for the titles. 
       call pglabel(xtitle,ytitle,title)                   !Plots the titles we set earlier.
       
       call pgsci(3)                                  !Sets colour for line.
       call pgline(npoints,xdata,ydata)   !Plots the data.
        
       call PGEND  !Closes PgPlot.

!===============================================================!
       
       stop
       END