L ixiXdgZddlZddlZddlZddlZddlZddddddd d d d d d d d ddZdddddddddddddddZiZ dZ d Z d!Z d"Z d#Zd$Zd%Zd&Zd'Zd(Zd)Zd*Zd+ZGd,d-ZGd.d/eZd0Zd1Zd2Zd3Zd4Zd5Zd6Zd7Z d8Z!d9Z"d:Z#Gd;dd=Z&y)?readsavNz>u1z>i2z>i4z>f4z>f8z>c8z|Oz>c16z>u2z>u4z>i8z>u8)  START_MARKERCOMMON_VARIABLEVARIABLESYSTEM_VARIABLE END_MARKER TIMESTAMPCOMPILEDIDENTIFICATIONVERSION HEAP_HEADER HEAP_DATA PROMOTE64NOTICE DESCRIPTION)rrrrr r rrrrch|j}|dzdk7r|j|dz|dzz y)z+Align to the next 32-bit position in a filerrN)tellseek)fposs S/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/io/_idl.py _align_32r+Ks6 &&(C Qw!| sQwq ! c&|j|y)zSkip `n` bytesNreadr(ns r* _skip_bytesr2TsFF1I r,c$|j|S)zRead the next `n` bytesr.r0s r* _read_bytesr4Zs 66!9r,c~tjtjd|j ddddS)zRead a single bytez>BrNrr)npuint8structunpackr/r(s r* _read_byter;_s/ 88FMM$q "1 6q9 ::r,cxtjtjd|j ddS)Read a signed 32-bit integer>lrrr6int32r8r9r/r:s r* _read_longrAd) 88FMM$q 215 66r,c~tjtjd|j ddddS)zRead a signed 16-bit integerz>hrrr)r6int16r8r9r/r:s r* _read_int16rEis/ 88FMM$q !A7: ;;r,cxtjtjd|j ddS)r=z>irrr?r:s r* _read_int32rGnrBr,cxtjtjd|j ddS)zRead a signed 64-bit integerz>qr r)r6int64r8r9r/r:s r* _read_int64rJsrBr,c~tjtjd|j ddddS)zRead an unsigned 16-bit integerz>Hrrr)r6uint16r8r9r/r:s r* _read_uint16rMxs/ 99V]]41Q8; <Irr)r6uint32r8r9r/r:s r* _read_uint32rQ}) 99V]]43A6 77r,cxtjtjd|j ddS)zRead an unsigned 64-bit integerz>Qr r)r6uint64r8r9r/r:s r* _read_uint64rUrRr,cxtjtjd|j ddS)zRead a 32-bit floatz>frr)r6float32r8r9r/r:s r* _read_float32rX) ::fmmD!&&)4Q7 88r,cxtjtjd|j ddS)zRead a 64-bit floatz>dr r)r6float64r8r9r/r:s r* _read_float64r\rYr,ceZdZdZdZy)PointerzClass used to define pointersc||_yN)index)selfras r*__init__zPointer.__init__s  r,N)__name__ __module__ __qualname____doc__rcr,r*r^r^s 'r,r^ceZdZdZy) ObjectPointerz$Class used to define object pointersN)rdrerfrgrhr,r*rjrjs.r,rjczt|}|dkDr(t||jd}t||Sd}|S)z Read a stringrlatin1)rAr4decoder+)r(lengthcharss r* _read_stringrqsC ]F zAv&--h7!  L Lr,crt|}|dkDr$t|}t||}t||Sd}|S)z.Read a data string (length is specified twice)rrm)rAr4r+)r(ro string_datas r*_read_string_datartsC ]F zA!!V, !   r,c|dk(r$t|dk7r tdt|S|dk(r t|S|dk(r t|S|dk(r t |S|dk(r t |S|dk(r1t |}t |}t j||dzzS|d k(r t|S|d k(r td |d k(r1t |}t |}t j||dzzS|d k(rtt|S|dk(rtt|S|dk(r t|S|dk(r t|S|dk(r t|S|dk(r t|Std|d)z*Read a variable with a specified data typerz*Error occurred while reading byte variablerrrrr y?r r z'Should not be here - please report thisr r rrrrrzUnknown IDL type: z - please report this)rG Exceptionr;rErXr\r6 complex64rt complex128r^rjrMrQrJrU)r(dtyperealimags r* _read_datar|s z q>Q HI I!} !1~ !1~ !Q !Q !QQ||D4"9,-- ! ## !ABB !QQ}}TD2I-.. "{1~&& "[^,, "A "A "1~ "A,UG3HIJJr,c |d}|d}g}|D]}|ds|dr8|j|dj|dftjfE|dtvr4|j|dj|dft|dft d|ddtj j|f| }t|D]v}|D]o}|d}|dr)t||d |d|d |d||d|<6|dr t|||d |d||d|<[t||||d|<qx|d d kDr5|ddt|d } | j|j| }|S)z Read a structure, with the array and structure descriptors given as `array_desc` and `structure_desc` respectively. nelementstagtable structurearraynametypecodezVariable type  not implementedryarrtable structtablendimsrdimsN)appendlowerr6object_ DTYPE_DICTrvrecrecarrayrange_read_structure _read_arrayr|intreversereshape) r( array_desc struct_descnrowscolumnsrycolrirs r*rrs { #E*%G ET { s7| LL3v;,,.F ?@@$VI%67F9 i55 )  * ,QF9 #-a=F< 1 $Q' z "a '!&&("!%v !:;;"!}H1} 344;'!0K 4M4? 4N"PvW%!,Q J0G0;L0I"Kv$J/!+Au!5v  k )Au%av%av%av  i '%a=x%av#At (Oy  o -'?x&q/w'?x  h &'?x  m + 1! 4}  m +&qMy49&:K4LMqZ]My  m +$Q-w%av7  / / 7AF,VI->,??OPQQFF7O M5N Os $L=1Mct|t|d}|ddzdk(r td|ddzdk(|d<|ddzdk(|d<|drt||d <t||d <|S|drt||d <|S) z%Function to read in a type descriptor)rvarflagsrrz System variables not implementedrr rrr)rArv_read_arraydesc_read_structdesc)r(typedescs r*rrs'qMz!}EH a1$:;; ,q0A5HW$Z025;H[ !0!3"21"5 O ' !0!3 Or,cdt|i}|ddk(rzt|dt||d<t||d<t||d<t|dt||d<t|dDcgc] }t|c}|d<|S|dd k(rtjd d t|dt ||d<t ||d<t||d<t|dd|d<g|d<t|dD]:}t|}|d k7r t d|djt|<|St d|dcc}w)z'Function to read in an array descriptorarrstartr rrr~rnmaxrz$Using experimental 64-bit array readrrrzExpected a zero in ARRAY_DESCzUnknown ARRSTART: )rAr2rrrrUrvr)r( arraydescrdvs r*rrs{Z]+I!Aq(m (!+A +'] 'Aq&qM &49)F:K4LMqZ]M &4 1 : " $ <KAq*1o (!-a +'] 'Aq & &y() 4A1 AAv ?@@ f  $ $Z] 3  4 ,Yz-B,CDEE1Ns6Eci}t|}|dk7r tdt||d<t|}t||d<t||d<|dz|d<|dz|d <|d z|d <|dst|dDcgc] }t |c}|d <|d D]}t||d<|d Dcic]}|d r|dt |c}|d<|d Dcic]}|dr|dt |c}|d<|d s|d rlt||d<t||d<t|dDcgc] }t|c}|d<t|dDcgc] }t |c}|d<|t|d<|S|dtvr tdt|d}|Scc}wcc}wcc}wcc}wcc}w)z*Function to read in a structure descriptorr zSTRUCTSTART should be 9rntagsrrpredefrinheritsris_superrrrrr classname nsupclasses supclassnames supclasstablez"PREDEF=1 but can't find definition)rArvrqr _read_tagdescrr STRUCT_DICT)r( structdesc structstartrrtags r*rrs<JQ-Ka122%aJv ]F$Q-Jw%a=Jx!A:Jx#aZJz#aZJz h ,1G1D+E"G&'#0"2"G :j) *C&q/CK *.8 -C"3&)%(\#&f+q/A"A"3 : 1;:0F%:),(+K(8&)[2B12E%E%: =! j !Z %;&21oJ{ #(21 J} %).z-/H)I+K$% Q+KJ '.3:m3L-M+O() #+OJ '+5 Jv&'  f [ 0@A A F!34 ?"G "3%:+K+OsF)8F. F37F8F=cdt|i}|ddk(rt||d<t||d<t|}|dzdk(|d<|dzdk(|d<|dtv|d<|S) z$Function to read in a tag descriptoroffsetrrrrrscalar)rArUr)r(tagdesctagflagss r*rrsA'GxB(O$Q-GJ!}H!|q(GG#b=B.GK +z9GH Nr,ct|trt|trZ|jdk(rd}n7|j|vr||j}ntjddd}t|trZt ||\}}|r|}d|fSt|t jjr.t|D]\}}t ||\}}|s|||<d|fSt|t jr.t|D]\}}t ||\}}|s|||<d|fSt|t jry|jjt jurOt|j D]7}t |j#||\}}|s$||j%d|<9d|fSd|fS)NrzNVariable referenced by pointer not found in heap: variable will be set to NonerrTFr) isinstancer^rarr _replace_heapr6rr enumeraterndarrayrytyperrsizeitemr)variableheapreplacenewirrivvalues r*rr2s(G$7+~~">>T)#HNN3HMM#J-.0 $H7+%Xt4  HX~ Hbffoo .$H- #JB(6LGS"  #h Hbii (#8, #IB(5LGS"  #h Hbjj ) >>  "** ,HMM* 3,X]]2->E /2H$$R(,  3hhr,cBeZdZdZddZfdZfdZdZeZeZ xZ S)AttrDicta] A case-insensitive dictionary with access via item, attribute, and call notations: >>> from scipy.io._idl import AttrDict >>> d = AttrDict() >>> d['Variable'] = 123 >>> d['Variable'] 123 >>> d.Variable 123 >>> d.variable 123 >>> d('VARIABLE') 123 >>> d['missing'] Traceback (most recent error last): ... KeyError: 'missing' >>> d.missing Traceback (most recent error last): ... AttributeError: 'AttrDict' object has no attribute 'missing' c8|i}tj||yr`)dictrc)rbinits r*rczAttrDict.__init__s <D dD!r,c>t||jSr`)super __getitem__r)rbr __class__s r*rzAttrDict.__getitem__sw"4::<00r,c@t||j|Sr`)r __setitem__r)rbkeyrrs r*rzAttrDict.__setitem__sw"399;66r,cx |j|S#t$rtdt|d|ddwxYw)N'z' object has no attribute ')rKeyErrorAttributeErrorr)rbrs r* __getattr__zAttrDict.__getattr__sS N##D) ) N DJ<:4&BDIM N Ns&9r`) rdrerfrgrcrrr __setattr____call__ __classcell__)rs@r*rrus)2" 17NKHr,rc  g}|s|ri}n t}t|d}t|d}|dk7rtd|t|d} | dk(rn| dk(r|r t d|r t|d} nt j d } |rt d | j| jd  t|} | jtjd t| t|} | t|jtj dzz } |j#d} t$| dk(rtj d}| jtjdt| |z| jtjdt| | |zz |z | j| n|j'}t)j*|j#| |z }| j't-|zdz} | jtjdt| dz| jtjdt| | dzz dz | j| | j||j/| }|j1dntd|  t3|}|j5|d|vr|drn'|j/i}|D]}|ddk(s |d||d<|D]=}|ddk(s t7|d|\}}|r||d<|d||dj9<?|r|D]J}|ddk(s t dt d|dt d|d t d!|d"n|D][}|dd#k(s t dt d$|d%t d&|d't d(|d)t d*|d+n|D]J}|dd,k(s t dt d-|d.t d/|d0t d1|d2n|D](}|dd3k(s t dt d4|d5nt dt d6t-|d7|Dcgc]}|d }}t;|D](}|dk7s t d8|j=|d9|*t dd|vr;t d:|D] }t d8|d;t?||d<"t d|r|D] }||||< |S|Scc}w)=a Read an IDL .sav file. Parameters ---------- file_name : str Name of the IDL save file. idict : dict, optional Dictionary in which to insert .sav file variables. python_dict : bool, optional By default, the object return is not a Python dictionary, but a case-insensitive dictionary with item, attribute, and call access to variables. To get a standard Python dictionary, set this option to True. uncompressed_file_name : str, optional This option only has an effect for .sav files written with the /compress option. If a file name is specified, compressed .sav files are uncompressed to this file. Otherwise, readsav will use the `tempfile` module to determine a temporary filename automatically, and will remove the temporary file upon successfully reading it in. verbose : bool, optional Whether to print out information about the save file, including the records read, and available variables. Returns ------- idl_dict : AttrDict or dict If `python_dict` is set to False (default), this function returns a case-insensitive dictionary with item, attribute, and call access to variables. If `python_dict` is set to True, this function returns a Python dictionary with all variable names in lowercase. If `idict` was specified, then variables are written to the dictionary specified, and the updated dictionary is returned. Examples -------- >>> from os.path import dirname, join as pjoin >>> import scipy.io as sio >>> from scipy.io import readsav Get the filename for an example .sav file from the tests/data directory. >>> data_dir = pjoin(dirname(sio.__file__), 'tests', 'data') >>> sav_fname = pjoin(data_dir, 'array_float32_1d.sav') Load the .sav file contents. >>> sav_data = readsav(sav_fname) Get keys of the .sav file contents. >>> print(sav_data.keys()) dict_keys(['array1d']) Access a content with a key. >>> print(sav_data['array1d']) [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] rbrsSRzInvalid SIGNATURE: sszIDL Save file is compressedzw+bz.sav)suffixz -> expanding to sSRr>rrrrOrzInvalid RECFMT: rrrrrrrrz2--------------------------------------------------zDate: rzUser: rzHost: rrzFormat: rzArchitecture: rzOperating System: rz IDL Version: rrzAuthor: rzTitle: rz ID Code: rr z Description: rzSuccessfully read z records of which:z - z are of type zAvailable variables:z []) ropenr4rvprinttempfileNamedTemporaryFilerwriterAr8packrrQrr6rIr/rr&zlib decompresslencloser'rrrrsetcountr) file_nameidict python_dictuncompressed_file_nameverboserecords variablesr( signaturerecfmtfoutrrunknownmodvalr) rec_stringrrrrrrectypesrtvars r*rrsLGe J  YAAq!IE-i[9::A F  ;   / 0 !.6D..f=D  %dii[1 2 =!!mG JJv{{4W6 7#1oG |A--bhh7%? ?GffQiGG$ 4% 6;;tS\F-BCD KKc7g6F+G6*Q&RS 7#&&(C )<=JiikC O3b8G JJv{{4Wu_)=> ? JJv{{4g5.IU-R)ST U JJw  JJz "IN    q *6(344  Oq A:x GGI D . Y<; &$%fID< !. 8 Y<: %(6D9LGS& ./iIa l((* + 8 Fi K/f vf~./0vf~./0vf~./0   Fi I-f !1 234vf~&678*6$<.9: fY&7%89:  Fi O3f !1 234w012 &"2!345   Fi M1f  f]&;%<=>   f  "3w<.0BCD+22QAiL22h- CB\!HNN2./}RDAB C f  ! ( )  <C54 ##7"8:; < &M  (C"3E#J ( %3s U7)NFNF)'__all__r8numpyr6rrrrrrr+r2r4r;rArErGrJrMrQrUrXr\r^rjrqrtr|rrrrrrrrrrrrhr,r*r.s@< +   ""$$$!! #     ; 7 < 7 7 = 8 8 9 9  G  'KT)X-`iX(+\3l&@F-t-`0516pr,