C+ C NAME: C smei_cal_add C PURPOSE: C Accumulutes information for engineering mode pattern calculation C CATEGORY: C ucsd/camera/for/lib C CALLING SEQUENCE: subroutine smei_cal_add(cut, nx, ny, frame, pattern, count, count_cr) C INPUTS: C cut real threshold for cosmic ray determination C nx integer horizontal frame size C ny integer vertical frame size C frame(nx,ny) real frame data with pedestal already subtracted C pattern(nx,ny) real accumulates pattern data C count (nx,ny) real counts number of frames contributing to each pixel C in the pattern. C !! Count is initialized by caller (href=smei_cal_build=). C count_cr integer counts # pixels excluded because they are suspected C to be cosmic rays. C !! count_cr must be initialized to a negative value C !! to make sure that smei_add_pat is initialized properly. C !! count_cr is set to zero as part of the initialization. C OUTPUTS: C pattern(nx,ny) real updated pattern C count (nx,ny) real updated count data C count_cr integer updated cosmic ray count C CALLS: C Say, Str2Str, Int2Str, Flt2Str, BadR4 C INCLUDE: include 'smei_frm_layout.h' C REMARK: C In Andys original program the 'cut' value used was twice as big as here, but was C multiplied by 0.5 when the cut was applied. The factor 0.5 has been absorbed here C in the value for 'cut'. C PROCEDURE: C The pattern is calculated in pedestal, dark current and covered pixels. C Only pixels that are consistently flagged as bad (probably by smei_frm_clean) C will not receive a pattern value. C Currently (Jun-2004) these are the four leading columns in the eng mode frames C and 8 pixels at the top right of the CCD, for a total of 4*256+8=1032 pixels C with no pattern. C MODIFICATION HISTORY: C JUN-2004, Paul Hick (UCSD/CASS; pphick@ucsd.edu) C- real cut integer nx integer ny real frame (nx,ny) ! Already has pedestal subtracted real pattern(nx,ny) real count (nx,ny) ! Needs to be initialized by caller integer count_cr ! Needs to be initialized by caller character cSay*12 /'smei_cal_add'/ integer Str2Str integer Flt2Str character cStr*80 integer nfrm /0/ save nfrm bad = BadR4() if (count_cr .lt. 0) then nfrm = 0 count_cr = 0 end if nfrm = nfrm+1 do j=1,ny do i=1,nx val = frame(i,j) if ( val .ne. bad ) then cnt = count(i,j) if (cnt .eq. 0) then if (nfrm .gt. 1) call Say(cSay,'W','pixel','initialized, but not in first frame') pat = val cnt = 1.0 else count_old = count_cr pat = pattern(i,j) pat_now = pat/cnt dval = val-pat_now ! Difference with average pattern accumulated thus far if (dval .gt. cut) then ! CR detected; increase counter count_cr = count_cr+1 !2nd frame rules if less by 100 e- or more else if (cnt .eq. 1.0 .and. dval .lt. -cut) then count_cr = count_cr+1 ! Pixel in previous frame was CR pat = val else pat = pat+val cnt = cnt+1.0 end if if (count_cr .ne. count_old) then if (i .lt. SMEI__DRK_COL(1) .or. i .gt. SMEI__DRK_COL(SMEI__DRK_NCOL)) then n = 0 n = n+Str2Str('in virtual pixel',cStr(n+1:))+1 n = n+Int2Str( i , cStr(n+1:)) n = n+Str2Str(',' ,cStr(n+1:)) n = n+Int2Str( j , cStr(n+1:)) n = n+Str2Str(' @' ,cStr(n+1:))+1 n = n+Flt2Str(val , 3 ,cStr(n+1:))+1 n = n+Str2Str(', expect',cStr(n+1:))+1 n = n+Flt2Str(pat_now , 3,cStr(n+1:)) n = n+Str2Str(', cut' ,cStr(n+1:))+1 n = n+Flt2Str(dval, 3 ,cStr(n+1:)) ! call Say(cSay,'W','CR', cStr) end if end if end if pattern(i,j) = pat count (i,j) = cnt end if end do end do return end