Writing and calling pure routines in Fortran 90 using gfortran

When writing and calling pure subroutines in Fortran 90 using gfortran, how do you know why the compiler is emitting this error?

Error: Subroutine call to XXXX at (1) is not PURE

      

I will try to ask my question as much as I can while at the same time general enough to be useful to others, so I will not embed in my actual code and will sketch out what happened instead.

I understand that there are various rules about pure procedures in Fortran 90, which I think basically boil down to not allowing side effects in functions or subroutines, and not allowing changes to subroutine parameters declared with intent(in)

. I have a series of routines that were not initially declared clean, and whose parameters did not declare intent, but which nevertheless did not perform side effects. Firstly, I have changed all the parameters of the ad to clearly declared intentions, or in

, out

or inout

. Then I announced that all routines would be PURE

. Naturally, on the first try, there were many errors, but the compiler told me what the errors are (for example, such and such parameter with intent(in)

), so one by one I fixed them all.

However, there are calls between these procedures, and now I still get a lot of mistakes in the form shown above: Subroutine call to XXXX at (1) is not PURE

. I don't understand why the call is not clear. I've done everything I can to make XXXX clean, but the compiler still thinks it isn't.

So my question - paraphrased - is: how do I get gfortran to tell me WHY it thinks XXXX is not clean?

+2


source to share


4 answers


"Placed all PURE routines in a library I am working on in MODULE (my client code then USEd) ....... Not sure why ..... but after that there were more helpful error messages that allowed me to trace the remaining impurities. "

Placing subroutines in a module and then using them makes the interface explicit. This allows the compiler to check for agreement between the call and the subroutine and generate error messages if there is a mismatch. Very useful, so placing subroutines and functions in modules is good practice.

Another way to make the interface explicit is to write the interface, but that's extra work and an extra step to get it wrong.



There is a long list of requirements for pure subroutines / functions. If you have Fortran 95/2003 explained by Metcalf, Reid, and Cohen, see Section 6.10. For example, no "save" variables, stop statement, IO for external file, ...

You can also try other compilers to see if their error message is more helpful. Others free, depending on the OS, include g95 and Sun Studio.

+2


source


I will try to be more clear about my question in my answer. I didn't want to post my code for these reasons.

  • I don't expect other people to debug my code for me. This is too much to ask.
  • I wanted my question and his answer to be more general.
  • It seems gfortran was telling me that my routines were not PURE, but that didn't tell me why they thought they were not PURE.

So I was hoping to figure out, not how to fix my code and make the procedures PURE, but rather learn how to coax more useful information from gfortran to help me fix my code.



Two things I have done have helped achieve these goals. Of course, your results may vary.

  • Added this flag to the gfortran command line: -fmax-errors = 100 Of course I've done this before, but I still felt like I didn't know what I needed to know.
  • Placed all PURE routines in a library I am working on in MODULE (my client code then USEd). Since this library lineage is Fortran77, this was not originally the case. Not sure why (which is why I emphasize that "your results may differ"), but after that there were more helpful error messages that allowed me to track down the remaining mixins.

This is kind of a hazy question, I know, and I'm not sure how useful it will be. However, thanks to everyone who read, commented, and added the answer (s).

+1


source


Perhaps because it is not marked CLEAN. The fact that a subroutine is clean is not related to what it does or not to its arguments, but to the fact that it is declared CLEAN. (Of course, once declared as pure, what you do with the arguments comes into play and is checked.)

0


source


I am starting Fortran and last week I came to the chapter on Fortran procedures in my book. Maybe I'm wrong, but ... So if you excuse my english, there are some comments:

  • It's not good style to declare subroutines clean. It is recommended for functions .
  • Pure procedures were introduced in the Fortran 95 standard. Not in Fortran 90.
  • Probably the problem comes from point C1270 in (Fortran 2003 Standard), which reads like this:

If a procedure that is not an internal procedure or operator function is used in a context that requires it to be clean, then its interface must be explicit within that use. The interface should indicate that the procedure is clean.

I hope this is helpful information.

0


source







All Articles