POV-Ray : Newsgroups : povray.advanced-users : File I/O handling... Server Time
25 Nov 2024 17:35:16 EST (-0500)
  File I/O handling... (Message 1 to 6 of 6)  
From: Tim Nikias
Subject: File I/O handling...
Date: 4 Aug 2002 10:01:49
Message: <3d4d33cd$1@news.povray.org>
I've got a pretty complex problem...

What I want my system to do is to read positions,
generate some new data from that, and write those
back to disk.

In order to make handling easy, the positions are first
copied (by reading and writing) to another file, from
which I read. This enables me to write in the original
file, thus making usage in animations etc. very easy.

Problem is, the system crashes when trying to write data
it read from an empty file. I would expect it to crash when
reading from an empty file, but not when writing the empty
data. Guess this has to do with internal handling of
identifiers etc.

Still, I'd like to make my system crash-proof. As long as
new positions are generated, everything works fine, but
I need to check if a file is empty, and then stop the system
from trying anything if that is the case.

So, how do I check if an opened file is actually empty?

--
Tim Nikias
Homepage: http://www.digitaltwilight.de/no_lights/index.html
Email: Tim### [at] gmxde


Post a reply to this message

From: Tim Nikias
Subject: Re: File I/O handling...
Date: 4 Aug 2002 10:04:14
Message: <3d4d345e$1@news.povray.org>
I forgot to mention that this happens even
while using
 #while (defined(File))

I'd expect the while loop to terminate at once with
an empty file, but it doesn't do so, and I'm slightly
clueless on how to check if the file is empty without
losing the data I read in first...


--
Tim Nikias
Homepage: http://www.digitaltwilight.de/no_lights/index.html
Email: Tim### [at] gmxde


Post a reply to this message

From: Simon Adameit
Subject: Re: File I/O handling...
Date: 4 Aug 2002 10:26:59
Message: <3d4d39b3@news.povray.org>
"Tim Nikias" wrote:
> So, how do I check if an opened file is actually empty?
>

Read it. If the file_handle is undefed after reading the first time from
this file than it's an empty file.
But somehow the data_identifier is defined but doesn't contain any data.
I think this is what is causing the crash when trying to write it.

Simon


Post a reply to this message

From: Tim Nikias
Subject: Re: File I/O handling...
Date: 4 Aug 2002 10:47:25
Message: <3d4d3e7d$1@news.povray.org>
Thanks. I tried it before, but I made a mistake in the algorithm...
I can see it cleary now... (Tadaa!)
;-)

Regards,

Tim

--
Tim Nikias
Homepage: http://www.digitaltwilight.de/no_lights/index.html
Email: Tim### [at] gmxde
"Simon Adameit" <gom### [at] gmxde> schrieb im Newsbeitrag
news:3d4d39b3@news.povray.org...
>
> "Tim Nikias" wrote:
> > So, how do I check if an opened file is actually empty?
> >
>
> Read it. If the file_handle is undefed after reading the first time from
> this file than it's an empty file.
> But somehow the data_identifier is defined but doesn't contain any data.
> I think this is what is causing the crash when trying to write it.
>
> Simon
>
>
>
>
>


Post a reply to this message

From: Tim Nikias
Subject: Nope, doesn't work
Date: 4 Aug 2002 11:09:54
Message: <3d4d43c2@news.povray.org>
Damn! It still doesn't work!

Problem is this:
When only one vector is saved in the file, the system
doesn't move on. With two vectors, it begins, but with
only one... Here's the code:

 #fopen _Seed_Origin concat("seedfile.",_VegI) read
 #fopen _Seed_Dump "veg_dump.tmp" write

 #local _Seed_Index=0; //Keeps track if first vector was saved...
 #local _Read_Seeds=0; //Keeps track of overall read vectors

 #while (defined(_Seed_Origin))
  #read (_Seed_Origin, _ISeed)
  #if (defined(_Seed_Origin) | defined(_ISeed))
   #local _Read_Seeds=_Read_Seeds+1;
   #if (_Seed_Index)
    #write (_Seed_Dump, ",",_ISeed) #else
    /*E*/ #write (_Seed_Dump, _ISeed) #local _Seed_Index=1; #end
  #end
  #undef _ISeed
 #end

 #fclose _Seed_Origin
 #fclose _Seed_Dump

The _Seed_Index just takes care of placing the comma
between the vectors to make POV able to read the
different vectors.

When the Seed_Origin file is empty, POV will crash
on the line marked with /*E*/ and state:
Parse Error: Expected 'string', undeclared identifier '_ISeed'
found instead.

Didn't I check for that "undeclared identifier" with
defined(_ISeed)?

I think something is definitely not working they way it
is explained by the error and in the documentation...?

Anyone got a clue what to do?

--
Tim Nikias
Homepage: http://www.digitaltwilight.de/no_lights/index.html
Email: Tim### [at] gmxde


Post a reply to this message

From: Simon Adameit
Subject: Re: Nope, doesn't work
Date: 4 Aug 2002 12:42:01
Message: <3d4d5959@news.povray.org>
"Tim Nikias" wrote:
> Damn! It still doesn't work!
>   #if (defined(_Seed_Origin) | defined(_ISeed))

Change this line into:
#if (defined(_Seed_Origin))

And make sure that you have a comma behind the last item in the file from
that you read.
Otherwise it will recognize the end of the file to early.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.