C+ C NAME: C smei_cal_get C PURPOSE: C Get closed shutter calibration pattern. C CALLING SEQUENCE: subroutine smei_cal_get(cFile,ipick,icam,mode,mask,time, & cpattern,pattern,pattern_dark,bNew,version) C INPUTS: C cFile*(*) character fully-qualified file name of pattern file C (must be a .grd file, .fts or .fts.gz file). C If left empty or set to SMEIDB? then a C calibration pattern is selected from C $SMEIDB/cal (a Fits file) based C on the fourth input argument (time). C ipick integer 0: pick earlier pattern for mode 1,2 C and nearest pattern for mode 0 C 1: always pick nearest pattern C 2: pick later pattern for mode 1,2 and C nearest pattern for mode 0 C camera integer camera number (1,2,3) C mode integer camera mode (0,1,2) C mask integer C3 mask applied or not (0=No,1=Yes) C time(2) integer time used for pattern selection. C For mode 0 the pattern closest to 'time' is returned C For mode 1 and 2 the last pattern preceeding 'time' C is returned. C OUTPUTS: C cpattern*(*) character file name of calibration pattern C pattern(*) real calibration pattern C pattern_dark real dark current in calibration pattern. C bNew logical .TRUE. if smei_cal_read was called to read new C pattern; .FALSE. if not. C version double precision (Only if bNew = .TRUE.) C version number of smei_cal program that wrote the C the calibration pattern. If bNew=.FALSE. then version=0. C I.e. the version number is returned only if C smei_cal_read is called. C INCLUDE: include 'filparts.h' include 'dirspec.h' include 'smei_frm_layout.h' C RESTRICTIONS: C smei_cal_init() needs to be called first. C CALLS: C Str2Str, Int2Str, iFilePath, iSearch, Time2Split, Time2Differ C Time2Delta, Say, smei_cal_read, iGetLun, iFreeLun, cInt2Str C iSetFileSpec, iGetFileSpec, itrim C PROCEDURE: C The first nX * nY elements of pattern will be filled where C nX = 1272, 636 or 318 and nY = 256, 128, 64 for mode 0,1 and C 2, respectively. C MODIFICATION HISTORY: C DEC-2004, Paul Hick (UCSD/CASS) C JUL-2005, Paul Hick (UCSD/CASS) C Fixed bug in pattern selection for mode 0 (would fail if C frame time was later than last pattern). C SEP-2005, Paul Hick (UCSD/CASS) C Added bNew C MAR-2007, Paul Hick (UCSD/CASS) C Added argument 'mask' to access patterns with c3 "bad pixel" C mask applied. C JAN-2008, Paul Hick (UCSD/CASS) C Added argument 'version' C JUL-2008, Paul Hick (UCSD/CASS) C Added argument ipick C JUN-2011, Paul Hick (UCSD/CASS; pphick@ucsd.edu) C Added ipick=2 option to pick later pattern. C- character cFile*(*) integer ipick integer icam integer mode integer mask integer time(2) character cpattern*(*) real pattern(*) real pattern_dark logical bNew double precision version character cSay *7 /'cal_get'/ character cStr *(FIL__LENGTH) character cType*10 logical bOK integer Str2Str integer Time2Differ character cInt2Str*14 integer dt(2) integer du(2) character ctime*(SMEI__UT_FORMAT_LEN) character cTime2Str*80 ! smei_cal_init will fill the following three arrays: ! cal_n is number of available patterns for each camera ! cal_t is the pattern time ! cal_f is the fully-qualified pattern file name parameter (NCAL = 800) integer cal_n( 3) /-1,-1,-1/ save cal_n integer cal_t(2,3,NCAL) save cal_t character cal_f( 3,NCAL)*(FIL__LENGTH) save cal_f ! The pattern last read is characterized by camera number ! cal_icam, mode cal_mode, and index cal_i ! The pattern has time cal_t(*,cal_icam,cal_i) and name ! cal_f(cal_icam,cal_i) integer cal_icam / 0/ save cal_icam integer cal_mode /-1/ save cal_mode integer cal_i / 0/ save cal_i integer cal_mask /-1/ save cal_mask version = 0.0d0 ! Do NOT modify the input argument cFile !!!! if (cFile .eq. 'SMEIDB?' .or. cFile .eq. ' ') then ! This section is used by smei_orb and smei_base. ! Pick last calibration pattern preceding the input time. if (cal_n(icam) .eq. -1) then call Say(cSay,'E','cam '//cInt2Str(icam),'call smei_cal_init() first') else if (cal_n(icam) .eq. 0) then call Say(cSay,'E','cam '//cInt2Str(icam),'no patterns available') end if i = 1 if (icam .eq. cal_icam .and. cal_i .ne. 0) i = cal_i bOK = Time2Differ(cal_t(1,icam,i),time) .le. 0 do while (bOK) i = i+1 bOK = i .le. cal_n(icam) if (bOK) bOK = Time2Differ(cal_t(1,icam,i),time) .le. 0 end do if (i .eq. 1) then ! Time preceeds time of first pattern ! Mode 1 or 2 with ipick=0: stop. No earlier pattern available if (mode .ne. 0 .and. ipick .eq. 0) & call Say(cSay,'E','time','preceeds first pattern') if (ipick .eq. 1) call Say(cSay,'W','time','preceeds first pattern; use first') else if (i .eq. cal_n(icam)+1) then ! Time is later than last pattern if (mode .ne. 0 .and. ipick .eq. 2) & call Say(cSay,'E','time','is later than last pattern') if (ipick .eq. 1) call Say(cSay,'W','time','is later than last pattern; use last') i = i-1 ! Index of last pattern else if (mode .eq. 0 .or. ipick .eq. 1) then ! For mode 0 always take pattern closest to 'time' i = i-1 ! Pattern with t <= time call Time2Delta(time,cal_t(1,icam,i),dt) call Time2Delta(cal_t(1,icam,i+1),time,du) if (Time2Differ(dt,du) .gt. 0) i = i+1 else if (ipick .eq. 0) then i = i-1 end if ! Read in a new pattern if necessary. bNew = icam .ne. cal_icam .or. mode .ne. cal_mode .or. & mask .ne. cal_mask .or. cal_i .ne. i if (bNew) then ! The informational message is primarily useful when reading of ! the calibration patterns fails (the time gives the time of the ! frame that is being processed (and probably contains the wrong ! pattern name. call Say(cSay,'I',cTime2Str(SMEI__UT_FORMAT,time),'time used for pattern selection') call smei_cal_read(cal_f(icam,i),mode,mask,pattern_dark,nx,ny,pattern) call smei_cal_version(version) cal_icam = icam cal_mode = mode cal_mask = mask cal_i = i end if cpattern = cal_f(cal_icam,cal_i) else i = iSetFileSpec(cFile) i = iGetFileSpec(FIL__NAME,FIL__NAME,cStr ) i = iGetFileSpec(FIL__TYPE,FIL__TYPE,cType) if (cStr .eq. cFile) then ! No directory and no type specified. ! This section is used by smei_htm and smei_orb. ! If only a file name is specified (no directory, no file type), then ! it probably is read from the corresponding entry in a SMEI frame header. ! Look for the pattern matching the file name. i = 1 if (icam .eq. cal_icam .and. cal_i .ne. 0) i = cal_i j = itrim(cFile) bOK = index(cal_f(icam,i),cFile(:j)) .eq. 0 do while (bOK) i = i+1 bOK = i .le. cal_n(icam) if (bOK) bOK = index(cal_f(icam,i),cFile(:j)) .eq. 0 end do if (i .gt. cal_n(icam)) call Say(cSay,'E',cFile,'pattern disappeared from data base') ! Read in a new pattern if necessary. bNew = icam .ne. cal_icam .or. mode .ne. cal_mode .or. cal_i .ne. i if (bNew) then call Say(cSay,'I',cTime2Str(SMEI__UT_FORMAT,time),'time used for pattern selection') call smei_cal_read(cal_f(icam,i),mode,mask,pattern_dark,nx,ny,pattern) call smei_cal_version(version) cal_icam = icam cal_mode = mode cal_i = i end if cpattern = cal_f(cal_icam,cal_i) else if (cType(:4) .eq. '.fts') then ! Used for test runs: explicit pattern (Fits file) specified on ! command line. bNew = .TRUE. call smei_cal_read(cFile,mode,mask,pattern_dark,nx,ny,pattern) call smei_cal_version(version) cpattern = cFile else bNew = .TRUE. ! Used for test runs: explicit pattern (.grd file) specified on ! command line. cStr = cFile call Say(cSay,'I','#'//cStr,'calibration pattern') nbin = 2**mode nx = SMEI__FRM_NX/nbin ny = SMEI__FRM_NY/nbin iU = iGetLun(cFile) open (iU, file=cFile, access='sequential') read (iU,'(A)') (cStr,i=1,5) do j=1,ny read (iU,'(20F9.3)') (pattern((j-1)*nx+i),i=1,nx) end do read (iU,'(F10.4)') pattern_dark iU = iFreeLun(iU) cpattern = cFile end if end if return C+ C NAME: C smei_cal_init C PURPOSE: C Initializes data base of calibration patterns for use C with smei_get_cal. C CALLING SEQUENCE: entry smei_cal_init() C CALLS: C iFilePath, Int2Str, Str2Str, iSearch, smei_Time2Split, Say C MODIFICATION HISTORY: C FEB-2005, Paul Hick (UCSD/CASS; pphick@ucsd.edu) C- do i=1,3 if (cal_n(i) .eq. -1) then j = iFilePath(cEnvi(:iEnvi)//'SMEIDB',1,'cal','c',cStr) j = j+Int2Str(i, cStr(j+1:)) j = j+Str2Str('cal_*.fts.gz', cStr(j+1:)) cal_n(i) = 0 bOK = iSearch(1,cStr,cStr) .eq. 1 do while (bOK) cal_n(i) = cal_n(i)+1 if (cal_n(i) .gt. NCAL) call Say(cSay,'E','NCAL','parameter too small') cal_f(i,cal_n(i)) = cStr call smei_Time2Split(1,cStr,cal_t(1,i,cal_n(i))) bOK = iSearch(0,' ',cStr) .eq. 1 end do end if end do return end