POV-Ray : Newsgroups : povray.general : dynamic memory possible? Server Time
31 Jul 2024 14:24:40 EDT (-0400)
  dynamic memory possible? (Message 11 to 16 of 16)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Gunnar
Subject: Re: dynamic memory possible?
Date: 5 Jun 2007 03:30:01
Message: <web.466510b8752edf44678ea4f80@news.povray.org>
Okay, thanks for all the ideas. Since it is not necessary to know the length
a second time I think I'll leave it as it is. And rendering (when finished)
will take a lot more time than counting the entries in the txt file, so
it's probably not worth it. I just wanted to do this as nifty as I could...


Post a reply to this message

From: Penelope20k
Subject: Re: dynamic memory possible?
Date: 5 Jun 2007 04:00:45
Message: <4665182d$1@news.povray.org>
ill will do like this
I read the data and create an include file containing all My_data[index] =
value;

then when all the txt file is read, i will declare the size of array and
include the .inc file

(please correct typo)


#declare  convert_file=on;  // switch here if you dont need to convert each
time


#if(convert_file)
    #fopen My_file_ACR "12440_ACR.txt" read
    #fopen My_data_ACR "My_Data_ACR.inc"

    #declare index=0;
    #while(defined(My_file_ACR))
        #read (My_file_ACR, a,b,c)
        #declare vector=<a,b,c>;
        #write (My_Data_ACR,"#declare my_data[",index,"]=",vector,";\n")
        #declare index=index+1;
    #end

// close files here


#end // end of if statement



    #declare my_data=array[index]    // the one resulting of the loop
    // then
    #include my_data_acr.inc




news:web.4663e8a8e799405a678ea4f80@news.povray.org...
> Hello there,
> I hope you understand my question, it's directly translated from German...
> ;)
>
> I have a file with some coordinates I want to store in an array. Since I
> don't know how to store in an array that was not defined before I do this:
> --------------------------------------
> #fopen fsbsp "124440_ACR.txt" read
> #declare fs_count = 0;
> #while(defined(fsbsp))
>   #read (fsbsp,utm_x,utm_y,utm_z)
>   #declare fs_count = fs_count+1;
> #end
> #debug concat("fs_count     ", str(fs_count, 0,0),"n")
>
> #declare a_pos = array[fs_count];
>
> #fopen a_pos_f "124440_ACR.txt" read
> #declare fs_count2 = 0;
> #while(defined(a_pos_f))
>   #read (a_pos_f,utm_x,utm_y,utm_z)
>   #declare a_pos[fs_count2] = <utm_x,utm_y,utm_z>;
>   #declare fs_count2 = fs_count2 + 1;
> #end
> --------------------------------------
> Here's what this does:
> - opens the file and "counts" the rows
> - closes the file (#while(defined(...)))
> - defines the array
> - opens the file again
> - reads and stores values
> - closes the file again
>
> Is there any possibility to do this without opening and reading the file
> twice? I know Java can do dynamic memory (if that's what it is called),
but
> POV?
>
> Thanks in advance
> Gunnar
>
>
>


Post a reply to this message

From: Gunnar
Subject: Re: dynamic memory possible?
Date: 5 Jun 2007 05:30:02
Message: <web.46652c79752edf44678ea4f80@news.povray.org>
"Penelope20k" <pen### [at] caramailfr> wrote:
> ill will do like this
> I read the data and create an include file containing all My_data[index] =
> value;
>
> then when all the txt file is read, i will declare the size of array and
> include the .inc file
>
> (please correct typo)
>
>
> #declare  convert_file=on;  // switch here if you dont need to convert each
> time
>
>
> #if(convert_file)
>     #fopen My_file_ACR "12440_ACR.txt" read
>     #fopen My_data_ACR "My_Data_ACR.inc"
>
>     #declare index=0;
>     #while(defined(My_file_ACR))
>         #read (My_file_ACR, a,b,c)
>         #declare vector=<a,b,c>;
>         #write (My_Data_ACR,"#declare my_data[",index,"]=",vector,";n")
>         #declare index=index+1;
>     #end
>
> // close files here
>
>
> #end // end of if statement
>
>
>
>     #declare my_data=array[index]    // the one resulting of the loop
>     // then
>     #include my_data_acr.inc
>
>
>

I will have a try, thanks for the suggestion! Seems to be a nice idea.


Post a reply to this message

From: Gunnar
Subject: Re: dynamic memory possible?
Date: 5 Jun 2007 06:45:02
Message: <web.46653e94752edf44678ea4f80@news.povray.org>
"Gunnar" <nomail@nomail> wrote:
> "Penelope20k" <pen### [at] caramailfr> wrote:
> > ill will do like this
> > I read the data and create an include file containing all My_data[index] =
> > value;
> >
> > then when all the txt file is read, i will declare the size of array and
> > include the .inc file
> >
> > (please correct typo)
> >
> >
> > #declare  convert_file=on;  // switch here if you dont need to convert each
> > time
> >
> >
> > #if(convert_file)
> >     #fopen My_file_ACR "12440_ACR.txt" read
> >     #fopen My_data_ACR "My_Data_ACR.inc"
> >
> >     #declare index=0;
> >     #while(defined(My_file_ACR))
> >         #read (My_file_ACR, a,b,c)
> >         #declare vector=<a,b,c>;
> >         #write (My_Data_ACR,"#declare my_data[",index,"]=",vector,";n")
> >         #declare index=index+1;
> >     #end
> >
> > // close files here
> >
> >
> > #end // end of if statement
> >
> >
> >
> >     #declare my_data=array[index]    // the one resulting of the loop
> >     // then
> >     #include my_data_acr.inc
> >
> >
> >
>
> I will have a try, thanks for the suggestion! Seems to be a nice idea.


Works great after adding a semicolon here and a "write" there. Thanks a
lot!!!


Post a reply to this message

From: Warp
Subject: Re: dynamic memory possible?
Date: 5 Jun 2007 08:59:15
Message: <46655e22@news.povray.org>
Penelope20k <pen### [at] caramailfr> wrote:
> ill will do like this
> I read the data and create an include file containing all My_data[index] =
> value;

  Wouldn't it be more efficient if the script wrote this in the file:

#declare My_data[<the amount of data>] =
{ the values here };

instead of a huge bunch of assignments?

-- 
                                                          - Warp


Post a reply to this message

From: KalleK
Subject: Re: dynamic memory possible?
Date: 6 Jun 2007 16:22:59
Message: <466717a3$1@news.povray.org>
Warp wrote:
> 
>   Wouldn't it be more efficient if the script wrote this in the file:
> 
> #declare My_data[<the amount of data>] =
> { the values here };
> 
> instead of a huge bunch of assignments?
> 
...but you don't know <the amount of data> beforehand...
But you could write the data in a file the way you proposed (i.e. just 
comma-separated-values with curly brackets), counting the amount, and 
then include them in an initializerstatement:


#declare My_data[<the amount of data>] = #include 
"my_prepared_array_initalizerfile"

cukk


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

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