The most portable code: Fortran!

The title might not be fully correct, but pretty close to. To start with I consider here only purely compiled programming languages. I.e. no scripting (no web browser). Then probably as the C programming language is used to build most of the tools, it deserves the first position.

Then indeed, this blog is to advertise the publishing of one of my old library and fortran framework. A bit of shouting cannot harm. But, somehow, I came up with this title for few reasons. For the impatient, this is here

The first obvious reason for this title is that I revived a 10/15 years old fortran framework and it basically compiled with minor changes (which actually where in a perl code used for processing makefiles). But not only on my up to date linux fedora box, it did work also right away on my macbook air 2011.

The second reason is that some of the code is dealing with subjects which where difficult to handle in fortran. It is nice to see that these tools are indeed still working.

The third reason is that the full code of the framework counts about 59000 lines (of which about 10000 of “help” comments and an other 10000 of “free” comments) with 39000 lines of pure fortran code. That of course is not the reason. The fundamental reason is that most of the code has been ported from fortran IV/77 to fortran 90 and not all of it really normalised to the new specifications. Yet, working.

I will publish then a full description of the framework, mainly for historical reasons, but also to let others to grab some ideas. Indeed the code per se, is high quality and tested in a period of about 10 years. At least for the part I (and my coworkers) used most. 😉

The fourth reason is indeed that I am coding in java. So I do know what it takes to match the versions of java with the huge available choice of libraries and tools, and their versions within them. In my personal opinion the portability of java is made vanishing by its fast development. This is especially true if you try to build a secure system which uses few new libraries. You need to be always way back to the current main version and patch for the new code.

But just to get an idea let me point out a couple of things of this fortran framework.

In first instance I call it a framework because there are few shell and perl scripts to help you building your fortran application.

  • After machine configuration, you can select the available fortran compilers
  • The makefiles are autogenerated
  • There is a full cleanup facility
  • There exists basic libraries

It almost goes this way:

  • Create a project directory
  • Put the code inside with a main (program)
  • write a 1 line of library dependencies: -Letc
  • run make from the main folder

It has also a facility to collect all the lines starting with ‘!H’ as help comments for the given function. It includes a directory which will compile latex documentation if it happens to you to write one.

I am sure there are today better frameworks. But i designed it to “bare”, only few basic shell commands (see portability, it did work!), and fully local, no external tools. For this reason there is a copy of the blas and lapack libraries with the distribution. (for this in particular I suggest to NOT  compile the local libraries as usually your machine has very good optimised versions of them. But in case you run out of resources, they are there.)

The fortran libraries included in the package handle different problems:

  • Strings, file ascii lines, and command line for example.
  • It has a fully featured library to handles files.
  • Within these, there is a library to read molden alike format files
  • A part in particular is dedicated to read the “molecule” section of the molden file.

Just for an idea, the code reads (almost) this without any problem:

1   H         1.0 1.0 1.0
2 1 H         1.0 0.0 0.0
3   H 1       0.0 1.0 0.0
    H         0.0 0.0 1.0
    H 1.00794 1.0 0.0 1.0

Almost because the code will warn you that it is reading from different line formats. Just in case the file is messed up 😉

Then beside these basic libraries or modules, there are already few programs you can play with.

The most famous is probably ADFrom. It is not supported anymore, I am sorry. The reason is not that it was not a good code, but simply licensing problems and time. I changed my activities and I could not get anymore a licence for ADF (Amsterdam Density Functional). On my side I did not ask for a free license just to maintain the code as I was not able to keep up with the time. If it would have been opensource: who knows.

The second in this short list is probably the CSM code. Continuous Symmetry Measure. You can use this code to relate molecules to symmetry, and if, you are brave enough, to each other.

Then there is a very fancy and powerful 1d fitting machinery. it is really 1D. I used it to test merging of potential energy surface. (I will update this blog with the published reference to the actual 9 and 10 dimetional merging).

You can fit with different functions, and you can even add them if you can code. The fancy thing is that it reads a unique file with multiple data columns and it can perform basic operations on the data before the fitting. The obvious might be: fit -> col1 + col2*3.14. But the code can get parts of the columns, like: col1[1:200],col2[202:400]*1.01 and fit. As I say, I used it to test surface merging, so it is fancy. In theory you can do it in excel, but in practice not that fast and in particular not that easy to be scripted and saved for each fit.

All the rest of the code copes with polyspherical coordinates mainly for the methane molecule.

I hope I gave a nice overview of this old but still pretty actual code.

The code is here:


Leave a Reply

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

You are commenting using your 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.