One thing to try would be namelist input for the variables.
Create a namelist group with a flag, a typeA variable name and
a typeB variable name. Then your input cards (ooops lines) would look
something like
flag = "it's an A", typeA_name = values appropriate for namelist
input...
and your code would look like
if (flag == "it's an A" ) then
call somesub(typeA_name)
else
call somesub(typeB_name)
endif
This mostly bypasses the advantage of generic names, but it at least
lets you read in values to a variable of "unknown" type.
Dick Hendrickson
Richard Maine wrote:
>
> Panagiotis Vossos writes:
> > call SOMESUB(foo)
> ...
> > The problem is that in my main program, I don't know in advance if 'foo'
> > will be a TYPEA or TYPEB variable.
>
> You fundamentally can't do that in f90/f95. The types of *ALL*
> variables are known at compile time. Even for generic procedures,
> what really happens is that the compiler figures out *AT COMPILE TIME*
> which types you are using, and thus which call to make.
>
> Sounds like you are looking for features that are part of object
> oriented programming. The f2k draft has stuff for this, but not
> f90/f95. In f2k, you could declare TYPEA and TYPEB to be extended
> from the same extensible type, define somesub to be a type-bound
> procedure and then do call foo%somesub or something of the sort.
> But in f90/95...
>
> I wanted to have an input file
> > that contained the following:
> >
> > TYPEA ...some values for a TYPEA variable go here...
> > or
> > TYPEB ...some values for a TYPEB variable go here...
> >
> > How can we make the main program operate for both these cases ?
> > Into what type of variable should "some values..." be read in ?
>
> You are going to have to have two separate variables, one of each
> type. Or I suppose you can do something like have a single derived
> type that has components of both types, plus a flag to tell which
> component has useful data. That kind of thing can work, but is,
> of course, wasteful of space. If you aren't working with large
> arrays, the space might not matter.
>
> --
> Richard Maine | Good judgment comes from experience;
> [log in to unmask] | experience comes from bad judgment.
> | -- Mark Twain
|