old_contents: #!/usr/bin/env python
  import sys, os, shutil, tempfile, subprocess
  
  if len(sys.argv) != 7:
      print("usage: " + sys.argv[0] + " sim_type static_Bz c13_abundance" + \
            " max_cluster_size log10_samples walltime_in_days")
      exit(1)
  
  sim_args = sys.argv[1:6]
  walltime_in_days = sys.argv[-1]
  
  work_dir = os.path.dirname(os.path.realpath(__file__))
  script = work_dir + "/fidelity-sweep.py"
  basename = "-".join(sim_args)
  out_file = "jobs/"+basename+".o"
  
  nodes = 1
  tasks_per_node = 16
  task_num = str(int(nodes)*tasks_per_node)
  resources = ",".join(["nodes={}:ppn={}".format(nodes,tasks_per_node),
                        "walltime={}:00:00:00".format(walltime_in_days),
                        "pmem=1mb"])
  
  _,temp_file = tempfile.mkstemp()
  with open(temp_file,"w") as f:
      f.write("python {} {} {}\n".format(script," ".join(sim_args),task_num))
  
  subprocess.call(["msub", "-m", "e", "-N", basename,
                   "-j", "oe", "-o", out_file,
                   "-l", resources, temp_file])
  os.remove(temp_file)
  
new_contents: #!/usr/bin/env python
  import sys, os, shutil, tempfile, subprocess
  
  if len(sys.argv) < 7:
      print("usage: " + sys.argv[0] + " sim_type static_Bz c13_abundance" + \
            " max_cluster_size log10_samples walltime_in_days [mkfac.py args]")
      exit(1)
  
  sim_args = sys.argv[1:6]
  walltime_in_days = sys.argv[6]
  mkfac_args = sys.argv[7:]
  
  project_dir = os.path.dirname(os.path.realpath(__file__))
  job_dir = "jobs"
  mkfac = "mkfac.py"
  script = "fidelity-sweep.py"
  basename = "-".join(sim_args)
  job_file = job_dir+"/"+basename+".sh"
  out_file = job_dir+"/"+basename+".o"
  
  nodes = 1
  tasks_per_node = 16
  task_num = str(int(nodes)*tasks_per_node)
  
  resources = ["nodes={}:ppn={}".format(nodes,tasks_per_node),
               "walltime={}:00".format(walltime_in_days),
               "pmem=1mb"]
  options = ["-N "+basename, "-m e", "-j oe", "-o "+out_file]
  for resource in resources:
      options += ["-l {}".format(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," ".join(sim_args),task_num)
  
  with open(job_file,"w") as f: f.write(job_text)
  
  subprocess.call(["./"+mkfac] + mkfac_args)
  subprocess.call(["msub",job_file])
  
subject: make run-sweep.py write a moab script