- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
user should be able to input 1 independent variable function like
f(x) = sin(x) + ( 1+x^2 + ln(x) )^0.25
or
f(x) = x^2.4 + 1/(sin(x) + ln(x))
to a text file. After that the program will read the equation from the text file, use this function in other calculation several times then return a result.
Currently, in my program, user has to open the source code then edit the function and recompile the source code again in order to change the function inside my program.
If anyone can help me with this issue will be very helpful?
Thank you for your time to read my question.
If you have the way to allow use input a multiple independent variable explicit fuction like
f(x,y) = x + sin(y) * ln(x) - y^2
please also tell me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
(i) call the compiler to compile the user-defined function and run the resulting object code, and manage the interaction between these processes or
(ii) implement a restricted interpreter, which can parse and evaluate expressions. There are several such interpreters that were published in earlier years.
See also: HICEST
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Windows WIN32 API is implemented as C routines (read Fortran can useWIN32 API)
WIN32 API can probe, load and unload Windows DLL's
Therefore
Read in your function from file and write as seperate .f90 file
Compile .f90 fileand link into .DLL
load .DLL
obtain address of function (WIN32 API to probe DLL for entry point)
call (unknown) function
If your functions are relatively trivial and called once or just a few times, thenI would suggest writing a parser and interpreter in Fortran (or C/C++).
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I get some idea on how to do it but it seem that I need to learn more on how to do what you've suggested.
To be honest, I just get a rough idea on how to do it but really don't know how to really do what you've suggested.
In my case, the function will run ~1000 times.
The input will be an elementary algebra - explicit function.
Sometimes it have 2 independent variable sometimes it doesn't.
The time to run program is about 10 - 30 minutes.
When I use the program myself I just edit the function in .f90 file and recompile it.
If other users do this then they will know or change my source code so I try to find the way for users to enter the formular without seeing or changing my source code.
Is there any ways to ask the compiler to compile an additional code and link to the source code that is already compiled?
If I can do this then the user just need to run my program on the computer that has a Fortran compiler.
When a user run my program, then my program will automatically ask the compiler to compile the addition code and link it to the existing program that is already compiled.
Thank you for your time to read my message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There are two perspectives to consider
a) Is your program the control
b) Is the user access to your program the control
If a) then your program needs to call a user specified function (or functions) defined at run time. This situation seems to be what was outlined in your first post. For this I suggest:
1) Compile your program containing
...
call UserFunc1_AB(A, B)
...
call UserFunc2_AB(A, B)
(above in a select/case, if/then, ...)
2) Ship the fully optimized .OBJ files without Debug symbols
3) Ship empty .F90 source files containing just the subroutine, argumentsand return
4a) user modifies UserFunn_AB, ...to their needs, user compiles and links with your .obj
.or.
4b) You provide automation program that performs 4a) under program control using user supplied script file
If b), then ship your components as static or dynamic library.
Alternative is to write a simple interpreter. The interpreter code may take 1ms to execute a statement (could be less depending on your programming skill). Interpreter overhead for run of program ~1 second out of 10-30 minute run time. 1/600'th to 1/1800th the totalrun time. Writing the interpreter would be the easiest way to go as long as the user functions do not contain conditionals, function calls to other user functions. You should be able to find sample interpreter code on the internet.
A second alternative is to have your .f90 program integrate to Visual Basic or other scripting language (similar to writing a .f90/C/C++ app). Then you could implement the user defined functions as VB/VJ/Vother code. This may take a little bit of learning on how to build a multi-language app.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Using your own interpeter requires no additional capability of the user.
Using VB/VJ/... requires user to be on Windows with VB/VJ/...
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The summary looks good. The OP should give it a look.
Thanks for the link.
Code like this should have been laying around for 30+ years.
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page