Print

Print


Having also had the benefit of a number of response postings, I offer the following comments:

*       Overall, the problem being addressed by the code might benefit from some broader restructuring (requiring more knowledge than currently conveyed)
*       It would appear on the evidence, however,  that porting to standard compliant ... and not obsolescent ... code with as little trouble as possible is the object of the exercise
*       For that reason, the 'if then ... else if ' type structure would be the one for the job    - as only one successful test results in clause execution, and there is an option for a default clause ('else')
*       One might consider, of course, putting the most populous (likely) case first    - if this is of assistance in improving overall speed
*       The very laudable suggestion of routine calls within each clause is supported    - but falls into the category of dot point one above

I would be interested in hearing from other contributors if there are contraindications to these suggestions.

KInd regards

Gary H




-----Original Message-----
From: Fortran 90 List [mailto:[log in to unmask]]On Behalf
Of Anthony Stone
Sent: Thursday, 13 January 2005 8:32 PM
To: [log in to unmask]
Subject: Computed GOTO


I have a program in which I use the structure

go to (101,102,103,104,105,106,107,108,109,110), index
110 stuff
    ...
109 more stuff
    ...
108 and so on
    ...
...


The computed GOTO used here is an obsolescent feature, but there
doesn't seem to be an obvious replacement. A CASE construct isn't
suitable, because there is no jump out at the end of each block --
execution falls through to the next block, as in C, so if (say)
index=9, the blocks of code labelled 108, 107 etc are to be executed
as well as the block labelled 109. Each block is quite large, so
repeating them is not sensible. I could get the same result using the
code

select case (index)
case(10)
  goto 110
case(9)
  goto 109
...
end select

but that is horribly clumsy. Arranging the blocks in the reverse order
and testing index after each one is a bit better but still relatively
clumsy.

Is there a neat way to do what I want without using the computed GOTO?
Could it be that (horrors) the computed GOTO has some uses after all?

--
Anthony Stone                           http://www-stone.ch.cam.ac.uk/
University Chemical Laboratory,         Email:   [log in to unmask]
Lensfield Road,                         Phone:  +44 1223 336375
Cambridge CB2 1EW                       Fax:    +44 1223 336362


************************************************************************
The information in this e-mail together with any attachments is
intended only for the person or entity to which it is addressed
and may contain confidential and/or privileged material.
Any form of review, disclosure, modification, distribution
and/or publication of this e-mail message is prohibited.  
If you have received this message in error, you are asked to
inform the sender as quickly as possible and delete this message
and any copies of this message from your computer and/or your
computer system network.  
************************************************************************