
    G/Ph                        d Z ddgZddlZddlZddlZ ej        dej                  Z ej        dej                  Z ej        dej                  Z	d Z
 ej        d	          Z ej        d
          Z ej        d          Zd Zd Z ej        d          Zd Zd Z ej        d          Zd Zd Z ej        dej                  Zd Zd Z ed          Zd Zedk    r e             dS dS )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:
   <p=d,s,z,c> where anywhere inside a block '<p>' 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:
   <s,d,c,z>, a short form of the named, useful when no <p> 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 '\<index>' then it will be replaced
  by <index>-th expression.

  Note that all '<..>' forms in a block must have the same number of
  comma-separated entries.

 Predefined named template rules:
  <prefix=s,d,c,z>
  <ftype=real,double precision,complex,double complex>
  <ftypereal=real,double precision,\0,\1>
  <ctype=float,double,complex_float,complex_double>
  <ctypereal=float,double,\0,\1>

process_strprocess_file    Nz2(\n|\A)((     (\$|\*))|)\s*(subroutine|function)\bz+\n\s*end\s*(subroutine|function)\b.*(\n|\Z)z\n     (\$|\*)\s*function\bc                 "   g }d}	 t                               | |          }|n|                                }t                              | ||                                          r4	 |                     d||          }|dk    rn|}| ||dz            dk    rn3|dz  }t                              | |                                          }|r|                                dz
  pt          |           x}}|	                    ||f           	|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.
    r   TN
   z
     $   )
routine_start_researchstartfunction_start_rematchendrfindroutine_end_relenappend)astrspanlistindmr   ir   s          ]/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numpy/distutils/from_template.pyparse_structurer   :   s    H
C&##D#..9		""488 	JJtS%00b55!A#;
** 	
!!$00O!%%''!)0s4yy0c%%%!&" O    z<\s*(\w[\w\d]*)\s*>z<\s*(\w[\w\d]*)\s*=\s*(.*?)\s*>z<\s*((.*?))\s*>c                     t                               |           }i }|D ][}|d                                         pt          |          }|d                             dd          }t          |          }|||<   \|S )Nr   r	   \,@comma@)named_refindallstrip
unique_keyreplaceconv)r   repsnamesrepnamereplthelists          r   find_repl_patternsr+   Y   sy    D!!DE  1v||~~2E!2!21v~~eY//t**dLr   c                 j    t          |           }t          j        t          d|           d         } | |fS )N r   )r+   resubnr   )r   r&   s     r   find_and_remove_repl_patternsr0   c   s1    t$$E78R&&q)D;r   z\A\\(?P<index>\d+)\Zc                 J   |                      d          }d |D             }t          t          |                    D ]Q}t                              ||                   }|r-t          |                    d                    }||         ||<   Rd                    |          S )N,c                 6    g | ]}|                                 S  )r!   ).0xs     r   
<listcomp>zconv.<locals>.<listcomp>k   s     qr   index)splitranger   item_rer   intgroupjoin)r   blr   r   js         r   r$   r$   i   s    

3AAA3q66]]  MM!A$ 	AGGG$$%%AQ4AaD88A;;r   c                 z    t          |                                           }d}d}|sd|z  }||v r|dz  }nd}||S )z( Obtain a unique key given a dictionary.Fr	   z__l%sT)listkeys)adictallkeysdonennewkeys        r   r"   r"   s   s^    5::<<  GD	A AWFAAD   Mr   z\A\s*(\w[\w\d]*)\s*\Zc                    |                      dd          } |                      dd          } t          |           t                              d|           } fd}t                              ||           } d }d }i t
                              |           D ]}|vr׉                    ||                    |d                     }|t          d|z            ||vr|	                    d          s|||<   d	 |
                    d
          D             }t          |          }|
|}||<   |}||k    r||<   t          d|dd
                    |                   d|d|d	           މs| S fd}	d}
t          |          D ]#|
t
                              |	|           dz   z  }
$|
                     dd          }
|
                     dd          }
|
S )Nz\>z@rightarrow@z\<z@leftarrow@z<\1>c                 2   t          |                     d                              dd                    }t                              |          rd|z  S d }                                D ]}|         |k    r|}|t                    }||<   d|z  S )Nr	   r   r   z<%s>)r$   r=   r#   template_name_rer   rD   r"   )mobjr*   r(   keylnamess       r   listreplzexpand_sub.<locals>.listrepl   s    tzz!}},,UI>>??!!'** 	&W%%;;== 	 	Cc{g%%<f%%D"F4L}r   zNo replicates found for <%s>_c                 :    g | ]}|                     d d          S )r   r2   )r#   )r5   r   s     r   r7   zexpand_sub.<locals>.<listcomp>   s&    JJJ!AIIi--JJJr   r2   z*Mismatch in number of replacements (base <=z>) for <z>. Ignoring.c                 t    |                      d          }                    |dz   |gz                     S )Nr	   )r=   get)rM   r(   kruless     r   namereplzexpand_sub.<locals>.namerepl   s5    zz!}}yy!dV|,,Q//r   r-   z

><)r#   r+   r   sublist_retemplate_rer    rU   
ValueError
startswithr9   r   printr>   r:   )substrr&   rP   numsubs	base_rulerr*   rulenumrX   newstrrV   rO   rW   s              @@@r   
expand_subrh      sE   ^^E>22F^^E=11F''F\\'6**F     [[6**F GIE  (( K KE>>jjEIIa$6$677G !?1!EFFF~~g&8&8&=&=~"aJJw}}S7I7IJJJDd))Ca		a yy#((5+;"<"<"<"<aaaJ K K K  0 0 0 0 0 0 F7^^ = =+//(F33f<<^^NC00F^^M3//FMr   c                 ^   | }d}t          |          }d}i }|                    t                     |D ]k}t          |||d                            \  }}||z  }|                    |           |t	          ||d         |d                  |          z  }|d         }l|||d          z  }|S )Nr-   r   r	   )r   update_special_namesr0   rh   )	allstrrg   writestrstructoldendr&   r[   
cleanedstrdefss	            r   r   r      s    FHV$$FFE	LL     8s1v9NOO
DJTJvc!fSVm4e<<<a&vwwHOr   z8(\n|\A)\s*include\s*['\"](?P<name>[\w\d./\\]+\.src)['\"]c                 \   t           j                            |           }t          |           5 }g }|D ]}t                              |          }|r|                    d          }t           j                            |          s t           j                            ||          }t           j        	                    |          r#|
                    t          |                     |                    |           |                    |           	 d d d            n# 1 swxY w Y   |S )Nr(   )ospathdirnameopeninclude_src_rer   r=   isabsr>   isfileextendresolve_includesr   )sourcedfidlinesliner   fns          r   r{   r{      sF   
A	f # 	# 	#D$$T**A 	#WWV__w}}R(( -a,,B7>>"%% 'LL!1"!5!56666LL&&&&T""""	## # # # # # # # # # # # # # # Ls   C%D!!D%(D%c                 d    t          |           }t          d                    |                    S )Nr-   )r{   r   r>   )r|   r   s     r   r   r      s'    V$$Erwwu~~&&&r   z
<_c=s,d,c,z>
<_t=real,double precision,complex,double complex>
<prefix=s,d,c,z>
<ftype=real,double precision,complex,double complex>
<ctype=float,double,complex_float,complex_double>
<ftypereal=real,double precision,\0,\1>
<ctypereal=float,double,\0,\1>
c                  v   	 t           j        d         } t          | d          }t          j                            |           \  }}|}t          |d          }n(# t          $ r t           j        }t           j        }Y nw xY w|	                                }t          |          }|                    |           d S )Nr	   rd   w)sysargvrv   rs   rt   splitext
IndexErrorstdinstdoutreadr   write)filer~   baseextnewnameoutfilerl   rm   s           r   mainr      s    	%x{
 4oog&&t,,sw$$    i* XXZZF6""HMM(s   A "A>=A>__main__)__doc____all__rs   r   r.   compileIr
   r   r   r   r]   r   r\   r+   r0   r;   r$   r"   rL   rh   r   rw   r{   r   rk   r   __name__r4   r   r   <module>r      s  - -\ .
) 				 



 				2:SUWUYZZ JBDQQBJ=rtDD   6 bj/002:899
"*'
(
(    
 "*,
-
-     2:677 : : :x  & WY[Y]^^  $' ' ' $# %    " zDFFFFF r   