×
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

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

White Paper - Strategies to Secure Connected Cars with Firewalls
White-hat hackers have demonstrated gaining remote access to dashboard functions and transmissions of connected vehicles. That makes a firewall a vital component of a multilayered approach to vehicle security as well as overall vehicle safety and reliability. Learn strategies to secure with firewalls. Download Now
White Paper - Model Based Engineering for Wire Harness Manufacturing
As complexity rises, current harness manufacturing methods are struggling to keep pace due to manual data exchanges and the inability to capture tribal knowledge. A model-based wire harness manufacturing engineering flow automates data exchange and captures tribal knowledge through design rules to help harness manufacturers improve harness quality and boost efficiency. Download Now
White Paper - What is Generative Design and Why Do You Need It?
Engineers are being asked to produce more sophisticated designs under a perfect storm of complexity, cost, and change management pressures. Generative design empowers automotive design teams to navigate this storm by employing automation, data re-use and synchronization, and framing design in the context of a full vehicle platform. Download Now
eBook - Simulation-Driven Design with SOLIDWORKS
Simulation-driven design can reduce the time and cost of product development. In this engineering.com eBook, we’ll explore how SOLIDWORKS users can access simulation-driven design through the SOLIDWORKS Simulation suite of analysis tools. 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