def main(hex_string):
    """Handle command line parameters"""
    
    try:
        
    except Exception as e:
        script_name = basename(__file__)
        print 'Usage: ' + script_name + ' <hex-value>'
        for max_cluster_size in max_cluster_sizes:
            for scale_factor in scale_factors:
                log10_samples = int(numpy.round(3 - numpy.log10(c13_factor)))

                sim_args = [ sim_type,
                             "--static_Bz", static_Bz,
                             "--c13_factor", c13_factor,
                             "--max_cluster_size", max_cluster_size,
                             "--scale_factor", scale_factor ] + sim_opts \
                             + [ log10_samples_hook, log10_samples ]

                if test_jobs:
                    subprocess.call(cmd_args(sim_args,3))

                else:
                    test_job_name = "./jobs/" + basename(sim_args) + ".o_feedback"
                    fname_candidates = glob.glob(test_job_name)
                    if not len(fname_candidates) == 1:
                        print("please run test jobs first")
                        exit(1)
                    fname = fname_candidates[0]

                    with open(fname,"r") as f:
                        for line in f:
                            if "WallTime" in line:
                                test_time_text = line.split()[2]
                                break

                    hh_mm_ss = [ int(t) for t in test_time_text.split(":") ]
                    test_time = hh_mm_ss[-1] + hh_mm_ss[-2]*60 + hh_mm_ss[-3]*3600
    print("must specify number of samples to simulate (via {} [num])"
          .format(log10_samples_hook))
    exit(1)
log10_samples = cmd_args[cmd_args.index(log10_samples_hook)+1]
del cmd_args[cmd_args.index(log10_samples_hook)+1]
del cmd_args[cmd_args.index(log10_samples_hook)]

print_period = 1800 # seconds

# identify some directories and names
project_dir = os.path.dirname(os.path.realpath(__file__))
data_dir = "data"
sim_file = "simulate.exe"
summary_script = "fidelity-summary.py"
basename_module = "basename.py"
out_file = "{}/{}.txt".format(data_dir,basename(sim_args))
base_cmd = ["./"+sim_file] + cmd_args

if "TMPDIR" not in os.environ:
    print("please set the TMPDIR environment variable")
    exit(1)
job_dir = os.environ["TMPDIR"] + "/" + os.environ["USER"] + "/" + "".join(sys.argv[1:])

# move into job directory
os.makedirs(job_dir)
for fname in [ sim_file, summary_script, basename_module ]:
    shutil.copy2(project_dir+"/"+fname, job_dir+"/"+fname)
os.chdir(job_dir)
os.mkdir(data_dir)

# method to execute a single simulation
nodes = 1
tasks_per_node = 16
task_num = str(int(nodes)*tasks_per_node)

if not log10_samples_hook in sim_args:
    print("must specify number of samples to simulate (via {} [num])"
          .format(log10_samples_hook))
    exit(1)
log10_samples = sim_args[sim_args.index(log10_samples_hook)+1]
mem_per_task_estimate_in_mb = int(0.5 * 4**float(log10_samples))

project_dir = os.path.dirname(os.path.realpath(__file__))
job_dir = "jobs"
mkfac = "mkfac.py"
script = "fidelity-sweep.py"
job_file = job_dir+"/"+basename(sim_args)+".sh"
out_file = job_dir+"/"+basename(sim_args)+".o"

resources = ["nodes={}:ppn={}".format(nodes,tasks_per_node),
             "walltime={}:00:00".format(walltime_in_hours),
             "pmem={}mb".format(mem_per_task_estimate_in_mb)]
options = ["-N "+basename(sim_args), "-m e", "-j oe", "-o "+out_file]
for resource in resources:
    options += ["-l "+resource]

job_text = "#!/usr/bin/env sh\n"
for option in options:
    job_text += "#MSUB {}\n".format(option)
job_text += "\n"
job_text += "python {}/{} {} {}\n".format(project_dir,script,task_num," ".join(sim_args))