Skip to content

Commit 30ba596

Browse files
authored
Merge pull request #143 from falconstryker/devel
Added copy fixed file to -split
2 parents 6e0fdd6 + a7d67e1 commit 30ba596

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

bin/MarsFiles.py

Lines changed: 16 additions & 4 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

989-
if split_dim in ('time', 'areo'):
990-
time_dim = (np.squeeze(fNcdf.variables['time'][:]))[indices]
991-
print(f"time_dim = {time_dim}")
992-
993990
fpath = os.path.dirname(input_file_name)
994991
fname = os.path.basename(input_file_name)
992+
993+
if split_dim in ('time', 'areo'):
994+
time_dim = (np.squeeze(fNcdf.variables['time'][:]))[indices]
995+
print(f"time_dim = {time_dim}\n")
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 {original_date}.fixed.nc copied to {int(time_dim[0]):05d}.fixed.nc.\n")
1002+
except FileNotFoundError:
1003+
print(f"{Red}No compatible fixed file for {fname} (e.g., {original_date}.fixed.nc) was found in {fpath}{Nclr}\n")
1004+
except Exception as e:
1005+
print(f"{Red}An error occurred: {e}\n")
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)