How to use the f90wrap.fortran.Subroutine 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
def visit_Function(self, node):

        # insert ret_val after last non-optional argument
        arguments = node.arguments[:]
        i = 0
        for i, arg in enumerate(arguments):
            if 'optional' in arg.attributes:
                break
        arguments.insert(i, node.ret_val)
        arguments[i].name = 'ret_' + arguments[i].name
        arguments[i].attributes.append('intent(out)')

        new_node = ft.Subroutine(node.name,
                                 node.filename,
                                 node.doc,
                                 node.lineno,
                                 arguments,
                                 node.uses,
                                 node.attributes,
                                 mod_name=node.mod_name)
        if hasattr(node, 'call_name'):
            new_node.call_name = node.call_name
        if hasattr(node, 'type'):
            new_node.type = node.type
        new_node.orig_name = node.orig_name
        new_node.orig_node = node  # keep a reference to the original node
        return new_node
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)],
                                     node.uses,
                                     ['constructor', 'skip_call'],
                                     mod_name=node.mod_name,
                                     type_name=node.name)
            new_node.method_name = '__init__'
            node.procedures.append(new_node)
    return tree
github jameskermode / f90wrap / f90wrap / latex.py View on Github external
for a in sub.doc:
                self.print_line(a)
            self.print_line('\n\n')

        got_args = (is_sub and sum([len(x.arguments) for x in node.procedures]) != 0) or not is_sub

        func_args = []
        if got_args:
            self.print_line(r'\begin{description}')


            arg_dict = {}
            i = 0  # counter for appearance order of args
            for sub in node.procedures:
                for a in sub.arguments:
                    if isinstance(a, ft.Subroutine) or isinstance(a, Function):
                        func_args.append(a)
                        continue
                    i = i + 1
                    if arg_dict.has_key(a.name):
                        if a.type.lower() + str(sorted(map(string.lower, a.attributes))) in \
                           [x[0].type.lower() + str(sorted(map(string.lower, x[0].attributes))) for x in arg_dict[a.name]]:
                            pass  # already got this name/type/attribute combo
                        else:
                            arg_dict[a.name].append((a, i))

                    else:
                        arg_dict[a.name] = [(a, i)]

            # Combine multiple types with the same name
            for name in arg_dict:
                types = [x[0].type for x in arg_dict[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'],
                                                  lineno=node.lineno,
                                                  attributes=['intent(inout)'],
                                                  type='type(%s)' % node.name)],
                                     node.uses,
                                     ['destructor', 'skip_call'],
                                     mod_name=node.mod_name,
                                     type_name=node.name)
            new_node.method_name = '__del__'
            node.procedures.append(new_node)
    return tree