def METHOD_NAME(self, ctx, modules, fd):
    """Main control function.
    """
    for epos, etag, eargs in ctx.errors:
        if error.is_error(error.err_level(etag)):
            raise error.EmitError("JTOX plugin needs a valid module")
    tree = {}
    mods = {}
    annots = {}
    for m,p in unique_prefixes(ctx).items():
        mods[m.i_modulename] = [p, m.search_one("namespace").arg]
    for module in modules:
        for ann in module.search(("ietf-yang-metadata", "annotation")):
            typ = ann.search_one("type")
            annots[module.arg + ":" + ann.arg] = (
                "string" if typ is None else self.base_type(ann, typ))
    for module in modules:
        self.process_children(module, tree, None)
    json.dump({"modules": mods, "tree": tree, "annotations": annots}, fd)