How to use the f90wrap.fortran function in f90wrap

To help you get started, we’ve selected a few f90wrap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jameskermode / f90wrap / f90wrap / transform.py View on Github external
# remove optional allocatable/pointer arguments
        if 'allocatable' in node.attributes or 'pointer' in node.attributes:
            warnings.warn('removing optional argument %s due to allocatable/pointer attributes' %
                          node.name)
            return None

        dims = [attrib for attrib in node.attributes if attrib.startswith('dimension')]

        # remove optional complex scalar arguments
        if node.type.startswith('complex') and len(dims) == 0:
            warnings.warn('removing optional argument %s as it is a complex scalar' % node.name)
            return None

        # remove optional derived types not in self.types
        if node.type.startswith('type') and ft.split_type(node.type) not in self.types:
            warnings.warn('removing optional argument %s due to unsupported derived type %s' %
                          (node.name, node.type))
            return None

        # remove optional arrays of derived types
        # EXPERIMENTAL !
        if node.type.startswith('type') and len(dims) != 0:
            if len(dims) > 1:
                raise ValueError('more than one dimension attribute found for arg %s' % node.name)
            dimensions_list = ArrayDimensionConverter.split_dimensions(dims[0])
            if len(dimensions_list) > 1 or ':' in dimensions_list:
                warnings.warn(
                    'test removing optional argument %s as only one dimensional fixed-length arrays are currently supported for derived type %s array' %
                    (node.name, node.type))
                return None
github jameskermode / f90wrap / f90wrap / f90wrapgen.py View on Github external
self.write('type(%s_ptr_type) :: this_ptr' % t.name)

        # Return/set by value
        attributes = [attr for attr in el.attributes if attr not in
                      ['pointer', 'allocatable', 'public', 'parameter', 'save']]

        if el.type.startswith('type'):
            # For derived types elements, treat as opaque reference
            self.write('integer, intent(%s) :: %s(%d)' % (inout, localvar, sizeof_fortran_t))

            self.write('type(%s_ptr_type) :: %s_ptr' % (ft.strip_type(el.type), el.orig_name))
            self.write()
            if isinstance(t, ft.Type):
                self.write('this_ptr = transfer(this, this_ptr)')
            if getset == "get":
                if isinstance(t, ft.Type):
                    self.write('%s_ptr%%p => this_ptr%%p%%%s' % (el.orig_name, el.orig_name))
                else:
                    self.write('%s_ptr%%p => %s_%s' % (el.orig_name, t.name, el.orig_name))
                self.write('%s = transfer(%s_ptr,%s)' % (localvar, el.orig_name, localvar))
            else:
                self.write('%s_ptr = transfer(%s,%s_ptr)' % (el.orig_name,
                                                             localvar,
                                                             el.orig_name))
                if isinstance(t, ft.Type):
                    self.write('this_ptr%%p%%%s = %s_ptr%%p' % (el.orig_name, el.orig_name))
                else:
                    self.write('%s_%s = %s_ptr%%p' % (t.name, el.orig_name, el.orig_name))
        else:
            if attributes != []:
                self.write('%s, %s, intent(%s) :: %s' % (el.type,
                                                         ','.join(attributes),
github jameskermode / f90wrap / f90wrap / transform.py View on Github external
#  along with f90wrap. If not, see .
# 
#  If you would like to license the source code under different terms,
#  please contact James Kermode, james.kermode@gmail.com

from __future__ import print_function

import copy
import logging
import re
import warnings

from f90wrap import fortran as ft


class AccessUpdater(ft.FortranTransformer):
    """Visit module contents and update public_symbols and
       private_symbols lists to be consistent with (i) default module
       access; (ii) public and private statements at module level;
       (iii) public and private statement in types; (iv) public
       and private attributes of individual elements."""

    def __init__(self):
        self.mod = None
        self.type = None

    def update_access(self, node, mod, default_access, in_type=False):
        if default_access == 'public':
            if ('private' not in getattr(node, 'attributes', []) and
                        node.name not in mod.private_symbols):

                # symbol should be marked as public if it's not already
github jameskermode / f90wrap / f90wrap / transform.py View on Github external
def add_missing_constructors(tree):
    for node in ft.walk(tree):
        if not isinstance(node, ft.Type):
            continue
        for child in ft.iter_child_nodes(node):
            if isinstance(child, ft.Procedure):
                if 'constructor' in child.attributes:
                    logging.info('found constructor %s' % child.name)
                    break
        else:

            logging.info('adding missing constructor for %s' % node.name)
            new_node = ft.Subroutine('%s_initialise' % node.name,
                                     node.filename,
                                     ['Automatically generated constructor for %s' % node.name],
                                     node.lineno,
                                     [ft.Argument(name='this',  # self.prefix + 'this' would probably be safer
                                                  filename=node.filename,
                                                  doc=['Object to be constructed'],
                                                  lineno=node.lineno,
                                                  attributes=['intent(out)'],
                                                  type='type(%s)' % node.name)],
github jameskermode / f90wrap / f90wrap / transform.py View on Github external
def add_missing_destructors(tree):
    for node in ft.walk(tree):
        if not isinstance(node, ft.Type):
            continue
        for child in ft.iter_child_nodes(node):
            if isinstance(child, ft.Procedure):
                if 'destructor' in child.attributes:
                    logging.info('found destructor %s' % child.name)
                    break
        else:

            logging.info('adding missing destructor for %s' % node.name)
            new_node = ft.Subroutine('%s_finalise' % node.name,
                                     node.filename,
                                     ['Automatically generated destructor for %s' % node.name],
                                     node.lineno,
                                     [ft.Argument(name='this',  # self.prefix + 'this' would probably be safer
                                                  filename=node.filename,
                                                  doc=['Object to be destructed'],