×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

read number in if sentences

read number in if sentences

read number in if sentences

(OP)
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

RE: read number in if sentences

that syntax is wrong; Fortran generally doesn't use
 two equal signs "==" for that purpose.

RE: read number in if sentences

(OP)
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))

RE: read number in if sentences

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.

RE: read number in if sentences

And in the dear dead days beyond recall "==" was .EQ.

RE: read number in if sentences

I still use .EQ.  !

RE: read number in if sentences

(OP)
johnhors,

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

RE: read number in if sentences

(OP)
If I use:

If (a==(parameter))

it says "user breakpoint called from code 0x7c901230".

RE: read number in if sentences

what level of Fortran did they introduce "=="? I too still use .EQ.

RE: read number in if sentences

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

RE: read number in if sentences

(OP)
Thanks to everybody now is working!

RE: read number in if sentences

The relief is palpable...

.EQ. rules ok... clown

RE: read number in if sentences

(OP)
ehehehe thanks again

RE: read number in if sentences

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    smile
dan@dtware.com

RE: read number in if sentences

Never.

The sky is falling...

"==" in FORTRAN.

Doomed, I tell ye, doomed.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close