FORTRAN Code
FORTRAN Code
implicit none
!declare variables
!constants to be declared initially
!Young's Modulus as real
real, parameter :: E = 4000.0 !(in N/mm^2)
!Geometric MOment of inertia as real
real, parameter :: Inertia = 5.0 !(in mm4^)
!overall length as real
real, parameter :: L = 40.0 !(in mm)
!distributed load per length as real
real, parameter :: W = 5.0 !(in N/mm)
!variables
!integer stored in array
integer, dimension(50) :: list
!number used in loop fetching for array
integer :: num
!i, ncount as integer for loop
integer :: i=1, ncount=0
!value from list in calculation
real :: x
!deflection as real
real :: y
!Bending moment as real
real :: M
!Shear force as real
real :: S
!others
!iostat variables
integer :: status1, status2, instat
!loop
do
!open the input file
open(unit = 10, file = 'input.txt', action = 'read', iostat = status1)
!exit if input file can be read using iostat
if(status1 == 0) exit
!else, print error message
write(*, '(t3, A)') 'Error: Input File cannot be opened'
!end loop
end do
!loop
do
!open the output file
open(unit = 11, file = 'output.txt', action = 'write', iostat = status2)
!exit if output file can be read using iostat
if(status2 == 0) exit
!else, print error message
write(*, '(t3, A)') 'Error: Output File cannot be opened'
!end loop
end do
!output file
!header
write(*,*)
write(*,*)
write(11, '(t20,a )') '--------------------------------'
write(11, '(t20 ,a)') ' Beam Values'
write(11, '(t20,a) ') '--------------------------------'
write(*,*)
write(*,*)
write(*,*)
write(*,*)
!table header
write(11, '(t5,a) ')
'----------------------------------------------------------------------------------
---'
write(11, '(t6 , a15, 3x, a18, 3x,a23, 3x, a18)') 'Distance, x(mm)',
'Deflection, y(mm)', 'Bending Moment, M(Nmm)', 'Shear Force, S(N)'
write(11, '(t5,a) ')
'----------------------------------------------------------------------------------
---'
!loop
do i = 1, ncount
!fetch value from list
x = list(i)
!calculate the formula for y, M, S. Convert x to real for calculation
y = ((W * real(x) )/(24.0 * E * Inertia)) * (L**3 -
((real(x))**2.0)*((real(x)) - 2.0*L))
M = ((W * real(x))/2.0) *(L - real(x))
S = W * (L/2 - real(x))
!print appropriately into output file and format
write(11, '(t6,I2,18x,F5.2,18x,F9.3,17x,F8.3 )') list(i), y, M, S
end do
write(11, '(t5,a) ')
'----------------------------------------------------------------------------------
---'
!end loop
!CLOSE FILES
close(10)
close(11)