diff --git a/Inst_eddies/inst_eddies_in.py b/Inst_eddies/inst_eddies_in.py index df0ec4ebd52315fe78bd709f471174a8ca507dcc..fadb864fccb59eb78f78f769596910eedab33091 100755 --- a/Inst_eddies/inst_eddies_in.py +++ b/Inst_eddies/inst_eddies_in.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -"""We are assuming that all input NetCDF files are in the same -directory and that the time coordinate is in days since 1950-1-1.""" import argparse import datetime @@ -18,13 +16,9 @@ import time import csv argparser = argparse.ArgumentParser() -argparser.add_argument("first_file", +argparser.add_argument("file", nargs = "+", help = "NetCDF file containing SSH and velocity at a " "single date") -argparser.add_argument("--template", - help = "template of basename with date format, only " - "used for several dates") -argparser.add_argument("-l", "--last_date", help = "%%Y-%%m-%%d") argparser.add_argument("-b", "--bbox", nargs=4, type = float, metavar = ("xmin", "xmax", "ymin", "ymax")) args = argparser.parse_args() @@ -33,26 +27,15 @@ inst_eddies_exe = "@CMAKE_CURRENT_BINARY_DIR@/inst_eddies" if not os.access(inst_eddies_exe, os.X_OK): sys.exit(inst_eddies_exe + " not found or not executable") -# Get the first date from the time coordinate in the NetCDF file: -with netCDF4.Dataset(args.first_file) as f: - my_date = f["time"][:].item() - -my_date = round(my_date) -my_date = datetime.date(1950, 1, 1) + datetime.timedelta(my_date) -#-- +if os.access("main_nml.txt", os.R_OK): + print("Will use main_nml.txt.") +else: + sys.exit('"main_nml.txt" not found') -dirname = path.dirname(args.first_file) -nc_file = args.first_file +d = input("Enter first date (integer value):") +d = int(d) nco_instance = nco.Nco() -if args.last_date: - last_date = parser.parse(args.last_date).date() - - if last_date > my_date and not args.template: - sys.exit("template option required for several dates") -else: - last_date = my_date - for orient in ["cyclo", "anti"]: if os.access(f"SHPC_{orient}", os.F_OK): shutil.rmtree(f"SHPC_{orient}") os.mkdir(f"SHPC_{orient}") @@ -61,8 +44,8 @@ perf_report = open("perf_report.csv", "w", newline='') writer = csv.writer(perf_report, lineterminator = "\n") writer.writerow(["date", "elapsed NCO", "elapsed Fortran"]) -while True: - print("inst_eddies.py: Date:", my_date) +for nc_file in args.file: + print("inst_eddies.py: Date:", d) if os.access(nc_file, os.F_OK): my_pc = time.perf_counter() @@ -80,11 +63,12 @@ while True: os.symlink("unpacked.nc", "uv.nc") elapsed_NCO = time.perf_counter() - my_pc my_pc = time.perf_counter() - subprocess.run(inst_eddies_exe, check = True) + subprocess.run(inst_eddies_exe, check = True, input = str(d) + "\n", + text = True) elapsed_Fortran = time.perf_counter() - my_pc os.remove("h.nc") os.remove("uv.nc") - writer.writerow([my_date, elapsed_NCO, elapsed_Fortran]) + writer.writerow([d, elapsed_NCO, elapsed_Fortran]) else: print("inst_eddies.py: Missing file:", nc_file) @@ -94,10 +78,7 @@ while True: n_shapes = len(shpr) ishape_last.write(str(n_shapes - 1) + "\n") - my_date += datetime.timedelta(1) - if my_date > last_date: break - basename = my_date.strftime(args.template) - nc_file = path.join(dirname, basename) + d += 1 perf_report.close() os.remove("unpacked.nc")