a
    Lf$&                     @   sz   d Z ddd ZdZddlZddlmZ dd	lmZ dd
lm	Z	m
Z
 ddlT i Zdd Zde j ZdZdZdd ZdS )a2  
Build F90 module support 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 License.

NO WARRANTY IS EXPRESSED OR IMPLIED.  USE AT YOUR OWN RISK.
z$Revision: 1.27 $
   zSee `f2py -v`    N   )	capi_maps)	func2subr)undo_rmbadnameundo_rmbadname1)*c                 C   sP   t | r| gS t| sg S g }| d D ]$}t |r>|| q&|t| }q&|S )Nbody)ismodulehasbodyappendfindf90modules)mretb r   P/var/www/ai-form-bot/venv/lib/python3.9/site-packages/numpy/f2py/f90mod_rules.pyr      s    r   a        external f2pysetdata
      logical ns
      integer r,i
      integer(%d) s(*)
      ns = .FALSE.
      if (allocated(d)) then
         do i=1,r
            if ((size(d,i).ne.s(i)).and.(s(i).ge.0)) then
               ns = .TRUE.
            end if
         end do
         if (ns) then
            deallocate(d)
         end if
      end if
      if ((.not.allocated(d)).and.(s(1).ge.1)) thenz      end if
      if (allocated(d)) then
         do i=1,r
            s(i) = size(d,i)
         end do
      end if
      flag = 1
      call f2pysetdata(d,allocated(d))z      end if
      if (allocated(d)) then
         do i=1,r
            s(i) = size(d,i)
         end do
         !s(r) must be equal to len(d(1))
      end if
      flag = 2
      call f2pysetdata(d,allocated(d))c           &      C   s  ddl m} g g g ddgddddgg d}d	g}|fd
d}d	g}|fdd}t| }t| D ]0}tdd |d D }	g g g g |d gg f\}
}}}}}g }g }g }t|r|d D ]}||d  q|d  D ]:}|d | }||vrtt	t
|s|| || qtd|d   |d |v rP|	sPtd|d  d q`|rhtdd|  d	g}|fdd}d	g}|fdd}t|}|d|d   |d|d   t|r|d }t|trd|}|| |r|d |D ]}|d | }|| t|}tj| }t||}|d  d!d" }|d#d" }|sbd"}t} |d$t||d% ||t|f  |d&t||  t|r|d }t|trd|}|d'|  t|r|d(|d |f  ||d)  |
d*|  |d+ |d,|d |f  |d-|d)   |d.|d t|f  |d/ |d0 t |d0< tdt|d% d }|d1d2d3d4 |D   |d0 |  |d0< |d5|d)   n6|| |
d6|  |d7 |d8|d |f  q|r|d9 t|r|d D ]}t|sLtd:|d;  d|d  d q|d<|d   |d |d=< | |\}!}"t!|r|d0 |" |d0< |d>|d |d f  |t"j#|dd? nb|"r|d0 |" |d0< |d>|d |d f  |t"j$|dd? n||d  ||d)  g |!d@< t%|!|}#g |#dA< g |#dB< t&||#}|dC|d |d |d |d |d f  |
d6|d   |dD |d8|d |d f  q|dE |dF dG|d d2|
|d0 f |d0< dH|d v rdI}$nd}$|dJ|$|d |d ' d2|f  |dK|d   |dL|$|d |d ' |d f  |dM |dN | | |dN< dO|d |d |d f g|dP  |dP< |d	 |dQ|d   |rt(|D ]}%|dR|d |%f  q|r|ddSg|  |dT |dU |r&t(|D ]}%|dV|%  q|dWd2t(|  |dX|d   |d|dY dZd[ g |dY< |dA d\|d d2t(|f  q`d	|d]< g |d^< g |dB< |d0 |dY< t)|dA dkrd	|dA< ||d0 fS )_Nr   )rulesF_FUNCzarrayobject.h
)Z	includes0Zincludesz"Fortran 90/95 modules:\n")f90modhooksinitf90modhooksr
   ZneedZseparatorsfordocslatexdoc c                 S   s   d|d | f |d< d S )Nz%s
      %sr   r   linesr   r   r   fadd[   s    zbuildhooks.<locals>.faddc                 S   s   d|d | f |d< d S Nz%s
%sr   r   r   r   r   r   dadd_   s    zbuildhooks.<locals>.daddc                 s   s   | ]}|d  dv r|V  qdS )block)functionZ
subroutineNr   ).0itemr   r   r   	<genexpr>d   s   zbuildhooks.<locals>.<genexpr>r
   namevarsz.		Constructing F90 module support for "%s"...
z			Skipping z since it is in 'use'...
z		  Variables: %s
 c                 S   s   d|d | f |d< d S r    r   r   r   r   r   cadd}   s    zbuildhooks.<locals>.caddc                 S   s   d|d | f |d< d S r    r   r   r   r   r   iadd   s    zbuildhooks.<locals>.iaddz'static FortranDataDef f2py_%s_def[] = {z.\subsection{Fortran 90/95 module \texttt{%s}}
notez\begin{description}dimsr	   z-1:z	{"%s",%s,{{%s}},%s, %s},Zrankz\item[]{{}\verb@%s@{}}z--- %szf2py_%s_getdims_%sr   z8void (*%s)(int*,npy_intp*,void(*)(char*,npy_intp*),int*)z6void (*)(int*,npy_intp*,void(*)(char*,npy_intp*),int*)z!	f2py_%s_def[i_f2py++].func = %s;z#subroutine %s(r,s,f2pysetdata,flag)zuse %s, only: d => %s
zinteger flag
r   z allocate(d(%s))
,c                 S   s   g | ]}d | qS )zs(%s)r   )r$   ir   r   r   
<listcomp>       zbuildhooks.<locals>.<listcomp>zend subroutine %szchar *%szchar*z!	f2py_%s_def[i_f2py++].data = %s;z\end{description}z"f90mod_rules.buildhooks: skipping r"   z%s()
modulenamezf2pywrap_%s_%s)	signatureZexternroutinesr   Zdocshortza	{"%s",-1,{{-1}},0,0,NULL,(void *)f2py_rout_#modulename#_%s_%s,doc_f2py_rout_#modulename#_%s_%s},zchar *z	{NULL}
};
}z0static void f2py_setup_%s(%s) {
	int i_f2py=0;%s_Z	F_FUNC_USz4extern void %s(f2pyinit%s,F2PYINIT%s)(void (*)(%s));z static void f2py_init_%s(void) {z*	%s(f2pyinit%s,F2PYINIT%s)(f2py_setup_%s);z}
r   zN	PyDict_SetItemString(d, "%s", PyFortranObject_New(f2py_%s_def,f2py_init_%s));r   z$subroutine f2pyinit%s(f2pysetupfunc)zuse %s, only : %sZ	interfacezend interfacezexternal f2pysetupfunczexternal %szcall f2pysetupfunc(%s)zend subroutine f2pyinit%s
r   z\subsection{z\subsubsection{z"	%s --- %s"Zroutine_defsdoc)*r   r   Zgetuseblocksr   anyr   r   keysZl_orZisintent_hideZ	isprivateZoutmessjoinr   Zmodsign2mapZhasnote
isinstancelistZgetctypeZ
c2capi_mapZ
getarrdimsreplacestrip	fgetdims2r   Z
get_elsizeZgetarrdocsignZisallocatable	fgetdims1rangeint	isroutineZbuildapi
isfunctionr   ZcreatefuncwrapperZcreatesubrwrapperZ
applyrulesZ
dictappendupperr   len)&Zpymodr   r   Zfhooksr   r7   r!   Zusenamesr   Z!contains_functions_or_subroutinesZsargsZfargsZefargsZmodobjsZnotvarsZonlyvarsZsargspZifargsZmfargsr   nvarZchooksr*   Zihooksr+   Zvrdr,   ctatdmZdmsZuse_fgetdims2apiwraparr   ar   r   r   
buildhooksR   s~   




















 



rP   )__doc____version__Zf2py_versionnumpynpr   r   r   Zcrackfortranr   r   Zauxfuncsoptionsr   Zintpitemsizer@   r?   Zfgetdims2_sarP   r   r   r   r   <module>   s   

