Create a ctypes type that corresponds to a compound type in memory.
558115
def make_compound_ctype(self, varname):
        

        # look up the type name
        compoundname = self.get_var_type(varname)
        nfields = self.inq_compound(compoundname)
        # for all the fields look up the type, rank and shape
        fields = []
        for i in range(nfields):
            (fieldname, fieldtype,
             fieldrank, fieldshape) = self.inq_compound_field(compoundname, i)
            assert fieldrank <= 1
            fieldctype = CTYPESMAP[fieldtype]
            if fieldrank == 1:
                fieldctype = fieldctype * fieldshape[0]
            fields.append((fieldname, fieldctype))
        # create a new structure

        class COMPOUND(Structure):
            _fields_ = fields

        # if we have a rank 1 array, create an array
        rank = self.get_var_rank(varname)
        assert rank <= 1, "we can't handle >=2 dimensional compounds yet"
        if rank == 1:
            shape = self.get_var_shape(varname)
            valtype = POINTER(ARRAY(COMPOUND, shape[0]))
        else:
            valtype = POINTER(COMPOUND)
        # return the custom type
        return valtype
254276
def _ctypes_assign(parameter):
    
    #If the array is set to only have intent(out), we don't want to allocate or assign
    #a value to it; otherwise we do.
    if (parameter.direction != "(out)" and ("allocate" in parameter.modifiers
                                            or "pointer" in parameter.modifiers
                                            or "target" in parameter.modifiers)):
        if "in" in parameter.direction:
            splice = _ctypes_splice(parameter)
            result = []
            result.append("    allocate({}({}))".format(parameter.name, splice))
            result.append("    {0} = {0}_c".format(parameter.name))
            return ('\n'.join(result), True)
    elif parameter.dtype == "logical" and "in" in parameter.direction:
        return ("    {0} = {0}_c".format(parameter.name), False)
707012
def pytype_to_deps(t):
    
    res = set()
    for hpp_dep in pytype_to_deps_hpp(t):
        res.add(os.path.join('pythonic', 'types', hpp_dep))
        res.add(os.path.join('pythonic', 'include', 'types', hpp_dep))
    return res
835468
def _resolve_dtype(data_type):
    """"""
    if isinstance(data_type, _FIXED_ATOMIC):
        out = _get_atomic_dtype(data_type)
    elif isinstance(data_type, _FLEXIBLE_ATOMIC):
        out = (_get_atomic_dtype(data_type), data_type.length)
    elif isinstance(data_type, Array):
        shape = data_type.shape
        if isinstance(shape, _SEQUENCE_TYPES) and len(shape) == 1:
            # Workaround the exception `ValueError: invalid itemsize in
            # generic type tuple` when an `Array` of shape 0 or (0,) is nested
            # within another `Array`.
            shape = shape[0]

        out = (_resolve_dtype(data_type.element_type), shape)
    elif isinstance(data_type, Structure):
        out = [(field.name, _resolve_dtype(field.type))
               for field in data_type.fields]

    return out
182974
def _set_types(self):
        """"""
        # If we given something that is not an int or a float we raise
        # a RuntimeError as we do not want to have to guess if the given
        # input should be interpreted as an int or a float, for example the
        # interpretation of the string "1" vs the interpretation of the string
        # "1.0".
        for c in (self.x, self.y):
            if not ( isinstance(c, int) or isinstance(c, float) ):
                raise(RuntimeError('x, y coords should be int or float'))

        if isinstance(self.x, int) and isinstance(self.y, int):
            self._dtype = "int"
        else:
            # At least one value is a float so promote both to float.
            self.x = float(self.x)
            self.y = float(self.y)
            self._dtype = "float"
336482
def ctype_for_encoding(self, encoding):
        """"""
        if encoding in self.typecodes:
            return self.typecodes[encoding]
        elif encoding[0:1] == b'^' and encoding[1:] in self.typecodes:
            return POINTER(self.typecodes[encoding[1:]])
        elif encoding[0:1] == b'^' and encoding[1:] in [CGImageEncoding,
                                                        NSZoneEncoding]:
            return c_void_p
        elif encoding[0:1] == b'r' and encoding[1:] in self.typecodes:
            return self.typecodes[encoding[1:]]
        elif encoding[0:2] == b'r^' and encoding[2:] in self.typecodes:
            return POINTER(self.typecodes[encoding[2:]])
        else:
            raise Exception('unknown encoding for %s: %s'
                            % (self.name, encoding))
949040
def bind_type(python_value):
    """"""
    binding_table = {'bool': Bool, 'int': Int, 'float': Float}

    if python_value is None:
        return NoneType()

    python_type = type(python_value)

    gibica_type = binding_table.get(python_type.__name__)

    if gibica_type is None:
        raise TypeError('Impossible to recognize underlying type.')
    return gibica_type(python_value)
779464
def _ctypes_out(parameter):
    
    if (parameter.dimension is not None and ":" in parameter.dimension
        and "out" in parameter.direction and ("allocatable" in parameter.modifiers or
                                              "pointer" in parameter.modifiers)):
        if parameter.direction == "(inout)":
            return ("type(C_PTR), intent(inout) :: {}_o".format(parameter.name), True)
        else: #self.direction == "(out)" since that is the only other option.
            return ("type(C_PTR), intent(inout) :: {}_c".format(parameter.name), True)
293077
def _get_ctypes_name(self, index=None):
        
        if index is None:
            if ("allocatable" not in self.modifiers and "pointer" not in self.modifiers
                and self.dtype != "logical"):
                #The fortan logical has type 4 by default, whereas c_bool only has 1
                return self.name
            else:
                return "{}_c".format(self.name)
        else:
            return "{0}_{1:d}_c".format(self.name, index)
1211874
def instantiate_from_config(cfg):
    """"""
    for h in cfg:
        if h.get("type") in data_types:
            raise KeyError("Data type '%s' already exists" % h)
        data_types[h.get("type")] = DataType(h)
70344
def type(self, name: str):
        """'"""
        for f in self.body:
            if (hasattr(f, '_ctype')
                    and f._ctype._storage == Storages.TYPEDEF
                    and f._name == name):
                return f
213588
def dtype_contract(input_dtype=None, output_dtype=None):
    """"""
    def wrap(function):
        @wraps(function)
        def wrapped_function(*args, **kwargs):
            if input_dtype is not None:
                check_dtype(args[0], input_dtype)
            array = function(*args, **kwargs)
            if output_dtype is not None:
                check_dtype(array, output_dtype)
            return array
        return wrapped_function
    return wrap
1221350
def add_defaults(self, ctype: ContentType = None) -> "InstanceNode":
        
        val = self.value
        if not (isinstance(val, StructuredValue) and self.is_internal()):
            return self
        res = self
        if isinstance(val, ObjectValue):
            if val:
                for mn in self._member_names():
                    m = res._member(mn) if res is self else res.sibling(mn)
                    res = m.add_defaults(ctype)
                res = res.up()
            return self.schema_node._add_defaults(res, ctype)
        if not val:
            return res
        en = res[0]
        while True:
            res = en.add_defaults(ctype)
            try:
                en = res.next()
            except NonexistentInstance:
                break
        return res.up()
976780
def declalltypes(self):
        """"""
        for f in self.body:
            if (hasattr(f, '_ctype')
                    and f._ctype._storage == Storages.TYPEDEF):
                yield f
1288104
def _ctypes_saved(parameter):
    
    if ("out" in parameter.direction and parameter.dimension is not None and
        ":" in parameter.dimension and ("allocatable" in parameter.modifiers or
                                        "pointer" in parameter.modifiers)):
        stype = _ctypes_dtype(parameter)
        name = "{}_t({})".format(parameter.name, parameter.dimension)
        return ("{}, allocatable, target, save :: {}".format(stype, name), True)
411295
def IOC_TYPECHECK(t):
    
    result = ctypes.sizeof(t)
    assert result <= _IOC_SIZEMASK, result
    return result
183144
void writeCompoundAttribute(Attribute.Compound c) {
        databuf.appendChar(pool.put(typeSig(c.type)));
        databuf.appendChar(c.values.length());
        for (Pair<Symbol.MethodSymbol,Attribute> p : c.values) {
            databuf.appendChar(pool.put(p.fst.name));
            p.snd.accept(awriter);
        }
    }