function di_filt2wl, filter, inst, date, INCLUDEIF=includeif

;;-----------------------------------------------------------------------------
;; PURPOSE:
;;	Converts a filter number from the spacecraft to the effective 
;;	wavelength. This is done by querying a database which contains
;;	this information.
;;
;; CALLING SEQUENCE:
;;	wl = di_filt2wl(filter, inst, date)
;;
;; REQUIRED INPUTS:
;;	filter - Integer specifying the filter
;;	inst - String specifying the instrument
;;	date - ISO string specifying the date in the mission when we want the
;;		wavelength
;;
;; OUTPUTS:
;;	RETURN - The wavelength in nanometers as a string
;;
;; OPTIONAL INPUT KEYWORDS:
;;	INCLUDEIF - specifies that the IF effective wavelength should also be returned
;;
;; EXAMPLE:
;;      IDL> wl = di_filt2wl(filter, inst, date)
;;
;; PROCEDURES USED (i.e. called directly!):
;;	getSQLServer
;;	sql_query
;;
;; MODIFICATION HISTORY:
;;   2004-10-01  M. Desnoyer    Created
;;   2005-04-05  B. Carcich     Modified output to always be string
;;
;;-----------------------------------------------------------------------------

serv = getSQLServer()
db = 'di_calib'
tbl = 'WAVELENGTH'
IF keyword_set(includeif) THEN sel = ['RadWavelength','Wavelength'] ELSE sel = ['Wavelength']
cond = "Date <= '"+date+"' AND Filter ="+strtrim(filter,2)+$
	" AND Instrument = '"+inst+"' order by Date desc, Version desc limit 1"

wl = di_sqlQuery(serv, db, tbl, sel, cond, dim=dim)

IF min(dim) EQ 0 THEN return, 'UNKNOWN'

;; Make sure we only return one result
IF keyword_set(includeif) THEN wl = wl[*,0] ELSE wl=wl[0]

wl = float(wl)
w = where(wl EQ 0,c)
IF c GT 0 THEN w[c]= 'CLEAR'

return, string(wl,format='(f18.2)')
END