-1

I'm having problems fitting LAPack subroutines, written in f77, into an f90 program. Gfortran is the compiler.

I know that f77 is supposed to be a subset of f90, but for example * is not recognized by the compiler as the start of a comment. It recognizes much of the code, but gives out a large list of errors.

My first idea was to compile program units separately, but I know nothing about f77 modules, if they exist at all.

How would you go about doing this?

Steve
  • 41
  • 6
  • Something I should have indicated in the original post is that things like * at the beginning of the line are not recognized when the subroutines are included in a .f90 program. – Steve Apr 24 '15 at 10:22
  • 1
    You should include the error messages, your compilation commands and a small relevant part of the code. – Vladimir F Героям слава Apr 24 '15 at 10:32
  • Compilation commands are as usual: gfortran progname.f90. The errors of given my the compiler are primarily syntax errors. The code is voluminous and I don't see what I could include that could help. Imagine a usual f90 program and subroutines in f77. – Steve Apr 24 '15 at 10:38
  • 2
    Fortran 77 code can't be in a .f90 file. Fixed source form files use .f or .for. You cannot mix fixed source form and free form source in one file. – Vladimir F Героям слава Apr 24 '15 at 10:40
  • @Vladimir F Then how would you go about compiling this? Excuse my newbie questions, I haven't been programming in this language for very long. – Steve Apr 24 '15 at 10:42
  • @Vladimir F That was my initial thought but I was reading up on f77 modules and these seem to be a new feature in f90? How do I put subroutines into a different file in f77? – Steve Apr 24 '15 at 10:45
  • @Vladimir F But it's a program, module, what? Remember they are subroutines that will be used by the main program. In f90 you'd put them into a module and the main program would call from the module. How do you do this in f77? – Steve Apr 24 '15 at 10:49
  • 2
    I'm puzzled. Lapack was rewritten into Fortran 90 some years ago. Why are you working with old sources ? – High Performance Mark Apr 24 '15 at 10:52
  • They are just external subroutines. Or create normal fortran 90 module, but keep the fixed source form. You really should study the differences between the source forms. – Vladimir F Героям слава Apr 24 '15 at 10:53
  • Hmm, to clarify my earlier puzzlement. While Lapack was rewritten into Fortran 90 (kind of) the sources ARE still in fixed-source form. I suggest OP study the many questions, and answers, here on SO relating to the compilation of programs combining both `.f` and `.f90` files. For example see http://stackoverflow.com/questions/16342259/how-to-use-fortran-77-subroutines-in-fortran-90-95/16349742. I don't have time to search further for you right now. – High Performance Mark Apr 24 '15 at 11:01
  • rescinding my previous comment, lapack does indeed use asterisks for comments, and that is f77 standard.. – agentp Apr 24 '15 at 15:39

1 Answers1

1

The solution is to include the LAPACK subroutine and dependencies (subroutines that are called by the main one, those called by these, etc.) in a single .f file. This file is not a module or a program unit of any kind, it's just a text file that contains all subroutines in no particular order, one after the other.

One must be careful because LAPACK often misses dependencies in the .tgz file that is supposed to contain them. There is a network where every subroutine is discussed, and where a map of dependencies can be found, to be found here: http://www.netlib.org/lapack/explore-html/. Check to see if ALL called subroutines are present, and if they are, put them all in one file to make for a simpler compiling command. Also, alter the main code so that all arguments are declared and considered in the main program. The arguments of every subroutine are described in the above network, so they are easily identifiable.

If using gfortran, compile the .f file as an .o object file. This acts as a sort of f77 module which contains all necessary subroutines. It is done through the following command:

gfortran -c filename.f

-c indicates that the file will be compiled as an object file. It is important that all subroutines written in FORTRAN 77 be in a file that is separate from everything written in f90.

There is no need for any "use" statements, as no actual FORTRAN module is being used. Call the necessary subroutines where necessary without worrying about this.

The command for compiling considers the object file as the linked library:

gfortran filename.o progname.f90

This explanation is very distilled and surely most of you know this already, but it was a newbie question that took many hours of research due to things that are not clearly explained in the literature. It is for my own future reference and hopefully it will help other beginners aswell.

Steve
  • 41
  • 6