PRO SETUT,UTBASE=BASE,UTSTART=START,UTEND=END1,error=error, set_utplot=set

on_error,2
!quiet=1
;
COMMON UTCOMMON, UTBASE, UTSTART, UTEND
COMMON LASTDATECOM, LASTDATE
COMMON SETCOMMON, SETPLOT
CHECKVAR,LASTDATE,'0' ;DEFAULT VALUE
CHECKVAR, SETPLOT, 0  ;DEFAULT VALUE - don't call set_utplot
CHECKVAR, SET, -1 ;DEFAULT VALUE, nothing is passed
if SET eq 1 then SETPLOT = 1
if SET eq 0 then SETPLOT = 0
error = 0
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Set the right variable in common
;FIND WHICH PARAMETERS HAVE BEEN PASSED
s_base=size(base)
s_start=size(start)
s_end1=size(end1)
;
;..............................
;SETUT works in one of two ways.  The first way is by calls to SETUTBASE, 
;SETUTSTART, or SETUTEND.  In these routines, the time is either passed directly 
;or it is passed interactively.  The second way is by passing parameters 
;directly into SETUT using the keyword parameters UTBASE, UTSTART, and UTEND.
;
;Process calls to SETUTBASE, SETUTSTART, or SETUTEND
;..............................
;
index = -1
IF s_base(1) gt 0 THEN INDEX=0
IF s_start(1) gt 0 THEN INDEX=1
IF s_end1(1) gt 0 THEN INDEX=2
WHICHTIME=['base','start','end']
;
CASE INDEX OF
   0: UTSTRING=BASE
   1: UTSTRING=START
   2: UTSTRING=END1
   ELSE: BEGIN
      ERROR=1
      RETURN
   ENDELSE
ENDCASE
;
;This block is to be used only if one variable is to be set interactively
;Only SETUTXXXX should be entering this block
IF UTSTRING EQ '-1' THEN BEGIN 
   READ,'Enter '+WHICHTIME(INDEX)+' time.  ' + $
    'Format is YY/MM/DD,HHMM:SS.XXX ', UTSTRING
;
;
   UTSTRING1=UTSTRING
;
;   if no date is given, i.e. 'YY/MM/DD,' isn't included in the string
;   then use the most recent date string appearing in a call to SETUT

   IF STRPOS(UTSTRING1,'/') NE -1 THEN $ ;date is not included!!!!
    LASTDATE=STRMID(ATIME(utplot_UTIME(UTSTRING1,err=error)),0,8) $;REMEMBER DATE
    ELSE IF (LASTDATE NE '0') AND (UTSTRING1 NE '0') THEN $
    UTSTRING1=LASTDATE+', '+UTSTRING1
   IF UTSTRING1 EQ '0' THEN UTOUT=0.D0 ELSE UTOUT=utplot_UTIME(UTSTRING1,err=error)

   if not error then begin
     CASE INDEX OF 
    0: UTBASE=UTOUT
    1: UTSTART=UTOUT
    2: UTEND=UTOUT
     ENDCASE
   endif ;close error check
ENDIF $
$;......................................................................
$;......................................................................
$;......................................................................
ELSE BEGIN
;
;PROCESS NON-INTERACTIVE CALLS TO SETUT OR SETUTXXX
;
;At least one parameter has been passed where UTXXX isn't -1, so
;process each parameter string into its appropriate common variable.
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Set the right variable in common
;*************************UTBASE************************************
 IF s_base(1) gt 0 THEN begin
  UTSTRING1=BASE
  IF STRPOS(UTSTRING1,'/') NE -1 THEN $
    LASTDATE=STRMID(ATIME(utplot_UTIME(UTSTRING1,err=error)) ,0,8) $;REMEMBER DATE
    ELSE IF (LASTDATE NE '0') AND (UTSTRING1 NE '0') THEN $
    UTSTRING1=LASTDATE+', '+UTSTRING1
  IF UTSTRING1 EQ '0' THEN UTOUT=0.D0 ELSE UTOUT=utplot_UTIME(UTSTRING1,err=error)
  if not error then UTBASE=UTOUT
 ENDIF
;*************************UTSTART***********************************
 IF s_start(1) gt 0 THEN BEGIN
  UTSTRING1=START
  IF STRPOS(UTSTRING1,'/') NE -1 THEN $
    LASTDATE=STRMID(ATIME(utplot_UTIME(UTSTRING1,err=error)),0,8) $;REMEMBER DATE
       ELSE IF (LASTDATE NE '0') AND (UTSTRING1 NE '0') THEN $
    UTSTRING1=LASTDATE+', '+UTSTRING1
  IF UTSTRING1 EQ '0' THEN UTOUT=0.D0 ELSE UTOUT=utplot_UTIME(UTSTRING1,err=error)
  if not error then UTSTART=UTOUT
 ENDIF
;*************************UTEND*************************************
 IF s_end1(1) gt 0 THEN BEGIN
  UTSTRING1=END1
  IF STRPOS(UTSTRING1,'/') NE -1 THEN $
    LASTDATE=STRMID(ATIME(utplot_UTIME(UTSTRING1,err=error)),0,8) $;REMEMBER DATE
    ELSE IF (LASTDATE NE '0') AND (UTSTRING1 NE '0') THEN $
    UTSTRING1=LASTDATE+', '+UTSTRING1
  IF UTSTRING1 EQ '0' THEN UTOUT=0.D0 ELSE UTOUT=utplot_UTIME(UTSTRING1,err=error)
  if not error then UTEND=UTOUT
 ENDIF
;*************************UTEND*************************************
ENDELSE
;
;Call SETUTPLOT with the new values of UTBASE, UTSTART, UTEND if SET
    if SETPLOT and keyword_set(UTEND) and $
        keyword_set(UTSTART) then $
        SET_UTPLOT, XRANGE = [UTSTART, UTEND] - UTBASE
$;......................................................................
$;......................................................................
$;......................................................................
RETURN
END