|
[Sponsors] |
July 27, 2009, 05:51 |
[Solve]programming issue
|
#1 |
Member
Julien Schaguene
Join Date: Apr 2009
Location: France
Posts: 55
Rep Power: 17 |
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 06:33. |
|
July 27, 2009, 06:01 |
|
#2 |
Senior Member
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18 |
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()); } |
|
July 27, 2009, 06:27 |
|
#3 |
Member
Julien Schaguene
Join Date: Apr 2009
Location: France
Posts: 55
Rep Power: 17 |
Perfect, that is exactly what I was looking for! I looked over other applications but not that one.
Thanks a lot! |
|
July 28, 2009, 03:31 |
|
#4 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
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. |
|
July 28, 2009, 03:40 |
|
#5 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
In OpenFOAM-1.6, the same thing becomes much more convenient:
Code:
scalar scaleFactor = 1.0; args.optionReadIfPresent("scale", scaleFactor); |
|
Tags |
programming |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
A book for a beginner wanting to learn programming | frank | Main CFD Forum | 9 | May 13, 2014 00:15 |
OpenFoam programming | prapanj | OpenFOAM | 10 | March 18, 2010 08:23 |
Programming in OpenFOAM | vinu | OpenFOAM | 2 | July 11, 2009 11:16 |
new CFD Programming Forum | Thinker | Main CFD Forum | 14 | November 19, 2002 17:03 |
STAR-CD Dynamics issue 16 | CD adapco Group Marketing | Siemens | 0 | November 30, 2001 11:25 |