ó
Ń%Tc           @   s-   d  Z  d d l m Z d d d     YZ d S(   sC   A class to perform linear interpolation on data read from csv file.i˙˙˙˙(   t   floort   LinearInterpc           B   s    e  Z d  Z d   Z d   Z RS(   sC   A class to perform linear interpolation on data read from csv file.c         C   s  d |  _ d |  _ d |  _ g  |  _ | |  _ t | d  } | j   | j   j d  } t | d  |  _ |  j j	 t | d   | j   j d  } t | d  t |  j  |  _ |  j j	 t | d   |  j d } xŠ | D]Ą } t
 | j    d k rqë n  | j d  } |  j |  j t
 |  j  } | | | d k rr| d | | k rrd |  j GHn  |  j j	 t | d   që W| j   d S(   sU  Initialize the class and read data from the specified a file name.
        
        ARGUMENTS:
            fileName - the name of the CSV data file.
                       This CSV file should have two columns: x and y, as well as a header row (which will be ignored).
        RETURNS:
            an initialized LinearInterp object
        t   rt   ,i    i   i'  s   Incorrect step size in file N(   t   Nonet   _LinearInterp__xStartt   _LinearInterp__xStept   _LinearInterp__fileNamet   _LinearInterp__yDatat   opent   readlinet   splitt   floatt   appendt   lent   rstript   close(   t   selft   fileNamet   inputt   curdatat   ept   curlinet   xVal(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/linearInterp.pyt   __init__   s.    
					
 (c         C   s6  t  t | |  j |  j   } d } | d k  rv |  j d |  j d } | |  j |  j } |  j d | | } nź | t |  j  d k rä |  j d |  j d } | |  j |  j t |  j  d } |  j d | | } nN | |  j |  j | } |  j | d | |  j |  j | d | |  j } | S(   sú   Determine the interpolated (or extrapolated) y value for the given x value
        
        ARGUMENTS:
            xVal - the x value to determine the y value for
        RETURNS:
            yVal - the interpolated (or extrapolated) y value
        i    i   i˙˙˙˙iţ˙˙˙N(   t   intR    R   R   R   R   R   (   R   R   t   xPost   yValt   yStept   numStepst	   remainder(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/linearInterp.pyt   interpI   s    	 %6(   t   __name__t
   __module__t   __doc__R   R   (    (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/linearInterp.pyR      s   	2N(    (   R"   t   mathR    R   (    (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/linearInterp.pyt   <module>   s   