def hydroWithInitialCondition(argv):
    """ Run hydro using intitial conditions specified in a source folder.
  Usage: hydroWithInitialCondition.py direct_init_filename source_folder destination_folder hydro_executable and parameters
  """

    initial_dir = "Initial"

    # check argument and get directories
    if len(argv) < 4:
        print(
            "Usage: hydroWithInitialCondition.py direct_init_filename source_folder destination_folder hydro_executable and parameters"
        )
        exit()
    else:
        direct_init_file = argv[1]
        sourceDir = argv[2]
        targetDir = argv[3]

    current_dir = getcwd()

    # get hydro_executable and parameters
    executable = " ".join(argv[4:])

    # get those initial conditions that already exist
    makeDir(targetDir)
    files_exist = []
    for aDir in ls(targetDir, "dir"):
        files_exist = union(
            [files_exist,
             ls(path.join(targetDir, aDir, initial_dir), "file")])

    # the big loop
    for init_file in ls(sourceDir, "file"):
        # first check if this initial has already be used
        if init_file in files_exist:
            print("\n********************************\n")
            print("Initial file" + " " + init_file + " " +
                  "already exists; skipping it.")
            continue
        run("rm ./Initial/*")
        print(
            "\n=============================================================\n"
        )
        print("Using" + " " + path.join(sourceDir, init_file) + "...")
        copy(path.join(sourceDir, init_file),
             path.join(current_dir, initial_dir, init_file))
        copy(path.join(sourceDir, init_file),
             path.join(current_dir, initial_dir, direct_init_file))
        print("python ./record-hydro.py" + " " + targetDir + " " + executable)
        run("python ./record-hydro.py" + " " + targetDir + " " + executable)
def hydroWithInitialCondition(argv):
  """ Run hydro using intitial conditions specified in a source folder.
  Usage: hydroWithInitialCondition.py direct_init_filename source_folder destination_folder hydro_executable and parameters
  """

  initial_dir = "Initial";

  # check argument and get directories
  if len(argv)<4:
    print("Usage: hydroWithInitialCondition.py direct_init_filename source_folder destination_folder hydro_executable and parameters");
    exit();
  else:
    direct_init_file=argv[1];
    sourceDir=argv[2];
    targetDir=argv[3];

  current_dir = getcwd();

  # get hydro_executable and parameters
  executable = " ".join(argv[4:]);

  # get those initial conditions that already exist
  makeDir(targetDir);
  files_exist = [];
  for aDir in ls(targetDir, "dir"):
    files_exist = union([files_exist, ls(path.join(targetDir, aDir, initial_dir), "file")]);

  # the big loop
  for init_file in ls(sourceDir, "file"):
    # first check if this initial has already be used
    if init_file in files_exist:
      print("\n********************************\n");
      print("Initial file"+" "+init_file+" "+"already exists; skipping it.");
      continue;
    run("rm ./Initial/*");
    print("\n=============================================================\n");
    print("Using"+" "+path.join(sourceDir, init_file)+"...");
    copy(path.join(sourceDir, init_file), path.join(current_dir, initial_dir, init_file));
    copy(path.join(sourceDir, init_file), path.join(current_dir, initial_dir, direct_init_file));
    print("python ./record-hydro.py" + " " + targetDir + " " + executable);
    run("python ./record-hydro.py" + " " + targetDir + " " + executable);
Пример #3
0
def record_hydro(argv):
    """ Run the commands specified by argv[2:] then copy the generated data files to a uniquely generated directory under argv[1]. """

    properEndingString1 = "Early"  # if this string is not found, the program must stoped in the middle
    properEndingString2 = "Decoupling"

    if len(argv) > 1:
        # generate necessary strings
        unique_signature = "-".join(
            argv[2:]) + "--" + strftime("%Y-%m-%d@%H:%M:%S")
        # for debug: print unique_signature
        store_rel_path = unique_signature
        logfile = unique_signature + ".log"
        exe_line = " ".join(argv[2:]) + " | tee " + logfile

        # clean up first
        run("bash ./del.sh")

        # execute hydro code (presumably)
        print "Executing " + exe_line + "..."
        run(exe_line)

        # copy data files
        tmpfile = open(path.join(getcwd(), logfile))
        tmpBuffer = tmpfile.read()
        if ((properEndingString1 in tmpBuffer) or
            (properEndingString2 in tmpBuffer)):  # program normally exited
            print("Program quit normally, copy data now.")
            # create target directory
            store_path = path.join(argv[1], store_rel_path)
            store_path = makeDir(store_path, "new")
            # get the next available dir
            run("bash ./copy-data-hydro.sh" + " " + str(getcwd()) + " " +
                store_path)
        else:
            print("Error in executation.")
        # clean up again
        run("bash ./del.sh")
    else:
        print "Usage: record base-dir-path command (with parameters)"
Пример #4
0
def record_hydro(argv):
  """ Run the commands specified by argv[2:] then copy the generated data files to a uniquely generated directory under argv[1]. """

  properEndingString1 = "Early" # if this string is not found, the program must stoped in the middle
  properEndingString2 = "Decoupling"

  if len(argv) > 1:
    # generate necessary strings
    unique_signature = "-".join(argv[2:])+"--"+strftime("%Y-%m-%d@%H:%M:%S")
    # for debug: print unique_signature
    store_rel_path = unique_signature
    logfile = unique_signature+".log"
    exe_line = " ".join(argv[2:])+" | tee "+logfile

    # clean up first
    run("bash ./del.sh")

    # execute hydro code (presumably)
    print "Executing " + exe_line + "..."
    run(exe_line)

    # copy data files
    tmpfile = open(path.join(getcwd(), logfile))
    tmpBuffer =  tmpfile.read()
    if ((properEndingString1 in tmpBuffer) or (properEndingString2 in tmpBuffer)): # program normally exited
      print("Program quit normally, copy data now.");
      # create target directory
      store_path = path.join(argv[1],store_rel_path);
      store_path = makeDir(store_path, "new"); # get the next available dir
      run("bash ./copy-data-hydro.sh"+" "+str(getcwd())+" "+store_path)
    else:
      print("Error in executation.")
    # clean up again
    run("bash ./del.sh")
  else:
    print "Usage: record base-dir-path command (with parameters)"