Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Added robust error handling and updated conversion code to handle Swifter to Swiftest.
  • Loading branch information
daminton committed Jun 25, 2021
1 parent 33cbac8 commit 2678819
Show file tree
Hide file tree
Showing 17 changed files with 304 additions and 242 deletions.
29 changes: 0 additions & 29 deletions examples/swifter_conversion/param.swiftest.in

This file was deleted.

24 changes: 0 additions & 24 deletions examples/swifter_conversion/swifter2swiftest.py

This file was deleted.

19 changes: 18 additions & 1 deletion python/swiftest/swiftest/simulation_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def read_param(self, param_file_name, codename="Swiftest"):

def write_param(self, param_file_name):
# Check to see if the parameter type matches the output type. If not, we need to convert
codename = self.param['VERSION'].split()[1]
codename = self.param['! VERSION'].split()[0]
if codename == "Swifter" or codename == "Swiftest":
swiftestio.write_labeled_param(self.param, param_file_name)
elif codename == "Swift":
Expand All @@ -33,6 +33,23 @@ def write_param(self, param_file_name):
print('Cannot process unknown code type. Call the read_param method with a valid code name. Valid options are "Swiftest", "Swifter", or "Swift".')
return

def convert(self, param_file_name, newcodename="Swiftest", plname="pl.swiftest.in", tpname="tp.swiftest.in", cbname="cb.swiftest.in"):
"""
Converts simulation input files from one code type to another (Swift, Swifter, or Swiftest). Returns the old parameter configuration.
"""
oldparam = self.param
if self.codename == newcodename:
print(f"This parameter configuration is already in {newcodename} format")
return oldparam
if newcodename != "Swift" and newcodename != "Swifter" and newcodename != "Swiftest":
print(f'{newcodename} is an invalid code type. Valid options are "Swiftest", "Swifter", or "Swift".')
return oldparam
if self.codename == "Swifter":
if newcodename == "Swiftest":
self.param = swiftestio.swifter2swiftest(self.param, plname, tpname, cbname)
self.write_param(param_file_name)
return oldparam

def bin2xr(self):
if self.codename == "Swiftest":
self.ds = swiftestio.swiftest2xr(self.param)
Expand Down
Loading

0 comments on commit 2678819

Please sign in to comment.