ground- water, geo- statistics, environmental- engineering, earth- science

Fortran under OS X

without comments

At work, we have a lot of fortran codes. And some people still develop in fortran. Don’t ask me why… I totally love the python/TextMate combo… well, but I needed to wrap my head around the whole fortran issue. Mostly, people here use Compaq Visual Fortran on Windows XP machines. That is a decent setup. But I wanted to try some things on my mac. So I looked into options. Note: I am still a very user oriented person… I still haven’t gotten very deep into the computer systems…

Firstly, I realized, that one flavor of fortran, called GFortran (with Manuals) is part of the “GNU Compiler Collection” GCC. This is also a very useful site.

I got a little scared, because I thought I have to build gcc somehow myself, and I didn’t know what and how, but then I found the guys at With a very straight forward 4-item cookbook-approach, I had xcode setup so I can edit, debug, and let fortran programs run. Here we go:

  1. Make sure you’ve got xcode (Apple Developer Tools) installed.
  2. Download an installation package from here. This package will install gfortran and the necessary xcode plugins.
  3. Follow these instructions. If you do this you will end up with an xcode project. In this xcode project a c-file will call a fortran file.
  4. If you want pure fortran, use these instructions.

With this setup I can copy my .f90 files from the MS-Compaq compiler to my mac, read them in xcode, and they compile just fine! ATTENTION: copy the entire .f90 files, no copy and pasting, especially not through email! That destroys the file-setup.

If somebody knows anything about how to couple TextMate to this setup — let me know!

[Update 20070210]: Re: File Endings

The file ending of the fortran file is important as to how xcode interprets the file for compilation. *.f leads to fixed form fortran77 type. *.f90 leads to free from fortran95 type. The file ending should be changed in xcode by right clicking on the file in the “source” area.

[Update 20070210_2]: Re: location of input files

Say the xcode project you’re working on is called “FileIO”, and is located at


Then an input file opened through the command

OPEN (UNIT = 3, FILE = filename, STATUS = 'OLD', ACTION = 'READ', & IOSTAT = status)

needs to be stored in


Otherwise an IOSTAT = 2 error occurs.

[Update 20070211]: Re: debugging “jstingley’s” points on macresearch regarding debugging are very important

  1. In the project window, Groups & Files pane, select your target (open the Targets group) and then click the Info button in the toolbar.
  2. In the Target “myfprog” Info window select the Build tab.
  3. Select Configuration: Debug (pop-up).
  4. Select Collection: Language (pop-up under GCC Fortran source compiler).
  5. There’s only one setting: OTHER_FORTRANFLAGS.
  6. To the right in the Value column, double click and enter “-g” (w/o the quotes) and “return”.
  7. Close the Info window, rebuild (w/ Debug as the Active Build Configuration) and then run the debugger. You should now see the program pause at your breakpoints and the current module’s variables displayed.

    Make sure you select the Target Info and make these settings. It doesn’t seem to work if Project Info is selected and the -g option is added there.

Written by Claus

February 7th, 2007 at 9:59 am

Posted in

Tagged with

Leave a Reply