;+
; Project     : SOHO - CDS     
;                   
; Name        : GET_TM_FILE
;               
; Purpose     : Return the telemetry file that corresponds to a UTC time.
;               
; Explanation : This function returns the name of the telemetry file which
;		corresponds to the UTC time that is passed to the function as
;		a parameter.  If no telemetry file corresponds to the time
;		which is passed to the function, then the empty string is 
;		returned.
;               
; Use         : filename = GET_TM_FILE (time, [keyword])
;    
; Inputs      : time:	Time to get the corresponding tm file for. Can be in
;			almost any format.
;               
; Opt. Inputs : None.
;               
; Outputs     : None.
;               
; Opt. Outputs: None.
;               
; Keywords    : ENDTIME If passed, then this will be set to the time
;			(in seconds) after which packets will be written
;			to the next telemetry file in sequence.  
;
; Returns     :	The complete path of the file that corresponds to the UTC time
;		which was passed to the function.  Otherwise the empty string
;		is returned.
;
; Calls       : ANYTIM2UTC
;		UTC2STR
;		UTC2DOY
;		STR2UTC
;		UTC2SEC
;		CONCAT_DIR
;		FILE_EXIST
;
; Common      : None.
;               
; Restrictions: None.
;               
; Side effects: None.
;               
; Category    : Telemetry
;               
; Prev. Hist. : None.
;
; Written     : Ron Yurow, SM&A, 12 May 1999
;               
; Modified    : Version 1, Initial Release		RY, 12 May 1999
;
; Version     : Version 1, 12 May 1999
;-            

	FUNCTION GET_TM_FILE, anytime, ENDTIME = endtime

;
; Convert the time to UTC.
;

	utc = ANYTIM2UTC (anytime)

;
; Convert the UTC time to a time string 
;

	timestr = UTC2STR (utc, /ECS)

;
; Get current year.
;

	year = STRMID (timestr, 2, 2)

;
; Get the day of year.
;

	doy = STRING (UTC2DOY (utc), FORMAT = '(i3.3)')

;
; Get the UT hour.
;

	hour = STRMID (timestr, 11, 2)

;
; Set file to the tm. filename that corresponds to the UTC time.
;

	file = 'tm.' + year + '_' + doy + '_' + hour

;
; Set path to the complete path name of the file.
;

	path = CONCAT_DIR ('$CDS_TM_DATA', file)

;
; Check if the file exists, if it does not exist then return an empty string.
;

	IF NOT FILE_EXIST (path) THEN RETURN, ''

;
; Check if the keyword endtime is defined.  If it is then find the last
; time which the file will contain packets for. 
;

	IF N_ELEMENTS (endtime) NE 0 THEN BEGIN

;
; Find the UTC time that corresponds to the starting time of the file.
;

	   start = STR2UTC (year + '-' + doy + ' ' + hour + ':00')

;
; Use the starting time of the file to find its end time.
;

	   endtime = UTC2SEC (start) + 3600

	ENDIF

;
; Return the full path name of the file.  Were done.
;

	RETURN, path

	END
