Electronics Industry Search

Polling Question

Green design is a priority for me in 2009.

  • Yes
  • No



View previous polls
Advertisement
Email
Print
Reprints/License
RSS
Article tools sponsored by

Converting a Fortran Program to Mathcad

By Design News Staff -- Design News, 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.

You need this trick if: You are currently using legacy Fortran programs for approximating linear and nonlinear algebraic or differential equations and need these equations in a format where they can not only be recalculated but also shared and understood by others.

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...

   Mathcad Results    
  T=0.50 Numerical  Exact 
  0.000 0.000 0.000
  0.100  0.260  0.222
  0.200 0.494  0.423 
  0.300 0.680 0.582
M= 0.400 0.800 0.684
  0.500 0.841 0.719
  0.600 0.800 0.684
  0.700 0.680 0.582
  0.800 0.494  0.423
  0.900 0.260 0.222
  1.000 0.000 0.000
Fortran Results    
T=0.50  Numerical Exact 
X=0.0 0.000000 0.000000
X=0.1  0.259879 0.222242
X=0.2 0.494319 0.422730
X=0.3 0.680372 0.581837
X=0.4 0.799826 0.683991
X=0.5 0.840987 0.719190
X=0.6 0.799826 0.683991
X=0.7 0.680372 0.581837
X=0.8 0.494319 0.422729
X=0.9 0.259879 0.222242
X=1.0 0.000000 0.000000
...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 kfield@reedbusiness.com. If we publish your trick, we'll send you a super cool, limited-edition Design News t-shirt.

Advertisement

Sponsored Content

Technology Marketplace

Email
Print
Reprints/License
RSS
Article tools sponsored by
Find a supplier on oemsuppliersearch.com

Talkback


We would love your feedback!


» Submit talk back
Advertisement

DN's Resource Center Get Free Information, Made Easy

Advertisement

Design News Partner Zones

AnarkCAD/CAE Model Clean-Up: Reduce Iterative Cycles
This webinar featured research and survey results related to problems associated with preparing CAD geometry for CAE applications.  We discussed how Recipe-Based Automation can help create "just-in-time" CAE-ready geometry each time a cad model is updated. Watch the Presentation


Light Matters: A High-Performance, "No-Compromise" Solid State Lamp?
First, let's define "no-compromise". In an ideal configuration, this lamp would use a high-brightness LED (HBLED) that is built into a small, integrated package, and is able to produce a large quantity of focused light, operate with a high level of reliability and generate no audible noise. Is this difficult? Yes, but it is possible.
Read More


Design Engineers' Portal for Sensing and Machine Safety
Whatever industry you're in, or whatever product you manufacture, the right sensors to automate your plant, and to improve your overall efficiency, quality and safety are a must. You'll find Banner Engineering to be an amazing resource of products, training and people with expertise.

Design News Partner Zone Directory »

Please visit these other Reed Business sites