NickFort
Technical User
- Jun 10, 2010
- 113
Hi,
I'm currently starting work on an engineering package that's calculations will be done with Fortran 95, with a GUI in Delphi (or to be more accurate, Lazarus:
Before I start any coding, I've been working on a "battle plan" for this thing. I'd like to split the program into DLLs, which can either call each other, or be called from the GUI. I've found excellent examples on this forum for creating DLLs with gfortran:
and a resource for a Fortran-Delphi interface:
So, I suspect that I'll manage to pull that part off; if not, I'll be back here bugging you guys.
But now, here's where my confusion comes in: what's the best way to share data between those DLLs, other than passing giant arrays from one function to the next? I imagine that would result in unnecessary overhead, although I could be mistaken. You see, in the GUI, I plan to load a pretty big matrix of data, from which only a subset will be used throughout the various Fortran DLLs. The idea I have is to load the required data into memory somewhere, and then have each Fortran function pick and take from that data set as it requires.
Forgetting the GUI bit for now, let's assume that everything is being done in Fortran, to make this discussion a bit simpler.
There are three options that spring to mind:
(1) modules,
(2) pointers, and
(3) persistent variables (not sure if that's the right term)
For option (1), I can't see how this might work without values having to be hard-coded. For option (2), well, I have no idea how to implement pointers (and only a rudimentary idea of what they do), but they sound like they might do what I need; if so, I'll have a good deal of reading to do. For (3), what I mean by "persistent" is using the SAVE parameter in a function, and writing to or reading from it as required. I suspect that (3) would work, but it doesn't seem much better than passing these huge arrays from one function to the next.
What would you guys suggest as the most efficient and elegant solution to this problem?
Thanks!
NickFort
--------------------------------------
Background: Chemical engineer, familiar mostly with MATLAB, but now branching out into real programming.
I'm currently starting work on an engineering package that's calculations will be done with Fortran 95, with a GUI in Delphi (or to be more accurate, Lazarus:
Before I start any coding, I've been working on a "battle plan" for this thing. I'd like to split the program into DLLs, which can either call each other, or be called from the GUI. I've found excellent examples on this forum for creating DLLs with gfortran:
and a resource for a Fortran-Delphi interface:
So, I suspect that I'll manage to pull that part off; if not, I'll be back here bugging you guys.
But now, here's where my confusion comes in: what's the best way to share data between those DLLs, other than passing giant arrays from one function to the next? I imagine that would result in unnecessary overhead, although I could be mistaken. You see, in the GUI, I plan to load a pretty big matrix of data, from which only a subset will be used throughout the various Fortran DLLs. The idea I have is to load the required data into memory somewhere, and then have each Fortran function pick and take from that data set as it requires.
Forgetting the GUI bit for now, let's assume that everything is being done in Fortran, to make this discussion a bit simpler.
There are three options that spring to mind:
(1) modules,
(2) pointers, and
(3) persistent variables (not sure if that's the right term)
For option (1), I can't see how this might work without values having to be hard-coded. For option (2), well, I have no idea how to implement pointers (and only a rudimentary idea of what they do), but they sound like they might do what I need; if so, I'll have a good deal of reading to do. For (3), what I mean by "persistent" is using the SAVE parameter in a function, and writing to or reading from it as required. I suspect that (3) would work, but it doesn't seem much better than passing these huge arrays from one function to the next.
What would you guys suggest as the most efficient and elegant solution to this problem?
Thanks!
NickFort
--------------------------------------
Background: Chemical engineer, familiar mostly with MATLAB, but now branching out into real programming.