def main(argv=None): """Main function: deal with command line arguments and start calculation as reqd.""" if not argv: argv = sys.argv #Parse command line options parser = optparse.OptionParser() parser.add_option("-f", "--filename", action="store", dest="mrgresults", default=run_config.mrgresults, type="string", metavar="FILE", help="merged first order and source results file, default=%default") loggroup = optparse.OptionGroup(parser, "Log Options", "These options affect the verbosity of the log files generated.") loggroup.add_option("-q", "--quiet", action="store_const", const=logging.FATAL, dest="loglevel", help="only print fatal error messages") loggroup.add_option("-v", "--verbose", action="store_const", const=logging.INFO, dest="loglevel", help="print informative messages") loggroup.add_option("--debug", action="store_const", const=logging.DEBUG, dest="loglevel", help="log lots of debugging information", default=run_config.LOGLEVEL) loggroup.add_option("--console", action="store_true", dest="console", default=False, help="if selected matches console log level " "to selected file log level, otherwise only warnings are shown.") parser.add_option_group(loggroup) (options, args) = parser.parse_args(args=argv[1:]) #Start the logging module if options.console: consolelevel = options.loglevel else: consolelevel = logging.WARN logfile = os.path.join(run_config.LOGDIR, "so.log") helpers.startlogging(log, logfile, options.loglevel, consolelevel) if (not _debug) and (options.loglevel == logging.DEBUG): log.warn("Debugging information will not be stored due to setting in run_config.") if not os.path.isfile(options.mrgresults): raise IOError("Merged results file %s does not exist!" % options.foresults) try: log.info("-----------Second order run requested------------------") runsomodel(mrgfile=options.mrgresults, soargs=run_config.soargs) except Exception: log.exception("Error getting second order results!") return 1 return 0
def main(argv=None): """Process command line options, create qsub scripts and start execution.""" if not argv: argv = sys.argv #Default dictionary for templates template_dict = base_qsub_dict.copy() #Parse command line options parser = OptionParser() loggroup = OptionGroup(parser, "Log Options", "These options affect the verbosity of the log files generated.") loggroup.add_option("-q", "--quiet", action="store_const", const=logging.FATAL, dest="loglevel", help="only print fatal error messages") loggroup.add_option("-v", "--verbose", action="store_const", const=logging.INFO, dest="loglevel", help="print informative messages") loggroup.add_option("--debug", action="store_const", const=logging.DEBUG, dest="loglevel", help="print lots of debugging information", default=run_config.LOGLEVEL) parser.add_option_group(loggroup) cfggroup = OptionGroup(parser, "Simulation configuration Options", "These options affect the options used by the simulation.") cfggroup.add_option("--name", action="store", dest="runname", type="string", help="name of run") cfggroup.add_option("--timelimit", action="store", dest="timelimit", type="string", help="time for simulation in format hh:mm:ss") cfggroup.add_option("--taskmin", action="store", dest="taskmin", type="string", metavar="NUM", help="minimum task number, default: 1") cfggroup.add_option("-t", "--taskmax", action="store", dest="taskmax", type="string", metavar="NUM", help="maximum task number, default: 20") parser.add_option_group(cfggroup) filegrp = OptionGroup(parser, "File options", "These options override the default choice of template and script files.") filegrp.add_option("--template", action="store", dest="templatefile", type="string", help="qsub template file") filegrp.add_option("--foscript", action="store", dest="foscriptname", type="string", help="first order script name") filegrp.add_option("--srcscript", action="store", dest="srcscriptname", type="string", help="source integration script name") parser.add_option_group(filegrp) (options, args) = parser.parse_args(args=argv[1:]) if args: raise ValueError("No extra command line arguments are allowed!") #Update dictionary with options for key in template_dict.keys(): if getattr(options, key, None): template_dict[key] = getattr(options, key, None) #Find templatefile if options.templatefile and os.path.isfile(options.templatefile): goodtemplatefile = options.templatefile elif os.path.isfile(run_config.templatefile): goodtemplatefile = run_config.templatefile elif os.path.isfile(os.path.join([os.path.abspath(run_config.__file__), run_config.templatefilename])): goodtemplatefile = os.path.join([os.path.abspath(run_config.__file__), run_config.templatefilename]) elif os.path.isfile(os.path.join([os.getcwd(), run_config.templatefilename])): goodtemplatefile = os.path.join([os.getcwd(), run_config.templatefilename]) else: #Can't find templatefile raise IOError("Can't find the qsub template file named %s." % run_config.templatefilename) template_dict["templatefile"] = goodtemplatefile helpers.startlogging(log, run_config.logfile, options.loglevel) #Log options chosen log.debug("Generic template dictionary is %s", template_dict) #First order calculation #First order script creation fo_dict = first_order_dict(template_dict) write_out_template(fo_dict["templatefile"],fo_dict["foscriptname"], fo_dict) #Launch first order script and get job id fo_jid = launch_qsub(fo_dict["foscriptname"]) #Source term calculation src_dict = source_dict(template_dict, fo_jid=fo_jid) write_out_template(src_dict["templatefile"],src_dict["srcscriptname"], src_dict) #Launch full script and get job id src_jid = launch_qsub(src_dict["srcscriptname"]) #Merger of source terms and combining with firstorder results mrg_dict = merge_dict(template_dict, src_jid=src_jid) write_out_template(mrg_dict["templatefile"], mrg_dict["mrgscriptname"], mrg_dict) #Launch full script and get job id mrg_jid = launch_qsub(mrg_dict["mrgscriptname"]) #Second order calculation so_dict = second_order_dict(template_dict, mrg_jid=mrg_jid) write_out_template(so_dict["templatefile"], so_dict["soscriptname"], so_dict) #Launch full script and get job id so_jid = launch_qsub(so_dict["soscriptname"]) #Combination of final results cmb_dict = combine_dict(template_dict, so_jid=so_jid) write_out_template(cmb_dict["templatefile"], cmb_dict["cmbscriptname"], cmb_dict) #Launch full script and get job id cmb_jid = launch_qsub(cmb_dict["cmbscriptname"]) #Write out individual source term qsub file src_indiv_dict = source_indiv_dict(template_dict) write_out_template(src_indiv_dict["templatefile"],src_indiv_dict["src_indivscriptname"], src_indiv_dict) return 0
def main(argv=None): """Process command line options, create qsub scripts and start execution.""" if not argv: argv = sys.argv #Default dictionary for templates template_dict = base_qsub_dict.copy() #Parse command line options parser = OptionParser() loggroup = OptionGroup( parser, "Log Options", "These options affect the verbosity of the log files generated.") loggroup.add_option("-q", "--quiet", action="store_const", const=logging.FATAL, dest="loglevel", help="only print fatal error messages") loggroup.add_option("-v", "--verbose", action="store_const", const=logging.INFO, dest="loglevel", help="print informative messages") loggroup.add_option("--debug", action="store_const", const=logging.DEBUG, dest="loglevel", help="print lots of debugging information", default=run_config.LOGLEVEL) parser.add_option_group(loggroup) cfggroup = OptionGroup( parser, "Simulation configuration Options", "These options affect the options used by the simulation.") cfggroup.add_option("--name", action="store", dest="runname", type="string", help="name of run") cfggroup.add_option("--timelimit", action="store", dest="timelimit", type="string", help="time for simulation in format hh:mm:ss") cfggroup.add_option("--taskmin", action="store", dest="taskmin", type="string", metavar="NUM", help="minimum task number, default: 1") cfggroup.add_option("-t", "--taskmax", action="store", dest="taskmax", type="string", metavar="NUM", help="maximum task number, default: 20") parser.add_option_group(cfggroup) filegrp = OptionGroup( parser, "File options", "These options override the default choice of template and script files." ) filegrp.add_option("--template", action="store", dest="templatefile", type="string", help="qsub template file") filegrp.add_option("--foscript", action="store", dest="foscriptname", type="string", help="first order script name") filegrp.add_option("--srcscript", action="store", dest="srcscriptname", type="string", help="source integration script name") parser.add_option_group(filegrp) (options, args) = parser.parse_args(args=argv[1:]) if args: raise ValueError("No extra command line arguments are allowed!") #Update dictionary with options for key in template_dict.keys(): if getattr(options, key, None): template_dict[key] = getattr(options, key, None) #Find templatefile if options.templatefile and os.path.isfile(options.templatefile): goodtemplatefile = options.templatefile elif os.path.isfile(run_config.templatefile): goodtemplatefile = run_config.templatefile elif os.path.isfile( os.path.join([ os.path.abspath(run_config.__file__), run_config.templatefilename ])): goodtemplatefile = os.path.join([ os.path.abspath(run_config.__file__), run_config.templatefilename ]) elif os.path.isfile( os.path.join([os.getcwd(), run_config.templatefilename])): goodtemplatefile = os.path.join( [os.getcwd(), run_config.templatefilename]) else: #Can't find templatefile raise IOError("Can't find the qsub template file named %s." % run_config.templatefilename) template_dict["templatefile"] = goodtemplatefile helpers.startlogging(log, run_config.logfile, options.loglevel) #Log options chosen log.debug("Generic template dictionary is %s", template_dict) #First order calculation #First order script creation fo_dict = first_order_dict(template_dict) write_out_template(fo_dict["templatefile"], fo_dict["foscriptname"], fo_dict) #Launch first order script and get job id fo_jid = launch_qsub(fo_dict["foscriptname"]) #Source term calculation src_dict = source_dict(template_dict, fo_jid=fo_jid) write_out_template(src_dict["templatefile"], src_dict["srcscriptname"], src_dict) #Launch full script and get job id src_jid = launch_qsub(src_dict["srcscriptname"]) #Merger of source terms and combining with firstorder results mrg_dict = merge_dict(template_dict, src_jid=src_jid) write_out_template(mrg_dict["templatefile"], mrg_dict["mrgscriptname"], mrg_dict) #Launch full script and get job id mrg_jid = launch_qsub(mrg_dict["mrgscriptname"]) #Second order calculation so_dict = second_order_dict(template_dict, mrg_jid=mrg_jid) write_out_template(so_dict["templatefile"], so_dict["soscriptname"], so_dict) #Launch full script and get job id so_jid = launch_qsub(so_dict["soscriptname"]) #Combination of final results cmb_dict = combine_dict(template_dict, so_jid=so_jid) write_out_template(cmb_dict["templatefile"], cmb_dict["cmbscriptname"], cmb_dict) #Launch full script and get job id cmb_jid = launch_qsub(cmb_dict["cmbscriptname"]) #Write out individual source term qsub file src_indiv_dict = source_indiv_dict(template_dict) write_out_template(src_indiv_dict["templatefile"], src_indiv_dict["src_indivscriptname"], src_indiv_dict) return 0
def main(argv=None): """Main function: deal with command line arguments and start calculation as reqd.""" if not argv: argv = sys.argv #Parse command line options parser = optparse.OptionParser() parser.add_option("-f", "--filename", action="store", dest="foresults", default=run_config.foresults, type="string", metavar="FILE", help="first order results file, default=%default") parser.add_option( "--overwrite", action="store_true", dest="overwrite", default=run_config.overwrite, help= "if selected source term files which already exist will be overwritten." ) arraygroup = optparse.OptionGroup( parser, "Task Array Options", "These options specify a task array to work inside. " "The array is the range taskmin:taskmax with step taskstep. " "The current process should be given a taskid in the range specified. " "The default is an array of 1:1, step 1 with id 1.") arraygroup.add_option("--taskmin", action="store", dest="taskmin", default=1, type="int", help="start of task array range", metavar="NUM") arraygroup.add_option("--taskmax", action="store", dest="taskmax", default=1, type="int", help="end of task array range", metavar="NUM") arraygroup.add_option("--taskstep", action="store", dest="taskstep", default=1, type="int", help="step size of task array range", metavar="NUM") arraygroup.add_option("--taskid", action="store", dest="taskid", default=1, type="int", help="task id of current process", metavar="NUM") parser.add_option_group(arraygroup) timegroup = optparse.OptionGroup( parser, "Timestep Options", "These options affect which timesteps the source term is calculated for." ) timegroup.add_option("--tstart", action="store", dest="tstart", default=0, type="int", help="first time step to calculate, default=%default") timegroup.add_option( "--tend", action="store", dest="tend", default=-1, type="int", help= "last time step to calculate, use -1 for the last value, default=%default" ) parser.add_option_group(timegroup) loggroup = optparse.OptionGroup( parser, "Log Options", "These options affect the verbosity of the log files generated.") loggroup.add_option("-q", "--quiet", action="store_const", const=logging.FATAL, dest="loglevel", help="only print fatal error messages") loggroup.add_option("-v", "--verbose", action="store_const", const=logging.INFO, dest="loglevel", help="print informative messages") loggroup.add_option("--debug", action="store_const", const=logging.DEBUG, dest="loglevel", help="log lots of debugging information", default=run_config.LOGLEVEL) loggroup.add_option( "--console", action="store_true", dest="console", default=False, help="if selected matches console log level " "to selected file log level, otherwise only warnings are shown.") parser.add_option_group(loggroup) (options, args) = parser.parse_args(args=argv[1:]) #Start the logging module if options.console: consolelevel = options.loglevel else: consolelevel = logging.WARN #Change logger to add task id if options.taskmax != options.taskmin: log.name = "src-" + str(options.taskid) sosource.set_log_name() logfile = os.path.join(run_config.LOGDIR, "src.log") helpers.startlogging(log, logfile, options.loglevel, consolelevel) if (not _debug) and (options.loglevel == logging.DEBUG): log.warn( "Debugging information will not be stored due to setting in run_config." ) taskarray = dict(min=options.taskmin, max=options.taskmax, step=options.taskstep, id=options.taskid) if not os.path.isfile(options.foresults): raise IOError( "First order file %s does not exist! Please run firstorder.py." % options.foresults) try: runsource(fofile=options.foresults, ninit=options.tstart, nfinal=options.tend, taskarray=taskarray, overwrite=options.overwrite) except Exception: log.exception("Error getting source integral!") return 1 return 0
def main(argv=None): """Main function: deal with command line arguments and start calculation as reqd.""" if not argv: argv = sys.argv #Parse command line options parser = optparse.OptionParser() parser.add_option("-f", "--filename", action="store", dest="srcresults", default=run_config.srcresults, type="string", metavar="FILE", help="file to store all src results, default=%default") parser.add_option("-d", "--dirname", action="store", dest="dirname", default=run_config.RESULTSDIR, type="string", metavar="DIR", help="directory to search for src node files, " "default=%default") parser.add_option("--pattern", action="store", dest="pattern", default=run_config.pattern, type="string", help="regex pattern to match with src node files, default=%default") mrggroup = optparse.OptionGroup(parser, "Combination Options", "These options control the merging of first order and source files.") mrggroup.add_option("--merge", action="store_true", dest="merge", default=False, help="combine first order and source results in one file") mrggroup.add_option("--fofile", action="store", dest="foresults", default=run_config.foresults, type="string", metavar="FILE", help="first order results file, default=%default") mrggroup.add_option("--mergedfile", action="store", dest="mrgresults", default=run_config.mrgresults, type="string", metavar="FILE", help="new file to store first order and source results, default=%default") parser.add_option_group(mrggroup) loggroup = optparse.OptionGroup(parser, "Log Options", "These options affect the verbosity of the log files generated.") loggroup.add_option("-q", "--quiet", action="store_const", const=logging.FATAL, dest="loglevel", help="only print fatal error messages") loggroup.add_option("-v", "--verbose", action="store_const", const=logging.INFO, dest="loglevel", help="print informative messages") loggroup.add_option("--debug", action="store_const", const=logging.DEBUG, dest="loglevel", help="log lots of debugging information", default=run_config.LOGLEVEL) loggroup.add_option("--console", action="store_true", dest="console", default=False, help="if selected matches console log level " "to selected file log level, otherwise only warnings are shown.") parser.add_option_group(loggroup) (options, args) = parser.parse_args(args=argv[1:]) #Start the logging module if options.console: consolelevel = options.loglevel else: consolelevel = logging.WARN logfile = os.path.join(run_config.LOGDIR, "mrg.log") helpers.startlogging(log, logfile, options.loglevel, consolelevel) if (not _debug) and (options.loglevel == logging.DEBUG): log.warn("Debugging information will not be stored due to setting in run_config.") if os.path.isfile(options.srcresults): raise IOError("File %s already exists! Please delete or specify another filename." % options.srcresults) if not os.path.isdir(options.dirname): raise IOError("Directory %s does not exist!" % options.dirname) try: srcfile = joinsrcfiles(options.srcresults, options.dirname, options.pattern) except Exception: log.exception("Something went wrong while combining source files!") return 1 if options.merge: if os.path.isfile(options.mrgresults): raise IOError("File %s already exists! Please delete or specify another filename." % options.srcresults) if not os.path.isfile(options.foresults): raise IOError("First order file %s does not exist!" % options.foresults) try: sohelpers.combine_source_and_fofile(srcfile, options.foresults, options.mrgresults) except Exception: log.exception("Something went wrong while merging first order and source files.") return 1 return 0
def main(argv=None): """Main function: deal with command line arguments and start calculation as reqd.""" if not argv: argv = sys.argv #Parse command line options parser = optparse.OptionParser() mrggroup = optparse.OptionGroup( parser, "Combination Options", "These options control the combination of first and second order files." ) mrggroup.add_option( "--merge", action="store_true", dest="merge", default=False, help="combine first order and source results in one file") mrggroup.add_option( "--fofile", action="store", dest="foresults", default=run_config.mrgresults, type="string", metavar="FILE", help="first order or merged fo and src results file, default=%default") mrggroup.add_option("--sofile", action="store", dest="soresults", default=run_config.soresults, type="string", metavar="FILE", help="second order results file, default=%default") mrggroup.add_option( "--cmbfile", action="store", dest="cmbresults", default=run_config.cmbresults, type="string", metavar="FILE", help="new file to store combined results, default=%default") parser.add_option_group(mrggroup) loggroup = optparse.OptionGroup( parser, "Log Options", "These options affect the verbosity of the log files generated.") loggroup.add_option("-q", "--quiet", action="store_const", const=logging.FATAL, dest="loglevel", help="only print fatal error messages") loggroup.add_option("-v", "--verbose", action="store_const", const=logging.INFO, dest="loglevel", help="print informative messages") loggroup.add_option("--debug", action="store_const", const=logging.DEBUG, dest="loglevel", help="log lots of debugging information", default=run_config.LOGLEVEL) loggroup.add_option( "--console", action="store_true", dest="console", default=False, help="if selected matches console log level " "to selected file log level, otherwise only warnings are shown.") parser.add_option_group(loggroup) (options, args) = parser.parse_args(args=argv[1:]) #Start the logging module if options.console: consolelevel = options.loglevel else: consolelevel = logging.WARN logfile = os.path.join(run_config.LOGDIR, "cmb.log") helpers.startlogging(log, logfile, options.loglevel, consolelevel) if (not _debug) and (options.loglevel == logging.DEBUG): log.warn( "Debugging information will not be stored due to setting in run_config." ) if os.path.isfile(options.cmbresults): raise IOError( "File %s already exists! Please delete or specify another filename." % options.cmbresults) if not os.path.isdir(os.path.dirname(options.cmbresults)): raise IOError("Directory %s does not exist!" % os.path.dirname(options.cmbresults)) try: srcfile = combine_results(options.foresults, options.soresults, options.cmbresults) except Exception: log.exception("Something went wrong while combining files!") return 1 return 0
def main(argv=None): """Main function: deal with command line arguments and start calculation as reqd.""" if not argv: argv = sys.argv #Parse command line options parser = optparse.OptionParser() parser.add_option("-f", "--filename", action="store", dest="foresults", default=run_config.foresults, type="string", metavar="FILE", help="first order results file, default=%default") parser.add_option("--overwrite", action="store_true", dest="overwrite", default=run_config.overwrite, help="if selected source term files which already exist will be overwritten.") arraygroup = optparse.OptionGroup(parser, "Task Array Options", "These options specify a task array to work inside. " "The array is the range taskmin:taskmax with step taskstep. " "The current process should be given a taskid in the range specified. " "The default is an array of 1:1, step 1 with id 1.") arraygroup.add_option("--taskmin", action="store", dest="taskmin", default=1, type="int", help="start of task array range", metavar="NUM") arraygroup.add_option("--taskmax", action="store", dest="taskmax", default=1, type="int", help="end of task array range", metavar="NUM") arraygroup.add_option("--taskstep", action="store", dest="taskstep", default=1, type="int", help="step size of task array range", metavar="NUM") arraygroup.add_option("--taskid", action="store", dest="taskid", default=1, type="int", help="task id of current process", metavar="NUM") parser.add_option_group(arraygroup) timegroup = optparse.OptionGroup(parser, "Timestep Options", "These options affect which timesteps the source term is calculated for.") timegroup.add_option("--tstart", action="store", dest="tstart", default=0, type="int", help="first time step to calculate, default=%default") timegroup.add_option("--tend", action="store", dest="tend", default=-1, type="int", help="last time step to calculate, use -1 for the last value, default=%default") parser.add_option_group(timegroup) loggroup = optparse.OptionGroup(parser, "Log Options", "These options affect the verbosity of the log files generated.") loggroup.add_option("-q", "--quiet", action="store_const", const=logging.FATAL, dest="loglevel", help="only print fatal error messages") loggroup.add_option("-v", "--verbose", action="store_const", const=logging.INFO, dest="loglevel", help="print informative messages") loggroup.add_option("--debug", action="store_const", const=logging.DEBUG, dest="loglevel", help="log lots of debugging information", default=run_config.LOGLEVEL) loggroup.add_option("--console", action="store_true", dest="console", default=False, help="if selected matches console log level " "to selected file log level, otherwise only warnings are shown.") parser.add_option_group(loggroup) (options, args) = parser.parse_args(args=argv[1:]) #Start the logging module if options.console: consolelevel = options.loglevel else: consolelevel = logging.WARN #Change logger to add task id if options.taskmax != options.taskmin: log.name = "src-" + str(options.taskid) sosource.set_log_name() logfile = os.path.join(run_config.LOGDIR, "src.log") helpers.startlogging(log, logfile, options.loglevel, consolelevel) if (not _debug) and (options.loglevel == logging.DEBUG): log.warn("Debugging information will not be stored due to setting in run_config.") taskarray = dict(min=options.taskmin, max=options.taskmax, step=options.taskstep, id=options.taskid) if not os.path.isfile(options.foresults): raise IOError("First order file %s does not exist! Please run firstorder.py." % options.foresults) try: runsource(fofile=options.foresults, ninit=options.tstart, nfinal=options.tend, taskarray=taskarray, overwrite=options.overwrite) except Exception: log.exception("Error getting source integral!") return 1 return 0
def main(argv=None): """Deal with command line arguments and start calculation as required. Parameters ---------- argv: list List of command line arguments in the same form as sys.argv, i.e. argv[0] is the name of command being run. Returns ------- int: Return value equivalent to shell return code, 0 corresponds to successful execution, a value not equal to 0 corresponds to an error. """ if not argv: argv = sys.argv #Parse command line options parser = optparse.OptionParser() parser.add_option("-f", "--filename", action="store", dest="foresults", default=run_config.foresults, type="string", metavar="FILE", help="file to store results") parser.add_option( "-p", "--potential", action="store", dest="fixture", default="", type="string", metavar="POTENTIAL", help= "the potential to use, choose from the fixtures dict in run_config.py") loggroup = optparse.OptionGroup( parser, "Log Options", "These options affect the verbosity of the log files generated.") loggroup.add_option("-q", "--quiet", action="store_const", const=logging.FATAL, dest="loglevel", help="only print fatal error messages") loggroup.add_option("-v", "--verbose", action="store_const", const=logging.INFO, dest="loglevel", help="print informative messages") loggroup.add_option("--debug", action="store_const", const=logging.DEBUG, dest="loglevel", help="log lots of debugging information", default=run_config.LOGLEVEL) loggroup.add_option( "--console", action="store_true", dest="console", default=False, help="if selected matches console log level " "to selected file log level, otherwise only warnings are shown.") parser.add_option_group(loggroup) (options, args) = parser.parse_args(args=argv[1:]) #Start the logging module if options.console: consolelevel = options.loglevel else: consolelevel = logging.WARN helpers.startlogging(log, run_config.logfile, options.loglevel, consolelevel) log.info("-----------First order run requested------------------") if os.path.isfile(options.foresults): raise IOError("First order results file already exists!") if options.fixture != "": try: foargs = run_config.fixtures[options.fixture] log.info("Potential %s selected." % foargs["potential_func"]) except ValueError: log.exception("Fixture doesn't exist in run_config.py!") else: foargs = run_config.foargs.copy() #Get k variable for first order run foargs["k"] = helpers.seq(run_config.kinit, run_config.kend, run_config.deltak) #Start first order run try: runfomodel(filename=options.foresults, foargs=foargs) except Exception: log.exception("Something went wrong during first order run!") return 1 log.info("----------First order run finished-------------------") return 0
def main(argv=None): """Main function: deal with command line arguments and start calculation as reqd.""" if not argv: argv = sys.argv #Parse command line options parser = optparse.OptionParser() parser.add_option( "-f", "--filename", action="store", dest="mrgresults", default=run_config.mrgresults, type="string", metavar="FILE", help="merged first order and source results file, default=%default") loggroup = optparse.OptionGroup( parser, "Log Options", "These options affect the verbosity of the log files generated.") loggroup.add_option("-q", "--quiet", action="store_const", const=logging.FATAL, dest="loglevel", help="only print fatal error messages") loggroup.add_option("-v", "--verbose", action="store_const", const=logging.INFO, dest="loglevel", help="print informative messages") loggroup.add_option("--debug", action="store_const", const=logging.DEBUG, dest="loglevel", help="log lots of debugging information", default=run_config.LOGLEVEL) loggroup.add_option( "--console", action="store_true", dest="console", default=False, help="if selected matches console log level " "to selected file log level, otherwise only warnings are shown.") parser.add_option_group(loggroup) (options, args) = parser.parse_args(args=argv[1:]) #Start the logging module if options.console: consolelevel = options.loglevel else: consolelevel = logging.WARN logfile = os.path.join(run_config.LOGDIR, "so.log") helpers.startlogging(log, logfile, options.loglevel, consolelevel) if (not _debug) and (options.loglevel == logging.DEBUG): log.warn( "Debugging information will not be stored due to setting in run_config." ) if not os.path.isfile(options.mrgresults): raise IOError("Merged results file %s does not exist!" % options.foresults) try: log.info("-----------Second order run requested------------------") runsomodel(mrgfile=options.mrgresults, soargs=run_config.soargs) except Exception: log.exception("Error getting second order results!") return 1 return 0