POV-Ray : Newsgroups : povray.general : input/output file Server Time
30 Jul 2024 06:30:37 EDT (-0400)
  input/output file (Message 1 to 10 of 10)  
From: esterichia
Subject: input/output file
Date: 16 Oct 2009 09:20:01
Message: <web.4ad872742aad556549aa3f520@news.povray.org>
I would like to read data (float or vectors of float) from an ascii file and use
the data as coordinates for the geometry in the scene: some spheres connected by
cylinders.

I tried with the following code and an input file with a sequence of floats.
The problem is that some data in the input file are not read (I checked with the
#write): sometimes every second float is read, sometimes there is no regular
pattern. Moreover, sometimes the minus sign is not read.
(I got a similar error with vectors of floats)

Am I doing something wrong or is there a bug in the I/O functions?

I'm using povray-3.6.1-12 on ubuntu 9.04 but I get the same error in windows
both with 3.6.1 and 3.6.2.

Thanks
Ester

#fopen inputfile "in.dat" read
//#fopen outputfile "out.dat" write

  #if (defined(inputfile))
    #read (inputfile, y1, y2, y3)
  #end

  #while (defined(inputfile))
    #declare x1 = y1;
    #declare x2 = y2;
    #declare x3 = y3;

    #read (inputfile, y1,y2,y3)

    sphere { <x1,x2,x3>, 0.3  pigment {color Green}}
    #if (!(x1 = y1 & x2 = y2 & x3 = y3))
      cylinder { <x1,x2,x3>, <y1,y2,y3>, 0.1 pigment {color Red}}
    #end

//    #write (outputfile, x1, " ", x2, " ", x3, "\n")
  #end

#fclose inputfile
//#fclose outputfile


Post a reply to this message

From: Thomas de Groot
Subject: Re: input/output file
Date: 16 Oct 2009 10:13:23
Message: <4ad87f83$1@news.povray.org>
"esterichia" <est### [at] gmailcom> schreef in bericht 
news:web.4ad872742aad556549aa3f520@news.povray.org...
>I would like to read data (float or vectors of float) from an ascii file 
>and use
> the data as coordinates for the geometry in the scene: some spheres 
> connected by
> cylinders.
>
> I tried with the following code and an input file with a sequence of 
> floats.
> The problem is that some data in the input file are not read (I checked 
> with the
> #write): sometimes every second float is read, sometimes there is no 
> regular
> pattern. Moreover, sometimes the minus sign is not read.
> (I got a similar error with vectors of floats)
>
> Am I doing something wrong or is there a bug in the I/O functions?
>
> I'm using povray-3.6.1-12 on ubuntu 9.04 but I get the same error in 
> windows
> both with 3.6.1 and 3.6.2.
>
> Thanks
> Ester
>
> #fopen inputfile "in.dat" read
> //#fopen outputfile "out.dat" write
>
>  #if (defined(inputfile))
>    #read (inputfile, y1, y2, y3)
>  #end
>
>  #while (defined(inputfile))
>    #declare x1 = y1;
>    #declare x2 = y2;
>    #declare x3 = y3;
>
>    #read (inputfile, y1,y2,y3)
>
>    sphere { <x1,x2,x3>, 0.3  pigment {color Green}}
>    #if (!(x1 = y1 & x2 = y2 & x3 = y3))
>      cylinder { <x1,x2,x3>, <y1,y2,y3>, 0.1 pigment {color Red}}
>    #end
>
> //    #write (outputfile, x1, " ", x2, " ", x3, "\n")
>  #end
>
> #fclose inputfile
> //#fclose outputfile
>

I think commas are missing in the write statement because they are needed to 
separate the written parameters in the file in order to be read correctly. 
Check that your input file has commas too between parametersAlso you can 
simplify your define as you do not need the #if statement. Just write:

#while (defined(inputfile))
  #declare x1 = y1;
  #declare x2 = y2;
  #declare x3 = y3;
  #read (inputfile, y1, y2, y3)
  ....
  ....
  #write (outputfile, x1,", ", x2,", ", x3,",","\n")
  ....
#end

Hope this helps.

Thomas


Post a reply to this message

From: clipka
Subject: Re: input/output file
Date: 16 Oct 2009 10:14:42
Message: <4ad87fd2$1@news.povray.org>
esterichia schrieb:
> 
> I tried with the following code and an input file with a sequence of floats.
> The problem is that some data in the input file are not read (I checked with the
> #write): sometimes every second float is read, sometimes there is no regular
> pattern. Moreover, sometimes the minus sign is not read.
> (I got a similar error with vectors of floats)
...
> //    #write (outputfile, x1, " ", x2, " ", x3, "\n")

See section 3.2.2.3.4 "The #write Directive" of the POV-Ray inbuilt help:

"Note: data read by the #read directive must have comma delimiters 
between values and quotes around string data but the #write directive 
does not automatically output commas or quotes."

It appears that in the absence of a separating comma, POV-Ray will 
instead "eat" the next number entirely if it is positive, OR its minus 
sign if it is negative.


Post a reply to this message

From: clipka
Subject: Re: input/output file
Date: 16 Oct 2009 10:20:21
Message: <4ad88125$1@news.povray.org>
Thomas de Groot schrieb:

> Also you can 
> simplify your define as you do not need the #if statement. Just write:
> 
> #while (defined(inputfile))
>   #declare x1 = y1;
>   #declare x2 = y2;
>   #declare x3 = y3;
>   #read (inputfile, y1, y2, y3)
>   ....
>   ....
>   #write (outputfile, x1,", ", x2,", ", x3,",","\n")
>   ....
> #end

I guess without the pre-read this will cause a parse error, as y1,y2,y3 
will be undefined at this point.


Post a reply to this message

From: Thomas de Groot
Subject: Re: input/output file
Date: 16 Oct 2009 10:34:51
Message: <4ad8848b$1@news.povray.org>
"clipka" <ano### [at] anonymousorg> schreef in bericht 
news:4ad88125$1@news.povray.org...
>
> I guess without the pre-read this will cause a parse error, as y1,y2,y3 
> will be undefined at this point.

Aaah... yes, indeed. In this case that is required. But then, why not put 
the #read as the first line in the #while loop? Then the #if statement could 
be omitted.

Thomas


Post a reply to this message

From: Alain
Subject: Re: input/output file
Date: 16 Oct 2009 15:59:22
Message: <4ad8d09a$1@news.povray.org>

> I would like to read data (float or vectors of float) from an ascii file and use
> the data as coordinates for the geometry in the scene: some spheres connected by
> cylinders.
> 
> I tried with the following code and an input file with a sequence of floats.
> The problem is that some data in the input file are not read (I checked with the
> #write): sometimes every second float is read, sometimes there is no regular
> pattern. Moreover, sometimes the minus sign is not read.
> (I got a similar error with vectors of floats)
> 
> Am I doing something wrong or is there a bug in the I/O functions?
> 
> I'm using povray-3.6.1-12 on ubuntu 9.04 but I get the same error in windows
> both with 3.6.1 and 3.6.2.
> 
> Thanks
> Ester
> 
> #fopen inputfile "in.dat" read
> //#fopen outputfile "out.dat" write
> 
>   #if (defined(inputfile))
>     #read (inputfile, y1, y2, y3)
>   #end
> 
>   #while (defined(inputfile))
>     #declare x1 = y1;
>     #declare x2 = y2;
>     #declare x3 = y3;
> 
>     #read (inputfile, y1,y2,y3)
> 
>     sphere { <x1,x2,x3>, 0.3  pigment {color Green}}
>     #if (!(x1 = y1 & x2 = y2 & x3 = y3))
>       cylinder { <x1,x2,x3>, <y1,y2,y3>, 0.1 pigment {color Red}}
>     #end
> 
> //    #write (outputfile, x1, " ", x2, " ", x3, "\n")
>   #end
> 
> #fclose inputfile
> //#fclose outputfile
> 
> 

Make sure that your file is comma separated. You don't always need the 
comma if all the values are positive, but you absolutely need them 
before any negative value.
Whenever you get a negative value preceded by a float or a vector, the 
negative value get substracted from the preceding one.

Normaly, <1 2 3><4 5 6, 7> is read correctly as a 3D and a 4D vectors,<1 
2 3>4.56 as a 3D vector and a float and 1.23 4.56 as two floats.
BUT!

17    -5 becomes 12

<12, 5, 9>    -8 becomes <4, -3, 1>

100	-5	-33 becomes 62



Alain


Post a reply to this message

From: clipka
Subject: Re: input/output file
Date: 17 Oct 2009 12:32:58
Message: <4ad9f1ba$1@news.povray.org>
Alain schrieb:

> Make sure that your file is comma separated. You don't always need the 
> comma if all the values are positive, but you absolutely need them 
> before any negative value.
> Whenever you get a negative value preceded by a float or a vector, the 
> negative value get substracted from the preceding one.

That's actually the case only when you #include the file. If you #read 
it, no arithmetics are done - but then lack of commas is problematic 
even with positive values.


Post a reply to this message

From: esterichia
Subject: Re: input/output file
Date: 18 Oct 2009 05:30:00
Message: <web.4adadf7ee89cf16bfc1bd5380@news.povray.org>
"Thomas de Groot" <tDOTdegroot@interDOTnlANOTHERDOTnet> wrote:
> I think commas are missing in the write statement because they are needed to
> separate the written parameters in the file in order to be read correctly.
> Check that your input file has commas too between parameters

Thank you, this works. It was my mistake.

> Also you can
> simplify your define as you do not need the #if statement. Just write:
>
> #while (defined(inputfile))
>   #declare x1 = y1;
>   #declare x2 = y2;
>   #declare x3 = y3;
>   #read (inputfile, y1, y2, y3)
>   ....
>   ....
>   #write (outputfile, x1,", ", x2,", ", x3,",","\n")
>   ....
> #end

> > I guess without the pre-read this will cause a parse error, as y1,y2,y3
> > will be undefined at this point.
>
> Aaah... yes, indeed. In this case that is required. But then, why not put
> the #read as the first line in the #while loop? Then the #if statement could
> be omitted.

I need two points to draw the cylinder, that is the first time I have to read 2
points and then only one for each cycle.


Post a reply to this message

From: addison merchut
Subject: Re: input/output file
Date: 5 Feb 2010 19:25:01
Message: <web.4b6cb5cce89cf16be5b492130@news.povray.org>
"esterichia" <est### [at] gmailcom> wrote:
> "Thomas de Groot" <tDOTdegroot@interDOTnlANOTHERDOTnet> wrote:
> > I think commas are missing in the write statement because they are needed to
> > separate the written parameters in the file in order to be read correctly.
> > Check that your input file has commas too between parameters
>
> Thank you, this works. It was my mistake.
>
> > Also you can
> > simplify your define as you do not need the #if statement. Just write:
> >
> > #while (defined(inputfile))
> >   #declare x1 = y1;
> >   #declare x2 = y2;
> >   #declare x3 = y3;
> >   #read (inputfile, y1, y2, y3)
> >   ....
> >   ....
> >   #write (outputfile, x1,", ", x2,", ", x3,",","\n")
> >   ....
> > #end
>
> > > I guess without the pre-read this will cause a parse error, as y1,y2,y3
> > > will be undefined at this point.
> >
> > Aaah... yes, indeed. In this case that is required. But then, why not put
> > the #read as the first line in the #while loop? Then the #if statement could
> > be omitted.
>
> I need two points to draw the cylinder, that is the first time I have to read 2
> points and then only one for each cycle.
Esterichia-

What is the range of data points you are having povray run through? Any idea how
to make it run through a couple thousand points?

-Thanks
--Addison


Post a reply to this message

From: addison merchut
Subject: Re: input/output file
Date: 5 Feb 2010 19:50:01
Message: <web.4b6cbc62e89cf16be5b492130@news.povray.org>
"addison.merchut" <add### [at] gmailcom> wrote:
> "esterichia" <est### [at] gmailcom> wrote:
> > "Thomas de Groot" <tDOTdegroot@interDOTnlANOTHERDOTnet> wrote:
> > > I think commas are missing in the write statement because they are needed to
> > > separate the written parameters in the file in order to be read correctly.
> > > Check that your input file has commas too between parameters
> >
> > Thank you, this works. It was my mistake.
> >
> > > Also you can
> > > simplify your define as you do not need the #if statement. Just write:
> > >
> > > #while (defined(inputfile))
> > >   #declare x1 = y1;
> > >   #declare x2 = y2;
> > >   #declare x3 = y3;
> > >   #read (inputfile, y1, y2, y3)
> > >   ....
> > >   ....
> > >   #write (outputfile, x1,", ", x2,", ", x3,",","\n")
> > >   ....
> > > #end
> >
> > > > I guess without the pre-read this will cause a parse error, as y1,y2,y3
> > > > will be undefined at this point.
> > >
> > > Aaah... yes, indeed. In this case that is required. But then, why not put
> > > the #read as the first line in the #while loop? Then the #if statement could
> > > be omitted.
> >
> > I need two points to draw the cylinder, that is the first time I have to read 2
> > points and then only one for each cycle.
> Esterichia-
>
> What is the range of data points you are having povray run through? Any idea how
> to make it run through a couple thousand points?
>
> -Thanks
> --Addison

Nevermind. Got it. My mistake.

-Addison


Post a reply to this message

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