|
[Sponsors] |
June 22, 2009, 04:38 |
automatic call a function in a program
|
#1 |
New Member
Gerard Mouokue
Join Date: Mar 2009
Location: Darmstadt, Hessen, Germany
Posts: 16
Rep Power: 17 |
Hi,
I have a program and want to call automatically another function in my program . for example int main (){ myprogram gambitToFoam "gambitmesh" return 0; } |
|
June 22, 2009, 06:54 |
|
#2 |
New Member
|
Hi Gerard!
in your case, wouldn't it be more adequate to change your program into a shell or python script? If you just manipulate data an/or files, this is the most portable and efficient way of doing it. Else, you still have the call to system() from <stdlib.h>, but you will need to make sure you find the executable, i.e. you might need to input the full path. This has the drawback that you will need to recompile your code every time you change the executable (here gambitToFoam) is in another location. The shell/python/perl/etc... scripts on the other can get the path to the executable from the environment variables. It's up to you to decide which strategy suits you best. |
|
June 25, 2009, 03:36 |
|
#3 |
New Member
Gerard Mouokue
Join Date: Mar 2009
Location: Darmstadt, Hessen, Germany
Posts: 16
Rep Power: 17 |
Hi Frank ,
I have a c++ code and don't want to transform the code in a script . my problem is that I want at some place of my program to call the function GambitToFoam without having to tipp it myself . |
|
June 25, 2009, 08:13 |
|
#4 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Quote:
There is also a Foam::system(const string&) available from OSspecific, so you can also call it with C++ strings. |
||
June 25, 2009, 09:05 |
|
#5 |
New Member
Gerard Mouokue
Join Date: Mar 2009
Location: Darmstadt, Hessen, Germany
Posts: 16
Rep Power: 17 |
hi Mark,
thanks for your advice. the problem it is not possible with Foam::system(const string&) to solve my problem. I want to call this function fluentMeshToFoam file.msh where file.msh is the fluent mesh and fluentMeshToFoam convert it to OpenFoam |
|
June 25, 2009, 09:10 |
|
#6 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Quote:
What problem does the system report when you call the function? Code:
#include "OSspecific.H" system("fluentMeshToFoam file.msh") |
||
June 25, 2009, 10:23 |
|
#7 | |
New Member
Gerard Mouokue
Join Date: Mar 2009
Location: Darmstadt, Hessen, Germany
Posts: 16
Rep Power: 17 |
Quote:
Fehler: »fluentMeshToFoam« wurde in diesem Gültigkeitsbereich nicht definiert that means fluentMeshToFoam ist not defined in this scope |
||
June 25, 2009, 10:41 |
|
#8 |
New Member
|
This is not very surprising: Your environment variables are not loaded, so the OpenFOAM paths are not available and so is the executable fluentMeshToFoam... What I said earlier: Make sure that the path is set before calling the executable. If I were you, I'd try:
system("<myPathToTheOFInstallationDir>/etc/bashrc; fluentMeshToFoam file.mesh"); |
|
June 25, 2009, 10:47 |
|
#9 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Quote:
Code:
system("echo PATH=$PATH | sed -e 's/:/\\n/g'"); system("echo look for fluentMeshToFoam; which fluentMeshToFoam"); |
||
June 29, 2009, 03:30 |
|
#10 |
New Member
Gerard Mouokue
Join Date: Mar 2009
Location: Darmstadt, Hessen, Germany
Posts: 16
Rep Power: 17 |
hi Mark ,Frank,
thanks for your help . it works Gerard |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Compile problem | ivanyao | OpenFOAM Running, Solving & CFD | 1 | October 12, 2012 10:31 |
[blockMesh] BlockMesh FOAM warning | gaottino | OpenFOAM Meshing & Mesh Conversion | 7 | July 19, 2010 15:11 |
Error with Wmake | skabilan | OpenFOAM Installation | 3 | July 28, 2009 01:35 |
Problem with compile the setParabolicInlet | ivanyao | OpenFOAM Running, Solving & CFD | 6 | September 5, 2008 21:50 |
[blockMesh] Axisymmetrical mesh | Rasmus Gjesing (Gjesing) | OpenFOAM Meshing & Mesh Conversion | 10 | April 2, 2007 15:00 |