CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

convert fileName to double

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   February 21, 2011, 04:59
Default convert fileName to double
  #1
Senior Member
 
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 10
braennstroem is on a distinguished road
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
braennstroem is offline   Reply With Quote

Old   February 21, 2011, 05:15
Default
  #2
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 14
l_r_mcglashan will become famous soon enough
Here's a C solution:

http://www.cplusplus.com/reference/c.../cstdlib/atof/
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   February 21, 2011, 05:40
Default
  #3
Senior Member
 
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 10
braennstroem is on a distinguished road
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:ointField&, 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:ointField&, 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:ointField&, 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:ointField&, 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
braennstroem is offline   Reply With Quote

Old   February 21, 2011, 05:50
Default
  #4
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 14
l_r_mcglashan will become famous soon enough
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());
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   February 21, 2011, 07:58
Default
  #5
Senior Member
 
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 10
braennstroem is on a distinguished road
....Thanks!
braennstroem is offline   Reply With Quote

Old   February 21, 2011, 08:29
Default
  #6
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,251
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
Greetings to all!

A similar question was asked not long ago, including the solution: float or scalar for runTime.tinename() ??

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
wyldckat is offline   Reply With Quote

Old   February 21, 2011, 08:59
Default
  #7
Senior Member
 
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 10
braennstroem is on a distinguished road
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
braennstroem is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parallel User Defined Real Gas Model aeroman FLUENT 4 July 1, 2015 06:09
Continuing User Defined Real Gas Model issues aeroman FLUENT 5 May 1, 2015 02:57
New densitybased solver AeroFoam giulio_romanelli OpenFOAM Running, Solving & CFD 39 October 8, 2013 02:37
Missing math.h header Travis FLUENT 4 January 15, 2009 12:48
REAL GAS UDF brian FLUENT 6 September 11, 2006 08:23


All times are GMT -4. The time now is 11:49.