Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29277 Discussions

how to change implicit type into explicit one

yugn
Beginner
1,037 Views
Is there any solution for me to change all implicit data type into explicit data type in my F77 code?
The implicit type hamper me badly form modifying the source code.
Thanks
0 Kudos
10 Replies
Intel_C_Intel
Employee
1,037 Views
The plusFORT utility from Polyhedron should be able to do it for you.

Alternatively, add "IMPLICIT NONE" before any declarations and the compiler will tell you which variables need to be declared. Then manually add each declaration.

All the best,
Eddie
0 Kudos
yugn
Beginner
1,037 Views
adding "implicit none" is what I want to do, but the compiler wont tell which type the implicit type variable should be set.
I will try Polyhedron.
Thanks
0 Kudos
yugn
Beginner
1,037 Views
What a pity.
There is plusFORT for linux avaiable.

0 Kudos
Intel_C_Intel
Employee
1,037 Views
Unless I have misunderstood the question, maybe the Fortran implict typing rules will help: INTEGER for variable names starting I to N, and REAL for all other letters.

Eddie
0 Kudos
Steven_L_Intel1
Employee
1,037 Views
How is the compiler supposed to know which type you want?

As mentioned above, IMPLICIT NONE will remove all implicit typing rules and will tell you which variables do not have types explicitly specified. The compiler does not have the "mind reader" option to know what type you meant! :-)

Steve
0 Kudos
yugn
Beginner
1,037 Views
I wanna explicitly declare all the variable which already exist in my F77 code.

steve, is there any solution for me?
Is it possible for me to check the type in runtime ?
Is there any utility in win9x for me?

0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,037 Views
As Eddie pointed out, there are commercial tools that can do it for you. Another one is Fortran Partner(there's also a free "lite" version, check if it has that capability).

You can do it yourself as well, with a bit more effort. First, in Project/Settings/Fortran/Listing files, check "Source listing". Build your project. That will generate a set of .lst files in your /Debug folder, containing, among other things, lines containing all variables used in routines:
VARIABLES
 Address      Type  Name  Address      Type  Name
  1-00000008  I*4   I      1-00000004  I*4   M   
ARRAYS
 Address      Type  Name        Bytes  Dimensions

  3-00000000  CHAR  OS             24  (6)
  1-0000000C  R*4   X              20  (5)
You could use a smart find/replace (or write a macro in VS) to convert these to normal declarations, which you should paste into your code. Add "implicit none" to your routines (and/or check Project/Settings/Fotran/Compilation diagnostics/Undeclared symbols warning). Good luck.

Jugoslav
0 Kudos
Steven_L_Intel1
Employee
1,037 Views
Perhaps I'm missing something here...

Jugoslav, how does having a list of all the variables in a routine help in deciding which ones need declaring?

IMPLICIT NONE (or the compiler option /warn:declarations as Jugoslav mentions) will cause the compiler to warn you about each variable used in the program that is not explicitly declared, and the message will name the variable. You compile, look at the variables it complains about, add the appropriate declarations, repeat until no more messages.

What it won't do is automatically generate the declaration for you according to the implicit type. I guess that's what the Fortran Partner (and perhaps others) tool will do and maybe that's what's being looked for?

The problem I have with this is that in many cases I see, the implicit datatype is NOT the correct one! Many programs go for years without this error being noticed - sometimes it's "mostly harmless", other times bad results are being quietly generated. I would not trust an automated tool to make the right choices here.

Steve
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,037 Views
Jugoslav, how does having a list of all the variables in a routine help in deciding which ones need declaring?

Well, every one needs declaring, doesn't it? If one wants to "implicitnonize" the program he needs the list of variables to start with. Exceptions would be common blocks brought in scope via INCLUDE (in which case you'd get redeclaration errors anyway) and module variables (which aren't an issue for OP) anyway.

What it won't do is automatically generate the declaration for you according to the implicit type. I guess that's what the Fortran Partner (and perhaps others) tool will do and maybe that's what's being looked for?

Yep, that was my reading of the question.

The problem I have with this is that in many cases I see, the implicit datatype is NOT the correct one!

Well, there's no magic wand for such situations anyway.

Jugoslav
0 Kudos
yugn
Beginner
1,037 Views
Thanks all of u! :)
0 Kudos
Reply