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/)
-   -   Error Reading date file (http://www.cfd-online.com/Forums/openfoam-solving/59070-error-reading-date-file.html)

chnrdu June 17, 2005 22:42

I want to make a transient sim
 
I want to make a transient simulation of a pipe. on one end, I make the pressure as a function respect to time and write to a file as:
(
t0 p0
t1 p1
...
tN pN
)
but when I compute it, there is a error:

Reading field p

--> FOAM FATAL IO ERROR : IOstream::check(const char* operation) : error in IOstream "inletPressure.dat" for operation Istream::operator()

file: inletPressure.dat at line 1.

Function: IOstream::check(const char* operation) const
in file: db/IOstreams/IOstreams/IOcheck.C at line: 54.

FOAM exiting

what about the error? How to correct?
Thanks in advance.

mattijs June 20, 2005 05:11

1. is the file present? 2.
 
1. is the file present?

2. what boundary condition are you using? timeVaryingUniformFixedValue?

Does it work if you remove the bracket pair? I think this b.c. reads an unformatted 2 column file to make it easy to use externally generated data.

chnrdu June 21, 2005 00:26

Yes, I use the timeVaryingUnif
 
Yes, I use the timeVaryingUniformFixedValue.

I removed the bracket pair. there is the same problem. You mean the unformatted 2 column file as binary file?

mattijs June 21, 2005 05:22

Sorry, never used it. I found
 
Sorry, never used it. I found the actual reading gets done in sampling/lnInclude/graph.C where it constructs the graph from an Istream.

Looks like the format is
"title"
"x" "y"
0.0 54
0.1 24
0.2 35

or something similar.

henry June 21, 2005 08:24

The format of the file read by
 
The format of the file read by timeVaryingUniformFixedValue is

(
t0 p0
t1 p1
...
tN pN
)

but the error message you get suggests that the file cannot be found, i.e. is not in the location you specify in the boundary condition details.

chnrdu June 21, 2005 08:37

Thank u, H. Weller. I find
 
Thank u, H. Weller.

I find the error that u pointed out. I located it in the 0/p fold. i copy it to the caseroot fold. Now It works well.

olivier September 27, 2005 15:05

Hi, Foam don't accept this i
 
Hi,
Foam don't accept this instruction.
How can I do this in Foam
-------------------
FILE *fp;
int i;
fp=fopen("filePr","r+");
for(i=0;i<=size;i++)
{
fscanf(fp,"%f %f %f %f",&pr[5*i],&pr[5*i+1],
&pr[5*i+2],&pr[5*i+3]);
}


fclose(fp);
-----------------------------
thanks

mattijs September 28, 2005 04:53

IFstream str("filePr"); sca
 
IFstream str("filePr");

scalar a,b,c,d;

str>> a >> n >> c >> d;

aurelia July 5, 2006 09:14

Hello For postprocessing pu
 
Hello

For postprocessing purpose, I am using ifstream to read a file and calculate something called A, which is then wroten in an other file


fileName fileV="v.dat";
OFstream VFile(fileV);
fileName fileC= "c.dat";
IFstream CFile(fileC);
char a;char b;
double T1;double T2;scalar C1x;scalar C1y;scalar C1z;scalar C2x;scalar C2y;scalar C2z;scalar A;
while(!CFile.eof() )
{ CFile>>T1>>a>>C1x>>C1y>>C1z>>b>>T2>>a>>C2x>>C2y>>C 2z>>b;
A= ...// Here it calculates A
VFile<< T2 << " "<<A<< endl;
}


It works (read, calculate and write) for all the value in the read-file but then I get the following error:

--> FOAM FATAL IO ERROR : Attempt to get back from bad stream

file: c.dat at line 124.

From function void Istream::getBack(token& t)
in file db/IOstreams/IOstreams/Istream.C at line 44.


I think that it doesn't understand that it is the end of the file, even with the .eof()
Should I close the file (... how?) to avoid this error?
Or should the read-file have something special at the end?

Thanks
Aurelia

maka March 6, 2008 11:52

I have a file with the followi
 
I have a file with the following format.

y1 u1 v1 w1
y2 u2 v2 w2
...
yn un vn wn

I know that one can read Field<t> from IStream but how can I read such mixed format to:
scalarField y;
vectorField u;

Is there a way to do it in OpenFOAM or should I write another graph class that accepts such format? thanks.

kuczmas March 3, 2011 09:11

Hey Aurelia,
Did you manege to solve you problem? I have got the same error message, when trying to write my data into the file.

Cheers

kuczmas March 3, 2011 09:18

Hey mattijs,

after using your code snippet
Quote:

Originally Posted by mattijs (Post 188829)
IFstream str("filePr");

scalar a,b,c,d;

str>> a >> n >> c >> d;

in my program I got the following error message:

Code:

--> FOAM FATAL IO ERROR:
Attempt to get back from bad stream

file: filePr at line 1.

    From function void Istream::getBack(token&)
    in file db/IOstreams/IOstreams/Istream.C at line 38.

FOAM exiting

Do you know what's wrong and how to fix it?

Bernhard January 29, 2013 02:57

Quote:

Originally Posted by aurelia (Post 188830)
--> FOAM FATAL IO ERROR : Attempt to get back from bad stream

I am encountering the same error message as above. Anyone who knows what I am doing wrong?

Bernhard January 29, 2013 03:35

So, apparently, the problem is, the I am trying to read four values at once, like

Code:

file >> a >> b >> c >> d;
There error-message occurs on the second >> as far as I can see.

My work-around is as follows
Code:

file >> a;
if( !file.bad() )
{
    file >> b >> c >> d;
    // Everything else
}

which solves my problem.

I don't like the 'niceness' of this solution, so I am open for suggestions.


All times are GMT -4. The time now is 05:09.