Question

I've been working with a lot of FORTRAN 77 lately, and though I had reservations at first, I now see some great qualities of the language. It is:

  • Simple to learn (no object-oriented or functional-programming complications)
  • Easy to read
  • Blazing fast at number-crunching

Those qualities are naturally attractive to non-programmer engineers and scientists who just want a way to make a computer give answers quickly. But it has a lot of limitations based on its age and some of its basic assumptions. I'm skeptical about how easily non-programmers can understand some of the added capabilities of later versions of Fortran, as well.

Is there a modern language that is as straightforward as FORTRAN, just as fast for mathematical applications, and less limited? Or is the answer Fortran 90, 95, 2003 . . . ?

Was it helpful?

Solution

Or is the answer Fortran 90, 95, 2003 . . . ?

Yes. Fortran 95 supported by most compilers is the language you are looking for. However Fortran 2003 has some major enhancements (besides unnecessary from your point of view support of OOP) which might be useful. Compiler Support for the Fortran 2003 Standard.

OTHER TIPS

Well, I'm a non-programmer engineer (whatever that means; I gather it means not having much contact with computer sciences studies) and ...

Partically in continuation to JasonFruit's comment on S. Lott's answer:

Yes, the standard has added quite a few features from F90 to 2003. But the "problem", if one can call it such (I cannot think or care to of a more appropriate word) is that many people who use Fortran do not know it, save the basic features they need. It is a blessing and a curse all in one, in a way. They have never learned it, never read a book on it - they kinda just picked it up as they went along. That way can certainly work for a time (if you structure your programs simply, as many have done for centuries, and have a sort of mental discipline, this approach can last for a lifetime/your entire career), but after a while it starts to show its disadvanages. Try for example, following some of the discussions on the recent features on comp.lang.fortran to test your knowledge.

So, take a good book (many recommend one of the three for beginners; a) Chapman J. Stephen's b) Maine, or c) Metcalf, Reid and Cohen (known as the "M.R.C. book") - after which a lot of the "more obscure" features not only become clearer, but also "obvious" (as in a way; this really is the better way - why did I did it that way ... before?).

That takes care of that question. Now, the other question -- which will certanly arise -- is Fortran worth learning nowadays? (it always does, trust me on this :). This has been covered numerous times, so I'll just direct to my own post regarding the above, and my older post (you'll have to scroll a little down) which regards some issues in comparison with some of the other langugages mentioned here.

The last thing, which is in a way the cause of all these question in most cases is people opinion on Fortran, with the emphasis on opinion! Generally speaking (and we can take this forum as a pretty good sample for our analysis) is that it's not so good. Few like it [ follow questions marked fortran on this forum for a month, and you'll quickly learn who they are. Btw, judging from the frequency your name's been appearing, you're quickly becoming a member of the club :) ], most are either indifferent, and some hate it, out of sheer ignorance (comparing F66 with today's languages is often used), some out of their own reasons. Now, if we take those and compare it with the general population, by simple an account, the result is bound to come out bad. If you interviewed just traditional engineers the results would be quite different.

Thhhh-aaa-ttt's it.

Oh, one more thing - Fortran is/was and still remains primarily aimed at engineers, not mathematicians. It is better suited for solving large systems, then calculating pi to a ka-zi-llionth decimal. I don't know if that was a typo in your question, or intentional. For purely mathematical applications (in a classical sense of mathematician) I would (were I a part of that field) probably choose, I don't know, Mathematica? Or Pascal (don't know why it was always Pascal; but it seems terribly popular with those chaps).

I'm surprised that the consensus here is for modern Fortran, and I grudgingly agree.

Whatever its failings, Fortran is the only language out there being designed explicitly for scientific programming. Scientific programming is both more subtle (per line) and less complicated (in structure) than, say, a web server, and it just needs different tools. Garbage collection, for instance, is almost never useful for solving large 2d/3d PDEs where your primary data structures are fixed.

Any programming language that doesn't even have multi-d arrays as first-class objects can be dismissed immediately for scientific programming. and that's all of the C-based languages. Any programming language which is inherently god-awful slow -- Java, I'm looking at you -- can be dismissed immediately. Any programming language which is proprietary and requires thousands of dollars of licensing fees -- Matlab -- can be dismissed immediately.

Python and related languages are good for prototyping, and plotting is easy, and once you've got things working can write the numerical kernels in compiled languages for speed; but it again suffers from the lack of real arrays (Numpy is good, but not great) and it is s..l..o..w.

By the way -- don't ever by the Numerical Recipes books. They're crap, the algorithms they pitch are of date, and the code ranges from poor to wrong. Take a real numerical algorithms course - there's good ones on line - or buy a real numerical algorithms book -- and for the love of God, don't type in code from a book to do linear algebra or whatever; use the zillions of real, professional quality libraries out there.

For the most direct answer to your question, I think that kemiisto's answer is correct, with the caveats identified by Idigas.

That said, I've found more of my numerical code coming into contact with things like FTP, web, and closer to graphics. I've seen MATLAB suggested in another answer, but I've been writing more and more Python (with NumPy) and calling out to Fortran when I need the speed. I'd almost certainly not write a whole system (e.g. an entire numerical weather prediction model) this way, but it does allow me to have the best of both worlds in many respects.

Or is the answer Fortran 90, 95, 2003 . . . ? Yes. For scientific computing, Fortran >=90 removes the limitations of FORTRAN 77. Learn how to use allocatable arrays to have dynamically sizable arrays. Learn how to use modules to organize your procedures and variables -- and easily provide automatic consistency checking between actual and dummy arguments. Starting from FORTRAN 77, you can gradually learn Fortran 90/95/2003, using whichever features seem useful to you. You don't have to learn the OO features and can ignore that portion of the language, until perhaps someday it offers utility to you.

I recommend the Metcalf, Reid and Cohen book.

You may be looking at MATLAB. Many engineer undergraduates learn that so I think it's easy for non-programmers to grok.

If you want to get hardcore, take a look at J.

I think Fortran 95 should be your choice it looks more modern and extends Fortran 77 quite significantly. The Fortran 2003 standard is not completely supported by most compilers. The great advantage of Fortran is that there is an optimized subroutine for every mathematical problem (such as root finding, matrix multiplication, eigenvalue problems, etc.). Other people mentioned legacy libraries and lapack is just one very powerful example. A major disadvantage of Fortran is that nobody is using it in the real world.

The best book around is is my opinion "Fortran 90/95 for Scientists and Engineers".

Of course all other suggestions are valid, but matlab is not free while Fortran is.

Python is free and has support for a lot of scientific applications through extra packages such as Numpy and Scipy. Python is however rather slow when it comes to numerical performance. It's probably a good option for small projects that don't require a lot of computational power. The syntax is very easy to understand.

C is of course also a free option and has a lot of (constantly updated) scientific libraries available. However, when it comes to readability it cannot beat Fortran. Fortran is well set-up to work with vectors and arrays.

C++ is a superset of C so it's definitely also a possible choice. However, it is a language that might be to complex for the problems that you're looking at. The number of scientific C++ libraries is rather limited. There are some around but they cannot beat the Fortran versions (or are just wrappers of those). It's probably a very good option for very big projects but some very big programs that run on the world's fastest computers are written in Fortran. C++ is definitely worth learning since it is used for a broad number of real world applications.

There are of course other languages or tools but I think these are the most commonly used across scientific disciplines.

If you're really excited about using Fortran, you might consider using Fortran for Microsoft.NET. The idea behind this project is that it allows you to use the Fortran language while taking advantage of a mangaged code environment via the Common Language Runtime (CLR).

@S.Lott: Cannot imagine Fortran users such as scientists, having to switch over and dump all their Fortran work..... :S The OP is looking for input on what's new...

To the OP: Have you read up on Wikipedia which details the changes made to Fortran, for 2003 version, allows interoperability with C, so maybe S.Lott does have a point, perhaps, bit by bit, gently port some stuff over or write a wrapper in C to call the Fortran modules? I'll quote from that Wikipedia page...

Interoperability with the C programming language.

I've worked recently with a lot of Matlab, and I can see it's benefits today. Yes is is slow because it is an interpreted language, but it's matrix algorithms are fast. And I like it exactly because of that behavior. The slowness of the for loops and the performance of the matrix operations encourage you to think in a more mathematical way instead of sticking to loop oriented programming. But I can agree that Matlab can be dismissed, because it is not open.

Currently I am looking forward to the Julia language. It is heavily inspired by Matlab except that it does want to be fast. Also it has static types which is also a very big advantage. But Julia is still very young, so do not expect that does already fulfill all your requirements.

Simple to learn (no object-oriented or functional-programming complications)

Easy to read

Blazing fast at number-crunching

Sounds like C.

Buy Numerical Recipes in C. That pretty much covers all the bases in a clear, readable style.

http://www.amazon.com/Numerical-Recipes-Art-Scientific-Computing/dp/0521431085

I assume you are considering small, dedicated programs written to solve specific problems. In that case, if the complexity of OO really bothered you I'd just write a C# or Java app and not use OO. Visual Basic should be pretty darn fast these days as well.

Nearly all compiled languages will be mathematically quick these days, all operations are done on the math co-processor--so unless you have found some language to be particularly lacking I wouldn't let any languages "math speed" bother me much.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top