; This routine reads a 2B-CLDCLASS file specified by infile and writes ; png images that match the quicklook segments found at ; http://www.cloudsat.cira.colostate.edu/dpcstatusQL.php ; ; Make sure you have a subdirectory called "images" under the data_directory. ; Also provides an example of how to work with bit fields in IDL. ; ; Phil Partain (partain@cira.colostate.edu) ; CloudSat Data Processing Center ; Cooperative Institute for Research in the Atmosphere ; Colorado State University ; Date: 9/27/06 ; ; Changes ; 6/4/07 - Color indices for 'missing' and 'deep convection' in the legend ; window were reversed. Now they match the rest of the code. (Phil) pro cldclass_png infile = '2006190054715_01047_CS_2B-CLDCLASS_GRANULE_P_R02_E01.hdf' data_directory = 'C:\cldclass_test\' swathname = '2B-CLDCLASS' fieldname1 = 'cloud_scenario' print,infile prefix = strmid(infile,0,23) ;-------------------------------------------------------------------- fid = eos_sw_open(data_directory+infile,/READ) print,'file',fid swathid = EOS_SW_ATTACH(fid, swathname) print,'swath',swathid status = EOS_SW_READFIELD(swathid, fieldname1, field1) print,'status',status status = EOS_SW_DETACH(swathid) print,'status',status status = EOS_SW_CLOSE(fid) print,'status',status plotfield,data_directory,prefix,swathname,field1,fieldname1 end ;======================================================================== pro plotfield,data_directory,prefix,swathname,field,fieldname LOADCT, 39 TVLCT, red, grn, blu, /GET red(0) = 200 grn(0) = 0 blu(0) = 200 red(1) = 0 grn(1) = 0 blu(1) = 0 red(2) = 84 grn(2) = 0 blu(2) = 163 red(3) = 0 grn(3) = 0 blu(3) = 255 red(4) = 0 grn(4) = 255 blu(4) = 255 red(5) = 0 grn(5) = 255 blu(5) = 0 red(6) = 255 grn(6) = 255 blu(6) = 0 red(7) = 255 grn(7) = 170 blu(7) = 0 red(8) = 255 grn(8) = 0 blu(8) = 0 red(9) = 255 grn(9) = 255 blu(9) = 255 tvlct,red,grn,blu ; uncomment the following to see a window with a legend ;device,decomposed=0 ;window,xsize=350,ysize=40 ;erase,1 ;xyouts,.01,.7,'cirrus',/normal,color=2 ;xyouts,.01,.4,'altostratus',/normal,color=3 ;xyouts,.01,.1,'altocumulus',/normal,color=4 ;xyouts,.3,.7,'stratus',/normal,color=5 ;xyouts,.3,.4,'stratocumulus',/normal,color=6 ;xyouts,.3,.1,'cumulus',/normal,color=7 ;xyouts,.6,.7,'nimbostratus',/normal,color=8 ;xyouts,.6,.4,'deep convection',/normal,color=9 ;xyouts,.6,.1,'missing',/normal,color=0 ; set up the window size win_xsize = n_elements(field(0,*)) win_ysize = n_elements(field(*,0)) miss = intarr(n_elements(field(*,0)),n_elements(field(0,*))) a = intarr(n_elements(field(*,0)),n_elements(field(0,*))) b = intarr(n_elements(field(*,0)),n_elements(field(0,*))) c = intarr(n_elements(field(*,0)),n_elements(field(0,*))) d = intarr(n_elements(field(*,0)),n_elements(field(0,*))) miss(*,*) = (field and 2^0) / 2^0 a(*,*) = (field and 2^1) / 2^1 b(*,*) = (field and 2^2) / 2^2 c(*,*) = (field and 2^3) / 2^3 d(*,*) = (field and 2^4) / 2^4 type = intarr(n_elements(field(*,0)),n_elements(field(0,*))) for j=0l,n_elements(a(0,*))-1 do begin for i=0l,n_elements(a(*,0))-1 do begin if (miss(i,j) eq 0) then begin type(i,j)=0 endif else if (a(i,j) eq 0 and b(i,j) eq 0 and c(i,j) eq 0 and d(i,j) eq 0) then begin type(i,j)=1 endif else if (d(i,j) eq 0 and c(i,j) eq 0 and b(i,j) eq 0 and a(i,j) eq 1) then begin type(i,j)=2 endif else if (d(i,j) eq 0 and c(i,j) eq 0 and b(i,j) eq 1 and a(i,j) eq 0) then begin type(i,j)=3 endif else if (d(i,j) eq 0 and c(i,j) eq 0 and b(i,j) eq 1 and a(i,j) eq 1) then begin type(i,j)=4 endif else if (d(i,j) eq 0 and c(i,j) eq 1 and b(i,j) eq 0 and a(i,j) eq 0) then begin type(i,j)=5 endif else if (d(i,j) eq 0 and c(i,j) eq 1 and b(i,j) eq 0 and a(i,j) eq 1) then begin type(i,j)=6 endif else if (d(i,j) eq 0 and c(i,j) eq 1 and b(i,j) eq 1 and a(i,j) eq 0) then begin type(i,j)=7 endif else if (d(i,j) eq 0 and c(i,j) eq 1 and b(i,j) eq 1 and a(i,j) eq 1) then begin type(i,j)=8 endif else if (d(i,j) eq 1 and c(i,j) eq 0 and b(i,j) eq 0 and a(i,j) eq 0) then begin type(i,j)=9 endif endfor endfor image = reverse(transpose(type),2) ;-------------------------------------------------------------------- ; set up the segments to match the standard cloudsat quicklooks NumSegments = ceil(float(win_xsize)/1200.) SegmentInc = win_xsize/NumSegments IndexBeg = 0L IndexEnd = 0L ; loop over the segments for i = 0, NumSegments-1 do begin IndexBeg = IndexEnd IndexEnd = IndexEnd + SegmentInc IntIndexBeg = long(IndexBeg) IntIndexEnd = long(IndexEnd) ;print,IntIndexBeg,IntIndexEnd-1 ; satellite travels from right to left smallimg = reverse(image(IntIndexBeg:IntIndexEnd-1,*)) ; make the image s = SIZE(smallimg) image3d = BYTARR(3, s(1), s(2)) image3d(0, *, *) = red(smallimg) image3d(1, *, *) = grn(smallimg) image3d(2, *, *) = blu(smallimg) ; set up the filename filename = data_directory+'images\'+prefix+swathname+'_'+fieldname+'_'+strtrim(i+1,2)+'.png' ; write the png file WRITE_PNG, filename, image3d, r,g,b ; want jpg? ;filename = data_directory+'images\'+prefix+swathname+'_'+fieldname+'_'+strtrim(i+1,2)+'.jpg' ;WRITE_JPEG, filename, image3d, TRUE=1 endfor print, "Finished!" end ;==============================================================================