POV-Ray : Newsgroups : povray.general : a simple question about File I/O Server Time
17 Nov 2024 03:21:37 EST (-0500)
  a simple question about File I/O (Message 1 to 8 of 8)  
From: aaaz123456
Subject: a simple question about File I/O
Date: 1 Jul 2003 12:26:59
Message: <3f01b653@news.povray.org>
How to read a lot of data from a file into a N*M array?
Thank a lot.


Post a reply to this message

From: ABX
Subject: Re: a simple question about File I/O
Date: 1 Jul 2003 12:42:38
Message: <9td3gvcapg56dpk1qgbo20idgu2bnsi7mh@4ax.com>
On Wed, 2 Jul 2003 00:26:48 +0800, "aaaz123456" <aaa### [at] yahoocomtw> wrote:
> How to read a lot of data from a file into a N*M array?

Running loop with necessary number of passes to read N*M elements which is
simplest to understand when realized as N loops of M loops of simple reading.

#local N=...;  // fill with
#local M=...;  // favorite dimensions
#local Array=array[N][M];
#fopen MyFile "myfile.txt" read
#local n=0;
#while (n<N)
  #local m=0;
  #while (m<M)
    #read(MyFile,Array[n][m])
    #local m=m+1;
  #end
  #local n=n+1;
#end
#fclose MyFile

Look at http://www.povray.org/documentation/view/147/ for further description of
used directives

ABX


Post a reply to this message

From: Tim Nikias v2 0
Subject: Re: a simple question about File I/O
Date: 1 Jul 2003 17:56:20
Message: <3f020384$1@news.povray.org>
You might also want to take a look at my
I/O Macros. Even if you don't want to use
them, they can provide a nice example
for you to dissect and study how to do it.
ABX's reply has already given the HOW,
so I'm just providing an example... :-)

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

> How to read a lot of data from a file into a N*M array?
> Thank a lot.
>
>


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.495 / Virus Database: 294 - Release Date: 30.06.2003


Post a reply to this message

From: aaaz123456
Subject: Re: a simple question about File I/O
Date: 1 Jul 2003 22:31:04
Message: <3f0243e8@news.povray.org>
I use the following loops to read data ,
but get a error message,that is "Parse error : Expected ' undeclared
indentifier' ,empty array found instead"
Why?
Thanks a lot .

> #local N=3;  // fill with
> #local M=3;  // favorite dimensions
> #local Array=array[N][M];
> #fopen MyFile "myfile.txt" read
> #local n=0;
> #while (n<N)
>   #local m=0;
>   #while (m<M)
>     #read(MyFile,Array[n][m])
>     #local m=m+1;
>   #end
>   #local n=n+1;
> #end
> #fclose MyFile
>


Post a reply to this message

From: ABX
Subject: Re: a simple question about File I/O
Date: 2 Jul 2003 02:17:09
Message: <5it4gv8jev6o6191jm5cs2b6pn21hut5om@4ax.com>
On Wed, 2 Jul 2003 10:30:53 +0800, "aaaz123456" <aaa### [at] yahoocomtw> wrote:
> I use the following loops to read data ,
> but get a error message,that is "Parse error : Expected ' undeclared
> indentifier' ,empty array found instead"
> Why?

Have you checked at which iteration it stops ? First ? Then before loops assign
value to any element of array to describe expected type of all array elements.
For example:

#local Array=array[N][M];
#local Array[0]0]=0;

Moreover you can introduce error checking inside loop:

   #ifdef(MyFile)
     #read(MyFile,Array[n][m])
   #else
     #error concat("Can't read element Array[",str(n,0,0),",",str(m,0,0),"]")
   #end


ABX


Post a reply to this message

From: Mike Williams
Subject: Re: a simple question about File I/O
Date: 2 Jul 2003 02:54:49
Message: <7+2ixHAlGoA$EwBb@econym.demon.co.uk>
Wasn't it aaaz123456 who wrote:
>I use the following loops to read data ,
>but get a error message,that is "Parse error : Expected ' undeclared
>indentifier' ,empty array found instead"
>Why?
>Thanks a lot .
>
>> #local N=3;  // fill with
>> #local M=3;  // favorite dimensions
>> #local Array=array[N][M];
>> #fopen MyFile "myfile.txt" read
>> #local n=0;
>> #while (n<N)
>>   #local m=0;
>>   #while (m<M)
>>     #read(MyFile,Array[n][m])
>>     #local m=m+1;
>>   #end
>>   #local n=n+1;
>> #end
>> #fclose MyFile
>>

Add this line before the loop and it works

  #local Array[0][0] = 0;

It looks like #read is failing to instantiate the array, so you have to
do it yourself first.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: aaaz123456
Subject: Re: a simple question about File I/O
Date: 2 Jul 2003 12:43:28
Message: <3f030bb0@news.povray.org>
Finally, I use the loop which is like the following loop.
I don't get any problem ,but I don't know why I can't use ABX's way to
write my loop.

Anyway, thank you.


#declare N=23431;  // fill with
#declare M=3;  // favorite dimensions
#declare Ar=array[N][M];
#fopen MyFile "data.txt" read

#declare n=0;
#while (n<N)
  //#declare m=0;
  //#while (m<M)

    #read(MyFile,a,b,c)

    #declare Ar[n][0]=a/100 ;
      #declare Ar[n][1]=b/100 ;
        #declare Ar[n][2]=c/100 ;

   // #declare m=m+1;
  //#end
  #declare n=n+1;
#end
#fclose MyFile


Post a reply to this message

From: ABX
Subject: Re: a simple question about File I/O
Date: 2 Jul 2003 12:49:12
Message: <0036gvkmv34e50atu0hk4oo25atceg9vdp@4ax.com>
On Thu, 3 Jul 2003 00:43:16 +0800, "aaaz123456" <aaa### [at] yahoocomtw> wrote:
> Finally, I use the loop which is like the following loop.
> I don't get any problem ,but I don't know why I can't use ABX's way to
> write my loop.

Is your input data correct? In particular, are numbers comma separated ?

ABX


Post a reply to this message

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