diff --git a/build.xml b/build.xml index 07d0789b7..1a0a2dbf3 100644 --- a/build.xml +++ b/build.xml @@ -85,6 +85,7 @@ + @@ -117,6 +118,7 @@ + @@ -163,6 +165,7 @@ + @@ -287,6 +290,7 @@ + @@ -367,6 +371,7 @@ + @@ -571,6 +576,7 @@ + @@ -592,6 +598,7 @@ --> + diff --git a/core/java/src/org/openda/exchange/timeseries/TimeUtils.java b/core/java/src/org/openda/exchange/timeseries/TimeUtils.java index 846b593ae..a7a0ce30e 100644 --- a/core/java/src/org/openda/exchange/timeseries/TimeUtils.java +++ b/core/java/src/org/openda/exchange/timeseries/TimeUtils.java @@ -73,11 +73,7 @@ public static String mjdToString(double mjd) { * @return date as string */ public static String mjdToString(double mjd, String format, TimeZone tz) { - final long timeInMillis = Math.round((mjd - mjdAtJanFirst1970) * daysToMillis); - final Date t = new java.util.Date(timeInMillis); - final SimpleDateFormat formatter = new SimpleDateFormat(format); - formatter.setTimeZone(tz); - return formatter.format(t); + return mjdToString(mjd, format, tz, null); } /** @@ -90,14 +86,18 @@ public static String mjdToString(double mjd, String format, TimeZone tz) { * @return date as string */ public static String mjdToString(double mjd, String format) { - final TimeZone tz = TimeZone.getTimeZone("UTC"); - final long timeInMillis = Math.round((mjd - mjdAtJanFirst1970) * daysToMillis); - final Date t = new java.util.Date(timeInMillis); - final SimpleDateFormat formatter = new SimpleDateFormat(format); - formatter.setTimeZone(tz); - return formatter.format(t); + TimeZone tz = TimeZone.getTimeZone("UTC"); + return mjdToString(mjd, format, tz, null); } + public static String mjdToString(double mjd, String format, TimeZone tz, Locale locale) { + long timeInMillis = Math.round((mjd - mjdAtJanFirst1970) * daysToMillis); + Date date = new java.util.Date(timeInMillis); + SimpleDateFormat formatter = locale == null ? new SimpleDateFormat(format) : new SimpleDateFormat(format, locale); + if (tz != null) formatter.setTimeZone(tz); + return formatter.format(date); + } + /** * Add days, hours, minutes to Modified Julian Date (days since 00:00 November 17, 1858 UTC) and return the result * diff --git a/model_hec_hms/build.xml b/model_hec_hms/build.xml index 0d7b3b06d..b79fa0d8f 100644 --- a/model_hec_hms/build.xml +++ b/model_hec_hms/build.xml @@ -1,4 +1,4 @@ - + - - - - @@ -144,11 +139,24 @@ + + + + + + + + + + + + + diff --git a/model_hec_hms/java/model_hec_hms.iml b/model_hec_hms/java/model_hec_hms.iml new file mode 100644 index 000000000..35e7fc6f9 --- /dev/null +++ b/model_hec_hms/java/model_hec_hms.iml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/model_hec_hms/java/resources/FastInfoset-1.2.6.jar b/model_hec_hms/java/resources/FastInfoset-1.2.6.jar new file mode 100644 index 000000000..a9ac6ede8 Binary files /dev/null and b/model_hec_hms/java/resources/FastInfoset-1.2.6.jar differ diff --git a/model_hec_hms/java/resources/flogger-0.7.4.jar b/model_hec_hms/java/resources/flogger-0.7.4.jar new file mode 100644 index 000000000..8d1964324 Binary files /dev/null and b/model_hec_hms/java/resources/flogger-0.7.4.jar differ diff --git a/model_hec_hms/java/resources/flogger-system-backend-0.7.4.jar b/model_hec_hms/java/resources/flogger-system-backend-0.7.4.jar new file mode 100644 index 000000000..3b7e874a3 Binary files /dev/null and b/model_hec_hms/java/resources/flogger-system-backend-0.7.4.jar differ diff --git a/model_hec_hms/java/resources/hamcrest-core-1.3.jar b/model_hec_hms/java/resources/hamcrest-core-1.3.jar new file mode 100644 index 000000000..9d5fe16e3 Binary files /dev/null and b/model_hec_hms/java/resources/hamcrest-core-1.3.jar differ diff --git a/model_hec_hms/java/resources/hec-monolith-3.3.28.jar b/model_hec_hms/java/resources/hec-monolith-3.3.28.jar new file mode 100644 index 000000000..730082f6a Binary files /dev/null and b/model_hec_hms/java/resources/hec-monolith-3.3.28.jar differ diff --git a/model_hec_hms/java/resources/hec-nucleus-data-2.0.4.jar b/model_hec_hms/java/resources/hec-nucleus-data-2.0.4.jar new file mode 100644 index 000000000..0f6cb61b8 Binary files /dev/null and b/model_hec_hms/java/resources/hec-nucleus-data-2.0.4.jar differ diff --git a/model_hec_hms/java/resources/hec-nucleus-metadata-2.0.4.jar b/model_hec_hms/java/resources/hec-nucleus-metadata-2.0.4.jar new file mode 100644 index 000000000..28c35b3c8 Binary files /dev/null and b/model_hec_hms/java/resources/hec-nucleus-metadata-2.0.4.jar differ diff --git a/model_hec_hms/java/resources/hecdss.dll b/model_hec_hms/java/resources/hecdss.dll new file mode 100644 index 000000000..44087cb64 Binary files /dev/null and b/model_hec_hms/java/resources/hecdss.dll differ diff --git a/model_hec_hms/java/resources/javaHeclib.dll b/model_hec_hms/java/resources/javaHeclib.dll new file mode 100644 index 000000000..a4f7b9d9c Binary files /dev/null and b/model_hec_hms/java/resources/javaHeclib.dll differ diff --git a/model_hec_hms/java/resources/jnidispatch.dll b/model_hec_hms/java/resources/jnidispatch.dll new file mode 100644 index 000000000..397a3a9d7 Binary files /dev/null and b/model_hec_hms/java/resources/jnidispatch.dll differ diff --git a/model_hec_hms/java/resources/libjavaHeclib.so b/model_hec_hms/java/resources/libjavaHeclib.so new file mode 100644 index 000000000..de80f13ba Binary files /dev/null and b/model_hec_hms/java/resources/libjavaHeclib.so differ diff --git a/model_hec_hms/java/resources/slf4j-api-1.7.13.jar b/model_hec_hms/java/resources/slf4j-api-1.7.13.jar new file mode 100644 index 000000000..f07884ee7 Binary files /dev/null and b/model_hec_hms/java/resources/slf4j-api-1.7.13.jar differ diff --git a/model_hec_hms/java/src/org/openda/model_hec_hms/ControlFile.java b/model_hec_hms/java/src/org/openda/model_hec_hms/ControlFile.java index 5fa32dabb..742081105 100644 --- a/model_hec_hms/java/src/org/openda/model_hec_hms/ControlFile.java +++ b/model_hec_hms/java/src/org/openda/model_hec_hms/ControlFile.java @@ -6,24 +6,19 @@ import org.openda.interfaces.IExchangeItem; import java.io.*; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; +import java.text.SimpleDateFormat; +import java.util.*; public class ControlFile implements IDataObject { private static final String[] EMPTY_STRING_ARRAY = new String[0]; private static final String START_TIME = "start_time"; private static final String END_TIME = "end_time"; + public static final String DATE_FORMAT = "dd MMMMM yyyy"; + public static final String TIME_FORMAT = "KK:mm"; private File workingDirectory; private String filename = null; private final Map exchangeItems = new HashMap<>(); - private String timeZoneId = null; private final Map lines = new LinkedHashMap<>(); private final Map valuesToUpdate = new HashMap<>(); @@ -47,15 +42,6 @@ public IExchangeItem getDataObjectExchangeItem(String exchangeItemID) { public void finish() { File outputFile = new File(workingDirectory, filename); - ZoneId zoneId = ZoneId.of(timeZoneId); - DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd MMMM yyyy").withZone(zoneId); - DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm").withZone(zoneId); - - ZoneId utcZoneId = ZoneId.of("UTC"); - - LocalDateTime startDateTime = getDateTime(utcZoneId, START_TIME); - LocalDateTime endDateTime = getDateTime(utcZoneId, END_TIME); - try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream); BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter)) { @@ -69,16 +55,16 @@ public void finish() { switch (label.trim()) { case "Start Date": - value = dateFormatter.format(startDateTime); + value = getDateTimeString(START_TIME, DATE_FORMAT); break; case "Start Time": - value = timeFormatter.format(startDateTime); + value = getDateTimeString(START_TIME, TIME_FORMAT); break; case "End Date": - value = dateFormatter.format(endDateTime); + value = getDateTimeString(END_TIME, DATE_FORMAT); break; case "End Time": - value = timeFormatter.format(endDateTime); + value = getDateTimeString(END_TIME, TIME_FORMAT); break; default: // Do nothing with other labels @@ -97,12 +83,10 @@ public void finish() { } } - private LocalDateTime getDateTime(ZoneId utcZoneId, String timeId) { - DoubleExchangeItem dateTimeExchangeItem = exchangeItems.get(timeId); + private String getDateTimeString(String timeEIId, String dateFormat) { + DoubleExchangeItem dateTimeExchangeItem = exchangeItems.get(timeEIId); double mjdDateTime = dateTimeExchangeItem.getValue(); - Date dateTime = TimeUtils.mjdToDate(mjdDateTime); - dateTime.setHours((int) Math.round((mjdDateTime % 1) * 24)); - return dateTime.toInstant().atZone(utcZoneId).toLocalDateTime(); + return TimeUtils.mjdToString(mjdDateTime, dateFormat, TimeZone.getTimeZone("UTC"), Locale.US); } @Override @@ -156,9 +140,6 @@ private void processInputFile(File inputFile) { String label = labelAndValue[0].trim(); switch (label) { - case "Time Zone ID": - timeZoneId = labelAndValue[1].trim(); - break; case "Start Date": valuesToUpdate.put(lineNumber, label); startDate = labelAndValue[1].trim(); @@ -183,22 +164,21 @@ private void processInputFile(File inputFile) { line = bufferedReader.readLine(); lineNumber++; } + String pattern = DATE_FORMAT + TIME_FORMAT; + SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.US); + format.setTimeZone(TimeZone.getTimeZone("UTC")); - DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd MMMM yyyyHH:mmVV"); - - ZonedDateTime startDateTime = ZonedDateTime.parse(startDate + startTime + timeZoneId, dateTimeFormatter); - long startDateTimeMillis = startDateTime.toInstant().toEpochMilli(); + long startDateTimeMillis = format.parse(startDate + startTime).getTime(); double startMjdDateTime = TimeUtils.date2Mjd(new Date(startDateTimeMillis)); DoubleExchangeItem startMjdDateTimeExchangeItem = new DoubleExchangeItem(START_TIME, IExchangeItem.Role.InOut, startMjdDateTime); exchangeItems.putIfAbsent(START_TIME, startMjdDateTimeExchangeItem); - ZonedDateTime endDateTime = ZonedDateTime.parse(endDate + endTime + timeZoneId, dateTimeFormatter); - long endDateTimeMillis = endDateTime.toInstant().toEpochMilli(); + long endDateTimeMillis = format.parse(endDate + endTime).getTime(); double endMjdDateTime = TimeUtils.date2Mjd(new Date(endDateTimeMillis)); DoubleExchangeItem endMjdDateTimeExchangeItem = new DoubleExchangeItem(END_TIME, IExchangeItem.Role.InOut, endMjdDateTime); exchangeItems.putIfAbsent(END_TIME, endMjdDateTimeExchangeItem); - } catch (IOException ioException) { - throw new RuntimeException(ioException); + } catch (Exception e) { + throw new RuntimeException(e); } } } diff --git a/model_hec_hms/java/src/org/openda/model_hec_hms/DssFile.java b/model_hec_hms/java/src/org/openda/model_hec_hms/DssFile.java new file mode 100644 index 000000000..ca27800cc --- /dev/null +++ b/model_hec_hms/java/src/org/openda/model_hec_hms/DssFile.java @@ -0,0 +1,143 @@ +package org.openda.model_hec_hms; + +import hec.heclib.dss.DSSPathname; +import hec.heclib.util.HecTime; +import hec.heclib.util.Heclib; +import hec.hecmath.DSS; +import hec.hecmath.DSSFile; +import hec.hecmath.HecMath; +import hec.io.DataContainer; +import hec.io.TimeSeriesContainer; +import org.openda.exchange.AbstractDataObject; +import org.openda.exchange.DoublesExchangeItem; +import org.openda.exchange.TimeInfo; +import org.openda.exchange.timeseries.TimeUtils; +import org.openda.interfaces.IExchangeItem; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.*; + +public class DssFile extends AbstractDataObject { + private HecTime hecTimeObject; + + static { + if (System.getProperty("os.name").startsWith("Linux")) System.loadLibrary("javaHeclib"); + Heclib.zset("MLEVEL", "", 0); // set log level + } + + @Override + public void finish() { + // Not needed yet + } + + @Override + public void initialize(File workingDir, String[] arguments) { + + File inputFile = new File(workingDir, arguments[0]); + + DSSFile dssFile = DSS.open(inputFile.getPath()); + try { + Map> idContainersMap = getContainersPerExchangeItemIdMap(dssFile); + mergeContainersIntoExchangeItems(idContainersMap); + } finally { + dssFile.close(); + File dscFile = new File(inputFile.getPath().replace(".dss", ".dsc")); + Path dscPath = dscFile.toPath(); + try { + Files.deleteIfExists(dscPath); + } catch (IOException e) { + System.out.println("Error deleting " + dscFile.getAbsolutePath() + ": " + e.getMessage()); + } + } + } + + private void mergeContainersIntoExchangeItems(Map> idContainersMap) { + for (Map.Entry> entry : idContainersMap.entrySet()) { + String exchangeItemId = entry.getKey(); + List valuesList = entry.getValue(); + valuesList.sort(Comparator.comparingLong(c -> c.startHecTime.getTimeInMillis())); + int totalValuesLength = 0; + for (TimeSeriesContainer arr : valuesList) totalValuesLength += arr.times.length; + double[] combinedValues = new double[totalValuesLength]; + double[] combinedTimes = new double[totalValuesLength]; + int valPos = 0; + for (TimeSeriesContainer container : valuesList) { + System.arraycopy(container.values, 0, combinedValues, valPos, container.values.length); + double[] times = new double[container.numberValues]; + for (int i = 0; i < container.numberValues; i++) { + times[i] = hecTimeToMJD(container.times[i]); + } + System.arraycopy(times, 0, combinedTimes, valPos, times.length); + valPos += container.values.length; + } + if (!isAscending(combinedTimes)) throw new IllegalStateException("Programming error: Times for exchange item " + exchangeItemId + " are not in ascending order"); + TimeInfo timeInfo = new TimeInfo(combinedTimes); + DoublesExchangeItem exchangeItem = new DoublesExchangeItem(exchangeItemId, IExchangeItem.Role.Output, combinedValues); + exchangeItem.setTimeInfo(timeInfo); + exchangeItems.put(exchangeItemId, exchangeItem); + } + } + + private Map> getContainersPerExchangeItemIdMap(DSSFile dssFile) { + List pathNames = new ArrayList(dssFile.getCatalogedPathnames()); + Map> idContainersMap = new LinkedHashMap<>(); + for (String pathname : pathNames) { + try { + if (dssFile.getDataManager().recordType(pathname) == 106) continue; + HecMath hecMath = dssFile.read(pathname); + DataContainer container = hecMath.getData(); + + if (!(container instanceof TimeSeriesContainer)) continue; + TimeSeriesContainer timeSeriesContainer = (TimeSeriesContainer) container; + String exchangeItemId = getExchangeItemId(pathname); + List valuesList = idContainersMap.getOrDefault(exchangeItemId, new ArrayList<>()); + valuesList.add(timeSeriesContainer); + idContainersMap.putIfAbsent(exchangeItemId, valuesList); + } catch (Exception e) { + System.out.println("Error reading " + pathname + ": " + e.getMessage()); + } + } + return idContainersMap; + } + + private String getExchangeItemId(String pathname) { + DSSPathname dssPathName = new DSSPathname(); + dssPathName.setPathname(pathname); + StringBuilder idBuilder = new StringBuilder(); + String aPart = dssPathName.getAPart(); + idBuilder.append(aPart); + idBuilder.append('/'); + String bPart = dssPathName.getBPart(); + idBuilder.append(bPart); + idBuilder.append('/'); + String cPart = dssPathName.getCPart(); + idBuilder.append(cPart); + idBuilder.append('/'); + String fPart = dssPathName.getFPart(); + idBuilder.append(fPart); + + return idBuilder.toString(); + } + + private double hecTimeToMJD(int hecTime) { + if (hecTimeObject == null) hecTimeObject = new HecTime(); + hecTimeObject.set(hecTime); + return TimeUtils.date2Mjd(new Date(hecTimeObject.getTimeInMillis())); + } + + public static boolean isAscending(double[] array) { + if (array.length <= 1) return true; + + double lastValue = array[0]; + for (int i = 1; i < array.length; i++) { + double v = array[i]; + if (v < lastValue) return false; + lastValue = v; + } + + return true; + } +} diff --git a/model_hec_hms/java/test/org/openda/model_hec_hms/ControlFileTest.java b/model_hec_hms/java/test/org/openda/model_hec_hms/ControlFileTest.java index 8780f7f53..b6ab6a1c5 100644 --- a/model_hec_hms/java/test/org/openda/model_hec_hms/ControlFileTest.java +++ b/model_hec_hms/java/test/org/openda/model_hec_hms/ControlFileTest.java @@ -4,6 +4,7 @@ import org.openda.exchange.DoubleExchangeItem; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; +import org.openda.utils.OpenDaTestSupport; import java.io.File; import java.io.IOException; @@ -12,13 +13,21 @@ import java.util.List; public class ControlFileTest extends TestCase { - private static final File TEST_RESOURCES_DIRECTORY = new File("java/testResources"); - private static final double DELTA = 0.001; + OpenDaTestSupport testData = null; + private File testRunDataDir; + + + protected void setUp() throws IOException { + testData = new OpenDaTestSupport(DssFileTest.class, "model_hec_hms"); + testRunDataDir = testData.getTestRunDataDir(); + } + + private static final double DELTA = 0.0001; public void testControlFile() throws IOException { // Given input file File temporaryInputFile = File.createTempFile("temp-exchange-items", ".control"); - File sourceInputFile = new File(TEST_RESOURCES_DIRECTORY, "exchange-items.control"); + File sourceInputFile = new File(testRunDataDir, "exchange-items.control"); try { Files.copy(sourceInputFile.toPath(), temporaryInputFile.toPath(), StandardCopyOption.REPLACE_EXISTING); @@ -31,7 +40,7 @@ public void testControlFile() throws IOException { // Then exchange items are found String[] exchangeItemIds = dataObject.getExchangeItemIDs(); - assertEquals(1, exchangeItemIds.length); + assertEquals(2, exchangeItemIds.length); // Then exchange items contains values for: IExchangeItem startTimeExchangeItem = dataObject.getDataObjectExchangeItem("start_time"); @@ -46,9 +55,9 @@ public void testControlFile() throws IOException { // Then the exchange item has an array of values double startValue = mjdStartTimeExchangeItem.getValue(); - assertEquals(60611.958, startValue, DELTA); + assertEquals(60612, startValue, DELTA); double endValue = mjdEndTimeExchangeItem.getValue(); - assertEquals(60612.166, endValue, DELTA); + assertEquals(60612.2083, endValue, DELTA); // When the values are updated double newStartTime = 60637.875; // 23 November 2024 21:00 UTC @@ -61,8 +70,8 @@ public void testControlFile() throws IOException { dataObject.finish(); // Then the values are updated - List expectedLines = Files.readAllLines(new File(TEST_RESOURCES_DIRECTORY, "expected-exchange-items.control").toPath()); - List actualLines = Files.readAllLines(temporaryInputFile.toPath()); + String expectedLines = Files.readString(new File(testRunDataDir, "expected-exchange-items.control").toPath()); + String actualLines = Files.readString(temporaryInputFile.toPath()); assertEquals(expectedLines, actualLines); } finally { Files.deleteIfExists(temporaryInputFile.toPath()); diff --git a/model_hec_hms/java/test/org/openda/model_hec_hms/DssFileTest.java b/model_hec_hms/java/test/org/openda/model_hec_hms/DssFileTest.java new file mode 100644 index 000000000..f31a8ab3f --- /dev/null +++ b/model_hec_hms/java/test/org/openda/model_hec_hms/DssFileTest.java @@ -0,0 +1,57 @@ +package org.openda.model_hec_hms; + +import junit.framework.TestCase; +import org.openda.interfaces.IExchangeItem; +import org.openda.utils.OpenDaTestSupport; + +import java.io.File; +import java.util.Arrays; + +public class DssFileTest extends TestCase { + OpenDaTestSupport testData = null; + private File testRunDataDir; + + + protected void setUp() { + testData = new OpenDaTestSupport(DssFileTest.class, "model_hec_hms"); + testRunDataDir = testData.getTestRunDataDir(); + } + + public void testReadReal() { + File dssFile = new File(testRunDataDir, "Run_2.dss"); + DssFile dssDataObject = new DssFile(); + dssDataObject.initialize(testRunDataDir, new String[]{dssFile.getName()}); + + String[] exchangeItemIDs = dssDataObject.getExchangeItemIDs(); + Arrays.sort(exchangeItemIDs); + assertEquals(34, exchangeItemIDs.length); + IExchangeItem junction1FlowItem = dssDataObject.getDataObjectExchangeItem("/Junction-1/FLOW/RUN:Run 2"); + assertNotNull(junction1FlowItem); + double[] timesJ1 = junction1FlowItem.getTimeInfo().getTimes(); + assertEquals(1152, timesJ1.length); + assertEquals(60611.0, timesJ1[0], 0.00001); + assertEquals(60611.34375, timesJ1[99], 0.00001); + assertEquals(60614.99652777778, timesJ1[1151], 0.00001); + + double[] valuesJ1 = junction1FlowItem.getValuesAsDoubles(); + assertEquals(1152, valuesJ1.length); + assertEquals(10.5, valuesJ1[0], 0.00001); + assertEquals(4.08500, valuesJ1[99], 0.00001); + assertEquals(0.01787, valuesJ1[1151], 0.00001); + + + IExchangeItem subBasin1FlowItem = dssDataObject.getDataObjectExchangeItem("/Subbasin-8/ET-POTENTIAL/RUN:Run 2"); + assertNotNull(subBasin1FlowItem); + double[] timesSB8 = subBasin1FlowItem.getTimeInfo().getTimes(); + assertEquals(1151, timesSB8.length); + assertEquals(60611.003472, timesSB8[0], 0.00001); + assertEquals(60611.347222, timesSB8[99], 0.00001); + assertEquals(60614.99652777778, timesSB8[1150], 0.00001); + + double[] valuesSB8 = subBasin1FlowItem.getValuesAsDoubles(); + assertEquals(1151, valuesSB8.length); + assertEquals(0.0106597, valuesSB8[0], 0.00001); + assertEquals(0.0106597, valuesSB8[99], 0.00001); + assertEquals(0.0106597, valuesSB8[1150], 0.00001); + } +} diff --git a/model_hec_hms/java/test/org/openda/model_hec_hms/StateFileTest.java b/model_hec_hms/java/test/org/openda/model_hec_hms/StateFileTest.java index 227b20fa9..0574b625a 100644 --- a/model_hec_hms/java/test/org/openda/model_hec_hms/StateFileTest.java +++ b/model_hec_hms/java/test/org/openda/model_hec_hms/StateFileTest.java @@ -22,6 +22,7 @@ import junit.framework.TestCase; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; +import org.openda.utils.OpenDaTestSupport; import java.io.File; import java.io.IOException; @@ -30,12 +31,19 @@ import java.util.List; public class StateFileTest extends TestCase { - private static final File TEST_RESOURCES_DIRECTORY = new File("java/testResources"); + OpenDaTestSupport testData = null; + private File testRunDataDir; + + + protected void setUp() { + testData = new OpenDaTestSupport(DssFileTest.class, "model_hec_hms"); + testRunDataDir = testData.getTestRunDataDir(); + } public void testStateFileWithNoExchangeItems() throws IOException { // Given input file File temporaryInputFile = File.createTempFile("temp-no-exchange-items", ".state"); - File sourceInputFile = new File(TEST_RESOURCES_DIRECTORY, "no-exchange-items.state"); + File sourceInputFile = new File(testRunDataDir, "no-exchange-items.state"); try { Files.copy(sourceInputFile.toPath(), temporaryInputFile.toPath(), StandardCopyOption.REPLACE_EXISTING); @@ -54,7 +62,7 @@ public void testStateFileWithNoExchangeItems() throws IOException { dataObject.finish(); // Then output file matches input file - List expectedLines = Files.readAllLines(new File(TEST_RESOURCES_DIRECTORY, "expected-no-exchange-items.state").toPath()); + List expectedLines = Files.readAllLines(new File(testRunDataDir, "expected-no-exchange-items.state").toPath()); List actualLines = Files.readAllLines(temporaryInputFile.toPath()); assertEquals(expectedLines, actualLines); } finally { @@ -65,7 +73,7 @@ public void testStateFileWithNoExchangeItems() throws IOException { public void testStateFile() throws IOException { // Given input file File temporaryInputFile = File.createTempFile("temp-exchange-items", ".state"); - File sourceInputFile = new File(TEST_RESOURCES_DIRECTORY, "exchange-items.state"); + File sourceInputFile = new File(testRunDataDir, "exchange-items.state"); try { Files.copy(sourceInputFile.toPath(), temporaryInputFile.toPath(), StandardCopyOption.REPLACE_EXISTING); @@ -100,7 +108,7 @@ public void testStateFile() throws IOException { dataObject.finish(); // Then the values are updated - List expectedLines = Files.readAllLines(new File(TEST_RESOURCES_DIRECTORY, "expected-exchange-items.state").toPath()); + List expectedLines = Files.readAllLines(new File(testRunDataDir, "expected-exchange-items.state").toPath()); List actualLines = Files.readAllLines(temporaryInputFile.toPath()); assertEquals(expectedLines, actualLines); } finally { diff --git a/model_hec_hms/java/test/org/openda/model_hec_hms/testData/Run_2.dss b/model_hec_hms/java/test/org/openda/model_hec_hms/testData/Run_2.dss new file mode 100644 index 000000000..c6ceef80a Binary files /dev/null and b/model_hec_hms/java/test/org/openda/model_hec_hms/testData/Run_2.dss differ diff --git a/model_hec_hms/java/testResources/exchange-items.control b/model_hec_hms/java/test/org/openda/model_hec_hms/testData/exchange-items.control similarity index 100% rename from model_hec_hms/java/testResources/exchange-items.control rename to model_hec_hms/java/test/org/openda/model_hec_hms/testData/exchange-items.control diff --git a/model_hec_hms/java/testResources/exchange-items.state b/model_hec_hms/java/test/org/openda/model_hec_hms/testData/exchange-items.state similarity index 100% rename from model_hec_hms/java/testResources/exchange-items.state rename to model_hec_hms/java/test/org/openda/model_hec_hms/testData/exchange-items.state diff --git a/model_hec_hms/java/testResources/expected-exchange-items.control b/model_hec_hms/java/test/org/openda/model_hec_hms/testData/expected-exchange-items.control similarity index 86% rename from model_hec_hms/java/testResources/expected-exchange-items.control rename to model_hec_hms/java/test/org/openda/model_hec_hms/testData/expected-exchange-items.control index 70ad0c164..2ea0fff89 100644 --- a/model_hec_hms/java/testResources/expected-exchange-items.control +++ b/model_hec_hms/java/test/org/openda/model_hec_hms/testData/expected-exchange-items.control @@ -5,8 +5,8 @@ Control: Control_File Time Zone ID: Europe/Madrid Time Zone GMT Offset: 3600000 Start Date: 23 November 2024 - Start Time: 20:00 + Start Time: 09:00 End Date: 03 January 2025 - End Time: 05:00 + End Time: 06:00 Time Interval: 60 End: diff --git a/model_hec_hms/java/testResources/expected-exchange-items.state b/model_hec_hms/java/test/org/openda/model_hec_hms/testData/expected-exchange-items.state similarity index 100% rename from model_hec_hms/java/testResources/expected-exchange-items.state rename to model_hec_hms/java/test/org/openda/model_hec_hms/testData/expected-exchange-items.state diff --git a/model_hec_hms/java/testResources/expected-no-exchange-items.state b/model_hec_hms/java/test/org/openda/model_hec_hms/testData/expected-no-exchange-items.state similarity index 100% rename from model_hec_hms/java/testResources/expected-no-exchange-items.state rename to model_hec_hms/java/test/org/openda/model_hec_hms/testData/expected-no-exchange-items.state diff --git a/model_hec_hms/java/testResources/no-exchange-items.state b/model_hec_hms/java/test/org/openda/model_hec_hms/testData/no-exchange-items.state similarity index 100% rename from model_hec_hms/java/testResources/no-exchange-items.state rename to model_hec_hms/java/test/org/openda/model_hec_hms/testData/no-exchange-items.state diff --git a/model_hec_hms/model_hec_hms.iml b/model_hec_hms/model_hec_hms.iml deleted file mode 100644 index e836ef153..000000000 --- a/model_hec_hms/model_hec_hms.iml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/model_hec_hms/module.properties b/model_hec_hms/module.properties index 2b7ff35b7..1151c432c 100644 --- a/model_hec_hms/module.properties +++ b/model_hec_hms/module.properties @@ -22,6 +22,9 @@ javadocdir=javadoc jarname=${module}.jar modulebindir=bin modulelibdir=bin +native_bin=native_bin +linuxnativelibdir=linux64_gnu/lib +winnativelibdir=win64_ifort listfiles=no failonerror=no diff --git a/model_hec_hms/native/.gitkeep b/model_hec_hms/native/.gitkeep deleted file mode 100644 index e69de29bb..000000000