Author 
Message 
Jaeeung #1 / 27

How to write "or statement" in Fortran 77?
I'm new to fortran. Can anyone help me how to write following statements in Fortran 77? Thanks in advance. IF a=1.0 then k=0 or k=1

Thu, 28 Aug 1997 06:10:31 GMT 


Lang #2 / 27

How to write "or statement" in Fortran 77?
Quote:
>I'm new to Fortran. Can anyone help me how to write following statements in >Fortran 77? Thanks in advance. >IF a=1.0 then >k=0 or k=1
The logic of the above escapes me. The closest I can come to an answer that makes sense is IF(A.EQ.1.0)THEN K = 0 ENDIF

Fri, 29 Aug 1997 01:49:03 GMT 


Bernie Bernste #3 / 27

How to write "or statement" in Fortran 77?
Quote:
> I'm new to Fortran. Can anyone help me how to write following statements in > Fortran 77? Thanks in advance. > IF a=1.0 then > k=0 or k=1
It's not clear what you really want, but perhaps it is: If (a = 1.0) then k = 0 ! a = 1.0 is true Else k = 1 ! a = 1.0 is false End if Bernie B.

Fri, 29 Aug 1997 05:30:01 GMT 


Jaeeung #4 / 27

How to write "or statement" in Fortran 77?
Quote:
>Subject: Re: How to write "or statement" in Fortran 77? >Date: Sun, 12 Mar 1995 13:30:01 0800
>> I'm new to Fortran. Can anyone help me how to write following >statements in >> Fortran 77? Thanks in advance. >> IF a=1.0 then >> k=0 or k=1 >It's not clear what you really want, but perhaps it is: > If (a = 1.0) then > k = 0 ! a = 1.0 is true > Else > k = 1 ! a = 1.0 is false > End if >Bernie B.
I'm sorry if my first post was not clear. What I want is 'do either this or that if some condition is met'. For example, IF (a=1.0) then either k=0 or k=1 (k can be either 0 or 1, but not both in the same time.) This kind of logic is popular in system engineering and easy to handle by using GAMS(General Algebraic Modeling System). But I need to use Fortran 77. Thanks again.

Thu, 28 Aug 1997 23:53:59 GMT 


Lang #5 / 27

How to write "or statement" in Fortran 77?
Quote:
>I'm sorry if my first post was not clear. What I want is 'do either this or >that if some condition is met'. For example, >IF (a=1.0) then >either k=0 or k=1 (k can be either 0 or 1, but not both in the same time.) >This kind of logic is popular in system engineering and easy to handle by >using GAMS(General Algebraic Modeling System). But I need to use Fortran 77. >Thanks again.
It still is not clear what you want. What is the condition? A = 1.0 or k = 0 or k = 1. And what do you want to set when the contition is met? Ed Lang

Fri, 29 Aug 1997 10:02:23 GMT 


Jaeeung #6 / 27

How to write "or statement" in Fortran 77?
Quote:
>Subject: Re: How to write "or statement" in Fortran 77? >Date: Mon, 13 Mar 1995 02:02:23 GMT
>>I'm sorry if my first post was not clear. What I want is 'do either this or >>that if some condition is met'. For example, >>IF (a=1.0) then >>either k=0 or k=1 (k can be either 0 or 1, but not both in the same time.) >>This kind of logic is popular in system engineering and easy to handle by >>using GAMS(General Algebraic Modeling System). But I need to use Fortran 77. >>Thanks again. > It still is not clear what you want. What is the condition? A = 1.0 >or k = 0 or k = 1. And what do you want to set when the contition is met? >Ed Lang
The condition : A=1.0 Execute : Either K=0 or K=1 Alternatively, how would you write following statement in Fortran 77? IF (condition), then x > 0 If a certain condition is met, make some variable positive variable. If I can do this, I can solve the first problem. Thanks.

Fri, 29 Aug 1997 04:01:22 GMT 


Lang #7 / 27

How to write "or statement" in Fortran 77?
Quote:
>The condition : A=1.0 >Execute : Either K=0 or K=1
IMHO, I think that part of the difficulty may be in confusing assignment statements with logical expressions. For example, the statement K = 0 is an assignment statement that sets the variable K equal to zero. On the other hand that expression K .EQ. 0 is a logical expression whose value is True or False depending on what the value of K is when the expression is evaluated. When you write Either K=0 or K=1 this is really a logical expression which in FORTRAN is written as (K.EQ.0) .OR. (K.EQ.1) When this expression is evaluated the result is either True or False depending on the value of K; in other words, K is not assigned a value by this expression but rather the value of K is compared to 0 or 1. Is this what you are trying to do? Quote: >Alternatively, how would you write following statement in Fortran 77? >IF (condition), then x > 0
The problem here is that FORTRAN has no explicit IF ... THEN ... logical structure. Once again, you statement x > 0 is a logical expression which is written in FORTRAN as X.GT.0.0 which is True or False depending on the value of x when the logical expression is evaluated. So are you trying to determine whether x is greater than zero? Quote: >If a certain condition is met, make some variable positive variable. >If I can do this, I can solve the first problem. >Thanks.
Ed Lang

Fri, 29 Aug 1997 13:40:49 GMT 


Jaeeung #8 / 27

How to write "or statement" in Fortran 77?
Quote:
>Subject: Re: How to write "or statement" in Fortran 77? >Date: Mon, 13 Mar 1995 05:40:49 GMT
>>The condition : A=1.0 >>Execute : Either K=0 or K=1 > IMHO, I think that part of the difficulty may be in confusing >assignment statements with logical expressions. For example, the >statement > K = 0 >is an assignment statement that sets the variable K equal to zero. >On the other hand that expression > K .EQ. 0 >is a logical expression whose value is True or False depending on >what the value of K is when the expression is evaluated. > When you write > Either K=0 or K=1 >this is really a logical expression which in FORTRAN is written as > (K.EQ.0) .OR. (K.EQ.1) >When this expression is evaluated the result is either True or False >depending on the value of K; in other words, K is not assigned a >value by this expression but rather the value of K is compared to >0 or 1. Is this what you are trying to do?
I want to assign either 0 or 1 value to variable K. Not logical comparison. Quote: >>Alternatively, how would you write following statement in Fortran 77? >>IF (condition), then x > 0 > The problem here is that FORTRAN has no explicit IF ... THEN ... >logical structure. Once again, you statement > x > 0 >is a logical expression which is written in FORTRAN as > X.GT.0.0 >which is True or False depending on the value of x when the logical >expression is evaluated. So are you trying to determine whether >x is greater than zero? >>If a certain condition is met, make some variable positive variable. >>If I can do this, I can solve the first problem. >>Thanks. >Ed Lang
Same here. I want to define the range for the variable X which should be greater than 0 if some condition is met. I don't want that expression to be evaluated by 'TRUE' or 'FALSE'. I guess it might be difficult in Fortran. Thanks.

Fri, 29 Aug 1997 07:41:34 GMT 


Jeff Sween #9 / 27

How to write "or statement" in Fortran 77?
Quote:
>I'm new to Fortran. Can anyone help me how to write following >statements in Fortran 77? >IF a=1.0 then >k=0 or k=1
Now that we know you really mean what you said :)... You don't care whether k=0 or k=1. So flip a coin. Write either: IF ( A .EQ. 0 ) K=0 ! heads or IF ( A .EQ. 0 ) K=1 ! tails  Jeff

Fri, 29 Aug 1997 22:31:15 GMT 


William F Mitche #10 / 27

How to write "or statement" in Fortran 77?
> > The condition : A=1.0 > Execute : Either K=0 or K=1 > This is a curious thread, as the requested operation is not deterministic. Perhaps the following: IF (A .EQ. 1.0) THEN IF (random() .GT. .5) THEN K=0 ELSE K=1 ENDIF ENDIF where random() is your favorite random number generator returning a real value between 0 and 1 > > Alternatively, how would you write following statement in Fortran 77? > > > IF (condition), then x > 0 > > > If a certain condition is met, make some variable positive variable. > If I can do this, I can solve the first problem. Under the same same hypothesis on what you're after, how about IF (condition) X=random() 
If anything looks like an opinion, NIST does not necessarily agree with it. If anything looks like an official NIST or government statement, it's not.

Fri, 29 Aug 1997 23:49:16 GMT 


Steve Lion #11 / 27

How to write "or statement" in Fortran 77?
>I'm sorry if my first post was not clear. What I want is 'do either this or >that if some condition is met'. For example, > >IF (a=1.0) then >either k=0 or k=1 (k can be either 0 or 1, but not both in the same time.) Is this what you want? If a is equal to 1.0 and k is equal to either 0 or 1, do something If so, then this is how to do it: IF (a .eq. 1.0 .and. ((b .eq. 0) .or. (b .eq. 1))) THEN ... do something END IF 
DEC Fortran Development WWW: http://www.digital.com/info/slionel.html Digital Equipment Corporation CompuServe: 75263,3001 110 Spit Brook Road, ZKO23/N30 Nashua, NH 030622698 "Free advice is worth every cent"

Fri, 29 Aug 1997 23:49:32 GMT 


r.. #12 / 27

How to write "or statement" in Fortran 77?
Quote: >> I'm new to Fortran. Can anyone help me how to write following > statements in >> Fortran 77? Thanks in advance. >> IF a=1.0 then >> k=0 or k=1 > It's not clear what you really want, but perhaps it is: > If (a = 1.0) then > k = 0 ! a = 1.0 is true > Else > k = 1 ! a = 1.0 is false > End if
Assuming that you interpreted his question correctly, your answer is wrong under all flavours of FORTRAN .... Try : IF (a .EQ. 1.0) THEN k = 0 ELSE k = 1 ENDIF In regard to the original question, I suggest investing in a good FORTRAN text  this type of stuff is fundamental to the language; if you don't know the syntax for an IF statement, you will really be hampered. Have a nice day.  <Standard Trailer> Robert O'Dowd Phone : +61 8 259 7097 Bldg. 113 TSAN Fax : +61 8 259 6104
Disclaimer: Opinions above are MINE and probably worth what you paid for them.

Fri, 29 Aug 1997 09:17:10 GMT 


Lang #13 / 27

How to write "or statement" in Fortran 77?
Quote: >I want to assign either 0 or 1 value to variable K. Not logical comparison.
Since you want to do an assignment of K, the question is under what conditions do you want to assign 0 and under what conditions do you want to assign 1. You must do one or the other, but not both. So you may have IF(test condition)THEN K = 0 ELSE K = 1 ENDIF Quote: >Same here. I want to define the range for the variable X which should >be greater than 0 if some condition is met. I don't want that expression to >be evaluated by 'TRUE' or 'FALSE'. >I guess it might be difficult in Fortran. >Thanks.
You cannot set a variable to be equal to a range, you must set it to be equal to a specific value. However, you can test whether it is within a certain range. BTW, what language do you normally program in? Ed Lang

Sat, 30 Aug 1997 01:00:22 GMT 


William B. Clodi #14 / 27

How to write "or statement" in Fortran 77?
Quote:
>> It still is not clear what you want. What is the condition? A = 1.0 >>or k = 0 or k = 1. And what do you want to set when the contition is met? >>Ed Lang >The condition : A=1.0 >Execute : Either K=0 or K=1 >Alternatively, how would you write following statement in Fortran 77? >IF (condition), then x > 0 >If a certain condition is met, make some variable positive variable. >If I can do this, I can solve the first problem. >Thanks.
What I think you want is not easy to do in Fortran, but can be done. I suspect you want something like Prolog. As to what I think you want, for the first case in nonstrict F77 but probably portable, INTEGER, K, SETOFK(1:100), NUMSET REAL A ... IF (A .EQ. 1.0) THEN ! Such a test on reals is error prone NUMSET = 2 SETOFK(1) = 0 SETOFK(2) = 1 ENDIF ... and similar code must be written for each change in the set. Any time you want to find out what elements are in the set you will have to inquire NUMSET for the number of elements and then SETOFK for the specific values. A negative value of NUMSET can be used as an error flag when the number of elements of the set is greater than the size of SETOFK. IF (condition), then x > 0 can also be done. For example REAL XSTART INTEGER XRELAT ... IF (condition) THEN XSTART = 0. XRELAT = 1 ! flag indicating > XSTART ENDIF ... IF (other condition) THEN XSTART = 0. XRELAT = 1 ! flag indicating < XSTART ENDIF ... IF (third condition) THEN XSTART = 0. XRELAT = 0 ! flag indicating == XSTART ENDIF It will be VERY awkawrd if you want something more general, e.g. IF (condition), then x > 0 and x < 1.0 or x > 200. and x < 400. etc.

Fri, 29 Aug 1997 18:29:58 GMT 


Dan P #15 / 27

How to write "or statement" in Fortran 77?
Quote:
>>> I'm new to Fortran. Can anyone help me how to write following >> statements in >>> Fortran 77? Thanks in advance. >>> IF a=1.0 then >>> k=0 or k=1 >> It's not clear what you really want, but perhaps it is: >> If (a = 1.0) then >> k = 0 ! a = 1.0 is true >> Else >> k = 1 ! a = 1.0 is false >> End if >Assuming that you interpreted his question correctly, your answer is wrong >under all flavours of FORTRAN .... >Try : > IF (a .EQ. 1.0) THEN > k = 0 > ELSE > k = 1 > ENDIF
Well, Bernie's example only needs one more "=" to become correct :) Dan  Dan Pop CERN, CN Division
Mail: CERN  PPE, Bat. 31 R004, CH1211 Geneve 23, Switzerland

Sat, 30 Aug 1997 02:36:50 GMT 

