Anthony Stone wrote:
>
> ... I don't use ASSIGN, but I would have used it
> in the following case if it had not been obsolescent. I would be
> interested to learn of an equally efficient and straightforward
> alternative.
>
> My program has a large number (several hundred) of shortish segments
> of code that are sometimes needed, sometimes not. The ones that are
> needed are evaluated many times in the course of one run of the
> program. The routine that evaluates them (actually several routines
> each dealing with a bunch of them) is handed an ordered list
> specifying the items to be evaluated. I would have liked to label each
> segment, ASSIGN the labels to an array segment(:) (this only needs to
> be done once), and at the end of each segment find the next segment in
> the list by
> n=n+1; GOTO segment(list(n))
> I don't think that this is at all inscrutable. I could even make the
> labels match the segment numbers used in the list. Possible
> alternatives: I could step through the code, testing before each
> segment to see whether it's the next one to be evaluated. Since the
> list is ordered, I only need one pass through the routine, but because
> each segment of code is much less likely to be needed than not in any
> given calculation, this is not very attractive. A binary chop search
> would be more efficient, and I use something along those lines, but
> it's very much clumsier to code.
Wouldn't `SELECT CASE' be appropriate here?
do j = 1, size(segment)
select case (segment(j))
case (SEGMENT1)
<code segment>
case (SEGMENT2)
<code segment>
...
end select
end do
Perhaps I've missed something here, but it doesn't seem particularly
relevent to your proposed ASSIGN solution that the segments are
ordered and a single linear pass is made through the code (as long
as your segment array is also ordered). Is your concern code locality?
Anyway, my understanding is that the CASE construct can be more
efficiently implemented than a functionally equivalent IF-THEN-ELSE
construct, and in terms of implementation, I don't see that the
evaluation of an assigned goto could be any different than the
evaluation of a select case.
Thoughts?
------------------------------------------------------------------------
Neil N. Carlson [log in to unmask] (work)
Theoretical Division [log in to unmask] (non-work)
Group T-1, Mailstop B221
Los Alamos National Laboratory 505-665-1220 (voice)
Los Alamos, NM 87545 505-665-5757 (fax)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|