FUNCTION CNVRT_CURRENT, dn_in, curr_type
;
;+
; NAME:
;	CNVRT_CURRENT
;
; PURPOSE:
;	This function converts DN to amps for various current monitors.
;
; CATEGORY:
;	PACKETS
;
; CALLING SEQUENCE:
;	Result = CNVRT_CURRENT (Dn_in, Curr_type)
;
; INPUTS:
;	Dn_in:	The raw DN value to be converted
;	Curr_type:	A parameter indicating the monitor type
;			0 = QI2P1B3, LASCO/VIRGO/GOLF
;			1 = QI3P1B3, EIT/SUMER/CELIAS
;			2 = QIL3, EIT
;			3 = QIL4, LASCO
;
; OUTPUTS:
;	This function returns the converted current in amps.
;
; PROCEDURE:
;	Uses calibration curves to perform the conversion
;
; EXAMPLE:
;	To conver the LASCO spacecraft current monitor which has a DN value
;	of 128:
;
;		A = CNVRT_CURRENT (128,3)
;
; MODIFICATION HISTORY:
; 	Written by:	R.A. Howard, 1994
;
;
;	@(#)cnvrt_current.pro	1.1 01/27/98 LASCO IDL LIBRARY
;-
CASE curr_type OF

    0:  BEGIN
    ;
    ;    convert the nominal current for QI2P1B3
    ;
       dn  = [0.,5.,7.,25.,91.,255.]
       curr = [0.,0.,0.1,0.9,3.4,9.96]
       n = 5
       k=0;
       len = N_ELEMENTS(dn_in)
       output = FLTARR(len)
       FOR j=0, len-1 DO BEGIN
           for i=0,n-1 do if (dn_in(j) GE dn(i) )   THEN k = i
           x0 = dn(k);
           x1 = dn(k+1);
           y0 = curr(k);
           y1 = curr(k+1);
           temp = (x1 - x0);
           if ( temp EQ 0 ) THEN y = y0 $
	      ELSE y = y0 + (y1-y0) * (dn_in(j)-x0) / temp
	   output(j) = y
       ENDFOR
       RETURN,output
    END
    
    1:  BEGIN
    ;
    ;    convert the nominal current for QI3P1B3
    ;
       dn  = [0.,5.,7.,25.,91.,255.]
       curr = [0.,0.,0.1,0.9,3.4,9.96]
       n = 5
       k=0;
       len = N_ELEMENTS(dn_in)
       output = FLTARR(len)
       FOR j=0, len-1 DO BEGIN
           for i=0,n-1 do if (dn_in(j) GE dn(i) )   THEN k = i
           x0 = dn(k);
           x1 = dn(k+1);
           y0 = curr(k);
           y1 = curr(k+1);
           temp = (x1 - x0);
           if ( temp EQ 0 ) THEN y = y0 $
	      ELSE y = y0 + (y1-y0) * (dn_in(j)-x0) / temp
	   output(j) = y
       ENDFOR
       RETURN,output
    END
    
    2:  BEGIN
    ;
    ;    convert the redundant current for QIL3 (EIT)
    ;
       dn  = [0.,1.,255.]
       curr = [0.,0.01829,4.664]
       n = 2
       k=0;
       len = N_ELEMENTS(dn_in)
       output = FLTARR(len)
       FOR j=0, len-1 DO BEGIN
           for i=0,n-1 do if (dn_in(j) GE dn(i) )   THEN k = i
           x0 = dn(k);
           x1 = dn(k+1);
           y0 = curr(k);
           y1 = curr(k+1);
           temp = (x1 - x0);
           if ( temp EQ 0 ) THEN y = y0 $
	      ELSE y = y0 + (y1-y0) * (dn_in(j)-x0) / temp
	   output(j) = y
       ENDFOR
       RETURN,output
    END
    
    3:  BEGIN
    ;
    ;    convert the redundant current for QIL4 (LASCO)
    ;
       dn  = [0.,1.,255.]
       curr = [0.,0.00287,0.7318]
       n = 2
       k=0;
       len = N_ELEMENTS(dn_in)
       output = FLTARR(len)
       FOR j=0, len-1 DO BEGIN
           for i=0,n-1 do if (dn_in(j) GE dn(i) )   THEN k = i
           x0 = dn(k);
           x1 = dn(k+1);
           y0 = curr(k);
           y1 = curr(k+1);
           temp = (x1 - x0);
           if ( temp EQ 0 ) THEN y = y0 $
	      ELSE y = y0 + (y1-y0) * (dn_in(j)-x0) / temp
	   output(j) = y
       ENDFOR
       RETURN,output
    END
    
    DEFAULT: BEGIN
    	PRINT, "%CNVRT_CURRENT: Invalid curr_type."
    	RETURN, -1
    END

ENDCASE

END
