Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

read number in if sentences

Status
Not open for further replies.

albert1981

New member
Feb 16, 2007
61
Hallo everybody,

I have this file:

parameter=5

Read(1,*)a
If (a==(parameter))
read(1,*)b
write(2,*)b
end if


where parameter it will be used for differents cases but the problem is that seems to be: If (a==(parameter)).It seems that can not read the number that I give two lines before.

Thanks
Albert
 
Replies continue below

Recommended for you

that syntax is wrong; Fortran generally doesn't use
two equal signs "==" for that purpose.
 
prost,
if I put a number is working:

parameter=5

Read(1,*)a
If (a==(5))
read(1,*)b
write(2,*)b
end if


but not if I put:
If (a==(parameter))
 
By default both parameter and a are real floating point numbers. It is considered bad fortran practice to compare two real numbers for equality, since you are relying too much on the precision of the hardware and software. Variable a may be stored as 5.0000001 and parameter may be stored as 4.99999999


Also 5 on its own is considered to be an integer, you should use 5.0 for single precision or 5.0D0 for double precision.
 
johnhors,

It still doesn't work even If I define parameter and a as integer or as real.
 
If I use:

If (a==(parameter))

it says "user breakpoint called from code 0x7c901230".
 
what level of Fortran did they introduce "=="? I too still use .EQ.

 
Try using something else other than parameter. parameter is a keyword; not a reserved word: just a keyword. It is recognized as part of the syntax and you are allowed to use it but it can be confusing and some compilers may not like it.

In Fortran, if you don't declare a variable, and it begins with letters a-h, o-z, it is real. Real, real comparisons don't always work.
Code:
prorgram main
integer:: param, a, b
param = 5

read(1,*)a
if (a .eq. param) then
   read(1,*)b
   write(2,*)b
end if
stop
end
 
I think you all will find that "==" is nowadays much more commonly used than ".EQ.". I'd venture that this has been true for more than 10 years now for those working with Fortran90 or beyond.

Also... the above code now works due to the use of the variable PARAM. The symbol used to check for equality is irrelevant.

Dan :)
dan@dtware.com
 
Never.

The sky is falling...

"==" in FORTRAN.

Doomed, I tell ye, doomed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor