![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /proc/self/root/usr/local/lib/python3.6/dist-packages/sympy/codegen/ |
Upload File : |
from itertools import chain from sympy.codegen.fnodes import Module from sympy.core.symbol import Dummy from sympy.printing.fortran import FCodePrinter """ This module collects utilities for rendering Fortran code. """ def render_as_module(definitions, name, declarations=(), printer_settings=None): """ Creates a ``Module`` instance and renders it as a string. This generates Fortran source code for a module with the correct ``use`` statements. Parameters ========== definitions : iterable Passed to :class:`sympy.codegen.fnodes.Module`. name : str Passed to :class:`sympy.codegen.fnodes.Module`. declarations : iterable Passed to :class:`sympy.codegen.fnodes.Module`. It will be extended with use statements, 'implicit none' and public list generated from ``definitions``. printer_settings : dict Passed to ``FCodePrinter`` (default: ``{'standard': 2003, 'source_format': 'free'}``). """ printer_settings = printer_settings or {'standard': 2003, 'source_format': 'free'} printer = FCodePrinter(printer_settings) dummy = Dummy() if isinstance(definitions, Module): raise ValueError("This function expects to construct a module on its own.") mod = Module(name, chain(declarations, [dummy]), definitions) fstr = printer.doprint(mod) module_use_str = ' %s\n' % ' \n'.join(['use %s, only: %s' % (k, ', '.join(v)) for k, v in printer.module_uses.items()]) module_use_str += ' implicit none\n' module_use_str += ' private\n' module_use_str += ' public %s\n' % ', '.join([str(node.name) for node in definitions if getattr(node, 'name', None)]) return fstr.replace(printer.doprint(dummy), module_use_str)