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

IFStream read float point data problem

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 24, 2008, 13:14
Default Hi, Just came across an probl
  #1
liu
Senior Member
 
Xiaofeng Liu
Join Date: Mar 2009
Location: State College, PA, USA
Posts: 118
Rep Power: 17
liu is on a distinguished road
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;
}

IFTest.tgz
__________________
Xiaofeng Liu, Ph.D., P.E.,
Assistant Professor
Department of Civil and Environmental Engineering
Penn State University
223B Sackett Building
University Park, PA 16802


Web: http://water.engr.psu.edu/liu/
liu is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
IFstream binary file read type conversion problem card OpenFOAM Bugs 3 October 30, 2008 15:18
How to read data into my UDF??? Harshit Gupta FLUENT 3 June 15, 2006 03:34
float point error soundar FLUENT 0 December 17, 2004 04:23
UDF to read and write data Mcgregor FLUENT 4 June 9, 2003 14:21
read in wall data Ethan Siemens 0 March 29, 2003 16:19


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