Skip to main content

SINEOUT.f95

	PROGRAM SINEOUT
!
!  Purpose: to output the angles 1, 2, 3 and 4 degrees, together with the
!  the values of their sines, to the screen and to the file A:\ANGLSINE.
!
	IMPLICIT NONE
	REAL:: THETA1, THETA2, THETA3, THETA4
	REAL:: SINE1, SINE2, SINE3, SINE4
	REAL:: PI
!
!  Define the angles:
	THETA1 = 1.0
	THETA2 = 2.0
	THETA3 = 3.0
	THETA4 = 4.0
!
!  Calculate their sine. We'll use the intrinsic function SIN, which expects
!  its argument to be expressed in radians, not in degrees. Hence, we convert
!  the angles from degrees to radians by multiplying by the appropriate
!  conversion factor. First, define pi.
	PI = 4.0 * ATAN(1.0)
	SINE1 = SIN(THETA1*PI/180.0)
	SINE2 = SIN(THETA2*PI/180.0)
	SINE3 = SIN(THETA3*PI/180.0)
	SINE4 = SIN(THETA4*PI/180.0)
!
!  Now, display the results on the screen, in two columns. The E16.7 format
!  descriptor ensures that all the significant digits are displayed. The
!  angles vary from 1 to 4, so the format descriptor F6.1 is appropriate.
!  The FORMAT statement is put at the end of the program, for clarity.
	WRITE(*,100)THETA1,SINE1
	WRITE(*,100)THETA2,SINE2
	WRITE(*,100)THETA3,SINE3
	WRITE(*,100)THETA4,SINE4
!
!  Also, write the results on the file A:\ANGLSINE. First, open the file.
!	OPEN(3,FILE='A:\ANGLSINE')
	OPEN(3,FILE='ANGLSINE')
	WRITE(3,100)THETA1,SINE1
	WRITE(3,100)THETA2,SINE2
	WRITE(3,100)THETA3,SINE3
	WRITE(3,100)THETA4,SINE4
!
  100	FORMAT(1X,F6.1,2X,E16.7)
!
	END PROGRAM SINEOUT