! This is a basic starting shell for your programs MODULE const INTEGER, PARAMETER :: dp = KIND(1.0d0), sp = KIND(1.0e0) REAL(KIND=dp), PARAMETER :: dpi = 3.141592653589793d0 END MODULE const ! ! Program to generate a table of values for y = sin(x) + cos(x) ! on [0,dpi] using array variables ! PROGRAM prog USE const IMPLICIT NONE INTEGER :: n,i REAL(kind=dp) :: a,b,h ! Declare array variables vecx and vecy. These will hold the table ! values REAL(kind=dp) :: vecx(11),vecy(11) ! Set up table parameters a = 0 b = dpi WRITE(*,*) 'input n' READ(*,*) n ! Get table spacing h = (b-a)/n ! Main loop to generate table DO i = 1,n+1 vecx(i) = a + (i-1)*h vecy(i) = SIN(vecx(i)) + COS(vecx(i)) WRITE(*,*) 'vecx(i),vecy(i) = ',vecx(i),vecy(i) ENDDO ! However, since we are now storing the table values in a way ! that they can be referenced later on if needed, we can also ! do the program as done below. ! ! In this case, we can have 3 completely separate loops that ! decouple the calculations from each other ! Generate just the x coordinates DO i = 1,n+1 vecx(i) = a + (i-1)*h ENDDO ! Generate the corresponding y coordinates DO i = 1,n+1 vecy(i) = SIN(vecx(i)) + COS(vecx(i)) ENDDO ! Print the table out WRITE(*,*) DO i = 1,n+1 WRITE(*,*) 'vecx(i),vecy(i) = ',vecx(i),vecy(i) ENDDO END PROGRAM prog