POV-Ray : Newsgroups : povray.newusers : I/O Macro problem Server Time
4 Nov 2024 21:22:36 EST (-0500)
  I/O Macro problem (Message 1 to 3 of 3)  
From: Stephen McAvoy
Subject: I/O Macro problem
Date: 25 Dec 2002 17:43:34
Message: <3e0a3471.38883090@news.povray.org>
I am trying to write a macro that will read a file into an array. It
works when it is called the first time but when it is called a second
time I get this error.

                        #read (ReadFile <----ERROR

Parse Error: Expected 'file identifier', undeclared identifier
'ReadFile' found instead

What have I done wrong? I get no clues from the documentation and
looking at Tim Nikias Wenclawiak's io_macs.inc does not help me I am
obviously missing something. A sandwich short of a picnic maybe :
I hope it allowable to post the code here

Stephen

#macro ReadDat (File_Name, Buff_Name) 

#fopen ReadFile File_Name  read 
#read (ReadFile,Var1,Var2,Var3)   
#declare Buff_Name=array [Var1][Var2]      ;  
#local H1=0                                   ;
        #while (H1< Var2 )
        #local W1=0   ;
                #while (W1< Var1)
                        #read (ReadFile,Var4) 
                        #declare Buff_Name  [W1][H1]  =  Var4      ;
             #local W1=W1+1           ;
                #end  
        #local H1=H1+1                    ;
        #end        
#fclose ReadFile
#end  
              
// First call of Macro
#declare File_Name = "b.dat"            ;
#declare Buff_Name= "BufferLast"           ;
ReadDat (File_Name, Buff_Name)

// Second call of Macro
#declare File_Name = "a.dat"            ;
#declare Buff_Name= "BufferCur"           ;
ReadDat (File_Name, Buff_Name)


Post a reply to this message

From: Tim Nikias
Subject: Re: I/O Macro problem
Date: 26 Dec 2002 08:44:10
Message: <3e0b07aa@news.povray.org>
1. I don't know why you're loading Var3...
2. Always use #local instead of #declare in Macros,
 unless you really want to declare something

And then, I'm not sure if the way how you pass the identifier
for the name of the array to the macro works. You're
passing a string and want it to become an identifier, if
I'm not mistaken, that doesn't work, which is the
reason why I made my macros the way I did. I had to
either declare the array beforehand, or prepare an
array-identifier which I overwrite inside the macro, like
this:

#declare Array= array[1][1]
#macro Overwrite(Array)
 #declare Array = Array[4][5] //Loaded values
#end

I've had several cases where POV issues an error, which is actually
just a result of some other mistake, but POV can only see the actual
mistake which hinders it to parse/render, so that's not a bug.

Take a closer look at the Documentation about #declare, #local,
#macro, strings/floats/arrays. You should find some answers there.

Regards,
Tim


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

> I am trying to write a macro that will read a file into an array. It
> works when it is called the first time but when it is called a second
> time I get this error.
>
>                         #read (ReadFile <----ERROR
>
> Parse Error: Expected 'file identifier', undeclared identifier
> 'ReadFile' found instead
>
> What have I done wrong? I get no clues from the documentation and
> looking at Tim Nikias Wenclawiak's io_macs.inc does not help me I am
> obviously missing something. A sandwich short of a picnic maybe :
> I hope it allowable to post the code here
>
> Stephen
>
> #macro ReadDat (File_Name, Buff_Name)
>
> #fopen ReadFile File_Name  read
> #read (ReadFile,Var1,Var2,Var3)
> #declare Buff_Name=array [Var1][Var2]      ;
> #local H1=0                                   ;
>         #while (H1< Var2 )
>         #local W1=0   ;
>                 #while (W1< Var1)
>                         #read (ReadFile,Var4)
>                         #declare Buff_Name  [W1][H1]  =  Var4      ;
>              #local W1=W1+1           ;
>                 #end
>         #local H1=H1+1                    ;
>         #end
> #fclose ReadFile
> #end
>
> // First call of Macro
> #declare File_Name = "b.dat"            ;
> #declare Buff_Name= "BufferLast"           ;
> ReadDat (File_Name, Buff_Name)
>
> // Second call of Macro
> #declare File_Name = "a.dat"            ;
> #declare Buff_Name= "BufferCur"           ;
> ReadDat (File_Name, Buff_Name)
>
>


Post a reply to this message

From: Stephen McAvoy
Subject: Re: I/O Macro problem
Date: 26 Dec 2002 13:53:37
Message: <3e0b4ef3.111205414@news.povray.org>
On Thu, 26 Dec 2002 14:45:35 +0100, "Tim Nikias" <tim### [at] gmxde>
wrote:

>I've had several cases where POV issues an error, which is actually
>just a result of some other mistake, but POV can only see the actual
>mistake which hinders it to parse/render, so that's not a bug.

How right you were. The "other mistake" was not having the second data
file in the correct format i.e. spaces instead of commas as
separators.

Thanks Stephen


Post a reply to this message

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