; $Id: oploterr.pro,v 1.6 1998/02/02 17:35:53 griz Exp $

PRO XYOErr, X, Xerr, Y, Yerr, LineSt, Thck
;
;+
; NAME:
; XYOErr
;
; PURPOSE:
; Overplot X and Y error bars.
;
; CATEGORY:
; Plotting, 2-dimensional.
;
; CALLING SEQUENCE:
; XYOErr, X, Xerr, Y, Yerr[, LineStyle, Thick]
;
; INPUTS:
; X: The array of Y values.

; Xerr: The array of error bar values for the X axis.
;
; Y: The array of Y values.
;
; Yrr: The array of error bar values for the Y axis.
;
; OPTIONAL INPUT PARAMETERS:
;
; LineStyle: A solid line is the default
;
; Thickness: The default is a thickness of 1.0
;
; COMMON BLOCKS:
; None.
;
; SIDE EFFECTS:
; None.
;
; RESTRICTIONS:
; Arrays cannot be of type string.  There must be enough points to
; plot.
;
; PROCEDURE:
; A plot of X versus Y error bars drawn from Y - ERR to Y + ERR
; and X - err to X + err is written to the output device over any plot
; already there.
;
; MODIFICATION HISTORY:
; William Thompson Applied Research Corporation
; July, 1986  8201 Corporate Drive
;    Landover, MD  20785
;       kdb, March, 1997  - Fixed a problem if 1 element arrays where used.
; Barbara am Ende  Changed to not plot the points, only plot
;    the error bars, also add X error bars
;-
;
PThick = !P.Thick  ; Save the affected system parameters
PLineStyle = !P.LineStyle
;
;  Interpret the input parameters.
;
ON_ERROR,2              ; Return to caller if an error occurs
NP = N_PARAMS(0)
IF NP LT 4 THEN $
  message, 'Must be called with 4-6 parameters: X, Xerr, Y , Yerr [, LineStyle, Thick]' $
  ELSE IF NP EQ 4 THEN BEGIN  ;No line attributes passed
 XX = X
 XXERR = Xerr
 YY = Y
 YYERR = Yerr
 !P.LineStyle = 0 ;Defaults to solid line
 !P.Thick = 1  ;Defaults to normal thickness
END ELSE IF NP EQ 5 THEN BEGIN  ;LineStyle passed, only
 XX = X
 XXERR = Xerr
 YY = Y
 YYERR = Yerr
 !P.LineStyle = LineSt
 !P.Thick = 1  ;Defaults to normal thickness
END ELSE BEGIN    ;Both LineStyle and Thickness passed
 XX = X
 XXERR = Xerr
 YY = Y
 YYERR = Yerr
 !P.LineStyle = LineSt
 !P.Thick = Thck
ENDELSE
;END
;
;  Plot the error bars.
;
N = n_elements(XX) ;Defien how many elements there are in the array
FOR I = 0,N-1 DO BEGIN   ;Plot the Y error bars.
 XXX = [XX[I],XX[I]]
 YYY = [YY[I]-YYERR[I],YY[I]+YYERR[I]]
 OPLOT,XXX,YYY
ENDFOR
FOR j = 0,N-1 DO BEGIN   ;Plot the X error bars.
 xhor = [XX[j]-XXERR[j],XX[j]+XXERR[j]]
 yhor = [YY[j],YY[j]]
 OPLOT,xhor,yhor
ENDFOR
;
!P.Thick = PThick  ; Return the orginal system parameter values.
!P.LineStyle = PLineStyle
;
RETURN
END