Anthony,
In the general case, where one wants a SELECT CASE with code common to
some cases I do the usual thing and put the common code in subroutines.
For example:
Select Case (i)
case (10)
call stuffA()
call stuffJ()
...other stuff
case (17)
call stuffB()
call stuffJ()
call stuffK()
...other stuff
case (99)
call stuffA()
End Select
It is easy to see what happens in each case, there is no risk of falling
through to the wrong code, and you are not having to duplicate code. The
subroutines can be external, internal, or module subroutines according
to the scoping of the data they operate on.
It might appear OTT for your very regular example, but think what
happens when someone else looks at the cascading IFs, say, in 10 years
time. Or the computed GOTOs. Supposing they want to add extra code for
cases 1,7,9.
Cheers,
Simon.
> -----Original Message-----
> From: Fortran 90 List [mailto:[log in to unmask]]
> On Behalf Of Keith Refson
> Sent: 13 January 2005 11:47
> To: [log in to unmask]
> Subject: Re: Computed GOTO
>
>
> Anthony Stone wrote:
> > 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 --
>
> If your problem is sufficiently regular, how about something
> along these lines
>
> do i=index,1,-1
> select case(i)
> case (10)
> .. stuff
> case (9)
> ... more stuff
> ...
> end select
> end do
>
> Keith Refson
>
>
> --
> Dr Keith Refson,
> Building R3
> Rutherford Appleton Laboratory
> Chilton
> Didcot kr AT isise
> Oxfordshire OX11 0QX DOT nd DOT rl DOT ac DOT uk
>
|