Monday, May 6, 2013

Of Fortran and Physicists: Part II

Part I: The Trinity of Physics Research


Part II:
Why Fortran?

As mentioned in Part I, physics research is divided into three branches: Theoretical, Experimental, and Computational. In the case of computational physics, research is aided by exteremely long and complicated computer codes to models their physical systems. I have seen computational physicists use all sorts of programming languages, ranging from C++ to IDL. In most cases, it is up to the individual researcher which language they feel is best suited for their particular project. That being said, it is typically best to use a language that everyone in your field knows, that way other researchers can check your work or look for bugs. In the case of some fields, that language is the ancient ancestor of all modern languages: Fortran.

As I said before, Fortran is the ent of the coding world. Even so, for computational research it can do just as much as C++ with only slightly retarded speed. Fortran, fortunately, has a computational advantage to every other language used in research today: it was built specifically for computation. Fotran, you see, stands for Formula Translation, and when the world was just learning how to code, this language stood above the rest for that purpose. It was so heavily used that millions of lines of code were written before other languages (such as C/C++, Fortran's greatest computational rival(s) today) took their first steps into the field. There was, in fact, so much momentum toward a Fortan-centric environment, that a good number of physics departments still use the language today.

You might have noticed in my "hello world" post, I left six spaces before every line. What were those spaces for? Well in the olden days, when Fortran still had to be printed to punchcards, those six spaces were necessary for the card to run through the system. Yeah, Fortran is that old. Still, those six spaces can be used for some nifty little tricks. You can, for example, replace spaces 1-5 of those six with a number. Any time you call that number in the code, it will automatically know which line you are referring to. That's a pretty nifty feature. On top of that, if you wish to continue a line, you can place just about anything in the 6th space, and fortran will know to read the above line along with the current line. Little features like these actually make fortran a very clean and readable language. 

Fortran codes, like most other computational codes, are written with readability and reliability in mind. That being said, unlike some more modern language, the syntax is still archaic. It might take a few days (or a glance at my upcoming post) to decipher it. Now the question: Should you learn Fortran? That depends, do you plan to research with a fortran-centric group? If so, then of course it would be better to learn Fortran than to try to duplicate their code with C or something. Unfortunately, there are very few other reasons outside of computation to learn the language. It's quircky and has some neat tricks, but don't waste your time on something you are not going to use. Still, it is the king of computational code, and it might be worthwhile to become familiar with how the language works. You can never learn too many languages!

No comments:

Post a Comment