a ;jgg@sdZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddl m Z gd Z e jZejZiZgZdZd d Zd d ZddZddZddZddZddZddZddZddZddZd d!Zd"d#Z d$d%Z!d&d'Z"d(d)Z#d*d+Z$d,d-Z%d.d/Z&d0d1Z'd2d3Z(d4d5Z)d6d7Z*d8d9Z+d:d;Z,dd?Z.d@dAZ/dBdCZ0dDdEZ1dFdGZ2dHdIZ3dJdKZ4dLdMZ5dNdOZ6dPdQZ7dRdSZ8dTdUZ9dVdWZ:dXdYZ;dZd[Zd`daZ?dbdcZ@dddeZAdfdgZBdhdiZCdjdkZDdldmZEdndoZFdpdqZGdrdsZHdtduZIdvdwZJdxdyZKdzd{ZLd|d}ZMd~dZNddZOddZPddZQddZRddZSddZTddZUddZVddZWddZXddZYddZZddZ[ddZ\ddZ]ddZ^ddZ_ddZ`eRdeSdeTdeUdeXdeWdeNde\de^de_de`di ZaddZbddZcddZdddZeddZfddZgddZhddZiddZjdd„ZkddĄZlddƄZmGddȄdenZoGddʄdʃZpdd̄Zqdd΄ZrddЄZsdd҄ZtddԄZudddքZvdd؄ZwifddڄZxdd܄ZyddބZzddZ{ddZ|ddZ}ddZ~ddZddZddZdddZddZifddZedejjZedejjZddZddZdddZdS(a9 Auxiliary functions for f2py2e. Copyright 1999 -- 2011 Pearu Peterson all rights reserved. Copyright 2011 -- present NumPy Developers. Permission to use, modify, and distribute this software is given under the terms of the NumPy (BSD style) LICENSE. NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. N)reduce)deepcopy) __version__)cfuncs)errmess)\ applyrules debugcapi dictappendrgentitlegetargs2getcallprotoargumentgetcallstatementgetfortrannamegetpymethoddef getrestdoc getusercode getusercode1 getdimensionhasbodyhascallstatement hascommon hasexternals hasinitvaluehasnote hasresultnote isallocatableisarrayisarrayofstrings ischaracterischaracterarrayischaracter_or_characterarray iscomplexiscomplexarrayiscomplexfunctioniscomplexfunction_warnisdoubleisdummyroutine isexternal isfunctionisfunction_wrapisint1 isint1array isinteger isintent_aux isintent_cisintent_callback isintent_copy isintent_dict isintent_hide isintent_inisintent_inoutisintent_inplaceisintent_nothide isintent_outisintent_overwrite islogicalislogicalfunctionislong_complex islong_doubleislong_doublefunction islong_longislong_longfunctionismoduleismoduleroutine isoptional isprivate isrequired isroutineisscalarissigned_long_longarrayisstring isstringarrayisstring_or_stringarrayisstringfunction issubroutineget_f2py_modulenameissubroutine_wrap isthreadsafe isunsignedisunsigned_charisunsigned_chararrayisunsigned_long_longisunsigned_long_longarrayisunsigned_shortisunsigned_shortarrayl_andl_notl_oroutmessreplaceshow stripcomma throw_error isattr_value getuseblocksprocess_f2cmap_dictcCstddrtj|dS)Nverboser)optionsgetsysstdoutwrite)trj=/usr/local/lib/python3.9/site-packages/numpy/f2py/auxfuncs.pyr[>s r[cCsdtvS)NZcapi) debugoptionsvarrjrjrkr Csr cCsd|vo|ddkot| SNtypespec characterr(rmrjrjrk _ischaracterGsrscCsd|vo|ddkot| Srorrrmrjrjrk _isstringLsrtcCst|od|vSNZ charselectorrsrmrjrjrkr!Qsr!cCst|ot| SNr!rrmrjrjrkrUsrcCst|ot|Srwrxrmrjrjrkr Ysr cCst|od|vSrurvrmrjrjrkrK]srKcCst|ot| SrwrKrrmrjrjrkrIasrIcCst|ot|SrwryrmrjrjrkrJesrJcCst|o|dddkS)N dimensionz(*))rJrmrjrjrkrisrcCsd|vot| SNrzrrrmrjrjrkrosrcCst|pt|pt| Srw)rrIr(rmrjrjrkrGssrGcCst|o|ddvSNrp)complexzdouble complexrGrermrjrjrkr"ws r"cCst|o|ddkS)Nrplogicalrrmrjrjrkr:|sr:cCst|o|ddkS)Nrpintegerrrmrjrjrkr-sr-cCst|o|ddkS)Nrprealrrmrjrjrkisrealsrc CsLz|ddWStyFz|ddWYSty@Yn0Yn0dS)NZ kindselector*kindKeyErrorrmrjrjrkget_kinds  rcCs$|ddko"t|dko"t| SNrpr1)rerrrmrjrjrkr+s  r+cCs*t|s dS|ddvrdSt|dkS)Nrrprr8rGrerrmrjrjrkr?s r?cCs*t|s dS|ddkrdSt|dkS)Nrrpr-1rrmrjrjrkrRs rRcCs*t|s dS|ddkrdSt|dkS)Nrrpr-2rrmrjrjrkrVs rVcCs*t|s dS|ddkrdSt|dkS)Nrrpr-4rrmrjrjrkrQs rQcCs*t|s dS|ddkrdSt|dkS)Nrrpr-8rrmrjrjrkrTs rTcCs*t|s dS|ddksdSt|dkS)Nrrprrrrmrjrjrkr&s r&cCs*t|s dS|ddksdSt|dkS)NrrprZ16rrmrjrjrkr=s r=cCst|s dSt|dkS)NrZ32)r"rrmrjrjrkr<sr<cCst|o|ddvSr})rrermrjrjrkr#s r#cCs"t|o |ddko t|dkSrrrerrmrjrjrkr,s r,cCs"t|o |ddvo t|dkS)NrprrrrmrjrjrkrSs rScCs"t|o |ddvo t|dkS)NrprrrrmrjrjrkrWs rWcCs"t|o |ddvo t|dkS)Nrprrrrmrjrjrkisunsignedarrays rcCs"t|o |ddvo t|dkS)NrprrrrmrjrjrkrUs rUcCs"t|o |ddvo t|dkS)Nrprrrrmrjrjrkissigned_chararrays rcCs"t|o |ddvo t|dkS)Nrpr2rrmrjrjrkissigned_shortarrays rcCs"t|o |ddvo t|dkS)Nrpr4rrmrjrjrkissigned_arrays rcCs"t|o |ddvo t|dkS)NrprrrrmrjrjrkrHs rHcCsd|vod|dvS)NattrspecZ allocatablerjrmrjrjrkrsrcCsd|vpt| Sr|)rIrmrjrjrk ismutable srcCsd|vS)N modulenamerjroutrjrjrkrBsrBcCsd|vod|dkS)NblockmodulerjrrjrjrkrAsrAcCsd|vod|dkS)Nrfunctionrjrrjrjrkr)sr)cCs"t|r dSto t|o t| SNr)r/ wrapfuncsr)r(rrjrjrkr*sr*cCsd|vod|dkS)NrZ subroutinerjrrjrjrkrM!srMcCst|r dSt|ot|Sr)r/rMhasassumedshaperrjrjrkrO%srOcCsd|dgvS)Nvaluerrermrjrjrkr`*sr`cCsV|drdS|dD]:}|d|idgD]}|dkr2d|d<dSq2qdS)NrTargsvarsrz:Fr)radrjrjrkr.s   rcCst|pt|Srw)rBrrrjrjrkrequiresf90wrapper9srcCst|pt|Srw)r)rMrrjrjrkrF=srFcCsFt|s dSd|vr|d}n|d}||dvrBt|d|SdSNrresultnamer)r)r:rrrjrjrkr;As  r;cCsFt|s dSd|vr|d}n|d}||dvrBt|d|SdSr)r)r?rrjrjrkr@Ms  r@cCsFt|s dSd|vr|d}n|d}||dvrBt|d|SdSr)r)r=rrjrjrkr>Ys  r>cCsFt|s dSd|vr|d}n|d}||dvrBt|d|SdSr)r)r"rrjrjrkr$es  r$cCst|rtddSdS)Na ************************************************************** Warning: code with a function returning complex value may not work correctly with your Fortran compiler. When using GNU gcc/g77 compilers, codes should work correctly for callbacks with: f2py -c -DF2PY_CB_RETURNCOMPLEX ************************************************************** rr)r$r[rrjrjrkr%qsr%cCsFt|s dSd|vr|d}n|d}||dvrBt|d|SdSr)r)rIrrjrjrkrLs  rLcCsd|vo|dS)NZ externalsrjrrjrjrkrsrcCsd|vod|dvS)Nf2pyenhancementsZ threadsaferjrrjrjrkrPs rPcCsd|vo|dS)Nrrjrrjrjrk hasvariablessrcCs(d|vo&d|dvo&d|dvo&t|S)Nroptionalrequired)r7rmrjrjrkrCs  rCcCsd|vod|dvS)NrZexternalrjrmrjrjrkr(sr(csDdd|vr@tdd|dDr@fdd|dDdSdS)Nz \((.*?)\)rcss|]}d|vVqdS)rzNrj).0srjrjrk zgetdimension..csg|]}t|qSrj)refindall)rvZ dimpatternrjrk rz getdimension..r)keysanyrmrjrrkrs rcCst| ot|Srw)rCr7rmrjrjrkrEsrEcCspd|vr dSd|dvrdSd|dvr,dSd|dvr.rr)rerr)rrZauxvarsrrjr rkr s   r cCs<d|vr dSd}|ddkr,|d|df}|d|dS)NZf2pymultilinesrz python modulerr)rkrjrjrkrs  rcCs*dt|dd}d|d||dfS)NPz /*%s %s %s*/r)r)rlnrjrjrkr sr cCs$t|trttfdd|gS|gS)NcSs |||Srwrj)xyrrjrjrk rzflatlist..)rrrflatlist)lstrjrjrkrs rcCs |r|ddkr|ddS|S)Nr{rrj)rrjrjrkr^ s r^rc sttrfddDSttr<fddDSdtD]v}|dkrZqLdvr||dvr|d|}n}t|trd||t|qLd||qLS)Ncsg|]}t|qSrjr\r_m) defaultseprrjrkrrzreplace..csg|]}t|qSrjrr)rrrjrkrrr separatorsforz#%s#)rrrr\rr)rrrr seprj)rrrrkr\s   r\cCs2t|tr"|D]}t||}q|S|D]}|ddkr>q*||vr t||trd||g||<t||trt||tr||||||<n||||ntt||tr,t||tr,|dkr||D]$}|||vr||||||<qnt||||||<q*||||<q*|S)Nr_r)rrr rrrdict)rdarrr k1rjrjrkr &s.      r c Csi}t|tr>|D]&}t|||}t||}d|vrq:q|Sd|vrV|d|sV|Sd|vrtd|di||}d|vrt|d|D]}|dkr||||<qt||trt|||||<nt||tr$g||<||D].}t||i||} || vr|| | |qn2|ddkr8qnt||t rBg||<||D]} t| t j r\| |r\t||| tr||| D]N}t|t rtd|i||}d|vr|d}nd }|| t||qnR||| }t|t r(td|i|}d|vr$|d}nd }|| t||q\nt d t||t||trt||d kr||d||<||gkr||=q|S) N_break_checkZneedZneedsrrrZ supertextrzapplyrules: ignoring rule %s. r)rrrr rZ append_needsrrr\rrtypes FunctionTyperrr) rulesrrnretrZrrresr rrrrjrjrkrCsl             rz%\s*python\s*module\s*(?P[\w_]+)z4\s*python\s*module\s*(?P[\w_]*?__user__[\w_]*)cCs^d}t|>}|D](}t|}|rt|r,q|d}q.)rerr)ZpymodZall_usesinnerZmodblockrjrjrkras    "raFc Csg}i}|D]&\}}dd|D}|||<q|D]\}}||vrXi||<|D]\} } | |vr| ||vrtd|| ||| | f| ||| <|rtd|| | f|| q`|r`td|| | | t|fq`q@||fS)a Update the Fortran-to-C type mapping dictionary with new mappings and return a list of successfully mapped C types. This function integrates a new mapping dictionary into an existing Fortran-to-C type mapping dictionary. It ensures that all keys are in lowercase and validates new entries against a given C-to-Python mapping dictionary. Redefinitions and invalid entries are reported with a warning. Parameters ---------- f2cmap_all : dict The existing Fortran-to-C type mapping dictionary that will be updated. It should be a dictionary of dictionaries where the main keys represent Fortran types and the nested dictionaries map Fortran type specifiers to corresponding C types. new_map : dict A dictionary containing new type mappings to be added to `f2cmap_all`. The structure should be similar to `f2cmap_all`, with keys representing Fortran types and values being dictionaries of type specifiers and their C type equivalents. c2py_map : dict A dictionary used for validating the C types in `new_map`. It maps C types to corresponding Python types and is used to ensure that the C types specified in `new_map` are valid. verbose : boolean A flag used to provide information about the types mapped Returns ------- tuple of (dict, list) The updated Fortran-to-C type mapping dictionary and a list of successfully mapped C types. cSsi|]\}}||qSrj)lower)rrv1rjrjrk rz'process_f2cmap_dict..z3 Warning: redefinition of {'%s':{'%s':'%s'->'%s'}} z Mapping "%s(kind=%s)" to "%s" z5 Ignoring map {'%s':{'%s':'%s'}}: '%s' must be in %s )itemsr0r[rrrr) Z f2cmap_allZnew_mapZc2py_maprcZ f2cmap_mappedZ new_map_lowerr Zd1Zd1_lowerrr1rjrjrkrbs6&   rb)rr)r)F)__doc__pprintrfrr" functoolsrrrrrrr__all__versionZ f2py_versionr]rdrlrr[r rsrtr!rr rKrIrJrrrGr"r:r-rrr+r?rRrVrQrTr&r=r<r#r,rSrWrrUrrrrHrrrBrAr)r*rMrOr`rrrFr;r@r>r$r%rLrrPrrCr(rrEr4r5r8r3r7r/rr1r9r0r6r.rrrr2rDrrrrrrrrrrr Exceptionrr_rXrZrYr'rrrr rrrr r rr rr^r\r rcompileImatchr(r)rNrarbrjrjrjrks                     '   =