a :jgéã@sødZddgZddlZddlZddlZe dej¡Ze dej¡Ze dej¡Z dd „Z e d ¡Z e d ¡Z e d ¡Z d d„Zdd„Ze d¡Zdd„Zdd„Ze d¡Zdd„Zdd„Ze dej¡Zdd„Zdd„ZedƒZdd „Zed!krôeƒdS)"aÆ process_file(filename) takes templated file .xxx.src and produces .xxx file where .xxx is .pyf .f90 or .f using the following template rules: '<..>' denotes a template. All function and subroutine blocks in a source file with names that contain '<..>' will be replicated according to the rules in '<..>'. The number of comma-separated words in '<..>' will determine the number of replicates. '<..>' may have two different forms, named and short. For example, named: where anywhere inside a block '

' will be replaced with 'd', 's', 'z', and 'c' for each replicate of the block. <_c> is already defined: <_c=s,d,c,z> <_t> is already defined: <_t=real,double precision,complex,double complex> short: , a short form of the named, useful when no

appears inside a block. In general, '<..>' contains a comma separated list of arbitrary expressions. If these expression must contain a comma|leftarrow|rightarrow, then prepend the comma|leftarrow|rightarrow with a backslash. If an expression matches '\' then it will be replaced by -th expression. Note that all '<..>' forms in a block must have the same number of comma-separated entries. Predefined named template rules: Ú process_strÚ process_fileéNz2(\n|\A)(( (\$|\*))|)\s*(subroutine|function)\bz+\n\s*end\s*(subroutine|function)\b.*(\n|\Z)z\n (\$|\*)\s*function\bcCs´g}d}t ||¡}|durq°| ¡}t ||| ¡¡rl| d||¡}|dkrPql|}|||d…dkr8qlq8|d7}t || ¡¡}|r”| ¡dpšt|ƒ}}|  ||f¡q|S)z‘ Return a list of tuples for each function or subroutine each tuple is the start and end of a subroutine or function to be expanded. rNÚ éÿÿÿÿéz $é) Úroutine_start_reÚsearchÚstartÚfunction_start_reÚmatchÚendÚrfindÚroutine_end_reÚlenÚappend)ÚastrZspanlistÚindÚmr Úir ©rúG/usr/local/lib/python3.9/site-packages/numpy/distutils/from_template.pyÚparse_structure:s$ rz<\s*(\w[\w\d]*)\s*>z<\s*(\w[\w\d]*)\s*=\s*(.*?)\s*>z<\s*((.*?))\s*>cCsPt |¡}i}|D]8}|d ¡p(t|ƒ}|d dd¡}t|ƒ}|||<q|S)Nrrú\,ú@comma@)Únamed_reÚfindallÚstripÚ unique_keyÚreplaceÚconv)rZrepsÚnamesÚrepÚnameÚreplÚthelistrrrÚfind_repl_patternsYs  r&cCs"t|ƒ}t td|¡d}||fS)NÚr)r&ÚreÚsubnr)rr!rrrÚfind_and_remove_repl_patternscsr*z\A\\(?P\d+)\ZcCs`| d¡}dd„|Dƒ}tt|ƒƒD]0}t ||¡}|r$t| d¡ƒ}||||<q$d |¡S)Nú,cSsg|] }| ¡‘qSr)r)Ú.0ÚxrrrÚ kózconv..Úindex)ÚsplitÚrangerÚitem_rer ÚintÚgroupÚjoin)rÚbÚlrrÚjrrrr is r cCs<t| ¡ƒ}d}d}|s8d|}||vr2|d7}qd}q|S)z( Obtain a unique key given a dictionary.Frz__l%sT)ÚlistÚkeys)ÚadictZallkeysÚdoneÚnZnewkeyrrrrss  rz\A\s*(\w[\w\d]*)\s*\Zc sl| dd¡}| dd¡}t|ƒ‰t d|¡}‡fdd„}t ||¡}d}d}i‰t |¡D]´}|ˆvrZˆ || |d¡¡}|durŽtd|ƒ‚||vr¨|  d ¡s¨|||<d d „|  d ¡Dƒ}t |ƒ}|durÞ|}|ˆ|<|}qZ||krð|ˆ|<qZt d |d   ˆ|¡||fƒqZˆs|S‡‡fdd„} d} t|ƒD]‰| t | |¡d7} q4|  dd¡} |  dd¡} | S)Nz\>z @rightarrow@z\csjt| d¡ dd¡ƒ}t |¡r(d|Sd}ˆ ¡D]}ˆ||kr4|}q4|durbtˆƒ}|ˆ|<d|S)Nrrrz<%s>)r r5rÚtemplate_name_rer r;r)Úmobjr%r#Úkey)ÚlnamesrrÚlistreplˆs   zexpand_sub..listreplzNo replicates found for <%s>Ú_cSsg|]}| dd¡‘qS)rr+)r)r,rrrrr.¢r/zexpand_sub..r+zHMismatch in number of replacements (base <%s=%s>) for <%s=%s>. Ignoring.cs$| d¡}ˆ |ˆd|g¡ˆS)Nr)r5Úget)r@r#)ÚkÚrulesrrÚnamerepl²s zexpand_sub..namereplr'z ú>ú<)rr&rÚsubÚlist_reÚ template_rerrEÚ ValueErrorÚ startswithr1rÚprintr6r2) Úsubstrr!rCZnumsubsZ base_ruleÚrr%ÚruleÚnumrHÚnewstrr)rFrBrGrÚ expand_sub‚sH      þ   rVc Cs|}d}t|ƒ}d}i}| t¡|D]T}t|||d…ƒ\}}||7}| |¡|t||d|d…|ƒ7}|d}q&|||d…7}|S)Nr'rr)rÚupdateÚ_special_namesr*rV) ÚallstrrUÚwritestrÚstructZoldendr!rKZ cleanedstrZdefsrrrr¾s   z8(\n|\A)\s*include\s*['\"](?P[\w\d./\\]+\.src)['\"]cCsªtj |¡}t|ƒ‚}g}|D]h}t |¡}|r|| d¡}tj |¡sTtj ||¡}tj  |¡rp|  t |ƒ¡q†|  |¡q|  |¡qWdƒn1sœ0Y|S)Nr#) ÚosÚpathÚdirnameÚopenÚinclude_src_rer r5Úisabsr6ÚisfileÚextendÚresolve_includesr)ÚsourceÚdÚfidÚlinesÚlinerÚfnrrrrdÓs       *rdcCst|ƒ}td |¡ƒS)Nr')rdrr6)rerhrrrråszÿ <_c=s,d,c,z> <_t=real,double precision,complex,double complex> cCstztjd}Wnty,tj}tj}Yn*0t|dƒ}tj |¡\}}|}t|dƒ}|  ¡}t |ƒ}|  |¡dS)NrrRÚw) ÚsysÚargvÚ IndexErrorÚstdinÚstdoutr_r\r]ÚsplitextÚreadrÚwrite)ÚfilergÚoutfileÚbaseÚextZnewnamerYrZrrrÚmainós    rxÚ__main__)Ú__doc__Ú__all__r\rlr(ÚcompileÚIrrr rrMrrLr&r*r3r rr?rVrr`rdrrXrxÚ__name__rrrrÚs4.       <