forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Embedded blanks in operators
Goto page Previous  1, 2
 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
KL



Joined: 16 Nov 2009
Posts: 155

PostPosted: Mon Jan 24, 2011 1:04 pm    Post subject: Reply with quote

I should have better put my example as
Code:

If ( (.  not  . x) .   and          . y ) z = . true   .
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2428
Location: Yateley, Hants, UK

PostPosted: Mon Jan 24, 2011 11:07 pm    Post subject: Reply with quote

Davidb:

Do you really (need logical operators) if all you have is an arithmetic IF (e.g. as in IBM1130 Fortran), or do they simply make the code more readable?

I'm still using this line, programmed in 1969 (I think) on said machine:

Code:
      IF ((H+0.40D0)*(H-0.50D0)) 7,7,4


because I can't puzzle out what the heck it does! (But I'm sure it has an .AND. in it).

Klaus:

FTN95 doesn't like the parts of a compound operator specified F90 style (e.g. <=) to be separated. If you don't like fixed format, how can you bear to use those horrid "dot" operators? Trouble is, the new form isn't much of an improvement, is it?

What is the benefit of adding extra spaces anyway - I find the dotty operators hard enough to read even if the dots are hard up against the letters?

Eddie
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2625
Location: Sydney

PostPosted: Tue Jan 25, 2011 12:42 pm    Post subject: Reply with quote

Klaus,

You wrote "We do not increase the portability of free format Fortran 9x if such simple definitions stay unclear."
My observation is that portability and the Fortran 9x standard are a bit mixed up.
They refused to give guidance on the values of KIND for integer and real.
I always thought that the 9x standard tried to introduce portability in OPEN but reading the fine print, "RECL=" was not standardised.

I think the rule that you should not use spaces within tokens should be applied wherever possible, such as .ne. or variabe_names. That being said, I never use ENDDO or ENDIF. (Ian, what is END CRITICAL ??)

John
Back to top
View user's profile Send private message
IanLambley



Joined: 17 Dec 2006
Posts: 514
Location: Sunderland

PostPosted: Tue Jan 25, 2011 1:32 pm    Post subject: Reply with quote

END CRITICAL - I'm glad you asked me that - It is something to do with multiple images, see below as long as you don't then ask about SYNCH ALL etc. They are part of Fortran 2008.
Regards
Ian
Quote:

8.1.5 CRITICAL construct
1 A CRITICAL construct limits execution of a block to one image at a time.
R810 critical-construct is critical-stmt
block
end-critical-stmt
R811 critical-stmt is [ critical-construct-name : ] CRITICAL
R812 end-critical-stmt is END CRITICAL [ critical-construct-name ]
C809 (R810) If the critical-stmt of a critical-construct specifies a critical-construct-name, the corresponding
end-critical-stmt shall specify the same critical-construct-name. If the critical-stmt of a critical-construct
does not specify a critical-construct-name, the corresponding end-critical-stmt shall not specify a critical-
construct-name.
C810 (R810) The block of a critical-construct shall not contain a RETURN statement or an image control
statement.
C811 A branch (8.2) within a CRITICAL construct shall not have a branch target that is outside the construct.
2 Execution of the CRITICAL construct is completed when execution of its block is completed. A procedure
invoked, directly or indirectly, from a CRITICAL construct shall not execute an image control statement.
3 The processor shall ensure that once an image has commenced executing block, no other image shall commence
executing block until this image has completed executing block. The image shall not execute an image control
statement during the execution of block. The sequence of executed statements is therefore a segment (8.5.2). If
image T is the next to execute the construct after image M, the segment on image M precedes the segment on
image T.
NOTE 8.6
If more than one image executes the block of a CRITICAL construct, its execution by one image always
either precedes or succeeds its execution by another image. Typically no other statement ordering is needed.
Consider the following example:
CRITICAL
GLOBAL_COUNTER[1] = GLOBAL_COUNTER[1] + 1
END CRITICAL
The definition of GLOBAL COUNTER [1] by a particular image will always precede the reference to the
same variable by the next image to execute the block.
NOTE 8.7
The following example permits a large number of jobs to be shared among the images:
INTEGER :: NUM_JOBS[*], JOB
IF (THIS_IMAGE() == 1) READ(*,*) NUM_JOBS
SYNC ALL
DO
CRITICAL
JOB = NUM_JOBS[1]
NUM_JOBS[1] = JOB - 1
END CRITICAL
IF (JOB > 0) THEN
! Work on JOB
ELSE
EXIT
END IF
END DO
SYNC ALL
Back to top
View user's profile Send private message Send e-mail
KL



Joined: 16 Nov 2009
Posts: 155

PostPosted: Tue Jan 25, 2011 6:36 pm    Post subject: Reply with quote

Thanks for the comments. May be that ">" is better readable than ".gt." but also this form must be standardised. With the remark about arithmetic IF I do not agree. For very good reasons this construct is on the list of obsolete features. But I do agree -as already said- to write all operators in discussion without any blanks.

To increase portability was -at least as I understood- one of the major goals for the Fortran 90 development. And I think that this goal has been reached to a certain extent. But it is never a mistake to further increase it.

Klaus
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2428
Location: Yateley, Hants, UK

PostPosted: Tue Jan 25, 2011 7:58 pm    Post subject: Reply with quote

Klaus,

It wasn't a statement of belief (about logical IF), it was a question. Actually, it WAS possible to do without logical operators in constructing IFs, but their meaning very quickly becomes obscure, and whether or not the construct is obsolete, the logical IF is easier to understand later (although anyone can write impenetrable code if they try).

Surely the point I made about compound operators (like >=) is that in free format in FTN95 they cannot have spaces in, and if you want code that is future proofed and compilable by multiple compilers, you should go that way. I agree that > looks better than .gt., but I'm not sure that >= or /= is better than the dotty version - I don't like either as a matter of aesthetics. I much preferred (decades ago) Algol-60 which had reserved words, including logical operators. But Algol-60 was about as portable as a Durian on a long distance flight!

davidb: You can't have != because the ! would indicate that an inline comment followed.

Eddie
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Tue Jan 25, 2011 11:38 pm    Post subject: Re: Reply with quote

LitusSaxonicum wrote:
Davidb:

Do you really (need logical operators) if all you have is an arithmetic IF (e.g. as in IBM1130 Fortran), or do they simply make the code more readable?

I'm still using this line, programmed in 1969 (I think) on said machine:

Code:
      IF ((H+0.40D0)*(H-0.50D0)) 7,7,4


because I can't puzzle out what the heck it does! (But I'm sure it has an .AND. in it).



It does this
Code:

if ((H+0.40D0)*(H-0.5D0)) GOTO 7 ! goto 7 if value is <= 0.0DO
GOTO 4 ! else goto 4


No "And" in there apparently. But there is hidden away, look:

In maths it means: if h**2 -0.1*h -0.2 <= 0 goto 7.

This is the same as if h >=-0.4 .AND. h <= 0.5 goto 7 (solving the quadratic and plotting it out to confirm its concave upwards)

So the function jumps to label 7 if h is between -0.4 and 0.5 (inclusive), otherwise it jumps to label 4.

Using a logical IF

Code:

IF (H >= -0.4D0 .AND. H <= 0.5D0) THEN
   ! Do label 7 code
ELSE
   ! Do label 4 code
END IF


Modern version is clearer and should be more efficient. Laughing

I think you still need .AND. .OR. etc since you can't formulate similar tricks when these are used in combination. (At least I can't).
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2625
Location: Sydney

PostPosted: Wed Jan 26, 2011 12:46 am    Post subject: Reply with quote

Shame on you davidb !!
Your analysis misses all the nostalga of 1130 fortran.
When I first started work, I refused to use the 1130 and so these logical expressions were mere fokelore to me.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group