; ; This program processes the two dimensional clutter flag and ; writes it to the output netcdf file. Determines the number ; of total data points, the number of cloudy data points, ; mode, minimum, and maximum clutter flag value for each time ; interval ; pro one_dimensional_variable_column_cfrac common ncdf_file, oldcdfname,twoD,time_dim_name,height_dim_name,$ height_var_name,avgfilename,curdate common old_grid, num_times,num_heights,base_time,time_offset,$ height,site,files,num_files,num_days common new_grid, numtimes,newtimes, numheights,newheights,$ timespacing,heightspacing common bracket, startbst common data, avg_data ; ; Loop through all the matching files in the directory ; m=-1 ;counts number of cdf files without the variable p=-1 ;counts number of cdf files with variable j=-1 ;counts number of cdf files for i = 0, num_files-1 do begin ; ; Don't try to process any gif files that may be in the directory ; if strpos(files[i],'gif') eq -1 and $ strpos(files[i],'png') eq -1 then begin j=j+1 print,i,j,files[i] ; ; Open the netcdf file ; cdf_id=ncdf_open(files[i]) ; ; Get the dimension id's ; time_did=ncdf_dimid(cdf_id,time_dim_name) height_did=ncdf_dimid(cdf_id,height_dim_name) ; ; Get the dimensions ; ncdf_diminq,cdf_id,time_did,charstring,ntimes ncdf_diminq,cdf_id,height_did,charstring,nheights ; ; Create array for nodata value ; dummy=make_array(ntimes,nheights,/float,value=-8888) ; ; Get the variable id ; clutter_id=ncdf_varid(cdf_id,'qc_ReflectivityClutterFlag') artifact_id=ncdf_varid(cdf_id,'qc_RadarArtifacts') ; ; Get the variable if it exists ; if clutter_id ne -1 then begin print,'Processing 2-D ','qc_ReflectivityClutterFlag' ncdf_varget, cdf_id, clutter_id, clutter clutter=transpose(clutter) p=p+1 endif else begin print, 'Variable not in this file' m=m+1 endelse if artifact_id ne -1 then begin print,'Processing 2-D ','qc_RadarArtifacts' ncdf_varget, cdf_id, artifact_id, artifact artifact=transpose(artifact) endif else begin print, 'Variable not in this file' endelse ; ; If it is the first real variable get the attributes ; if p eq 0 and clutter_id ne -1 then begin print, 'first variable, getting the attributes' datainfo=ncdf_varinq(cdf_id, clutter_id) ;inquire about the variable numatts=datainfo.natts ;number of attributes assigned to the variable parts=strsplit(files[i],'/',/extract) part=strsplit(parts[5],'.',/extract) origfile=part[0]+'.'+part[1] ; ; Store the attribute names ; dataatr=strarr(numatts) ;string array to hold attribute names for k=0,numatts-1 do begin ; Returns the name of the attribute dataatr[k]=ncdf_attname(cdf_id, clutter_id, k) endfor endif ; ; Create the data array ; if p eq 0 and m lt 0 and clutter_id ne -1 then begin print,'first file and variable exists' combined_clutter=clutter combined_artifact=artifact endif else if p ge 0 and clutter_id ne -1 then begin print,'adding on existing variable' combined_clutter=[combined_clutter,clutter] combined_artifact=[combined_artifact,artifact] endif else if p lt 0 and m eq 0 and clutter_id eq -1 then begin print,'first file and variable doesnt exist' combined_clutter=dummy combined_artifact=dummy endif else if m ge 0 and clutter_id eq -1 then begin print,'adding on dummy variable' combined_clutter=[combined_clutter,dummy] combined_artifact=[combined_artifact,dummy] endif ; ; Close the netcdf file ; ncdf_close,cdf_id endif ;end of not a gif file endfor ;end of looping though the matching files print,'finished reading in the data' ; ; Continue processing data because some data exists ; if j gt -1 and p gt -1 then begin ; ; Manipulate the big data array ; clutter=combined_clutter artifact=combined_artifact combined_clutter=0 ;release memory combined_artifact=0 ;release memory clutter=fix(clutter) artifact=fix(artifact) ; ; Find the column cloud fraction of data in timespacing intervals ; cloudy_profile=make_array(numtimes,/float,value=0.0) for t=0,numtimes-2 do begin ;loop through time intervals result_int=where(time_offset ge newtimes[t] and $ time_offset lt newtimes[t+1],count_int) if count_int gt 0 then begin clutter_int=clutter[result_int,*] artifact_int=artifact[result_int,*] cloudy_profile[t]=0 for i=0,count_int-1 do begin ;loop through the profiles clutter_profile=clutter_int[i,*] artifact_profile=artifact_int[i,*] ; change the clutter array to reflect the clutter-artifact conditions result=where(clutter_profile eq 2 and artifact_profile eq 1,count) if count ne 0 then clutter_profile[result]=-1 result=where(clutter_profile eq 3 and artifact_profile eq 0,count) if count ne 0 then clutter_profile[result]=-1 result=where(clutter_profile eq 3 and artifact_profile eq 6,count) if count ne 0 then clutter_profile[result]=-1 result=where(clutter_profile eq 0 and artifact_profile eq 0,count) if count ne 0 then clutter_profile[result]=-1 result=where(clutter_profile ne -1 and $ clutter_profile ne -8888 and $ clutter_profile ne -9999,count_cld) if count_cld gt 0 then cloudy_profile[t]=cloudy_profile[t]+1 ;print,t,count_cld,cloudy_profile[t] endfor cloudy_profile[t]=cloudy_profile[t]/count_int endif else cloudy_profile[t]=-9999 ;print, t,cloudy_profile[t] endfor ; ; Find the column cloud fraction for the last time interval ; result_int=where(time_offset ge newtimes[numtimes-1] and $ time_offset lt (newtimes[numtimes-1]+timespacing),count_int) if count_int gt 0 then begin clutter_int=clutter[result_int,*] artifact_int=artifact[result_int,*] cloudy_profile[numtimes-1]=0 for i=0,count_int-1 do begin ;loop through the profiles clutter_profile=clutter_int[i,*] artifact_profile=artifact_int[i,*] ; change the clutter array to reflect the clutter-artifact conditions result=where(clutter_profile eq 2 and artifact_profile eq 1,count) if count ne 0 then clutter_profile[result]=-1 result=where(clutter_profile eq 3 and artifact_profile eq 0,count) if count ne 0 then clutter_profile[result]=-1 result=where(clutter_profile eq 3 and artifact_profile eq 6,count) if count ne 0 then clutter_profile[result]=-1 result=where(clutter_profile eq 0 and artifact_profile eq 0,count) if count ne 0 then clutter_profile[result]=-1 result=where(clutter_profile ne -1 and $ clutter_profile ne -8888 and $ clutter_profile ne -9999,count_cld) if count_cld gt 0 then cloudy_profile[numtimes-1]=cloudy_profile[numtimes-1]+1 ;print,numtimes-1,count_cld,cloudy_profile[numtimes-1] endfor cloudy_profile[numtimes-1]=cloudy_profile[numtimes-1]/count_int endif else cloudy_profile[numtimes-1]=-9999 ;print,numtimes-1,cloudy_profile[numtimes-1] ; ; Convert to percent ; result=where(cloudy_profile ne -9999,count) if count gt 0 then cloudy_profile[result]=cloudy_profile[result]*100. ;************************************** ; Write to the output file ;************************************** ; ; Open the netcdf file ; avg_id=ncdf_open(avgfilename, /write) ; ; Get the variable dimensions ; time_id=ncdf_dimid(avg_id,'time') height2_did=ncdf_dimid(avg_id,'height') ; ; Try to get the column_cfrac variable. ; If the variable already exists, then ; don't try to write it. This will ; screw up the file. ; varid=ncdf_varid(avg_id,'column_cfrac') ; ; Only write the variable if it doesn't ; already exist. ; if varid eq -1 then begin ; ; Put the netcdf file into define mode ; ncdf_control, avg_id, /redef ; ; Define variable ; column_cfrac_id=ncdf_vardef(avg_id,'column_cfrac',time_id) ; ; Define attributes ; ncdf_attput,avg_id,column_cfrac_id,'long_name','column cloud fraction' ncdf_attput,avg_id,column_cfrac_id,'units','%' ncdf_attput,avg_id,column_cfrac_id,'comment1','% of height profiles in the time interval' ncdf_attput,avg_id,column_cfrac_id,'comment2','containing any hydrometeor' ncdf_attput,avg_id,column_cfrac_id,'original data source file ',origfile ; ; Change from define mode to data mode ; ncdf_control, avg_id, /endef ; ; Write variable ; ncdf_varput,avg_id,column_cfrac_id,cloudy_profile ; ; Close the netcdf file ; ncdf_close, avg_id endif ;column_cfrac already exists in one of the files. endif ;variable does exist in one of the files return end