
    HR-e                     0   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mZm	Z	 d dl
Zd dlmZ d dlmZ d dlmZmZmZmZ d dl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! d d	l"m#Z# d d
l$m%Z% g dZ& G d d          Z' e'            Z(dddddddZ)	 ddddddddddd
Z*	  G d de+          Z,d Z- G d d           Z.e.Z/e.j0        Z0e.j1        Z1 G d! d"e.          Z2 G d# d$e.e!          Z3 G d% d&e.e!          Z4 G d' d(e4          Z5e5Z6 G d) d*e5          Z7e7Z8dS )+    N)suppress)	Parameter	signature)conf)_File)Header_BasicHeader_DelayedHeader_pad_length)	_extract_number_free_space_check_get_array_mmap_is_int_is_pseudo_integer_pseudo_zerodecode_asciifirstitersubclasses)_ErrList_Verify)lazyproperty)AstropyUserWarning)DELAYEDInvalidHDUExceptionExtensionHDUNonstandardExtHDUc                       e Zd ZdS )_DelayedN)__name__
__module____qualname__     8lib/python3.11/site-packages/astropy/io/fits/hdu/base.pyr   r   )   s        Dr#   r   uint8int16int32int64float32float64)          @   r+   r,   r-   r.   r/   r0   )
int8r%   r&   uint16r'   uint32r(   uint64r)   r*   c                       e Zd ZdZdS )r   z
    A custom exception class used mainly to signal to _BaseHDU.__new__ that
    an HDU cannot possibly be considered valid, and must be assumed to be
    corrupted.
    N)r   r    r!   __doc__r"   r#   r$   r   r   M   s           r#   r   c                    | }|rt          t          t          |                               D ]}	 |j                            d          s
|| j        v s'|                    |          r|} nsA# t          $ r Y Mt          $ rZ}t          j
        d                    |          t                     t          j
        dt                     t          }~Y d}~ nd}~ww xY w|S )a  
    Iterates through the subclasses of _BaseHDU and uses that class's
    match_header() method to determine which subclass to instantiate.

    It's important to be aware that the class hierarchy is traversed in a
    depth-last order.  Each match_header() should identify an HDU type as
    uniquely as possible.  Abstract types may choose to simply return False
    or raise NotImplementedError to be skipped.

    If any unexpected exceptions are raised while evaluating
    match_header(), the type is taken to be _CorruptedHDU.

    Used primarily by _BaseHDU._readfrom_internal and _BaseHDU._from_data to
    find an appropriate HDU class to use based on values in the header.
    zastropy.io.fits.zLAn exception occurred matching an HDU header to the appropriate HDU type: {}z%The HDU will be treated as corrupted.N)reversedlistr   r    
startswith_hdu_registrymatch_headerNotImplementedError	Exceptionwarningswarnformatr   _CorruptedHDU)clsheaderklasscexcs        r$   _hdu_class_from_headerrH   U   s%     E $~c223344 	 	A L++,>??C--->>&)) EE '      //5vc{{&  
 ;=O   & Ls$   #A/A//
C;	CACCc                   t    e Zd ZdZ e            ZdZdZdZ e	            Z
d+dZ fdZed             Zej        d	             Zed
             Zej        d             Zed             Zej        d             Zed             Zej        d             Zed             Zed             Zed             Zed             Zed             Zed             Zed,d            Zed,d            Zd-dZed             Ze	 d.d            Zd Zd,dZ d Z!	 d/d"Z"d# Z#d$ Z$d% Z%d& Z&d' Z'd,d(Z(d) Z)d0d*Z* xZ+S )1_BaseHDUz2Base class for all HDU (header data unit) classes.T  Nc                    |t                      }|| _        d | _        d | _        d | _        d | _        d | _        d | _        d| _        d| _	        d| _
        d| _        d| j        v rd| j        vr	d| _        d S d| j        v r	d| _        d S d S )NFTDATASUMCHECKSUMdatasum)r   _header_header_str_file_buffer_header_offset_data_offset
_data_size_data_replaced_data_needs_rescale_new_output_checksum)selfdatarD   argskwargss        r$   __init__z_BaseHDU.__init__   s    >XXF
"  $#( 	 %$$4<)G)G$-D!!!4<''$(D!!! ('r#   c                     | j                             dd           }t          |t          t          f          r$|j        d }|                    |          | _         t                      j	        di |S )Nr]   c                     | j         b| j        r]t          t          d          }|rt          j        | j                  }| j        d= |r%|dk    r!| j                                          d S d S d S d S d S )Ngetrefcountr]      )rS   _data_loadedhasattrsysrc   r]   __dict___maybe_close_mmap)r\   has_getrefcountdata_refcounts      r$   r]   z(_BaseHDU.__init_subclass__.<locals>.data   s    :)d.?)&-c=&A&AO& C(+	(B(B f- ' 7=A+=+=
4466666! *)))7 7+=+=r#   r"   )
rh   get
isinstancer   propertyfdeldeleterr]   super__init_subclass__)rC   r_   	data_propr]   	__class__s       r$   rr   z_BaseHDU.__init_subclass__   s}    
 L$$VT22	i,!9:: 	/y~?U7 7 7( !((..CH(uww(226222r#   c                     | j         S NrQ   r\   s    r$   rD   z_BaseHDU.header   s
    |r#   c                     || _         d S rv   rw   r\   values     r$   rD   z_BaseHDU.header   s    r#   c                 \    t          | j                            d| j                            S NEXTNAME)strrQ   rl   _default_namerx   s    r$   namez_BaseHDU.name   s'     4<##It/ABBCCCr#   c                     t          |t                    st          d          t          j        s|                                }d| j        v r|| j        d<   d S |df| j        d<   d S )Nz!'name' attribute must be a stringr~   zextension name)rm   r   	TypeErrorr   extension_name_case_sensitiveupperrQ   rz   s     r$   r   z_BaseHDU.name   ss    %%% 	A?@@@1 	"KKMME$$&+DL###',.>&?DL###r#   c                 8    | j                             dd          S )NEXTVER   rQ   rl   rx   s    r$   verz_BaseHDU.ver   s    |!,,,r#   c                     t          |          st          d          d| j        v r|| j        d<   d S |df| j        d<   d S )Nz"'ver' attribute must be an integerr   zextension valuer   r   rQ   rz   s     r$   r   z_BaseHDU.ver   sW    u~~ 	B@AAAt|##%*DL"""&+->%?DL"""r#   c                 8    | j                             dd          S )NEXTLEVELr   r   rx   s    r$   levelz_BaseHDU.level   s    |
A...r#   c                     t          |          st          d          d| j        v r|| j        d<   d S |df| j        d<   d S )Nz$'level' attribute must be an integerr   zextension levelr   rz   s     r$   r   z_BaseHDU.level   sW    u~~ 	DBCCC%%',DL$$$(-/@'ADL$$$r#   c                     | j         dk    pBd| j        v o9| j        d         dk    p(| j        d         dk    od| j        v o| j        d         du S )NPRIMARYXTENSIONIMAGEBINTABLEZIMAGET)r   rQ   rx   s    r$   is_imagez_BaseHDU.is_image  sk    yI% 

$,& Z(G3 L,
: 7 DL07X.$6
	
r#   c                 0    d| j         v o| j        t          uS )Nr]   )rh   r]   r   rx   s    r$   re   z_BaseHDU._data_loaded  s    &C49G+CCr#   c                 "    | j         o| j        d uS rv   )re   r]   rx   s    r$   	_has_dataz_BaseHDU._has_data  s     :TYd%::r#   c                 :    | j                             |           d S rv   )r;   addrC   hduclss     r$   register_hduz_BaseHDU.register_hdu  s    f%%%%%r#   c                 P    || j         v r| j                             |           d S d S rv   )r;   remover   s     r$   unregister_hduz_BaseHDU.unregister_hdu  s5    S&&&$$V,,,,, '&r#   c                     t           rv   r=   rC   rD   s     r$   r<   z_BaseHDU.match_header$  s    !!r#   Fc                 $     | j         |f||d|S )a  
        Creates a new HDU object of the appropriate type from a string
        containing the HDU's entire header and, optionally, its data.

        Note: When creating a new HDU from a string without a backing file
        object, the data of that HDU may be read-only.  It depends on whether
        the underlying string was an immutable Python str/bytes object, or some
        kind of read-write memory buffer such as a `memoryview`.

        Parameters
        ----------
        data : str, bytes, memoryview, ndarray
            A byte string containing the HDU's header and data.

        checksum : bool, optional
            Check the HDU's checksum and/or datasum.

        ignore_missing_end : bool, optional
            Ignore a missing end card in the header data.  Note that without the
            end card the end of the header may be ambiguous and resulted in a
            corrupt HDU.  In this case the assumption is that the first 2880
            block that does not begin with valid FITS header data is the
            beginning of the data.

        **kwargs : optional
            May consist of additional keyword arguments specific to an HDU
            type--these correspond to keywords recognized by the constructors of
            different HDU classes such as `PrimaryHDU`, `ImageHDU`, or
            `BinTableHDU`.  Any unrecognized keyword arguments are simply
            ignored.
        checksumignore_missing_end)_readfrom_internal)rC   r]   r   r   r_   s        r$   
fromstringz_BaseHDU.fromstring(  s7    B &s%
#8J
 
NT
 
 	
r#   c                     t          |t                    st          |          } | j        |f||d|}|                    |j        |j        z   t          j                   |S )a  
        Read the HDU from a file.  Normally an HDU should be opened with
        :func:`open` which reads the entire HDU list in a FITS file.  But this
        method is still provided for symmetry with :func:`writeto`.

        Parameters
        ----------
        fileobj : file-like
            Input FITS file.  The file's seek pointer is assumed to be at the
            beginning of the HDU.

        checksum : bool
            If `True`, verifies that both ``DATASUM`` and ``CHECKSUM`` card
            values (when present in the HDU header) match the header and data
            of all HDU's in the file.

        ignore_missing_end : bool
            Do not issue an exception when opening a file that is missing an
            ``END`` card in the last header.
        r   )rm   r   r   seekrV   rW   osSEEK_SET)rC   fileobjr   r   r_   hdus         r$   readfromz_BaseHDU.readfromM  sw    0 '5)) 	%GnnG$c$
&;M
 
QW
 
 	S%6DDD
r#   	exceptionc                 \    ddl m}  || g          }|                    ||||           dS )aj  
        Write the HDU to a new file. This is a convenience method to
        provide a user easier output interface if only one HDU needs
        to be written to a file.

        Parameters
        ----------
        name : path-like or file-like
            Output FITS file.  If the file object is already opened, it must
            be opened in a writeable mode.

        output_verify : str
            Output verification option.  Must be one of ``"fix"``,
            ``"silentfix"``, ``"ignore"``, ``"warn"``, or
            ``"exception"``.  May also be any combination of ``"fix"`` or
            ``"silentfix"`` with ``"+ignore"``, ``"+warn"``, or ``"+exception"``
            (e.g. ``"fix+warn"``).  See :ref:`astropy:verify` for more info.

        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``.

        checksum : bool
            When `True` adds both ``DATASUM`` and ``CHECKSUM`` cards
            to the header of the HDU when written to the file.
        r   HDUList	overwriter   N)hdulistr   writeto)r\   r   output_verifyr   r   r   r   s          r$   r   z_BaseHDU.writetoq  sE    8 	%$$$$$'4&//my8TTTTTr#   c                 8    t          | |          } |d||d|S )zg
        Instantiate the HDU object after guessing the HDU class from the
        FITS Header.
        r]   rD   r"   )rH   )rC   r]   rD   r_   rE   s        r$   
_from_dataz_BaseHDU._from_data  s0     'sF33u8$v88888r#   c                 2   d}d}d}t          t                    r|i                                }	 t          j                  \  }	}n<# t
          $ r/                     |           t          j        |           }Y nw xY w}                                }
n	 t          j	        dd           n!# t          $ r t          dd          w xY w|Dfd	}t          j        |d
d| d
          \  }	}t                    t          |	          k    r}nr}d}t          |	          }
t          | |          } t          | j                  }|                                }t"          j        d |j                                        D             vr|D ]}||j        vr||= 	  | dt*          |d|}nK# t          $ r> t          |t                    r%t          j        |	          } | dt*          |d|}n Y nw xY w||_        ||_        ||_        |
|_        |j        }|t9          |          z   |_        t          |j        t                    r	|`|	|_        |r/|dk    r)t          |t@                    r|!                                 |S )z
        Provides the bulk of the internal implementation for readfrom and
        fromstring.

        For some special cases, supports using a header that was already
        created, and just using the input data for the actual array data.
        Nr   )endcardr"   ubyte)dtypebufferzThe provided object z does not contain an underlying memory buffer.  fromstring() requires an object that supports the buffer interface such as bytes, buffer, memoryview, ndarray, etc.  This restriction is to ensure that efficient access to the array/table data is possible.c              3      K   d}|t                    k     r)||| z            V  || z  }|t                    k     'd S d S Nr   )len)nbytesidxr]   s     r$   
block_iterz/_BaseHDU._readfrom_internal.<locals>.block_iter  sW      CD		//"3v#56666v D		//////r#   TrL   c              3   $   K   | ]}|j         V  d S rv   )kind).0xs     r$   	<genexpr>z._BaseHDU._readfrom_internal.<locals>.<genexpr>  s$      (Q(QA(Q(Q(Q(Q(Q(Qr#   r   r   )"rm   r   tellr	   fromfiler>   r   r   npndarrayr   _from_blocksr   rH   r   r`   copyr   VAR_KEYWORD
parametersvaluesr   r   rS   rT   rU   rV   sizer   rW   rQ   rR   	_ValidHDU_verify_checksum_datasum)rC   r]   rD   r   r   r_   
hdu_bufferhdu_fileobjheader_offset
header_strdata_offsetr   sig
new_kwargskeyr   r   s    `               r$   r   z_BaseHDU._readfrom_internal  sI    
dE"" 2	*~ $		S
 *6)>t)D)D&J  S S S
 IIm,,,#_T?Q;QRRRFFFS K))++KK 
2WT:::::   Q4 Q Q Q   ~& & & & & &,%8b.@*@$& &"
F t99s:..!%J "!
Mj//K
 %S&11%%[[]]
 (Q(Q9N9N9P9P(Q(Q(QQQ  ( (cn,,"3	#@76@@Z@@CC 	 	 	 &,// *:66cDwvDDDD 	  	 *& xD 1 11ck<00 		) (CO  	+H,,C1K1K,((***
s0   A 6BB B8 8C-F> >AHHc                     t          |t          j                  r|f}| j        rt	          j        ||| j        |          S | j        r| j                            |||          S dS )zb
        Return raw array from either the HDU's memory buffer or underlying
        file.
        )r   r   offset)r   r   shapeN)rm   numbersIntegralrT   r   r   rS   	readarray)r\   r   coder   s       r$   _get_raw_dataz_BaseHDU._get_raw_data  sq    
 eW-.. 	HE< 	:e4VTTTTZ 	:''vT'OOO4r#   c                 X    |                                   |                     |           d S rv   )!_update_pseudo_int_scale_keywords_update_checksum)r\   r   inplaces      r$   _prewritetoz_BaseHDU._prewriteto+  s0    ..000 	h'''''r#   c                    | j         r| j        rt          | j        j                  rd| j        v r| j                            ddd           nBd| j        v r| j                            ddd           n| j                            dd           | j                            dt          | j        j                  d           dS dS dS dS )zt
        If the data is signed int 8, unsigned int 16, 32, or 64,
        add BSCALE/BZERO cards to header.
        TFIELDSBSCALEr   )afterGCOUNTBZERON)r   	_standardr   r]   r   rQ   setr   rx   s    r$   r   z*_BaseHDU._update_pseudo_int_scale_keywords1  s    
 > 		Udn 		U1CDIO1T1T 		U DL((  1I >>>>T\))  1H ====  1---LWl49?&C&C8TTTTT		U 		U 		U 		U 		U 		Ur#   rO   rN   c                 T   | j         j        p| j        }|dk    r&|| j         v r| j         |= || j         v r
| j         |= dS dS |s)| j        s"|rYd| j         vsd| j         vs| j        r| j        s;|dk    r|                     |           dS |r|                     ||           dS dS dS dS )a!  Update the 'CHECKSUM' and 'DATASUM' keywords in the header (or
        keywords with equivalent semantics given by the ``checksum_keyword``
        and ``datasum_keyword`` arguments--see for example ``CompImageHDU``
        for an example of why this might need to be overridden).
        r   rO   rN   rP   datasum_keyword)checksum_keywordr   N)rQ   	_modifiedre   rZ   _checksum_valid_datasum_validadd_datasumadd_checksum)r\   r   r   r   modifieds        r$   r   z_BaseHDU._update_checksumA  s(    <)>T->x4<//L!12$,..L111 /. 	y	 		 dl22 44/ 5. 5 9$$   AAAAA !!%5 "     !	 	 54 r#   c                     | j         rY| j        rTt          | j        j                  r=dD ]<}t          t                    5  | j        |= d d d            n# 1 swxY w Y   7d S d S d S d S )N)r   r   )r   r   r   r]   r   r   KeyErrorrQ   r\   keywords     r$   _postwritetoz_BaseHDU._postwritetog  s     > 	.dn 	.1CDIO1T1T 	.. . .h'' . .W-. . . . . . . . . . . . . . .	. 	. 	. 	. 	. 	.. .s    	AA	A	c                 p   d}t          t          t                    5  |                                }d d d            n# 1 swxY w Y   | j                            |           	 |                                |z
  }n8# t          t          f$ r$ t          t          | j                            }Y nw xY w||fS r   )r   AttributeErrorOSErrorr   rQ   tofiler   r   r\   r   r   r   s       r$   _writeheaderz_BaseHDU._writeheadero  s    ng.. 	$ 	$\\^^F	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	G$$$	*<<>>F*DD( 	* 	* 	*s4<(())DDD	* t|s!   >AA$A< <2B10B1c                    d}|                                  	 |                                }n# t          t          f$ r d}Y nw xY w| j        s| j        r| j        ||                     |          z  }|dk    rdt          |          dk    rQt          |          | j	        z  }|
                    |                    d                     |t          |          z  }n||                     |          z  }|                                  ||fS )Nr   ascii)flushr   r  r	  re   rY   r]   _writedata_internalr   _padding_bytewriteencoder   _writedata_direct_copy)r\   r   r   r   paddings        r$   
_writedataz_BaseHDU._writedata}  s    	\\^^FF( 	 	 	FFF	  	9 8 	9y$00999 axxK--11%d++d.@@
 gnnW55666G$
 D//888D 	 t|s   - AAc                 h    |                     | j                   | j        j        | j        j        z  S )a#  
        The beginning and end of most _writedata() implementations are the
        same, but the details of writing the data array itself can vary between
        HDU types, so that should be implemented in this method.

        Should return the size in bytes of the data written.
        )
writearrayr]   r   itemsize)r\   r   s     r$   r  z_BaseHDU._writedata_internal  s.     	49%%%y~	 222r#   c                     |                      | j        d| j                  }||                    |           |j        S dS )a  Copies the data directly from one file/buffer to the new file.

        For now this is handled by loading the raw data from the existing data
        (including any padding) via a memory map or from an already in-memory
        buffer and using Numpy's existing file-writing facilities to write to
        the new file.

        If this proves too slow a more direct approach may be used.
        r   Nr   )r   rW   rV   r  r   )r\   r   raws      r$   r  z_BaseHDU._writedata_direct_copy  sF       '4;LMM?s###:1r#   c                    	 t           j                            |j        j                  }n# t
          t          f$ r d }Y nw xY wt          | |          5  |                     |||           d d d            d S # 1 swxY w Y   d S rv   )	r   pathdirnamerS   r   r  r   r   _writeto_internal)r\   r   r   r   r  s        r$   _writetoz_BaseHDU._writeto  s    	googm&899GG	* 	 	 	GGG	 tW-- 	; 	;""7GT:::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s!   ), AAA::A>A>c                    |r| j         rN|                     |          \  }}|                     |          \  }}| j         r|| _        || _        || _        d S | j        }| j        | j        z
  }	| j        }
| j        }| j        j        r8| j        	                    |           |                     |          \  }}	||	z   }
nq|ro| j        	                    |           |
                                }|                    | j                            |	                     |
                                }
| j        rv| j        n|s| j        rd }nt!          | j                  }||                                 nO| j        	                    | j                   |                     |          \  }
}n|r|                     |          }|| _        |
| _        || _        d| _        d S )NF)rZ   r  r  rU   rV   rW   rQ   r   rS   r   r   r  readre   r]   rX   r   r  r  )r\   r   r   r   r   _r   	data_sizehdrlochdrsizedatlocdatsize
array_mmaps                r$   r  z_BaseHDU._writeto_internal  s    		$) 		#0099M1%)__W%=%="K y ,&3#$/!"+F$#d&99"/<! 	$JOOF###"//88OFG
 g%FF 		$JOOF### \\^^FMM$*//'22333 \\^^F 	;y$  <4. < "&JJ!0!;!;J)$$&&&&JOOD$5666&*oog&>&>OFG 	;11'::G$"!#r#   c                 P    |r| j         rt          | j                  | `d S d S d S d S rv   )re   r   r]   )r\   closeds     r$   _closez_BaseHDU._close	  sH    
  	d' 	ODI,F,F,R				 	 	 	,R,Rr#   )NN)FFr   FF)NFF)rO   rN   )T),r   r    r!   r6   r   r;   r   r  r   r
   rQ   r`   rr   rn   rD   setterr   r   r   r   re   r   classmethodr   r   r<   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r   r  r,  __classcell__rt   s   @r$   rJ   rJ      s       <<CEEM I MM nG) ) ) )23 3 3 3 3B   X ]  ] D D XD
 
[@ @ [@ - - X- 	Z@ @ Z@ / / X/ \B B \B 
 
 X
 D D XD ; ; X; & & [& - - [- " " [" "
 "
 "
 ["
H ! ! ! [!FU U U UB 9 9 [9 CHz z z [zx  &( ( ( (U U U" FO$ $ $ $L. . .       D	3 	3 	3  *; ; ; ;?$ ?$ ?$B       r#   rJ   c                   4    e Zd ZdZed             Zd Zd ZdS )rB   aQ  
    A Corrupted HDU class.

    This class is used when one or more mandatory `Card`s are
    corrupted (unparsable), such as the ``BITPIX``, ``NAXIS``, or
    ``END`` cards.  A corrupted HDU usually means that the data size
    cannot be calculated or the ``END`` card is not found.  In the case
    of a missing ``END`` card, the `Header` may also contain the binary
    data

    .. note::
       In future, it may be possible to decipher where the last block
       of the `Header` ends, but this task may be difficult when the
       extension is a `TableHDU` containing ASCII data.
    c                 p    | j         t          | j                   | j        z
  S | j        j        | j        z
  S zE
        Returns the size (in bytes) of the HDU's data part.
        rT   r   rV   rS   r   rx   s    r$   r   z_CorruptedHDU.size.  s6     <#t|$$t'888z!222r#   c                      | j         | j        dfS )NCorruptedHDU)r   r   rx   s    r$   _summaryz_CorruptedHDU._summary:  s    	48^44r#   c                     d S rv   r"   rx   s    r$   verifyz_CorruptedHDU.verify=  s    r#   N)r   r    r!   r6   rn   r   r8  r:  r"   r#   r$   rB   rB     sW           	3 	3 X	35 5 5    r#   rB   c                   l    e Zd ZdZdZed             Zed             Zd Z	d Z
ed             Zdd	Zd
S )_NonstandardHDUax  
    A Non-standard HDU class.

    This class is used for a Primary HDU when the ``SIMPLE`` Card has
    a value of `False`.  A non-standard HDU comes from a file that
    resembles a FITS file but departs from the standards in some
    significant way.  One example would be files where the numbers are
    in the DEC VAX internal storage format rather than the standard
    FITS most significant byte first.  The header for this HDU should
    be valid.  The data for this HDU is read from the file as a byte
    stream that begins at the first byte after the header ``END`` card
    and continues until the end of the file.
    Fc                 D    |j         d         }|j        dk    o|j        du S )zt
        Matches any HDU that has the 'SIMPLE' keyword but is not a standard
        Primary or Groups HDU.
        r   SIMPLEF)cardsr  r{   )rC   rD   cards      r$   r<   z_NonstandardHDU.match_headerR  s(     |A|x'?DJ%,??r#   c                 p    | j         t          | j                   | j        z
  S | j        j        | j        z
  S r4  r5  rx   s    r$   r   z_NonstandardHDU.size\  s6    
 <#t|$$t'888z!222r#   c                    d}d}|                                  	 |                                }n# t          $ r d}Y nw xY w| j        B|                    | j                   |                                  t          | j                  }||fS )z
        Differs from the base class :class:`_writedata` in that it doesn't
        automatically add padding, and treats the data as a string of raw bytes
        instead of an array.
        r   )r  r   r	  r]   r  r   r  s       r$   r  z_NonstandardHDU._writedataf  s     	\\^^FF 	 	 	FFF	 9 MM$)$$$MMOOOty>>D t|s   / >>c                 F    | j         | j        dt          | j                  fS )NNonstandardHDU)r   r   r   rQ   rx   s    r$   r8  z_NonstandardHDU._summary~  s     	48%5s4<7H7HIIr#   c                 D    |                      | j        d| j                  S z'
        Return the file data.
        r   r   r   rV   rx   s    r$   r]   z_NonstandardHDU.data  !    
 !!$)Wd6GHHHr#   r@   c                     t          g d          }| j        j        D ]*}|                    |                    |                     +|S )NCardunit)r   rQ   r?  append_verify)r\   optionerrsr@  s       r$   rN  z_NonstandardHDU._verify  sP    ((( L& 	. 	.DKKV,,----r#   Nr@   )r   r    r!   r6   r   r/  r<   rn   r   r  r8  r   r]   rN  r"   r#   r$   r<  r<  A  s          I@ @ [@ 3 3 X3  0J J J I I \I     r#   r<  c                        e Zd ZdZd fd	Zed             Zed             Zd Z	d Z
d Zd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#dZg dZg dZd Zd Z xZS )$r   z:
    Base class for all HDUs which are not corrupted.
    Nc                    t                                          ||           |+t          |t          t          f          st          d          d | _        d | _        d | _        d | _	        ||| _
        |	|| _        d S d S )Nr   zheader must be a Header object)rq   r`   rm   r   r	   
ValueError	_checksumr   _datasumr   r   r   )r\   r]   rD   r   r   r_   rt   s         r$   r`   z_ValidHDU.__init__  s    d6222j&,9O&P&P =>>> #"DI?DHHH ?r#   c                 H    t          |                                          dvS )a  
        Matches any HDU that is not recognized as having either the SIMPLE or
        XTENSION keyword in its header's first card, but is nonetheless not
        corrupted.

        TODO: Maybe it would make more sense to use _NonstandardHDU in this
        case?  Not sure...
        )r>  r   )r   keysr   s     r$   r<   z_ValidHDU.match_header  s      V[[]]##+AAAr#   c                     | j         j        S )zA
        Size (in bytes) of the data portion of the HDU.
        )rQ   r$  rx   s    r$   r   z_ValidHDU.size  s    
 |%%r#   c                     t                      }|                     |          d         |                     |          d         z   S )zh
        Calculates and returns the number of bytes that this HDU will write to
        a file.
        r   )r   r  r  )r\   fs     r$   	filebytesz_ValidHDU.filebytes  s<    
 GG  ##A&););A)>>>r#   c                     t          | d          r-| j        r&| j        | j        j        | j        | j        | j        dS dS )a  
        Returns a dictionary detailing information about the locations
        of this HDU within any associated file.  The values are only
        valid after a read or write of the associated file with no
        intervening changes to the `HDUList`.

        Returns
        -------
        dict or None
            The dictionary details information about the locations of
            this HDU within an associated file.  Returns `None` when
            the HDU is not associated with a file.

            Dictionary contents:

            ========== ================================================
            Key        Value
            ========== ================================================
            file       File object associated with the HDU
            filemode   Mode in which the file was opened (readonly, copyonwrite,
                       update, append, ostream)
            hdrLoc     Starting byte location of header in file
            datLoc     Starting byte location of data block in file
            datSpan    Data size including padding
            ========== ================================================
        rS   )filefilemodehdrLocdatLocdatSpanN)rf   rS   moderU   rV   rW   rx   s    r$   fileinfoz_ValidHDU.fileinfo  sR    6 4!! 		dj 		
 JO-+?   4r#   c                     | j         | j                                         }nd}|                     || j                                                  S )zJ
        Make a copy of the HDU, both header and data are copied.
        Nr   )r]   r   rt   rQ   )r\   r]   s     r$   r   z_ValidHDU.copy  sH     9 9>>##DDD~~40A0A0C0C~DDDr#   r@   c           
         t          g d          }t          j        t          | t                    r
d}| j        }nd}d}|                     |dd |||           |                     ddfd	d
||           |                     ddd d||           | j                            dd          }|dk     rt          d|dz             D ]L}dt          |dz
            z   }|                     ||d t          | j        |         d          ||           M| j        D ]}|                    d          rt          |          dk    r	 t          |dd                    }	|	dk    s|	|k    rt          V# t          $ rK d                    ||          }
| |fd}|                    |                     ||
|d                     Y w xY wd| j        v rZt          | j        d         t                    s:d}
d}| j        fd}|                    |                     ||
||                     | j        j        D ]*}|                    |                    |                     +|S )NrJ  rK  r   r>  Tr   BITPIXr   c                 8    t          |           o
 |           S rv   r   )vis_valids    r$   <lambda>z#_ValidHDU._verify.<locals>.<lambda>	  s    GAJJ$>88A;; r#   r+   NAXISrd   c                 @    t          |           od| cxk    odk    nc S )Nr   i  ri  rj  s    r$   rl  z#_ValidHDU._verify.<locals>.<lambda>  s%    71::#?!q----C---- r#   i     c                 ,    t          |           o| dk    S r   ri  ro  s    r$   rl  z#_ValidHDU._verify.<locals>.<lambda>  s    wqzz4a1f r#   )default   z3NAXISj keyword out of range ('{}' when NAXIS == {})c                     | j         |= d S rv   rw   r  s     r$   fixz_ValidHDU._verify.<locals>.fix)  s     $W 5 5 5r#   zDeleted.)rO  err_textru  fix_textr~   z-The EXTNAME keyword must have a string value.z0Converted the EXTNAME keyword to a string value.c                 6    t          | d                   | d<   d S r}   )r   )rD   s    r$   ru  z_ValidHDU._verify.<locals>.fix;  s    (+F9,=(>(>F9%%%r#   rv  rw  ru  )r   BITPIX2DTYPE__contains__rm   r   
_extension	req_cardsrQ   rl   ranger   r   r:   r   intrT  rA   rM  
run_optionr?  rN  )r\   rO  rP  firstkeyfirstvalnaxisaxr   r  numberrv  ru  rw  r@  rk  s                 @r$   rN  z_ValidHDU._verify  s   (((,
 dL)) 	!HHHHHxD(FDAAAa????FD	
 	
 	
 	Q@@!VT	
 	
 	
   !,,4<<Auqy)) 	 	BF+55#DL$5qAAA     <  %%g.. 3w<<!3C3C!$WQRR[!1!1!Q;;&5..",, +9%   ++16'5+A+A !
 &*7 6 6 6 6  OO'-)1$')3	 ,      & $$dl95s;; JM#| ? ? ? ? OOH# $     L& 	. 	.DKKV,,----s   *E33AGGc           	         |}d}	 | j                             |          }	n# t          $ r d}	Y nw xY wdu}
t          | j                   dz   t	          |          r|fd}|	Gd| d}d| d}|
r|f}| |fd}|                    |                     |||||
	                     n|M ||	          sBd| d
|	 d}d d}| |	fd}|                    |                     ||||                     |r_| j         |         } ||          sGd| d| d}d d}|
r	| |ffd	}|                    |                     |||||
	                     |S )a	  
        Check the existence, location, and value of a required `Card`.

        Parameters
        ----------
        keyword : str
            The keyword to validate

        pos : int, callable
            If an ``int``, this specifies the exact location this card should
            have in the header.  Remember that Python is zero-indexed, so this
            means ``pos=0`` requires the card to be the first card in the
            header.  If given a callable, it should take one argument--the
            actual position of the keyword--and return `True` or `False`.  This
            can be used for custom evaluation.  For example if
            ``pos=lambda idx: idx > 10`` this will check that the keyword's
            index is greater than 10.

        test : callable
            This should be a callable (generally a function) that is passed the
            value of the given keyword and returns `True` or `False`.  This can
            be used to validate the value associated with the given keyword.

        fix_value : str, int, float, complex, bool, None
            A valid value for a FITS keyword to to use if the given ``test``
            fails to replace an invalid value.  In other words, this provides
            a default value to use as a replacement if the keyword's current
            value is invalid.  If `None`, there is no replacement value and the
            keyword is unfixable.

        option : str
            Output verification option.  Must be one of ``"fix"``,
            ``"silentfix"``, ``"ignore"``, ``"warn"``, or
            ``"exception"``.  May also be any combination of ``"fix"`` or
            ``"silentfix"`` with ``"+ignore"``, ``+warn``, or ``+exception"
            (e.g. ``"fix+warn"``).  See :ref:`astropy:verify` for more info.

        errlist : list
            A list of validation errors already found in the FITS file; this is
            used primarily for the validation system to collect errors across
            multiple HDUs and multiple calls to `req_cards`.

        Notes
        -----
        If ``pos=None``, the card can be anywhere in the header.  If the card
        does not exist, the new card will have the ``fix_value`` as its value
        when created.  Also check the card's value by using the ``test``
        argument.
        Nr   c                     | k    S rv   r"   )r   
insert_poss    r$   rl  z%_ValidHDU.req_cards.<locals>.<lambda>  s    AO r#   'z' card does not exist.zFixed by inserting a new 'z' card.c                 <    | j                             ||           d S rv   )rQ   insert)r\   r  r@  s      r$   ru  z _ValidHDU.req_cards.<locals>.fix  s     L''
D99999r#   )rv  rw  ru  fixablez ' card at the wrong place (card z).z,Fixed by moving it to the right place (card c                 p    | j         j        |         }| j         |= | j                             ||           d S rv   )rQ   r?  r  )r\   indexr  r@  s       r$   ru  z _ValidHDU.req_cards.<locals>.fix  s9    #|1%8 L/++J=====r#   ry  z' card has invalid value 'z'.zFixed by setting a new value 'c                     | j         |<   d S rv   rw   )r\   r  val	fix_values      r$   ru  z _ValidHDU.req_cards.<locals>.fix  s    4=DL111r#   )rQ   r  rT  r   r   rM  r  )r\   r  postestr  rO  errlistrP  ru  r  r  rv  rw  r@  r  r  s       `          @r$   r}  z_ValidHDU.req_cardsL  s   d 	L&&w//EE 	 	 	EEE	 4'&&*
 3<< 	,J++++C =:7:::HDGDDDH :  +!jt : : : : KK%%#        s5zz U7UUEUUUHUzUUU  "&Uz > > > >
 KK"Xc (      l7+tCyy M7MMcMMMHM	MMMH >%)7	 > > > > > > KK"%-%- #$+ (     s   # 22rN   c                     |                                  }|d|                                  }t          |          |f| j        |<   |S )a  
        Add the ``DATASUM`` card to this HDU with the value set to the
        checksum calculated for the data.

        Parameters
        ----------
        when : str, optional
            Comment string for the card that by default represents the
            time when the checksum was calculated

        datasum_keyword : str, optional
            The name of the header keyword to store the datasum value in;
            this is typically 'DATASUM' per convention, but there exist
            use cases in which a different keyword should be used

        Returns
        -------
        checksum : int
            The calculated datasum

        Notes
        -----
        For testing purposes, provide a ``when`` argument to enable the comment
        value in the card to remain consistent.  This will enable the
        generation of a ``CHECKSUM`` card with a consistent value.
        Nzdata unit checksum updated )_calculate_datasum_get_timestampr   rQ   )r\   whenr   css       r$   r   z_ValidHDU.add_datasum  sN    6 $$&&<H1D1D1F1FHHD),R$_%	r#   FrO   c                 ^   |s|                      ||          }n|                                 }|d|                                  }|| j        v r| j                            |d||           n| j                            |d|           |                     ||          }|| j        |<   dS )a  
        Add the ``CHECKSUM`` and ``DATASUM`` cards to this HDU with
        the values set to the checksum calculated for the HDU and the
        data respectively.  The addition of the ``DATASUM`` card may
        be overridden.

        Parameters
        ----------
        when : str, optional
            comment string for the cards; by default the comments
            will represent the time when the checksum was calculated
        override_datasum : bool, optional
            add the ``CHECKSUM`` card only
        checksum_keyword : str, optional
            The name of the header keyword to store the checksum value in; this
            is typically 'CHECKSUM' per convention, but there exist use cases
            in which a different keyword should be used

        datasum_keyword : str, optional
            See ``checksum_keyword``

        Notes
        -----
        For testing purposes, first call `add_datasum` with a ``when``
        argument, then call `add_checksum` with a ``when`` argument and
        ``override_datasum`` set to `True`.  This will provide consistent
        comments for both cards and enable the generation of a ``CHECKSUM``
        card with a consistent value.
        r   NzHDU checksum updated 0000000000000000)before)r   )r   r  r  rQ   r   _calculate_checksum)r\   r  override_datasumr   r   data_cscsums          r$   r   z_ValidHDU.add_checksum  s    H   	0&&t_&MMGG --//G<B4+>+>+@+@BBD dl**L-xoVVVVL-x>>>''BR'SS)-%&&&r#   c                     d| j         v r6|                                 }|t          | j         d                   k    rdS dS dS )a.  
        Verify that the value in the ``DATASUM`` keyword matches the value
        calculated for the ``DATASUM`` of the current HDU data.

        Returns
        -------
        valid : int
            - 0 - failure
            - 1 - success
            - 2 - no ``DATASUM`` keyword present
        rN   r   r   rd   )rQ   r  r  )r\   rP   s     r$   verify_datasumz_ValidHDU.verify_datasum+  sM     $$--//G#dl956666q q1r#   c                     d| j         v rJd| j         v r|                                 }nd}|                     |          }|| j         d         k    rdS dS dS )a!  
        Verify that the value in the ``CHECKSUM`` keyword matches the
        value calculated for the current HDU CHECKSUM.

        Returns
        -------
        valid : int
            - 0 - failure
            - 1 - success
            - 2 - no ``CHECKSUM`` keyword present
        rO   rN   r   r   rd   )rQ   r  r  )r\   rP   r   s      r$   verify_checksumz_ValidHDU.verify_checksumA  sl     %%DL((1133//88H4<
333q q1r#   c                    d| j         v r\| j         d         | _        |                                 | _        | j        s*t	          j        d| j        | j        f dt                     d| j         v r^| j         d         | _	        | 
                                | _        | j        s.t	          j        d| j        | j        f dt                     dS dS dS )z
        Verify the checksum/datasum values if the cards exist in the header.
        Simply displays warnings if either the checksum or datasum don't match.
        rO   z%Checksum verification failed for HDU z.
rN   z$Datasum verification failed for HDU N)rQ   rU  r  r   r?   r@   r   r   r   rV  r  r   rx   s    r$   r   z"_ValidHDU._verify_checksum_datasum[  s    
 %%!\*5DN#'#7#7#9#9D ' TDItx;PTTT&  
 $$ L3DM"&"5"5"7"7D& S49dh:OSSS&    	 %$ r#   c                 r    t           j                                                                         dd         S )z
        Return the current timestamp in ISO 8601 format, with microseconds
        stripped off.

        Ex.: 2007-05-30T19:05:11
        N   )datetimenow	isoformatrx   s    r$   r  z_ValidHDU._get_timestampr  s.      $$&&00223B377r#   c                    | j         sC| j        dk    r6|                     | j        d| j                  }|                     |          S dS | j        -|                     | j                            d                    S dS )zJ
        Calculate the value for the ``DATASUM`` card in the HDU.
        r   r   )re   r   r   rW   rV   _compute_checksumr]   view)r\   raw_datas     r$   r  z_ValidHDU._calculate_datasum{  s       	 y1}}--OWd.?  --h777qY"))$)..*A*ABBB1r#   c                     | j         |         }d| j         |<   | j                                                             d          }|                     t	          j        |d          |          }|                     |           }|| j         |<   |S )zJ
        Calculate the value of the ``CHECKSUM`` card in the HDU.
        r  utf8r   r   )rQ   tostringr  r  r   
frombuffer_char_encode)r\   rP   r   old_checksumsr  s         r$   r  z_ValidHDU._calculate_checksum  s     |$45)1%& L!!##**622 ##BM!7$C$C$CWMM rc"" *6%&r#   r   c                     d}t          j        |          }t          dt          |          |          D ]C}t	          |t          |          |z
            }|                     ||||z            |          }D|S )a6  
        Compute the ones-complement checksum of a sequence of bytes.

        Parameters
        ----------
        data
            a memory region to checksum

        sum32
            incremental checksum value from another region

        Returns
        -------
        ones complement checksum
        i@  r   )r   r3   r~  r   min_compute_hdu_checksum)r\   r]   sum32blocklenilengths         r$   r  z_ValidHDU._compute_checksum  s}      	%  q#d))X.. 	L 	LA3t99q=11F..tAF
N/CUKKEEr#   c                    t          j        d          }t          j        d          }t          j        d          }|j        dz  r|d         }|dd         }nt          j        d          }|                    d          }||z	  }||z  }|t           j                            |ddd         t           j        	          z  }|t           j                            |d
dd         t           j        	          z  }|j        dz  dz  r	|||z  z  }n|||z  z  }||z	  }	||z	  }
|	s|
r||z  |
z   }||z  |	z   }||z	  }	||z	  }
|	|
||z  |z   S )a  
        Translated from FITS Checksum Proposal by Seaman, Pence, and Rots.
        Use uint32 literals as a hedge against type promotion to int64.

        This code should only be called with blocks of 2880 bytes
        Longer blocks result in non-standard checksums with carry overflow
        Historically,  this code *was* called with larger blocks and for that
        reason still needs to be for backward compatibility.
        r+   r,   i  rd   Nr   z>u2r  r   )r   r3   r   r  r   reducer4   )r\   r]   r  u8u16uFFFFlasthilohicarrylocarrys              r$   r  z_ValidHDU._compute_hdu_checksum  sv    Yq\\imm	&!!;? 	 8D9DD9Q<<Dyyc\U]
bfmmDAJbim888
bfmmDAJbim888K1! 	$"*BB$"*B)) 	  	 u*'Bu*'BCiGCiG	  	  	  c	Rr#   )l      ~ i   i      ):   ;   <   =   >   ?   r.   [   \   ]   ^   _   `   c                 "   |dz  t          d          z   }|dz  }t          j        ||z   |||gd          }d}|rSd}| j        D ]G}dD ]B}||         |k    s||dz            |k    r%||xx         dz  cc<   ||dz   xx         dz  cc<   d}CH|S|S )	z'
        Encode a single byte.
           0r'   r  TF)r   rd   r   )ordr   array_EXCLUDE)r\   bytequotient	remainderchcheckr   js           r$   _encode_bytez_ValidHDU._encode_byte  s     19s3xx'1H	X"XxB'
 
 
  	%E] % % % %A!uzzRAY!^^1
1q5			Q			 $	%  	% 	r#   c                    t          j        |          }t          j        dd          }t          j        dd          }t          d          D ]S}|| j        |         z  d|z
  dz  z	  }|                     |          }t          d          D ]}||         |d|z  |z   <   Tt          d          D ]}||dz   dz           ||<   t          |                                          S )	a   
        Encodes the checksum ``value`` using the algorithm described
        in SPR section A.7.2 and returns it as a 16 character string.

        Parameters
        ----------
        value
            a checksum

        Returns
        -------
        ascii encoded checksum
        )r,   r  r  r  rp  r+   r,      )r   r3   zerosr~  _MASKr  r   tobytes)r\   r{   ascr  r  r  r  r  s           r$   r  z_ValidHDU._char_encode  s     	%  huF+++f---q 	' 	'ADJqM)A{;D""4((B1XX ' '!#AAEAI' r 	* 	*AAFb=)E!HHEMMOO,,,r#   )NNNNrQ  )NrN   )NFrO   rN   )rO   )r   )r   r    r!   r6   r`   r/  r<   rn   r   r\  rd  r   rN  r}  r   r   r  r  r   r  r  r  r  r  r  r  r  r  r0  r1  s   @r$   r   r     s             * 	B 	B [	B & & X&? ? ?$ $ $LE E EP P P PhC C CJ! ! ! !J #!5. 5. 5. 5.n  ,  4  .8 8 8  (   *   .)  )  )  ) Z =<<E4 4 4H  ,- - - - - - -r#   r   c                   F     e Zd ZdZdZed             Zd	dZd
 fd	Z xZ	S )r   z
    An extension HDU class.

    This class is the base class for the `TableHDU`, `ImageHDU`, and
    `BinTableHDU` classes.
    rL   c                     t           )z
        This class should never be instantiated directly.  Either a standard
        extension HDU type should be used for a specific extension, or
        NonstandardExtHDU should be used.
        r   r   s     r$   r<   zExtensionHDU.match_header,  s
     "!r#   r   Fc                 z    ddl m} ddlm}  | |            | g          }|                    ||||           dS )z
        Works similarly to the normal writeto(), but prepends a default
        `PrimaryHDU` are required by extension HDUs (which cannot stand on
        their own).
        r   r   )
PrimaryHDUr   N)r   r   imager  r   )r\   r   r   r   r   r   r  r   s           r$   r   zExtensionHDU.writeto5  sb     	%$$$$$%%%%%%'::<<.//my8TTTTTr#   r@   c                     t                                          |          }| j                            dd          }|                     d|dz   d d||           |                     d|dz   d	 d
||           |S )N)rO  rm  r   PCOUNTrp  c                 ,    t          |           o| dk    S r   ri  ro  s    r$   rl  z&ExtensionHDU._verify.<locals>.<lambda>G      GAJJ,A16 r#   r   r  c                 ,    t          |           o| dk    S )Nr   ri  ro  s    r$   rl  z&ExtensionHDU._verify.<locals>.<lambda>J  r  r#   r   )rq   rN  rQ   rl   r}  )r\   rO  rP  r  rt   s       r$   rN  zExtensionHDU._verifyA  s    wwf--   !,,eai!B!BAvt	
 	
 	
 	eai!B!BAvt	
 	
 	
 r#   r-  rQ  )
r   r    r!   r6   r|  r/  r<   r   rN  r0  r1  s   @r$   r   r   "  s          J" " ["
U 
U 
U 
U         r#   r   c                   H    e Zd ZdZdZed             Zd Zed             Z	dS )r   a  
    A Non-standard Extension HDU class.

    This class is used for an Extension HDU when the ``XTENSION``
    `Card` has a non-standard value.  In this case, Astropy can figure
    out how big the data is but not what it is.  The data for this HDU
    is read from the file as a byte stream that begins at the first
    byte after the header ``END`` card and continues until the
    beginning of the next header or the end of the file.
    Fc                     |j         d         }|j        }t          |t                    r|                                }d}|j        dk    o||vS )zh
        Matches any extension HDU that is not one of the standard extension HDU
        types.
        r   )r   TABLEr   A3DTABLEr   )r?  r{   rm   r   rstripr  )rC   rD   r@  xtensionstandard_xtensionss        r$   r<   zNonstandardExtHDU.match_headerc  sZ     |A:h$$ 	)((H H |z)Ph>P.PPr#   c                 z    t          | j        j                  }| j        | j        dt          | j                  |fS )Nr   )tupler]   r   r   r   r   rQ   )r\   axess     r$   r8  zNonstandardExtHDU._summaryu  s3    TY_%%	48%8#dl:K:KTRRr#   c                 D    |                      | j        d| j                  S rF  rG  rx   s    r$   r]   zNonstandardExtHDU.datay  rH  r#   N)
r   r    r!   r6   r   r/  r<   r8  r   r]   r"   r#   r$   r   r   U  ss        	 	 IQ Q [Q"S S S I I \I I Ir#   r   )9r  r   r   rg   r?   
contextlibr   inspectr   r   numpyr   astropy.io.fitsr   astropy.io.fits.filer   astropy.io.fits.headerr   r	   r
   r   astropy.io.fits.utilr   r   r   r   r   r   r   r   r   astropy.io.fits.verifyr   r   astropy.utilsr   astropy.utils.exceptionsr   __all__r   r   rz  DTYPE2BITPIXr>   r   rH   rJ   _AllHDUr   r   rB   r<  r   r   _ExtensionHDUr   _NonstandardExtHDUr"   r#   r$   <module>r     s     				 



        ( ( ( ( ( ( ( (                 & & & & & & T T T T T T T T T T T T
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 5 4 4 4 4 4 4 4 & & & & & & 7 7 7 7 7 7  	 	 	 	 	 	 	 	 (** 		  4      )   - - -dH
 H
 H
 H
 H
 H
 H
 H
Z 
 $(! ! ! ! !H ! ! !HN N N N Nh N N NbM
- M
- M
- M
- M
-' M
- M
- M
-`+ + + + +9 + + +` )I )I )I )I )I )I )I )IZ '   r#   