comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Constant Size Array in Class Init
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Constant Size Array in Class Init [message #76228] Mon, 23 May 2011 15:18
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Chris Williams writes:

> I just realized that all the fields of the class are private by
> default and there is no way I am going to write 50 setters and getters
> for a data storage class. I'm just going to do what I need to do in
> python.

Goodness, I wouldn't write 50 getters and setters either!!
Sounds like JAVA to me. :-)

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Constant Size Array in Class Init [message #76229 is a reply to message #76228] Mon, 23 May 2011 15:16 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Chris Williams writes:

> Hmm, now I get "Pointer expression not allowed in this context" when
> entering the initialization function.

Did you restart IDL after you changed the class definition?

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Constant Size Array in Class Init [message #76230 is a reply to message #76229] Mon, 23 May 2011 15:11 Go to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On May 23, 7:03 pm, Chris Williams <fam36boozl...@gmail.com> wrote:
> I just realized that all the fields of the class are private by
> default and there is no way I am going to write 50 setters and getters
> for a data storage class. I'm just going to do what I need to do in
> python.

Just a couple of ideas:

It does not have to be 100 functions. It can be just two (get/
setproperty), either each one with 50 arguments, or just one argument,
with uses of execute() or scope_varfetch().

But in this case maybe just putting an extra layer would be more
convenient. You can group everything into a single container (by a
pointer, a structure, a hash or a list, whichever is more convenient),
and then pass just that one container with get/setproperty.
Re: Constant Size Array in Class Init [message #76231 is a reply to message #76230] Mon, 23 May 2011 15:03 Go to previous message
Chris Williams is currently offline  Chris Williams
Messages: 4
Registered: May 2011
Junior Member
On May 23, 5:32 pm, David Fanning <n...@idlcoyote.com> wrote:
> Chris Williams writes:
>> I am creating a class that holds multidimensional data of several
>> different arrays.What I am trying to do is create a class to hold the
>> arrays, and then define the array sizes in the init function since
>> they will be different sizes.
>
>> For example, I want to do something like this
>
>> FUNCTION myclass:init, dim1, dim2, dim3
>
>> myarray = dblarr(dim1, dim2, dim3)
>
>> RETURN,1
>> END
>
>> PRO myclass__define
>
>> void = {myclass, myarray :dblarr } ;NO SIZE ON ARRAY
>
>> RETURN
>> END
>
>> However, I get a conflicting data structure error without first
>> defining the size of the array in the procedure myclass__define. Is
>> there an empty array object that allows me to define the array size at
>> initialization and not at object creation?
>
> You are going to have to define this field as a pointer
> to an array in IDL.
>
>     void = {myclass, myarray :ptr_new() } ;NO SIZE ON ARRAY
>
> Then,
>
>     myArray = Ptr_New(dblarr(dim1,dim2,dim3))
>     Help, *myArray
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.idlcoyote.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

I just realized that all the fields of the class are private by
default and there is no way I am going to write 50 setters and getters
for a data storage class. I'm just going to do what I need to do in
python.

Thanks a ton David.
Re: Constant Size Array in Class Init [message #76233 is a reply to message #76231] Mon, 23 May 2011 14:59 Go to previous message
Chris Williams is currently offline  Chris Williams
Messages: 4
Registered: May 2011
Junior Member
On May 23, 5:32 pm, David Fanning <n...@idlcoyote.com> wrote:
> Chris Williams writes:
>> I am creating a class that holds multidimensional data of several
>> different arrays.What I am trying to do is create a class to hold the
>> arrays, and then define the array sizes in the init function since
>> they will be different sizes.
>
>> For example, I want to do something like this
>
>> FUNCTION myclass:init, dim1, dim2, dim3
>
>> myarray = dblarr(dim1, dim2, dim3)
>
>> RETURN,1
>> END
>
>> PRO myclass__define
>
>> void = {myclass, myarray :dblarr } ;NO SIZE ON ARRAY
>
>> RETURN
>> END
>
>> However, I get a conflicting data structure error without first
>> defining the size of the array in the procedure myclass__define. Is
>> there an empty array object that allows me to define the array size at
>> initialization and not at object creation?
>
> You are going to have to define this field as a pointer
> to an array in IDL.
>
>     void = {myclass, myarray :ptr_new() } ;NO SIZE ON ARRAY
>
> Then,
>
>     myArray = Ptr_New(dblarr(dim1,dim2,dim3))
>     Help, *myArray
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.idlcoyote.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Hmm, now I get "Pointer expression not allowed in this context" when
entering the initialization function.
Re: Constant Size Array in Class Init [message #76237 is a reply to message #76233] Mon, 23 May 2011 14:32 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Chris Williams writes:

> I am creating a class that holds multidimensional data of several
> different arrays.What I am trying to do is create a class to hold the
> arrays, and then define the array sizes in the init function since
> they will be different sizes.
>
> For example, I want to do something like this
>
> FUNCTION myclass:init, dim1, dim2, dim3
>
> myarray = dblarr(dim1, dim2, dim3)
>
> RETURN,1
> END
>
> PRO myclass__define
>
> void = {myclass, myarray :dblarr } ;NO SIZE ON ARRAY
>
> RETURN
> END
>
> However, I get a conflicting data structure error without first
> defining the size of the array in the procedure myclass__define. Is
> there an empty array object that allows me to define the array size at
> initialization and not at object creation?

You are going to have to define this field as a pointer
to an array in IDL.

void = {myclass, myarray :ptr_new() } ;NO SIZE ON ARRAY

Then,

myArray = Ptr_New(dblarr(dim1,dim2,dim3))
Help, *myArray

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Constant Size Array in Class Init
Next Topic: Success!! Add and manipulate a visualization in standard iTool - Part II

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:22:35 PDT 2025

Total time taken to generate the page: 0.00475 seconds