Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<buildmodule module="model_external_file" />
<buildmodule module="model_glm" />
<buildmodule module="model_gotm" />
<buildmodule module="model_hec_hms" />
<buildmodule module="model_hspf" />
<buildmodule module="model_metaswap"/>
<buildmodule module="model_nemo"/>
Expand Down Expand Up @@ -117,6 +118,7 @@
<docmodule module="model_example_fortran" />
<docmodule module="model_external_socket"/>
<docmodule module="model_external_file"/>
<docmodule module="model_hec_hms"/>
<docmodule module="model_hspf"/>
<docmodule module="model_swan" />
<docmodule module="model_wflow"/>
Expand Down Expand Up @@ -163,6 +165,7 @@
<moduletests module="model_bmi" />
<moduletests module="model_example_blackbox" />
<moduletests module="model_external_socket"/>
<moduletests module="model_hec_hms"/>
<moduletests module="model_swan" />
<moduletests module="model_nemo" />
<moduletests module="model_delft3d"/>
Expand Down Expand Up @@ -287,6 +290,7 @@
<cleanmodule module="model_external_file"/>
<cleanmodule module="model_glm" />
<cleanmodule module="model_gotm" />
<cleanmodule module="model_hec_hms" />
<cleanmodule module="model_hspf" />
<cleanmodule module="model_metaswap" />
<cleanmodule module="model_nemo" />
Expand Down Expand Up @@ -367,6 +371,7 @@
<zipfileset dir="model_glm" prefix="openda_${version}/public/model_glm" excludes="*.svn"/>
<zipfileset dir="model_gotm" prefix="openda_${version}/public/model_gotm" excludes="*.svn"/>
<zipfileset dir="model_hspf" prefix="openda_${version}/public/model_hspf" excludes="*.svn"/>
<zipfileset dir="model_hec_hms" prefix="openda_${version}/public/model_hec_hms" excludes="*.svn"/>
<zipfileset dir="model_metaswap" prefix="openda_${version}/public/model_metaswap" excludes="*.svn"/>
<zipfileset dir="model_nemo" prefix="openda_${version}/public/model_nemo" excludes="*.svn"/>
<zipfileset dir="model_mikeshe" prefix="openda_${version}/public/model_mikeshe" excludes="*.svn"/>
Expand Down Expand Up @@ -571,6 +576,7 @@
<buildmoduletests module="model_example_blackbox" />
<buildmoduletests module="model_example_fortran" />
<buildmoduletests module="model_external_socket" />
<buildmoduletests module="model_hec_hms" />
<buildmoduletests module="model_hspf" />
<buildmoduletests module="model_swan"/>
<buildmoduletests module="model_wflow"/>
Expand All @@ -592,6 +598,7 @@
<buildmoduletests module="model_efdc_dll"/> -->
<buildmoduletests module="model_example_blackbox" />
<buildmoduletests module="model_example_fortran" />
<buildmoduletests module="model_hec_hms" />
<buildmoduletests module="model_hspf" />
<!--<buildmoduletests module="model_swan"/>-->
<buildmoduletests module="model_wflow"/>
Expand Down
22 changes: 11 additions & 11 deletions core/java/src/org/openda/exchange/timeseries/TimeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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
*
Expand Down
20 changes: 14 additions & 6 deletions model_hec_hms/build.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<project xmlns:if="ant:if" name="openDA" default="help" basedir=".">
<project xmlns:if="ant:if" name="model_hec_hms" default="help" basedir=".">
<!--
================================================================================
Ant build file for openda java code
Expand Down Expand Up @@ -126,14 +126,9 @@
</target>

<target name="copy-module-resources">
<!-- copy openda resources and additional binaries -->
<copy todir="${modulelibdir}" flatten="yes">
<!-- copy resources -->
<fileset dir="${resourcesdir}">
<include name="**/*.jar"/>
<include name="**/*.dll"/>
<include name="**/*.DLL"/>
<include name="**/*.so"/>
<include name="**/*.lic"/>
<include name="**/*.LIC"/>
<include name="**/*.xsd"/>
Expand All @@ -144,11 +139,24 @@
<include name="**/*.test"/>
</fileset>
</copy>
<mkdir dir="${modulelibdir}/${winnativelibdir}"/>
<mkdir dir="${modulelibdir}/${linuxnativelibdir}"/>
<copy todir="${modulelibdir}/${winnativelibdir}" flatten="yes">
<fileset dir="${resourcesdir}">
<include name="**/*.dll"/>
</fileset>
</copy>
<copy todir="${modulelibdir}/${linuxnativelibdir}" flatten="yes">
<fileset dir="${resourcesdir}">
<include name="**/*.so"/>
</fileset>
</copy>
<copy todir="${modulebindir}" flatten="yes">
<fileset dir="${external}">
<include name="**/*"/>
</fileset>
</copy>

<chmod dir="${modulebindir}" perm="ugo+rx" includes="**/*.sh"/>
</target>
</project>
38 changes: 38 additions & 0 deletions model_hec_hms/java/model_hec_hms.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="Python" name="Python">
<configuration sdkName="" />
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
</content>
<content url="file://$MODULE_DIR$/../native_bin" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="core" />
<orderEntry type="module" module-name="algorithms" />
<orderEntry type="module" module-name="models" />
<orderEntry type="module" module-name="observers" />
<orderEntry type="library" name="netcdf" level="project" />
<orderEntry type="library" name="CoreResources" level="project" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="file://$MODULE_DIR$/resources" />
</CLASSES>
<JAVADOC />
<NATIVE>
<root url="file://$MODULE_DIR$/resources" />
</NATIVE>
<SOURCES />
<jarDirectory url="file://$MODULE_DIR$/resources" recursive="false" />
</library>
</orderEntry>
</component>
</module>
Binary file not shown.
Binary file added model_hec_hms/java/resources/flogger-0.7.4.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added model_hec_hms/java/resources/hecdss.dll
Binary file not shown.
Binary file added model_hec_hms/java/resources/javaHeclib.dll
Binary file not shown.
Binary file added model_hec_hms/java/resources/jnidispatch.dll
Binary file not shown.
Binary file added model_hec_hms/java/resources/libjavaHeclib.so
Binary file not shown.
Binary file added model_hec_hms/java/resources/slf4j-api-1.7.13.jar
Binary file not shown.
56 changes: 18 additions & 38 deletions model_hec_hms/java/src/org/openda/model_hec_hms/ControlFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, DoubleExchangeItem> exchangeItems = new HashMap<>();
private String timeZoneId = null;

private final Map<Integer, String> lines = new LinkedHashMap<>();
private final Map<Integer, String> valuesToUpdate = new HashMap<>();
Expand All @@ -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)) {
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
}
}
Loading
Loading