pro fnmap2file, fnmap, dset, files, dset_out, $
		sxtp=sxtp, sxtf=sxtf, bcs=bcs, hxt=hxt, wbs=wbs, $
                one_set=one_set, one_file=one_file, qstop=qstop
;+
;Name:
;       fnmap2file
;Purpose:
;       Given a filename map and a dataset vector and a
;	selection of an instrument, return the
;	file names and datasets for the desired dataset.  
;
;	It assumes that the routines
;       GETOBSDAT/FIDMAP/CREDVEC (or equivalent routines)
;	have already been run.
;Restrictions:
;Input:
;       fnmap   - The structure returned from CREDVEC
;       dset    - A vector "m" long with the data
;                 set number within the file for
;                 the desired image which is also
;		  part of CREDVEC output
;	One of the instruments must be selected:
;	/sxtp
;	/sxtf
;	/bcs
;	/hxt
;	/wbs
;Output:
;	files	- The name of the file selected.
;		  If ONE_IMG or ONE_FILE is not used, then
;		  file_out is an array of all files
;	dset_out- A list of the datasets selected.
;		  If ONE_IMG or ONE_FILE is not used, then
;		  dset_out is a copy of dset
;Optional Input:
;       one_set - Only select one dset.
;                 The value should be between
;                 0 and "m-1"
;       one_file- Only return the datasets for 
;                 datasets that fall in one file.
;History:
;       written 17-Oct-91 by M.Morrison
;-
;
files = get_fninfo(fnmap, limits, sxtf=sxtf, sxtp=sxtp)		;, bcs=bcs, hxt=hxt, wbs=wbs)
dset_out = dset
;
n = n_elements(files)
m = n_elements(dset)
;
if (n_elements(one_set) ne 0) then begin
    if ((one_set lt 0) or (one_set ge m)) then begin
        print, 'FNMAP2FILE: Must select between 0 and ', strtrim(m-1,2)
        print, 'You selected dataset # ', strtrim(one_set,2)
        return
    end
    istfil = where((limits(*,0) le one_set) and (limits(*,1) ge one_set))
    istfil = istfil(0)
    ;
    abort = 0
    if (istfil eq -1) then abort = 1
    if (not abort) then if (limits(istfil) eq -1) then abort = 1
    if (abort) then begin
        print, 'DSET # ', one_set, ' is not available in the LIMITS variable'
	files = ''
	dset_out = -1
        return
    end

    files = files(istfil)
    dset_out = dset(one_set)
end else begin
    if (n_elements(one_file) ne 0) then begin
	print, 'FNMAP2FILE: Only selecting data in file: ', files(one_file)
	files = files(one_file)
        dset_out = dset( limits(one_file,0): limits(one_file,1) )
    end
end
;
end
