Skip to content

CodeMigra/fortran-to-python-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

fortran to python: beam analysis

A migration of a 1979 Fortran 77 structural analysis program to Python with NumPy. The original calculated deflection, moment, shear, and bending stress for a simply supported beam under a uniformly distributed load. It ran on a VAX-11/780 and took its input from a fixed-format text file piped to stdin.

what the original does

BEAMLOAD.f is fixed-form Fortran 77. It reads five parameters from unit 5 (span, load, E-modulus, second moment of area, section modulus), computes the four peak values using standard beam theory formulas from Roark's, then loops over N points along the beam printing deflection, moment, and shear at each position. It uses COMMON blocks to pass material and geometry properties between routines, FORMAT statements for all I/O, and REAL*8 (64-bit double) throughout.

what changed

The Python version keeps the same formulas and produces the same numerical output:

  • BeamParams is a dataclass — same fields, same meaning, no global state
  • NumPy handles the point-by-point array in one vectorised pass instead of a DO loop
  • Functions are separated by concern: analyse() for peak values, deflection_at() / moment_at() / shear_at() for point values, print_report() for output
  • The same input file format works — pass it as a command-line argument

The formulas themselves are unchanged. We verified output against the Fortran version on three test cases before signing off.

running it

Fortran (requires gfortran):

gfortran -o beamload BEAMLOAD.f
echo "6.0\n5000.0\n200e9\n1.943e-5\n1.943e-4\n10" | ./beamload

Python (requires Python 3.10+, NumPy):

pip install numpy
python beam_analysis.py          # runs built-in example
python beam_analysis.py input.dat  # reads from file

Input file format: one value per line — span, load, E, I, S, n_points.

about codemigra

We migrate Fortran, COBOL, VB6, and Delphi to modern languages. codemigra.com

About

Fortran 77 beam analysis migrated to Python + NumPy

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors