Fortran re-engineering example (6)

The code is effectively disassociated from anything legacy at this point… but it still needs some tidying up. Firstly we could combine the final two if statements into an if-else statement, which is effectively what they are. Therefore this code:

 if (dist.le.30) vel = 2.425+0.00175*dist*dist
 if (dist.gt.30) vel = 0.625+0.12*dist-0.00025*dist*dist

becomes:

 if (dist .le. 30) then
     vel = 2.425 + 0.00175*dist*dist
 else
     vel = 0.625 + 0.12*dist - 0.00025*dist*dist
 end if

Next all the old-fashioned conditional operators could be changed, i.e from .le. to <=. Finally we could improve readability by adding some spaces to equations, and remove the stop statement.

Here’s the final piece of code:

cablecar5

There is nothing inherently difficult about the process of re-engineering. This is of course a very simple example, and re-engineering a 10,000 line Fortran program *may* be somewhat of a nightmare… but it *is* possible. Most of all, one has to develop a rigorous process to re-engineer a program. You can’t just go and start editing code, especially as a *lot* of code may not be well documented, or have algorithms which seem cryptic. Stand-alone Fortran functions can be somewhat easier, as they can always be called from other languages such as Julia.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s