[Solve]programming issue
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 |
Julien,
yes, arguments are passed only as strings. Have a look into fluentMeshToFoam.L where it says: Code:
scalar scaleFactor = 1.0; |
Perfect, that is exactly what I was looking for! I looked over other applications but not that one.
Thanks a lot! |
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")) Of course, both solutions look fairly messy. |
In OpenFOAM-1.6, the same thing becomes much more convenient:
Code:
scalar scaleFactor = 1.0; |
All times are GMT -4. The time now is 19:10. |