U C^__@s6dZddlmZmZmZddlZddlZddlZddlZddl m Z ddl m Z ddl m Z ddl m Z dd l mZdd l mZdd l mZdd l mZejZejjZejZe jZzdd lmZWnek rd ZYnXdeefZddZddZddZddZ ddZ!d!ddZ"ddZ#ddZ$dd Z%dS)"a f2py2e - Fortran to Python C/API generator. 2nd Edition. See __usage__ below. Copyright 1999--2011 Pearu Peterson all rights reserved, Pearu Peterson 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 )divisionabsolute_importprint_functionN) crackfortran)rules)cb_rules)auxfuncs)cfuncs) f90mod_rules) __version__) capi_mapszN/Aa|Usage: 1) To construct extension module sources: f2py [] [[[only:]||[skip:]] \ ] \ [: ...] 2) To compile fortran files and build extension modules: f2py -c [, , ] 3) To generate signature files: f2py -h ...< same options as in (1) > Description: This program generates a Python C/API file (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 Write signatures of the fortran routines to file and exit. You can then edit and use it instead of . If ==stdout then the signatures are printed to stdout. Names of fortran routines for which Python C/API functions will be generated. Default is all that are found in . Paths to fortran/signature files that will be scanned for in order to determine their signatures. skip: Ignore fortran functions that follow until `:'. only: Use only fortran functions that follow until `:'. : Get back to mode. -m Name of the module; f2py generates a Python/C API file module.c or extension module . Default is 'untitled'. --[no-]lower Do [not] lower the cases in . By default, --lower is assumed with -h key, and --no-lower without -h key. --build-dir All f2py generated files are created in . Default is tempfile.mkdtemp(). --overwrite-signature Overwrite existing signature file. --[no-]latex-doc Create (or not) 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) 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 ::... Search include files from the given directories. --help-link [..] List system resources found by system_info.py. See also --link- switch below. [..] is optional list of resources names. E.g. try 'f2py --help-link lapack_opt'. --f2cmap Load Fortran-to-Python KIND specification from the given file. Default: .f2py_f2cmap in current directory. --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- Link extension module with 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 -D -U -I/path/to/include/ .o .so .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=, a message is sent to stderr whenever F2PY interface makes a copy of an array. Integer 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 Csggggf\}}}}d\ }}}}} } } } } d}d}d}d}d}d}g}d\}}|ddd}|D]z}|dkrnq^|d kr|d}q^|d krd}q^|d krd}q^|dd d kr||d dq^|dkrd}q^|dkrd} q^|dkrd}q^|dkrd}q^|dkr |d7}q^|dkrd}q^|dkr*d}q^|dkr:d}q^|dkrJd}q^|dkrZd}q^|dkrjd}q^|dkr~d|d<q^|dkrd} q^|dkrd} q^|dkrd} q^|dkrd|d<q^|d krd}q^|d!krd}q^|dd"d#krtttq^|d$krd}q^|dd d%kr`tjd&|d'dd(|d dtj|d'd<q^|dd)d*krtd+d} q^|dd)d,krd} q^|dd-krt d.t |tq^|rd}|}q^|rd}|}q^| rd} |}q^| rd} | | t jq^| r"d} ||d/<q^| r6d} ||d0<q^| rJd} ||d1<q^|dkrz"t|W5QRX||Wn8tk r}zt d2t||fW5d}~XYnXq^|dkr||q^|dkr^||q^|s|s|stttt j|s(|std3|t ||r<||d?<||d@<|d1d||fS)AN) rrrrrrrrrrr.)NN) buildpathcoutputf2py_wrapper_outputonly:skip::z--debug-z--lower --build-dirz --no-lower--quietz --verbosez --latex-docz--no-latex-docz --rest-docz --no-rest-docz--wrap-functionsz--no-wrap-functionsz --short-latexZ shortlatexz --coutputz--f2py-wrapper-output--f2cmapz--overwrite-signaturez h-overwritez-h-mz-vz--show-compilersz-include userincludes z #include --include_pathszHf2py option --include_paths is deprecated, use --include-paths instead. --include-paths-zUnknown option %s rr f2cmap_filez!IOError: %s. Skipping file "%s". zCreating build directory %szFSignature file "%s" exists!!! Use --overwrite-signature to overwrite. debugverbosedo-lowermodule signsfile onlyfuncs skipfuncs dolatexdoc dorestdoc wrapfuncsr include_paths)appendprint f2py_versionsysexitr ZoutneedsroutmesserrmessreprextendsplitospathsepopenIOErrorstr __usage__pathisdirmkdirjoinisfile setdefault)Z inputlinefilesr*r)r$ff2Zf3Zf5Zf6Zf7Zf8Zf9Zf10r%Zdolcr+r,r-rr.r( modulenameoptionslZdetailrK4/tmp/pip-install-6_kvzl1k/numpy/numpy/f2py/f2py2e.py scaninputlines&                                     rMc Csh|t_|dt_|dt_d|kr,|dt_d|kr>|dt_d|krP|dt_|dtjdd<|dt_ t|}d|krt d |dt |}|dd dd krt j |n$t|dd }||W5QRX|d dkr|D]}d|d|d <qn|D]}|d |d <q |ddkrL|D]}d|d|d<q2n|D]}|d|d<qP|S)Nr$r%r'r*r)r.r&r(zSaving signatures to file "%s" istdoutwrz %smodule.cnamerz%s-f2pywrappers.f)rrIrr$r%Z f77modulenamer*r)r.Z dolowercaser4Z crack2fortranr2rNwriter;)rErIpostlistZpyfrFmodrKrKrLcallcrackfortranHs<        rTc Csttdggi}}}tt|D]}d||dkrPt||q,d||kr||dD]*}||krg||<||||dql||||||dq,i}tt|D]}|||kr td||d dd|||Dfqg}d||krr||dD]D}||krZ||krZ||| |ntd |||fq,i|||<t |||t |||q|S) NzBuilding modules... __user__rPusez+ Skipping module "%s" which is used by %s. ,cSsg|] }d|qSz"%s"rK.0srKrKrL sz buildmodules..z: Module "%s" uses nonexisting "%s" which will be ignored. )r Z buildcfuncsr4rangelenrZbuildcallbackskeysr/rBindex dict_appendrZ buildmodule)lstmodulesZmnamesisusedbyiuretZumrKrKrL buildmodulesls>    rhcCsP|D]B\}}||kr g||<t|tr<|||||<q|||qdSN)items isinstancelistr/)Zd_outZd_inkvrKrKrLras  rac Csttjtjtj}tj|dd}tj|dd}t |\}}|t _ t |dt||}i}tt|D]L}d||krx||dD]*} | |krg|| <|| ||dqqxtt|D]h}||ddkrd ||dkr||d|krtd ||dd d d |||dDfqd|kr|ddkr~tdtdtjtjd|dfdStt|D]B}||ddkrd|krtdtdt||dq|dt _|t_ |dt _t|} | D]} t| | ||dq| S)aJ Equivalent to running:: f2py where ``=string.join(,' ')``, 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: srczfortranobject.hzfortranobject.cr#rVrPblockz python modulerUz.r(r%rzKStopping. Edit the signature file and then run f2py on the signature file: z%s %s rNzJTip: If your original code is Fortran source then you must use -m option. z2All blocks must be python module blocks but got %sr$r-)Zcsrch)rZreset_global_f2py_varsr9r?dirnameabspathr __file__rBrMr rIr Zload_f2cmap_filerTr]r^r_r/r4basenamer2argvr5 TypeErrorr6Z debugoptionsr r-rhra) Z comline_listZf2pydirZfobjhsrcZfobjcsrcrErIrRrdrerfrgmnrKrKrLrun_mains^            ryc Csvgg}}t|d|dj}|r0t|}nd}dd|DD]*}||rb|||dqB||qB||fS)z, Filter files by prefix and suffix. z.*z\ZrcSsg|] }|qSrK)strip)rZxrKrKrLr\sz filter_files..N)recompilematchr^r/) prefixsuffixrE remove_prefixfilteredrestr~indfilerKrKrL filter_filess   rcCstjtj|j}|Sri)r9r?rrrt)r'prKrKrL get_prefixsrc$ sddl}tjd}tj|=d}ztjd}Wntk rHd}YnX|dk rvtj|d}tj|d=tj|=n d}|}tdfddtjddD fd dtjDt_ rd d D td fd dtjddDfd dtjDt_gd}tjddD]>}|dkr6d}n|dkrDd}|sT|dkr"|q"rddkrd fddtjDt_tdfddtjddDfddtjDt_tdfddtjddDfddtjDt_g}D]}d}|dt ||kr ddl m } | t| j} |t |d} } | | kri} z | | } Wn<tk r| | krtd|t |dYnX| } |}d| |<q q |D]}|}|=qt dks(tttdfddtjddD fddtjDt_dkrx dd }tjdd}d!D]X}|tjkrtj|} tj||dtj|d=tj|=tjdd}qd"tjkr2tjd"}tj|d}tj|d=tj|=tjdd}nDdd#lm}td$d%|\}}||}|D]}||}|rZqvqZtd$d&|\}}td'd$|dd(\}}td)d$|dd(\}}td*d$|dd(\}}td+d$|dd(\}}td,d$|dd(\}}tt |D]T}||d-d}t |dkr"|dt |dkr>t|||<n td.|qdd/lm}i}|rt| |d0gdd1l m!}m"}||||||||d2 } rdd3l#m$}  D]0}!||!}|st%d4t|!| |f|q|f|}"tjdg t_tj d5d6|d7|d8d9gr2tj d:grJtj d;g||"gd<|rt&j'(|rddl)}#t%d=||#*|dS)>z Do it all in one call! rN-crrz [-][-]link[-]csg|]}|r|qSrKr~rZ_m)_reg1rKrLr\ s zrun_compile..csg|]}|kr|qSrKrKr) sysinfo_flagsrKrLr\ scSsg|]}|ddqS)NrK)rZrFrKrKrLr\ szF[-][-]((no[-]|)(wrap[-]functions|lower)|debug[-]capi|quiet)|[-]includecsg|]}|r|qSrKrr)_reg2rKrLr\s csg|]}|kr|qSrKrKr) f2py_flagsrKrLr\s)rrrrcsg|]}|kr|qSrKrKr) f2py_flags2rKrLr\sz<[-][-]((f(90)?compiler([-]exec|)|compiler)=|help[-]compiler)csg|]}|r|qSrKrr)_reg3rKrLr\"s csg|]}|kr|qSrKrKr) flib_flagsrKrLr\#szN[-][-]((f(77|90)(flags|exec)|opt|arch)=|(debug|noopt|noarch|help[-]fcompiler))csg|]}|r|qSrKrr)_reg4rKrLr\&s csg|]}|kr|qSrKrKr)fc_flagsrKrLr\'sz --fcompiler=) fcompilerzUnknown vendor: "%s"rz[-][-](verbose)csg|]}|r|qSrKrr)_reg5rKrLr\Cs csg|]}|kr|qSrKrKr) setup_flagsrKrLr\DsrZuntitled)r r!rr)get_f2py_modulenamerz[.]pyf([.]src|)z [.](o|a|so)z-I)rz-Lz-lz-Uz-D=zInvalid use of -D:)get_info include_dirs)setup Extension) rPsourcesr library_dirs libraries define_macros undef_macros extra_objectsZ f2py_options)raz9No %s resources found in system (try `f2py --help-link`) buildz --build-tempz --build-basez--build-platlibrZ config_fc build_ext) ext_moduleszRemoving build directory %s )+tempfiler2rvr` ValueErrormkdtempr|r}r/r7r^Znumpy.distutilsrZload_all_fcompiler_classesrlZfcompiler_classr_lowerKeyErrorvaluesr0AssertionErrorr6Z!numpy.distutils.command.build_srcrrr]r8tuplenumpy.distutils.system_inforgetZnumpy.distutils.corerrZnumpy.distutils.misc_utilrar4r9r?existsshutilrmtree)$rreZremove_build_dir build_dirflaZdel_listr[rnrZ allowed_keysnvovZvmaprHroptnamerZ pyf_filesrFrrrrrr name_valuerZnum_inforrZext_argsranextrrK) rrrrrrrrrrrrL run_compiles,                                rcCsdtjddkr4tjdddlm}|dSdtjddkr^tjdtdnldtjddkr~tjdnLdtjddkrtjd tjdn d tjddkrtjd nd tjddkrt nt tjdddS) Nz --help-linkrrshow_allz --g3-numpyz*G3 f2py support is not implemented, yet.\nz --2e-numericz --2e-numarrayz -DNUMARRAYz --2e-numpyr) r2rvremoverrstderrrQr3r/rryrrKrKrLmains$     r)N)&__doc__ __future__rrrr2r9pprintr|rrrrr r r r r versionr1rrQr5showr4ZnumpyZ numpy_version ImportErrorr>rMrTrhraryrrrrrKrKrKrLsL          $" C ,