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

Home » Public Forums » archive » Changing variable type
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Changing variable type [message #93226 is a reply to message #93224] Mon, 16 May 2016 05:37 Go to previous messageGo to previous message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
On Monday, May 16, 2016 at 1:19:53 PM UTC+1, Mats Löfdahl wrote:
> Den måndag 16 maj 2016 kl. 13:34:52 UTC+2 skrev Helder:
>> On Monday, May 16, 2016 at 12:31:45 PM UTC+1, Helder wrote:
>>> On Monday, May 16, 2016 at 11:43:54 AM UTC+1, Mats Löfdahl wrote:
>>>> Is there a way in IDL to change the type of an array, specifically a 16-bit integer into a 16 bit unsigned integer?
>>>>
>>>> No, I do not mean b = uint(a). This makes a new array and keeps the values. I want to change the variable type of the existing array (from 2 to 12), so the bit values are interpreted differently. Is this possible?
>>>>
>>>> /Mats
>>>
>>> Hi Mats,
>>> I think you're looking for the offset keyword in the uint function, but I'm not 100% sure (because this also makes a copy of the variable... there is no /temporary keyword)
>>>
>>> IDL> a = -1
>>> IDL> help, a
>>> A INT = -1
>>> IDL> print, uint(a,0)
>>> 65535
>>>
>>> Would this do what you want?
>>>
>>> Cheers,
>>> Helder
>>
>> Sorry, you wanted an array, so you have to do this:
>> IDL> a = indgen(20)
>> IDL> a[10:19] = -indgen(10)
>> IDL> a
>> 0 1 2 3 4 5 6 7 8 9 0 -1 -2 -3 -4 -5 -6 -7 -8 -9
>> IDL> print, uint(a,0,20)
>> 0 1 2 3 4 5 6 7 8 9 0 65535 65534 65533 65532 65531 65530 65529 65528 65527
>>
>> Does it make sense?
>>
>> Cheers,
>> Helder
>
> I'd like to avoid making new variables if possible.
>
> I guess I was thinking that IDL variables in reality were some sort of objects, and there would be methods that just change the type property. Or something like that.

Well, there's the idl_variable method convert:
a.convert(type=12)
but it also creates a new variable.

I don't see another way around unless you use some DLL trick to modify the variable internally. But maybe some IDL gurus know more about this stuff... I never ventured beyond using the offset options.

Cheers,
Helder
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: HDF-Browser
Next Topic: PDE

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

Current Time: Wed Oct 08 16:02:31 PDT 2025

Total time taken to generate the page: 0.00188 seconds