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

Home » Public Forums » archive » Re: Reading individual bits of MODIS BRDF quality files
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: Reading individual bits of MODIS BRDF quality files [message #68072] Mon, 21 September 2009 01:38
wita is currently offline  wita
Messages: 43
Registered: January 2005
Member
>
> Is there a function in IDL that can read individual bits, or any other
> clever way to produce an array of 1s and 0s from a 32-bit integer?

Hi Edward,

Compile the function below and run it trough ENVI Band math and it
will return an 0/1 map of the bit position that you specify. So for
retrieving
bit position 7 (integer value 128) use:

cgi_map_bitwise_flag(b1, 7)

with best regards,

Allard


FUNCTION cgi_map_bitwise_flag, statusmap, bitposition
return, BYTE((statusmap AND (2UL^bitposition))/(2UL^bitposition))
END
Re: Reading individual bits of MODIS BRDF quality files [message #68091 is a reply to message #68072] Fri, 18 September 2009 06:25 Go to previous message
pgrigis is currently offline  pgrigis
Messages: 436
Registered: September 2007
Senior Member
On Sep 18, 5:54 am, emitchard <emitch...@googlemail.com> wrote:
[skip]

> Is there a function in IDL that can read individual bits, or any other
> clever way to produce an array of 1s and 0s from a 32-bit integer?

For the record (in case somebody needs that):

IDL> x=2LL^45+2LL^35+2LL^32+2LL^31+2LL^25+2LL^15+2LL^5-1 & print,x
35225207865375

;get only 32 bits
IDL> a=string(ulong(x),format='(B)') & print,a
10000010000000001000000000011111

;get all bits
IDL> a=string(x,format='(B)') & print,a
1000000000100110000010000000001000000000011111

Ciao,
Paolo

>
> Many thanks for your help,
>
> Edward Mitchard
Re: Reading individual bits of MODIS BRDF quality files [message #68094 is a reply to message #68091] Fri, 18 September 2009 05:05 Go to previous message
emitchard is currently offline  emitchard
Messages: 3
Registered: May 2008
Junior Member
Please ignore this, I've solved the problem by writing to a temporary
file, opening it using readu as a byte array with four times as many
lines, reading the needed bytes and allowing the values I need through
an 'if' statement.

Apologies,

Edward

On Sep 18, 10:54 am, emitchard <emitch...@googlemail.com> wrote:
> I am running IDL 7.0.6 on Windows vista (with ENVI 4.6). I am using
> MODIS BRDF corrected 500 m data (MCD43A4). I have sucessfully written
> a program to open the HDF files and produce the output vegetation
> indices I'm interested in. However, I need to filter out cloud-
> contaminated pixels, and am having problem reading the bit-packed
> quality control file (MCD43A2).
>
> I have written a program to extract the layer I'm interested in from
> the HDF file and save it as a 32-bit unsigned integer. However, I
> really need to extract the raw values of the first 12 bits of this
> number (the values of the remaining fields do not matter to me). I
> started writing a program to list all the numbers (from 0-4294967295)
> that result from my required bit combination of these first 12 bits,
> but that approach is not going to work as there are several million
> 'allowable' numbers.
>
> Is there a function in IDL that can read individual bits, or any other
> clever way to produce an array of 1s and 0s from a 32-bit integer?
>
> Many thanks for your help,
>
> Edward Mitchard
Re: Reading individual bits of MODIS BRDF quality files [message #68095 is a reply to message #68094] Fri, 18 September 2009 05:05 Go to previous message
Wout De Nolf is currently offline  Wout De Nolf
Messages: 194
Registered: October 2008
Senior Member
On Fri, 18 Sep 2009 02:54:55 -0700 (PDT), emitchard
<emitchard@googlemail.com> wrote:

> I am running IDL 7.0.6 on Windows vista (with ENVI 4.6). I am using
> MODIS BRDF corrected 500 m data (MCD43A4). I have sucessfully written
> a program to open the HDF files and produce the output vegetation
> indices I'm interested in. However, I need to filter out cloud-
> contaminated pixels, and am having problem reading the bit-packed
> quality control file (MCD43A2).
>
> I have written a program to extract the layer I'm interested in from
> the HDF file and save it as a 32-bit unsigned integer. However, I
> really need to extract the raw values of the first 12 bits of this
> number (the values of the remaining fields do not matter to me). I
> started writing a program to list all the numbers (from 0-4294967295)
> that result from my required bit combination of these first 12 bits,
> but that approach is not going to work as there are several million
> 'allowable' numbers.
>
> Is there a function in IDL that can read individual bits, or any other
> clever way to produce an array of 1s and 0s from a 32-bit integer?
>
> Many thanks for your help,
>
> Edward Mitchard

Maybe I don't understand what you want, but to extract the first
12bits from a 32bit integer:

a=54564L
b=a and 'FFF'xl
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: HDF: accessing VData in VGroup
Next Topic: idl on mac

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

Current Time: Wed Oct 08 19:23:36 PDT 2025

Total time taken to generate the page: 0.00477 seconds