program main * * Comments: c, C or * in column one * text in columns > 72 * ! F90-comment * First five columns: labels * Continuation line: non-blank in column 6 * Statements: columns 7 through 72 * Case or blanks are not significant * (unless they are in strings). * * Arrays start at one by default. * integer k, n, in double precision a(100), b(100), sum double precision ddot ! a function n = 100 print*, "Type a value for in:" read*, in print*, "This is how you write: in = ", in do k = 1, n ! do when k = 1, 2, ..., n a(k) = k b(k) = -sin(dble(k)) ! using sin end do * * Call by reference for all variables. * print*, "The inner product is ", ddot(a, b, n) call sum_array(a, sum, n) ! NOTE, call print*, "The sum of the array is ", sum end subroutine sum_array(a, sum, n) * * Fortran has an implicit type rule but * implicit none forces you to declare everything. * Highly recommended! * implicit none integer n double precision a(n), sum integer k sum = 0.0 ! 0.0 is single and 0.0d0 double do k = 1, n sum = sum + a(k) end do end double precision function ddot(x, y, n) implicit none integer n double precision x(n), y(n) integer k double precision sum sum = 0.0 do k = 1, n sum = sum + x(k) * y(k) end do ddot = sum ! give the function its value end