0

I have spent several hours on understanding why my code eventually produced an error (for a large enough number of loops). I reduced the problem to the following MWE:

file fout=stdout; // to write on Terminal

for(int j=1;j<=30;j=j+1) 
{
    write(fout,'\n');
    write(fout,j);

    for (int i=j; i<50; i=i+1)
    {
        file in1=input("gag.dat").line().csv();
    }
}

gag.dat can be anything, including an empty file. I have tested this on two independent computers (both under Linux) and both returns an error when j reaches 30:

10.6: runtime: Cannot open file "gag.dat"

This is extremely annoying since it prevents me from building animations. I could compile my code by slices of j (1 to 10, 11 to 20, etc.) but then I have to rename every single output file.

Can it be something else than a bug?!

Any solution or workaround welcome.

1 Answer 1

2

Can it be something else than a bug?!

Yes. Opened files should be closed (with close(filename))... The following code works.

file fout=stdout; // to write on Terminal

for(int j=1;j<=30;j=j+1) 
{
    write(fout,'\n');
    write(fout,j);

    for (int i=j; i<50; i=i+1)
    {
        file in1=input("gag.dat").line().csv();
        close(in1); // <- ADDED LINE
    }
}

Sorry for disturbing...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .