Print

Print


I would be grateful for advice on another Fortran 90 issue.

My program contains code to evaluate several hundred functions of several
variables and their derivatives, some complicated, others fairly simple. In
any particular application, only some of them are needed, and the program
constructs a list of those that are wanted and then calls a routine to
evaluate them.

It seems to me that the following code would be efficient:

(a) In an initialization call:
      integer label(500)
      ASSIGN 1 to label(1)
      ASSIGN 2 to label(2)
      ...
      ASSIGN 500 to label(500)

(b) In computation calls:

      n=0
1000  n=n+1
      if (list(n) .gt. 0) then
        go to label(list(n))
      endif
      return

where the code at each label assigns values to entry n in a number of tables
and ends with "go to 1000".

I realise that this has all sorts of nasty features in the eyes of the
purists, and ASSIGN is obsolescent anyway, so I don't do it this way. I
currently use a sequence of IF statements to jump through the code in a
binary-chop fashion to find the next function to be calculated. However this
seems likely to be relatively inefficient. Is there a better way? One
possibility is to use an array of subroutine names instead of an array of
labels (if this is permitted), and to call the appropriate one of those, but
there is then likely to be a good deal of overhead. Is the subroutine-call
overhead significantly reduced where the subroutines are all in one module?

--
Anthony Stone
University Chemical Laboratory,         Email:   [log in to unmask]
Lensfield Road,                         Phone:  +44 1223 336375
Cambridge CB2 1EW                       Fax:    +44 1223 336362


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%