C+ C NAME: C smei_cal_bin C PURPOSE: C Rebin engineering mode frame (mode 0) to C pseudo science=mode frame (mode 1 and 2) C CATEGORY: C camera/for/cal C CALLING SEQUENCE: subroutine smei_cal_bin(mode,hdr,frame,hdr_,frame_) C INPUTS: C OUTPUTS: C CALLS: C Time2Str, smei_frm_c3mask_active, smei_hdr_str C smei_hdr_time C ArrR8Copy, ArrR4TimesConstant, Say C INCLUDE: include 'smei_frm_hdr.h' include 'smei_frm_layout.h' C PROCEDURE: C MODIFICATION HISTORY: C JUN-2008, Paul Hick (UCSD/CASS; pphick@ucsd.edu) C- integer mode double precision hdr (*) real frame (*) double precision hdr_ (*) real frame_(*) character cSay*12 /'smei_cal_bin'/ integer tt(2) integer flat_enabled integer camera integer Time2Str integer smei_frm_c3mask_active character ctime*(SMEI__UT_FORMAT_LEN) character cmask*(SMEI__UT_FORMAT_LEN) character cStr*512 call ArrR8Copy(SMEI__HDR_N,hdr,hdr_) call smei_hdr_str(SMEI__HDR_TLM_FILE, hdr, cStr) nbin = 2**mode nx = SMEI__FRM_NX/nbin ny = SMEI__FRM_NY/nbin hdr_(SMEI__HDR_MODE ) = dble(mode) hdr_(SMEI__HDR_NAXES ) = dble(nx) hdr_(SMEI__HDR_NAXES+1 ) = dble(ny) hdr_(SMEI__HDR_BASE_DONE ) = 0.0d0 hdr_(SMEI__HDR_BASE_OK ) = 0.0d0 hdr_(SMEI__HDR_PEDESTAL ) = 0.0d0 hdr_(SMEI__HDR_DARK_MEDIAN ) = 0.0d0 hdr_(SMEI__HDR_DARK_MEAN ) = 0.0d0 hdr_(SMEI__HDR_PED_SIGMA ) = 0.0d0 hdr_(SMEI__HDR_DARK_SIGMA ) = 0.0d0 hdr_(SMEI__HDR_SQUARE ) = 0.0d0 hdr_(SMEI__HDR_CENTER ) = 0.0d0 hdr_(SMEI__HDR_N_PEDESTAL ) = 0.0d0 hdr_(SMEI__HDR_N_DARK_CURRENT ) = 0.0d0 hdr_(SMEI__HDR_N_SATURATED ) = 0.0d0 hdr_(SMEI__HDR_N_POS_MEASLES ) = 0.0d0 hdr_(SMEI__HDR_N_BIG_MEASLES ) = 0.0d0 hdr_(SMEI__HDR_N_PIXSUM ) = 0.0d0 hdr_(SMEI__HDR_N_PIXDIF ) = 0.0d0 hdr_(SMEI__HDR_PIXSUM ) = 0.0d0 hdr_(SMEI__HDR_PIXDIF ) = 0.0d0 call smei_hdr_str(-SMEI__HDR_CAL_PATTERN,hdr_,' ') call smei_hdr_str(-SMEI__HDR_ORB_PATTERN,hdr_,' ') hdr_(SMEI__HDR_VERSION ) = 1.0d0 do j=1,ny do i=1,nx k = (j-1)*nx+i frame_(k) = 0.0 icnt = 0 i0 = (i-1)*nbin j0 = (j-1)*nbin do jj=j0+1,j0+nbin do ii=i0+1,i0+nbin kk = (jj-1)*SMEI__FRM_NX+ii if (frame(kk) .ne. 0.0) then frame_(k) = frame_(k)+frame(kk) icnt = icnt+1 end if end do end do if (icnt .ne. 0) frame_(k) = frame_(k)/icnt end do end do call smei_hdr_time(hdr_,tt) i = Time2Str(SMEI__UT_FORMAT,tt,ctime) flat_enabled = nint(hdr_(SMEI__HDR_FLAT_ENABLED)) camera = nint(hdr_(SMEI__HDR_CAMERA )) ! "Bad-pixel" mask is used ONLY for camera 3 if (camera .eq. 3) then MaskActive = smei_frm_c3mask_active(0,ctime,flat_enabled,cmask,fudge) else MaskActive = 0 end if ! Make various adjustments to CCD readout. ! (these are the inverse of the adjustment made in ! smei_frm_read when reading the frame). if (flat_enabled .eq. 1) then ! If the onboard flat field is enabled then the frame is ! multiplied by 0.75 onboard, BUT ... ! the factor 0.75 is NOT applied when a c3 "bad pixel" ! mask is active. ! (Note that for cameras 1 and 2 always MaskActive=0) if (MaskActive .eq. 0) then ! "Bad pixel" mask NOT active call Say(cSay,'I','apply','0.75 headroom') call ArrR4TimesConstant(nx*ny,frame_,SMEI__HEADROOM,frame_) end if end if ! For camera 3 in mode 1 the gain increases by a factor 2 after ! 24 Feb 2005, 17:30 UT. ! Multiply by 0.5 here to compensate for this, BUT ... ! ... NOT when the c3 "bad pixel" mask is active. if (camera .eq. 3 .and. mode .eq. 1) then if (MaskActive .eq. 0) then if (ctime .gt. SMEI__UT_C3_GAIN_CHANGE) then call Say(cSay,'I','apply','factor 2.0 gain increase') call ArrR4TimesConstant(nx*ny,frame_,2.0,frame_) end if end if end if return end