Re: help with reading unsigned 16-bit integers [message #57451] |
Sun, 09 December 2007 12:57 |
teich
Messages: 33 Registered: May 2007
|
Member |
|
|
On Dec 9, 3:46 pm, David Fanning <n...@dfanning.com> wrote:
> te...@atmsci.msrc.sunysb.edu writes:
>> Still not sure what's going on.
>
>> If I pick a value:
>
>>> myval= FEATURE_CLASSIFICATION_FLAGS(10,20)
>>> print,binary(fix(myval))
>> 0 1 0 0 0 0 0 0 0 0 0 1 1 1 0 1
>
>> Then is it safe to say that bits 1 to 3 represent 1*2^0 + 0*2^1 +
>> 1*2^2 = 3. So then I know it's not cloud since cloud is '2'? Bits
>> 1-3 can take on any values '0' to '7', '2' being cloud. Documentation
>> also says that bits 4 through 5 take on values '0' to '3'. So in the
>> above, I would do 1*2^0 + 1*2^1 = 3? Bits 6 to 7 can also take on
>> values from '0' to '3', ... bits 14 to 16 can take on values from '0'
>> to '5' so in the above, bits 14 to 16 give a value of 2?
>
>> For bits 14 to 16, if I do
>
>> print,ishft((fix(myval)),-13) I also get a value of 2 so I think this
>> is what your saying to do here?
>
> Ok, you have a value:
>
> IDL> val = 16413
> IDL> Print, Binary(val)
> 0 1 0 0 0 0 0 0 0 0 0 1 1 1 0 1
>
> You want to know the value of the first three bits:
>
> IDL> Print, val AND (2L^3-1)
> 5
>
> You want to know the value of bits 4 and 5:
>
> IDL> Print, ISHFT(val AND (2L^3 + 2L^4), -3)
> 3
>
> You want to know the value of bits 14-16:
>
> IDL> Print, ISHFT(val AND (2L^13 + 2L^14 + 2L^15), -13)
> 2
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")- Hide quoted text -
>
> - Show quoted text -
Ah! Starting to make sense! Thanks,
Howard
|
|
|
Re: help with reading unsigned 16-bit integers [message #57452 is a reply to message #57451] |
Sun, 09 December 2007 12:46  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
teich@atmsci.msrc.sunysb.edu writes:
> Still not sure what's going on.
>
> If I pick a value:
>
>> myval= FEATURE_CLASSIFICATION_FLAGS(10,20)
>> print,binary(fix(myval))
> 0 1 0 0 0 0 0 0 0 0 0 1 1 1 0 1
>
> Then is it safe to say that bits 1 to 3 represent 1*2^0 + 0*2^1 +
> 1*2^2 = 3. So then I know it's not cloud since cloud is '2'? Bits
> 1-3 can take on any values '0' to '7', '2' being cloud. Documentation
> also says that bits 4 through 5 take on values '0' to '3'. So in the
> above, I would do 1*2^0 + 1*2^1 = 3? Bits 6 to 7 can also take on
> values from '0' to '3', ... bits 14 to 16 can take on values from '0'
> to '5' so in the above, bits 14 to 16 give a value of 2?
>
> For bits 14 to 16, if I do
>
> print,ishft((fix(myval)),-13) I also get a value of 2 so I think this
> is what your saying to do here?
Ok, you have a value:
IDL> val = 16413
IDL> Print, Binary(val)
0 1 0 0 0 0 0 0 0 0 0 1 1 1 0 1
You want to know the value of the first three bits:
IDL> Print, val AND (2L^3-1)
5
You want to know the value of bits 4 and 5:
IDL> Print, ISHFT(val AND (2L^3 + 2L^4), -3)
3
You want to know the value of bits 14-16:
IDL> Print, ISHFT(val AND (2L^13 + 2L^14 + 2L^15), -13)
2
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: help with reading unsigned 16-bit integers [message #57453 is a reply to message #57452] |
Sun, 09 December 2007 12:12  |
teich
Messages: 33 Registered: May 2007
|
Member |
|
|
On Dec 9, 9:59 am, David Fanning <n...@dfanning.com> wrote:
> dcl...@gmail.com writes:
>> Try using ISHFT to create a mask that you will use to determine (by
>> using a bitwise AND) if/where given bits are set:
>> Taking your example for the 2-'cloud' bit:
>>> cloudmask = ISHFT(1,2)
>>> cloudy = FEATURE_CLASSIFICATION_FLAGS AND cloudmask
>> The resulting "CLOUDY" variable will be nonzero where the 2-'cloud'
>> bit is set.
>> combine with other bits as needed.
>
> Here is an article that might give you some help with
> how to use ISHFT:
>
> http://www.dfanning.com/code_tips/convert24to8.html
>
> This is essentially what you want to do with your
> value.
>
> Cheers,
> David
>
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Hmmm,
Still not sure what's going on.
If I pick a value:
> myval= FEATURE_CLASSIFICATION_FLAGS(10,20)
> print,binary(fix(myval))
0 1 0 0 0 0 0 0 0 0 0 1 1 1 0 1
Then is it safe to say that bits 1 to 3 represent 1*2^0 + 0*2^1 +
1*2^2 = 3. So then I know it's not cloud since cloud is '2'? Bits
1-3 can take on any values '0' to '7', '2' being cloud. Documentation
also says that bits 4 through 5 take on values '0' to '3'. So in the
above, I would do 1*2^0 + 1*2^1 = 3? Bits 6 to 7 can also take on
values from '0' to '3', ... bits 14 to 16 can take on values from '0'
to '5' so in the above, bits 14 to 16 give a value of 2?
For bits 14 to 16, if I do
print,ishft((fix(myval)),-13) I also get a value of 2 so I think this
is what your saying to do here?
Thanks,
Howard
|
|
|
Re: help with reading unsigned 16-bit integers [message #57470 is a reply to message #57453] |
Sun, 09 December 2007 06:59  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
dcleon@gmail.com writes:
> Try using ISHFT to create a mask that you will use to determine (by
> using a bitwise AND) if/where given bits are set:
> Taking your example for the 2-'cloud' bit:
>> cloudmask = ISHFT(1,2)
>> cloudy = FEATURE_CLASSIFICATION_FLAGS AND cloudmask
> The resulting "CLOUDY" variable will be nonzero where the 2-'cloud'
> bit is set.
> combine with other bits as needed.
Here is an article that might give you some help with
how to use ISHFT:
http://www.dfanning.com/code_tips/convert24to8.html
This is essentially what you want to do with your
value.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: help with reading unsigned 16-bit integers [message #57477 is a reply to message #57470] |
Sun, 09 December 2007 01:37  |
dcleon@gmail.com
Messages: 12 Registered: November 2007
|
Junior Member |
|
|
On Dec 9, 12:28 am, te...@atmsci.msrc.sunysb.edu wrote:
> Hi,
>
> I am reading a HDF file and one of the SDS is an unsigned 16-bit
> integer. According to documentation, the bits have certain meanings.
> The bits go from 1 to 16. For example, bits 1-3 represent feature
> type (0- invalid, 1-'clean air', 2-'cloud', ...). This is data from
> NASA's Calipso Vertical Feature Mask (in case your wondering).
>
> I have no idea what's going on when I read the SDS. For example, I
> get the following ouput:
>
>> HDF_SD_GETDATA,sds_id,Feature_Classification_Flags
>> FEATURE_CLASSIFICATION_FLAGS UINT = Array[5515, 3744]
>
> IDL> print,FEATURE_CLASSIFICATION_FLAGS(5500:5514,3743)
> 8221 8221 8221 8221 8221 16413 16413 16413
> 16413 16413 16413 16413
> 16413 16413 16413
>
> Could anyone tell me what I am looking at here? Where are bits 1-3,
> etc? Do I need to do some conversion? I tried some of the stuff at:
>
Howard,
Try using ISHFT to create a mask that you will use to determine (by
using a bitwise AND) if/where given bits are set:
Taking your example for the 2-'cloud' bit:
> cloudmask = ISHFT(1,2)
> cloudy = FEATURE_CLASSIFICATION_FLAGS AND cloudmask
The resulting "CLOUDY" variable will be nonzero where the 2-'cloud'
bit is set.
combine with other bits as needed.
cheers
dave
|
|
|