School has begun again and I’m taking three classes that will necessitate number crunching. My research also demands precise, high-powered computation. Naturally, I knew I had to go from casual, sloppy Fortran user to master Fortran ninja.
Getting serious with Fortran
I’m almost done learning Fortran 90/95 according to Chapman. It’s a pretty good book for Fortran beginners (especially those engineers who started with Matlab and are looking to actually start learning a programming language). But if your goal is to simply learn how to program, go with Python.
If you already know Matlab, Fortran is not much of a leap. If you weren’t aware, it’s not ALL YELLING, as the case-sensitivity from FORTRAN 77 has gone away (but you still may NEED TO READ IT if you go back to compile older codes from antique projects). I haven’t had much difficulty getting through all of the examples, and now I feel confident writing, compiling, and executing my codes. I also feel much better about debugging. Previously, my experience was obtained by compiling and running existing Fortran codes. Debugging was difficult without knowing how to speak the language. So I bought Chapman’s book and ran with it.
Some lessons learned
1. Because Fortran is absurdly systematic, you learn to love flowcharts. I used to ignore flowcharts (which is why Ben has historically been a garbage programmer). I knew it was one of my weaknesses, so I’ve started taking a much more rigorous approach to the process. Programming is obviously one of those activities where adequate preparation will show in the result. As an (aerospace) engineer, you often could get away with starting a project in Matlab by just typing your thoughts and equations, and pressing run until you got the desired results. Impossible in Fortran, so I learned to love flowcharts.
2. Understanding how to compile and debug code is a lesson best learned before you start writing code. I highly recommend obtaining very small, simple, and previously written codes so that you may compile and understand how they work with Fortran compilers. I’ve come across several examples in Chapman where I used my experience compiling and debugging codes to get through his example problems. Sadly, books aren’t bulletproof, and you should be at least somewhat familiar with programming concepts before you start with this book. Chapman’s mistakes were small and infrequent but could cause frustration to a programmer with no room for error. I don’t recall finding an error in his examples, but I found a couple in his Figures (which are just pictures of code…).
I mentioned compilers, so I’ll digress here. The best compiler to obtain is Intel’s Fortran compiler, ifort. It can be obtained for a pretty penny, or if you’re just testing and learning, grab it off their Non-Commercial Software Download page. However, if you’re under a time crunch, or if you prefer simpler and less complicated barriers to entry, try gfortran. It’s not as well maintained or cool (when engineers think cool, they think high-performing, with neat tricks and features, etc.) as ifort. gfortran can be downloaded very easily onto an Ubuntu 11.10 machine by simply issuing the command through the terminal window:
$ sudo apt-get install gfortran
It was not pre-loaded on my distribution. I would rather not spend the hour or so (45 minutes for download…if you’re fast) of installation procedure when I could simply install gfortran in one line. The ifort installation is not rocket science, but it’s not a walk in the park, either. So it’s somewhere between a walk in the park and rocket science. If someone says “it’s not rocket science” they usually mean it’s trivial. If an aerospace engineer says “it’s not rocket science” they’re probably being snarky and it’s plainly difficult.
There are plenty of resources on how to compile your codes in Fortran, but they’re not in books, typically. Books will illustrate the processes of compilation and how source code goes to object code, etc. but typically won’t demonstrate how exactly to compile your code. The answers are on the internet, so search thoroughly. I may write something soon on the topic.
3. Fortran is not an engineer tool that will set you apart in the computational sciences. It is a prerequisite. If your career is moving in that direction, pick up Chapman’s book and start learning today.
The purpose of this post
Originally, I wanted to write about a specific problem I ran into on Example 6-4 Gauss-Jordan elimination in Chapman. I had to figure out a compiling issue because Chapman did not specify what the input file would look like. I won’t post the answer here because it’s fun to figure out on your own. It was more important for me to generalize the lesson I learned and then articulate the main ideas I’ve learned since I picked up Chapman’s book. I’ll probably comment again on the overall quality of the text when I’m finished with it, but I’ve enjoyed it thoroughly thus far.