C+ C NAME: C darkr C PURPOSE: C To determine the dark current - this is removed from each data frame C Note the dark current, to be distinguished from "pedestal" is determined C from "covered pixels", not "empty pixels". C CATEGORY: C Data processing C CALLING SEQUENCE: C call darkr(mode,ic,ifm,id,jd,iframemask,frame,dark) C INPUTS: C mode integer 1 - "Engineering" frame records, no onboard binning C 2 - "Hi-res" frame records, binned 2 x 2 pixels C 4 - "Normal Data" frame records, binned 4 x 4 pixels C ic integer Camera 0,1,2, or 3 C ifm integer frame mask mode - 0 mask not imposed, 1 frame mask imposed C id integer data frame max x-value (along rows) C jd integer data frame max y-value (down columns) C iframemask(id,jd) integer data mask - 0 data are invalid 1 data are valid C frame(id,jd) real data frame that needs to have its pedestal removed C OUTPUTS: C frame(id,jd) real data frame that now has its pedestal removed C dark real Dark current value removed from the data frame C CALLS: C PROCEDURE: C Uses covered pixels to determine the dark current C The first row is skipped for RAL (600 rows) data C MODIFICATION HISTORY: C Dec, 2002 B. Jackson (UCSD), Jan, 2003 A. Buffington (UCSD) C Feb, 2003 A. Smith (UCSD) C- c Here we have introduced the convention [i,j]= along [rows,columns], to render c compatible with the convention in C. Let i always here be the "inner loop". c subroutine darkr(mode,ic,ifm,id,jd,iframemask,frame,dark,idarkcr) real*4 frame(id,jd),dark,darkcnt,crmin integer*4 i,j,id,jd, idarkcr,ibad integer*4 iframemask(jd,id) data crmin / 27.78 / !500 electron threshold c data crmin / 11.11 / !200 electron threshold c darkcnt = 0.0 dark=0.0 idarkcr=0 if(mode.eq.1.and.ic.eq.0) then C C Remove the known dark current from the data frame in Engineering mode for Camera 0 (RAL data format) C Here id = 1280 and jd = 600 C do j=2,600 do i=1266,1269 !These limits are compatible with those below dark = dark + frame(i,j) darkcnt = darkcnt + 1.0 end do do i=18,21 !These limits are compatible with those below dark = dark + frame(i,j) darkcnt = darkcnt + 1.0 end do end do end if C if(mode.eq.2.and.ic.eq.0) then C C Remove the known dark current from the 2 by 2 pixel binning mode, Camera 0 C c (This depends upon how the camera 0 data get binned...) end if C if(mode.eq.4.and.ic.eq.0) then C C Remove the known dark current from the 4 by 4 pixel binning mode, Camera 0 C c (This depends upon how the camera 0 data get binned...) end if C if(mode.eq.1.and.ic.ge.1) then C C Remove the known dark current from the data frame in Engineering mode for Flight Cameras (GSE format) C C Here id = 1272 and jd = 256; this rectangle is shifted relative to Camera 0 (RAL format) C by +1 pixel in i, and in j by +61, +55, and +57 rows respectively for Cameras 1, 2, and 3 C do j=1,256 do i=1265,1268 ibad=0 if(frame(i,j).ge.crmin)ibad=1 if(ibad.eq.0)then dark = dark + frame(i,j) darkcnt = darkcnt + 1.0 else idarkcr=idarkcr+1 c jarg=1+nint(4.0*4.5*frame(i,j)/50.) !50 electron bins c if(jarg.gt.250)jarg=250 c print 1000,i,j,frame(i,j) c ihist(jarg)=ihist(jarg)+1 endif end do do i=17,20 ibad=0 if(frame(i,j).ge.crmin)ibad=1 if(ibad.eq.0)then dark = dark + frame(i,j) darkcnt = darkcnt + 1.0 else idarkcr=idarkcr+1 c jarg=1+nint(4.0*4.5*frame(i,j)/50.) !50 electron bins c if(jarg.gt.250)jarg=250 c print 1000,i,j,frame(i,j) c ihist(jarg)=ihist(jarg)+1 endif end do end do endif C if(mode.eq.2.and.ic.ge.1) then C Remove the known dark current from the 2 by 2 pixel binning mode for Flight Cameras (presumed format) C Here id = 636 and jd = 128 c This quick version, iframemask disabled C do j=1,128 do i=633,634 ibad=0 if(frame(i,j).ge.crmin)ibad=1 if(ibad.eq.0)then dark = dark + frame(i,j) darkcnt = darkcnt + 1.0 else idarkcr=idarkcr+1 c jarg=1+nint(4.0*4.5*frame(i,j)/50.) !50 electron bins c if(jarg.gt.250)jarg=250 c print 1000,i,j,frame(i,j) 1000 format('Cosmic ray in covered pixel at ',2i4,', ',f6.0,' ADUs') c ihist(jarg)=ihist(jarg)+1 endif end do do i=9,10 ibad=0 if(frame(i,j).ge.crmin)ibad=1 if(ibad.eq.0)then dark = dark + frame(i,j) darkcnt = darkcnt + 1.0 else idarkcr=idarkcr+1 c print 1000,i,j,frame(i,j) endif end do end do endif C if(mode.eq.4.and.ic.ge.1) then C C Remove the known dark current from the 4 by 4 pixel binning mode for Flight Cameras (presumed format) C Here id = 318 and jd = 64 C do j=1,64 do i=317,317 dark = dark + frame(i,j) darkcnt = darkcnt + 1.0 end do do i=5,5 dark = dark + frame(i,j) darkcnt = darkcnt + 1.0 end do end do end if c if(darkcnt.eq.0)then print *,"No dark current: mode, ic = ",mode,ic return endif c dark=dark/darkcnt c if(ifm.eq.0)then do j=1,jd do i=1,id if(frame(i,j).gt.0.)frame(i,j) = frame(i,j) - dark end do end do else do j=1,jd do i=1,id if(iframemask(i,j).ne.0.and.frame(i,j).gt.0.)frame(i,j) = frame(i,j) - dark end do end do endif return end