C+
C NAME:
C	smei_frm_getnext
C PURPOSE:
C	(internal use by smei_frm_get)
C CALLING SEQUENCE:
	logical function smei_frm_getnext(iFind,cPath,TTime,mode,cFrmSpec)
C INPUTS:
C	iFind		integer		1 for new search
C					0 to continue search
C					(passed to iSearch)
C	cPath*(*)	character	directory is SMEI data base where
C					data for current doy are located.
C	TTime(2)	integer		test time
C	mode		integer		mode number (0,1,2)
C OUTPUTS:
C	smei_frm_getnext
C			logical		.TRUE. if a frame is found with mode less than 
C						requested.
C					.FALSE. if no frame is found, cFrmSpec is blank
C					.FALSE. if frame is found with mode larger than
C						requested. cFrmSpec is blank
C					.FALSE. if frame is found right mode but with
C						T > TTime; cFrmSpec is blank
C					.FALSE. if frame is found with right mode and
C						T <= TTime; cFrmSpec contains
C						fully-qualified filename
C	cFrmSpec*(*)	character	Fully qualified file name of SMEI frame
C					or blank string
C INCLUDE:
	include		'filparts.h'
C CALLS:
C	iFilePath, iSearch, iSetFileSpec, iGetFileSpec, smei_Time2Split
C	Time2Differ, bOSFindClose
C PROCEDURE:
C	smei_frm_get calls this routine in a while loop, that terminates
C	when .FALSE. is returned. On a .FALSE. return cFrmSpec contains a
C	filename only if it has the right mode and T <= TTime.
C MODIFICATION HISTORY:
C	MAR-2005, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
C-
	    integer	iFind
	    character	cPath*(*)
	    integer	TTime(2)
	    integer	mode
	    character	cFrmSpec*(*)

	integer		Time2Differ
	character	cStr*(FIL__LENGTH)
	integer		TFrm(2)
	character	cMode(0:2)*1		/'0','1','2'/
	logical		bTmp
	logical		bOSFindClose

	if (iFind .eq. 1) then			! New search

	    ! The iSearch call puts picks up all frames in the directory.
	    ! The frames are ordered in three groups: first all mode 0
	    ! frames chronological, then mode 1, then mode 2.

	    ! There will be a problem if both .fts and .fts.gz files for
	    ! the same frames are available. Presumably the .fts.gz
	    ! files will follow the .fts for each mode.

	    i = iFilePath(cPath,0,' ','*.*',cStr)
	    smei_frm_getnext = iSearch(1,cStr,cFrmSpec) .eq. 1

	else					! Continue search

	    smei_frm_getnext = iSearch(0,' ' ,cFrmSpec) .eq. 1

	end if

	if (smei_frm_getnext) then		! Frame found

	    i = iSetFileSpec(cFrmSpec)
	    i = iGetFileSpec(FIL__NAME,FIL__NAME,cStr)

	    smei_frm_getnext = cStr(4:4) .le. cMode(mode)

	    if (smei_frm_getnext) then
						! Mode too low
		smei_frm_getnext = cStr(4:4) .lt. cMode(mode)

		if (.not. smei_frm_getnext) then! Right mode

		    ! We may also need to compare here with the time
		    ! from the previous (accepted) frame. If the current
		    ! frame time is earlier then the previous one we
		    ! probably have both .fts.gz. and .fts files present
		    ! in the same directory.

		    ! If the time is later than TTime clear cFrmSpec

		    call smei_Time2Split(0, cStr, TFrm)
		    if (Time2Differ(TFrm,TTime) .gt. 0) then
			cFrmSpec = ' '
			bTmp = bOSFindClose()
		    end if

		end if

	    else				! Mode too high

		cFrmSpec = ' '
		bTmp = bOSFindClose()

	    end if

	else					! No more frames

	    cFrmSpec = ' '			! NOT redundant !!!!
	    bTmp = bOSFindClose()		! (takes care of parse errors)

	end if

	return
	end
