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

convert fileName to double

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 21, 2011, 03:59
Default convert fileName to double
  #1
Senior Member
 
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 19
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, 04:15
Default
  #2
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23
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, 04:40
Default
  #3
Senior Member
 
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 19
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, 04:50
Default
  #4
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23
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, 06:58
Default
  #5
Senior Member
 
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 19
braennstroem is on a distinguished road
....Thanks!
braennstroem is offline   Reply With Quote

Old   February 21, 2011, 07:29
Default
  #6
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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
__________________
wyldckat is offline   Reply With Quote

Old   February 21, 2011, 07:59
Default
  #7
Senior Member
 
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 19
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


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 Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 06:51.