Software Archive
Read-only legacy content
17060 토론

Calling a subroutine whose name is in a variable

Intel_C_Intel
직원
1,203 조회수
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 포인트
3 응답
james1
초급자
1,203 조회수
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 포인트
Intel_C_Intel
직원
1,203 조회수
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 포인트
Jugoslav_Dujic
소중한 기여자 II
1,203 조회수
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 포인트
응답