
PROGRAM files_9
	IMPLICIT NONE

	! This program shows how to write data to a file 
	! This data appears as two columns (x,y) which can be plotted 
	! using Gnuplot or whatever graphics software you are familiar with.

	! declarations:
	INTEGER :: i
	REAL    :: x,y, deltax
	! note the PARAMETER attribute for pi. It means that pi is set to 
	! this value at compile time and cannot be changed within the program.
	REAL, PARAMETER :: pi = 3.141592654
	REAL, INTRINSIC :: SIN

	deltax = pi/50.0 	!any operations which can be carried out outside the loop
				!should be in the interests of efficiency 
				!(i.e. once rather than 100 times).
				!deltax is then just the interval, or step size, between 
				!one x value and the next in the DO loop

	DO i = 1,100
		x = i*deltax 
		y = SIN(x)
		! On the first cycle round the do_loop this statement 
		! creates the file fort.21 and writes the first value 
		! of (x,y); thereafter, each new value of (x,y) is 
		! appended to the fort.21
		WRITE(21,*) x,y
	END DO

END PROGRAM files_9

