Changing variable type [message #93218] |
Mon, 16 May 2016 03:43  |
Mats Löfdahl
Messages: 263 Registered: January 2012
|
Senior Member |
|
|
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
|
|
|
Re: Changing variable type [message #93220 is a reply to message #93218] |
Mon, 16 May 2016 04:31   |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
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
|
|
|
Re: Changing variable type [message #93221 is a reply to message #93220] |
Mon, 16 May 2016 04:34   |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
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
|
|
|
Re: Changing variable type [message #93224 is a reply to message #93221] |
Mon, 16 May 2016 05:19   |
Mats Löfdahl
Messages: 263 Registered: January 2012
|
Senior Member |
|
|
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.
|
|
|
Re: Changing variable type [message #93226 is a reply to message #93224] |
Mon, 16 May 2016 05:37   |
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
|
|
|
Re: Changing variable type [message #93227 is a reply to message #93226] |
Mon, 16 May 2016 05:51   |
Mats Löfdahl
Messages: 263 Registered: January 2012
|
Senior Member |
|
|
Den måndag 16 maj 2016 kl. 14:37:24 UTC+2 skrev Helder:
> 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
Oh, that looks almost like what I envisioned! Thanks! Where can I read about these methods? I tried searching for "variable methods" in www.harrisgeospatial.com/docs but the hits don't look like they would lead to a list of such methods.
Anyway, I believe what would be needed is a procedure form of that method. So one could do
a.convert, type=12
(I tried it, doesn't work in IDL 8.5.1...)
|
|
|
|
Re: Changing variable type [message #93229 is a reply to message #93227] |
Mon, 16 May 2016 06:12   |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Monday, May 16, 2016 at 1:51:18 PM UTC+1, Mats Löfdahl wrote:
> Den måndag 16 maj 2016 kl. 14:37:24 UTC+2 skrev Helder:
>> 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
>
> Oh, that looks almost like what I envisioned! Thanks! Where can I read about these methods? I tried searching for "variable methods" in www.harrisgeospatial.com/docs but the hits don't look like they would lead to a list of such methods.
>
> Anyway, I believe what would be needed is a procedure form of that method. So one could do
>
> a.convert, type=12
>
> (I tried it, doesn't work in IDL 8.5.1...)
Hi,
I obviously tried the convert method as a procedure call, but didn't work :-)
Cheers,
Helder
|
|
|
|
|
Re: Changing variable type [message #93277 is a reply to message #93233] |
Sat, 28 May 2016 19:03   |
andrewcool777
Messages: 27 Registered: November 2012
|
Junior Member |
|
|
On Tuesday, 17 May 2016 01:49:20 UTC+9:30, Mats Löfdahl wrote:
> Den måndag 16 maj 2016 kl. 17:36:18 UTC+2 skrev alx:
>> Le lundi 16 mai 2016 12:43:54 UTC+2, Mats Löfdahl a écrit :
>>> 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
>>
>> Would not a = uint(a,0,Size(a, /DIM)) do what you want ("the bit values are interpreted differently") ?
>> alx.
>
> Right, I was confused there. But the main thing was not having to create a new variable.
IDL> b=2
IDL> a=temporary(b)
IDL> help,a
A INT = 2
IDL> help,b
B UNDEFINED = <Undefined>
Andrew
a=temporary(b)
|
|
|
Re: Changing variable type [message #93851 is a reply to message #93218] |
Sun, 06 November 2016 00:40   |
876.sabri
Messages: 2 Registered: November 2016
|
Junior Member |
|
|
On Monday, May 16, 2016 at 3:13:54 PM UTC+4:30, 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
I want to make a ps and plot with data.dbl format dataes from PLUTO code
I typed
set_plot,'x'
filename='fig1.png'
display,x1=x1,x2=x2,vx2
write_png,filename,tvrd()
pload
pload,0,/silent
loadct,5,/silent
END
run this and I have a png without any pictures
error: Display: image is not valid
|
|
|
Re: Changing variable type [message #93852 is a reply to message #93851] |
Mon, 07 November 2016 00:01  |
876.sabri
Messages: 2 Registered: November 2016
|
Junior Member |
|
|
On Sunday, November 6, 2016 at 11:10:34 AM UTC+3:30, 876....@gmail.com wrote:
> On Monday, May 16, 2016 at 3:13:54 PM UTC+4:30, 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
> I want to make a ps and plot with data.dbl format dataes from PLUTO code
> I typed
> set_plot,'x'
> filename='fig1.png'
> display,x1=x1,x2=x2,vx2
> write_png,filename,tvrd()
> pload
> pload,0,/silent
> loadct,5,/silent
> END
> run this and I have a png without any pictures
> error: Display: image is not valid
|
|
|