
    HR-eV                        d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl mZ d dl	Z
d dl	mZ d dlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZmZm Z  d dl!m"Z"m#Z# d dl$m%Z%m&Z&m'Z' d dl(m)Z) d d	l*m+Z+ d
dl,m-Z-m.Z.m/Z/  G d dej0                  Z1 G d de/          Z2 G d de.e2          Z3 G d de3          Z4 G d de3          Z5e j6        d             Z7dS )    N)suppress)char)ATTRIBUTE_TO_KEYWORD
FITS2NUMPYKEYWORD_NAMESKEYWORD_TO_ATTRIBUTETDEF_REColDefsColumn_AsciiColDefs_cmp_recformats_convert_format_FormatP_FormatQ_makep_parse_tformat_scalar_to_format)FITS_rec_get_recarray_field_has_unicode_fields)Header_pad_length)_is_int_str_to_num	path_like)lazyproperty)AstropyDeprecationWarning   )DELAYEDExtensionHDU	_ValidHDUc                   0    e Zd ZdZdZdZdZej        Z	dZ
dS )FITSTableDumpDialectzM
    A CSV dialect for the Astropy format of ASCII dumps of FITS tables.
     
"TN)__name__
__module____qualname____doc__	delimiterlineterminator	quotecharcsv	QUOTE_ALLquotingskipinitialspace     9lib/python3.11/site-packages/astropy/io/fits/hdu/table.pyr#   r#   .   s8          INImGr3   r#   c                       e Zd ZdZeZeZdZdZ	e
d             Ze
	 	 	 	 dd            Zed             Zed	             Zd
 Zd Zd Zd Zd ZdS )_TableLikeHDUz
    A class for HDUs that have table-like data.  This is used for both
    Binary/ASCII tables as well as Random Access Group HDUs (which are
    otherwise too dissimilar for tables to use _TableBaseHDU directly).
    FTc                     t           )z
        This is an abstract HDU type for HDUs that contain table-like data.
        This is even more abstract than _TableBaseHDU which is specifically for
        the standard ASCII and Binary Table types.
        NotImplementedErrorclsheaders     r4   match_headerz_TableLikeHDU.match_headerO   
     "!r3   Nr   c                     |                      |          }t          j        ||||          } | d|||d|}	|                    |	           |	S )a  
        Given either a `ColDefs` object, a sequence of `Column` objects,
        or another table HDU or table data (a `FITS_rec` or multi-field
        `numpy.ndarray` or `numpy.recarray` object, return a new table HDU of
        the class this method was called on using the column definition from
        the input.

        See also `FITS_rec.from_columns`.

        Parameters
        ----------
        columns : sequence of `Column`, `ColDefs` -like
            The columns from which to create the table data, or an object with
            a column-like structure from which a `ColDefs` can be instantiated.
            This includes an existing `BinTableHDU` or `TableHDU`, or a
            `numpy.recarray` to give some examples.

            If these columns have data arrays attached that data may be used in
            initializing the new table.  Otherwise the input columns will be
            used as a template for a new table with the requested number of
            rows.

        header : `Header`
            An optional `Header` object to instantiate the new HDU yet.  Header
            keywords specifically related to defining the table structure (such
            as the "TXXXn" keywords like TTYPEn) will be overridden by the
            supplied column definitions, but all other informational and data
            model-specific keywords are kept.

        nrows : int
            Number of rows in the new table.  If the input columns have data
            associated with them, the size of the largest input column is used.
            Otherwise the default is 0.

        fill : bool
            If `True`, will fill all cells with zeros or blanks.  If `False`,
            copy the data from input, undefined cells will still be filled with
            zeros/blanks.

        character_as_bytes : bool
            Whether to return bytes for string columns when accessed from the
            HDU. By default this is `False` and (unicode) strings are returned,
            but for large tables this may use up a lot of memory.

        Notes
        -----
        Any additional keyword arguments accepted by the HDU class's
        ``__init__`` may also be passed in as keyword arguments.
        nrowsfillcharacter_as_bytes)datar<   rC   r2   )_columns_typer   from_columns_add_listener)
r;   columnsr<   rA   rB   rC   kwargscoldefsrD   hdus
             r4   rF   z_TableLikeHDU.from_columnsX   s    v ##G,,$5t@R
 
 
 c 
f9K
 
OU
 
 	c"""
r3   c                      t          g           S )T
        The :class:`ColDefs` objects describing the columns in this table.
        )r
   selfs    r4   rH   z_TableLikeHDU.columns   s     r{{r3   c                     t           )z
        table-like HDUs must provide an attribute that specifies the number of
        rows in the HDU's table.

        For now this is an internal-only attribute.
        r8   rN   s    r4   _nrowsz_TableLikeHDU._nrows   s
     "!r3   c                    | j         }| j        rt          d |j        D                       r| j        | j        | j        k    rz|                     | j        t          j        | j	                  }| j
        d         | j
        d         z  }|d|                             |j        t          j        j                  }ng|                     | j        |j        | j	                  }|t          j        g |j                  }|                    t          j        j                  }|                     |           |                    | j                  }| j        |_        |                    |           |S )z,Get the table data from an input HDU object.c              3   P   K   | ]!}t          |          t          t          fv V  "d S N)typer   r   ).0rs     r4   	<genexpr>z,_TableLikeHDU._get_tbdata.<locals>.<genexpr>   s2      QQDGG(33QQQQQQr3   NNAXIS1NAXIS2)dtyperU   r[   )rH   _load_variable_length_dataany_recformats
_data_size_theap_get_raw_datanpuint8_data_offset_headerviewr[   recrecarrayrQ   array_init_tbdata
_data_typerG   )rO   rH   raw_datatbsizerD   s        r4   _get_tbdataz_TableLikeHDU._get_tbdata   sN   , +	2QQW=PQQQQQ	2 +$+-- ))$/28TEVWWH\(+dl8.DDFGVG$))BFO)TTDD))$+w}dFWXXH 8Bgm<<<==11D$yy))*.*I'd###r3   c                 \   | j         }|j                            d          |_        | j        |_        | j        |_        | j        d         |_        | j        d         | j        d         z  }| j        |z
  |_        t          |          D ]\  }}|
                    |          |_         |`d S )N>PCOUNTrY   rZ   )rH   r[   newbyteorder_uintra   _heapoffsetrf   	_heapsize_gap	enumeratefieldrj   _arrays)rO   rD   rH   rn   idxcols         r4   rk   z_TableLikeHDU._init_tbdata   s    ,Z,,S11
 Z
  ;h/h'$,x*@@K&(	 "'** 	( 	(HC

3CII OOOr3   c                 &    | j         s	| j         dS dS )zLoad the data if asked to.N)_data_loadedrD   rN   s    r4   _update_load_dataz_TableLikeHDU._update_load_data   s"      	IIII	 	r3   c                 ^    t          j        | j        | j        d| j                  | _        dS )zh
        Update the data upon addition of a new column through the `ColDefs`
        interface.
        Fr@   Nr   rF   rH   rQ   _character_as_bytesrD   )rO   rH   columns      r4   _update_column_addedz"_TableLikeHDU._update_column_added   4     )L+#7	
 
 
			r3   c                 ^    t          j        | j        | j        d| j                  | _        dS )zc
        Update the data upon removal of a column through the `ColDefs`
        interface.
        Fr@   Nr   )rO   rH   col_idxs      r4   _update_column_removedz$_TableLikeHDU._update_column_removed   r   r3   )Nr   FF)r'   r(   r)   r*   r   rl   r
   rE   rt   r]   classmethodr=   rF   r   rH   propertyrQ   ro   rk   r   r   r   r2   r3   r4   r6   r6   :   s         JM E "&" " ["   B B B [BH   \ " " X"  B  .  

 
 

 
 
 
 
r3   r6   c                       e Zd ZdZdZ	 	 	 	 	 	 	 d fd	Zed             Zed             Z	ed             Z
e
j        d             Z
ed	             Zed
             Zd Zd Zd fd	Zd fd	Zd Z fdZd ZddZd Z xZS )_TableBaseHDUaw  
    FITS table extension base HDU class.

    Parameters
    ----------
    data : array
        Data to be used.
    header : `Header` instance
        Header to be used. If the ``data`` is also specified, header keywords
        specifically related to defining the table structure (such as the
        "TXXXn" keywords like TTYPEn) will be overridden by the supplied column
        definitions, but all other informational and data model-specific
        keywords are kept.
    name : str
        Name to be populated in ``EXTNAME`` keyword.
    uint : bool, optional
        Set to `True` if the table contains unsigned integer columns.
    ver : int > 0 or None, optional
        The ver of the HDU, will be the value of the keyword ``EXTVER``.
        If not given or None, it defaults to the value of the ``EXTVER``
        card of the ``header`` or 1.
        (default: None)
    character_as_bytes : bool
        Whether to return bytes for string columns. By default this is `False`
        and (unicode) strings are returned, but this does not respect memory
        mapping and loads the whole column in memory when accessed.
    FNc                 :   t                                          ||||           || _        || _        |t          u r|t          d          || _        nd| j        | j        fdddddd	d
g}|0|	                    d          }|
                    |j                   t          |          | _        t          |t          j                  r%|j        j        t          || j                  r|| _        n| j                            |          | _        |t+                      }	|                                D ]V}
t/          j        |
          }	 |                    d          }n# t4          $ r Y 9w xY w|dv r|	                    |           W|	rYd                    d t;          |	          D                       }t=          j        d                     |          tB                     | j        j"        | j        d<   | j        j#        d         | j        d<   tI          | j        j%                  | j        d<   | j        j%        | _&        | j&        '                    | j                   | (                                 tS          tT          tV                    5  tY          | j&                  D ]$\  }}| j        -                    |          |_.        %| j&        `/d d d            n# 1 swxY w Y   n|ntU          d          |r|| _0        |	|| _1        d S d S )N)rD   r<   nameverzNo header to setup HDU.XTENSION)BITPIX   zarray data type)NAXIS   znumber of array dimensions)rY   r   zlength of dimension 1)rZ   r   zlength of dimension 2)rr   r   znumber of group parameters)GCOUNTr   znumber of groups)TFIELDSr   znumber of table fieldsT)striplabel   TCDLTTCRPXTCRVLTCTYPTCUNITRPOS, c              3       K   | ]	}|d z   V  
dS )nNr2   )rV   xs     r4   rX   z)_TableBaseHDU.__init__.<locals>.<genexpr>y  s&      (P(PQS(P(P(P(P(P(Pr3   a  The following keywords are now recognized as special column-related attributes and should be set via the Column objects: {}. In future, these values will be dropped from manually specified headers automatically and replaced with values generated based on the Column objects.rY   r   rZ   r   Table data has incorrect type.)2super__init__rt   r   r   
ValueErrorrf   
_extension_ext_commentcopyextendcardsr   
isinstancerc   ndarrayr[   fieldsrl   rD   rF   setkeysr	   matchgroup	Exceptionaddjoinsortedwarningswarnformatr   _raw_itemsizeshapelen_coldefsrH   rG   updater   	TypeErrorAttributeErrorrx   ry   rj   rz   r   r   )rO   rD   r<   r   uintr   rC   r   hcopyfuture_ignorekeywordr   base_keywordr   r{   r|   	__class__s                   r4   r   z_TableBaseHDU.__init__/  sg    	d6#FFF
#5 7??~ !:;;;
  & T_d.?@0:66;18	E ! $//U[)))!%==DL$
++ BB
0A0MdDO44 C $DII $ < <T B BDI %$'EEM#);;== < < 'g 6 6%+0;;w+?+?LL( % % %$H%' ,   *--l;;;$ 
#yy(P(P&:O:O(P(P(PPP .
 /5fTll5   *.)@X&)-);X&*-di.@*A*AY'#y1**49555i88 	- 	- %.dl$;$; 9 9S$(IOOC$8$8		 ,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-  @AAA  	DI?DHHH ?s%   E**
E76E7AK))K-0K-c                     t           )z
        This is an abstract type that implements the shared functionality of
        the ASCII and Binary Table HDU types, which should be used instead of
        this.
        r8   r:   s     r4   r=   z_TableBaseHDU.match_header  r>   r3   c                 |    | j         r!t          | j        d          r| j        j        S |                     |           S )rM   r   )	_has_datahasattrrD   r   rE   rN   s    r4   rH   z_TableBaseHDU.columns  s@    
 > 	&gdi<< 	&9%%!!$'''r3   c                 b    |                                  }| j        |_        | j        |_        | `|S rT   )ro   rH   r   r   )rO   rD   s     r4   rD   z_TableBaseHDU.data  s1    !!#'#; Lr3   c                 &   d| j         v r| j         d         |u rd S d| _        nd| _        d| _        |S| j        rLd                    | j        j                  }t          j                            d || j        j	        d          }t          |t          j                  r^|j        j        Q|                    | j                  }t          |j        | j                  s.|                     |j                  }t#          j        |          }d| j         v r%| j                            | j         d                    || j         d<   | j        j        | _        | j                            | j                   |                                  t/          t0          t2                    5  t5          | j                  D ]$\  }}| j                            |          |_        %| j        `d d d            n# 1 swxY w Y   n|nt1          d          |S )NrD   T,r   )formatsnamesr   r   )__dict___data_replaced	_modifiedrH   r   r_   rc   rh   rj   r   r   r   r[   r   rg   rl   rE   r   rF   _remove_listenerrD   rG   r   r   r   r   rx   ry   rz   )rO   rD   r   new_columnsr{   r|   s         r4   rD   z_TableBaseHDU.data  s)   T]""}V$,,&*##"&D<DL<hht|788G6<<gT\-?q    D dBJ'' "	>DJ,=,I 99T_--DdlD,>?? : #00>>,[99&&--dmF.CDDD$(DM&!9,DLL&&ty111KKMMM)^44 	) 	) !*$, 7 7 5 5HC $	 4 4CII L(	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) \<=== s   &AG33G7:G7c                 n    | j         s| j                            dd          S t          | j                  S )NrZ   r   )r~   rf   getr   rD   rN   s    r4   rQ   z_TableBaseHDU._nrows  s3      	"<##Ha000ty>>!r3   c                 n    | j         d         | j         d         z  }| j                             d|          S )NrY   rZ   THEAP)rf   r   )rO   sizes     r4   ra   z_TableBaseHDU._theap  s2    |H%X(>>|...r3   c                 \   | j                             d| j        j        d           | j                             d| j        j        d         d           | j                             dt          | j                  d           |                                  |                                  dS )	zN
        Update header keywords to reflect recent changes of columns.
        rY   r   afterrZ   r   r   r   N)	rf   r   rD   r   r   r   rH   _clear_table_keywords_populate_table_keywordsrN   s    r4   r   z_TableBaseHDU.update  s     	49#:'JJJ49?1#5XFFFC$5$5XFFF""$$$%%'''''r3   c                     |                      | j                                        | j                                                  S )zP
        Make a copy of the table HDU, both header and data are copied.
        rD   r<   )r   rD   r   rf   rN   s    r4   r   z_TableBaseHDU.copy  s4     ~~49>>#3#3DL<M<M<O<O~PPPr3   c                 d   | j         r| j                            | j                    t	          | j        j                  | j        d<   | j        j        d         | j        d<   | j        d         | j        d         z  }| j                            d|          }||z
  | j        _	        | j        j
        | j        j	        z   }|dk    r
|| j        d<   |                                  t          | j        j                  D ]}| j        j        j        |         }t          |t                     r`| j                            |          j        }|j        }	 |	|j        |j        |          }|j        | j        d	t/          |d
z             z   <   t1                                          ||          S )N)update_heap_pointersr   r   rZ   rY   r   rr   )repeatmaxTFORMr   )r   rD   _scale_back_manages_own_heapr   r   rf   r   r   rw   rv   r   range_nfieldsr_   r   r   ry   r   r   r[   r   tformstrr   _prewriteto)rO   checksuminplacern   	heapstartpcountr{   r   _max
format_clsr   s             r4   r   z_TableBaseHDU._prewriteto  s   > 	HI!!4;Q7Q!RRR&)$)*<&=&=DL#%)Y_Q%7DL" \(+dl8.DDF((&99I&/DINY(49>9Fzz)/X& ))+++ TY/00 H H+7<fh// H9??3//3D!'!1J'ZV]PTUUUF;A<DL3sQw<<!78ww""8W555r3   r   c           	          t                                          |          }t           j                  dk    r*t	           j        d         t
                    r( j        d                                          j        k    sEd}d j         d} j        f fd	}|                     	                    ||||                      
                    d	d
d d||            
                    dd
d d||            
                    ddd d||            j        d         }t          |          D ]/} 
                    dt          |dz             z   d
d
d
||           0|S )z.
        _TableBaseHDU verify method.
        optionr   r   z-The XTENSION keyword must match the HDU type.z"Converted the XTENSION keyword to .c                 *    j         j        f| d<   d S Nr   )r   r   )r<   rO   s    r4   fixz"_TableBaseHDU._verify.<locals>.fixH  s    !%$2C DF1IIIr3   )err_textfix_textr   r   Nc                     | dk    S )Nr   r2   vs    r4   <lambda>z'_TableBaseHDU._verify.<locals>.<lambda>Q  s
    Q!V r3   r   r   c                     | dk    S )Nr   r2   r   s    r4   r   z'_TableBaseHDU._verify.<locals>.<lambda>R  s
    a1f r3   r   r      c                 8    t          |           o| dk    o| dk    S )Nr   i  )r   r   s    r4   r   z'_TableBaseHDU._verify.<locals>.<lambda>V  s    71::=!q&=Q#X r3   r   )r   _verifyr   rf   r   r   rstripr   append
run_option	req_cardsr   )	rO   r   errsr   r   r   tfieldsr{   r   s	   `       r4   r  z_TableBaseHDU._verify;  s    wwf--t|q  4<?C00LO**,,??JRRRR#| E E E E E E OOH# $     NN7D*<*<aNNNNN8T+=+=q&$OOONN>>   l9-GW~~ W WwS1W5tT4QUVVVVr3   c                      j         j        } j        r? j        d}nt	           j                  }t	           j                  } j        j        }nN j        d         } j        d         }d                     fdt          |          D                       }d| d}| d	| d
}t	           j                  } j
         j        ||||fS )zC
        Summarize the HDU: name, dimensions, and formats.
        Nr   rZ   r   r   c                 P    g | ]"}j         d t          |dz             z            #S )r   r   )rf   r   )rV   jrO   s     r4   
<listcomp>z*_TableBaseHDU._summary.<locals>.<listcomp>u  s/    JJJgAE

23JJJr3   []zR x C)r   r'   r~   rD   r   rH   r   rf   r   r   r   r   )rO   
class_namerA   ncolsr   dimsncardss   `      r4   _summaryz_TableBaseHDU._summary`  s     ^,
  	#y DI%%E\)FF L*EL+EYYJJJJU5\\JJJ F #]]]F%%U%%%T\""	48ZvFFr3   c                 x    t                                          ||           |                     |           d S )N)index)r   r   r   )rO   rH   r{   r   s      r4   r   z$_TableBaseHDU._update_column_removed}  s<    &&w444 	"""-----r3   c                 ,   t           |         }|t          |dz             z   }|| j        v r|
| j        |= dS || j        |<   dS t          j        |          }t          t          d|                   D ]B}	|	t          |dz             z  }	|	| j        v r"| j                            |	||fd            dS Ct          |dz   d         D ]@}
|
t          |dz             z  }
|
| j        v r | j                            |
||f            dS A|| j        |<   dS )zN
        Update the header when one of the column objects is updated.
        r   NTr   )r   r   rf   r   r  reversedinsert)rO   r   r   attr	old_value	new_valuer   r   keyword_idxbefore_keywordafter_keywords              r4    _update_column_attribute_changedz._TableBaseHDU._update_column_attribute_changed  si    ,D1Wq[!1!11dl""  L)))(1W%%%'-l;;K #+=++F"G"G 6 6#gk"2"22!T\11L''&)(<D (    EE	 2 &3;?3D3D%E 6 6M!S1%5%55M$44++MGY;OPPP 5
 -6DL)))r3   c                 j   g }t          | j                                                  D ]\  }}t          j        |          }	 |                    d          }n# t          $ r Y <w xY w|t          v rV|dv rNt          |                    d                    dz
  }|	                    ||                    d          ||f           t          |t          j        d          d          }|D ]\  }}}	}|||k    r| j        |= |t          |t          j        d	          
          }
|
D ]b\  }	}}}||k    r| j        j        |         }|t          |          z   |j        |j        f}| j                            ||           | j        |= cd| j        v r| j        dxx         dz  cc<   dS dS dS )a  
        Wipe out any existing table definition keywords from the header.

        If specified, only clear keywords for the given table index (shifting
        up keywords for any other columns).  The index is zero-based.
        Otherwise keywords for all columns.
        r   r   numr   r   T)keyreverseN   )r%  r   )rx   rf   r   r	   r   r   r   r   intr  r   operator
itemgetterr   r   valuecommentr  )rO   r  table_keywordsr{   r   r   r   r$  rev_sorted_idx_0_sorted_idx_3old_cardnew_cards                r4   r   z#_TableBaseHDU._clear_table_keywords  s    %dl&7&7&9&9:: 	P 	PLCM'**E${{733    333
   $   %++e,,--1%%sEKKNNL#&NOOO " 3A 6 6
 
 
 %5 	& 	& C!S}L% !.h6I!6L6LMMML1= * *-7L#%<<<-g6(3s883X^XEUV##GX666L)) DL((Y'''1,'''''  )(s   A
A&%A&c                     t          | j                  D ]O\  }}t          j                    D ]6\  }}t	          ||          }||t          |dz             z   }|| j        |<   7PdS )z;Populate the new table definition keywords from the header.Nr   )rx   rH   r   itemsgetattrr   rf   )rO   r{   r   r   r  vals         r4   r   z&_TableBaseHDU._populate_table_keywords  s    $T\22 	0 	0KC!5!;!=!= 0 0fd++?%C!G4G,/DL)	0	0 	0r3   NNNFNF)FFr   rT   )r'   r(   r)   r*   r   r   r   r=   r   rH   rD   setterr   rQ   ra   r   r   r   r  r  r   r"  r   r   __classcell__r   s   @r4   r   r     s        8   u u u u u un " " [" ( ( \(   \ 
[8 8 [8t " " X" / / \/	( 	( 	(Q Q Q6 6 6 6 6 6:# # # # # #JG G G:. . . . .&6 &6 &6P=- =- =- =-~0 0 0 0 0 0 0r3   r   c                        e Zd ZdZdZdZdZeZ e	j
        d          Z	 d fd	Zed	             Zd
 Z fdZd fd	Z xZS )TableHDUa  
    FITS ASCII table extension HDU class.

    Parameters
    ----------
    data : array or `FITS_rec`
        Data to be used.
    header : `Header`
        Header to be used.
    name : str
        Name to be populated in ``EXTNAME`` keyword.
    ver : int > 0 or None, optional
        The ver of the HDU, will be the value of the keyword ``EXTVER``.
        If not given or None, it defaults to the value of the ``EXTVER``
        card of the ``header`` or 1.
        (default: None)
    character_as_bytes : bool
        Whether to return bytes for string columns. By default this is `False`
        and (unicode) strings are returned, but this does not respect memory
        mapping and loads the whole column in memory when accessed.

    TABLEzASCII table extensionr$   z4(?P<code>[ADEFIJ])(?P<width>\d+)(?:\.(?P<prec>\d+))?NFc                 T    t                                          |||||           d S )N)r   r   rC   )r   r   )rO   rD   r<   r   r   rC   r   s         r4   r   zTableHDU.__init__  s<     	&tAS 	 	
 	
 	
 	
 	
r3   c                     |j         d         }|j        }t          |t                    r|                                }|j        dk    o
|| j        k    S )Nr   r   r   r+  r   r   r  r   r   r;   r<   cardxtensions       r4   r=   zTableHDU.match_header  sN    |A:h$$ 	)((H|z)Hh#..HHr3   c                 <   | j         }d t          |j                  D             }t          j                            |          }|rt          d|           |j        d         |j        d         z   dz
  }i }t          t          |                    D ]}dt          |j        |                   z   }|t          |          dz
  k    r?| j        d         |k    r.dt          |j        |         | j        d         z   |z
            z   }||j        |         dz
  f||j        |         <   |                     | j        || j                  }|                    t          j        j                  }	|                     |	           |	                    | j                  S )Nc                     g | ]\  }}|S r2   r2   )rV   r{   r   s      r4   r  z(TableHDU._get_tbdata.<locals>.<listcomp>%  s    :::vsA:::r3   zDuplicate field names: r   SrY   )rH   rx   r   rc   rh   find_duplicater   spansstartsr   r   r   rf   rb   rQ   re   rg   ri   rk   rl   )
rO   rH   r   dupitemsizer[   r{   	data_typerm   rD   s
             r4   ro   zTableHDU._get_tbdata#  s   ,::7=!9!9::: f##E** 	><s<<===
 =$w~b'99A=W&& 		M 		MCc'-"4555Ic'llQ&&&<)H44 #cc*T\(-CChN' ' !I *3GN34G!4K(LE'-$%%%%dk5$:KLL}}RV_--$yy)))r3   c                 t   | j         r| j                            t          j        t          j                  }t          j        t          | j                  dz  t          j                  }t          j	        ||          }| 
                    |          }|S t                                                      S )J
        Calculate the value for the ``DATASUM`` card in the HDU.
        rU   r[       r\   )r   rD   rg   rc   r   ubyte
frombufferr   r   r  _compute_checksumr   _calculate_datasum)rO   bytes_arraypaddingdcsr   s        r4   rV  zTableHDU._calculate_datasumD  s     > 	0 )..bj.IIKmK	$:$:T$ARRRG	+w//A''**BI 77--///r3   r   c           	      $   t                                          |          }|                     ddd d||           | j        d         }t	          |          D ]4}|                     dt          |dz             z   dt          d||           5|S )	z+
        `TableHDU` verify method.
        r   rr   Nc                     | dk    S r   r2   r   s    r4   r   z"TableHDU._verify.<locals>.<lambda>_  s
    !q& r3   r   r   TBCOLr   )r   r  r  rf   r   r   r   )rO   r   r	  r
  r{   r   s        r4   r  zTableHDU._verifyZ  s     wwf--x'9'91fdKKK,y)>> 	V 	VCNN7Sq\\14$PTUUUUr3   )NNNNFr8  )r'   r(   r)   r*   r   r   _padding_byter   rE   recompile_TableHDU__format_REr   r   r=   ro   rV  r  r:  r;  s   @r4   r=  r=    s         . J*LM!M"*TUUK OT
 
 
 
 
 
 I I [I* * *B0 0 0 0 0,	 	 	 	 	 	 	 	 	 	r3   r=  c                       e Zd ZdZdZdZ	 	 	 	 	 	 d fd	Zed             Zd Z	 fd	Z
d
 Zd Z ej        d          ZddZ eej        e          r$exj        e                    dd          z  c_        ddZ eej        e          r$exj        e                    dd          z  c_         ee          Zd Zd Zedd            Zed             Z xZS )BinTableHDUaX  
    Binary table HDU class.

    Parameters
    ----------
    data : array, `FITS_rec`, or `~astropy.table.Table`
        Data to be used.
    header : `Header`
        Header to be used.
    name : str
        Name to be populated in ``EXTNAME`` keyword.
    uint : bool, optional
        Set to `True` if the table contains unsigned integer columns.
    ver : int > 0 or None, optional
        The ver of the HDU, will be the value of the keyword ``EXTVER``.
        If not given or None, it defaults to the value of the ``EXTVER``
        card of the ``header`` or 1.
        (default: None)
    character_as_bytes : bool
        Whether to return bytes for string columns. By default this is `False`
        and (unicode) strings are returned, but this does not respect memory
        mapping and loads the whole column in memory when accessed.

    BINTABLEzbinary table extensionNFc                    |Z|t           urQddlm} t          ||          r;ddlm}  ||          }	||	j                            |           |	j        }|	j        }t                      
                    ||||||           d S )Nr   )Table)table_to_hdu)r   r   r   rC   )r   astropy.tablerf  r   astropy.io.fits.conveniencerg  r<   r   rD   r   r   )rO   rD   r<   r   r   r   rC   rf  rg  rK   r   s             r4   r   zBinTableHDU.__init__  s     G 3 3++++++$&& $DDDDDD"l4((%J%%f---x1 	 	
 	
 	
 	
 	
r3   c                     |j         d         }|j        }t          |t                    r|                                }|j        dk    o
|| j        dfv S )Nr   r   A3DTABLErA  rB  s       r4   r=   zBinTableHDU.match_header  sS    |A:h$$ 	)((H|z)Vh3>::V.VVr3   c                 P   t          | j                  5 }|                    t          j        t          j                  }|                     |          }|                                {t          |j	                  D ]e}t          |j        j        |         t                    r>|                    |          D ](}t          |          s|                     ||          })fn(|                     |                                |          }|cddd           S # 1 swxY w Y   dS )zT
        Calculate the value for the ``DATASUM`` card given the input data.
        rQ  N)_binary_table_byte_swaprD   rg   rc   r   rS  rU  rb   r   r   r   rH   r_   r   ry   r   _get_heap_data)rO   rD   doutcsumr{   coldatas         r4   _calculate_datasum_with_heapz(BinTableHDU._calculate_datasum_with_heap  sa    %TY// 	499"*BH9==D))$//D
 !!##+ !// I IC!$,":3"?JJ I'+zz# I IG $'w<< ) (#'#9#9'4#H#HDDI --d.A.A.C.CTJJ3	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   C9DD"Dc                 z    | j         r|                                 S t                                                      S )rP  )r   rr  r   rV  )rO   r   s    r4   rV  zBinTableHDU._calculate_datasum  s;     > 
	0 44666 77--///r3   c                    d}| j         |S t          | j                   5 }t          |          r|                     |           nP|                    |           |j        dk    r0|                    |j        dz                      d                     |j        }| j        st          |j
                  D ]y}t          |j        j        |         t                    s(| j                             |          }|D ]4}t!          |          dk    r||j        z  }|                    |           5znN|                                }t!          |          dk    r'|t!          |          z  }|                    |           ||j        z
  |_        ||z  }d d d            n# 1 swxY w Y   || j         j        | j         j        z  z  }|S )Nr    ascii)rD   rm  r   _writedata_by_row
writearrayrw   writeencoder   r   r   r   rH   r_   r   ry   r   nbytesrn  rv   r   r   )	rO   fileobjr   rD   r{  r{   ry   row	heap_datas	            r4   _writedata_internalzBinTableHDU._writedata_internal  s   9K$TY// &	4"4(( F &&w////""4(((
 9q==MM49t#3";";G"D"DEEEYF) 2
 !// 4 4C%dl&>s&CXNN !  IOOC00E$ 4 4s88a<<"cj0F#..s33344 !//11	y>>A%%c)nn,F&&y111#di/DNFNDM&	 &	 &	 &	 &	 &	 &	 &	 &	 &	 &	 &	 &	 &	 &	P 		!888s   E5F!!F%(F%c                      fdt          t           j        j                            D             }t          t           j                            D ]%}|D ]}||         }d }|j        j        dk    rm|j        j                            |j        j                  }t          |j        j        |dz   d                    }t          j
                            |d          }|                    |           |}|j        j                            |j        j                  }t          |j        j        |dz   d                    }	d||	z
  z  }
|                    |
                    d                      'd S )Nc                 D    g | ]}j                             |          S r2   )rD   ry   )rV   r{   rO   s     r4   r  z1BinTableHDU._writedata_by_row.<locals>.<listcomp>  s'    PPP3$)//#&&PPPr3   Ur   rv  ru  )r   r   rD   rH   r[   kindr   r  r(  rc   r   rz  rx  ry  )rO   r|  r   r{   ry   itemfield_widthir  item_lengthrX  s   `          r4   rw  zBinTableHDU._writedata_by_row
  s^   PPPP%DI<M8N8N2O2OPPP
 TY(( 	; 	;C ; ;Sz";#s**--ek.>??A"%ekoa!egg&>"?"?K7>>$88D""4(((*
,,TZ_==A"%djnQUWW&=">">K$k(ABGMM'.."9"9:::!;	; 	;r3   aq  

        - **datafile:** Each line of the data file represents one row of table
          data.  The data is output one column at a time in column order.  If
          a column contains an array, each element of the column array in the
          current row is output before moving on to the next column.  Each row
          ends with a new line.

          Integer data is output right-justified in a 21-character field
          followed by a blank.  Floating point data is output right justified
          using 'g' format in a 21-character field with 15 digits of
          precision, followed by a blank.  String data that does not contain
          whitespace is output left-justified in a field whose width matches
          the width specified in the ``TFORM`` header parameter for the
          column, followed by a blank.  When the string data contains
          whitespace characters, the string is enclosed in quotation marks
          (``""``).  For the last data element in a row, the trailing blank in
          the field is replaced by a new line character.

          For column data containing variable length arrays ('P' format), the
          array data is preceded by the string ``'VLA_Length= '`` and the
          integer length of the array for that row, left-justified in a
          21-character field, followed by a blank.

          .. note::

              This format does *not* support variable length arrays using the
              ('Q' format) due to difficult to overcome ambiguities. What this
              means is that this file format cannot support VLA columns in
              tables stored in files that are over 2 GB in size.

          For column data representing a bit field ('X' format), each bit
          value in the field is output right-justified in a 21-character field
          as 1 (for true) or 0 (for false).

        - **cdfile:** Each line of the column definitions file provides the
          definitions for one column in the table.  The line is broken up into
          8, sixteen-character fields.  The first field provides the column
          name (``TTYPEn``).  The second field provides the column format
          (``TFORMn``).  The third field provides the display format
          (``TDISPn``).  The fourth field provides the physical units
          (``TUNITn``).  The fifth field provides the dimensions for a
          multidimensional array (``TDIMn``).  The sixth field provides the
          value that signifies an undefined value (``TNULLn``).  The seventh
          field provides the scale factor (``TSCALn``).  The eighth field
          provides the offset value (``TZEROn``).  A field value of ``""`` is
          used to represent the case where no value is provided.

        - **hfile:** Each line of the header parameters file provides the
          definition of a single HDU header card as represented by the card
          image.
      c                 Z   t          |t                    rt          j                            |          }t          |t                    rt          j                            |          }t          |t                    rt          j                            |          }g }|||g}|D ]}t          |t                    rnt          j                            |          rOt          j                            |          dk    r,|rt          j        |           p|                    |           |r/t          d
                    d |D                       dz             |                     |           |r|                     |           |r | j                            |ddd           dS dS )	a  
        Dump the table HDU to a file in ASCII format.  The table may be dumped
        in three separate files, one containing column definitions, one
        containing header parameters, and one for table data.

        Parameters
        ----------
        datafile : path-like or file-like, optional
            Output data file.  The default is the root name of the
            fits file associated with this HDU appended with the
            extension ``.txt``.

        cdfile : path-like or file-like, optional
            Output column definitions file.  The default is `None`, no
            column definitions output is produced.

        hfile : path-like or file-like, optional
            Output header parameters file.  The default is `None`,
            no header parameters output is produced.

        overwrite : bool, optional
            If ``True``, overwrite the output file if it exists. Raises an
            ``OSError`` if ``False`` and the output file exists. Default is
            ``False``.

        Notes
        -----
        The primary use for the `dump` method is to allow viewing and editing
        the table data and parameters in a standard text editor.
        The `load` method can be used to create a new table from the three
        plain text (ASCII) files.
        r   z  c                     g | ]}d | d	S )zFile 'z' already exists.r2   )rV   fs     r4   r  z$BinTableHDU.dump.<locals>.<listcomp>  s$    HHHQ8A888HHHr3   zL  If you mean to replace the file(s) then use the argument 'overwrite=True'.r%   F)sependcardrX  N)r   r   ospath
expanduserexistsgetsizeremover  OSErrorr   
_dump_data_dump_coldefsrf   tofile)rO   datafilecdfilehfile	overwriteexistfilesr  s           r4   dumpzBinTableHDU.dumpZ  s   B h	** 	4w))(33Hfi(( 	0W''//FeY'' 	.G&&u--E65) 	( 	(A!Y'' (7>>!$$ (););q)@)@  (	!Q 			HH%HHHII$$   	!!!  	'v&&&  	OL4NNNNN	O 	Or3   r%   z	
        c                 T   |t                      }|rA|rt          j        |          }n*|                    t          j        |          dd           d}|r|                     |          }|                     ||          }|t          |          } | ||          }||_        |S )a=	  
        Create a table from the input ASCII files.  The input is from up to
        three separate files, one containing column definitions, one containing
        header parameters, and one containing column data.

        The column definition and header parameters files are not required.
        When absent the column definitions and/or header parameters are taken
        from the header object given in the header argument; otherwise sensible
        defaults are inferred (though this mode is not recommended).

        Parameters
        ----------
        datafile : path-like or file-like
            Input data file containing the table data in ASCII format.

        cdfile : path-like or file-like, optional
            Input column definition file containing the names,
            formats, display formats, physical units, multidimensional
            array dimensions, undefined values, scale factors, and
            offsets associated with the columns in the table.  If
            `None`, the column definitions are taken from the current
            values in this object.

        hfile : path-like or file-like, optional
            Input parameter definition file containing the header
            parameter definitions to be associated with the table.  If
            `None`, the header parameter definitions are taken from
            the current values in this objects header.

        replace : bool, optional
            When `True`, indicates that the entire header should be
            replaced with the contents of the ASCII file instead of
            just updating the current header.

        header : `~astropy.io.fits.Header`, optional
            When the cdfile and hfile are missing, use this Header object in
            the creation of the new table and HDU.  Otherwise this Header
            supersedes the keywords from hfile, which is only used to update
            values not present in this Header, unless ``replace=True`` in which
            this Header's values are completely replaced with the values from
            hfile.

        Notes
        -----
        The primary use for the `load` method is to allow the input of ASCII
        data that was edited in a standard text editor of the table data and
        parameters.  The `dump` method can be used to create the initial ASCII
        files.
        NT)r   update_firstr   )r   fromtextfiler   _load_coldefs
_load_datar
   rH   )	r;   r  r  r  replacer<   rJ   rD   rK   s	            r4   loadzBinTableHDU.load  s    f >XXF 	 ,U33'..t$      	0''//G ~~h00?dmmG ctF+++
r3   c           	         |s;| j         r4t          j                            | j         j                  d         }|dz   }d}t          |t                    rt          |d          }d}t          j	        |t                    }d }| j        D ]}g }| j        D ]}d}	t          |j                  }
t          |
t                    ru|                    d	           |                    t#          ||j                           d
           t%          |j                  \  }}}t&          |d                  d         }	|	r5||j                 j        D ]!}|                     |||	                     "| j        j        j        |j                 d         }|j        }|dk    r|j        j        }|dk    r|t          |j                  z  }|j        dk    r6||j                 j        D ]!}|                     |||                     "s|                     |||j                 |                     |                    |           |r|                                 dS dS )zi
        Write the table data in the ASCII format read by BinTableHDU.load()
        to fileobj.
        r   z.txtFwTdialectc                 *   |d         dk    r.t          |dd                    }d                    | |          S |t          j        d         v r| dS |t          j        d         v r| j        d	d
| j        ddS |t          j        d         v r| dS d S )Nr   rH  r   z	{:{size}})r   
AllInteger21dComplexz21.15g+z.15gr  Floatz#21.15g)r(  r   rc   	typecodesrealimag)r6  r   rM  s      r4   format_valuez,BinTableHDU._dump_data.<locals>.format_value  s    ayCvabbz??"))#H)===2<555||#2<	222(<<<CH<<<<<2<000''' 10r3   NVLA_Length=r  VrH  )_filer  r  splitextr   r   r   openr.   writerr#   rD   rH   r   r   r   r  r   r   r   flatr[   r   r   baserM  writerowclose)rO   r|  root
close_file
linewriterr  r}  liner   
vla_formatr   r/  r[   r   r6  array_formatr+  s                    r4   r  zBinTableHDU._dump_data  s   
  	$4: 	$7##DJO44Q7DVmG
gs## 	7C((GJZ1EFFF
	( 	( 	( 9 %	& %	&CD ,  R  R "
(77fh// : KK...KK3s6;'7#8#8 > >???'5fm'D'D$Auf!+F1I!6q!9J R"6;/4 C CLLj$A$ABBBBC !IO26;?BE#(:L#s**',z#s**$EN(;(;;zS((%(%5%: K KE KKUL(I(IJJJJK LLV[1A<$P$PQQQQ%%%% 	MMOOOOO	 	r3   c                 r   d}t          |t                    rt          |d          }d}| j        D ]lj        j        g}g d}|d fd|D             D             z  }|                    d                    |                     |                    d           m|r|                                 d	S d	S )
z{
        Write the column definition parameters in the ASCII format read by
        BinTableHDU.load() to fileobj.
        Fr  T)dispunitdimnullbscalebzeroc                 @    g | ]}d                      |r|nd          S )z{!s:16s}"")r   )rV   r+  s     r4   r  z-BinTableHDU._dump_coldefs.<locals>.<listcomp>N  s?        !!5":%%d;;  r3   c              3   8   K   | ]}t          |          V  d S rT   )r5  )rV   r  r   s     r4   rX   z,BinTableHDU._dump_coldefs.<locals>.<genexpr>P  s-      FFgfd33FFFFFFr3   r$   r%   N)	r   r   r  rH   r   r   ry  r   r  )rO   r|  r  r  attrsr   s        @r4   r  zBinTableHDU._dump_coldefs>  s    
 
gs## 	7C((GJ l 	  	 FK/DFFFE  FFFFFFF   D MM#((4..)))MM$ 	MMOOOOO	 	r3   c           
         d}t          |t                    r0t          j                            |          }t          |          }d}|                                }t          j        |t                    }g }g g }d}||j
        |j        }fd}	|D ]}
|dz  }|
dd}|t          |
          k     r|
|         dk    rtt          |          k     r	|         }n-t          |
|dz                      }|                    |           |d	z  }|r |	|
|                    |dz  }|dz  }|dz  nDt          |          k    r|                    d            |	|
|                    dz  |dz  }|t          |
          k     ׌t          |          D ]"\  }}|t!          |          |         z   |<   #t"          j                            |d          j        }t*                              t#          j        d|
          |d          }|j        }t          |          D ]\  }}||j        j        |         }|         t          t!          |                    d         }t7          ||          |<   |         |j        j
        |<   |j        j        |         }|                    |t;          |||                              fd|                    |           t          j        |t                    }t          |          D ]4\  }
}dd}|t          |          k     r||         dk    rD|         }|d	z  }t?          |||z             }||||z            ||
                  dd<   ||z  }n_|         j         rPt          t"          j!        "                    |         j                             }t?          |||z             }||z  }nd}|! ||                   ||
         <   |dz  }n+fd||         D             ||
                  j#        dd<   dz  |t          |          k     6|r|$                                 |S )zW
        Read the table data from the ASCII file output by BinTableHDU.dump().
        FTr  r   Nc                     t          |           }t          |          }|t                    k    r                    |           d S t	          |         |          dk     r||<   d S d S r   )r   r   r   r  r   )r+  r{   
fitsformat	recformat
recformatss       r4   update_recformatsz1BinTableHDU._load_data.<locals>.update_recformatss  sw    *511J'
33Ic*oo%%!!),,,,,":c?I>>BB&/JsOOO CBr3   r   r  r   )r   r[   )rA   rB   )r   c                     |          t           d         k    rt          t          |                    S |          t           d         k    rt          |          S |S )NLM)r   boolr(  complex)r|   r6  r  s     r4   r  z,BinTableHDU._load_data.<locals>.format_value  sN    #*S/11CHH~~%CJsO33
 s||#
r3   c                 (    g | ]} |          S r2   r2   )rV   r6  r|   r  s     r4   r  z*BinTableHDU._load_data.<locals>.<listcomp>  s2     . . .36S#... . .r3   )%r   r   r  r  r  r  tellr.   readerr#   r_   r   r   r(  r  rx   r   rc   rh   format_parserr[   rc  rF   ri   rD   rH   rz   r   _cache_fieldr   seekslicer   multiplyreducer  r  )r;   r|  rJ   r  
initialpos
linereadervla_lengthsr   rA   r  r}  r{   
vla_lengthlengthr[   rK   rD   arrdtr   r  vla_lenslice_
array_sizer|   r  r  s                           @@@r4   r  zBinTableHDU._load_dataX  s   
 
gy)) 	g((11G7mmGJ\\^^
Z1EFFF
 
 ,JME	0 	0 	0 	0 	0  	 	CQJE"CCC..s8},,S----%0%5

%(S1W%6%6
#**:6661HC$ !))#c(C888"a
q % ! 1HCCc+....#**4000%%c#h4441HC1HC% C..* %[11 	@ 	@KC!"%f++
3"?
3$$Z==C
 &&Kau---U ' 
 
 x$[11 	K 	KKC!l*3/_SV%5%5%7%78 #+26":":":
30:3(-|)#.!!$sCC(I(IJJJ	 	 	 	 	 	Z   Z1EFFF
":.. 	 	ICCCD		//9--)#.G1HC"3g66F(,S3=-@(ADIcN111%7NCC3Z% "!$R[%7%7c
8H%I%I!J!JJ"3j(899F:%CC!F>%1\#tCy%A%ADIcN1HCC. . . . .:>v,. . .DIcN'* q1 D		//4  	MMOOOr3   c                 L   d}t          |t                    r0t          j                            |          }t          |          }d}g }|D ]}|dd                                         }i }dD ].}|                    d                              dd          ||<   /d	D ]A}|                    d                              dd          }|rt          |          }|||<   B|
                    t          d
i |           |r|                                 t          |          S )zm
        Read the table column definitions from the ASCII file output by
        BinTableHDU.dump().
        FTNrG  )r   r   r  r  r  r   r   )r  r  r  r2   )r   r   r  r  r  r  splitpopr  r   r  r   r  r
   )	r;   r|  r  rH   r  wordsrI   r%  words	            r4   r  zBinTableHDU._load_coldefs  s8    
gy)) 	g((11G7mmGJ 	- 	-D"IOO%%EF@ = =#iill224<<s2 # #yy||++D"55 -&t,,D"sNN6++F++,,,, 	MMOOOwr3   r7  )NNNF)NNFNrT   )r'   r(   r)   r*   r   r   r   r   r=   rr  rV  r  rw  textwrapdedent_tdump_file_formatr  r   r   r  r  r  r  r  r  r:  r;  s   @r4   rc  rc  f  s        2 J+L  
 
 
 
 
 
< W W [W  >0 0 0 0 0 0 0 0d; ; ;2 )3	
5 5nCO CO CO COJ z$,$$ G*224FFFK K K KZ z$,$$ G*224FFF;tDF F FP  4 M M M [M^     [         r3   rc  c              #     K   | j         }g }g }g }g }t          j        dk    rd}nd}t          |j                  D ]Z\  }}t          | |          }	|j        |         \  }
}|                    |           |                    |
           |                    |           t          |	t          j	                  r|	j
        dk    r@|
j        j        d         |v r,|                    |	           |
                                |d<   | j        j        |         }t          |t                     rh|                     |          }|D ]P}t          |t          j	                  s4|j
        dk    r)|j         j        d         |v r|                    |           Q\t%          |          D ]}|                    d           t)          j         |||d          | _         | V  |D ]}|                    d           || _         d	S )
a  
    Ensures that all the data of a binary FITS table (represented as a FITS_rec
    object) is in a big-endian byte order.  Columns are swapped in-place one
    at a time, and then returned to their previous byte order when this context
    manager exits.

    Because a new dtype is needed to represent the byte-swapped columns, the
    new dtype is temporarily applied as well.
    little)<=)r  r   r   rG  T)r   r   offsetsN)r[   sys	byteorderrx   r   r   r   r  r   	chararrayrM  r  r   rs   rH   r_   r   ry   r  byteswaprc   )rD   
orig_dtyper   r   r  to_swap
swap_typesr{   r   ry   field_dtypefield_offsetr  rq  cr  s                   r4   rm  rm  
  s      JEGGG
}  


z/00 & &	T#D#..$.$5d$;!\T{###|$$$eY011 	
 >A+"2"6q"9Z"G"GNN5!!! &2244GBK L,S1	i** 	&jjooG & &"1i&9::&
QA*44NN1%%%    TEg'RRSSDJ
JJJ  TDJJJr3   )8
contextlibr.   r)  r  r_  r  r  r   r   numpyrc   r   r  astropy.io.fits.columnr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   astropy.io.fits.fitsrecr   r   r   astropy.io.fits.headerr   r   astropy.io.fits.utilr   r   r   astropy.utilsr   astropy.utils.exceptionsr   r  r   r    r!   excelr#   r6   r   r=  rc  contextmanagerrm  r2   r3   r4   <module>r     s       



  				 				 



             # # # # # #
                                 " W V V V V V V V V V 6 6 6 6 6 6 6 6 @ @ @ @ @ @ @ @ @ @ & & & & & & > > > > > > 2 2 2 2 2 2 2 2 2 2	 	 	 	 	39 	 	 	K
 K
 K
 K
 K
I K
 K
 K
\i0 i0 i0 i0 i0L- i0 i0 i0Xo o o o o} o o oda
  a
  a
  a
  a
 - a
  a
  a
 H A A A A Ar3   