From e58c54a242c8ea722afffbf25fa19b7945586f31 Mon Sep 17 00:00:00 2001 From: Lionel GUEZ <guez@lmd.ens.fr> Date: Thu, 23 Mar 2023 20:35:42 +0100 Subject: [PATCH] Create files in the slice directory Create `cropped.nc` and `unpacked.nc` in the slice directory, so that several processes running `inst_eddies.py` for different slices can run in parallel. --- Inst_eddies/inst_eddies.py.in | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Inst_eddies/inst_eddies.py.in b/Inst_eddies/inst_eddies.py.in index 5b837cd1..c7f8361d 100644 --- a/Inst_eddies/inst_eddies.py.in +++ b/Inst_eddies/inst_eddies.py.in @@ -51,6 +51,9 @@ def loop_inst_eddies(files, bbox, d, my_slice): # Short names (without blanks): writer.writerow(["date", "elapsed_NCO", "elapsed_Fortran"]) + cropped_fname = f"SHPC/Slice_{my_slice}/cropped.nc" + unpacked_fname = f"SHPC/Slice_{my_slice}/unpacked.nc" + for nc_file in files: print("inst_eddies.loop_inst_eddies: Date:", d) print("inst_eddies.loop_inst_eddies: Input file:", nc_file, @@ -63,7 +66,7 @@ def loop_inst_eddies(files, bbox, d, my_slice): xmin, xmax, ymin, ymax = bbox try: - nco_instance.ncks(nc_file, output = "cropped.nc", + nco_instance.ncks(nc_file, output = cropped_fname, options = [f"--dimension=longitude,{xmin},{xmax}", f"--dimension=latitude,{ymin},{ymax}"]) @@ -71,13 +74,13 @@ def loop_inst_eddies(files, bbox, d, my_slice): print(err.stdout) raise - nc_file = "cropped.nc" + nc_file = cropped_fname - nco_instance.ncpdq(nc_file, output = "unpacked.nc", + nco_instance.ncpdq(nc_file, output = unpacked_fname, options = ["--unpack"]) elapsed_NCO = time.perf_counter() - my_pc my_pc = time.perf_counter() - subprocess.run([inst_eddies_exe, "unpacked.nc", "unpacked.nc"], + subprocess.run([inst_eddies_exe, unpacked_fname, unpacked_fname], check = True, input = f"&dates_nml date = {d}, " f"slice = {my_slice}/\n", text = True) elapsed_Fortran = time.perf_counter() - my_pc @@ -96,8 +99,8 @@ def loop_inst_eddies(files, bbox, d, my_slice): d += 1 perf_report.close() - os.remove("unpacked.nc") - if bbox: os.remove("cropped.nc") + os.remove(unpacked_fname) + if bbox: os.remove(cropped_fname) if my_slice == 0 and not os.access("SHPC/n_slices.txt", os.F_OK): with open("SHPC/n_slices.txt", "w") as f: f.write("1\n") -- GitLab