! Example 2.8. Two assignments with mixed types. program C08 implicit none real, parameter :: A = 3.0 integer, parameter :: K = 3 integer :: M1, M2 ! start program C08 M1 = (A / 4) * K ! M1 = (3.0 / 4) * 3 M2 = (K / 4) * A ! M2 = (3 / 4) * 3.0 write (unit = *, fmt = *) M1, M2 stop end program C08 ! Examples of intrinsic library functions. program C09 implicit none real :: A, B, C, Term ! start program C09 write (unit = *, fmt = *) atan2( 0.0, -1.0 ), exp( 1.0 ) read (unit = *, fmt = *) A, B, C Term = sqrt( abs( B ** 2 - 4.0 * A * C ) ) write (unit = *, fmt = *) A, B, C, Term stop end program C09 ! Examples of intrinsic library functions. program C09 implicit none real :: A, B, C, Term ! start program C09 write (unit = *, fmt = *) atan2( 0.0, -1.0 ), exp( 1.0 ) read (unit = *, fmt = *) A, B, C Term = sqrt( abs( B ** 2 - 4.0 * A * C ) ) write (unit = *, fmt = *) A, B, C, Term stop end program C09 ! Simple sort with module subroutine Swap. program C12 use Swap_Reals_M implicit none real :: A, B, C ! start program C12 write (unit = *, fmt = *) " Please enter three numbers." read (unit = *, fmt = *) A, B, C write (unit = *, fmt = *) " Thank you. You have entered: ", A, B, C if (A > B) then call Swap( A, B ) end if if (A > C) then call Swap( A, C ) end if if (B > C) then call Swap( B, C ) end if write (unit = *, fmt = *) " The numbers in increasing order are: ", A, B, C stop end program C12 ! Temperature Conversion with Subroutines. program C13 use C13M implicit none real :: Fahr, Cels ! start program C13 call Input( Fahr ) call Calculate( Fahr, Cels ) call Output( Fahr, Cels ) stop end program C13 ! Program Example from "Essential Fortran 90 & 95" by Loren P. Meissner ! Copyright 1996. Copying for sale requires permission from the author. ! Otherwise, distribution is permitted if these three lines are included. module C13M implicit none public :: Input, Calculate, Output contains subroutine Input( FT1 ) real, intent (out) :: FT1 ! start subroutine Input write (unit = *, fmt = *) " Please enter the Fahrenheit temperature. " read (unit = *, fmt = *) FT1 return end subroutine Input subroutine Calculate (FT2, CT2) real, intent (in) :: FT2 real, intent (out) :: CT2 real, parameter :: T_SCALE = 1.8, OFFSET = 32.0 ! start subroutine Calculate CT2 = (FT2 - OFFSET) / T_SCALE return end subroutine Calculate subroutine Output( FT3, CT3 ) real, intent (in) :: FT3, CT3 ! start subroutine Output write (unit = *, fmt = *) FT3, " deg. F = ", CT3, " deg. C" return end subroutine Output end module C13M program C3X12 implicit none real, parameter :: A = 16.0, B = 4.0, C = 0.25, Theta = -0.5, X = 4.0 integer, parameter :: I = 1, J = -256, L = 4, M = 17, N = 8, Minute = 61 ! start program C3X12 write (unit = *, fmt = *) abs( A ) * B / C write (unit = *, fmt = *) sqrt( real( ((M - 9) / L) * N ) ) write (unit = *, fmt = *) A * sign( Theta, 1.0 ) write (unit = *, fmt = *) 0.5 * (sqrt( X ) + A / sqrt( X )) write (unit = *, fmt = *) abs( I - 5 ) write (unit = *, fmt = *) modulo( Minute, 60 ) write (unit = *, fmt = *) max( abs( I - 5 ), I, 1 ) write (unit = *, fmt = *) sqrt( sqrt( A ) ) write (unit = *, fmt = *) sqrt( B ** 2 - 4.0 * A * C ) / (2.0 * A) write (unit = *, fmt = *) 1 + nint( sqrt( real( abs( J ) ) ) ) stop end program C3X12 module calculations public :: mean, geomean, standev contains subroutine mean(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,mv) real,intent(in) :: x1,x2,x3,x4,x5,x6,x7,x8,x9,x10 real, intent(out) :: mv real :: s s=x1+x2+x3+x4+x5+x6+x7+x8+x9+x10 mv=s/10 end subroutine mean subroutine geomean(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,gm) real, intent(in) :: x1,x2,x3,x4,x5,x6,x7,x8,x9,x10 real, intent(out) :: gm real :: m m=x1*x2*x3*x4*x5*x6*x7*x8*x9*x10 gm=exp(log(m)/10) end subroutine geomean subroutine standev(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,mv,sd) real, intent(in) :: x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,mv real, intent(out) :: sd real :: u u=(x1-mv)**2+(x2-mv)**2+(x3-mv)**2+(x4-mv)**2 u=u+(x5-mv)**2+(x6-mv)**2+(x7-mv)**2+(x8-mv)**2 u=u+(x9-mv)**2+(x10-mv)**2 sd=sqrt(u/(10-1)) end subroutine standev end module calculations