Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Meaning of IMPLICIT REAL*8(A-H,O-Z)

Status
Not open for further replies.

niloy112

Programmer
Mar 5, 2013
7
CA
Dear All,
I have found this notation.
'IMPLICIT REAL*8(A-H,O-Z)'
why we use this instead of
'Implicit none'
Thank you
Niloy
 
Well, those are two different things.

Implicit none says that you have to explicitly declare all your variables before using them. If you come up with a new variable in the middle of your source code, the compiler will complain and make you go back and declare it. You can declare variable whatever type and size you want to, but you have to do it yourself.

Implicit REAL*8(A-H,O-Z), on the other hand, allows you to go the implicit route where you can come up with variables along the way, as needed, without having to declare first. Additionally, all those variables would be REAL*8, which is NOT the default size; default is REAL*4, or simply REAL.
 
... and this statement means that all variables with names beginning with either letter of 'a' to 'h' and 'o' to 'z' are declared real*8.

But still, this is poor programming style. 'implicit none' is a very powerful means to avoid typos while coding.

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Thank you both for your reply.
say i have a given value say (8/9)^0.5 and it is fixed.
I want to define it this way,
Real,parameter::x1=(8/9)^0.5

But they are showing that i cannot do this..but why? is my value value contain long significant values?

Niloy
 
Is the character ' ^ ' the exponentiation operator nowadays? I thought it was double asterisk.

In any case, you cannot perform an exponentiation operation with a non-integer at compilation time...the compiler is not your running program just yet...you want that kind of value as a parameter? Either calculate it as a regular variable later, or calculate the value once with your calculator or a 3-line fortran program and then hard code the value in your program.

it is just that the PARAMETER statement expects a constant expression, so, it handle most operations, but exponentiation with float seems to be a bit to much to figure out.


 
Why would you want to make x1 a parameter?
For whatever you want to do in your program

real*8 x1
...
x1 = (8/9)**0.5

will do the same job.
'paramater' means that (1) you cannot edit this variable in your code and (2) variable name and variable value are equivalent to each other. As far as I know, the compiler would include the value into the executable whenever the name is referenced.

The usage - at least the only real sensible usage - is to name paramters to control certain features of your prog.

Example:
Say, the user shall be able to select the language of the message prompts. so You will have a variable iLanguage that may show the values as follows

iLanguage = 1 means English
iLanguage = 2 means French
iLanguage = 3 means German
iLanguage = 4 means Italian
...
...

In your code you will have to do the selection like
Code:
select case (iLanguage)
   case (1)
      output in English
    case (2)
      output in French
    ....
    ....
end select

but if you use parameters, then you could have it like this

Code:
integer, parameter :: iEnglish = 1
integer, parameter :: iFrench = 2
integer, parameter :: iGerman = 3
...
... (customer to select language)
...
select case (iLanguage)
    case (iEnglish)
         output in English
    case (iFrench)
         output in French
...
...
(end select)

So while coding or debugging you do not have to memorize which value indicates which language.

I do not know of any other sensible way to use parameters.



Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top