|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
How to read a lot of data from a file into a N*M array?
Thank a lot.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |