0% found this document useful (0 votes)
7 views3 pages

FORTRAN Code

The Fortran program 'goodBending' calculates the deflection, bending moment, and shear force for a beam under a distributed load. It reads input values from a file, performs calculations based on defined constants such as Young's Modulus and moment of inertia, and outputs the results to another file. Error handling is implemented for file operations to ensure successful reading and writing.

Uploaded by

vicflare07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

FORTRAN Code

The Fortran program 'goodBending' calculates the deflection, bending moment, and shear force for a beam under a distributed load. It reads input values from a file, performs calculations based on defined constants such as Young's Modulus and moment of inertia, and outputs the results to another file. Error handling is implemented for file operations to ensure successful reading and writing.

Uploaded by

vicflare07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

program goodBending

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

!read from the file using iostat.


!loop
do
!start reading from file
read(10, '(I2)', iostat = instat) num
!read error message if iostat >0
if (instat >0) stop 'Input File cannot be read'
!stop loop if iostat <0
if (instat < 0) exit
!else, read from file otherwise as list(i)
!and increase i
list(i) = num
i = i + 1
ncount = ncount + 1
end do
!end loop

!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)

write(*, '(t8, a)') 'Values Calculated'


!close both files
end program goodBending

You might also like