PRO rdmeandk,cam,exp,img,nointeractive=nointeractive,debug=debug ; ; Given camera number and exposure time (1, 10, 60, 120, 180 s ; only!), this procedure returns the appropriate mean dark image. ; Otherwise, it reads in the appropriate zero-time count and rate ; images and generates a synthetic dark frame for the requested ; exposure time. Let's see how it works! ; ; Initialize OS-specific items @isitdos IF (exp EQ 1) OR (exp EQ 10) OR (exp EQ 60) OR (exp EQ 120) OR $ (exp EQ 180) THEN BEGIN stexp=STRTRIM(FIX(exp),2) dkname=STRING(dkroot,dd,cc,cam,dd,cam,dc,exp,meantag $ ,FORMAT='(A,2A1,I1,A1,"dk",I1,A1,I3.3,"s",A)') df=FINDFILE(dkname,COUNT=nd) IF nd GT 1 THEN BEGIN IF NOT KEYWORD_SET(nointeractive) THEN BEGIN FOR j=0,nd-1 DO PRINT,j,df(j),FORMAT='(I1,2X,A)' PRINT,'Enter the number of the correct file' READ,ndc ENDIF ELSE ndc=0 dkname=df(ndc) ENDIF ELSE dkname=df(0) OPENR,dkunit,dkname,/GET_LUN fs=FSTAT(dkunit) IF fs.SIZE EQ 65536 THEN img=BYTARR(256,256) $ ELSE img=INTARR(256,256) READU,dkunit,img CLOSE,dkunit FREE_LUN,dkunit ENDIF ELSE BEGIN PRINT,STRING(STRTRIM(exp,2),cam $ ,FORMAT='("Synthesizing ",A,"-s dark frame for camera ",I1)') ; first read in the zero-time count image template=STRING(dkroot,dd,cc,cam,dd,cam,biastag $ ,FORMAT='(A,A1,A,I1,A1,"dk",I1,A)') biasname=FINDFILE(template,count=nb) bias=BYTARR(256,256) IF nb GT 0 THEN BEGIN OPENR,dkunit,biasname(0),/GET_LUN READU,dkunit,bias CLOSE,dkunit FREE_LUN,dkunit ENDIF ELSE PRINT,'Can''t find the bias file! Faking it...' ; next read in the count rate image (DN/sec) template=STRING(dkroot,dd,cc,cam,dd,cam,ratetag $ ,FORMAT='(A,A1,A,I1,A1,"dk",I1,A)') ratename=FINDFILE(template,count=nr) rate=BYTARR(256,256) IF nr GT 0 THEN BEGIN OPENR,dkunit,ratename(0),/GET_LUN READU,dkunit,rate CLOSE,dkunit FREE_LUN,dkunit ENDIF ELSE PRINT,'Can''t find the rate file! Faking it...' ; then synthesize the dark frame for the requested exposure time img=bias+exp*FLOAT(rate)/200. IF MAX(img) LE 255. THEN img=BYTE((img+0.5)>0) $ ELSE img=FIX((img+0.5)>0) ; show what the synthetic image looks like ; WINDOW,2,TITLE='Synthetic '+STRTRIM(exp,2)+'-s dark frame' $ ; ,XSIZE=256,YSIZE=256 ; TVSCL,img<255 ; WAIT,5 ; WDELETE,2 ENDELSE IF KEYWORD_SET(debug) THEN STOP RETURN END