Skip to content

Commit a446914

Browse files
committed
split by time will now also copy over a fixed file with a compatible date
1 parent f97fef8 commit a446914

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

bin/MarsFiles.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import shutil # For OS-friendly file operations
6464
import functools # For function decorators
6565
import traceback # For printing stack traces
66+
import shutil # For copy/pasting fixed file after -split
6667

6768
# Load amesCAP modules
6869
from amescap.Ncdf_wrapper import (Ncdf, Fort)
@@ -986,12 +987,23 @@ def split_files(file_list, split_dim):
986987
)
987988
exit()
988989

990+
fpath = os.path.dirname(input_file_name)
991+
fname = os.path.basename(input_file_name)
992+
989993
if split_dim in ('time', 'areo'):
990994
time_dim = (np.squeeze(fNcdf.variables['time'][:]))[indices]
991995
print(f"time_dim = {time_dim}")
992-
993-
fpath = os.path.dirname(input_file_name)
994-
fname = os.path.basename(input_file_name)
996+
997+
try:
998+
org_fixed_file = (os.path.normpath(os.path.join(fpath, f"{original_date}.fixed.nc")))
999+
new_fixed_file = (os.path.normpath(os.path.join(fpath, f"{int(time_dim[0]):05d}.fixed.nc")))
1000+
shutil.copyfile(org_fixed_file, new_fixed_file)
1001+
print(f"File '{org_fixed_file}' copied to '{new_fixed_file}'.")
1002+
except FileNotFoundError:
1003+
print(f"{Red}No compatible fixed file for {fname} was found in {fpath}{Nclr}")
1004+
except Exception as e:
1005+
print(f"{Red}An error occurred: {e}")
1006+
9951007
if split_dim == 'time':
9961008
if len(np.atleast_1d(bounds)) < 2:
9971009
base_name = (f"{int(time_dim):05d}{fname[5:-3]}_nearest_sol"

0 commit comments

Comments
 (0)