×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

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!
  • Students Click Here

*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

Jobs

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

eBook - Manufacturing the Cars of Tomorrow
In this ebook, we'll explore how additive manufacturing is going to transform the way cars are made. This includes commentary from thought leaders such as Ford's CTO, Ken Washington, Customer case studies of ways 3D printing is being used today, and a variety of part examples where 3D printing is already impacting how automobiles are made. Download Now
White Paper - Smart Manufacturing for Semiconductor
New technologies and approaches present great opportunities for semiconductor manufacturers to achieve high levels of innovation, yield and improvement. This white paper explores some of these cutting-edge technologies and how they can be applied effectively in the semiconductor industry. Read about how Smart Manufacturing is transforming the semiconductor industry. Download Now
White Paper - Analysis and Simulation in Aircraft Structure Certification
Organizations using simulation and analysis tools effectively see the benefits in their ability to achieve certification faster and with drastically less total cost than those who do not maximize these tools. Read this White Paper to learn about how digital tools such as analysis and simulation help in aircraft structure certification. 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