EXAMPLE USE OF THE IMAPP CLOUD MASK ----------------------------------- The MODIS cloud mask consists of a 6 byte (48 bit) array. For simply a cloud/clear discimination, you will need to extract only the first three bits. This FORTRAN code excerpt shows how you would test a pixel for cloudy or clear using the 95 % probability clear cutoff ( 99%,95% - clear, 66%,1% - cloud ) given an array of pixels. It also demonstrates the extraction of the sunglint bit. This code is just an example. Parts were taken from operational code, but it has not been compiled. This code excerpt utilizes the unix bit function iand. If you wish to read the individual test result bits and use them, you will need to also look at the cloud mask QA output file which will tell you whether or not that test was applied for a given pixel. For example, some tests are not applied at night or in a given ecosystem. ------------------------------------------------------------------------- c BOX_CLOUD Clear/cloud flag array for box c (-1 = undefined, 0 = Clear, 1 = Cloud) c Declaration byte mask_byte, mask_test, mask_value c Cloud mask array byte mask1( max_pixel, max_line ) integer box_cloud( isamp, isamp ) c Number of sunglint contaminated pixels integer nglint c Number of good pixels (where first bit is set to 1) integer ngood_msk jbox = 1 do j = line, line + isamp - 1 ibox = 1 do i = pixel, pixel + isamp - 1 c ... Check that cloud mask was determined for this pixel, and if so c ... check cloud mask c ... (99% and 95% confidence clear pixels are classified CLEAR) c ... (Low confidence clear and cloudy pixels are classified CLOUD) mask_byte = mask1( i, j ) mask_test = 1 c If first bit is set to 1, then mask has been determined mask_value = iand( mask_byte, mask_test ) if ( mask_value .eq. 1 ) then ngood_msk = ngood_msk + 1 mask_test = 6 mask_value = iand( mask_byte, mask_test ) c If both bits 2 and 3 are set or if bit 3 is set c (95 or 99% probability clear) then clear if ( mask_value .ge. 4 ) then box_cloud( ibox, jbox ) = 0 c Else, cloudy else box_cloud( ibox, jbox ) = 1 endif endif c ... Now check sunglint flag in cloud mask mask_byte = mask1( i, j ) mask_test = 1 c If first bit is set to 1, then mask has been determined mask_value = iand( mask_byte, mask_test ) if ( mask_value .eq. 1 ) then mask_test = 16 c If bit 5 is not set, then sunglint mask_value = iand( mask_byte, mask_test ) if ( mask_value .lt. 16 ) nglint = nglint + 1 endif enddo enddo