CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   convert fileName to double (http://www.cfd-online.com/Forums/openfoam-programming-development/85240-convert-filename-double.html)

braennstroem February 21, 2011 04:59

convert fileName to double
 
Hi,

does anyone know, how I can convert a fileName (which is basically just the time step for this case) to double!?

Thanks in advance!
Fabian

l_r_mcglashan February 21, 2011 05:15

Here's a C solution:

http://www.cplusplus.com/reference/c.../cstdlib/atof/

braennstroem February 21, 2011 05:40

Hello Laurence,

thanks for the hint, though I get for this command:

68 char *url="1";
69 strcpy(url, timeDir.c_str());
70 double timeDump = atof(url);

this warning:

sampledSurface/writers/foamFileVars/foamFileVars.C:68: warning: deprecated conversion from string constant to ‘char*’
sampledSurface/writers/foamFileVars/foamFileVarsWriters.C:41: instantiated from here
sampledSurface/writers/foamFileVars/foamFileVars.C:70: warning: unused variable ‘timeDump’
sampledSurface/writers/foamFileVars/foamFileVars.C: In member function ‘void Foam::foamFileVars<Type>::write(const Foam::fileName&, const Foam::fileName&, const Foam::fileName&, const Foam::pointField&, const Foam::faceList&, const Foam::fileName&, const Foam::Field<Type>&, bool) const [with Type = Foam::SymmTensor<double>]’:
sampledSurface/writers/foamFileVars/foamFileVarsWriters.C:41: instantiated from here
sampledSurface/writers/foamFileVars/foamFileVars.C:68: warning: deprecated conversion from string constant to ‘char*’
sampledSurface/writers/foamFileVars/foamFileVarsWriters.C:41: instantiated from here
sampledSurface/writers/foamFileVars/foamFileVars.C:70: warning: unused variable ‘timeDump’
sampledSurface/writers/foamFileVars/foamFileVars.C: In member function ‘void Foam::foamFileVars<Type>::write(const Foam::fileName&, const Foam::fileName&, const Foam::fileName&, const Foam::pointField&, const Foam::faceList&, const Foam::fileName&, const Foam::Field<Type>&, bool) const [with Type = Foam::SphericalTensor<double>]’:
sampledSurface/writers/foamFileVars/foamFileVarsWriters.C:41: instantiated from here
sampledSurface/writers/foamFileVars/foamFileVars.C:68: warning: deprecated conversion from string constant to ‘char*’
sampledSurface/writers/foamFileVars/foamFileVarsWriters.C:41: instantiated from here
sampledSurface/writers/foamFileVars/foamFileVars.C:70: warning: unused variable ‘timeDump’
sampledSurface/writers/foamFileVars/foamFileVars.C: In member function ‘void Foam::foamFileVars<Type>::write(const Foam::fileName&, const Foam::fileName&, const Foam::fileName&, const Foam::pointField&, const Foam::faceList&, const Foam::fileName&, const Foam::Field<Type>&, bool) const [with Type = Foam::Vector<double>]’:
sampledSurface/writers/foamFileVars/foamFileVarsWriters.C:41: instantiated from here
sampledSurface/writers/foamFileVars/foamFileVars.C:68: warning: deprecated conversion from string constant to ‘char*’
sampledSurface/writers/foamFileVars/foamFileVarsWriters.C:41: instantiated from here
sampledSurface/writers/foamFileVars/foamFileVars.C:70: warning: unused variable ‘timeDump’
sampledSurface/writers/foamFileVars/foamFileVars.C: In member function ‘void Foam::foamFileVars<Type>::write(const Foam::fileName&, const Foam::fileName&, const Foam::fileName&, const Foam::pointField&, const Foam::faceList&, const Foam::fileName&, const Foam::Field<Type>&, bool) const [with Type = double]’:
sampledSurface/writers/foamFileVars/foamFileVarsWriters.C:41: instantiated from here
sampledSurface/writers/foamFileVars/foamFileVars.C:68: warning: deprecated conversion from string constant to ‘char*’


Probably there is a better way...!?
Thanks! Fabian

l_r_mcglashan February 21, 2011 05:50

I'll let someone else find a more 'foam' solution, but you can just do this, then you'll have no warnings:

double timeDump = atof(timeDir.c_str());

braennstroem February 21, 2011 07:58

....Thanks!

wyldckat February 21, 2011 08:29

Greetings to all!

A similar question was asked not long ago, including the solution: http://www.cfd-online.com/Forums/ope...-tinename.html

Basically, you can use runTime.value() to get the value of the latest time step :) This is valid only for objects of type Foam::Time, which should be the situation you're in. Otherwise, probably atof is the quickest solution.

Best regards,
Bruno

braennstroem February 21, 2011 08:59

Hi Bruno,
thanks for the info... I tried to get the current time step in a foamFile-functionObject, where I did have the fileName timedir available, so I thought, it would be easier to use this.

Regards!
Fabian


All times are GMT -4. The time now is 23:35.