POV-Ray : Newsgroups : povray.advanced-users : File I/O question Server Time
2 Nov 2024 05:17:43 EDT (-0400)
  File I/O question (Message 1 to 4 of 4)  
From: David Vincent-Jones
Subject: File I/O question
Date: 10 Mar 2000 13:40:59
Message: <38c941bb@news.povray.org>
I would like to be able to selectively read from a text file with records
terminated with a line feed.

The #read - #write looks just fine for a single item file but how can I
select a specific record?


Post a reply to this message

From: Margus Ramst
Subject: Re: File I/O question
Date: 10 Mar 2000 19:32:32
Message: <38C99491.45FB4438@peak.edu.ee>
Random reading is not very easy with POV. You have to move through records one
by one, i.e. to get to record N you have go through 1,2,3,...,N #reads. For
example get 10th record do sth. like this (untested):

#fopen F "file" read
#local N=10; //Needed record
#local C=0;
//Jump through the first 9 records
#while (C<N)
  #read(F,X)
#end
#read(F,NeededValue)

Of course if all jumps are are known to be forward (i.e. the next record is
always somewhere after the current one) you don't have to start from the
beginning every time (to restart from the beginning you have to close the file
and reopen it)
Not very elegant; if memory is not a critical issue, I suggest you read all
values into an array, and use this instead.
Also note that values _have_ to be separated by commas.

Margus

David Vincent-Jones wrote:
> 
> I would like to be able to selectively read from a text file with records
> terminated with a line feed.
> 
> The #read - #write looks just fine for a single item file but how can I
> select a specific record?


Post a reply to this message

From: David Vincent-Jones
Subject: Re: File I/O question
Date: 10 Mar 2000 21:46:01
Message: <38c9b369$1@news.povray.org>
Looks like this would be a useful extension area for the language

If the full file is placed into an array. What is the array item select
procedure. I don't see anything in the Help and not much in the written
Docs.

David

Margus Ramst <mar### [at] peakeduee> wrote in message
news:38C99491.45FB4438@peak.edu.ee...
> Random reading is not very easy with POV. You have to move through records
one
> by one, i.e. to get to record N you have go through 1,2,3,...,N #reads.
For
> example get 10th record do sth. like this (untested):
>
> #fopen F "file" read
> #local N=10; file://Needed record
> #local C=0;
> file://Jump through the first 9 records
> #while (C<N)
>   #read(F,X)
> #end
> #read(F,NeededValue)
>
> Of course if all jumps are are known to be forward (i.e. the next record
is
> always somewhere after the current one) you don't have to start from the
> beginning every time (to restart from the beginning you have to close the
file
> and reopen it)
> Not very elegant; if memory is not a critical issue, I suggest you read
all
> values into an array, and use this instead.
> Also note that values _have_ to be separated by commas.
>
> Margus
>
> David Vincent-Jones wrote:
> >
> > I would like to be able to selectively read from a text file with
records
> > terminated with a line feed.
> >
> > The #read - #write looks just fine for a single item file but how can I
> > select a specific record?


Post a reply to this message

From: Margus Ramst
Subject: Re: File I/O question
Date: 11 Mar 2000 09:48:26
Message: <38CA5D24.82015B3E@peak.edu.ee>
David Vincent-Jones wrote:
> 
> Looks like this would be a useful extension area for the language

I quite agree.

> If the full file is placed into an array. What is the array item select
> procedure. I don't see anything in the Help and not much in the written
> Docs.
> 

For example, the first item of a (one-dimensional) array MyArray is referred to
as MyArray[0] (records are zero-based). Each initialized array item can be
thought of as a declared variable. So you can perform any operations you would
with declared variables such as:

#declare X = X + MyArray[0];

Also, you have to bear in mind that a particular array can only contain records
of one data type (float, vector, object, etc).

Margus


Post a reply to this message

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