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

Home » Public Forums » archive » How to get _overloadSize to return N_Dimensions=0?
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
How to get _overloadSize to return N_Dimensions=0? [message #88661] Tue, 27 May 2014 15:40 Go to next message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
I was wondering how it is possible to get the _overloadSize function to return N_DIMENSION=0 when there are no dimensions. Below is an example. The docs seems like it reports N_Elements(Size(input, /DIMENSIONS), which is not correct for an undefined variable...

IDL> print, size(!Null, /N_DIMENSIONS)
0
IDL> .run test_olsize__define
Dimensions: [0]
N_Elements: 0
N_Dimensions: 1


;-----------------------------------------------
function test_olSize::_OverloadSize
return, size(*self.value, /N_DIMENSIONS)
end

function test_olSize::Init
compile_opt strictarr
self.value = Ptr_New(/ALLOCATE_HEAP)
return, 1
end

pro test_olSize__define
class = {test_olSize, $
inherits IDL_Object, $
value: ptr_new()}
end


;Main level test program
myObj = Obj_New('Test_olSize')
print, 'Dimensions: ', '[' + strjoin(strtrim(size(myObj, /DIMENSIONS), 2), ', ') + ']'
print, 'N_Elements: ', strtrim(size(myObj, /N_ELEMENTS), 2)
print, 'N_Dimensions: ', strtrim(size(myObj, /N_DIMENSIONS), 2)
obj_destroy, myObj

end
Re: How to get _overloadSize to return N_Dimensions=0? [message #88662 is a reply to message #88661] Tue, 27 May 2014 20:14 Go to previous messageGo to next message
chris_torrence@NOSPAM is currently offline  chris_torrence@NOSPAM
Messages: 528
Registered: March 2007
Senior Member
Looks like a bug to me. One side note - you want to return SIZE with the DIMENSIONS keyword, not N_DIMENSIONS:

function test_olSize::_OverloadSize
return, size(*self.value, /DIMENSIONS)
end

Regardless, it still doesn't work properly... I'll fix it for IDL 8.3.1.

-Chris
ExelisVIS
Re: How to get _overloadSize to return N_Dimensions=0? [message #94355 is a reply to message #88662] Tue, 18 April 2017 06:56 Go to previous messageGo to next message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
The problem with undefined variables was fixed, but there is another bug related to scalar values. I assume N_Elements is determined as Product(Size(input, /DIMENSIONS)). However, a scalar value has a dimension size of 0, so the result of 0 elements.


function test_olSize::_OverloadSize
return, size(*self.value, /DIMENSIONS)
end

function test_olSize::Init, value
compile_opt strictarr
self.value = Ptr_New(value, /NO_COPY)
return, 1
end

pro test_olSize__define
class = {test_olSize, $
inherits IDL_Object, $
value: ptr_new()}
end


IDL> myObj = Obj_New('Test_olSize', 1)
IDL> Print, N_Elements(myObj)
0
Re: How to get _overloadSize to return N_Dimensions=0? [message #94360 is a reply to message #94355] Wed, 19 April 2017 14:19 Go to previous messageGo to next message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 4/18/17 7:56 AM, Matthew Argall wrote:
> The problem with undefined variables was fixed, but there is another
> bug related to scalar values. I assume N_Elements is determined as
> Product(Size(input, /DIMENSIONS)). However, a scalar value has a
> dimension size of 0, so the result of 0 elements.
>
>
> function test_olSize::_OverloadSize
> return, size(*self.value, /DIMENSIONS)
> end
>
> function test_olSize::Init, value
> compile_opt strictarr
> self.value = Ptr_New(value, /NO_COPY)
> return, 1
> end
>
> pro test_olSize__define
> class = {test_olSize, $
> inherits IDL_Object, $
> value: ptr_new()}
> end
>
>
> IDL> myObj = Obj_New('Test_olSize', 1)
> IDL> Print, N_Elements(myObj)
> 0
>

I would use something like the following for your _overloadSize method:

function test_olsize::_overloadSize
return, size(*self.value, /n_dimensions) eq 0 $
? 1L $
: size(*self.value, /dimensions)
end

IDL> myObj = Obj_New('Test_olSize', 1)
IDL> Print, N_Elements(myObj)
1

Mike

--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Re: How to get _overloadSize to return N_Dimensions=0? [message #94368 is a reply to message #94360] Fri, 21 April 2017 09:48 Go to previous message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
The fix has to be a bit more complicated. Using your suggestion,

IDL> myobj = Test_olSize(!Null)
IDL> Print, N_Elements(myobj)
1


function test_olSize::_OverloadSize
return, n_elements(*self.value) eq 0 ? 0L : $
size(*self.value, /n_dimensions) eq 0 ? 1L : $
size(*self.value, /dimensions)
end


IDL> myobj = Test_olSize(!Null)
IDL> Print, N_Elements(myobj)
0


Consequently, this fixes the original problem as well.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: constant time cadence
Next Topic: alignment of y-axis tick labels

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

Current Time: Wed Oct 08 15:09:56 PDT 2025

Total time taken to generate the page: 0.00450 seconds