ó
$Oc           @   s¹   d  d l  m Z d  d l Z d  d l Z d  d l Z d „  Z d „  Z d d „ Z d d „ Z d „  Z	 d	 „  Z
 d
 „  Z d „  Z d „  Z d d „ Z d d „ Z d „  Z d „  Z d S(   iÿÿÿÿ(   t   divisionNc         C   s,  d } d } t  j  |  ƒ } | d d k r; | d d !} n  t j d d | ƒ } t j d d | ƒ } | d k r” t j d I| IJt j d ƒ n  t j d	 | ƒ } t | ƒ d
 k rÛ t | d ƒ } t | d ƒ } nE t | ƒ d k r t | d ƒ } n  t j d I| IJt j d ƒ | | d S(   Ni    iÿÿÿÿs   
s   ^\s+t    s   \s+$s   pyrcio_m:  empty input at linei   s   \s+i   s'   pyrcio_m:  unrecognizable input at liney              ð?(	   t   copyt   ret   subt   syst   stderrt   exitt   splitt   lent   float(   t	   orig_linet   lnot   zret   zimt   linet   strings(    (    s0   /Users/kerl/pub_http_internet/python/pyrcio_m.pyt   complex_scalar_from_string   s&    c         C   sé   d } t  j  |  ƒ } | d d k r5 | d d !} n  t j d d | ƒ } t j d d | ƒ } | d k rŽ t j d I| IJt j d ƒ n  t j d	 | ƒ } t | ƒ d k rÅ t | d ƒ } n  t j d
 I| IJt j d ƒ | S(   Ni    iÿÿÿÿs   
s   ^\s+R   s   \s+$s   pyrcio_m:  empty input at linei   s   \s+s'   pyrcio_m:  unrecognizable input at line(	   R   R   R   R   R   R   R   R	   R
   (   R   R   t   zR   R   (    (    s0   /Users/kerl/pub_http_internet/python/pyrcio_m.pyt   real_scalar_from_string5   s    t   -c         C   sû   d } g  } d } |  d k r* t  j } n? y t |  d ƒ } Wn) t  j d |  d IJt  j d ƒ n XxI | j ƒ  } | d k rˆ Pn  | d 7} | j t | | ƒ ƒ | d 7} ql |  d k rÎ | j ƒ  n  | d k r÷ t  j d IJt  j d ƒ n  | S(	   Ni    R   t   rs   Couldn't open "s   " for read.i   R   s   pyrcio_m:  Empty input.(	   R   t   stdint   openR   R   t   readlinet   appendR   t   close(   t	   file_namet   nt   vR   t   file_handleR   (    (    s0   /Users/kerl/pub_http_internet/python/pyrcio_m.pyt   read_complex_column_vectorR   s.    
c         C   sû   d } g  } d } |  d k r* t  j } n? y t |  d ƒ } Wn) t  j d |  d IJt  j d ƒ n XxI | j ƒ  } | d k rˆ Pn  | d 7} | j t | | ƒ ƒ | d 7} ql |  d k rÎ | j ƒ  n  | d k r÷ t  j d IJt  j d ƒ n  | S(	   Ni    R   R   s   Couldn't open "s   " for read.i   R   s   pyrcio_m:  Empty input.(	   R   R   R   R   R   R   R   R   R   (   R   R   R   R   R   R   (    (    s0   /Users/kerl/pub_http_internet/python/pyrcio_m.pyt   read_real_column_vectorr   s.    
c         C   sG   t  |  ƒ } x4 t d | ƒ D]# } d |  | j |  | j f GHq Wd  S(   Ni    s   %18.11f %18.11f(   R	   t   ranget   realt   imag(   R   R   t   i(    (    s0   /Users/kerl/pub_http_internet/python/pyrcio_m.pyt   print_complex_column_vector’   s    c         C   s7   t  |  ƒ } x$ t d | ƒ D] } d |  | GHq Wd  S(   Ni    s   %18.11f(   R	   R!   (   R   R   R$   (    (    s0   /Users/kerl/pub_http_internet/python/pyrcio_m.pyt   print_real_column_vector˜   s    c         C   sE  g  } t  j  |  ƒ } | d d k r5 | d d !} n  t j d d | ƒ } t j d d | ƒ } | d k rŽ t j d I| IJt j d ƒ n  t j d	 | ƒ } t | ƒ d
 d k rÙ t j d I| IJt j d ƒ n  t | ƒ d
 } d } xO t d | ƒ D]> } | j	 t
 t | | ƒ t | | d ƒ ƒ ƒ | d
 7} qÿ W| S(   Niÿÿÿÿs   
i    s   ^\s+R   s   \s+$s   pyrcio_m:  empty input at linei   s   \s+i   s$   pyrcio_m:  odd complex input at line(   R   R   R   R   R   R   R   R	   R!   R   t   complexR
   (   R   R   R   R   R   t   ncplxt   jR$   (    (    s0   /Users/kerl/pub_http_internet/python/pyrcio_m.pyt   complex_row_vector_from_stringŸ   s&    .c         C   së   g  } t  j  |  ƒ } | d d k r5 | d d !} n  t j d d | ƒ } t j d d | ƒ } | d k rŽ t j d I| IJt j d ƒ n  t j d	 | ƒ } d } x> t d t | ƒ ƒ D]' } | j	 t
 | | ƒ ƒ | d 7} q¼ W| S(
   Niÿÿÿÿs   
i    s   ^\s+R   s   \s+$s   pyrcio_m:  empty input at linei   s   \s+(   R   R   R   R   R   R   R   R!   R	   R   R
   (   R   R   R   R   R   R)   R$   (    (    s0   /Users/kerl/pub_http_internet/python/pyrcio_m.pyt   real_row_vector_from_string¾   s    c         C   s£   t  |  ƒ } t  |  d ƒ } d } xQ t d | ƒ D]@ } t  |  | ƒ } | | k  r] | } n  | | k r2 | } q2 q2 W| | k rŸ t j d IJt j d ƒ n  | S(   Ni    s   pyrcio_m:  ragged matrix.i   (   R	   R!   R   R   R   (   t   At   nrt   min_nct   max_ncR$   t   cur_nc(    (    s0   /Users/kerl/pub_http_internet/python/pyrcio_m.pyt   validate_matrixÚ   s    	c         C   s  d } d } g  } d } |  d k r0 t  j } n? y t |  d ƒ } Wn) t  j d |  d IJt  j d ƒ n XxI | j ƒ  } | d k rŽ Pn  | d 7} | j t | | ƒ ƒ | d 7} qr t | ƒ } |  d k rà | j	 ƒ  n  | d k sø | d k rt  j d IJt  j d ƒ n  | S(	   Ni    R   R   s   Couldn't open "s   " for read.i   R   s   pyrcio_m:  Empty input.(
   R   R   R   R   R   R   R   R*   R1   R   (   R   R-   t   ncR,   R   R   R   (    (    s0   /Users/kerl/pub_http_internet/python/pyrcio_m.pyt   read_complex_matrixê   s2    
c         C   s#  d } d } g  } d } |  d k r0 t  j } n? y t |  d ƒ } Wn) t  j d |  d IJt  j d ƒ n XxI | j ƒ  } | d k rŽ Pn  | d 7} | j t | | ƒ ƒ | d 7} qr t | ƒ } |  d k rà | j	 ƒ  n  | d k sø | d k rt  j d IJt  j d ƒ n  t | ƒ | S(	   Ni    R   R   s   Couldn't open "s   " for read.i   R   s   pyrcio_m:  Empty input.(
   R   R   R   R   R   R   R   R+   R1   R   (   R   R-   R2   R,   R   R   R   (    (    s0   /Users/kerl/pub_http_internet/python/pyrcio_m.pyt   read_real_matrix
  s4    

c         C   sy   t  |  ƒ } t  |  d ƒ } xV t d | ƒ D]E } x; t d | ƒ D]* } d |  | | j |  | | j f GqB WHq, Wd  S(   Ni    s   %11.7f %11.7f(   R	   R!   R"   R#   (   R,   R-   R2   R$   R)   (    (    s0   /Users/kerl/pub_http_internet/python/pyrcio_m.pyt   print_complex_matrix+  s    (c         C   se   t  |  ƒ } t  |  d ƒ } xB t d | ƒ D]1 } x' t d | ƒ D] } d |  | | GqB WHq, Wd  S(   Ni    s   %11.7f(   R	   R!   (   R,   R-   R2   R$   R)   (    (    s0   /Users/kerl/pub_http_internet/python/pyrcio_m.pyt   print_real_matrix4  s    (   t
   __future__R    R   R   R   R   R   R   R    R%   R&   R*   R+   R1   R3   R4   R5   R6   (    (    (    s0   /Users/kerl/pub_http_internet/python/pyrcio_m.pyt   <module>   s    	 	  					 !		