CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (http://www.cfd-online.com/Forums/openfoam-solving/)
-   -   IFStream read float point data problem (http://www.cfd-online.com/Forums/openfoam-solving/58424-ifstream-read-float-point-data-problem.html)

liu October 24, 2008 12:14

Hi, Just came across an probl
 
Hi,
Just came across an problem related to IFStream.
I have a data file: sample.xyz which has xyz data
384165.6 4762392.7 0
384204.5 4762602.3 0

Then I simply read the data and print them on the screen. They output is:
384166 4.76239e+06 0
384204 4.7626e+06 0

The float point data x becomes an integer and the y data also lost some precision.

I believe it is related to the format. Could someone give me some hint?

The test program is:
#include "fvCFD.H"
#include "OFstream.H"
#include "IFstream.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{
//dem data
const int nDEMPoints=2;
scalar tmp;
label tmpl;
scalar x,y,z;

//read in the dem data
fileName dxDataFile("sample.xyz");
IFstream dataIn(dxDataFile);

for (label i=0;i<nDEMPoints;i++)
{
dataIn >> x >> y >> z;
Info << x << " " << y << " " << z << endl;
}

Info << "\nEnd\n" << endl;

return 0;
}

http://www.cfd-online.com/OpenFOAM_D...hment_icon.gif IFTest.tgz


All times are GMT -4. The time now is 10:15.