diff --git a/src/Solver/AdisTS.py b/src/Solver/AdisTS.py index 71d62395..7f2f8d09 100644 --- a/src/Solver/AdisTS.py +++ b/src/Solver/AdisTS.py @@ -594,7 +594,9 @@ class AdisTSwc(AdisTS): f.write(f"*---------++++++++++\n") for LC_data in LC.data: - tmp = timestamp_to_old_pamhyr_date_adists(int(LC_data[0])) + tmp = timestamp_to_old_pamhyr_date_adists( + int(self.export_time(study, LC_data[0])) + ) f.write(" ".join((f"{tmp}", f"{LC_data[1]}\n"))) f.write(f"*\n") @@ -626,7 +628,9 @@ class AdisTSwc(AdisTS): f.write(f"*---------++++++++++\n") for BC_data in BC.data: - tmp = timestamp_to_old_pamhyr_date_adists(int(BC_data[0])) + tmp = timestamp_to_old_pamhyr_date_adists( + int(self.export_time(study, BC_data[0])) + ) f.write(" ".join((f"{tmp}", f"{BC_data[1]}\n"))) f.write(f"*\n") diff --git a/src/Solver/AdisTT.py b/src/Solver/AdisTT.py index 7605ed13..a379445c 100644 --- a/src/Solver/AdisTT.py +++ b/src/Solver/AdisTT.py @@ -884,7 +884,9 @@ class AdisTTwc(AdisTT): f.write("*temps |temperature (degC)\n") f.write("*---------++++++++++\n") for value in boundary_condition.data: - date = timestamp_to_old_pamhyr_date_adists(int(value[0])) + date = timestamp_to_old_pamhyr_date_adists( + int(self.export_time(study, value[0])) + ) f.write(f"{date} {value[1]}\n") f.write("*\n") return filename @@ -907,7 +909,9 @@ class AdisTTwc(AdisTT): f.write("*temps |value\n") f.write("*---------++++++++++\n") for value in weather_parameter.data: - date = timestamp_to_old_pamhyr_date_adists(int(value[0])) + date = timestamp_to_old_pamhyr_date_adists( + int(self.export_time(study, value[0])) + ) f.write(f"{date} {value[1]}\n") f.write("*\n") return filename diff --git a/src/Solver/CommandLine.py b/src/Solver/CommandLine.py index c908ffce..32dfaec9 100644 --- a/src/Solver/CommandLine.py +++ b/src/Solver/CommandLine.py @@ -19,8 +19,9 @@ import os import logging -from datetime import datetime +from datetime import datetime, timezone from tools import timer, parse_command_line, get_version, logger_exception +from tools import parse_datetime try: # Installation allow Unix-like signal @@ -44,6 +45,15 @@ logger = logging.getLogger() class CommandLineSolver(AbstractSolver): _type = "" + @staticmethod + def export_time(study, value): + """Return elapsed seconds before applying the solver file's units.""" + if study.time_system != "date": + return value + # Match the UTC timestamps produced by date entry in the tables. + start = parse_datetime(study.date).replace(tzinfo=timezone.utc) + return float(value) - start.timestamp() + def __init__(self, name): super(CommandLineSolver, self).__init__(name) diff --git a/src/Solver/Mage.py b/src/Solver/Mage.py index c15b2152..9f8bcd81 100644 --- a/src/Solver/Mage.py +++ b/src/Solver/Mage.py @@ -303,7 +303,7 @@ class Mage(CommandLineSolver): # Point line wfile.write(f"{x} {y} {z} {n} {sediment}\n") - def _export_BC(self, t, bounds, repertory, qlog, name="0"): + def _export_BC(self, study, t, bounds, repertory, qlog, name="0"): files = [] if len(bounds) == 0: @@ -333,7 +333,7 @@ class Mage(CommandLineSolver): v1 = d[1] if t in ["HYD", "LIM"]: - v0 /= 60 # Convert first column to minute + v0 = self.export_time(study, v0) / 60 # Minutes f.write(f"{v0:9} {v1:9} \n") @@ -365,10 +365,16 @@ class Mage(CommandLineSolver): elif bound.bctype == "SL": QSO.append(bound) - files = files + self._export_BC("AVA", AVA, repertory, qlog, name=name) - files = files + self._export_BC("HYD", HYD, repertory, qlog, name=name) - files = files + self._export_BC("LIM", LIM, repertory, qlog, name=name) - files = files + self._export_QSO(QSO, repertory, qlog, name=name) + files = files + self._export_BC( + study, "AVA", AVA, repertory, qlog, name=name + ) + files = files + self._export_BC( + study, "HYD", HYD, repertory, qlog, name=name + ) + files = files + self._export_BC( + study, "LIM", LIM, repertory, qlog, name=name + ) + files = files + self._export_QSO(study, QSO, repertory, qlog, name=name) return files @@ -422,10 +428,11 @@ class Mage(CommandLineSolver): if d.is_deleted(): continue + time = self.export_time(study, d[0]) if lateral.lctype in ["EV"]: - f.write(f"{d[0]:10.3f}{-d[1]:10.3f}\n") + f.write(f"{time:10.3f}{-d[1]:10.3f}\n") else: - f.write(f"{d[0]:10.3f}{d[1]:10.3f}\n") + f.write(f"{time:10.3f}{d[1]:10.3f}\n") def _export_RUG(self, study, repertory, qlog, name="0"): files = [] @@ -964,7 +971,7 @@ class Mage8(Mage): return files - def _export_QSO(self, bounds, repertory, qlog, name="0"): + def _export_QSO(self, study, bounds, repertory, qlog, name="0"): files = [] if len(bounds) == 0: @@ -994,7 +1001,8 @@ class Mage8(Mage): # Data for d in bound.data: - f.write(f"{d[0]/60:10.3f}{d[1]:10.3f}\n") + time = self.export_time(study, d[0]) / 60 + f.write(f"{time:10.3f}{d[1]:10.3f}\n") return files diff --git a/src/Solver/RubarBE.py b/src/Solver/RubarBE.py index 4da1ad1f..48ea9ecd 100644 --- a/src/Solver/RubarBE.py +++ b/src/Solver/RubarBE.py @@ -550,7 +550,8 @@ class Rubar3(CommandLineSolver): for bc in bcs: f.write(f"{len(bc)}\n") for d0, d1 in bc.data: - f.write(f"{d1} {d0}\n") + time = self.export_time(study, d0) + f.write(f"{d1} {time}\n") def _export_condav(self, study, repertory, qlog, name="0"): if qlog is not None: @@ -577,7 +578,8 @@ class Rubar3(CommandLineSolver): f.write(f"{d1} {d0}\n") else: for d0, d1 in bc.data: - f.write(f"{d0} {d1}\n") + time = self.export_time(study, d0) + f.write(f"{time} {d1}\n") def read_profil(self, study, fname, results, qlog=None, name="0"): logger.info(f"read: profil.{name}")