;+
; NAME:
;	SMEI_DOCS
;
;
; PURPOSE:
;	Find a suitable application and show the SMEI PDF
;	documentation.
;
;
; CATEGORY:
;	CLI
;
;
; CALLING SEQUENCE:
;	smei_docs
;
;
; KEYWORD PARAMETERS:
;	/reference		If set, then show the reference manual
;				rather than the users' guide.
;	/tutorial		If set, then show the tutorial.
;	/admin			If set, then show the administrators
;				guide.
;	pdfviewer	string	Specify a PDF viewer other than the default.
;
;
; MODIFICATION HISTORY:
;	Original: 6/6/05; SJT
;-
 
pro smei_docs, reference = reference, tutorial = tutorial, admin = $
               admin, pdfviewer = pdfviewer, help = help

if keyword_set(help) then begin
    self_help
    return
endif

if keyword_set(pdfviewer) then pdfutil = pdfviewer $
else begin
    pdfapps = ['acroread', $
               'kpdf', $
               'xpdf', $
               'kghostview', $
               'gv']
    
    for iapp = 0, n_elements(pdfapps)-1 do begin
        spawn, /sh, 'which '+pdfapps[iapp], wh
        if strlen(wh[0]) ne 0 then begin
            pdfutil = pdfapps[iapp]
            break
        endif
    endfor

    if n_elements(pdfutil) eq 0 then begin
        smei_msg, /alert, ['No PDF display application found', $
                           'Please contact your system administrator', $
                           'or specify a viewer manually.']
        return
    endif
endelse
docpath = getenv("SSW_SMEI_BHAM")+'/Docs/'
if keyword_set(reference) then file = 'reference.pdf' $
else if keyword_set(tutorial) then file = 'tutorial.pdf' $
     else if keyword_set(admin) then file = 'admin.pdf' $
          else file = 'Uguide.pdf'

spawn, pdfutil+' '+docpath+file+' &'

end
