POV-Ray : Newsgroups : povray.general : er...huh? Server Time
5 Aug 2024 02:17:36 EDT (-0400)
  er...huh? (Message 1 to 5 of 5)  
From: Timothy R  Cook
Subject: er...huh?
Date: 15 Dec 2002 00:29:00
Message: <3dfc131c@news.povray.org>
ok, the following code:

#fopen window "c:\program files\moray for windows beta\mdl\balcony.csv" read
#read(window,tile_amount)
#declare tilearray=array[tile_amount][21]
#declare current_tile=0;
#while(defined(window))
   #read(window,tilenumber,rrr,ggg,bbb,points)
   #declare tilearray[current_tile][0]=tilenumber;
   #declare tilearray[current_tile][1]=rrr;
   #declare tilearray[current_tile][2]=ggg;
   #declare tilearray[current_tile][3]=bbb;
   #declare tilearray[current_tile][4]=points;
   #declare n=0;
   #while(n<points)
     #read(window,pointx,pointy)
     #declare tilearray[current_tile][5+n]=pointx;
     #declare tilearray[current_tile][6+n]=pointy;
     #declare n=n+2;
   #end
   #declare current_tile=current_tile+1;
#end
#fclose window

with file "c:\program files\moray for windows beta\mdl\balcony.csv":
20
"Tile0001" 64 61 78 8 0 4 -29 0 0.8 -28.7 0.9 -28.1 0.8 -27 9 0.0 -28.0 
0.0 -28.7 0.2 -29.0 0.4 -29.0
"Tile0002",55,52,66,5,1.7,-29.0,1.9,-28.7,1.2,-28.3,1.0,-29.0,1.7,-29.0
"Tile0003",70,68,84,6,2.5,-28.2,2.4,-27.9,1.9,-27.9,1.5,-28.2,2.2,-28.5,2.5,-28.2
"Tile0004",56,53,67,7,3.4,-29.0,3.6,-28.7,3.4,-28.3,2.8,-28.3,2.5,-28.6,2.8,-29.0,3.4,-29.0
"Tile0005",94,92,112,5,1.3,-28.1,1.6,-27.7,1.0,-27.5,1.0,-27.9,1.3,-28.1
"Tile0006",117,107,129,5,0.8,-27.7,0.8,-27.4,0.3,-27.2,0.0,-27.8,0.8,-27.7
"Tile0007",139,126,150,5,2.3,-27.6,2.3,-26.9,1.7,-27.1,1.5,-27.5,2.3,-27.6
"Tile0008",164,138,172,7,3.5,-27.0,3.2,-26.4,2.8,-26.3,2.5,-26.8,2.6,-27.3,3.2,-27.4,3.5,-27.0
"Tile0009",112,97,118,6,3.5,-27.9,3.3,-27.7,2.6,-27.6,2.6,-27.8,2.7,-27.9,3.5,-27.9
"Tile0010",140,122,146,6,4.1,-27.5,4.2,-27.1,3.9,-27.1,3.5,-27.6,3.7,-27.7,4.1,-27.5
"Tile0011",54,48,61,5,5.0,-29.0,4.8,-28.4,4.3,-28.7,4.4,-29.0,5.0,-29.0
"Tile0012",77,68,85,6,4.3,-28.5,4.5,-28.3,3.9,-27.8,3.6,-28.1,3.8,-28.5,4.3,-28.5
"Tile0013",102,86,109,5,4.9,-28.0,4.9,-27.7,4.2,-27.7,4.7,-28.2,4.9,-28.0
"Tile0014",77,64,83,6,6.0,-28.5,5.6,-28.0,5.1,-27.8,5.0,-28.2,5.2,-28.5,6.0,-28.5
"Tile0015",91,75,97,6,6.9,-28.4,7.1,-27.9,6.6,-27.5,5.8,-27.9,6.3,-28.5,6.9,-28.4
"Tile0016",73,62,85,6,7.6,-28.6,7.9,-28.2,7.3,-28.0,7.1,-28.5,7.3,-28.6,7.6,-28.6
"Tile0017",56,47,64,5,8.7,-29.0,8.3,-28.3,7.8,-28.8,7.9,-29.0,8.7,-29.0
"Tile0018",71,55,79,7,9.1,-28.7,9.6,-28.2,9.2,-27.9,8.7,-27.9,8.5,-28.1,8.9,-28.8,9.1,-28.7
"Tile0019",53,38,55,5,9.2,-29.0,10.0,-29.0,10.0,-28.4,9.8,-28.3,9.2,-29.0
"Tile0020",82,62,91,4,10.0,-28.2,10.0,-27.5,9.7,-27.8,10.0,-28.2

gives an error on line 3 of the CSV with a parse error "Expected 'float, 
vector, or string literal', ,  found instead"...but the POV docs say the 
data file needs be delimited by commas.  so why does POV like spaces as 
delimiters but not commas?  How do I keep the comma-delimited file 
format and still use it in POV?

Apart from that, how crappy is my first attempt at writing POV code?
-- 
Tim Cook
http://empyrean.scifi-fantasy.com

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GFA dpu- s: a?-- C++(++++) U P? L E--- W++(+++)>$
N++ o? K- w(+) O? M-(--) V? PS+(+++) PE(--) Y(--)
PGP-(--) t* 5++>+++++ X+ R* tv+ b++(+++) DI
D++(---) G(++) e*>++ h+ !r--- !y--
------END GEEK CODE BLOCK------


Post a reply to this message

From: Mike Williams
Subject: Re: er...huh?
Date: 15 Dec 2002 01:52:09
Message: <lJpOdDARZC$9Ewx9@econym.demon.co.uk>
Wasn't it Timothy R. Cook who wrote:
>gives an error on line 3 of the CSV with a parse error "Expected 'float, 
>vector, or string literal', ,  found instead"...but the POV docs say the 
>data file needs be delimited by commas.  so why does POV like spaces as 
>delimiters but not commas?  How do I keep the comma-delimited file 
>format and still use it in POV?

It says that the data file needs to be delimited by commas. It doesn't
explain the details of the unpredictable results that you will get if 
you try to use space and end-of-line as delimiters.

In this particular case, the input is 
20
"Tile0001" 64 61 78 8 0 4 -29 0 0.8 -28.7 0.9 -28.1 0.8 -27 9 0.0 -28.0 0.0 -28.7 0.2
-29.0 0.4 -29.0
"Tile0002",55,52,66,5,1.7,-29.0,1.9,-28.7,1.2,-28.3,1.0,-29.0,1.7,-29.0

but the POV command  #read(window,tilenumber,rrr,ggg,bbb,points) returns 
the following on the first pass:-

tilenumber = 64
rrr = 78
ggg = 0
bbb = -29
points = 0.8

This is not what anyone wants and you probably should not depend on POV 
behaving in a predictable manner when supplied with data that is not 
separated by commas.

If you want a series of characters that contain spaces and/or end-of-
line characters to be considered as a single field, then you should 
enclose it in quotes and it will be read as a string (you can't get it 
to read it as a number because numbers can't contain such characters).

Your code needs to look more like this:-

#fopen window "balcony.csv" read
#read(window,tile_amount)
#declare tilearray=array[tile_amount][21]
#declare current_tile=0;
#while(defined(window))
   #read(window,tilenumber,rrr,ggg,bbb,points)
   
   //#declare tilearray[current_tile][0]=tilenumber;  Note 1
   #declare tilearray[current_tile][1]=rrr;
   #declare tilearray[current_tile][2]=ggg;
   #declare tilearray[current_tile][3]=bbb;
   #declare tilearray[current_tile][4]=points;
   #declare n=0;
   #while(n<points)
     #read(window,pointx,pointy)
     #declare tilearray[current_tile][5+n]=pointx;
     #declare tilearray[current_tile][6+n]=pointy;
     #declare n=n+1;                               // Note 2
   #end
   
   #declare current_tile=current_tile+1;
#end
#fclose window



Note 1: You can't do that with a string.
Note 2: You had n=n+2, which only reads half the points.


Your data should use only commas as delimiters, like this. 
Note, in particular, that commas are needed at the ends of lines.

20,
"Tile0001",64,61,78,8,0,4,-29,0,0.8,-28.7,0.9,-28.1,0.8,-27,9,0.0,-28.0,
0.0,-28.7,0.2,
"Tile0002",55,52,66,5,1.7,-29.0,1.9,-28.7,1.2,-28.3,1.0,-29.0,1.7,-29.0,
"Tile0003",70,68,84,6,2.5,-28.2,2.4,-27.9,1.9,-27.9,1.5,-28.2,2.2,-28.5,2.5,-28.2,
"Tile0004",56,53,67,7,3.4,-29.0,3.6,-28.7,3.4,-28.3,2.8,-28.3,2.5,-28.6,2.8,-29.0,3.4,-29.0,
"Tile0005",94,92,112,5,1.3,-28.1,1.6,-27.7,1.0,-27.5,1.0,-27.9,1.3,-28.1,
"Tile0006",117,107,129,5,0.8,-27.7,0.8,-27.4,0.3,-27.2,0.0,-27.8,0.8,-27.7,
"Tile0007",139,126,150,5,2.3,-27.6,2.3,-26.9,1.7,-27.1,1.5,-27.5,2.3,-27.6,
"Tile0008",164,138,172,7,3.5,-27.0,3.2,-26.4,2.8,-26.3,2.5,-26.8,2.6,-27.3,3.2,-27.4,3.5,-27.0,
"Tile0009",112,97,118,6,3.5,-27.9,3.3,-27.7,2.6,-27.6,2.6,-27.8,2.7,-27.9,3.5,-27.9,
"Tile0010",140,122,146,6,4.1,-27.5,4.2,-27.1,3.9,-27.1,3.5,-27.6,3.7,-27.7,4.1,-27.5,
"Tile0011",54,48,61,5,5.0,-29.0,4.8,-28.4,4.3,-28.7,4.4,-29.0,5.0,-29.0,
"Tile0012",77,68,85,6,4.3,-28.5,4.5,-28.3,3.9,-27.8,3.6,-28.1,3.8,-28.5,4.3,-28.5,
"Tile0013",102,86,109,5,4.9,-28.0,4.9,-27.7,4.2,-27.7,4.7,-28.2,4.9,-28.0,
"Tile0014",77,64,83,6,6.0,-28.5,5.6,-28.0,5.1,-27.8,5.0,-28.2,5.2,-28.5,6.0,-28.5,
"Tile0015",91,75,97,6,6.9,-28.4,7.1,-27.9,6.6,-27.5,5.8,-27.9,6.3,-28.5,6.9,-28.4,
"Tile0016",73,62,85,6,7.6,-28.6,7.9,-28.2,7.3,-28.0,7.1,-28.5,7.3,-28.6,7.6,-28.6,
"Tile0017",56,47,64,5,8.7,-29.0,8.3,-28.3,7.8,-28.8,7.9,-29.0,8.7,-29.0,
"Tile0018",71,55,79,7,9.1,-28.7,9.6,-28.2,9.2,-27.9,8.7,-27.9,8.5,-28.1,8.9,-28.8,9.1,-28.7,
"Tile0019",53,38,55,5,9.2,-29.0,10.0,-29.0,10.0,-28.4,9.8,-28.3,9.2,-29.0,
"Tile0020",82,62,91,4,10.0,-28.2,10.0,-27.5,9.7,-27.8,10.0,-28.2


-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Timothy R  Cook
Subject: Re: er...huh?
Date: 15 Dec 2002 03:24:16
Message: <3dfc3c30@news.povray.org>
Mike Williams wrote:
> If you want a series of characters that contain spaces and/or end-of-
> line characters to be considered as a single field, then you should 
> enclose it in quotes and it will be read as a string (you can't get it 
> to read it as a number because numbers can't contain such characters).

the problem was the lack of comma at end of line; see end note

> Note 1: You can't do that with a string.

k

> Note 2: You had n=n+2, which only reads half the points.

note the pointx and pointy being 5+n and 6+n, meaning if i
only increase n by 1 i'd get duplicate numbers

> Your data should use only commas as delimiters, like this. 
> Note, in particular, that commas are needed at the ends of lines.

hmm ok that was the primary cause of the problem

pushing onwards...

-- 
Tim Cook
http://empyrean.scifi-fantasy.com

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GFA dpu- s: a?-- C++(++++) U P? L E--- W++(+++)>$
N++ o? K- w(+) O? M-(--) V? PS+(+++) PE(--) Y(--)
PGP-(--) t* 5++>+++++ X+ R* tv+ b++(+++) DI
D++(---) G(++) e*>++ h+ !r--- !y--
------END GEEK CODE BLOCK------


Post a reply to this message

From: Mike Williams
Subject: Re: er...huh?
Date: 15 Dec 2002 14:57:30
Message: <HcFWYEAg6H$9EwFo@econym.demon.co.uk>
Wasn't it Timothy R. Cook who wrote:
>> Note 2: You had n=n+2, which only reads half the points.
>
>note the pointx and pointy being 5+n and 6+n, meaning if i
>only increase n by 1 i'd get duplicate numbers

OK, but if you use n+2 you need to say

   #while (n < points * 2)

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Timothy R  Cook
Subject: Re: er...huh?
Date: 16 Dec 2002 06:12:23
Message: <3dfdb517$1@news.povray.org>
Mike Williams wrote:
> OK, but if you use n+2 you need to say
>    #while (n < points * 2)

Yep.  Figured that out.  Was wondering why it kept giving array out of
bounds errors...:P

-- 
Tim Cook
http://empyrean.scifi-fantasy.com

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GFA dpu- s: a?-- C++(++++) U P? L E--- W++(+++)>$
N++ o? K- w(+) O? M-(--) V? PS+(+++) PE(--) Y(--)
PGP-(--) t* 5++>+++++ X+ R* tv+ b++(+++) DI
D++(---) G(++) e*>++ h+ !r--- !y--
------END GEEK CODE BLOCK------


Post a reply to this message

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