- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Another nice tool would take all the USE statements that don't have ONLY and add just the ones that really are used.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Another nice tool would take all the USE statements that don't have ONLY and add just the ones that really are used.
Automating the implicit to explicit is a false hope type of adventure.
The automation would not know the size of the integer or real (or other types). As part of your conversion effort you will also need to run the /gen-interfaces /warn:interfaces such that you can catch errant calls to the subroutines.
How many subroutines/functions are you looking at to fix?
An editing script could be written to perform the insert IMPLICIT NONE (and comment out IMPLICIT type(...))
I wrote one in TECO to handle ~750 source files.
The variable usage needs to be looked at due to old legacy code assuming particular sized variables for INTEGER and REAL. Might as well bite the bullet once.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
One thing on the gen-interfaces. It doesn't seem to always update the interface it has generated. I have several times fixed a problem and tried unsuccessfully to recompile. I sometimes need to find the interface and delete it to fix the problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
One of the principal reasons for using IMPLICIT NONE is to catch problems of specifying a variable you expect to be in COMMON or in MODULE but forgot the INCLUDE or USE. Replacing IMPLICIT NONE with IMPLICIT REAL(A-H,O-Z) will defeat the purpose of using explicit declarations.
This may seem like mindless work, until using the other way, you spend two weeks tracking down a bug relating to a bug where a variable is local as opposed to residing in COMMON or module. (or worse yet you included the wrong COMMON include file(
Too often is the case you have "Gold Code" that breaks due to an innocuouschange in aheader file.
I recommend you take the time to fix the code. It will save you time later, and give you another look at the complete code, and in the process will pick up a few other problems or discover improvements.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would like this feature also and had actually also thought about posting if anybody had an automatic procedure to do this.
I have a 100,000 line legacy program with thousands of undeclared variables. Automatically making the current variables (which all non-array variables are integer*4 or real*4) wouldn't fix any problems, but at least I could use implicit none here on out and not add to the problem (and catch a few more bugs early). As it is, I don't have time to fix the existing situation by hand. So I don't use implicit none and therefore, it is not clear when something is misdeclared/misused.
The program also was based on common blocks. I have converted all of these to modules, but of course, none of them have the use "only" syntax. I would very much like to have them all be "only" since many modules have hundreds of variables in them only a few of which any one subroutine uses. But my project manager has never been keen to give me a couple of years to rewrite the program from scratch.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would like this feature also and had actually also thought about posting if anybody had an automatic procedure to do this.
I have a 100,000 line legacy program with thousands of undeclared variables. Automatically making the current variables (which all non-array variables are integer*4 or real*4) wouldn't fix any problems, but at least I could use implicit none here on out and not add to the problem (and catch a few more bugs early). As it is, I don't have time to fix the existing situation by hand. So I don't use implicit none and therefore, it is not clear when something is misdeclared/misused.
The program also was based on common blocks. I have converted all of these to modules, but of course, none of them have the use "only" syntax. I would very much like to have them all be "only" since many modules have hundreds of variables in them only a few of which any one subroutine uses. But my project manager has never been keen to give me a couple of years to rewrite the program from scratch.
Jarvus,
So you want explicit variables without having to explicitly declare the variables. Kafka-esk programming requirement.
What I would do is
0) copy entire program tree to test directory
(don't do automated edits on existing code base, perform edits on copy of code base)
1) use editing macro to assure IMPLICIT NONE were in all subroutine and functions
2) use VS to run test build with no limit on numbers of errors/warnings
3) Select all of output window, copy to clip board
4) open NOTEPAD and paste into notepad window and save as text file, then save as 2nd copy of text file
5) write editing macro to squnch text file for use as editing inputby subsequent editing macros(keep path and filename plus list of variable names to change, remove redundant variable names)
6) use resultant file as input to editing macro to tidy up all the programs with REAL(4) :: ..., INTEGER(4) :: ...
I personally would use TECO to run the editing macros but you could use AWK, Pearl, ???
Could take less than 1 day to do the conversion.
You may find some problems, but adding exception code to editingmacros would be relatively easy work.
I've done this with solutions containing 13 projects, 750 files, ~600,000 lines of code.
You may be timmid to do this at first, as long as you work off copies of your files you won't break anyting.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jarvus,
So you want explicit variables without having to explicitly declare the variables. Kafka-esk programming requirement.
My reading is that he only wants to do it once, to "convert" the existing code to more modern style. Further maintenance (addition/removal/changing of variables) would be done by hand, as usual. If there happens to be a misspelled variable somewhere, tough luck -- it would get declared along with its correctly spelled pair.
I have a source tokenizer, written in Fortran, that scans through lines and finds tokens; from then on, it's a moderate effort to use it to recognize variables (more precisely, non-keywords), sort them out, and declare them according to implicit rules, then automatically rewrite the source files with declarations inserted into appropriate places. However, if you have INCLUDEs (with e.g. COMMON and PARAMETER declarations), that could significantly complicate the process. In that case, Jim's suggestion would be better indeed (or if you can find a similar tool elsewhere)...
You might be better off asking in comp.lang.fortran newsgroup, for a more widely profiled audience; if such a tool exists, someone there would know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
http://www.polyhedron.co.uk/spag0html
It appears to be part of plusFort - many years ago it was stand-alone.
http://www.polyhedron.co.uk/pf-plusfort0html
Pricing seems 'high', but about the same as a day of staff time at typical charge-out rates.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much for all the comments and suggestions. This isn't my top priority, but when I saw the thread that alreadyasked about it, I thought I would add a "me too". I will look into the Spag/plusFort. I was afraid to try and change thingsby hand. Beside the amount of time it would take, if I explicity declared a variable of the wrong type (pretty easy to dogiven the number of declarations we are talking about),I would be adding a newbug to a part of the code thatpreviously worked (just didn't seem worth it) and I'm not already proficient with any off the shelf script tools that wouldsemi-automate the process. Having this cleaned up so I could do implicit none for all new code (including changes to old code) would be nice.
Maybe Spag/plusFort will do this also, but I'm also interested in an automatic tool to change my use module statements to use module only. Again, I'm afraid to do this by hand because ifI miss anyvariables, and thus turnthem intolocal variables, I've added bugs (and they could be hard to track down). I suppose if I do get my code to implicit none compliant, missing a variable would be more apparent.
Thanks once again. I appreciate the time that is spent to offer upall the tidbitsyou findin these forums.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The problem you will have with the automated tool is it may make the wrong decision. In particular it may make bad code that works on your old system (more by accident than by design), into bad code that doesn't work on the ported system (new compiler new platform). A particularly annoying problem aside from implicit types is duplication of variable names in various commons and includesas they are "ported" into modules.
Too often I have found the case where very commonly used symbol names such as T1, TEMP, X, A, etc... exist in many places in the program. The old version of the program worked when using the wrong instance of the variable. When reworking the code, by consolidating COMMON into module you will run into the case of having the same named variable in different modules. This by itself is not bad unless you have a source file that now must use both modules. This should be fixable with use only... but at times this is not sufficient due to neither being the correct variable to use.
Using an automated tool provides for a false comfort. It may work 99.9% of the time. But that last 0.1% may cost you more time to locate once it is hidden by the lack of compiler error/warning message.
Jim Dempsey

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page