Software Archive
Read-only legacy content
17060 Discussions

Calling a subroutine whose name is in a variable

Intel_C_Intel
Employé
1 162 Visites
Is it possible to call a subroutine whose name is in a variable?
Let's say for example I have a character array with the string 'MYFUNCTION' in it, I would like to issue an instruction that does the same as ' CALL MYFUNCTION ( blabla ) '

Thanks, Michael
0 Compliments
3 Réponses
james1
Débutant
1 162 Visites
Not in a portable way but certainly doable, the manner dictated by the target platform. The best method depends on why you want to do this. Generally making some sort of dispatch function which accepts "MYFUNCTION" as an argument can be used while keeping things relatively generic though.

James
0 Compliments
Intel_C_Intel
Employé
1 162 Visites
Thanks for your answer. I will try to explain what we want to do:
The idea is to have a library of components that simulate the behaviour of thermal systems. These components are in DLL libraries and each component coresponds to a FORTRAN routine (e.g. one routine simulates a boiler, another routine simulates a heat exchanger).
The user creates a simulation scheme (you can see it as a text file with the names of the routines, their parameters and the way they are connected to each other) One instruction in the file could be that we have to call the "BOILER" routine with some parameters.
Ideally, every user could add libraries with new modules and so we need a way to be able to look into all DLL's in a given folder if a given routine exists, and then call it.

Thanks,Michael
0 Compliments
Jugoslav_Dujic
Précieux contributeur II
1 162 Visites
You'd have to use dynamic binding of dll routines (LoadLibrary/GetProcAddress), which requires that dll's lib file is not linked with the calling module, and routines are referenced by dll name and routine name. See
this recent thread.
0 Compliments
Répondre