POV-Ray : Newsgroups : povray.newusers : reading from a text file Server Time
1 Nov 2024 07:28:09 EDT (-0400)
  reading from a text file (Message 1 to 5 of 5)  
From: shimon a10
Subject: reading from a text file
Date: 25 Jan 2006 07:50:01
Message: <web.43d7729ee27d4f0dd402cb690@news.povray.org>
Hi, every body

1. I want to know how can i read from a text file, float numbers, in order,
   without the "defined" command.
2. When i used the exmple in the tutorial, for reading, i read the float
   numbers not in the order(seqance) that i wanted.
3. Exmple of the text file, look like that:
   -0.5 0 -0.5
    0   0  0
    0.2 0  0.2
    1   1  1
4. I want to know how can i read line's (the three commponent of the vector
   at the same time).
5. Is any other format that pov can read except *.txt?.
6. Lots of thanks.

Shimon


Post a reply to this message

From: Mike Williams
Subject: Re: reading from a text file
Date: 25 Jan 2006 08:50:55
Message: <km7hVDA5I41DFwZh@econym.demon.co.uk>
Wasn't it shimon_a10 who wrote:
>Hi, every body
>
>1. I want to know how can i read from a text file, float numbers, in order,
>   without the "defined" command.
>2. When i used the exmple in the tutorial, for reading, i read the float
>   numbers not in the order(seqance) that i wanted.
>3. Exmple of the text file, look like that:
>   -0.5 0 -0.5
>    0   0  0
>    0.2 0  0.2
>    1   1  1
>4. I want to know how can i read line's (the three commponent of the vector
>   at the same time).
>5. Is any other format that pov can read except *.txt?.
>6. Lots of thanks.

1. I can't imagine what defined() has to do with any of this.

2. POV's #read command doesn't see the file as a series of lines, it
sees it as a series of fields separated by commas. If you don't have
commas between each of your fields it will miss them. 

3. That's no good. It doesn't have any commas.

4. Only if the data file contains the fields in vector format, like this
        <-0.5,0,-0.5>,
        <0,0,0>,
        <0.2,0,0.2>,
        <1,1,1>
Note that the commas after each vector are required. The line breaks are
not required, sot you can write it like this if you prefer.
        <-0.5,0,-0.5>,<0,0,0>,<0.2,0,0.2>,<1,1,1>

POV doesn't know in advance what sort of field it is expected to try to
read. If is sees a vector it reads a vector. If it sees a number it
reads a number. If it sees a quoted string it reads a string. It doesn't
matter if the variable already contains a different type of object.

5. You can give the file any extension you like, but it has to contain
ASCII text in the specified format.

6. You're welcome
-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: shimon a10
Subject: Re: reading from a text file
Date: 25 Jan 2006 10:20:00
Message: <web.43d796cf70cad013d402cb690@news.povray.org>
Mike Williams <nos### [at] econymdemoncouk> wrote:
> Wasn't it shimon_a10 who wrote:
> >Hi, every body
> >
> >1. I want to know how can i read from a text file, float numbers, in order,
> >   without the "defined" command.
> >2. When i used the exmple in the tutorial, for reading, i read the float
> >   numbers not in the order(seqance) that i wanted.
> >3. Exmple of the text file, look like that:
> >   -0.5 0 -0.5
> >    0   0  0
> >    0.2 0  0.2
> >    1   1  1
> >4. I want to know how can i read line's (the three commponent of the vector
> >   at the same time).
> >5. Is any other format that pov can read except *.txt?.
> >6. Lots of thanks.
>
> 1. I can't imagine what defined() has to do with any of this.
>
> 2. POV's #read command doesn't see the file as a series of lines, it
> sees it as a series of fields separated by commas. If you don't have
> commas between each of your fields it will miss them.
>
> 3. That's no good. It doesn't have any commas.
>
> 4. Only if the data file contains the fields in vector format, like this
>         <-0.5,0,-0.5>,
>         <0,0,0>,
>         <0.2,0,0.2>,
>         <1,1,1>
> Note that the commas after each vector are required. The line breaks are
> not required, sot you can write it like this if you prefer.
>         <-0.5,0,-0.5>,<0,0,0>,<0.2,0,0.2>,<1,1,1>
>
> POV doesn't know in advance what sort of field it is expected to try to
> read. If is sees a vector it reads a vector. If it sees a number it
> reads a number. If it sees a quoted string it reads a string. It doesn't
> matter if the variable already contains a different type of object.
>
> 5. You can give the file any extension you like, but it has to contain
> ASCII text in the specified format.
>
> 6. You're welcome
> --
> Mike Williams
> Gentleman of Leisure

Hi to Mike Williams , and thank u!

1. How can i put commas to very long text file for separting the float
   numbers.
2. thanks again.

Shimon


Post a reply to this message

From: Chris B
Subject: Re: reading from a text file
Date: 25 Jan 2006 10:52:33
Message: <43d79ec1$1@news.povray.org>
"shimon_a10" <shi### [at] wallacoil> wrote in message 
news:web.43d796cf70cad013d402cb690@news.povray.org...
> Mike Williams <nos### [at] econymdemoncouk> wrote:
>> Wasn't it shimon_a10 who wrote:
>> >Hi, every body
>> >
>> >1. I want to know how can i read from a text file, float numbers, in 
>> >order,
>> >   without the "defined" command.
>> >2. When i used the exmple in the tutorial, for reading, i read the float
>> >   numbers not in the order(seqance) that i wanted.
>> >3. Exmple of the text file, look like that:
>> >   -0.5 0 -0.5
>> >    0   0  0
>> >    0.2 0  0.2
>> >    1   1  1
>> >4. I want to know how can i read line's (the three commponent of the 
>> >vector
>> >   at the same time).
>> >5. Is any other format that pov can read except *.txt?.
>> >6. Lots of thanks.
>>
>> 1. I can't imagine what defined() has to do with any of this.
>>
>> 2. POV's #read command doesn't see the file as a series of lines, it
>> sees it as a series of fields separated by commas. If you don't have
>> commas between each of your fields it will miss them.
>>
>> 3. That's no good. It doesn't have any commas.
>>
>> 4. Only if the data file contains the fields in vector format, like this
>>         <-0.5,0,-0.5>,
>>         <0,0,0>,
>>         <0.2,0,0.2>,
>>         <1,1,1>
>> Note that the commas after each vector are required. The line breaks are
>> not required, sot you can write it like this if you prefer.
>>         <-0.5,0,-0.5>,<0,0,0>,<0.2,0,0.2>,<1,1,1>
>>
>> POV doesn't know in advance what sort of field it is expected to try to
>> read. If is sees a vector it reads a vector. If it sees a number it
>> reads a number. If it sees a quoted string it reads a string. It doesn't
>> matter if the variable already contains a different type of object.
>>
>> 5. You can give the file any extension you like, but it has to contain
>> ASCII text in the specified format.
>>
>> 6. You're welcome
>> --
>> Mike Williams
>> Gentleman of Leisure
>
> Hi to Mike Williams , and thank u!
>
> 1. How can i put commas to very long text file for separting the float
>   numbers.
> 2. thanks again.
>
> Shimon
>

Hi Shimon,
Most text editors allow you to do that sort of thing quite quickly.

To convert your example to the format in Mike's example using the POV-Ray 
editor you could:
1. Take a copy of your data file so that, if you inadvertently mess it up, 
you can recover
2. Use Search, Replace to replace all double spaces with single spaces. 
Repeat this as many times as you need to to get all of your numbers 
seperated by only one space.
3. Use Search, Replace to replace each of those single spaces with commas.
4. Clicking the mouse button in front of the first character on the first 
line to move the cursor there. Scroll down, then hold down the Shift-key and 
the Ctrl-key and click the mouse  button in front of the first character on 
the last line. Type '<'. This inserts a left chevron in front of all of the 
lines in the file.
5. Move the cursor to the end of the first line and add as many spaces as 
you need to move it to the right far enough to be well clear of the longest 
line in the file.
6. Scroll to the bottom of the file, hold down the Shift-key and the 
Ctrl-key and press the mouse button down in line with the position you chose 
at the top of the file. Keep the button pressed while you move the mouse 
around to get a very thin blue line (showing that you have only a column 
selected).
7. Type '>,'  to inset a right chevron and a comma at the end of all of the 
selected lines.
8. Use Search and Replace to replace ', ' (a comma followed by a space) into 
'' (nothing). This removes the commas following the last digits within the 
chevrons on each line, which should by now be the only commas followed by a 
space in the whole file.
9. If it's not right, take a new copy of the file and repeat steps 2-9 
adjusting instructions to meet required results. :-)

Hope that helps,
Chris B.


Post a reply to this message

From: Alain
Subject: Re: reading from a text file
Date: 25 Jan 2006 17:56:35
Message: <43d80223$1@news.povray.org>
shimon_a10 nous apporta ses lumieres en ce 25/01/2006 10:18:
> Mike Williams <nos### [at] econymdemoncouk> wrote:
> 
>>Wasn't it shimon_a10 who wrote:
>>
>>
>>1. I can't imagine what defined() has to do with any of this.
>>
>>2. POV's #read command doesn't see the file as a series of lines, it
>>sees it as a series of fields separated by commas. If you don't have
>>commas between each of your fields it will miss them.
>>
>>3. That's no good. It doesn't have any commas.
>>
>>4. Only if the data file contains the fields in vector format, like this
>>        <-0.5,0,-0.5>,
>>        <0,0,0>,
>>        <0.2,0,0.2>,
>>        <1,1,1>
>>Note that the commas after each vector are required. The line breaks are
>>not required, sot you can write it like this if you prefer.
>>        <-0.5,0,-0.5>,<0,0,0>,<0.2,0,0.2>,<1,1,1>
>>
>>POV doesn't know in advance what sort of field it is expected to try to
>>read. If is sees a vector it reads a vector. If it sees a number it
>>reads a number. If it sees a quoted string it reads a string. It doesn't
>>matter if the variable already contains a different type of object.
>>
>>5. You can give the file any extension you like, but it has to contain
>>ASCII text in the specified format.
>>
>>6. You're welcome
>>--
>>Mike Williams
>>Gentleman of Leisure
> 
> 
> Hi to Mike Williams , and thank u!
> 
> 1. How can i put commas to very long text file for separting the float
>    numbers.
> 2. thanks again.
> 
> Shimon
> 
> 
> 
> 
Search & replace in a text editor, NOT a word processor. Launch a search for <space>
and replace 
with a comma.
You may end up with strings of commas, if you have formating spaces, in that case, do
a new search & 
replace for ",," to "," and repeate until you no longer have strings of commas.

-- 
Alain
-------------------------------------------------
Agnostic: Shit might have happened; then again, maybe not.


Post a reply to this message

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