|
[Sponsors] |
IFstream binary file read type conversion problem |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
October 24, 2008, 16:02 |
In OpenFOAM 1.5, I believe the
|
#1 |
New Member
David Car
Join Date: Mar 2009
Location: Dayton, OH, USA
Posts: 7
Rep Power: 17 |
In OpenFOAM 1.5, I believe there might be an issue with the IFstream when trying to read a binary block. See my sample code below. When tracking this down, I realized that there is also a "word" constructor with takes the arguments passed to the binary reader (IFstream::read(char *, std::streamsize) of the IFstream, i.e. a character pointer and an int. Since the "word" constructor is not declared explicit, the compiler (tried both gcc-4.3.1 and gcc-4.3.2) is doing the nice thing and type converting my arguments to a "word" before passing looking up which overloaded read function of IFstream to use. I deduced this from the following error when running the code on a simple binary file:
.... word too long maximum number of characters allowed = 1024 file: flat-plate-medium-binary.g.r8 at line 1. From function ISstream::read(word&) in file db/IOstreams/Sstreams/ISread.C at line 81. FOAM exiting ..... So it appears that its type converting by calling the word constructor and then call the appropriate read function of the IFstream. I find it hard to believe that no-one has experienced this so I feel pretty certain that I'm missing something here. Otherwise, should the word constructor be declared explicit to prevent this type conversion? Or will that introduce other issues in OpenFOAM. Many thanks. Sample code: ------------ #include "argList.H" #include "IFstream.H" using namespace Foam; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Main program: int main(int argc, char *argv[]) { argList::noParallel(); argList::validArgs.append("binary file"); argList args(argc, argv); if (!args.check()) { FatalError.exit(); } IFstream::streamFormat ifmt = IFstream::BINARY; IFstream myFile(args.additionalArgs()[0], ifmt); int myvar; myFile.read(reinterpret_cast<char> &myvar), sizeof(myvar)); return 0; } ....... Testcase: (preferably one of the tutorials) Platform: Linux gcc-4.3.1 and gcc-4.3.2, KUbuntu. Version: OpenFOAM 1.5 All the best, David |
|
October 24, 2008, 18:09 |
FYI, the syntax in the myFile.
|
#2 |
New Member
David Car
Join Date: Mar 2009
Location: Dayton, OH, USA
Posts: 7
Rep Power: 17 |
FYI, the syntax in the myFile.read statement above did not cut and paste properly. It is and should be:
myFile.read(reinterpret_cast<char*>(&myvar), sizeof(myvar)); |
|
October 29, 2008, 12:39 |
No issues... I'm really sorry
|
#3 |
New Member
David Car
Join Date: Mar 2009
Location: Dayton, OH, USA
Posts: 7
Rep Power: 17 |
No issues... I'm really sorry for the confusion... it didn't make sense with the type conversion at first... after digging for a few hours through the code base, I now see how the IFstream is implemented and realize that the binary block read is not a raw binary read, but looks for a BEGIN_LIST token... after creating a binary file with the "(" token to begin and a ")" token to end it works just fine. Again, my apologies.
|
|
October 30, 2008, 15:18 |
The OpenFOAM binary streams ar
|
#4 |
Senior Member
Mattijs Janssens
Join Date: Mar 2009
Posts: 1,419
Rep Power: 26 |
The OpenFOAM binary streams are specifically created to input/output OpenFOAM meshes and fields. Have a look at e.g. constant/polyMesh/owner after setting writeFormat to binary and running blockMesh.
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
IFStream read float point data problem | liu | OpenFOAM Running, Solving & CFD | 0 | October 24, 2008 13:14 |
invalid type for binary expression: double / funct | Fiachra | FLUENT | 0 | April 12, 2007 09:04 |
How to read the patch type | diegon | OpenFOAM Running, Solving & CFD | 0 | January 10, 2007 16:03 |
UDF Read external File problem | guru | FLUENT | 1 | September 15, 2004 07:24 |
Read Plot3D Binary File | John | Main CFD Forum | 3 | January 17, 2001 04:57 |