Mixed Fixed and Free Comments and Continuation Syntax

Mixed Fixed and Free Comments and Continuation Syntax

I am using Intel Visual Fortran 64 Compiler XE, Version Build 20110427 from a Windows 7 command line.

Here is some example code I am trying to compile:


!       This is a comment    
C       This is also a comment
c       This is also a comment

        PRINT *,"Hello, world."  ! An inline comment

        PRINT *, &
                "This is the new continuation type."

        PRINT *,
     &          "This is the old continuation type."


I have a very large code base with mixed fixed and free syntax in both comments and continuation syntax.  A co-worker is using a different Intel compiler (Version 11.1 Build 20100401 in Linux), and is able this mixed syntax without a problem, but I cannot.

I have found that if I use the /free option, I get syntax errors on both the comments that do not start with "!" and the old continuation syntax.  If I use the /fixed option, it seems to be OK with both old and new comment types, but chokes on the F90 continuation syntax, with the "&" at the end of the line to continue.  

Any advice on how I can get this code to compile without changing it?  We're talking tens of thousands of lines of legacy code, so I'm trying to avoid that.


12 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.


You may try putting the & in column 73, assuming 72 column wide for fixed format - if you have the option for 132 character wide, then it would need to go in column 133 or further to the right.


Is the mixed source form in the one file?

The "intersection" source form that David mentions is useful for small snippets of source that might be INCLUDE'd in larger source of unknown form, but I wouldn't go rewriting large code bases that way - if you are going to rewrite things then just rewrite it to the free form rules and say goodbye to fixed form for evermore.

You also have the !DEC$ FREEFORM and !DEC$ NOFREEFORM directives that you can use to switch source form mid file.  But you'd only use these as a transitional work-around (or again - perhaps because you had a INCLUDE file that was of different form to the including file).

If you do have mixed source form in the one file, and it isn't a transitional "work in progress", then whoever did that has some explaining to do!

I also had tens (if not hundreds) of thousands of lines of legacy code to convert. I wanted them all in complete free form. After laboriously converting a few programs manually I finally decided to write a small program (in Fortran!) to do the conversion for me. Didn't take as long as I had anticipated and it works great. In addition to handling comment and continuation lines, it also converts .LE. to '<=' etc. It's simple to use and pretty user-friendly. I would be happy to give it to you (no obligation / no guarantee) if you just send me a message.

I believe there are other commercial converters available that do more and are probably pretty slick, but I can't recommend any and have no idea what they cost. 

Frequently used fixed f77 to free form f90 converters include Metcalf's convert.f90 (free) and Polyhedron Software plusFORT

I am pretty sure that your coworker is mistaken in saying that version 11.1 accepts this kind of mixture. As David says, it is possible to write source that is acceptable to both fixed and free form, but the sample you showed isn't. 

Retired 12/31/2016


Good idea.  I gave that a try, and no luck, unfortunately.



Thanks.  The !DEC$ FREEFORM and !DEC$ NOFREEFORM might work in some cases since lots of the include files are fixed form, and mainly the code is free form...at least it might reduce the amount of conversion we need to do.



Thanks for the offer, but my I.T. department would blow a gasket if I brought in software without their permission.  I'm glad you got yours fixed, though, and I may look at other open source to see if I can re-use.


@Tim Prince,

Thanks.  I will take a look.


@Steve Lionel,

I know what he has builds and runs...it's ancient code, and he may have some tricky makefile stuff going on that I don't understand.  OR, my code isn't a good represenative example.  I'll dig deeper and post again when I understand which.  Right now, we're leaning toward converting to all free form or all fixed form (my vote is free); we're trying to figure out which will cause less pain.




John K. wrote:

.. Right now, we're leaning toward converting to all free form or all fixed form (my vote is free); we're trying to figure out which will cause less pain...

I hope y'all end up voting for free-form.  With fixed-form, at most you will postpone the pain.  Another thing to note, based on our experience, is that no good young talent wants to work on FORTRAN code i.e., FORTRAN 77 and older style code; fixed-form with all the accompanying restrictions being a huge detriment.  Perhaps you don't have this problem yet, but sooner or later, definitely in less than a generation from now, you will find few people wanting to touch the "legacy" stuff which generally means a death sentence.

By the way, re: continuation line, the following may be food for thought:

      PRINT *,     &
     &   "This is acceptable in free-form." 


Leave a Comment

Please sign in to add a comment. Not a member? Join today