pro smei_msg, message, inform = inform, error = error, $
                warning = warning, alert = alert, noshow = noshow, $
                dialog_parent = dialog_parent, _extra = _extra

;+ *
; SMEI_MSG
;	Display an error message, in a suitable manner.
;
; Usage:
;	smei_msg, message
;
; Argument:
;	message	string	input	The error message to be displayed.
;
; Keywords:
;	error	If set, then the message is an error.
;	warning	If set, then the message is a warning.
;	alert	If set, then then message is a warning that needs to
;		be noticed.
;	inform	If set, then the message is for information only.
;	noshow	If set, then don't pop the main widget to the front.
;	dialog_parent	long	Optional "parent" for the dialogue.
;
; Other keys used by dialog_message can also be passed (they will of
; course be ignored if no pop-up is generated).
;
; History:
;	Temporary Version: 18/11/99; SJT
;	Use dialog_message: 2/12/99; SJT
;	Rewrote to use the message panel on the TLM: 11/7/00; SJT
;	Added alert keyword: 21/2/01; SJT
;	Add dialog keys and remove common block: 22/2/01; SJT
;	Prevent duplication of alert and error level messages:
;	19/6/01; SJT
;-


if (strpos(message, 'ERROR'))[0] ne -1 or keyword_set(error) then begin
    help, calls = tracelist
    msgout = [message, "", "Occurred at:", tracelist[1:*]]
    if widget_info(/active) then begin
        pold = !P
        dold = !D.name
        set_plot, 'X'
        
        junk = dialog_message(msgout, /error, dialog_parent = $
                              dialog_parent, _extra = _extra)

        set_plot, dold
        !P = pold

    endif else begin
        print, "   ******  ERROR *****"
        print, msgout, format = "(A)"
        print, "   *******************"
        ink = ""
        read, "Press 'return' to continue", ink
    endelse
endif else if (strpos(message, 'ALERT'))[0] ne -1 or $
  keyword_set(alert) then begin
    help, calls = tracelist
    msgout = [message, "", "Occurred at:", tracelist[1:*]]
    if widget_info(/active) then begin
        pold = !P
        dold = !D.name
        set_plot, 'X'
        
        junk = dialog_message(msgout, dialog_parent = $
                              dialog_parent, _extra = _extra)

        set_plot, dold
        !P = pold

    endif else begin
        print, "   ******  WARNING *****"
        print, msgout, format = "(A)"
        print, "    *******************"
        ink = ""
        read, "Press 'return' to continue", ink
    endelse
endif else begin
    if ((strpos(message, 'WARNING'))[0] ne -1 or $
        keyword_set(warning)) then $
      msgout = ["++ Warning ++", $
                message, $
                "-------------", ""] $
    else msgout =  message

    print, msgout, format = "(A)"
endelse

end
