
Xc           @` 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 Wn e k
 rd Z n Xd e e f Z d   Z d   Z d   Z d   Z d   Z  d d  Z" d   Z# d   Z$ d   Z% d S(   s  

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

i    (   t   divisiont   absolute_importt   print_functionNi   (   t   crackfortran(   t   rules(   t   cb_rules(   t   auxfuncs(   t   cfuncs(   t   f90mod_rules(   t   __version__s   N/As  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= \ } } i | d 6d  d 6d  d 6} x|  D]} | d k r q | d	 k r d } q | d
 k r d } q | d k r d } q | d  d k r| j | d  q | d k r!d } q | d k r6d }	 q | d k rKd } q | d k r`d } q | d k ry| d 7} 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 } q | d k rd } q | d k rd | d <q | d k r%d } q | d k r:d } q | d k rSd | d <q | d k rhd } q | d  k r}d } q | d!  d" k rt t  t j   q | d# k rd } q | d  d$ k rt j d% j | d& d ! d' | d t j | d& d !<q | d(  d) k r&t	 d*  d }
 q | d(  d+ k r?d }
 q | d d, k rp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 riy! t |  j   | j |  Wqt k
 re} t
 d. t |  | f  qXq | d k r| j |  q | d k r | j |  q q W| r| r| rt t  t j   n  t j j |  s
| st	 d/ |  n  t j |  n  | r(t j j | |  } n  | rgt j j |  rgd | k rgt
 d0 |  t j   n  | | d1 <| | d2 <| d k r| rd | d3 <n
 | | d3 <| r| | d4 <n  | r| | d5 <n  | r| | d6 <n  | r| | d7 <n  | | d8 <| | d9 <| | d: <| | d <| | d; <| | f S(>   Ni   i    it   .t	   buildpatht   coutputt   f2py_wrapper_outputt    s   only:s   skip:t   :i   s   --debug-s   --lowers   --build-dirs
   --no-lowers   --quiets	   --verboses   --latex-docs   --no-latex-docs
   --rest-docs   --no-rest-docs   --wrap-functionss   --no-wrap-functionss   --short-latext
   shortlatexs	   --coutputs   --f2py-wrapper-outputs   --overwrite-signatures   h-overwrites   -hs   -mi   s   -vs   --show-compilerss   -includet   userincludesi	   s	   #include i   s   --include_pathssH   f2py option --include_paths is deprecated, use --include-paths instead.
s   --include-pathst   -s   Unknown option %s
s!   IOError: %s. Skipping file "%s".
s   Creating build directory %ssF   Signature file "%s" exists!!! Use --overwrite-signature to overwrite.
t   debugt   verboses   do-lowert   modulet	   signsfilet	   onlyfuncst	   skipfuncst
   dolatexdoct	   dorestdoct	   wrapfuncst   include_paths(   i   i    i    i    i    i    i    i    (   NN(   t   Nonet   appendt   printt   f2py_versiont   syst   exitR   t   outneedsR   t   outmesst   errmesst   reprt   extendt   splitt   ost   pathsept   opent   closet   IOErrort   strt	   __usage__t   patht   isdirt   mkdirt   joint   isfile(   t	   inputlinet   filesR   R   R   t   ft   f2t   f3t   f5t   f6t   f7t   f8t   f9R   t   dolcR   R   R   R   R   R   t
   modulenamet   optionst   lt   detail(    (    s0   /tmp/pip-build-X4mzal/numpy/numpy/f2py/f2py2e.pyt   scaninputline   s   

																	
						
$







c         C` s  | t  _ | d t _ | d t _ d | k r? | d t _ n  d | k r[ | d t _ n  d | k rw | d t _ n  | d t j (| d t _	 t j |   } d | k r"t
 d	 | d  t j |  } | d d
 d k r t j j |  q"t | d d  } | j |  | j   n  | d d  k rXxB | D] } d | d | d <q9Wn x | D] } | d | d <q_W| d d  k rxB | D] } d | d | d <qWn x | D] } | d | d <qW| S(   NR   R   R   R   R   R   s   do-lowerR   s   Saving signatures to file "%s"
it   stdoutt   wR   s
   %smodule.ct   nameR   s   %s-f2pywrappers.f(   R   RA   R   R   R   t   f77modulenameR   R   R   t   dolowercaseR$   t   crack2fortranR!   RE   t   writeR+   R,   R   (   R6   RA   t   postlistt   pyfR7   t   mod(    (    s0   /tmp/pip-build-X4mzal/numpy/numpy/f2py/f2py2e.pyt   callcrackfortran=  s>    	c   	   	   C` s)  t  j   t d  g  g  i  } } } x t t |    D] } d |  | d k ri t j |  |  q; d |  | k r xQ |  | d j   D]8 } | | k r g  | | <n  | | j |  | d  q Wn  | j |  |  | j |  | d  q; Wi  } x%t t |   D]} | | | k rit d | | d j	 g  | | | D] } d | ^ qH f  qg  } d | | k rxl | | d j   D]S } | | k r| | k r| j | | j
 |   qt d | | | f  qWn  i  | | | <t | | | t j | | |   qW| S(	   Ns   Building modules...
t   __user__RG   t   uses+   	Skipping module "%s" which is used by %s.
t   ,s   "%s"s:   	Module "%s" uses nonexisting "%s" which will be ignored.
(   R   t   buildcfuncsR$   t   ranget   lenR   t   buildcallbackst   keysR   R3   t   indext   dict_appendR   t   buildmodule(	   t   lstt   modulest   mnamest   isusedbyt   it   ut   rett   st   um(    (    s0   /tmp/pip-build-X4mzal/numpy/numpy/f2py/f2py2e.pyt   buildmodulesb  s8    

 =)c         C` so   xh | j    D]Z \ } } | |  k r2 g  |  | <n  t | t  rV |  | | |  | <q |  | j |  q Wd  S(   N(   t   itemst
   isinstancet   listR   (   t   d_outt   d_int   kt   v(    (    s0   /tmp/pip-build-X4mzal/numpy/numpy/f2py/f2py2e.pyRY     s    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]j } d | | k r xQ | | d j   D]8 }	 |	 | k r g  | |	 <n  | |	 j | | d  q Wq q Wx t t |   D] } | | d d k rd | | d k r| | d | k rt d	 | | d d
 j g  | | | d D] }
 d |
 ^ q f  qqqWd | k r| d d k rt d  t d t j j t j d  | d f  n  d Sxh t t |   D]T } | | d d k rd | k rQt d  n  t d t | | d    qqW| d t
 _ | t _ | d t
 _ t |  } x3 | j   D]% } t | | i | d 6| d 6 qW| S(   sw   Run f2py as if string.join(comline_list,' ') is used as a command line.
    In case of using -h flag, return None.
    t   srcs   fortranobject.hs   fortranobject.cRQ   RG   t   blocks   python moduleRP   s<   Skipping Makefile build for module "%s" which is used by %s
RR   s   "%s"R   R   i   sK   Stopping. Edit the signature file and then run f2py on the signature file: s   %s %s
i    NsJ   Tip: If your original code is Fortran source then you must use -m option.
s2   All blocks must be python module blocks but got %sR   R   t   csrct   h(   R   t   reset_global_f2py_varsR)   R0   t   dirnamet   abspathR   t   __file__R3   RD   R   RA   RO   RT   RU   RW   R   R$   t   basenameR!   t   argvR%   t	   TypeErrorR&   t   debugoptionsR   R   Rd   RY   (   t   comline_listt   f2pydirt   fobjhsrct   fobjcsrcR6   RA   RL   R^   R_   R`   Rb   Ra   t   mn(    (    s0   /tmp/pip-build-X4mzal/numpy/numpy/f2py/f2py2e.pyt   run_main  sP    
!	$(L(
	#c   
      C` s   g  g  } } t  j |  d | d  j } | r@ t |   } n d } xT g  | D] } | j   ^ qP D]3 }	 | |	  r | j |	 |  qf | j |	  qf W| | f S(   s,   
    Filter files by prefix and suffix.
    s   .*s   \Zi    (   t   ret   compilet   matchRU   t   stripR   (
   t   prefixt   suffixR6   t   remove_prefixt   filteredt   restR   t   indt   xt   file(    (    s0   /tmp/pip-build-X4mzal/numpy/numpy/f2py/f2py2e.pyt   filter_files  s    &c         C` s%   t  j j t  j j |  j   } | S(   N(   R)   R0   Rq   Rs   (   R   t   p(    (    s0   /tmp/pip-build-X4mzal/numpy/numpy/f2py/f2py2e.pyt
   get_prefix  s    !c    0      C` s`	  d d l  }  t j j d  } t j | =d } y t j j d  } Wn t k
 r] d } n X| d k	 r t j | d } t j | d =t j | =n d } |  j   } t j d  } g  t j d D] } | j	 |  r | ^ q } g  t j D] } | | k r | ^ q t _ | r7g  | D] } | d ^ q} n  t j d  } g  t j d D] } | j	 |  rT| ^ qT}	 g  t j D] } | |	 k r| ^ qt _ g  }
 d } xa t j d D]R } | d; k rd } n | d k rd } n  | s| d k r|
 j
 |  qqW|
 r6|
 d d k r6|
 j
 d  n  |	 j |
  g  t j D] } | |
 k rM| ^ qMt _ t j d  } g  t j d D] } | j	 |  r| ^ q} g  t j D] } | | k r| ^ qt _ t j d  } g  t j d D] } | j	 |  r| ^ q} g  t j D] } | | k r| ^ qt _ g  } x | D] } d } | t |   | k rMd d l m } | j   t | j j    } | t |  j   } } | | k r"i  } y | | } Wn> t k
 r| | j   k rt d | t |   qn X| } n  | j |  } d | | | <qMqMqMWx$ | D] } | j |  } | | =qPWt |  d k st t |    t j d  } g  t j d D] } | j	 |  r| ^ q} g  t j D] } | | k r| ^ qt _ d |	 k r| j
 d  n  d } t j d } xx d d g D]j } | t j k r9t j j |  } |	 j t j | | d ! t j | d =t j | =t j d } q9q9Wd t j k rt j j d  } t j | d } t j | d =t j | =t j d } nY d d l m } t d d |  \ } } | | } x$ | D] } | |  } | r:Pq:q:Wt 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 \ }% } x t t |%   D]p } |% | j d# d  }& t |&  d k rY|& j
 d  n  t |&  d k r~t |&  |% | <qt d$ |&  qWd d% l m  }' i  }( |( r|! j |( j! d& g    n  d d' l" m# }) m$ }* i	 | d( 6| d) 6|! d& 6|" d* 6|# d+ 6|% d, 6|$ d- 6|  d. 6|	 d/ 6}+ | rd d0 l% m& }, xG | D]< }- |' |-  } | snt' d1 t |-   n  |, |+ |  q?Wn  |* |+   }. t j d g | t _ t j j d2 d3 | d4 | d5 d6 g  | rt j j d7 g |  n  | r
	t j j d8 g |  n  |) d9 |. g  | r\	t( j) j* |  r\	d d l+ }/ t' d: |  |/ j, |  n  d S(<   s    
    Do it all in one call!
    i    Ns   -cs   --build-diri   s   [-][-]link[-]i   sF   [-][-]((no[-]|)(wrap[-]functions|lower)|debug[-]capi|quiet)|[-]includes   only:s   skip:R   is<   [-][-]((f(90)?compiler([-]exec|)|compiler)=|help[-]compiler)sN   [-][-]((f(77|90)(flags|exec)|opt|arch)=|(debug|noopt|noarch|help[-]fcompiler))s   --fcompiler=(   t	   fcompilers   Unknown vendor: "%s"i   s   [-][-](verbose)s   --quiett   untitleds   --include_pathss   --include-pathss   -m(   t   get_f2py_modulenameR   s   [.]pyf([.]src|)s   [.](o|a|so)s   -IR   s   -Ls   -ls   -Us   -Dt   =s   Invalid use of -D:(   t   get_infot   include_dirs(   t   setupt	   ExtensionRG   t   sourcest   library_dirst	   librariest   define_macrost   undef_macrost   extra_objectst   f2py_options(   RY   s9   No %s resources found in system (try `f2py --help-link`)
t   builds   --build-temps   --build-bases   --build-platlibR
   t	   config_fct	   build_extt   ext_moduless   Removing build directory %s
(   s   only:s   skip:(-   t   tempfileR!   Ru   RX   t
   ValueErrorR   t   mkdtempR~   R   R   R   R'   RU   t   numpy.distutilsR   t   load_all_fcompiler_classesRg   t   fcompiler_classRW   t   lowert   KeyErrort   valuesR   t   AssertionErrorR&   t!   numpy.distutils.command.build_srcR   R   RT   R(   t   tuplet   numpy.distutils.system_infoR   t   gett   numpy.distutils.coreR   R   t   numpy.distutils.misc_utilRY   R$   R)   R0   t   existst   shutilt   rmtree(0   R   R_   t   remove_build_dirt	   build_dirt   _reg1t   _mt   sysinfo_flagsR7   t   _reg2t
   f2py_flagst   f2py_flags2t   flt   at   _reg3t
   flib_flagst   _reg4t   fc_flagst   del_listRb   Rk   R   t   allowed_keyst   nvt   ovt   vmapt   _reg5t   setup_flagsR@   R   t   optnameR   t	   pyf_filesR   R   R   R   R   R   t
   name_valueR   t   num_infoR   R   t   ext_argsRY   t   nt   extR   (    (    s0   /tmp/pip-build-X4mzal/numpy/numpy/f2py/f2py2e.pyt   run_compile  s   

/+ 	/+		+	/+	/+
	
$/+

c          C` sp   d t  j d k r> t  j j d  d d l m }  |    d  Sd t  j d k r[ t   n t t  j d  d  S(   Ns   --help-linki   i    (   t   show_alls   -c(   R!   Ru   t   removeR   R   R   R}   (   R   (    (    s0   /tmp/pip-build-X4mzal/numpy/numpy/f2py/f2py2e.pyt   main  s    
(&   t   __doc__t
   __future__R    R   R   R!   R)   t   pprintR~   R   R   R   R   R   R   R   R	   t   versionR    t   stderrRK   R%   t   showR$   t   numpyt   numpy_versiont   ImportErrorR/   RD   RO   Rd   RY   R}   R   R   R   R   R   (    (    (    s0   /tmp/pip-build-X4mzal/numpy/numpy/f2py/f2py2e.pyt   <module>   s<   			
		%	"	
	1		