- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a legacy Fortran program, where each line starts in column 7 except for statement numbers (in column 1) and continuation marks (in column 6). I have tried to get the editor in Visual Studio 2010 to behave this way, but cannot find any combination of settings where the first tab goes to 7 and others add 4 from that point.
Just now the code is a mess, with some lines starting in 4 via a tab, but others starting at 8 because of a long statement number. Those lines do not line up nicely as before.
Does anyone know how to do this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If your 500 KLOC (kilo lines of code) are being happily digested by the compiler, I'd leave the code alone. Making it look nice in one editor is just not a good enough reason to incur the risk of replacing tabs by an incorrect number of spaces and have some source lines stretched beyond column 72. Converters are useful, but they invariably produce results that need manual touch up.
If you are going to maintain the code, I suggest that you split it up into one subprogram per file. Then, when you wish to update one or more of those subprograms, you can also convert just those files to cleaned up fixed form sources or newly formatted free form sources. Then, before you update any of those modified sources, build and run some reference cases to check that the beautification has not affected the program output results.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tabs in source are subject to different interpretation (or may be regarded as causes of syntax errors simply by being present). How a particular program text editor displays code containing tabs -- that is not really useful. See the advice regarding tabs at http://fortranwiki.org/fortran/show/Modernizing+Old+Fortran , under the heading "Tab Characters in Source Code".
How big is the source file in question?
Those lines do not line up nicely as before.
Sorry, "nicely" is very subjective.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The program is about half a million lines of code.
By "nicely" I mean that adjacent lines of code all start at the same column.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, that is exactly the reason I myself dislike tab characters ;). You should probably be able to expand them into the correct number of spaces via your text editor or some other tool or, failing that, write a small program (in, say, Fortran), to convert those tabs into a number of spaces that will put the code into the right position.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Make sure to keep backups of those half-million LOC.
Please try Urban's http://fortranwiki.org/fortran/show/notab .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It looks like the world has moved on from the days of punched cards, and I'm thinking of converting to free-form Fortran. It could wind up being a bag of worms, however, which is why I haven't done so yet.
I can change the tabs into spaces with the VS editor -- but then the compiler doesn't like all those characters in column 6.
Long ago I found a way to make the VS editor put the first character in column 7 and tabs at four characters thereafter. But after migrating to a new PC, I lost those settings and can't find them again.
Does anyone have experience with a free-form converter program? There are some out there, but I dread the worms.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If your 500 KLOC (kilo lines of code) are being happily digested by the compiler, I'd leave the code alone. Making it look nice in one editor is just not a good enough reason to incur the risk of replacing tabs by an incorrect number of spaces and have some source lines stretched beyond column 72. Converters are useful, but they invariably produce results that need manual touch up.
If you are going to maintain the code, I suggest that you split it up into one subprogram per file. Then, when you wish to update one or more of those subprograms, you can also convert just those files to cleaned up fixed form sources or newly formatted free form sources. Then, before you update any of those modified sources, build and run some reference cases to check that the beautification has not affected the program output results.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Excellent advice. I guess I'll leave the code alone, except for cosmetic fixes here and there. Nice to have a second opinion!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can also try to open it with an editor that respect forttran tabulation (Notepad++, old Visual Studio editor) and use it to convert tabs to spaces with the appropriate saving option before saving it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>> except for cosmetic fixes here and there....
Be careful of the choice of editors. Many will unbeknownst substitute Tab for multiple spaces....
...OR... you inadvertently, out of habit, you use the Tab character.
Nothing inherently wrong with Tab character.... as long as you know it represents only 1 character position.
I would refrain from using auto-tabulating software until after conversion to Free Form.
Several times I have been burned where DATA statements get buggered up where the result does not generate compile time errors. When this happens to formerly working programs, finding the error is extremely difficult (code looks good, and problem occurs in code you did not change). Trying to fix a problem that visual walkthroughs check out is extremely time consuming.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
jimdempseyatthecove (Blackbelt) wrote:Nothing inherently wrong with Tab character.... as long as you know it represents only 1 character position
Or not. I know of other compilers that treat a tab as "however many blanks are necessary to the next tab stop" for the purpose of line length. This means that a tab-containing source line that is treated as 72 characters or less in Intel Fortran may get truncated by a different compiler. Tab is not part of the "Fortran character set" and I recommend against its use in new code.
That said, I agree with those who say to not try to "fix" existing code that contains tabs, but realize that they may cause headaches down the road.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is a lesson here. When I migrated to a new PC, I installed Fortran from the original disk. That was version XE 2011. The columns did not line up as previously, and the "C" in column 1 was not recognized by the editor. So I started this thread.
Today I upgraded to the 2013 version -- and the problem disappeared! I post this in the event that someone else makes the same careless mistake.
Now you know. It's a good idea to keep your software up to date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is not fixed, the problem has just gone into hiding for a while
If your code is now 'correct' you can use the advanced options in the VS editor to "untabify" the files, i.e. replace tabs with spaces but retain the current spacing. Please note that you need to use the untabify command more than once per file. If you compile with /stand it will throw errors if there are tabs so you can use that as a test.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A promising suggestion. But when I untabify a line where the text was tabbed over to column 7, as it should be, the tab gets replaced with four spaces, and the line starts in column 5. Since the code already looks perfect and compiles and runs, I think I'll let well enough alone.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Don D. wrote:A promising suggestion. But when I untabify a line where the text was tabbed over to column 7, as it should be, the tab gets replaced with four spaces, and the line starts in column 5. Since the code already looks perfect and compiles and runs, I think I'll let well enough alone.
Can you confirm your code is version controlled? https://en.wikipedia.org/wiki/List_of_version-control_software
If your application (call it Foo) is fully managed in a revision control system, you can create a new independent management "branch", say FooPlus, for code refactoring that addresses the use of tabs and anything else of interest such as transformation to free-form source. Once the branch is fully validated, it can transition to the main instance (meaning Foo itself) while the current 'production' one becomes something else. say FooPrevious.
By the way, here're a couple of links if you decide to pursue free-form source for your code:
http://degenerateconic.com/fixed-to-free-form-fortran-conversion/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is impressive. I'm not on a revision control system, although that is on the horizon. Many thanks for the suggestion.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page