3
ßL]»]  ã               @   s*  d Z ddlmZmZmZ ddlZddlZddlZddlZddl	m
Z
 ddl	mZ ddl	mZ ddl	mZ dd	l	mZ dd
l	mZ ddl	mZ ejZejjZejZejZyddlmZ W n ek
rÎ   dZY nX deef Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z d dd„Z!dd„ Z"dd„ Z#dd„ Z$dS )!a‡  

f2py2e - Fortran to Python C/API generator. 2nd Edition.
         See __usage__ below.

Copyright 1999--2011 Pearu Peterson all rights reserved,
Pearu Peterson <pearu@cens.ioc.ee>
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.
$Date: 2005/05/06 08:31:19 $
Pearu Peterson

é    )ÚdivisionÚabsolute_importÚprint_functionNé   )Úcrackfortran)Úrules)Úcb_rules)Úauxfuncs)Úcfuncs)Úf90mod_rules)Ú__version__zN/Aaæ  Usage:

1) To construct extension module sources:

      f2py [<options>] <fortran files> [[[only:]||[skip:]] \
                                        <fortran functions> ] \
                                       [: <fortran files> ...]

2) To compile fortran files and build extension modules:

      f2py -c [<options>, <build_flib options>, <extra options>] <fortran files>

3) To generate signature files:

      f2py -h <filename.pyf> ...< same options as in (1) >

Description: This program generates a Python C/API file (<modulename>module.c)
             that contains wrappers for given fortran functions so that they
             can be called from Python. With the -c option the corresponding
             extension modules are built.

Options:

  --2d-numpy       Use numpy.f2py tool with NumPy support. [DEFAULT]
  --2d-numeric     Use f2py2e tool with Numeric support.
  --2d-numarray    Use f2py2e tool with Numarray support.
  --g3-numpy       Use 3rd generation f2py from the separate f2py package.
                   [NOT AVAILABLE YET]

  -h <filename>    Write signatures of the fortran routines to file <filename>
                   and exit. You can then edit <filename> and use it instead
                   of <fortran files>. If <filename>==stdout then the
                   signatures are printed to stdout.
  <fortran functions>  Names of fortran routines for which Python C/API
                   functions will be generated. Default is all that are found
                   in <fortran files>.
  <fortran files>  Paths to fortran/signature files that will be scanned for
                   <fortran functions> in order to determine their signatures.
  skip:            Ignore fortran functions that follow until `:'.
  only:            Use only fortran functions that follow until `:'.
  :                Get back to <fortran files> mode.

  -m <modulename>  Name of the module; f2py generates a Python/C API
                   file <modulename>module.c or extension module <modulename>.
                   Default is 'untitled'.

  --[no-]lower     Do [not] lower the cases in <fortran files>. By default,
                   --lower is assumed with -h key, and --no-lower without -h key.

  --build-dir <dirname>  All f2py generated files are created in <dirname>.
                   Default is tempfile.mkdtemp().

  --overwrite-signature  Overwrite existing signature file.

  --[no-]latex-doc Create (or not) <modulename>module.tex.
                   Default is --no-latex-doc.
  --short-latex    Create 'incomplete' LaTeX document (without commands
                   \documentclass, \tableofcontents, and \begin{document},
                   \end{document}).

  --[no-]rest-doc Create (or not) <modulename>module.rst.
                   Default is --no-rest-doc.

  --debug-capi     Create C/API code that reports the state of the wrappers
                   during runtime. Useful for debugging.

  --[no-]wrap-functions    Create Fortran subroutine wrappers to Fortran 77
                   functions. --wrap-functions is default because it ensures
                   maximum portability/compiler independence.

  --include-paths <path1>:<path2>:...   Search include files from the given
                   directories.

  --help-link [..] List system resources found by system_info.py. See also
                   --link-<resource> switch below. [..] is optional list
                   of resources names. E.g. try 'f2py --help-link lapack_opt'.

  --quiet          Run quietly.
  --verbose        Run with extra verbosity.
  -v               Print f2py version ID and exit.


numpy.distutils options (only effective with -c):

  --fcompiler=         Specify Fortran compiler type by vendor
  --compiler=          Specify C compiler type (as defined by distutils)

  --help-fcompiler     List available Fortran compilers and exit
  --f77exec=           Specify the path to F77 compiler
  --f90exec=           Specify the path to F90 compiler
  --f77flags=          Specify F77 compiler flags
  --f90flags=          Specify F90 compiler flags
  --opt=               Specify optimization flags
  --arch=              Specify architecture specific optimization flags
  --noopt              Compile without optimization
  --noarch             Compile without arch-dependent optimization
  --debug              Compile with debugging information

Extra options (only effective with -c):

  --link-<resource>    Link extension module with <resource> as defined
                       by numpy.distutils/system_info.py. E.g. to link
                       with optimized LAPACK libraries (vecLib on MacOSX,
                       ATLAS elsewhere), use --link-lapack_opt.
                       See also --help-link switch.

  -L/path/to/lib/ -l<libname>
  -D<define> -U<name>
  -I/path/to/include/
  <filename>.o <filename>.so <filename>.a

  Using the following macros may be required with non-gcc Fortran
  compilers:
    -DPREPEND_FORTRAN -DNO_APPEND_FORTRAN -DUPPERCASE_FORTRAN
    -DUNDERSCORE_G77

  When using -DF2PY_REPORT_ATEXIT, a performance report of F2PY
  interface is printed out at exit (platforms: Linux).

  When using -DF2PY_REPORT_ON_ARRAY_COPY=<int>, a message is
  sent to stderr whenever F2PY interface makes a copy of an
  array. Integer <int> sets the threshold for array sizes when
  a message should be shown.

Version:     %s
numpy Version: %s
Requires:    Python 2.3 or higher.
License:     NumPy license (see LICENSE.txt in the NumPy source code)
Copyright 1999 - 2011 Pearu Peterson all rights reserved.
http://cens.ioc.ee/projects/f2py2e/c             C   sô  g g g g f\}}}}d<\}}}}}	}
}}d}d=}d}d}d}d}g }d>\}}|d d dœ}�xd| D �]Z}|dkrpq`|dkr~d}q`|dkrŒd?}q`|dkršd}q`|d d	… d
kr¾|j |d	d … ƒ q`|dkrÌd}q`|dk� rÜd}	q`|dk� rìd}q`|dk� rüd}q`|dk�r|d7 }q`|dk�r d}q`|dk�r0d}q`|dk�r@d}q`|dk�rPd}q`|dk�r`d}q`|dk�rpd}q`|dk�r„d|d< q`|dk�r”d}q`|dk�r¤d}q`|dk�r¸d|d< q`|dk�rÈd}q`|dk�rØd}q`|d d… dk�rüttƒ tjƒ  q`|d k�rd}q`|d d	… d!k�rVtjd" j |d#d@… ƒ d$|d	d …  tj|d#dA… < q`|d d%… d&k�rvtd'ƒ d}
q`|d d%… d(k�rŽd}
q`|d d)k�r¶t	d*t
|ƒ ƒ tjƒ  q`|�rÆd}|}q`|�rÖd}|}q`|	�ræd}	|}q`|
�rd}
|j|jtjƒƒ q`|�rd}||d+< q`|�r,d}||d,< q`|dk�r”y"t|ƒ� W d Q R X |j |ƒ W n8 tk
�r� } zt	d-t|ƒ|f ƒ W Y d d }~X nX q`|dBk�rª|j |ƒ q`|dkr`|j |ƒ q`W | �rè| �rè| �rèttƒ tjƒ  tjj|ƒ�s|�std.| ƒ tj|ƒ |�r&tjj||ƒ}|�rXtjj|ƒ�rXd|k�rXt	d/| ƒ tjƒ  ||d0< ||d1< |dCk�r„| �r„d|d2< n||d2< |�rš||d3< |�r¨||d4< |�r¶||d5< |�rÄ||d6< ||d7< ||d8< ||d9< ||d:< ||d;< ||fS )DNr   r   Ú.)Ú	buildpathÚcoutputÚf2py_wrapper_outputÚ zonly:zskip:ú:é   z--debug-z--lowerz--build-dirz
--no-lowerz--quietz	--verbosez--latex-docz--no-latex-docz
--rest-docz--no-rest-docz--wrap-functionsz--no-wrap-functionsz--short-latexZ
shortlatexz	--coutputz--f2py-wrapper-outputz--overwrite-signaturezh-overwritez-hz-mé   z-vz--show-compilersz-includeÚuserincludesé	   z	#include é   z--include_pathszHf2py option --include_paths is deprecated, use --include-paths instead.
z--include-pathsú-zUnknown option %s
r   r   z!IOError: %s. Skipping file "%s".
zCreating build directory %szFSignature file "%s" exists!!! Use --overwrite-signature to overwrite.
ÚdebugÚverbosezdo-lowerÚmoduleÚ	signsfileÚ	onlyfuncsÚ	skipfuncsÚ
dolatexdocÚ	dorestdocÚ	wrapfuncsr   Úinclude_paths)r   r   r   r   r   r   r   r   éÿÿÿÿ)NNr#   r#   r#   r#   r#   )ÚappendÚprintÚf2py_versionÚsysÚexitr
   Zoutneedsr   ÚoutmessÚerrmessÚreprÚextendÚsplitÚosÚpathsepÚopenÚIOErrorÚstrÚ	__usage__ÚpathÚisdirÚmkdirÚjoinÚisfile)Z	inputlineÚfilesr   r   r   ÚfÚf2Zf3Zf5Zf6Zf7Zf8Zf9r   Zdolcr   r    r!   r   r"   r   Ú
modulenameÚoptionsÚlZdetail© r?   ú4/tmp/pip-install-q_7g0qgj/Numpy/numpy/f2py/f2py2e.pyÚscaninputline°   s   




















 





$



rA   c             C   sx  |t _|d t_|d t_d|kr,|d t_d|kr>|d t_d|krP|d t_|d tjd d …< |d t_	tj| ƒ}d|krÞt
d	|d  ƒ tj|ƒ}|d dd … dkrºtjj|ƒ n$t|d dƒ�}|j|ƒ W d Q R X |d d k�rx:|D ]}d|d  |d< qòW nx|D ]}|d |d< �qW |d d k�rXx<|D ]}d|d  |d< �q<W nx|D ]}|d |d< �q^W |S )Nr   r   r   r   r   r"   zdo-lowerr   zSaving signatures to file "%s"
é   ÚstdoutÚwr   z
%smodule.cÚnamer   z%s-f2pywrappers.fiúÿÿÿ)r   r=   r   r   r   Zf77modulenamer   r   r"   Zdolowercaser)   Zcrack2fortranr'   rC   Úwriter0   )r9   r=   ÚpostlistZpyfr:   Úmodr?   r?   r@   Úcallcrackfortran>  s<    











rI   c          	   C   s²  t jƒ  tdƒ g g i   }}}x tt| ƒƒD ]�}d| | d krRtj| | ƒ q.d| | kržx>| | d jƒ D ]*}||kr„g ||< || j| | d ƒ qpW |j| | ƒ |j| | d ƒ q.W i }xætt|ƒƒD ]Ö}|| |k�rtd|| dj	dd„ |||  D ƒƒf ƒ qÔg }d|| k�r€xX|| d jƒ D ]D}||k�rf||k�rf|j||j
|ƒ ƒ ntd	|| |f ƒ �q8W i ||| < t|||  tj|| |ƒƒ qÔW |S )
NzBuilding modules...
Ú__user__rE   Úusez+	Skipping module "%s" which is used by %s.
ú,c             S   s   g | ]}d | ‘qS )z"%s"r?   )Ú.0Úsr?   r?   r@   ú
<listcomp>u  s    z buildmodules.<locals>.<listcomp>z:	Module "%s" uses nonexisting "%s" which will be ignored.
)r
   Zbuildcfuncsr)   ÚrangeÚlenr   ZbuildcallbacksÚkeysr$   r7   ÚindexÚdict_appendr   Zbuildmodule)ÚlstÚmodulesZmnamesÚisusedbyÚiÚuÚretZumr?   r?   r@   Úbuildmodulesb  s8    *"r[   c             C   sT   xN|j ƒ D ]B\}}|| kr"g | |< t|tƒr>| | | | |< q
| | j|ƒ q
W d S )N)ÚitemsÚ
isinstanceÚlistr$   )Zd_outZd_inÚkÚvr?   r?   r@   rT   „  s    
rT   c          	   C   s"  t jƒ  tjjtjjtjƒƒ}tjj|ddƒ}tjj|ddƒ}t	| ƒ\}}|t
_t||ƒ}i }x`tt|ƒƒD ]P}d|| krlx>|| d jƒ D ]*}	|	|kr¢g ||	< ||	 j|| d ƒ qŽW qlW xxtt|ƒƒD ]h}|| d dkoðd|| d krÎ|| d |krÎtd	|| d d
jdd„ ||| d  D ƒƒf ƒ qÎW d|k�r€|d dk�r|tdƒ tdtjjtjd ƒ|d f ƒ dS xRtt|ƒƒD ]B}|| d dk�rŽd|k�r¶tdƒ tdt|| d ƒ ƒ‚�qŽW |d t
_|t_|d t
_t|ƒ}
x&|
jƒ D ]}t|
| ||dœƒ �q W |
S )aJ  
    Equivalent to running::

        f2py <args>

    where ``<args>=string.join(<list>,' ')``, but in Python.  Unless
    ``-h`` is used, this function returns a dictionary containing
    information on generated modules and their dependencies on source
    files.  For example, the command ``f2py -m scalar scalar.f`` can be
    executed from Python as follows

    You cannot build extension modules with this function, that is,
    using ``-c`` is not allowed. Use ``compile`` command instead

    Examples
    --------
    .. include:: run_main_session.dat
        :literal:

    Úsrczfortranobject.hzfortranobject.crK   rE   Úblockzpython modulerJ   z<Skipping Makefile build for module "%s" which is used by %s
rL   c             S   s   g | ]}d | ‘qS )z"%s"r?   )rM   rN   r?   r?   r@   rO   ¶  s    zrun_main.<locals>.<listcomp>r   r   r   zKStopping. Edit the signature file and then run f2py on the signature file: z%s %s
r   NzJTip: If your original code is Fortran source then you must use -m option.
z2All blocks must be python module blocks but got %sr   r!   )ZcsrcÚh)r   Zreset_global_f2py_varsr.   r4   ÚdirnameÚabspathr
   Ú__file__r7   rA   r	   r=   rI   rP   rQ   rR   r$   r)   Úbasenamer'   Úargvr*   Ú	TypeErrorr+   Zdebugoptionsr   r!   r[   rT   )Zcomline_listZf2pydirZfobjhsrcZfobjcsrcr9   r=   rG   rW   rX   rY   rZ   Úmnr?   r?   r@   Úrun_mainŽ  sP    
 4



rk   c       	      C   sz   g g  }}t j| d | d ƒj}|r0t| ƒ}nd}x<dd„ |D ƒD ]*}||ƒrd|j||d… ƒ qD|j|ƒ qDW ||fS )z,
    Filter files by prefix and suffix.
    z.*z\Zr   c             S   s   g | ]}|j ƒ ‘qS r?   )Ústrip)rM   Úxr?   r?   r@   rO   Ú  s    z filter_files.<locals>.<listcomp>N)ÚreÚcompileÚmatchrQ   r$   )	ÚprefixÚsuffixr9   Úremove_prefixÚfilteredÚrestrp   ÚindÚfiler?   r?   r@   Úfilter_filesÐ  s    

rx   c             C   s   t jjt jj| jƒƒ}|S )N)r.   r4   rd   rf   )r   Úpr?   r?   r@   Ú
get_prefixâ  s    rz   c        $         s¤  ddl } tjjdƒ}tj|= d}ytjjdƒ}W n tk
rH   d}Y nX |dk	rvtj|d  }tj|d = tj|= nd}| jƒ }tjdƒ‰ ‡ fdd„tjdd… D ƒ‰
‡
fd	d„tjD ƒt_ˆ
rÐd
d„ ˆ
D ƒ‰
tjdƒ‰‡fdd„tjdd… D ƒ‰‡fdd„tjD ƒt_g ‰d}xPtjdd… D ]>}|d?k�r8d}n|dk�rFd}|�sV|dk�r$ˆj|ƒ �q$W ˆ�r„ˆd@ dk�r„ˆjdƒ ˆj	ˆƒ ‡fdd„tjD ƒt_tjdƒ‰‡fdd„tjdd… D ƒ‰‡fdd„tjD ƒt_tjdƒ‰‡fdd„tjdd… D ƒ‰‡fdd„tjD ƒt_g }xØˆD ]Ð}d}|dt
|ƒ… |k�r&ddlm}	 |	jƒ  t|	jjƒ ƒ}
|t
|ƒd… jƒ  }}||
k�rÚi }y|| }W n< tk
�rÔ   ||jƒ k�rÐtd|t
|ƒd…  ƒ Y nX |}ˆj|ƒ}d| ˆ|< �q&�q&W x|D ]}ˆj|ƒ}ˆ|= �q W t
ˆƒdk�s4ttˆƒƒ‚tjdƒ‰‡fdd„tjdd… D ƒ‰	‡	fdd„tjD ƒt_dˆk�r„ˆ	jdƒ d }tjdd… }x`dAD ]X}|tjk�rœtjj|ƒ}ˆj	tj||d … ƒ tj|d = tj|= tjdd… }�qœW d#tjk�rBtjjd#ƒ}tj|d  }tj|d = tj|= tjdd… }nDdd$lm} td%d&|ƒ\}}|| }x|D ]}||ƒ}|�rlP �qlW td%d'|ƒ\}}td(d%|dd)�\}}td*d%|dd)�\}}td+d%|dd)�\}}td,d%|dd)�\}}td-d%|dd)�\}}xdtt
|ƒƒD ]T}|| jd.dƒ}t
|ƒdk�r4|jdƒ t
|ƒdk�rPt|ƒ||< n
td/|ƒ �qW dd0lm} i }|�rˆ|j	|jd1g ƒƒ dd2l m!}m"} ||||||||ˆd3œ	}ˆ
�rüdd4l#m$}  x8ˆ
D ]0}!||!ƒ}|�sêt%d5t|!ƒ ƒ | |f|Ž �qÈW |f |Ž}"tjd gˆ	 t_tjj	d6d7|d8|d9d:gƒ ˆ�rJtjj	d;gˆ ƒ ˆ�rbtjj	d<gˆ ƒ ||"gd=� |�r t&j'j(|ƒ�r ddl)}#t%d>| ƒ |#j*|ƒ dS )Bz 
    Do it all in one call!
    r   Nz-cz--build-dirr   z[-][-]link[-]c                s   g | ]}ˆ j |ƒr|‘qS r?   )rp   )rM   Ú_m)Ú_reg1r?   r@   rO   þ  s    zrun_compile.<locals>.<listcomp>c                s   g | ]}|ˆ kr|‘qS r?   r?   )rM   r{   )Úsysinfo_flagsr?   r@   rO   ÿ  s    c             S   s   g | ]}|d d… ‘qS )é   Nr?   )rM   r:   r?   r?   r@   rO     s    zF[-][-]((no[-]|)(wrap[-]functions|lower)|debug[-]capi|quiet)|[-]includec                s   g | ]}ˆ j |ƒr|‘qS r?   )rp   )rM   r{   )Ú_reg2r?   r@   rO     s    c                s   g | ]}|ˆ kr|‘qS r?   r?   )rM   r{   )Ú
f2py_flagsr?   r@   rO     s    úonly:úskip:r   c                s   g | ]}|ˆ kr|‘qS r?   r?   )rM   r{   )Úf2py_flags2r?   r@   rO     s    z<[-][-]((f(90)?compiler([-]exec|)|compiler)=|help[-]compiler)c                s   g | ]}ˆ j |ƒr|‘qS r?   )rp   )rM   r{   )Ú_reg3r?   r@   rO     s    c                s   g | ]}|ˆ kr|‘qS r?   r?   )rM   r{   )Ú
flib_flagsr?   r@   rO     s    zN[-][-]((f(77|90)(flags|exec)|opt|arch)=|(debug|noopt|noarch|help[-]fcompiler))c                s   g | ]}ˆ j |ƒr|‘qS r?   )rp   )rM   r{   )Ú_reg4r?   r@   rO     s    c                s   g | ]}|ˆ kr|‘qS r?   r?   )rM   r{   )Úfc_flagsr?   r@   rO     s    z--fcompiler=)Ú	fcompilerzUnknown vendor: "%s"r   z[-][-](verbose)c                s   g | ]}ˆ j |ƒr|‘qS r?   )rp   )rM   r{   )Ú_reg5r?   r@   rO   8  s    c                s   g | ]}|ˆ kr|‘qS r?   r?   )rM   r{   )Úsetup_flagsr?   r@   rO   9  s    z--quietZuntitledú--include_pathsú--include-pathsz-m)Úget_f2py_modulenamer   z[.]pyf([.]src|)z[.](o|a|so)z-I)rs   z-Lz-lz-Uz-Dú=zInvalid use of -D:)Úget_infoÚinclude_dirs)ÚsetupÚ	Extension)	rE   Úsourcesr�   Úlibrary_dirsÚ	librariesÚdefine_macrosÚundef_macrosÚextra_objectsZf2py_options)rT   z9No %s resources found in system (try `f2py --help-link`)
Úbuildz--build-tempz--build-basez--build-platlibr   Z	config_fcÚ	build_ext)Úext_moduleszRemoving build directory %s
)r�   r‚   r#   )r‹   rŒ   )+Útempfiler'   rh   rS   Ú
ValueErrorÚmkdtemprn   ro   r$   r,   rQ   Znumpy.distutilsrˆ   Zload_all_fcompiler_classesr^   Zfcompiler_classrR   ÚlowerÚKeyErrorÚvaluesr%   ÚAssertionErrorr+   Z!numpy.distutils.command.build_srcr�   rx   rP   r-   ÚtupleÚnumpy.distutils.system_infor�   ÚgetZnumpy.distutils.corer‘   r’   Znumpy.distutils.misc_utilrT   r)   r.   r4   ÚexistsÚshutilÚrmtree)$rœ   rX   Zremove_build_dirÚ	build_dirÚflÚaZdel_listrN   r`   rˆ   Zallowed_keysÚnvÚovZvmapr<   r“   Úoptnamer�   Z	pyf_filesr:   r˜   r�   r”   r•   r—   r–   Ú
name_valuer�   Znum_infor‘   r’   Zext_argsrT   ÚnÚextr§   r?   )r|   r   r„   r†   r‰   r€   rƒ   r‡   r…   rŠ   r}   r@   Úrun_compileç  s   





















r²   c              C   sú   dt jdd … kr4t jjdƒ ddlm}  | ƒ  d S dt jdd … kr^t jjdƒ t jdƒ nldt jdd … kr~t jjdƒ nLdt jdd … krªt jjd	ƒ t jjdƒ n d
t jdd … krÊt jjd
ƒ n dt jdd … krät	ƒ  nt
t jdd … ƒ d S )Nz--help-linkr   r   )Úshow_allz
--g3-numpyz*G3 f2py support is not implemented, yet.\nz--2e-numericz--2e-numarrayz
-DNUMARRAYz
--2e-numpyz-c)r'   rh   Úremover¤   r³   ÚstderrrF   r(   r$   r²   rk   )r³   r?   r?   r@   Úmain’  s$    r¶   )N)%Ú__doc__Ú
__future__r   r   r   r'   r.   Úpprintrn   r   r   r   r   r	   r
   r   r   Úversionr&   rµ   rF   r*   Úshowr)   ZnumpyZnumpy_versionÚImportErrorr3   rA   rI   r[   rT   rk   rx   rz   r²   r¶   r?   r?   r?   r@   Ú<module>   sB   
  $"
B
 ,