# Converting a Fortran Program to Mathcad

DN Staff

June 6, 2005

Fortran has been so successful at helping engineers to approximate equations that for many it has become a key part of the engineering process. But with many of the engineers who coded in Fortran now retiring, it leaves a lot of legacy bits unsupported out there. All the more a problem since Fortran and Microsoft products don't naturally go together.

"Many of these legacy programs are rapidly turning into black boxes and that's a worry for many engineering departments," says John Sheehan, VP of services at Mathsoft, makers of Mathcad, a software tool for math calculations.

It was actually at the request of several customers who were worried about the growing black-box nature of their Fortran programs that Sheehan looked into how Mathcad-an interpretive math engine with natural math notation-could help. Mathcad is also a strong collaborative work tool-which makes it easy for engineers to publish and share information.

Although engineers can enter an exact system of equations into Mathcad, Sheehan discovered that some engineers want to replicate exactly the results they were getting in Fortran-possibly they need the margin of error for backward compatibility. He then demonstrated a better approach-taking the original partial differential equations (which the Fortran code was trying to approximate) and typing them directly in Mathcad.

Fortran to Mathcad: A Conversion Plan
This is the system of equations that John set up to solve...

ut(x,t) - uxx(x,t) = 0

u(x,0) = f(x)

u(0,t) = p(t) u(1,t) = q(t)

u:= Pdesolve [ u,x (0 1), t, (0 0.5)] solve for u (x,t) over the range
x = 0 to 1 and t = 0 to 0.5

x:=0,0.01 .. 1 t:= 0.5

...then he compared the results he generated using Mathcad (by using the column operator) to results from the FORTRAN program...

 ...and then showed that you can obtain the exact solution using Mathcad's built-in Pdesolve function.

For John's complete instructions for converting a Fortran program with several do laps into an equivalent Mathcad program using Mathcad's while loop, go to: http://rbi.ims.ca/4392-553.

Got a cool software trick? Send us details, including any documentation and supporting code, to [email protected]. If we publish your trick, we'll send you a super cool, limited-edition Design News t-shirt.