Call subroutine based on character variables? Guru Required!
From: Matt (i.mosgplc_at_aunet)
Date: Thu, 6 Jan 2005 01:49:20 +0000
I've been using g77 for several years now (for various projects at
University) and I'm now in a situation whereby I have a large library
of subroutines. Several of these subroutines solve a specific set of
equations using different numerical methods (i.e. one uses the explicit
Euler method, others use various semi-implicit methods, ... etc).
In my current program I am solving this set of equations many times
over, at various different parts of the program. I want to be able to
choose which method the program will use without using hundreds of
embedded IF statements, e.g.
CALL EXPL( ... )
CALL IMP1( ... )
CALL IMP2( ... )
... etc ...
It would be bad enough doing this just once, but as I said there are
several (currently eleven!) parts in the program where the correct
method must be chosen. However, note that the method to be employed is
chosen at run-time, and will be the same at each 'solving' instance.
I'm wondering if it would be possible to somehow call the appropriate
subroutine based on a character variable. Something along the lines of
CALL METHOD( ... )
where "METHOD" is chosen at run-time (in the previous example, it would
take the values: "EXPL", "IMP1", IMP2", ...etc). Of course, this would
be *far* neater than using nested IF statements. Is this possible in
either fortran77 or g77?
If anyone has any other suggestions, I'd be delighted to hear them! ;)