2D Histogram error [message #94293] |
Fri, 31 March 2017 04:58  |
mitali1203
Messages: 4 Registered: March 2017
|
Junior Member |
|
|
Hello,
I am a newbie to IDL. I am currently working on event files (which are similar to FITS files) in IDL. I have written a code which will sort out event files from a list of directories and then compute detector plane histograms (DPH) (2D Histograms, basically) for each of those event files. In the process, I have also set up a 4-D array (4,25,64,64) and run a 'for' loop to save all DPH's to this array.
However, I keep getting this error "Expression must be an array in this context:H", at the line where I have used 'hist_2d' function. I heard this is because there may not be any events in that particular file; hence IDL does not have any data values to create histogram. I guess I have to put a conditional loop (if..else) in order to detect such null event files. I am getting confused as to how this problem can be solved. It would be of great help if someone can troubleshoot this problem.
Here is the code I have written- The line containing hist_2d function is where the error is-
function compute_dph, infile, outpath
dph=fltarr(4,25,64,64)
for quad=0,3 do begin
data=mrdfits(infile,quad+1, /unsigned,/dscale)
for ebin=0,24 do begin
index=where(data.energy gt 5+ebin*10 and data.energy le 5+(ebin+1)*10)
;result= sxpar(H,'NAXIS2')
;if result = 0 then dph(0,0,0,0)=qdph
;endelse
qdph=hist_2d(data(index).detx,data(index).dety,MAX1=63,MAX2= 63,MIN1=0,MIN2=0)
dph(quad,ebin,*,*)=qdph
;tv,bytscl(rebin(qdph,320,320,/sample))
endfor
endfor
names=strsplit(infile,'/', /EXTRACT)
stem=names(N_ELEMENTS(names)-1)
outfile=strmid(stem,0,srtlen(stem)-3)+'dph'
outfile=outpath+outfile
save,dph,filename=outfile
print,infile,outpath
return,0
end
|
|
|