ó
xTc           @   sw   d  d l  m Z d d d     YZ e d k rs d  d l Z d  d l Z e   Z e j e j d  e j	   Z
 n  d S(   i˙˙˙˙(   t   divisiont   readerc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s)   A class to read the CBF files used in XDSc         C   s   d  S(   N(    (   t   self(    (    s?   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/xds_cbf.pyt   __init__   s    c         C   sB   d d l  } | j   |  _ |  j j | | j  |  j j   d S(   s   Read the CBF filei˙˙˙˙N(   t   pycbft   cbf_handle_structt
   cbf_handlet	   read_filet
   MSG_DIGESTt   rewind_datablock(   R   t   filenameR   (    (    s?   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/xds_cbf.pyR      s    c         C   sÓ   d d l  } |  j j d  |  j j d  |  j j d  |  j j d  |  j j   } | j d  d k rĂ |  j j   } | j	 | | j
  } |  j j   } | d | d f } | | _ n t d   | S(	   s    Get the gain array from the filei˙˙˙˙Ni    i   t   bnryi
   i	   s   Can't find image(   t   numpyR   t   select_datablockt   select_categoryt   select_columnt
   select_rowt   get_typeofvaluet   findt   get_integerarray_as_stringt
   fromstringt   int32t    get_integerarrayparameters_wdimst   shapet	   TypeError(   R   R   t   typet   image_stringt   imaget
   parameterst
   image_size(    (    s?   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/xds_cbf.pyt   get_data   s    (   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    s?   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/xds_cbf.pyR      s   		t   __main__Ni   (    (   t
   __future__R    R   R   t   sysR   t   handleR   t   argvR   R   (    (    (    s?   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/xds_cbf.pyt   <module>	   s   ,	