C+ C NAME: C smei_frm_ok C PURPOSE: C Process command line arguments related to frame selection C CALLING SEQUENCE: logical function smei_frm_ok(cArg,cName,hdr,hdrok,iSilent) C INPUTS: C cName*(*) character file name of frame C cArg*(*) character command line keywords C hdr(*) double precision frame header array C iSilent integer higher value suppresses more C informational messages C INCLUDE: include 'smei_frm_hdr.h' include 'smei_frm_hdrok.h' C CALLS: C ForeignI4Arg, ForeignR8ArgN, ForeignArgSet, Say, Str2Str, Int2Str, Dbl2Str C ArrR8Zero C PROCEDURE: C bodyexcl(4,3) double precision C defines exclusion area around optical axis for Sun, Moon C and Venus: if Sun, Moon or Venus are inside the exclusion C area the frame will not be used for indexing. C The exclusion area is defined in terms of C theta-x = atan(rx,rz) and theta-y=atan(ry/rz), where C (rx,ry,rz) is the unit vector to Sun, Moon, Venus in the C camera coordinate frame C If C bodyexcl(1,i) <= theta_x <= bodyexcl(2,i) C bodyexcl(3,i) <= theta_y <= bodyexcl(4,i) C then the corresponding frame is excluded, where C i=0 is the Sun, i=1 is the Moon, i=2 is Venus. C The values for the Sun are extracted from cmd line arg C -sunbox=tx1,tx2,ty1,ty2. The moon is extracted C from -moonbox=tx1,tx2,ty1,ty2, and Venus from C -venusbox=tx1,tx2,ty1,ty2 (all angles in degrees). C Setting keyword -avoid_moon is equivalent to C -moonbox=-42,42,-6.5,6.5 degrees. C MODIFICATION HISTORY: C MAY-2005, Paul Hick (UCSD/CASS) C JUL-2006, Paul Hick (UCSD/CASS) C Added check for bad quaternions. C NOV-2008, Paul Hick (UCSD/CASS) C Added default box for avoiding Sun. C Fixed bug in processing of avoid* keywords. C- character cArg *(*) character cName*(*) double precision hdr (*) double precision hdrok (*) integer iSilent character cSay*6 /'frm_ok'/ character cStr*100 ! === ! Functions logical ForeignArgSet integer Str2Str integer Dbl2Str ! === ! Saved quantities are filled on the first call logical bFirst /.TRUE./ save bFirst logical bDefaultTest save bDefaultTest integer nped_min save nped_min integer ndark_min save ndark_min integer nshutter_skip save nshutter_skip integer nshutter_count save nshutter_count logical bAvoidBody(SMEI__HDROK_NBODY) save bAvoidBody double precision bodyexcl(SMEI__HDROK_NBOX,SMEI__HDROK_NBODY) save bodyexcl ! ==== double precision box(SMEI__HDROK_NBOX) logical bShutterClosed character cbody*10 double precision rx double precision ry double precision rz double precision tx double precision ty double precision datan2d bShutterClosed = nint( hdr(SMEI__HDR_SHUTTER) ) .eq. 0 if (bFirst) then bFirst = .FALSE. ! Saved call ForeignI4Arg(cArg,'nped_min' ,0,nped_min ) ! Saved call ForeignI4Arg(cArg,'ndark_min',0,ndark_min) ! Saved nped_min = max(nped_min ,0) ndark_min = max(ndark_min,0) bDefaultTest = nped_min .eq. 0 .and. ndark_min .eq. 0 ! Saved if (bDefaultTest) then call Say(cSay,'I','using','default test for frame selection') else nped_min = max(nped_min ,1) ! Must be at least one ndark_min = max(ndark_min,1) i = 0 i = i+Str2Str('user-defined test' , cStr(i+1:)) i = i+Str2Str('#minimum pedestal count:', cStr(i+1:))+1 i = i+Int2Str(nped_min , cStr(i+1:)) i = i+Str2Str('#minimum dark current count:', cStr(i+1:))+1 i = i+Int2Str(ndark_min , cStr(i+1:)) call Say(cSay,'I','key',cStr) end if ! bDefaultTest call ForeignI4Arg(cArg,'nshutter_open_skip',0,nshutter_skip) nshutter_skip = max(nshutter_skip,0) ! Saved if (nshutter_skip .ne. 0) then i = 0 i = i+Str2Str('skipping' , cStr(i+1:))+1 i = i+Int2Str(nshutter_skip , cStr(i+1:))+1 i = i+Str2Str('frames after shutter closes', cStr(i+1:)) call Say(cSay,'I','key',cStr) end if ! To avoid loosing 'shutter-open' frames when the first frame already ! is 'shutter-open' set the shutter-open counter to the skip value. if (.not. bShutterClosed) nshutter_count = nshutter_skip ! Check for exclusion areas around optical axis for sun, moon, venus do ibody=1,SMEI__HDROK_NBODY cbody = 'avoid'//SMEI__HDROK_BODIES(ibody) ! Name of keyword ! First check for -avoidxxx=tx1,tx2,ty1,ty2 ! Accept result only if exactly nbox=4 numbers are found i = SMEI__HDROK_NBOX call ForeignR8ArgN(cArg,cbody,0.0d0,i,bodyexcl(1,ibody)) ! Saved if (i .ne. SMEI__HDROK_NBOX) then ! If not nbox numbers found, check for presence of -avoidxxx ! If found then set default box for moon. For Sun and Venus abort ! If not found then set box to bad (= no box applied) if (ForeignArgSet(cArg,cbody)) then if (ibody .eq. SMEI__HDROK_MOON) then ! Moon bodyexcl(1,ibody) = -42.0d0 ! Set default excl area bodyexcl(2,ibody) = 42.0d0 bodyexcl(3,ibody) = -6.5d0 bodyexcl(4,ibody) = 6.5d0 else if (ibody .eq. SMEI__HDROK_SUN) then ! Sun bodyexcl(1,ibody) = -58.0d0 ! Set default excl area bodyexcl(2,ibody) = 58.0d0 bodyexcl(3,ibody) = -20.0d0 bodyexcl(4,ibody) = 20.0d0 else call Say(cSay,'E','bad '//cbody,cArg) end if else call ArrR8Zero(SMEI__HDROK_NBOX,bodyexcl(1,ibody)) end if end if bAvoidBody(ibody) = bodyexcl(1,ibody) .ne. 0.0d0 .or.! Saved & bodyexcl(2,ibody) .ne. 0.0d0 .or. & bodyexcl(3,ibody) .ne. 0.0d0 .or. & bodyexcl(4,ibody) .ne. 0.0d0 if (bAvoidBody(ibody)) then i = 0 i = i+Str2Str('theta-x = [' , cStr(i+1:)) i = i+Dbl2Str(bodyexcl(1,ibody),2 , cStr(i+1:)) i = i+Str2Str(',' , cStr(i+1:)) i = i+Dbl2Str(bodyexcl(2,ibody),2 , cStr(i+1:)) i = i+Str2Str('], theta-y = [' , cStr(i+1:)) i = i+Dbl2Str(bodyexcl(3,ibody),2 , cStr(i+1:)) i = i+Str2Str(',' , cStr(i+1:)) i = i+Dbl2Str(bodyexcl(4,ibody),2 , cStr(i+1:)) i = i+Str2Str('] degrees' , cStr(i+1:)) call Say(cSay,'I',cbody,cStr) end if end do ! Set up info to be added to skymap file (in smei_htm_fts) hdrok(SMEI__HDROK_NPED_MIN ) = dble(nped_min) hdrok(SMEI__HDROK_NDARK_MIN ) = dble(ndark_min) hdrok(SMEI__HDROK_SHUTTER_SKIP) = dble(nshutter_skip) call ArrR8Copy(SMEI__HDROK_NBOX*SMEI__HDROK_NBODY,bodyexcl,hdrok(SMEI__HDROK_BODYEXCL)) end if ! if (bFirst) then ! Count number of frames with shutter open since the last frame with ! shutter closed. The shutter_open counter only increases if the shutter is open. if (bShutterClosed) nshutter_count = 0 nshutter_count = nshutter_count+nint( hdr(SMEI__HDR_SHUTTER) ) ! First check whether Sun, Moon, Venus are too close to optical axis ! (test is only done if bAvoidBody(ibody)=.TRUE.) smei_frm_ok = .TRUE. ibody = 1 do while (ibody .le. SMEI__HDROK_NBODY .and. smei_frm_ok) if (bAvoidBody(ibody)) then if (ibody .eq. SMEI__HDROK_SUN) then ! Sun rx = hdr( SMEI__HDR_SUN +0 ) ry = hdr( SMEI__HDR_SUN +1 ) rz = hdr( SMEI__HDR_SUN +2 ) else if (ibody .eq. SMEI__HDROK_MOON) then ! Moon rx = hdr( SMEI__HDR_MOON +0 ) ry = hdr( SMEI__HDR_MOON +1 ) rz = hdr( SMEI__HDR_MOON +2 ) else if (ibody .eq. SMEI__HDROK_VENUS) then ! Venus rx = hdr( SMEI__HDR_VENUS+0 ) ry = hdr( SMEI__HDR_VENUS+1 ) rz = hdr( SMEI__HDR_VENUS+2 ) else call Say(cSay,'E','undefined','body for exclusion area') end if tx = datan2d(rx,rz) ty = datan2d(ry,rz) ! Shouldn't we be taking the phase into account here for Moon and Venus? smei_frm_ok = .not. ( bodyexcl(1,ibody) .lt. tx .and. tx .lt. bodyexcl(2,ibody) .and. & bodyexcl(3,ibody) .lt. ty .and. ty .lt. bodyexcl(4,ibody) ) end if if (smei_frm_ok) ibody = ibody+1 end do ! Now do all the other tests if (.not. smei_frm_ok) then if (iSilent .le. 1) then i = 0 i = i+Str2Str('skip; '// & SMEI__HDROK_BODIES(ibody)(:itrim(SMEI__HDROK_BODIES(ibody)))// & ' too close;',cStr(i+1:)) i = i+1 i = i+Str2Str('tx=' ,cStr(i+1:)) i = i+Dbl2Str( tx ,2,cStr(i+1:)) i = i+Str2Str('; ty=',cStr(i+1:)) i = i+Dbl2Str( ty ,2,cStr(i+1:)) call Say(cSay,'W',cName,cStr) end if else if (nint( hdr(SMEI__HDR_JUST_BAD) ) .eq. 1) then smei_frm_ok = .FALSE. if (iSilent .le. 1) call Say(cSay,'W',cName,'crazy frame') else if (nint( hdr(SMEI__HDR_BAD_QUAT) ) .eq. 1) then smei_frm_ok = .FALSE. if (iSilent .le. 1) call Say(cSay,'W',cName,'bad quaternion') else if (bShutterClosed) then smei_frm_ok = .FALSE. if (iSilent .le. 1) call Say(cSay,'W',cName,'shutter closed') else if (nshutter_count .le. nshutter_skip) then smei_frm_ok = .FALSE. if (iSilent .le. 1) call Say(cSay,'W',cName,'skip because shutter just closed') else if (nint( hdr(SMEI__HDR_BASE_DONE) ) .eq. 0) then smei_frm_ok = .FALSE. if(iSilent .le. 1) call Say(cSay,'W',cName,'no pedestal and dark current available') else if (bDefaultTest) then smei_frm_ok = nint( hdr(SMEI__HDR_BASE_OK) ) .eq. 1 if (iSilent .le. 1 .and. .not. smei_frm_ok) call Say(cSay,'W',cName,'bad pedestal and/or dark current') else ! User-defined test (from command line arguments) nped = nint( hdr(SMEI__HDR_N_PEDESTAL ) ) ndark = nint( hdr(SMEI__HDR_N_DARK_CURRENT) ) smei_frm_ok = nped .ge. nped_min .and. ndark .ge. ndark_min if (iSilent .le. 1 .and. .not. smei_frm_ok) then i = 0 i = i+Str2Str('reject, nped=' , cStr(i+1:)) i = i+Int2Str(nped , cStr(i+1:)) if (nped .lt. nped_min) then i = i+Str2Str('<' , cStr(i+1:)) else i = i+Str2Str('>' , cStr(i+1:)) end if i = i+Int2Str(nped_min , cStr(i+1:)) i = i+Str2Str(', ndark=' , cStr(i+1:)) i = i+Int2Str(ndark , cStr(i+1:)) if (ndark .lt. ndark_min) then i = i+Str2Str('<' , cStr(i+1:)) else i = i+Str2Str('>' , cStr(i+1:)) end if i = i+Int2Str(ndark_min , cStr(i+1:)) call Say(cSay,'W',cName,cStr) end if end if ! The PIXDIF value in the header is not the one needed !! !cutoff = hdr(SMEI__HDR_PIXDIF)+hdr(SMEI__HDR_N_POS_MEASLES)/25.0 !else if (cutoff .gt. 120.0) then ! call Say(cSay,'I',cName,'above cutoff '//cFlt2Str(cutoff,3)) ! return !end if return end