pro bitflag_visualizer ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Name: Bit Flag Visualizer ; ; Purpose: ; Read and visualize any Bit-Flag from MODIS Atmosphere HDF files ; Program creates PNG images using a discrete 23 color bar. ; Images are output to your local directory. ; ; Detail: ; Runtime QA Bit Flags can be visualized as well as ; Bit Flags in the primary 35_L2 Cloud_Mask SDS. ; Data is unmapped, that is, one pixel in the image is ; equivalent to one pixel in the data. ; ; Requirements: ; HDF file must be visible (accessible) from your local platform. ; Must have x-window display capability on your local platform. ; ; Credits: ; Written by Paul A. Hubanks ; ; Version: ; 2.0 ; ; Date: ; 1 June 2005 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Specify Filename and SDS to Read ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; BEGIN USER DEFINED INPUT: Part 1 ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Specify HDF Filename HDFFileName="MOD06_L2.A2001043.1510.005.2005105195333.hdf" HDFFileName="MOD06_L2.A2001043.1630.005.2005105200719.hdf" HDFFileName="MOD04_L2.A2001043.1510.005.2005105193145.hdf" HDFFileName="MOD05_L2.A2001043.1510.005.2005105193042.hdf" HDFFileName="MOD06_L2.A2001043.1510.005.2005105195333.hdf" HDFFileName="MOD07_L2.A2001043.1510.005.2005105171354.hdf" HDFFileName="MOD35_L2.A2001043.1510.005.2005105171245.hdf" HDFFileName="MOD06_L2.A2001043.1510.005.2005105195333.hdf" HDFFileName="MOD35_L2.A2001043.1510.005.2005105171245.hdf" HDFFileName="MOD06_L2.A2001043.1510.005.2005105195333.hdf" HDFFileName="MOD06_L2.A2001043.1510.005.2005145233327.hdf" ; Specify SDS to read from HDF File variable="Cloud_Mask_QA" variable="Quality_Assurance_Land" variable="Quality_Assurance_Ocean" variable="Cloud_Mask_QA" variable="Quality_Assurance_Near_Infrared" variable="Quality_Assurance_Infrared" variable="Cloud_Mask_1km" variable="Quality_Assurance_1km" variable="Quality_Assurance_5km" variable="Cloud_Mask" variable="Quality_Assurance" variable="Cloud_Mask_5km" variable="Cloud_Mask" variable="Quality_Assurance_1km" ; Specify Number of Flags To Read and Image flagnum=3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; END USER DEFINED INPUT: Part 1 ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;; ; Allocate Arrays ;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Variable name used as image title and filename prefix ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; SDS Name to print on Image title = STRARR(flagnum) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Byte and Bit Position of Flag in BitString SDS Array is 0 indexed ; First Byte is byte 0, bits are numbered 0 to 7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; QA_Byte = INTARR(flagnum) QA_Start_Bit = INTARR(flagnum) QA_Num_Bits = INTARR(flagnum) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Number of QA categories (valid QA flag settings) ; min QA value assumed = 0 ; max QA value assumed 1 less than number of categories ; (see hardwire just after NUM loop) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; qanum = INTARR(flagnum) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Labels for color bar ; or definitions of valid QA flag settings ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; scalelabel = strarr(flagnum,16) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Specify Flags To Read and Image ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; BEGIN USER DEFINED INPUT: Part 2 ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; SAMPLE FLAGS ARE SHOWN BELOW! ; note qanum is number of scale labels (and flags) title(0) = "CSR_Flag" QA_Byte(0) = 3 QA_Start_Bit(0) = 6 QA_Num_Bits(0) = 2 qanum(0) = 4 scalelabel(0,0) = "Not Restored (0)" scalelabel(0,1) = "Restored via Edge Detect. (1)" scalelabel(0,2) = "Restored via Spatial Var. (2)" scalelabel(0,3) = "Restored via 250m. Tests (3)" title(1) = "RPP_Flag" QA_Byte(1) = 2 QA_Start_Bit(1) = 0 QA_Num_Bits(1) = 3 qanum(1) = 5 scalelabel(1,0) = "Cloud Mask Undet. (0)" scalelabel(1,1) = "Clear/Stop (1)" scalelabel(1,2) = "Liquid Water Cloud (2)" scalelabel(1,3) = "Ice Cloud (3)" scalelabel(1,4) = "Undetermined Phase Cloud (4)" title(2) = "Multilayer_Cloud_And_Phase_Flag" QA_Byte(2) = 4 QA_Start_Bit(2) = 3 QA_Num_Bits(2) = 3 qanum(2) = 8 scalelabel(2,0) = "Cloud Mask Undet. (0)" scalelabel(2,1) = "Clear/Stop (1)" scalelabel(2,2) = "SL Liquid Water Cloud (2)" scalelabel(2,3) = "ML Liquid Water Cloud (3)" scalelabel(2,4) = "SL Ice Cloud (4)" scalelabel(2,5) = "ML Ice Cloud (5)" scalelabel(2,6) = "SL Undet Phase Cloud (6)" scalelabel(2,7) = "ML Undet Phase Cloud (7)" goto, jump4477 title(0) = "Ecosystem_Map_Flag" QA_Byte(0) = 9 QA_Start_Bit(0) = 0 QA_Num_Bits(0) = 2 qanum(0) = 4 scalelabel(0,0) = "Loveland NA 1km (0)" scalelabel(0,1) = "Olsen Ecosystem (1)" scalelabel(0,2) = "MOD12 (MODIS) (2)" scalelabel(0,3) = "Other (3)" goto, jump4477 title(0) = "NCO_Test_Flag" QA_Byte(0) = 1 QA_Start_Bit(0) = 0 QA_Num_Bits(0) = 1 qanum(0) = 2 scalelabel(0,0) = "Not Applied (0)" scalelabel(0,1) = "Applied (1)" title(1) = "Thin_Cirrus_Solar_Test_Flag" QA_Byte(1) = 1 QA_Start_Bit(1) = 1 QA_Num_Bits(1) = 1 qanum(1) = 2 scalelabel(1,0) = "Not Applied (0)" scalelabel(1,1) = "Applied (1)" title(2) = "Shadow_Detection_Test_Flag" QA_Byte(2) = 1 QA_Start_Bit(2) = 2 QA_Num_Bits(2) = 1 qanum(2) = 2 scalelabel(2,0) = "Not Applied (0)" scalelabel(2,1) = "Applied (1)" title(3) = "Thin_Cirrus_Test_Flag" QA_Byte(3) = 1 QA_Start_Bit(3) = 3 QA_Num_Bits(3) = 1 qanum(3) = 2 scalelabel(3,0) = "Not Applied (0)" scalelabel(3,1) = "Applied (1)" title(4) = "Cloud_Adjacency_Test_Flag" QA_Byte(4) = 1 QA_Start_Bit(4) = 4 QA_Num_Bits(4) = 1 qanum(4) = 2 scalelabel(4,0) = "Not Applied (0)" scalelabel(4,1) = "Applied (1)" title(5) = "IR_Threshold_Test_Flag" QA_Byte(5) = 1 QA_Start_Bit(5) = 5 QA_Num_Bits(5) = 1 qanum(5) = 2 scalelabel(5,0) = "Not Applied (0)" scalelabel(5,1) = "Applied (1)" goto, jump4477 title(0) = "Cloud_Mask_Usefulness_Flag" QA_Byte(0) = 0 QA_Start_Bit(0) = 0 QA_Num_Bits(0) = 1 qanum(0) = 2 scalelabel(0,0) = "Not Useful (0)" scalelabel(0,1) = "Useful (1)" title(1) = "Cloud_Mask_Confidence_Flag" QA_Byte(1) = 0 QA_Start_Bit(1) = 1 QA_Num_Bits(1) = 3 qanum(1) = 4 scalelabel(1,0) = "No Confidence or Fill (0)" scalelabel(1,1) = "Marginal (1)" scalelabel(1,2) = "Good (2)" scalelabel(1,3) = "Very Good (3)" goto, jump4477 title(0) = "Guess_Moisture_Profile_Flag" QA_Byte(0) = 7 QA_Start_Bit(0) = 0 QA_Num_Bits(0) = 2 qanum(0) = 4 scalelabel(0,0) = "NCEP/GDAS (0)" scalelabel(0,1) = "GMAO (1)" scalelabel(0,2) = "AIRS/AMSU (2)" scalelabel(0,3) = "Other (3)" goto, jump4477 title(0) = "Method_Of_Ozone_Retrieval_Flag" QA_Byte(0) = 6 QA_Start_Bit(0) = 2 QA_Num_Bits(0) = 2 qanum(0) = 4 scalelabel(0,0) = "RTE Perturbation (0)" scalelabel(0,1) = "Stratospheric Method (1)" scalelabel(0,2) = "Other Method (2)" scalelabel(0,3) = "No Retrieval (3)" goto, jump4477 title(0) = "Method_Of_Profile_Retrieval_Flag" QA_Byte(0) = 6 QA_Start_Bit(0) = 0 QA_Num_Bits(0) = 2 qanum(0) = 4 scalelabel(0,0) = "Statistical (0)" scalelabel(0,1) = "Physical (1)" scalelabel(0,2) = "Other Method (2)" scalelabel(0,3) = "No Retrieval (3)" goto, jump4477 title(0) = "Temperature_Profile_Usefulness_Flag" QA_Byte(0) = 0 QA_Start_Bit(0) = 0 QA_Num_Bits(0) = 1 qanum(0) = 2 scalelabel(0,0) = "Not Useful (0)" scalelabel(0,1) = "Useful (1)" goto, jump4477 title(0) = "Cloud_Mask_Cloudiness_Flag" QA_Byte(0) = 0 QA_Start_Bit(0) = 1 QA_Num_Bits(0) = 2 qanum(0) = 4 scalelabel(0,0) = "Confident Cloudy (0)" scalelabel(0,1) = "Probably Cloudy(1)" scalelabel(0,2) = "Probably Clear (2)" scalelabel(0,3) = "Confident Clear (3)" goto, jump4477 title(0) = "Cirrus_Flag" QA_Byte(0) = 2 QA_Start_Bit(0) = 4 QA_Num_Bits(0) = 2 qanum(0) = 3 scalelabel(0,0) = "Missing (0)" scalelabel(0,1) = "No Cirrus Found (1)" scalelabel(0,2) = "Cirrus Found (2)" title(1) = "High_Cloud_Flag" QA_Byte(1) = 2 QA_Start_Bit(1) = 6 QA_Num_Bits(1) = 2 qanum(1) = 3 scalelabel(1,0) = "Missing (0)" scalelabel(1,1) = "No High Cloud Found (1)" scalelabel(1,2) = "High Cloud Found (2)" goto, jump4477 title(0) = "Thin_Cirrus_Flag" QA_Byte(0) = 1 QA_Start_Bit(0) = 1 QA_Num_Bits(0) = 1 qanum(0) = 2 scalelabel(0,0) = "Yes (0)" scalelabel(0,1) = "No (1)" goto, jump4477 title(0) = "CSR_Flag" QA_Byte(0) = 3 QA_Start_Bit(0) = 6 QA_Num_Bits(0) = 2 qanum(0) = 4 scalelabel(0,0) = "Not Restored (0)" scalelabel(0,1) = "Restored via Edge Detect. (1)" scalelabel(0,2) = "Restored via Spatial Var. (2)" scalelabel(0,3) = "Restored via 250m. Tests (3)" goto, jump4477 title(0) = "Heavy_Aerosol_Flag" QA_Byte(0) = 1 QA_Start_Bit(0) = 0 QA_Num_Bits(0) = 1 qanum(0) = 2 scalelabel(0,0) = "Yes (0)" scalelabel(0,1) = "No (1)" goto, jump4477 title(0) = "RPP_Flag" QA_Byte(0) = 2 QA_Start_Bit(0) = 0 QA_Num_Bits(0) = 3 qanum(0) = 5 scalelabel(0,0) = "Cloud Mask Undet. (0)" scalelabel(0,1) = "Clear/Stop (1)" scalelabel(0,2) = "Liquid Water Cloud (2)" scalelabel(0,3) = "Ice Cloud (3)" scalelabel(0,4) = "Undetermined Phase Cloud (4)" goto, jump4477 title(0) = "TWPNIR_Usefulness_Flag" QA_Byte(0) = 0 QA_Start_Bit(0) = 0 QA_Num_Bits(0) = 1 qanum(0) = 2 scalelabel(0,0) = "Not Useful (0)" scalelabel(0,1) = "Useful (1)" goto, jump4477 title(0) = "Retrieval_Method_IR_Flag" QA_Byte(0) = 4 QA_Start_Bit(0) = 0 QA_Num_Bits(0) = 2 qanum(0) = 4 scalelabel(0,0) = "Split Window (0)" scalelabel(0,1) = "Moisture Profile (1)" scalelabel(0,2) = "Other (2)" scalelabel(0,3) = "No Retrieval (3)" title(1) = "TPW_Confidence_Flag" QA_Byte(1) = 0 QA_Start_Bit(1) = 1 QA_Num_Bits(1) = 3 qanum(1) = 4 scalelabel(1,0) = "No Confidence or Fill (0)" scalelabel(1,1) = "Marginal (1)" scalelabel(1,2) = "Good (2)" scalelabel(1,3) = "Very Good (3)" title(2) = "TPW_Usefulness_Flag" QA_Byte(2) = 0 QA_Start_Bit(2) = 0 QA_Num_Bits(2) = 1 qanum(2) = 2 scalelabel(2,0) = "Not Useful (0)" scalelabel(2,1) = "Useful (1)" goto, jump4477 title(0) = "Surface_Type_NIR_Flag" QA_Byte(0) = 0 QA_Start_Bit(0) = 6 QA_Num_Bits(0) = 2 qanum(0) = 4 scalelabel(0,0) = "Bright Land (0)" scalelabel(0,1) = "Ocean (1)" scalelabel(0,2) = "Cloud (2)" scalelabel(0,3) = "Sunglint (3)" goto, jump4477 title(0) = "Cloud_Mask_Cloudiness_Flag" QA_Byte(0) = 0 QA_Start_Bit(0) = 1 QA_Num_Bits(0) = 2 qanum(0) = 4 scalelabel(0,0) = "Confident Cloudy (0)" scalelabel(0,1) = "Probably Cloudy(1)" scalelabel(0,2) = "Probably Clear (2)" scalelabel(0,3) = "Confident Clear (3)" goto, jump4477 title(0) = "Ocean_Retrieval_Condition_Part_1" QA_Byte(0) = 1 QA_Start_Bit(0) = 0 QA_Num_Bits(0) = 4 qanum(0) = 11 scalelabel(0,0) = "Retrieval Performed (0)" scalelabel(0,1) = "Glitter Present (1)" scalelabel(0,2) = "Cloudy (2)" scalelabel(0,3) = "R(0.865) Too Low (3)" scalelabel(0,4) = "Insuff. VIS/SWIR Bands (4)" scalelabel(0,5) = "Available Wavelengths < 3 (5)" scalelabel(0,6) = "Angles Out-Of-Bounds (6)" scalelabel(0,7) = "Land Present (7)" scalelabel(0,8) = "AOT < 0 Found (8)" scalelabel(0,9) = "AOT > 5 Found (9)" scalelabel(0,10) = "Invalid Input Data (10)" goto, jump4477 title(2) = "AOT47_Usefulness_Flag" QA_Byte(2) = 0 QA_Start_Bit(2) = 0 QA_Num_Bits(2) = 1 qanum(2) = 2 scalelabel(2,0) = "Not Useful (0)" scalelabel(2,1) = "Useful (1)" goto, jump4477 title(0) = "AOT47_Confidence_Flag" QA_Byte(0) = 0 QA_Start_Bit(0) = 1 QA_Num_Bits(0) = 3 qanum(0) = 4 scalelabel(0,0) = "No Confidence or Fill (0)" scalelabel(0,1) = "Marginal (1)" scalelabel(0,2) = "Good (2)" scalelabel(0,3) = "Very Good (3)" title(1) = "Aerosol_Type_Flag" QA_Byte(1) = 2 QA_Start_Bit(1) = 0 QA_Num_Bits(1) = 2 qanum(1) = 4 scalelabel(1,0) = "Mixed or Fill (0)" scalelabel(1,1) = "Dust (1)" scalelabel(1,2) = "Sulfate (2)" scalelabel(1,3) = "Smoke (3)" goto, jump4477 title(0) = "Cloud_Mask_Usefulness_Flag" QA_Byte(0) = 0 QA_Start_Bit(0) = 0 QA_Num_Bits(0) = 1 qanum(0) = 2 scalelabel(0,0) = "Not Useful (0)" scalelabel(0,1) = "Useful (1)" title(1) = "Cloud_Mask_Cloudiness_Flag" QA_Byte(1) = 0 QA_Start_Bit(1) = 1 QA_Num_Bits(1) = 2 qanum(1) = 4 scalelabel(1,0) = "Confident Cloudy (0)" scalelabel(1,1) = "Probably Cloudy(1)" scalelabel(1,2) = "Probably Clear (2)" scalelabel(1,3) = "Confident Clear (3)" title(2) = "Day_Night_Flag" QA_Byte(2) = 0 QA_Start_Bit(2) = 3 QA_Num_Bits(2) = 1 qanum(2) = 2 scalelabel(2,0) = "Night (0)" scalelabel(2,1) = "Day (1)" title(3) = "Sunglint_Flag" QA_Byte(3) = 0 QA_Start_Bit(3) = 4 QA_Num_Bits(3) = 1 qanum(3) = 2 scalelabel(3,0) = "Yes (0)" scalelabel(3,1) = "No (1)" title(4) = "Snow_Ice_Flag" QA_Byte(4) = 0 QA_Start_Bit(4) = 5 QA_Num_Bits(4) = 1 qanum(4) = 2 scalelabel(4,0) = "Yes (0)" scalelabel(4,1) = "No (1)" title(5) = "Surface_Type_Flag" QA_Byte(5) = 0 QA_Start_Bit(5) = 6 QA_Num_Bits(5) = 2 qanum(5) = 4 scalelabel(5,0) = "Ocean or Deep Lakes/Rivers (0)" scalelabel(5,1) = "Coast or Shallow Lakes/Rivers (1)" scalelabel(5,2) = "Desert (2)" scalelabel(5,3) = "Land (3)" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; END USER DEFINED INPUT: Part 2 ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; jump4477: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Set Color Table Assignments ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; print,' # of colors = ', !D.N_Colors red=bytarr(256) grn=bytarr(256) blu=bytarr(256) LUTR=BYTARR(256) LUTG=BYTARR(256) LUTB=BYTARR(256) r=bytarr(23) g=bytarr(23) b=bytarr(23) r = [ 0,225,139,098, 8, 8, 8, 8,102, 8, 8, 8, 8,255,222,205,230,230,153,240,160,204,255] g = [ 0,225, 8, 8, 8,106,148,172,255,205,222,213,197,255,238,205,172,139, 90,106, 32, 0, 0] b = [ 0,225,213,213,222,222,238,222,255,172,139, 90, 8, 0, 8, 8, 8, 8, 8,108, 0, 0, 0] for i=0,21 do begin red(i*11:i*11+10)=r(i) grn(i*11:i*11+10)=g(i) blu(i*11:i*11+10)=b(i) endfor red(242:253)=r(22) grn(242:253)=g(22) blu(242:253)=b(22) ;assign 254 to white red(254)=255 grn(254)=255 blu(254)=255 ;assign 255 to black red(255)=000 grn(255)=000 blu(255)=000 ;reload modified color table tvlct,red,grn,blu ;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;; ; Read L2 Data ;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Read in the 1km Data: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; HDFFileID = HDF_SD_START(HDFFileName,/READ) Read_product_sds, L2QA, range, fillvalue, HDFfileID, variable, $ fail, /scaleNo, /offsetNo, /validrangeNo, /fillNo ;;Read_product_sds, array, range, fillvalue, HDFfileID, variable, $ ;; fail HDF_SD_END, HDFFileID help, L2QA ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Determine the size of the SDS array ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; dims = size(L2QA,/dimensions) help, dims ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Find number of dimensions in array ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; asize = size(L2QA) numdim = asize(0) help, numdim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Determine Type of SDS (CASE) Being Read ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 10x10 km array dimensions (203,135) ;; 5x5 km array dimensions (406,270) ;; 1x1 km array dimensions (2030,1354) ;;;;;;;;;;;;; ;; CASE #1 ;; ;;;;;;;;;;;;; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Runtime QA Flag Array w./ 3 dimensions ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;; Regular QA Arrays ;;;;;;;;;;;;;;;;;;;;;;; ; ; Transpose Regular QA arrays from [band,x,y] to [x,y,band] ; ; Example: native 06_L2 Quality_Assurance_1km array dimensions (2030,1354,6) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; if (numdim EQ 3 and variable NE "Cloud_Mask") then begin print,'***********************************************' print,'Regular Runtime QA Flag Array with 3 Dimensions' print,'***********************************************' L2QA = TRANSPOSE(L2QA, [1, 2, 0]) ; Set array dimensions xdim = dims(1) ydim = dims(2) nbands = dims(0) print, 'xdim = ',xdim print, 'ydim = ',ydim print, 'nbands = ',nbands goto, jump4000 endif ;;;;;;;;;;;;; ;; CASE #2 ;; ;;;;;;;;;;;;; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Runtime QA Flag Array w./ Only 2 dimensions ;; ;; ;; No Need To Transpose ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; if (numdim EQ 2) then begin print,'***********************************************' print,'Regular Runtime QA Flag Array with 2 Dimensions' print,'***********************************************' ; Set array dimensions xdim = dims(0) ydim = dims(1) print, 'xdim = ',xdim print, 'ydim = ',ydim goto, jump4000 endif ;;;;;;;;;;;;; ;; CASE #3 ;; ;;;;;;;;;;;;; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;i;;;;;;;;;;;;;;;;; ;; Primary Cloud Mask Flag Array 3 dimensions but not transposed ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;; Primary Cloud Mask Array ;;;;;;;;;;;;;;; ;; from 35_L2 (L2 Cloud Mask Product) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Note the Cloud Mask QA Array from 07_L2 (Profiles) ;; has the EXACT same name ... that case will be ;; handled by the logic directly above (2 dims) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Primary Cloud_Mask is already [x,y,band], no need to transpose ; native 1km L2 array dimensions (6,2030,1354) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; if (numdim EQ 3 and variable EQ "Cloud_Mask") then begin print,'******************************************************' print,'Primary 35_L2 Cloud_Mask Flag Array (has 3 Dimensions)' print,'******************************************************' ; Set array dimensions for Cloud Mask xdim = dims(0) ydim = dims(1) nbands = dims(2) print, 'xdim = ',xdim print, 'ydim = ',ydim print, 'nbands = ',nbands goto, jump4000 endif ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; END OF CASES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; jump4000: help, L2QA ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Loop Through Flags To Read and Image ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; FOR NUM=0,flagnum-1 DO BEGIN ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; QA min and max values ; Assume min = 0 ; max = 1 less than number of categories ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; rmin=0 rmax=qanum(NUM)-1 variablenew = variable + " " + title(NUM) ;Create the integer QA Flags output array: temp = IntArr(xdim,ydim) ;;;;;;; ;Extract the appropriate QA Flag: ; temp[*,*] = ISHFT((L2QA[*,*,QA_Byte(NUM)] AND 192B), -QA_Start_Bit(NUM)) ; Grab the byte "QA_Byte" and ; shift the byte to the right by the start bit value ; (this eliminates all less significant bits) temp[*,*] = ISHFT( L2QA[*,*,QA_Byte(NUM)], -QA_Start_Bit(NUM)) help, temp if(QA_Num_Bits(NUM) EQ 1) then mask = 1B if(QA_Num_Bits(NUM) EQ 2) then mask = 2B + 1B if(QA_Num_Bits(NUM) EQ 3) then mask = 4B + 2B + 1B if(QA_Num_Bits(NUM) EQ 4) then mask = 8B + 4B + 2B + 1B if(QA_Num_Bits(NUM) EQ 5) then mask = 16B + 8B + 4B + 2B + 1B if(QA_Num_Bits(NUM) EQ 6) then mask = 32B + 16B + 8B + 4B + 2B + 1B if(QA_Num_Bits(NUM) EQ 7) then mask = 64B + 32B + 16B + 8B + 4B + 2B + 1B if(QA_Num_Bits(NUM) EQ 8) then mask = 128B + 64B + 32B + 16B + 8B + 4B + 2B + 1B help, mask array = IntArr(xdim,ydim) array[*,*] = temp AND mask help, array print,' min array = ', min(array) print,' max array = ', max(array) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ;data = array * 1.0 ; ensure it is floating data type ; ; index = Where(sdsData NE fillValue, ncount) ; ; IF ncount gt 0 THEN $ ; data[index] = (sdsData[index] - addOffset) * scaleFactor ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Determine the size of the SDS array: dims = size(array,/dimensions) xdimgeo = dims(0) ydimgeo = dims(1) xg = dims(0) - 1 yg = dims(1) - 1 print, ' min = ', min(array) print, ' max = ', max(array) asize = size(array) print," " print," " print," ******************** " print," " print,title(NUM) help,array print," " print," ******************** " print," " print," " ;number of dimensions in array dim=asize(0) ;size of 1st, 2nd, 3rd, 4th dimension xdim=asize(1) ydim=asize(2) ndim=asize(3) mdim=asize(4) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Begin Building Master Image ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; image = 1354 x 2030 ; image = 1354 x 2040 ; new = 1500 x 2100 ; new = 1600 x 2100 ;new=bytarr(1600,2100) new=bytarr(xdim+246,ydim+60) ;set master image background color to white ;new(0:1599,0:2099)=254 new(0:xdim+245,0:ydim+59)=254 ;;;;;;;;;;;;;;;;;;;;;;;; ; Build a Color Bar ;;;;;;;;;;;;;;;;;;;;;;;; print, 'height of image = ',ydim print,' height of color bar = ',ydim ; build colorbar (0 to 253 only) bar=fltarr(40,ydim) colorbar=bytarr(40,ydim) icbidx = ydim - 1 ; add 0.5 to adjust for truncation (round off) ; this allows the 0 and 253 color bar blocks ; to be the same size (5 pixels in height) for i=0,icbidx do begin realval=253.0*(float(i)/float(icbidx))+0.5 bar(0:39,i)=realval endfor colorbar=byte(bar) print,"barmin = ",min(colorbar),"barmax = ",max(colorbar) print,"barbot = ",colorbar(0,0),"bartop = ",colorbar(0,icbidx) print, ' dim = ', dim ;;;;;;;;;;;;;;;;;;;; ; Process Image Data ;;;;;;;;;;;;;;;;;;;; ;; if ( dim eq 2 ) then begin if ( dim eq 2 and rmin ne 1.0 and rmax ne 100.0) then begin flipped=rotate(array,7) goto, jump3884 ;check for all missing data values (no data) if (MIN(flipped) eq FillValue and MAX(flipped) eq FillValue) then begin minvalue = 0.0 maxvalue = 0.0 goto, JUMP1 endif ;compute min and max data values if (MIN(flipped) eq FillValue) then begin minvalue = MIN(flipped[WHERE(flipped ne FillValue)]) minvalue = rmin endif if (MIN(flipped) ne FillValue) then begin minvalue = MIN(flipped) minvalue = rmin endif jump3884: minvalue = rmin maxvalue = rmax print, "datamin = ", minvalue, "datamax = ", maxvalue ;;;;;;;;;;;;;;;;;;;;;;;;; ;;May2003 Scale Fix ;;scale data from 0 to 251 byte_array=bytscl(flipped,min=minvalue,max=maxvalue,top=251) ;print the scaled byte min and max print,"bytemin (0) = ",min(byte_array),"bytemax (251) = ",max(byte_array) ;;scale data from 1 to 252 byte_array=byte_array+1 ;print the scaled byte min and max print,"bytemin (1) = ",min(byte_array),"bytemax (252) = ",max(byte_array) ;; set data LE minvalue to byte(0) if (MIN(flipped) le minvalue) then begin ;le_array=bytarr(1354,2030) le_array=bytarr(xdim,ydim) le_array(0:xdim-1,0:ydim-1)=0 byte_array[WHERE(flipped le minvalue)]=le_array[WHERE(flipped le minvalue)] endif ;; set data GE maxvalue to byte(253) if (MAX(flipped) ge maxvalue) then begin ;ge_array=bytarr(1354,2030) ge_array=bytarr(xdim,ydim) ge_array(0:xdim-1,0:ydim-1)=253 byte_array[WHERE(flipped ge maxvalue)]=ge_array[WHERE(flipped ge maxvalue)] endif ;;;;;;;;;;;;;;;;;;;;;;;; JUMP1: goto, jump4499 ;set fillvalue to 255 (black) if (MIN(flipped) eq FillValue) then begin print,'setting fillvalue to 255' ;fill_array=bytarr(1354,2030) fill_array=bytarr(xdim,ydim) fill_array(0:xdim-1,0:ydim-1)=255 byte_array[WHERE(flipped eq FillValue)]=fill_array[WHERE(flipped eq FillValue)] endif jump4499: ;;;;;;;;;;;;;;;;;;; ; TEXT ANNOTATIONS ;;;;;;;;;;;;;;;;;;; ; display to z buffer Set_Plot,'Z',/Copy !p.font=0 ;; [1354,2040] ;; [1600,2100] ;; new=bytarr(xdim+246,ydim+60) Device, Set_Colors=256, Set_Resolution=[xdim+246,ydim+60],set_character_size=[8,9] Device, set_font='Helvetica',/tt_font ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Set scale size of title and annotations (1.0 is default) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; sizenum_title=1.0 sizenum=0.8 sizenum_footer=1.0 fillcolor = 000 ;Create Temporary Array for Text textcolor = 255 base=0 xbase=1440 xbase=xdim+86 barbase=25 barbase=30 ;Write Annotations ;; erase XYOUTs window before writing annotation for each image erase ; sds name XYOuts,030,base+ydim+40,variablenew,/Device,Color=textcolor,CharSize=sizenum_title ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; compute max qa category looping index qanum_index=qanum(NUM)-1 ; compute scale y-position increment si=ydim/qanum_index ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; print scale numbers in proper x,y coordinates for i=0,qanum_index do begin XYOuts,xbase,barbase+si*i,scalelabel(NUM,i),/Device,Color=textcolor,CharSize=sizenum endfor ; hdf filename XYOuts,030,base+8,HDFFilename,/Device,Color=textcolor,CharSize=sizenum_footer ;Read the screen to get text annotation print,'read tv screen' temptext = tvrd(0,0,xdim+246,ydim+60) print,'done reading tv screen!' ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Place Text Into Master Image & Write to PNG ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; mintmp = min(temptext) maxtmp = max(temptext) print, 'min temptext=',mintmp,'max temptext=',maxtmp ; SET BACKGROUND TO WHITE!!! temptext[where(temptext eq mintmp)]=254 temptext[where(temptext eq maxtmp)]=255 ;ADD ANNOTATION new(0,0)=temptext(0:xdim+245,0:ydim+59) ;ADD IMAGE new(30,30)=byte_array ;ADD COLOR BAR new(xdim+36,30)=colorbar ;;;;;;;;;;;;;;;;;; ; WRITE PNG IMAGE ;;;;;;;;;;;;;;;;;; print,'write png' image_filename=title(NUM)+".png" write_image,image_filename,'PNG',new,red,grn,blu endif ENDFOR ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; END NUM (QA FLAG #) LOOP ;;;;;;;;;;;;;;;;;;;;;;;;;;;; end