From: dw1725 on
Hi All,

I am working in a project, which is a simple VB GUI calls CVF DLL,
user can set up a bunch of parameters in GUI and trigger the
calculation of Fortran model by calling the DLL, then some output
data will be write into the file where GUI can retrieve them to show
back to the user.

Since there are a lot of variables in my Fortran calculation model
(more than 1000 and most of them are real value), it's not necessary
to show all of them to the user (all of these variables will be
calculated in the model though), so user can select the variables in
the GUI which they wanna see in the output part...

for instance,
I have a variable list includes 10 variables : varA,varB, varC,...,
VarJ, all of them will be calculated in the model and get a real value
eventually. But user may only wanna see some of them, let's say: varA
and VarD for example.

My problem is : how can I just only write the values of those "user-
selected" variables to the output file?
I mean, do I have to pass an "array of string" which contains "user-
selected variables" from GUI to my Fortran model? or just save these
"user-selected variables" in a tmp data file, and Fortran model can
read them later when it starts the output generate part.
And under the both circumstances, how can I use the "write" statement
in detail.

Thanks in advances for any comments or suggestions.


From: Lorenzo `paulatz' Paulatto on
dw1725 ha scritto:
> I mean, do I have to pass an "array of string" which contains "user-
> selected variables" from GUI to my Fortran model?

As far as I know (but I may be wrong), you cannot do something like
this. You cannot retrieve the name of a variable from inside the program
to which it belongs. The human-readable names of the variables are not
even stored in the executable (unless some debug option is used).

Somewhere in the code you will have to hard-code a map from human-names
to computer variables, something like:

if(save_this=='varA') write(*,*) varA

iterated for all of the variables you wish to show.

Of course you can do something smarter than a list of ifs. I would
probably use an array of a derived type; the type will contain a string
(the variable name) and a pointer (set to point the corresponding
variable). Something like this:

TYPE variables_index
CHARACTER(len=5) :: name
REAL(DP),POINTER :: value
END TYPE variables_index

TYPE(variables_index) :: vindex(10)

vindex(1)%name = 'varA'
vindex(1)%value => varA
....

If you variables have different kinds it get trickier, but is still
feasible with a single derived type.

Hope this helps

P.S. this kind of stuff is very easy to do with interpreted languages,
like java or python.

--
Lorenzo `paulatz' Paulatto
Trieste

``Grandissima mi par l'inezia di coloro che vorrebbero che Iddio avesse
fatto l'universo pi� proporzionato alla piccola capacit� del lor discorso.''
--Galileo Galilei (Opere VII)
From: glen herrmannsfeldt on
Lorenzo `paulatz' Paulatto wrote:
> dw1725 ha scritto:

>> I mean, do I have to pass an "array of string" which contains "user-
>> selected variables" from GUI to my Fortran model?

> As far as I know (but I may be wrong), you cannot do something like
> this. You cannot retrieve the name of a variable from inside the program
> to which it belongs. The human-readable names of the variables are not
> even stored in the executable (unless some debug option is used).

If you use NAMELIST then the names are stored, likely along with
the addresses so that namelist I/O works. Namelist input allows
one to specify a selected set of input variables by name.
Namelist output writes all the variables in the list.

-- glen


> Somewhere in the code you will have to hard-code a map from human-names
> to computer variables, something like:
>
> if(save_this=='varA') write(*,*) varA
>
> iterated for all of the variables you wish to show.
>
> Of course you can do something smarter than a list of ifs. I would
> probably use an array of a derived type; the type will contain a string
> (the variable name) and a pointer (set to point the corresponding
> variable). Something like this:
>
> TYPE variables_index
> CHARACTER(len=5) :: name
> REAL(DP),POINTER :: value
> END TYPE variables_index
>
> TYPE(variables_index) :: vindex(10)
>
> vindex(1)%name = 'varA'
> vindex(1)%value => varA
> ...
>
> If you variables have different kinds it get trickier, but is still
> feasible with a single derived type.
>
> Hope this helps
>
> P.S. this kind of stuff is very easy to do with interpreted languages,
> like java or python.
>

From: jon on
On Apr 1, 10:24 am, dw1725 <dw1...(a)gmail.com> wrote:
> Hi All,
>
> I am working in a project, which is a simple VB GUI calls CVF DLL,
> user can set up a bunch of parameters in GUI and trigger the
> calculation of Fortran model by calling the DLL,  then some output
> data will be write into the file where GUI can retrieve them to show
> back to the user.
>
> Since there are a lot of variables in my Fortran calculation model
> (more than 1000 and most of them are real value), it's not necessary
> to show all of them to the user (all of these variables will be
> calculated in the model though), so user can select the variables in
> the GUI which they wanna see in the output part...
>
> for instance,
> I have a variable list includes 10 variables : varA,varB, varC,...,
> VarJ, all of them will be calculated in the model and get a real value
> eventually. But user may only wanna see some of them, let's say: varA
> and VarD for example.
>
> My problem is : how can I just only write the values of those "user-
> selected" variables to the output file?
> I mean, do I have to pass an "array of string" which contains "user-
> selected variables" from GUI to my Fortran model? or just save these
> "user-selected variables" in a tmp data file, and Fortran model can
> read them later when it starts the output generate part.
> And under the both circumstances, how can I use the "write" statement
> in detail.
>
> Thanks in advances for any comments or suggestions.
Lorenzo has given you a good answer to work from.

Another thing to think about: Using the file system to transfer
information in this manner can be chancy. Even if you 'flush' output
buffers and close the output file, some OSs buffer output to file
systems. Notoriously, Windows can have a 'lazy' write to disk, where
the values you want to read might not be available by opening and
reading from the GUI. (I've run into this problem). You might
consider looking into Interprocess Communication (IPC) that might be
available for your operating system/languages. Examples are shared
memory, named pipes, ....

Glen also has a viable solution. I've used NAMELIST effectively in
such instances. However the problem remains that the file information
might not be available to the GUI if the OS can't *really* flush the
output to the file system.

--
jon

From: dw1725 on
Thank you all so much for inputs.

I finally got a clue more or less...
 | 
Pages: 1
Prev: Project Settings
Next: progress bar in fortran