POV-Ray : Newsgroups : povray.general : comma separated value file for data input : Re: comma separated value file for data input Server Time
8 May 2024 10:00:17 EDT (-0400)
  Re: comma separated value file for data input  
From: Charles C
Date: 10 Feb 2007 18:05:00
Message: <web.45ce4e5cd81812bfe94cc5130@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
> Charles C <nomail@nomail> wrote:
> > In my original reply I went with the assumption that knowing the amount of
> > data he'd want to display was something he could do manually.  But the docs
> > for the "#read" keyword reveal kindof a nifty way to do it.  Just add a(n
> > initialized) counter where the "..." is below, and then re-open the file
> > and count/read to that value.
>
>   The problem is not reading the data until it ends. The problem is
> how to create an array which can be used to store those values.

I thought I answered that.... Here's an automatically created exact-fit
array for 1D (pending mistakes as always).  Hopefully if more than 1D is
needed, the data would be cleanly & predictably divisable quantities of
CSV's, but if not, I guess it's up to Eric to know how the CSV's are
formatted and what assumptions can be made.

#local LengthOfList = 0;
#fopen MyFile "mydata.txt" read
#while (defined(MyFile))
  #read (MyFile,Var1,Var2,Var3)
  #local LengthOfList = LengthOfList + 1;
#end
//The file is now closed and undefined but we know how long it is.

#declare MyArray = array[LengthOfList];

#fopen MyFile "mydata.txt" read
#local Ctr = 0;
#while (Ctr < LengthOfList)
  #read (MyFile, MyArray[Ctr])
  #local Ctr = Ctr + 1;
#end

Charles


Post a reply to this message

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