|
[Sponsors] | |||||
|
|
|
#1 |
|
Member
Julien Schaguene
Join Date: Apr 2009
Location: France
Posts: 55
Rep Power: 6 ![]() |
Hi,
I think it's quite trivial, but I spent time on finding how to get a float as argument for an application. It's a little application dealing with boundary conditions, let's name it JulienFoam I want to be able to use it as: JulienFoam <Boundary> -numericalarg <float> for the moment, I have that: int main(int argc, char *argv[]) { float numericalarg; argList::validArgs.append("patchName"); argList::validOptions.insert("numericalarg",numeri calarg); word patchName(args.args()[1]); [...] } and I don't find how to get my numericalarg as a float, it seems that argList only gets strings. If someone can give me any piece of advice, I think it would be very usefull for my future using, not just for that program. Regards Julien Last edited by Schag; July 27, 2009 at 05:33. |
|
|
|
|
|
|
|
|
#2 |
|
Senior Member
Henrik Rusche
Join Date: Mar 2009
Location: Braunschweig, Niedersachsen, Germany
Posts: 262
Rep Power: 7 ![]() |
Julien,
yes, arguments are passed only as strings. Have a look into fluentMeshToFoam.L where it says: Code:
scalar scaleFactor = 1.0;
if (args.options().found("scale"))
{
scaleFactor = atof(args.options()["scale"].c_str());
}
|
|
|
|
|
|
|
|
|
#3 |
|
Member
Julien Schaguene
Join Date: Apr 2009
Location: France
Posts: 55
Rep Power: 6 ![]() |
Perfect, that is exactly what I was looking for! I looked over other applications but not that one.
Thanks a lot! |
|
|
|
|
|
|
|
|
#4 |
|
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: http://olesenm.github.com/
Posts: 766
Rep Power: 16 ![]() |
Just for completeness (to followup on what Henrik mentioned), you might note that readScalar operates on an Istream, and IStringStream can be used to create an Istream from a string.
Thus the following would also work: Code:
if (args.options().found("scale"))
{
scaleFactor = readScalar(IStringStream(args.options()["scale"])());
}
Of course, both solutions look fairly messy. |
|
|
|
|
|
|
|
|
#5 |
|
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: http://olesenm.github.com/
Posts: 766
Rep Power: 16 ![]() |
In OpenFOAM-1.6, the same thing becomes much more convenient:
Code:
scalar scaleFactor = 1.0;
args.optionReadIfPresent("scale", scaleFactor);
|
|
|
|
|
|
![]() |
| Tags |
| programming |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| OpenFoam programming | prapanj | OpenFOAM | 10 | March 18, 2010 08:23 |
| Programming in OpenFOAM | vinu | OpenFOAM | 2 | July 11, 2009 10:16 |
| A book for a beginner wanting to learn programming | frank | Main CFD Forum | 7 | September 23, 2005 16:57 |
| new CFD Programming Forum | Thinker | Main CFD Forum | 14 | November 19, 2002 16:03 |
| STAR-CD Dynamics issue 16 | CD adapco Group Marketing | CD-adapco | 0 | November 30, 2001 10:25 |