'Main program.'

def main(self):

    parser = optparse.OptionParser(usage='\n DCTB %prog    [options]    [file]    ...', version=('%%prog    %s' % __version__))
    parser.add_option('-o', '--output', metavar='FILE', type='string', dest='output', help='output    filename    [stdout]')
    parser.add_option('-n', '--node-thres', metavar='PERCENTAGE', type='float', dest='node_thres', default=0.5, help='eliminate    nodes    below    this    threshold    [default:    %default]')
    parser.add_option('-e', '--edge-thres', metavar='PERCENTAGE', type='float', dest='edge_thres', default=0.1, help='eliminate    edges    below    this    threshold    [default:    %default]')
    parser.add_option('-f', '--format', type='choice', choices=('prof', 'callgrind', 'oprofile', 'sysprof', 'pstats', 'shark', 'sleepy', 'aqtime', 'xperf'), dest='format', default='prof', help='profile    format:    prof,    callgrind,    oprofile,    sysprof,    shark,    sleepy,    aqtime,    pstats,    or    xperf    [default:    %default]')
    parser.add_option('-c', '--colormap', type='choice', choices=('color', 'pink', 'gray', 'bw'), dest='theme', default='color', help='color    map:    color,    pink,    gray,    or    bw    [default:    %default]')
    parser.add_option('-s', '--strip', action='store_true', dest='strip', default=False, help='strip    function    parameters,    template    parameters,    and    const    modifiers    from    demangled    C++    function    names')
    parser.add_option('-w', '--wrap', action='store_true', dest='wrap', default=False, help='wrap    function    names')
    parser.add_option('--skew', type='float', dest='theme_skew', default=1.0, help='skew    the    colorization    curve.        Values    <    1.0    give    more    variety    to    lower    percentages.        Value    >    1.0    give    less    variety    to    lower    percentages')
    (self.options, self.args) = parser.parse_args(sys.argv[1:])
    if ((len(self.args) > 1) and (self.options.format != 'pstats')):
        parser.error('incorrect    number    of    arguments')
    try:
        self.theme = self.themes[self.options.theme]
    except KeyError:
        parser.error(("invalid    colormap    '%s'" % self.options.theme))
    if self.options.theme_skew:
        self.theme.skew = self.options.theme_skew
    if (self.options.format == 'prof'):
        if (not self.args):
            fp = sys.stdin
        else:
            fp = open(self.args[0], 'rt')
        parser = GprofParser(fp)
    elif (self.options.format == 'callgrind'):
        if (not self.args):
            fp = sys.stdin
        else:
            fp = open(self.args[0], 'rt')
        parser = CallgrindParser(fp)
    elif (self.options.format == 'oprofile'):
        if (not self.args):
            fp = sys.stdin
        else:
            fp = open(self.args[0], 'rt')
        parser = OprofileParser(fp)
    elif (self.options.format == 'sysprof'):
        if (not self.args):
            fp = sys.stdin
        else:
            fp = open(self.args[0], 'rt')
        parser = SysprofParser(fp)
    elif (self.options.format == 'pstats'):
        if (not self.args):
            parser.error('at    least    a    file    must    be    specified    for    pstats    input')
        parser = PstatsParser(*self.args)
    elif (self.options.format == 'xperf'):
        if (not self.args):
            fp = sys.stdin
        else:
            fp = open(self.args[0], 'rt')
        parser = XPerfParser(fp)
    elif (self.options.format == 'shark'):
        if (not self.args):
            fp = sys.stdin
        else:
            fp = open(self.args[0], 'rt')
        parser = SharkParser(fp)
    elif (self.options.format == 'sleepy'):
        if (len(self.args) != 1):
            parser.error('exactly    one    file    must    be    specified    for    sleepy    input')
        parser = SleepyParser(self.args[0])
    elif (self.options.format == 'aqtime'):
        if (not self.args):
            fp = sys.stdin
        else:
            fp = open(self.args[0], 'rt')
        parser = AQtimeParser(fp)
    else:
        parser.error(("invalid    format    '%s'" % self.options.format))
    self.profile = parser.parse()
    if (self.options.output is None):
        self.output = sys.stdout
    else:
        self.output = open(self.options.output, 'wt')
    self.write_graph()
