Fail to compile legacy code

Disclaimer: I have little experience with fortran, but recently I need to read a very old routine mirkdc for a project, so for now my goal is simply getting this code run locally.

MIRKDC is a solver for BVP and there are also a driver on netlib.

I try to compile mirkdc.f90 and mirkdc_driver.f90 locally but always got a lot of errors.

gfortran mirkdc_driver.f90 -o mirkdc_driver

Besides, when I opened mirkdc.f90 file using vscode, the extension seems doesn’t recognize the comment?

It would be great if anyone can try to compile this program and make the code run locally.

Welcome to the forum!

The first thing to note is that the code is in so-called fixed form. This is the original layout for Fortran source code. Ever since Fortran 90 there has been a second form, called free form, that is more flexible and preferred by many (most?) programmers. The two forms are commonly distinguished via the file extension: .f for fixed form and .f90 for free form. This is not chiseled in stone, but it does help to use this convention.

The first thing to do then is to rename the two files to .f. That should help the compiler to compile it correclty.


I downloaded the two files and used gfortran to compile them. With the default options I got messages about rank mismatches. That is a consequence of an ancient idiom. Use -std=legacy to get rid of them. (They are then turned into warnings).

You will need BLAS routines to actually build the program.


Expanding on this: the original file seemed to have different indentation from the screenshot shown here. The keyword subroutine is indented 6 spaces in the original file, and the + continuation character is in the sixth column.

Fixed form requires the the first six characters to be blank, unless a continuation is used. It also assumes lines are ended unless explicitly continued. Here, on line 1 we see an error at the end highlighted because the line should be continued but is not.

1 Like

Thanks a lot!!! Now I know why I can’t compile them.

@Arjen I followed your instruction but the code still seems weird(the indentation are all wrong here) Could you help me by telling the detailed flow of how you successfully ran the code? , e.g. the detailed commands and operations. It would help me a lot!

Well, I copied the code from netlib, as per the links you showed. By simply copying from the webpage, which preserved the indentation in my case, I got the source files I required. My command-line read:

gfrotran -o testing mirkdc.f mikrdc_driver.f -std=legagy

As there are a number of routines (from the BLAS library) that were not included in that build command, I got a list of unresolved externals, but the compile errors were all gone - turned into warnings.

1 Like

Thanks a lot guys!!! The code is working on my computer!!
By linking with BLAS:

gfortran -o testing mirkdc.f mirkdc_driver.f -std=legacy blas_LINUX.a

The driver program is working fine and I can specify the input parameters on command line!! It is so great to have you guys!!!:grinning:

Great! Good to hear that :slight_smile:

1 Like