Reading values from file
Hi all,
I want to read a file with FOAM classes. I checked out the boundary condition "timeVaryingMappedFixedValue" but I did not get the point how to read a file and store the values in an array (scalarField etc.) At the moment I created an IFstream: Code:
Thanks in advance Tobi |
Dear Tobi,
As I can see in the openfoam code (IFstream.H - .C) there are practically no implemented functions for the IFstream class. Why don't you use the original ifstream C++ class? You can read everything with it. |
Because I wanna use FOAM classes :)
But yes as you told, it seems to be no implementation of functions for that file but it sdhould be possible to do sth. like that. |
Hi,
Can you please clarify several moments: 1. You'd like to read values into array (i.e. just a sequence of values) or it should be a Field (i.e. values have spatial variations and linked to the mesh)? 2. You'd like to read ASCII file, binary file? 3. What is wrong with ISstream's read method? http://foam.sourceforge.net/docs/cpp...e693cadb1d0305 4. If I am not mistaken there are also overloaded right shift operators. 4. Finally there is DataEntry class which can read values from OpenFOAM's dictionaries/CSV files. Though in this case it's more complicated as the class adds interpolation. |
Hi Alex,
thanks for your reply. Did not know why I am not using ISstream. Yesterday I had a look at Doxygen and got the point that ISstream would be a good class (necessary functions available like getLine() ...). I will test it today in the evening. At least to your questions:
Code:
#List which has to be read
Thanks in advance, |
Hi,
Quote:
In case of ASCII files solution if straightforward, read line, if it is not a comment try to parse number. In case of binary files everything is a little bit more complicated. Read into char buffer, convert into scalar. Though I'm not quite sure that is not an invention of the wheel. About timeVaryingMappedFixedValue, list is read during construction of this property of the class: Code:
autoPtr<DataEntry<Type> > offset_; Code:
offset_->value(t) |
Thank you again.
Well I am stupid because I checked the Doxygen and saw that IFstream is a child of ISstream but in the header I checked the wrong class which has no derivation to ISstream. After your hints I checked it again and now I get the lines: So then it should be possible to use IFstream and use the ISstream functionallity. I try it today in the evening. |
All times are GMT -4. The time now is 13:55. |