diff --git a/.gitignore b/.gitignore index 1f1c025f5..81bef13e3 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ opendaTestReports/ **/MANIFEST.MF **/tests/*.log OpenDATimings_*.txt +*.*~ diff --git a/.travis.yml b/.travis.yml index e62ce0adf..70f43e41d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,6 @@ sudo: required jdk: - openjdk11 - - oraclejdk11 before_install: - sudo apt-get update @@ -18,7 +17,7 @@ before_install: install: ./travis_install.sh -script: ./travis_test.sh +script: ./travis_test.sh #after_script: # - java -cp ~/codacy-coverage-reporter-assembly-latest.jar com.codacy.CodacyCoverageReporter -l Java -r build/reports/jacoco/test/jacocoTestReport.xml diff --git a/algorithms/java/algorithms.iml b/algorithms/java/algorithms.iml index 13472b223..50e667504 100644 --- a/algorithms/java/algorithms.iml +++ b/algorithms/java/algorithms.iml @@ -17,24 +17,6 @@ - - - - - - - - - - - - - - - - - - @@ -53,5 +35,6 @@ + \ No newline at end of file diff --git a/algorithms/java/src/org/openda/algorithms/AbsoluteAveragePerLocationStopCriterion.java b/algorithms/java/src/org/openda/algorithms/AbsoluteAveragePerLocationStopCriterion.java index be5491bcd..dd363b466 100644 --- a/algorithms/java/src/org/openda/algorithms/AbsoluteAveragePerLocationStopCriterion.java +++ b/algorithms/java/src/org/openda/algorithms/AbsoluteAveragePerLocationStopCriterion.java @@ -18,7 +18,7 @@ * along with OpenDA. If not, see . */ package org.openda.algorithms; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.interfaces.IObservationDescriptions; import org.openda.interfaces.IVector; @@ -72,7 +72,7 @@ public boolean checkForStop(IVector parameters, IVector residuals, double cost, public boolean checkForStop(IVector parameters, IVector residuals, IObservationDescriptions descriptions, double cost, double threshold) { boolean isStop = false; this.threshold = threshold; - List items = descriptions.getExchangeItems(); + List items = descriptions.getExchangeItems(); this.nLoc = items.size(); this.isSatisfied = new boolean[this.nLoc]; this.Ids = new String[this.nLoc]; @@ -80,9 +80,8 @@ public boolean checkForStop(IVector parameters, IVector residuals, IObservationD int indLast = 0; double absAvg = 0.0; double maxAbsAvg = Double.NEGATIVE_INFINITY; -// for(IPrevExchangeItem item : items){ // assume the exchangeItems are in the for (int i=0; i. */ package org.openda.algorithms; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.interfaces.IObservationDescriptions; import org.openda.interfaces.IStochObserver; import org.openda.observers.DischargeDependentSelector; @@ -77,13 +77,13 @@ public ObservationSpace applyFilter(ObservationSpace input) { private void stopIfNoSelectedData(IStochObserver observer) { IObservationDescriptions descr = observer.getObservationDescriptions(); - List items; + List items; try{ items = descr.getExchangeItems(); }catch (Exception e) { - items = new ArrayList(); //Empty list + items = new ArrayList(); //Empty list } - for(IPrevExchangeItem item : items){ // assume the exchangeItems are in the + for(IExchangeItem item : items){ // assume the exchangeItems are in the String id = item.getId(); double times[] = item.getTimes(); if (times == null) { @@ -143,11 +143,11 @@ public void initialize(File workingDir, String[] arguments) { } private void logObservationSpace(ObservationSpace observationSpace) throws IOException { - List observationItems = + List observationItems = observationSpace.observer.getObservationDescriptions().getExchangeItems(); String idLine = "obs.EI id's/size"; List obsValues = new ArrayList(); - for (IPrevExchangeItem exchangeItem : observationItems) { + for (IExchangeItem exchangeItem : observationItems) { double[] eiValues = exchangeItem.getValuesAsDoubles(); idLine += "," + exchangeItem.getId() + "=" + eiValues.length; for (double eiValue : eiValues) { diff --git a/algorithms/java/src/org/openda/algorithms/GLUE.java b/algorithms/java/src/org/openda/algorithms/GLUE.java index 53c987213..5af4ca593 100644 --- a/algorithms/java/src/org/openda/algorithms/GLUE.java +++ b/algorithms/java/src/org/openda/algorithms/GLUE.java @@ -39,7 +39,7 @@ public class GLUE extends Instance implements IAlgorithm { private IStochModelFactory stochModelFactory; protected ConfigTree glueConf; - private IStochModelInstance bestEstimate = null; + protected IStochModelInstance bestEstimate = null; private IStochObserver stochObserver = null; private IVector pInit=null; diff --git a/algorithms/java/src/org/openda/algorithms/GriddedFullSearch.java b/algorithms/java/src/org/openda/algorithms/GriddedFullSearch.java index d55884904..4fdc6986a 100644 --- a/algorithms/java/src/org/openda/algorithms/GriddedFullSearch.java +++ b/algorithms/java/src/org/openda/algorithms/GriddedFullSearch.java @@ -40,7 +40,7 @@ public class GriddedFullSearch extends Instance implements IAlgorithm { private IStochModelFactory stochModelFactory; protected ConfigTree gfsConf; - private IStochModelInstance bestEstimate = null; + protected IStochModelInstance bestEstimate = null; private IStochObserver stochObserver = null; private SimulationKwadraticCostFunction J=null; diff --git a/algorithms/java/src/org/openda/algorithms/Powell.java b/algorithms/java/src/org/openda/algorithms/Powell.java index 3e26a7f2e..23edcc535 100644 --- a/algorithms/java/src/org/openda/algorithms/Powell.java +++ b/algorithms/java/src/org/openda/algorithms/Powell.java @@ -40,7 +40,7 @@ public class Powell extends Instance implements IAlgorithm { private IStochModelFactory stochModelFactory; protected ConfigTree powellConf; - private IStochModelInstance bestEstimate = null; + protected IStochModelInstance bestEstimate = null; private SimulationKwadraticCostFunction J=null; private PowellCoreOptimizer powellOptimizer; diff --git a/algorithms/java/src/org/openda/algorithms/RMSECostFunction.java b/algorithms/java/src/org/openda/algorithms/RMSECostFunction.java index 91163cea3..419282ca3 100644 --- a/algorithms/java/src/org/openda/algorithms/RMSECostFunction.java +++ b/algorithms/java/src/org/openda/algorithms/RMSECostFunction.java @@ -383,15 +383,15 @@ public double evaluate(IVector p, String context) { private IVector removeBias(IStochObserver obsSelection, IVector lastPredicted) { IVector prd = lastPredicted.clone(); IObservationDescriptions descr = obsSelection.getObservationDescriptions(); - List items; + List items; try{ - items = (List) descr.getExchangeItems(); + items = (List) descr.getExchangeItems(); }catch (Exception e) { throw new RuntimeException("No observation data is available."); } int firstIndex=0; int lastIndex; - for(IPrevExchangeItem item : items){ + for(IExchangeItem item : items){ String id = item.getId(); double times[] = item.getTimes(); if (times == null) { diff --git a/algorithms/java/src/org/openda/algorithms/SCE.java b/algorithms/java/src/org/openda/algorithms/SCE.java index 3e158052c..4be8b0e82 100644 --- a/algorithms/java/src/org/openda/algorithms/SCE.java +++ b/algorithms/java/src/org/openda/algorithms/SCE.java @@ -29,7 +29,6 @@ import org.openda.utils.io.CalRestartSettings; import java.io.File; -import java.util.ArrayList; import java.util.Random; @@ -44,7 +43,7 @@ public class SCE extends Instance implements IAlgorithm { private IStochModelFactory stochModelFactory; protected ConfigTree sceConf; - private IStochModelInstance bestEstimate = null; + protected IStochModelInstance bestEstimate = null; //config public double initStep=1.0; //scaling factor for initial perturbations of parameters //workspace diff --git a/algorithms/java/src/org/openda/algorithms/Simplex.java b/algorithms/java/src/org/openda/algorithms/Simplex.java index c4fb1185f..09b744cfe 100644 --- a/algorithms/java/src/org/openda/algorithms/Simplex.java +++ b/algorithms/java/src/org/openda/algorithms/Simplex.java @@ -38,12 +38,12 @@ public class Simplex extends Instance implements IAlgorithm { private IStochModelFactory stochModelFactory; protected ConfigTree simplexConf; - private IStochModelInstance bestEstimate = null; + protected IStochModelInstance bestEstimate = null; //config public double initStep=1.0; //scaling factor for initial perturbations of parameters //workspace private SimulationKwadraticCostFunction J=null; - private SimplexCoreOptimizer simplexOptimizer = null; + protected SimplexCoreOptimizer simplexOptimizer = null; private File workingDir=null; private String[] arguments=null; diff --git a/algorithms/java/src/org/openda/algorithms/SimplexCoreOptimizer.java b/algorithms/java/src/org/openda/algorithms/SimplexCoreOptimizer.java index da7f8bd82..d5acdeca6 100644 --- a/algorithms/java/src/org/openda/algorithms/SimplexCoreOptimizer.java +++ b/algorithms/java/src/org/openda/algorithms/SimplexCoreOptimizer.java @@ -58,9 +58,10 @@ public class SimplexCoreOptimizer{ //stopping private boolean moreToDo = true; // is this optimization finished private int imain=0; // main iterations done + private double[] stdValues; - /** + /** * Constructor for Simplex minimization * @param f : cost function to be minimized */ @@ -475,7 +476,8 @@ void next(){ std.sqrt(); // now make this pretty for treeVectors IVector stdWithStructure = this.pCurrent[0].clone(); - stdWithStructure.setValues(std.getValues()); + stdValues = std.getValues(); + stdWithStructure.setValues(stdValues); Results.putMessage("Error estimate for this outer iteration"); Results.putValue( "parameterErrorEstimateStd", stdWithStructure, stdWithStructure.getSize(), "outer iteration "+imain, IResultWriter.OutputLevel.Verbose, @@ -589,4 +591,7 @@ private IVector vectorSum(IVector[] vs){ return result; } + public double[] getStdValues() { + return stdValues; + } } diff --git a/algorithms/java/src/org/openda/algorithms/SimulationKwadraticCostFunction.java b/algorithms/java/src/org/openda/algorithms/SimulationKwadraticCostFunction.java index a08a27f29..c927d3e1c 100644 --- a/algorithms/java/src/org/openda/algorithms/SimulationKwadraticCostFunction.java +++ b/algorithms/java/src/org/openda/algorithms/SimulationKwadraticCostFunction.java @@ -462,13 +462,13 @@ private void logDebugInfo(String modelInstanceName, IStochObserver observationSe // Add model instance identifier to evaluation String message = "Evaluation:," + numberEvaluation + "," + modelInstanceName; debugFileWriter.write(message + "\n"); - List observationItems = + List observationItems = observationSelection.getObservationDescriptions().getExchangeItems(); debugFileWriter.write("obs.id's,size,startIndex\n"); List obsValues = new ArrayList(); List obsTimes = new ArrayList(); int startIndex = 1; - for (IPrevExchangeItem exchangeItem : observationItems) { + for (IExchangeItem exchangeItem : observationItems) { double[] eiValues = exchangeItem.getValuesAsDoubles(); double[] eiTimes = exchangeItem.getTimes(); debugFileWriter.write(exchangeItem.getId() + "," + eiValues.length + "," + startIndex + "\n"); @@ -508,7 +508,7 @@ private void logDebugInfo(String modelInstanceName, IStochObserver observationSe private IVector removeBias(IStochObserver obsSelection, IVector lastPredicted) { IVector prd = lastPredicted.clone(); IObservationDescriptions descr = obsSelection.getObservationDescriptions(); - List items; + List items; try{ items = descr.getExchangeItems(); }catch (Exception e) { @@ -516,7 +516,7 @@ private IVector removeBias(IStochObserver obsSelection, IVector lastPredicted) { } int firstIndex=0; int lastIndex; - for(IPrevExchangeItem item : items){ + for(IExchangeItem item : items){ String id = item.getId(); double times[] = item.getTimes(); if (times == null) { @@ -555,7 +555,7 @@ private IVector removeBias(IStochObserver obsSelection, IVector lastPredicted) { private IVector removeStd(IStochObserver obsSelection, IVector lastPredicted) { IVector prd = lastPredicted.clone(); IObservationDescriptions descr = obsSelection.getObservationDescriptions(); - List items; + List items; try{ items = descr.getExchangeItems(); }catch (Exception e) { @@ -563,7 +563,7 @@ private IVector removeStd(IStochObserver obsSelection, IVector lastPredicted) { } int firstIndex=0; int lastIndex; - for(IPrevExchangeItem item : items){ + for(IExchangeItem item : items){ String id = item.getId(); double times[] = item.getTimes(); if (times == null) { diff --git a/algorithms/java/src/org/openda/algorithms/SparseDud.java b/algorithms/java/src/org/openda/algorithms/SparseDud.java index d40b7f1a8..d8a4cd3ae 100644 --- a/algorithms/java/src/org/openda/algorithms/SparseDud.java +++ b/algorithms/java/src/org/openda/algorithms/SparseDud.java @@ -66,7 +66,7 @@ private int[][] findNonZeros( boolean verbose) { } ConfigTree[] subTrees = configtree.getSubTrees("dependencies/obs"); - List exchangeItems = stochObserver.getObservationDescriptions().getExchangeItems(); + List exchangeItems = stochObserver.getObservationDescriptions().getExchangeItems(); checkDependenciesForAllExchangeItems(subTrees, exchangeItems); boolean[] allParsFound = new boolean[npar]; @@ -97,7 +97,7 @@ private int[][] findNonZeros( boolean verbose) { if ( predFound==0) { String allObservations=""; if (exchangeItems != null) { - for (IPrevExchangeItem exchangeItem : exchangeItems) { + for (IExchangeItem exchangeItem : exchangeItems) { allObservations += "\t'" + exchangeItem.getId() + "'\n"; } } else { @@ -150,9 +150,9 @@ private void checkDependenciesForAllParameters(ArrayList parameterNames, throw new RuntimeException(parsNotFound + " parameter(s) found without any dependency"); } - private void checkDependenciesForAllExchangeItems(ConfigTree[] subTrees, List exchangeItems) { + private void checkDependenciesForAllExchangeItems(ConfigTree[] subTrees, List exchangeItems) { boolean anyExchangeItemNotFound = false; - for (IPrevExchangeItem exchangeItem : exchangeItems) { + for (IExchangeItem exchangeItem : exchangeItems) { String exchangeItemId = exchangeItem.getId(); boolean exchangeItemFound = false; for (ConfigTree subTree : subTrees) { diff --git a/algorithms/java/src/org/openda/algorithms/kalmanFilter/EnKFSeq.java b/algorithms/java/src/org/openda/algorithms/kalmanFilter/EnKFSeq.java index e130fc1dc..eb25e7e6d 100644 --- a/algorithms/java/src/org/openda/algorithms/kalmanFilter/EnKFSeq.java +++ b/algorithms/java/src/org/openda/algorithms/kalmanFilter/EnKFSeq.java @@ -142,7 +142,7 @@ private MinimalObservationDescriptions(double x, double y) { this.y = y; } - public List getExchangeItems() { + public List getExchangeItems() { throw new UnsupportedOperationException(getClass().getName() + ".getExchangeItems() not implemented."); } diff --git a/algorithms/java/test/org/openda/algorithms/DudWithObservationFilterTest.java b/algorithms/java/test/org/openda/algorithms/DudWithObservationFilterTest.java index 67cdcc67f..528463da5 100644 --- a/algorithms/java/test/org/openda/algorithms/DudWithObservationFilterTest.java +++ b/algorithms/java/test/org/openda/algorithms/DudWithObservationFilterTest.java @@ -120,8 +120,8 @@ public IObservationOperator getObservationOperator() { public IVector getObservedValues(IObservationDescriptions observationDescriptions) { TreeVector treeVector = new TreeVector("predictions"); - List items = observationDescriptions.getExchangeItems(); - for(IPrevExchangeItem item : items) { + List items = observationDescriptions.getExchangeItems(); + for(IExchangeItem item : items) { double[] prd = item.getValuesAsDoubles(); for (int i=0; i - - - - - - - - - - - - - - - - - - @@ -42,6 +24,6 @@ - + \ No newline at end of file diff --git a/application/java/test/org/openda/costa/CostaOpendaAppTest.java b/application/java/test/org/openda/costa/CostaOpendaAppTest.java index c1e1cf896..fa91c8223 100644 --- a/application/java/test/org/openda/costa/CostaOpendaAppTest.java +++ b/application/java/test/org/openda/costa/CostaOpendaAppTest.java @@ -24,7 +24,6 @@ import junit.framework.TestCase; import org.openda.application.ApplicationRunner; import org.openda.utils.OpenDaTestSupport; -import org.openda.utils.performance.OdaTiming; import java.io.File; import java.io.IOException; @@ -46,29 +45,29 @@ public static void testDummy() { // the test below is de-activated by renaming it to tst...() } - public void testOscill_EnKF() throws IOException { + public void testOscill_EnKF() { ApplicationRunner.setRunningInTest(true); File config = new File(testRunDataDir, "OscillEnKFOpenDaConfig.xml"); - String args[] = new String[1]; + String[] args = new String[1]; args[0] = config.getAbsolutePath(); org.openda.application.OpenDaApplication.main(args); System.out.println("testOscill_EnKF DONE"); } - public void tstOscill_Simplex() throws IOException { + public void tstOscill_Simplex() { ApplicationRunner.setRunningInTest(true); File config = new File(testRunDataDir, "OscillSimplexOpenDaConfig.xml"); - String args[] = new String[1]; + String[] args = new String[1]; args[0] = config.getAbsolutePath(); org.openda.application.OpenDaApplication.main(args); } // Test with a java observer - public void tstOscill_EnKF2() throws IOException { + public void tstOscill_EnKF2() { ApplicationRunner.setRunningInTest(true); File config = new File(testRunDataDir, "OscillEnKFOpenDaConfig_javaobs.xml"); - String args[] = new String[1]; + String[] args = new String[1]; args[0] = config.getAbsolutePath(); // TODO fails on announce obs. now. org.openda.application.OpenDaApplication.main(args); diff --git a/build.xml b/build.xml index b9cc7a170..582d5196f 100644 --- a/build.xml +++ b/build.xml @@ -78,6 +78,7 @@ + @@ -107,6 +108,7 @@ + @@ -152,6 +154,7 @@ + @@ -269,6 +272,7 @@ + @@ -345,6 +349,7 @@ + @@ -554,6 +559,7 @@ + diff --git a/core/java/core.iml b/core/java/core.iml index 5494fbdee..4edcea51a 100644 --- a/core/java/core.iml +++ b/core/java/core.iml @@ -88,35 +88,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -136,15 +107,6 @@ - - - - - - - - - @@ -165,4 +127,4 @@ - + \ No newline at end of file diff --git a/core/java/resources/openDA/core_castor.jar b/core/java/resources/openDA/core_castor.jar index 0a569c4ff..d45667a64 100644 Binary files a/core/java/resources/openDA/core_castor.jar and b/core/java/resources/openDA/core_castor.jar differ diff --git a/core/java/resources/openDA/core_castor_schemas.zip b/core/java/resources/openDA/core_castor_schemas.zip index a122eaed8..a60ee2525 100644 Binary files a/core/java/resources/openDA/core_castor_schemas.zip and b/core/java/resources/openDA/core_castor_schemas.zip differ diff --git a/core/java/resources/openDA/core_castor_src.zip b/core/java/resources/openDA/core_castor_src.zip index f97f7990f..e51f13e5d 100644 Binary files a/core/java/resources/openDA/core_castor_src.zip and b/core/java/resources/openDA/core_castor_src.zip differ diff --git a/core/java/src/org/openda/blackbox/config/BBModelConfigReader.java b/core/java/src/org/openda/blackbox/config/BBModelConfigReader.java index 882e56835..5ce1e3f00 100644 --- a/core/java/src/org/openda/blackbox/config/BBModelConfigReader.java +++ b/core/java/src/org/openda/blackbox/config/BBModelConfigReader.java @@ -22,7 +22,7 @@ import org.openda.core.io.castorgenerated.*; import org.openda.core.io.castorgenerated.types.BlackBoxModelRoleTypesXML; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.interfaces.ITime; import org.openda.utils.DimensionIndex; import org.openda.utils.Time; @@ -84,7 +84,7 @@ public static BBModelConfig parseBBModelConfig(File modelConfigFile, BlackBoxMod String id; String objectId; String elementId; - IPrevExchangeItem.Role role; + IExchangeItem.Role role; DimensionIndex[] selectionIndices = null; BBConfigurable selectorConfig = null; String idSuffix = null; @@ -92,7 +92,10 @@ public static BBModelConfig parseBBModelConfig(File modelConfigFile, BlackBoxMod // subvector (with indices or selector) BlackBoxIoSubVectorXML subVector = exchangeItemXMLItem.getSubVector(); id = subVector.getId(); - objectId = subVector.getIoObjectId(); + objectId = subVector.getDataObjectId(); + if (objectId == null){ + objectId = subVector.getIoObjectId(); + } elementId = subVector.getElementId(); role = determineRoleType(subVector.getRole()); selectionIndices = parseSelectionIndices(subVector.getSelection()); @@ -101,7 +104,10 @@ public static BBModelConfig parseBBModelConfig(File modelConfigFile, BlackBoxMod // simple vector BlackBoxIoVectorXML vector = exchangeItemXMLItem.getVector(); id = vector.getId(); - objectId = vector.getIoObjectId(); + objectId = vector.getDataObjectId(); + if (objectId == null) { + objectId = vector.getIoObjectId(); + } elementId = vector.getElementId(); role = determineRoleType(vector.getRole()); if (elementId == null) { @@ -110,13 +116,13 @@ public static BBModelConfig parseBBModelConfig(File modelConfigFile, BlackBoxMod idSuffix = vector.getIdSuffix(); } - IoObjectConfig ioObjectConfig = bbWrapperConfig.getIoObject(objectId); - if (ioObjectConfig == null) { + DataObjectConfig dataObjectConfig = bbWrapperConfig.getIoObject(objectId); + if (dataObjectConfig == null) { throw new RuntimeException("ObjectId \"" + objectId + "\" is not specified in the wrapper configuration " + "(model file: " + modelConfigFile.getAbsolutePath() + ", wrapper config. file: " + wrapperConfigFile.getAbsolutePath() + ")"); } - vectorConfigs.add(new BBModelVectorConfig(id, ioObjectConfig, elementId, selectionIndices, selectorConfig, role, idSuffix)); + vectorConfigs.add(new BBModelVectorConfig(id, dataObjectConfig, elementId, selectionIndices, selectorConfig, role, idSuffix)); } ITime startTime = null; @@ -190,15 +196,15 @@ private static DimensionIndex[] SelectionIndices(String index1, String index2, S return selectionIndices; } - private static IPrevExchangeItem.Role determineRoleType(BlackBoxModelRoleTypesXML roleXML) { - IPrevExchangeItem.Role role = IPrevExchangeItem.Role.InOut; + private static IExchangeItem.Role determineRoleType(BlackBoxModelRoleTypesXML roleXML) { + IExchangeItem.Role role = IExchangeItem.Role.InOut; if (roleXML == null) return role; if (roleXML.getType() == BlackBoxModelRoleTypesXML.INPUT_TYPE) { - role = IPrevExchangeItem.Role.Input; + role = IExchangeItem.Role.Input; } else if (roleXML.getType() == BlackBoxModelRoleTypesXML.OUTPUT_TYPE) { - role = IPrevExchangeItem.Role.Output; + role = IExchangeItem.Role.Output; } return role; } diff --git a/core/java/src/org/openda/blackbox/config/BBModelVectorConfig.java b/core/java/src/org/openda/blackbox/config/BBModelVectorConfig.java index a86fb82fc..b091b1ad1 100644 --- a/core/java/src/org/openda/blackbox/config/BBModelVectorConfig.java +++ b/core/java/src/org/openda/blackbox/config/BBModelVectorConfig.java @@ -21,30 +21,30 @@ package org.openda.blackbox.config; import org.openda.interfaces.IDimensionIndex; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; /** * Configuration speficying a subvector in the parameter vector, the state vector, or the predictor vector */ public class BBModelVectorConfig extends BBStochModelVectorConfig { - private IoObjectConfig ioObjectConfig; - private IPrevExchangeItem.Role role; + private DataObjectConfig dataObjectConfig; + private IExchangeItem.Role role; //can be null. private final String idSuffix; - public BBModelVectorConfig(String id, IoObjectConfig ioObjectConfig, String elementId, IDimensionIndex[] selectionIndices, BBConfigurable selectorConfig, IPrevExchangeItem.Role role, String idSuffix) { + public BBModelVectorConfig(String id, DataObjectConfig dataObjectConfig, String elementId, IDimensionIndex[] selectionIndices, BBConfigurable selectorConfig, IExchangeItem.Role role, String idSuffix) { super(id, elementId, selectionIndices, selectorConfig); this.role = role; - this.ioObjectConfig = ioObjectConfig; + this.dataObjectConfig = dataObjectConfig; this.idSuffix = idSuffix; } - public IoObjectConfig getIoObjectConfig() { - return ioObjectConfig; + public DataObjectConfig getDataObjectConfig() { + return dataObjectConfig; } - public IPrevExchangeItem.Role getRole() { + public IExchangeItem.Role getRole() { return role; } diff --git a/core/java/src/org/openda/blackbox/config/BBUtils.java b/core/java/src/org/openda/blackbox/config/BBUtils.java index 0fe64fbba..908d505ff 100644 --- a/core/java/src/org/openda/blackbox/config/BBUtils.java +++ b/core/java/src/org/openda/blackbox/config/BBUtils.java @@ -31,7 +31,10 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.nio.channels.FileChannel; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; /** * TODO: description @@ -117,15 +120,9 @@ public static IDataObject createDataObject(File workingDir, String className, St public static Object createIoOrDataObject(String className) { // Create instance of class - final Class javaClass; - Object object; - try { - javaClass = Class.forName(className); - object = javaClass.newInstance(); - } catch (Exception e) { - throw new RuntimeException("Could not create instance for " + className + ": " + e.getMessage(), e); - } - if (className.equals("org.openda.interfaces.IDataObject") && + Class javaClass = getJavaClass(className); + Object object = getNewInstanceOfJavaClass(className, javaClass); + if (className.equals("org.openda.interfaces.IDataObject") && !IDataObject.class.isInstance(object)) { return null; } @@ -136,7 +133,30 @@ public static Object createIoOrDataObject(String className) { return object; } - public static SelectorInterface createSelectorInstance(File workingDir, String className, String[] arguments) { + private static Object getNewInstanceOfJavaClass(String className, Class javaClass) { + try { + return javaClass.newInstance(); + } catch (InstantiationException | IllegalAccessException e) { + throw new RuntimeException("Could not create instance for " + className + ": " + e.getMessage(), e); + } + } + + private static Class getJavaClass(String className) { + try { + return Class.forName(className); + } catch (ClassNotFoundException e) { + String newDataObjectClassName = IoObjectToDataObjectDictionary.getNewDataObjectClassName(className); + if (newDataObjectClassName == null) throw new RuntimeException("Java class " + className + " not found please check the spelling"); + try { + System.out.println("Class name " + className + " is obsolete, please use new class name " + newDataObjectClassName); + return Class.forName(newDataObjectClassName); + } catch (ClassNotFoundException ex) { + throw new RuntimeException("Programming error: Class from IoObjectToDataObjectDictionary " + newDataObjectClassName + " not found, this should be fixed in the dictionary."); + } + } + } + + public static SelectorInterface createSelectorInstance(File workingDir, String className, String[] arguments) { SelectorInterface selector = (SelectorInterface) ObjectSupport.createNewInstance(className, SelectorInterface.class); selector.initialize(workingDir, arguments); return selector; diff --git a/core/java/src/org/openda/blackbox/config/BBWrapperConfig.java b/core/java/src/org/openda/blackbox/config/BBWrapperConfig.java index f29c2d883..3ad892652 100644 --- a/core/java/src/org/openda/blackbox/config/BBWrapperConfig.java +++ b/core/java/src/org/openda/blackbox/config/BBWrapperConfig.java @@ -31,7 +31,7 @@ public enum CloneType { None, Directory, File } - private HashMap ioObjects = new HashMap(); + private HashMap ioObjects = new HashMap(); private AliasDefinitions aliasDefinitions; private CloneType cloneType; @@ -54,7 +54,7 @@ public BBWrapperConfig(AliasDefinitions aliasDefinitions, Collection computeActions, Collection additionalComputeActions, Collection finalizeActions, - HashMap ioObjects) { + HashMap ioObjects) { this.aliasDefinitions = aliasDefinitions; this.cloneType = cloneType; @@ -123,7 +123,7 @@ public Collection getFinalizeActions() { return finalizeActions; } - public IoObjectConfig getIoObject(String id) { + public DataObjectConfig getIoObject(String id) { return ioObjects.get(id); } diff --git a/core/java/src/org/openda/blackbox/config/BBWrapperConfigReader.java b/core/java/src/org/openda/blackbox/config/BBWrapperConfigReader.java index 29143c013..587af3cb6 100644 --- a/core/java/src/org/openda/blackbox/config/BBWrapperConfigReader.java +++ b/core/java/src/org/openda/blackbox/config/BBWrapperConfigReader.java @@ -33,7 +33,7 @@ */ public class BBWrapperConfigReader { - private BBWrapperConfig bbWrapperConfig; + private final BBWrapperConfig bbWrapperConfig; public BBWrapperConfigReader(File wrapperConfigFile) { @@ -55,34 +55,34 @@ public BBWrapperConfigReader(File wrapperConfigFile) { String instanceName = null; Collection initializeActions; - BlackBoxWrapperRunXMLChoice inititialActionsChoice = bbWrapperConfigXML.getRun().getBlackBoxWrapperRunXMLChoice(); - if (inititialActionsChoice.getInitializeActionsUsingFileClone() != null) { + BlackBoxWrapperRunXMLChoice initialActionsChoice = bbWrapperConfigXML.getRun().getBlackBoxWrapperRunXMLChoice(); + if (initialActionsChoice.getInitializeActionsUsingFileClone() != null) { cloneType = BBWrapperConfig.CloneType.File; - templateName = inititialActionsChoice.getInitializeActionsUsingFileClone().getTemplateFile(); - instanceName = inititialActionsChoice.getInitializeActionsUsingFileClone().getInstanceFile(); + templateName = initialActionsChoice.getInitializeActionsUsingFileClone().getTemplateFile(); + instanceName = initialActionsChoice.getInitializeActionsUsingFileClone().getInstanceFile(); initializeActions = parseActions(wrapperConfigFile, aliasDefinitions, - inititialActionsChoice.getInitializeActionsUsingFileClone().getAction()); - } else if (inititialActionsChoice.getInitializeActionsUsingDirClone() != null) { + initialActionsChoice.getInitializeActionsUsingFileClone().getAction()); + } else if (initialActionsChoice.getInitializeActionsUsingDirClone() != null) { cloneType = BBWrapperConfig.CloneType.Directory; - templateName = inititialActionsChoice.getInitializeActionsUsingDirClone().getTemplateDir(); - instanceName = inititialActionsChoice.getInitializeActionsUsingDirClone().getInstanceDir(); + templateName = initialActionsChoice.getInitializeActionsUsingDirClone().getTemplateDir(); + instanceName = initialActionsChoice.getInitializeActionsUsingDirClone().getInstanceDir(); initializeActions = parseActions(wrapperConfigFile, aliasDefinitions, - inititialActionsChoice.getInitializeActionsUsingDirClone().getAction()); + initialActionsChoice.getInitializeActionsUsingDirClone().getAction()); } else { initializeActions = parseActions(wrapperConfigFile, aliasDefinitions, - inititialActionsChoice.getInitializeActions().getAction()); + initialActionsChoice.getInitializeActions().getAction()); } // parse computate actions and cleanup actions Collection computeActions = parseActions(wrapperConfigFile, aliasDefinitions, bbWrapperConfigXML.getRun().getComputeActions().getAction()); - Collection addionalComputeActions = new ArrayList(); + Collection addionalComputeActions = new ArrayList<>(); if (bbWrapperConfigXML.getRun().getAdditionalComputeActions() != null) { addionalComputeActions = parseActions(wrapperConfigFile, aliasDefinitions, bbWrapperConfigXML.getRun().getAdditionalComputeActions().getAction()); } Collection finalizeActions = parseActions(wrapperConfigFile, aliasDefinitions, bbWrapperConfigXML.getRun().getFinalizeActions().getAction()); // parse IO objects - HashMap ioObjects = parseIoObjects(aliasDefinitions, bbWrapperConfigXML.getInputOutput().getIoObject()); + HashMap ioObjects = parseIoObjects(aliasDefinitions, bbWrapperConfigXML.getInputOutput().getInputOutputXMLItem()); // create the config for all bbWrapperConfig = new BBWrapperConfig(aliasDefinitions, cloneType, templateName, instanceName, @@ -94,12 +94,16 @@ public BBWrapperConfig getBBWrapperConfig() { return bbWrapperConfig; } - private static HashMap parseIoObjects(AliasDefinitions aliasDefinitions, IoObjectXML[] ioObjectXMLs) { - HashMap ioObjects = new HashMap(); - for (IoObjectXML ioObjectXML : ioObjectXMLs) { - ioObjects.put(ioObjectXML.getId(), new IoObjectConfig(ioObjectXML.getId(), ioObjectXML.getClassName(), - ioObjectXML.getFile(), aliasDefinitions, ioObjectXML.getArg())); - } + private static HashMap parseIoObjects(AliasDefinitions aliasDefinitions, InputOutputXMLItem[] ioOrDataObjectXMLs) { + HashMap ioObjects = new HashMap<>(); + for (InputOutputXMLItem inputOutputXMLItem : ioOrDataObjectXMLs) { + DataObjectXML dataObjectXML = inputOutputXMLItem.getIoObject(); + if (dataObjectXML == null) { + dataObjectXML = inputOutputXMLItem.getDataObject(); + } + ioObjects.put(dataObjectXML.getId(), new DataObjectConfig(dataObjectXML.getId(), dataObjectXML.getClassName(), + dataObjectXML.getFile(), aliasDefinitions, dataObjectXML.getArg())); + } return ioObjects; } @@ -153,7 +157,7 @@ public static AliasDefinitions parseAliasDefinitions(AliasDefinitionsXML aliasDe } public static Collection parseActions(File configFile, AliasDefinitions aliasDefinitions, ActionXML[] computeActionsXML) { - ArrayList actions = new ArrayList(); + ArrayList actions = new ArrayList<>(); for (ActionXML actionXML : computeActionsXML) { BBAction bbAction = parseBBAction(configFile, actionXML, aliasDefinitions); if (bbAction != null) { @@ -169,7 +173,7 @@ public static BBAction parseBBAction(File configFile, ActionXML actionXML, Alias return null; } - ArrayList checkOutputs = new ArrayList(); + ArrayList checkOutputs = new ArrayList<>(); for (CheckOutputXML checkOutputXML : actionXML.getCheckOutput()) { checkOutputs.add(new BBCheckOutput(checkOutputXML.getFile(), checkOutputXML.getExpect(), aliasDefinitions)); @@ -182,7 +186,6 @@ public static BBAction parseBBAction(File configFile, ActionXML actionXML, Alias } String exeName = actionXML.getExe(); - String os = System.getProperty("os.name"); if (exeName == null) { if (BBUtils.RUNNING_ON_LINUX) { exeName = actionXML.getLinuxExe(); diff --git a/core/java/src/org/openda/blackbox/config/ConstantLimitsRangeValidationConstraint.java b/core/java/src/org/openda/blackbox/config/ConstantLimitsRangeValidationConstraint.java index 7f033c104..04c05c3ec 100644 --- a/core/java/src/org/openda/blackbox/config/ConstantLimitsRangeValidationConstraint.java +++ b/core/java/src/org/openda/blackbox/config/ConstantLimitsRangeValidationConstraint.java @@ -20,7 +20,7 @@ package org.openda.blackbox.config; import org.openda.exchange.ConstantLimitsRangeValidationExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; /** * Constraint that limits the range of the values of an exchangeItem using a constant lower and/or upper limit. @@ -107,7 +107,7 @@ public String getAffectedExchangeItemId() { * @param affectedExchangeItem the item to be wrapped. * @return rangeValidationExchangeItem that wraps the given item. */ - public IPrevExchangeItem wrapAffectedExchangeItem(IPrevExchangeItem affectedExchangeItem) { + public IExchangeItem wrapAffectedExchangeItem(IExchangeItem affectedExchangeItem) { if (affectedExchangeItem == null) { throw new IllegalArgumentException("affectedExchangeItem is null."); } diff --git a/core/java/src/org/openda/blackbox/config/IoObjectConfig.java b/core/java/src/org/openda/blackbox/config/DataObjectConfig.java similarity index 93% rename from core/java/src/org/openda/blackbox/config/IoObjectConfig.java rename to core/java/src/org/openda/blackbox/config/DataObjectConfig.java index a39f9c6cb..ce0687adf 100644 --- a/core/java/src/org/openda/blackbox/config/IoObjectConfig.java +++ b/core/java/src/org/openda/blackbox/config/DataObjectConfig.java @@ -23,11 +23,11 @@ import java.util.Collection; /** - * Object for storage of the data needed to initialize or reinitialize an IoObject. + * Object for storage of the data needed to initialize or reinitialize a data object. * Now that aliases have become more dynamic, it has become necessary to pass the aliases as * an argument instead of storing them with this config-object. */ -public class IoObjectConfig { +public class DataObjectConfig { private String id; private String className; @@ -39,7 +39,7 @@ public class IoObjectConfig { private Collection aliasesUsedInFileName; private Collection aliasesUsedInArguments; - public IoObjectConfig(String id, String className, String fileName, AliasDefinitions aliasDefinitions, String[] arguments) { + public DataObjectConfig(String id, String className, String fileName, AliasDefinitions aliasDefinitions, String[] arguments) { this.id = id; this.className = className; this.fileName = fileName; diff --git a/core/java/src/org/openda/blackbox/config/IoObjectToDataObjectDictionary.java b/core/java/src/org/openda/blackbox/config/IoObjectToDataObjectDictionary.java new file mode 100644 index 000000000..a6408b0ad --- /dev/null +++ b/core/java/src/org/openda/blackbox/config/IoObjectToDataObjectDictionary.java @@ -0,0 +1,30 @@ +package org.openda.blackbox.config; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public class IoObjectToDataObjectDictionary { + + private static Map map; + + static { + HashMap dictionary = new HashMap<>(); + + dictionary.put("org.openda.blackbox.io.TreeVectorIoObject", "org.openda.blackbox.io.TreeVectorDataObject"); + dictionary.put("org.openda.model_efdc.EfdcTimeSeriesIoObject", "org.openda.model_efdc.EfdcTimeSeriesDataObject"); + dictionary.put("org.openda.model_efdc.EfdcRestartFileIoObject", "org.openda.model_efdc.EfdcRestartFileDataObject"); + dictionary.put("org.openda.model_efdc.EfdcInpIoObject", "org.openda.model_efdc.EfdcInpDataObject"); + dictionary.put("org.openda.model_efdc.EfdcGridTimeSeriesIoObject", "org.openda.model_efdc.EfdcGridTimeSeriesDataObject"); + dictionary.put("org.openda.model_efdc.EfdcEventTox2InpIoObject", "org.openda.model_efdc.EfdcEventTox2InpDataObject"); + dictionary.put("org.openda.blackbox.wrapper.DummyTimeInfoIoObject", "org.openda.blackbox.wrapper.DummyTimeInfoDataObject"); + dictionary.put("org.openda.blackbox.wrapper.DummyParametersIoObject", "org.openda.blackbox.wrapper.DummyParametersDataObject"); + dictionary.put("org.openda.blackbox.wrapper.DummyAstroIoObject", "org.openda.blackbox.wrapper.DummyAstroDataObject"); + + map = Collections.unmodifiableMap(dictionary); + } + + static String getNewDataObjectClassName(String oldIoObjectClassName) { + return map.get(oldIoObjectClassName); + } +} diff --git a/core/java/src/org/openda/blackbox/config/RangeValidationConstraint.java b/core/java/src/org/openda/blackbox/config/RangeValidationConstraint.java index 144a9ea8e..20ae37cc5 100644 --- a/core/java/src/org/openda/blackbox/config/RangeValidationConstraint.java +++ b/core/java/src/org/openda/blackbox/config/RangeValidationConstraint.java @@ -19,7 +19,7 @@ */ package org.openda.blackbox.config; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; /** * Interface to be implemented by classes that can wrap an exchange item in a rangeValidationExchangeItem @@ -53,5 +53,5 @@ public interface RangeValidationConstraint { * @param affectedExchangeItem the item to be wrapped. * @return rangeValidationExchangeItem that wraps the given item. */ - public IPrevExchangeItem wrapAffectedExchangeItem(IPrevExchangeItem affectedExchangeItem); + public IExchangeItem wrapAffectedExchangeItem(IExchangeItem affectedExchangeItem); } diff --git a/core/java/src/org/openda/blackbox/interfaces/IoObjectInterface.java b/core/java/src/org/openda/blackbox/interfaces/IoObjectInterface.java index 9b31a2593..496c17a09 100644 --- a/core/java/src/org/openda/blackbox/interfaces/IoObjectInterface.java +++ b/core/java/src/org/openda/blackbox/interfaces/IoObjectInterface.java @@ -20,7 +20,7 @@ package org.openda.blackbox.interfaces; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import java.io.File; @@ -42,7 +42,7 @@ public interface IoObjectInterface { * Ask which elements can be accessed * @return The list of element identifiers that can be accessed */ - public IPrevExchangeItem[] getExchangeItems(); // + public IExchangeItem[] getExchangeItems(); // public void finish(); } diff --git a/core/java/src/org/openda/blackbox/io/BaseTemplateDataObject.java b/core/java/src/org/openda/blackbox/io/BaseTemplateDataObject.java index edaa99c82..e762cb3a2 100644 --- a/core/java/src/org/openda/blackbox/io/BaseTemplateDataObject.java +++ b/core/java/src/org/openda/blackbox/io/BaseTemplateDataObject.java @@ -23,7 +23,6 @@ import org.openda.exchange.TemplateKeyExchangeItem; import org.openda.interfaces.IExchangeItem; import org.openda.interfaces.IDataObject; -import org.openda.interfaces.IPrevExchangeItem; import java.io.File; import java.io.FileOutputStream; @@ -63,24 +62,24 @@ public void initialize(File workingDir, String fileName, String[] arguments) { } } - public IPrevExchangeItem[] getExchangeItems() { + public IExchangeItem[] getExchangeItems() { return exchangeItems; } public String[] getExchangeItemIDs() { - if (exchangeItems == null) return new String[]{}; - IPrevExchangeItem[] items = getExchangeItems(); + if (exchangeItems == null) return new String[]{}; + IExchangeItem[] items = getExchangeItems(); String[] ids = new String[items.length]; int k=0; - for (IPrevExchangeItem exchangeItem : items) { + for (IExchangeItem exchangeItem : items) { ids[k++] = exchangeItem.getId(); } return ids; } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { return getExchangeItemIDs(); } @@ -88,7 +87,7 @@ public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { public IExchangeItem getDataObjectExchangeItem(String exchangeItemID) { int indexExchangeItem = Integer.MAX_VALUE; - IPrevExchangeItem[] items = getExchangeItems(); + IExchangeItem[] items = getExchangeItems(); for (int i = 0; i < items.length; i++) { if (exchangeItemID.equals(items[i].getId())) { indexExchangeItem = i; @@ -101,7 +100,7 @@ public IExchangeItem getDataObjectExchangeItem(String exchangeItemID) { if (!(items[indexExchangeItem] instanceof IExchangeItem)) { throw new RuntimeException("Found exchange item is not instance of IExchangeItem " + exchangeItemID); } - return (IExchangeItem)items[indexExchangeItem]; + return items[indexExchangeItem]; } } @@ -149,7 +148,7 @@ public void writeValuesFile(String filename, boolean overwriteExistingFiles) { } public void writeValuesFile(PrintWriter printer) { - for (IPrevExchangeItem exchangeItem: exchangeItems) { + for (IExchangeItem exchangeItem: exchangeItems) { printer.println(exchangeItem.getId() + "=" + exchangeItem.getValues()); } diff --git a/core/java/src/org/openda/blackbox/io/TreeVectorIoObject.java b/core/java/src/org/openda/blackbox/io/TreeVectorDataObject.java similarity index 65% rename from core/java/src/org/openda/blackbox/io/TreeVectorIoObject.java rename to core/java/src/org/openda/blackbox/io/TreeVectorDataObject.java index bf1e903a4..0d73b4b05 100644 --- a/core/java/src/org/openda/blackbox/io/TreeVectorIoObject.java +++ b/core/java/src/org/openda/blackbox/io/TreeVectorDataObject.java @@ -18,9 +18,9 @@ * along with OpenDA. If not, see . */ package org.openda.blackbox.io; -import org.openda.blackbox.interfaces.IoObjectInterface; -import org.openda.interfaces.IPrevExchangeItem; -import org.openda.interfaces.ITreeVector; + +import org.openda.exchange.AbstractDataObject; +import org.openda.interfaces.*; import org.openda.utils.Vector; import org.openda.utils.io.TreeVectorReader; import org.openda.utils.io.TreeVectorWriter; @@ -31,49 +31,40 @@ /** * IoObject based on treevector xml-file */ -public class TreeVectorIoObject implements IoObjectInterface { +public class TreeVectorDataObject extends AbstractDataObject { private File treeVectorFile = null; private ITreeVector treeVector = null; private boolean exportAsOneExchangeItem = false; - private final String exportAsOneExchangeItemString = "OneExchangeItem"; - private IPrevExchangeItem[] exchangeItems = null; - public void initialize(File workingDir, String fileName, String[] arguments) { - treeVectorFile = new File(workingDir, fileName); - if (arguments.length > 0) { - if (arguments.length != 1) { + @Override + public void initialize(File workingDir, String[] arguments) { + treeVectorFile = new File(workingDir, arguments[0]); + if (arguments.length > 1) { + if (arguments.length != 2) { throw new RuntimeException(this.getClass().getName() + ".initialize()expects only one (optional) argument. TreeVector file: " + treeVectorFile.getAbsolutePath()); } - if(arguments[0].equalsIgnoreCase(exportAsOneExchangeItemString)) { + String exportAsOneExchangeItemString = "OneExchangeItem"; + if(arguments[1].equalsIgnoreCase(exportAsOneExchangeItemString)) { exportAsOneExchangeItem = true; } } TreeVectorReader treeVectorReader = new TreeVectorReader(treeVectorFile); treeVector = treeVectorReader.readTreeVector(); - } - public IPrevExchangeItem[] getExchangeItems() { - if (treeVectorFile == null) { - throw new RuntimeException(this.getClass().getName() + ": IoObject has not been initialized"); - } - if (exchangeItems == null) { - if (exportAsOneExchangeItem) { - exchangeItems = new IPrevExchangeItem[] {new TreeVectorIoObjectExchangeItem(treeVector)}; - } else { - ArrayList subTreeVectorIds = treeVector.getSubTreeVectorIds(); - exchangeItems = new IPrevExchangeItem[subTreeVectorIds.size()]; - for (int i = 0, subTreeVectorIdsSize = subTreeVectorIds.size(); i < subTreeVectorIdsSize; i++) { - String childId = subTreeVectorIds.get(i); - exchangeItems[i] = new TreeVectorIoObjectExchangeItem(treeVector.getSubTreeVector(childId)); - } + if (exportAsOneExchangeItem) { + exchangeItems.put(treeVector.getId(), new TreeVectorIoObjectExchangeItem(treeVector)); + } else { + ArrayList subTreeVectorIds = treeVector.getSubTreeVectorIds(); + for (String childId : subTreeVectorIds) { + exchangeItems.put(childId, new TreeVectorIoObjectExchangeItem(treeVector.getSubTreeVector(childId))); } } - return exchangeItems; } + @Override public void finish() { if (treeVectorFile == null) { throw new RuntimeException(this.getClass().getName() + ": IoObject has not been initialized"); @@ -87,11 +78,11 @@ public String toString() { return treeVectorFile.toString(); } - private class TreeVectorIoObjectExchangeItem implements IPrevExchangeItem { + private static class TreeVectorIoObjectExchangeItem implements IExchangeItem { private ITreeVector treeVector; - public TreeVectorIoObjectExchangeItem(ITreeVector treeVector) { + private TreeVectorIoObjectExchangeItem(ITreeVector treeVector) { this.treeVector = treeVector; } @@ -103,13 +94,27 @@ public String getDescription() { return treeVector.getDescription(); } - public Class getValueType() { + @Override + public void copyValuesFromItem(IExchangeItem sourceItem) { + throw new RuntimeException("org.openda.blackbox.io.TreeVectorIoObject.TreeVectorIoObjectExchangeItem.copyValuesFromItem not implemented"); + } + + public IQuantityInfo getQuantityInfo() { return null; } + + public IGeometryInfo getGeometryInfo() { return null; } + + @Override + public ValueType getValuesType() { + throw new RuntimeException("org.openda.blackbox.io.TreeVectorIoObject.TreeVectorIoObjectExchangeItem.getValuesType not implemented"); + } + + public Class getValueType() { return double[].class; } - public Role getRole() { - return IPrevExchangeItem.Role.InOut; - } + public IExchangeItem.Role getRole() { + return IExchangeItem.Role.InOut; + } public Object getValues() { return getValuesAsDoubles(); @@ -135,10 +140,12 @@ public void setValues(Object values) { setValuesAsDoubles((double[]) values); } - public void setValuesAsDoubles(double[] values) { + public void setValuesAsDoubles(double[] values) { treeVector.setValues(values); } + public ITimeInfo getTimeInfo() { return null; } + public double[] getTimes() { return null; } diff --git a/core/java/src/org/openda/blackbox/wrapper/BBCollectTimeSeriesExchangeItem.java b/core/java/src/org/openda/blackbox/wrapper/BBCollectTimeSeriesExchangeItem.java index bea5d1446..ee3034241 100644 --- a/core/java/src/org/openda/blackbox/wrapper/BBCollectTimeSeriesExchangeItem.java +++ b/core/java/src/org/openda/blackbox/wrapper/BBCollectTimeSeriesExchangeItem.java @@ -28,12 +28,12 @@ **/ public class BBCollectTimeSeriesExchangeItem implements IExchangeItem { - private IPrevExchangeItem modelExchangeItem; + private IExchangeItem modelExchangeItem; private ArrayList concatenatedValues = new ArrayList(); private ArrayList concatenatedTimes = new ArrayList(); // private Class valueType; - public BBCollectTimeSeriesExchangeItem(IPrevExchangeItem modelExchangeItem) + public BBCollectTimeSeriesExchangeItem(IExchangeItem modelExchangeItem) { this.modelExchangeItem = modelExchangeItem; // this.valueType = modelExchangeItem.getValueType(); @@ -45,10 +45,7 @@ public void UpdateTimeStepValue(ITime time, double value) { concatenatedTimes.add(time.getMJD()); } - - public Role getRole() { - return modelExchangeItem.getRole(); - } + public IExchangeItem.Role getRole() { return null; } public String getId() { diff --git a/core/java/src/org/openda/blackbox/wrapper/BBExchangeItem.java b/core/java/src/org/openda/blackbox/wrapper/BBExchangeItem.java index a407803bb..b17e51551 100644 --- a/core/java/src/org/openda/blackbox/wrapper/BBExchangeItem.java +++ b/core/java/src/org/openda/blackbox/wrapper/BBExchangeItem.java @@ -39,12 +39,12 @@ public class BBExchangeItem implements IExchangeItem { private String id; private String description = null; private BBStochModelVectorConfig vectorConfig; - private IPrevExchangeItem ioObjectExchangeItem; + private IExchangeItem ioObjectExchangeItem; private HashMap selectors; private File configRootDir; public BBExchangeItem(String id, BBStochModelVectorConfig vectorConfig, - IPrevExchangeItem ioObjectExchangeItem, + IExchangeItem ioObjectExchangeItem, HashMap selectors, File configRootDir) { this.id = id; this.vectorConfig = vectorConfig; @@ -65,41 +65,15 @@ public String getDescription() { return description; } - public Class getValueType() { - return ioObjectExchangeItem.getValueType(); - } - public ValueType getValuesType() { - ValueType result; - if(ioObjectExchangeItem.getValueType()==double.class){ - result=ValueType.doubleType; - }else if(ioObjectExchangeItem.getValueType()==double[].class){ - result=ValueType.doublesType; - }else if(ioObjectExchangeItem.getValueType()==float[].class){ - result=ValueType.floatsType; - }else if(ioObjectExchangeItem.getValueType()==double[][].class){ - result=ValueType.doubles2dType; - }else if(ioObjectExchangeItem.getValueType()==int.class){ - result=ValueType.intType; - }else if(ioObjectExchangeItem.getValueType()==String.class){ - result=ValueType.StringType; - }else if(ioObjectExchangeItem.getValueType()==IVector.class){ - result=ValueType.IVectorType; - }else if(ioObjectExchangeItem.getValueType()==IArray.class){ - result=ValueType.IArrayType; - }else{ - throw new RuntimeException("BBExchangeItem: unsupported ValueType"); - } - return result; + return ioObjectExchangeItem.getValuesType(); } - public Role getRole() { - return ioObjectExchangeItem.getRole(); - } + public Role getRole() {return Role.InOut; } public Object getValues() { - Class valueType = ioObjectExchangeItem.getValueType(); + ValueType valueType = ioObjectExchangeItem.getValuesType(); Object valuesObject = ioObjectExchangeItem.getValues(); @@ -115,19 +89,19 @@ public Object getValues() { } return selectorResult; } else if (vectorConfig.getSelectionIndices() != null) { - if ( valueType != IVector.class && valueType != ITreeVector.class && valueType != double[].class && valueType != IArray.class) { + if ( valueType != ValueType.IVectorType && valueType != ValueType.doublesType && valueType != ValueType.IArrayType) { throw new RuntimeException("Index selection can not be applied on values of type " + valueType); } IDimensionIndex[] selectionIndices = vectorConfig.getSelectionIndices(); double[] orgValues = ioObjectExchangeItem.getValuesAsDoubles(); int[] dimSizes; - if (valueType == double[].class) { + if (valueType == ValueType.doublesType) { dimSizes = new int[1]; dimSizes[0] = orgValues.length; - } else if (valueType == IArray.class) { + } else if (valueType == ValueType.IArrayType) { dimSizes = ((IArray) valuesObject).getDimensions(); - } else if (valueType == IVector.class) { + } else if (valueType == ValueType.IVectorType) { dimSizes = getDimensionSizes((IVector) valuesObject); } else { throw new RuntimeException("BBModelInstance.getValues: method not implemented for type " + valuesObject.getClass().getName()); @@ -259,7 +233,7 @@ public void setValues(Object values) { // setvalues without selections if (values instanceof double[]){ ioObjectExchangeItem.setValuesAsDoubles((double[]) values); - } else if (ioObjectExchangeItem.getValueType() == double.class) { + } else if (ioObjectExchangeItem.getValuesType() == ValueType.doubleType) { if (values instanceof Double) { setBaseOrOrgExchangeItemValues(values); } else if (values instanceof IVector) { @@ -271,7 +245,7 @@ public void setValues(Object values) { setBaseOrOrgExchangeItemValues(vector.getValue(0)); } } else { - ObjectSupport.checkCompatibility(values, ioObjectExchangeItem.getValueType(), + ObjectSupport.checkCompatibility(values, ioObjectExchangeItem.getValuesType().getClass(), this.getClass().getName() + ".setValues()"); setBaseOrOrgExchangeItemValues(values); } @@ -304,9 +278,9 @@ private void setBaseOrOrgExchangeItemValues(Object values) { } public void copyValuesFromItem(IExchangeItem sourceItem) { - if (sourceItem.getValueType() != getValueType()) { + if (sourceItem.getValuesType() != getValuesType()) { throw new RuntimeException("Incompatible value types in copy action from " + sourceItem.getId() + - " to " + getId() + "(" + sourceItem.getValueType().toString() + "/=" + getValueType().toString()); + " to " + getId() + "(" + sourceItem.getValuesType().toString() + "/=" + getValuesType().toString()); } setValues(sourceItem.getValues()); } diff --git a/core/java/src/org/openda/blackbox/wrapper/BBModelInstance.java b/core/java/src/org/openda/blackbox/wrapper/BBModelInstance.java index 5b1e0d27f..93def2ba4 100644 --- a/core/java/src/org/openda/blackbox/wrapper/BBModelInstance.java +++ b/core/java/src/org/openda/blackbox/wrapper/BBModelInstance.java @@ -44,6 +44,7 @@ */ public class BBModelInstance extends Instance implements IModelInstance { private final String ALL_ELEMENTS_FROM_IO_OBJECT = "allElementsFromIoObject"; + private final String ALL_ELEMENTS_FROM_DATA_OBJECT = "allElementsFromDataObject"; protected BBModelConfig bbModelConfig; @@ -195,7 +196,7 @@ private void determineTimeHorizon() { if (timeStepExchangeItemIds!=null){ if (timeStepExchangeItemIds[0] != null){ for (int n=0; n < timeStepExchangeItemIds.length; n++){ - IPrevExchangeItem timeExchangeItem = getExchangeItem(timeStepExchangeItemIds[n]); + IExchangeItem timeExchangeItem = getExchangeItem(timeStepExchangeItemIds[n]); timeStepMJD = timeExchangeItem.getValuesAsDoubles()[0]; if (!Double.isNaN(timeStepMJD)){ break; @@ -277,7 +278,7 @@ public String[] getExchangeItemIDs() { /** * Note: this method also works in combination with the option "allElementsFromIoObject". */ - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { checkForPendingComputeActions(); List exchangeItemIds = new ArrayList(); @@ -296,18 +297,18 @@ public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { private void addAllExchangeItemIdsFromVectorConfig(BBModelVectorConfig vectorConfig, List bbExchangeItemIds) { String idSuffix = vectorConfig.getIdSuffix(); - if (vectorConfig.getId().equalsIgnoreCase(ALL_ELEMENTS_FROM_IO_OBJECT)) { + if (vectorConfig.getId().equalsIgnoreCase(ALL_ELEMENTS_FROM_IO_OBJECT) || vectorConfig.getId().equalsIgnoreCase(ALL_ELEMENTS_FROM_DATA_OBJECT)) { //add all exchange item ids from ioObject or dataObject. - IoObjectInterface ioObject = findOrCreateIoObject(vectorConfig.getIoObjectConfig()); + IoObjectInterface ioObject = findOrCreateIoObject(vectorConfig.getDataObjectConfig()); if (ioObject != null) { - for (IPrevExchangeItem sourceItem : ioObject.getExchangeItems()) { + for (IExchangeItem sourceItem : ioObject.getExchangeItems()) { //for allElementsFromIoObject the bbExchangeItemId is the same as the sourceId. String bbExchangeItemId = sourceItem.getId(); if (idSuffix != null) bbExchangeItemId += idSuffix; bbExchangeItemIds.add(bbExchangeItemId); } } else { - IDataObject dataObject = findOrCreateDataObject(vectorConfig.getIoObjectConfig()); + IDataObject dataObject = findOrCreateDataObject(vectorConfig.getDataObjectConfig()); if (dataObject != null) { String[] sourceIds = dataObject.getExchangeItemIDs(); //for allElementsFromIoObject the bbExchangeItemId is the same as the sourceId. @@ -316,7 +317,7 @@ private void addAllExchangeItemIdsFromVectorConfig(BBModelVectorConfig vectorCon bbExchangeItemIds.add(bbExchangeItemId); } } else { - throw new IllegalArgumentException("IoObject or DataObject could not be created for \"" + vectorConfig.getIoObjectConfig().getId(this.aliasDefinitions) + "\""); + throw new IllegalArgumentException("IoObject or DataObject could not be created for \"" + vectorConfig.getDataObjectConfig().getId(this.aliasDefinitions) + "\""); } } } else { @@ -327,14 +328,14 @@ private void addAllExchangeItemIdsFromVectorConfig(BBModelVectorConfig vectorCon } public IExchangeItem getDataObjectExchangeItem(String exchangeItemID) { - IPrevExchangeItem exchangeItem = getExchangeItem(exchangeItemID); + IExchangeItem exchangeItem = getExchangeItem(exchangeItemID); if (!(exchangeItem instanceof BBExchangeItem)) { throw new RuntimeException("Unexpected exchange item type " + exchangeItem.getClass().toString()); } return (BBExchangeItem) exchangeItem; } - public IPrevExchangeItem getExchangeItem(String searchedBBExchangeItemId) { + public IExchangeItem getExchangeItem(String searchedBBExchangeItemId) { checkForPendingComputeActions(); BBExchangeItem bbExchangeItem = bbExchangeItems.get(searchedBBExchangeItemId); @@ -343,19 +344,19 @@ public IPrevExchangeItem getExchangeItem(String searchedBBExchangeItemId) { BBModelVectorConfig vectorConfig = findVectorConfig(searchedBBExchangeItemId); if (vectorConfig != null) { //find exchangeItem for vectorConfig that does not have id="allElementsFromIoObject". - IoObjectInterface ioObject = findOrCreateIoObject(vectorConfig.getIoObjectConfig()); + IoObjectInterface ioObject = findOrCreateIoObject(vectorConfig.getDataObjectConfig()); if (ioObject != null) { - for (IPrevExchangeItem sourceItem : ioObject.getExchangeItems()) { + for (IExchangeItem sourceItem : ioObject.getExchangeItems()) { String sourceId = sourceItem.getId(); if (sourceId.equalsIgnoreCase(vectorConfig.getSourceId())) { - bbExchangeItem = new BBExchangeItem(searchedBBExchangeItemId, vectorConfig, sourceItem, + bbExchangeItem = new BBExchangeItem(searchedBBExchangeItemId, vectorConfig, (IExchangeItem)sourceItem, selectors, bbModelConfig.getConfigRootDir()); break; } newExchangeItemIDs.add(sourceId); } } else { - IDataObject dataObject = findOrCreateDataObject(vectorConfig.getIoObjectConfig()); + IDataObject dataObject = findOrCreateDataObject(vectorConfig.getDataObjectConfig()); if (dataObject != null) { for (String sourceId : dataObject.getExchangeItemIDs()) { if (sourceId.equalsIgnoreCase(vectorConfig.getSourceId())) { @@ -367,7 +368,7 @@ public IPrevExchangeItem getExchangeItem(String searchedBBExchangeItemId) { } } else { throw new IllegalArgumentException("IoObject or DataObject could not be created for \"" + - vectorConfig.getIoObjectConfig().getId(this.aliasDefinitions) + "\""); + vectorConfig.getDataObjectConfig().getId(this.aliasDefinitions) + "\""); } } @@ -380,21 +381,21 @@ public IPrevExchangeItem getExchangeItem(String searchedBBExchangeItemId) { for (BBModelVectorConfig allElementVectorConfig : allElementVectorConfigs) { String idSuffix = allElementVectorConfig.getIdSuffix(); - IoObjectInterface ioObject = findOrCreateIoObject(allElementVectorConfig.getIoObjectConfig()); + IoObjectInterface ioObject = findOrCreateIoObject(allElementVectorConfig.getDataObjectConfig()); if (ioObject != null) { - for (IPrevExchangeItem sourceItem : ioObject.getExchangeItems()) { + for (IExchangeItem sourceItem : ioObject.getExchangeItems()) { //for allElementsFromIoObject the bbExchangeItemId is the same as the sourceId. String bbExchangeItemId = sourceItem.getId(); if (idSuffix != null) bbExchangeItemId += idSuffix; if (bbExchangeItemId.equalsIgnoreCase(searchedBBExchangeItemId)) { - bbExchangeItem = new BBExchangeItem(searchedBBExchangeItemId, allElementVectorConfig, sourceItem, + bbExchangeItem = new BBExchangeItem(searchedBBExchangeItemId, allElementVectorConfig, (IExchangeItem)sourceItem, selectors, bbModelConfig.getConfigRootDir()); break; } newExchangeItemIDs.add(sourceItem.getId()); } } else { - IDataObject dataObject = findOrCreateDataObject(allElementVectorConfig.getIoObjectConfig()); + IDataObject dataObject = findOrCreateDataObject(allElementVectorConfig.getDataObjectConfig()); if (dataObject != null) { for (String sourceId : dataObject.getExchangeItemIDs()) { //for allElementsFromIoObject the bbExchangeItemId is the same as the sourceId. @@ -409,7 +410,7 @@ public IPrevExchangeItem getExchangeItem(String searchedBBExchangeItemId) { } } else { throw new IllegalArgumentException("IoObject or DataObject could not be created for \"" + - allElementVectorConfig.getIoObjectConfig().getId(this.aliasDefinitions) + "\""); + allElementVectorConfig.getDataObjectConfig().getId(this.aliasDefinitions) + "\""); } } @@ -612,7 +613,7 @@ private BBModelVectorConfig findVectorConfig(String searchedBBExchangeItemId) { private List findAllVectorConfigsWithAllElementsFromIoObject() { List allElementsVectorConfigs = new ArrayList(); for (BBModelVectorConfig vectorConfig : bbModelConfig.getVectorConfigs()) { - if (vectorConfig.getId().equalsIgnoreCase(ALL_ELEMENTS_FROM_IO_OBJECT)) { + if (vectorConfig.getId().equalsIgnoreCase(ALL_ELEMENTS_FROM_IO_OBJECT) || vectorConfig.getId().equalsIgnoreCase(ALL_ELEMENTS_FROM_DATA_OBJECT)) { allElementsVectorConfigs.add(vectorConfig); } } @@ -620,7 +621,7 @@ private List findAllVectorConfigsWithAllElementsFromIoObjec } - private IoObjectInterface findOrCreateIoObject(IoObjectConfig ioObjectConfig) { + private IoObjectInterface findOrCreateIoObject(DataObjectConfig ioObjectConfig) { // find or create io object IoObjectInterface ioObject = ioObjects.get(ioObjectConfig.getId(this.aliasDefinitions)); @@ -638,7 +639,7 @@ private IoObjectInterface findOrCreateIoObject(IoObjectConfig ioObjectConfig) { return ioObject; } - private IDataObject findOrCreateDataObject(IoObjectConfig ioObjectConfig) { + private IDataObject findOrCreateDataObject(DataObjectConfig ioObjectConfig) { // find or create io object IDataObject dataObject = dataObjects.get(ioObjectConfig.getId(this.aliasDefinitions)); @@ -720,14 +721,13 @@ private void feedComputationSpanToModel(ITime computationStart, ITime computatio private ITime getStartOrEndTime(String timeExchangeItemId) { ITime startOrEndTime = null; if (timeExchangeItemId != null) { - IPrevExchangeItem timeExchangeItem = getExchangeItem(timeExchangeItemId); - if (timeExchangeItem.getRole() != IPrevExchangeItem.Role.Input) { - if (timeExchangeItem.getValueType() == Date.class) { + IExchangeItem timeExchangeItem = getExchangeItem(timeExchangeItemId); + if (timeExchangeItem.getRole() != IExchangeItem.Role.Input) { + if (timeExchangeItem.getValuesType() == IExchangeItem.ValueType.DateType) { startOrEndTime = new Time((Date)timeExchangeItem.getValues()); - } else if (timeExchangeItem.getValueType() == ITime.class) { + } else if (timeExchangeItem.getValuesType() == IExchangeItem.ValueType.ITimeType) { startOrEndTime = (ITime) timeExchangeItem.getValues(); - } else if (timeExchangeItem.getValueType() == double.class || - timeExchangeItem.getValueType() == Double.class) { + } else if (timeExchangeItem.getValuesType() == IExchangeItem.ValueType.doubleType ) { startOrEndTime = new Time((Double)timeExchangeItem.getValues()); } } @@ -737,15 +737,14 @@ private ITime getStartOrEndTime(String timeExchangeItemId) { private void setStartOrEndTime(ITime startOrEndTime, String timeExchangeItemId) { if (timeExchangeItemId != null) { - IPrevExchangeItem timeExchangeItem = getExchangeItem(timeExchangeItemId); - if (timeExchangeItem.getRole() != IPrevExchangeItem.Role.Output) { - if (timeExchangeItem.getValueType() == Date.class) { + IExchangeItem timeExchangeItem = getExchangeItem(timeExchangeItemId); + if (timeExchangeItem.getRole() != IExchangeItem.Role.Output) { + if (timeExchangeItem.getValuesType() == IExchangeItem.ValueType.DateType) { Date startOrEndTimeAsJavaDate = new Date(Time.mjdToMillies(startOrEndTime.getMJD())); timeExchangeItem.setValues(startOrEndTimeAsJavaDate); - } else if (timeExchangeItem.getValueType() == ITime.class) { + } else if (timeExchangeItem.getValuesType() == IExchangeItem.ValueType.ITimeType) { timeExchangeItem.setValues(startOrEndTime); - } else if (timeExchangeItem.getValueType() == double.class || - timeExchangeItem.getValueType() == Double.class) { + } else if (timeExchangeItem.getValuesType() == IExchangeItem.ValueType.doubleType) { timeExchangeItem.setValues(startOrEndTime.getMJD()); } } diff --git a/core/java/src/org/openda/blackbox/wrapper/BBStochModelInstance.java b/core/java/src/org/openda/blackbox/wrapper/BBStochModelInstance.java index a909c78bf..5133cccae 100644 --- a/core/java/src/org/openda/blackbox/wrapper/BBStochModelInstance.java +++ b/core/java/src/org/openda/blackbox/wrapper/BBStochModelInstance.java @@ -57,7 +57,7 @@ public class BBStochModelInstance extends Instance implements IStochModelInstanc private OdaTiming timerGetObs = null; private OdaTiming timerGetState = null; - private List collectTimeSeriesBbExchangeItems = new ArrayList(); + private List collectTimeSeriesBbExchangeItems = new ArrayList<>(); private File configRootDir; protected IModelInstance model; @@ -68,22 +68,22 @@ public class BBStochModelInstance extends Instance implements IStochModelInstanc protected int[] stateNoiseModelsEndIndices = null; protected int[] stateVectorsEndIndices = null; private boolean doAutomaticNoiseGeneration = false; - private String savedStatesDirPrefix = null; - private String savedStatesNoiseModelPrefix = null; - private String modelSavedStateFile = null; - private UncertaintyEngine uncertaintyEngine = null; + private String savedStatesDirPrefix; + private String savedStatesNoiseModelPrefix; + private String modelSavedStateFile; + private UncertaintyEngine uncertaintyEngine; private IStochVector parameterUncertainty; private ITreeVector paramsTreeVector; private HashMap lastNoiseTimes;//avoid adding noise more than once private LinkedHashMap> dataObjectBoundaryMappings; private int ensembleMemberIndex; - private HashMap prevNoiseModelEIValuesForTimeStep = new HashMap(); + private HashMap prevNoiseModelEIValuesForTimeStep = new HashMap<>(); private boolean warningLogged = false; // files for local analysis private boolean useLocalAnalysis = true; // TODO: SH: add it to BB Stoch Model config private List noiseModelsInState = new ArrayList<>(); - private List modelExchangeItemsInState = new ArrayList<>(); // TODO: check if all models that support local analysis have no longer IPrevExchangeItems + private List modelExchangeItemsInState = new ArrayList<>(); public IObservationOperator getObservationOperator(){ return new ObservationOperatorDeprecatedModel(this); @@ -93,14 +93,14 @@ public IObservationOperator getObservationOperator(){ * For each constraintExchangeItemId for which there is a range validation constraint this map contains * the corresponding RangeValidationConstraint object. */ - private Map constraintExchangeItemIdConstraintMap = new LinkedHashMap(); + private Map constraintExchangeItemIdConstraintMap = new LinkedHashMap<>(); /** * All constraintExchangeItems that have been constructed so far are stored in this map. * This list is filled lazily, i.e. a constraintExchangeItem with constraint(s) is constructed (by wrapping the affected exchangeItem) * when it is first requested in method BBStochModelInstance.getExchangeItem. This is needed because * some (e.g. output) exchangeItems are not initialized when the model has not run yet. */ - private Map constraintExchangeItems = new LinkedHashMap(); + private Map constraintExchangeItems; private IObservationDescriptions observationDescriptions; public BBStochModelInstance(File configRootDir, IModelInstance model, @@ -134,10 +134,10 @@ public BBStochModelInstance(File configRootDir, IModelInstance model, this.modelSavedStateFile = modelSavedStateFile; this.dataObjectBoundaryMappings = dataObjectBoundaryMappings; this.ensembleMemberIndex = ensembleMemberIndex; - selectors = new LinkedHashMap(); - armaNoiseModels = new LinkedHashMap(); + selectors = new LinkedHashMap<>(); + armaNoiseModels = new LinkedHashMap<>(); createStateNoiseModels(); - this.lastNoiseTimes=new HashMap(); //avoid adding noise more than once + this.lastNoiseTimes= new HashMap<>(); //avoid adding noise more than once //prepare index for range constraints RangeValidationConstraint[] rangeValidationConstraints = this.bbStochModelVectorsConfig.getRangeValidationConstraints(); @@ -148,6 +148,7 @@ public BBStochModelInstance(File configRootDir, IModelInstance model, if (dataObjectBoundaryMappings.size() > 0) { processProvidedBoundaries(this.dataObjectBoundaryMappings, this.ensembleMemberIndex); } + constraintExchangeItems = new LinkedHashMap<>(); } private void processProvidedBoundaries(LinkedHashMap> boundaryProviderConfigs, int ensembleMemberIndex) { @@ -167,7 +168,7 @@ private void processProvidedBoundaries(LinkedHashMap list = new ArrayList(); + ArrayList list = new ArrayList<>(); list.addAll(this.constraintExchangeItemIdConstraintMap.keySet()); list.addAll(Arrays.asList(model.getExchangeItemIDs())); - return list.toArray(new String[list.size()]); + return list.toArray(new String[0]); } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { - ArrayList list = new ArrayList(); + public String[] getExchangeItemIDs(IExchangeItem.Role role) { + ArrayList list = new ArrayList<>(); //TODO only add constraintExchangeItems for the given role. AK list.addAll(this.constraintExchangeItemIdConstraintMap.keySet()); list.addAll(Arrays.asList(model.getExchangeItemIDs(role))); - return list.toArray(new String[list.size()]); + return list.toArray(new String[0]); } /** * Get exchangeItems through new IDataObject interface. This is inherited through IModelInstance. * NOTE: all methods in the stochmodel now use the OLD interface. - * @param exchangeItemId + * @param exchangeItemId The id of the exchange item * @return exchangeItem */ public IExchangeItem getDataObjectExchangeItem(String exchangeItemId) { - IPrevExchangeItem item = this.getExchangeItem(exchangeItemId); - if(item instanceof IExchangeItem){ - return (IExchangeItem)item; + IExchangeItem item = this.getExchangeItem(exchangeItemId); + if(item != null){ + return item; }else{ throw new RuntimeException("BBStochModel.getDataObjectExchangeItem: item "+exchangeItemId+" is not of type IExchangeItem"); } @@ -397,9 +398,9 @@ public IExchangeItem getDataObjectExchangeItem(String exchangeItemId) { * Get ExchangeItems through old interface of IModelInstance. * NOTE: all methods in the stochmodel now use the OLD interface. TODO move to new interface. */ - public IPrevExchangeItem getExchangeItem(String exchangeItemId) { + public IExchangeItem getExchangeItem(String exchangeItemId) { //check if exchangeItem with given id is a constraintExchangeItem and has already been constructed. - IPrevExchangeItem constraintExchangeItem = this.constraintExchangeItems.get(exchangeItemId); + IExchangeItem constraintExchangeItem = this.constraintExchangeItems.get(exchangeItemId); if (constraintExchangeItem != null) { return constraintExchangeItem; } @@ -409,7 +410,7 @@ public IPrevExchangeItem getExchangeItem(String exchangeItemId) { if (constraint != null) { //construct constraintExchangeItem. //the wrapping constraintExchangeItem always has a different unique id from the original wrapped exchangeItem. - IPrevExchangeItem affectedExchangeItem = getExchangeItem(constraint.getAffectedExchangeItemId()); + IExchangeItem affectedExchangeItem = getExchangeItem(constraint.getAffectedExchangeItemId()); constraintExchangeItem = constraint.wrapAffectedExchangeItem(affectedExchangeItem); this.constraintExchangeItems.put(exchangeItemId, constraintExchangeItem); return constraintExchangeItem; @@ -419,13 +420,13 @@ public IPrevExchangeItem getExchangeItem(String exchangeItemId) { return getExchangeItemDirectlyFromModel(exchangeItemId); } - private IPrevExchangeItem getExchangeItemDirectlyFromModel(String exchangeItemId) { - IPrevExchangeItem exchangeItem = this.model.getExchangeItem(exchangeItemId); + private IExchangeItem getExchangeItemDirectlyFromModel(String exchangeItemId) { + IExchangeItem exchangeItem = this.model.getExchangeItem(exchangeItemId); if (exchangeItem == null) { - String allItems = ""; + StringBuilder allItems = new StringBuilder(); for (String availableExchangeItemId : this.getExchangeItemIDs()) { - allItems += " " + availableExchangeItemId + "\n"; + allItems.append(" ").append(availableExchangeItemId).append("\n"); } throw new RuntimeException(getClass().getSimpleName() + ".getExchangeItem:\n" + " Exchange item with id '" + exchangeItemId + "' not found.\n" @@ -636,13 +637,13 @@ public void setParameters(IVector parameters) { double parameterDelta = paramChild.getValue(0) * regularisationConstantConfig.getScale(); for (BBStochModelVectorConfig stochModelVectorConfig : regularisationConstantConfig.getVectorConfigs()) { - IPrevExchangeItem sourceExchangeItem = getExchangeItem(stochModelVectorConfig.getSourceId()); + IExchangeItem sourceExchangeItem = getExchangeItem(stochModelVectorConfig.getSourceId()); if (sourceExchangeItem == null) { throw new RuntimeException("BBStochModelInstance.setParameters(): parameter not found: " + stochModelVectorConfig.getSourceId()); } - IPrevExchangeItem exchangeItem = new BBExchangeItem(stochModelVectorConfig.getId(), stochModelVectorConfig, - sourceExchangeItem, selectors, configRootDir); + IExchangeItem exchangeItem = new BBExchangeItem(stochModelVectorConfig.getId(), stochModelVectorConfig, + sourceExchangeItem, selectors, configRootDir); addParameterDeltaToExchangeItem(parameterDelta, exchangeItem, regularisationConstantConfig.getTransformation()); @@ -661,13 +662,13 @@ public void setParameters(IVector parameters) { int vectorConfigNr = 0; while (vectorConfigNr < cartesianToPolarConfig.getVectorConfigs().size()) { - IPrevExchangeItem radiusExchangeItem = getExchangeItem( + IExchangeItem radiusExchangeItem = getExchangeItem( cartesianToPolarConfig.getVectorConfigs().get(vectorConfigNr).getSourceId()); if (radiusExchangeItem == null) { throw new RuntimeException("BBStochModelInstance.setParameters(): radius parameter not found: " + cartesianToPolarConfig.getVectorConfigs().get(vectorConfigNr).getSourceId()); } - IPrevExchangeItem angleExchangeItem = getExchangeItem( + IExchangeItem angleExchangeItem = getExchangeItem( cartesianToPolarConfig.getVectorConfigs().get(vectorConfigNr + 1).getSourceId()); if (angleExchangeItem == null) { throw new RuntimeException("BBStochModelInstance.setParameters(): angle parameter not found: " + @@ -706,7 +707,7 @@ public void setParameters(IVector parameters) { for (NoiseModelExchangeItemConfig exchangeItemConfig : noiseConfig.getExchangeItemConfigs()) { IVector paramChild = getAndCheckParamChild(parameters, exchangeItemConfig.getId()); for (String modelExchangeItemId : exchangeItemConfig.getModelExchangeItemIds()) { - IPrevExchangeItem exchangeItem = getExchangeItem(modelExchangeItemId); + IExchangeItem exchangeItem = getExchangeItem(modelExchangeItemId); if (exchangeItem == null) { throw new RuntimeException("BBStochModelInstance.setParameters(): parameter not found: " + modelExchangeItemId); @@ -725,7 +726,7 @@ public void axpyOnParameters(double alpha, IVector vector) { } public IModelState saveInternalState() { - File dirForRestartFiles = checkRestartDir(getCurrentTime(), false); + File dirForRestartFiles = checkRestartDir(getCurrentTime()); FileBasedModelState stochSavedModelState = new FileBasedModelState(); stochSavedModelState.setDirContainingModelstateFiles(dirForRestartFiles); int i = 0; @@ -761,7 +762,7 @@ public void restoreInternalState(IModelState savedInternalState) { " for " + this.getClass().getName() + ".releaseInternalState"); } FileBasedModelState stochModelState = (FileBasedModelState) savedInternalState; - File dirForRestartFiles = checkRestartDir(getCurrentTime(), false); + File dirForRestartFiles = checkRestartDir(getCurrentTime()); File incomingStateDir = stochModelState.getDirContainingModelStateFiles(); // the particle filter exchanges full states. Copy a full state dir from another ensemble member @@ -797,13 +798,13 @@ public void releaseInternalState(IModelState savedInternalState) { throw new IllegalArgumentException("Unknown state type (" + savedInternalState.getClass().getName() + " for " + this.getClass().getName() + ".releaseInternalState"); } - File dirForRestartFiles = checkRestartDir(getCurrentTime(), false); + File dirForRestartFiles = checkRestartDir(getCurrentTime()); FileBasedModelState modelState = (FileBasedModelState) savedInternalState; modelState.releaseState(dirForRestartFiles); } public IModelState loadPersistentState(File persistentStateFile) { - File dirForRestartFiles = checkRestartDir(getCurrentTime(), false); + File dirForRestartFiles = checkRestartDir(getCurrentTime()); return FileBasedModelState.loadPersistenState(persistentStateFile, dirForRestartFiles); } @@ -820,27 +821,23 @@ public IStochVector getStateUncertainty() { // state size is equal to the last sub index if (stateNoiseModelsEndIndices.length<1){ - System.out.println("Warning no noise model specified but the method getStateUncertainty is called. Pleae check whether this is correct."); + System.out.println("Warning no noise model specified but the method getStateUncertainty is called. Please check whether this is correct."); return null; } int fullStateSize = 0; - if (stateNoiseModelsEndIndices.length > 0) { - fullStateSize += stateNoiseModelsEndIndices[stateNoiseModelsEndIndices.length - 1]; - } + fullStateSize += stateNoiseModelsEndIndices[stateNoiseModelsEndIndices.length - 1]; if (stateVectorsEndIndices.length > 0) { fullStateSize += stateVectorsEndIndices[stateVectorsEndIndices.length - 1]; } Collection stateNoiseModelCollection = this.bbStochModelVectorsConfig.getStateConfig().getUncertaintyOrArmaNoiseConfigs(); - ArrayList stdDevList = new ArrayList(); + ArrayList stdDevList = new ArrayList<>(); for (BBUncertOrArmaNoiseConfig stateNoiseModelConfig : stateNoiseModelCollection) { int noiseStateSize = 1; // TODO elaborate double[] stdDevs = new double[noiseStateSize]; - for (int i = 0; i < stdDevs.length; i++) { - stdDevs[i] = stateNoiseModelConfig.getStdDev(); - } + Arrays.fill(stdDevs, stateNoiseModelConfig.getStdDev()); stdDevList.add(stdDevs); } double[] means = new double[fullStateSize]; // value = 0 @@ -875,11 +872,11 @@ public IVector[] getWhiteNoise(ITime timeSpan) { throw new UnsupportedOperationException("org.openda.blackbox.wrapper.BBStochModelInstance.getWhiteNoise(): Not implemented yet."); } - public void setWhiteNoise(IVector whiteNoise[]) { + public void setWhiteNoise(IVector[] whiteNoise) { throw new UnsupportedOperationException("org.openda.blackbox.wrapper.BBStochModelInstance.setWhiteNoise(): Not implemented yet."); } - public void axpyOnWhiteNoise(double alpha, IVector vector[]) { + public void axpyOnWhiteNoise(double alpha, IVector[] vector) { throw new UnsupportedOperationException("org.openda.blackbox.wrapper.BBStochModelInstance.axpyOnWhiteNoise(): Not implemented yet."); } @@ -938,24 +935,24 @@ private IVector getObservedValuesBB(IObservationDescriptions observationDescript timerGetObs.start(); TreeVector treeVector = new TreeVector("predictions"); - String errorMessage = ""; - for (IPrevExchangeItem observationExchangeItem : observationDescriptions.getExchangeItems()) { + StringBuilder errorMessage = new StringBuilder(); + for (IExchangeItem observationExchangeItem : observationDescriptions.getExchangeItems()) { //get modelExchangeItem that corresponds to current observationExchangeItem. BBStochModelVectorConfig vectorConfig = findPredictionVectorConfig(observationExchangeItem.getId()); - IPrevExchangeItem modelExchangeItem = null; + IExchangeItem modelExchangeItem = null; if (this.bbStochModelVectorsConfig.isCollectPredictorTimeSeries()) { - for (int i=0; i< collectTimeSeriesBbExchangeItems.size(); i++){ - if (collectTimeSeriesBbExchangeItems.get(i).getId().contentEquals(observationExchangeItem.getId())){ - modelExchangeItem = collectTimeSeriesBbExchangeItems.get(i); - vectorConfig = new BBStochModelVectorConfig(modelExchangeItem.getId(),modelExchangeItem.getId(),null,null); - break; - } - } + for (BBCollectTimeSeriesExchangeItem collectTimeSeriesBbExchangeItem : collectTimeSeriesBbExchangeItems) { + if (collectTimeSeriesBbExchangeItem.getId().contentEquals(observationExchangeItem.getId())) { + modelExchangeItem = collectTimeSeriesBbExchangeItem; + vectorConfig = new BBStochModelVectorConfig(modelExchangeItem.getId(), modelExchangeItem.getId(), null, null); + break; + } + } } else { modelExchangeItem = getExchangeItem(vectorConfig.getSourceId()); } if (modelExchangeItem == null) { - errorMessage += "\n\tExchange item not found: " + vectorConfig.getSourceId(); + errorMessage.append("\n\tExchange item not found: ").append(vectorConfig.getSourceId()); continue; } String modelExchangeItemId = modelExchangeItem.getId();//only used for log messages. @@ -966,7 +963,7 @@ private IVector getObservedValuesBB(IObservationDescriptions observationDescript double[] computedValues = mappedExchangeItem.getValuesAsDoubles(); //get the model values at the observed coordinates. - if (!GeometryUtils.isScalar(observationExchangeItem)) {//if grid observationExchangeItem. + if (!GeometryUtils.isScalar(observationExchangeItem.getGeometryInfo())) {//if grid observationExchangeItem. String logMessage = "Getting model values at observed coordinates for grid observation exchangeItem with id '" + observationExchangeItem.getId() + "'."; if (LOGGER.isInfoEnabled()) LOGGER.info(logMessage); Results.putMessage(logMessage); @@ -977,7 +974,7 @@ private IVector getObservedValuesBB(IObservationDescriptions observationDescript + "' is a grid, therefore the corresponding model exchange item must also be a grid. Model exchange item with id '" + modelExchangeItemId + "' is scalar."); } //grid exchangeItems are always IExchangeItems. - IVector observedModelValues = getObservedModelValuesForGrid(((IExchangeItem) observationExchangeItem).getGeometryInfo(), mappedExchangeItem.getGeometryInfo(), computedValues, + IVector observedModelValues = getObservedModelValuesForGrid(observationExchangeItem.getGeometryInfo(), mappedExchangeItem.getGeometryInfo(), computedValues, observationExchangeItem.getId(), modelExchangeItemId); ITreeVector treeVectorLeaf = new TreeVector(mappedExchangeItem.getId(), observedModelValues); treeVector.addChild(treeVectorLeaf); @@ -997,9 +994,7 @@ private IVector getObservedValuesBB(IObservationDescriptions observationDescript if (computedTimes != null) { //this code only works for scalar time series. if (computedTimes.length != computedValues.length) { - errorMessage += "\n\tInconsistency in #times (" + - computedTimes.length + ") and #values (" + computedValues.length + ") for" + - vectorConfig.getId(); + errorMessage.append("\n\tInconsistency in #times (").append(computedTimes.length).append(") and #values (").append(computedValues.length).append(") for").append(vectorConfig.getId()); } double[] sortedValues = computedValues; if (computedTimes.length != observationTimes.length) { @@ -1007,21 +1002,18 @@ private IVector getObservedValuesBB(IObservationDescriptions observationDescript int[][] indices = SortUtils.mergeDoubleIndex(observationTimes, computedTimes, SortUtils.MergeType.left, tolerance); int[] observedIndices = indices[0]; int[] computedIndices = indices[1]; - String missingTimeStepsString = ""; - String missingTimeStepStringMJD = ""; + StringBuilder missingTimeStepsString = new StringBuilder(); + StringBuilder missingTimeStepStringMJD = new StringBuilder(); for (int i = 0; i < computedIndices.length; i++) { if (computedIndices[i] == -1) { - missingTimeStepStringMJD += ", "+ observationTimes[observedIndices[i]]; - missingTimeStepsString += ", " + TimeUtils.mjdToString(observationTimes[observedIndices[i]]); + missingTimeStepStringMJD.append(", ").append(observationTimes[observedIndices[i]]); + missingTimeStepsString.append(", ").append(TimeUtils.mjdToString(observationTimes[observedIndices[i]])); } } if (missingTimeStepsString.length() > 0) { - errorMessage += "\n\tNo computed values XX available for " + - vectorConfig.getId() + missingTimeStepsString+"\n"+ - "MJD :"+missingTimeStepStringMJD+"\n"+ - "available times are: \n"; - for (int i=0; i noiseModelsInState = new ArrayList<>(); - List modelExchangeItemsInState = new ArrayList<>(); + List modelExchangeItemsInState = new ArrayList<>(); if (useLocalAnalysis) { @@ -1241,9 +1233,8 @@ public ILocalizationDomains getLocalizationDomains(){ this.bbStochModelVectorsConfig.getStateConfig().getVectorCollection(); for (BBStochModelVectorConfig vectorConfig : vectorCollection) { - IPrevExchangeItem prevExchangeItem = getExchangeItem(vectorConfig.getId()); - IExchangeItem exchangeItem = (IExchangeItem) prevExchangeItem; - modelExchangeItemsInState.add(exchangeItem); + IExchangeItem ExchangeItem = getExchangeItem(vectorConfig.getId()); + modelExchangeItemsInState.add(ExchangeItem); } @@ -1289,7 +1280,7 @@ public IVector[] getObservedLocalization(IObservationDescriptions observationDes IVector xObs = observationDescriptions.getValueProperties("xposition"); IVector yObs = observationDescriptions.getValueProperties("yposition"); IVector zObs = observationDescriptions.getValueProperties("height"); - String obsId[] = observationDescriptions.getStringProperties("id"); + String[] obsId = observationDescriptions.getStringProperties("id"); int obsCount = observationDescriptions.getObservationCount(); IVector[] obsVectorArray = new IVector[obsCount]; @@ -1323,18 +1314,17 @@ private ITreeVector getLocalizedCohnWeights(String obsId, double distanceCohnMet //int k=0; for (BBStochModelVectorConfig vectorConfig : vectorCollection) { - IPrevExchangeItem prevExchangeItem = getExchangeItem(vectorConfig.getId()); - if (prevExchangeItem instanceof IExchangeItem) { - IExchangeItem exchangeItem = (IExchangeItem) prevExchangeItem; + IExchangeItem prevExchangeItem = getExchangeItem(vectorConfig.getId()); + if (prevExchangeItem != null) { - double[] distancesForExchangeItem = exchangeItem.getGeometryInfo().distanceToPoint(xObs, yObs, zObs).getValuesAsDoubles(); + double[] distancesForExchangeItem = prevExchangeItem.getGeometryInfo().distanceToPoint(xObs, yObs, zObs).getValuesAsDoubles(); double[] weightsForExchangeItem = new double[distancesForExchangeItem.length]; for (int xy = 0; xy < distancesForExchangeItem.length; xy++) { weightsForExchangeItem[xy] = GeometryUtils.calculateCohnWeight(distancesForExchangeItem[xy], distanceCohnMeters); //k++; } - treeVector.addChild(exchangeItem.getId(), weightsForExchangeItem); + treeVector.addChild(prevExchangeItem.getId(), weightsForExchangeItem); //iWeightsVector[k] = weightsForExchangeItem; } } @@ -1429,10 +1419,10 @@ private BBStochModelVectorConfig findPredictionVectorConfig(String obsId) { } } - String allVectors = ""; + StringBuilder allVectors = new StringBuilder(); for (BBStochModelVectorConfig bbStochModelVectorConfig : this.bbStochModelVectorsConfig.getPredictorVectorCollection()) { - allVectors += " " + bbStochModelVectorConfig.getId() + "\n"; + allVectors.append(" ").append(bbStochModelVectorConfig.getId()).append("\n"); } throw new RuntimeException( "announceObservedValues:\n" + @@ -1443,7 +1433,7 @@ private BBStochModelVectorConfig findPredictionVectorConfig(String obsId) { allVectors + "\n"); } - private void addParameterDeltaToExchangeItem(double parameterDelta, IPrevExchangeItem exchangeItem, int transformation) { + private void addParameterDeltaToExchangeItem(double parameterDelta, IExchangeItem exchangeItem, int transformation) { double[] values = exchangeItem.getValuesAsDoubles(); if (transformation == BBRegularisationConstantConfig.TRANSFORMATION_ADD) { for (int i = 0; i < values.length; i++) { @@ -1454,9 +1444,7 @@ private void addParameterDeltaToExchangeItem(double parameterDelta, IPrevExchang values[i] = values[i] * Math.exp(parameterDelta); } } else if (transformation == BBRegularisationConstantConfig.TRANSFORMATION_SET) { - for (int i = 0; i < values.length; i++) { - values[i] = parameterDelta; - } + Arrays.fill(values, parameterDelta); } else if (transformation == BBRegularisationConstantConfig.TRANSFORMATION_MULTIPLY) { for (int i = 0; i < values.length; i++) { values[i] *= 1d + parameterDelta; @@ -1509,7 +1497,7 @@ private boolean propagateNoiseModelsAndAddNoiseToExchangeItems(ITime currentTime noiseModel.compute(targetTime); for (NoiseModelExchangeItemConfig exchangeItemConfig : noiseModelConfig.getExchangeItemConfigs()) { double[] noiseModelEITimes; - IPrevExchangeItem noiseModelExchangeItem = noiseModel.getExchangeItem(exchangeItemConfig.getId()); + IExchangeItem noiseModelExchangeItem = noiseModel.getExchangeItem(exchangeItemConfig.getId()); if (noiseModelExchangeItem == null) { noiseModelExchangeItem = noiseModel.getDataObjectExchangeItem(exchangeItemConfig.getId()); } @@ -1521,13 +1509,13 @@ private boolean propagateNoiseModelsAndAddNoiseToExchangeItems(ITime currentTime throw new RuntimeException("No times for noise model item " + noiseModelExchangeItem.getId()); } for (String modelExchangeItemId : exchangeItemConfig.getModelExchangeItemIds()) { - IPrevExchangeItem modelExchangeItem = getExchangeItem(modelExchangeItemId); - double modelTimes[] = modelExchangeItem.getTimes(); + IExchangeItem modelExchangeItem = getExchangeItem(modelExchangeItemId); + double[] modelTimes = modelExchangeItem.getTimes(); List modelTimesInCurrentPeriod; if (modelTimes == null) { double currentModelTime = getCurrentTime().getMJD(); modelTimes = new double[] {currentModelTime}; - modelTimesInCurrentPeriod = new ArrayList(); + modelTimesInCurrentPeriod = new ArrayList<>(); modelTimesInCurrentPeriod.add(currentModelTime); } else { modelTimesInCurrentPeriod = determineTimeStampsInInterval( @@ -1538,38 +1526,36 @@ private boolean propagateNoiseModelsAndAddNoiseToExchangeItems(ITime currentTime //Note: this loops over the model exchangeItem times. For each model time the same time //must be present in the noise model exchangeItem. For each model time the noise of the //noise model for that time is added to the model values for that time. - for (int t = 0; t < modelTimesInCurrentPeriod.size(); t++) { - double time = modelTimesInCurrentPeriod.get(t); - if(!this.lastNoiseTimes.containsKey(modelExchangeItemId)){ + for (double time : modelTimesInCurrentPeriod) { + if (!this.lastNoiseTimes.containsKey(modelExchangeItemId)) { this.lastNoiseTimes.put(modelExchangeItemId, Double.NEGATIVE_INFINITY); } double timePrecision = OdaGlobSettings.getTimePrecision(); - if(time>this.lastNoiseTimes.get(modelExchangeItemId)+0.5*timePrecision){ + if (time > this.lastNoiseTimes.get(modelExchangeItemId) + 0.5 * timePrecision) { // we need values for each of the model times in this forecast // look for index in ALL times for noise model exchange item - int ti= TimeUtils.findMatchingTimeIndex(noiseModelEITimes, time, timePrecision); - if(ti==-1){ - String message = "Cannot find model time " + time + " in noise model." - + " The noise model must contain the same times as the model. Please adjust the noise model configuration.\n"; - message += "Noise model times for " + noiseModelExchangeItem.getId() + "\n"; - for(int j = 0; j < noiseModelEITimes.length; j++){ - message += noiseModelEITimes[j] + "\n"; - } - //for historic reasons also write this message to System.out. - System.out.println(message); - throw new RuntimeException(message); + int ti = TimeUtils.findMatchingTimeIndex(noiseModelEITimes, time, timePrecision); + if (ti == -1) { + StringBuilder message = new StringBuilder("Cannot find model time " + time + " in noise model." + + " The noise model must contain the same times as the model. Please adjust the noise model configuration.\n"); + message.append("Noise model times for ").append(noiseModelExchangeItem.getId()).append("\n"); + for (double noiseModelEITime : noiseModelEITimes) { + message.append(noiseModelEITime).append("\n"); + } + //for historic reasons also write this message to System.out. + System.out.println(message); + throw new RuntimeException(message.toString()); } double[] noiseModelEIValuesForTimeStep = - getNoiseModelValuesForTimeStep(noiseModelExchangeItem, ti); + getNoiseModelValuesForTimeStep(noiseModelExchangeItem, ti); if (exchangeItemConfig.doAddOnlyNoiseDifference()) { int noiseLength = noiseModelEIValuesForTimeStep.length; double[] previousValues = prevNoiseModelEIValuesForTimeStep.get(exchangeItemConfig.getId()); if (previousValues == null) { prevNoiseModelEIValuesForTimeStep.put(exchangeItemConfig.getId(), noiseModelEIValuesForTimeStep); // only add new noise, no difference needed - } - else { + } else { // substract previous noise from new noise. store resulting noise for next time step for (int i = 0; i < noiseLength; i++) { double currentNoiseValue = noiseModelEIValuesForTimeStep[i]; @@ -1578,13 +1564,13 @@ private boolean propagateNoiseModelsAndAddNoiseToExchangeItems(ITime currentTime } } } - int modelTimeIndex= TimeUtils.findMatchingTimeIndex(modelTimes, time, timePrecision); - boolean addNoiseBefore = !afterCompute && !exchangeItemConfig.isAddStateNoiseAfterCompute(); - boolean addNoiseAfter = afterCompute && exchangeItemConfig.isAddStateNoiseAfterCompute(); - addNoiseAfterComputeForAnyExchangeItem |= (!afterCompute && exchangeItemConfig.isAddStateNoiseAfterCompute()); - if (addNoiseAfter || addNoiseBefore) addNoiseToExchangeItemForOneTimeStep(modelExchangeItem, noiseModelExchangeItem, modelTimeIndex, - noiseModelEIValuesForTimeStep, exchangeItemConfig.getTransformation(), exchangeItemConfig.getStateSizeNoiseSizeRatio()); - this.lastNoiseTimes.put(modelExchangeItemId,time); + int modelTimeIndex = TimeUtils.findMatchingTimeIndex(modelTimes, time, timePrecision); + boolean addNoiseBefore = !afterCompute && !exchangeItemConfig.isAddStateNoiseAfterCompute(); + boolean addNoiseAfter = afterCompute && exchangeItemConfig.isAddStateNoiseAfterCompute(); + addNoiseAfterComputeForAnyExchangeItem |= (!afterCompute && exchangeItemConfig.isAddStateNoiseAfterCompute()); + if (addNoiseAfter || addNoiseBefore) addNoiseToExchangeItemForOneTimeStep(modelExchangeItem, noiseModelExchangeItem, modelTimeIndex, + noiseModelEIValuesForTimeStep, exchangeItemConfig.getTransformation(), exchangeItemConfig.getStateSizeNoiseSizeRatio()); + this.lastNoiseTimes.put(modelExchangeItemId, time); } } } @@ -1654,39 +1640,38 @@ private boolean propagateNoiseModelsAndAddNoiseToExchangeItems(ITime currentTime * @param timeStepIndex * @return */ - private double[] getNoiseModelValuesForTimeStep(IPrevExchangeItem noiseModelExchangeItem, int timeStepIndex) { - if (noiseModelExchangeItem instanceof IExchangeItem) { - IExchangeItem exchangeItem = (IExchangeItem) noiseModelExchangeItem; - if (exchangeItem.getTimeInfo() == null) { + private double[] getNoiseModelValuesForTimeStep(IExchangeItem noiseModelExchangeItem, int timeStepIndex) { + if (noiseModelExchangeItem != null) { + if (noiseModelExchangeItem.getTimeInfo() == null) { throw new RuntimeException( - "No time info available in exchange item " + exchangeItem.getId()); + "No time info available in exchange item " + noiseModelExchangeItem.getId()); } - double[] timeStamps = exchangeItem.getTimeInfo().getTimes(); + double[] timeStamps = noiseModelExchangeItem.getTimeInfo().getTimes(); if (timeStamps == null) { throw new RuntimeException( - "No times set for exchange item " + exchangeItem.getId()); + "No times set for exchange item " + noiseModelExchangeItem.getId()); } if(timeStepIndex<0) timeStepIndex+=timeStamps.length; //negative indices count from end - IGeometryInfo iGeometryInfo = exchangeItem.getGeometryInfo(); + IGeometryInfo iGeometryInfo = noiseModelExchangeItem.getGeometryInfo(); if (iGeometryInfo != null) { if (!(iGeometryInfo instanceof ArrayGeometryInfo)) { throw new RuntimeException( "Unknown geometry info type " + iGeometryInfo.getClass().getName() + - " for exchange item " + exchangeItem.getId()); + " for exchange item " + noiseModelExchangeItem.getId()); } ArrayGeometryInfo geometryInfo = (ArrayGeometryInfo) iGeometryInfo; if (geometryInfo.getLatitudeArray().getNumberOfDimensions() != 1 || geometryInfo.getLongitudeArray().getNumberOfDimensions() != 1) { throw new RuntimeException( - "Currently only able to handle 1D long/lat arrays, exchange item " + exchangeItem.getId()); + "Currently only able to handle 1D long/lat arrays, exchange item " + noiseModelExchangeItem.getId()); } } - Object valuesObject = exchangeItem.getValues(); + Object valuesObject = noiseModelExchangeItem.getValues(); if (!(valuesObject instanceof IArray)) { throw new RuntimeException( "Values object type " + valuesObject.getClass().getName() + - " not support, for exchange item " + exchangeItem.getId()); + " not support, for exchange item " + noiseModelExchangeItem.getId()); } // TODO assume time index is at position=0, which is often true return ((IArray) valuesObject).getSliceAsDoubles(0, timeStepIndex, timeStepIndex); @@ -1720,7 +1705,7 @@ private void addNoiseToExchangeItem(BBUncertOrArmaNoiseConfig stateNoiseModelCon for (BBStochModelVectorConfig vectorConfig : stateNoiseModelConfig.getVectorConfigs()) { String exchangeItemID = vectorConfig.getSourceId(); - IPrevExchangeItem exchangeItem = getExchangeItem(exchangeItemID); + IExchangeItem exchangeItem = getExchangeItem(exchangeItemID); int tStart = 0; double[] exchangeItemTimes = exchangeItem.getTimes(); if (exchangeItemTimes != null) { @@ -1738,7 +1723,7 @@ private void addNoiseToExchangeItem(BBUncertOrArmaNoiseConfig stateNoiseModelCon private int determineNumBcTimeSteps(ITime currentTime, ITime targetTime, BBStochModelVectorConfig[] vectorConfigs) { int numBcTimeStepsInPeriod = Integer.MIN_VALUE; for (BBStochModelVectorConfig vectorConfig : vectorConfigs) { - IPrevExchangeItem exchangeItem = getExchangeItem(vectorConfig.getSourceId()); + IExchangeItem exchangeItem = getExchangeItem(vectorConfig.getSourceId()); if (exchangeItem.getTimes() != null) { int exchangeItemNumTimestepsInComputationSpan = determineNumTimeStepsInSpan(exchangeItem.getTimes(), currentTime, targetTime); if (numBcTimeStepsInPeriod == Integer.MIN_VALUE) { @@ -1758,7 +1743,7 @@ private int determineNumBcTimeSteps(ITime currentTime, ITime targetTime, BBStoch } private List determineTimeStampsInInterval(double[] exchangeItemTimes, ITime currentTime, ITime targetTime, boolean skipFirstNoiseTimeStep) { - List timeStampsInInterval = new ArrayList(); + List timeStampsInInterval = new ArrayList<>(); for (Double exchangeItemTime : exchangeItemTimes) { if (isTimeIncludedInInterval(currentTime.getMJD(), targetTime.getMJD(), exchangeItemTime)) { if (!(skipFirstNoiseTimeStep && exchangeItemTime < currentTime.getMJD()+ 1.e-6)) { @@ -1783,8 +1768,8 @@ private boolean isTimeIncludedInInterval(double currentTime, double targetTime, return ((exchangeItemTime + 1.e-6) >= currentTime) && ((exchangeItemTime - 1.e-6) < targetTime); } - private void addNoiseToExchangeItemForOneTimeStep(IPrevExchangeItem modelExchangeItem, - IPrevExchangeItem noiseModelExchangeItem, int timeIndex, double[] noise, int transformationFromOperation, int stateSizeNoiseSizeRatio) { + private void addNoiseToExchangeItemForOneTimeStep(IExchangeItem modelExchangeItem, + IExchangeItem noiseModelExchangeItem, int timeIndex, double[] noise, int transformationFromOperation, int stateSizeNoiseSizeRatio) { int numValuesInExchangeItem; try { // check the number of input values @@ -1940,7 +1925,7 @@ private void addNoiseToExchangeItemForOneTimeStep(IPrevExchangeItem modelExchang } } - private double[] getSpatialNoise(IPrevExchangeItem modelExchangeItem, IPrevExchangeItem noiseModelExchangeItem, double[] noise, int stateSizeNoiseSizeRatioX, int timeIndex) { + private double[] getSpatialNoise(IExchangeItem modelExchangeItem, IExchangeItem noiseModelExchangeItem, double[] noise, int stateSizeNoiseSizeRatioX, int timeIndex) { // ODA-617 double[] valuesAsDoubles; if (modelExchangeItem instanceof NetcdfGridTimeSeriesExchangeItem) { @@ -1950,7 +1935,7 @@ private double[] getSpatialNoise(IPrevExchangeItem modelExchangeItem, IPrevExcha } if (is2DNoise(modelExchangeItem, noiseModelExchangeItem)) { - return get2DInterpolatedNoise((IExchangeItem) modelExchangeItem, (IExchangeItem) noiseModelExchangeItem, noise, stateSizeNoiseSizeRatioX, valuesAsDoubles); + return get2DInterpolatedNoise(modelExchangeItem, noiseModelExchangeItem, noise, stateSizeNoiseSizeRatioX, valuesAsDoubles); } return get1DInterpolatedNoise(noise, stateSizeNoiseSizeRatioX, valuesAsDoubles); @@ -2070,11 +2055,11 @@ private static double[] interpolateNoise(double[] noise, int stateSizeNoiseSizeR return spatialNoise; } - private static boolean is2DNoise(IPrevExchangeItem modelExchangeItem, IPrevExchangeItem noiseModelExchangeItem) { - if (!(noiseModelExchangeItem != null && noiseModelExchangeItem instanceof IExchangeItem && modelExchangeItem instanceof IExchangeItem)) return false; + private static boolean is2DNoise(IExchangeItem modelExchangeItem, IExchangeItem noiseModelExchangeItem) { + if (!(noiseModelExchangeItem != null && modelExchangeItem != null)) return false; - IGeometryInfo noiseModelGeometryInfo = ((IExchangeItem) noiseModelExchangeItem).getGeometryInfo(); - IGeometryInfo modelGeometryInfo = ((IExchangeItem) modelExchangeItem).getGeometryInfo(); + IGeometryInfo noiseModelGeometryInfo = noiseModelExchangeItem.getGeometryInfo(); + IGeometryInfo modelGeometryInfo = modelExchangeItem.getGeometryInfo(); return modelGeometryInfo instanceof IArrayGeometryInfo && noiseModelGeometryInfo instanceof IArrayGeometryInfo; } @@ -2087,13 +2072,13 @@ private static void checkStateSizeNoiseSizeRatio(int stateSizeNoiseSizeRatio, in } } - private File checkRestartDir(ITime time, boolean mustExist) { + private File checkRestartDir(ITime time) { if (this.savedStatesDirPrefix == null) { throw new RuntimeException("Dir for restart files not specified in black box stoch model config file on dir. " + configRootDir.getAbsolutePath()); } File savedStatesRootDir = configRootDir; String savedStatesDirPrefix = this.savedStatesDirPrefix; - return BBModelInstance.createDirectoryForSavedState(time, mustExist, savedStatesRootDir, savedStatesDirPrefix); + return BBModelInstance.createDirectoryForSavedState(time, false, savedStatesRootDir, savedStatesDirPrefix); } } diff --git a/core/java/src/org/openda/costa/CtaObservationDescriptions.java b/core/java/src/org/openda/costa/CtaObservationDescriptions.java index f52495595..b18d2106a 100644 --- a/core/java/src/org/openda/costa/CtaObservationDescriptions.java +++ b/core/java/src/org/openda/costa/CtaObservationDescriptions.java @@ -40,7 +40,7 @@ private CtaObservationDescriptions(int ctaHandle) { this.ctaHandle = ctaHandle; } - public List getExchangeItems() { + public List getExchangeItems() { throw new UnsupportedOperationException("org.costa.CtaObservationDescriptions.getExchangeItems(): Not implemented yet."); } diff --git a/core/java/src/org/openda/costa/CtaOpenDaModel.java b/core/java/src/org/openda/costa/CtaOpenDaModel.java index 148612a14..84b325fa4 100644 --- a/core/java/src/org/openda/costa/CtaOpenDaModel.java +++ b/core/java/src/org/openda/costa/CtaOpenDaModel.java @@ -165,8 +165,8 @@ public String[] getExchangeItemIDs() { throw new UnsupportedOperationException("org.costa.CtaOpenDaModel.getExchangeItemIDs(): Not implemented yet."); } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { - if (role == IPrevExchangeItem.Role.InOut) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { + if (role == IExchangeItem.Role.InOut) { return getExchangeItemIDs(); } throw new UnsupportedOperationException("org.costa.CtaOpenDaModel.getExchangeItemIDs(): Role selection not implemented yet."); @@ -176,7 +176,7 @@ public IExchangeItem getDataObjectExchangeItem(String exchangeItemID) { throw new UnsupportedOperationException("org.openda.costa.CtaOpenDaModel.getDataObjectExchangeItem(): Not implemented yet."); } - public IPrevExchangeItem getExchangeItem(String exchangeItemID) { + public IExchangeItem getExchangeItem(String exchangeItemID) { throw new UnsupportedOperationException("org.costa.CtaOpenDaModel.getExchangeItem(): Not implemented yet."); } diff --git a/core/java/src/org/openda/exchange/AbstractDataObject.java b/core/java/src/org/openda/exchange/AbstractDataObject.java new file mode 100644 index 000000000..fa970057a --- /dev/null +++ b/core/java/src/org/openda/exchange/AbstractDataObject.java @@ -0,0 +1,41 @@ +package org.openda.exchange; + +import org.openda.interfaces.IDataObject; +import org.openda.interfaces.IExchangeItem; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; + +public abstract class AbstractDataObject implements IDataObject { + + public static final String[] EMPTY_STRING_ARRAY = new String[0]; + protected Map exchangeItems = new LinkedHashMap<>(); + + @Override + public String[] getExchangeItemIDs() { + return this.exchangeItems.keySet().toArray(EMPTY_STRING_ARRAY); + } + + @Override + public String[] getExchangeItemIDs(IExchangeItem.Role role) { + Collection exchangeItems = this.exchangeItems.values(); + ArrayList idsForRole = new ArrayList<>(); + for (IExchangeItem exchangeItem : exchangeItems) { + IExchangeItem.Role exchangeItemRole = exchangeItem.getRole(); + if (exchangeItemRole.equals(role)) idsForRole.add(exchangeItem.getId()); + // If the role is InOut, then we are done. + if (role.equals(IExchangeItem.Role.InOut)) continue; + // For roles In and Out, we also add the exchangeItemIds for InOut to the result. + if (exchangeItemRole.equals(IExchangeItem.Role.InOut)) idsForRole.add(exchangeItem.getId()); + } + return idsForRole.toArray(EMPTY_STRING_ARRAY); + } + + @Override + public IExchangeItem getDataObjectExchangeItem(String exchangeItemID) { + return this.exchangeItems.get(exchangeItemID); + } + +} diff --git a/core/java/src/org/openda/exchange/ArrayExchangeItem.java b/core/java/src/org/openda/exchange/ArrayExchangeItem.java index 8f6ce0639..58441093f 100644 --- a/core/java/src/org/openda/exchange/ArrayExchangeItem.java +++ b/core/java/src/org/openda/exchange/ArrayExchangeItem.java @@ -89,7 +89,7 @@ public Role getRole() { return this.role; } - + public String getId() { return id; } @@ -134,7 +134,7 @@ public void copyValuesFromItem(IExchangeItem sourceItem) { Object values = sourceItem.getValues(); if (!(values instanceof IArray)) { - throw new IllegalArgumentException("Cannot convert values of type " + sourceItem.getValueType().getSimpleName() + throw new IllegalArgumentException("Cannot convert values of type " + sourceItem.getValuesType().getClass().getSimpleName() + " to type " + getValueType().getSimpleName()); } diff --git a/core/java/src/org/openda/exchange/ConstantLimitsRangeValidationExchangeItem.java b/core/java/src/org/openda/exchange/ConstantLimitsRangeValidationExchangeItem.java index 784a49aea..40b432a9b 100644 --- a/core/java/src/org/openda/exchange/ConstantLimitsRangeValidationExchangeItem.java +++ b/core/java/src/org/openda/exchange/ConstantLimitsRangeValidationExchangeItem.java @@ -22,7 +22,10 @@ import org.openda.blackbox.config.BBUtils; import org.openda.interfaces.IArray; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; +import org.openda.interfaces.IGeometryInfo; +import org.openda.interfaces.IQuantityInfo; +import org.openda.interfaces.ITimeInfo; import org.openda.interfaces.IVector; /** @@ -32,13 +35,13 @@ * @author Arno Kockx */ @SuppressWarnings("serial") -public class ConstantLimitsRangeValidationExchangeItem implements IPrevExchangeItem { +public class ConstantLimitsRangeValidationExchangeItem implements IExchangeItem { /** * Id of this constraintExchangeItem. */ private final String constraintExchangeItemId; - private final IPrevExchangeItem wrappedExchangeItem; + private final IExchangeItem wrappedExchangeItem; /** * This is Double.NaN if not set. @@ -59,7 +62,7 @@ public class ConstantLimitsRangeValidationExchangeItem implements IPrevExchangeI * @param upperLimit Double.NaN means not set. */ public ConstantLimitsRangeValidationExchangeItem(String constraintExchangeItemId, - IPrevExchangeItem exchangeItem, double lowerLimit, double upperLimit) { + IExchangeItem exchangeItem, double lowerLimit, double upperLimit) { if (constraintExchangeItemId == null || constraintExchangeItemId.isEmpty()) { throw new IllegalArgumentException("constraintExchangeItemId is empty."); @@ -88,13 +91,15 @@ public String getDescription() { return this.wrappedExchangeItem.getDescription(); } - public Role getRole() { - return this.wrappedExchangeItem.getRole(); - } + public IQuantityInfo getQuantityInfo() { return this.wrappedExchangeItem.getQuantityInfo(); } - public Class getValueType() { - return this.wrappedExchangeItem.getValueType(); - } + public IGeometryInfo getGeometryInfo() { return this.wrappedExchangeItem.getGeometryInfo(); } + + public Role getRole() { return this.wrappedExchangeItem.getRole(); } + + public ValueType getValuesType() { return this.wrappedExchangeItem.getValuesType(); } + + public ITimeInfo getTimeInfo() { return this.wrappedExchangeItem.getTimeInfo(); } public double[] getTimes() { return this.wrappedExchangeItem.getTimes(); @@ -138,6 +143,14 @@ public void multiplyValues(double[] multiplicationFactors) { setValuesAsDoubles(values); } + public void copyValuesFromItem(IExchangeItem sourceItem) { + ValueType sourceType=sourceItem.getValuesType(); + if(sourceType != ValueType.doublesType){ + throw new RuntimeException("TreeVectorIoObjectExchangeItem.copyValuesFromItem(): unknown type: " + sourceType ); + } + this.setValues(sourceItem.getValues()); + } + public void setValues(Object values) { //need to convert the given values from Object to double array, because method applyLimits only works for a double array. double[] doubles = convertValuesToDoubles(values); @@ -183,7 +196,7 @@ private double[] convertValuesToDoubles(Object values) { private static double[] applyLimits(double[] values, double lowerLimit, double upperLimit) { if (values == null) { - return values; + return null; } //copy values so that original values are not changed. diff --git a/core/java/src/org/openda/exchange/DoubleExchangeItem.java b/core/java/src/org/openda/exchange/DoubleExchangeItem.java index bf9de987f..d10934227 100644 --- a/core/java/src/org/openda/exchange/DoubleExchangeItem.java +++ b/core/java/src/org/openda/exchange/DoubleExchangeItem.java @@ -198,12 +198,12 @@ public Class getValueType() { } - @Deprecated public double[] getTimes() { + public double[] getTimes() { return null; } - @Deprecated public void setTimes(double[] times) { + public void setTimes(double[] times) { throw new UnsupportedOperationException("setTimes method make no sense for a DoubleExchangeItem"); } diff --git a/core/java/src/org/openda/exchange/ExchangeItem.java b/core/java/src/org/openda/exchange/ExchangeItem.java index eaa34d753..11b9334e6 100644 --- a/core/java/src/org/openda/exchange/ExchangeItem.java +++ b/core/java/src/org/openda/exchange/ExchangeItem.java @@ -24,7 +24,7 @@ import org.openda.interfaces.*; /** - * Base implementation of IPrevExchangeItem + * Base implementation of IExchangeItem */ public abstract class ExchangeItem implements IExchangeItem { @@ -32,7 +32,7 @@ public abstract class ExchangeItem implements IExchangeItem { private String description; private String quantityId; private String unitId; - private IPrevExchangeItem.Role role= IPrevExchangeItem.Role.InOut; + private IExchangeItem.Role role= IExchangeItem.Role.InOut; private TimeInfo timeInfo = new TimeInfo(); public ExchangeItem(String id) { @@ -70,15 +70,15 @@ public void setUnitId(String unitId) { this.unitId = unitId; } - public void setRole(IPrevExchangeItem.Role role){ + public void setRole(IExchangeItem.Role role){ this.role = role; } - public IPrevExchangeItem.Role getRole(){ - return this.role; - } + public IExchangeItem.Role getRole(){ + return this.role; + } - public String getQuantityId() { + public String getQuantityId() { return quantityId; } @@ -99,9 +99,9 @@ public void setTimes(ITime[] times) { } public void copyValuesFromItem(IExchangeItem sourceItem) { - if (sourceItem.getValueType() != getValueType()) { + if (sourceItem.getValuesType() != getValuesType()) { throw new RuntimeException("Incompatible value types in copy action from " + sourceItem.getId() + - " to " + getId() + "(" + sourceItem.getValueType().toString() + "/=" + getValueType().toString()); + " to " + getId() + "(" + sourceItem.getValuesType().toString() + "/=" + getValuesType().toString()); } setValues(sourceItem.getValues()); } diff --git a/core/java/src/org/openda/exchange/NetcdfScalarTimeSeriesExchangeItem.java b/core/java/src/org/openda/exchange/NetcdfScalarTimeSeriesExchangeItem.java index 6e2fe8a45..8a041baa7 100644 --- a/core/java/src/org/openda/exchange/NetcdfScalarTimeSeriesExchangeItem.java +++ b/core/java/src/org/openda/exchange/NetcdfScalarTimeSeriesExchangeItem.java @@ -312,21 +312,20 @@ public void copyValuesFromItem(IExchangeItem sourceItem, IDimensionIndex[] selec private double[] getSelectedValues(IExchangeItem sourceItem, IDimensionIndex[] selectionIndices) { - Class valueType = sourceItem.getValueType(); + ValueType valueType = sourceItem.getValuesType(); Object valuesObject = sourceItem.getValues(); if (selectionIndices != null) { - if ( valueType != IVector.class && - valueType != ITreeVector.class && - valueType != double[].class) { + if ( valueType != ValueType.IVectorType && + valueType != ValueType.doublesType) { throw new RuntimeException("Index selection can not be applied on values of type " + valueType); } // IDimensionIndex[] selectionIndices = vectorConfig.getSelectionIndices(); int[] dimSizes; double[] orgValues; - if (valueType == double[].class) { + if (valueType == ValueType.doublesType) { dimSizes = new int[1]; orgValues = (double[])valuesObject; dimSizes[0] = orgValues.length; diff --git a/core/java/src/org/openda/exchange/dataobjects/AsciiKeywordDataObject.java b/core/java/src/org/openda/exchange/dataobjects/AsciiKeywordDataObject.java index 6ccb7aca4..8343f4bbb 100644 --- a/core/java/src/org/openda/exchange/dataobjects/AsciiKeywordDataObject.java +++ b/core/java/src/org/openda/exchange/dataobjects/AsciiKeywordDataObject.java @@ -24,7 +24,6 @@ import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -94,9 +93,9 @@ public class AsciiKeywordDataObject implements IDataObject{ * @param arguments list of other arguments: *
    *
  1. The name of the file containing the data - * for this IoObject (relative to the working directory).
  2. + * for this DataObject (relative to the working directory). *
  3. Optional, a referenceDate in ISO 8601 notatation, e.g - * for this IoObject (relative to the working directory).
  4. + * for this DataObject (relative to the working directory). * *
*/ @@ -192,11 +191,11 @@ public void initialize(File workingDir, String[] arguments) { /** {@inheritDoc} */ - public IPrevExchangeItem[] getExchangeItems() { + public IExchangeItem[] getExchangeItems() { int n = this.items.size(); Set keys = this.items.keySet(); - IPrevExchangeItem[] result=new IPrevExchangeItem[n]; + IExchangeItem[] result=new IExchangeItem[n]; int i=0; for(String key : keys){ result[i]=this.items.get(key); @@ -214,14 +213,14 @@ public IExchangeItem getDataObjectExchangeItem(String exchangeItemID) { /** {@inheritDoc} */ public String[] getExchangeItemIDs() { - return items.keySet().toArray(new String[items.size()]); + return items.keySet().toArray(new String[0]); } /** {@inheritDoc} */ - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { //TODO: select on role - return items.keySet().toArray(new String[items.size()]); + return items.keySet().toArray(new String[0]); } /** {@inheritDoc} diff --git a/core/java/src/org/openda/exchange/dataobjects/EsriAsciiGridDataObject.java b/core/java/src/org/openda/exchange/dataobjects/EsriAsciiGridDataObject.java index 4148afce4..2cbdb8c30 100644 --- a/core/java/src/org/openda/exchange/dataobjects/EsriAsciiGridDataObject.java +++ b/core/java/src/org/openda/exchange/dataobjects/EsriAsciiGridDataObject.java @@ -130,7 +130,7 @@ public String[] getExchangeItemIDs() { return new String[] {exchangeItemId}; } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { return getExchangeItemIDs(); } @@ -296,7 +296,7 @@ private void readValues(String[] rowItems) throws IOException { ArrayGeometryInfo geometryInfo = new ArrayGeometryInfo(yCoordArray, yCoordValueIndices, yCoordsQuantityInfo, xCoordArray, xCoordValueIndices, xCoordsQuantityInfo,null,null,null); - exchangeItem = new ArrayExchangeItem(exchangeItemId, IPrevExchangeItem.Role.InOut); + exchangeItem = new ArrayExchangeItem(exchangeItemId, IExchangeItem.Role.InOut); exchangeItem.setGeometryInfo(geometryInfo); exchangeItem.setArray(array); diff --git a/core/java/src/org/openda/exchange/dataobjects/NetcdfDataObject.java b/core/java/src/org/openda/exchange/dataobjects/NetcdfDataObject.java index 9d5702202..46c9cc80b 100644 --- a/core/java/src/org/openda/exchange/dataobjects/NetcdfDataObject.java +++ b/core/java/src/org/openda/exchange/dataobjects/NetcdfDataObject.java @@ -23,7 +23,7 @@ import org.openda.blackbox.config.BBUtils; import org.openda.exchange.*; import org.openda.interfaces.*; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; import org.openda.utils.Results; import org.openda.utils.generalJavaUtils.StringUtilities; import org.openda.utils.geometry.GeometryUtils; @@ -366,7 +366,7 @@ private void readNetcdfFile() throws IOException { exchangeItem = new DoubleExchangeItem(exchangeItemId, Role.InOut, variable.readScalarDouble()); } else {//if array. - ArrayExchangeItem arrayBasedExchangeItem = new ArrayExchangeItem(exchangeItemId, IPrevExchangeItem.Role.InOut); + ArrayExchangeItem arrayBasedExchangeItem = new ArrayExchangeItem(exchangeItemId, IExchangeItem.Role.InOut); arrayBasedExchangeItem.setQuantityInfo(new QuantityInfo(exchangeItemId, variable.getUnitsString())); IArrayTimeInfo newTimeInfo = NetcdfUtils.createTimeInfo(variable, netcdfFile, timeInfoCache); //skip variables that do not depend on time. diff --git a/core/java/src/org/openda/exchange/dataobjects/NoosDataObject.java b/core/java/src/org/openda/exchange/dataobjects/NoosDataObject.java index 6ae8a4290..226cac75c 100644 --- a/core/java/src/org/openda/exchange/dataobjects/NoosDataObject.java +++ b/core/java/src/org/openda/exchange/dataobjects/NoosDataObject.java @@ -19,56 +19,34 @@ */ package org.openda.exchange.dataobjects; -import java.io.*; -import java.util.Arrays; -import java.util.LinkedHashMap; - +import org.openda.exchange.AbstractDataObject; import org.openda.exchange.timeseries.NoosTimeSeriesFormatter; import org.openda.exchange.timeseries.TimeSeries; import org.openda.interfaces.IComposableDataObject; -import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem.Role; import org.openda.utils.Glob; +import java.io.*; +import java.util.Arrays; + -public class NoosDataObject implements IDataObject, IComposableDataObject{ +public class NoosDataObject extends AbstractDataObject implements IComposableDataObject { private static final String PROPERTY_PATHNAME = "pathName"; - private LinkedHashMap timeSeriesSet = new LinkedHashMap(); private File workingDir = new File("."); - /** * Initialize the IDataObject * * @param workingDir * Working directory * @param arguments - * First argument should be a filename his fileName may be null, empty or - * contain wildcard characters. - * Additional arguments (may be null zero-length) These arguments are ignored. - */ - - public void initialize(File workingDir, String[] arguments) { - String fileName=arguments[0]; - String newArguments[] = new String[arguments.length-1]; - System.arraycopy(arguments, 1, newArguments, 0, arguments.length - 1); - this.initialize(workingDir, fileName, newArguments); - } - - /** - * Initialize the IDataObject - * - * @param workingDir - * Working directory - * @param fileName * The name of the file containing the data (relative to the working dir) This fileName may be null, empty or - * contain wildcard characters. - * @param arguments + * contain wildcard characters. * Additional arguments (may be null zero-length) These arguments are ignored. */ - public void initialize(File workingDir, String fileName, String[] arguments) { - this.timeSeriesSet = new LinkedHashMap(); + @Override + public void initialize(File workingDir, String[] arguments) { + String fileName = arguments[0]; if(workingDir==null){ this.workingDir=new File("."); @@ -88,6 +66,7 @@ public void initialize(File workingDir, String fileName, String[] arguments) { } else { final String regexp = Glob.createRegex(fileName); + assert workingDir != null; fileNames = workingDir.list(new FilenameFilter() { public boolean accept(File dir, String name) { return name.matches(regexp); @@ -96,6 +75,7 @@ public boolean accept(File dir, String name) { } // Sort names to make the order independent of the OS + assert fileNames != null; Arrays.sort(fileNames); // Then, read each file for (String name : fileNames) { @@ -108,20 +88,6 @@ public boolean accept(File dir, String name) { } } - /** - * Initialize the IDataObject without arguments - * - * @param workingDir - * Working directory - * @param fileName - * The name of the file containing the data (relative to the working dir) This fileName may be null, empty or - * contain wildcard characters. - */ - public void initialize(File workingDir, String fileName) { - final String args[] = {}; - this.initialize(workingDir, fileName, args); - } - /** * Read a single Noos timeseries from a file. * @@ -143,33 +109,20 @@ public void readNoosTimeSeries(File workingDir, String fileName) { NoosTimeSeriesFormatter noosFormatter = new NoosTimeSeriesFormatter(); TimeSeries series = noosFormatter.read(noosFileInputStream); series.setProperty(PROPERTY_PATHNAME, noosFile.getAbsolutePath()); - this.timeSeriesSet.put(series.getId(),series); - } - - - - public String[] getExchangeItemIDs() { - return this.timeSeriesSet.keySet().toArray(new String[this.timeSeriesSet.size()]); - } - - - public String[] getExchangeItemIDs(Role role) { - return this.timeSeriesSet.keySet().toArray(new String[this.timeSeriesSet.size()]); - } - - - public IExchangeItem getDataObjectExchangeItem(String exchangeItemID) { - return this.timeSeriesSet.get(exchangeItemID); + this.exchangeItems.put(series.getId(),series); } /** * Write all time series in this IDataObject that were read from file (with property NoosTimeSeriesIDataObject.PROPERTY_PATHNAME * set). Ignores all other time series, including those obtained from an URL. */ + @Override public void finish() { - if (this.timeSeriesSet == null) return; - for (TimeSeries series : this.timeSeriesSet.values()) - if (series.hasProperty(PROPERTY_PATHNAME)) writeNoosTimeSeries(series); + if (this.exchangeItems == null) return; + for (IExchangeItem exchangeItem : this.exchangeItems.values()) { + TimeSeries timeSeries = (TimeSeries) exchangeItem; + if (timeSeries.hasProperty(PROPERTY_PATHNAME)) writeNoosTimeSeries(timeSeries); + } } /** @@ -237,12 +190,12 @@ public void addExchangeItem(IExchangeItem item) { File file = new File(this.workingDir,fileName); s.setProperty(PROPERTY_PATHNAME, file.getAbsolutePath()); } - this.timeSeriesSet.put(id, s); + this.exchangeItems.put(id, s); } public String toString(){ StringBuilder result= new StringBuilder("noosDataObject{\n"); - for(TimeSeries series: this.timeSeriesSet.values()){ + for(IExchangeItem series: this.exchangeItems.values()){ result.append(series.toString()); } result.append("}\n"); diff --git a/core/java/src/org/openda/exchange/dataobjects/TestDataObject.java b/core/java/src/org/openda/exchange/dataobjects/TestDataObject.java index 8ba809314..1156458af 100644 --- a/core/java/src/org/openda/exchange/dataobjects/TestDataObject.java +++ b/core/java/src/org/openda/exchange/dataobjects/TestDataObject.java @@ -31,8 +31,6 @@ import org.openda.exchange.iotools.IoUtils; import org.openda.interfaces.IComposableDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; -import org.openda.interfaces.IPrevExchangeItem.Role; import org.openda.utils.Results; /** @@ -69,7 +67,7 @@ public String[] getExchangeItemIDs() { } - public String[] getExchangeItemIDs(Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { ArrayList exchangeItemIDs = new ArrayList(); for (IExchangeItem exchangeItem : this.exchangeItems) { @@ -105,7 +103,7 @@ public void addExchangeItem(IExchangeItem item) { public void finish() { List outputExchangeItems = new ArrayList(); for (IExchangeItem exchangeItem : this.exchangeItems) { - if (exchangeItem.getRole() == IPrevExchangeItem.Role.Output || exchangeItem.getRole() == IPrevExchangeItem.Role.InOut) { + if (exchangeItem.getRole() == IExchangeItem.Role.Output || exchangeItem.getRole() == IExchangeItem.Role.InOut) { outputExchangeItems.add(exchangeItem); } } diff --git a/core/java/src/org/openda/exchange/dataobjects/TimeSeriesFormatterDataObject.java b/core/java/src/org/openda/exchange/dataobjects/TimeSeriesFormatterDataObject.java index 1cfcfb0ac..6adc21759 100644 --- a/core/java/src/org/openda/exchange/dataobjects/TimeSeriesFormatterDataObject.java +++ b/core/java/src/org/openda/exchange/dataobjects/TimeSeriesFormatterDataObject.java @@ -20,18 +20,15 @@ package org.openda.exchange.dataobjects; -import org.openda.interfaces.IPrevExchangeItem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; import org.openda.exchange.timeseries.TimeSeries; import org.openda.exchange.timeseries.TimeSeriesFormatter; @@ -167,7 +164,7 @@ public void finish() { logger.debug("Parsing file'{}'", seriesFile.getName()); if (seriesFile.exists()) { TimeSeries timeSeries = seriesMap.get(id); - if ( timeSeries.getRole() == IPrevExchangeItem.Role.Input ) { + if ( timeSeries.getRole() == IExchangeItem.Role.Input ) { continue; } formatter.writeFile(seriesFile, timeSeries, true); diff --git a/core/java/src/org/openda/exchange/ioobjects/NoosTimeSeriesIoObject.java b/core/java/src/org/openda/exchange/ioobjects/NoosTimeSeriesIoObject.java index 611d1fc18..c610c3135 100644 --- a/core/java/src/org/openda/exchange/ioobjects/NoosTimeSeriesIoObject.java +++ b/core/java/src/org/openda/exchange/ioobjects/NoosTimeSeriesIoObject.java @@ -23,7 +23,7 @@ import org.openda.exchange.timeseries.NoosTimeSeriesFormatter; import org.openda.exchange.timeseries.TimeSeries; import org.openda.exchange.timeseries.TimeSeriesSet; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.Glob; import java.io.*; @@ -118,8 +118,8 @@ public void readNoosTimeSeries(File workingDir, String fileName) { * * @return The list of element identifiers can be accessed */ - public IPrevExchangeItem[] getExchangeItems() { - return this.timeSeriesSet.toArray(new IPrevExchangeItem[this.timeSeriesSet.size()]); + public IExchangeItem[] getExchangeItems() { + return this.timeSeriesSet.toArray(new IExchangeItem[this.timeSeriesSet.size()]); } /** diff --git a/core/java/src/org/openda/exchange/iotools/ioCopier.java b/core/java/src/org/openda/exchange/iotools/ioCopier.java index 038aa7bc4..1fd55f054 100644 --- a/core/java/src/org/openda/exchange/iotools/ioCopier.java +++ b/core/java/src/org/openda/exchange/iotools/ioCopier.java @@ -21,7 +21,7 @@ import java.io.File; import java.util.Set; import org.openda.blackbox.interfaces.IoObjectInterface; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.Reflection; /** @@ -39,7 +39,8 @@ public class ioCopier { /** * Add the dumper to an existing ioObject - * @param ioObject + * @param input + * @parm output */ public ioCopier(IoObjectInterface input, IoObjectInterface output){ this.inputIoObject = input; @@ -98,13 +99,13 @@ public ioCopier(File inputWorkingDir, String inputFileName, String inputClassNam * Copy the values for all exchangeItems with named ids */ public void copyValuesForNamedItems(String inputId, String outputId){ - IPrevExchangeItem[] inputItems = this.inputIoObject.getExchangeItems(); - IPrevExchangeItem[] outputItems = this.outputIoObject.getExchangeItems(); - IPrevExchangeItem inputItem = findItem(inputItems,inputId); + IExchangeItem[] inputItems = this.inputIoObject.getExchangeItems(); + IExchangeItem[] outputItems = this.outputIoObject.getExchangeItems(); + IExchangeItem inputItem = findItem(inputItems,inputId); if(inputItem==null){ throw new RuntimeException("Id not found in input object"); } - IPrevExchangeItem outputItem = findItem(outputItems,outputId); + IExchangeItem outputItem = findItem(outputItems,outputId); if(outputItem==null){ throw new RuntimeException("Id not found in output object"); } @@ -135,9 +136,9 @@ public void copyValuesForNamedItems(String inputId, String outputId){ * @param id * @return */ - private IPrevExchangeItem findItem(IPrevExchangeItem[] exchangeItems, String id){ - IPrevExchangeItem result = null; - for(IPrevExchangeItem item : exchangeItems){ + private IExchangeItem findItem(IExchangeItem[] exchangeItems, String id){ + IExchangeItem result = null; + for(IExchangeItem item : exchangeItems){ if(item.getId().equalsIgnoreCase(id)){ result = item; } @@ -145,7 +146,7 @@ private IPrevExchangeItem findItem(IPrevExchangeItem[] exchangeItems, String id) if(result==null){ System.out.println("Id was not found: "+id); System.out.println("Available id's are:"); - for(IPrevExchangeItem item : exchangeItems){ + for(IExchangeItem item : exchangeItems){ System.out.println(" id="+item.getId()); } } diff --git a/core/java/src/org/openda/exchange/iotools/ioDumper.java b/core/java/src/org/openda/exchange/iotools/ioDumper.java index ce73342dd..7ea0073c6 100644 --- a/core/java/src/org/openda/exchange/iotools/ioDumper.java +++ b/core/java/src/org/openda/exchange/iotools/ioDumper.java @@ -23,7 +23,7 @@ import org.openda.blackbox.interfaces.IoObjectInterface; import org.openda.exchange.timeseries.NoosTimeSeriesFormatter; import org.openda.exchange.timeseries.TimeSeries; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.Reflection; import org.openda.utils.Vector; @@ -75,8 +75,8 @@ public ioDumper(File workingDir, String fileName, String className, String args[ * Dump contents to stdout. */ public void dump(){ - IPrevExchangeItem[] items = this.ioObject.getExchangeItems(); - for(IPrevExchangeItem item : items){ + IExchangeItem[] items = this.ioObject.getExchangeItems(); + for(IExchangeItem item : items){ System.out.println("#================================"); if(item instanceof TimeSeries){ System.out.println("TimeSeries id="+item.getId()); diff --git a/core/java/src/org/openda/exchange/timeseries/DelimitedTextTimeSeriesFormatter.java b/core/java/src/org/openda/exchange/timeseries/DelimitedTextTimeSeriesFormatter.java index bd478e199..537ebf6f3 100644 --- a/core/java/src/org/openda/exchange/timeseries/DelimitedTextTimeSeriesFormatter.java +++ b/core/java/src/org/openda/exchange/timeseries/DelimitedTextTimeSeriesFormatter.java @@ -20,7 +20,7 @@ package org.openda.exchange.timeseries; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.ConfigTree; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,7 +45,7 @@ public class DelimitedTextTimeSeriesFormatter extends TimeSeriesFormatter{ private int dateTimeSelector; private int valueSelector; - private IPrevExchangeItem.Role role; + private IExchangeItem.Role role; public DelimitedTextTimeSeriesFormatter(ConfigTree configTree) { String datePattern = configTree.getAsString("dateTimePattern", null); @@ -65,11 +65,11 @@ public DelimitedTextTimeSeriesFormatter(ConfigTree configTree) { String role = configTree.getAsString("role", "input"); if ("input".equalsIgnoreCase(role)){ - this.role = IPrevExchangeItem.Role.Input; + this.role = IExchangeItem.Role.Input; } else if ("output".equalsIgnoreCase(role)) { - this.role = IPrevExchangeItem.Role.Output; + this.role = IExchangeItem.Role.Output; } else if ("inout".equalsIgnoreCase(role)) { - this.role = IPrevExchangeItem.Role.InOut; + this.role = IExchangeItem.Role.InOut; } if (this.dateFormatter!=null) { diff --git a/core/java/src/org/openda/exchange/timeseries/TimeSeries.java b/core/java/src/org/openda/exchange/timeseries/TimeSeries.java index 13e0f9bc8..48ef6bff7 100644 --- a/core/java/src/org/openda/exchange/timeseries/TimeSeries.java +++ b/core/java/src/org/openda/exchange/timeseries/TimeSeries.java @@ -25,7 +25,6 @@ import org.openda.interfaces.IArray; import org.openda.interfaces.IExchangeItem; import org.openda.interfaces.IGeometryInfo; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.interfaces.IQuantityInfo; import org.openda.interfaces.ITimeInfo; import org.openda.utils.Array; @@ -54,12 +53,12 @@ * @author verlaanm */ -public class TimeSeries implements IPrevExchangeItem, IExchangeItem{ +public class TimeSeries implements IExchangeItem{ // define and set defaults // meta data private String description = null; private String location = ""; - private final double position[] = {0.0, 0.0}; // {longitude,latitude} WGS84 + private final double[] position = {0.0, 0.0}; // {longitude,latitude} WGS84 private double height = 0.0; // user defined for now private String source = "observed"; // what produced the data private String quantity = "waterlevel"; // what do values represent @@ -67,11 +66,11 @@ public class TimeSeries implements IPrevExchangeItem, IExchangeItem{ private String id = "id-not-set"; // unique identifier private boolean autoId = true; // automatically set to location.quantity // by default - private final HashMap properties = new HashMap(); // additional properties - private final java.util.Vector defaultProps = new java.util.Vector(); // data - private double times[] = null; // times for values as MJD - private double values[] = null; // this is the real data! - private final HashMap extraValues = new HashMap(); // optional arrays for secondary values + private final HashMap properties = new HashMap<>(); // additional properties + private final java.util.Vector defaultProps = new java.util.Vector<>(); // data + private double[] times = null; // times for values as MJD + private double[] values = null; // this is the real data! + private final HashMap extraValues = new HashMap<>(); // optional arrays for secondary values // (like Matroos analysis times) protected Role role; private double tstart = Double.NaN; @@ -118,12 +117,12 @@ public TimeSeries(TimeSeries other) { * @param times The time array. * @param values The value array. */ - public TimeSeries(double times[], double values[]) { + public TimeSeries(double[] times, double[] values) { this(); this.setData(times, values); } - public TimeSeries(double times[], double values[], double x, double y, String source, String quantity, String unit, + public TimeSeries(double[] times, double[] values, double x, double y, String source, String quantity, String unit, String location, Role role) { this(times, values, x, y, source, quantity, unit, location); this.role = role; @@ -141,7 +140,7 @@ public TimeSeries(double times[], double values[], double x, double y, String so * @param unit String describing the value's unit * @param location String describing the location of this series */ - public TimeSeries(double times[], double values[], double x, double y, String source, String quantity, String unit, String location) { + public TimeSeries(double[] times, double[] values, double x, double y, String source, String quantity, String unit, String location) { this(times, values, source, quantity, unit, location); this.setPosition(x, y); this.setId(this.location + "." + this.getQuantityId()); @@ -274,7 +273,7 @@ public void setPosition(double x, double y) { * @return Array containing the X and the Y coordinate. */ public double[] getPosition() { - double result[] = new double[2]; + double[] result = new double[2]; result[0] = this.position[0]; result[1] = this.position[1]; return result; @@ -354,7 +353,7 @@ public double[] getTimes() { } /** - * @see org.openda.interfaces.IPrevExchangeItem#setTimes(double[]) + * @see org.openda.interfaces.IExchangeItem#setTimes(double[]) */ public void setTimes(double[] times) { @@ -385,7 +384,7 @@ public double[] getValuesAsDoubles() { } /** - * @see org.openda.interfaces.IPrevExchangeItem#axpyOnValues(double, double[]) + * @see org.openda.interfaces.IExchangeItem#axpyOnValues(double, double[]) */ public void axpyOnValues(double alpha, double[] axpyValues) { @@ -402,7 +401,7 @@ public void axpyOnValues(double alpha, double[] axpyValues) { } /** - * @see org.openda.interfaces.IPrevExchangeItem#multiplyValues(double[]) + * @see org.openda.interfaces.IExchangeItem#multiplyValues(double[]) */ public void multiplyValues(double[] multiplicationFactors) { @@ -562,7 +561,7 @@ public void setProperty(String propertyName, String propertyValue) { * @return Array with the property names. */ public String[] getPropertyNames() { - String result[] = new String[this.properties.size()]; + String[] result = new String[this.properties.size()]; int i = 0; for (String label : this.properties.keySet()) { result[i] = label; @@ -578,7 +577,7 @@ public String[] getPropertyNames() { * @return Array with the default property names. */ public String[] getDefaultPropertyNames() { - String result[] = new String[this.defaultProps.size()]; + String[] result = new String[this.defaultProps.size()]; int i = 0; for (String label : this.defaultProps) { result[i] = label; @@ -730,8 +729,8 @@ public TimeSeries selectTimeSubset(double startTime, double endTime) { iEnd++; } } - double timesNew[]; - double valuesNew[]; + double[] timesNew; + double[] valuesNew; TimeSeries result; if (iEnd > iStart) { timesNew = new double[iEnd - iStart]; @@ -748,12 +747,12 @@ public TimeSeries selectTimeSubset(double startTime, double endTime) { // add metadata result.setHeight(this.getHeight()); result.setLocation(this.getLocation()); - double pos[] = this.getPosition(); + double[] pos = this.getPosition(); result.setPosition(pos[0], pos[1]); result.setQuantity(this.getQuantityId()); result.setSource(this.getSource()); result.setUnit(this.getUnitId()); - String propNames[] = getPropertyNames(); + String[] propNames = getPropertyNames(); for (String propName : propNames) { result.setProperty(propName, this.getProperty(propName)); } @@ -776,9 +775,9 @@ public TimeSeries selectTimeSubset(double startTime, double endTime) { */ public TimeSeries selectValueSubset(double minValue, double maxValue) { // make selection of values - java.util.Vector tempTimes = new java.util.Vector(); - java.util.Vector tempValues = new java.util.Vector(); - java.util.Vector tempIndex = new java.util.Vector(); + java.util.Vector tempTimes = new java.util.Vector<>(); + java.util.Vector tempValues = new java.util.Vector<>(); + java.util.Vector tempIndex = new java.util.Vector<>(); for (int i = 0; i < this.values.length; i++) { if ((Double.isNaN(minValue)) | (this.values[i] >= minValue)) { if ((Double.isNaN(maxValue)) | (this.values[i] <= maxValue)) { @@ -801,12 +800,12 @@ public TimeSeries selectValueSubset(double minValue, double maxValue) { // add metadata result.setHeight(this.getHeight()); result.setLocation(this.getLocation()); - double pos[] = this.getPosition(); + double[] pos = this.getPosition(); result.setPosition(pos[0], pos[1]); result.setQuantity(this.getQuantityId()); result.setSource(this.getSource()); result.setUnit(this.getUnitId()); - String propNames[] = getPropertyNames(); + String[] propNames = getPropertyNames(); for (String propName : propNames) { result.setProperty(propName, this.getProperty(propName)); } @@ -828,14 +827,14 @@ public TimeSeries selectValueSubset(double minValue, double maxValue) { public String toString() { StringBuilder result = new StringBuilder("TimeSeries(\n"); result.append(" Location = ").append(this.getLocation()).append("\n"); - double pos[] = this.getPosition(); + double[] pos = this.getPosition(); result.append(" Position = (").append(pos[0]).append(",").append(pos[1]).append(")\n"); result.append(" Height = ").append(this.getHeight()).append("\n"); result.append(" Quantity = ").append(this.getQuantityId()).append("\n"); result.append(" Unit = ").append(this.getUnitId()).append("\n"); result.append(" Source = ").append(this.getSource()).append("\n"); result.append(" Id = ").append(this.getId()).append("\n"); - String propNames[] = getPropertyNames(); + String[] propNames = getPropertyNames(); for (String propName : propNames) { result.append(" ").append(propName).append(" = ").append(this.getProperty(propName)).append("\n"); } @@ -890,7 +889,7 @@ public void setId(String id) { public void setValues(Object values) { - if (values instanceof org.openda.exchange.timeseries.TimeSeries) { + if (values instanceof TimeSeries) { TimeSeries series = (TimeSeries) values; this.setData(series.getTimes(), series.getValuesAsDoubles()); } else if (values instanceof double[]) { @@ -902,7 +901,7 @@ public void setValues(Object values) { this.values = new double[valuesCast.length]; System.arraycopy(valuesCast, 0, this.values, 0, valuesCast.length); }else if (values instanceof IArray){ - double valuesCast[]=((IArray)values).getValuesAsDoubles(); + double[] valuesCast =((IArray)values).getValuesAsDoubles(); if ((this.times == null) || (this.times.length != valuesCast.length)) { throw new RuntimeException( "TimeSeries: length for times and values do not match."); @@ -1065,9 +1064,8 @@ public double getInterpolatedExtraValueAsDouble(String key, double time) { * Show Type of this object for proper casting */ - @SuppressWarnings("rawtypes") public Class getValueType() { - return org.openda.utils.Array.class; + return TimeSeries.class; } @@ -1194,14 +1192,14 @@ public boolean equals(TimeSeries other, boolean verbose) { if (this.values == null && other.values == null) return true; if (this.times.length != other.times.length) { if (verbose) - System.err.println("Lengths of the time arrays do not match. this: " + String.valueOf(this.times.length) - + "; other: " + String.valueOf(other.times.length)); + System.err.println("Lengths of the time arrays do not match. this: " + this.times.length + + "; other: " + other.times.length); return false; } if (this.values.length != other.values.length) { if (verbose) - System.err.println("Lengths of the value arrays do not match. this: " + String.valueOf(this.values.length) - + "; other: " + String.valueOf(other.values.length)); + System.err.println("Lengths of the value arrays do not match. this: " + this.values.length + + "; other: " + other.values.length); return false; } if (this.extraValues.keySet().size() != other.extraValues.keySet().size()) { @@ -1209,13 +1207,13 @@ public boolean equals(TimeSeries other, boolean verbose) { return false; } for (String key : this.extraValues.keySet()) { - if (!other.extraValues.keySet().contains(key)) { + if (!other.extraValues.containsKey(key)) { if (verbose) System.err.println("this.extraValues key missing in other: " + key); return false; } } for (String key : other.extraValues.keySet()) { - if (!this.extraValues.keySet().contains(key)) { + if (!this.extraValues.containsKey(key)) { if (verbose) System.err.println("other.extraValues key missing in this: " + key); return false; } @@ -1223,22 +1221,22 @@ public boolean equals(TimeSeries other, boolean verbose) { for (int i = 0; i < this.times.length; ++i) { if (this.times[i] != other.times[i] && !(Double.isNaN(this.times[i]) && Double.isNaN(other.times[i]))) { if (verbose) - System.err.println("At index " + String.valueOf(i) + ": times do not match. this: " - + String.valueOf(this.times[i]) + "; other: " + String.valueOf(other.times[i])); + System.err.println("At index " + i + ": times do not match. this: " + + this.times[i] + "; other: " + other.times[i]); return false; } if (this.values[i] != other.values[i] && !(Double.isNaN(this.values[i]) && Double.isNaN(other.values[i]))) { if (verbose) - System.err.println("At index " + String.valueOf(i) + ": values do not match. this: " - + String.valueOf(this.values[i]) + "; other: " + String.valueOf(other.values[i])); + System.err.println("At index " + i + ": values do not match. this: " + + this.values[i] + "; other: " + other.values[i]); return false; } for (String key : this.extraValues.keySet()) { if (this.extraValues.get(key)[i] != other.extraValues.get(key)[i] && !(Double.isNaN(this.extraValues.get(key)[i]) && Double.isNaN(other.extraValues.get(key)[i]))) { if (verbose) - System.err.println("At index " + String.valueOf(i) + ": extraValues " + key + " do not match. this: " - + String.valueOf(this.values[i]) + "; other: " + String.valueOf(other.values[i])); + System.err.println("At index " + i + ": extraValues " + key + " do not match. this: " + + this.values[i] + "; other: " + other.values[i]); return false; } } @@ -1416,7 +1414,7 @@ public IQuantityInfo getQuantityInfo() { public IGeometryInfo getGeometryInfo() { - double pos[]=this.getPosition(); + double[] pos=this.getPosition(); if((pos!=null) && (pos.length==2)){ return new PointGeometryInfo(pos[0], pos[1], this.getHeight()); }else{ diff --git a/core/java/src/org/openda/interfaces/IComposableDataObject.java b/core/java/src/org/openda/interfaces/IComposableDataObject.java index f9feac375..ef87acd74 100644 --- a/core/java/src/org/openda/interfaces/IComposableDataObject.java +++ b/core/java/src/org/openda/interfaces/IComposableDataObject.java @@ -26,7 +26,7 @@ public interface IComposableDataObject extends IDataObject { * exchangeItem after adding it, but before calling finish, may alter the outcome. * Throws an UnsupportedOperationException when the dataObject does not support the addition of items. * A RuntimeException is thrown if the type of data can not be handled. Note that in general, it is also - * possible that the type of echchangeItem can be handled, but with degraded meta data. + * possible that the type of exchangeItem can be handled, but with degraded meta data. * * @param item exchangeItem to be duplicated */ diff --git a/core/java/src/org/openda/interfaces/IDataObject.java b/core/java/src/org/openda/interfaces/IDataObject.java index 1d35baeb3..9ba817d74 100644 --- a/core/java/src/org/openda/interfaces/IDataObject.java +++ b/core/java/src/org/openda/interfaces/IDataObject.java @@ -40,7 +40,7 @@ public interface IDataObject extends IConfigurable { * @param role Input, Output, or InOut (i.e. both) * @return The array of exchange item identifiers. */ - String [] getExchangeItemIDs(IPrevExchangeItem.Role role); + String [] getExchangeItemIDs(IExchangeItem.Role role); /** * Get the exchange item specified by exchangeItemID. diff --git a/core/java/src/org/openda/interfaces/IEnsembleDataObject.java b/core/java/src/org/openda/interfaces/IEnsembleDataObject.java index ecf93db95..002bcdeee 100644 --- a/core/java/src/org/openda/interfaces/IEnsembleDataObject.java +++ b/core/java/src/org/openda/interfaces/IEnsembleDataObject.java @@ -29,7 +29,7 @@ * * If a DataObject implements this interface, then the following methods should ignore any ensemble exchange items: * getExchangeItemIDs() - * getExchangeItemIDs(IPrevExchangeItem.Role role) + * getExchangeItemIDs(IExchangeItem.Role role) * * If a DataObject implements this interface, then the following method should throw an IllegalStateException when it is called for an ensemble exchange item: * getDataObjectExchangeItem(String exchangeItemID) diff --git a/core/java/src/org/openda/interfaces/IExchangeItem.java b/core/java/src/org/openda/interfaces/IExchangeItem.java index 393604d81..bc9835a5a 100644 --- a/core/java/src/org/openda/interfaces/IExchangeItem.java +++ b/core/java/src/org/openda/interfaces/IExchangeItem.java @@ -21,40 +21,64 @@ package org.openda.interfaces; +import java.io.Serializable; + /** * Item for which the values can be retrieved from or provided to the model. * The model tells which exchange items it has, after which the exchange item is used to access the values. * The IExchange item currently extends the 'previous' version. */ -public interface IExchangeItem extends IPrevExchangeItem{ +public interface IExchangeItem extends Serializable { /** * List of available data types. */ - public enum ValueType { + enum ValueType { /** corresponds to java int */ intType, /** corresponds to java double */ doubleType, /** corresponds to java double[] -> to be replaced by IArray */ doublesType, + /** corresponds to java float */ + floatType, /** corresponds to java float[] -> to be replaced by IArray */ floatsType, /** corresponds to java double[][] -> to be replaced by IArray */ doubles2dType, /** corresponds to java String */ StringType, + /** corresponds to java Boolean */ + BooleanType, /** IVector -> in future IVector will extend IArray */ IVectorType, /** IArray */ - IArrayType + IArrayType, + /** corresponds to java Date */ + DateType, + /** corresponds to ITime */ + ITimeType, + /** can be any type of object, only used for very specific implementations */ + custom + } + + /** + * List of possible roles for the exchange values. + */ + enum Role { + /** Input for the model.*/ + Input, + /** Output from the model.*/ + Output, + /** Both input for the model and output from the model.*/ + InOut } /** * Get the role of the exchange item (input, output, or both) * @return The exchange items's role */ - public Role getRole(); + Role getRole(); /** * The identifier for the exchangeItem (must be unique within the context of a model instance). @@ -75,7 +99,7 @@ public enum ValueType { * @param sourceItem The item to copy the values from. * */ - public void copyValuesFromItem(IExchangeItem sourceItem); + void copyValuesFromItem(IExchangeItem sourceItem); /** * Return information about time if it exists. @@ -84,7 +108,7 @@ public enum ValueType { * * @return time info */ - public ITimeInfo getTimeInfo(); + ITimeInfo getTimeInfo(); /** * Return information about the content of the data if it exists. Returns null if no quantity info exists. @@ -92,7 +116,7 @@ public enum ValueType { * * @return quantity info */ - public IQuantityInfo getQuantityInfo(); + IQuantityInfo getQuantityInfo(); /** * Return information about the spatial aspect of the data if it exists. Returns null if no geometry info exists. @@ -100,18 +124,63 @@ public enum ValueType { * * @return geometry info */ - public IGeometryInfo getGeometryInfo(); + IGeometryInfo getGeometryInfo(); /** * Ask which object type will be returned by getValues() call * @return The object type that will be returned by getValues() call */ - public ValueType getValuesType(); + ValueType getValuesType(); /** * Get the values of the exchange item * @return The values, according the type as defined in getValueType() */ - public Object getValues(); + Object getValues(); + + /** + * Get the values of the exchange item as an array of doubles + * @return The values as an array of doubles + */ + double[] getValuesAsDoubles(); + + /** + * Perform a values += alpha * axpyValues operation on each value in the exchange item. + * @param alpha The alpha in state variable += alpha * vector. + * @param axpyValues The values for the axpy-operation on all values in the exchange item. + */ + void axpyOnValues(double alpha, double[] axpyValues); + + /** + * Multiply each value in the exchange item's value with the related multiplication factor. + * @param multiplicationFactors The multiplication factors for all exchange time values. + */ + void multiplyValues(double[] multiplicationFactors); + + /** + * Set the values of the exchange item + * @param values The values to be set, according the type as defined in getValueType() + */ + void setValues(Object values); + + /** + * Set the values of the exchange item + * @param values The values as an array of doubles + */ + void setValuesAsDoubles(double[] values); + + /** + * Check if the exchange item is a time series + * @return null if the exchange item is time independent, series of time stamps/spans otherwise + */ + double[] getTimes(); + + /** + * Set the times for the exchangeItem + * setTimes is only allowed if getTimes() != null + * and if the exchangeItem has role Input or InOut + * @param times The times as an array of doubles + */ + void setTimes(double[] times); } diff --git a/core/java/src/org/openda/interfaces/IModelInstance.java b/core/java/src/org/openda/interfaces/IModelInstance.java index 383969c05..5d6305029 100644 --- a/core/java/src/org/openda/interfaces/IModelInstance.java +++ b/core/java/src/org/openda/interfaces/IModelInstance.java @@ -39,7 +39,7 @@ public interface IModelInstance extends IDataObject, IInstance { * @param exchangeItemID The exchange item identifier. * @return The required exchange item. */ - IPrevExchangeItem getExchangeItem(String exchangeItemID); + IExchangeItem getExchangeItem(String exchangeItemID); /************************************* *** Time information / Computing diff --git a/core/java/src/org/openda/interfaces/IObservationDescriptions.java b/core/java/src/org/openda/interfaces/IObservationDescriptions.java index 91b02d976..f019fbeb5 100644 --- a/core/java/src/org/openda/interfaces/IObservationDescriptions.java +++ b/core/java/src/org/openda/interfaces/IObservationDescriptions.java @@ -32,7 +32,7 @@ public interface IObservationDescriptions extends Serializable{ /** Get the exchange items describing the measures available in the stoch. observer. * @return All exchange items in the stoch. observer. */ - List getExchangeItems(); + List getExchangeItems(); /** Get properties (values) that correspond to a given key. * diff --git a/core/java/src/org/openda/interfaces/IPrevExchangeItem.java b/core/java/src/org/openda/interfaces/IPrevExchangeItem.java index 27e7196e6..b375c482e 100644 --- a/core/java/src/org/openda/interfaces/IPrevExchangeItem.java +++ b/core/java/src/org/openda/interfaces/IPrevExchangeItem.java @@ -26,7 +26,10 @@ /** * Item for which the values can be retrieved from or provided to the model. * The model tells which exchange items it has, after which the exchange item is used to access the values. - * This version of the exchange item is called the 'previous' version. It will become deprecated not too + * This version of the exchange item is called the 'previous' version. + * @deprecated + * This class is replaced by the generic DFlowFMXynExchangeItem class + * * long from now, so new model and data object developers should implement * @see IExchangeItem */ @@ -35,7 +38,7 @@ public interface IPrevExchangeItem extends Serializable { /** * List of possible roles for the exchange values. */ - public enum Role { + enum PrevRole { /** Input for the model.*/ Input, /** Output from the model.*/ @@ -56,54 +59,48 @@ public enum Role { */ String getDescription(); - /** - * Ask which object type will be returned by getValues() call - * @return The object type that will be returned by getValues() call - */ - public Class getValueType(); - /** * Get the role of the exchange item (input, output, or both) * @return The exchange items's role */ - public Role getRole(); + PrevRole getPrevRole(); /** * Get the values of the exchange item * @return The values, according the type as defined in getValueType() */ - public Object getValues(); + Object getValues(); /** * Get the values of the exchange item as an array of doubles * @return The values as an array of doubles */ - public double[] getValuesAsDoubles(); + double[] getValuesAsDoubles(); /** * Perform a values += alpha * axpyValues operation on each value in the exchange item. * @param alpha The alpha in state variable += alpha * vector. * @param axpyValues The values for the axpy-operation on all values in the exchange item. */ - public void axpyOnValues(double alpha, double[] axpyValues); + void axpyOnValues(double alpha, double[] axpyValues); /** * Multiply each value in the exchange item's value with the related multiplication factor. * @param multiplicationFactors The multiplication factors for all exchange time values. */ - public void multiplyValues(double[] multiplicationFactors); + void multiplyValues(double[] multiplicationFactors); /** * Set the values of the exchange item - * @param values The values to be set, ccording the type as defined in getValueType() + * @param values The values to be set, according the type as defined in getValueType() */ - public void setValues(Object values); + void setValues(Object values); /** * Set the values of the exchange item * @param values The values as an array of doubles */ - public void setValuesAsDoubles(double[] values); + void setValuesAsDoubles(double[] values); /** * Check if the exchange item is a time series @@ -117,5 +114,5 @@ public enum Role { * and if the exchangeItem has role Input or InOut * @param times The times as an array of doubles */ - public void setTimes(double[] times); + void setTimes(double[] times); } diff --git a/core/java/src/org/openda/noiseModels/MapsNoiseModelInstance.java b/core/java/src/org/openda/noiseModels/MapsNoiseModelInstance.java index d3e17cc49..c3e7d18a2 100644 --- a/core/java/src/org/openda/noiseModels/MapsNoiseModelInstance.java +++ b/core/java/src/org/openda/noiseModels/MapsNoiseModelInstance.java @@ -26,7 +26,7 @@ import org.openda.exchange.TimeInfo; import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.*; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; import org.openda.interfaces.IStochModelFactory.OutputLevel; import org.openda.localization.LocalizationDomainsSimpleModel; import org.openda.noiseModels.SpatialCorrelationStochVector.CoordinatesType; @@ -398,7 +398,7 @@ private void addSystemNoiseChild(StochTreeVector systemNoise, String id, Coordin systemNoise.addChild(spatialCorrelationStochVector); } - public IPrevExchangeItem getExchangeItem(String exchangeItemID) { + public IExchangeItem getExchangeItem(String exchangeItemID) { return outputSeries.get(exchangeItemID); } diff --git a/core/java/src/org/openda/noiseModels/TimeSeriesNoiseModelInstance.java b/core/java/src/org/openda/noiseModels/TimeSeriesNoiseModelInstance.java index 1c51bd5e5..5f0fbe461 100644 --- a/core/java/src/org/openda/noiseModels/TimeSeriesNoiseModelInstance.java +++ b/core/java/src/org/openda/noiseModels/TimeSeriesNoiseModelInstance.java @@ -24,7 +24,7 @@ import org.openda.exchange.timeseries.TimeSeries; import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.*; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; import org.openda.interfaces.IStochModelFactory.OutputLevel; import org.openda.utils.*; import org.openda.utils.io.FileBasedModelState; @@ -328,7 +328,7 @@ public void initialize(File workingDir, String[] arguments) { this.sysNoiseIntensity = new StochVector(new Vector(seriesTrees.length) , this.standardDeviation); } - public IPrevExchangeItem getExchangeItem(String exchangeItemID) { + public IExchangeItem getExchangeItem(String exchangeItemID) { return outputSeries.get(exchangeItemID); } diff --git a/core/java/src/org/openda/uncertaintyModels/ParameterDrawer.java b/core/java/src/org/openda/uncertaintyModels/ParameterDrawer.java index df62149f9..3d0f088de 100644 --- a/core/java/src/org/openda/uncertaintyModels/ParameterDrawer.java +++ b/core/java/src/org/openda/uncertaintyModels/ParameterDrawer.java @@ -145,7 +145,7 @@ public IVector[] getStateScaling(IObservationDescriptions observationDescription } - public IPrevExchangeItem getExchangeItem(String exchangeItemID) { + public IExchangeItem getExchangeItem(String exchangeItemID) { throw new UnsupportedOperationException("org.openda.uncertaintyModels.ParameterDrawer.getExchangeItem(): Not implemented yet."); } @@ -210,7 +210,7 @@ public String[] getExchangeItemIDs() { } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { throw new UnsupportedOperationException("org.openda.uncertaintyModels.ParameterDrawer.getExchangeItemIDs(): Not implemented yet."); } diff --git a/core/java/src/org/openda/uncertaintygui/tablemodels/UIModel.java b/core/java/src/org/openda/uncertaintygui/tablemodels/UIModel.java index 66eb629e7..44d1ac3a7 100644 --- a/core/java/src/org/openda/uncertaintygui/tablemodels/UIModel.java +++ b/core/java/src/org/openda/uncertaintygui/tablemodels/UIModel.java @@ -20,7 +20,7 @@ package org.openda.uncertaintygui.tablemodels; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.uncertainties.UncertainItem; import org.openda.uncertainties.Uncertainties; import org.openda.uncertainties.autocorrelationfunctions.AutoCorrelationFunction; @@ -65,7 +65,7 @@ public UIModel() { * * @param uncertaintiesSpecificationFile File containing the uncertainty specification * @param reader If not equal to null, there is already an opened file reader - * @throws IOException + * @throws IOException If an error occurs, an exception is thrown. */ public void readUncertaintyFiles(File uncertaintiesSpecificationFile, Reader reader) throws IOException { @@ -79,8 +79,7 @@ public void readUncertaintyFiles(File uncertaintiesSpecificationFile, Reader rea } else { uncertaintyReader = new UncertaintyReader(reader); } - boolean getActiveUncertaintiesOnly = false; - uncertainties = uncertaintyReader.getUncertainties(getActiveUncertaintiesOnly); + uncertainties = uncertaintyReader.getUncertainties(false); uncertaintyReader.close(); } @@ -161,37 +160,36 @@ private void addNewVariationUncertaintyFromMapping(Uncertainties uncertainties, variationFunction.setUncertainItem(uncertainItem); uncertainties.addVariationFunction(variationFunction); } - - private void addNewPdfFromExchangeItem(Uncertainties uncertainties, IPrevExchangeItem exchangeItem) { - - //create new UncertainItem for uncertainty from mapping. - UncertainItem uncertainItem = new UncertainItem(exchangeItem.getId(), "", false); - - //get description. - if (exchangeItem.getDescription() != null) { - uncertainItem.setDescription(exchangeItem.getDescription()); - } - - // get basic value from mapping file. - double[] valuesAsDoubles = exchangeItem.getValuesAsDoubles(); - double value = Double.NaN; - if (valuesAsDoubles.length == 1) { - value = valuesAsDoubles[0]; - } - uncertainItem.setBasicValue(value); - - //create new PDF for uncertainty from mapping. - PDF pdf = new NormalDistribution(); - pdf.setUncertainItem(uncertainItem); - uncertainties.addPdf(pdf); - - //create new AutoCorrelationFunction for uncertainty from mapping. - AutoCorrelationFunction autoCorrelationFunction = new GaussianCorrelation(); - autoCorrelationFunction.setUncertainItem(uncertainItem); - uncertainties.addAutoCorrelation(autoCorrelationFunction); - } - - public File getUncertaintySpecificationFile() { + private void addNewPdfFromExchangeItem(Uncertainties uncertainties, IExchangeItem exchangeItem) { + + //create new UncertainItem for uncertainty from mapping. + UncertainItem uncertainItem = new UncertainItem(exchangeItem.getId(), "", false); + + //get description. + if (exchangeItem.getDescription() != null) { + uncertainItem.setDescription(exchangeItem.getDescription()); + } + + // get basic value from mapping file. + double[] valuesAsDoubles = exchangeItem.getValuesAsDoubles(); + double value = Double.NaN; + if (valuesAsDoubles.length == 1) { + value = valuesAsDoubles[0]; + } + uncertainItem.setBasicValue(value); + + //create new PDF for uncertainty from mapping. + PDF pdf = new NormalDistribution(); + pdf.setUncertainItem(uncertainItem); + uncertainties.addPdf(pdf); + + //create new AutoCorrelationFunction for uncertainty from mapping. + AutoCorrelationFunction autoCorrelationFunction = new GaussianCorrelation(); + autoCorrelationFunction.setUncertainItem(uncertainItem); + uncertainties.addAutoCorrelation(autoCorrelationFunction); + } + + public File getUncertaintySpecificationFile() { return this.uncertaintyGuiConfiguration.getUncertaintiesSpecificationFile(); } diff --git a/core/java/src/org/openda/utils/ObjectSupport.java b/core/java/src/org/openda/utils/ObjectSupport.java index 20f9f226e..bccd4c993 100644 --- a/core/java/src/org/openda/utils/ObjectSupport.java +++ b/core/java/src/org/openda/utils/ObjectSupport.java @@ -18,10 +18,7 @@ * along with OpenDA. If not, see . */ package org.openda.utils; -import org.openda.interfaces.IAlgorithm; -import org.openda.interfaces.IConfigurable; -import org.openda.interfaces.IStochModelFactory; -import org.openda.interfaces.IStochObserver; +import org.openda.interfaces.*; import java.io.File; @@ -31,10 +28,11 @@ public class ObjectSupport { public static void checkCompatibility(Object objectInstance, Class expectedType, String messagePrefix) { + if (expectedType == IExchangeItem.ValueType.custom.getClass()) return; if (!expectedType.isInstance(objectInstance)) { String prefix = messagePrefix != null ? messagePrefix + ": " : ""; throw new RuntimeException(prefix + "Object instance of type " + objectInstance.getClass().getName() - + " is not assignable to " + (expectedType.isInterface() ? "interface" : "class") + expectedType.getName()); + + " is not assignable to " + (expectedType.isInterface() ? "interface" : "class ") + expectedType.getName()); } } diff --git a/core/java/src/org/openda/utils/Statistics.java b/core/java/src/org/openda/utils/Statistics.java index ae3c05a75..7588112de 100644 --- a/core/java/src/org/openda/utils/Statistics.java +++ b/core/java/src/org/openda/utils/Statistics.java @@ -18,7 +18,7 @@ * along with OpenDA. If not, see . */ package org.openda.utils; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.interfaces.IObservationDescriptions; import org.openda.interfaces.ITreeVector; import org.openda.interfaces.IVector; @@ -92,15 +92,15 @@ private void computeStatisticsOverAll() { public Statistics(IVector values, IObservationDescriptions descriptions){ this.values=values; this.descriptions=descriptions; - List items = null; + List items = null; try{ items = this.descriptions.getExchangeItems(); }catch (Exception e) { - items = new ArrayList(); //Empty list + items = new ArrayList(); //Empty list } int indFirst = 0; int indLast = 0; - for(IPrevExchangeItem item : items){ // assume the exchangeItems are in the + for(IExchangeItem item : items){ // assume the exchangeItems are in the String id = item.getId(); double times[] = item.getTimes(); if (times != null) { diff --git a/core/java/src/org/openda/utils/geometry/GeometryUtils.java b/core/java/src/org/openda/utils/geometry/GeometryUtils.java index b853b2767..5b7e8453e 100644 --- a/core/java/src/org/openda/utils/geometry/GeometryUtils.java +++ b/core/java/src/org/openda/utils/geometry/GeometryUtils.java @@ -45,40 +45,10 @@ public class GeometryUtils { private GeometryUtils() { } - /** - * Returns the number of grid cells for the given exchangeItem and timeIndex. If item is not a grid, then that is the same as a grid with only one cell. - */ - public static int getGridCellCount(IPrevExchangeItem prevExchangeItem, int timeIndex) { - //get exchangeItem. - if (!(prevExchangeItem instanceof IExchangeItem)) { - //IPrevExchangeItem has no geometryInfo, so can never be a grid. - return 1; - } - IExchangeItem exchangeItem = (IExchangeItem) prevExchangeItem; - - //get geometryInfo. - IGeometryInfo geometryInfo; - if (exchangeItem instanceof IGridTimeSeriesExchangeItem && timeIndex != -1) { - geometryInfo = ((IGridTimeSeriesExchangeItem) exchangeItem).getGeometryInfoForSingleTimeIndex(timeIndex); - } else { - geometryInfo = exchangeItem.getGeometryInfo(); - } - - //get cellCount. - return getGridCellCount(geometryInfo); - } - /** * Returns the number of grid cells for the given exchangeItem. If item is not a grid, then that is the same as a grid with only one cell. */ - public static int getGridCellCount(IPrevExchangeItem prevExchangeItem) { - //get exchangeItem. - if (!(prevExchangeItem instanceof IExchangeItem)) { - //IPrevExchangeItem has no geometryInfo, so can never be a grid. - return 1; - } - IExchangeItem exchangeItem = (IExchangeItem) prevExchangeItem; - + public static int getGridCellCount(IExchangeItem exchangeItem) { return getGridCellCount(exchangeItem.getGeometryInfo()); } @@ -92,17 +62,6 @@ public static int getGridCellCount(IGeometryInfo geometryInfo) { return ((LayeredIrregularGridGeometryInfo) geometryInfo).getCellCount(); } - public static boolean isScalar(IPrevExchangeItem prevExchangeItem) { - //get exchangeItem. - if (!(prevExchangeItem instanceof IExchangeItem)) { - //IPrevExchangeItem has no geometryInfo, so can never be a grid. - return true; - } - IExchangeItem exchangeItem = (IExchangeItem) prevExchangeItem; - - return isScalar(exchangeItem.getGeometryInfo()); - } - public static boolean isScalar(IGeometryInfo geometryInfo) { if (geometryInfo == null || geometryInfo instanceof PointGeometryInfo) {//if scalar. return true; diff --git a/core/java/test/org/openda/blackbox/config/testData/wrapper/BBWrapperConfigTest_config.xml b/core/java/test/org/openda/blackbox/config/testData/wrapper/BBWrapperConfigTest_config.xml index ee509810a..21c89c651 100644 --- a/core/java/test/org/openda/blackbox/config/testData/wrapper/BBWrapperConfigTest_config.xml +++ b/core/java/test/org/openda/blackbox/config/testData/wrapper/BBWrapperConfigTest_config.xml @@ -21,11 +21,11 @@ - + %outputFile% outputIoObject %timeZone% %startTime% - + diff --git a/core/java/test/org/openda/blackbox/io/BaseTemplateDataObjectTest.java b/core/java/test/org/openda/blackbox/io/BaseTemplateDataObjectTest.java index d5bfe1a80..21dd18878 100644 --- a/core/java/test/org/openda/blackbox/io/BaseTemplateDataObjectTest.java +++ b/core/java/test/org/openda/blackbox/io/BaseTemplateDataObjectTest.java @@ -23,7 +23,7 @@ import org.openda.blackbox.config.BBTemplateFile; import org.openda.blackbox.config.BBUtils; import org.openda.interfaces.IDataObject; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.OpenDaTestSupport; import java.io.File; @@ -52,7 +52,7 @@ public void testTemplateDataObject() { assertEquals("Number of templateFiles not equal", 1, bbTemplateConfig.getTemplateFiles().size()); BBTemplateFile bbTemplateFile = bbTemplateConfig.getTemplateFiles().iterator().next(); - IPrevExchangeItem[] exchangeItems = ((BaseTemplateDataObject) baseTemplateDataObject).getExchangeItems(); + IExchangeItem[] exchangeItems = ((BaseTemplateDataObject) baseTemplateDataObject).getExchangeItems(); assertTrue("exchangeItems list is null",exchangeItems != null); assertEquals("exchangeItems size is not equal",4,exchangeItems.length); @@ -63,7 +63,7 @@ public void testTemplateDataObject() { boolean foundIterations=false; - for (IPrevExchangeItem exchangeItem : exchangeItems) { + for (IExchangeItem exchangeItem : exchangeItems) { if (exchangeItem.getId().equals("endtime")) { foundEndTime=true; exchangeItem.setValues("14400.0"); diff --git a/core/java/test/org/openda/blackbox/io/TreeVectorIoObjectTest.java b/core/java/test/org/openda/blackbox/io/TreeVectorIoObjectTest.java index 260a2794b..b93bff6ad 100644 --- a/core/java/test/org/openda/blackbox/io/TreeVectorIoObjectTest.java +++ b/core/java/test/org/openda/blackbox/io/TreeVectorIoObjectTest.java @@ -18,10 +18,9 @@ * along with OpenDA. If not, see . */ package org.openda.blackbox.io; + import junit.framework.TestCase; -import org.openda.blackbox.config.BBUtils; -import org.openda.blackbox.interfaces.IoObjectInterface; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.OpenDaTestSupport; import java.io.File; @@ -41,47 +40,55 @@ protected void setUp() throws IOException { } public void testSingleExchangeItem() { - IoObjectInterface treeVectorIoObject = BBUtils.createIoObjectInstance( - treeVectorDataDir, TreeVectorIoObject.class.getName(), - "rtcParameterConfig.xml", new String[]{"OneExchangeItem"}); - IPrevExchangeItem[] exchangeItems = treeVectorIoObject.getExchangeItems(); - assertTrue("Tree vector id", exchangeItems[0].getId().equals("TV")); - double[] values = exchangeItems[0].getValuesAsDoubles(); + TreeVectorDataObject treeVectorObject = new TreeVectorDataObject(); + String fileName = "rtcParameterConfig.xml"; + String[] arguments = {fileName,"OneExchangeItem"}; + treeVectorObject.initialize(treeVectorDataDir, arguments); + String[] exchangeItemIDs = treeVectorObject.getExchangeItemIDs(); + IExchangeItem exchangeItem = treeVectorObject.getDataObjectExchangeItem(exchangeItemIDs[0]); + assertEquals("Tree vector id", "TV", exchangeItem.getId()); + double[] values = exchangeItem.getValuesAsDoubles(); for (int i = 0, valuesLength = values.length; i < valuesLength; i++) { values[i] += 10.d; } - exchangeItems[0].setValuesAsDoubles(values); - treeVectorIoObject.finish(); + exchangeItem.setValuesAsDoubles(values); + treeVectorObject.finish(); testData.FilesAreIdentical(new File(treeVectorDataDir,"rtcParameterConfig.xml"), new File(treeVectorDataDir, "rtcParameterConfig_ref_1.xml")); } public void testMultiExchangeItems() { - IoObjectInterface treeVectorIoObject = BBUtils.createIoObjectInstance( - treeVectorDataDir, TreeVectorIoObject.class.getName(), - "rtcParameterConfig.xml", new String[]{}); - IPrevExchangeItem[] exchangeItems = treeVectorIoObject.getExchangeItems(); - assertTrue("B01.01", exchangeItems[0].getId().equals("B01.01")); - assertTrue("endTime", exchangeItems[19].getId().equals("B13.03")); + TreeVectorDataObject treeVectorObject = new TreeVectorDataObject(); + String fileName = "rtcParameterConfig.xml"; + String[] arguments = {fileName}; + treeVectorObject.initialize(treeVectorDataDir, arguments); + String[] exchangeItemIDs = treeVectorObject.getExchangeItemIDs(); + IExchangeItem firstExchangeItem = treeVectorObject.getDataObjectExchangeItem(exchangeItemIDs[0]); + assertEquals("B01.01", "B01.01", firstExchangeItem.getId()); + IExchangeItem lastExchangeItem = treeVectorObject.getDataObjectExchangeItem(exchangeItemIDs[19]); + assertEquals("endTime", "B13.03", lastExchangeItem.getId()); for (int ei = 0; ei<20 ; ei+=19) { - double[] values = exchangeItems[ei].getValuesAsDoubles(); + IExchangeItem exchangeItem = treeVectorObject.getDataObjectExchangeItem(exchangeItemIDs[ei]); + double[] values = exchangeItem.getValuesAsDoubles(); for (int i = 0, valuesLength = values.length; i < valuesLength; i++) { values[i] += 1.0d + (double) ei; } - exchangeItems[ei].setValuesAsDoubles(values); + exchangeItem.setValuesAsDoubles(values); } - treeVectorIoObject.finish(); + treeVectorObject.finish(); testData.FilesAreIdentical(new File(treeVectorDataDir, "rtcParameterConfig.xml"), new File(treeVectorDataDir, "rtcParameterConfig_ref_2.xml")); } public void testReadRtcStateImport() { try { - IoObjectInterface treeVectorIoObject = BBUtils.createIoObjectInstance( - treeVectorDataDir, TreeVectorIoObject.class.getName(), - "state_import.xml", new String[]{}); - IPrevExchangeItem[] exchangeItems = treeVectorIoObject.getExchangeItems(); - assertTrue("Main_P[0]", exchangeItems[0].getId().equals("Main_P[0]")); + TreeVectorDataObject treeVectorObject = new TreeVectorDataObject(); + String fileName = "state_import.xml"; + String[] arguments = {fileName}; + treeVectorObject.initialize(treeVectorDataDir, arguments); + String[] exchangeItemIDs = treeVectorObject.getExchangeItemIDs(); + IExchangeItem exchangeItem = treeVectorObject.getDataObjectExchangeItem(exchangeItemIDs[0]); + assertEquals("Main_P[0]", "Main_P[0]", exchangeItem.getId()); } catch (Exception e) { if (!e.getMessage().contains("Parsing Error : Content is not allowed in prolog")) { throw e; diff --git a/core/java/test/org/openda/blackbox/wrapper/BBExchangeItemTest.java b/core/java/test/org/openda/blackbox/wrapper/BBExchangeItemTest.java index 62afdf803..94415b9f5 100644 --- a/core/java/test/org/openda/blackbox/wrapper/BBExchangeItemTest.java +++ b/core/java/test/org/openda/blackbox/wrapper/BBExchangeItemTest.java @@ -24,13 +24,11 @@ import org.openda.blackbox.config.AliasDefinitions; import org.openda.blackbox.config.BBModelVectorConfig; import org.openda.blackbox.config.BBStochModelVectorConfig; -import org.openda.blackbox.config.IoObjectConfig; -import org.openda.blackbox.interfaces.IoObjectInterface; -import org.openda.blackbox.interfaces.SelectorInterface; +import org.openda.blackbox.config.DataObjectConfig; import org.openda.exchange.ArrayExchangeItem; import org.openda.exchange.ArrayTimeInfo; import org.openda.interfaces.IDimensionIndex; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.Array; import junit.framework.TestCase; import org.openda.utils.DimensionIndex; @@ -38,7 +36,6 @@ import java.io.File; import java.io.IOException; -import java.util.HashMap; /** * Test for Black Box ExchangeItem @@ -46,10 +43,9 @@ public class BBExchangeItemTest extends TestCase { private File testRunDataDir; - private OpenDaTestSupport testData; - protected void setUp() throws IOException { - testData = new OpenDaTestSupport(BBApplicationTest.class,"core"); + protected void setUp() throws IOException { + OpenDaTestSupport testData = new OpenDaTestSupport(BBApplicationTest.class, "core"); testRunDataDir = testData.getTestRunDataDir(); } @@ -65,7 +61,7 @@ public void testSelectFrom2DArrayExchangeItem() { Array ar = new Array(vals, dims, true); // initialize ExchangeItem with values from array - ArrayExchangeItem arrayEI = new ArrayExchangeItem("2Darray", IPrevExchangeItem.Role.InOut); + ArrayExchangeItem arrayEI = new ArrayExchangeItem("2Darray", IExchangeItem.Role.InOut); arrayEI.setArray(ar); // specify indices for the selection @@ -74,14 +70,13 @@ public void testSelectFrom2DArrayExchangeItem() { dimensionIndices[1] = new DimensionIndex(2, 5); // initialize dummy/minimal objects in order to initialize the BBExchangeItem - HashMap selectors = null; - IoObjectConfig ioObjectConfig = new IoObjectConfig("ioObject1", + DataObjectConfig dataObjectConfig = new DataObjectConfig("ioObject1", "org.openda.blackbox.wrapper.BBExchangeItemTest.DummyIoObject", "not used", new AliasDefinitions(), new String[0]); - BBStochModelVectorConfig vectorConfig = new BBModelVectorConfig("item1", ioObjectConfig, "itemA", - dimensionIndices, null, IPrevExchangeItem.Role.Output, null); + BBStochModelVectorConfig vectorConfig = new BBModelVectorConfig("item1", dataObjectConfig, "itemA", + dimensionIndices, null, IExchangeItem.Role.Output, null); // create the BBExchangeItem and ask for values - BBExchangeItem bbExchangeItem = new BBExchangeItem("test", vectorConfig, arrayEI, selectors, testRunDataDir); + BBExchangeItem bbExchangeItem = new BBExchangeItem("test", vectorConfig, arrayEI, null, testRunDataDir); double[] selectedValues = bbExchangeItem.getValuesAsDoubles(); // check size of returned array @@ -109,7 +104,7 @@ public void testSelectFrom3DArrayExchangeItem() { Array ar = new Array(vals, dims, true); // initialize ExchangeItem with values from array - ArrayExchangeItem arrayEI = new ArrayExchangeItem("2Darray", IPrevExchangeItem.Role.InOut); + ArrayExchangeItem arrayEI = new ArrayExchangeItem("2Darray", IExchangeItem.Role.InOut); arrayEI.setArray(ar); arrayEI.setTimeInfo(times); @@ -119,37 +114,17 @@ public void testSelectFrom3DArrayExchangeItem() { dimensionIndices[1] = new DimensionIndex(4, 7); // initialize dummy/minimal objects in order to initialize the BBExchangeItem - HashMap selectors = null; - IoObjectConfig ioObjectConfig = new IoObjectConfig("ioObject1", + DataObjectConfig dataObjectConfig = new DataObjectConfig("ioObject1", "org.openda.blackbox.wrapper.BBExchangeItemTest.DummyIoObject", "not used", new AliasDefinitions(), new String[0]); - BBStochModelVectorConfig vectorConfig = new BBModelVectorConfig("item1", ioObjectConfig, "itemA", - dimensionIndices, null, IPrevExchangeItem.Role.Output, null); + BBStochModelVectorConfig vectorConfig = new BBModelVectorConfig("item1", dataObjectConfig, "itemA", + dimensionIndices, null, IExchangeItem.Role.Output, null); // create the BBExchangeItem and ask for values - BBExchangeItem bbExchangeItem = new BBExchangeItem("test", vectorConfig, arrayEI, selectors, testRunDataDir); + BBExchangeItem bbExchangeItem = new BBExchangeItem("test", vectorConfig, arrayEI, null, testRunDataDir); double[] selectedValues = bbExchangeItem.getValuesAsDoubles(); // check size of returned array assertEquals(selectedValues.length, dims[0]*dimensionIndices[0].getSize()*dimensionIndices[1].getSize()); } - - private class DummyIoObject implements IoObjectInterface{ - - private IPrevExchangeItem[] exchangeItems; - - public void initialize(File workingDir, String fileName, String[] arguments) { - exchangeItems = new IPrevExchangeItem[1]; - ArrayExchangeItem item1 = new ArrayExchangeItem("item1", IPrevExchangeItem.Role.Output); - exchangeItems[0] = null; - } - - public IPrevExchangeItem[] getExchangeItems() { - return exchangeItems; - } - - public void finish() { - // no action - } - } } diff --git a/core/java/test/org/openda/blackbox/wrapper/BBStochModelFactoryTestWithIoObjects.java b/core/java/test/org/openda/blackbox/wrapper/BBStochModelFactoryTestWithIoObjects.java new file mode 100644 index 000000000..6e8352d2b --- /dev/null +++ b/core/java/test/org/openda/blackbox/wrapper/BBStochModelFactoryTestWithIoObjects.java @@ -0,0 +1,64 @@ +/* MOD_V2.0 +* Copyright (c) 2012 OpenDA Association +* All rights reserved. +* +* This file is part of OpenDA. +* +* OpenDA is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License as +* published by the Free Software Foundation, either version 3 of +* the License, or (at your option) any later version. +* +* OpenDA is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with OpenDA. If not, see . +*/ + + +package org.openda.blackbox.wrapper; + +import junit.framework.TestCase; +import org.openda.interfaces.IStochModelFactory; +import org.openda.interfaces.IStochModelInstance; +import org.openda.interfaces.ITime; +import org.openda.utils.OpenDaTestSupport; +import org.openda.utils.Time; + +import java.io.File; +import java.io.IOException; +import java.util.GregorianCalendar; + +/** + * Tests for black box stoch model factory + * This test makes sure that IoObject can still be used (until they are really removed) + */ +public class BBStochModelFactoryTestWithIoObjects extends TestCase { + + private File testRunDataDir; + + protected void setUp() throws IOException { + OpenDaTestSupport testData = new OpenDaTestSupport(BBStochModelFactoryTestWithIoObjects.class, "core"); + testRunDataDir = testData.getTestRunDataDir(); + } + + public void testIoObjectConfigWithTime () { + BBStochModelFactory bbStochModelFactory = new BBStochModelFactory(); + File testData = new File(testRunDataDir,"ioObjectConfig"); + bbStochModelFactory.initialize(testData,new String[] {"stochModelConfWithTime.xml"}); + IStochModelInstance stochModelInstance = bbStochModelFactory.getInstance(IStochModelFactory.OutputLevel.Suppress); + ITime timeHorizon = stochModelInstance.getTimeHorizon(); + GregorianCalendar beginCalendar = new GregorianCalendar(2008,1,1,0,0,0); + double expectedBeginTimeAsMJD = Time.milliesToMjd(beginCalendar.getTimeInMillis()); + GregorianCalendar endCalendar = new GregorianCalendar(2008,2,3,23,0,0); + double expectedEndTimeAsMJD = Time.milliesToMjd(endCalendar.getTimeInMillis()); + assertEquals("timeHorizon.getBeginTime()", expectedBeginTimeAsMJD, timeHorizon.getBeginTime().getMJD(), 1e-9); + assertEquals("timeHorizon.getEndTime()", expectedEndTimeAsMJD, timeHorizon.getEndTime().getMJD(), 1e-9); + } + + //TODO: make TestIoObject to test if BBStochModelFactory is working correctly + +} diff --git a/core/java/test/org/openda/blackbox/wrapper/BBStochModelParametersTest.java b/core/java/test/org/openda/blackbox/wrapper/BBStochModelParametersTest.java index 7dde9c57f..e6711689a 100644 --- a/core/java/test/org/openda/blackbox/wrapper/BBStochModelParametersTest.java +++ b/core/java/test/org/openda/blackbox/wrapper/BBStochModelParametersTest.java @@ -135,7 +135,7 @@ public void testMultiply() { stochModelInstance.setParameters(paramClone); String[] exchangeItemIDs = stochModelInstance.getExchangeItemIDs(); - IPrevExchangeItem exchangeItem = stochModelInstance.getExchangeItem(exchangeItemIDs[0]); + IExchangeItem exchangeItem = stochModelInstance.getExchangeItem(exchangeItemIDs[0]); double[] valuesAsDoubles = exchangeItem.getValuesAsDoubles(); assertEquals(131.3, valuesAsDoubles[0]); diff --git a/core/java/test/org/openda/blackbox/wrapper/DummyAstroIoObject.java b/core/java/test/org/openda/blackbox/wrapper/DummyAstroIoObject.java index f2bb237bc..20c14085d 100644 --- a/core/java/test/org/openda/blackbox/wrapper/DummyAstroIoObject.java +++ b/core/java/test/org/openda/blackbox/wrapper/DummyAstroIoObject.java @@ -21,42 +21,49 @@ package org.openda.blackbox.wrapper; -import org.openda.blackbox.interfaces.IoObjectInterface; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.exchange.AbstractDataObject; +import org.openda.interfaces.IExchangeItem; +import org.openda.interfaces.IGeometryInfo; +import org.openda.interfaces.IQuantityInfo; +import org.openda.interfaces.ITimeInfo; import java.io.File; /** * Dummy Astro Io Object for testing purposes */ -public class DummyAstroIoObject implements IoObjectInterface { - - private IPrevExchangeItem[] exchangeItems; - - public void initialize(File workingDir, String fileName, String[] arguments) { - exchangeItems = new IPrevExchangeItem[10]; - exchangeItems[0] = new DummyExchangeItem("locA.Ampl", .6); - exchangeItems[1] = new DummyExchangeItem("locA.Phase", 145); - exchangeItems[2] = new DummyExchangeItem("locB.Ampl", .8); - exchangeItems[3] = new DummyExchangeItem("locB.Phase", 260); - exchangeItems[4] = new DummyExchangeItem("locC.Ampl", 1.2); - exchangeItems[5] = new DummyExchangeItem("locC.Phase", -40); - exchangeItems[6] = new DummyExchangeItem("locD.Ampl", 10); - exchangeItems[7] = new DummyExchangeItem("locD.Phase", -5); - exchangeItems[8] = new DummyExchangeItem("locE.Ampl", 10); - exchangeItems[9] = new DummyExchangeItem("locE.Phase", 185); - } - - public IPrevExchangeItem[] getExchangeItems() { - return exchangeItems; - } - - private class DummyExchangeItem implements IPrevExchangeItem { +public class DummyAstroIoObject extends AbstractDataObject { + + @Override + public void initialize(File workingDir, String[] arguments) { + String locAAmplId = "locA.Ampl"; + String locAPhaseId = "locA.Phase"; + String locBAmplId = "locB.Ampl"; + String locBPhaseId = "locB.Phase"; + String locCAmplId = "locC.Ampl"; + String locCPhaseId = "locC.Phase"; + String locDAmplId = "locD.Ampl"; + String locDPhaseId = "locD.Phase"; + String locEAmplId = "locE.Ampl"; + String locEPhaseId = "locE.Phase"; + exchangeItems.put(locAAmplId, new DummyExchangeItem(locAAmplId, .6)); + exchangeItems.put(locAPhaseId, new DummyExchangeItem(locAPhaseId, 145)); + exchangeItems.put(locBAmplId, new DummyExchangeItem(locBAmplId, .8)); + exchangeItems.put(locBPhaseId, new DummyExchangeItem(locBPhaseId, 260)); + exchangeItems.put(locCAmplId, new DummyExchangeItem(locCAmplId, 1.2)); + exchangeItems.put(locCPhaseId, new DummyExchangeItem(locCPhaseId, -40)); + exchangeItems.put(locDAmplId, new DummyExchangeItem(locDAmplId, 10)); + exchangeItems.put(locDPhaseId, new DummyExchangeItem(locDPhaseId, -5)); + exchangeItems.put(locEAmplId, new DummyExchangeItem(locEAmplId, 10)); + exchangeItems.put(locEPhaseId, new DummyExchangeItem(locEPhaseId, 185)); + } + + private static class DummyExchangeItem implements IExchangeItem { private String exchangeItemId; private Double value; - public DummyExchangeItem(String exchangeItemId, double value) { + DummyExchangeItem(String exchangeItemId, double value) { this.exchangeItemId = exchangeItemId; this.value = value; } @@ -69,21 +76,15 @@ public String getDescription() { return null; // no description } - public String getQuantityId() { - return exchangeItemId; - } + public IQuantityInfo getQuantityInfo() { return null; } - public String getUnitId() { - return "-"; - } + public IGeometryInfo getGeometryInfo() { return null; } - public Class getValueType() { - return Double.TYPE; + public ValueType getValuesType() { + return ValueType.doublesType; } - public Role getRole() { - return Role.InOut; - } + public Role getRole() { return Role.InOut; } public Object getValues() { return value; @@ -107,7 +108,15 @@ public void multiplyValues(double[] multiplicationFactors) { this.value *= multiplicationFactors[0]; } - public void setValues(Object values) { + public void copyValuesFromItem(IExchangeItem sourceItem) { + ValueType sourceType=sourceItem.getValuesType(); + if(sourceType != ValueType.doublesType){ + throw new RuntimeException("DummyAstroDataObject.DummyExchangeItem.setValues(): unknown type: " + sourceType ); + } + this.setValues(sourceItem.getValues()); + } + + public void setValues(Object values) { if (!(values instanceof Double)) { throw new RuntimeException("DummyAstroIoObject.DummyExchangeItem.setValues(): unknown object type: " + values.getClass() ); } @@ -121,6 +130,10 @@ public void setValuesAsDoubles(double[] values) { value = values[0]; } + public ITimeInfo getTimeInfo() { + return null; + } + public double[] getTimes() { return null; } @@ -130,6 +143,7 @@ public void setTimes(double[] times) { } } + @Override public void finish() { // no action needed } diff --git a/core/java/test/org/openda/blackbox/wrapper/DummyModelForTestingNoise.java b/core/java/test/org/openda/blackbox/wrapper/DummyModelForTestingNoise.java index 3337bba74..5e861f028 100644 --- a/core/java/test/org/openda/blackbox/wrapper/DummyModelForTestingNoise.java +++ b/core/java/test/org/openda/blackbox/wrapper/DummyModelForTestingNoise.java @@ -23,7 +23,7 @@ import org.openda.exchange.DoubleExchangeItem; import org.openda.exchange.DoublesExchangeItem; import org.openda.interfaces.*; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; import org.openda.localization.LocalizationDomainsSimpleModel; import org.openda.utils.Array; import org.openda.utils.Time; @@ -38,7 +38,7 @@ */ public class DummyModelForTestingNoise implements IModelInstance { - private HashMap exchangeItems = new HashMap(); + private HashMap exchangeItems = new HashMap(); private Time simulationTime; private Time currentTime; private ArrayList exchangeItemsIdsTS; @@ -87,7 +87,7 @@ public String[] getExchangeItemIDs() { return exchangeItems.keySet().toArray(new String[exchangeItems.size()]); } - public IPrevExchangeItem getExchangeItem(String exchangeItemID) { + public IExchangeItem getExchangeItem(String exchangeItemID) { return exchangeItems.get(exchangeItemID); } @@ -145,7 +145,7 @@ public File getModelRunDir() { throw new UnsupportedOperationException("org.openda.blackbox.wrapper.DummyModelForTestingNoise.getModelRunDir(): Not implemented yet."); } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { throw new UnsupportedOperationException("org.openda.blackbox.wrapper.DummyModelForTestingNoise.getExchangeItemIDs(): Not implemented yet."); } diff --git a/core/java/test/org/openda/blackbox/wrapper/DummyParametersIoObject.java b/core/java/test/org/openda/blackbox/wrapper/DummyParametersDataObject.java similarity index 54% rename from core/java/test/org/openda/blackbox/wrapper/DummyParametersIoObject.java rename to core/java/test/org/openda/blackbox/wrapper/DummyParametersDataObject.java index 72a314bca..108f5dcf1 100644 --- a/core/java/test/org/openda/blackbox/wrapper/DummyParametersIoObject.java +++ b/core/java/test/org/openda/blackbox/wrapper/DummyParametersDataObject.java @@ -21,42 +21,49 @@ package org.openda.blackbox.wrapper; -import org.openda.blackbox.interfaces.IoObjectInterface; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.exchange.AbstractDataObject; +import org.openda.interfaces.IExchangeItem; +import org.openda.interfaces.IGeometryInfo; +import org.openda.interfaces.IQuantityInfo; +import org.openda.interfaces.ITimeInfo; import java.io.File; /** * Dummy Io Object for testing parameter uncertainty purposes */ -public class DummyParametersIoObject implements IoObjectInterface { - - private IPrevExchangeItem[] exchangeItems; - - public void initialize(File workingDir, String fileName, String[] arguments) { - exchangeItems = new IPrevExchangeItem[10]; - exchangeItems[0] = new DummyExchangeItem("locA.Par1", 101.d); - exchangeItems[1] = new DummyExchangeItem("locA.Par2", 102.d); - exchangeItems[2] = new DummyExchangeItem("locB.Par1", 201.d); - exchangeItems[3] = new DummyExchangeItem("locB.Par2", 202.d); - exchangeItems[4] = new DummyExchangeItem("locC.Par_I", 301.d); - exchangeItems[5] = new DummyExchangeItem("locC.Par_II",302.d); - exchangeItems[6] = new DummyExchangeItem("locD.Par_I", 401.d); - exchangeItems[7] = new DummyExchangeItem("locD.Par_II",402.d); - exchangeItems[8] = new DummyExchangeItem("locE.Par_m", 501.d); - exchangeItems[9] = new DummyExchangeItem("locE.Par_n", 502.d); +public class DummyParametersDataObject extends AbstractDataObject { + + @Override + public void initialize(File workingDir, String[] arguments) { + String locAPar1 = "locA.Par1"; + String locAPar2 = "locA.Par2"; + String locBPar1 = "locB.Par1"; + String locBPar2 = "locB.Par2"; + String locCPar_I = "locC.Par_I"; + String locCPar_II = "locC.Par_II"; + String locDPar_I = "locD.Par_I"; + String locDPar_II = "locD.Par_II"; + String locEPar_m = "locE.Par_m"; + String locEPar_n = "locE.Par_n"; + exchangeItems.put(locAPar1 , new DummyExchangeItem(locAPar1, 101.d)); + exchangeItems.put(locAPar2 , new DummyExchangeItem(locAPar2, 102.d)); + exchangeItems.put(locBPar1 , new DummyExchangeItem(locBPar1, 201.d)); + exchangeItems.put(locBPar2 , new DummyExchangeItem(locBPar2, 202.d)); + exchangeItems.put(locCPar_I , new DummyExchangeItem(locCPar_I, 301.d)); + exchangeItems.put(locCPar_II, new DummyExchangeItem(locCPar_II, 302.d)); + exchangeItems.put(locDPar_I , new DummyExchangeItem(locDPar_I, 401.d)); + exchangeItems.put(locDPar_II, new DummyExchangeItem(locDPar_II, 402.d)); + exchangeItems.put(locEPar_m , new DummyExchangeItem(locEPar_m, 501.d)); + exchangeItems.put(locEPar_n , new DummyExchangeItem(locEPar_n, 502.d)); } - public IPrevExchangeItem[] getExchangeItems() { - return exchangeItems; - } - - private class DummyExchangeItem implements IPrevExchangeItem { + private static class DummyExchangeItem implements IExchangeItem { private String exchangeItemId; private Double value; - public DummyExchangeItem(String exchangeItemId, double value) { + DummyExchangeItem(String exchangeItemId, double value) { this.exchangeItemId = exchangeItemId; this.value = value; } @@ -69,21 +76,15 @@ public String getDescription() { return null; // no description } - public String getQuantityId() { - return exchangeItemId; - } + public IQuantityInfo getQuantityInfo() { return null; } - public String getUnitId() { - return "-"; - } + public IGeometryInfo getGeometryInfo() { return null; } - public Class getValueType() { - return Double.TYPE; + public ValueType getValuesType() { + return ValueType.doublesType; } - public Role getRole() { - return Role.InOut; - } + public Role getRole() { return Role.InOut; } public Object getValues() { return value; @@ -107,6 +108,14 @@ public void multiplyValues(double[] multiplicationFactors) { this.value *= multiplicationFactors[0]; } + public void copyValuesFromItem(IExchangeItem sourceItem) { + ValueType sourceType=sourceItem.getValuesType(); + if(sourceType != ValueType.doublesType){ + throw new RuntimeException("DummyAstroDataObject.DummyExchangeItem.setValues(): unknown type: " + sourceType ); + } + this.setValues(sourceItem.getValues()); + } + public void setValues(Object values) { if (!(values instanceof Double)) { throw new RuntimeException("DummyAstroIoObject.DummyExchangeItem.setValues(): unknown object type: " + values.getClass() ); @@ -121,6 +130,10 @@ public void setValuesAsDoubles(double[] values) { value = values[0]; } + public ITimeInfo getTimeInfo() { + return null; + } + public double[] getTimes() { return null; } @@ -130,6 +143,7 @@ public void setTimes(double[] times) { } } + @Override public void finish() { // no action needed } diff --git a/core/java/test/org/openda/blackbox/wrapper/DummySeries.java b/core/java/test/org/openda/blackbox/wrapper/DummySeries.java deleted file mode 100644 index c16485226..000000000 --- a/core/java/test/org/openda/blackbox/wrapper/DummySeries.java +++ /dev/null @@ -1,129 +0,0 @@ -/* MOD_V2.0 -* Copyright (c) 2012 OpenDA Association -* All rights reserved. -* -* This file is part of OpenDA. -* -* OpenDA is free software: you can redistribute it and/or modify -* it under the terms of the GNU Lesser General Public License as -* published by the Free Software Foundation, either version 3 of -* the License, or (at your option) any later version. -* -* OpenDA is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with OpenDA. If not, see . -*/ - - -package org.openda.blackbox.wrapper; - -import org.openda.blackbox.interfaces.IoObjectInterface; -import org.openda.interfaces.IPrevExchangeItem; - -import java.io.File; - -/** - * Dummy Series object for testing purposes - */ -public class DummySeries implements IoObjectInterface { - private IPrevExchangeItem[] exchangeItems; - - public void initialize(File workingDir, String fileName, String[] arguments) { - String[] exchangeItemIds = fileName.split(";"); - exchangeItems = new IPrevExchangeItem[exchangeItemIds.length]; - for (int i = 0; i < exchangeItemIds.length; i++) { - exchangeItems[i] = new DummyExchangeItem(exchangeItemIds[i], (i+1)*1000); - } - } - - public IPrevExchangeItem[] getExchangeItems() { - return exchangeItems; - } - - private class DummyExchangeItem implements IPrevExchangeItem { - - private String exchangeItemId; - private Double value; - - public DummyExchangeItem(String exchangeItemId, double value) { - this.exchangeItemId = exchangeItemId; - this.value = value; - } - - public String getId() { - return exchangeItemId; - } - - public String getDescription() { - return null; // no description - } - - public String getQuantityId() { - return exchangeItemId; - } - - public String getUnitId() { - return "-"; - } - - public Class getValueType() { - return Double.TYPE; - } - - public Role getRole() { - return IPrevExchangeItem.Role.InOut; - } - - public Object getValues() { - return value; - } - - public double[] getValuesAsDoubles() { - return new double[]{value}; - } - - public void axpyOnValues(double alpha, double[] axpyValues) { - if (axpyValues.length !=1){ - throw new UnsupportedOperationException("Length of axpy value array must be 1"); - } - this.value += alpha * axpyValues[0]; - } - - public void multiplyValues(double[] multiplicationFactors) { - if (multiplicationFactors.length !=1){ - throw new UnsupportedOperationException("Length of multiplication factors array must be 1"); - } - this.value *= multiplicationFactors[0]; - } - - public void setValues(Object values) { - if (!(values instanceof Double)) { - throw new RuntimeException("DummySeries.DummyExchangeItem.setValues(): unknown object type: " + values.getClass() ); - } - value = (Double) values; - } - - public void setValuesAsDoubles(double[] values) { - if (values.length != 1 ) { - throw new RuntimeException("DummySeries.DummyExchangeItem.setValuesAsDoubles(): values size > 1 : " + values.length); - } - value = values[0]; - } - - public double[] getTimes() { - return null; - } - - public void setTimes(double[] times) { - throw new RuntimeException(this.getClass().getName() + " does not have timeStamps"); - } - } - - public void finish() { - // no action needed - } -} diff --git a/core/java/test/org/openda/blackbox/wrapper/DummyState.java b/core/java/test/org/openda/blackbox/wrapper/DummyState.java index 4504dffbc..ed7a568de 100644 --- a/core/java/test/org/openda/blackbox/wrapper/DummyState.java +++ b/core/java/test/org/openda/blackbox/wrapper/DummyState.java @@ -21,26 +21,26 @@ package org.openda.blackbox.wrapper; -import org.openda.blackbox.interfaces.IoObjectInterface; +import org.openda.exchange.AbstractDataObject; import org.openda.exchange.DoublesExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem; import java.io.*; import java.util.ArrayList; import java.util.Locale; /** - * Dummy Astro Io Object for testing purposes + * Dummy Astro DataObject for testing purposes */ -public class DummyState implements IoObjectInterface { +public class DummyState extends AbstractDataObject { - private IPrevExchangeItem[] exchangeItems = null; - private File stateFile = null; + public static final String STATE = "state"; + private File stateFile = null; - public void initialize(File workingDir, String fileName, String[] arguments) { - stateFile = new File(workingDir, fileName); - ArrayList lines = new ArrayList(); + @Override + public void initialize(File workingDir, String[] arguments) { + stateFile = new File(workingDir, arguments[0]); + ArrayList lines = new ArrayList<>(); try { BufferedReader bufferedReader = new BufferedReader(new FileReader(stateFile)); String line = bufferedReader.readLine(); @@ -60,19 +60,16 @@ public void initialize(File workingDir, String fileName, String[] arguments) { for (int i = 0, valuesLength = values.length; i < valuesLength; i++) { values[i] = Double.parseDouble(lines.get(i)); } - exchangeItems = new IPrevExchangeItem[]{new DoublesExchangeItem("state", Role.InOut, values)}; - } - - public IPrevExchangeItem[] getExchangeItems() { - return exchangeItems; + exchangeItems.put(STATE, new DoublesExchangeItem(STATE, IExchangeItem.Role.InOut, values)); } + @Override public void finish() { Locale locale = new Locale("EN"); try { FileWriter fileWriter = new FileWriter(stateFile); BufferedWriter outputFileBufferedWriter = new BufferedWriter(fileWriter); - for (double value : exchangeItems[0].getValuesAsDoubles()) { + for (double value : exchangeItems.get(STATE).getValuesAsDoubles()) { outputFileBufferedWriter.write(String.format(locale, "%5.2f", value)); outputFileBufferedWriter.newLine(); } diff --git a/core/java/test/org/openda/blackbox/wrapper/DummyStateDataObject.java b/core/java/test/org/openda/blackbox/wrapper/DummyStateDataObject.java index bd70d9cc5..967701e55 100644 --- a/core/java/test/org/openda/blackbox/wrapper/DummyStateDataObject.java +++ b/core/java/test/org/openda/blackbox/wrapper/DummyStateDataObject.java @@ -4,7 +4,6 @@ import org.openda.exchange.DoublesExchangeItem; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import java.io.File; @@ -20,7 +19,7 @@ public String[] getExchangeItemIDs() { } @Override - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { throw new RuntimeException("org.openda.blackbox.wrapper.DummyStateDataObject.getExchangeItemIDs() not implemented yet"); } @@ -32,13 +31,13 @@ public IExchangeItem getDataObjectExchangeItem(String exchangeItemID) { //double[] values = new double[1061]; double[] values = new double[stateSize]; fillWithRandomValues(values); - return new DoublesExchangeItem("state", IPrevExchangeItem.Role.InOut, values); + return new DoublesExchangeItem("state", IExchangeItem.Role.InOut, values); case "StartTime" : - return new DoubleExchangeItem("StartTime", IPrevExchangeItem.Role.InOut, 0); + return new DoubleExchangeItem("StartTime", IExchangeItem.Role.InOut, 0); case "StopTime" : - return new DoubleExchangeItem("StopTime", IPrevExchangeItem.Role.InOut, 10); + return new DoubleExchangeItem("StopTime", IExchangeItem.Role.InOut, 10); case "TimeStep" : - return new DoubleExchangeItem("TimeStep", IPrevExchangeItem.Role.InOut, 1); + return new DoubleExchangeItem("TimeStep", IExchangeItem.Role.InOut, 1); default: return null; } diff --git a/core/java/test/org/openda/blackbox/wrapper/DummyTestStochObserver.java b/core/java/test/org/openda/blackbox/wrapper/DummyTestStochObserver.java index b1a9a5a6e..65b3ea217 100644 --- a/core/java/test/org/openda/blackbox/wrapper/DummyTestStochObserver.java +++ b/core/java/test/org/openda/blackbox/wrapper/DummyTestStochObserver.java @@ -107,9 +107,9 @@ public void free() { private class DummyTestObservationDescriptions implements IObservationDescriptions { - private List exchangeItems = new ArrayList(); + private List exchangeItems = new ArrayList<>(); - public DummyTestObservationDescriptions(String[] arguments) { + DummyTestObservationDescriptions(String[] arguments) { for (String argument : arguments) { String[] ids = argument.trim().split(";"); for (String id : ids) { @@ -118,7 +118,7 @@ public DummyTestObservationDescriptions(String[] arguments) { } } - public List getExchangeItems() { + public List getExchangeItems() { return exchangeItems; } @@ -146,9 +146,9 @@ public ITime[] getTimes() { return null; } - private class DummyTestExchangeItem extends ExchangeItem implements IPrevExchangeItem { + private class DummyTestExchangeItem extends ExchangeItem { - public DummyTestExchangeItem(String argument) { + DummyTestExchangeItem(String argument) { super(argument); } diff --git a/core/java/test/org/openda/blackbox/wrapper/DummyTimeInfoIoObject.java b/core/java/test/org/openda/blackbox/wrapper/DummyTimeInfoIoObject.java index 9f629a644..3a379ae5d 100644 --- a/core/java/test/org/openda/blackbox/wrapper/DummyTimeInfoIoObject.java +++ b/core/java/test/org/openda/blackbox/wrapper/DummyTimeInfoIoObject.java @@ -19,9 +19,8 @@ */ package org.openda.blackbox.wrapper; -import org.openda.blackbox.interfaces.IoObjectInterface; +import org.openda.exchange.AbstractDataObject; import org.openda.exchange.DoubleExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.Time; import java.io.File; @@ -33,121 +32,39 @@ /** * Dummy IoObject for time info */ -public class DummyTimeInfoIoObject implements IoObjectInterface { +public class DummyTimeInfoIoObject extends AbstractDataObject { - private IPrevExchangeItem[] exchangeItems = null; - - public void initialize(File workingDir, String fileName, String[] arguments) { - if (arguments.length != 2) { - throw new RuntimeException(this.getClass().getName() + ": expecting two arguments: start time end time"); + @Override + public void initialize(File workingDir, String[] arguments) { + if (arguments.length != 3) { + throw new RuntimeException(this.getClass().getName() + ": expecting three arguments: file name, start time end time"); } DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date startDate; Date endDate; try { - startDate = (Date) formatter.parse(arguments[0]); + startDate = formatter.parse(arguments[1]); } catch (ParseException e) { throw new RuntimeException(this.getClass().getName() + - ": could not parse start time from argument \"" + arguments[0] + "\""); + ": could not parse start time from argument \"" + arguments[1] + "\""); } try { - endDate = (Date) formatter.parse(arguments[1]); + endDate = formatter.parse(arguments[2]); } catch (ParseException e) { throw new RuntimeException(this.getClass().getName() + - ": could not parse end time from argument \"" + arguments[1] + "\""); + ": could not parse end time from argument \"" + arguments[2] + "\""); } double startTimeAsMjd = new Time(startDate).getMJD(); double endTimeAsMjd = new Time(endDate).getMJD(); - exchangeItems = new IPrevExchangeItem[2]; - exchangeItems[0] = new DoubleExchangeItem("start_time", startTimeAsMjd); - exchangeItems[1] = new DoubleExchangeItem("end_time", endTimeAsMjd); - } - - public IPrevExchangeItem[] getExchangeItems() { - return exchangeItems; - } - - private class DummyExchangeItem implements IPrevExchangeItem { - - private String exchangeItemId; - private Double value; - - public DummyExchangeItem(String exchangeItemId, double value) { - this.exchangeItemId = exchangeItemId; - this.value = value; - } - - public String getId() { - return exchangeItemId; - } - - public String getDescription() { - return null; // no description - } - - public String getQuantityId() { - return exchangeItemId; - } - - public String getUnitId() { - return "-"; - } - - public Class getValueType() { - return Double.TYPE; - } - - public Role getRole() { - return Role.InOut; - } - - public Object getValues() { - return value; - } - - public double[] getValuesAsDoubles() { - return new double[]{value}; - } - - public void axpyOnValues(double alpha, double[] axpyValues) { - if (axpyValues.length !=1){ - throw new UnsupportedOperationException("Length of axpy value array must be 1"); - } - this.value += alpha * axpyValues[0]; - } - - public void multiplyValues(double[] multiplicationFactors) { - if (multiplicationFactors.length !=1){ - throw new UnsupportedOperationException("Length of multiplication factors array must be 1"); - } - this.value *= multiplicationFactors[0]; - } - - public void setValues(Object values) { - if (!(values instanceof Double)) { - throw new RuntimeException("DummyAstroIoObject.DummyExchangeItem.setValues(): unknown object type: " + values.getClass()); - } - value = (Double) values; - } - - public void setValuesAsDoubles(double[] values) { - if (values.length != 1) { - throw new RuntimeException("DummyAstroIoObject.DummyExchangeItem.setValuesAsDoubles(): values size > 1 : " + values.length); - } - value = values[0]; - } - - public double[] getTimes() { - return null; - } - - public void setTimes(double[] times) { - throw new RuntimeException(this.getClass().getName() + " does not have timeStamps"); - } + String startTime = "start_time"; + String endTime = "end_time"; + exchangeItems.put(startTime, new DoubleExchangeItem(startTime, startTimeAsMjd)); + exchangeItems.put(endTime, new DoubleExchangeItem(endTime, endTimeAsMjd)); } + @Override public void finish() { // no action needed } diff --git a/core/java/test/org/openda/blackbox/wrapper/testData/ioObjectConfig/modelConfWithTime.xml b/core/java/test/org/openda/blackbox/wrapper/testData/ioObjectConfig/modelConfWithTime.xml new file mode 100644 index 000000000..fc2c9de7b --- /dev/null +++ b/core/java/test/org/openda/blackbox/wrapper/testData/ioObjectConfig/modelConfWithTime.xml @@ -0,0 +1,14 @@ + + + + + wrapperConf.xml + + + + + + + + + diff --git a/core/java/test/org/openda/blackbox/wrapper/testData/ioObjectConfig/stochModelConfWithTime.xml b/core/java/test/org/openda/blackbox/wrapper/testData/ioObjectConfig/stochModelConfWithTime.xml new file mode 100644 index 000000000..4e02b58dd --- /dev/null +++ b/core/java/test/org/openda/blackbox/wrapper/testData/ioObjectConfig/stochModelConfWithTime.xml @@ -0,0 +1,11 @@ + + + + + + ./modelConfWithTime.xml + + + + + diff --git a/core/java/test/org/openda/blackbox/wrapper/testData/ioObjectConfig/wrapperConf.xml b/core/java/test/org/openda/blackbox/wrapper/testData/ioObjectConfig/wrapperConf.xml new file mode 100644 index 000000000..5c7c9e276 --- /dev/null +++ b/core/java/test/org/openda/blackbox/wrapper/testData/ioObjectConfig/wrapperConf.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + noRealFile + timeInfoIoObject + 2010-07-16 23:59:59 + 2010-07-17 00:01:01 + + + + + diff --git a/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel/bbWrapperConfig.xml b/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel/bbWrapperConfig.xml index 428bd79ff..6bcb3c820 100644 --- a/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel/bbWrapperConfig.xml +++ b/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel/bbWrapperConfig.xml @@ -1,66 +1,67 @@ - + - + - - - - - - - - - + + + + + + + + + - + - - + + - - - - - %instanceDir%%instanceNumber% - - + + + + + %instanceDir%%instanceNumber% + + - - + + - + - + - + - - %noosfile_1% - noosfile_1 - + + %noosfile_1% + noosfile_1 + - + - - %noosfile_2% - noosfile_2 - + + %noosfile_2% + noosfile_2 + - + - - %noosfile_3% - noosfile_3 - + + %noosfile_3% + noosfile_3 + - + - - %statefile% - statefile - + + %statefile% + statefile + - + diff --git a/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/bbWrapperConfig_noiseRatio.xml b/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/bbWrapperConfig_noiseRatio.xml index 191ab4ed2..9db2e742d 100644 --- a/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/bbWrapperConfig_noiseRatio.xml +++ b/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/bbWrapperConfig_noiseRatio.xml @@ -22,10 +22,10 @@ - + notUsed DummyStateObject - + diff --git a/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/noiseAfterCompute/bbModelConfig_noiseAfterCompute.xml b/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/noiseAfterCompute/bbModelConfig_noiseAfterCompute.xml index 2c41d1f89..d554bb303 100644 --- a/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/noiseAfterCompute/bbModelConfig_noiseAfterCompute.xml +++ b/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/noiseAfterCompute/bbModelConfig_noiseAfterCompute.xml @@ -18,7 +18,7 @@ - + diff --git a/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/noiseAfterCompute/bbWrapperConfig_noiseAfterCompute.xml b/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/noiseAfterCompute/bbWrapperConfig_noiseAfterCompute.xml index 191ab4ed2..9db2e742d 100644 --- a/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/noiseAfterCompute/bbWrapperConfig_noiseAfterCompute.xml +++ b/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/noiseAfterCompute/bbWrapperConfig_noiseAfterCompute.xml @@ -22,10 +22,10 @@ - + notUsed DummyStateObject - + diff --git a/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/noiseRatio2DMapping/bbWrapperConfig_noiseRatio2DMapping.xml b/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/noiseRatio2DMapping/bbWrapperConfig_noiseRatio2DMapping.xml index 237cbb4a1..400ff6c7c 100644 --- a/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/noiseRatio2DMapping/bbWrapperConfig_noiseRatio2DMapping.xml +++ b/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/noiseRatio2DMapping/bbWrapperConfig_noiseRatio2DMapping.xml @@ -22,10 +22,10 @@ - + param2D_20020102.asc param2D - + diff --git a/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/noiseRatio2DMappingBigger/bbWrapperConfig_noiseRatio2DMappingBigger.xml b/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/noiseRatio2DMappingBigger/bbWrapperConfig_noiseRatio2DMappingBigger.xml index 237cbb4a1..400ff6c7c 100644 --- a/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/noiseRatio2DMappingBigger/bbWrapperConfig_noiseRatio2DMappingBigger.xml +++ b/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/noiseRatio2DMappingBigger/bbWrapperConfig_noiseRatio2DMappingBigger.xml @@ -22,10 +22,10 @@ - + param2D_20020102.asc param2D - + diff --git a/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/noiseRatio2DMappingSmaller/bbWrapperConfig_noiseRatio2DMappingSmaller.xml b/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/noiseRatio2DMappingSmaller/bbWrapperConfig_noiseRatio2DMappingSmaller.xml index 237cbb4a1..400ff6c7c 100644 --- a/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/noiseRatio2DMappingSmaller/bbWrapperConfig_noiseRatio2DMappingSmaller.xml +++ b/core/java/test/org/openda/blackbox/wrapper/testData/noiseModel2DMaps/noiseRatio2DMappingSmaller/bbWrapperConfig_noiseRatio2DMappingSmaller.xml @@ -22,10 +22,10 @@ - + param2D_20020102.asc param2D - + diff --git a/core/java/test/org/openda/blackbox/wrapper/testData/restart/bbWrapperConfig.xml b/core/java/test/org/openda/blackbox/wrapper/testData/restart/bbWrapperConfig.xml index b0f93c73f..16b71a38a 100644 --- a/core/java/test/org/openda/blackbox/wrapper/testData/restart/bbWrapperConfig.xml +++ b/core/java/test/org/openda/blackbox/wrapper/testData/restart/bbWrapperConfig.xml @@ -21,12 +21,12 @@ - + dflow1d/wlevStateFileIn.xyz state - + - \ No newline at end of file + diff --git a/core/java/test/org/openda/blackbox/wrapper/testData/restartFirstPart/bbWrapperConfig.xml b/core/java/test/org/openda/blackbox/wrapper/testData/restartFirstPart/bbWrapperConfig.xml index 428bd79ff..6f655562b 100644 --- a/core/java/test/org/openda/blackbox/wrapper/testData/restartFirstPart/bbWrapperConfig.xml +++ b/core/java/test/org/openda/blackbox/wrapper/testData/restartFirstPart/bbWrapperConfig.xml @@ -56,10 +56,10 @@ - + %statefile% statefile - + diff --git a/core/java/test/org/openda/blackbox/wrapper/testData/restartFull/bbWrapperConfig.xml b/core/java/test/org/openda/blackbox/wrapper/testData/restartFull/bbWrapperConfig.xml index 428bd79ff..6f655562b 100644 --- a/core/java/test/org/openda/blackbox/wrapper/testData/restartFull/bbWrapperConfig.xml +++ b/core/java/test/org/openda/blackbox/wrapper/testData/restartFull/bbWrapperConfig.xml @@ -56,10 +56,10 @@ - + %statefile% statefile - + diff --git a/core/java/test/org/openda/blackbox/wrapper/testData/restartSecondPart/bbWrapperConfig.xml b/core/java/test/org/openda/blackbox/wrapper/testData/restartSecondPart/bbWrapperConfig.xml index 428bd79ff..6f655562b 100644 --- a/core/java/test/org/openda/blackbox/wrapper/testData/restartSecondPart/bbWrapperConfig.xml +++ b/core/java/test/org/openda/blackbox/wrapper/testData/restartSecondPart/bbWrapperConfig.xml @@ -56,10 +56,10 @@ - + %statefile% statefile - + diff --git a/core/java/test/org/openda/blackbox/wrapper/testData/timeInfo/wrapperConf.xml b/core/java/test/org/openda/blackbox/wrapper/testData/timeInfo/wrapperConf.xml index d3843d8ae..53ac3d635 100644 --- a/core/java/test/org/openda/blackbox/wrapper/testData/timeInfo/wrapperConf.xml +++ b/core/java/test/org/openda/blackbox/wrapper/testData/timeInfo/wrapperConf.xml @@ -12,13 +12,13 @@ - + noRealFile timeInfoIoObject 2010-07-16 23:59:59 2010-07-17 00:01:01 - + - + diff --git a/core/java/test/org/openda/blackbox/wrapper/testData/transformations/simpleBbWrapperConfig.xml b/core/java/test/org/openda/blackbox/wrapper/testData/transformations/simpleBbWrapperConfig.xml index f117424dd..01e7eea30 100644 --- a/core/java/test/org/openda/blackbox/wrapper/testData/transformations/simpleBbWrapperConfig.xml +++ b/core/java/test/org/openda/blackbox/wrapper/testData/transformations/simpleBbWrapperConfig.xml @@ -1,5 +1,7 @@ - + @@ -22,10 +24,10 @@ - + no file needed DummyAstroIoObject - + diff --git a/core/java/test/org/openda/exchange/ExchangeItemTest.java b/core/java/test/org/openda/exchange/ExchangeItemTest.java index 3a63b9123..731022324 100644 --- a/core/java/test/org/openda/exchange/ExchangeItemTest.java +++ b/core/java/test/org/openda/exchange/ExchangeItemTest.java @@ -21,8 +21,7 @@ import org.openda.interfaces.IArray; import org.openda.interfaces.IArrayGeometryInfo; import org.openda.interfaces.IArrayTimeInfo; -import org.openda.interfaces.IPrevExchangeItem; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; import org.openda.interfaces.IQuantityInfo; import org.openda.utils.Array; @@ -45,7 +44,7 @@ public static void testDoubleExchangeItem() { assertEquals("m^3", unit); Role role = item.getRole(); - assertEquals(IPrevExchangeItem.Role.Input, role); + assertEquals(Role.Input, role); item.setValue(2.0); double value = item.getValue(); @@ -74,7 +73,7 @@ public static void testIntExchangeItem() { assertEquals("1/m^2", unit); Role role = item.getRole(); - assertEquals(IPrevExchangeItem.Role.Input, role); + assertEquals(Role.Input, role); item.setValue(2); int value = item.getValue(); @@ -96,7 +95,7 @@ public static void testStringExchangeItem() { assertEquals("id", id); Role role = item.getRole(); - assertEquals(IPrevExchangeItem.Role.Input, role); + assertEquals(Role.Input, role); item.setValue("logfile.dat"); String value = item.getValue(); @@ -126,7 +125,7 @@ public static void testDoublesExchangeItem() { assertEquals("m^3", unit); Role role = item.getRole(); - assertEquals(IPrevExchangeItem.Role.InOut, role); + assertEquals(Role.InOut, role); double values[] = item.getValuesAsDoubles(); assertEquals(4, values.length); @@ -170,7 +169,7 @@ public static void testGridXYTExchangeItem() { System.out.println(item.toString()); Role role = item.getRole(); - assertEquals(IPrevExchangeItem.Role.InOut, role); + assertEquals(Role.InOut, role); double values[] = item.getValuesAsDoubles(); assertEquals(2*3*4, values.length); @@ -225,7 +224,7 @@ public static void testArrayExchangeItem() { System.out.println(item.toString()); Role role = item.getRole(); - assertEquals(IPrevExchangeItem.Role.InOut, role); + assertEquals(Role.InOut, role); double values[] = item.getValuesAsDoubles(); assertEquals(2*3*4, values.length); diff --git a/core/java/test/org/openda/exchange/dataobjects/AsciiVectorDataObjectTest.java b/core/java/test/org/openda/exchange/dataobjects/AsciiVectorDataObjectTest.java index 6505d37f3..eb9f03f26 100644 --- a/core/java/test/org/openda/exchange/dataobjects/AsciiVectorDataObjectTest.java +++ b/core/java/test/org/openda/exchange/dataobjects/AsciiVectorDataObjectTest.java @@ -26,7 +26,6 @@ import java.io.IOException; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.OpenDaTestSupport; public class AsciiVectorDataObjectTest extends TestCase { @@ -48,7 +47,7 @@ public void testIoCopySeriesFromObject(){ AsciiVectorDataObject vec1 = new AsciiVectorDataObject(); vec1.initialize(this.testRunDataDir, new String[] {"vector1.txt"}); - IPrevExchangeItem[] exchange1 = vec1.getExchangeItems(); + IExchangeItem[] exchange1 = vec1.getExchangeItems(); assertEquals(1,exchange1.length); double[] vals1 = exchange1[0].getValuesAsDoubles(); assertEquals(5, vals1.length); @@ -67,7 +66,7 @@ public void testIoCopySeriesFromObject(){ AsciiVectorDataObject vec2 = new AsciiVectorDataObject(); vec2.initialize(this.testRunDataDir, new String[] {"vector1.txt"}); - IPrevExchangeItem [] exchange2 = vec2.getExchangeItems(); + IExchangeItem [] exchange2 = vec2.getExchangeItems(); assertEquals(1,exchange2.length); double[] vals2 = exchange2[0].getValuesAsDoubles(); assertEquals(5, vals1.length); diff --git a/core/java/test/org/openda/exchange/dataobjects/NoosDataObjectTest.java b/core/java/test/org/openda/exchange/dataobjects/NoosDataObjectTest.java index 07e4713a0..d3fcc68ac 100644 --- a/core/java/test/org/openda/exchange/dataobjects/NoosDataObjectTest.java +++ b/core/java/test/org/openda/exchange/dataobjects/NoosDataObjectTest.java @@ -21,15 +21,16 @@ import junit.framework.TestCase; -import org.openda.exchange.dataobjects.NoosDataObject; +import org.openda.exchange.timeseries.NoosTimeSeriesFormatter; import org.openda.exchange.timeseries.TimeSeries; +import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.Array; import org.openda.utils.OpenDaTestSupport; import java.io.File; import java.io.IOException; +import java.text.ParseException; /** * @author johan, verlaanm @@ -52,33 +53,33 @@ public void testRead1() { System.out.println("-------------------------------------------------------------------"); // read noos file and create object NoosDataObject noosDO = new NoosDataObject(); - noosDO.initialize(this.testRunDataDir, "aberdeen_waterlevel_astro.noos"); + noosDO.initialize(this.testRunDataDir, new String[]{"aberdeen_waterlevel_astro.noos"}); - String ids[]=noosDO.getExchangeItemIDs(); + String[] ids =noosDO.getExchangeItemIDs(); assertEquals(1, ids.length); IExchangeItem noosEx = noosDO.getDataObjectExchangeItem(ids[0]); assertEquals("TimeSeries", noosEx.getClass().getSimpleName()); TimeSeries ts = (TimeSeries) (noosEx); - assertEquals("aberdeen.waterlevel_astro", ts.getId()); - assertEquals("aberdeen", ts.getLocation()); + assertEquals("Aberdeen.waterlevel_astro", ts.getId()); + assertEquals("Aberdeen", ts.getLocation()); assertEquals("observed", ts.getSource()); assertEquals("m", ts.getUnitId()); assertEquals("waterlevel_astro", ts.getQuantityId()); - assertEquals(-2.045543, ts.getPosition()[0]); - assertEquals(57.361939, ts.getPosition()[1]); + assertEquals(-2.073333, ts.getPosition()[0]); + assertEquals(57.143333, ts.getPosition()[1]); - assertEquals(54466.0, ts.getStartTime()); - assertEquals(54466.125, ts.getStopTime()); + assertEquals("202001010000", TimeUtils.mjdToString(ts.getStartTime())); + assertEquals("202001010300", TimeUtils.mjdToString(ts.getStopTime())); assertEquals(19, ts.getTimes().length); - assertEquals(54466.0, ts.getTimes()[0]); - assertEquals(54466.125, ts.getTimes()[18]); + assertEquals("202001010000", TimeUtils.mjdToString(ts.getTimes()[0])); + assertEquals("202001010300", TimeUtils.mjdToString(ts.getTimes()[18])); assertEquals(19, ts.getValuesAsDoubles().length); - assertEquals(-0.83, ts.getValuesAsDoubles()[0]); - assertEquals(-0.6, ts.getValuesAsDoubles()[18]); + assertEquals(-1.09, ts.getValuesAsDoubles()[0]); + assertEquals(0.4, ts.getValuesAsDoubles()[18]); assertEquals(0, ts.getExtraValuesKeySet().size()); } @@ -89,33 +90,33 @@ public void testRead2() { System.out.println("-------------------------------------------------------------------"); // read noos files and create object NoosDataObject noosDO = new NoosDataObject(); - noosDO.initialize(this.testRunDataDir, "*_waterlevel_astro.noos"); + noosDO.initialize(this.testRunDataDir, new String[]{"*_waterlevel*.noos"}); - String ids[]=noosDO.getExchangeItemIDs(); + String[] ids =noosDO.getExchangeItemIDs(); assertEquals(2, ids.length); - IExchangeItem noosEx = noosDO.getDataObjectExchangeItem("den helder.waterlevel_astro"); + IExchangeItem noosEx = noosDO.getDataObjectExchangeItem("Den Helder.waterlevel"); assertEquals("TimeSeries", noosEx.getClass().getSimpleName()); TimeSeries ts = (TimeSeries) (noosEx); - assertEquals("den helder.waterlevel_astro", ts.getId()); - assertEquals("den helder", ts.getLocation()); - assertEquals("observed", ts.getSource()); + assertEquals("Den Helder.waterlevel", ts.getId()); + assertEquals("Den Helder", ts.getLocation()); + assertEquals("dcsm_v6_kf_hirlam", ts.getSource()); assertEquals("m", ts.getUnitId()); - assertEquals("waterlevel_astro", ts.getQuantityId()); - assertEquals(4.745356, ts.getPosition()[0]); - assertEquals(52.966001, ts.getPosition()[1]); + assertEquals("waterlevel", ts.getQuantityId()); + assertEquals(4.745326, ts.getPosition()[0]); + assertEquals(52.965441, ts.getPosition()[1]); - assertEquals(54466.0, ts.getStartTime()); - assertEquals(54466.125, ts.getStopTime()); + assertEquals("202001010000", TimeUtils.mjdToString(ts.getStartTime())); + assertEquals("202001010300", TimeUtils.mjdToString(ts.getStopTime())); assertEquals(19, ts.getTimes().length); - assertEquals(54466.0, ts.getTimes()[0]); - assertEquals(54466.125, ts.getTimes()[18]); + assertEquals("202001010000", TimeUtils.mjdToString(ts.getTimes()[0])); + assertEquals("202001010300", TimeUtils.mjdToString(ts.getTimes()[18])); assertEquals(19, ts.getValuesAsDoubles().length); - assertEquals(0.73, ts.getValuesAsDoubles()[0]); - assertEquals(0.0, ts.getValuesAsDoubles()[18]); + assertEquals(0.0997, ts.getValuesAsDoubles()[0]); + assertEquals(-0.7394, ts.getValuesAsDoubles()[18]); assertEquals(0, ts.getExtraValuesKeySet().size()); } @@ -126,9 +127,9 @@ public void testWrite() { System.out.println("-------------------------------------------------------------------"); // read noos files and create object NoosDataObject noosDO = new NoosDataObject(); - noosDO.initialize(this.testRunDataDir, "series*.noos"); + noosDO.initialize(this.testRunDataDir, new String[]{"series*.noos"}); - String ids[]=noosDO.getExchangeItemIDs(); + String[] ids =noosDO.getExchangeItemIDs(); assertEquals(2, ids.length); // check original series @@ -144,12 +145,12 @@ public void testWrite() { assertEquals(-2.0, ts.getPosition()[0]); assertEquals(53.3, ts.getPosition()[1]); - assertEquals(54466.0, ts.getStartTime()); - assertEquals(54466.0833333, ts.getStopTime(),1e-3); + assertEquals("200801010000", TimeUtils.mjdToString(ts.getStartTime())); + assertEquals("200801010200", TimeUtils.mjdToString(ts.getStopTime())); assertEquals(5, ts.getTimes().length); - assertEquals(54466.0, ts.getTimes()[0]); - assertEquals(54466.0833333, ts.getTimes()[4],1e-3); + assertEquals("200801010000", TimeUtils.mjdToString(ts.getTimes()[0])); + assertEquals("200801010200", TimeUtils.mjdToString(ts.getTimes()[4])); assertEquals(5, ts.getValuesAsDoubles().length); assertEquals(-0.83, ts.getValuesAsDoubles()[0]); @@ -158,7 +159,7 @@ public void testWrite() { assertEquals(0, ts.getExtraValuesKeySet().size()); // modify content - Array values = (Array)ts.getValues(); + Array values; values=new Array("{0.,1.,2.,3.,4.}"); ts.setValues(values); @@ -178,9 +179,9 @@ public void testCreateWrite() { System.out.println("-------------------------------------------------------------------"); // read noos files and create object NoosDataObject noosDO = new NoosDataObject(); - noosDO.initialize(this.testRunDataDir, ""); // no data yet + noosDO.initialize(this.testRunDataDir, new String[]{""}); // no data yet - String ids[]=noosDO.getExchangeItemIDs(); + String[] ids =noosDO.getExchangeItemIDs(); assertEquals(0, ids.length); //empty // create and add some timeseries @@ -207,142 +208,74 @@ public void testCreateWrite() { assertTrue(test2); } -// public void testWrite1() { -// -// // read noos file and create object -// NoosTimeSeriesIoObject noosIO = new NoosTimeSeriesIoObject(); -// -// noosIO.initialize(this.testRunDataDir, "NoosTimeSeriesIoObjectTestData1.txt"); -// assertEquals(1, noosIO.getExchangeItems().length); -// assertEquals(1, noosIO.getTimeSeriesSet().size()); -// -// // then write it again under another name -// File noosFile = new File(this.testRunDataDir, "copy_of_NoosTimeSeriesIoObjectTestData1.txt"); -// NoosTimeSeriesIoObject.writeNoosTimeSeries((TimeSeries) noosIO.getExchangeItems()[0], noosFile); -// -// // finally, test it -// TimeSeries series1 = (TimeSeries) noosIO.getExchangeItems()[0]; -// NoosTimeSeriesIoObject noosIO2 = new NoosTimeSeriesIoObject(); -// noosIO2.initialize(this.testRunDataDir, "copy_of_NoosTimeSeriesIoObjectTestData1.txt"); -// TimeSeries series2 = (TimeSeries) noosIO2.getExchangeItems()[0]; -// assertTrue(series1.equals(series2)); -// } -// -// @SuppressWarnings("boxing") -// public void testRead2() { -// // data with analysis times as additional column -// // read noos file and create object -// NoosTimeSeriesIoObject noosIO = new NoosTimeSeriesIoObject(); -// -// noosIO.initialize(this.testRunDataDir, "NoosTimeSeriesIoObjectTestData2.txt"); -// -// IPrevExchangeItem noosEx[] = noosIO.getExchangeItems(); -// assertEquals(1, noosEx.length); -// assertEquals("TimeSeries", noosEx[0].getClass().getSimpleName()); -// -// TimeSeries ts = (TimeSeries) (noosEx[0]); -// assertEquals("hoekvanholland.waterlevel", ts.getId()); -// assertEquals("hoekvanholland", ts.getLocation()); -// assertEquals("observed", ts.getSource()); -// assertEquals("m", ts.getUnitId()); -// assertEquals("waterlevel", ts.getQuantityId()); -// assertEquals(4.120131, ts.getPosition()[0]); -// assertEquals(51.978539, ts.getPosition()[1]); -// -// assertEquals(55391.0, ts.getStartTime()); -// assertEquals(55392.0, ts.getStopTime()); -// assertTrue(ts.intersectsWithTimeInterval(55389.0, 55391.0)); -// assertTrue(ts.intersectsWithTimeInterval(55391.0, 55392.0)); -// assertTrue(ts.intersectsWithTimeInterval(55389.0, 55394.0)); -// assertTrue(ts.intersectsWithTimeInterval(55392.0, 55394.0)); -// assertFalse(ts.intersectsWithTimeInterval(55389.0, 55390.9)); -// assertFalse(ts.intersectsWithTimeInterval(55392.1, 55394.0)); -// -// assertEquals(145, ts.getTimes().length); -// assertEquals(55391.0, ts.getTimes()[0]); -// assertEquals(55392.0, ts.getTimes()[144]); -// -// assertEquals(145, ts.getValuesAsDoubles().length); -// assertEquals(-0.59, ts.getValuesAsDoubles()[0]); -// assertEquals(-0.71, ts.getValuesAsDoubles()[144]); -// -// assertEquals(1, ts.getExtraValuesKeySet().size()); -// assertTrue(ts.getExtraValuesKeySet().contains("analTimes")); -// } -// -// public void testWrite2() { -// -// // read noos file and create object -// NoosTimeSeriesIoObject noosIO = new NoosTimeSeriesIoObject(); -// -// noosIO.initialize(this.testRunDataDir, "NoosTimeSeriesIoObjectTestData2.txt"); -// assertEquals(1, noosIO.getExchangeItems().length); -// -// // then write it again under another name -// File noosFile = new File(this.testRunDataDir, "copy_of_NoosTimeSeriesIoObjectTestData2.txt"); -// NoosTimeSeriesIoObject.writeNoosTimeSeries((TimeSeries) noosIO.getExchangeItems()[0], noosFile); -// -// // finally, test it -// TimeSeries series1 = (TimeSeries) noosIO.getExchangeItems()[0]; -// NoosTimeSeriesIoObject noosIO2 = new NoosTimeSeriesIoObject(); -// noosIO2.initialize(this.testRunDataDir, "copy_of_NoosTimeSeriesIoObjectTestData2.txt"); -// TimeSeries series2 = (TimeSeries) noosIO2.getExchangeItems()[0]; -// assertTrue(series1.equals(series2)); -// } -// -// public void testRead3() { -// -// // read noos files and create object -// NoosTimeSeriesIoObject noosIO = new NoosTimeSeriesIoObject(); -// -// noosIO.initialize(this.testRunDataDir, "NoosTimeSeriesIoObjectTestData*.txt"); -// assertEquals(2, noosIO.getTimeSeriesSet().size()); -// -// IPrevExchangeItem noosEx[] = noosIO.getExchangeItems(); -// assertEquals(2, noosEx.length); -// assertEquals("TimeSeries", noosEx[0].getClass().getSimpleName()); -// assertEquals("TimeSeries", noosEx[1].getClass().getSimpleName()); -// -// TimeSeries ts0 = (TimeSeries) (noosEx[0]); -// TimeSeries ts1 = (TimeSeries) (noosEx[1]); -// assertTrue((ts0.hasExtraValues("analTimes") && !ts1.hasExtraValues("analTimes")) -// || (ts1.hasExtraValues("analTimes") && !ts0.hasExtraValues("analTimes"))); -// } -// -// public void testWrite3() { -// -// // read noos files and create object -// NoosTimeSeriesIoObject noosIO = new NoosTimeSeriesIoObject(); -// -// noosIO.initialize(this.testRunDataDir, "NoosTimeSeriesIoObjectTestData*.txt"); -// assertEquals(2, noosIO.getTimeSeriesSet().size()); -// -// IPrevExchangeItem noosEx[] = noosIO.getExchangeItems(); -// assertEquals(2, noosEx.length); -// assertEquals("TimeSeries", noosEx[0].getClass().getSimpleName()); -// assertEquals("TimeSeries", noosEx[1].getClass().getSimpleName()); -// -// TimeSeries ts0 = (TimeSeries) (noosEx[0]); -// TimeSeries ts1 = (TimeSeries) (noosEx[1]); -// assertTrue((ts0.hasExtraValues("analTimes") && !ts1.hasExtraValues("analTimes")) -// || (ts1.hasExtraValues("analTimes") && !ts0.hasExtraValues("analTimes"))); -// -// ts0.setProperty(NoosTimeSeriesIoObject.PROPERTY_PATHNAME, new File(this.testRunDataDir, "test0.txt").getAbsolutePath()); -// ts1.setProperty(NoosTimeSeriesIoObject.PROPERTY_PATHNAME, new File(this.testRunDataDir, "test1.txt").getAbsolutePath()); -// -// noosIO.finish(); -// -// NoosTimeSeriesIoObject noosIO2 = new NoosTimeSeriesIoObject(); -// -// noosIO2.initialize(this.testRunDataDir, "test?.txt"); -// assertEquals(2, noosIO2.getTimeSeriesSet().size()); -// -// IPrevExchangeItem noosEx2[] = noosIO2.getExchangeItems(); -// TimeSeries ts0a = (TimeSeries) (noosEx2[0]); -// TimeSeries ts1a = (TimeSeries) (noosEx2[1]); -// -// assertTrue(ts0.equals(ts0a) || ts0.equals(ts1a)); -// assertTrue(ts1.equals(ts1a) || ts1.equals(ts0a)); -// } + public void testReadTimeZoneMET() throws ParseException { + + // read noos file and create object + NoosDataObject noosDO = new NoosDataObject(); + + noosDO.initialize(this.testRunDataDir, new String[]{"NoosTimeSeriesDataObjectTestMETData.txt"}); + + String[] ids = noosDO.getExchangeItemIDs(); + assertEquals(1, ids.length); + IExchangeItem noosEx = noosDO.getDataObjectExchangeItem(ids[0]); + + assertEquals("TimeSeries", noosEx.getClass().getSimpleName()); + + TimeSeries ts = (TimeSeries) noosEx; + assertEquals("Hoek van Holland.waterlevel", ts.getId()); + assertEquals("Hoek van Holland", ts.getLocation()); + assertEquals("dcsm_v6_kf_hirlam", ts.getSource()); + assertEquals("m", ts.getUnitId()); + assertEquals("waterlevel", ts.getQuantityId()); + assertEquals(4.120131, ts.getPosition()[0]); + assertEquals(51.978539, ts.getPosition()[1]); + + //Note: in NoosTimeSeriesFormatter, a correction from the actual time zone to GMT is done, + // so therefore there is 1 hour difference with the noos data. + assertEquals("201912312300", TimeUtils.mjdToString(ts.getStartTime())); + assertEquals("202001010200", TimeUtils.mjdToString(ts.getStopTime())); + assertTrue(ts.intersectsWithTimeInterval(TimeUtils.date2Mjd("201912310000"), TimeUtils.date2Mjd("202001010200"))); + assertTrue(ts.intersectsWithTimeInterval(TimeUtils.date2Mjd("202001010100"), TimeUtils.date2Mjd("202001020000"))); + assertTrue(ts.intersectsWithTimeInterval(TimeUtils.date2Mjd("201912290000"), TimeUtils.date2Mjd("202001030000"))); + assertTrue(ts.intersectsWithTimeInterval(TimeUtils.date2Mjd("201912312300"), TimeUtils.date2Mjd("202001030000"))); + assertFalse(ts.intersectsWithTimeInterval(TimeUtils.date2Mjd("201912290000"), TimeUtils.date2Mjd("201912312200"))); + assertFalse(ts.intersectsWithTimeInterval(TimeUtils.date2Mjd("202001010400"), TimeUtils.date2Mjd("202001030000"))); + + assertEquals(19, ts.getTimes().length); + assertEquals("201912312300", TimeUtils.mjdToString(ts.getTimes()[0])); + assertEquals("202001010200", TimeUtils.mjdToString(ts.getTimes()[18])); + + assertEquals(19, ts.getValuesAsDoubles().length); + assertEquals(-0.5444, ts.getValuesAsDoubles()[0]); + assertEquals(-0.4781, ts.getValuesAsDoubles()[18]); + + assertEquals(0, ts.getExtraValuesKeySet().size()); + assertEquals("MET", ts.getProperty(NoosTimeSeriesFormatter.PROPERTY_TIMEZONE)); + } + + public void testWriteTimeZoneMET() { + + // read noos file and create object + NoosDataObject noosDO = new NoosDataObject(); + noosDO.initialize(this.testRunDataDir, new String[]{"NoosTimeSeriesDataObjectTestMETData.txt"}); + + String[] ids = noosDO.getExchangeItemIDs(); + assertEquals(1, ids.length); + IExchangeItem noosEx = noosDO.getDataObjectExchangeItem(ids[0]); + + // then write it again under another name + File noosFile = new File(this.testRunDataDir, "copy_of_NoosTimeSeriesDataObjectTestMETData.txt"); + NoosDataObject.writeNoosTimeSeries((TimeSeries) noosEx, noosFile); + + // finally, test it + TimeSeries series1 = (TimeSeries) noosEx; + NoosDataObject noosDO2 = new NoosDataObject(); + noosDO2.initialize(this.testRunDataDir, new String[]{"copy_of_NoosTimeSeriesDataObjectTestMETData.txt"}); + + ids = noosDO2.getExchangeItemIDs(); + IExchangeItem noosEx2 = noosDO2.getDataObjectExchangeItem(ids[0]); + TimeSeries series2 = (TimeSeries) noosEx2; + assertTrue(series1.equals(series2)); + } } diff --git a/core/java/test/org/openda/exchange/dataobjects/testData/NoosTimeSeriesDataObjectTestMETData.txt b/core/java/test/org/openda/exchange/dataobjects/testData/NoosTimeSeriesDataObjectTestMETData.txt new file mode 100644 index 000000000..fdab239ec --- /dev/null +++ b/core/java/test/org/openda/exchange/dataobjects/testData/NoosTimeSeriesDataObjectTestMETData.txt @@ -0,0 +1,30 @@ +#------------------------------------------------------ +# Timeseries retrieved from the MATROOS series database +# Created at Tue Apr 28 12:24:50 CEST 2020 +#------------------------------------------------------ +# Location : Hoek van Holland +# Position : (4.120131,51.978539) +# Source : dcsm_v6_kf_hirlam +# Unit : waterlevel +# Analyse time: 202001010700 +# Timezone : MET +#------------------------------------------------------ +202001010000 -0.5444 +202001010010 -0.5288 +202001010020 -0.5346 +202001010030 -0.5424 +202001010040 -0.5513 +202001010050 -0.5615 +202001010100 -0.5710 +202001010110 -0.6027 +202001010120 -0.6208 +202001010130 -0.6242 +202001010140 -0.6100 +202001010150 -0.6114 +202001010200 -0.6160 +202001010210 -0.5991 +202001010220 -0.5600 +202001010230 -0.5859 +202001010240 -0.7032 +202001010250 -0.6739 +202001010300 -0.4781 \ No newline at end of file diff --git a/core/java/test/org/openda/exchange/dataobjects/testData/TimeSeriesFormatter.xml b/core/java/test/org/openda/exchange/dataobjects/testData/TimeSeriesFormatter.xml index 1184bf8d1..3e381fbeb 100644 --- a/core/java/test/org/openda/exchange/dataobjects/testData/TimeSeriesFormatter.xml +++ b/core/java/test/org/openda/exchange/dataobjects/testData/TimeSeriesFormatter.xml @@ -7,7 +7,7 @@ # - den_helder_waterlevel_astro.noos + den_helder_waterlevel.noos aberdeen_waterlevel_astro.noos diff --git a/core/java/test/org/openda/exchange/dataobjects/testData/aberdeen_waterlevel_astro.noos b/core/java/test/org/openda/exchange/dataobjects/testData/aberdeen_waterlevel_astro.noos index cf9576a15..2c826b49f 100644 --- a/core/java/test/org/openda/exchange/dataobjects/testData/aberdeen_waterlevel_astro.noos +++ b/core/java/test/org/openda/exchange/dataobjects/testData/aberdeen_waterlevel_astro.noos @@ -1,30 +1,30 @@ #------------------------------------------------------ # Timeseries retrieved from the MATROOS series database -# Created at Mon Mar 17 10:37:38 CET 2008 +# Created at Tue Apr 28 10:50:53 CEST 2020 #------------------------------------------------------ -# Location : aberdeen -# Position : (-2.045543,57.361939) +# Location : Aberdeen +# Position : (-2.073333,57.143333) # Source : observed # Unit : waterlevel_astro -# Analyse time: most recent +# Analyse time: 000000000000 # Timezone : GMT #------------------------------------------------------ -200801010000 -0.8300 -200801010010 -0.8800 -200801010020 -0.9100 -200801010030 -0.9500 -200801010040 -0.9700 -200801010050 -0.9800 -200801010100 -0.9900 -200801010110 -0.9900 -200801010120 -0.9800 -200801010130 -0.9700 -200801010140 -0.9500 -200801010150 -0.9200 -200801010200 -0.8900 -200801010210 -0.8500 -200801010220 -0.8100 -200801010230 -0.7700 -200801010240 -0.7100 -200801010250 -0.6600 -200801010300 -0.6000 +202001010000 -1.0900 +202001010010 -1.0300 +202001010020 -0.9700 +202001010030 -0.8900 +202001010040 -0.8100 +202001010050 -0.7300 +202001010100 -0.6400 +202001010110 -0.5500 +202001010120 -0.4600 +202001010130 -0.3700 +202001010140 -0.2800 +202001010150 -0.1900 +202001010200 -0.1000 +202001010210 -0.0200 +202001010220 0.0700 +202001010230 0.1500 +202001010240 0.2400 +202001010250 0.3200 +202001010300 0.4000 diff --git a/core/java/test/org/openda/exchange/dataobjects/testData/den_helder_waterlevel.noos b/core/java/test/org/openda/exchange/dataobjects/testData/den_helder_waterlevel.noos new file mode 100644 index 000000000..fe4ec3998 --- /dev/null +++ b/core/java/test/org/openda/exchange/dataobjects/testData/den_helder_waterlevel.noos @@ -0,0 +1,30 @@ +#------------------------------------------------------ +# Timeseries retrieved from the MATROOS series database +# Created at Tue Apr 28 10:42:52 CEST 2020 +#------------------------------------------------------ +# Location : Den Helder +# Position : (4.745326,52.965441) +# Source : dcsm_v6_kf_hirlam +# Unit : waterlevel +# Analyse time: 202001010600 +# Timezone : GMT +#------------------------------------------------------ +202001010000 0.0997 +202001010010 0.0653 +202001010020 0.0019 +202001010030 -0.0799 +202001010040 -0.1338 +202001010050 -0.2034 +202001010100 -0.2407 +202001010110 -0.2941 +202001010120 -0.3460 +202001010130 -0.3930 +202001010140 -0.4314 +202001010150 -0.4754 +202001010200 -0.5323 +202001010210 -0.5670 +202001010220 -0.5994 +202001010230 -0.6360 +202001010240 -0.6720 +202001010250 -0.7098 +202001010300 -0.7394 \ No newline at end of file diff --git a/core/java/test/org/openda/exchange/dataobjects/testData/den_helder_waterlevel_astro.noos b/core/java/test/org/openda/exchange/dataobjects/testData/den_helder_waterlevel_astro.noos deleted file mode 100644 index 41b217ee5..000000000 --- a/core/java/test/org/openda/exchange/dataobjects/testData/den_helder_waterlevel_astro.noos +++ /dev/null @@ -1,30 +0,0 @@ -#------------------------------------------------------ -# Timeseries retrieved from the MATROOS series database -# Created at Mon Mar 17 10:37:58 CET 2008 -#------------------------------------------------------ -# Location : den helder -# Position : (4.745356,52.966001) -# Source : observed -# Unit : waterlevel_astro -# Analyse time: most recent -# Timezone : GMT -#------------------------------------------------------ -200801010000 0.7300 -200801010010 0.7300 -200801010020 0.7200 -200801010030 0.7000 -200801010040 0.6800 -200801010050 0.6600 -200801010100 0.6300 -200801010110 0.5900 -200801010120 0.5500 -200801010130 0.5100 -200801010140 0.4600 -200801010150 0.4000 -200801010200 0.3500 -200801010210 0.2900 -200801010220 0.2300 -200801010230 0.1700 -200801010240 0.1200 -200801010250 0.0600 -200801010300 0.0000 diff --git a/core/java/test/org/openda/exchange/ioobjects/NoosTimeSeriesIoObjectTest.java b/core/java/test/org/openda/exchange/ioobjects/NoosTimeSeriesIoObjectTest.java index 7f4f3cd1f..9eaf8aa24 100644 --- a/core/java/test/org/openda/exchange/ioobjects/NoosTimeSeriesIoObjectTest.java +++ b/core/java/test/org/openda/exchange/ioobjects/NoosTimeSeriesIoObjectTest.java @@ -22,7 +22,7 @@ import junit.framework.TestCase; import org.openda.exchange.timeseries.NoosTimeSeriesFormatter; import org.openda.exchange.timeseries.TimeSeries; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.OpenDaTestSupport; import java.io.File; @@ -50,7 +50,7 @@ public void testRead1() { noosIO.initialize(this.testRunDataDir, "NoosTimeSeriesIoObjectTestData1.txt"); - IPrevExchangeItem noosEx[] = noosIO.getExchangeItems(); + IExchangeItem noosEx[] = noosIO.getExchangeItems(); assertEquals(1, noosEx.length); assertEquals("TimeSeries", noosEx[0].getClass().getSimpleName()); @@ -112,7 +112,7 @@ public void testRead2() { noosIO.initialize(this.testRunDataDir, "NoosTimeSeriesIoObjectTestData2.txt"); - IPrevExchangeItem noosEx[] = noosIO.getExchangeItems(); + IExchangeItem noosEx[] = noosIO.getExchangeItems(); assertEquals(1, noosEx.length); assertEquals("TimeSeries", noosEx[0].getClass().getSimpleName()); @@ -174,7 +174,7 @@ public void testRead3() { noosIO.initialize(this.testRunDataDir, "NoosTimeSeriesIoObjectTestData*.txt"); assertEquals(2, noosIO.getTimeSeriesSet().size()); - IPrevExchangeItem noosEx[] = noosIO.getExchangeItems(); + IExchangeItem noosEx[] = noosIO.getExchangeItems(); assertEquals(2, noosEx.length); assertEquals("TimeSeries", noosEx[0].getClass().getSimpleName()); assertEquals("TimeSeries", noosEx[1].getClass().getSimpleName()); @@ -193,7 +193,7 @@ public void testWrite3() { noosIO.initialize(this.testRunDataDir, "NoosTimeSeriesIoObjectTestData*.txt"); assertEquals(2, noosIO.getTimeSeriesSet().size()); - IPrevExchangeItem noosEx[] = noosIO.getExchangeItems(); + IExchangeItem noosEx[] = noosIO.getExchangeItems(); assertEquals(2, noosEx.length); assertEquals("TimeSeries", noosEx[0].getClass().getSimpleName()); assertEquals("TimeSeries", noosEx[1].getClass().getSimpleName()); @@ -213,7 +213,7 @@ public void testWrite3() { noosIO2.initialize(this.testRunDataDir, "test?.txt"); assertEquals(2, noosIO2.getTimeSeriesSet().size()); - IPrevExchangeItem noosEx2[] = noosIO2.getExchangeItems(); + IExchangeItem noosEx2[] = noosIO2.getExchangeItems(); TimeSeries ts0a = (TimeSeries) (noosEx2[0]); TimeSeries ts1a = (TimeSeries) (noosEx2[1]); @@ -229,7 +229,7 @@ public void testReadTimeZoneCET() { noosIO.initialize(this.testRunDataDir, "NoosTimeSeriesIoObjectTestCETData.txt"); - IPrevExchangeItem noosEx[] = noosIO.getExchangeItems(); + IExchangeItem noosEx[] = noosIO.getExchangeItems(); assertEquals(1, noosEx.length); assertEquals("TimeSeries", noosEx[0].getClass().getSimpleName()); diff --git a/core/java/test/org/openda/exchange/timeseries/TimeSeriesTest.java b/core/java/test/org/openda/exchange/timeseries/TimeSeriesTest.java index 1f487ce4d..d968a0b95 100644 --- a/core/java/test/org/openda/exchange/timeseries/TimeSeriesTest.java +++ b/core/java/test/org/openda/exchange/timeseries/TimeSeriesTest.java @@ -23,31 +23,29 @@ import org.openda.interfaces.IArray; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.Mask; -import java.lang.reflect.Type; import java.util.Arrays; public class TimeSeriesTest extends TestCase { - public static void testTimeSeries() { + public void testTimeSeries() { System.out.println("=============================================================================="); System.out.println("test TimeSeries"); System.out.println("=============================================================================="); double delta = 0.00001; // public TimeSeries(double times[], double values[]){ - double times[] = { 0.0, 1.0, 2.0, 3.0 }; - double values[] = { 0.0, 0.1, 0.2, 0.3 }; + double[] times = { 0.0, 1.0, 2.0, 3.0 }; + double[] values = { 0.0, 0.1, 0.2, 0.3 }; TimeSeries ts1 = new TimeSeries(times, values); // public double[] getTimes(){ - double times2[] = ts1.getTimes(); + double[] times2 = ts1.getTimes(); System.out.println("times2[1] =" + times2[1]); System.out.println("Should be times2[1] = 1.0"); assertEquals(1.0, times2[1], delta); // public double[] getValues(){ - double values2[] = ts1.getValuesAsDoubles(); + double[] values2 = ts1.getValuesAsDoubles(); System.out.println("values2[1] =" + values2[1]); System.out.println("Should be values2[1] = 0.1"); assertEquals(0.1, values2[1], delta); @@ -62,12 +60,12 @@ public static void testTimeSeries() { TimeSeries ts2 = new TimeSeries(times, values, x, y, source, quantity, unit, location); // public TimeSeries(double times[], double values[]){ // public double[] getTimes(){ - double times3[] = ts2.getTimes(); + double[] times3 = ts2.getTimes(); System.out.println("times3[1] =" + times3[1]); System.out.println("Should be times3[1] = 1.0"); assertEquals(1.0, times3[1], delta); // public double[] getValues(){ - double values3[] = ts2.getValuesAsDoubles(); + double[] values3 = ts2.getValuesAsDoubles(); System.out.println("values3[1] =" + values3[1]); System.out.println("Should be values3[1] = 0.1"); assertEquals(0.1, values3[1], delta); @@ -146,13 +144,13 @@ public static void testTimeSeries() { assertEquals(0.1, height2, delta); // public void setData(double[] times,double[] values){ - double times4[] = { 10.0, 11.0, 12.0, 13.0 }; - double values4[] = { 10.0, 10.1, 10.2, 10.3 }; + double[] times4 = { 10.0, 11.0, 12.0, 13.0 }; + double[] values4 = { 10.0, 10.1, 10.2, 10.3 }; ts2.setData(times4, values4); // public double[] getTimesRef(){ - double times5[] = ts2.getTimesRef(); + double[] times5 = ts2.getTimesRef(); // public double[] getValuesRef(){ - double values5[] = ts2.getValuesRef(); + double[] values5 = ts2.getValuesRef(); System.out.println("times5[1] =" + times5[1]); System.out.println("Should be times5[1] = 11.0"); assertEquals(11.0, times5[1], delta); @@ -172,13 +170,13 @@ public static void testTimeSeries() { String property2 = ts2.getProperty("doesNotExist"); System.out.println("property2 =" + property2); System.out.println("Should be property2 = null"); - assertEquals(null, property2); + assertNull(property2); // check for a property boolean propIsThere = ts2.hasProperty("referencePlane"); boolean propIsNotThere = ts2.hasProperty("doesNotExist"); - assertEquals(true, propIsThere); - assertEquals(false, propIsNotThere); + assertTrue(propIsThere); + assertFalse(propIsNotThere); // get property with a default if it is not there String refPlane = ts2.getStringProperty("referencePlane", "Rijksdriehoek"); @@ -194,22 +192,22 @@ public static void testTimeSeries() { } - public static void testTimeSeriesSelection() { + public void testTimeSeriesSelection() { System.out.println("=============================================================================="); System.out.println("test selection on TimeSeries"); System.out.println("=============================================================================="); double delta = 0.00001; // public TimeSeries(double times[], double values[]){ - double times[] = { 0.0, 1.0, 2.0, 3.0 }; - double values[] = { 0.0, 0.1, 0.2, 0.3 }; + double[] times = { 0.0, 1.0, 2.0, 3.0 }; + double[] values = { 0.0, 0.1, 0.2, 0.3 }; TimeSeries ts1 = new TimeSeries(times, values); ts1.setLocation("location"); // public double[] getTimes(){ TimeSeries ts2 = ts1.selectTimeSubset(0.5, 2.5); - double times2[] = ts2.getTimesRef(); - double values2[] = ts2.getValuesRef(); + double[] times2 = ts2.getTimesRef(); + double[] values2 = ts2.getValuesRef(); System.out.println("times2.length =" + times2.length); System.out.println("Should be times2.length = 2"); assertEquals(2, times2.length); @@ -246,8 +244,8 @@ public static void testTimeSeriesSelection() { // times[] = {0.0, 1.0, 2.0, 3.0}; TimeSeries ts3 = ts1.selectTimeSubset(0.5, 4.0); - double times3[] = ts3.getTimesRef(); - double values3[] = ts3.getValuesRef(); + double[] times3 = ts3.getTimesRef(); + double[] values3 = ts3.getValuesRef(); System.out.println("times3.length =" + times3.length); System.out.println("Should be times3.length = 3"); assertEquals(3, times3.length); @@ -262,8 +260,8 @@ public static void testTimeSeriesSelection() { // times[] = {0.0, 1.0, 2.0, 3.0}; TimeSeries ts4 = ts1.selectTimeSubset(-0.5, 2.5); - double times4[] = ts4.getTimesRef(); - double values4[] = ts4.getValuesRef(); + double[] times4 = ts4.getTimesRef(); + double[] values4 = ts4.getValuesRef(); System.out.println("times4.length =" + times4.length); System.out.println("Should be times4.length = 4"); assertEquals(3, times4.length); @@ -278,21 +276,21 @@ public static void testTimeSeriesSelection() { // times[] = {0.0, 1.0, 2.0, 3.0}; Empty selection TimeSeries ts5 = ts1.selectTimeSubset(3.5, 5.5); - double times5[] = ts5.getTimesRef(); - double values5[] = ts5.getValuesRef(); - assertTrue(times5 == null); - assertTrue(values5 == null); + double[] times5 = ts5.getTimesRef(); + double[] values5 = ts5.getValuesRef(); + assertNull(times5); + assertNull(values5); } - public static void testTimeSeriesMaskSelection() { + public void testTimeSeriesMaskSelection() { System.out.println("=============================================================================="); System.out.println("test mask selection on TimeSeries"); System.out.println("=============================================================================="); double delta = 0.00001; // public TimeSeries(double times[], double values[]){ - double times[] = { 0.0, 1.0, 2.0, 3.0 }; - double values[] = { 0.0, 0.1, 0.2, 0.3 }; + double[] times = { 0.0, 1.0, 2.0, 3.0 }; + double[] values = { 0.0, 0.1, 0.2, 0.3 }; TimeSeries ts1 = new TimeSeries(times, values); ts1.setLocation("location"); // public double[] getTimes(){ @@ -309,8 +307,8 @@ public static void testTimeSeriesMaskSelection() { assertTrue(ts2.equals(ts2d)); assertTrue(ts2.equals(ts2e)); - double times2[] = ts2.getTimesRef(); - double values2[] = ts2.getValuesRef(); + double[] times2 = ts2.getTimesRef(); + double[] values2 = ts2.getValuesRef(); System.out.println("times2.length =" + times2.length); System.out.println("Should be times2.length = 2"); assertEquals(2, times2.length); @@ -352,8 +350,8 @@ public static void testTimeSeriesMaskSelection() { assertTrue(ts3.equals(ts3a)); assertTrue(ts3.equals(ts3b)); - double times3[] = ts3.getTimesRef(); - double values3[] = ts3.getValuesRef(); + double[] times3 = ts3.getTimesRef(); + double[] values3 = ts3.getValuesRef(); System.out.println("times3.length =" + times3.length); System.out.println("Should be times3.length = 3"); assertEquals(3, times3.length); @@ -371,8 +369,8 @@ public static void testTimeSeriesMaskSelection() { TimeSeries ts4a = ts1.selectTimeSubset(-0.5, 2.5); assertTrue(ts4.equals(ts4a)); - double times4[] = ts4.getTimesRef(); - double values4[] = ts4.getValuesRef(); + double[] times4 = ts4.getTimesRef(); + double[] values4 = ts4.getValuesRef(); System.out.println("times4.length =" + times4.length); System.out.println("Should be times4.length = 4"); assertEquals(3, times4.length); @@ -390,26 +388,26 @@ public static void testTimeSeriesMaskSelection() { TimeSeries ts5a = ts1.selectTimeSubset(3.5, 5.5); assertTrue(ts5.equals(ts5a)); - double times5[] = ts5.getTimesRef(); - double values5[] = ts5.getValuesRef(); - assertTrue(times5 == null); - assertTrue(values5 == null); + double[] times5 = ts5.getTimesRef(); + double[] values5 = ts5.getValuesRef(); + assertNull(times5); + assertNull(values5); } - public static void testTimeSeries2() { + public void testTimeSeries2() { System.out.println("=============================================================================="); System.out.println("test TimeSeries as an implementation of IExchange"); System.out.println("=============================================================================="); // public TimeSeries(double times[], double values[]){ - double times[] = { 0.0, 1.0, 2.0, 3.0 }; - double values[] = { 0.0, 0.1, 0.2, 0.3 }; + double[] times = { 0.0, 1.0, 2.0, 3.0 }; + double[] values = { 0.0, 0.1, 0.2, 0.3 }; double x = 1.0; double y = 2.0; String source = "source"; String quantity = "quantity"; String unit = "unit"; String location = "location"; - IExchangeItem ex = new TimeSeries(times, values, x, y, source, quantity, unit, location); + TimeSeries ex = new TimeSeries(times, values, x, y, source, quantity, unit, location); // String getId(); String id = ex.getId(); @@ -418,24 +416,23 @@ public static void testTimeSeries2() { assertEquals("ex.getId()", "location.quantity", id); // String getQuantityId(); - String quantityId = ((TimeSeries) ex).getQuantityId(); + String quantityId = ex.getQuantityId(); System.out.println("ex.getQuantityId() =" + quantityId); System.out.println("Should be ex.getQuantityId() = quantity"); assertEquals("ex.getQuantityId()", "quantity", quantityId); // String getUnitId(); - String unitId = ((TimeSeries) ex).getUnitId(); + String unitId = ex.getUnitId(); System.out.println("ex.getUnitId() =" + unitId); System.out.println("Should be ex.getUnitId() = unit"); assertEquals("ex.getUnitId()", "unit", unitId); - // public Type getObjectType(); // - Type valueType = ex.getValueType(); - assertTrue(valueType == org.openda.utils.Array.class); + // public valueType getValuesType(); // + IExchangeItem.ValueType valueType = ex.getValuesType(); + assertSame(valueType, IExchangeItem.ValueType.IArrayType); // public Object times; - TimeSeries seriesRef = (TimeSeries) ex; - double[] timesRef = seriesRef.getTimesRef(); + double[] timesRef = ex.getTimesRef(); System.out.println("times[1] =" + timesRef[1]); System.out.println("Should be times[1] = 1.0"); assertEquals("times[1]", 1.0, timesRef[1], 0.0001); @@ -447,7 +444,7 @@ public static void testTimeSeries2() { assertEquals("values[1]", 0.1, valuesCopy[1], 0.0001); // public void setValues(Object values); - double newValues[] = { 2.0, 2.1, 2.2, 2.3 }; + double[] newValues = { 2.0, 2.1, 2.2, 2.3 }; ex.setValuesAsDoubles(newValues); double[] valuesCopy2 = ex.getValuesAsDoubles(); System.out.println("values[1] =" + valuesCopy2[1]); @@ -470,18 +467,18 @@ public static void testTimeSeries2() { } - public static void testTimeSeriesSelection_2() { + public void testTimeSeriesSelection_2() { System.out.println("=============================================================================="); System.out.println("test time selection on TimeSeries"); System.out.println("=============================================================================="); double delta = 0.01; // public TimeSeries(double times[], double values[]){ - double times[] = { 0.0, 1.0, 2.0, 3.0, 4.0 }; - double values[] = { 0.0, 0.1, 0.2, 0.3, 0.4 }; + double[] times = { 0.0, 1.0, 2.0, 3.0, 4.0 }; + double[] values = { 0.0, 0.1, 0.2, 0.3, 0.4 }; TimeSeries ts1 = new TimeSeries(times, values); ts1.setLocation("location"); - double times2[] = { 1.0, 1.999, 2.001, 3.0, 7.0 }; + double[] times2 = { 1.0, 1.999, 2.001, 3.0, 7.0 }; // 1.999,2.001 are within tolerance and 7.0 does not exist // now get selection double[] values2 = ts1.getValuesAsDoubles(times2, delta, 999.00); @@ -490,30 +487,30 @@ public static void testTimeSeriesSelection_2() { assertEquals("values2", "[0.1, 0.2, 0.2, 0.3, 999.0]", Arrays.toString(values2)); } - public static void testTimeSeriesSelection_3() { - double times[] = { 0.0, 1.0, 2.0, 3.0, 4.0 }; - double values[] = { 0.0, 0.1, 0.2, 0.3, 0.4 }; + public void testTimeSeriesSelection_3() { + double[] times = { 0.0, 1.0, 2.0, 3.0, 4.0 }; + double[] values = { 0.0, 0.1, 0.2, 0.3, 0.4 }; TimeSeries ts1 = new TimeSeries(times, values); - double times2[] = { 1.0, 1.999, 2.001, 3.0, 7.0 }; + double[] times2 = { 1.0, 1.999, 2.001, 3.0, 7.0 }; TimeSeries ts2 = ts1.selectTimeSubset(times2); assertEquals(2, ts2.getSize()); assertEquals(1.0, ts2.getTimesRef()[0], 0.01); assertEquals(3.0, ts2.getTimesRef()[1], 0.01); assertEquals(0.1, ts2.getValuesRef()[0], 0.01); assertEquals(0.3, ts2.getValuesRef()[1], 0.01); - double times3[] = { -1.0, 1.999, 2.001, 7.0, 7.0 }; + double[] times3 = { -1.0, 1.999, 2.001, 7.0, 7.0 }; TimeSeries ts3 = ts1.selectTimeSubset(times3); assertEquals(0, ts3.getSize()); } - public static void testTimeSeriesId() { + public void testTimeSeriesId() { System.out.println("=============================================================================="); System.out.println("test default and overrule for id"); System.out.println("=============================================================================="); // public TimeSeries(double times[], double values[]){ - double times[] = { 0.0, 1.0, 2.0, 3.0, 4.0 }; - double values[] = { 0.0, 0.1, 0.2, 0.3, 0.4 }; + double[] times = { 0.0, 1.0, 2.0, 3.0, 4.0 }; + double[] values = { 0.0, 0.1, 0.2, 0.3, 0.4 }; TimeSeries ts1 = new TimeSeries(times, values); ts1.setLocation("valve1"); ts1.setQuantity("pressure"); @@ -525,14 +522,14 @@ public static void testTimeSeriesId() { assertEquals("default id", "pressure@valve1", id); } - public static void testTimeSeriesValueSelection() { + public void testTimeSeriesValueSelection() { System.out.println("=============================================================================="); System.out.println("test excluding values outside the range"); System.out.println("=============================================================================="); // public TimeSeries(double times[], double values[]){ - double times[] = { 0.0, 1.0, 2.0, 3.0, 4.0 }; - double values[] = { 0.0, 0.1, 0.2, 0.3, 0.4 }; + double[] times = { 0.0, 1.0, 2.0, 3.0, 4.0 }; + double[] values = { 0.0, 0.1, 0.2, 0.3, 0.4 }; TimeSeries ts1 = new TimeSeries(times, values); ts1.setLocation("valve1"); ts1.setQuantity("pressure"); @@ -556,29 +553,29 @@ public static void testTimeSeriesValueSelection() { assertEquals("values4", "[0.1, 0.2, 0.3, 0.4]", Arrays.toString(values4)); } - public static void testTimeSeriesToString() { + public void testTimeSeriesToString() { System.out.println("=============================================================================="); System.out.println("test TimeSeries.toString"); System.out.println("=============================================================================="); // public TimeSeries(double times[], double values[]){ - double times1[] = { 0.0, 1.0, 2.0, 3.0 }; - double values1[] = { 0.0, 0.1, 0.2, 0.3 }; + double[] times1 = { 0.0, 1.0, 2.0, 3.0 }; + double[] values1 = { 0.0, 0.1, 0.2, 0.3 }; TimeSeries ts1 = new TimeSeries(times1, values1); String ts1String = ts1.toString(); assertEquals(-297300475, ts1String.hashCode()); // public TimeSeries(double times[], double values[]){ - double times2[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 }; - double values2[] = { 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7 }; + double[] times2 = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 }; + double[] values2 = { 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7 }; TimeSeries ts2 = new TimeSeries(times2, values2); String ts2String = ts2.toString(); System.out.println("ts2=" + ts2String); assertEquals(-925868425, ts2String.hashCode()); // public TimeSeries(double times[], double values[]){ - double times3[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0 }; - double values3[] = { 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3 }; + double[] times3 = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0 }; + double[] values3 = { 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3 }; TimeSeries ts3 = new TimeSeries(times3, values3); String ts3String = ts3.toString(); System.out.println("ts3=" + ts3String); diff --git a/core/java/test/org/openda/noiseModels/Maps2dNoiseModelTest.java b/core/java/test/org/openda/noiseModels/Maps2dNoiseModelTest.java index f8644923f..c9304b9b9 100644 --- a/core/java/test/org/openda/noiseModels/Maps2dNoiseModelTest.java +++ b/core/java/test/org/openda/noiseModels/Maps2dNoiseModelTest.java @@ -478,7 +478,7 @@ public void testMaps2dNoiseSeparableRecompute(){ assertEquals(2, ids.length); System.out.println("ids[0]="+ids[0]); assertEquals("waterlevel@aberdeen", ids[0]); - IPrevExchangeItem series1=model.getExchangeItem("waterlevel@aberdeen"); + IExchangeItem series1=model.getExchangeItem("waterlevel@aberdeen"); assertTrue(series1 instanceof TimeSeries); System.out.println("location1.quantity1 =>"+series1.toString()); double[] times=series1.getTimes(); diff --git a/core/java/test/org/openda/noiseModels/TimeSeriesNoiseModelTest.java b/core/java/test/org/openda/noiseModels/TimeSeriesNoiseModelTest.java index 9152b9f0b..a3ad5a082 100644 --- a/core/java/test/org/openda/noiseModels/TimeSeriesNoiseModelTest.java +++ b/core/java/test/org/openda/noiseModels/TimeSeriesNoiseModelTest.java @@ -66,7 +66,7 @@ public void testNoiseForTimeSeries_basics(){ assertEquals(3, ids.length); System.out.println("ids[0]="+ids[0]); assertEquals("location1.quantity1", ids[0]); - IPrevExchangeItem series1=model.getExchangeItem("location1.quantity1"); + IExchangeItem series1=model.getExchangeItem("location1.quantity1"); assertTrue(series1 instanceof TimeSeries); System.out.println("location1.quantity1 =>"+series1.toString()); double[] times=series1.getTimes(); @@ -79,7 +79,7 @@ public void testNoiseForTimeSeries_basics(){ valueVector1.maxFullExpandLength=1000; System.out.println("values1="+valueVector1.toString()); //series 2 - IPrevExchangeItem series2=model.getExchangeItem("location2.quantity2"); + IExchangeItem series2=model.getExchangeItem("location2.quantity2"); assertTrue(series2 instanceof TimeSeries); System.out.println("location2.quantity2 =>"+series2.toString()); double[] values2=series2.getValuesAsDoubles(); @@ -90,7 +90,7 @@ public void testNoiseForTimeSeries_basics(){ System.out.println("values2="+valueVector2.toString()); //series 3 - IPrevExchangeItem series3=model.getExchangeItem("location3.quantity3"); + IExchangeItem series3=model.getExchangeItem("location3.quantity3"); assertTrue(series3 instanceof TimeSeries); System.out.println("location3.quantity3 =>"+series3.toString()); double[] values3=series3.getValuesAsDoubles(); @@ -118,7 +118,7 @@ public void testNoiseForTimeSeries_initialValue(){ model.compute(new Time((double)endTimeInDays)); String noiseModelExchItemId=model.getExchangeItemIDs()[0]; - IPrevExchangeItem series1=model.getExchangeItem(noiseModelExchItemId); + IExchangeItem series1=model.getExchangeItem(noiseModelExchItemId); double[] times=series1.getTimes(); double[] values=series1.getValuesAsDoubles(); File file = new File(testRunDataDir, "noise_with_initial_values.csv"); @@ -172,7 +172,7 @@ public void testNoiseForTimeSeries_config(){ assertEquals(2, ids.length); System.out.println("ids[0]="+ids[0]); assertEquals("waterlevel@aberdeen", ids[0]); - IPrevExchangeItem series1=model.getExchangeItem("waterlevel@aberdeen"); + IExchangeItem series1=model.getExchangeItem("waterlevel@aberdeen"); assertTrue(series1 instanceof TimeSeries); System.out.println("location1.quantity1 =>"+series1.toString()); double[] times=series1.getTimes(); @@ -261,7 +261,7 @@ public void testNoiseFixedVersusRandom(){ modelWithFixedSeed.setAutomaticNoiseGeneration(true); ITime targetTime = modelWithFixedSeed.getTimeHorizon().getEndTime(); modelWithFixedSeed.compute(targetTime); - IPrevExchangeItem seriesWithFixedSeed=modelWithFixedSeed.getExchangeItem("waterlevel@aberdeen"); + IExchangeItem seriesWithFixedSeed=modelWithFixedSeed.getExchangeItem("waterlevel@aberdeen"); resultsFixedSeed[i]=seriesWithFixedSeed.getValuesAsDoubles(); StochVector.setInitialSeedType(StochVector.InitialSeedType.random); @@ -270,7 +270,7 @@ public void testNoiseFixedVersusRandom(){ modelWithRandomSeed = factoryWithRandomSeed.getInstance(OutputLevel.Debug); modelWithRandomSeed.setAutomaticNoiseGeneration(true); modelWithRandomSeed.compute(targetTime); - IPrevExchangeItem seriesWithRandomSeed=modelWithRandomSeed.getExchangeItem("waterlevel@aberdeen"); + IExchangeItem seriesWithRandomSeed=modelWithRandomSeed.getExchangeItem("waterlevel@aberdeen"); resultsRandomSeed[i]=seriesWithRandomSeed.getValuesAsDoubles(); } diff --git a/core/java/test/org/openda/utils/ProposedTreeVectorTest.java b/core/java/test/org/openda/utils/ProposedTreeVectorTest.java index 054b0bbc0..12628d12a 100644 --- a/core/java/test/org/openda/utils/ProposedTreeVectorTest.java +++ b/core/java/test/org/openda/utils/ProposedTreeVectorTest.java @@ -28,7 +28,7 @@ import org.openda.interfaces.IArray; import org.openda.interfaces.IArrayExchangeItem; import org.openda.interfaces.IQuantityInfo; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; import org.openda.interfaces.IArrayTimeInfo; import org.openda.interfaces.ProposedITreeVector; import org.openda.utils.ProposedTreeVector; diff --git a/core/java/test/org/openda/utils/ReflectionTest.java b/core/java/test/org/openda/utils/ReflectionTest.java index fad6cce23..b5ca5d089 100644 --- a/core/java/test/org/openda/utils/ReflectionTest.java +++ b/core/java/test/org/openda/utils/ReflectionTest.java @@ -54,13 +54,13 @@ public void testClasses(){ } // get classes that implement a certain interface - String ifaceName = ref.findFullName("IoObjectInterface"); - assertEquals("org.openda.blackbox.interfaces.IoObjectInterface", ifaceName); + String ifaceName = ref.findFullName("IDataObject"); + assertEquals("org.openda.interfaces.IDataObject", ifaceName); Set selection = ref.getClassNames(ifaceName); - System.out.println("There are "+selection.size()+" classes that implement the IoObjectInterface"); + System.out.println("There are "+selection.size()+" classes that implement the IDataObject"); assertTrue(selection.size()>4); //some classes were found counter=0; - System.out.println("classes that implement the IoObjectInterface:"); + System.out.println("classes that implement the IDataObject:"); for(String classname : selection){ System.out.println(" "+counter+" class name:"+classname); counter++; @@ -72,7 +72,7 @@ public void testImplementsInterface() throws ClassNotFoundException { System.out.println(" Basic test for relation between classes that implement an interface"); System.out.println("=============================================================================="); Class aClass = Class.forName("org.openda.exchange.ioobjects.NoosTimeSeriesIoObject"); - Class interfaces[] = aClass.getInterfaces(); + Class[] interfaces = aClass.getInterfaces(); boolean found=false; for(Class iface : interfaces){ String iName = iface.getCanonicalName(); @@ -81,7 +81,7 @@ public void testImplementsInterface() throws ClassNotFoundException { found=true; } } - assertEquals(true, found); + assertTrue(found); } public void testInfoMain(){ diff --git a/core/native/src/openda/org/costa/CtaObservationDescriptions.java b/core/native/src/openda/org/costa/CtaObservationDescriptions.java index 92cc2fb51..a1c6fe4ca 100644 --- a/core/native/src/openda/org/costa/CtaObservationDescriptions.java +++ b/core/native/src/openda/org/costa/CtaObservationDescriptions.java @@ -34,7 +34,7 @@ private CtaObservationDescriptions(int ctaHandle) { this.ctaHandle = ctaHandle; } - public List getExchangeItems() { + public List getExchangeItems() { throw new UnsupportedOperationException("org.costa.CtaObservationDescriptions.getExchangeItems(): Not implemented yet."); } diff --git a/core/native/src/openda/org/costa/CtaOpenDaModel.java b/core/native/src/openda/org/costa/CtaOpenDaModel.java index 60a669664..54289df02 100644 --- a/core/native/src/openda/org/costa/CtaOpenDaModel.java +++ b/core/native/src/openda/org/costa/CtaOpenDaModel.java @@ -99,14 +99,14 @@ public String[] getExchangeItemIDs() { throw new UnsupportedOperationException("org.costa.CtaOpenDaModel.getExchangeItemIDs(): Not implemented yet."); } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { - if (role == IPrevExchangeItem.Role.InOut) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { + if (role == IExchangeItem.Role.InOut) { return getExchangeItemIDs(); } throw new UnsupportedOperationException("org.costa.CtaOpenDaModel.getExchangeItemIDs(): Role selection not implemented yet."); } - public IPrevExchangeItem getExchangeItem(String exchangeItemID) { + public IExchangeItem getExchangeItem(String exchangeItemID) { throw new UnsupportedOperationException("org.costa.CtaOpenDaModel.getExchangeItem(): Not implemented yet."); } diff --git a/core/xmlSchemas/blackBoxModelConfig.xsd b/core/xmlSchemas/blackBoxModelConfig.xsd index 258e32339..d02e1d76a 100644 --- a/core/xmlSchemas/blackBoxModelConfig.xsd +++ b/core/xmlSchemas/blackBoxModelConfig.xsd @@ -114,11 +114,16 @@ Identity of the exchange item vector to be used in the stochastic model configuration. Note: by using the reserved id "allElementsFromIoObject" all the elements in the data/io object are exposed as exchange items (with the element id in the data/io object as id) - + - The corresponding object identity of the exchange item + Obsolete, please use dataObjectId. The corresponding object identity of the exchange item + + + The corresponding object identity of the exchange item + + The corresponding identity of the exchange item as used internally within the model. If this is not specified, then the elementId will be equal to the specified id. @@ -156,11 +161,16 @@ Identity of the exchange item vector to be used in the stochastic model configuration - + - The corresponding object identity of the exchange item + Obsolete, please use dataObjectId. The corresponding object identity of the exchange item + + + The corresponding object identity of the exchange item + + The corresponding identity of the exchange item as used internally within the model diff --git a/core/xmlSchemas/blackBoxWrapperConfig.xsd b/core/xmlSchemas/blackBoxWrapperConfig.xsd index 4976fc68a..de1a82627 100644 --- a/core/xmlSchemas/blackBoxWrapperConfig.xsd +++ b/core/xmlSchemas/blackBoxWrapperConfig.xsd @@ -1,4 +1,5 @@ + @@ -179,7 +180,7 @@ - + @@ -199,18 +200,23 @@ - The openda:class name of the input/output object + The openda:class name of the input/output data object - - + + - Specify the input/output object + element ioObject is obsolete, please use dataObject - + + + Specify the input/output data object + + + diff --git a/core/xmlSchemas/examples/stochObservers/swanStochObsConfig.xml b/core/xmlSchemas/examples/stochObservers/swanStochObsConfig.xml index 4e354be70..139f57179 100644 --- a/core/xmlSchemas/examples/stochObservers/swanStochObsConfig.xml +++ b/core/xmlSchemas/examples/stochObservers/swanStochObsConfig.xml @@ -1,9 +1,9 @@ - + stochObsUncertainties.xml - + meas_l21triad_loc.tab - - + + diff --git a/core/xmlSchemas/examples/wrappers/d3dBbWrapperConfig.xml b/core/xmlSchemas/examples/wrappers/d3dBbWrapperConfig.xml index 5afc60ed8..33f363e22 100644 --- a/core/xmlSchemas/examples/wrappers/d3dBbWrapperConfig.xml +++ b/core/xmlSchemas/examples/wrappers/d3dBbWrapperConfig.xml @@ -30,25 +30,25 @@ - + %runid%.mdf roughness rgh - + - + %runid%.mdf depth dep - + - + trih-%runid%.dat trih-file %NATIVE_DLL_DIR% - + diff --git a/course/exercise_black_box_calibration_polution_NOT_WORKING/reactive_advection_wrapper/java/src/org/openda/mywrapper/myCopier.java b/course/exercise_black_box_calibration_polution_NOT_WORKING/reactive_advection_wrapper/java/src/org/openda/mywrapper/myCopier.java index 1b358a899..8bec73986 100644 --- a/course/exercise_black_box_calibration_polution_NOT_WORKING/reactive_advection_wrapper/java/src/org/openda/mywrapper/myCopier.java +++ b/course/exercise_black_box_calibration_polution_NOT_WORKING/reactive_advection_wrapper/java/src/org/openda/mywrapper/myCopier.java @@ -20,7 +20,6 @@ package org.openda.mywrapper; import java.io.File; import org.openda.blackbox.interfaces.IoObjectInterface; -import org.openda.interfaces.IPrevExchangeItem; /** * Copy values for 'c' concentration on grid from one file to another. @@ -55,9 +54,9 @@ public static void main(String args[]){ IoObjectInterface output = new myWrapper(); String ioArgs[] = {}; output.initialize(outputFile.getParentFile(), outputFile.getName(), ioArgs); - IPrevExchangeItem outputItem1=null; - IPrevExchangeItem outputItem2=null; - for(IPrevExchangeItem item:output.getExchangeItems()){ + IExchangeItem outputItem1=null; + IExchangeItem outputItem2=null; + for(IExchangeItem item:output.getExchangeItems()){ String itemId = item.getId(); System.out.println("looking at item: "+itemId); if(itemId.equalsIgnoreCase("concentration1.grid")){ @@ -70,7 +69,7 @@ public static void main(String args[]){ IoObjectInterface input = new myWrapper(); input.initialize(inputFile.getParentFile(), inputFile.getName(), ioArgs); - for(IPrevExchangeItem item:input.getExchangeItems()){ + for(IExchangeItem item:input.getExchangeItems()){ String itemId = item.getId(); System.out.println("looking at item: "+itemId); if(itemId.equalsIgnoreCase("concentration1.grid")){ diff --git a/course/exercise_black_box_calibration_polution_NOT_WORKING/reactive_advection_wrapper/java/src/org/openda/mywrapper/myWrapper.java b/course/exercise_black_box_calibration_polution_NOT_WORKING/reactive_advection_wrapper/java/src/org/openda/mywrapper/myWrapper.java index f4c85165a..67bcf2ab3 100644 --- a/course/exercise_black_box_calibration_polution_NOT_WORKING/reactive_advection_wrapper/java/src/org/openda/mywrapper/myWrapper.java +++ b/course/exercise_black_box_calibration_polution_NOT_WORKING/reactive_advection_wrapper/java/src/org/openda/mywrapper/myWrapper.java @@ -94,7 +94,7 @@ public class myWrapper implements IoObjectInterface{ File workingDir; String fileName = null; HashMap variables = new LinkedHashMap(); - HashMap items = new LinkedHashMap(); + HashMap items = new LinkedHashMap(); //cache these values double refdate; @@ -191,15 +191,15 @@ public void initialize(File workingDir, String fileName, String[] arguments) { tstop=time[2]*unit; //add exchange items for time - IPrevExchangeItem startTime = new DoubleExchangeItem("startTime", this.refdate+this.tstart); + IExchangeItem startTime = new DoubleExchangeItem("startTime", this.refdate+this.tstart); this.items.put("startTime",startTime); - IPrevExchangeItem endTime = new DoubleExchangeItem("endTime", this.refdate+this.tstop); + IExchangeItem endTime = new DoubleExchangeItem("endTime", this.refdate+this.tstop); this.items.put("endTime",endTime); //add reaction_time if(variables.containsKey("reaction_time")){ double reactionTimevalues[] = parseVector(variables.get("reaction_time")); - IPrevExchangeItem reactionTime = new DoubleExchangeItem("reactionTime", reactionTimevalues[0]); + IExchangeItem reactionTime = new DoubleExchangeItem("reactionTime", reactionTimevalues[0]); this.items.put("reactionTime",reactionTime); } @@ -333,11 +333,11 @@ public void initialize(File workingDir, String fileName, String[] arguments) { } } - public IPrevExchangeItem[] getExchangeItems() { + public IExchangeItem[] getExchangeItems() { //TODO for now return some dummy timeSeries int n = this.items.size(); Set keys = this.items.keySet(); - IPrevExchangeItem[] result=new IPrevExchangeItem[n]; + IExchangeItem[] result=new IExchangeItem[n]; int i=0; for(String key : keys){ result[i]=this.items.get(key); @@ -456,7 +456,7 @@ public void finish() { if(!this.items.containsKey(id)){ throw new RuntimeException("ExchangeItem with id ="+id+" got lost."); } - IPrevExchangeItem item = this.items.get(id); + IExchangeItem item = this.items.get(id); String key="c1"; double values[] = item.getValuesAsDoubles(); String valueString = writeVector(values); @@ -467,7 +467,7 @@ public void finish() { if(!this.items.containsKey(id)){ throw new RuntimeException("ExchangeItem with id ="+id+" got lost."); } - IPrevExchangeItem item = this.items.get(id); + IExchangeItem item = this.items.get(id); String key="c2"; double values[] = item.getValuesAsDoubles(); String valueString = writeVector(values); diff --git a/course/exercise_black_box_calibration_polution_NOT_WORKING/reactive_advection_wrapper/java/test/org/openda/mywrapper/myWrapperTest.java b/course/exercise_black_box_calibration_polution_NOT_WORKING/reactive_advection_wrapper/java/test/org/openda/mywrapper/myWrapperTest.java index 1c0583531..b727f30d1 100644 --- a/course/exercise_black_box_calibration_polution_NOT_WORKING/reactive_advection_wrapper/java/test/org/openda/mywrapper/myWrapperTest.java +++ b/course/exercise_black_box_calibration_polution_NOT_WORKING/reactive_advection_wrapper/java/test/org/openda/mywrapper/myWrapperTest.java @@ -25,7 +25,6 @@ import org.openda.exchange.timeseries.NoosTimeSeriesFormatter; import org.openda.exchange.timeseries.TimeSeries; import org.openda.exchange.timeseries.TimeSeriesFormatter; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.OpenDaTestSupport; import java.io.File; import java.io.IOException; @@ -48,12 +47,12 @@ public void testReadInput() { String args[] = {}; ioObject.initialize(testRunDataDir, "reactive_pollution_model.input", args); - IPrevExchangeItem[] exchangeItems = ioObject.getExchangeItems(); + IExchangeItem[] exchangeItems = ioObject.getExchangeItems(); for(int item=0;item - - + + %inputFile% input - + - + %inputFileReactionTime% input_reaction_time - + - + %inputFileSimulationTime% input_simulation_time as_separate_exchange_items - + - + %inputFileC1% input_c1 - + - + %inputFileC2% input_c2 - + - - + + %outputFile% output - + diff --git a/course/exercise_black_box_enkf_polution/stochModel/polluteWrapper.xml b/course/exercise_black_box_enkf_polution/stochModel/polluteWrapper.xml index 365654e68..d48b06a08 100644 --- a/course/exercise_black_box_enkf_polution/stochModel/polluteWrapper.xml +++ b/course/exercise_black_box_enkf_polution/stochModel/polluteWrapper.xml @@ -56,36 +56,36 @@ - + --> - + %configFile% configuration - + - + %inputFileC1% state_concentration1 - + - + %inputFileC2% state_concentration2 - + - + timeSeriesFormatter.xml output - + - + forcingsSeriesFormatter.xml forcings - + diff --git a/course/exercise_oct24/stochModel/polluteWrapper.xml b/course/exercise_oct24/stochModel/polluteWrapper.xml index 0f9e10535..e8f4e327e 100644 --- a/course/exercise_oct24/stochModel/polluteWrapper.xml +++ b/course/exercise_oct24/stochModel/polluteWrapper.xml @@ -1,7 +1,7 @@ + xsi:schemaLocation="http://www.openda.org http://schemas.openda.org/blackBoxWrapperConfig.xsd"> @@ -45,16 +45,16 @@ - + %inputFile% input - + - + %outputFile% output - + diff --git a/course/exercise_oct24/stochModel/polluteWrapper1.xml b/course/exercise_oct24/stochModel/polluteWrapper1.xml index 8c9137214..bf600c4f1 100644 --- a/course/exercise_oct24/stochModel/polluteWrapper1.xml +++ b/course/exercise_oct24/stochModel/polluteWrapper1.xml @@ -1,7 +1,8 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.openda.org + http://schemas.openda.org/blackBoxWrapperConfig.xsd"> @@ -46,23 +47,23 @@ - + %templateFile% template starttime reaction_time - + - + %inputFile% input - + - + %outputFile% output - + diff --git a/course/exercise_oct24/stochModel/polluteWrapper2.xml b/course/exercise_oct24/stochModel/polluteWrapper2.xml index 7c05c51b0..ee58bc814 100644 --- a/course/exercise_oct24/stochModel/polluteWrapper2.xml +++ b/course/exercise_oct24/stochModel/polluteWrapper2.xml @@ -1,7 +1,7 @@ + xsi:schemaLocation="http://www.openda.org http://schemas.openda.org/blackBoxWrapperConfig.xsd"> @@ -55,17 +55,6 @@ - - %inputFile% - input - - - - - %outputFile% - output - - %noosFilec1A% c1_locA @@ -91,6 +80,17 @@ c2_locC + + %inputFile% + input + + + + + %outputFile% + output + + diff --git a/course/exercise_oct24/stochModel/polluteWrapper3.xml b/course/exercise_oct24/stochModel/polluteWrapper3.xml index 8620d5397..dc77594cd 100644 --- a/course/exercise_oct24/stochModel/polluteWrapper3.xml +++ b/course/exercise_oct24/stochModel/polluteWrapper3.xml @@ -1,7 +1,7 @@ + xsi:schemaLocation="http://www.openda.org http://schemas.openda.org/blackBoxWrapperConfig.xsd"> @@ -60,12 +60,6 @@ - - %inputFile% - input - - - %noosFilec1A% c1_locA @@ -91,15 +85,22 @@ c2_locC - - %xmlFilec1% - grid_c1 - + + %inputFile% + input + + + + + + %xmlFilec1% + grid_c1 + - - %xmlFilec2% - grid_c2 - + + %xmlFilec2% + grid_c2 + diff --git a/dotnet_bridge/dotnet/src/OpenDA.DotNet.SDK/UtilsJ2NAndN2J.cs b/dotnet_bridge/dotnet/src/OpenDA.DotNet.SDK/UtilsJ2NAndN2J.cs index 25136a617..49870222b 100644 --- a/dotnet_bridge/dotnet/src/OpenDA.DotNet.SDK/UtilsJ2NAndN2J.cs +++ b/dotnet_bridge/dotnet/src/OpenDA.DotNet.SDK/UtilsJ2NAndN2J.cs @@ -44,16 +44,16 @@ public static int CompareTimeSpans(double timeStamp1Begin, double timeSpan1End, throw new NotImplementedException(); } - public static org.openda.interfaces.IPrevExchangeItem.Role RoleMapN2J(int role) + public static org.openda.interfaces.IExchangeItem.Role RoleMapN2J(int role) { switch (role) { case 0: - return org.openda.interfaces.IPrevExchangeItem.Role.Input; + return org.openda.interfaces.IExchangeItem.Role.Input; case 1: - return org.openda.interfaces.IPrevExchangeItem.Role.Output; + return org.openda.interfaces.IExchangeItem.Role.Output; case 2: - return org.openda.interfaces.IPrevExchangeItem.Role.InOut; + return org.openda.interfaces.IExchangeItem.Role.InOut; } throw new Exception("Unknown IExchangeItem.Role value: " + role); } @@ -86,7 +86,7 @@ public static Type ValueTypeMapJ2N(Class valueType) throw new Exception("Unknown value type " + valueTypeString); } - public static Role RoleMapJ2N(org.openda.interfaces.IPrevExchangeItem.Role role) + public static Role RoleMapJ2N(org.openda.interfaces.IExchangeItem.Role role) { string roleString = role.toString(); if (roleString.ToLower().Equals("input")) diff --git a/dotnet_bridge/java/dotnet_bridge.iml b/dotnet_bridge/java/dotnet_bridge.iml index 2c7ef2b2f..03b35409c 100644 --- a/dotnet_bridge/java/dotnet_bridge.iml +++ b/dotnet_bridge/java/dotnet_bridge.iml @@ -38,14 +38,6 @@
- - - - - - - - - + \ No newline at end of file diff --git a/dotnet_bridge/java/src/org/openda/dotnet/ExchangeItemN2J.java b/dotnet_bridge/java/src/org/openda/dotnet/ExchangeItemN2J.java index a413e7fad..33049b7be 100644 --- a/dotnet_bridge/java/src/org/openda/dotnet/ExchangeItemN2J.java +++ b/dotnet_bridge/java/src/org/openda/dotnet/ExchangeItemN2J.java @@ -21,12 +21,15 @@ package org.openda.dotnet; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; +import org.openda.interfaces.IGeometryInfo; +import org.openda.interfaces.IQuantityInfo; +import org.openda.interfaces.ITimeInfo; /** * Java wrapper around .net class for an Exchange Item */ -public class ExchangeItemN2J implements IPrevExchangeItem { +public class ExchangeItemN2J implements IExchangeItem { private cli.OpenDA.DotNet.Interfaces.IExchangeItem dotNotExchangeItem; @@ -42,16 +45,21 @@ public String getDescription() { return dotNotExchangeItem.get_Description(); } + public IQuantityInfo getQuantityInfo() { throw new UnsupportedOperationException("org.openda.dotnet.ExchangeItemN2J.getQuantityInfo(): Not implemented yet."); } + + public IGeometryInfo getGeometryInfo() { throw new UnsupportedOperationException("org.openda.dotnet.ExchangeItemN2J.getGeometryInfo(): Not implemented yet."); } + public Class getValueType() { // for now, just always return an array of doubles, no matter wat the dotnet object's value type is return double[].class; } - public Role getRole() { - // for now, just always return in/out - return Role.InOut; + public ValueType getValuesType() { + return ValueType.doublesType; } + public Role getRole() { return Role.InOut; } + public Object getValues() { // for now, just always return an array of doubles, no matter wat the dotnet object's value type is return dotNotExchangeItem.get_ValuesAsDoubles(); @@ -61,6 +69,14 @@ public double[] getValuesAsDoubles() { return dotNotExchangeItem.get_ValuesAsDoubles(); } + public void copyValuesFromItem(IExchangeItem sourceItem) { + ValueType sourceType=sourceItem.getValuesType(); + if(sourceType != ValueType.doublesType){ + throw new RuntimeException("DummyAstroDataObject.DummyExchangeItem.setValues(): unknown type: " + sourceType ); + } + this.setValues(sourceItem.getValues()); + } + public void axpyOnValues(double alpha, double[] axpyValues) { dotNotExchangeItem.AxpyOnValues(alpha, axpyValues); } @@ -77,6 +93,8 @@ public void setValuesAsDoubles(double[] values) { dotNotExchangeItem.set_ValuesAsDoubles(values); } + public ITimeInfo getTimeInfo() { throw new UnsupportedOperationException("org.openda.dotnet.ExchangeItemN2J.getTimeInfo(): Not implemented yet."); } + public double[] getTimes() { return dotNotExchangeItem.get_Times(); } diff --git a/dotnet_bridge/java/src/org/openda/dotnet/ModelInstanceN2J.java b/dotnet_bridge/java/src/org/openda/dotnet/ModelInstanceN2J.java index b01c2e74d..53ddd939e 100644 --- a/dotnet_bridge/java/src/org/openda/dotnet/ModelInstanceN2J.java +++ b/dotnet_bridge/java/src/org/openda/dotnet/ModelInstanceN2J.java @@ -80,7 +80,7 @@ public IVector[] getObservedLocalization(String exchageItemID, IObservationDescr } /* - List javaExchangeItems = observationDescriptions.getExchangeItems(); + List javaExchangeItems = observationDescriptions.getExchangeItems(); String [] keys =observationDescriptions.getPropertyKeys(); int nKeys=observationDescriptions.getPropertyCount(); int nObs =observationDescriptions.getObservationCount(); @@ -89,7 +89,7 @@ public IVector[] getObservedLocalization(String exchageItemID, IObservationDescr cli.OpenDA.DotNet.Interfaces.IExchangeItem[] dotnetExchangeItems = new cli.OpenDA.DotNet.Interfaces.IExchangeItem[javaExchangeItems.size()]; for (int i = 0; i < javaExchangeItems.size(); i++) { - IPrevExchangeItem javaExchangeItem = javaExchangeItems.get(i); + IExchangeItem javaExchangeItem = javaExchangeItems.get(i); cli.OpenDA.DotNet.Interfaces.IExchangeItem dotnetExchangeItem = new DoublesExchangeItem(javaExchangeItem.getId(), javaExchangeItem.getDescription(), @@ -142,11 +142,11 @@ public IVector[] getObservedLocalization(IObservationDescriptions observationDes /* - List javaExchangeItems = observationDescriptions.getExchangeItems(); + List javaExchangeItems = observationDescriptions.getExchangeItems(); cli.OpenDA.DotNet.Interfaces.IExchangeItem[] dotnetExchangeItems = new cli.OpenDA.DotNet.Interfaces.IExchangeItem[javaExchangeItems.size()]; for (int i = 0; i < javaExchangeItems.size(); i++) { - IPrevExchangeItem javaExchangeItem = javaExchangeItems.get(i); + IExchangeItem javaExchangeItem = javaExchangeItems.get(i); cli.OpenDA.DotNet.Interfaces.IExchangeItem dotnetExchangeItem = new DoublesExchangeItem(javaExchangeItem.getId(), javaExchangeItem.getDescription(), @@ -189,7 +189,7 @@ public IVector getObservedValues(IObservationDescriptions observationDescription dotNetObservationDescriptions = translateObservationDesciptions(observationDescriptions); } /* - List javaExchangeItems = observationDescriptions.getExchangeItems(); + List javaExchangeItems = observationDescriptions.getExchangeItems(); String [] keys =observationDescriptions.getPropertyKeys(); int nKeys=observationDescriptions.getPropertyCount(); int nObs =observationDescriptions.getObservationCount(); @@ -198,7 +198,7 @@ public IVector getObservedValues(IObservationDescriptions observationDescription cli.OpenDA.DotNet.Interfaces.IExchangeItem[] dotnetExchangeItems = new cli.OpenDA.DotNet.Interfaces.IExchangeItem[javaExchangeItems.size()]; for (int i = 0; i < javaExchangeItems.size(); i++) { - IPrevExchangeItem javaExchangeItem = javaExchangeItems.get(i); + IExchangeItem javaExchangeItem = javaExchangeItems.get(i); cli.OpenDA.DotNet.Interfaces.IExchangeItem dotnetExchangeItem = new DoublesExchangeItem(javaExchangeItem.getId(), javaExchangeItem.getDescription(), @@ -237,7 +237,7 @@ public String[] getExchangeItemIDs() return _dotNetModelInstance.get_ExchangeItemIDs(); } - public String[] getExchangeItemIDs(org.openda.interfaces.IPrevExchangeItem.Role role) + public String[] getExchangeItemIDs(org.openda.interfaces.IExchangeItem.Role role) { return _dotNetModelInstance.GetExchangeItemIDs(role.ordinal()); } @@ -246,7 +246,7 @@ public IExchangeItem getDataObjectExchangeItem(String exchangeItemID) { throw new UnsupportedOperationException("org.openda.dotnet.ModelInstanceN2J.getDataObjectExchangeItem(): Not implemented yet."); } - public IPrevExchangeItem getExchangeItem(String str) + public IExchangeItem getExchangeItem(String str) { return new ExchangeItemN2J(_dotNetModelInstance.GetExchangeItem(str)); } @@ -311,7 +311,7 @@ private cli.OpenDA.DotNet.Interfaces.IObservationDescriptions translateObservati cli.OpenDA.DotNet.Interfaces.IObservationDescriptions dotNetObservationDescriptions = null; - List javaExchangeItems = observationDescriptions.getExchangeItems(); + List javaExchangeItems = observationDescriptions.getExchangeItems(); String [] keys =observationDescriptions.getPropertyKeys(); int nKeys=observationDescriptions.getPropertyCount(); int nObs =observationDescriptions.getObservationCount(); @@ -320,7 +320,7 @@ private cli.OpenDA.DotNet.Interfaces.IObservationDescriptions translateObservati cli.OpenDA.DotNet.Interfaces.IExchangeItem[] dotnetExchangeItems = new cli.OpenDA.DotNet.Interfaces.IExchangeItem[javaExchangeItems.size()]; for (int i = 0; i < javaExchangeItems.size(); i++) { - IPrevExchangeItem javaExchangeItem = javaExchangeItems.get(i); + IExchangeItem javaExchangeItem = javaExchangeItems.get(i); cli.OpenDA.DotNet.Interfaces.IExchangeItem dotnetExchangeItem = new DoublesExchangeItem(javaExchangeItem.getId(), javaExchangeItem.getDescription(), diff --git a/dotnet_bridge/java/src/org/openda/dotnet/ObservationDescriptionsJ2N.java b/dotnet_bridge/java/src/org/openda/dotnet/ObservationDescriptionsJ2N.java index a51b506cd..d5e013ed3 100644 --- a/dotnet_bridge/java/src/org/openda/dotnet/ObservationDescriptionsJ2N.java +++ b/dotnet_bridge/java/src/org/openda/dotnet/ObservationDescriptionsJ2N.java @@ -21,7 +21,7 @@ import org.openda.exchange.ExchangeItem; import org.openda.interfaces.IObservationDescriptions; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.interfaces.ITime; import org.openda.interfaces.IVector; @@ -44,7 +44,7 @@ public class ObservationDescriptionsJ2N implements IObservationDescriptions { * * @return All exchange items in the stoch. observer. */ - public List getExchangeItems() + public List getExchangeItems() { throw new UnsupportedOperationException("Not implemented yet."); } diff --git a/dotnet_bridge/java/src/org/openda/dotnet/ObservationDescriptionsN2J.java b/dotnet_bridge/java/src/org/openda/dotnet/ObservationDescriptionsN2J.java index f00d33bfc..7626f188c 100644 --- a/dotnet_bridge/java/src/org/openda/dotnet/ObservationDescriptionsN2J.java +++ b/dotnet_bridge/java/src/org/openda/dotnet/ObservationDescriptionsN2J.java @@ -21,7 +21,6 @@ import cli.OpenDA.DotNet.Bridge.DoublesExchangeItem; import cli.OpenDA.DotNet.Interfaces.IExchangeItem; import org.openda.interfaces.IObservationDescriptions; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.interfaces.ITime; import org.openda.interfaces.IVector; @@ -36,11 +35,11 @@ public class ObservationDescriptionsN2J implements IObservationDescriptions { public ObservationDescriptionsN2J(IObservationDescriptions javaObservationDescriptions ) { - List javaExchangeItems = javaObservationDescriptions.getExchangeItems(); + List javaExchangeItems = javaObservationDescriptions.getExchangeItems(); cli.OpenDA.DotNet.Interfaces.IExchangeItem[] dotNetExchangeItems = new cli.OpenDA.DotNet.Interfaces.IExchangeItem[javaExchangeItems.size()]; for (int i = 0; i < javaExchangeItems.size(); i++) { - IPrevExchangeItem javaExchangeItem = javaExchangeItems.get(i); + org.openda.interfaces.IExchangeItem javaExchangeItem = javaExchangeItems.get(i); int role = UtilsJ2NAndN2J.ExchangeItemRoleMapJ2N(javaExchangeItem.getRole()); IExchangeItem dotNetExchangeItem = new DoublesExchangeItem( @@ -57,7 +56,7 @@ public cli.OpenDA.DotNet.Interfaces.IObservationDescriptions getDotNetObservatio } - public List getExchangeItems() { + public List getExchangeItems() { throw new UnsupportedOperationException("org.openda.dotnet.ObservationDescriptionsN2J.getExchangeItems(): Not implemented yet."); } diff --git a/dotnet_bridge/java/src/org/openda/dotnet/UtilsJ2NAndN2J.java b/dotnet_bridge/java/src/org/openda/dotnet/UtilsJ2NAndN2J.java index 24cd2b4b7..1b6d03d69 100644 --- a/dotnet_bridge/java/src/org/openda/dotnet/UtilsJ2NAndN2J.java +++ b/dotnet_bridge/java/src/org/openda/dotnet/UtilsJ2NAndN2J.java @@ -21,7 +21,7 @@ package org.openda.dotnet; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.interfaces.IStochModelFactory; public class UtilsJ2NAndN2J @@ -39,16 +39,16 @@ public static int OutputLevelMapJ2N(IStochModelFactory.OutputLevel outputLevel) throw new RuntimeException("Unknown IStochModelFactory.OutputLevel type: " + outputLevel); } - public static int ExchangeItemRoleMapJ2N(IPrevExchangeItem.Role role) { - if (role == IPrevExchangeItem.Role.Input) { + public static int ExchangeItemRoleMapJ2N(IExchangeItem.Role role) { + if (role == IExchangeItem.Role.Input) { return 0; // TODO cli.OpenDA.DotNet.Interfaces.Role.Input; } - if (role == IPrevExchangeItem.Role.Output) { + if (role == IExchangeItem.Role.Output) { return 1; // TODO cli.OpenDA.DotNet.Interfaces.Role.Input; } - if (role == IPrevExchangeItem.Role.InOut) { + if (role == IExchangeItem.Role.InOut) { return 2; // TODO cli.OpenDA.DotNet.Interfaces.Role.Input; } - throw new RuntimeException("Unknown IPrevExchangeItem.Role type: " + role); + throw new RuntimeException("Unknown IExchangeItem.Role type: " + role); } } diff --git a/install_castor.sh b/install_castor.sh index d2cb3fe57..9e28c4832 100644 --- a/install_castor.sh +++ b/install_castor.sh @@ -10,7 +10,7 @@ HIER=$PWD -for DIRBUILD in model_delft3d core model_wflow model_efdc_dll model_bmi observers +for DIRBUILD in model_delft3d core model_wflow model_efdc_dll model_bmi observers model_external_socket do cd $DIRBUILD ant -f build_castor.xml build diff --git a/model_RainfallRunoffZhang/java/model_RainfallRunoffZhang.iml b/model_RainfallRunoffZhang/java/model_RainfallRunoffZhang.iml index 8f56852d8..429985812 100644 --- a/model_RainfallRunoffZhang/java/model_RainfallRunoffZhang.iml +++ b/model_RainfallRunoffZhang/java/model_RainfallRunoffZhang.iml @@ -10,16 +10,8 @@ - - - - - - - - - + \ No newline at end of file diff --git a/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/ASCIITimeSeriesObservationDescriptions.java b/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/ASCIITimeSeriesObservationDescriptions.java index be6d2ba4c..26811d863 100644 --- a/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/ASCIITimeSeriesObservationDescriptions.java +++ b/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/ASCIITimeSeriesObservationDescriptions.java @@ -21,7 +21,7 @@ import org.openda.interfaces.IObservationDescriptions; import org.openda.interfaces.ITime; import org.openda.interfaces.IVector; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import java.util.List; public class ASCIITimeSeriesObservationDescriptions implements IObservationDescriptions { @@ -38,7 +38,7 @@ public ASCIITimeSeriesObservationDescriptions(ASCII_TimeSeriesStochObserver obs) } @Override - public List getExchangeItems() { + public List getExchangeItems() { return obs.getExchangeItems(); } diff --git a/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/ASCII_TimeSeriesStochObserver.java b/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/ASCII_TimeSeriesStochObserver.java index 5b8e025d7..18d41f9ee 100644 --- a/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/ASCII_TimeSeriesStochObserver.java +++ b/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/ASCII_TimeSeriesStochObserver.java @@ -46,7 +46,7 @@ public class ASCII_TimeSeriesStochObserver extends Instance implements IStochObs double tolerance = 1.0/24.0/60.0/2.0; // 0.5 minute // cache propertyLabels java.util.Vector propertyLabels = new java.util.Vector(); - private List exchangeItems = new ArrayList(); + private List exchangeItems = new ArrayList(); private HashMap allObsIds = new HashMap(); @@ -74,7 +74,7 @@ public void initialize(File workingDir, String[] arguments) { /** * Save some property names to a list of time series. These properties are: location, quantity, source, unit, height, xposition, yposition, and id. - * @param series[] A list of time series. + * @param series A list of time series. */ public void setSeries(TimeSeries series[]){ this.series = series; @@ -714,7 +714,7 @@ public int getPropertyCount(){ return this.propertyLabels.size(); } - public List getExchangeItems() { + public List getExchangeItems() { return exchangeItems; } diff --git a/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/ForcingWrapper.java b/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/ForcingWrapper.java index 1237bef3f..c60d29a62 100644 --- a/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/ForcingWrapper.java +++ b/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/ForcingWrapper.java @@ -26,15 +26,11 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Set; -import org.openda.blackbox.interfaces.IoObjectInterface; +import org.openda.exchange.AbstractDataObject; import org.openda.exchange.timeseries.TimeSeries; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; /** * ForcingWrapper class reads the entire time series of the example model in one go. @@ -62,13 +58,11 @@ * */ -public class ForcingWrapper implements IoObjectInterface { +public class ForcingWrapper extends AbstractDataObject { // Class specific values File workingDir; - String configString; String fileName = null; - HashMap items = new LinkedHashMap(); /** * Cache values to be read. The dynamic form of an ArrayList is chosen here @@ -76,69 +70,51 @@ public class ForcingWrapper implements IoObjectInterface { * Cache Lists for times and values are needed. * -- Modify variables for forcing to be read here. */ - private List precipitationCache = new ArrayList(); - private List precipTimeCache = new ArrayList(); - private List potETCache = new ArrayList(); - private List potETTimeCache = new ArrayList(); - - + private List precipitationCache = new ArrayList<>(); + private List precipTimeCache = new ArrayList<>(); + private List potETCache = new ArrayList<>(); + private List potETTimeCache = new ArrayList<>(); + + // --- Methods -- /** - * Initialize the IoObject. Reads the content of a file (fileName) in + * Initialize the DataObject. Reads the content of a file (fileName) in * directory (workingDir) with given arguments. * * @param workingDir * Working directory - * @param fileName - * The name of the file containing the data (relative to the - * working directory.) * @param arguments - * Additional arguments (may be null zero-length) + * Contains the name of the file containing the data (relative to the + * working directory), and additional arguments (may be null zero-length) */ - public void initialize(File workingDir, String fileName, String[] arguments) { + @Override + public void initialize(File workingDir, String[] arguments) { this.workingDir = workingDir; - this.fileName = fileName; + fileName = arguments[0]; try { - ReadNameListFile(workingDir, fileName, arguments); + ReadNameListFile(workingDir, fileName); } catch (IOException e) { e.printStackTrace(); } } - /** - * Ask which elements can be accessed - * - * @return The list of element identifiers that can be accessed - */ - public IPrevExchangeItem[] getExchangeItems() { - // Get the number of items. - int n = this.items.size(); - Set keys = this.items.keySet(); - IExchangeItem[] result = new IExchangeItem[n]; - int i = 0; - for (String key : keys) { - result[i] = this.items.get(key); - i++; - } - return result; - } - /** * Updates the forcing files. Here, the entire time series is written. */ + @Override public void finish() { double[] pt; double[] p; - if (this.fileName.contains("precip") || this.fileName.contains("Precip")) { - pt = this.items.get("precipitation").getTimes(); - p = this.items.get("precipitation").getValuesAsDoubles(); + if (fileName.contains("precip") || fileName.contains("Precip")) { + pt = exchangeItems.get("precipitation").getTimes(); + p = exchangeItems.get("precipitation").getValuesAsDoubles(); //write to file - System.out.println("ForcingWrapper.finish(): Writing to file: "+this.workingDir+"/"+this.fileName); - File outputFile = new File(this.workingDir,this.fileName); + System.out.println("ForcingWrapper.finish(): Writing to file: "+this.workingDir+"/"+fileName); + File outputFile = new File(this.workingDir,fileName); try{ if(outputFile.isFile()){ outputFile.delete(); @@ -164,12 +140,12 @@ public void finish() { } catch (Exception e) { throw new RuntimeException("ForcingWrapper.finish(): Problem writing to file "+fileName+" : "+System.lineSeparator()+e.getMessage()); } - } else if (this.fileName.contains("pot") || this.fileName.contains("Pot") || this.fileName.contains("ET")) { - pt = this.items.get("potET").getTimes(); - p = this.items.get("potET").getValuesAsDoubles(); + } else if (fileName.contains("pot") || fileName.contains("Pot") || fileName.contains("ET")) { + pt = exchangeItems.get("potET").getTimes(); + p = exchangeItems.get("potET").getValuesAsDoubles(); //write to file - System.out.println("ForcingWrapper.finish(): Writing to file: "+this.workingDir+"/"+this.fileName); - File outputFile = new File(this.workingDir,this.fileName); + System.out.println("ForcingWrapper.finish(): Writing to file: "+this.workingDir+"/"+fileName); + File outputFile = new File(this.workingDir,fileName); try{ if(outputFile.isFile()){ outputFile.delete(); @@ -209,12 +185,11 @@ public void finish() { * -- Adapt reading of the key-value pairs to the format of the i/o file * and the number and ids of the ExchangeItem(s). * - * @param workingDir - * @param fileName - * @param arguments - * @throws IOException + * @param workingDir WorkingDir + * @param fileName The name of the file containing the data (relative to the working dir.) + * @throws IOException Exception that might be thrown */ - private void ReadNameListFile(File workingDir, String fileName, String[] arguments) throws IOException { + private void ReadNameListFile(File workingDir, String fileName) throws IOException { File namelist = new File(workingDir, fileName); if (!namelist.exists()) { @@ -223,8 +198,8 @@ private void ReadNameListFile(File workingDir, String fileName, String[] argumen // Create nested reader. FileInputStream in = new FileInputStream(namelist); BufferedReader buff = new BufferedReader(new InputStreamReader(in)); - String line = ""; // Initialize line. - Boolean eof = false; // End of file cache. + String line; // Initialize line. + boolean eof = false; // End of file cache. // While End of file is not reached yet do the following: while (!eof) { @@ -284,10 +259,7 @@ private void ReadNameListFile(File workingDir, String fileName, String[] argumen TimeSeries precipitationSeries = new TimeSeries(pt,p); String id = "precipitation"; precipitationSeries.setId(id); - this.items.put(id,precipitationSeries); - @SuppressWarnings("unused") - IExchangeItem precipitationExchangeItem = new TimeSeries(precipitationSeries); - //System.out.println("<- stored precipSeries ->"); + exchangeItems.put(id, precipitationSeries); } else if (fileName.contains("pot") || fileName.contains("Pot") || fileName.contains("ET")) { int timeLength = potETTimeCache.size(); @@ -303,7 +275,7 @@ private void ReadNameListFile(File workingDir, String fileName, String[] argumen TimeSeries potETSeries = new TimeSeries(pt,p); String id = "potET"; potETSeries.setId(id); - this.items.put(id,potETSeries); + exchangeItems.put(id, potETSeries); @SuppressWarnings("unused") IExchangeItem potETExchangeItem = new TimeSeries(potETSeries); //System.out.println("<- stored potETSeries ->"); diff --git a/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/InitialStatesWrapper.java b/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/InitialStatesWrapper.java index c4e190623..c8d2456ae 100644 --- a/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/InitialStatesWrapper.java +++ b/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/InitialStatesWrapper.java @@ -18,21 +18,12 @@ * along with OpenDA. If not, see . */ package org.openda.model_RainfallRunoffZhang; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Set; -import org.openda.blackbox.interfaces.IoObjectInterface; +import org.openda.exchange.AbstractDataObject; import org.openda.exchange.timeseries.TimeSeries; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; + +import java.io.*; /** * Allows reading of initial states from matlab readable ASCII file and @@ -63,14 +54,11 @@ * @author Beatrice Marti, hydrosolutions ltd. * */ -public class InitialStatesWrapper implements - IoObjectInterface { +public class InitialStatesWrapper extends AbstractDataObject { // Class specific values File workingDir; - String configString; String fileName = null; - HashMap items = new LinkedHashMap(); // Cache values to be read. // -- Add variables for initial States to be read here. @@ -79,53 +67,35 @@ public class InitialStatesWrapper implements private double[] timeCache = new double[2]; /** - * Initialize the IoObject. Reads the content of a file (fileName) in + * Initialize the DataObject. Reads the content of a file (fileName) in * directory (workingDir) with given arguments. * * @param workingDir * Working directory - * @param fileName - * The name of the file containing the data (relative to the - * working directory.) * @param arguments - * Additional arguments (may be null zero-length) + * The name of the file containing the data (relative to the + * working directory), and possible + * additional arguments */ - public void initialize(File workingDir, String fileName, String[] arguments) { + @Override + public void initialize(File workingDir, String[] arguments) { this.workingDir = workingDir; - this.fileName = fileName; + this.fileName = arguments[0]; try { - ReadNameListFile(workingDir, fileName, arguments); + ReadNameListFile(workingDir, arguments); } catch (IOException e) { e.printStackTrace(); } } - /** - * Ask which elements can be accessed - * - * - * @return The list of element identifiers that can be accessed - */ - public IPrevExchangeItem[] getExchangeItems() { - // Get the number of items. - int n = this.items.size(); - Set keys = this.items.keySet(); - IExchangeItem[] result = new IExchangeItem[n]; - int i = 0; - for (String key : keys) { - result[i] = this.items.get(key); - i++; - } - return result; - } - +@Override public void finish() { // Updates initial states file. - double[] currentTimeCache = this.items.get("soilMoisture").getTimes(); - double[] soilMoistureCache = this.items.get("soilMoisture").getValuesAsDoubles(); - double[] gwStorageCache = this.items.get("gwStorage").getValuesAsDoubles(); + double[] currentTimeCache = this.exchangeItems.get("soilMoisture").getTimes(); + double[] soilMoistureCache = this.exchangeItems.get("soilMoisture").getValuesAsDoubles(); + double[] gwStorageCache = this.exchangeItems.get("gwStorage").getValuesAsDoubles(); //write to file System.out.println("InitialStatesWrapper.finish(): Writing to file: "+this.workingDir+"/"+this.fileName); @@ -162,16 +132,15 @@ public void finish() { * them to an ExchangeItem. * -- Adapt reading of the key-value pairs and writing to the ExchangeItem * here below. - * - * @param workingDir - * @param fileName - * @param arguments - * @throws IOException + * + * @param workingDir: Working directory + * @param arguments: The name of the file containing the data (relative to the + * working directory), and possible additional arguments + * @throws IOException: in case of an error, an IOException is thrown */ - private void ReadNameListFile(File workingDir, String fileName, - String[] arguments) throws IOException { + private void ReadNameListFile(File workingDir, String[] arguments) throws IOException { - File namelist = new File(workingDir, fileName); + File namelist = new File(workingDir, arguments[0]); if (!namelist.exists()) { throw new RuntimeException("InitialStatesWrapper.ReadNameListFile(): settings file " + namelist.getAbsolutePath() + " does not exist"); @@ -179,8 +148,8 @@ private void ReadNameListFile(File workingDir, String fileName, // Create nested reader. FileInputStream in = new FileInputStream(namelist); BufferedReader buff = new BufferedReader(new InputStreamReader(in)); - String line = ""; // Initialize line. - Boolean eof = false; // End of file cache. + String line; // Initialize line. + boolean eof = false; // End of file cache. //System.out.println("Initial States wrapper: Start reading file."); // While End of file is not reached yet do the following: @@ -198,7 +167,7 @@ private void ReadNameListFile(File workingDir, String fileName, // Now parse the line. // Remove comments at end of line. if (line.indexOf("%") > 1) { - String columns[] = line.split("%"); + String[] columns = line.split("%"); line = columns[0]; //System.out.println("Line with comment at end of key-value pair : " + line); } @@ -216,7 +185,7 @@ private void ReadNameListFile(File workingDir, String fileName, columns[3] = columns[3].trim(); // Remove comma from columns[3]. String[] tempTime = columns[3].split(","); - timeCache[0] = Double.valueOf(tempTime[0]); + timeCache[0] = Double.parseDouble(tempTime[0]); } else { System.out.println("InitialStatesWrapper.ReadNameListFile(): trouble reading current time."); } @@ -224,7 +193,7 @@ private void ReadNameListFile(File workingDir, String fileName, if (columns[4].equals("finalTime")) { columns[6] = columns[6].trim(); String[] temp = columns[6].split(";"); - timeCache[1] = Double.valueOf(temp[0]); + timeCache[1] = Double.parseDouble(temp[0]); } else { System.out.println("InitialStatesWrapper.ReadNameListFile(): trouble reading final time."); } @@ -246,17 +215,17 @@ private void ReadNameListFile(File workingDir, String fileName, columns[1] = columns[1].trim(); // Remove the semicollon at the end of the string in // columns[1]. - String temp[] = columns[1].split(";"); + String[] temp = columns[1].split(";"); columns[1] = temp[0]; // Parse the values to the key caches in Java. // -- Add if-loops for variables to be read here. if (columns[0].equals("soilMoisture")) { - soilMoistureCache[0] = Double.valueOf(columns[1]); + soilMoistureCache[0] = Double.parseDouble(columns[1]); soilMoistureCache[1] = soilMoistureCache[0]; } if (columns[0].equals("gwStorage")) { - gwStorageCache[0] = Double.valueOf(columns[1]); + gwStorageCache[0] = Double.parseDouble(columns[1]); gwStorageCache[1] = gwStorageCache[0]; } @@ -272,14 +241,14 @@ private void ReadNameListFile(File workingDir, String fileName, TimeSeries soilMoistureSeries = new TimeSeries(timeCache, soilMoistureCache); String id1 = "soilMoisture"; soilMoistureSeries.setId(id1); - this.items.put(id1,soilMoistureSeries); + this.exchangeItems.put(id1,soilMoistureSeries); @SuppressWarnings("unused") IExchangeItem soilMoistureExchangeItem = new TimeSeries(soilMoistureSeries); TimeSeries gwStorageSeries = new TimeSeries(timeCache, gwStorageCache); String id2 = "gwStorage"; gwStorageSeries.setId(id2); - this.items.put(id2,gwStorageSeries); + this.exchangeItems.put(id2,gwStorageSeries); @SuppressWarnings("unused") IExchangeItem gwStorageExchangeItem = new TimeSeries(gwStorageSeries); diff --git a/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/ParametersWrapper.java b/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/ParametersWrapper.java index da772c730..57733baa8 100644 --- a/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/ParametersWrapper.java +++ b/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/ParametersWrapper.java @@ -18,21 +18,12 @@ * along with OpenDA. If not, see . */ package org.openda.model_RainfallRunoffZhang; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Set; -import org.openda.blackbox.interfaces.IoObjectInterface; +import org.openda.exchange.AbstractDataObject; import org.openda.exchange.timeseries.TimeSeries; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; + +import java.io.*; /** * Allows reading of time variables from matlab readable ASCII file and @@ -73,15 +64,12 @@ * @author Beatrice Marti, hydrosolutions ltd. * */ -public class ParametersWrapper implements - IoObjectInterface { +public class ParametersWrapper extends AbstractDataObject { // Class specific values File workingDir; - String configString; String fileName = null; - HashMap items = new LinkedHashMap(); // Cache values to be read. // -- Add variables for initial States to be read here. @@ -92,56 +80,37 @@ public class ParametersWrapper implements private double[] timeCache = new double[2]; /** - * Initialize the IoObject. Reads the content of a file (fileName) in + * Initialize the DataObject. Reads the content of a file (fileName) in * directory (workingDir) with given arguments. * * @param workingDir * Working directory - * @param fileName - * The name of the file containing the data (relative to the - * working directory.) * @param arguments - * Additional arguments (may be null zero-length) + * The name of the file containing the data (relative to the + * working directory), and additional arguments (may be null zero-length) */ - public void initialize(File workingDir, String fileName, String[] arguments) { + @Override + public void initialize(File workingDir, String[] arguments) { this.workingDir = workingDir; - this.fileName = fileName; + this.fileName = arguments[0]; try { System.out.println("Parameter wrapper starts reading file."); - ReadNameListFile(workingDir, fileName, arguments); + ReadNameListFile(workingDir, arguments); } catch (IOException e) { e.printStackTrace(); } } - /** - * Ask which elements can be accessed - * - * - * @return The list of element identifiers that can be accessed - */ - public IPrevExchangeItem[] getExchangeItems() { - // Get the number of items. - int n = this.items.size(); - Set keys = this.items.keySet(); - IPrevExchangeItem[] result = new IPrevExchangeItem[n]; - int i = 0; - for (String key : keys) { - result[i] = this.items.get(key); - i++; - } - return result; - } - + @Override public void finish() { // Updates parameter file. - double[] currentTimeCache = this.items.get("parameter_d").getTimes(); - double[] parameter_dCache = this.items.get("parameter_d").getValuesAsDoubles(); - double[] parameter_SmaxCache = this.items.get("parameter_Smax").getValuesAsDoubles(); - double[] parameter_alpha1Cache = this.items.get("parameter_alpha1").getValuesAsDoubles(); - double[] parameter_alpha2Cache = this.items.get("parameter_alpha2").getValuesAsDoubles(); + double[] currentTimeCache = this.exchangeItems.get("parameter_d").getTimes(); + double[] parameter_dCache = this.exchangeItems.get("parameter_d").getValuesAsDoubles(); + double[] parameter_SmaxCache = this.exchangeItems.get("parameter_Smax").getValuesAsDoubles(); + double[] parameter_alpha1Cache = this.exchangeItems.get("parameter_alpha1").getValuesAsDoubles(); + double[] parameter_alpha2Cache = this.exchangeItems.get("parameter_alpha2").getValuesAsDoubles(); //write to file System.out.println("ParametersWrapper.finish(): Writing to file: "+this.workingDir+"/"+this.fileName); @@ -179,15 +148,16 @@ public void finish() { *

* -- Adapt reading of the key-value pairs and writing to the ExchangeItem * here below. - * + * * @param workingDir - * @param fileName + * Working directory * @param arguments + * The name of the file containing the data (relative to the + * working directory), and additional arguments (may be null zero-length) * @throws IOException */ - private void ReadNameListFile(File workingDir, String fileName, - String[] arguments) throws IOException { - File namelist = new File(workingDir, fileName); + private void ReadNameListFile(File workingDir, String[] arguments) throws IOException { + File namelist = new File(workingDir, arguments[0]); if (!namelist.exists()) { throw new RuntimeException("ParametersWrapper.ReadNameListFile(): settings file " + namelist.getAbsolutePath() + " does not exist"); @@ -195,8 +165,8 @@ private void ReadNameListFile(File workingDir, String fileName, // Create nested reader. FileInputStream in = new FileInputStream(namelist); BufferedReader buff = new BufferedReader(new InputStreamReader(in)); - String line = ""; // Initialize line. - Boolean eof = false; // End of file cache. + String line; // Initialize line. + boolean eof = false; // End of file cache. // While End of file is not reached yet do the following: while (!eof) { @@ -213,7 +183,7 @@ private void ReadNameListFile(File workingDir, String fileName, // Now parse the line. // Remove comments at end of line. if (line.indexOf("%") > 1) { - String columns[] = line.split("%"); + String[] columns = line.split("%"); line = columns[0]; } if (line.startsWith("%")) { @@ -230,14 +200,14 @@ private void ReadNameListFile(File workingDir, String fileName, columns[3] = columns[3].trim(); // Remove comma from columns[3]. String[] tempTime = columns[3].split(","); - timeCache[0] = Double.valueOf(tempTime[0]); + timeCache[0] = Double.parseDouble(tempTime[0]); } else { System.out.println("Error in parameters wrapper. Trouble reading current time."); } if (columns[4].equals("finalTime")) { columns[6] = columns[6].trim(); String[] temp = columns[6].split(";"); - timeCache[1] = Double.valueOf(temp[0]); + timeCache[1] = Double.parseDouble(temp[0]); } else { System.out.println("Error in parameters wrapper. Trouble reading final time."); } @@ -253,27 +223,27 @@ private void ReadNameListFile(File workingDir, String fileName, columns[1] = columns[1].trim(); // Remove the semicollon at the end of the string in // columns[1]. - String temp[] = columns[1].split(";"); + String[] temp = columns[1].split(";"); columns[1] = temp[0]; // Parse the values to the key caches in Java. // -- Add if-loops for variables to be read here. if (columns[0].equals("parameter_d")) { - parameter_dCache[0] = Double.valueOf(columns[1]); + parameter_dCache[0] = Double.parseDouble(columns[1]); parameter_dCache[1] = parameter_dCache[0]; } if (columns[0].equals("parameter_Smax")) { - parameter_SmaxCache[0] = Double.valueOf(columns[1]); + parameter_SmaxCache[0] = Double.parseDouble(columns[1]); parameter_SmaxCache[1] = parameter_SmaxCache[0]; } if (columns[0].equals("parameter_alpha1")) { - parameter_alpha1Cache[0] = Double.valueOf(columns[1]); + parameter_alpha1Cache[0] = Double.parseDouble(columns[1]); parameter_alpha1Cache[1] = parameter_alpha1Cache[0]; } if (columns[0].equals("parameter_alpha2")) { - parameter_alpha2Cache[0] = Double.valueOf(columns[1]); + parameter_alpha2Cache[0] = Double.parseDouble(columns[1]); parameter_alpha2Cache[1] = parameter_alpha2Cache[0]; } @@ -290,7 +260,7 @@ private void ReadNameListFile(File workingDir, String fileName, parameter_dSeries.setLocation("default"); String id1 = "parameter_d"; parameter_dSeries.setId(id1); - this.items.put(id1,parameter_dSeries); + this.exchangeItems.put(id1,parameter_dSeries); @SuppressWarnings("unused") IExchangeItem parameter_dExchangeItem = new TimeSeries(parameter_dSeries); @@ -298,7 +268,7 @@ private void ReadNameListFile(File workingDir, String fileName, parameter_SmaxSeries.setLocation("default"); String id2 = "parameter_Smax"; parameter_SmaxSeries.setId(id2); - this.items.put(id2,parameter_SmaxSeries); + this.exchangeItems.put(id2,parameter_SmaxSeries); @SuppressWarnings("unused") IExchangeItem parameter_SmaxExchangeItem = new TimeSeries(parameter_SmaxSeries); @@ -306,7 +276,7 @@ private void ReadNameListFile(File workingDir, String fileName, parameter_alpha1Series.setLocation("default"); String id3 = "parameter_alpha1"; parameter_alpha1Series.setId(id3); - this.items.put(id3,parameter_alpha1Series); + this.exchangeItems.put(id3,parameter_alpha1Series); @SuppressWarnings("unused") IExchangeItem parameter_alpha1ExchangeItem = new TimeSeries(parameter_alpha1Series); @@ -314,7 +284,7 @@ private void ReadNameListFile(File workingDir, String fileName, parameter_alpha2Series.setLocation("default"); String id4 = "parameter_alpha2"; parameter_alpha2Series.setId(id4); - this.items.put(id4,parameter_alpha2Series); + this.exchangeItems.put(id4,parameter_alpha2Series); @SuppressWarnings("unused") IExchangeItem parameter_alpha2ExchangeItem = new TimeSeries(parameter_alpha2Series); diff --git a/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/ResultFileWrapper.java b/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/ResultFileWrapper.java index 6bd60603a..b8f8ea431 100644 --- a/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/ResultFileWrapper.java +++ b/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/ResultFileWrapper.java @@ -18,22 +18,14 @@ * along with OpenDA. If not, see . */ package org.openda.model_RainfallRunoffZhang; -import java.io.BufferedReader; -//import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -//import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Set; -import java.util.Vector; -import org.openda.blackbox.interfaces.IoObjectInterface; +import org.openda.exchange.AbstractDataObject; import org.openda.exchange.timeseries.TimeSeries; import org.openda.interfaces.IExchangeItem; +import java.io.*; +import java.util.Vector; + /** * Allows reading of time variables from matlab readable ASCII file and * transferring these to OpenDA ExchangeItems. @@ -54,107 +46,42 @@ * @author Beatrice Marti, hydrosolutions ltd. * */ -public class ResultFileWrapper implements IoObjectInterface { +public class ResultFileWrapper extends AbstractDataObject { // Class specific values File workingDir; - String configString; String fileName = null; - HashMap items = new LinkedHashMap(); - + /** - * Initialize the IoObject. Reads the content of a file (fileName) in + * Initialize the DataObject. Reads the content of a file in * directory (workingDir) with given arguments. * * @param workingDir * Working directory - * @param fileName - * The name of the file containing the data (relative to the - * working directory.) * @param arguments - * Additional arguments (may be null zero-length) + * The name of the file containing the data (relative to the + * working directory), and additional arguments (may be null zero-length) */ - public void initialize(File workingDir, String fileName, String[] arguments) { + @Override + public void initialize(File workingDir, String[] arguments) { this.workingDir = workingDir; - this.fileName = fileName; + this.fileName = arguments[0]; try { - ReadNameListFile(workingDir, fileName, arguments); + ReadNameListFile(); } catch (IOException e) { e.printStackTrace(); } } - /** - * Ask which elements can be accessed - * - * - * @return The list of element identifiers that can be accessed - */ - public TimeSeries[] getExchangeItems() { - // Get the number of items. - int n = this.items.size(); - Set keys = this.items.keySet(); - TimeSeries[] result = new TimeSeries[n]; - int i = 0; - for (String key : keys) { - result[i] = this.items.get(key); - i++; - } - return result; - } - - /** - * A slightly more elegant variant of getExchangeItems(). - * - * @return A vector of type TimeSeries containing the values of the - * time series stored in the hash map items. - */ - public Vector getData() { - return new Vector(this.items.values()); - } - - + @Override public void finish() { /* * In this example, writing the result file is not needed because the totalRunoff is not * read by the rainfall runoff model to initialize a run. * - * - // Write updated predictor - double[] currentTimeCache = this.items.get("totalRunoff").getTimes(); - double[] totalRunoffCache = this.items.get("totalRunoff").getValuesAsDoubles(); - - //write to file - System.out.println("Result wrapper finish(): Writing to file: "+this.workingDir+"/"+this.fileName); - File outputFile = new File(this.workingDir,this.fileName); - try{ - if(outputFile.isFile()){ - outputFile.delete(); - } - }catch (Exception e) { - System.out.println("ResultWrapper: trouble removing file "+ fileName); - } - try { - FileWriter writer = new FileWriter(outputFile); - BufferedWriter out = new BufferedWriter(writer); - - int seriesLength = currentTimeCache.length; - if (seriesLength != totalRunoffCache.length) { - System.out.println("Error writing result file. Length of times and values are not the same."); - } - for (int i = 0 ; i < seriesLength; i++) { - out.write(currentTimeCache[i] + " " + totalRunoffCache[i] + System.getProperty("line.separator")); - } - out.flush(); // Force java to write buffered stream to disk. - out.close(); - writer.close(); - - } catch (Exception e) { - throw new RuntimeException("Result file wrapper: Problem writing to file "+fileName+" : " + System.getProperty("line.separator") + e.getMessage()); - } - */ + */ } /** @@ -162,26 +89,19 @@ public void finish() { * them to an ExchangeItem. *

* Actually reads one single value from file. - * - * @param workingDir - * @param fileName - * @param arguments + * * @throws IOException */ - private void ReadNameListFile(File workingDir, String fileName, - String[] arguments) throws IOException { - + private void ReadNameListFile() throws IOException { + File namelist = new File(workingDir, fileName); if (!namelist.exists()) { System.out.println("ResultFileWrapper.ReadNameListFile(): Failed to open File " + fileName + " in " + workingDir); } - //TimeSeries series = new TimeSeries(); - Vector timesVector = new Vector(); - Vector valuesVector = new Vector(); - //ArrayList times = new ArrayList(); - //ArrayList values = new ArrayList(); - double[] times = null; - double[] values = null; + Vector timesVector = new Vector<>(); + Vector valuesVector = new Vector<>(); + double[] times; + double[] values; if (!namelist.exists()) { throw new RuntimeException("ResultFileWrapper.ReadNameListFile(): settings file " @@ -190,8 +110,8 @@ private void ReadNameListFile(File workingDir, String fileName, // Create nested reader. FileInputStream in = new FileInputStream(namelist); BufferedReader buff = new BufferedReader(new InputStreamReader(in)); - String line = ""; // Initialize line. - Boolean eof = false; // End of file cache. + String line; // Initialize line. + boolean eof = false; // End of file cache. // While End of file is not reached yet do the following: while (!eof) { @@ -243,10 +163,7 @@ private void ReadNameListFile(File workingDir, String fileName, TimeSeries series = new TimeSeries(times, values); String id = "totalRunoff"; series.setId(id); - this.items.put(id,series); - @SuppressWarnings("unused") - IExchangeItem totalRunoffExchangeItem = new TimeSeries(series); - + this.exchangeItems.put(id,series); } diff --git a/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/TimesWrapper.java b/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/TimesWrapper.java index 387bbc4a3..a976b2105 100644 --- a/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/TimesWrapper.java +++ b/model_RainfallRunoffZhang/java/src/org/openda/model_RainfallRunoffZhang/TimesWrapper.java @@ -18,21 +18,12 @@ * along with OpenDA. If not, see . */ package org.openda.model_RainfallRunoffZhang; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Set; -import org.openda.blackbox.interfaces.IoObjectInterface; +import org.openda.exchange.AbstractDataObject; import org.openda.exchange.DoubleExchangeItem; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; + +import java.io.*; /** * Allows reading of time variables from matlab readable ASCII file and @@ -55,23 +46,11 @@ * @author Beatrice Marti, hydrosolutions ltd. * */ -public class TimesWrapper implements - IoObjectInterface { - - // Define a private class to cache the exchange items. - private class TimesWrapperExchangeItem { - public IExchangeItem exchangeItem; - - TimesWrapperExchangeItem(IExchangeItem exchangeItem) { - this.exchangeItem = exchangeItem; - } - } +public class TimesWrapper extends AbstractDataObject { // Class specific values File workingDir; - String configString; String fileName = null; - HashMap items = new LinkedHashMap(); // Cache values to be read. // -- Add variables for initial States to be read here. @@ -80,53 +59,34 @@ private class TimesWrapperExchangeItem { private double finalTimeCache = 0.0; /** - * Initialize the IoObject. Reads the content of a file (fileName) in + * Initialize the DataObject. Reads the content of a file (fileName) in * directory (workingDir) with given arguments. * * @param workingDir * Working directory - * @param fileName - * The name of the file containing the data (relative to the - * working directory.) * @param arguments - * Additional arguments (may be null zero-length) + * The name of the file containing the data (relative to the + * working directory), and additional arguments (may be null zero-length) */ - public void initialize(File workingDir, String fileName, String[] arguments) { + @Override + public void initialize(File workingDir, String[] arguments) { this.workingDir = workingDir; - this.fileName = fileName; + this.fileName = arguments[0]; try { - ReadNameListFile(workingDir, fileName, arguments); + ReadNameListFile(); } catch (IOException e) { e.printStackTrace(); } } - /** - * Ask which elements can be accessed - * - * - * @return The list of element identifiers that can be accessed - */ - public IPrevExchangeItem[] getExchangeItems() { - // Get the number of items. - int n = this.items.size(); - Set keys = this.items.keySet(); - IExchangeItem[] result = new IExchangeItem[n]; - int i = 0; - for (String key : keys) { - result[i] = this.items.get(key).exchangeItem; - i++; - } - return result; - } - + @Override public void finish() { // Updates time configuration file. - double currentTime = this.items.get("currentTime").exchangeItem.getValuesAsDoubles()[0]; - double simulationTimeStep = this.items.get("simulationTimeStep").exchangeItem.getValuesAsDoubles()[0]; - double finalTime = this.items.get("finalTime").exchangeItem.getValuesAsDoubles()[0]; + double currentTime = exchangeItems.get("currentTime").getValuesAsDoubles()[0]; + double simulationTimeStep = exchangeItems.get("simulationTimeStep").getValuesAsDoubles()[0]; + double finalTime = exchangeItems.get("finalTime").getValuesAsDoubles()[0]; //write to file System.out.println("TimesWrapper.finish(): writing to " +this.workingDir+"/"+this.fileName); @@ -163,14 +123,10 @@ public void finish() { * them to an ExchangeItem. * -- Adapt reading of the key-value pairs and writing to the ExchangeItem * here below. - * - * @param workingDir - * @param fileName - * @param arguments + * * @throws IOException */ - private void ReadNameListFile(File workingDir, String fileName, - String[] arguments) throws IOException { + private void ReadNameListFile() throws IOException { File namelist = new File(workingDir, fileName); if (!namelist.exists()) { throw new RuntimeException("TimesWrapper.ReadNameListFile(): settings file " @@ -180,7 +136,7 @@ private void ReadNameListFile(File workingDir, String fileName, FileInputStream in = new FileInputStream(namelist); BufferedReader buff = new BufferedReader(new InputStreamReader(in)); String line = ""; // Initialize line. - Boolean eof = false; // End of file cache. + boolean eof = false; // End of file cache. // While End of file is not reached yet do the following: while (!eof) { @@ -197,7 +153,7 @@ private void ReadNameListFile(File workingDir, String fileName, // Now parse the line. // Remove comments at end of line. if (line.indexOf("%") > 1) { - String columns[] = line.split("%"); + String[] columns = line.split("%"); line = columns[0]; } if (line.startsWith("%")) { @@ -212,20 +168,20 @@ private void ReadNameListFile(File workingDir, String fileName, // of the string. columns[1] = columns[1].trim(); // Remove the semicollon at the end of the string in columns[1]. - String temp[] = columns[1].split(";"); + String[] temp = columns[1].split(";"); columns[1] = temp[0]; // Parse the values to the key caches in Java. // -- Add if-loops for variables to be read here. if (columns[0].equals("currentTime")) { - currentTimeCache = Double.valueOf(columns[1]); + currentTimeCache = Double.parseDouble(columns[1]); } if (columns[0].equals("simulationTimeStep")) { - simulationTimeStepCache = Double.valueOf(columns[1]); + simulationTimeStepCache = Double.parseDouble(columns[1]); } if (columns[0].equals("finalTime")) { - finalTimeCache = Double.valueOf(columns[1]); + finalTimeCache = Double.parseDouble(columns[1]); } } @@ -239,18 +195,15 @@ private void ReadNameListFile(File workingDir, String fileName, // -- Add commands for storing the read key-value pairs in the exchange items. IExchangeItem currentTimeExchangeItem = new DoubleExchangeItem( "currentTime", this.currentTimeCache); - this.items.put("currentTime", new TimesWrapperExchangeItem( - currentTimeExchangeItem)); + exchangeItems.put("currentTime", currentTimeExchangeItem); IExchangeItem finalTimeExchangeItem = new DoubleExchangeItem( "finalTime", this.finalTimeCache); - this.items.put("finalTime", new TimesWrapperExchangeItem( - finalTimeExchangeItem)); + exchangeItems.put("finalTime", finalTimeExchangeItem); IExchangeItem simulationTimeStepExchangeItem = new DoubleExchangeItem( "simulationTimeStep", this.simulationTimeStepCache); - this.items.put("simulationTimeStep", new TimesWrapperExchangeItem( - simulationTimeStepExchangeItem)); + exchangeItems.put("simulationTimeStep", simulationTimeStepExchangeItem); } diff --git a/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/ASCIITimeSeriesStochObserverTest.java b/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/ASCIITimeSeriesStochObserverTest.java index d93f89df1..e32dfff92 100644 --- a/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/ASCIITimeSeriesStochObserverTest.java +++ b/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/ASCIITimeSeriesStochObserverTest.java @@ -382,13 +382,13 @@ public void testStochObserver_noosObserver6() { IStochObserver noosStochObserver_a = new ASCIITimeSeriesStochObserver(); noosStochObserver_a.initialize(workingDir, new String[]{"noosStochObsConfig_a.xml"}); - List exchangeItems_a = noosStochObserver_a.getObservationDescriptions().getExchangeItems(); + List exchangeItems_a = noosStochObserver_a.getObservationDescriptions().getExchangeItems(); assertEquals("First Series", "location 1 Measurement", exchangeItems_a.get(0).getId()); assertEquals("First Series", "location 2 Measurement", exchangeItems_a.get(1).getId()); IStochObserver noosStochObserver_b = new ASCIITimeSeriesStochObserver(); noosStochObserver_b.initialize(workingDir, new String[]{"noosStochObsConfig_b.xml"}); - List exchangeItems_b = noosStochObserver_b.getObservationDescriptions().getExchangeItems(); + List exchangeItems_b = noosStochObserver_b.getObservationDescriptions().getExchangeItems(); assertEquals("First Series", "ObsPoint1.waterlevel", exchangeItems_b.get(0).getId()); assertEquals("First Series", "ObsPoint2.waterlevel", exchangeItems_b.get(1).getId()); @@ -397,7 +397,7 @@ public void testStochObserver_noosObserver6() { double endTime = times[times.length-1]; ITime timeSpan = new Time(startTime, endTime); IStochObserver selection = noosStochObserver_b.createSelection(timeSpan); - List exchangeItems_c = selection.getObservationDescriptions().getExchangeItems(); + List exchangeItems_c = selection.getObservationDescriptions().getExchangeItems(); assertEquals("First Series", "ObsPoint1.waterlevel", exchangeItems_c.get(0).getId()); assertEquals("First Series", "ObsPoint2.waterlevel", exchangeItems_c.get(1).getId()); } diff --git a/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/ForcingWrapperTest.java b/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/ForcingWrapperTest.java index 5f279a732..76930b851 100644 --- a/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/ForcingWrapperTest.java +++ b/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/ForcingWrapperTest.java @@ -18,29 +18,20 @@ * along with OpenDA. If not, see . */ package org.openda.model_RainfallRunoffZhang; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.file.Files; -import java.nio.file.NoSuchFileException; -import java.nio.file.Path; -import org.openda.blackbox.interfaces.IoObjectInterface; -import org.openda.interfaces.IPrevExchangeItem; +import junit.framework.TestCase; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.OpenDaTestSupport; -import junit.framework.TestCase; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.NoSuchFileException; +import java.nio.file.Path; public class ForcingWrapperTest extends TestCase { // Use openDA test suite. private File testRunDataDir; - private OpenDaTestSupport testData; // Class types definitions: private String fileNamePrecip = "forcingWrapperTestPrecip.txt"; // Needs to be created. @@ -64,7 +55,7 @@ public class ForcingWrapperTest extends TestCase { protected void setUp() throws IOException { // Use openDA test utilities. This allows the test files to be stored // in a separate directory from the source code. - testData = new OpenDaTestSupport(ResultFileWrapperTest.class, "model_RainfallRunoffZhang"); + OpenDaTestSupport testData = new OpenDaTestSupport(ResultFileWrapperTest.class, "model_RainfallRunoffZhang"); testRunDataDir = testData.getTestRunDataDir(); // Write a test file. @@ -111,7 +102,7 @@ protected void setUp() throws IOException { /** * Cleans up test file created in setUp(). */ - protected void tearDown() throws Exception { + protected void tearDown() { try { File file = new File(testRunDataDir, fileNamePrecip); @@ -144,21 +135,23 @@ protected void tearDown() throws Exception { */ public void testReadPrecipitationInput() { // Creates the I/O-Object from the wrapper to be tested. - IoObjectInterface forcingWrapper = new ForcingWrapper(); - String args[] = {}; - double[] expectedTimes = new double[3]; - double[] expectedValues = new double[3]; + ForcingWrapper forcingWrapper = new ForcingWrapper(); + String[] args = {fileNamePrecip}; + double[] expectedTimes; + double[] expectedValues; // Call to initialize -> reads the file and writes 2 Exchange items. - forcingWrapper.initialize(testRunDataDir, fileNamePrecip, args); + forcingWrapper.initialize(testRunDataDir, args); - IPrevExchangeItem[] exchangeItems = forcingWrapper.getExchangeItems(); + String[] exchangeItemIDs = forcingWrapper.getExchangeItemIDs(); - for (int item = 0; item < exchangeItems.length; item++) { - if (exchangeItems[item].getId().equalsIgnoreCase("Precipitation")) { - IPrevExchangeItem expectedExchangeItem = exchangeItems[item]; - expectedTimes = (double[]) expectedExchangeItem.getTimes(); - expectedValues = (double[]) expectedExchangeItem.getValuesAsDoubles(); + for (String id:exchangeItemIDs) { + IExchangeItem expectedExchangeItem = forcingWrapper.getDataObjectExchangeItem(id); + String exId = expectedExchangeItem.getId(); + assertEquals(id, exId); + if (exId.equalsIgnoreCase("Precipitation")) { + expectedTimes = expectedExchangeItem.getTimes(); + expectedValues = expectedExchangeItem.getValuesAsDoubles(); assertEquals(value0, expectedValues[0]); assertEquals(time0, expectedTimes[0]); assertEquals(value1, expectedValues[1]); @@ -171,21 +164,23 @@ public void testReadPrecipitationInput() { public void testReadPotETInput() { // Creates the I/O-Object from the wrapper to be tested. - IoObjectInterface forcingWrapper = new ForcingWrapper(); - String args[] = {}; - double[] expectedTimes = new double[3]; - double[] expectedValues = new double[3]; + ForcingWrapper forcingWrapper = new ForcingWrapper(); + String[] args = {fileNamePotET}; + double[] expectedTimes; + double[] expectedValues; // Call to initialize -> reads the file and writes 2 Exchange items. - forcingWrapper.initialize(testRunDataDir, fileNamePotET, args); + forcingWrapper.initialize(testRunDataDir, args); - IPrevExchangeItem[] exchangeItems = forcingWrapper.getExchangeItems(); + String[] exchangeItemIDs = forcingWrapper.getExchangeItemIDs(); - for (int item = 0; item < exchangeItems.length; item++) { - if (exchangeItems[item].getId().equalsIgnoreCase("potET")) { - IPrevExchangeItem expectedExchangeItem = exchangeItems[item]; - expectedTimes = (double[]) expectedExchangeItem.getTimes(); - expectedValues = (double[]) expectedExchangeItem.getValuesAsDoubles(); + for (String id:exchangeItemIDs) { + IExchangeItem expectedExchangeItem = forcingWrapper.getDataObjectExchangeItem(id); + String exId = expectedExchangeItem.getId(); + assertEquals(id, exId); + if (exId.equalsIgnoreCase("potET")) { + expectedTimes = expectedExchangeItem.getTimes(); + expectedValues = expectedExchangeItem.getValuesAsDoubles(); assertEquals(value0, expectedValues[0]); assertEquals(time00, expectedTimes[0]); assertEquals(value1, expectedValues[1]); @@ -197,35 +192,36 @@ public void testReadPotETInput() { } /** - * Test whether or not the new forcing is written to file. - * @throws FileNotFoundException + * Test whether or not the new forcing is written to file. */ - public void testPrecipFinish() throws FileNotFoundException { + public void testPrecipFinish() { // Creates the I/O-Object from the wrapper to be tested. - IoObjectInterface precipWrapper = new ForcingWrapper(); - String args[] = {}; + ForcingWrapper precipWrapper = new ForcingWrapper(); + String[] args = {fileNamePrecip}; double[] times = new double[3]; double[] values = new double[3]; // Call to initialize -> reads the file and writes 2 Exchange items. - precipWrapper.initialize(testRunDataDir, fileNamePrecip, args); + precipWrapper.initialize(testRunDataDir, args); // Modify times and values in exchange items - IPrevExchangeItem[] exchangeItems = precipWrapper.getExchangeItems(); + String[] exchangeItemIDs = precipWrapper.getExchangeItemIDs(); times[0] = time0 + 30; times[1] = time1 + 30; times[2] = time2 + 30; - for (int item = 0; item < exchangeItems.length; item++) { + for (int i = 0; i < exchangeItemIDs.length; i++) { + String id = exchangeItemIDs[i]; + IExchangeItem exchangeItem = precipWrapper.getDataObjectExchangeItem(id); values[0] = value1 + 1; values[1] = value1 + 2; values[2] = value1 + 3; - exchangeItems[item].setValues(values); - exchangeItems[item].setTimes(times); - System.out.println("testPrecipFinish(): writes exchangeItems[" + item + "].setValues[0] = " + values[0]); - System.out.println("testPrecipFinish(): writes exchangeItems[" + item + "].setValues[1] = " + values[1]); - System.out.println("testPrecipFinish(): writes exchangeItems[" + item + "].setTimes[0] = " + times[0]); - System.out.println("testPrecipFinish(): writes exchangeItems[" + item + "].setTimes[1] = " + times[1]); + exchangeItem.setValues(values); + exchangeItem.setTimes(times); + System.out.println("testPrecipFinish(): writes exchangeItems[" + i + "].setValues[0] = " + values[0]); + System.out.println("testPrecipFinish(): writes exchangeItems[" + i + "].setValues[1] = " + values[1]); + System.out.println("testPrecipFinish(): writes exchangeItems[" + i + "].setTimes[0] = " + times[0]); + System.out.println("testPrecipFinish(): writes exchangeItems[" + i + "].setTimes[1] = " + times[1]); } precipWrapper.finish(); @@ -239,7 +235,7 @@ public void testPrecipFinish() throws FileNotFoundException { FileInputStream in = new FileInputStream(testFile); BufferedReader buff = new BufferedReader(new InputStreamReader(in)); String line = ""; // Initialize line. - Boolean eof = false; // End of file cache. + boolean eof = false; // End of file cache. double[] expectedTimes = new double[3]; double[] expectedValues = new double[3]; @@ -272,8 +268,8 @@ public void testPrecipFinish() throws FileNotFoundException { columns[1] = columns[1].trim(); // Parse the values. - expectedTimes[index] = Double.valueOf(columns[0]); - expectedValues[index] = Double.valueOf(columns[1]); + expectedTimes[index] = Double.parseDouble(columns[0]); + expectedValues[index] = Double.parseDouble(columns[1]); System.out.println("testPrecipFinish(): reads times[" + index + "] = " + expectedTimes[index]); System.out.println("testPrecipFinish(): reads values[" + index + "] = " + expectedValues[index]); index = index + 1; @@ -291,31 +287,33 @@ public void testPrecipFinish() throws FileNotFoundException { } } - public void testPotETFinish() throws FileNotFoundException { + public void testPotETFinish() { // Creates the I/O-Object from the wrapper to be tested. - IoObjectInterface potETWrapper = new ForcingWrapper(); - String args[] = {}; + ForcingWrapper potETWrapper = new ForcingWrapper(); + String[] args = {fileNamePotET}; double[] times = new double[3]; double[] values = new double[3]; // Call to initialize -> reads the file and writes 2 Exchange items. - potETWrapper.initialize(testRunDataDir, fileNamePotET, args); + potETWrapper.initialize(testRunDataDir, args); // Modify times and values in exchange items - IPrevExchangeItem[] exchangeItems = potETWrapper.getExchangeItems(); + String[] exchangeItemIDs = potETWrapper.getExchangeItemIDs(); times[0] = time00 + 30; times[1] = time01 + 30; times[2] = time02 + 30; - for (int item = 0; item < exchangeItems.length; item++) { + for (int i = 0; i < exchangeItemIDs.length; i++) { + String id = exchangeItemIDs[i]; + IExchangeItem exchangeItem = potETWrapper.getDataObjectExchangeItem(id); values[0] = value1 + 1; values[1] = value1 + 2; values[2] = value1 + 3; - exchangeItems[item].setValues(values); - exchangeItems[item].setTimes(times); - System.out.println("testPrecipFinish(): writes exchangeItems[" + item + "].setValues[0] = " + values[0]); - System.out.println("testPrecipFinish(): writes exchangeItems[" + item + "].setValues[1] = " + values[1]); - System.out.println("testPrecipFinish(): writes exchangeItems[" + item + "].setTimes[0] = " + times[0]); - System.out.println("testPrecipFinish(): writes exchangeItems[" + item + "].setTimes[1] = " + times[1]); + exchangeItem.setValues(values); + exchangeItem.setTimes(times); + System.out.println("testPrecipFinish(): writes exchangeItems[" + i + "].setValues[0] = " + values[0]); + System.out.println("testPrecipFinish(): writes exchangeItems[" + i + "].setValues[1] = " + values[1]); + System.out.println("testPrecipFinish(): writes exchangeItems[" + i + "].setTimes[0] = " + times[0]); + System.out.println("testPrecipFinish(): writes exchangeItems[" + i + "].setTimes[1] = " + times[1]); } potETWrapper.finish(); @@ -329,7 +327,7 @@ public void testPotETFinish() throws FileNotFoundException { FileInputStream in = new FileInputStream(testFile); BufferedReader buff = new BufferedReader(new InputStreamReader(in)); String line = ""; // Initialize line. - Boolean eof = false; // End of file cache. + boolean eof = false; // End of file cache. double[] expectedTimes = new double[3]; double[] expectedValues = new double[3]; @@ -362,8 +360,8 @@ public void testPotETFinish() throws FileNotFoundException { columns[1] = columns[1].trim(); // Parse the values. - expectedTimes[index] = Double.valueOf(columns[0]); - expectedValues[index] = Double.valueOf(columns[1]); + expectedTimes[index] = Double.parseDouble(columns[0]); + expectedValues[index] = Double.parseDouble(columns[1]); System.out.println("testPotETFinish(): reads times[" + index + "] = " + expectedTimes[index]); System.out.println("testPotETFinish(): reads values[" + index + "] = " + expectedValues[index]); index = index + 1; diff --git a/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/InitialStatesWrapperTest.java b/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/InitialStatesWrapperTest.java index 83429b354..2f0434684 100644 --- a/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/InitialStatesWrapperTest.java +++ b/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/InitialStatesWrapperTest.java @@ -18,23 +18,15 @@ * along with OpenDA. If not, see . */ package org.openda.model_RainfallRunoffZhang; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.file.Files; -import java.nio.file.NoSuchFileException; -import java.nio.file.Path; -import org.openda.blackbox.interfaces.IoObjectInterface; -import org.openda.interfaces.IPrevExchangeItem; +import junit.framework.TestCase; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.OpenDaTestSupport; -import junit.framework.TestCase; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.NoSuchFileException; +import java.nio.file.Path; /** * Tester for a wrapper. The reading of a correct input file and the storing of @@ -48,13 +40,10 @@ public class InitialStatesWrapperTest extends TestCase { // Use openDA test suite. private File testRunDataDir; - private OpenDaTestSupport testData; // Class types definitions: private String fileName = "initialStatesTestInput.m"; // Needs to be created. - - // Reference ids and values. - private String id0 = "currentTime"; + private String id1 = "soilMoisture"; private String id2 = "gwStorage"; private double value0 = 33000; @@ -67,10 +56,12 @@ public class InitialStatesWrapperTest extends TestCase { protected void setUp() throws IOException { // Use openDA test utilities. This allows the test files to be stored // in a separate directory from the source code. - testData = new OpenDaTestSupport(ResultFileWrapperTest.class, "model_RainfallRunoffZhang"); + OpenDaTestSupport testData = new OpenDaTestSupport(ResultFileWrapperTest.class, "model_RainfallRunoffZhang"); testRunDataDir = testData.getTestRunDataDir(); // Write a test file. + // Reference ids and values. + String id0 = "currentTime"; String line0 = "% " + id0 + " = " + value0 + ", " + " finalTime " + " = " + value0 + System.getProperty("line.separator"); String line1 = id1 + " = " + value1 + "; % Some comment." + System.getProperty("line.separator"); // Correct input line. @@ -98,7 +89,7 @@ protected void setUp() throws IOException { /** * Cleans up test file created in setUp(). */ - protected void tearDown() throws Exception { + protected void tearDown() { try { File file = new File(testRunDataDir, fileName); Path path = file.toPath(); @@ -119,43 +110,36 @@ protected void tearDown() throws Exception { public void testReadInput() { // Creates the I/O-Object from the wrapper to be tested. - IoObjectInterface ioObject = new InitialStatesWrapper(); - String args[] = {}; + InitialStatesWrapper dataObject = new InitialStatesWrapper(); + String[] args = {fileName}; double[] expectedTimes = new double[1]; double[] expectedTimes2 = new double[1]; - double[] expectedValue = new double[1]; + double[] expectedValue; // Call to initialize -> reads the file and writes 2 Exchange items. - ioObject.initialize(testRunDataDir, fileName, args); + dataObject.initialize(testRunDataDir, args); // 2 exchange items should be present: soilMoistureExchangeItem and // gwStorageExchangeItem. - IPrevExchangeItem[] exchangeItems = ioObject.getExchangeItems(); - - for (int item = 0; item < exchangeItems.length; item++) { - if (exchangeItems[item].getId().equalsIgnoreCase(id1)) { - IPrevExchangeItem expectedExchangeItem = exchangeItems[item]; - // String getId(); - String expectedId = expectedExchangeItem.getId(); - assertEquals(id1, expectedId); + String[] exchangeItemIDs = dataObject.getExchangeItemIDs(); - // public Object getValues(); - expectedTimes = (double[]) expectedExchangeItem.getTimes(); - expectedValue = (double[]) expectedExchangeItem.getValuesAsDoubles(); + for (String id : exchangeItemIDs) { + IExchangeItem exchangeItem = dataObject.getDataObjectExchangeItem(id); + String exId = exchangeItem.getId(); + assertEquals(id, exId); + if (exId.equalsIgnoreCase(id1)) { + expectedTimes = exchangeItem.getTimes(); + expectedValue = exchangeItem.getValuesAsDoubles(); assertEquals(value1, expectedValue[0]); assertEquals(value0, expectedTimes[0]); } - if (exchangeItems[item].getId().equalsIgnoreCase(id2)) { - IPrevExchangeItem expectedExchangeItem = exchangeItems[item]; - String expectedId = expectedExchangeItem.getId(); - assertEquals(id2, expectedId); - - expectedTimes2 = (double[]) expectedExchangeItem.getTimes(); - expectedValue = (double[]) expectedExchangeItem.getValuesAsDoubles(); + if (exId.equalsIgnoreCase(id2)) { + expectedTimes2 = exchangeItem.getTimes(); + expectedValue = exchangeItem.getValuesAsDoubles(); assertEquals(value2, expectedValue[0]); assertEquals(value0, expectedTimes2[0]); - - + + } } @@ -165,36 +149,38 @@ public void testReadInput() { /** * Test whether or not the new initial states are written to file. - * @throws FileNotFoundException */ - public void testFinish() throws FileNotFoundException { + public void testFinish() { // Creates the I/O-Object from the wrapper to be tested. - IoObjectInterface initialStatesWrapper = new InitialStatesWrapper(); - String args[] = {}; + InitialStatesWrapper initialStatesWrapper = new InitialStatesWrapper(); + String[] args = {fileName}; double[] times = new double[2]; double[] values = new double[2]; double[] values2 = new double[2]; // Call to initialize -> reads the file and writes 2 Exchange items. - initialStatesWrapper.initialize(testRunDataDir, fileName, args); + initialStatesWrapper.initialize(testRunDataDir, args); // Modify times and values in exchange items - IPrevExchangeItem[] exchangeItems = initialStatesWrapper.getExchangeItems(); + String[] exchangeItemIDs = initialStatesWrapper.getExchangeItemIDs(); times[0] = value0 + 1; times[1] = value0 + 2; - for (int item = 0; item < exchangeItems.length; item++) { - if (exchangeItems[item].getId().equalsIgnoreCase(id1)) { + for (String id : exchangeItemIDs) { + IExchangeItem exchangeItem = initialStatesWrapper.getDataObjectExchangeItem(id); + String exId = exchangeItem.getId(); + assertEquals(id, exId); + if (exId.equalsIgnoreCase(id1)) { values[0] = value1 + 1; values[1] = value1 + 2; - exchangeItems[item].setValues(values); - exchangeItems[item].setTimes(times); - } else if (exchangeItems[item].getId().equalsIgnoreCase(id2)) { + exchangeItem.setValues(values); + exchangeItem.setTimes(times); + } else if (exId.equalsIgnoreCase(id2)) { values2[0] = value2 + 1; values2[1] = value2 + 2; - exchangeItems[item].setValues(values2); - exchangeItems[item].setTimes(times); - + exchangeItem.setValues(values2); + exchangeItem.setTimes(times); + } } @@ -210,7 +196,7 @@ public void testFinish() throws FileNotFoundException { FileInputStream in = new FileInputStream(testFile); BufferedReader buff = new BufferedReader(new InputStreamReader(in)); String line = ""; // Initialize line. - Boolean eof = false; // End of file cache. + boolean eof = false; // End of file cache. double[] expectedTime = new double[2]; double[] expectedSoilMoisture = new double[1]; double[] expectedGwStorage = new double[1]; @@ -236,7 +222,7 @@ public void testFinish() throws FileNotFoundException { // Now parse the line. // Remove comments at end of line. if (line.indexOf("%") > 1) { - String columns[] = line.split("%"); + String[] columns = line.split("%"); line = columns[0]; } if (line.startsWith("%")) { @@ -252,14 +238,14 @@ public void testFinish() throws FileNotFoundException { columns[3] = columns[3].trim(); // Remove comma from columns[3]. String[] tempTime = columns[3].split(","); - expectedTime[0] = Double.valueOf(tempTime[0]); + expectedTime[0] = Double.parseDouble(tempTime[0]); } else { System.out.println("InitialStatesWrapperTest.TestFinish(): Trouble reading current time."); } if (columns[4].equals("finalTime")) { columns[6] = columns[6].trim(); - expectedTime[1] = Double.valueOf(columns[6]); + expectedTime[1] = Double.parseDouble(columns[6]); } else { System.out.println("InitialStatesWrapperTest.TestFinish(): Trouble reading final time."); } @@ -279,18 +265,18 @@ public void testFinish() throws FileNotFoundException { // the beginning or the end // of the string. columns[1] = columns[1].trim(); - // Remove the semicollon at the end of the string in + // Remove the semicolon at the end of the string in // columns[1]. - String temp[] = columns[1].split(";"); + String[] temp = columns[1].split(";"); columns[1] = temp[0]; // Parse the values to the key caches in Java. // --> Add if-loops for variables to be read here. if (columns[0].equals("soilMoisture")) { - expectedSoilMoisture[0] = Double.valueOf(columns[1]); + expectedSoilMoisture[0] = Double.parseDouble(columns[1]); System.out.println(">> soilMoistureCache = " + expectedSoilMoisture[0]); } if (columns[0].equals("gwStorage")) { - expectedGwStorage[0] = Double.valueOf(columns[1]); + expectedGwStorage[0] = Double.parseDouble(columns[1]); System.out.println(">> gwStorageCache = " + expectedGwStorage[0]); } } diff --git a/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/ParametersWrapperTest.java b/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/ParametersWrapperTest.java index c9dc53c93..7d5eec098 100644 --- a/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/ParametersWrapperTest.java +++ b/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/ParametersWrapperTest.java @@ -18,23 +18,15 @@ * along with OpenDA. If not, see . */ package org.openda.model_RainfallRunoffZhang; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.file.Files; -import java.nio.file.NoSuchFileException; -import java.nio.file.Path; -import org.openda.blackbox.interfaces.IoObjectInterface; -import org.openda.interfaces.IPrevExchangeItem; +import junit.framework.TestCase; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.OpenDaTestSupport; -import junit.framework.TestCase; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.NoSuchFileException; +import java.nio.file.Path; /** * Tester for a wrapper. The reading of a correct input file and the storing of @@ -48,7 +40,6 @@ public class ParametersWrapperTest extends TestCase { // Use openDA test suite. private File testRunDataDir; - private OpenDaTestSupport testData; private String fileName = "parametersWrapperTestInput.m"; // Needs to be created. @@ -69,7 +60,7 @@ protected void setUp() throws IOException { // Use openDA test utilities. This allows the test files to be stored // in a separate directory from the source code. - testData = new OpenDaTestSupport(ResultFileWrapperTest.class, "model_RainfallRunoffZhang"); + OpenDaTestSupport testData = new OpenDaTestSupport(ResultFileWrapperTest.class, "model_RainfallRunoffZhang"); testRunDataDir = testData.getTestRunDataDir(); // Write a test file. @@ -105,7 +96,7 @@ protected void setUp() throws IOException { /** * Cleans up test file created in setUp(). */ - protected void tearDown() throws Exception { + protected void tearDown() { try { File file = new File(testRunDataDir, fileName); @@ -128,46 +119,45 @@ protected void tearDown() throws Exception { public void testReadInput() { // Creates the I/O-Object from the wrapper to be tested. - IoObjectInterface ioObject = new ParametersWrapper(); - String args[] = {}; + ParametersWrapper parametersWrapper = new ParametersWrapper(); + String[] args = {fileName}; // Call to initialize -> reads the file and writes 2 Exchange items. - ioObject.initialize(testRunDataDir, fileName, args); + parametersWrapper.initialize(testRunDataDir, args); // 2 exchange items should be present: soilMoistureExchangeItem and // gwStorageExchangeItem. - IPrevExchangeItem[] exchangeItems = ioObject.getExchangeItems(); + String[] exchangeItemIDs = parametersWrapper.getExchangeItemIDs(); - for (int item = 0; item < exchangeItems.length; item++) { - if (exchangeItems[item].getId().equalsIgnoreCase(id1)) { - IPrevExchangeItem expectedExchangeItem = exchangeItems[item]; - // String getId(); - String expectedId = expectedExchangeItem.getId(); - assertEquals(id1, expectedId); + for (String id : exchangeItemIDs) { + if (id.equalsIgnoreCase(id1)) { + IExchangeItem expectedExchangeItem = parametersWrapper.getDataObjectExchangeItem(id); + String exId = expectedExchangeItem.getId(); + assertEquals(exId,id1); // public Object getValues(); double[] expectedValue = expectedExchangeItem.getValuesAsDoubles(); assertEquals(value1, expectedValue[0]); } - if (exchangeItems[item].getId().equalsIgnoreCase(id2)) { - IPrevExchangeItem expectedExchangeItem = exchangeItems[item]; - String expectedId = expectedExchangeItem.getId(); - assertEquals(id2, expectedId); + if (id.equalsIgnoreCase(id2)) { + IExchangeItem expectedExchangeItem = parametersWrapper.getDataObjectExchangeItem(id); + String exId = expectedExchangeItem.getId(); + assertEquals(exId,id2); double[] expectedValue = expectedExchangeItem.getValuesAsDoubles(); assertEquals(value2, expectedValue[0]); } - if (exchangeItems[item].getId().equalsIgnoreCase(id3)) { - IPrevExchangeItem expectedExchangeItem = exchangeItems[item]; - String expectedId = expectedExchangeItem.getId(); - assertEquals(id3, expectedId); + if (id.equalsIgnoreCase(id3)) { + IExchangeItem expectedExchangeItem = parametersWrapper.getDataObjectExchangeItem(id); + String exId = expectedExchangeItem.getId(); + assertEquals(exId,id3); double[] expectedValue = expectedExchangeItem.getValuesAsDoubles(); assertEquals(value3, expectedValue[0]); } - if (exchangeItems[item].getId().equalsIgnoreCase(id4)) { - IPrevExchangeItem expectedExchangeItem = exchangeItems[item]; - String expectedId = expectedExchangeItem.getId(); - assertEquals(id4, expectedId); + if (id.equalsIgnoreCase(id4)) { + IExchangeItem expectedExchangeItem = parametersWrapper.getDataObjectExchangeItem(id); + String exId = expectedExchangeItem.getId(); + assertEquals(exId,id4); double[] expectedValue = expectedExchangeItem.getValuesAsDoubles(); assertEquals(value4, expectedValue[0]); @@ -183,8 +173,8 @@ public void testReadInput() { public void testFinish() throws FileNotFoundException { // Creates the I/O-Object from the wrapper to be tested. - IoObjectInterface parameterWrapper = new ParametersWrapper(); - String args[] = {}; + ParametersWrapper parameterWrapper = new ParametersWrapper(); + String[] args = {fileName}; double[] times = new double[2]; double[] values1 = new double[2]; double[] values2 = new double[2]; @@ -192,38 +182,41 @@ public void testFinish() throws FileNotFoundException { double[] values4 = new double[2]; // Call to initialize -> reads the file and writes 2 Exchange items. - parameterWrapper.initialize(testRunDataDir, fileName, args); + parameterWrapper.initialize(testRunDataDir, args); - IPrevExchangeItem[] exchangeItems = parameterWrapper.getExchangeItems(); - for (int item = 0; item < exchangeItems.length; item++) { - if (exchangeItems[item].getId().equalsIgnoreCase(id1)) { - values1 = exchangeItems[item].getValuesAsDoubles(); + String[] exchangeItemIDs = parameterWrapper.getExchangeItemIDs(); + for (String id : exchangeItemIDs) { + IExchangeItem exchangeItem = parameterWrapper.getDataObjectExchangeItem(id); + String exId = exchangeItem.getId(); + assertEquals(id, exId); + if (exId.equalsIgnoreCase(id1)) { + values1 = exchangeItem.getValuesAsDoubles(); values1[0] = values1[0] + 1; values1[1] = values1[1] + 1; - exchangeItems[item].setValues(values1); - times = exchangeItems[item].getTimes(); + exchangeItem.setValues(values1); + times = exchangeItem.getTimes(); times[0] = times[0] + 1; times[1] = times[1] + 1; - exchangeItems[item].setTimes(times); + exchangeItem.setTimes(times); System.out.println("% currentTime = " + times[0] + ", finalTime = " + times[1]); - } else if (exchangeItems[item].getId().equalsIgnoreCase(id2)) { - values2 = exchangeItems[item].getValuesAsDoubles(); + } else if (exId.equalsIgnoreCase(id2)) { + values2 = exchangeItem.getValuesAsDoubles(); values2[0] = values2[0] + 1; values2[1] = values2[1] + 1; - exchangeItems[item].setValues(values2); - exchangeItems[item].setTimes(times); - } else if (exchangeItems[item].getId().equalsIgnoreCase(id3)) { - values3 = exchangeItems[item].getValuesAsDoubles(); + exchangeItem.setValues(values2); + exchangeItem.setTimes(times); + } else if (exId.equalsIgnoreCase(id3)) { + values3 = exchangeItem.getValuesAsDoubles(); values3[0] = values3[0] + 0.4; values3[1] = values3[1] + 0.4; - exchangeItems[item].setValues(values3); - exchangeItems[item].setTimes(times); - } else if (exchangeItems[item].getId().equalsIgnoreCase(id4)) { - values4 = exchangeItems[item].getValuesAsDoubles(); + exchangeItem.setValues(values3); + exchangeItem.setTimes(times); + } else if (exId.equalsIgnoreCase(id4)) { + values4 = exchangeItem.getValuesAsDoubles(); values4[0] = values4[0] - 0.4; values4[1] = values4[1] - 0.4; - exchangeItems[item].setValues(values4); - exchangeItems[item].setTimes(times); + exchangeItem.setValues(values4); + exchangeItem.setTimes(times); } } @@ -238,7 +231,7 @@ public void testFinish() throws FileNotFoundException { FileInputStream in = new FileInputStream(testFile); BufferedReader buff = new BufferedReader(new InputStreamReader(in)); String line = ""; // Initialize line. - Boolean eof = false; // End of file cache. + boolean eof = false; // End of file cache. double[] expectedTime = new double[1]; double[] expectedParam_d = new double[1]; double[] expectedParam_Smax = new double[1]; @@ -265,7 +258,7 @@ public void testFinish() throws FileNotFoundException { // Now parse the line. // Remove comments at end of line. if (line.indexOf("%") > 1) { - String columns[] = line.split("%"); + String[] columns = line.split("%"); line = columns[0]; } if (line.startsWith("%")) { @@ -282,7 +275,7 @@ public void testFinish() throws FileNotFoundException { // Remove comma from columns[3]. String[] tempTime = columns[3].split(","); System.out.println(">> Parameters : currentTime = " + tempTime[0]); - expectedTime[0] = Double.valueOf(tempTime[0]); + expectedTime[0] = Double.parseDouble(tempTime[0]); } else { System.out.println("ParametersWrapper.testFinish(): trouble reading current time."); } @@ -305,25 +298,25 @@ public void testFinish() throws FileNotFoundException { //System.out.println("dbg1 - key:"+columns[0]+" = value:"+columns[1]); // Remove the semicollon at the end of the string in // columns[1]. - String temp[] = columns[1].split(";"); + String[] temp = columns[1].split(";"); columns[1] = temp[0]; // Parse the values to the key caches in Java. // --> Add if-loops for variables to be read here. if (columns[0].equals("parameter_d")) { - expectedParam_d[0] = Double.valueOf(columns[1]); + expectedParam_d[0] = Double.parseDouble(columns[1]); System.out.println("expectedParam_d = " + expectedParam_d[0]); } if (columns[0].equals("parameter_Smax")) { - expectedParam_Smax[0] = Double.valueOf(columns[1]); + expectedParam_Smax[0] = Double.parseDouble(columns[1]); System.out.println("expectedParam_Smax = " + expectedParam_Smax[0]); } // System.out.println("2 - key:"+columns[0]+" = value:"+columns[1]); if (columns[0].equals("parameter_alpha1")) { - expectedParam_a1[0] = Double.valueOf(columns[1]); + expectedParam_a1[0] = Double.parseDouble(columns[1]); System.out.println("expectedParam_a1 = " + expectedParam_a1[0]); } if (columns[0].equals("parameter_alpha2")) { - expectedParam_a2[0] = Double.valueOf(columns[1]); + expectedParam_a2[0] = Double.parseDouble(columns[1]); System.out.println("expectedParam_a2 = " + expectedParam_a2[0]); } } diff --git a/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/ResultFileWrapperTest.java b/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/ResultFileWrapperTest.java index 725e723ef..2b13535ff 100644 --- a/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/ResultFileWrapperTest.java +++ b/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/ResultFileWrapperTest.java @@ -29,7 +29,7 @@ import org.openda.exchange.DoublesExchangeItem; import org.openda.exchange.timeseries.TimeSeries; import org.openda.exchange.timeseries.TimeSeriesFormatter; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.OpenDaTestSupport; import junit.framework.TestCase; @@ -45,7 +45,6 @@ public class ResultFileWrapperTest extends TestCase { // Use openDA test suite. private File testRunDataDir; - private OpenDaTestSupport testData; private String fileName = "resultFileWrapperTestInput.txt"; // Needs to be created. @@ -66,7 +65,7 @@ protected void setUp() throws IOException { // Use openDA test utilities. This allows the test files to be stored // in a separate directory from the source code. - testData = new OpenDaTestSupport(ResultFileWrapperTest.class, "model_RainfallRunoffZhang"); + OpenDaTestSupport testData = new OpenDaTestSupport(ResultFileWrapperTest.class, "model_RainfallRunoffZhang"); testRunDataDir = testData.getTestRunDataDir(); // Write a test file. @@ -101,7 +100,7 @@ protected void setUp() throws IOException { /** * Cleans up (deletes) test file created in setUp(). */ - protected void tearDown() throws Exception { + protected void tearDown() { try { File file = new File(testRunDataDir, fileName); @@ -125,148 +124,49 @@ public void testReadInput() { // Creates the I/O-Object from the wrapper to be tested. ResultFileWrapper resultFileWrapper = new ResultFileWrapper(); - String args[] = {}; + String[] args = {fileName}; // Call to initialize -> reads the file and writes exchange items. - resultFileWrapper.initialize(testRunDataDir, fileName, args); + resultFileWrapper.initialize(testRunDataDir, args); - IPrevExchangeItem[] resultExchangeItems = resultFileWrapper.getExchangeItems(); + String[] exchangeItemIDs = resultFileWrapper.getExchangeItemIDs(); // Iterate through all found exchange items. - for(int item=0;item timesVector = new Vector(); - Vector valuesVector = new Vector(); - double[] times = new double[4]; - double[] values = new double[4]; - - // Call to initialize -> reads the file and writes 2 Exchange items. - resultWrapper.initialize(workingDir, fileName, args); - - // Modify times and values in exchange items - IPrevExchangeItem[] exchangeItems = resultWrapper.getExchangeItems(); - times[0] = time1 + 10; - times[1] = time2 + 10; - times[2] = time3 + 10; - times[3] = time4 + 10; - for (int item = 0; item < exchangeItems.length; item++) { - values[0] = value1 + 1; - values[1] = value1 + 2; - values[2] = value1 + 3; - values[3] = value1 + 4; - exchangeItems[item].setValues(values); - exchangeItems[item].setTimes(times); - } - - resultWrapper.finish(); - - // Read in the file again. - // Create nested reader. - File testFile = new File(workingDir, fileName); - try{ - FileInputStream in = new FileInputStream(testFile); - BufferedReader buff = new BufferedReader(new InputStreamReader(in)); - String line = ""; // Initialize line. - Boolean eof = false; // End of file cache. - - while (!eof) { - // Read line. - line = buff.readLine(); - // System.out.println("line : " + line); - // Test for end of file. - if (line == null) { - eof = true; - } else if (line.startsWith("%")) { - // If the lines starts with comment or meta data, do nothing. - continue; - } else if (line.startsWith("#")) { - continue; - } else if (line.equals("")) { - // If the line is empty, do nothing. - continue; - } else { - // If the end of the file is not reached yet split line and store - // data. - String[] columns = line.split("\\s"); - - if (columns.length != 2) { - buff.close(); - in.close(); - throw new RuntimeException("Reading TimeSeries : Wrong number of arguments : '" + line + "'"); - } - - // Now parse the line. - columns[0] = columns[0].trim(); - columns[1] = columns[1].trim(); - - timesVector.add(Double.valueOf(columns[0])); // Values are added to dynamic Vector. - valuesVector.add(Double.valueOf(columns[1])); - } - } - // Close the writers. - buff.close(); - in.close(); - } catch (IOException e) { - System.out.println("IOException in WrapperTest -> testFinish()"); - e.printStackTrace(); - } - - assertEquals(times[0],timesVector.get(0)); - assertEquals(times[1],timesVector.get(1)); - assertEquals(times[2],timesVector.get(2)); - assertEquals(times[3],timesVector.get(3)); - assertEquals(values[0],valuesVector.get(0)); - assertEquals(values[1],valuesVector.get(1)); - assertEquals(values[2],valuesVector.get(2)); - assertEquals(values[3],valuesVector.get(3)); - */ - } - } diff --git a/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/TimesWrapperTest.java b/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/TimesWrapperTest.java index 7046916b5..0950223cc 100644 --- a/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/TimesWrapperTest.java +++ b/model_RainfallRunoffZhang/java/test/org/openda/model_RainfallRunoffZhang/TimesWrapperTest.java @@ -18,22 +18,15 @@ * along with OpenDA. If not, see . */ package org.openda.model_RainfallRunoffZhang; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.file.Files; -import java.nio.file.NoSuchFileException; -import java.nio.file.Path; -import org.openda.blackbox.interfaces.IoObjectInterface; -import org.openda.interfaces.IPrevExchangeItem; +import junit.framework.TestCase; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.OpenDaTestSupport; -import junit.framework.TestCase; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.NoSuchFileException; +import java.nio.file.Path; /** * Tester for a wrapper. The reading of a correct input file and the storing of @@ -48,7 +41,6 @@ public class TimesWrapperTest extends TestCase { // Use openDA test suite. private File testRunDataDir; - private OpenDaTestSupport testData; private String fileName = "timesWrapperTestInput.m"; // Needs to be created. @@ -67,7 +59,7 @@ protected void setUp() throws IOException { // Use openDA test utilities. This allows the test files to be stored // in a separate directory from the source code. - testData = new OpenDaTestSupport(ResultFileWrapperTest.class, "model_RainfallRunoffZhang"); + OpenDaTestSupport testData = new OpenDaTestSupport(ResultFileWrapperTest.class, "model_RainfallRunoffZhang"); testRunDataDir = testData.getTestRunDataDir(); // Write a test input file. @@ -94,7 +86,7 @@ protected void setUp() throws IOException { /** * Cleans up test file created in setUp(). */ - protected void tearDown() throws Exception { + protected void tearDown() { try { File file = new File(testRunDataDir, fileName); Path path = file.toPath(); @@ -116,39 +108,29 @@ protected void tearDown() throws Exception { public void testReadInput() { // Creates the I/O-Object from the wrapper to be tested. - IoObjectInterface ioObject = new TimesWrapper(); - String args[] = {}; + TimesWrapper timesWrapper = new TimesWrapper(); + String[] args = {fileName}; // Call to initialize -> reads the file and writes 2 Exchange items. - ioObject.initialize(testRunDataDir, fileName, args); + timesWrapper.initialize(testRunDataDir, args); // 2 exchange items should be present: soilMoistureExchangeItem and // gwStorageExchangeItem. - IPrevExchangeItem[] exchangeItems = ioObject.getExchangeItems(); - - for (int item = 0; item < exchangeItems.length; item++) { - if (exchangeItems[item].getId().equalsIgnoreCase(id1)) { - IPrevExchangeItem expectedExchangeItem = exchangeItems[item]; - String expectedId = expectedExchangeItem.getId(); - assertEquals(id1, expectedId); - - // public Object getValues(); - double[] expectedValue = expectedExchangeItem.getValuesAsDoubles(); + String[] exchangeItemIDs = timesWrapper.getExchangeItemIDs(); + + for (String id : exchangeItemIDs) { + IExchangeItem exchangeItem = timesWrapper.getDataObjectExchangeItem(id); + String exId = exchangeItem.getId(); + assertEquals(id, exId); + if (exId.equalsIgnoreCase(id1)) { + double[] expectedValue = exchangeItem.getValuesAsDoubles(); assertEquals(value1, expectedValue[0]); } - if (exchangeItems[item].getId().equalsIgnoreCase(id2)) { - IPrevExchangeItem expectedExchangeItem = exchangeItems[item]; - String expectedId = expectedExchangeItem.getId(); - assertEquals(id2, expectedId); - - double[] expectedValue = expectedExchangeItem.getValuesAsDoubles(); + if (exId.equalsIgnoreCase(id2)) { + double[] expectedValue = exchangeItem.getValuesAsDoubles(); assertEquals(value2, expectedValue[0]); } - if (exchangeItems[item].getId().equalsIgnoreCase(id3)) { - IPrevExchangeItem expectedExchangeItem = exchangeItems[item]; - String expectedId = expectedExchangeItem.getId(); - assertEquals(id3, expectedId); - - double[] expectedValue = expectedExchangeItem.getValuesAsDoubles(); + if (exId.equalsIgnoreCase(id3)) { + double[] expectedValue = exchangeItem.getValuesAsDoubles(); assertEquals(value3, expectedValue[0]); } } @@ -163,31 +145,31 @@ public void testFinish() { double[] expectedSimTimeStep = new double[1]; double[] expectedFinalTime = new double[1]; - IoObjectInterface timesWrapper = new TimesWrapper(); - String args[] = {}; - timesWrapper.initialize(testRunDataDir, fileName, args); + TimesWrapper timesWrapper = new TimesWrapper(); + String[] args = {fileName}; + timesWrapper.initialize(testRunDataDir, args); - IPrevExchangeItem[] exchangeItems = timesWrapper.getExchangeItems(); + String[] exchangeItemIDs = timesWrapper.getExchangeItemIDs(); // modify the entries of the exchange items. - for (int item = 0 ; item < exchangeItems.length; item++) { - if (exchangeItems[item].getId().equalsIgnoreCase(id1)) { - IPrevExchangeItem ei = exchangeItems[item]; - expectedCurrentTime = ei.getValuesAsDoubles(); + for (String id : exchangeItemIDs) { + IExchangeItem exchangeItem = timesWrapper.getDataObjectExchangeItem(id); + String exId = exchangeItem.getId(); + assertEquals(id, exId); + if (exId.equalsIgnoreCase(id1)) { + expectedCurrentTime = exchangeItem.getValuesAsDoubles(); expectedCurrentTime[0] = 2; - ei.setValuesAsDoubles(expectedCurrentTime); + exchangeItem.setValuesAsDoubles(expectedCurrentTime); } - if (exchangeItems[item].getId().equalsIgnoreCase(id2)) { - IPrevExchangeItem ei = exchangeItems[item]; - expectedSimTimeStep = ei.getValuesAsDoubles(); + if (exId.equalsIgnoreCase(id2)) { + expectedSimTimeStep = exchangeItem.getValuesAsDoubles(); expectedSimTimeStep[0] = 100; - ei.setValuesAsDoubles(expectedSimTimeStep); + exchangeItem.setValuesAsDoubles(expectedSimTimeStep); } - if (exchangeItems[item].getId().equalsIgnoreCase(id3)) { - IPrevExchangeItem ei = exchangeItems[item]; - expectedFinalTime = ei.getValuesAsDoubles(); + if (exId.equalsIgnoreCase(id3)) { + expectedFinalTime = exchangeItem.getValuesAsDoubles(); expectedFinalTime[0] = 21; - ei.setValuesAsDoubles(expectedFinalTime); + exchangeItem.setValuesAsDoubles(expectedFinalTime); } } @@ -204,8 +186,8 @@ public void testFinish() { try{ FileInputStream in = new FileInputStream(namelist); BufferedReader buff = new BufferedReader(new InputStreamReader(in)); - String line = ""; // Initialize line. - Boolean eof = false; // End of file cache. + String line; // Initialize line. + boolean eof = false; // End of file cache. // While End of file is not reached yet do the following: while (!eof) { @@ -222,7 +204,7 @@ public void testFinish() { // Now parse the line. // Remove comments at end of line. if (line.indexOf("%") > 1) { - String columns[] = line.split("%"); + String[] columns = line.split("%"); line = columns[0]; } if (line.startsWith("%")) { @@ -237,20 +219,20 @@ public void testFinish() { // of the string. columns[1] = columns[1].trim(); // Remove the semicollon at the end of the string in columns[1]. - String temp[] = columns[1].split(";"); + String[] temp = columns[1].split(";"); columns[1] = temp[0]; // Parse the values to the key caches in Java. // --> Add if-loops for variables to be read here. if (columns[0].equals("currentTime")) { - readCurrentTime = Double.valueOf(columns[1]); + readCurrentTime = Double.parseDouble(columns[1]); } if (columns[0].equals("simulationTimeStep")) { - readSimulationTimeStep = Double.valueOf(columns[1]); + readSimulationTimeStep = Double.parseDouble(columns[1]); } if (columns[0].equals("finalTime")) { - readFinalTime = Double.valueOf(columns[1]); + readFinalTime = Double.parseDouble(columns[1]); } } diff --git a/model_RainfallRunoffZhang/tests/model/WrapperConfig.xml b/model_RainfallRunoffZhang/tests/model/WrapperConfig.xml index acc1e0e55..f57638cf2 100644 --- a/model_RainfallRunoffZhang/tests/model/WrapperConfig.xml +++ b/model_RainfallRunoffZhang/tests/model/WrapperConfig.xml @@ -42,46 +42,46 @@ - + %inputFileInitialStates% initialStates %instanceDir%%instanceNumber% - + - + %inputFileParameters% parameters %instanceDir%%instanceNumber% - + - + %inputFileTimes% timeConfig %instanceDir%%instanceNumber% - + - + %outputFile% output %instanceDir%%instanceNumber% - + - + %forcingPrecipFile% forcingPrecip %instanceDir%%instanceNumber% - + - + %forcingPotETFile% forcingPotET %instanceDir%%instanceNumber% - + diff --git a/model_bmi/java/src/org/openda/model_bmi/BmiModelInstance.java b/model_bmi/java/src/org/openda/model_bmi/BmiModelInstance.java index d438bb717..cfa52608f 100644 --- a/model_bmi/java/src/org/openda/model_bmi/BmiModelInstance.java +++ b/model_bmi/java/src/org/openda/model_bmi/BmiModelInstance.java @@ -29,7 +29,7 @@ import org.openda.exchange.TimeInfo; import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.*; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; import org.openda.localization.LocalizationDomainsSimpleModel; import org.openda.utils.Instance; import org.openda.utils.Results; @@ -187,17 +187,17 @@ private static Map createExchangeItems(BMI model, double Map result = new HashMap(); for (String variable : inputVars) { - BmiOutputExchangeItem item = new BmiOutputExchangeItem(variable, IPrevExchangeItem.Role.Input, model, modelMissingValue); + BmiOutputExchangeItem item = new BmiOutputExchangeItem(variable, IExchangeItem.Role.Input, model, modelMissingValue); result.put(variable, item); } for (String variable : outputVars) { - BmiOutputExchangeItem item = new BmiOutputExchangeItem(variable, IPrevExchangeItem.Role.Output, model, modelMissingValue); + BmiOutputExchangeItem item = new BmiOutputExchangeItem(variable, IExchangeItem.Role.Output, model, modelMissingValue); result.put(variable, item); } for (String variable : inoutVars) { - BmiOutputExchangeItem item = new BmiOutputExchangeItem(variable, IPrevExchangeItem.Role.InOut, model, modelMissingValue); + BmiOutputExchangeItem item = new BmiOutputExchangeItem(variable, IExchangeItem.Role.InOut, model, modelMissingValue); result.put(variable, item); } return result; @@ -294,7 +294,7 @@ public IExchangeItem getDataObjectExchangeItem(String exchangeItemId) { return exchangeItem; } - public IPrevExchangeItem getExchangeItem(String exchangeItemID) { + public IExchangeItem getExchangeItem(String exchangeItemID) { if (inOutputMode && bufferedExchangeItems !=null && bufferedExchangeItems.containsKey(exchangeItemID)) { return bufferedExchangeItems.get(exchangeItemID); } diff --git a/model_bmi/java/src/org/openda/model_bmi/BmiOutputExchangeItem.java b/model_bmi/java/src/org/openda/model_bmi/BmiOutputExchangeItem.java index ef792ec15..563bc5378 100644 --- a/model_bmi/java/src/org/openda/model_bmi/BmiOutputExchangeItem.java +++ b/model_bmi/java/src/org/openda/model_bmi/BmiOutputExchangeItem.java @@ -31,7 +31,6 @@ import org.openda.interfaces.IArray; import org.openda.interfaces.IExchangeItem; import org.openda.interfaces.IGeometryInfo; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.interfaces.IQuantityInfo; import org.openda.interfaces.ITimeInfo; import org.openda.interfaces.IVector; @@ -52,7 +51,7 @@ public class BmiOutputExchangeItem implements IExchangeItem { private static final long serialVersionUID = 1L; private final String variableName; - private final IPrevExchangeItem.Role role; + private final IExchangeItem.Role role; private final String type; private final BMI model; private final IQuantityInfo quantityInfo; @@ -66,7 +65,7 @@ public class BmiOutputExchangeItem implements IExchangeItem { * @param model * @throws BMIModelException */ - public BmiOutputExchangeItem(String variableName, IPrevExchangeItem.Role role, BMI model, double modelMissingValue) throws BMIModelException { + public BmiOutputExchangeItem(String variableName, IExchangeItem.Role role, BMI model, double modelMissingValue) throws BMIModelException { this.modelMissingValue = modelMissingValue; if (variableName == null) throw new IllegalArgumentException("variableName == null"); if (role == null) throw new IllegalArgumentException("role == null"); diff --git a/model_bmi/java/test/org/openda/model_bmi/testData/wflowBmiModelTest/openda_config/Murrumbegee/Murrumbegee_stochObsConfig.xml b/model_bmi/java/test/org/openda/model_bmi/testData/wflowBmiModelTest/openda_config/Murrumbegee/Murrumbegee_stochObsConfig.xml index 71c85c027..04aff351c 100644 --- a/model_bmi/java/test/org/openda/model_bmi/testData/wflowBmiModelTest/openda_config/Murrumbegee/Murrumbegee_stochObsConfig.xml +++ b/model_bmi/java/test/org/openda/model_bmi/testData/wflowBmiModelTest/openda_config/Murrumbegee/Murrumbegee_stochObsConfig.xml @@ -1,5 +1,5 @@ - @@ -9,10 +9,10 @@ - + ../../observations.nc true false - + - + diff --git a/model_bmi/model_bmi.iml b/model_bmi/model_bmi.iml index 30a591cfb..1c9955a6f 100644 --- a/model_bmi/model_bmi.iml +++ b/model_bmi/model_bmi.iml @@ -34,15 +34,6 @@ - - - - - - - - - diff --git a/model_damflow/java/src/org/openda/model_damflow/DupuitBHOFile.java b/model_damflow/java/src/org/openda/model_damflow/DupuitBHOFile.java index f16ebe2e1..b2bc1ae56 100644 --- a/model_damflow/java/src/org/openda/model_damflow/DupuitBHOFile.java +++ b/model_damflow/java/src/org/openda/model_damflow/DupuitBHOFile.java @@ -159,7 +159,7 @@ public String[] getExchangeItemIDs() { } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { throw new UnsupportedOperationException("Class Name : org.openda.model_damflow.DupuitBHOFile - Method Name : getExchangeItemIDs"); } diff --git a/model_damflow/java/src/org/openda/model_damflow/DupuitCFile.java b/model_damflow/java/src/org/openda/model_damflow/DupuitCFile.java index 370dccbf6..6d6a15a6c 100644 --- a/model_damflow/java/src/org/openda/model_damflow/DupuitCFile.java +++ b/model_damflow/java/src/org/openda/model_damflow/DupuitCFile.java @@ -136,7 +136,7 @@ public String[] getExchangeItemIDs() { } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { throw new UnsupportedOperationException("Class Name : org.openda.model_damflow.DupuitCFile - Method Name : getExchangeItemIDs"); } diff --git a/model_damflow/java/src/org/openda/model_damflow/DupuitCFileExchangeItem.java b/model_damflow/java/src/org/openda/model_damflow/DupuitCFileExchangeItem.java index c3dc480fa..4eb2e02b1 100644 --- a/model_damflow/java/src/org/openda/model_damflow/DupuitCFileExchangeItem.java +++ b/model_damflow/java/src/org/openda/model_damflow/DupuitCFileExchangeItem.java @@ -38,7 +38,7 @@ public DupuitCFileExchangeItem(String id, DupuitCFile dupuitCFile) { public Role getRole() { - return IPrevExchangeItem.Role.InOut; + return IExchangeItem.Role.InOut; } diff --git a/model_damflow/java/src/org/openda/model_damflow/DupuitGFile.java b/model_damflow/java/src/org/openda/model_damflow/DupuitGFile.java index 28c41d5d0..8af76fe90 100644 --- a/model_damflow/java/src/org/openda/model_damflow/DupuitGFile.java +++ b/model_damflow/java/src/org/openda/model_damflow/DupuitGFile.java @@ -21,7 +21,6 @@ import org.openda.blackbox.config.BBUtils; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import java.io.*; import java.util.ArrayList; @@ -196,7 +195,7 @@ public String[] getExchangeItemIDs() { } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { throw new UnsupportedOperationException("Class Name : org.openda.model_damflow.DupuitGFile - Method Name : getExchangeItemIDs"); } diff --git a/model_damflow/java/src/org/openda/model_damflow/DupuitPFile.java b/model_damflow/java/src/org/openda/model_damflow/DupuitPFile.java index ce6b35bf0..35f31518c 100644 --- a/model_damflow/java/src/org/openda/model_damflow/DupuitPFile.java +++ b/model_damflow/java/src/org/openda/model_damflow/DupuitPFile.java @@ -21,7 +21,6 @@ import org.openda.blackbox.config.BBUtils; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import java.io.*; import java.util.Locale; @@ -61,7 +60,7 @@ public String[] getExchangeItemIDs() { } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { throw new UnsupportedOperationException("Class Name : org.openda.model_damflow.DupuitPFile - Method Name : getExchangeItemIDs"); } diff --git a/model_damflow/java/src/org/openda/model_damflow/DupuitPFileExchangeItem.java b/model_damflow/java/src/org/openda/model_damflow/DupuitPFileExchangeItem.java index 7c29fae67..bdeafb4ec 100644 --- a/model_damflow/java/src/org/openda/model_damflow/DupuitPFileExchangeItem.java +++ b/model_damflow/java/src/org/openda/model_damflow/DupuitPFileExchangeItem.java @@ -39,7 +39,7 @@ public DupuitPFileExchangeItem(String id, DupuitPFile dupuitPFile) { public Role getRole() { - return IPrevExchangeItem.Role.InOut; + return IExchangeItem.Role.InOut; } diff --git a/model_damflow/tests/test1/stochModel/damflowWrapper.xml b/model_damflow/tests/test1/stochModel/damflowWrapper.xml index b5c2edadb..0988afaa0 100644 --- a/model_damflow/tests/test1/stochModel/damflowWrapper.xml +++ b/model_damflow/tests/test1/stochModel/damflowWrapper.xml @@ -38,35 +38,35 @@ - + %inputFileName%.C000 dupuitC - + - + %inputFileName%.P dupuitP - + - + %inputFileName%.O dupuitO - + - + %inputFileName%.B dupuitB - + - + %inputFileName%.G dupuitG - + diff --git a/model_damflow/tests/test1/stochObserver/damflowStochObsConfig.xml b/model_damflow/tests/test1/stochObserver/damflowStochObsConfig.xml index 14aa41040..d7cc82475 100644 --- a/model_damflow/tests/test1/stochObserver/damflowStochObsConfig.xml +++ b/model_damflow/tests/test1/stochObserver/damflowStochObsConfig.xml @@ -1,9 +1,9 @@ - + stochObsUncertainties.xml - + observ/dupuit.H - - + + diff --git a/model_damflow/tests/test2/stochModel/damflowWrapper.xml b/model_damflow/tests/test2/stochModel/damflowWrapper.xml index 641360d2e..e70600422 100644 --- a/model_damflow/tests/test2/stochModel/damflowWrapper.xml +++ b/model_damflow/tests/test2/stochModel/damflowWrapper.xml @@ -28,41 +28,41 @@ - + %inputFileName%.C000 state0 - + - + %inputFileName%.C001 state1 - + - + %inputFileName%.P timeInfo - + - + %inputFileName%.O output - + - + %inputFileName%.B input - + - + %inputFileName%.G materialProperty - + diff --git a/model_damflow/tests/test2/stochObserver/damflowStochObsConfig.xml b/model_damflow/tests/test2/stochObserver/damflowStochObsConfig.xml index 14aa41040..d7cc82475 100644 --- a/model_damflow/tests/test2/stochObserver/damflowStochObsConfig.xml +++ b/model_damflow/tests/test2/stochObserver/damflowStochObsConfig.xml @@ -1,9 +1,9 @@ - + stochObsUncertainties.xml - + observ/dupuit.H - - + + diff --git a/model_damflow/tests/test3/stochModel/damflowWrapper.xml b/model_damflow/tests/test3/stochModel/damflowWrapper.xml index 5399f8f63..210caa46f 100644 --- a/model_damflow/tests/test3/stochModel/damflowWrapper.xml +++ b/model_damflow/tests/test3/stochModel/damflowWrapper.xml @@ -37,35 +37,35 @@ - + %inputFileName%.C000 dupuitC - + - + %inputFileName%.P dupuitP - + - + %inputFileName%.O dupuitO - + - + %inputFileName%.B dupuitB - + - + %inputFileName%.G dupuitG - + diff --git a/model_damflow/tests/test3/stochObserver/damflowStochObsConfig.xml b/model_damflow/tests/test3/stochObserver/damflowStochObsConfig.xml index 14aa41040..d7cc82475 100644 --- a/model_damflow/tests/test3/stochObserver/damflowStochObsConfig.xml +++ b/model_damflow/tests/test3/stochObserver/damflowStochObsConfig.xml @@ -1,9 +1,9 @@ - + stochObsUncertainties.xml - + observ/dupuit.H - - + + diff --git a/model_delft3d/java/model_delft3d.iml b/model_delft3d/java/model_delft3d.iml index d0bb37654..6de2f842d 100644 --- a/model_delft3d/java/model_delft3d.iml +++ b/model_delft3d/java/model_delft3d.iml @@ -26,15 +26,6 @@ - - - - - - - - - diff --git a/model_delft3d/java/src/org/openda/model_delft3d/D3dAstroComponentFiles.java b/model_delft3d/java/src/org/openda/model_delft3d/D3dAstroComponentFiles.java index 5076b964e..0d7832626 100644 --- a/model_delft3d/java/src/org/openda/model_delft3d/D3dAstroComponentFiles.java +++ b/model_delft3d/java/src/org/openda/model_delft3d/D3dAstroComponentFiles.java @@ -20,8 +20,9 @@ package org.openda.model_delft3d; -import org.openda.blackbox.interfaces.IoObjectInterface; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IDataObject; +import org.openda.interfaces.IExchangeItem; + import java.io.File; import java.util.ArrayList; import java.util.List; @@ -29,20 +30,23 @@ /** * Combination of D3D astro file (bca) and its corresponding correction file (cor) */ -public class D3dAstroComponentFiles implements IoObjectInterface { +public class D3dAstroComponentFiles implements IDataObject { - ModelDefinitionFile modelDefinitionFile = null; - D3dAstroComponentsFile bcaComponents = null; - D3dAstroComponentsFile corComponents = null; + private ModelDefinitionFile modelDefinitionFile = null; + private D3dAstroComponentsFile bcaComponents = null; + private D3dAstroComponentsFile corComponents = null; private List exchangeItems = new ArrayList(); + private String[] ids; - public void initialize(File workingDir, String mdFileName, String[] arguments) { - if (arguments != null && arguments.length > 0) { - throw new RuntimeException("No arguments expected"); + @Override + public void initialize(File workingDir, String[] arguments) { + if (arguments != null && arguments.length > 1) { + throw new RuntimeException("No arguments except filename expected"); } - modelDefinitionFile = ModelDefinitionFile.getModelDefinitionFile(workingDir, mdFileName); + // TODO: check roles + modelDefinitionFile = ModelDefinitionFile.getModelDefinitionFile(workingDir, arguments[0]); File bcaFile = modelDefinitionFile.getFieldFile(ModelDefinitionFile.BC_ASTRONOMIC, true); File corFile = modelDefinitionFile.getFieldFile(ModelDefinitionFile.BC_ASTRO_CORR, false); @@ -60,13 +64,34 @@ public void initialize(File workingDir, String mdFileName, String[] arguments) { astroStation.getId(), D3dAstroExchangeItem.phaseString, astroComponent)); } } + int size = exchangeItems.size(); + ids = new String[size]; + for (int i = 0; i < size; i++) { + ids[i] = exchangeItems.get(i).getId(); + } } - public IPrevExchangeItem[] getExchangeItems() { - return exchangeItems.toArray(new IPrevExchangeItem[exchangeItems.size()]); - } + @Override + public String[] getExchangeItemIDs() { + return ids; + } + + @Override + // FIXME: loop over exchange items and check role + public String[] getExchangeItemIDs(IExchangeItem.Role role) { + return getExchangeItemIDs(); + } + + @Override + public IExchangeItem getDataObjectExchangeItem(String exchangeItemID) { + for (int i = 0; i < ids.length; i++) { + if (ids[i].equals(exchangeItemID)) return exchangeItems.get(i); + } + return null; + } - public void finish() { + @Override + public void finish() { bcaComponents.write(modelDefinitionFile.getFieldFile(ModelDefinitionFile.BC_ASTRONOMIC, true)); if (corComponents != null) { corComponents.write(modelDefinitionFile.getFieldFile(ModelDefinitionFile.BC_ASTRO_CORR, true)); diff --git a/model_delft3d/java/src/org/openda/model_delft3d/D3dAstroComponentsFile.java b/model_delft3d/java/src/org/openda/model_delft3d/D3dAstroComponentsFile.java index 8126be527..eec2c405d 100644 --- a/model_delft3d/java/src/org/openda/model_delft3d/D3dAstroComponentsFile.java +++ b/model_delft3d/java/src/org/openda/model_delft3d/D3dAstroComponentsFile.java @@ -29,7 +29,7 @@ */ public class D3dAstroComponentsFile { - private List astroStations = new ArrayList(); + private List astroStations = new ArrayList<>(); public D3dAstroComponentsFile(File componentsFile) { try { diff --git a/model_delft3d/java/src/org/openda/model_delft3d/D3dAstroExchangeItem.java b/model_delft3d/java/src/org/openda/model_delft3d/D3dAstroExchangeItem.java index 845ce8196..7601e61b2 100644 --- a/model_delft3d/java/src/org/openda/model_delft3d/D3dAstroExchangeItem.java +++ b/model_delft3d/java/src/org/openda/model_delft3d/D3dAstroExchangeItem.java @@ -20,12 +20,12 @@ package org.openda.model_delft3d; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.*; /** * Exchange Item representing a D3D astro component or correction */ -public class D3dAstroExchangeItem implements IPrevExchangeItem { +public class D3dAstroExchangeItem implements IExchangeItem { private String id; private D3dAstroComponent astroComponent; @@ -57,9 +57,7 @@ public Class getValueType() { return double.class; } - public Role getRole() { - return IPrevExchangeItem.Role.InOut; - } + public Role getRole() { return IExchangeItem.Role.InOut; } public Object getValues() { if (astroComponent != null) { @@ -141,5 +139,30 @@ public void setTimes(double[] times) { throw new RuntimeException(this.getClass().getName() + "setTimes(): time stamps can not be set"); } + @Override + public void copyValuesFromItem(IExchangeItem sourceItem) { + throw new RuntimeException("org.openda.model_delft3d.D3dAstroExchangeItem.copyValuesFromItem not implemented"); + } + + @Override + public ITimeInfo getTimeInfo() { + throw new RuntimeException("org.openda.model_delft3d.D3dAstroExchangeItem.getTimeInfo not implemented"); + } + + @Override + public IQuantityInfo getQuantityInfo() { + throw new RuntimeException("org.openda.model_delft3d.D3dAstroExchangeItem.getQuantityInfo not implemented"); + } + + @Override + public IGeometryInfo getGeometryInfo() { + throw new RuntimeException("org.openda.model_delft3d.D3dAstroExchangeItem.getGeometryInfo not implemented"); + } + + @Override + public ValueType getValuesType() { + throw new RuntimeException("org.openda.model_delft3d.D3dAstroExchangeItem.getValuesType not implemented"); + } + } diff --git a/model_delft3d/java/src/org/openda/model_delft3d/D3dBctExchangeItem.java b/model_delft3d/java/src/org/openda/model_delft3d/D3dBctExchangeItem.java index a59495079..8dd1aeac6 100644 --- a/model_delft3d/java/src/org/openda/model_delft3d/D3dBctExchangeItem.java +++ b/model_delft3d/java/src/org/openda/model_delft3d/D3dBctExchangeItem.java @@ -1,8 +1,11 @@ package org.openda.model_delft3d; -import org.openda.interfaces.*; +import org.openda.interfaces.IExchangeItem; +import org.openda.interfaces.IGeometryInfo; +import org.openda.interfaces.IQuantityInfo; +import org.openda.interfaces.ITimeInfo; -public class D3dBctExchangeItem implements IPrevExchangeItem, IExchangeItem { +public class D3dBctExchangeItem implements IExchangeItem { private final String id; private double[] values; private final double[] times; @@ -101,8 +104,4 @@ public Object getValues() { return null; } - @Override - public Class getValueType() { - return null; - } } diff --git a/model_delft3d/java/src/org/openda/model_delft3d/D3dBctFileDataObject.java b/model_delft3d/java/src/org/openda/model_delft3d/D3dBctFileDataObject.java index dfbde5dd4..dfabbe4c7 100644 --- a/model_delft3d/java/src/org/openda/model_delft3d/D3dBctFileDataObject.java +++ b/model_delft3d/java/src/org/openda/model_delft3d/D3dBctFileDataObject.java @@ -3,7 +3,6 @@ import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import java.io.*; import java.text.DecimalFormat; @@ -30,7 +29,7 @@ public String[] getExchangeItemIDs() { } @Override - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { return getExchangeItemIDs(); } diff --git a/model_delft3d/java/src/org/openda/model_delft3d/D3dField2DExchangeItem.java b/model_delft3d/java/src/org/openda/model_delft3d/D3dField2DExchangeItem.java index 8672a15f4..18d9c02ec 100644 --- a/model_delft3d/java/src/org/openda/model_delft3d/D3dField2DExchangeItem.java +++ b/model_delft3d/java/src/org/openda/model_delft3d/D3dField2DExchangeItem.java @@ -20,12 +20,12 @@ package org.openda.model_delft3d; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.*; /** * Exchange Item representing a 2D-field in a D3D file */ -public class D3dField2DExchangeItem implements IPrevExchangeItem { +public class D3dField2DExchangeItem implements IExchangeItem { private String id; private D3dField2D field2D; @@ -49,9 +49,7 @@ public Class getValueType() { return D3dField2D.class; } - public Role getRole() { - return IPrevExchangeItem.Role.InOut; - } + public Role getRole() { return IExchangeItem.Role.InOut; } public Object getValues() { return field2D; @@ -101,4 +99,30 @@ public void setTimes(double[] times) { public boolean getDataChanged() { return dataChanged; } + + @Override + public void copyValuesFromItem(IExchangeItem sourceItem) { + throw new RuntimeException("org.openda.model_delft3d.D3dField2DExchangeItem.copyValuesFromItem not implemented"); + } + + @Override + public ITimeInfo getTimeInfo() { + throw new RuntimeException("org.openda.model_delft3d.D3dField2DExchangeItem.getTimeInfo not implemented"); + } + + @Override + public IQuantityInfo getQuantityInfo() { + throw new RuntimeException("org.openda.model_delft3d.D3dField2DExchangeItem.getQuantityInfo not implemented"); + } + + @Override + public IGeometryInfo getGeometryInfo() { + throw new RuntimeException("org.openda.model_delft3d.D3dField2DExchangeItem.getGeometryInfo not implemented"); + } + + @Override + public ValueType getValuesType() { + return ValueType.custom; + } + } diff --git a/model_delft3d/java/src/org/openda/model_delft3d/D3dField2DFile.java b/model_delft3d/java/src/org/openda/model_delft3d/D3dField2DFile.java index 458b0c590..e8f1fa09c 100644 --- a/model_delft3d/java/src/org/openda/model_delft3d/D3dField2DFile.java +++ b/model_delft3d/java/src/org/openda/model_delft3d/D3dField2DFile.java @@ -20,32 +20,33 @@ package org.openda.model_delft3d; -import org.openda.blackbox.interfaces.IoObjectInterface; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IDataObject; +import org.openda.interfaces.IExchangeItem; import java.io.*; import java.util.Locale; /** * Delft3D 2d-field files reader/writer */ -public class D3dField2DFile implements IoObjectInterface { +public class D3dField2DFile implements IDataObject { private static String[] knownFileTypes = {ModelDefinitionFile.DEPTH, ModelDefinitionFile.ROUGHNESS}; private ModelDefinitionFile modelDefinitionFile = null; private D3dField2DExchangeItem[] exchangeItems = null; + private String[] ids; private String fileKey = null; - private int lineLength = 12; - public void initialize(File workingDir, String mdFileName, String[] arguments) { + @Override + public void initialize(File workingDir, String[] arguments) { - if (arguments.length != 1) { + if (arguments.length != 2) { throw new RuntimeException("Expected one argument, the 2D-field type: " + ModelDefinitionFile.getKnownFileTypesString(knownFileTypes)); } - fileKey = arguments[0]; + fileKey = arguments[1]; ModelDefinitionFile.checkD3dFileArguments(fileKey, knownFileTypes); - modelDefinitionFile = ModelDefinitionFile.getModelDefinitionFile(workingDir, mdFileName); + modelDefinitionFile = ModelDefinitionFile.getModelDefinitionFile(workingDir, arguments[0]); File fieldFile = modelDefinitionFile.getFieldFile(fileKey, true); try { @@ -54,11 +55,19 @@ public void initialize(File workingDir, String mdFileName, String[] arguments) { if (fileKey.equals(ModelDefinitionFile.DEPTH)) { exchangeItems = new D3dField2DExchangeItem[1]; - exchangeItems[0] = readExchangeItem2D(inputFileBufferedReader, "depth"); + String depthExchangeItemId = "depth"; + exchangeItems[0] = readExchangeItem2D(inputFileBufferedReader, depthExchangeItemId); + ids = new String[1]; + ids[0] = depthExchangeItemId; } else if (fileKey.equals(ModelDefinitionFile.ROUGHNESS)) { exchangeItems = new D3dField2DExchangeItem[2]; - exchangeItems[0] = readExchangeItem2D(inputFileBufferedReader, "roughness-u"); - exchangeItems[1] = readExchangeItem2D(inputFileBufferedReader, "roughness-v"); + String roughuExchangeItemId = "roughness-u"; + String roughvExchangeItemId = "roughness-v"; + exchangeItems[0] = readExchangeItem2D(inputFileBufferedReader, roughuExchangeItemId); + exchangeItems[1] = readExchangeItem2D(inputFileBufferedReader, roughvExchangeItemId); + ids = new String[2]; + ids[0] = roughuExchangeItemId; + ids[1] = roughvExchangeItemId; } inputFileBufferedReader.close(); fileReader.close(); @@ -68,11 +77,26 @@ public void initialize(File workingDir, String mdFileName, String[] arguments) { } } - public IPrevExchangeItem[] getExchangeItems() { - return exchangeItems; - } + @Override + public String[] getExchangeItemIDs() { + return ids; + } + + @Override + public String[] getExchangeItemIDs(IExchangeItem.Role role) { + return getExchangeItemIDs(); + } + + @Override + public IExchangeItem getDataObjectExchangeItem(String exchangeItemID) { + for (int i = 0; i < ids.length; i++) { + if (ids[i].equals(exchangeItemID)) return exchangeItems[i]; + } + return null; + } - public void finish() { + @Override + public void finish() { boolean dataChanged = false; for (int i = 0; !dataChanged && i < exchangeItems.length; i++) { @@ -133,7 +157,8 @@ private void writeExchangeItem2D(BufferedWriter outputFileBufferedWriter, double int index = 0; for (int n = 0; n < nmax; n++) { for (int m = 0; m < mmax; m++) { - if (m > 0 && m % lineLength == 0) { + int lineLength = 12; + if (m > 0 && m % lineLength == 0) { outputFileBufferedWriter.newLine(); } outputFileBufferedWriter.write(String.format(locale, floatValueFormat, values[index++])); diff --git a/model_delft3d/java/src/org/openda/model_delft3d/D3dMdFileDataObject.java b/model_delft3d/java/src/org/openda/model_delft3d/D3dMdFileDataObject.java index 520d115b8..cf8fb79bb 100644 --- a/model_delft3d/java/src/org/openda/model_delft3d/D3dMdFileDataObject.java +++ b/model_delft3d/java/src/org/openda/model_delft3d/D3dMdFileDataObject.java @@ -23,7 +23,6 @@ import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import java.io.*; import java.util.*; @@ -84,7 +83,7 @@ public String[] getExchangeItemIDs() { } @java.lang.Override - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { List matchingExchangeItemIds = new ArrayList<>(); for(IExchangeItem exchangeItem : exchangeItems.values()) @@ -138,16 +137,16 @@ public void initialize(File workingDir, String[] arguments) { double valueAsDouble_D2 = Double.parseDouble(values_D[4].trim()); double valueAsDouble_D3 = Double.parseDouble(values_D[8].trim()); - exchangeItems.put(key1, new DoubleExchangeItem(key, IPrevExchangeItem.Role.InOut, valueAsDouble_D1)); - exchangeItems.put(key2, new DoubleExchangeItem(key, IPrevExchangeItem.Role.InOut, valueAsDouble_D2)); - exchangeItems.put(key3, new DoubleExchangeItem(key, IPrevExchangeItem.Role.InOut, valueAsDouble_D3)); + exchangeItems.put(key1, new DoubleExchangeItem(key, IExchangeItem.Role.InOut, valueAsDouble_D1)); + exchangeItems.put(key2, new DoubleExchangeItem(key, IExchangeItem.Role.InOut, valueAsDouble_D2)); + exchangeItems.put(key3, new DoubleExchangeItem(key, IExchangeItem.Role.InOut, valueAsDouble_D3)); } // for (int i = 0; i < allKeys.length; i++) { if (Arrays.asList(fileKeys).contains(key)) { double valueAsDouble = Double.parseDouble(value); - exchangeItems.put(key, new DoubleExchangeItem(key, IPrevExchangeItem.Role.InOut, valueAsDouble)); + exchangeItems.put(key, new DoubleExchangeItem(key, IExchangeItem.Role.InOut, valueAsDouble)); }else if (Arrays.asList(timeKeys).contains(key)) { @@ -157,10 +156,10 @@ public void initialize(File workingDir, String[] arguments) { this.mjdFactor = getTimeToMjdFactor(value); }else if(key.equalsIgnoreCase(PROPERTY_STARTTIME)){ StartTime = getMjdFromDiff(Double.parseDouble(value)); - exchangeItems.put(PROPERTY_STARTTIME, new DoubleExchangeItem(PROPERTY_STARTTIME, IPrevExchangeItem.Role.InOut, StartTime)); + exchangeItems.put(PROPERTY_STARTTIME, new DoubleExchangeItem(PROPERTY_STARTTIME, IExchangeItem.Role.InOut, StartTime)); }else if(key.equalsIgnoreCase(PROPERTY_STOPTIME)){ StopTime = getMjdFromDiff(Double.parseDouble(value)); - exchangeItems.put(PROPERTY_STOPTIME, new DoubleExchangeItem(PROPERTY_STOPTIME, IPrevExchangeItem.Role.InOut, StopTime)); + exchangeItems.put(PROPERTY_STOPTIME, new DoubleExchangeItem(PROPERTY_STOPTIME, IExchangeItem.Role.InOut, StopTime)); } } @@ -168,12 +167,12 @@ public void initialize(File workingDir, String[] arguments) { if (Arrays.asList(fileKeys).contains(Ccofuv) && key.equalsIgnoreCase(Ccofu)){ double valueAsDouble = Double.parseDouble(value); CcofuvInit = valueAsDouble; - exchangeItems.put(Ccofuv, new DoubleExchangeItem(Ccofuv, IPrevExchangeItem.Role.InOut, valueAsDouble)); + exchangeItems.put(Ccofuv, new DoubleExchangeItem(Ccofuv, IExchangeItem.Role.InOut, valueAsDouble)); }else if (Arrays.asList(fileKeys).contains(DVicouv) && key.equalsIgnoreCase(D_H)){ double valueAsDouble = Double.parseDouble(value); DVicouvInit = valueAsDouble; - exchangeItems.put(DVicouv, new DoubleExchangeItem(DVicouv, IPrevExchangeItem.Role.InOut, valueAsDouble)); + exchangeItems.put(DVicouv, new DoubleExchangeItem(DVicouv, IExchangeItem.Role.InOut, valueAsDouble)); } diff --git a/model_delft3d/java/src/org/openda/model_delft3d/D3dRoughParamsFile.java b/model_delft3d/java/src/org/openda/model_delft3d/D3dRoughParamsFile.java index fc148ed73..6b40d394e 100644 --- a/model_delft3d/java/src/org/openda/model_delft3d/D3dRoughParamsFile.java +++ b/model_delft3d/java/src/org/openda/model_delft3d/D3dRoughParamsFile.java @@ -20,10 +20,9 @@ package org.openda.model_delft3d; -import org.openda.blackbox.interfaces.IoObjectInterface; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.exchange.AbstractDataObject; +import org.openda.interfaces.IExchangeItem; import java.io.File; -import java.util.ArrayList; /** * Created by IntelliJ IDEA. @@ -31,16 +30,12 @@ * Date: May 8, 2009 * Time: 2:49:06 PM */ -public class D3dRoughParamsFile implements IoObjectInterface { +public class D3dRoughParamsFile extends AbstractDataObject { - private File workingDir = null; - private String configString = null; - private IPrevExchangeItem[] exchangeItems =null; - - public void initialize(File workingDir, String configString, String[] arguments) { + @Override + public void initialize(File workingDir, String[] arguments) { /* Just save the initialization input */ - this.workingDir = workingDir; - this.configString = configString; + String configString = arguments[0]; /*Not sure what will be the content of fileName This can be a whole XML-file specifying what parameters we will use but for now @@ -48,7 +43,6 @@ public void initialize(File workingDir, String configString, String[] arguments) */ // Create an arraylist for storing all exchange items that are found in the input file - ArrayList listOfExchangeItems= new ArrayList(); /* read the parameters file */ File roughFile =new File(workingDir, configString); @@ -69,7 +63,6 @@ public void initialize(File workingDir, String configString, String[] arguments) // Check whether the line starts with R_CODE if (lineParts.length>2){ - boolean hasA=false; boolean hasB=false; boolean hasC=false; boolean hasD=false; @@ -78,10 +71,6 @@ public void initialize(File workingDir, String configString, String[] arguments) String sCode=lineParts[0]; String sFormulaNumber=lineParts[1]; - if(lineParts.length>=3){ // first parameter exists - hasA=true; - - } if(lineParts.length>=4){ // second parameter exists hasB=true; @@ -106,42 +95,38 @@ public void initialize(File workingDir, String configString, String[] arguments) } // Add exchange items for all parameters (if they exist) - if (hasA){ + // first parameter exists + { String idA=id+"_A"; - IPrevExchangeItem newExchangeItem=new D3dRoughParamsFileExchangeItem(idA, roughFile, iLine, "A"); - listOfExchangeItems.add(newExchangeItem); + IExchangeItem newExchangeItem=new D3dRoughParamsFileExchangeItem(idA, roughFile, iLine, "A"); + exchangeItems.put(idA, newExchangeItem); } if (hasB){ String idB=id+"_B"; - IPrevExchangeItem newExchangeItem=new D3dRoughParamsFileExchangeItem(idB, roughFile, iLine, "B"); - listOfExchangeItems.add(newExchangeItem); + IExchangeItem newExchangeItem=new D3dRoughParamsFileExchangeItem(idB, roughFile, iLine, "B"); + exchangeItems.put(idB, newExchangeItem); } if (hasC){ String idC=id+"_C"; - IPrevExchangeItem newExchangeItem=new D3dRoughParamsFileExchangeItem(idC, roughFile, iLine, "C"); - listOfExchangeItems.add(newExchangeItem); + IExchangeItem newExchangeItem=new D3dRoughParamsFileExchangeItem(idC, roughFile, iLine, "C"); + exchangeItems.put(idC, newExchangeItem); } if (hasD){ String idD=id+"_D"; - IPrevExchangeItem newExchangeItem=new D3dRoughParamsFileExchangeItem(idD, roughFile, iLine, "D"); - listOfExchangeItems.add(newExchangeItem); + IExchangeItem newExchangeItem=new D3dRoughParamsFileExchangeItem(idD, roughFile, iLine, "D"); + exchangeItems.put(idD, newExchangeItem); } if (hasE){ - String idD=id+"_E"; - IPrevExchangeItem newExchangeItem=new D3dRoughParamsFileExchangeItem(idD, roughFile, iLine, "E"); - listOfExchangeItems.add(newExchangeItem); + String idE=id+"_E"; + IExchangeItem newExchangeItem=new D3dRoughParamsFileExchangeItem(idE, roughFile, iLine, "E"); + exchangeItems.put(idE, newExchangeItem); } } } } - this.exchangeItems = new IPrevExchangeItem[listOfExchangeItems.size()]; - listOfExchangeItems.toArray(this.exchangeItems); - } - - public IPrevExchangeItem[] getExchangeItems() { - return this.exchangeItems; } + @Override public void finish() { // no action needed } diff --git a/model_delft3d/java/src/org/openda/model_delft3d/D3dRoughParamsFileExchangeItem.java b/model_delft3d/java/src/org/openda/model_delft3d/D3dRoughParamsFileExchangeItem.java index 2b54fbff7..97d5a67b7 100644 --- a/model_delft3d/java/src/org/openda/model_delft3d/D3dRoughParamsFileExchangeItem.java +++ b/model_delft3d/java/src/org/openda/model_delft3d/D3dRoughParamsFileExchangeItem.java @@ -20,7 +20,10 @@ package org.openda.model_delft3d; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; +import org.openda.interfaces.IGeometryInfo; +import org.openda.interfaces.IQuantityInfo; +import org.openda.interfaces.ITimeInfo; import java.io.File; @@ -49,7 +52,7 @@ * items implementation * */ -public class D3dRoughParamsFileExchangeItem implements IPrevExchangeItem { +public class D3dRoughParamsFileExchangeItem implements IExchangeItem { private String id; // Unique ID of the parameter private String quantityId ="-"; // The code A,B,C,D @@ -80,6 +83,8 @@ public D3dRoughParamsFileExchangeItem(String id, String description, File roughF this.description = description; } + public Role getRole() { return IExchangeItem.Role.InOut; } + public String getId() { return this.id; } @@ -92,6 +97,31 @@ public String getDescription() { return description; } + @Override + public void copyValuesFromItem(IExchangeItem sourceItem) { + throw new RuntimeException("org.openda.model_delft3d.D3dRoughParamsFileExchangeItem.copyValuesFromItem not implemented"); + } + + @Override + public ITimeInfo getTimeInfo() { + throw new RuntimeException("org.openda.model_delft3d.D3dRoughParamsFileExchangeItem.getTimeInfo not implemented"); + } + + @Override + public IQuantityInfo getQuantityInfo() { + throw new RuntimeException("org.openda.model_delft3d.D3dRoughParamsFileExchangeItem.getQuantityInfo not implemented"); + } + + @Override + public IGeometryInfo getGeometryInfo() { + throw new RuntimeException("org.openda.model_delft3d.D3dRoughParamsFileExchangeItem.getGeometryInfo not implemented"); + } + + @Override + public ValueType getValuesType() { + throw new RuntimeException("org.openda.model_delft3d.D3dRoughParamsFileExchangeItem.getValuesType not implemented"); + } + public String getQuantityId() { return this.quantityId; } @@ -104,10 +134,6 @@ public Class getValueType() { return this.classType; } - public Role getRole() { - return IPrevExchangeItem.Role.InOut; - } - public Object getValues() { return this.value; } diff --git a/model_delft3d/java/src/org/openda/model_delft3d/D3dWindExchangeItem.java b/model_delft3d/java/src/org/openda/model_delft3d/D3dWindExchangeItem.java index 161ff0e5d..79151a7fe 100644 --- a/model_delft3d/java/src/org/openda/model_delft3d/D3dWindExchangeItem.java +++ b/model_delft3d/java/src/org/openda/model_delft3d/D3dWindExchangeItem.java @@ -89,9 +89,7 @@ public Class getValueType() { return List.class; } - public Role getRole() { - return Role.InOut; - } + public Role getRole() { return Role.InOut; } public Object getValues() { return valuesOnGrid2D; diff --git a/model_delft3d/java/src/org/openda/model_delft3d/D3dWindFile.java b/model_delft3d/java/src/org/openda/model_delft3d/D3dWindFile.java index 9aaf775d3..7a14f9340 100644 --- a/model_delft3d/java/src/org/openda/model_delft3d/D3dWindFile.java +++ b/model_delft3d/java/src/org/openda/model_delft3d/D3dWindFile.java @@ -24,7 +24,6 @@ import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import java.io.*; import java.util.ArrayList; import java.util.Arrays; @@ -93,7 +92,7 @@ public String[] getExchangeItemIDs() { return new String[] {windExchangeItem.getId()}; } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { if (windExchangeItem.getRole().equals(role)) { return new String[] {windExchangeItem.getId()}; } diff --git a/model_delft3d/java/src/org/openda/model_delft3d/NetcdfD3dHisExchangeItem.java b/model_delft3d/java/src/org/openda/model_delft3d/NetcdfD3dHisExchangeItem.java index 0223a9e98..ab8f736d3 100644 --- a/model_delft3d/java/src/org/openda/model_delft3d/NetcdfD3dHisExchangeItem.java +++ b/model_delft3d/java/src/org/openda/model_delft3d/NetcdfD3dHisExchangeItem.java @@ -48,11 +48,6 @@ public ValueType getValuesType() { return ValueType.doublesType; } - @Override - public Class getValueType() { - return double[].class; - } - @Override public Object getValues() { int stationValues[] = new int[2]; diff --git a/model_delft3d/java/src/org/openda/model_delft3d/NetcdfD3dMapExchangeItem.java b/model_delft3d/java/src/org/openda/model_delft3d/NetcdfD3dMapExchangeItem.java index e552bde03..b14e00a8a 100644 --- a/model_delft3d/java/src/org/openda/model_delft3d/NetcdfD3dMapExchangeItem.java +++ b/model_delft3d/java/src/org/openda/model_delft3d/NetcdfD3dMapExchangeItem.java @@ -50,12 +50,7 @@ public NetcdfD3dMapExchangeItem(String varName, NetcdfD3dMapDataObject netcdfD3d public ValueType getValuesType() { return ValueType.doublesType; } - - @Override - public Class getValueType() { - return double[].class; - } - + @Override public Object getValues() {throw new RuntimeException("org.openda.exchange.dataobjects.NetcdfD3dMapExchangeItem.getValues() not implemented yet"); // return netcdfD3dMapDataObject.getExchangeItemValues(varName); diff --git a/model_delft3d/java/test/org/openda/model_delft3d/D3dAstroComponentsTest.java b/model_delft3d/java/test/org/openda/model_delft3d/D3dAstroComponentsTest.java index 094754712..acdd0ed0a 100644 --- a/model_delft3d/java/test/org/openda/model_delft3d/D3dAstroComponentsTest.java +++ b/model_delft3d/java/test/org/openda/model_delft3d/D3dAstroComponentsTest.java @@ -20,7 +20,8 @@ package org.openda.model_delft3d; import junit.framework.TestCase; import org.openda.blackbox.config.BBUtils; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IDataObject; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.OpenDaTestSupport; import java.io.File; @@ -33,7 +34,7 @@ public class D3dAstroComponentsTest extends TestCase { private OpenDaTestSupport testData = null; - protected void setUp() throws IOException { + protected void setUp() { testData = new OpenDaTestSupport(D3dAstroComponentsTest.class,"model_delft3d"); } @@ -51,14 +52,19 @@ public void testAstroFiles() throws IOException { BBUtils.copyFile(correctionBase, correction); // Read astro files, check content - D3dAstroComponentFiles astroFiles = new D3dAstroComponentFiles(); - astroFiles.initialize(testDir, "m27.mdf", new String[]{}); - IPrevExchangeItem[] bcaExchItems = astroFiles.getExchangeItems(); - assertEquals("bcaExchItems.length", 374, bcaExchItems.length); + IDataObject astroFiles = new D3dAstroComponentFiles(); + astroFiles.initialize(testDir, new String[]{"m27.mdf"}); + + String[] astroExchItemIDs = astroFiles.getExchangeItemIDs(); + IExchangeItem[] bcaExchItems = new IExchangeItem[astroExchItemIDs.length]; + for (int i = 0; i < astroExchItemIDs.length; i++) { + bcaExchItems[i] = astroFiles.getDataObjectExchangeItem(astroExchItemIDs[i]); + } + assertEquals("bcaExchItems.length", 374, bcaExchItems.length); assertEquals("bcaExchItems[ 0].id", "BND01.A0", bcaExchItems[ 0].getId()); assertEquals("bcaExchItems[ 5].id", "BND01.P1.Amplitude", bcaExchItems[ 5].getId()); - for (IPrevExchangeItem bcaExchItem : bcaExchItems) { + for (IExchangeItem bcaExchItem : bcaExchItems) { System.out.println(bcaExchItem.getId() + "\t" + bcaExchItem.getValues().toString()); } assertEquals("bcaExchItems[ 0].values[0]", 0.0, bcaExchItems[ 0].getValuesAsDoubles()[0]); @@ -73,9 +79,13 @@ public void testAstroFiles() throws IOException { astroFiles.finish(); // Re-read astro file, check changed vales - astroFiles = new D3dAstroComponentFiles(); - astroFiles.initialize(testDir, "m27.mdf", new String[]{}); - bcaExchItems = astroFiles.getExchangeItems(); + astroFiles = new D3dAstroComponentFiles(); + astroFiles.initialize(testDir, new String[]{"m27.mdf"}); + + bcaExchItems = new IExchangeItem[astroExchItemIDs.length]; + for (int i = 0; i < astroExchItemIDs.length; i++) { + bcaExchItems[i] = astroFiles.getDataObjectExchangeItem(astroExchItemIDs[i]); + } assertEquals("bcaExchItems.length", 374, bcaExchItems.length); assertEquals("bcaExchItems[ 0].id", "BND01.A0", bcaExchItems[ 0].getId()); assertEquals("bcaExchItems[ 5].id", "BND01.P1.Amplitude", bcaExchItems[ 5].getId()); diff --git a/model_delft3d/java/test/org/openda/model_delft3d/D3dField2DFileTest.java b/model_delft3d/java/test/org/openda/model_delft3d/D3dField2DFileTest.java index 109563072..f52030a74 100644 --- a/model_delft3d/java/test/org/openda/model_delft3d/D3dField2DFileTest.java +++ b/model_delft3d/java/test/org/openda/model_delft3d/D3dField2DFileTest.java @@ -20,7 +20,8 @@ package org.openda.model_delft3d; import junit.framework.TestCase; import org.openda.blackbox.config.BBUtils; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IDataObject; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.OpenDaTestSupport; import java.io.File; @@ -33,7 +34,7 @@ public class D3dField2DFileTest extends TestCase { private OpenDaTestSupport testData = null; - protected void setUp() throws IOException { + protected void setUp() { testData = new OpenDaTestSupport(D3dField2DFileTest.class,"model_delft3d"); } @@ -50,9 +51,13 @@ public void testField2DFiles() throws IOException { BBUtils.copyFile(depthBase, depth); // Read depth file, check content - D3dField2DFile depthFile = new D3dField2DFile(); - depthFile.initialize(testDir, "test.mdf", new String[] {"dep"}); - IPrevExchangeItem[] depExchItems = depthFile.getExchangeItems(); + IDataObject depthFile = new D3dField2DFile(); + depthFile.initialize(testDir, new String[] {"test.mdf", "dep"}); + String[] depExchItemIDs = depthFile.getExchangeItemIDs(); + IExchangeItem[] depExchItems = new IExchangeItem[depExchItemIDs.length]; + for (int i = 0; i < depExchItemIDs.length; i++) { + depExchItems[i] = depthFile.getDataObjectExchangeItem(depExchItemIDs[i]); + } assertEquals("depExchItems.length", 1, depExchItems.length); assertEquals("exchItemdepthFile[0].id", "depth", depExchItems[0].getId()); double[] depthValues = depExchItems[0].getValuesAsDoubles(); @@ -60,9 +65,13 @@ public void testField2DFiles() throws IOException { assertEquals("exchItemRoughFile[1].values[345]", -999.000, depthValues[345]); // Read roughness file, check content - D3dField2DFile roughnessFile = new D3dField2DFile(); - roughnessFile.initialize(testDir, "test.mdf", new String[] {"rgh"}); - IPrevExchangeItem[] rghExchItems = roughnessFile.getExchangeItems(); + IDataObject roughnessFile = new D3dField2DFile(); + roughnessFile.initialize(testDir, new String[] {"test.mdf", "rgh"}); + String[] rghExchItemIDs = roughnessFile.getExchangeItemIDs(); + IExchangeItem[] rghExchItems = new IExchangeItem[rghExchItemIDs.length]; + for (int i = 0; i < rghExchItemIDs.length; i++) { + rghExchItems[i] = roughnessFile.getDataObjectExchangeItem(rghExchItemIDs[i]); + } assertEquals("rghExchItems.length", 2, rghExchItems.length); assertEquals("exchItemRoughFile[0].id", "roughness-u", rghExchItems[0].getId()); assertEquals("exchItemRoughFile[1].id", "roughness-v", rghExchItems[1].getId()); @@ -81,9 +90,14 @@ public void testField2DFiles() throws IOException { roughnessFile.finish(); // Re-read roughness file, check changed vValues - D3dField2DFile adjustedRoughnessFile = new D3dField2DFile(); - adjustedRoughnessFile.initialize(testDir, "test.mdf", new String[] {"rgh"}); - double[] adjustedVValues = adjustedRoughnessFile.getExchangeItems()[1].getValuesAsDoubles(); + IDataObject adjustedRoughnessFile = new D3dField2DFile(); + adjustedRoughnessFile.initialize(testDir, new String[] {"test.mdf","rgh"}); + String[] adjrghExchItemIDs = adjustedRoughnessFile.getExchangeItemIDs(); + IExchangeItem[] adjrghExchItems = new IExchangeItem[adjrghExchItemIDs.length]; + for (int i = 0; i < adjrghExchItemIDs.length; i++) { + adjrghExchItems[i] = adjustedRoughnessFile.getDataObjectExchangeItem(adjrghExchItemIDs[i]); + } + double[] adjustedVValues = adjrghExchItems[1].getValuesAsDoubles(); assertEquals("exchItemRoughFile[1].values[6]", 101.008, adjustedVValues[6]); assertEquals("exchItemRoughFile[1].values[7]", 101.009, adjustedVValues[7]); } diff --git a/model_delft3d/java/test/org/openda/model_delft3d/D3dField2DMaskTest.java b/model_delft3d/java/test/org/openda/model_delft3d/D3dField2DMaskTest.java index 87254dbc6..f733dcc75 100644 --- a/model_delft3d/java/test/org/openda/model_delft3d/D3dField2DMaskTest.java +++ b/model_delft3d/java/test/org/openda/model_delft3d/D3dField2DMaskTest.java @@ -21,7 +21,8 @@ import junit.framework.TestCase; import org.openda.blackbox.config.BBUtils; import org.openda.blackbox.interfaces.SelectorInterface; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IDataObject; +import org.openda.interfaces.IExchangeItem; import org.openda.interfaces.IVector; import org.openda.utils.OpenDaTestSupport; @@ -35,7 +36,7 @@ public class D3dField2DMaskTest extends TestCase { private OpenDaTestSupport testData = null; - protected void setUp() throws IOException { + protected void setUp() { testData = new OpenDaTestSupport(D3dField2DMaskTest.class,"model_delft3d"); } @@ -49,9 +50,11 @@ public void testField2DMask() throws IOException { BBUtils.copyFile(roughessBase, roughess); // Read roughness file, check original content - D3dField2DFile roughnessFile = new D3dField2DFile(); - roughnessFile.initialize(testDir, "test.mdf", new String[] {"rgh"}); - IPrevExchangeItem uRoughExchItem = roughnessFile.getExchangeItems()[0]; + IDataObject roughnessFile = new D3dField2DFile(); + roughnessFile.initialize(testDir, new String[] {"test.mdf","rgh"}); + String[] rghExchItemIDs = roughnessFile.getExchangeItemIDs(); + IExchangeItem uRoughExchItem = roughnessFile.getDataObjectExchangeItem(rghExchItemIDs[0]); + double[] uValues = uRoughExchItem.getValuesAsDoubles(); assertEquals("exchItemRoughFile[1].values[185]", 7.012, uValues[185]); assertEquals("exchItemRoughFile[1].values[186]", 7.013, uValues[186]); @@ -71,8 +74,10 @@ public void testField2DMask() throws IOException { // Re-read roughness file, check changed u-values D3dField2DFile adjustedRoughnessFile = new D3dField2DFile(); - adjustedRoughnessFile.initialize(testDir, "test.mdf", new String[] {"rgh"}); - double[] adjustedUValues = adjustedRoughnessFile.getExchangeItems()[0].getValuesAsDoubles(); + adjustedRoughnessFile.initialize(testDir, new String[] {"test.mdf","rgh"}); + String[] adjrghExchItemIDs = adjustedRoughnessFile.getExchangeItemIDs(); + IExchangeItem AdjRoughExchItem = adjustedRoughnessFile.getDataObjectExchangeItem(adjrghExchItemIDs[0]); + double[] adjustedUValues = AdjRoughExchItem.getValuesAsDoubles(); assertEquals("exchItemRoughFile[1].values[185]", -7.012, adjustedUValues[185]); assertEquals("exchItemRoughFile[1].values[186]", 7.013, adjustedUValues[186]); } diff --git a/model_delft3d/java/test/org/openda/model_delft3d/D3dRoughParamsTest.java b/model_delft3d/java/test/org/openda/model_delft3d/D3dRoughParamsTest.java index 385d0b7b5..7e3dbf1a6 100644 --- a/model_delft3d/java/test/org/openda/model_delft3d/D3dRoughParamsTest.java +++ b/model_delft3d/java/test/org/openda/model_delft3d/D3dRoughParamsTest.java @@ -20,11 +20,10 @@ package org.openda.model_delft3d; import junit.framework.TestCase; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.OpenDaTestSupport; import java.io.File; -import java.io.IOException; /** * Created by IntelliJ IDEA. @@ -38,7 +37,7 @@ public class D3dRoughParamsTest extends TestCase { private File testRunDataDir; private OpenDaTestSupport testData; - protected void setUp() throws IOException { + protected void setUp() { testData = new OpenDaTestSupport(D3dRoughParamsTest.class,"model_delft3d"); testRunDataDir = testData.getTestRunDataDir(); } @@ -48,30 +47,32 @@ public void testExistingfile(){ // First write a test file File dataDir=testRunDataDir; D3dRoughParamsFile roughFile=new D3dRoughParamsFile(); - roughFile.initialize(testRunDataDir, "ruw.karak",new String[]{}); + roughFile.initialize(testRunDataDir, new String[]{"ruw.karak"}); - IPrevExchangeItem[] items = roughFile.getExchangeItems(); + String[] ids = roughFile.getExchangeItemIDs(); - int n=items.length; + int n=ids.length; double delta=0.00001; assertEquals(10, n); - for(int i=0;i + diff --git a/model_delft3d/java/test/org/openda/model_delft3d/testData/bb_test_1/stochModel/config/d3dBbWrapperConfig.xml b/model_delft3d/java/test/org/openda/model_delft3d/testData/bb_test_1/stochModel/config/d3dBbWrapperConfig.xml index 9e3c81a99..e0de42450 100644 --- a/model_delft3d/java/test/org/openda/model_delft3d/testData/bb_test_1/stochModel/config/d3dBbWrapperConfig.xml +++ b/model_delft3d/java/test/org/openda/model_delft3d/testData/bb_test_1/stochModel/config/d3dBbWrapperConfig.xml @@ -32,31 +32,32 @@ - + %runid%.mdf astro-components - + - + %runid%.mdf roughness rgh - + - + %runid%.mdf depth dep - + - + + trih-%runid%.dat trih-file %NATIVE_DLL_DIR% - + diff --git a/model_delft3d/java/test/org/openda/model_delft3d/testData/bb_test_1/stochModel/config/d3dBbWrapperConfig_linux64_gnu.xml b/model_delft3d/java/test/org/openda/model_delft3d/testData/bb_test_1/stochModel/config/d3dBbWrapperConfig_linux64_gnu.xml index d95ba14ca..45bc69554 100644 --- a/model_delft3d/java/test/org/openda/model_delft3d/testData/bb_test_1/stochModel/config/d3dBbWrapperConfig_linux64_gnu.xml +++ b/model_delft3d/java/test/org/openda/model_delft3d/testData/bb_test_1/stochModel/config/d3dBbWrapperConfig_linux64_gnu.xml @@ -32,31 +32,31 @@ - + %runid%.mdf astro-components - + - + %runid%.mdf roughness rgh - + - + %runid%.mdf depth dep - + - + trih-%runid%.dat trih-file %NATIVE_DLL_DIR% - - + + diff --git a/model_delft3d/java/test/org/openda/model_delft3d/testData/test_4/stochmodel/D3DWrapperConfig.xml b/model_delft3d/java/test/org/openda/model_delft3d/testData/test_4/stochmodel/D3DWrapperConfig.xml index 472536bca..a7386d116 100644 --- a/model_delft3d/java/test/org/openda/model_delft3d/testData/test_4/stochmodel/D3DWrapperConfig.xml +++ b/model_delft3d/java/test/org/openda/model_delft3d/testData/test_4/stochmodel/D3DWrapperConfig.xml @@ -41,46 +41,47 @@ - + %runid%.mdf astro-components - + - + %runid%.mdf roughness rgh - + - + %runid%.mdf depth dep - + - + %runid%.mdf windguFile gu - + - + %runid%.mdf windgvFile gv - + - + + trih-%runid%.dat trih-file %NATIVE_DLL_DIR% - + diff --git a/model_delft3d/java/test/org/openda/model_delft3d/testData/test_4/stochmodel/D3DWrapperConfig_linux64_gnu.xml b/model_delft3d/java/test/org/openda/model_delft3d/testData/test_4/stochmodel/D3DWrapperConfig_linux64_gnu.xml index eb5cc9d1b..0f52d1c52 100644 --- a/model_delft3d/java/test/org/openda/model_delft3d/testData/test_4/stochmodel/D3DWrapperConfig_linux64_gnu.xml +++ b/model_delft3d/java/test/org/openda/model_delft3d/testData/test_4/stochmodel/D3DWrapperConfig_linux64_gnu.xml @@ -41,46 +41,46 @@ - + %runid%.mdf astro-components - + - + %runid%.mdf roughness rgh - + - + %runid%.mdf depth dep - + - + %runid%.mdf windguFile gu - + - + %runid%.mdf windgvFile gv - + - + trih-%runid%.dat trih-file %NATIVE_DLL_DIR% - + diff --git a/model_delft3d/tests/calibration_estuary/stochModel/D3DWrapper.xml b/model_delft3d/tests/calibration_estuary/stochModel/D3DWrapper.xml index d75ef9761..dc96a621f 100644 --- a/model_delft3d/tests/calibration_estuary/stochModel/D3DWrapper.xml +++ b/model_delft3d/tests/calibration_estuary/stochModel/D3DWrapper.xml @@ -39,31 +39,31 @@ - + %runid%.mdf roughness rgh - + - + %runid%.mdf depth dep - + - + %runid%.mdf astro-components - + - + trih-%runid%.nc trih-file true - + diff --git a/model_delft3d/tests/calibration_estuary_dd/stochModel/D3DWrapper.xml b/model_delft3d/tests/calibration_estuary_dd/stochModel/D3DWrapper.xml index fa2aebc2a..c49c45023 100644 --- a/model_delft3d/tests/calibration_estuary_dd/stochModel/D3DWrapper.xml +++ b/model_delft3d/tests/calibration_estuary_dd/stochModel/D3DWrapper.xml @@ -40,46 +40,46 @@ - + %runid%1.mdf roughness1 rgh - - + + %runid%2.mdf roughness2 rgh - + - + %runid%1.mdf depth1 dep - - + + %runid%2.mdf depth2 dep - + - + %runid%1.mdf astro-components - + - + trih-%runid%1.nc trih-file1 true - - + + trih-%runid%2.nc trih-file2 true - + diff --git a/model_delft3d/tests/calibration_river_roughness/stochmodel/detmodel/D3DWrapper.xml b/model_delft3d/tests/calibration_river_roughness/stochmodel/detmodel/D3DWrapper.xml index a2ddc5aa7..1c9002b6a 100644 --- a/model_delft3d/tests/calibration_river_roughness/stochmodel/detmodel/D3DWrapper.xml +++ b/model_delft3d/tests/calibration_river_roughness/stochmodel/detmodel/D3DWrapper.xml @@ -35,37 +35,37 @@ - + %runid%.mdf roughness rgh - + - + %runid%.mdf depth dep - + - + %runid%.mdf astro-components - + - + trih-%runid%.nc trih-file true - + - + %roughParamsFile% roughParams - + diff --git a/model_delft3d/tests/calibration_wind/stochmodel/D3DWrapperConfig.xml b/model_delft3d/tests/calibration_wind/stochmodel/D3DWrapperConfig.xml index e10017d8f..e5c06598a 100644 --- a/model_delft3d/tests/calibration_wind/stochmodel/D3DWrapperConfig.xml +++ b/model_delft3d/tests/calibration_wind/stochmodel/D3DWrapperConfig.xml @@ -41,46 +41,46 @@ - + %runid%.mdf - astro-components - + astro-components + - + %runid%.mdf roughness rgh - + - + %runid%.mdf depth dep - + - + %runid%.mdf windguFile gu - + - + %runid%.mdf windgvFile gv - - - - - trih-%runid%.nc - trih-file - true - - + + + + + trih-%runid%.nc + trih-file + true + + diff --git a/model_delft3d/tests/d3d_3Dlake_EnKF/stochModel/D3DWrapper.xml b/model_delft3d/tests/d3d_3Dlake_EnKF/stochModel/D3DWrapper.xml index fa692f71f..967149bd7 100644 --- a/model_delft3d/tests/d3d_3Dlake_EnKF/stochModel/D3DWrapper.xml +++ b/model_delft3d/tests/d3d_3Dlake_EnKF/stochModel/D3DWrapper.xml @@ -38,39 +38,39 @@ - + %runid%.mdf mdFile - + - + trih-%runid%.nc trih-file - + - + %runid%.mdf windwuFile wu - + - + %runid%.mdf windwvFile wv - + - + trim-%runid%.nc states tri-rst.restart-in %targetTime% - + diff --git a/model_delft3d/tests/d3d_3Dlake_EnKF_states/stochModel/D3DWrapper.xml b/model_delft3d/tests/d3d_3Dlake_EnKF_states/stochModel/D3DWrapper.xml index fc39bdfda..51f301630 100644 --- a/model_delft3d/tests/d3d_3Dlake_EnKF_states/stochModel/D3DWrapper.xml +++ b/model_delft3d/tests/d3d_3Dlake_EnKF_states/stochModel/D3DWrapper.xml @@ -30,39 +30,39 @@ - + %runid%.mdf mdFile - + - + trih-%runid%.nc trih-file - + - + %runid%.mdf windwuFile wu - + - + %runid%.mdf windwvFile wv - + - + trim-%runid%.nc states restart-in %targetTime% - + diff --git a/model_delft3d/tests/d3d_3Dlake_calibration/stochModel/D3DWrapper.xml b/model_delft3d/tests/d3d_3Dlake_calibration/stochModel/D3DWrapper.xml index ddd082582..68cc63cc1 100644 --- a/model_delft3d/tests/d3d_3Dlake_calibration/stochModel/D3DWrapper.xml +++ b/model_delft3d/tests/d3d_3Dlake_calibration/stochModel/D3DWrapper.xml @@ -39,16 +39,16 @@ - + %runid%.mdf mdFile - + - + trih-%runid%.nc trih-file - + diff --git a/model_delft3d/tests/d3d_3Dlake_calibration/stochObserver/stochObsConfig.xml b/model_delft3d/tests/d3d_3Dlake_calibration/stochObserver/stochObsConfig.xml index 1335abd8a..417426184 100644 --- a/model_delft3d/tests/d3d_3Dlake_calibration/stochObserver/stochObsConfig.xml +++ b/model_delft3d/tests/d3d_3Dlake_calibration/stochObserver/stochObsConfig.xml @@ -1,11 +1,11 @@ - + stochObsUncertainties.xml - + trih-cadagno_netcdf.nc - - + + diff --git a/model_delft3d/tests/kalman_estuary/stochModel/D3DWrapper.xml b/model_delft3d/tests/kalman_estuary/stochModel/D3DWrapper.xml index d75ef9761..dc96a621f 100644 --- a/model_delft3d/tests/kalman_estuary/stochModel/D3DWrapper.xml +++ b/model_delft3d/tests/kalman_estuary/stochModel/D3DWrapper.xml @@ -39,31 +39,31 @@ - + %runid%.mdf roughness rgh - + - + %runid%.mdf depth dep - + - + %runid%.mdf astro-components - + - + trih-%runid%.nc trih-file true - + diff --git a/model_delwaq/java/model_delwaq.iml b/model_delwaq/java/model_delwaq.iml index 45c995358..b1ec4385f 100644 --- a/model_delwaq/java/model_delwaq.iml +++ b/model_delwaq/java/model_delwaq.iml @@ -12,14 +12,6 @@ - - - - - - - - - + \ No newline at end of file diff --git a/model_delwaq/java/src/org/openda/model_delwaq/delwaqBinaryFile.java b/model_delwaq/java/src/org/openda/model_delwaq/delwaqBinaryFile.java index 0b1bf3fcf..836359a15 100644 --- a/model_delwaq/java/src/org/openda/model_delwaq/delwaqBinaryFile.java +++ b/model_delwaq/java/src/org/openda/model_delwaq/delwaqBinaryFile.java @@ -20,7 +20,6 @@ package org.openda.model_delwaq; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.Time; import java.io.File; @@ -78,7 +77,7 @@ public String[] getExchangeItemIDs() { * @param role Input, Output, or InOut (i.e. both) * @return The array of exchange item identifiers. */ - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { return ids; // For now return all IDs. } @@ -121,7 +120,7 @@ private IExchangeItem findOrCreateExchangeItem(int index) { } catch (IOException e) { e.printStackTrace(); } - items.add(new delwaqSubstanceExchangeItem(ids[index], itemDescription, IPrevExchangeItem.Role.Input, values, this)); + items.add(new delwaqSubstanceExchangeItem(ids[index], itemDescription, IExchangeItem.Role.Input, values, this)); return items.get(items.size()-1); } diff --git a/model_delwaq/java/src/org/openda/model_delwaq/delwaqInpFile.java b/model_delwaq/java/src/org/openda/model_delwaq/delwaqInpFile.java index 7268e41ef..fcdb69d24 100644 --- a/model_delwaq/java/src/org/openda/model_delwaq/delwaqInpFile.java +++ b/model_delwaq/java/src/org/openda/model_delwaq/delwaqInpFile.java @@ -20,10 +20,8 @@ package org.openda.model_delwaq; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import java.io.File; -import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; @@ -84,7 +82,7 @@ public String[] getExchangeItemIDs() { * @param role Input, Output, or InOut (i.e. both) * @return The array of exchange item identifiers. */ - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { ArrayList identifiers = null; for (IExchangeItem item : items) { if (item.getRole().equals(role)) { @@ -176,7 +174,7 @@ public void initialize(File workingDir, String[] arguments) { for (int i=0; i - + %inpConstantsFile% constantsFile %inpConstantsDataFile% - + - + %delwaqOutputFile% outputFile - + diff --git a/model_delwaq/tests/test1/stochObserver/delwaqMapStochObsConfig.xml b/model_delwaq/tests/test1/stochObserver/delwaqMapStochObsConfig.xml index acff9af53..eae45935e 100644 --- a/model_delwaq/tests/test1/stochObserver/delwaqMapStochObsConfig.xml +++ b/model_delwaq/tests/test1/stochObserver/delwaqMapStochObsConfig.xml @@ -1,13 +1,13 @@ - stochObsUncertainties.xml - + measurements_res.map 0 0 - - + + diff --git a/model_dflowfm_blackbox/java/model_dflowfm_blackbox.iml b/model_dflowfm_blackbox/java/model_dflowfm_blackbox.iml index 411be0715..0c051854d 100644 --- a/model_dflowfm_blackbox/java/model_dflowfm_blackbox.iml +++ b/model_dflowfm_blackbox/java/model_dflowfm_blackbox.iml @@ -15,15 +15,6 @@ - - - - - - - - - @@ -37,5 +28,6 @@ + \ No newline at end of file diff --git a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/BcExchangeItem.java b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/BcExchangeItem.java index 0117bec0c..67fd17910 100644 --- a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/BcExchangeItem.java +++ b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/BcExchangeItem.java @@ -39,9 +39,7 @@ public BcExchangeItem(String id, double[] timeSeriesData, double[] valueData) } @Override - public Role getRole() { - return Role.InOut; - } + public Role getRole() { return Role.InOut; } @Override public String getId() { @@ -53,9 +51,6 @@ public String getDescription() { return id; } - @Override - public Class getValueType() { return double[].class; } - @Override public void copyValuesFromItem(IExchangeItem sourceItem) { setValues(sourceItem.getValues()); } diff --git a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/BcFile.java b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/BcFile.java index a70fb325d..05653e0cf 100644 --- a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/BcFile.java +++ b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/BcFile.java @@ -22,7 +22,6 @@ import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import java.io.File; import java.util.ArrayList; @@ -84,7 +83,7 @@ public String[] getExchangeItemIDs() } @Override - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) + public String[] getExchangeItemIDs(IExchangeItem.Role role) { List matchingExchangeItemIds = new ArrayList<>(); for(IExchangeItem exchangeItem : exchangeItems.values()) diff --git a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMCalibrationFactorFile.java b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMCalibrationFactorFile.java index 6afbfdd42..974c741e1 100644 --- a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMCalibrationFactorFile.java +++ b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMCalibrationFactorFile.java @@ -21,7 +21,6 @@ import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.generalJavaUtils.StringUtilities; import org.openda.utils.io.AsciiFileUtils; @@ -50,7 +49,7 @@ public String[] getExchangeItemIDs() { } @Override - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { return getExchangeItemIDs(); } diff --git a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMFrictionCoefExchangeItem.java b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMFrictionCoefExchangeItem.java index 27f5a92c5..6e492bb70 100644 --- a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMFrictionCoefExchangeItem.java +++ b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMFrictionCoefExchangeItem.java @@ -116,7 +116,7 @@ public IGeometryInfo getGeometryInfo(){ public void copyValuesFromItem(IExchangeItem sourceItem) { if (this.valuetype != sourceItem.getValuesType()) { throw new RuntimeException("Incompatible value types in copy action from " + sourceItem.getId() + - " to " + getId() + "(" + sourceItem.getValueType().toString() + "/=" + this.valuetype.toString()); + " to " + getId() + "(" + sourceItem.getValuesType().toString() + "/=" + this.valuetype.toString()); } setValues(sourceItem.getValues()); } diff --git a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMMeteoFile.java b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMMeteoFile.java index a9ff404ea..3689d5827 100644 --- a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMMeteoFile.java +++ b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMMeteoFile.java @@ -21,12 +21,10 @@ package org.openda.model_dflowfm; import org.openda.exchange.ArrayExchangeItem; -import org.openda.exchange.ArrayGeometryInfo; import org.openda.exchange.TimeInfo; import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.Vector; import java.io.*; @@ -209,7 +207,7 @@ public String[] getExchangeItemIDs() { return result; } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { if (exchangeItem.getRole() == role) { String[] result = new String[1]; result[0] = exchangeItem.getId(); @@ -270,4 +268,4 @@ public void finish() { } -} \ No newline at end of file +} diff --git a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMRestartFileWrapper.java b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMRestartFileWrapper.java index 27c52a964..e39bdbac1 100644 --- a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMRestartFileWrapper.java +++ b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMRestartFileWrapper.java @@ -22,7 +22,6 @@ import org.openda.exchange.ExchangeItem; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.*; import org.openda.utils.Vector; @@ -218,7 +217,7 @@ public void initialize(File workingDir, String[] arguments) { return result; } - public String [] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String [] getExchangeItemIDs(IExchangeItem.Role role) { return getExchangeItemIDs(); } diff --git a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMTimTimeSeriesFormatter.java b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMTimTimeSeriesFormatter.java index fda357241..ac2a59bc5 100644 --- a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMTimTimeSeriesFormatter.java +++ b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMTimTimeSeriesFormatter.java @@ -30,7 +30,7 @@ import org.openda.exchange.timeseries.TimeSeries; import org.openda.exchange.timeseries.TimeSeriesFormatter; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; public class DFlowFMTimTimeSeriesFormatter extends TimeSeriesFormatter { diff --git a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMTimeInfo.java b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMTimeInfo.java index f5d8ff513..ac88a29fd 100644 --- a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMTimeInfo.java +++ b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMTimeInfo.java @@ -23,7 +23,6 @@ import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import java.io.*; import java.util.HashMap; import java.util.Locale; @@ -83,7 +82,7 @@ public String[] getExchangeItemIDs() { return exchangeItemIDs; } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { return getExchangeItemIDs(); } diff --git a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMTimeInfoExchangeItem.java b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMTimeInfoExchangeItem.java index 199de8714..0d1e4ccaf 100644 --- a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMTimeInfoExchangeItem.java +++ b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMTimeInfoExchangeItem.java @@ -53,7 +53,7 @@ public ValueType getValuesType() { } public Role getRole() { - return IPrevExchangeItem.Role.InOut; + return IExchangeItem.Role.InOut; } public Object getValues() { diff --git a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMTimeSeriesDataObject.java b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMTimeSeriesDataObject.java index 79e482ea2..cceb4375f 100644 --- a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMTimeSeriesDataObject.java +++ b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMTimeSeriesDataObject.java @@ -27,14 +27,15 @@ import org.openda.exchange.timeseries.TimeSeriesSet; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem.Role; import org.openda.utils.Results; -import java.io.*; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; -import java.util.Set; public final class DFlowFMTimeSeriesDataObject implements IDataObject { public static final String PROPERTY_PATHNAME = "pathName"; @@ -65,10 +66,10 @@ public void initialize(File workingDir, String[] arguments) { } } this.timeSeriesSet = new TimeSeriesSet(); - this.amplitudes = new LinkedHashMap(); - this.phases = new LinkedHashMap(); - this.cmpFileNames = new ArrayList(); - this.cmpNameFromId = new LinkedHashMap(); + this.amplitudes = new LinkedHashMap<>(); + this.phases = new LinkedHashMap<>(); + this.cmpFileNames = new ArrayList<>(); + this.cmpNameFromId = new LinkedHashMap<>(); parseConfigurationFiles(mduFile); } @@ -138,7 +139,7 @@ public void parseConfigurationFiles(File mduFile) { String location = String.format("%s.%d" , locationId ,fileNr+1); String amplitudeId = location + idSeparator + quantity + "."+var+"_amplitude" ; double ampl = cmpfile.getAmplitude(var); - amplitude = new DoubleExchangeItem(amplitudeId, Role.InOut, ampl); + amplitude = new DoubleExchangeItem(amplitudeId, IExchangeItem.Role.InOut, ampl); amplitude.setQuantityInfo(new QuantityInfo(quantity + ".amplitude","m")); amplitude.setLatitude(lat); amplitude.setLongitude(lon); @@ -148,7 +149,7 @@ public void parseConfigurationFiles(File mduFile) { //phase String phaseId = location + idSeparator + quantity + "."+var+"_phase" ; double phi = cmpfile.getPhase(var); - phase = new DoubleExchangeItem(phaseId, Role.InOut, phi); + phase = new DoubleExchangeItem(phaseId, IExchangeItem.Role.InOut, phi); phase.setQuantityInfo(new QuantityInfo(quantity + ".phase","degrees")); phase.setLatitude(lat); phase.setLongitude(lon); @@ -175,10 +176,8 @@ public void parseConfigurationFiles(File mduFile) { public String [] getExchangeItemIDs() { String [] result = new String[this.timeSeriesSet.size()+2*this.amplitudes.size()]; int idx=0; - Iterator it = this.timeSeriesSet.iterator(); - while (it.hasNext()) { - TimeSeries t = it.next(); - result[idx]= t.getId(); + for (TimeSeries t : this.timeSeriesSet) { + result[idx] = t.getId(); idx++; } @@ -215,12 +214,10 @@ public IExchangeItem getDataObjectExchangeItem(String exchangeItemID) { throw new RuntimeException("No tidal phase found for " + exchangeItemID); } }else{ - Iterator iterator = this.timeSeriesSet.iterator(); - while (iterator.hasNext()) { - TimeSeries ts = iterator.next(); - if (exchangeItemID.equals(ts.getId()) ) { + for (TimeSeries ts : this.timeSeriesSet) { + if (exchangeItemID.equals(ts.getId())) { return ts; - }; + } } } return null; @@ -295,7 +292,7 @@ public TimeSeriesSet getTimeSeriesSet() { /** * @param set - * The TimeSeriesSet to set in this IoObject + * The TimeSeriesSet to set in this DataObject */ public void setTimeSeriesSet(TimeSeriesSet set) { this.timeSeriesSet = set; diff --git a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMTrachytopeFile.java b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMTrachytopeFile.java index 64f17008c..bd4a43bd7 100644 --- a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMTrachytopeFile.java +++ b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMTrachytopeFile.java @@ -20,10 +20,8 @@ package org.openda.model_dflowfm; -import org.openda.blackbox.interfaces.IoObjectInterface; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem.Role; import java.io.File; import java.util.ArrayList; @@ -168,8 +166,8 @@ public String[] getExchangeItemIDs() { } @Override - public String[] getExchangeItemIDs(Role role) { - if(role==Role.InOut){ + public String[] getExchangeItemIDs(IExchangeItem.Role role) { + if(role==IExchangeItem.Role.InOut){ return getExchangeItemIDs(); }else{ return new String[0]; diff --git a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMXyzExchangeItem.java b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMXyzExchangeItem.java index 166f89822..01b53d486 100644 --- a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMXyzExchangeItem.java +++ b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMXyzExchangeItem.java @@ -120,7 +120,7 @@ public IGeometryInfo getGeometryInfo() { public void copyValuesFromItem(IExchangeItem sourceItem) { if (this.valuetype != sourceItem.getValuesType()) { throw new RuntimeException("Incompatible value types in copy action from " + sourceItem.getId() + - " to " + getId() + "(" + sourceItem.getValueType().toString() + "/=" + this.valuetype.toString()); + " to " + getId() + "(" + sourceItem.getValuesType().getClass().toString() + "/=" + this.valuetype.toString()); } setValues(sourceItem.getValues()); } diff --git a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMXyzFile.java b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMXyzFile.java index f4a508cd0..401ced07a 100644 --- a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMXyzFile.java +++ b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DFlowFMXyzFile.java @@ -21,7 +21,6 @@ import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem.Role; import java.io.File; import java.util.ArrayList; @@ -157,7 +156,7 @@ public String[] getExchangeItemIDs() { } - public String[] getExchangeItemIDs(Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { ArrayList exchangeItemIDs = new ArrayList(); for (IExchangeItem item : this.exchangeItems) { if (item.getRole().equals(role)) { diff --git a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DflowfmFrictionCoefficientFile.java b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DflowfmFrictionCoefficientFile.java index b9e51d59c..5dc1c71ef 100644 --- a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DflowfmFrictionCoefficientFile.java +++ b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DflowfmFrictionCoefficientFile.java @@ -21,7 +21,6 @@ import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem.Role; import java.io.File; import java.util.ArrayList; @@ -109,7 +108,7 @@ public String[] getExchangeItemIDs() { } - public String[] getExchangeItemIDs(Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { ArrayList exchangeItemIDs = new ArrayList(); for (IExchangeItem item : this.exchangeItems) { if (item.getRole().equals(role)) { diff --git a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DimrConfigFile.java b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DimrConfigFile.java index 9784f0a62..ebb309838 100644 --- a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DimrConfigFile.java +++ b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/DimrConfigFile.java @@ -20,7 +20,6 @@ package org.openda.model_dflowfm; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.ConfigTree; import java.io.File; @@ -60,7 +59,7 @@ public String[] getExchangeItemIDs() return flowMdFile.getExchangeItemIDs(); } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) + public String[] getExchangeItemIDs(IExchangeItem.Role role) { return flowMdFile.getExchangeItemIDs(role); } diff --git a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/Flow1DTimeInfoExchangeItem.java b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/Flow1DTimeInfoExchangeItem.java index 7bc08e988..676cd2ef1 100644 --- a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/Flow1DTimeInfoExchangeItem.java +++ b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/Flow1DTimeInfoExchangeItem.java @@ -44,7 +44,7 @@ public Flow1DTimeInfoExchangeItem(PropertyId id, double value) @Override public Role getRole() { - return IPrevExchangeItem.Role.InOut; + return IExchangeItem.Role.InOut; } @Override @@ -56,9 +56,6 @@ public String getId() { @Override public String getDescription() { return id.name(); } - @Override - public Class getValueType() { return double.class; } - @Override public void copyValuesFromItem(IExchangeItem sourceItem) { setValues(sourceItem.getValues()); } diff --git a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/Md1dFile.java b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/Md1dFile.java index 701a9501f..4b843f6b7 100644 --- a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/Md1dFile.java +++ b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/Md1dFile.java @@ -23,7 +23,6 @@ import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import java.io.File; import java.io.IOException; @@ -116,7 +115,7 @@ public String[] getExchangeItemIDs() return exchangeItems.keySet().toArray(new String[exchangeItems.keySet().size()]); } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) + public String[] getExchangeItemIDs(IExchangeItem.Role role) { List matchingExchangeItemIds = new ArrayList<>(); for(IExchangeItem exchangeItem : exchangeItems.values()) diff --git a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/RtcToolsRuntimeConfigFile.java b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/RtcToolsRuntimeConfigFile.java index 2f7b0d915..36352525a 100644 --- a/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/RtcToolsRuntimeConfigFile.java +++ b/model_dflowfm_blackbox/java/src/org/openda/model_dflowfm/RtcToolsRuntimeConfigFile.java @@ -21,7 +21,6 @@ import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.ConfigTree; import java.io.File; @@ -91,7 +90,7 @@ public String[] getExchangeItemIDs() return exchangeItems.keySet().toArray(new String[exchangeItems.keySet().size()]); } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) + public String[] getExchangeItemIDs(IExchangeItem.Role role) { List matchingExchangeItemIds = new ArrayList<>(); for(IExchangeItem exchangeItem : exchangeItems.values()) diff --git a/model_dflowfm_blackbox/java/test/org/openda/model_dflowfm/DFlowFMTimeSeriesDataObjectTest.java b/model_dflowfm_blackbox/java/test/org/openda/model_dflowfm/DFlowFMTimeSeriesDataObjectTest.java index 43ffba113..e0f54e242 100644 --- a/model_dflowfm_blackbox/java/test/org/openda/model_dflowfm/DFlowFMTimeSeriesDataObjectTest.java +++ b/model_dflowfm_blackbox/java/test/org/openda/model_dflowfm/DFlowFMTimeSeriesDataObjectTest.java @@ -25,7 +25,6 @@ import org.openda.exchange.timeseries.TimeSeries; import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.OpenDaTestSupport; import java.io.File; diff --git a/model_dflowfm_blackbox/tests/calibration_discharge_dependent_river_roughness/stochModel/dflowfmWrapper.xml b/model_dflowfm_blackbox/tests/calibration_discharge_dependent_river_roughness/stochModel/dflowfmWrapper.xml index a603724ec..943a5583c 100644 --- a/model_dflowfm_blackbox/tests/calibration_discharge_dependent_river_roughness/stochModel/dflowfmWrapper.xml +++ b/model_dflowfm_blackbox/tests/calibration_discharge_dependent_river_roughness/stochModel/dflowfmWrapper.xml @@ -35,35 +35,35 @@ - + %frictionMultiplierFile% frictionCoefFile idsFromTemplateFile=%frictionMultiplierTemplateFile% idPrefix=friction_ - + - + %depthMultiplierFile% depthCoefFile idsFromTemplateFile=%depthMultiplierTemplateFile% idPrefix=depth_ - + - + %netcdfoutput% %netcdfoutput% true false - - + + %inputFile% boundaries - + - + %trachytopeFile% ttdFile - + diff --git a/model_dflowfm_blackbox/tests/calibration_river_roughness/stochModel/dflowfmWrapper.xml b/model_dflowfm_blackbox/tests/calibration_river_roughness/stochModel/dflowfmWrapper.xml index a603724ec..943a5583c 100644 --- a/model_dflowfm_blackbox/tests/calibration_river_roughness/stochModel/dflowfmWrapper.xml +++ b/model_dflowfm_blackbox/tests/calibration_river_roughness/stochModel/dflowfmWrapper.xml @@ -35,35 +35,35 @@ - + %frictionMultiplierFile% frictionCoefFile idsFromTemplateFile=%frictionMultiplierTemplateFile% idPrefix=friction_ - + - + %depthMultiplierFile% depthCoefFile idsFromTemplateFile=%depthMultiplierTemplateFile% idPrefix=depth_ - + - + %netcdfoutput% %netcdfoutput% true false - - + + %inputFile% boundaries - + - + %trachytopeFile% ttdFile - + diff --git a/model_dflowfm_blackbox/tests/dcsmv5_kalman/stochModel/dflowfmWrapper.xml b/model_dflowfm_blackbox/tests/dcsmv5_kalman/stochModel/dflowfmWrapper.xml index 0fd7a8245..9838b8af8 100644 --- a/model_dflowfm_blackbox/tests/dcsmv5_kalman/stochModel/dflowfmWrapper.xml +++ b/model_dflowfm_blackbox/tests/dcsmv5_kalman/stochModel/dflowfmWrapper.xml @@ -39,24 +39,24 @@ - + %mdufile% mdufile - - + + %mapfile% mapfile - - + + %outputdir%/%hisfile% hisfile true false - - + + %meteofile% meteofile - + diff --git a/model_dflowfm_blackbox/tests/estuary_calibration/stochModel/dflowfmWrapper.xml b/model_dflowfm_blackbox/tests/estuary_calibration/stochModel/dflowfmWrapper.xml index 6a7ebf07a..b3e6bf4f2 100644 --- a/model_dflowfm_blackbox/tests/estuary_calibration/stochModel/dflowfmWrapper.xml +++ b/model_dflowfm_blackbox/tests/estuary_calibration/stochModel/dflowfmWrapper.xml @@ -34,30 +34,30 @@ - + %frictionMultiplierFile% frictionCoefFile idsFromTemplateFile=%frictionMultiplierTemplateFile% idPrefix=friction_ - + - + %depthMultiplierFile% depthCoefFile idsFromTemplateFile=%depthMultiplierTemplateFile% idPrefix=depth_ - + - + %netcdfoutput% %netcdfoutput% true false - - + + %inputFile% boundaries - + diff --git a/model_dflowfm_blackbox/tests/estuary_kalman/stochModel/dflowfmWrapper.xml b/model_dflowfm_blackbox/tests/estuary_kalman/stochModel/dflowfmWrapper.xml index ef26f2d9d..2d2b4a4ad 100644 --- a/model_dflowfm_blackbox/tests/estuary_kalman/stochModel/dflowfmWrapper.xml +++ b/model_dflowfm_blackbox/tests/estuary_kalman/stochModel/dflowfmWrapper.xml @@ -39,24 +39,24 @@ - + %mdufile% mdufile - - + + %mapfile% mapfile - - + + %outputdir%/%hisfile% hisfile true false - - + + %mdufile% boundaries - + diff --git a/model_dflowfm_blackbox/tests/estuary_kalman_FMSuite2019.01/stochModel/dflowfmWrapper.xml b/model_dflowfm_blackbox/tests/estuary_kalman_FMSuite2019.01/stochModel/dflowfmWrapper.xml index 016eba827..d380ded3a 100644 --- a/model_dflowfm_blackbox/tests/estuary_kalman_FMSuite2019.01/stochModel/dflowfmWrapper.xml +++ b/model_dflowfm_blackbox/tests/estuary_kalman_FMSuite2019.01/stochModel/dflowfmWrapper.xml @@ -41,24 +41,24 @@ - + %mdufile% mdufile - - + + %mapfile% mapfile - - + + %hisfile% hisfile true false - - + + %mdufile% boundaries - + diff --git a/model_dflowfm_blackbox/tests/estuary_kalman_FMSuite2019.01_bcfile/stochModel/dflowfmWrapper.xml b/model_dflowfm_blackbox/tests/estuary_kalman_FMSuite2019.01_bcfile/stochModel/dflowfmWrapper.xml index df1d5e072..85d9c6f91 100644 --- a/model_dflowfm_blackbox/tests/estuary_kalman_FMSuite2019.01_bcfile/stochModel/dflowfmWrapper.xml +++ b/model_dflowfm_blackbox/tests/estuary_kalman_FMSuite2019.01_bcfile/stochModel/dflowfmWrapper.xml @@ -41,29 +41,29 @@ - + %mdufile% mdufile - - + + %mapfile% mapfile - - + + %hisfile% hisfile true false - - - + + dflowfm/waterlevel_noise.bc bcfile dflowfm/waterlevel_noise.bc - + diff --git a/model_dflowfm_blackbox/tests/lake_kalman/stochModel/dflowfmWrapper.xml b/model_dflowfm_blackbox/tests/lake_kalman/stochModel/dflowfmWrapper.xml index 0fd7a8245..9838b8af8 100644 --- a/model_dflowfm_blackbox/tests/lake_kalman/stochModel/dflowfmWrapper.xml +++ b/model_dflowfm_blackbox/tests/lake_kalman/stochModel/dflowfmWrapper.xml @@ -39,24 +39,24 @@ - + %mdufile% mdufile - - + + %mapfile% mapfile - - + + %outputdir%/%hisfile% hisfile true false - - + + %meteofile% meteofile - + diff --git a/model_dflowfm_blackbox/tests/lake_kalman/stochObserver/dflowfmStochObsConfig.xml b/model_dflowfm_blackbox/tests/lake_kalman/stochObserver/dflowfmStochObsConfig.xml index 4ded5bda9..9428d621f 100644 --- a/model_dflowfm_blackbox/tests/lake_kalman/stochObserver/dflowfmStochObsConfig.xml +++ b/model_dflowfm_blackbox/tests/lake_kalman/stochObserver/dflowfmStochObsConfig.xml @@ -1,11 +1,11 @@ - + stochObsUncertainties.xml - + lake2d_his.nc true false - - + + diff --git a/model_dflowfm_blackbox/tests/simple_waal_calibration_roughness/stochModel/dflowfmWrapper.xml b/model_dflowfm_blackbox/tests/simple_waal_calibration_roughness/stochModel/dflowfmWrapper.xml index 39ebd42ac..4644eeb0a 100644 --- a/model_dflowfm_blackbox/tests/simple_waal_calibration_roughness/stochModel/dflowfmWrapper.xml +++ b/model_dflowfm_blackbox/tests/simple_waal_calibration_roughness/stochModel/dflowfmWrapper.xml @@ -32,19 +32,19 @@ - + %frictionMultiplierFile% frictionCoefFile idsFromTemplateFile=%frictionMultiplierTemplateFile% idPrefix=friction_ - + - + %netcdfoutput% %netcdfoutput% true false - + diff --git a/model_dflowfm_blackbox/tests/simple_waal_kalman/stochModel/dflowfmWrapper.xml b/model_dflowfm_blackbox/tests/simple_waal_kalman/stochModel/dflowfmWrapper.xml index ea1cbf9a5..02ab02669 100644 --- a/model_dflowfm_blackbox/tests/simple_waal_kalman/stochModel/dflowfmWrapper.xml +++ b/model_dflowfm_blackbox/tests/simple_waal_kalman/stochModel/dflowfmWrapper.xml @@ -38,24 +38,24 @@ - + %mdufile% mdufile - - + + %mapfile% mapfile - - + + %outputdir%/%hisfile% hisfile true false - - + + %mdufile% boundaries - + diff --git a/model_dflowfm_blackbox/tests/simple_waal_salt_kalman/stochModel/dflowfmWrapper.xml b/model_dflowfm_blackbox/tests/simple_waal_salt_kalman/stochModel/dflowfmWrapper.xml index ef26f2d9d..2d2b4a4ad 100644 --- a/model_dflowfm_blackbox/tests/simple_waal_salt_kalman/stochModel/dflowfmWrapper.xml +++ b/model_dflowfm_blackbox/tests/simple_waal_salt_kalman/stochModel/dflowfmWrapper.xml @@ -39,24 +39,24 @@ - + %mdufile% mdufile - - + + %mapfile% mapfile - - + + %outputdir%/%hisfile% hisfile true false - - + + %mdufile% boundaries - + diff --git a/model_efdc/java/src/org/openda/model_efdc/EfdcEventTox2InpIoObject.java b/model_efdc/java/src/org/openda/model_efdc/EfdcEventTox2InpDataObject.java similarity index 76% rename from model_efdc/java/src/org/openda/model_efdc/EfdcEventTox2InpIoObject.java rename to model_efdc/java/src/org/openda/model_efdc/EfdcEventTox2InpDataObject.java index db19411bd..efd9525b3 100644 --- a/model_efdc/java/src/org/openda/model_efdc/EfdcEventTox2InpIoObject.java +++ b/model_efdc/java/src/org/openda/model_efdc/EfdcEventTox2InpDataObject.java @@ -20,6 +20,13 @@ package org.openda.model_efdc; +import org.openda.exchange.AbstractDataObject; +import org.openda.exchange.DoubleExchangeItem; +import org.openda.exchange.timeseries.TimeUtils; +import org.openda.utils.Results; +import org.openda.utils.Time; +import org.openda.utils.io.AsciiFileUtils; + import java.io.File; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -27,14 +34,6 @@ import java.util.List; import java.util.TimeZone; -import org.openda.blackbox.interfaces.IoObjectInterface; -import org.openda.exchange.DoubleExchangeItem; -import org.openda.exchange.timeseries.TimeUtils; -import org.openda.interfaces.IPrevExchangeItem; -import org.openda.utils.Results; -import org.openda.utils.Time; -import org.openda.utils.io.AsciiFileUtils; - /** * The EVENT_TOX2.INP control input file for the EFDC (Environmental Fluid Dynamics Code) model * is searched for keywords in the format $$. All "$$" strings found @@ -47,7 +46,7 @@ * * @author Arno Kockx */ -public class EfdcEventTox2InpIoObject implements IoObjectInterface { +public class EfdcEventTox2InpDataObject extends AbstractDataObject { private static final String TAG = "$"; private static final String TSTART_TAG = "TSTART"; @@ -61,44 +60,48 @@ public class EfdcEventTox2InpIoObject implements IoObjectInterface { */ private TimeZone timeZone = TimeZone.getTimeZone("GMT"); - private IPrevExchangeItem startTimeExchangeItem = null; - private IPrevExchangeItem endTimeExchangeItem = null; private File eventTox2InpFile; private DateFormat dateFormat; + private String startTimeID; + private String endTimeID; - /** + /** * @param workingDir the working directory. - * @param fileName the name of the file containing the data for this IoObject (relative to the working directory). - * @param arguments the first argument should be the timeZone that is used by the model (in hours with respect to GMT, between -12 and 12), - * the second and third arguments should be the ids of the startTime and endTime exchangeItems respectively. + * @param arguments the first argument should be the the name of the file containing the data for this IDataObject (relative to the working directory), + * the second argument should be the timeZone that is used by the model (in hours with respect to GMT, between -12 and 12), + * the third and fourth arguments should be the ids of the startTime and endTime exchangeItems respectively. */ - - public void initialize(File workingDir, String fileName, String[] arguments) { - this.eventTox2InpFile = new File(workingDir, fileName); - //get timeZone. - if (arguments == null || arguments.length < 1) { - throw new IllegalArgumentException("No timeZone argument specified for " + this.getClass().getSimpleName() - + ". The first argument should be the timeZone that is used by the model" - + " (in hours with respect to GMT, between -12 and 12)."); - } + @Override + public void initialize(File workingDir, String[] arguments) { + //get timeZone. + if (arguments == null || arguments.length < 2) { + throw new IllegalArgumentException("No timeZone argument specified for " + this.getClass().getSimpleName() + + ". The second argument should be the timeZone that is used by the model" + + " (in hours with respect to GMT, between -12 and 12)."); + } + + this.eventTox2InpFile = new File(workingDir, arguments[0]); + try { - double timeZoneOffsetInHours = Double.parseDouble(arguments[0]); + double timeZoneOffsetInHours = Double.parseDouble(arguments[1]); this.timeZone = TimeUtils.createTimeZoneFromDouble(timeZoneOffsetInHours); } catch (Exception e) { - throw new IllegalArgumentException("Cannot parse first argument '" + arguments[0] + throw new IllegalArgumentException("Cannot parse first argument '" + arguments[1] + "' for " + this.getClass().getSimpleName() + ". The first argument should be the timeZone that is used by the model" + " (in hours with respect to GMT, between -12 and 12).", e); } //create exchange items. - if (arguments.length < 3) { + if (arguments.length < 4) { throw new IllegalArgumentException("No exchange item ids arguments specified for " + this.getClass().getSimpleName() - + ". The second and third arguments should be the ids of the startTime and endTime exchangeItems respectively."); + + ". The third and fourth arguments should be the ids of the startTime and endTime exchangeItems respectively."); } - this.startTimeExchangeItem = new DoubleExchangeItem(arguments[1], 0); - this.endTimeExchangeItem = new DoubleExchangeItem(arguments[2], 0); + startTimeID = arguments[2]; + endTimeID = arguments[3]; + exchangeItems.put(startTimeID, new DoubleExchangeItem(startTimeID, 0)); + exchangeItems.put(endTimeID, new DoubleExchangeItem(endTimeID, 0)); //The dateFormat for the start and end dates in the EVENT_TOX2.INP file is yyyy MM dd HH mm, e.g.: //"2009 01 01 09 00" @@ -107,12 +110,7 @@ public void initialize(File workingDir, String fileName, String[] arguments) { this.dateFormat.setTimeZone(this.timeZone); } - - public IPrevExchangeItem[] getExchangeItems() { - return new IPrevExchangeItem[]{this.startTimeExchangeItem, this.endTimeExchangeItem}; - } - - + @Override public void finish() { writeControlFile(); } @@ -122,7 +120,7 @@ public void finish() { * that correspond to the ids of the exchangeItems. */ public void writeControlFile() { - if (this.startTimeExchangeItem == null || this.endTimeExchangeItem == null) { + if (exchangeItems.isEmpty()) { throw new IllegalStateException("EfdcEventTox2InpIoObject not initialized yet."); } if (!this.eventTox2InpFile.exists()) { @@ -135,8 +133,8 @@ public void writeControlFile() { List content = AsciiFileUtils.readLines(this.eventTox2InpFile); //get start and stop times. - double startTime = (Double) this.startTimeExchangeItem.getValues(); - double endTime = (Double) this.endTimeExchangeItem.getValues(); + double startTime = (Double) this.exchangeItems.get(startTimeID).getValues(); + double endTime = (Double) this.exchangeItems.get(endTimeID).getValues(); //get keyword values. String startTimeString = getTimeString(startTime); diff --git a/model_efdc/java/src/org/openda/model_efdc/EfdcGridTimeSeriesIoObject.java b/model_efdc/java/src/org/openda/model_efdc/EfdcGridTimeSeriesDataObject.java similarity index 81% rename from model_efdc/java/src/org/openda/model_efdc/EfdcGridTimeSeriesIoObject.java rename to model_efdc/java/src/org/openda/model_efdc/EfdcGridTimeSeriesDataObject.java index a5383a834..c0a623b48 100644 --- a/model_efdc/java/src/org/openda/model_efdc/EfdcGridTimeSeriesIoObject.java +++ b/model_efdc/java/src/org/openda/model_efdc/EfdcGridTimeSeriesDataObject.java @@ -20,23 +20,21 @@ package org.openda.model_efdc; +import org.openda.exchange.AbstractDataObject; +import org.openda.exchange.timeseries.TimeUtils; +import org.openda.interfaces.IExchangeItem; +import org.openda.utils.Results; +import org.openda.utils.Time; + import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.text.ParseException; import java.util.ArrayList; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import java.util.TimeZone; -import org.openda.blackbox.interfaces.IoObjectInterface; -import org.openda.exchange.timeseries.TimeUtils; -import org.openda.interfaces.IPrevExchangeItem; -import org.openda.utils.Results; -import org.openda.utils.Time; - /** * IoObject for a .DAT (EFDC grid output) file that contains one or more grid time series. * The .DAT file with grid data is generated from the binary model output @@ -46,60 +44,59 @@ * * @author Arno Kockx */ -public class EfdcGridTimeSeriesIoObject implements IoObjectInterface { - - /** - * The timeZone that is used by the model. - * This is required to convert the times of the data values - * to/from the timeZone that is used by the model. - * Default is GMT. - */ - private TimeZone timeZone = TimeZone.getTimeZone("GMT"); +public class EfdcGridTimeSeriesDataObject extends AbstractDataObject { - private File timeSeriesFile; - private Map timeSeriesExchangeItems = new LinkedHashMap(); + private File timeSeriesFile; /** * @param workingDir the working directory. - * @param fileName the name of the file containing the data for this IoObject (relative to the working directory). - * @param arguments the first argument should be the timeZone that is used by the model (in hours with respect to GMT, between -12 and 12), - * the second argument should be the startTime of the model run. + * @param arguments the first argument should be the name of the file containing the data for this IDataObject (relative to the working directory). + * the second argument should be the timeZone that is used by the model (in hours with respect to GMT, between -12 and 12), + * the third argument should be the startTime of the model run. */ - - public void initialize(File workingDir, String fileName, String[] arguments) { - this.timeSeriesFile = new File(workingDir, fileName); + + @Override + public void initialize(File workingDir, String[] arguments) { + this.timeSeriesFile = new File(workingDir, arguments[0]); //get timeZone. - if (arguments == null || arguments.length < 1) { + if (arguments.length < 2) { throw new IllegalArgumentException("No timeZone argument specified for " + this.getClass().getSimpleName() - + ". The first argument should be the timeZone that is used by the model" + + ". The second argument should be the timeZone that is used by the model" + " (in hours with respect to GMT, between -12 and 12)."); } - try { - double timeZoneOffsetInHours = Double.parseDouble(arguments[0]); - this.timeZone = TimeUtils.createTimeZoneFromDouble(timeZoneOffsetInHours); + /** + * The timeZone that is used by the model. + * This is required to convert the times of the data values + * to/from the timeZone that is used by the model. + * Default is GMT. + */ + TimeZone timeZone = TimeZone.getTimeZone("GMT"); + try { + double timeZoneOffsetInHours = Double.parseDouble(arguments[1]); + timeZone = TimeUtils.createTimeZoneFromDouble(timeZoneOffsetInHours); } catch (Exception e) { - throw new IllegalArgumentException("Cannot parse first argument '" + arguments[0] + throw new IllegalArgumentException("Cannot parse second argument '" + arguments[1] + "' for " + this.getClass().getSimpleName() - + ". The first argument should be the timeZone that is used by the model" + + ". The second argument should be the timeZone that is used by the model" + " (in hours with respect to GMT, between -12 and 12).", e); } //get start time. - if (arguments.length < 2) { + if (arguments.length < 3) { throw new IllegalArgumentException("No startTime argument specified for " + this.getClass().getSimpleName() - + ". The second argument should be the start time of the model run."); + + ". The third argument should be the start time of the model run."); } double startTime; try { - startTime = TimeUtils.date2Mjd(arguments[1]); + startTime = TimeUtils.date2Mjd(arguments[2]); } catch (ParseException e) { throw new IllegalArgumentException("Invalid startTime argument specified for " + this.getClass().getSimpleName() - + ". Cannot parse second argument '" + arguments[1] - + "'. The second argument should be the startTime of the model run.", e); + + ". Cannot parse third argument '" + arguments[2] + + "'. The third argument should be the startTime of the model run.", e); } //determine referenceTime. - long referenceTime = EfdcUtils.getReferenceTime(Time.mjdToMillies(startTime), this.timeZone); + long referenceTime = EfdcUtils.getReferenceTime(Time.mjdToMillies(startTime), timeZone); //read data from file and create exchangeItems. createTimeSeriesExchangeItems(this.timeSeriesFile, referenceTime); @@ -109,7 +106,7 @@ public void initialize(File workingDir, String fileName, String[] arguments) { * Reads the data from the given inputFile and creates an * exchangeItem for each data column in the file. * - * @param inputFile + * @param inputFile inputFile */ private void createTimeSeriesExchangeItems(File inputFile, long referenceTime) { if (!inputFile.exists()) { @@ -149,7 +146,7 @@ private void createTimeSeriesExchangeItems(File inputFile, long referenceTime) { /** * Returns the number of columns for the data in the given inputFile. * - * @param inputFile + * @param inputFile InputFile */ private int readColumnCount(File inputFile) { if (!inputFile.exists()) { @@ -173,10 +170,8 @@ private int readColumnCount(File inputFile) { line = reader.readLine(); if (line != null) { String[] columns = line.trim().split("\\s+"); - if (columns != null) { - columnCount = columns.length; - } - } + columnCount = columns.length; + } } finally { reader.close(); @@ -192,7 +187,7 @@ private int readColumnCount(File inputFile) { /** * Returns the number of grid cells for the first time for the data in the given inputFile. * - * @param inputFile + * @param inputFile InputFile */ private int readCellCount(File inputFile) { if (!inputFile.exists()) { @@ -217,7 +212,7 @@ private int readCellCount(File inputFile) { line = reader.readLine(); while (line != null) { String[] columns = line.trim().split("\\s+"); - if (columns == null || columns.length < 1) { + if (columns.length < 1) { throw new IllegalArgumentException("Invalid empty line in file " + inputFile.getAbsolutePath()); } @@ -260,7 +255,7 @@ private double[] readTimes(File inputFile, int cellCount, long referenceTime) { + "' does not exist."); } - List timesList = new ArrayList(); + List timesList = new ArrayList<>(); try { BufferedReader reader = new BufferedReader(new FileReader(inputFile)); @@ -277,7 +272,7 @@ private double[] readTimes(File inputFile, int cellCount, long referenceTime) { while (line != null) { //read time. String[] columns = line.trim().split("\\s+"); - if (columns == null || columns.length < 1) { + if (columns.length < 1) { throw new IllegalArgumentException("Invalid empty line in file " + inputFile.getAbsolutePath()); } double time = parseDouble(columns[0], inputFile); @@ -305,7 +300,7 @@ private double[] readTimes(File inputFile, int cellCount, long referenceTime) { for (int n = 0; n < timesList.size(); n++) { double relativeTime = timesList.get(n); times[n] = Time.milliesToMjd(EfdcUtils.getAbsoluteTime(relativeTime, - referenceTime, EfdcTimeSeriesIoObject.SECONDS_PER_TIME_UNIT)); + referenceTime, EfdcTimeSeriesDataObject.SECONDS_PER_TIME_UNIT)); } return times; @@ -348,7 +343,7 @@ private double[][][] readData(File inputFile, int columnCount, int timeCount, in int cellIndex = 0; while (line != null && cellIndex < cellCount) { String[] columns = line.trim().split("\\s+"); - if (columns == null || columns.length < columnCount) { + if (columns.length < columnCount) { throw new IllegalArgumentException("Invalid line '" + line + "' in file '" + inputFile.getAbsolutePath() + "'. " + columnCount + " columns expected."); } @@ -387,39 +382,29 @@ private static double parseDouble(String string, File inputFile) { } private void createTimeSeriesExchangeItems(double[] times, double[][][] data) { - //reset this.timeSeriesExchangeItems list. - this.timeSeriesExchangeItems.clear(); - //create an exchangeItem for each data column. If only some columns are used, //then the whole file has to be read anyway, so always filling all column exchangeItems //if some are not used will not take much extra time. for (int parameterIndex = 0; parameterIndex < data.length; parameterIndex++) { //use the columnNumber (not columnIndex) as the id for the exchangeItem. int columnNumber = parameterIndex + 5; - IPrevExchangeItem exchangeItem = new EfdcGridTimeSeriesExchangeItem(String.valueOf(columnNumber)); + IExchangeItem exchangeItem = new EfdcGridTimeSeriesExchangeItem(String.valueOf(columnNumber)); //set times and values. exchangeItem.setTimes(times); exchangeItem.setValues(data[parameterIndex]); //add exchangeItem. - this.timeSeriesExchangeItems.put(columnNumber, exchangeItem); + exchangeItems.put(String.valueOf(columnNumber), exchangeItem); } - if (this.timeSeriesExchangeItems.isEmpty()) { + if (exchangeItems.isEmpty()) { throw new IllegalArgumentException("No time series found for time series file '" + this.timeSeriesFile.getAbsolutePath() + "'."); } } - - public IPrevExchangeItem[] getExchangeItems() { - //return all available exchange items. - List exchangeItems = new ArrayList(this.timeSeriesExchangeItems.values()); - return exchangeItems.toArray(new IPrevExchangeItem[exchangeItems.size()]); - } - - + @Override public void finish() { //do nothing. } diff --git a/model_efdc/java/src/org/openda/model_efdc/EfdcGridTimeSeriesExchangeItem.java b/model_efdc/java/src/org/openda/model_efdc/EfdcGridTimeSeriesExchangeItem.java index 3f754377e..7a7f8d247 100644 --- a/model_efdc/java/src/org/openda/model_efdc/EfdcGridTimeSeriesExchangeItem.java +++ b/model_efdc/java/src/org/openda/model_efdc/EfdcGridTimeSeriesExchangeItem.java @@ -46,11 +46,6 @@ public Role getRole() { return Role.Output; } - - @SuppressWarnings("rawtypes") - public Class getValueType() { - return double[][].class; - } public ValueType getValuesType() { return ValueType.doubles2dType; diff --git a/model_efdc/java/src/org/openda/model_efdc/EfdcInpIoObject.java b/model_efdc/java/src/org/openda/model_efdc/EfdcInpDataObject.java similarity index 85% rename from model_efdc/java/src/org/openda/model_efdc/EfdcInpIoObject.java rename to model_efdc/java/src/org/openda/model_efdc/EfdcInpDataObject.java index 0ae97465a..5e94bbb60 100644 --- a/model_efdc/java/src/org/openda/model_efdc/EfdcInpIoObject.java +++ b/model_efdc/java/src/org/openda/model_efdc/EfdcInpDataObject.java @@ -20,19 +20,18 @@ package org.openda.model_efdc; -import java.io.File; -import java.util.Iterator; -import java.util.List; -import java.util.TimeZone; - -import org.openda.blackbox.interfaces.IoObjectInterface; +import org.openda.exchange.AbstractDataObject; import org.openda.exchange.DoubleExchangeItem; import org.openda.exchange.timeseries.TimeUtils; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.Results; import org.openda.utils.Time; import org.openda.utils.io.AsciiFileUtils; +import java.io.File; +import java.util.Iterator; +import java.util.List; +import java.util.TimeZone; + /** * The EFDC.INP control input file for the EFDC (Environmental Fluid Dynamics Code) model * is searched for keywords in the format $$. All "$$" strings found @@ -41,7 +40,7 @@ * * @author Arno Kockx */ -public class EfdcInpIoObject implements IoObjectInterface { +public class EfdcInpDataObject extends AbstractDataObject { private static final String TAG = "$"; private static final String RELATIVE_TSTART_TAG = "RELATIVE_TSTART"; @@ -54,52 +53,49 @@ public class EfdcInpIoObject implements IoObjectInterface { * Default is GMT. */ private TimeZone timeZone = TimeZone.getTimeZone("GMT"); - - private IPrevExchangeItem startTimeExchangeItem = null; - private IPrevExchangeItem endTimeExchangeItem = null; private File efdcInpFile; + private String startTimeID; + private String endTimeID; - /** + /** * @param workingDir the working directory. - * @param fileName the name of the file containing the data for this IoObject (relative to the working directory). - * @param arguments the first argument should be the timeZone that is used by the model (in hours with respect to GMT, between -12 and 12), - * the second and third arguments should be the ids of the startTime and endTime exchangeItems respectively. + * @param arguments the first argument is the name of the file containing the data for this IoObject (relative to the working directory), + * the second argument should be the timeZone that is used by the model (in hours with respect to GMT, between -12 and 12), + * the third and fourth arguments should be the ids of the startTime and endTime exchangeItems respectively. */ - - public void initialize(File workingDir, String fileName, String[] arguments) { - this.efdcInpFile = new File(workingDir, fileName); + + @Override + public void initialize(File workingDir, String[] arguments) { + this.efdcInpFile = new File(workingDir, arguments[0]); //get timeZone. - if (arguments == null || arguments.length < 1) { + if (arguments.length < 2) { throw new IllegalArgumentException("No timeZone argument specified for " + this.getClass().getSimpleName() - + ". The first argument should be the timeZone that is used by the model" + + ". The second argument should be the timeZone that is used by the model" + " (in hours with respect to GMT, between -12 and 12)."); } try { - double timeZoneOffsetInHours = Double.parseDouble(arguments[0]); + double timeZoneOffsetInHours = Double.parseDouble(arguments[1]); this.timeZone = TimeUtils.createTimeZoneFromDouble(timeZoneOffsetInHours); } catch (Exception e) { - throw new IllegalArgumentException("Cannot parse first argument '" + arguments[0] + throw new IllegalArgumentException("Cannot parse second argument '" + arguments[1] + "' for " + this.getClass().getSimpleName() - + ". The first argument should be the timeZone that is used by the model" + + ". The second argument should be the timeZone that is used by the model" + " (in hours with respect to GMT, between -12 and 12).", e); } //create exchange items. - if (arguments.length < 3) { + if (arguments.length < 4) { throw new IllegalArgumentException("No exchange item ids arguments specified for " + this.getClass().getSimpleName() - + ". The second and third arguments should be the ids of the startTime and endTime exchangeItems respectively."); + + ". The third and fourth arguments should be the ids of the startTime and endTime exchangeItems respectively."); } - this.startTimeExchangeItem = new DoubleExchangeItem(arguments[1], 0); - this.endTimeExchangeItem = new DoubleExchangeItem(arguments[2], 0); - } - - - public IPrevExchangeItem[] getExchangeItems() { - return new IPrevExchangeItem[]{this.startTimeExchangeItem, this.endTimeExchangeItem}; + startTimeID = arguments[2]; + endTimeID = arguments[3]; + exchangeItems.put(startTimeID, new DoubleExchangeItem(startTimeID, 0)); + exchangeItems.put(endTimeID, new DoubleExchangeItem(endTimeID, 0)); } - + @Override public void finish() { writeControlFile(); } @@ -109,7 +105,7 @@ public void finish() { * that correspond to the ids of the exchangeItems. */ private void writeControlFile() { - if (this.startTimeExchangeItem == null || this.endTimeExchangeItem == null) { + if (exchangeItems.isEmpty()) { throw new IllegalStateException("EfdcInpIoObject not initialized yet."); } if (!this.efdcInpFile.exists()) { @@ -119,8 +115,8 @@ private void writeControlFile() { Results.putMessage(this.getClass().getSimpleName() + ": replacing tags in file " + this.efdcInpFile.getAbsolutePath()); //get start and stop times. - double startTimeDouble = (Double) this.startTimeExchangeItem.getValues(); - double endTimeDouble = (Double) this.endTimeExchangeItem.getValues(); + double startTimeDouble = (Double) this.exchangeItems.get(startTimeID).getValues(); + double endTimeDouble = (Double) this.exchangeItems.get(endTimeID).getValues(); //read file. List content = AsciiFileUtils.readLines(this.efdcInpFile); @@ -186,7 +182,7 @@ private double getSecondsPerTimeUnit(List content) { throw new RuntimeException("Card image with number 8 not found in EFDC.INP file."); } String[] strings = parameterLine.trim().split("\\s+"); - if (strings == null || strings.length < 1) { + if (strings.length < 1) { throw new RuntimeException("TCON not found in EFDC.INP file. Card image with number 8 contains not enough parameters."); } String tCon = strings[0]; @@ -231,7 +227,7 @@ private double getSecondsPerReferencePeriod(List content) { throw new RuntimeException("Card image with number 8 not found in EFDC.INP file."); } String[] strings = parameterLine.trim().split("\\s+"); - if (strings == null || strings.length < 3) { + if (strings.length < 3) { throw new RuntimeException("TREF not found in EFDC.INP file. Card image with number 8 contains not enough parameters."); } String tRef = strings[2]; @@ -264,7 +260,7 @@ private String getFirstParameterLineForCardImage(List content, int cardI String line = iterator.next(); String[] strings = line.trim().split("\\s+"); - if (strings != null && strings.length > 0 && searchString.equalsIgnoreCase(strings[0])) { + if (strings.length > 0 && searchString.equalsIgnoreCase(strings[0])) { if (!firstLineFound) { firstLineFound = true; continue; diff --git a/model_efdc/java/src/org/openda/model_efdc/EfdcRestartFileIoObject.java b/model_efdc/java/src/org/openda/model_efdc/EfdcRestartFileDataObject.java similarity index 74% rename from model_efdc/java/src/org/openda/model_efdc/EfdcRestartFileIoObject.java rename to model_efdc/java/src/org/openda/model_efdc/EfdcRestartFileDataObject.java index df4010d70..ed9eb002e 100644 --- a/model_efdc/java/src/org/openda/model_efdc/EfdcRestartFileIoObject.java +++ b/model_efdc/java/src/org/openda/model_efdc/EfdcRestartFileDataObject.java @@ -20,26 +20,25 @@ package org.openda.model_efdc; -import java.io.File; -import java.util.List; -import java.util.Locale; -import java.util.TimeZone; - -import org.openda.blackbox.interfaces.IoObjectInterface; +import org.openda.exchange.AbstractDataObject; import org.openda.exchange.DoubleExchangeItem; import org.openda.exchange.timeseries.TimeUtils; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.Results; import org.openda.utils.Time; import org.openda.utils.io.AsciiFileUtils; +import java.io.File; +import java.util.List; +import java.util.Locale; +import java.util.TimeZone; + /** * This IoObject changes the relative startTime in the RESTART.INP file, * which is used for the EFDC (Environmental Fluid Dynamics Code) model. * * @author Arno Kockx */ -public class EfdcRestartFileIoObject implements IoObjectInterface { +public class EfdcRestartFileDataObject extends AbstractDataObject { /** * The timeZone that is used by the model. @@ -49,49 +48,46 @@ public class EfdcRestartFileIoObject implements IoObjectInterface { */ private TimeZone timeZone = TimeZone.getTimeZone("GMT"); - private IPrevExchangeItem startTimeExchangeItem = null; - private File efdcRestartFile; + private String startTimeID; + private File efdcRestartFile; - /** + /** * @param workingDir the working directory. - * @param fileName the name of the restart file for this IoObject (relative to the working directory). - * @param arguments the first argument should be the timeZone that is used by the model (in hours with respect to GMT, between -12 and 12), - * the second argument should be the id of the startTime exchangeItem. + * @param arguments the first argument should be the name of the restart file for this IoObject (relative to the working directory), + * the second argument should be the timeZone that is used by the model (in hours with respect to GMT, between -12 and 12), + * the third argument should be the id of the startTime exchangeItem. */ - - public void initialize(File workingDir, String fileName, String[] arguments) { - this.efdcRestartFile = new File(workingDir, fileName); + + @Override + public void initialize(File workingDir, String[] arguments) { + this.efdcRestartFile = new File(workingDir, arguments[0]); //get timeZone. - if (arguments == null || arguments.length < 1) { + if (arguments.length < 2) { throw new IllegalArgumentException("No timeZone argument specified for " + this.getClass().getSimpleName() - + ". The first argument should be the timeZone that is used by the model" + + ". The second argument should be the timeZone that is used by the model" + " (in hours with respect to GMT, between -12 and 12)."); } try { - double timeZoneOffsetInHours = Double.parseDouble(arguments[0]); + double timeZoneOffsetInHours = Double.parseDouble(arguments[1]); this.timeZone = TimeUtils.createTimeZoneFromDouble(timeZoneOffsetInHours); } catch (Exception e) { - throw new IllegalArgumentException("Cannot parse first argument '" + arguments[0] + throw new IllegalArgumentException("Cannot parse second argument '" + arguments[1] + "' for " + this.getClass().getSimpleName() - + ". The first argument should be the timeZone that is used by the model" + + ". The second argument should be the timeZone that is used by the model" + " (in hours with respect to GMT, between -12 and 12).", e); } //create exchange items. - if (arguments.length < 2) { + if (arguments.length < 3) { throw new IllegalArgumentException("No exchange item id argument specified for " + this.getClass().getSimpleName() - + ". The second argument should be the id of the startTime exchangeItem."); + + ". The third argument should be the id of the startTime exchangeItem."); } - this.startTimeExchangeItem = new DoubleExchangeItem(arguments[1], 0); - } - - - public IPrevExchangeItem[] getExchangeItems() { - return new IPrevExchangeItem[]{this.startTimeExchangeItem}; + startTimeID = arguments[2]; + exchangeItems.put(startTimeID, new DoubleExchangeItem(arguments[2], 0)); } - + @Override public void finish() { changeRelativeStartTimeInRestartFile(); } @@ -100,7 +96,7 @@ public void finish() { * This method changes the relative startTime in the RESTART.INP file. */ private void changeRelativeStartTimeInRestartFile() { - if (this.startTimeExchangeItem == null) { + if (exchangeItems.isEmpty()) { throw new IllegalStateException("EfdcRestartFileIoObject not initialized yet."); } if (!this.efdcRestartFile.exists()) { @@ -109,14 +105,14 @@ private void changeRelativeStartTimeInRestartFile() { } //get start time. - double startTimeDouble = (Double) this.startTimeExchangeItem.getValues(); + double startTimeDouble = (Double) this.exchangeItems.get(startTimeID).getValues(); //get relative start time. double relativeStartTime = getRelativeStartTime(startTimeDouble, - EfdcTimeSeriesIoObject.SECONDS_PER_TIME_UNIT, this.timeZone); + this.timeZone); //read file. List content = AsciiFileUtils.readLines(this.efdcRestartFile); - if (content == null || content.size() < 1) { + if (content.size() < 1) { throw new RuntimeException("Invalid RESTART.INP file. File is empty."); } @@ -159,9 +155,9 @@ private int getIndexOfWhiteSpaceAfterFirstNumber(String line) { return -1; } - private double getRelativeStartTime(double startTimeDouble, double secondsPerTimeUnit, TimeZone timeZone) { + private double getRelativeStartTime(double startTimeDouble, TimeZone timeZone) { long startTime = Time.mjdToMillies(startTimeDouble); long referenceTime = EfdcUtils.getReferenceTime(startTime, timeZone); - return EfdcUtils.getRelativeTimeInTimeUnits(startTime, referenceTime, secondsPerTimeUnit); + return EfdcUtils.getRelativeTimeInTimeUnits(startTime, referenceTime, EfdcTimeSeriesDataObject.SECONDS_PER_TIME_UNIT); } } diff --git a/model_efdc/java/src/org/openda/model_efdc/EfdcTimeSeriesIoObject.java b/model_efdc/java/src/org/openda/model_efdc/EfdcTimeSeriesDataObject.java similarity index 66% rename from model_efdc/java/src/org/openda/model_efdc/EfdcTimeSeriesIoObject.java rename to model_efdc/java/src/org/openda/model_efdc/EfdcTimeSeriesDataObject.java index 3bdd25582..5a0cc9072 100644 --- a/model_efdc/java/src/org/openda/model_efdc/EfdcTimeSeriesIoObject.java +++ b/model_efdc/java/src/org/openda/model_efdc/EfdcTimeSeriesDataObject.java @@ -20,28 +20,18 @@ package org.openda.model_efdc; -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.TimeZone; - import org.openda.blackbox.config.BBUtils; -import org.openda.blackbox.interfaces.IoObjectInterface; +import org.openda.exchange.AbstractDataObject; import org.openda.exchange.DoubleExchangeItem; import org.openda.exchange.timeseries.TimeUtils; -import org.openda.interfaces.IPrevExchangeItem; -import org.openda.model_efdc.timeseriesformat.EfdcAserTimeSeriesFormatter; -import org.openda.model_efdc.timeseriesformat.EfdcCwqsrTimeSeriesFormatter; -import org.openda.model_efdc.timeseriesformat.EfdcPserTimeSeriesFormatter; -import org.openda.model_efdc.timeseriesformat.EfdcQserTimeSeriesFormatter; -import org.openda.model_efdc.timeseriesformat.EfdcTimeSeriesFormatter; -import org.openda.model_efdc.timeseriesformat.EfdcTserTimeSeriesFormatter; +import org.openda.interfaces.IExchangeItem; +import org.openda.model_efdc.timeseriesformat.*; import org.openda.utils.Results; import org.openda.utils.Time; +import java.io.File; +import java.util.*; + /** * IoObject for a .INP (EFDC input) file that contains one or more time series. * This can be used for the files QSER.INP, TSER.INP, PSER.INP, ASER.INP @@ -49,7 +39,7 @@ * * @author Arno Kockx */ -public class EfdcTimeSeriesIoObject implements IoObjectInterface { +public class EfdcTimeSeriesDataObject extends AbstractDataObject { /** * The times in the .INP input files are in this time unit. @@ -71,59 +61,60 @@ public class EfdcTimeSeriesIoObject implements IoObjectInterface { private File timeSeriesFile; private EfdcTimeSeriesFormatter timeSeriesFormatter; - private IPrevExchangeItem startTimeExchangeItem = null; - private Map timeSeriesExchangeItems = new LinkedHashMap(); + private String startTimeID; - /** + /** * @param workingDir the working directory. - * @param fileName the name of the file containing the data for this IoObject (relative to the working directory). - * @param arguments the first argument should be the type of file, e.g. QSER, TSER or ASER, - * the second argument should be the timeZone that is used by the model (in hours with respect to GMT, between -12 and 12), - * the third argument should be the id of the startTime exchangeItem, - * the fourth and further arguments should be the ids of the time series + * @param arguments the first argument should be the name of the file containing the data for this IoObject (relative to the working directory), + * the second argument should be the type of file, e.g. QSER, TSER or ASER, + * the third argument should be the timeZone that is used by the model (in hours with respect to GMT, between -12 and 12), + * the fourth argument should be the id of the startTime exchangeItem, + * the fifth and further arguments should be the ids of the time series * for which exchange items should be made. */ - - public void initialize(File workingDir, String fileName, String[] arguments) { - this.timeSeriesFile = new File(workingDir, fileName); + + @Override + public void initialize(File workingDir, String[] arguments) { + this.timeSeriesFile = new File(workingDir, arguments[0]); //create time series formatter. - if (arguments == null || arguments.length < 1) { + if (arguments.length < 2) { throw new IllegalArgumentException("No arguments specified for " + this.getClass().getSimpleName() - + ". The first argument should be the type of file, e.g. QSER, TSER or ASER."); + + ". The second argument should be the type of file, e.g. QSER, TSER or ASER."); } - String fileType = arguments[0]; + String fileType = arguments[1]; createTimeSeriesFormatter(fileType); //get timeZone. - if (arguments.length < 2) { + if (arguments.length < 3) { throw new IllegalArgumentException("No timeZone argument specified for " + this.getClass().getSimpleName() - + ". The second argument should be the timeZone that is used by the model" + + ". The third argument should be the timeZone that is used by the model" + " (in hours with respect to GMT, between -12 and 12)."); } try { - double timeZoneOffsetInHours = Double.parseDouble(arguments[1]); + double timeZoneOffsetInHours = Double.parseDouble(arguments[2]); this.timeZone = TimeUtils.createTimeZoneFromDouble(timeZoneOffsetInHours); } catch (Exception e) { - throw new IllegalArgumentException("Cannot parse second argument '" + arguments[1] + throw new IllegalArgumentException("Cannot parse third argument '" + arguments[2] + "' for " + this.getClass().getSimpleName() - + ". The second argument should be the timeZone that is used by the model" + + ". The third argument should be the timeZone that is used by the model" + " (in hours with respect to GMT, between -12 and 12).", e); } //create start time exchange item. - if (arguments.length < 3) { + if (arguments.length < 4) { throw new IllegalArgumentException("No exchange item ids arguments specified for " + this.getClass().getSimpleName() - + ". The third argument should be the id of the startTime exchangeItem."); + + ". The fourth argument should be the id of the startTime exchangeItem."); } - this.startTimeExchangeItem = new DoubleExchangeItem(arguments[2], 0); + startTimeID = arguments[3]; + exchangeItems.put(startTimeID, new DoubleExchangeItem(startTimeID, 0)); //create exchange items. - if (arguments.length < 4) { + if (arguments.length < 5) { throw new IllegalArgumentException("No time series ids arguments specified for " + this.getClass().getSimpleName() - + ". The fourth and further arguments should be the ids of time series."); + + ". The fifth and further arguments should be the ids of time series."); } - String[] timeSeriesIdList = Arrays.copyOfRange(arguments, 3, arguments.length); + String[] timeSeriesIdList = Arrays.copyOfRange(arguments, 4, arguments.length); createTimeSeriesExchangeItems(timeSeriesIdList); //read file. @@ -159,11 +150,8 @@ private void createTimeSeriesFormatter(String fileType) { } private void createTimeSeriesExchangeItems(String[] timeSeriesIdList) { - //reset this.timeSeriesExchangeItems list. - this.timeSeriesExchangeItems.clear(); - //for all identifiers in the idList create a TimeSeriesExchangeItem. - List ids = new ArrayList(); + List ids = new ArrayList<>(); for (String timeSeriesId : timeSeriesIdList) { //create timeSeriesExchangeItem. EfdcTimeSeriesExchangeItem timeSeriesExchangeItem = new EfdcTimeSeriesExchangeItem(); @@ -180,32 +168,24 @@ private void createTimeSeriesExchangeItems(String[] timeSeriesIdList) { } //add timeSeriesExchangeItem. - this.timeSeriesExchangeItems.put(timeSeriesExchangeItem.getId(), timeSeriesExchangeItem); + exchangeItems.put(timeSeriesExchangeItem.getId(), timeSeriesExchangeItem); ids.add(id); } - if (this.timeSeriesExchangeItems.isEmpty()) { + if (exchangeItems.isEmpty()) { throw new IllegalArgumentException("No time series found for time series file '" + this.timeSeriesFile.getAbsolutePath() + "'."); } } - - public IPrevExchangeItem[] getExchangeItems() { - //return all available exchange items. - List exchangeItems = new ArrayList(this.timeSeriesExchangeItems.values()); - exchangeItems.add(this.startTimeExchangeItem); - return exchangeItems.toArray(new IPrevExchangeItem[exchangeItems.size()]); - } - - + @Override public void finish() { - if (this.startTimeExchangeItem == null) { + if (exchangeItems.isEmpty()) { throw new IllegalStateException("EfdcTimeSeriesIoObject not initialized yet."); } //get startTime. - double startTime = (Double) this.startTimeExchangeItem.getValues(); + double startTime = (Double) exchangeItems.get(startTimeID).getValues(); //determine referenceTime. long referenceTime = EfdcUtils.getReferenceTime(Time.mjdToMillies(startTime), this.timeZone); @@ -213,6 +193,8 @@ public void finish() { //write data to file for each time series exchange item. this.timeSeriesFormatter.setReferenceTime(referenceTime); this.timeSeriesFormatter.setTimeUnit(SECONDS_PER_TIME_UNIT); - this.timeSeriesFormatter.writeTimeSeriesToFile(this.timeSeriesFile, this.timeSeriesExchangeItems); + Map exchangeItemsWithoutStartTime = new LinkedHashMap<>(this.exchangeItems); + exchangeItemsWithoutStartTime.remove(startTimeID); + this.timeSeriesFormatter.writeTimeSeriesToFile(this.timeSeriesFile, exchangeItemsWithoutStartTime); } } diff --git a/model_efdc/java/src/org/openda/model_efdc/EfdcTimeSeriesExchangeItem.java b/model_efdc/java/src/org/openda/model_efdc/EfdcTimeSeriesExchangeItem.java index db88d0d15..b9eb668dd 100644 --- a/model_efdc/java/src/org/openda/model_efdc/EfdcTimeSeriesExchangeItem.java +++ b/model_efdc/java/src/org/openda/model_efdc/EfdcTimeSeriesExchangeItem.java @@ -21,7 +21,7 @@ package org.openda.model_efdc; import org.openda.exchange.timeseries.TimeSeries; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; /** * Exchange item for a time series stored in a .INP (EFDC input) file. @@ -36,6 +36,6 @@ public EfdcTimeSeriesExchangeItem() { public Role getRole() { - return IPrevExchangeItem.Role.Input; + return IExchangeItem.Role.Input; } } diff --git a/model_efdc/java/src/org/openda/model_efdc/timeseriesformat/EfdcAserTimeSeriesFormatter.java b/model_efdc/java/src/org/openda/model_efdc/timeseriesformat/EfdcAserTimeSeriesFormatter.java index e15ecf7b3..892dfc498 100644 --- a/model_efdc/java/src/org/openda/model_efdc/timeseriesformat/EfdcAserTimeSeriesFormatter.java +++ b/model_efdc/java/src/org/openda/model_efdc/timeseriesformat/EfdcAserTimeSeriesFormatter.java @@ -29,7 +29,7 @@ import java.util.List; import java.util.Map; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.model_efdc.EfdcTimeSeriesExchangeItem; import org.openda.model_efdc.EfdcUtils; import org.openda.utils.Results; @@ -175,10 +175,10 @@ private void readTimeSeriesHeaderParameters(List lines) { * Writes all given timeSeries to the given file. * * @param outputFile - * @param timeSeriesList + * @param timeSeriesMap */ - public void writeTimeSeriesToFile(File outputFile, Map timeSeriesMap) { + public void writeTimeSeriesToFile(File outputFile, Map timeSeriesMap) { if (timeSeriesMap == null || timeSeriesMap.isEmpty()) { throw new RuntimeException("No time series to write to file '" + outputFile.getAbsolutePath() + "'."); } @@ -222,7 +222,7 @@ public void writeTimeSeriesToFile(File outputFile, Map timeSeriesMap) { + protected void writeTimeSeriesForLocation(PrintWriter writer, int locationId, Map timeSeriesMap) { //get data. String[] parameterIds = {"PATM", "TDRY", "TWET", "RAIN", "EVAP", "SOLSWR", "CLOUD"}; diff --git a/model_efdc/java/src/org/openda/model_efdc/timeseriesformat/EfdcTimeSeriesFormatter.java b/model_efdc/java/src/org/openda/model_efdc/timeseriesformat/EfdcTimeSeriesFormatter.java index e4135ebed..d85c709b8 100644 --- a/model_efdc/java/src/org/openda/model_efdc/timeseriesformat/EfdcTimeSeriesFormatter.java +++ b/model_efdc/java/src/org/openda/model_efdc/timeseriesformat/EfdcTimeSeriesFormatter.java @@ -28,7 +28,7 @@ import java.util.List; import java.util.Map; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.model_efdc.EfdcTimeSeriesExchangeItem; import org.openda.model_efdc.EfdcUtils; import org.openda.utils.Results; @@ -110,7 +110,7 @@ protected void removeAndStoreFileHeader(List lines) { * @param outputFile * @param timeSeriesMap */ - public void writeTimeSeriesToFile(File outputFile, Map timeSeriesMap) { + public void writeTimeSeriesToFile(File outputFile, Map timeSeriesMap) { if (timeSeriesMap == null || timeSeriesMap.isEmpty()) { throw new RuntimeException("No time series to write to file '" + outputFile.getAbsolutePath() + "'."); } @@ -166,7 +166,7 @@ protected void writeFileHeader(PrintWriter writer) { * @param locationId * @param timeSeriesMap */ - protected void writeTimeSeriesForLocation(PrintWriter writer, int locationId, Map timeSeriesMap) { + protected void writeTimeSeriesForLocation(PrintWriter writer, int locationId, Map timeSeriesMap) { EfdcTimeSeriesExchangeItem timeSeries = (EfdcTimeSeriesExchangeItem) timeSeriesMap.get(locationId + "." + getFileType()); if (timeSeries == null) { diff --git a/model_efdc/java/test/org/openda/model_efdc/EfdcEventTox2InpFileTest.java b/model_efdc/java/test/org/openda/model_efdc/EfdcEventTox2InpFileTest.java index 225c1eb61..9d55fa179 100644 --- a/model_efdc/java/test/org/openda/model_efdc/EfdcEventTox2InpFileTest.java +++ b/model_efdc/java/test/org/openda/model_efdc/EfdcEventTox2InpFileTest.java @@ -21,13 +21,12 @@ package org.openda.model_efdc; import java.io.File; -import java.io.IOException; import java.util.Calendar; import java.util.TimeZone; import junit.framework.TestCase; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.OpenDaTestSupport; import org.openda.utils.Time; @@ -41,7 +40,7 @@ public class EfdcEventTox2InpFileTest extends TestCase { private OpenDaTestSupport testData; private File testRunDataDir; - protected void setUp() throws IOException { + protected void setUp() { testData = new OpenDaTestSupport(EfdcEventTox2InpFileTest.class, "model_efdc"); testRunDataDir = testData.getTestRunDataDir(); } @@ -50,36 +49,37 @@ public void testWriteEfdcEventTox2InpFile() { Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT")); - calendar.set(2009, 0, 1, 9, 0, 0); + calendar.set(2009, Calendar.JANUARY, 1, 9, 0, 0); calendar.set(Calendar.MILLISECOND, 0); double startDate = Time.milliesToMjd(calendar.getTimeInMillis()); - calendar.set(2009, 0, 3, 9, 0, 0); + calendar.set(2009, Calendar.JANUARY, 3, 9, 0, 0); calendar.set(Calendar.MILLISECOND, 0); double endDate = Time.milliesToMjd(calendar.getTimeInMillis()); - EfdcEventTox2InpIoObject efdcEventTox2InpIoObject = new EfdcEventTox2InpIoObject(); + EfdcEventTox2InpDataObject efdcEventTox2InpDataObject = new EfdcEventTox2InpDataObject(); //working directory (testRunDataDir) is openda_public/opendaTestRuns/model_efdc/org/openda/model_efdc String eventTox2InpFilename = "efdcEventTox2InpFileTest/input/EVENT_TOX2.INP"; String startTimeExchangeItemId = "TSTART1"; String endTimeExchangeItemId = "TSTOP1"; - efdcEventTox2InpIoObject.initialize(testRunDataDir, eventTox2InpFilename, - new String[]{"0", startTimeExchangeItemId, endTimeExchangeItemId}); + efdcEventTox2InpDataObject.initialize(testRunDataDir, + new String[]{eventTox2InpFilename, "0", startTimeExchangeItemId, endTimeExchangeItemId}); //Get all exchangeItems items - IPrevExchangeItem[] exchangeItems = efdcEventTox2InpIoObject.getExchangeItems(); - //Loop over all exchangeItems items and request the ID, name and value - for (IPrevExchangeItem exchangeItem : exchangeItems) { - String id = exchangeItem.getId(); - if (id.equals(startTimeExchangeItemId)) { + String[] exchangeItemIDs = efdcEventTox2InpDataObject.getExchangeItemIDs(); + for (String id : exchangeItemIDs) { + IExchangeItem exchangeItem = efdcEventTox2InpDataObject.getDataObjectExchangeItem(id); + String exId = exchangeItem.getId(); + assertEquals(id, exId); + if (exId.equals(startTimeExchangeItemId)) { exchangeItem.setValues(startDate); - } else if (id.equals(endTimeExchangeItemId)) { + } else if (exId.equals(endTimeExchangeItemId)) { exchangeItem.setValues(endDate); } } //This command actually replaces the tags in the file by the values //of the corresponding exchangeItems. - efdcEventTox2InpIoObject.finish(); + efdcEventTox2InpDataObject.finish(); //compare actual result file with expected result file. File actualOutputFile = new File(testRunDataDir, eventTox2InpFilename); diff --git a/model_efdc/java/test/org/openda/model_efdc/EfdcGridTimeSeriesTest.java b/model_efdc/java/test/org/openda/model_efdc/EfdcGridTimeSeriesTest.java index 96b40a95e..cffb85a9d 100644 --- a/model_efdc/java/test/org/openda/model_efdc/EfdcGridTimeSeriesTest.java +++ b/model_efdc/java/test/org/openda/model_efdc/EfdcGridTimeSeriesTest.java @@ -20,18 +20,16 @@ package org.openda.model_efdc; -import java.io.File; -import java.io.IOException; -import java.util.Calendar; -import java.util.TimeZone; - import junit.framework.TestCase; - import org.openda.exchange.timeseries.TimeUtils; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.OpenDaTestSupport; import org.openda.utils.Time; +import java.io.File; +import java.util.Calendar; +import java.util.TimeZone; + /** * Test class for testing EfdcGridTimeSeriesIoObject and EfdcGridTimeSeriesExchangeItem. * @@ -40,10 +38,9 @@ public class EfdcGridTimeSeriesTest extends TestCase { private File testRunDataDir; - private OpenDaTestSupport testData; - protected void setUp() throws IOException { - testData = new OpenDaTestSupport(EfdcGridTimeSeriesTest.class, "model_efdc"); + protected void setUp() { + OpenDaTestSupport testData = new OpenDaTestSupport(EfdcGridTimeSeriesTest.class, "model_efdc"); testRunDataDir = testData.getTestRunDataDir(); } @@ -55,14 +52,13 @@ protected void setUp() throws IOException { * using a tool called POST_PCfile_ASCII.exe. This tool was developed by * EnssoHitech for NIER (National Institute of Environmental Research) in Korea. * - * @throws Exception - */ - public void testReadGridTimeSeries() throws Exception { + */ + public void testReadGridTimeSeries() { //read period from MJD 55679.375 (2011-04-28 09:00) to MJD 55682.375 (2011-05-01 09:00). Calendar calendar = Calendar.getInstance(); //startTime is in GMT. calendar.setTimeZone(TimeZone.getTimeZone("GMT")); - calendar.set(2011, 04, 28, 0, 0, 0); + calendar.set(2011, Calendar.MAY, 28, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); long startTime = calendar.getTimeInMillis(); //expectedTimes4 are in GMT. @@ -73,18 +69,22 @@ public void testReadGridTimeSeries() throws Exception { File outputFile = new File(testRunDataDir, outputFileName); assertTrue(outputFile.exists()); - EfdcGridTimeSeriesIoObject efdcGridTimeSeriesIoObject = new EfdcGridTimeSeriesIoObject(); - String[] arguments = new String[]{"9", TimeUtils.mjdToString(Time.milliesToMjd(startTime))}; - efdcGridTimeSeriesIoObject.initialize(testRunDataDir, outputFileName, arguments); + EfdcGridTimeSeriesDataObject efdcGridTimeSeriesDataObject = new EfdcGridTimeSeriesDataObject(); + String[] arguments = new String[]{outputFileName, "9", TimeUtils.mjdToString(Time.milliesToMjd(startTime))}; + efdcGridTimeSeriesDataObject.initialize(testRunDataDir, arguments); //get all exchangeItems. - IPrevExchangeItem[] exchangeItems = efdcGridTimeSeriesIoObject.getExchangeItems(); - assertEquals(23, exchangeItems.length); + String[] exchangeItemIDs = efdcGridTimeSeriesDataObject.getExchangeItemIDs(); + assertEquals(23, exchangeItemIDs.length); + + //the id is the one-based columnNumber of the column in the file. + String id = exchangeItemIDs[3]; + IExchangeItem exchangeItem4 = efdcGridTimeSeriesDataObject.getDataObjectExchangeItem(id); + String exId4 = exchangeItem4.getId(); + assertEquals(id, exId4); - //check times and values. - IPrevExchangeItem exchangeItem4 = exchangeItems[3]; - //the id is the one-based columnNumber of the column in the file. - assertEquals("8", exchangeItem4.getId()); + //check times and values. + assertEquals("8", exId4); double[] times4 = exchangeItem4.getTimes(); assertNotNull(times4); diff --git a/model_efdc/java/test/org/openda/model_efdc/EfdcInpFileTest.java b/model_efdc/java/test/org/openda/model_efdc/EfdcInpFileTest.java index 5440e3091..3c406270d 100644 --- a/model_efdc/java/test/org/openda/model_efdc/EfdcInpFileTest.java +++ b/model_efdc/java/test/org/openda/model_efdc/EfdcInpFileTest.java @@ -20,17 +20,15 @@ package org.openda.model_efdc; -import java.io.File; -import java.io.IOException; -import java.util.Calendar; -import java.util.TimeZone; - import junit.framework.TestCase; - -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.OpenDaTestSupport; import org.openda.utils.Time; +import java.io.File; +import java.util.Calendar; +import java.util.TimeZone; + /** * Test class for testing EfdcInpIoObject. * @@ -41,7 +39,7 @@ public class EfdcInpFileTest extends TestCase { private OpenDaTestSupport testData; private File testRunDataDir; - protected void setUp() throws IOException { + protected void setUp() { testData = new OpenDaTestSupport(EfdcInpFileTest.class, "model_efdc"); testRunDataDir = testData.getTestRunDataDir(); } @@ -50,36 +48,38 @@ public void testWriteEfdcInpFile() { Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT")); - calendar.set(2009, 0, 1, 9, 0, 0); + calendar.set(2009, Calendar.JANUARY, 1, 9, 0, 0); calendar.set(Calendar.MILLISECOND, 0); double startDate = Time.milliesToMjd(calendar.getTimeInMillis()); - calendar.set(2009, 0, 3, 9, 0, 0); + calendar.set(2009, Calendar.JANUARY, 3, 9, 0, 0); calendar.set(Calendar.MILLISECOND, 0); double endDate = Time.milliesToMjd(calendar.getTimeInMillis()); - EfdcInpIoObject efdcInpIoObject = new EfdcInpIoObject(); + EfdcInpDataObject efdcInpDataObject = new EfdcInpDataObject(); //working directory (testRunDataDir) is openda_public/opendaTestRuns/model_efdc/org/openda/model_efdc String efdcInpFilename = "efdcInpFileTest/input/EFDC.INP"; String startTimeExchangeItemId = "TSTART1"; String endTimeExchangeItemId = "TSTOP1"; - efdcInpIoObject.initialize(testRunDataDir, efdcInpFilename, - new String[]{"0", startTimeExchangeItemId, endTimeExchangeItemId}); + efdcInpDataObject.initialize(testRunDataDir, + new String[]{efdcInpFilename, "0", startTimeExchangeItemId, endTimeExchangeItemId}); //Get all exchangeItems items - IPrevExchangeItem[] exchangeItems = efdcInpIoObject.getExchangeItems(); + String[] exchangeItemIDs = efdcInpDataObject.getExchangeItemIDs(); //Loop over all exchangeItems items and request the ID, name and value - for (IPrevExchangeItem exchangeItem : exchangeItems) { - String id = exchangeItem.getId(); - if (id.equals(startTimeExchangeItemId)) { + for (String id : exchangeItemIDs) { + IExchangeItem exchangeItem = efdcInpDataObject.getDataObjectExchangeItem(id); + String exId = exchangeItem.getId(); + assertEquals(id, exId); + if (exId.equals(startTimeExchangeItemId)) { exchangeItem.setValues(startDate); - } else if (id.equals(endTimeExchangeItemId)) { + } else if (exId.equals(endTimeExchangeItemId)) { exchangeItem.setValues(endDate); } } //This command actually replaces the tags in the file by the values //of the corresponding exchangeItems. - efdcInpIoObject.finish(); + efdcInpDataObject.finish(); //compare actual result file with expected result file. File actualOutputFile = new File(testRunDataDir, efdcInpFilename); diff --git a/model_efdc/java/test/org/openda/model_efdc/EfdcRestartFileTest.java b/model_efdc/java/test/org/openda/model_efdc/EfdcRestartFileTest.java index 04a7c6547..d7529a59f 100644 --- a/model_efdc/java/test/org/openda/model_efdc/EfdcRestartFileTest.java +++ b/model_efdc/java/test/org/openda/model_efdc/EfdcRestartFileTest.java @@ -20,17 +20,15 @@ package org.openda.model_efdc; -import java.io.File; -import java.io.IOException; -import java.util.Calendar; -import java.util.TimeZone; - import junit.framework.TestCase; - -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.OpenDaTestSupport; import org.openda.utils.Time; +import java.io.File; +import java.util.Calendar; +import java.util.TimeZone; + /** * Test class for testing EfdcRestartFileIoObject. * @@ -41,7 +39,7 @@ public class EfdcRestartFileTest extends TestCase { private OpenDaTestSupport testData; private File testRunDataDir; - protected void setUp() throws IOException { + protected void setUp() { testData = new OpenDaTestSupport(EfdcInpFileTest.class, "model_efdc"); testRunDataDir = testData.getTestRunDataDir(); } @@ -50,29 +48,31 @@ public void testWriteEfdcRestartFile1() { Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT")); - calendar.set(2009, 0, 9, 0, 0, 0); + calendar.set(2009, Calendar.JANUARY, 9, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); double startDate = Time.milliesToMjd(calendar.getTimeInMillis()); - EfdcRestartFileIoObject efdcRestartFileIoObject = new EfdcRestartFileIoObject(); + EfdcRestartFileDataObject efdcRestartFileDataObject = new EfdcRestartFileDataObject(); //working directory (testRunDataDir) is openda_public/opendaTestRuns/model_efdc/org/openda/model_efdc String efdcRestartFilename = "efdcRestartFileTest/input/RESTART1.INP"; String startTimeExchangeItemId = "TSTART1"; - efdcRestartFileIoObject.initialize(testRunDataDir, efdcRestartFilename, - new String[]{"0", startTimeExchangeItemId}); + efdcRestartFileDataObject.initialize(testRunDataDir, + new String[]{efdcRestartFilename, "0", startTimeExchangeItemId}); //Get all exchangeItems items - IPrevExchangeItem[] exchangeItems = efdcRestartFileIoObject.getExchangeItems(); + String[] exchangeItemIDs = efdcRestartFileDataObject.getExchangeItemIDs(); //Loop over all exchangeItems items and request the ID, name and value - for (IPrevExchangeItem exchangeItem : exchangeItems) { - String id = exchangeItem.getId(); - if (id.equals(startTimeExchangeItemId)) { + for (String id : exchangeItemIDs) { + IExchangeItem exchangeItem = efdcRestartFileDataObject.getDataObjectExchangeItem(id); + String exId = exchangeItem.getId(); + assertEquals(id, exId); + if (exId.equals(startTimeExchangeItemId)) { exchangeItem.setValues(startDate); } } //This command actually replaces the startTime in the restart file. - efdcRestartFileIoObject.finish(); + efdcRestartFileDataObject.finish(); //compare actual result file with expected result file. File actualOutputFile = new File(testRunDataDir, efdcRestartFilename); @@ -85,29 +85,31 @@ public void testWriteEfdcRestartFile2() { Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT")); - calendar.set(2009, 4, 23, 9, 0, 0); + calendar.set(2009, Calendar.MAY, 23, 9, 0, 0); calendar.set(Calendar.MILLISECOND, 0); double startDate = Time.milliesToMjd(calendar.getTimeInMillis()); - EfdcRestartFileIoObject efdcRestartFileIoObject = new EfdcRestartFileIoObject(); + EfdcRestartFileDataObject efdcRestartFileDataObject = new EfdcRestartFileDataObject(); //working directory (testRunDataDir) is openda_public/opendaTestRuns/model_efdc/org/openda/model_efdc String efdcRestartFilename = "efdcRestartFileTest/input/RESTART2.INP"; String startTimeExchangeItemId = "TSTART1"; - efdcRestartFileIoObject.initialize(testRunDataDir, efdcRestartFilename, - new String[]{"0", startTimeExchangeItemId}); + efdcRestartFileDataObject.initialize(testRunDataDir, + new String[]{efdcRestartFilename, "0", startTimeExchangeItemId}); //Get all exchangeItems items - IPrevExchangeItem[] exchangeItems = efdcRestartFileIoObject.getExchangeItems(); + String[] exchangeItemIDs = efdcRestartFileDataObject.getExchangeItemIDs(); //Loop over all exchangeItems items and request the ID, name and value - for (IPrevExchangeItem exchangeItem : exchangeItems) { - String id = exchangeItem.getId(); - if (id.equals(startTimeExchangeItemId)) { + for (String id : exchangeItemIDs) { + IExchangeItem exchangeItem = efdcRestartFileDataObject.getDataObjectExchangeItem(id); + String exId = exchangeItem.getId(); + assertEquals(id, exId); + if (exId.equals(startTimeExchangeItemId)) { exchangeItem.setValues(startDate); } } //This command actually replaces the startTime in the restart file. - efdcRestartFileIoObject.finish(); + efdcRestartFileDataObject.finish(); //compare actual result file with expected result file. File actualOutputFile = new File(testRunDataDir, efdcRestartFilename); diff --git a/model_efdc/java/test/org/openda/model_efdc/EfdcTimeSeriesTest.java b/model_efdc/java/test/org/openda/model_efdc/EfdcTimeSeriesTest.java index 4a9f5f864..909796e6d 100644 --- a/model_efdc/java/test/org/openda/model_efdc/EfdcTimeSeriesTest.java +++ b/model_efdc/java/test/org/openda/model_efdc/EfdcTimeSeriesTest.java @@ -27,7 +27,7 @@ import junit.framework.TestCase; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.OpenDaTestSupport; import org.openda.utils.Time; @@ -51,9 +51,8 @@ protected void setUp() throws IOException { /** * Test writing time series to an existing ASER.INP file. * - * @throws Exception - */ - public void testWriteAserTimeSeries() throws Exception { + */ + public void testWriteAserTimeSeries() { //working directory (testRunDataDir) is openda_public/opendaTestRuns/model_efdc/org/openda/model_efdc String outputFileName = "efdcTimeSeriesTest/output/ASER.INP"; File outputFile = new File(testRunDataDir, outputFileName); @@ -61,33 +60,37 @@ public void testWriteAserTimeSeries() throws Exception { String[] locationIds = new String[]{"1", "2", "3"}; String[] parameterIds = new String[]{"PATM", "TDRY", "TWET", "RAIN", "EVAP", "SOLSWR", "CLOUD"}; - EfdcTimeSeriesIoObject efdcTimeSeriesIoObject = new EfdcTimeSeriesIoObject(); - String[] arguments = new String[locationIds.length*parameterIds.length + 3]; - arguments[0] = "ASER"; - arguments[1] = "0"; - arguments[2] = "TSTART1"; + EfdcTimeSeriesDataObject efdcTimeSeriesDataObject = new EfdcTimeSeriesDataObject(); + String[] arguments = new String[locationIds.length*parameterIds.length + 4]; + arguments[0] = outputFileName; + arguments[1] = "ASER"; + arguments[2] = "0"; + arguments[3] = "TSTART1"; for (int n = 0; n < locationIds.length; n++) { for (int k = 0; k < parameterIds.length; k++) { String timeSeriesId = locationIds[n] + "." + parameterIds[k]; - arguments[n*parameterIds.length + k + 3] = timeSeriesId; + arguments[n*parameterIds.length + k + 4] = timeSeriesId; } } - efdcTimeSeriesIoObject.initialize(testRunDataDir, outputFileName, arguments); + efdcTimeSeriesDataObject.initialize(testRunDataDir, arguments); //get all exchangeItems. - IPrevExchangeItem[] exchangeItems = efdcTimeSeriesIoObject.getExchangeItems(); - assertEquals(arguments.length - 2, exchangeItems.length); + String[] exchangeItemIDs = efdcTimeSeriesDataObject.getExchangeItemIDs(); + assertEquals(arguments.length - 3, exchangeItemIDs.length); //set start time. //write period from MJD 55562.0 (2011-01-01 00:00) to MJD 55564.0 (2011-01-03 00:00). Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT")); - calendar.set(2011, 0, 1, 0, 0, 0); + calendar.set(2011, Calendar.JANUARY, 1, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); double startTime = Time.milliesToMjd(calendar.getTimeInMillis()); - for (IPrevExchangeItem exchangeItem : exchangeItems) { - if ("TSTART1".equalsIgnoreCase(exchangeItem.getId())) { - exchangeItem.setValues(startTime); + for (String id: exchangeItemIDs) { + IExchangeItem exchangeItem = efdcTimeSeriesDataObject.getDataObjectExchangeItem(id); + String exId = exchangeItem.getId(); + assertEquals(id, exId); + if ("TSTART1".equalsIgnoreCase(exId)) { + exchangeItem.setValues(startTime); } } @@ -95,35 +98,37 @@ public void testWriteAserTimeSeries() throws Exception { //write period from MJD 55562.0 (2011-01-01 00:00) to MJD 55564.0 (2011-01-03 00:00). double[] times = new double[]{55562.0, 55563.0, 55564.0}; double currentValue = 1; - for (int n = 0; n < locationIds.length; n++) { - for (int k = 0; k < parameterIds.length; k++) { - String timeSeriesId = locationIds[n] + "." + parameterIds[k]; - - //get exchangeItem. - IPrevExchangeItem currentExchangeItem = null; - for (IPrevExchangeItem exchangeItem : exchangeItems) { - if (timeSeriesId.equalsIgnoreCase(exchangeItem.getId())) { - currentExchangeItem = exchangeItem; - break; - } - } - if (currentExchangeItem == null) { - fail("ExchangeItem for time series id '" + timeSeriesId + "' not found."); - return; - } - - double[] values = new double[times.length]; - for (int i = 0; i < values.length; i++) { - values[i] = currentValue; - currentValue++; - } - currentExchangeItem.setTimes(times); - currentExchangeItem.setValuesAsDoubles(values); - } - } + for (String locationId : locationIds) { + for (String parameterId : parameterIds) { + String timeSeriesId = locationId + "." + parameterId; + + //get exchangeItem. + IExchangeItem currentExchangeItem = null; + for (String id : exchangeItemIDs) { + currentExchangeItem = efdcTimeSeriesDataObject.getDataObjectExchangeItem(id); + String exId = currentExchangeItem.getId(); + assertEquals(id, exId); + if (timeSeriesId.equalsIgnoreCase(exId)) { + break; + } + } + if (currentExchangeItem == null) { + fail("ExchangeItem for time series id '" + timeSeriesId + "' not found."); + return; + } + + double[] values = new double[times.length]; + for (int i = 0; i < values.length; i++) { + values[i] = currentValue; + currentValue++; + } + currentExchangeItem.setTimes(times); + currentExchangeItem.setValuesAsDoubles(values); + } + } //write data to file. - efdcTimeSeriesIoObject.finish(); + efdcTimeSeriesDataObject.finish(); //compare actual result file with expected result file. //working directory (testRunDataDir) is openda_public/opendaTestRuns/model_efdc/org/openda/model_efdc @@ -134,28 +139,27 @@ public void testWriteAserTimeSeries() throws Exception { /** * Test writing time series to an existing CWQSR**.INP file. * - * @throws Exception - */ - public void testWriteCwqsrTimeSeries() throws Exception { + */ + public void testWriteCwqsrTimeSeries() { //working directory (testRunDataDir) is openda_public/opendaTestRuns/model_efdc/org/openda/model_efdc String outputFileName = "efdcTimeSeriesTest/output/CWQSR02.INP"; File outputFile = new File(testRunDataDir, outputFileName); assertTrue(outputFile.exists()); - EfdcTimeSeriesIoObject efdcTimeSeriesIoObject = new EfdcTimeSeriesIoObject(); + EfdcTimeSeriesDataObject efdcTimeSeriesDataObject = new EfdcTimeSeriesDataObject(); //here 1 is the location (can be multiple locations with series per file) //and CWQSR02 is the parameter. - String[] arguments = new String[]{"CWQSR02", "0", "TSTART1", "1.CWQSR02", "2.CWQSR02"}; - efdcTimeSeriesIoObject.initialize(testRunDataDir, outputFileName, arguments); + String[] arguments = new String[]{outputFileName, "CWQSR02", "0", "TSTART1", "1.CWQSR02", "2.CWQSR02"}; + efdcTimeSeriesDataObject.initialize(testRunDataDir, arguments); //get all exchangeItems. - IPrevExchangeItem[] exchangeItems = efdcTimeSeriesIoObject.getExchangeItems(); - assertEquals(arguments.length - 2, exchangeItems.length); + String[] exchangeItemIDs = efdcTimeSeriesDataObject.getExchangeItemIDs(); + assertEquals(arguments.length - 3, exchangeItemIDs.length); //set times and values. Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT")); - calendar.set(2011, 0, 1, 0, 0, 0); + calendar.set(2011, Calendar.JANUARY, 1, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); double startTime = Time.milliesToMjd(calendar.getTimeInMillis()); //write period from MJD 55561.0 (2010-31-12 00:00) to MJD 55927.5 (2012-01-01 12:00). @@ -164,17 +168,20 @@ public void testWriteCwqsrTimeSeries() throws Exception { for (int n = 0; n < times.length; n++) { times[n] = times[n] + 55561; } - for (IPrevExchangeItem exchangeItem : exchangeItems) { - if ("TSTART1".equalsIgnoreCase(exchangeItem.getId())) { - exchangeItem.setValues(startTime); - - } else if ("1.CWQSR02".equalsIgnoreCase(exchangeItem.getId())) { + for (String id : exchangeItemIDs) { + IExchangeItem exchangeItem = efdcTimeSeriesDataObject.getDataObjectExchangeItem(id); + String exId = exchangeItem.getId(); + assertEquals(id, exId); + if ("TSTART1".equalsIgnoreCase(exId)) { + exchangeItem.setValues(startTime); + + } else if ("1.CWQSR02".equalsIgnoreCase(exId)) { double[] values = new double[]{6.7181, 6.7181, 7.1966, 5.7133, 4.5170, 1.3589, 0.4306, 1.1867, 1.2728, 1.7896, 2.1628, 1.7800, 0.1436, 0.1436}; exchangeItem.setTimes(times); exchangeItem.setValuesAsDoubles(values); - } else if ("2.CWQSR02".equalsIgnoreCase(exchangeItem.getId())) { + } else if ("2.CWQSR02".equalsIgnoreCase(exId)) { double[] values = new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; exchangeItem.setTimes(times); exchangeItem.setValuesAsDoubles(values); @@ -182,7 +189,7 @@ public void testWriteCwqsrTimeSeries() throws Exception { } //write data to file. - efdcTimeSeriesIoObject.finish(); + efdcTimeSeriesDataObject.finish(); //compare actual result file with expected result file. //working directory (testRunDataDir) is openda_public/opendaTestRuns/model_efdc/org/openda/model_efdc @@ -193,28 +200,27 @@ public void testWriteCwqsrTimeSeries() throws Exception { /** * Test writing time series to an existing PSER.INP file. * - * @throws Exception - */ - public void testWritePserTimeSeriesWithTimeZone() throws Exception { + */ + public void testWritePserTimeSeriesWithTimeZone() { //working directory (testRunDataDir) is openda_public/opendaTestRuns/model_efdc/org/openda/model_efdc String outputFileName = "efdcTimeSeriesTest/output/PSER.INP"; File outputFile = new File(testRunDataDir, outputFileName); assertTrue(outputFile.exists()); - EfdcTimeSeriesIoObject efdcTimeSeriesIoObject = new EfdcTimeSeriesIoObject(); - String[] arguments = new String[]{"PSER", "9", "TSTART1", "1.PSER"}; - efdcTimeSeriesIoObject.initialize(testRunDataDir, outputFileName, arguments); + EfdcTimeSeriesDataObject efdcTimeSeriesDataObject = new EfdcTimeSeriesDataObject(); + String[] arguments = new String[]{outputFileName, "PSER", "9", "TSTART1", "1.PSER"}; + efdcTimeSeriesDataObject.initialize(testRunDataDir, arguments); //get all exchangeItems. - IPrevExchangeItem[] exchangeItems = efdcTimeSeriesIoObject.getExchangeItems(); - assertEquals(arguments.length - 2, exchangeItems.length); + String[] exchangeItemIDs = efdcTimeSeriesDataObject.getExchangeItemIDs(); + assertEquals(arguments.length - 3, exchangeItemIDs.length); //set times and values. //write period from MJD 55563.625 GMT (2011-01-02 15:00 GMT) to MJD 55568.625 GMT (2011-01-07 15:00 GMT). Calendar calendar = Calendar.getInstance(); //startTimeDouble in exchangeItems is in GMT. calendar.setTimeZone(TimeZone.getTimeZone("GMT")); - calendar.set(2011, 0, 2, 15, 0, 0); + calendar.set(2011, Calendar.JANUARY, 2, 15, 0, 0); calendar.set(Calendar.MILLISECOND, 0); double startTime = Time.milliesToMjd(calendar.getTimeInMillis()); //1.PSER @@ -224,17 +230,19 @@ public void testWritePserTimeSeriesWithTimeZone() throws Exception { times[n] = times[n] + 55561.625; } double[] values = new double[]{4.7, 4.8, 4.9, 2.06}; - for (IPrevExchangeItem exchangeItem : exchangeItems) { - if ("TSTART1".equalsIgnoreCase(exchangeItem.getId())) { + for (String id : exchangeItemIDs) { + IExchangeItem exchangeItem = efdcTimeSeriesDataObject.getDataObjectExchangeItem(id); + String exId = exchangeItem.getId(); + if ("TSTART1".equalsIgnoreCase(exId)) { exchangeItem.setValues(startTime); - } else if ("1.PSER".equalsIgnoreCase(exchangeItem.getId())) { + } else if ("1.PSER".equalsIgnoreCase(exId)) { exchangeItem.setTimes(times); exchangeItem.setValuesAsDoubles(values); } } //write data to file. - efdcTimeSeriesIoObject.finish(); + efdcTimeSeriesDataObject.finish(); //compare actual result file with expected result file. //working directory (testRunDataDir) is openda_public/opendaTestRuns/model_efdc/org/openda/model_efdc @@ -245,52 +253,54 @@ public void testWritePserTimeSeriesWithTimeZone() throws Exception { /** * Test writing time series to an existing QSER.INP file. * - * @throws Exception - */ - public void testWriteQserTimeSeries() throws Exception { + */ + public void testWriteQserTimeSeries() { //working directory (testRunDataDir) is openda_public/opendaTestRuns/model_efdc/org/openda/model_efdc String outputFileName = "efdcTimeSeriesTest/output/QSER.INP"; File outputFile = new File(testRunDataDir, outputFileName); assertTrue(outputFile.exists()); - EfdcTimeSeriesIoObject efdcTimeSeriesIoObject = new EfdcTimeSeriesIoObject(); - String[] arguments = new String[]{"QSER", "0", "TSTART23", "3.QSER", "1.QSER", "4.QSER", "2.QSER"}; - efdcTimeSeriesIoObject.initialize(testRunDataDir, outputFileName, arguments); + EfdcTimeSeriesDataObject efdcTimeSeriesDataObject = new EfdcTimeSeriesDataObject(); + String[] arguments = new String[]{outputFileName, "QSER", "0", "TSTART23", "3.QSER", "1.QSER", "4.QSER", "2.QSER"}; + efdcTimeSeriesDataObject.initialize(testRunDataDir, arguments); //get all exchangeItems. - IPrevExchangeItem[] exchangeItems = efdcTimeSeriesIoObject.getExchangeItems(); - assertEquals(arguments.length - 2, exchangeItems.length); + String[] exchangeItemIDs = efdcTimeSeriesDataObject.getExchangeItemIDs(); + assertEquals(arguments.length - 3, exchangeItemIDs.length); //set times and values. //write period from MJD 55562.0 (2011-01-01 00:00) to MJD 55564.0 (2011-01-03 00:00). Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT")); - calendar.set(2011, 0, 1, 0, 0, 0); + calendar.set(2011, Calendar.JANUARY, 1, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); double startTime = Time.milliesToMjd(calendar.getTimeInMillis()); - for (IPrevExchangeItem exchangeItem : exchangeItems) { - if ("TSTART23".equalsIgnoreCase(exchangeItem.getId())) { + for (String id : exchangeItemIDs) { + IExchangeItem exchangeItem = efdcTimeSeriesDataObject.getDataObjectExchangeItem(id); + String exId = exchangeItem.getId(); + assertEquals(id, exId); + if ("TSTART23".equalsIgnoreCase(exId)) { exchangeItem.setValues(startTime); - } else if ("1.QSER".equalsIgnoreCase(exchangeItem.getId())) { + } else if ("1.QSER".equalsIgnoreCase(exId)) { double[] times = new double[]{55562.0, 55562.5, 55563.0, 55563.5, 55564.0}; double[] values = new double[]{1, -2.2, 3.33, -4.444, 5.5555}; exchangeItem.setTimes(times); exchangeItem.setValuesAsDoubles(values); - } else if ("2.QSER".equalsIgnoreCase(exchangeItem.getId())) { + } else if ("2.QSER".equalsIgnoreCase(exId)) { double[] times = new double[]{55562.0, 55562.5, 55563.0, 55563.5, 55564.0}; double[] values = new double[]{8888.8888, 99999.9999, 1000000000, 10000000.00000001, 0.0000000001}; exchangeItem.setTimes(times); exchangeItem.setValuesAsDoubles(values); - } else if ("3.QSER".equalsIgnoreCase(exchangeItem.getId())) { + } else if ("3.QSER".equalsIgnoreCase(exId)) { double[] times = new double[]{55562.0, 55562.5, 55563.0, Double.NaN, 55564.0}; double[] values = new double[]{1, Double.NaN, Double.NaN, 4, 5}; exchangeItem.setTimes(times); exchangeItem.setValuesAsDoubles(values); - } else if ("4.QSER".equalsIgnoreCase(exchangeItem.getId())) { + } else if ("4.QSER".equalsIgnoreCase(exId)) { double[] times = new double[]{55562.0, 55563.0, 55564.0}; double[] values = new double[]{1.1574E-05, 0, 2.8E-06}; exchangeItem.setTimes(times); @@ -299,7 +309,7 @@ public void testWriteQserTimeSeries() throws Exception { } //write data to file. - efdcTimeSeriesIoObject.finish(); + efdcTimeSeriesDataObject.finish(); //compare actual result file with expected result file. //working directory (testRunDataDir) is openda_public/opendaTestRuns/model_efdc/org/openda/model_efdc @@ -310,52 +320,54 @@ public void testWriteQserTimeSeries() throws Exception { /** * Test writing time series to an existing TSER.INP file. * - * @throws Exception - */ - public void testWriteTserTimeSeries() throws Exception { + */ + public void testWriteTserTimeSeries() { //working directory (testRunDataDir) is openda_public/opendaTestRuns/model_efdc/org/openda/model_efdc String outputFileName = "efdcTimeSeriesTest/output/TSER.INP"; File outputFile = new File(testRunDataDir, outputFileName); assertTrue(outputFile.exists()); - EfdcTimeSeriesIoObject efdcTimeSeriesIoObject = new EfdcTimeSeriesIoObject(); - String[] arguments = new String[]{"TSER","0", "TSTART1", "4.TSER", "1.TSER", "2.TSER", "3.TSER"}; - efdcTimeSeriesIoObject.initialize(testRunDataDir, outputFileName, arguments); + EfdcTimeSeriesDataObject efdcTimeSeriesDataObject = new EfdcTimeSeriesDataObject(); + String[] arguments = new String[]{outputFileName, "TSER","0", "TSTART1", "4.TSER", "1.TSER", "2.TSER", "3.TSER"}; + efdcTimeSeriesDataObject.initialize(testRunDataDir, arguments); //get all exchangeItems. - IPrevExchangeItem[] exchangeItems = efdcTimeSeriesIoObject.getExchangeItems(); - assertEquals(arguments.length - 2, exchangeItems.length); + String[] exchangeItemIDs = efdcTimeSeriesDataObject.getExchangeItemIDs(); + assertEquals(arguments.length - 3, exchangeItemIDs.length); //set times and values. //write period from MJD 55562.0 (2011-01-01 00:00) to MJD 55564.0 (2011-01-03 00:00). Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT")); - calendar.set(2011, 0, 1, 0, 0, 0); + calendar.set(2011, Calendar.JANUARY, 1, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); double startTime = Time.milliesToMjd(calendar.getTimeInMillis()); - for (IPrevExchangeItem exchangeItem : exchangeItems) { - if ("TSTART1".equalsIgnoreCase(exchangeItem.getId())) { + for (String id : exchangeItemIDs) { + IExchangeItem exchangeItem = efdcTimeSeriesDataObject.getDataObjectExchangeItem(id); + String exId = exchangeItem.getId(); + assertEquals(id, exId); + if ("TSTART1".equalsIgnoreCase(exId)) { exchangeItem.setValues(startTime); - } else if ("1.TSER".equalsIgnoreCase(exchangeItem.getId())) { + } else if ("1.TSER".equalsIgnoreCase(exId)) { double[] times = new double[]{55562.0, 55562.5, 55563.0, 55563.5, 55564.0}; double[] values = new double[]{1, -2.2, 3.33, -4.444, 5.5555}; exchangeItem.setTimes(times); exchangeItem.setValuesAsDoubles(values); - } else if ("2.TSER".equalsIgnoreCase(exchangeItem.getId())) { + } else if ("2.TSER".equalsIgnoreCase(exId)) { double[] times = new double[]{55562.0, 55562.5, 55563.0, 55563.5, 55564.0}; double[] values = new double[]{8888.8888, 99999.9999, 1000000000, 10000000.00000001, 0.0000000001}; exchangeItem.setTimes(times); exchangeItem.setValuesAsDoubles(values); - } else if ("3.TSER".equalsIgnoreCase(exchangeItem.getId())) { + } else if ("3.TSER".equalsIgnoreCase(exId)) { double[] times = new double[]{55562.0, 55562.5, 55563.0, Double.NaN, 55564.0}; double[] values = new double[]{1, Double.NaN, Double.NaN, 4, 5}; exchangeItem.setTimes(times); exchangeItem.setValuesAsDoubles(values); - } else if ("4.TSER".equalsIgnoreCase(exchangeItem.getId())) { + } else if ("4.TSER".equalsIgnoreCase(exId)) { double[] times = new double[]{55562.0, 55563.0, 55564.0}; double[] values = new double[]{1.1574E-05, 0, 2.8E-06}; exchangeItem.setTimes(times); @@ -364,7 +376,7 @@ public void testWriteTserTimeSeries() throws Exception { } //write data to file. - efdcTimeSeriesIoObject.finish(); + efdcTimeSeriesDataObject.finish(); //compare actual result file with expected result file. //working directory (testRunDataDir) is openda_public/opendaTestRuns/model_efdc/org/openda/model_efdc diff --git a/model_efdc_dll/java/model_efdc_dll.iml b/model_efdc_dll/java/model_efdc_dll.iml index 543cd47b7..f537773eb 100644 --- a/model_efdc_dll/java/model_efdc_dll.iml +++ b/model_efdc_dll/java/model_efdc_dll.iml @@ -29,16 +29,8 @@ - - - - - - - - - + \ No newline at end of file diff --git a/model_efdc_dll/java/src/org/openda/model_efdc_dll/EfdcModelFactory.java b/model_efdc_dll/java/src/org/openda/model_efdc_dll/EfdcModelFactory.java index b5098d4fe..6eda1b340 100644 --- a/model_efdc_dll/java/src/org/openda/model_efdc_dll/EfdcModelFactory.java +++ b/model_efdc_dll/java/src/org/openda/model_efdc_dll/EfdcModelFactory.java @@ -26,11 +26,11 @@ import org.openda.blackbox.interfaces.IModelFactory; import org.openda.blackbox.interfaces.ITimeHorizonConsumer; import org.openda.interfaces.IModelInstance; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.interfaces.IStochModelFactory.OutputLevel; import org.openda.interfaces.ITime; -import org.openda.model_efdc.EfdcEventTox2InpIoObject; -import org.openda.model_efdc.EfdcInpIoObject; +import org.openda.model_efdc.EfdcEventTox2InpDataObject; +import org.openda.model_efdc.EfdcInpDataObject; import org.openda.utils.DistributedCounter; import org.openda.utils.Results; @@ -124,32 +124,34 @@ private static void writeRunPeriodInModelConfigFiles(File templateDir, //use EfdcInpIoObject to write timeHorizon in EFDC.INP file. BBUtils.makeFileClone(new File(templateDir, EFDC_INP_TEMPLATE_FILE_NAME), new File(templateDir, EFDC_INP_FILE_NAME)); - EfdcInpIoObject efdcInpIoObject = new EfdcInpIoObject(); - efdcInpIoObject.initialize(templateDir, EFDC_INP_FILE_NAME, - new String[]{String.valueOf(timeZoneOffsetInHours), TSTART, TSTOP}); - for (IPrevExchangeItem exchangeItem : efdcInpIoObject.getExchangeItems()) { - if (TSTART.equals(exchangeItem.getId())) { + EfdcInpDataObject efdcInpDataObject = new EfdcInpDataObject(); + efdcInpDataObject.initialize(templateDir, + new String[]{EFDC_INP_FILE_NAME, String.valueOf(timeZoneOffsetInHours), TSTART, TSTOP}); + for (String id : efdcInpDataObject.getExchangeItemIDs()) { + IExchangeItem exchangeItem = efdcInpDataObject.getDataObjectExchangeItem(id); + if (TSTART.equals(id)) { exchangeItem.setValuesAsDoubles(new double[]{startTime}); - } else if (TSTOP.equals(exchangeItem.getId())) { + } else if (TSTOP.equals(id)) { exchangeItem.setValuesAsDoubles(new double[]{endTime}); } } - efdcInpIoObject.finish(); + efdcInpDataObject.finish(); //use EfdcEventTox2InpIoObject to write timeHorizon in EVENT_TOX2.INP file. BBUtils.makeFileClone(new File(templateDir, EVENT_TOX2_INP_TEMPLATE_FILE_NAME), new File(templateDir, EVENT_TOX2_INP_FILE_NAME)); - EfdcEventTox2InpIoObject efdcEventTox2InpIoObject = new EfdcEventTox2InpIoObject(); - efdcEventTox2InpIoObject.initialize(templateDir, EVENT_TOX2_INP_FILE_NAME, - new String[]{String.valueOf(timeZoneOffsetInHours), TSTART, TSTOP}); - for (IPrevExchangeItem exchangeItem : efdcEventTox2InpIoObject.getExchangeItems()) { - if (TSTART.equals(exchangeItem.getId())) { + EfdcEventTox2InpDataObject efdcEventTox2InpDataObject = new EfdcEventTox2InpDataObject(); + efdcEventTox2InpDataObject.initialize(templateDir, + new String[]{EVENT_TOX2_INP_FILE_NAME, String.valueOf(timeZoneOffsetInHours), TSTART, TSTOP}); + for (String id : efdcEventTox2InpDataObject.getExchangeItemIDs()) { + IExchangeItem exchangeItem = efdcInpDataObject.getDataObjectExchangeItem(id); + if (TSTART.equals(id)) { exchangeItem.setValuesAsDoubles(new double[]{startTime}); - } else if (TSTOP.equals(exchangeItem.getId())) { + } else if (TSTOP.equals(id)) { exchangeItem.setValuesAsDoubles(new double[]{endTime}); } } - efdcEventTox2InpIoObject.finish(); + efdcEventTox2InpDataObject.finish(); } /** diff --git a/model_efdc_dll/java/src/org/openda/model_efdc_dll/EfdcModelInstance.java b/model_efdc_dll/java/src/org/openda/model_efdc_dll/EfdcModelInstance.java index bbd9ea68e..1666c166e 100644 --- a/model_efdc_dll/java/src/org/openda/model_efdc_dll/EfdcModelInstance.java +++ b/model_efdc_dll/java/src/org/openda/model_efdc_dll/EfdcModelInstance.java @@ -27,7 +27,7 @@ import org.openda.blackbox.config.BBUtils; import org.openda.exchange.dataobjects.NetcdfDataObject; import org.openda.interfaces.*; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; import org.openda.localization.LocalizationDomainsSimpleModel; import org.openda.model_efdc_dll.EfdcExchangeItemType.EfdcExchangeItemRole; import org.openda.utils.Instance; @@ -506,7 +506,7 @@ public String[] getExchangeItemIDs() { * @param role Input, Output, or InOut. * @return exchangeItemIds. */ - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { List ids = new ArrayList(); for (IExchangeItem exchangeItem : this.boundaryExchangeItems.values()) { if (exchangeItem.getRole() == role) { @@ -543,12 +543,12 @@ public IExchangeItem getDataObjectExchangeItem(String exchangeItemId) { * Returns the exchange item with the given exchangeItemId, if it exists. * * @param exchangeItemId Identifier of exchange item - * @return IPrevExchangeItem + * @return IExchangeItem */ //TODO this method is only present for backwards compatibility. This method should be removed //once all ioObjects and exchange items have been migrated to the new IDataObject/IExchangeItem approach. AK @Deprecated - public IPrevExchangeItem getExchangeItem(String exchangeItemId) { + public IExchangeItem getExchangeItem(String exchangeItemId) { //delegate to new getDataObjectExchangeItem method. return getDataObjectExchangeItem(exchangeItemId); } diff --git a/model_efdc_dll/java/test/org/openda/model_efdc_dll/testData/observation/stochObserverConfig.xml b/model_efdc_dll/java/test/org/openda/model_efdc_dll/testData/observation/stochObserverConfig.xml index c76bf68f0..52bdf9464 100644 --- a/model_efdc_dll/java/test/org/openda/model_efdc_dll/testData/observation/stochObserverConfig.xml +++ b/model_efdc_dll/java/test/org/openda/model_efdc_dll/testData/observation/stochObserverConfig.xml @@ -1,5 +1,5 @@ - @@ -9,11 +9,11 @@ - + AlgalGreenAlgae.nc true false - + - + diff --git a/model_efdc_dll/tests/han_dll_EnSIM_NN/stochObserver/stochObserverConfig.xml b/model_efdc_dll/tests/han_dll_EnSIM_NN/stochObserver/stochObserverConfig.xml index 60f91ba00..147c31b71 100644 --- a/model_efdc_dll/tests/han_dll_EnSIM_NN/stochObserver/stochObserverConfig.xml +++ b/model_efdc_dll/tests/han_dll_EnSIM_NN/stochObserver/stochObserverConfig.xml @@ -1,5 +1,5 @@ - @@ -9,11 +9,11 @@ - + WaterTemperature.nc true false - + - + diff --git a/model_example_blackbox/java/model_example_blackbox.iml b/model_example_blackbox/java/model_example_blackbox.iml index 525cdf3f6..a35a9d104 100644 --- a/model_example_blackbox/java/model_example_blackbox.iml +++ b/model_example_blackbox/java/model_example_blackbox.iml @@ -10,18 +10,10 @@ - - - - - - - - - + \ No newline at end of file diff --git a/model_example_blackbox/java/src/org/openda/blackbox/io/SimpleBbAsciiCopier.java b/model_example_blackbox/java/src/org/openda/blackbox/io/SimpleBbAsciiCopier.java index c6d329214..7d1a7e9db 100644 --- a/model_example_blackbox/java/src/org/openda/blackbox/io/SimpleBbAsciiCopier.java +++ b/model_example_blackbox/java/src/org/openda/blackbox/io/SimpleBbAsciiCopier.java @@ -20,8 +20,9 @@ * along with OpenDA. If not, see . */ package org.openda.blackbox.io; -import org.openda.blackbox.interfaces.IoObjectInterface; -import org.openda.interfaces.IPrevExchangeItem; + +import org.openda.exchange.AbstractDataObject; +import org.openda.interfaces.IExchangeItem; import java.io.File; @@ -39,9 +40,9 @@ public class SimpleBbAsciiCopier { * arg[0] is source file * arg[1] is destination * - * @param args + * @param args corresponding arguments */ - public static void main(String args[]){ + public static void main(String[] args){ if(args.length<2){ throw new RuntimeException("SimpleBbAsciiCopier.main requires 2 arguments"); } @@ -55,27 +56,27 @@ public static void main(String args[]){ } - IoObjectInterface output = new SimpleBbAsciiFile(); - String ioArgs[] = {}; - output.initialize(outputFile.getParentFile(), outputFile.getName(), ioArgs); - IPrevExchangeItem outputItem=null; - for(IPrevExchangeItem item:output.getExchangeItems()){ - String itemId = item.getId(); - System.out.println("looking at item: "+itemId); - if(itemId.equalsIgnoreCase("concentration.grid")){ - outputItem = item; + AbstractDataObject output = new SimpleBbAsciiFile(); + String[] ioArgs = {outputFile.getName()}; + output.initialize(outputFile.getParentFile(), ioArgs); + IExchangeItem outputItem=null; + for(String id:output.getExchangeItemIDs()){ + System.out.println("looking at item: "+id); + if(id.equalsIgnoreCase("concentration.grid")){ + outputItem = output.getDataObjectExchangeItem(id); break; } } - IoObjectInterface input = new SimpleBbAsciiFile(); - input.initialize(inputFile.getParentFile(), inputFile.getName(), ioArgs); - for(IPrevExchangeItem item:input.getExchangeItems()){ - String itemId = item.getId(); - System.out.println("looking at item: "+itemId); - if(itemId.equalsIgnoreCase("concentration.grid")){ - System.out.println("changing item: "+itemId); - double values[] = item.getValuesAsDoubles(); + AbstractDataObject input = new SimpleBbAsciiFile(); + ioArgs = new String[]{inputFile.getName()}; + input.initialize(inputFile.getParentFile(), ioArgs); + for(String id:input.getExchangeItemIDs()){ + System.out.println("looking at item: "+id); + if(id.equalsIgnoreCase("concentration.grid")){ + System.out.println("changing item: "+id); + IExchangeItem inputItem = input.getDataObjectExchangeItem(id); + double[] values = inputItem.getValuesAsDoubles(); outputItem.setValuesAsDoubles(values); break; } diff --git a/model_example_blackbox/java/src/org/openda/blackbox/io/SimpleBbAsciiFile.java b/model_example_blackbox/java/src/org/openda/blackbox/io/SimpleBbAsciiFile.java index 1662c4b80..97f878efa 100644 --- a/model_example_blackbox/java/src/org/openda/blackbox/io/SimpleBbAsciiFile.java +++ b/model_example_blackbox/java/src/org/openda/blackbox/io/SimpleBbAsciiFile.java @@ -18,22 +18,15 @@ * along with OpenDA. If not, see . */ package org.openda.blackbox.io; -import org.openda.blackbox.interfaces.IoObjectInterface; + +import org.openda.exchange.AbstractDataObject; import org.openda.exchange.DoubleExchangeItem; import org.openda.exchange.DoublesExchangeItem; -import org.openda.exchange.ExchangeItem; import org.openda.exchange.timeseries.TimeSeries; -import org.openda.interfaces.*; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.Results; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; +import java.io.*; import java.text.ParseException; import java.util.HashMap; import java.util.LinkedHashMap; @@ -80,12 +73,10 @@ */ -public class SimpleBbAsciiFile implements IoObjectInterface{ +public class SimpleBbAsciiFile extends AbstractDataObject { File workingDir; - String configString; String fileName = null; - HashMap variables = new LinkedHashMap(); - HashMap items = new LinkedHashMap(); + HashMap variables = new LinkedHashMap<>(); //cache these values double refdate; @@ -93,27 +84,28 @@ public class SimpleBbAsciiFile implements IoObjectInterface{ double dt=1.0; double tstop; double unit=1.0; - String sourceLabels[]; - String boundLabels[]; - String outputLabels[]; + String[] sourceLabels; + String[] boundLabels; + String[] outputLabels; - public void initialize(File workingDir, String fileName, String[] arguments) { + @Override + public void initialize(File workingDir, String[] arguments) { this.workingDir = workingDir; - this.fileName = fileName; - System.out.println("ioObject : filename = "+fileName); + this.fileName = arguments[0]; + System.out.println("dataobject : filename = "+arguments[0]); - if (arguments != null && arguments.length > 0) { - for(int i=0;i0){ + int newTimesLength = times.length - skipCount; + double[] newValues; + if (newTimesLength > 0) { newValues = new double[newTimesLength]; System.arraycopy(values, skipCount, newValues, 0, newTimesLength); - }else{ + } else { newValues = new double[1]; - int last=values.length-1; - newValues[0]=values[last]; + int last = values.length - 1; + newValues[0] = values[last]; } String valueString = writeVector(newValues); this.variables.put(key, valueString); @@ -366,25 +341,25 @@ public void finish() { // update boundaries String boundLabelsString = variables.get("bound_labels"); if(boundLabelsString!=null){ - for(int i=0;i0){ + int newTimesLength = times.length - skipCount; + double[] newValues; + if (newTimesLength > 0) { newValues = new double[newTimesLength]; System.arraycopy(values, skipCount, newValues, 0, newTimesLength); - }else{ + } else { newValues = new double[1]; - int last=values.length-1; - newValues[0]=values[last]; + int last = values.length - 1; + newValues[0] = values[last]; } String valueString = writeVector(newValues); this.variables.put(key, valueString); @@ -394,25 +369,25 @@ public void finish() { // update outputs String outputLabelsString = variables.get("output_labels"); if(outputLabelsString!=null){ - for(int i=0;i0){ + int newTimesLength = times.length - skipCount; + double[] newValues; + if (newTimesLength > 0) { newValues = new double[newTimesLength]; System.arraycopy(values, skipCount, newValues, 0, newTimesLength); - }else{ + } else { newValues = new double[1]; - int last=values.length-1; - newValues[0]=values[last]; + int last = values.length - 1; + newValues[0] = values[last]; } String valueString = writeVector(newValues); this.variables.put(key, valueString); @@ -422,12 +397,12 @@ public void finish() { // concentration if(this.variables.containsKey("c")){ String id = "concentration.grid"; - if(!this.items.containsKey(id)){ + if(!exchangeItems.containsKey(id)){ throw new RuntimeException("ExchangeItem with id ="+id+" got lost."); } - IPrevExchangeItem item = this.items.get(id); + IExchangeItem item = exchangeItems.get(id); String key="c"; - double values[] = item.getValuesAsDoubles(); + double[] values = item.getValuesAsDoubles(); String valueString = writeVector(values); this.variables.put(key, valueString); } @@ -463,10 +438,10 @@ public void finish() { /** * Parse a string with format like "[1.0, 2.2, 4.6 , 5.95]" - * @param String to parse + * @param valuestring to parse */ private double[] parseVector(String valuestring){ - double result[] = null; + double[] result; int ifirst = valuestring.indexOf("[") + 1; int ilast = valuestring.indexOf("]"); String buffer = valuestring.substring(ifirst, ilast); @@ -484,17 +459,17 @@ private double[] parseVector(String valuestring){ } private String writeVector(double[] values){ - String result = "["; + StringBuilder result = new StringBuilder("["); for(int i=0;i0) result+=","; - result += values[i]; + if(i>0) result.append(","); + result.append(values[i]); } - result+="]"; - return result; + result.append("]"); + return result.toString(); } private String[] parseStrings(String valuestring){ - String result[] = null; + String[] result; int ifirst = valuestring.indexOf("[") + 1; int ilast = valuestring.indexOf("]"); String buffer = valuestring.substring(ifirst, ilast); @@ -502,8 +477,8 @@ private String[] parseStrings(String valuestring){ int n = values.length; result = new String[n]; for (int i = 0; i < n; i++) { - int ifirstQuote = values[i].indexOf("\'") + 1; - int ilastQoute = values[i].lastIndexOf("\'"); + int ifirstQuote = values[i].indexOf("'") + 1; + int ilastQoute = values[i].lastIndexOf("'"); if ((ifirstQuote<0)|(ilastQoute<0)){ throw new RuntimeException("Expecting quotes around strings. Trouble reading "+values[i]); } @@ -516,10 +491,10 @@ private String[] parseStrings(String valuestring){ } private String parseString(String valuestring){ - String result = null; - int ifirstQuote = valuestring.indexOf("\'") + 1; - int ilastQoute = valuestring.lastIndexOf("\'"); - if ((ifirstQuote<0)|(ilastQoute<0)){ + String result; + int ifirstQuote = valuestring.indexOf("'") + 1; + int ilastQoute = valuestring.lastIndexOf("'"); + if (ilastQoute < 0){ throw new RuntimeException("Expecting quotes around strings. Trouble reading "+valuestring); } if (ifirstQuote==ilastQoute){ diff --git a/model_example_blackbox/java/test/org/openda/blackbox/io/SimpleBbAsciiFileTest.java b/model_example_blackbox/java/test/org/openda/blackbox/io/SimpleBbAsciiFileTest.java index 115d10b56..dca22ef0c 100644 --- a/model_example_blackbox/java/test/org/openda/blackbox/io/SimpleBbAsciiFileTest.java +++ b/model_example_blackbox/java/test/org/openda/blackbox/io/SimpleBbAsciiFileTest.java @@ -18,101 +18,98 @@ * along with OpenDA. If not, see . */ package org.openda.blackbox.io; + import junit.framework.TestCase; import org.openda.blackbox.config.BBUtils; -import org.openda.blackbox.interfaces.IoObjectInterface; import org.openda.exchange.DoublesExchangeItem; import org.openda.exchange.timeseries.NoosTimeSeriesFormatter; import org.openda.exchange.timeseries.TimeSeries; import org.openda.exchange.timeseries.TimeSeriesFormatter; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.OpenDaTestSupport; import java.io.File; import java.io.IOException; -import java.lang.reflect.Type; public class SimpleBbAsciiFileTest extends TestCase { private File testRunDataDir; private OpenDaTestSupport testData; - protected void setUp() throws IOException { + protected void setUp() { testData = new OpenDaTestSupport(SimpleBbAsciiFileTest.class,"model_example_blackbox"); testRunDataDir = testData.getTestRunDataDir(); } public void testReadInput() { - IoObjectInterface ioObject = new SimpleBbAsciiFile(); - String args[] = {}; - ioObject.initialize(testRunDataDir, "pollution_model.input", args); + SimpleBbAsciiFile dataObject = new SimpleBbAsciiFile(); + String[] args = {"pollution_model.input"}; + dataObject.initialize(testRunDataDir, args); - IPrevExchangeItem[] exchangeItems = ioObject.getExchangeItems(); + String[] exchangeItemIDs = dataObject.getExchangeItemIDs(); - for(int item=0;item - + %inputFile% input - + - + %outputFile% output - + diff --git a/model_example_blackbox/tests/blackbox_example_kalman/stochModel/polluteWrapper.xml b/model_example_blackbox/tests/blackbox_example_kalman/stochModel/polluteWrapper.xml index 368bbadf2..fa7c07e72 100644 --- a/model_example_blackbox/tests/blackbox_example_kalman/stochModel/polluteWrapper.xml +++ b/model_example_blackbox/tests/blackbox_example_kalman/stochModel/polluteWrapper.xml @@ -46,16 +46,16 @@ - + %inputFile% input - + - + %outputFile% output - + diff --git a/model_example_fortran/java/model_example_fortran.iml b/model_example_fortran/java/model_example_fortran.iml index 3b6b7b0c2..25d20d114 100644 --- a/model_example_fortran/java/model_example_fortran.iml +++ b/model_example_fortran/java/model_example_fortran.iml @@ -10,15 +10,6 @@ - - - - - - - - - @@ -28,5 +19,6 @@ + \ No newline at end of file diff --git a/model_example_fortran/java/src/org/openda/examples/simplef90model/SimpleExchangeItem.java b/model_example_fortran/java/src/org/openda/examples/simplef90model/SimpleExchangeItem.java index 8c4a3a30c..2fefe99bc 100644 --- a/model_example_fortran/java/src/org/openda/examples/simplef90model/SimpleExchangeItem.java +++ b/model_example_fortran/java/src/org/openda/examples/simplef90model/SimpleExchangeItem.java @@ -19,18 +19,21 @@ */ package org.openda.examples.simplef90model; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; +import org.openda.interfaces.IGeometryInfo; +import org.openda.interfaces.IQuantityInfo; +import org.openda.interfaces.ITimeInfo; /** * Exchange item for a DLL based model */ -public class SimpleExchangeItem implements IPrevExchangeItem{ +public class SimpleExchangeItem implements IExchangeItem{ private String id; private int indexInDLL; private Class valueType; private SimpleModelInstance SimpleModelInstance; - private IPrevExchangeItem.Role role; + private IExchangeItem.Role role; public SimpleExchangeItem(String id, int indexInDLL, Class valueType, SimpleModelInstance SimpleModelInstance) { @@ -42,9 +45,9 @@ public SimpleExchangeItem(String id, int indexInDLL, Class valueType, SimpleMode if (indexInDLL == SimpleModelDLL.gravity || indexInDLL == SimpleModelDLL.friction_on_grid || indexInDLL == SimpleModelDLL.discharge_on_laterals ) { - role = IPrevExchangeItem.Role.InOut; + role = IExchangeItem.Role.InOut; } else if (indexInDLL == SimpleModelDLL.waterlevel_on_grid) { - role = IPrevExchangeItem.Role.Output; + role = IExchangeItem.Role.Output; } else { throw new RuntimeException("Unknown role for exchange item: " + id); } @@ -58,13 +61,17 @@ public String getDescription() { return null; // no description } + public IQuantityInfo getQuantityInfo() { return null; } + + public IGeometryInfo getGeometryInfo() { return null; } + public Class getValueType() { return valueType; } - public Role getRole() { - return role; - } + public ValueType getValuesType() { return null; } + + public Role getRole() { return role; } public Object getValues() { if (valueType == double[].class) { @@ -96,7 +103,15 @@ public void multiplyValues(double[] multiplicationFactors) { setValuesAsDoubles(values); } - public void setValues(Object o) { + public void copyValuesFromItem(IExchangeItem sourceItem) { + ValueType sourceType = sourceItem.getValuesType(); + if (sourceType != ValueType.doublesType) { + throw new RuntimeException("ConstantLimitsRangeValidationExchangeItem.copyValuesFromItem(): unknown type: " + sourceType); + } + this.setValues(sourceItem.getValues()); + } + + public void setValues(Object o) { if (o instanceof double[]) { if (valueType != double[].class) { throw new RuntimeException("Incompatible object type in setValues: " + @@ -118,6 +133,8 @@ public void setValues(Object o) { public void setValuesAsDoubles(double[] doubles) { } + public ITimeInfo getTimeInfo() { return null; } + public double[] getTimes() { return SimpleModelInstance.getTimes(); } diff --git a/model_example_fortran/java/src/org/openda/examples/simplef90model/SimpleModelInstance.java b/model_example_fortran/java/src/org/openda/examples/simplef90model/SimpleModelInstance.java index c47afa0fc..3b75d3127 100644 --- a/model_example_fortran/java/src/org/openda/examples/simplef90model/SimpleModelInstance.java +++ b/model_example_fortran/java/src/org/openda/examples/simplef90model/SimpleModelInstance.java @@ -113,8 +113,8 @@ public String[] getExchangeItemIDs() { return exchangeItemIDs; } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { - if (role == IPrevExchangeItem.Role.InOut) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { + if (role == IExchangeItem.Role.InOut) { return getExchangeItemIDs(); } throw new UnsupportedOperationException("getExchangeItemIDs(role = in or out): Selection not yet implemented yet."); @@ -124,8 +124,8 @@ public IExchangeItem getDataObjectExchangeItem(String exchangeItemID) { throw new UnsupportedOperationException("org.openda.examples.simplef90model.SimpleModelInstance.getDataObjectExchangeItem(): Not implemented yet."); } - public IPrevExchangeItem getExchangeItem(String exchangeItemId) { - IPrevExchangeItem exchangeItem = exchangeItems.get(exchangeItemId); + public IExchangeItem getExchangeItem(String exchangeItemId) { + IExchangeItem exchangeItem = exchangeItems.get(exchangeItemId); if (exchangeItem == null) { throw new RuntimeException("Invalid exchange item id: " + exchangeItemId); } diff --git a/model_example_fortran/java/src/org/openda/examples/simplef90model/SimpleModelInstanceTestExe.java b/model_example_fortran/java/src/org/openda/examples/simplef90model/SimpleModelInstanceTestExe.java index 2829c0533..1cda022c9 100644 --- a/model_example_fortran/java/src/org/openda/examples/simplef90model/SimpleModelInstanceTestExe.java +++ b/model_example_fortran/java/src/org/openda/examples/simplef90model/SimpleModelInstanceTestExe.java @@ -21,10 +21,6 @@ import java.io.File; -import org.openda.interfaces.IPrevExchangeItem; -import org.openda.interfaces.IInstance; -import org.openda.interfaces.IModelInstance; - /** * Executable version (i.e. version with static main method) of SimpleModelInstanceTest */ diff --git a/model_example_fortran/java/test/org/openda/examples/simplef90model/SimpleModelInstanceTest.java b/model_example_fortran/java/test/org/openda/examples/simplef90model/SimpleModelInstanceTest.java index 87b6b60b6..886a0eec1 100644 --- a/model_example_fortran/java/test/org/openda/examples/simplef90model/SimpleModelInstanceTest.java +++ b/model_example_fortran/java/test/org/openda/examples/simplef90model/SimpleModelInstanceTest.java @@ -22,7 +22,7 @@ import junit.framework.TestCase; import org.openda.blackbox.config.BBUtils; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.interfaces.IInstance; import org.openda.interfaces.IModelInstance; import org.openda.utils.OpenDaTestSupport; @@ -84,7 +84,7 @@ static void runSimpleModelInstancesTest(File simpleFortranDll, File modelParentD IModelInstance modelInstance = modelInstances[i]; // adjust gravity - IPrevExchangeItem exchangeItem = modelInstance.getExchangeItem("Gravity"); + IExchangeItem exchangeItem = modelInstance.getExchangeItem("Gravity"); assertEquals("gravity", 9.1d, exchangeItem.getValuesAsDoubles()[0], 1e-10); exchangeItem.setValues(9.1d + .01d * (i+1)); diff --git a/model_external_socket/bin_external/bin_external_to_bin.test b/model_external_socket/bin_external/bin_external_to_bin.test new file mode 100644 index 000000000..e69de29bb diff --git a/model_external_socket/build.xml b/model_external_socket/build.xml new file mode 100644 index 000000000..9ca19203a --- /dev/null +++ b/model_external_socket/build.xml @@ -0,0 +1,157 @@ + + + + + ant help --> print this help + ant build --> compile, make jar and copy resources + ant build-test --> compile test classes + ant clean --> remove output + ant javadoc --> build javadoc + + + + + + + + + module=${module} + srcdir=${srcdir} + jarname=${jarname} + builddir=${builddir} + bindir=${bindir} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Subversion Revision: ${svn.revision} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/model_external_socket/build_castor.xml b/model_external_socket/build_castor.xml new file mode 100644 index 000000000..fd2f50333 --- /dev/null +++ b/model_external_socket/build_castor.xml @@ -0,0 +1,138 @@ + + + + + Build castor jar in 2 steps: + - target castor-src + - target castor-jar + See "NOTE:" in build_castor.xml (this file) + ant help --> print this help + ant castor --> rebuild castor parsers from xml + + + + + + + + + + + + + + + + + + module=${module} + srcdir=${srcdir} + openda_castor_jar=${openda_castor_jar} + openda_castor_schemas=${openda_castor_schemas} + openda_castor_src=${openda_castor_src} + castor_temp_srcdir=${castor_temp_srcdir} + castor_temp_builddir=${castor_temp_builddir} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Generate Castor XML based on ${schema} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexType.class b/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexType.class new file mode 100644 index 000000000..438915fcf Binary files /dev/null and b/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexType.class differ diff --git a/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexTypeDescriptor$1.class b/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexTypeDescriptor$1.class new file mode 100644 index 000000000..d20bb47ec Binary files /dev/null and b/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexTypeDescriptor$1.class differ diff --git a/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexTypeDescriptor$2.class b/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexTypeDescriptor$2.class new file mode 100644 index 000000000..c02da7750 Binary files /dev/null and b/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexTypeDescriptor$2.class differ diff --git a/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexTypeDescriptor$3.class b/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexTypeDescriptor$3.class new file mode 100644 index 000000000..05f502219 Binary files /dev/null and b/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexTypeDescriptor$3.class differ diff --git a/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexTypeDescriptor$4.class b/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexTypeDescriptor$4.class new file mode 100644 index 000000000..ad977cf29 Binary files /dev/null and b/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexTypeDescriptor$4.class differ diff --git a/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexTypeDescriptor.class b/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexTypeDescriptor.class new file mode 100644 index 000000000..9863928df Binary files /dev/null and b/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexTypeDescriptor.class differ diff --git a/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalSocketModelFactoryConfigXML.class b/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalSocketModelFactoryConfigXML.class new file mode 100644 index 000000000..946c1a4cb Binary files /dev/null and b/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalSocketModelFactoryConfigXML.class differ diff --git a/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalSocketModelFactoryConfigXMLDescriptor$1.class b/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalSocketModelFactoryConfigXMLDescriptor$1.class new file mode 100644 index 000000000..86eac0873 Binary files /dev/null and b/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalSocketModelFactoryConfigXMLDescriptor$1.class differ diff --git a/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalSocketModelFactoryConfigXMLDescriptor$2.class b/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalSocketModelFactoryConfigXMLDescriptor$2.class new file mode 100644 index 000000000..b0a2e537a Binary files /dev/null and b/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalSocketModelFactoryConfigXMLDescriptor$2.class differ diff --git a/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalSocketModelFactoryConfigXMLDescriptor.class b/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalSocketModelFactoryConfigXMLDescriptor.class new file mode 100644 index 000000000..212a7fe46 Binary files /dev/null and b/model_external_socket/castor_temp_build/org/openda/model_external_socket/io/castorgenerated/ExternalSocketModelFactoryConfigXMLDescriptor.class differ diff --git a/model_external_socket/castor_temp_src/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexType.java b/model_external_socket/castor_temp_src/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexType.java new file mode 100644 index 000000000..387492314 --- /dev/null +++ b/model_external_socket/castor_temp_src/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexType.java @@ -0,0 +1,281 @@ +/* + * This class was automatically generated with + * Castor 0.9.4.3, using an XML + * Schema. + * $Id$ + */ + +package org.openda.model_external_socket.io.castorgenerated; + + //---------------------------------/ + //- Imported classes and packages -/ +//---------------------------------/ + +import java.io.IOException; +import java.io.Reader; +import java.io.Serializable; +import java.io.Writer; +import org.exolab.castor.xml.MarshalException; +import org.exolab.castor.xml.Marshaller; +import org.exolab.castor.xml.Unmarshaller; +import org.exolab.castor.xml.ValidationException; +import org.xml.sax.ContentHandler; + +/** + * Class ExternalModelParameterComplexType. + * + * @version $Revision$ $Date$ + */ +public class ExternalModelParameterComplexType implements java.io.Serializable { + + + //--------------------------/ + //- Class/Member Variables -/ + //--------------------------/ + + /** + * Field _startValue + */ + private double _startValue; + + /** + * keeps track of state for field: _startValue + */ + private boolean _has_startValue; + + /** + * Field _stdDev + */ + private double _stdDev; + + /** + * keeps track of state for field: _stdDev + */ + private boolean _has_stdDev; + + /** + * Field _lowerBound + */ + private double _lowerBound; + + /** + * keeps track of state for field: _lowerBound + */ + private boolean _has_lowerBound; + + /** + * Field _upperBound + */ + private double _upperBound; + + /** + * keeps track of state for field: _upperBound + */ + private boolean _has_upperBound; + + + //----------------/ + //- Constructors -/ + //----------------/ + + public ExternalModelParameterComplexType() { + super(); + } //-- org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType() + + + //-----------/ + //- Methods -/ + //-----------/ + + /** + * Method deleteLowerBound + */ + public void deleteLowerBound() + { + this._has_lowerBound= false; + } //-- void deleteLowerBound() + + /** + * Method deleteUpperBound + */ + public void deleteUpperBound() + { + this._has_upperBound= false; + } //-- void deleteUpperBound() + + /** + * Returns the value of field 'lowerBound'. + * + * @return the value of field 'lowerBound'. + */ + public double getLowerBound() + { + return this._lowerBound; + } //-- double getLowerBound() + + /** + * Returns the value of field 'startValue'. + * + * @return the value of field 'startValue'. + */ + public double getStartValue() + { + return this._startValue; + } //-- double getStartValue() + + /** + * Returns the value of field 'stdDev'. + * + * @return the value of field 'stdDev'. + */ + public double getStdDev() + { + return this._stdDev; + } //-- double getStdDev() + + /** + * Returns the value of field 'upperBound'. + * + * @return the value of field 'upperBound'. + */ + public double getUpperBound() + { + return this._upperBound; + } //-- double getUpperBound() + + /** + * Method hasLowerBound + */ + public boolean hasLowerBound() + { + return this._has_lowerBound; + } //-- boolean hasLowerBound() + + /** + * Method hasStartValue + */ + public boolean hasStartValue() + { + return this._has_startValue; + } //-- boolean hasStartValue() + + /** + * Method hasStdDev + */ + public boolean hasStdDev() + { + return this._has_stdDev; + } //-- boolean hasStdDev() + + /** + * Method hasUpperBound + */ + public boolean hasUpperBound() + { + return this._has_upperBound; + } //-- boolean hasUpperBound() + + /** + * Method isValid + */ + public boolean isValid() + { + try { + validate(); + } + catch (org.exolab.castor.xml.ValidationException vex) { + return false; + } + return true; + } //-- boolean isValid() + + /** + * Method marshal + * + * @param out + */ + public void marshal(java.io.Writer out) + throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException + { + + Marshaller.marshal(this, out); + } //-- void marshal(java.io.Writer) + + /** + * Method marshal + * + * @param handler + */ + public void marshal(org.xml.sax.ContentHandler handler) + throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException + { + + Marshaller.marshal(this, handler); + } //-- void marshal(org.xml.sax.ContentHandler) + + /** + * Sets the value of field 'lowerBound'. + * + * @param lowerBound the value of field 'lowerBound'. + */ + public void setLowerBound(double lowerBound) + { + this._lowerBound = lowerBound; + this._has_lowerBound = true; + } //-- void setLowerBound(double) + + /** + * Sets the value of field 'startValue'. + * + * @param startValue the value of field 'startValue'. + */ + public void setStartValue(double startValue) + { + this._startValue = startValue; + this._has_startValue = true; + } //-- void setStartValue(double) + + /** + * Sets the value of field 'stdDev'. + * + * @param stdDev the value of field 'stdDev'. + */ + public void setStdDev(double stdDev) + { + this._stdDev = stdDev; + this._has_stdDev = true; + } //-- void setStdDev(double) + + /** + * Sets the value of field 'upperBound'. + * + * @param upperBound the value of field 'upperBound'. + */ + public void setUpperBound(double upperBound) + { + this._upperBound = upperBound; + this._has_upperBound = true; + } //-- void setUpperBound(double) + + /** + * Method unmarshalExternalModelParameterComplexType + * + * @param reader + */ + public static org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType unmarshalExternalModelParameterComplexType(java.io.Reader reader) + throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException + { + return (org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType) Unmarshaller.unmarshal(org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType.class, reader); + } //-- org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType unmarshalExternalModelParameterComplexType(java.io.Reader) + + /** + * Method validate + */ + public void validate() + throws org.exolab.castor.xml.ValidationException + { + org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator(); + validator.validate(this); + } //-- void validate() + +} diff --git a/model_external_socket/castor_temp_src/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexTypeDescriptor.java b/model_external_socket/castor_temp_src/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexTypeDescriptor.java new file mode 100644 index 000000000..a72c0410f --- /dev/null +++ b/model_external_socket/castor_temp_src/org/openda/model_external_socket/io/castorgenerated/ExternalModelParameterComplexTypeDescriptor.java @@ -0,0 +1,302 @@ +/* + * This class was automatically generated with + * Castor 0.9.4.3, using an XML + * Schema. + * $Id$ + */ + +package org.openda.model_external_socket.io.castorgenerated; + + //---------------------------------/ + //- Imported classes and packages -/ +//---------------------------------/ + +import org.exolab.castor.mapping.AccessMode; +import org.exolab.castor.xml.TypeValidator; +import org.exolab.castor.xml.XMLFieldDescriptor; +import org.exolab.castor.xml.validators.*; + +/** + * Class ExternalModelParameterComplexTypeDescriptor. + * + * @version $Revision$ $Date$ + */ +public class ExternalModelParameterComplexTypeDescriptor extends org.exolab.castor.xml.util.XMLClassDescriptorImpl { + + + //--------------------------/ + //- Class/Member Variables -/ + //--------------------------/ + + /** + * Field nsPrefix + */ + private java.lang.String nsPrefix; + + /** + * Field nsURI + */ + private java.lang.String nsURI; + + /** + * Field xmlName + */ + private java.lang.String xmlName; + + /** + * Field identity + */ + private org.exolab.castor.xml.XMLFieldDescriptor identity; + + + //----------------/ + //- Constructors -/ + //----------------/ + + public ExternalModelParameterComplexTypeDescriptor() { + super(); + nsURI = "http://www.openda.org"; + xmlName = "ExternalModelParameterComplexType"; + org.exolab.castor.xml.util.XMLFieldDescriptorImpl desc = null; + org.exolab.castor.xml.XMLFieldHandler handler = null; + org.exolab.castor.xml.FieldValidator fieldValidator = null; + //-- initialize attribute descriptors + + //-- _startValue + desc = new org.exolab.castor.xml.util.XMLFieldDescriptorImpl(java.lang.Double.TYPE, "_startValue", "startValue", org.exolab.castor.xml.NodeType.Attribute); + handler = (new org.exolab.castor.xml.XMLFieldHandler() { + public java.lang.Object getValue( java.lang.Object object ) + throws IllegalStateException + { + ExternalModelParameterComplexType target = (ExternalModelParameterComplexType) object; + if(!target.hasStartValue()) + return null; + return new Double(target.getStartValue()); + } + public void setValue( java.lang.Object object, java.lang.Object value) + throws IllegalStateException, IllegalArgumentException + { + try { + ExternalModelParameterComplexType target = (ExternalModelParameterComplexType) object; + // ignore null values for non optional primitives + if (value == null) return; + + target.setStartValue( ((Double)value).doubleValue()); + } + catch (java.lang.Exception ex) { + throw new IllegalStateException(ex.toString()); + } + } + public java.lang.Object newInstance( java.lang.Object parent ) { + return null; + } + } ); + desc.setHandler(handler); + desc.setRequired(true); + addFieldDescriptor(desc); + + //-- validation code for: _startValue + fieldValidator = new org.exolab.castor.xml.FieldValidator(); + fieldValidator.setMinOccurs(1); + { //-- local scope + DoubleValidator typeValidator = new DoubleValidator(); + fieldValidator.setValidator(typeValidator); + } + desc.setValidator(fieldValidator); + //-- _stdDev + desc = new org.exolab.castor.xml.util.XMLFieldDescriptorImpl(java.lang.Double.TYPE, "_stdDev", "stdDev", org.exolab.castor.xml.NodeType.Attribute); + handler = (new org.exolab.castor.xml.XMLFieldHandler() { + public java.lang.Object getValue( java.lang.Object object ) + throws IllegalStateException + { + ExternalModelParameterComplexType target = (ExternalModelParameterComplexType) object; + if(!target.hasStdDev()) + return null; + return new Double(target.getStdDev()); + } + public void setValue( java.lang.Object object, java.lang.Object value) + throws IllegalStateException, IllegalArgumentException + { + try { + ExternalModelParameterComplexType target = (ExternalModelParameterComplexType) object; + // ignore null values for non optional primitives + if (value == null) return; + + target.setStdDev( ((Double)value).doubleValue()); + } + catch (java.lang.Exception ex) { + throw new IllegalStateException(ex.toString()); + } + } + public java.lang.Object newInstance( java.lang.Object parent ) { + return null; + } + } ); + desc.setHandler(handler); + desc.setRequired(true); + addFieldDescriptor(desc); + + //-- validation code for: _stdDev + fieldValidator = new org.exolab.castor.xml.FieldValidator(); + fieldValidator.setMinOccurs(1); + { //-- local scope + DoubleValidator typeValidator = new DoubleValidator(); + fieldValidator.setValidator(typeValidator); + } + desc.setValidator(fieldValidator); + //-- _lowerBound + desc = new org.exolab.castor.xml.util.XMLFieldDescriptorImpl(java.lang.Double.TYPE, "_lowerBound", "lowerBound", org.exolab.castor.xml.NodeType.Attribute); + handler = (new org.exolab.castor.xml.XMLFieldHandler() { + public java.lang.Object getValue( java.lang.Object object ) + throws IllegalStateException + { + ExternalModelParameterComplexType target = (ExternalModelParameterComplexType) object; + if(!target.hasLowerBound()) + return null; + return new Double(target.getLowerBound()); + } + public void setValue( java.lang.Object object, java.lang.Object value) + throws IllegalStateException, IllegalArgumentException + { + try { + ExternalModelParameterComplexType target = (ExternalModelParameterComplexType) object; + // if null, use delete method for optional primitives + if (value == null) { + target.deleteLowerBound(); + return; + } + target.setLowerBound( ((Double)value).doubleValue()); + } + catch (java.lang.Exception ex) { + throw new IllegalStateException(ex.toString()); + } + } + public java.lang.Object newInstance( java.lang.Object parent ) { + return null; + } + } ); + desc.setHandler(handler); + addFieldDescriptor(desc); + + //-- validation code for: _lowerBound + fieldValidator = new org.exolab.castor.xml.FieldValidator(); + { //-- local scope + DoubleValidator typeValidator = new DoubleValidator(); + fieldValidator.setValidator(typeValidator); + } + desc.setValidator(fieldValidator); + //-- _upperBound + desc = new org.exolab.castor.xml.util.XMLFieldDescriptorImpl(java.lang.Double.TYPE, "_upperBound", "upperBound", org.exolab.castor.xml.NodeType.Attribute); + handler = (new org.exolab.castor.xml.XMLFieldHandler() { + public java.lang.Object getValue( java.lang.Object object ) + throws IllegalStateException + { + ExternalModelParameterComplexType target = (ExternalModelParameterComplexType) object; + if(!target.hasUpperBound()) + return null; + return new Double(target.getUpperBound()); + } + public void setValue( java.lang.Object object, java.lang.Object value) + throws IllegalStateException, IllegalArgumentException + { + try { + ExternalModelParameterComplexType target = (ExternalModelParameterComplexType) object; + // if null, use delete method for optional primitives + if (value == null) { + target.deleteUpperBound(); + return; + } + target.setUpperBound( ((Double)value).doubleValue()); + } + catch (java.lang.Exception ex) { + throw new IllegalStateException(ex.toString()); + } + } + public java.lang.Object newInstance( java.lang.Object parent ) { + return null; + } + } ); + desc.setHandler(handler); + addFieldDescriptor(desc); + + //-- validation code for: _upperBound + fieldValidator = new org.exolab.castor.xml.FieldValidator(); + { //-- local scope + DoubleValidator typeValidator = new DoubleValidator(); + fieldValidator.setValidator(typeValidator); + } + desc.setValidator(fieldValidator); + //-- initialize element descriptors + + } //-- org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexTypeDescriptor() + + + //-----------/ + //- Methods -/ + //-----------/ + + /** + * Method getAccessMode + */ + public org.exolab.castor.mapping.AccessMode getAccessMode() + { + return null; + } //-- org.exolab.castor.mapping.AccessMode getAccessMode() + + /** + * Method getExtends + */ + public org.exolab.castor.mapping.ClassDescriptor getExtends() + { + return null; + } //-- org.exolab.castor.mapping.ClassDescriptor getExtends() + + /** + * Method getIdentity + */ + public org.exolab.castor.mapping.FieldDescriptor getIdentity() + { + return identity; + } //-- org.exolab.castor.mapping.FieldDescriptor getIdentity() + + /** + * Method getJavaClass + */ + public java.lang.Class getJavaClass() + { + return org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType.class; + } //-- java.lang.Class getJavaClass() + + /** + * Method getNameSpacePrefix + */ + public java.lang.String getNameSpacePrefix() + { + return nsPrefix; + } //-- java.lang.String getNameSpacePrefix() + + /** + * Method getNameSpaceURI + */ + public java.lang.String getNameSpaceURI() + { + return nsURI; + } //-- java.lang.String getNameSpaceURI() + + /** + * Method getValidator + */ + public org.exolab.castor.xml.TypeValidator getValidator() + { + return this; + } //-- org.exolab.castor.xml.TypeValidator getValidator() + + /** + * Method getXMLName + */ + public java.lang.String getXMLName() + { + return xmlName; + } //-- java.lang.String getXMLName() + +} diff --git a/model_external_socket/castor_temp_src/org/openda/model_external_socket/io/castorgenerated/ExternalSocketModelFactoryConfigXML.java b/model_external_socket/castor_temp_src/org/openda/model_external_socket/io/castorgenerated/ExternalSocketModelFactoryConfigXML.java new file mode 100644 index 000000000..2ea19122f --- /dev/null +++ b/model_external_socket/castor_temp_src/org/openda/model_external_socket/io/castorgenerated/ExternalSocketModelFactoryConfigXML.java @@ -0,0 +1,273 @@ +/* + * This class was automatically generated with + * Castor 0.9.4.3, using an XML + * Schema. + * $Id$ + */ + +package org.openda.model_external_socket.io.castorgenerated; + + //---------------------------------/ + //- Imported classes and packages -/ +//---------------------------------/ + +import java.io.IOException; +import java.io.Reader; +import java.io.Serializable; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Enumeration; +import org.exolab.castor.xml.MarshalException; +import org.exolab.castor.xml.Marshaller; +import org.exolab.castor.xml.Unmarshaller; +import org.exolab.castor.xml.ValidationException; +import org.xml.sax.ContentHandler; + +/** + * Class ExternalSocketModelFactoryConfigXML. + * + * @version $Revision$ $Date$ + */ +public class ExternalSocketModelFactoryConfigXML implements java.io.Serializable { + + + //--------------------------/ + //- Class/Member Variables -/ + //--------------------------/ + + /** + * Field _portNumber + */ + private int _portNumber; + + /** + * keeps track of state for field: _portNumber + */ + private boolean _has_portNumber; + + /** + * Field _parameterList + */ + private java.util.ArrayList _parameterList; + + + //----------------/ + //- Constructors -/ + //----------------/ + + public ExternalSocketModelFactoryConfigXML() { + super(); + _parameterList = new ArrayList(); + } //-- org.openda.model_external_socket.io.castorgenerated.ExternalSocketModelFactoryConfigXML() + + + //-----------/ + //- Methods -/ + //-----------/ + + /** + * Method addParameter + * + * @param vParameter + */ + public void addParameter(org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType vParameter) + throws java.lang.IndexOutOfBoundsException + { + _parameterList.add(vParameter); + } //-- void addParameter(org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType) + + /** + * Method addParameter + * + * @param index + * @param vParameter + */ + public void addParameter(int index, org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType vParameter) + throws java.lang.IndexOutOfBoundsException + { + _parameterList.add(index, vParameter); + } //-- void addParameter(int, org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType) + + /** + * Method clearParameter + */ + public void clearParameter() + { + _parameterList.clear(); + } //-- void clearParameter() + + /** + * Method enumerateParameter + */ + public java.util.Enumeration enumerateParameter() + { + return new org.exolab.castor.util.IteratorEnumeration(_parameterList.iterator()); + } //-- java.util.Enumeration enumerateParameter() + + /** + * Method getParameter + * + * @param index + */ + public org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType getParameter(int index) + throws java.lang.IndexOutOfBoundsException + { + //-- check bounds for index + if ((index < 0) || (index > _parameterList.size())) { + throw new IndexOutOfBoundsException(); + } + + return (org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType) _parameterList.get(index); + } //-- org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType getParameter(int) + + /** + * Method getParameter + */ + public org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType[] getParameter() + { + int size = _parameterList.size(); + org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType[] mArray = new org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType[size]; + for (int index = 0; index < size; index++) { + mArray[index] = (org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType) _parameterList.get(index); + } + return mArray; + } //-- org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType[] getParameter() + + /** + * Method getParameterCount + */ + public int getParameterCount() + { + return _parameterList.size(); + } //-- int getParameterCount() + + /** + * Returns the value of field 'portNumber'. + * + * @return the value of field 'portNumber'. + */ + public int getPortNumber() + { + return this._portNumber; + } //-- int getPortNumber() + + /** + * Method hasPortNumber + */ + public boolean hasPortNumber() + { + return this._has_portNumber; + } //-- boolean hasPortNumber() + + /** + * Method isValid + */ + public boolean isValid() + { + try { + validate(); + } + catch (org.exolab.castor.xml.ValidationException vex) { + return false; + } + return true; + } //-- boolean isValid() + + /** + * Method marshal + * + * @param out + */ + public void marshal(java.io.Writer out) + throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException + { + + Marshaller.marshal(this, out); + } //-- void marshal(java.io.Writer) + + /** + * Method marshal + * + * @param handler + */ + public void marshal(org.xml.sax.ContentHandler handler) + throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException + { + + Marshaller.marshal(this, handler); + } //-- void marshal(org.xml.sax.ContentHandler) + + /** + * Method removeParameter + * + * @param vParameter + */ + public boolean removeParameter(org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType vParameter) + { + boolean removed = _parameterList.remove(vParameter); + return removed; + } //-- boolean removeParameter(org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType) + + /** + * Method setParameter + * + * @param index + * @param vParameter + */ + public void setParameter(int index, org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType vParameter) + throws java.lang.IndexOutOfBoundsException + { + //-- check bounds for index + if ((index < 0) || (index > _parameterList.size())) { + throw new IndexOutOfBoundsException(); + } + _parameterList.set(index, vParameter); + } //-- void setParameter(int, org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType) + + /** + * Method setParameter + * + * @param parameterArray + */ + public void setParameter(org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType[] parameterArray) + { + //-- copy array + _parameterList.clear(); + for (int i = 0; i < parameterArray.length; i++) { + _parameterList.add(parameterArray[i]); + } + } //-- void setParameter(org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType) + + /** + * Sets the value of field 'portNumber'. + * + * @param portNumber the value of field 'portNumber'. + */ + public void setPortNumber(int portNumber) + { + this._portNumber = portNumber; + this._has_portNumber = true; + } //-- void setPortNumber(int) + + /** + * Method unmarshalExternalSocketModelFactoryConfigXML + * + * @param reader + */ + public static org.openda.model_external_socket.io.castorgenerated.ExternalSocketModelFactoryConfigXML unmarshalExternalSocketModelFactoryConfigXML(java.io.Reader reader) + throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException + { + return (org.openda.model_external_socket.io.castorgenerated.ExternalSocketModelFactoryConfigXML) Unmarshaller.unmarshal(org.openda.model_external_socket.io.castorgenerated.ExternalSocketModelFactoryConfigXML.class, reader); + } //-- org.openda.model_external_socket.io.castorgenerated.ExternalSocketModelFactoryConfigXML unmarshalExternalSocketModelFactoryConfigXML(java.io.Reader) + + /** + * Method validate + */ + public void validate() + throws org.exolab.castor.xml.ValidationException + { + org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator(); + validator.validate(this); + } //-- void validate() + +} diff --git a/model_external_socket/castor_temp_src/org/openda/model_external_socket/io/castorgenerated/ExternalSocketModelFactoryConfigXMLDescriptor.java b/model_external_socket/castor_temp_src/org/openda/model_external_socket/io/castorgenerated/ExternalSocketModelFactoryConfigXMLDescriptor.java new file mode 100644 index 000000000..10339873b --- /dev/null +++ b/model_external_socket/castor_temp_src/org/openda/model_external_socket/io/castorgenerated/ExternalSocketModelFactoryConfigXMLDescriptor.java @@ -0,0 +1,220 @@ +/* + * This class was automatically generated with + * Castor 0.9.4.3, using an XML + * Schema. + * $Id$ + */ + +package org.openda.model_external_socket.io.castorgenerated; + + //---------------------------------/ + //- Imported classes and packages -/ +//---------------------------------/ + +import org.exolab.castor.mapping.AccessMode; +import org.exolab.castor.xml.TypeValidator; +import org.exolab.castor.xml.XMLFieldDescriptor; +import org.exolab.castor.xml.validators.*; + +/** + * Class ExternalSocketModelFactoryConfigXMLDescriptor. + * + * @version $Revision$ $Date$ + */ +public class ExternalSocketModelFactoryConfigXMLDescriptor extends org.exolab.castor.xml.util.XMLClassDescriptorImpl { + + + //--------------------------/ + //- Class/Member Variables -/ + //--------------------------/ + + /** + * Field nsPrefix + */ + private java.lang.String nsPrefix; + + /** + * Field nsURI + */ + private java.lang.String nsURI; + + /** + * Field xmlName + */ + private java.lang.String xmlName; + + /** + * Field identity + */ + private org.exolab.castor.xml.XMLFieldDescriptor identity; + + + //----------------/ + //- Constructors -/ + //----------------/ + + public ExternalSocketModelFactoryConfigXMLDescriptor() { + super(); + nsURI = "http://www.openda.org"; + xmlName = "ExternalSocketModelFactoryConfigXML"; + + //-- set grouping compositor + setCompositorAsSequence(); + org.exolab.castor.xml.util.XMLFieldDescriptorImpl desc = null; + org.exolab.castor.xml.XMLFieldHandler handler = null; + org.exolab.castor.xml.FieldValidator fieldValidator = null; + //-- initialize attribute descriptors + + //-- initialize element descriptors + + //-- _portNumber + desc = new org.exolab.castor.xml.util.XMLFieldDescriptorImpl(java.lang.Integer.TYPE, "_portNumber", "portNumber", org.exolab.castor.xml.NodeType.Element); + handler = (new org.exolab.castor.xml.XMLFieldHandler() { + public java.lang.Object getValue( java.lang.Object object ) + throws IllegalStateException + { + ExternalSocketModelFactoryConfigXML target = (ExternalSocketModelFactoryConfigXML) object; + if(!target.hasPortNumber()) + return null; + return new Integer(target.getPortNumber()); + } + public void setValue( java.lang.Object object, java.lang.Object value) + throws IllegalStateException, IllegalArgumentException + { + try { + ExternalSocketModelFactoryConfigXML target = (ExternalSocketModelFactoryConfigXML) object; + // ignore null values for non optional primitives + if (value == null) return; + + target.setPortNumber( ((Integer)value).intValue()); + } + catch (java.lang.Exception ex) { + throw new IllegalStateException(ex.toString()); + } + } + public java.lang.Object newInstance( java.lang.Object parent ) { + return null; + } + } ); + desc.setHandler(handler); + desc.setNameSpaceURI("http://www.openda.org"); + desc.setRequired(true); + desc.setMultivalued(false); + addFieldDescriptor(desc); + + //-- validation code for: _portNumber + fieldValidator = new org.exolab.castor.xml.FieldValidator(); + fieldValidator.setMinOccurs(1); + { //-- local scope + IntegerValidator typeValidator = new IntegerValidator(); + fieldValidator.setValidator(typeValidator); + } + desc.setValidator(fieldValidator); + //-- _parameterList + desc = new org.exolab.castor.xml.util.XMLFieldDescriptorImpl(org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType.class, "_parameterList", "parameter", org.exolab.castor.xml.NodeType.Element); + handler = (new org.exolab.castor.xml.XMLFieldHandler() { + public java.lang.Object getValue( java.lang.Object object ) + throws IllegalStateException + { + ExternalSocketModelFactoryConfigXML target = (ExternalSocketModelFactoryConfigXML) object; + return target.getParameter(); + } + public void setValue( java.lang.Object object, java.lang.Object value) + throws IllegalStateException, IllegalArgumentException + { + try { + ExternalSocketModelFactoryConfigXML target = (ExternalSocketModelFactoryConfigXML) object; + target.addParameter( (org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType) value); + } + catch (java.lang.Exception ex) { + throw new IllegalStateException(ex.toString()); + } + } + public java.lang.Object newInstance( java.lang.Object parent ) { + return new org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType(); + } + } ); + desc.setHandler(handler); + desc.setNameSpaceURI("http://www.openda.org"); + desc.setRequired(true); + desc.setMultivalued(true); + addFieldDescriptor(desc); + + //-- validation code for: _parameterList + fieldValidator = new org.exolab.castor.xml.FieldValidator(); + fieldValidator.setMinOccurs(1); + { //-- local scope + } + desc.setValidator(fieldValidator); + } //-- org.openda.model_external_socket.io.castorgenerated.ExternalSocketModelFactoryConfigXMLDescriptor() + + + //-----------/ + //- Methods -/ + //-----------/ + + /** + * Method getAccessMode + */ + public org.exolab.castor.mapping.AccessMode getAccessMode() + { + return null; + } //-- org.exolab.castor.mapping.AccessMode getAccessMode() + + /** + * Method getExtends + */ + public org.exolab.castor.mapping.ClassDescriptor getExtends() + { + return null; + } //-- org.exolab.castor.mapping.ClassDescriptor getExtends() + + /** + * Method getIdentity + */ + public org.exolab.castor.mapping.FieldDescriptor getIdentity() + { + return identity; + } //-- org.exolab.castor.mapping.FieldDescriptor getIdentity() + + /** + * Method getJavaClass + */ + public java.lang.Class getJavaClass() + { + return org.openda.model_external_socket.io.castorgenerated.ExternalSocketModelFactoryConfigXML.class; + } //-- java.lang.Class getJavaClass() + + /** + * Method getNameSpacePrefix + */ + public java.lang.String getNameSpacePrefix() + { + return nsPrefix; + } //-- java.lang.String getNameSpacePrefix() + + /** + * Method getNameSpaceURI + */ + public java.lang.String getNameSpaceURI() + { + return nsURI; + } //-- java.lang.String getNameSpaceURI() + + /** + * Method getValidator + */ + public org.exolab.castor.xml.TypeValidator getValidator() + { + return this; + } //-- org.exolab.castor.xml.TypeValidator getValidator() + + /** + * Method getXMLName + */ + public java.lang.String getXMLName() + { + return xmlName; + } //-- java.lang.String getXMLName() + +} diff --git a/model_external_socket/castorbuilder.properties b/model_external_socket/castorbuilder.properties new file mode 100644 index 000000000..39d3a656a --- /dev/null +++ b/model_external_socket/castorbuilder.properties @@ -0,0 +1,50 @@ +# +# Property file for SourceCodeGenerator +# +# $Id: castorbuilder.properties,v 1.1.1.1 2003/03/03 07:07:40 kvisco Exp $ +# To enable bound properties uncomment the following line. Please +# note that currently *all* fields will be treated as bound properties +# when enabled. This will change in the future when we introduce +# fine grained control over each class and it's properties. +# +#org.exolab.castor.builder.boundproperties=true +# Java class mapping of 's and 's +# +#org.exolab.castor.builder.javaclassmapping=element +org.exolab.castor.builder.javaclassmapping=type +# This property allows one to specify the super class of *all* +# generated classes +# +#org.exolab.castor.builder.superclass=com.xyz.BaseObject +# XML namespace mapping to Java packages +# +#org.exolab.castor.builder.nspackages=\ +http://www.xyz.com/schemas/project=com.xyz.schemas.project,\ + http://www.xyz.com/schemas/person=com.xyz.schemas.person +# Set to true if you want to generate the equals method +# for each generated class +# false by default +# +#org.exolab.castor.builder.equalsmethod=true +# Set to true if you want to use Object Wrappers instead +# of primitives (e.g Float instead of float). +# false by default. +# +#org.exolab.castor.builder.primitivetowrapper=false +# Set to true if you want the generated class descriptors to +# expose the element and attribute names they contain. +# false by default. +# +#org.exolab.castor.builder.classdescfieldnames=false +# Set to true if you want the generated source code to contain +# Extra methods for the collection fields, such as get/set using +# the collection type in addition to the type-safe array. +# Set this to true if you want your code to be more compatible +# with Castor JDO. This is false by default. +# +#org.exolab.castor.builder.extraCollectionMethods=true +# Use old-style (Castor 0.9.3.9) of naming that uppercases +# names after an underscore +# +#org.exolab.castor.xml.JavaNaming.upperCaseAfterUnderscore=true + diff --git a/model_external_socket/doc/.gitkeep b/model_external_socket/doc/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/model_external_socket/java/model_external_socket.iml b/model_external_socket/java/model_external_socket.iml new file mode 100644 index 000000000..afc7b546b --- /dev/null +++ b/model_external_socket/java/model_external_socket.iml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/model_external_socket/java/resources/openda/model_external_socket_castor.jar b/model_external_socket/java/resources/openda/model_external_socket_castor.jar new file mode 100644 index 000000000..9f810a6ef Binary files /dev/null and b/model_external_socket/java/resources/openda/model_external_socket_castor.jar differ diff --git a/model_external_socket/java/resources/openda/model_external_socket_castor_schemas.zip b/model_external_socket/java/resources/openda/model_external_socket_castor_schemas.zip new file mode 100644 index 000000000..bee787a91 Binary files /dev/null and b/model_external_socket/java/resources/openda/model_external_socket_castor_schemas.zip differ diff --git a/model_external_socket/java/resources/openda/model_external_socket_castor_src.zip b/model_external_socket/java/resources/openda/model_external_socket_castor_src.zip new file mode 100644 index 000000000..472c1d32e Binary files /dev/null and b/model_external_socket/java/resources/openda/model_external_socket_castor_src.zip differ diff --git a/model_external_socket/java/resources/resources_to_bin.test b/model_external_socket/java/resources/resources_to_bin.test new file mode 100644 index 000000000..e69de29bb diff --git a/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketBFGSAlgorithm.java b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketBFGSAlgorithm.java new file mode 100644 index 000000000..fb027bfb7 --- /dev/null +++ b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketBFGSAlgorithm.java @@ -0,0 +1,17 @@ +package org.openda.externalsocket; + +import org.openda.algorithms.BFGS; +import org.openda.blackbox.wrapper.BBStochModelInstance; +import org.openda.interfaces.IModelInstance; + +public class ExternalSocketBFGSAlgorithm extends BFGS { + @Override + public void next() { + super.next(); + if (this.hasNext() || this.bestEstimate == null) return; + if (!(bestEstimate instanceof BBStochModelInstance)) return; + IModelInstance bestModel = ((BBStochModelInstance) bestEstimate).getModel(); + if (!(bestModel instanceof ExternalSocketModelInstance)) return; + ((ExternalSocketModelInstance) bestModel).sendFinalParameters(null); + } +} diff --git a/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketConjugateGradientAlgorithm.java b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketConjugateGradientAlgorithm.java new file mode 100644 index 000000000..f83baec13 --- /dev/null +++ b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketConjugateGradientAlgorithm.java @@ -0,0 +1,17 @@ +package org.openda.externalsocket; + +import org.openda.algorithms.ConjugateGradient; +import org.openda.blackbox.wrapper.BBStochModelInstance; +import org.openda.interfaces.IModelInstance; + +public class ExternalSocketConjugateGradientAlgorithm extends ConjugateGradient { + @Override + public void next() { + super.next(); + if (this.hasNext() || this.bestEstimate == null) return; + if (!(bestEstimate instanceof BBStochModelInstance)) return; + IModelInstance bestModel = ((BBStochModelInstance) bestEstimate).getModel(); + if (!(bestModel instanceof ExternalSocketModelInstance)) return; + ((ExternalSocketModelInstance) bestModel).sendFinalParameters(null); + } +} diff --git a/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketDudAlgorithm.java b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketDudAlgorithm.java new file mode 100644 index 000000000..25c23ad0e --- /dev/null +++ b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketDudAlgorithm.java @@ -0,0 +1,31 @@ +package org.openda.externalsocket; + +import org.openda.algorithms.Dud; +import org.openda.blackbox.wrapper.BBStochModelInstance; +import org.openda.interfaces.IModelInstance; +import org.openda.interfaces.IStochModelInstance; + +public class ExternalSocketDudAlgorithm extends Dud { + + private IStochModelInstance currentBestEstimate; + private double[] currentBestStdValues; + + @Override + public void next() { + super.next(); + if (this.hasNext()) { + if (this.bestEstimate != currentBestEstimate) { + currentBestStdValues = optimizer.getStdValues(); + currentBestEstimate = this.bestEstimate; + } + return; + } + if (this.bestEstimate == null) return; + if (!(bestEstimate instanceof BBStochModelInstance)) return; + IModelInstance bestModel = ((BBStochModelInstance) bestEstimate).getModel(); + if (!(bestModel instanceof ExternalSocketModelInstance)) return; + ((ExternalSocketModelInstance) bestModel).sendFinalParameters(currentBestStdValues); + } + + +} diff --git a/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketGLUEAlgorithm.java b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketGLUEAlgorithm.java new file mode 100644 index 000000000..2aed4fa98 --- /dev/null +++ b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketGLUEAlgorithm.java @@ -0,0 +1,17 @@ +package org.openda.externalsocket; + +import org.openda.algorithms.GLUE; +import org.openda.blackbox.wrapper.BBStochModelInstance; +import org.openda.interfaces.IModelInstance; + +public class ExternalSocketGLUEAlgorithm extends GLUE { + @Override + public void next() { + super.next(); + if (this.hasNext() || this.bestEstimate == null) return; + if (!(bestEstimate instanceof BBStochModelInstance)) return; + IModelInstance bestModel = ((BBStochModelInstance) bestEstimate).getModel(); + if (!(bestModel instanceof ExternalSocketModelInstance)) return; + ((ExternalSocketModelInstance) bestModel).sendFinalParameters(null); + } +} diff --git a/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketGriddedFullSearchAlgorithm.java b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketGriddedFullSearchAlgorithm.java new file mode 100644 index 000000000..96f3dcae8 --- /dev/null +++ b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketGriddedFullSearchAlgorithm.java @@ -0,0 +1,17 @@ +package org.openda.externalsocket; + +import org.openda.algorithms.GriddedFullSearch; +import org.openda.blackbox.wrapper.BBStochModelInstance; +import org.openda.interfaces.IModelInstance; + +public class ExternalSocketGriddedFullSearchAlgorithm extends GriddedFullSearch { + @Override + public void next() { + super.next(); + if (this.hasNext() || this.bestEstimate == null) return; + if (!(bestEstimate instanceof BBStochModelInstance)) return; + IModelInstance bestModel = ((BBStochModelInstance) bestEstimate).getModel(); + if (!(bestModel instanceof ExternalSocketModelInstance)) return; + ((ExternalSocketModelInstance) bestModel).sendFinalParameters(null); + } +} diff --git a/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketModelFactory.java b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketModelFactory.java new file mode 100644 index 000000000..5070a639b --- /dev/null +++ b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketModelFactory.java @@ -0,0 +1,59 @@ +package org.openda.externalsocket; + +import org.openda.blackbox.interfaces.IModelFactory; +import org.openda.blackbox.interfaces.ITimeHorizonConsumer; +import org.openda.interfaces.IStochModelFactory; +import org.openda.interfaces.IStochModelPostProcessor; +import org.openda.interfaces.ITime; + +import java.io.File; + +public class ExternalSocketModelFactory implements IModelFactory, ITimeHorizonConsumer, IStochModelFactory { + + private ExternalSocketModelFactoryConfigReader configReader; + private File dummyModelDir; + + @Override + public ExternalSocketModelInstance getInstance(OutputLevel outputLevel) { + return new ExternalSocketModelInstance(configReader.getPortNumber(), configReader.getValues(), configReader.getStdDev(), configReader.getLowerBounds(), configReader.getUpperBounds(), dummyModelDir); + } + + @Override + public IStochModelPostProcessor getPostprocessorInstance(File instanceDir) { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelFactory.getPostprocessorInstance() not implemented yet"); + + } + + @Override + public ExternalSocketModelInstance getInstance(String[] arguments, IStochModelFactory.OutputLevel outputLevel) { + return new ExternalSocketModelInstance(configReader.getPortNumber(), configReader.getValues(), configReader.getStdDev(), configReader.getLowerBounds(), configReader.getUpperBounds(), dummyModelDir); + } + + @Override + public void finish() { + throw new RuntimeException("org.openda.externalsocket.ExternalModelStochModelFactory.finish() not implemented yet"); + + } + + @Override + public void setTimeHorizon(ITime timeHorizon) { + throw new RuntimeException("org.openda.externalsocket.ExternalModelStochModelFactory.setTimeHorizon() not implemented yet"); + + } + + @Override + public void initialize(File workingDir, String[] arguments) { + if (arguments == null || arguments.length < 1) { + throw new IllegalArgumentException(getClass().getSimpleName() + + ": First argument should be: relative bmiModelFactoryConfig file path."); + } + dummyModelDir = new File(workingDir, "dummyModelDir"); + File externalModelFactoryConfigFile = new File(workingDir, arguments[0]); + if (!externalModelFactoryConfigFile.exists()) { + throw new IllegalArgumentException(getClass().getSimpleName() + ": Cannot find bmiModelFactoryConfig file " + + externalModelFactoryConfigFile.getAbsolutePath()); + } + + configReader = new ExternalSocketModelFactoryConfigReader(externalModelFactoryConfigFile); + } +} diff --git a/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketModelFactoryConfigReader.java b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketModelFactoryConfigReader.java new file mode 100644 index 000000000..c81db4fd5 --- /dev/null +++ b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketModelFactoryConfigReader.java @@ -0,0 +1,53 @@ +package org.openda.externalsocket; + +import org.openda.model_external_socket.io.castorgenerated.ExternalModelParameterComplexType; +import org.openda.model_external_socket.io.castorgenerated.ExternalSocketModelFactoryConfigXML; +import org.openda.utils.io.CastorUtils; + +import java.io.File; + +public class ExternalSocketModelFactoryConfigReader { + + private final int portNumber; + private final double[] values; + private final double[] stdDev; + private final double[] lowerBounds; + private final double[] upperBounds; + + public ExternalSocketModelFactoryConfigReader(File configFile) { + ExternalSocketModelFactoryConfigXML castor = (ExternalSocketModelFactoryConfigXML) CastorUtils.parse(configFile, ExternalSocketModelFactoryConfigXML.class); + portNumber = castor.getPortNumber(); + int parameterCount = castor.getParameterCount(); + values = new double[parameterCount]; + stdDev = new double[parameterCount]; + lowerBounds = new double[parameterCount]; + upperBounds = new double[parameterCount]; + for (int i = 0; i < parameterCount; i++) { + ExternalModelParameterComplexType parameter = castor.getParameter(i); + values[i] = parameter.getStartValue(); + stdDev[i] = parameter.getStdDev(); + lowerBounds[i] = parameter.hasLowerBound() ? parameter.getLowerBound() : Double.NaN; + upperBounds[i] = parameter.hasUpperBound() ? parameter.getUpperBound() : Double.NaN; + } + } + + public int getPortNumber() { + return portNumber; + } + + public double[] getValues() { + return values; + } + + public double[] getStdDev() { + return stdDev; + } + + public double[] getLowerBounds() { + return lowerBounds; + } + + public double[] getUpperBounds() { + return upperBounds; + } +} diff --git a/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketModelInstance.java b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketModelInstance.java new file mode 100644 index 000000000..33b531040 --- /dev/null +++ b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketModelInstance.java @@ -0,0 +1,303 @@ +package org.openda.externalsocket; + +import org.openda.exchange.DoubleExchangeItem; +import org.openda.interfaces.IExchangeItem; +import org.openda.interfaces.IInstance; +import org.openda.interfaces.ILocalizationDomains; +import org.openda.interfaces.IModelState; +import org.openda.interfaces.IObservationDescriptions; +import org.openda.interfaces.IObservationOperator; +import org.openda.interfaces.IStochModelInstance; +import org.openda.interfaces.IStochModelInstanceDeprecated; +import org.openda.interfaces.IStochVector; +import org.openda.interfaces.ITime; +import org.openda.interfaces.IVector; +import org.openda.observationOperators.ObservationOperatorDeprecatedModel; +import org.openda.utils.StochVector; +import org.openda.utils.Time; +import org.openda.utils.Vector; + +import java.io.File; +import java.util.LinkedHashMap; + +public class ExternalSocketModelInstance implements IStochModelInstance, IStochModelInstanceDeprecated, Cloneable { + + private static final String EXTERNAL_SOCKET_PARAMETER = "ExternalSocketParameter"; + private int portNumber; + private Vector parameterVector; + private Vector modelResults; + private final double[] lowerBounds; + private final double[] upperBounds; + private File dummyModelDir; + private final StochVector parameterUncertainties; + private LinkedHashMap exchangeItems = new LinkedHashMap<>(); + private Time fakeTime = new Time(58119,58120,1d/24d); + + public ExternalSocketModelInstance(int portNumber, double[] parameterValues, double[] standardDeviations, double[] lowerBounds, double[] upperBounds, File dummyModelDir) { + this.portNumber = portNumber; + this.parameterVector = new Vector(parameterValues); + this.lowerBounds = lowerBounds; + this.upperBounds = upperBounds; + this.dummyModelDir = dummyModelDir; + this.parameterUncertainties = new StochVector(parameterValues, standardDeviations); + for (int i = 0; i < parameterValues.length; i++) { + String paramId = EXTERNAL_SOCKET_PARAMETER + "_" + i; + DoubleExchangeItem paramEI = new DoubleExchangeItem(paramId, parameterValues[i]); + exchangeItems.put(paramId, paramEI); + } + } + + public IVector getState() { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.getState() not implemented yet"); + + } + + public IVector getState(int iDomain) { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.getState() not implemented yet"); + + } + + public void axpyOnState(double alpha, IVector vector) { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.axpyOnState() not implemented yet"); + + } + + public void axpyOnState(double alpha, IVector vector, int iDomain) { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.axpyOnState() not implemented yet"); + + } + + public IVector getParameters() { + if (parameterVector == null) { + throw new RuntimeException("CalLibStochModelInstance.getParameters(): initialParameterVector == null"); + } + return parameterVector; + } + + public void setParameters(IVector parameters) { + parameterVector = new Vector(parameters.getValues()); + } + + public void axpyOnParameters(double alpha, IVector vector) { + Vector parameterVector = new Vector(this.parameterVector.getValues()); + parameterVector.axpy(alpha, vector); + this.parameterVector = parameterVector.clone(); + } + + public IStochVector getStateUncertainty() { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.getStateUncertainty() not implemented yet"); + + } + + public IStochVector getParameterUncertainty() { + return parameterUncertainties; + } + + public IStochVector[] getWhiteNoiseUncertainty(ITime time) { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.getWhiteNoiseUncertainty() not implemented yet"); + + } + + public boolean isWhiteNoiseStationary() { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.isWhiteNoiseStationary() not implemented yet"); + + } + + public ITime[] getWhiteNoiseTimes(ITime timeSpan) { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.getWhiteNoiseTimes() not implemented yet"); + + } + + public IVector[] getWhiteNoise(ITime timeSpan) { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.getWhiteNoise() not implemented yet"); + + } + + public void setWhiteNoise(IVector[] whiteNoise) { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.setWhiteNoise() not implemented yet"); + + } + + public void axpyOnWhiteNoise(double alpha, IVector[] vector) { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.axpyOnWhiteNoise() not implemented yet"); + + } + + public void setAutomaticNoiseGeneration(boolean value) { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.setAutomaticNoiseGeneration() not implemented yet"); + + } + + public IObservationOperator getObservationOperator() { + return new ObservationOperatorDeprecatedModel(this); + + } + + public void announceObservedValues(IObservationDescriptions observationDescriptions) { + // Not used + } + + public IVector getStateScaling() { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.getStateScaling() not implemented yet"); + + } + + public IVector[] getStateScaling(IObservationDescriptions observationDescriptions) { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.getStateScaling() not implemented yet"); + + } + + public IExchangeItem getExchangeItem(String exchangeItemID) { + return exchangeItems.get(exchangeItemID); + } + + public ITime getTimeHorizon() { + return fakeTime; + } + + public ITime getCurrentTime() { + return fakeTime; + } + + public void compute(ITime targetTime) { + +/* Runnable socketServerRunnable = new Runnable() { + @Override + public void run() { + SocketServer socketServer = new SocketServer(portNumber); + socketServer.runAndWaitForMessage(); + } + }; + Thread thread = new Thread(socketServerRunnable); + thread.start();*/ + + SocketClient socketClient = new SocketClient(portNumber); + int size = parameterVector.getSize(); + StringBuilder stringBuilder = new StringBuilder(10); + stringBuilder.append("X:"); + for (int i = 0; i < size; i++) { + double value = parameterVector.getValue(i); + // When comparing with Double.NaN < and > always return false + if (value < lowerBounds[i]) value = lowerBounds[i]; + if (value > upperBounds[i]) value = upperBounds[i]; + stringBuilder.append(value); + stringBuilder.append(';'); + } + String messageIn = stringBuilder.toString(); + System.out.println("Sending message: " + messageIn); + String received = socketClient.sendAndReceive(messageIn); + System.out.println("Received" + received); + String[] split = received.trim().split(";"); + double[] receivedValues = new double[split.length]; + for (int i = 0; i < split.length; i++) { + double parsedModelResult = Double.parseDouble(split[i]); + receivedValues[i] = parsedModelResult; + } + modelResults = new Vector(receivedValues); + } + + public ILocalizationDomains getLocalizationDomains() { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.getLocalizationDomains() not implemented yet"); + + } + + public IVector[] getObservedLocalization(IObservationDescriptions observationDescriptions, double distance) { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.getObservedLocalization() not implemented yet"); + + } + + public IVector[] getObservedLocalization(IObservationDescriptions observationDescriptions, double distance, int iDomain) { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.getObservedLocalization() not implemented yet"); + + } + + public IModelState saveInternalState() { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.saveInternalState() not implemented yet"); + + } + + public void restoreInternalState(IModelState savedInternalState) { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.restoreInternalState() not implemented yet"); + + } + + public void releaseInternalState(IModelState savedInternalState) { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.releaseInternalState() not implemented yet"); + + } + + public IModelState loadPersistentState(File persistentStateFile) { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.loadPersistentState() not implemented yet"); + + } + + public File getModelRunDir() { + return dummyModelDir; + } + + public String[] getExchangeItemIDs() { + return exchangeItems.keySet().toArray(new String[0]); + } + + public String[] getExchangeItemIDs(IExchangeItem.Role role) { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.getExchangeItemIDs() not implemented yet"); + + } + + public IExchangeItem getDataObjectExchangeItem(String exchangeItemID) { + return exchangeItems.get(exchangeItemID); + + } + + public void finish() { + // Not used, sendFinalParameters is used instead + } + + public void initialize(File workingDir, String[] arguments) { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.initialize() not implemented yet"); + + } + + public IInstance getParent() { + throw new RuntimeException("org.openda.externalsocket.ExternalSocketModelInstance.getParent() not implemented yet"); + + } + + public IVector getObservedValues(IObservationDescriptions observationDescriptions) { + return modelResults; + } + + void sendFinalParameters(double[] stdValues) { + // Used for testing +/* Runnable socketServerRunnable = new Runnable() { + @Override + public void run() { + SocketServer socketServer = new SocketServer(portNumber); + socketServer.runAndWaitForMessage(); + } + }; + Thread thread = new Thread(socketServerRunnable); + thread.start();*/ + + SocketClient socketClient = new SocketClient(portNumber); + int size = parameterVector.getSize(); + StringBuilder stringBuilder = new StringBuilder(10); + stringBuilder.append("C:"); + for (int i = 0; i < size; i++) { + stringBuilder.append(parameterVector.getValue(i)); + if (i != size - 1) stringBuilder.append(';'); + } + if (stdValues != null) { + stringBuilder.append(':'); + for (int i = 0; i < stdValues.length; i++) { + stringBuilder.append(stdValues[i]); + if (i != stdValues.length - 1) stringBuilder.append(';'); + } + } + String messageIn = stringBuilder.toString(); + System.out.println("Sending message: " + messageIn); + socketClient.send(messageIn); + System.out.println("Message sent " + messageIn); + + } +} diff --git a/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketPowellAlgorithm.java b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketPowellAlgorithm.java new file mode 100644 index 000000000..ffde22bad --- /dev/null +++ b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketPowellAlgorithm.java @@ -0,0 +1,17 @@ +package org.openda.externalsocket; + +import org.openda.algorithms.Powell; +import org.openda.blackbox.wrapper.BBStochModelInstance; +import org.openda.interfaces.IModelInstance; + +public class ExternalSocketPowellAlgorithm extends Powell { + @Override + public void next() { + super.next(); + if (this.hasNext() || this.bestEstimate == null) return; + if (!(bestEstimate instanceof BBStochModelInstance)) return; + IModelInstance bestModel = ((BBStochModelInstance) bestEstimate).getModel(); + if (!(bestModel instanceof ExternalSocketModelInstance)) return; + ((ExternalSocketModelInstance) bestModel).sendFinalParameters(null); + } +} diff --git a/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketSCEAlgorithm.java b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketSCEAlgorithm.java new file mode 100644 index 000000000..d3f4952f3 --- /dev/null +++ b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketSCEAlgorithm.java @@ -0,0 +1,17 @@ +package org.openda.externalsocket; + +import org.openda.algorithms.SCE; +import org.openda.blackbox.wrapper.BBStochModelInstance; +import org.openda.interfaces.IModelInstance; + +public class ExternalSocketSCEAlgorithm extends SCE { + @Override + public void next() { + super.next(); + if (this.hasNext() || this.bestEstimate == null) return; + if (!(bestEstimate instanceof BBStochModelInstance)) return; + IModelInstance bestModel = ((BBStochModelInstance) bestEstimate).getModel(); + if (!(bestModel instanceof ExternalSocketModelInstance)) return; + ((ExternalSocketModelInstance) bestModel).sendFinalParameters(null); + } +} diff --git a/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketSimplexAlgorithm.java b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketSimplexAlgorithm.java new file mode 100644 index 000000000..21ceb9688 --- /dev/null +++ b/model_external_socket/java/src/org/openda/externalsocket/ExternalSocketSimplexAlgorithm.java @@ -0,0 +1,29 @@ +package org.openda.externalsocket; + +import org.openda.algorithms.Simplex; +import org.openda.blackbox.wrapper.BBStochModelInstance; +import org.openda.interfaces.IModelInstance; +import org.openda.interfaces.IStochModelInstance; + +public class ExternalSocketSimplexAlgorithm extends Simplex { + + private IStochModelInstance currentBestEstimate; + private double[] currentBestStdValues; + + @Override + public void next() { + super.next(); + if (this.hasNext()) { + if (this.bestEstimate != currentBestEstimate) { + currentBestStdValues = simplexOptimizer.getStdValues(); + currentBestEstimate = this.bestEstimate; + } + return; + } + if (this.bestEstimate == null) return; + if (!(bestEstimate instanceof BBStochModelInstance)) return; + IModelInstance bestModel = ((BBStochModelInstance) bestEstimate).getModel(); + if (!(bestModel instanceof ExternalSocketModelInstance)) return; + ((ExternalSocketModelInstance) bestModel).sendFinalParameters(currentBestStdValues); + } +} diff --git a/model_external_socket/java/src/org/openda/externalsocket/SocketClient.java b/model_external_socket/java/src/org/openda/externalsocket/SocketClient.java new file mode 100644 index 000000000..aa03ed7cc --- /dev/null +++ b/model_external_socket/java/src/org/openda/externalsocket/SocketClient.java @@ -0,0 +1,62 @@ +package org.openda.externalsocket; + +import java.io.*; +import java.net.InetAddress; +import java.net.Socket; +import java.net.UnknownHostException; + +class SocketClient { + + private final String hostAddress; + private int port; + + SocketClient(int port) { + try { + this.hostAddress = InetAddress.getLocalHost().getHostAddress(); + } catch (UnknownHostException e) { + throw new RuntimeException(e.getMessage(), e); + } + this.port = port; + } + + String sendAndReceive(String messageIn) { + try ( + Socket echoSocket = new Socket(hostAddress, port); + PrintWriter out = new PrintWriter(echoSocket.getOutputStream(), true); + InputStream inputStream = echoSocket.getInputStream()) { + out.println(messageIn); + System.out.println("Message sent: " + messageIn); + while (inputStream.available() == 0) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + System.out.println("Waiting for input stream to have data available interrupted"); + } + } + int availableLength = inputStream.available(); + System.out.println("Input stream available: " + availableLength); + byte[] bytes = new byte[availableLength]; + DataInputStream dataInputStream = new DataInputStream(inputStream); + dataInputStream.readFully(bytes); + return new String(bytes); + } catch (UnknownHostException e) { + System.err.println("Don't know about host " + hostAddress); + } catch (IOException e) { + System.err.println("Couldn't get I/O for the connection to " + hostAddress); + } + return null; + } + + void send(String messageIn) { + try ( + Socket echoSocket = new Socket(hostAddress, port); + PrintWriter out = new PrintWriter(echoSocket.getOutputStream(), true)) { + out.println(messageIn); + System.out.println("Message sent: " + messageIn); + } catch (UnknownHostException e) { + System.err.println("Don't know about host " + hostAddress); + } catch (IOException e) { + System.err.println("Couldn't get I/O for the connection to " + hostAddress); + } + } +} diff --git a/model_external_socket/java/src/org/openda/externalsocket/SocketServer.java b/model_external_socket/java/src/org/openda/externalsocket/SocketServer.java new file mode 100644 index 000000000..bd1cf6a31 --- /dev/null +++ b/model_external_socket/java/src/org/openda/externalsocket/SocketServer.java @@ -0,0 +1,43 @@ +package org.openda.externalsocket; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.ServerSocket; +import java.net.Socket; + +class SocketServer { + + private int portNumber; + + SocketServer(int portNumber) { + this.portNumber = portNumber; + } + + void runAndWaitForMessage() { + try ( + ServerSocket serverSocket = new ServerSocket(portNumber); + Socket clientSocket = serverSocket.accept(); + BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()))) { + PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); + String inputLine; + while ((inputLine = in.readLine()) != null) { + System.out.println("Server received: " + inputLine); + String[] split = inputLine.substring(2).split(";"); + StringBuilder builder = new StringBuilder(10); + for (int i = 0; i < split.length; i++) { + double receivedDouble = Double.parseDouble(split[i]); + double returnDouble = receivedDouble - (receivedDouble / (receivedDouble - i)) / 2; + builder.append(returnDouble).append(";"); + } + String sendMessage = builder.toString(); + System.out.println("Server sends: " + sendMessage); + out.println(sendMessage); + } + } catch (IOException e) { + System.out.println("Exception caught when trying to listen on port " + portNumber + " or listening for a connection"); + System.out.println(e.getMessage()); + } + } +} diff --git a/model_external_socket/java/test/org/openda/externalsocket/ExternalModelStochModelFactoryTest.java b/model_external_socket/java/test/org/openda/externalsocket/ExternalModelStochModelFactoryTest.java new file mode 100644 index 000000000..51138c4ee --- /dev/null +++ b/model_external_socket/java/test/org/openda/externalsocket/ExternalModelStochModelFactoryTest.java @@ -0,0 +1,32 @@ +package org.openda.externalsocket; + +import junit.framework.TestCase; +import org.openda.interfaces.IStochModelFactory; +import org.openda.interfaces.IVector; +import org.openda.utils.OpenDaTestSupport; + +import java.io.File; + +public class ExternalModelStochModelFactoryTest extends TestCase { + + private File testRunDataDir; + + protected void setUp() { + OpenDaTestSupport testData = new OpenDaTestSupport(ExternalModelStochModelFactoryTest.class, "model_external_socket"); + testRunDataDir = testData.getTestRunDataDir(); + } + + + public void testReadConfig() { + ExternalSocketModelFactory externalModelStochModelFactory = new ExternalSocketModelFactory(); + externalModelStochModelFactory.initialize(testRunDataDir, new String[]{"ExternalSocketModelFactory.xml"}); + ExternalSocketModelInstance stochModelInstance = externalModelStochModelFactory.getInstance(new String[0], IStochModelFactory.OutputLevel.Suppress); + IVector parameters = stochModelInstance.getParameters(); + int size = parameters.getSize(); + assertEquals(3, size); + for (int i = 0; i < size; i++) { + assertEquals((double) i + 1, parameters.getValue(i)); + } + } + +} diff --git a/model_external_socket/java/test/org/openda/externalsocket/SocketClientServerTest.java b/model_external_socket/java/test/org/openda/externalsocket/SocketClientServerTest.java new file mode 100644 index 000000000..42c630437 --- /dev/null +++ b/model_external_socket/java/test/org/openda/externalsocket/SocketClientServerTest.java @@ -0,0 +1,26 @@ +package org.openda.externalsocket; + +import junit.framework.TestCase; + +public class SocketClientServerTest extends TestCase { + + public void setUp() throws Exception { + super.setUp(); + } + + public void testSendAndReceive() { + /*final int port = 8124; + Runnable socketServerRunnable = new Runnable() { + @Override + public void run() { + SocketServer socketServer = new SocketServer(port); + socketServer.runAndWaitForMessage(); + } + }; + Thread thread = new Thread(socketServerRunnable); + thread.start(); + SocketClient socketClient = new SocketClient(port); + String messageReceived = socketClient.sendAndReceive("Z:0.1;0.2;0.3;"); + assertEquals("0.05;0.6000000000000001;1.15;", messageReceived);*/ + } +} diff --git a/model_external_socket/java/test/org/openda/externalsocket/testData/ExternalSocketModelFactory.xml b/model_external_socket/java/test/org/openda/externalsocket/testData/ExternalSocketModelFactory.xml new file mode 100644 index 000000000..33d67a0d1 --- /dev/null +++ b/model_external_socket/java/test/org/openda/externalsocket/testData/ExternalSocketModelFactory.xml @@ -0,0 +1,7 @@ + + + 8124 + + + + diff --git a/model_external_socket/java/unit_test_info.txt b/model_external_socket/java/unit_test_info.txt new file mode 100644 index 000000000..36f573c4f --- /dev/null +++ b/model_external_socket/java/unit_test_info.txt @@ -0,0 +1,6 @@ +# +# Info for running unit tests when IDE has current directory as startup dir. +# + +ModuleName=model_external_socket +UnitTestsRootDir=.. diff --git a/model_external_socket/module.properties b/model_external_socket/module.properties new file mode 100644 index 000000000..7a2d395a0 --- /dev/null +++ b/model_external_socket/module.properties @@ -0,0 +1,31 @@ +#module settings +module=model_external_socket + +#preferences +debug=yes + +#import stuff from other modules from here +projectdir=.. +projectlib=bin + +# +# ALL SET TO DEFAULTS - NO NEED TO CHANGE +# +srcdir=java/src +testdir=java/test +resourcesdir=java/resources +external=bin_external +builddir=build +buildtestdir=build-test +javadocdir=javadoc +jarname=${module}.jar +modulebindir=bin +modulelibdir=bin + +listfiles=no +failonerror=no +minmemory=200M +maxmemory=200M + +projectname=OpenDA +vendor=OpenDA association diff --git a/model_external_socket/native/.gitkeep b/model_external_socket/native/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/model_external_socket/tests/run_test.sh b/model_external_socket/tests/run_test.sh new file mode 100644 index 000000000..be8d05897 --- /dev/null +++ b/model_external_socket/tests/run_test.sh @@ -0,0 +1,3 @@ +#! /bin/sh + +java -cp ../bin/module_template.jar org.openda.NothingUseful diff --git a/model_external_socket/unit_test_info.txt b/model_external_socket/unit_test_info.txt new file mode 100644 index 000000000..aa0152578 --- /dev/null +++ b/model_external_socket/unit_test_info.txt @@ -0,0 +1,6 @@ +# +# Info for running unit tests when IDE has current directory as startup dir. +# + +ModuleName=model_external_socket +UnitTestsRootDir=. diff --git a/model_external_socket/xmlSchemas/.gitkeep b/model_external_socket/xmlSchemas/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/model_external_socket/xmlSchemas/externalSocketModelFactory.xsd b/model_external_socket/xmlSchemas/externalSocketModelFactory.xsd new file mode 100644 index 000000000..fe5ab088c --- /dev/null +++ b/model_external_socket/xmlSchemas/externalSocketModelFactory.xsd @@ -0,0 +1,21 @@ + + + + + + Configuration for an external model factory. It contains information on the socket port number and parameter initialisation values + + + + + + + + + + + + + + + diff --git a/model_glm/java/src/org/openda/model_glm/GlmNetcdfFile.java b/model_glm/java/src/org/openda/model_glm/GlmNetcdfFile.java index 40412185e..f2814669e 100644 --- a/model_glm/java/src/org/openda/model_glm/GlmNetcdfFile.java +++ b/model_glm/java/src/org/openda/model_glm/GlmNetcdfFile.java @@ -98,7 +98,7 @@ import org.openda.exchange.timeseries.TimeSeries; import org.openda.interfaces.IDataObject; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; import java.io.File; import java.io.IOException; @@ -141,7 +141,7 @@ public void initialize(File workingDir, String fileName, String[] arguments) { * Returns exchange Items from the netcdf file * For all waterlevel stations a TimeSeries exchange item is created * For the SEP variable a SimonaNetcdfFileExchangeItem is created to pass the netcdf file itself - * @return IPrevExchangeItem[] list of exchangeItems + * @return IExchangeItem[] list of exchangeItems */ public TimeSeries[] getExchangeItems() { TimeSeries[] result=null; @@ -149,7 +149,7 @@ public TimeSeries[] getExchangeItems() { // = new WaquaNetcdfTimeSeriesFormatter(); //String timeSeriesIds[] = waquaFormatter.getTimeSeriesIds(this.fileName); //String mapsIds[] = waquaFormatter.getMapIds(this.fileName); - //result = new IPrevExchangeItem[timeSeriesIds.length + mapsIds.length]; MVL disabled maps + //result = new IExchangeItem[timeSeriesIds.length + mapsIds.length]; MVL disabled maps //result = new TimeSeries[timeSeriesIds.length]; int i = 0; //for(String id: timeSeriesIds) { diff --git a/model_glm/java/src/org/openda/model_glm/GlmNmlFile.java b/model_glm/java/src/org/openda/model_glm/GlmNmlFile.java index 2195f3e46..e9c7dcc7d 100644 --- a/model_glm/java/src/org/openda/model_glm/GlmNmlFile.java +++ b/model_glm/java/src/org/openda/model_glm/GlmNmlFile.java @@ -20,7 +20,7 @@ package org.openda.model_glm; import org.openda.exchange.DoubleExchangeItem; import org.openda.interfaces.*; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; import org.openda.utils.Results; import java.io.BufferedReader; import java.io.BufferedWriter; diff --git a/model_glm/java/test/org/openda/model_glm/GlmNetcdfFileTest.java b/model_glm/java/test/org/openda/model_glm/GlmNetcdfFileTest.java index 3551a9d46..cb03c1549 100644 --- a/model_glm/java/test/org/openda/model_glm/GlmNetcdfFileTest.java +++ b/model_glm/java/test/org/openda/model_glm/GlmNetcdfFileTest.java @@ -47,11 +47,11 @@ public void testDummy(){ */ // public void testSeriesWaterlevel1() { // -// IDataObject ioObject = new GlmNetcdfFile(); +// IDataObject dataObject = new GlmNetcdfFile(); // String args[] = {}; -// ioObject initialize(testRunDataDir, "SimonaNetcdfFile/waterlevelseries.nc", args); +// dataObject initialize(testRunDataDir, "SimonaNetcdfFile/waterlevelseries.nc", args); // -// TimeSeries[] exchangeItems = ioObject.getExchangeItems(); +// TimeSeries[] exchangeItems = dataObject.getExchangeItems(); // int n = exchangeItems.length; // assertEquals("exchangeItems.length", 275, exchangeItems.length); // @@ -92,11 +92,11 @@ public void testDummy(){ // File inputFile = new File(testRunDataDir, "SimonaNetcdfFile/waqua.nc"); // ioObject.initialize(testRunDataDir, "SimonaNetcdfFile/waqua.nc", args); // -// IPrevExchangeItem[] exchangeItems = ioObject.getExchangeItems(); +// IExchangeItem[] exchangeItems = ioObject.getExchangeItems(); // int n = exchangeItems.length; // assertEquals("exchangeItems.length", 32, n); // -// IPrevExchangeItem lastExchangeItem = exchangeItems[n-1]; +// IExchangeItem lastExchangeItem = exchangeItems[n-1]; // assertEquals("last exchangeItems id", "SEP", lastExchangeItem.getId()); // TODO (SV): Fix test. Test gives error diff --git a/model_glm/java/test/org/openda/model_glm/GlmNmlFileTest.java b/model_glm/java/test/org/openda/model_glm/GlmNmlFileTest.java index 743875e35..108b6424b 100644 --- a/model_glm/java/test/org/openda/model_glm/GlmNmlFileTest.java +++ b/model_glm/java/test/org/openda/model_glm/GlmNmlFileTest.java @@ -39,18 +39,18 @@ protected void setUp() throws IOException { public void testReadInput() { - IDataObject ioObject = new GlmNmlFile(); + IDataObject dataObject = new GlmNmlFile(); String args[] = {"fabm.nml"}; - ioObject.initialize(testRunDataDir, args); + dataObject.initialize(testRunDataDir, args); // dump interpreted data to screen - System.out.println(ioObject.toString()); + System.out.println(dataObject.toString()); - String[] exchangeItemIds = ioObject.getExchangeItemIDs(); + String[] exchangeItemIds = dataObject.getExchangeItemIDs(); for(int item=0;item - + %inputFile% input - + - + %outputFile% output - + diff --git a/model_gotm/java/src/org/openda/model_gotm/GotmMeteoFile.java b/model_gotm/java/src/org/openda/model_gotm/GotmMeteoFile.java index 9c02049bb..65a874a07 100644 --- a/model_gotm/java/src/org/openda/model_gotm/GotmMeteoFile.java +++ b/model_gotm/java/src/org/openda/model_gotm/GotmMeteoFile.java @@ -25,7 +25,7 @@ import org.openda.exchange.timeseries.TimeSeriesSet; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; //import org.openda.model_dflowfm.DFlowFMTimTimeSeriesFormatter; import org.openda.exchange.DoubleExchangeItem; import org.openda.exchange.QuantityInfo; diff --git a/model_gotm/java/src/org/openda/model_gotm/GotmNetcdfFile.java b/model_gotm/java/src/org/openda/model_gotm/GotmNetcdfFile.java index 662c3e6af..eefbcf71e 100644 --- a/model_gotm/java/src/org/openda/model_gotm/GotmNetcdfFile.java +++ b/model_gotm/java/src/org/openda/model_gotm/GotmNetcdfFile.java @@ -98,7 +98,7 @@ import org.openda.exchange.timeseries.TimeSeries; import org.openda.interfaces.IDataObject; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; import java.io.File; import java.io.IOException; @@ -141,7 +141,7 @@ public void initialize(File workingDir, String fileName, String[] arguments) { * Returns exchange Items from the netcdf file * For all waterlevel stations a TimeSeries exchange item is created * For the SEP variable a SimonaNetcdfFileExchangeItem is created to pass the netcdf file itself - * @return IPrevExchangeItem[] list of exchangeItems + * @return IExchangeItem[] list of exchangeItems */ public TimeSeries[] getExchangeItems() { TimeSeries[] result=null; @@ -149,7 +149,7 @@ public TimeSeries[] getExchangeItems() { // = new WaquaNetcdfTimeSeriesFormatter(); //String timeSeriesIds[] = waquaFormatter.getTimeSeriesIds(this.fileName); //String mapsIds[] = waquaFormatter.getMapIds(this.fileName); - //result = new IPrevExchangeItem[timeSeriesIds.length + mapsIds.length]; MVL disabled maps + //result = new IExchangeItem[timeSeriesIds.length + mapsIds.length]; MVL disabled maps //result = new TimeSeries[timeSeriesIds.length]; int i = 0; //for(String id: timeSeriesIds) { diff --git a/model_gotm/java/src/org/openda/model_gotm/GotmNmlFile.java b/model_gotm/java/src/org/openda/model_gotm/GotmNmlFile.java index 24fd9ce18..db3bb20c3 100644 --- a/model_gotm/java/src/org/openda/model_gotm/GotmNmlFile.java +++ b/model_gotm/java/src/org/openda/model_gotm/GotmNmlFile.java @@ -22,7 +22,7 @@ import org.openda.exchange.QuantityInfo; import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.*; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; import org.openda.utils.Results; import java.io.BufferedReader; diff --git a/model_gotm/java/src/org/openda/model_gotm/GotmNmlFile2.java b/model_gotm/java/src/org/openda/model_gotm/GotmNmlFile2.java index 8a786c10b..abbb16194 100644 --- a/model_gotm/java/src/org/openda/model_gotm/GotmNmlFile2.java +++ b/model_gotm/java/src/org/openda/model_gotm/GotmNmlFile2.java @@ -22,7 +22,7 @@ import org.openda.exchange.QuantityInfo; import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.*; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; import org.openda.utils.Results; import java.io.BufferedReader; diff --git a/model_gotm/java/src/org/openda/model_gotm/GotmProfileFile.java b/model_gotm/java/src/org/openda/model_gotm/GotmProfileFile.java index 7809eb2da..76b601ae6 100644 --- a/model_gotm/java/src/org/openda/model_gotm/GotmProfileFile.java +++ b/model_gotm/java/src/org/openda/model_gotm/GotmProfileFile.java @@ -24,7 +24,7 @@ import org.openda.exchange.TimeInfo; import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.*; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; import org.openda.utils.Results; import org.openda.utils.Vector; @@ -214,7 +214,7 @@ public void initialize(File workingDir, String[] arguments) { } for ( int iVar = 0 ; iVar < nVar ; iVar++ ) { - ArrayExchangeItem item = new ArrayExchangeItem(idVar[iVar], IPrevExchangeItem.Role.InOut); + ArrayExchangeItem item = new ArrayExchangeItem(idVar[iVar], IExchangeItem.Role.InOut); item.setValuesAsDoubles(valuesVector[iVar].getValues()); item.setTimeInfo(new TimeInfo(timesVector.getValues())); items.add(item); diff --git a/model_gotm/java/test/org/openda/model_gotm/GotmMeteoFileTest.java b/model_gotm/java/test/org/openda/model_gotm/GotmMeteoFileTest.java index 9fb76ee5d..e64e65797 100644 --- a/model_gotm/java/test/org/openda/model_gotm/GotmMeteoFileTest.java +++ b/model_gotm/java/test/org/openda/model_gotm/GotmMeteoFileTest.java @@ -39,18 +39,18 @@ protected void setUp() throws IOException { public void testReadInput() { - IDataObject ioObject = new GotmMeteoFile(); + IDataObject dataObject = new GotmMeteoFile(); String args[] = {"meteo_test.dat"}; - ioObject.initialize(testRunDataDir, args); + dataObject.initialize(testRunDataDir, args); // dump interpreted data to screen - // System.out.println(ioObject.toString()); + // System.out.println(dataObject.toString()); - String[] exchangeItemIds = ioObject.getExchangeItemIDs(); + String[] exchangeItemIds = dataObject.getExchangeItemIDs(); for(int item=0;item - + %inputFile% input - + - + %inputFileTurb% inputTurb - - + + %outputMeanTop% meanTempTop - - + + %outputMeanMid% meanTempMid - - + + %outputMeanBot% meanTempBot - + - + --> - + %outputFile% output true false - + diff --git a/model_gotm/tests/gotm_calibration_example/stochObserver/gotmStochObsConfig.xml b/model_gotm/tests/gotm_calibration_example/stochObserver/gotmStochObsConfig.xml index 7dc1c4c64..4af8c80a1 100644 --- a/model_gotm/tests/gotm_calibration_example/stochObserver/gotmStochObsConfig.xml +++ b/model_gotm/tests/gotm_calibration_example/stochObserver/gotmStochObsConfig.xml @@ -1,15 +1,15 @@ - + stochObsUncertainties.xml - + observ/meantemptop.txt - - + + observ/meantempmid.txt - - + + observ/meantempbot.txt - - + + diff --git a/model_gotm/tests/gotm_simple_kalman/stochModel/gotmWrapper.xml b/model_gotm/tests/gotm_simple_kalman/stochModel/gotmWrapper.xml index 1ba2f579e..a34c71433 100644 --- a/model_gotm/tests/gotm_simple_kalman/stochModel/gotmWrapper.xml +++ b/model_gotm/tests/gotm_simple_kalman/stochModel/gotmWrapper.xml @@ -83,82 +83,82 @@ - + %inputFile% input - + - + %inputFileTurb% inputTurb - + - + %inputFileMeteo% inputMeteo - + - + %outputTemp% outTemp - - + + %outputSalt% outSalt - - + + %outputEps% outEps - - + + %outputVelo% outVelo - - + + %outputMeanTop% meanTempTop - - + + %outputMeanMid% meanTempMid - - + + %outputMeanBot% meanTempBot - - + + %outputEps% noise - - + + - + - + --> - + %outputFile% output true false - + diff --git a/model_gotm/tests/gotm_simple_kalman/stochObserver/gotmStochObsConfig.xml b/model_gotm/tests/gotm_simple_kalman/stochObserver/gotmStochObsConfig.xml index 7dc1c4c64..4af8c80a1 100644 --- a/model_gotm/tests/gotm_simple_kalman/stochObserver/gotmStochObsConfig.xml +++ b/model_gotm/tests/gotm_simple_kalman/stochObserver/gotmStochObsConfig.xml @@ -1,15 +1,15 @@ - + stochObsUncertainties.xml - + observ/meantemptop.txt - - + + observ/meantempmid.txt - - + + observ/meantempbot.txt - - + + diff --git a/model_hspf/java/model_hspf.iml b/model_hspf/java/model_hspf.iml index 3b6b7b0c2..25d20d114 100644 --- a/model_hspf/java/model_hspf.iml +++ b/model_hspf/java/model_hspf.iml @@ -10,15 +10,6 @@ - - - - - - - - - @@ -28,5 +19,6 @@ + \ No newline at end of file diff --git a/model_hspf/java/src/org/openda/model_hspf/UciDataObject.java b/model_hspf/java/src/org/openda/model_hspf/UciDataObject.java index e5671c778..1759a3326 100644 --- a/model_hspf/java/src/org/openda/model_hspf/UciDataObject.java +++ b/model_hspf/java/src/org/openda/model_hspf/UciDataObject.java @@ -24,7 +24,6 @@ import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.Results; import org.openda.utils.io.AsciiFileUtils; @@ -125,8 +124,8 @@ public String[] getExchangeItemIDs() { return new String[]{startTimeExchangeItem.getId(), endTimeExchangeItem.getId()}; } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { - if (role == IPrevExchangeItem.Role.Input || role == IPrevExchangeItem.Role.InOut) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { + if (role == IExchangeItem.Role.Input || role == IExchangeItem.Role.InOut) { return new String[]{startTimeExchangeItem.getId(), endTimeExchangeItem.getId()}; } return null; diff --git a/model_hspf/java/src/org/openda/model_hspf/UciIoObject.java b/model_hspf/java/src/org/openda/model_hspf/UciIoObject.java index 7e083e7cc..75ea4119e 100644 --- a/model_hspf/java/src/org/openda/model_hspf/UciIoObject.java +++ b/model_hspf/java/src/org/openda/model_hspf/UciIoObject.java @@ -23,7 +23,7 @@ import org.openda.blackbox.interfaces.IoObjectInterface; import org.openda.exchange.DoubleExchangeItem; import org.openda.exchange.timeseries.TimeUtils; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.Results; import org.openda.utils.io.AsciiFileUtils; @@ -48,6 +48,8 @@ * * @author Arno Kockx */ +//@Deprecated +// Use UciDataObject instead public class UciIoObject implements IoObjectInterface { private static final String TAG = "$"; @@ -62,8 +64,8 @@ public class UciIoObject implements IoObjectInterface { */ private TimeZone timeZone = TimeZone.getTimeZone("GMT"); - private IPrevExchangeItem startTimeExchangeItem = null; - private IPrevExchangeItem endTimeExchangeItem = null; + private IExchangeItem startTimeExchangeItem = null; + private IExchangeItem endTimeExchangeItem = null; private File uciFile; private DateFormat dateFormat; /** @@ -130,8 +132,8 @@ public void initialize(File workingDir, String fileName, String[] arguments) { } - public IPrevExchangeItem[] getExchangeItems() { - return new IPrevExchangeItem[]{this.startTimeExchangeItem, this.endTimeExchangeItem}; + public IExchangeItem[] getExchangeItems() { + return new IExchangeItem[]{this.startTimeExchangeItem, this.endTimeExchangeItem}; } diff --git a/model_hspf/java/src/org/openda/model_hspf/UciStateDataObject.java b/model_hspf/java/src/org/openda/model_hspf/UciStateDataObject.java index 130e244d7..fbfc1c3f0 100644 --- a/model_hspf/java/src/org/openda/model_hspf/UciStateDataObject.java +++ b/model_hspf/java/src/org/openda/model_hspf/UciStateDataObject.java @@ -23,7 +23,6 @@ import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.Results; import org.openda.utils.Time; import org.openda.utils.io.AsciiFileUtils; @@ -132,7 +131,7 @@ public String[] getExchangeItemIDs() { return ids.toArray(new String[ids.size()]); } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { //all exchange items have role InOut, so always return all items. return getExchangeItemIDs(); } diff --git a/model_hspf/java/src/org/openda/model_hspf/UciUtils.java b/model_hspf/java/src/org/openda/model_hspf/UciUtils.java index 364d57822..72dff879a 100644 --- a/model_hspf/java/src/org/openda/model_hspf/UciUtils.java +++ b/model_hspf/java/src/org/openda/model_hspf/UciUtils.java @@ -22,7 +22,6 @@ import org.openda.exchange.DoubleExchangeItem; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.Time; import java.text.DateFormat; @@ -325,7 +324,7 @@ private static void createExchangeItems(String moduleName, String tableName, Str String parameterId = parameterIds.get(n); String id = locationId + "." + parameterId; - DoubleExchangeItem newItem = new DoubleExchangeItem(id, IPrevExchangeItem.Role.InOut, values.get(n)); + DoubleExchangeItem newItem = new DoubleExchangeItem(id, IExchangeItem.Role.InOut, values.get(n)); newItem.setTime(stateTime); IExchangeItem previous = exchangeItems.put(id, newItem); if (previous != null) throw new IllegalArgumentException("Multiple exchange items with id '" + id + "' found in uci state file."); diff --git a/model_hspf/java/src/org/openda/model_hspf/WdmEnsembleTimeSeriesOutputDataObject.java b/model_hspf/java/src/org/openda/model_hspf/WdmEnsembleTimeSeriesOutputDataObject.java index b2285b91a..0cbf65d89 100644 --- a/model_hspf/java/src/org/openda/model_hspf/WdmEnsembleTimeSeriesOutputDataObject.java +++ b/model_hspf/java/src/org/openda/model_hspf/WdmEnsembleTimeSeriesOutputDataObject.java @@ -23,8 +23,6 @@ import org.openda.interfaces.IDataObject; import org.openda.interfaces.IEnsembleDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; -import org.openda.interfaces.IPrevExchangeItem.Role; import org.openda.utils.Results; import java.io.File; @@ -73,8 +71,8 @@ public void initialize(File workingDir, String[] arguments) { if (arguments.length < 4) { throw new IllegalArgumentException(getClass().getSimpleName() + ": No role argument specified. The third argument should be the role of this DataObject. Role must be 'output'."); } - Role role = WdmUtils.initializeRole(arguments[3]); - if (role == IPrevExchangeItem.Role.Input) { + IExchangeItem.Role role = WdmUtils.initializeRole(arguments[3]); + if (role == IExchangeItem.Role.Input) { throw new UnsupportedOperationException(getClass().getSimpleName() + " not implemented for role input."); } @@ -116,7 +114,7 @@ public String[] getExchangeItemIDs() { return new String[0]; } - public String[] getExchangeItemIDs(Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { //ignore ensemble exchange items. return new String[0]; } diff --git a/model_hspf/java/src/org/openda/model_hspf/WdmTimeSeriesDataObject.java b/model_hspf/java/src/org/openda/model_hspf/WdmTimeSeriesDataObject.java index 5381b217a..ceefa7b8f 100644 --- a/model_hspf/java/src/org/openda/model_hspf/WdmTimeSeriesDataObject.java +++ b/model_hspf/java/src/org/openda/model_hspf/WdmTimeSeriesDataObject.java @@ -22,8 +22,7 @@ import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; import java.io.File; import java.util.ArrayList; @@ -92,27 +91,27 @@ public void initialize(File workingDir, String[] arguments) { public String[] getExchangeItemIDs() { List exchangeItemIds = new ArrayList<>(); - for (IPrevExchangeItem exchangeItem : wrappedIoObject.getExchangeItems()) { + for (IExchangeItem exchangeItem : wrappedIoObject.getExchangeItems()) { exchangeItemIds.add(exchangeItem.getId()); } - return exchangeItemIds.toArray(new String[exchangeItemIds.size()]); + return exchangeItemIds.toArray(new String[0]); } public String[] getExchangeItemIDs(Role role) { List exchangeItemIds = new ArrayList<>(); - for (IPrevExchangeItem exchangeItem : wrappedIoObject.getExchangeItems()) { + for (IExchangeItem exchangeItem : wrappedIoObject.getExchangeItems()) { if (exchangeItem.getRole().equals(role)) { exchangeItemIds.add(exchangeItem.getId()); } } - return exchangeItemIds.toArray(new String[exchangeItemIds.size()]); + return exchangeItemIds.toArray(new String[0]); } public IExchangeItem getDataObjectExchangeItem(String exchangeItemId) { - for (IPrevExchangeItem exchangeItem : wrappedIoObject.getExchangeItems()) { + for (IExchangeItem exchangeItem : wrappedIoObject.getExchangeItems()) { //a WdmTimeSeriesIoObject returns WdmTimeSeriesExchangeItems that implement TimeSeries which implements both IPrevExchangeItem and IExchangeItem, //so here can cast IPrevExchangeItem to IExchangeItem. - if (exchangeItem.getId().equals(exchangeItemId)) return (IExchangeItem) exchangeItem; + if (exchangeItem.getId().equals(exchangeItemId)) return exchangeItem; } //if not found. diff --git a/model_hspf/java/src/org/openda/model_hspf/WdmTimeSeriesIoObject.java b/model_hspf/java/src/org/openda/model_hspf/WdmTimeSeriesIoObject.java index 97cf12f9f..17bec6198 100644 --- a/model_hspf/java/src/org/openda/model_hspf/WdmTimeSeriesIoObject.java +++ b/model_hspf/java/src/org/openda/model_hspf/WdmTimeSeriesIoObject.java @@ -27,8 +27,8 @@ import org.openda.blackbox.interfaces.IoObjectInterface; import org.openda.exchange.DoubleExchangeItem; import org.openda.exchange.timeseries.TimeUtils; -import org.openda.interfaces.IPrevExchangeItem; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem; +import org.openda.interfaces.IExchangeItem.Role; import org.openda.utils.Results; /** @@ -85,8 +85,8 @@ public class WdmTimeSeriesIoObject implements IoObjectInterface { private WdmDll wdmDll; private Role role; - private IPrevExchangeItem startTimeExchangeItem = null; - private IPrevExchangeItem endTimeExchangeItem = null; + private IExchangeItem startTimeExchangeItem = null; + private IExchangeItem endTimeExchangeItem = null; private double startTimeDouble = Double.NaN; private double endTimeDouble = Double.NaN; private List wdmTimeSeriesExchangeItems = new ArrayList(); @@ -152,7 +152,7 @@ public void initialize(File workingDir, String fileName, String[] arguments) { //Note: the timeInfoExchangeItems are also set after the input ioObjects have already been initialized, //but the timeInfoExchangeItems need only be created during ioObject initialization and can then be //used later, after they have been set. - if (this.role == IPrevExchangeItem.Role.Input) { + if (this.role == Role.Input) { //create exchange items. if (arguments.length < 6) { throw new IllegalArgumentException("No start/endTime exchange item ids arguments specified for " + getClass().getSimpleName() @@ -162,7 +162,7 @@ public void initialize(File workingDir, String fileName, String[] arguments) { this.startTimeExchangeItem = new DoubleExchangeItem(arguments[4], 0); this.endTimeExchangeItem = new DoubleExchangeItem(arguments[5], 0); - } else {//if this.role == IPrevExchangeItem.Role.Output. + } else { if (arguments.length < 6) { throw new IllegalArgumentException("No start/endTime arguments specified for " + getClass().getSimpleName() + ". For role OUTPUT the fifth and sixth arguments should be respectively the startTime and endTime of the model run."); @@ -222,14 +222,14 @@ private void createWdmTimeSeriesExchangeItemsFromFile() { if (this.wdmTimeSeriesExchangeItems.isEmpty()) throw new IllegalArgumentException(this.getClass().getSimpleName() + ": No time series found in time series file '" + this.wdmTimeSeriesFilePath + "'."); } - public IPrevExchangeItem[] getExchangeItems() { + public IExchangeItem[] getExchangeItems() { //return all available exchange items. - List exchangeItems = new ArrayList(this.wdmTimeSeriesExchangeItems); + List exchangeItems = new ArrayList(this.wdmTimeSeriesExchangeItems); if (this.startTimeExchangeItem != null && this.endTimeExchangeItem != null) { exchangeItems.add(this.startTimeExchangeItem); exchangeItems.add(this.endTimeExchangeItem); } - return exchangeItems.toArray(new IPrevExchangeItem[exchangeItems.size()]); + return exchangeItems.toArray(new IExchangeItem[exchangeItems.size()]); } /** @@ -240,7 +240,7 @@ public IPrevExchangeItem[] getExchangeItems() { * Updates the in-memory stored values and times by reading from the wdm file. */ private void readValuesAndTimesFromFile() { - if (this.role == IPrevExchangeItem.Role.Input) { + if (this.role == Role.Input) { return; } @@ -269,7 +269,7 @@ private void readValuesAndTimesFromFile() { * so that it can be used as input by the model. */ public void finish() { - if (this.role == IPrevExchangeItem.Role.Output) { + if (this.role == Role.Output) { return; } diff --git a/model_hspf/java/src/org/openda/model_hspf/WdmUtils.java b/model_hspf/java/src/org/openda/model_hspf/WdmUtils.java index 3afb5f3bf..c51adb404 100644 --- a/model_hspf/java/src/org/openda/model_hspf/WdmUtils.java +++ b/model_hspf/java/src/org/openda/model_hspf/WdmUtils.java @@ -23,7 +23,7 @@ import java.io.File; import java.util.*; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.Results; import org.openda.utils.Time; @@ -125,9 +125,9 @@ public static String initializeWdmMessageFilePath(File workingDir, String relati return wdmMessageFile.getAbsolutePath(); } - public static IPrevExchangeItem.Role initializeRole(String roleString) { - if ("input".equalsIgnoreCase(roleString)) return IPrevExchangeItem.Role.Input; - if ("output".equalsIgnoreCase(roleString)) return IPrevExchangeItem.Role.Output; + public static IExchangeItem.Role initializeRole(String roleString) { + if ("input".equalsIgnoreCase(roleString)) return IExchangeItem.Role.Input; + if ("output".equalsIgnoreCase(roleString)) return IExchangeItem.Role.Output; throw new IllegalArgumentException(WdmUtils.class.getSimpleName() + ": unknown role type '" + roleString + "' specified."); } @@ -510,7 +510,7 @@ public static void deleteTimesAndValues(WdmDll wdmDll, int wdmFileNumber) { /** * Creates an exchange item with the given role for each dataSet in the wdm file with the given unit number. */ - public static List createExchangeItemsFromFile(WdmDll wdmDll, int wdmFileNumber, IPrevExchangeItem.Role role) { + public static List createExchangeItemsFromFile(WdmDll wdmDll, int wdmFileNumber, IExchangeItem.Role role) { List exchangeItems = new ArrayList(); //get first existing dataSet and put its number in the variable dataSetNumber. @@ -543,7 +543,7 @@ public static List createExchangeItemsFromFile(WdmDll * Creates an exchange item with the given role for each dataSet in the wdm file that is also in the given timeSeriesIdList. */ public static List createExchangeItemsFromList(WdmDll wdmDll, int wdmFileNumber, String wdmFilePath, - IPrevExchangeItem.Role role, String[] timeSeriesIdList) { + IExchangeItem.Role role, String[] timeSeriesIdList) { if (timeSeriesIdList == null || timeSeriesIdList.length == 0) throw new IllegalArgumentException("timeSeriesIdList == null || timeSeriesIdList.length == 0"); Set timeSeriesIdSet = new HashSet(Arrays.asList(timeSeriesIdList)); diff --git a/model_hspf/java/test/org/openda/model_hspf/UciFileTest.java b/model_hspf/java/test/org/openda/model_hspf/UciFileTest.java index 068bc8ac2..d61eb0cd5 100644 --- a/model_hspf/java/test/org/openda/model_hspf/UciFileTest.java +++ b/model_hspf/java/test/org/openda/model_hspf/UciFileTest.java @@ -24,7 +24,6 @@ import org.openda.blackbox.config.BBUtils; import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.OpenDaTestSupport; import org.openda.utils.Time; import org.openda.utils.io.AsciiFileUtils; @@ -65,11 +64,11 @@ public void testWriteUciFile() { uciIoObject.initialize(testRunDataDir, uciFilename, arguments); //Get all exchangeItems items - IPrevExchangeItem[] exchangeItems = uciIoObject.getExchangeItems(); + IExchangeItem[] exchangeItems = uciIoObject.getExchangeItems(); assertEquals(2, exchangeItems.length); //Loop over all exchangeItems items and request the ID, name and value - for (IPrevExchangeItem exchangeItem : exchangeItems) { + for (IExchangeItem exchangeItem : exchangeItems) { String id = exchangeItem.getId(); if ("TSTART".equals(id)) { exchangeItem.setValues(startDate); @@ -105,11 +104,11 @@ public void testWriteUciFileWithExtendedPeriod() { uciIoObject.initialize(testRunDataDir, uciFilename, arguments); //Get all exchangeItems items - IPrevExchangeItem[] exchangeItems = uciIoObject.getExchangeItems(); + IExchangeItem[] exchangeItems = uciIoObject.getExchangeItems(); assertEquals(2, exchangeItems.length); //Loop over all exchangeItems items and request the ID, name and value - for (IPrevExchangeItem exchangeItem : exchangeItems) { + for (IExchangeItem exchangeItem : exchangeItems) { String id = exchangeItem.getId(); if ("TSTART".equals(id)) { exchangeItem.setValues(startDate); diff --git a/model_hspf/java/test/org/openda/model_hspf/WdmTimeSeriesTest.java b/model_hspf/java/test/org/openda/model_hspf/WdmTimeSeriesTest.java index 5d846c49d..117074139 100644 --- a/model_hspf/java/test/org/openda/model_hspf/WdmTimeSeriesTest.java +++ b/model_hspf/java/test/org/openda/model_hspf/WdmTimeSeriesTest.java @@ -31,7 +31,6 @@ import org.openda.exchange.iotools.DataCopier; import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.OpenDaTestSupport; import org.openda.utils.Time; import org.openda.utils.io.AsciiFileUtils; @@ -89,7 +88,7 @@ public void testReadTimeSeries() throws Exception { wdmTimeSeriesIoObject.initialize(testRunDataDir, inputFileName, arguments); //get all exchangeItems. - IPrevExchangeItem[] exchangeItems = wdmTimeSeriesIoObject.getExchangeItems(); + IExchangeItem[] exchangeItems = wdmTimeSeriesIoObject.getExchangeItems(); assertEquals(2, exchangeItems.length); //check id for RCH103.FLOW @@ -293,7 +292,7 @@ public void testWriteTimeSeries() throws Exception { wdmTimeSeriesIoObject1.initialize(testRunDataDir, relativeOutputFilePath, arguments1); //get all exchangeItems. - IPrevExchangeItem[] exchangeItems1 = wdmTimeSeriesIoObject1.getExchangeItems(); + IExchangeItem[] exchangeItems1 = wdmTimeSeriesIoObject1.getExchangeItems(); assertEquals(4, exchangeItems1.length); //set times and values. @@ -318,7 +317,7 @@ public void testWriteTimeSeries() throws Exception { expectedValues[7] = 5; expectedValues[8] = 15000; expectedValues[9] = 1; - for (IPrevExchangeItem exchangeItem1 : exchangeItems1) { + for (IExchangeItem exchangeItem1 : exchangeItems1) { if ("TSTART1".equalsIgnoreCase(exchangeItem1.getId())) { exchangeItem1.setValues(expectedTimes[0]); @@ -354,13 +353,13 @@ public void testWriteTimeSeries() throws Exception { wdmTimeSeriesIoObject2.initialize(testRunDataDir, relativeOutputFilePath, arguments2); //get all exchangeItems. - IPrevExchangeItem[] exchangeItems2 = wdmTimeSeriesIoObject2.getExchangeItems(); + IExchangeItem[] exchangeItems2 = wdmTimeSeriesIoObject2.getExchangeItems(); assertEquals(2, exchangeItems2.length); //get exchangeItem for RCH103.FLOW String timeSeriesId = "RCH103.FLOW"; - IPrevExchangeItem currentExchangeItem = null; - for (IPrevExchangeItem exchangeItem : exchangeItems2) { + IExchangeItem currentExchangeItem = null; + for (IExchangeItem exchangeItem : exchangeItems2) { if (timeSeriesId.equalsIgnoreCase(exchangeItem.getId())) { currentExchangeItem = exchangeItem; break; diff --git a/model_hspf/java/test/org/openda/model_hspf/WdmUtilsTest.java b/model_hspf/java/test/org/openda/model_hspf/WdmUtilsTest.java index d3f658d72..a50d21d3e 100644 --- a/model_hspf/java/test/org/openda/model_hspf/WdmUtilsTest.java +++ b/model_hspf/java/test/org/openda/model_hspf/WdmUtilsTest.java @@ -27,7 +27,7 @@ import junit.framework.TestCase; import org.openda.blackbox.config.BBUtils; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.OpenDaTestSupport; import org.openda.utils.io.AsciiFileUtils; @@ -179,14 +179,14 @@ public void testCreateExchangeItemsFromFile() throws Exception { File wdmMessageFile = new File(testRunDataDir, relativeWdmMessageFilePath); WdmUtils.openWdmFile(wdmDll, wdmFileNumber, inputFile.getAbsolutePath(), wdmMessageFile.getAbsolutePath()); - List exchangeItems = WdmUtils.createExchangeItemsFromFile(wdmDll, wdmFileNumber, IPrevExchangeItem.Role.Input); + List exchangeItems = WdmUtils.createExchangeItemsFromFile(wdmDll, wdmFileNumber, IExchangeItem.Role.Input); //close wdm file. WdmUtils.closeWdmFile(wdmDll, wdmFileNumber); assertEquals(923, exchangeItems.size()); WdmTimeSeriesExchangeItem exchangeItem = exchangeItems.get(42); - assertEquals(IPrevExchangeItem.Role.Input, exchangeItem.getRole()); + assertEquals(IExchangeItem.Role.Input, exchangeItem.getRole()); assertEquals("48A0341.FLOW", exchangeItem.getId()); assertEquals("48A0341", exchangeItem.getLocation()); assertEquals("FLOW", exchangeItem.getQuantityId()); @@ -221,19 +221,19 @@ public void testCreateExchangeItemsFromList() throws Exception { WdmUtils.openWdmFile(wdmDll, wdmFileNumber, inputFile.getAbsolutePath(), wdmMessageFile.getAbsolutePath()); String[] timeSeriesIdList = new String[]{"48A0341.FLOW", "47A0211.ORP"}; - List exchangeItems = WdmUtils.createExchangeItemsFromList(wdmDll, wdmFileNumber, inputFile.getAbsolutePath(), IPrevExchangeItem.Role.Input, timeSeriesIdList); + List exchangeItems = WdmUtils.createExchangeItemsFromList(wdmDll, wdmFileNumber, inputFile.getAbsolutePath(), IExchangeItem.Role.Input, timeSeriesIdList); //close wdm file. WdmUtils.closeWdmFile(wdmDll, wdmFileNumber); assertEquals(2, exchangeItems.size()); WdmTimeSeriesExchangeItem exchangeItem1 = exchangeItems.get(0); - assertEquals(IPrevExchangeItem.Role.Input, exchangeItem1.getRole()); + assertEquals(IExchangeItem.Role.Input, exchangeItem1.getRole()); assertEquals("48A0341.FLOW", exchangeItem1.getId()); assertEquals("48A0341", exchangeItem1.getLocation()); assertEquals("FLOW", exchangeItem1.getQuantityId()); WdmTimeSeriesExchangeItem exchangeItem2 = exchangeItems.get(1); - assertEquals(IPrevExchangeItem.Role.Input, exchangeItem2.getRole()); + assertEquals(IExchangeItem.Role.Input, exchangeItem2.getRole()); assertEquals("47A0211.ORP", exchangeItem2.getId()); assertEquals("47A0211", exchangeItem2.getLocation()); assertEquals("ORP", exchangeItem2.getQuantityId()); diff --git a/model_metaswap/java/model_metaswap.iml b/model_metaswap/java/model_metaswap.iml index 4db80cbcf..e90c34286 100644 --- a/model_metaswap/java/model_metaswap.iml +++ b/model_metaswap/java/model_metaswap.iml @@ -12,14 +12,5 @@ - - - - - - - - - \ No newline at end of file diff --git a/model_metaswap/java/src/org/openda/model_metaswap/EsriAsciiGridSeriesDataObject.java b/model_metaswap/java/src/org/openda/model_metaswap/EsriAsciiGridSeriesDataObject.java index d8231ecb5..a8997e898 100644 --- a/model_metaswap/java/src/org/openda/model_metaswap/EsriAsciiGridSeriesDataObject.java +++ b/model_metaswap/java/src/org/openda/model_metaswap/EsriAsciiGridSeriesDataObject.java @@ -123,7 +123,7 @@ public void initialize(File workingDir, String[] arguments) { } System.arraycopy(exchangeItemValues, 0 , allValues, i*exchangeItemValues.length, exchangeItemValues.length); } - exchangeItem = new ArrayExchangeItem(exchangeItemId, IPrevExchangeItem.Role.InOut); + exchangeItem = new ArrayExchangeItem(exchangeItemId, IExchangeItem.Role.InOut); exchangeItem.setGeometryInfo(geometryInfo); IArray array = new Array(allValues, new int[]{ filesCount, geometryInfo.getLongitudeArray().length(), geometryInfo.getLatitudeArray().length()}, @@ -137,7 +137,7 @@ public String[] getExchangeItemIDs() { } - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { return getExchangeItemIDs(); } diff --git a/model_metaswap/java/src/org/openda/model_metaswap/SwapResultExchangeItem.java b/model_metaswap/java/src/org/openda/model_metaswap/SwapResultExchangeItem.java index d1384ad67..e856494c6 100644 --- a/model_metaswap/java/src/org/openda/model_metaswap/SwapResultExchangeItem.java +++ b/model_metaswap/java/src/org/openda/model_metaswap/SwapResultExchangeItem.java @@ -105,8 +105,4 @@ public Object getValues() { return null; } - @Override - public Class getValueType() { - return null; - } -} \ No newline at end of file +} diff --git a/model_metaswap/java/src/org/openda/model_metaswap/SwapResultFile.java b/model_metaswap/java/src/org/openda/model_metaswap/SwapResultFile.java index 78ab6fb7e..09568d999 100644 --- a/model_metaswap/java/src/org/openda/model_metaswap/SwapResultFile.java +++ b/model_metaswap/java/src/org/openda/model_metaswap/SwapResultFile.java @@ -3,7 +3,6 @@ import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.io.CsvReader; import java.io.File; @@ -23,7 +22,7 @@ public String[] getExchangeItemIDs() { } @Override - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { return getExchangeItemIDs(); } diff --git a/model_metaswap/java/src/org/openda/model_metaswap/SwapStateExchangeItem.java b/model_metaswap/java/src/org/openda/model_metaswap/SwapStateExchangeItem.java index 16ec65cc3..a8375c0e3 100644 --- a/model_metaswap/java/src/org/openda/model_metaswap/SwapStateExchangeItem.java +++ b/model_metaswap/java/src/org/openda/model_metaswap/SwapStateExchangeItem.java @@ -15,10 +15,11 @@ public SwapStateExchangeItem(String id, double[] values) { } @Override - public IPrevExchangeItem.Role getRole() { + public IExchangeItem.Role getRole() { return null; } + @Override public double[] getValuesAsDoubles() { if (values == null) return null; @@ -103,8 +104,4 @@ public Object getValues() { return null; } - @Override - public Class getValueType() { - return null; - } } diff --git a/model_metaswap/java/src/org/openda/model_metaswap/SwapStateFile.java b/model_metaswap/java/src/org/openda/model_metaswap/SwapStateFile.java index cf46268ee..11994d8c2 100644 --- a/model_metaswap/java/src/org/openda/model_metaswap/SwapStateFile.java +++ b/model_metaswap/java/src/org/openda/model_metaswap/SwapStateFile.java @@ -2,7 +2,6 @@ import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import java.io.*; import java.text.DecimalFormat; @@ -11,7 +10,7 @@ import java.util.LinkedHashMap; import java.util.List; -public class SwapStateFile implements IDataObject { +public class SwapStateFile implements IDataObject{ static final String PRESSURE_HEAD_ROOT_ZONE = "pressureHeadRootZone"; private LinkedHashMap exchangeItems = new LinkedHashMap<>(); private int headerBytesLength = 0; @@ -34,7 +33,7 @@ public String[] getExchangeItemIDs() { } @Override - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { return getExchangeItemIDs(); } @@ -67,6 +66,7 @@ private void editFile(byte[][] bytesArray) { private byte[][] convertDoublesToStringBytes(SwapStateExchangeItem swapStateExchangeItem) { double[] doubles = swapStateExchangeItem.getValuesAsDoubles(); + logStateValues("AFTER ", doubles); byte[][] bytesArray = new byte[doubles.length][]; for (int i = 0; i < doubles.length; i++) { String replace = formatDouble.format(doubles[i]); @@ -90,7 +90,7 @@ public void initialize(File workingDir, String[] arguments) { } int size = strings.size(); double[] doubles = convertStringsToDoubles(strings, size); - + logStateValues("BEFORE", doubles); SwapStateExchangeItem pressureHeadRootZone = new SwapStateExchangeItem(PRESSURE_HEAD_ROOT_ZONE, doubles); exchangeItems.put(PRESSURE_HEAD_ROOT_ZONE, pressureHeadRootZone); } @@ -121,5 +121,48 @@ private ArrayList getStringsFrom16thColumn() { } return strings; } + private void logStateValues(String beforeOrAfter, double[] stateValues) { + + File svatIdsfile = new File (sourceFile.getParentFile(), "svatids.txt"); + if (!svatIdsfile.exists()) + return; + + ArrayList svatIds = new ArrayList<>(); + try { + FileReader fileReader = new FileReader(svatIdsfile); + BufferedReader inputFileBufferedReader = new BufferedReader(fileReader); + String line = inputFileBufferedReader.readLine(); + while (line != null) { + String trimmedLine = line.trim(); + if (trimmedLine.length() > 0) { + if (!trimmedLine.startsWith("#")) { + svatIds.add(Integer.parseInt(trimmedLine)); + } + } + line = inputFileBufferedReader.readLine(); + } + inputFileBufferedReader.close(); + fileReader.close(); + } catch (IOException e) { + throw new RuntimeException("Could not svids read from " + svatIdsfile.getAbsolutePath()); + } + File file = new File(sourceFile.getParentFile(), "statevalues.log"); + Writer writer; + try { + writer = new FileWriter(file, true); + writer.write(beforeOrAfter); + for (int i = 0; i < svatIds.size(); i++) { + writer.write(","); + int id = svatIds.get(i); + String valueAsString = formatDouble.format(stateValues[id - 1]); + if (valueAsString.length() < 14) valueAsString += ' '; + writer.write(valueAsString); + } + writer.write("\n"); + writer.close(); + } catch (IOException e) { + throw new RuntimeException("Could not close log file " + file.getAbsolutePath()); + } + } } diff --git a/model_metaswap/java/test/org/openda/model_metaswap/SwapStateFileTest.java b/model_metaswap/java/test/org/openda/model_metaswap/SwapStateFileTest.java index 35d5d1a48..3abb26828 100644 --- a/model_metaswap/java/test/org/openda/model_metaswap/SwapStateFileTest.java +++ b/model_metaswap/java/test/org/openda/model_metaswap/SwapStateFileTest.java @@ -6,6 +6,9 @@ import org.openda.utils.io.AsciiFileUtils; import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; import static org.openda.model_metaswap.SwapStateFile.PRESSURE_HEAD_ROOT_ZONE; @@ -19,6 +22,39 @@ protected void setUp() { } public void testEdit() { + runFileAdjustmentTest(); + } + + public void testLogging() { + File svatIdsFile = new File(testRunDataDir, "svatids.txt"); + try { + Writer writer = new FileWriter(svatIdsFile); + writer.write("# svat id's to be logged\n"); + writer.write("2\n"); + writer.write("5\n"); + writer.write("# last one\n"); + writer.write("7\n"); + writer.close(); + } catch (IOException e) { + throw new RuntimeException("Could not write file with svatids"); + } + runFileAdjustmentTest(); + + File logFile = new File(testRunDataDir, "statevalues.log"); + assertTrue(logFile.exists()); + String text = AsciiFileUtils.readText(logFile); + + File expectedFile = new File(testRunDataDir, "statevalues_expected.log"); + String expectedText = AsciiFileUtils.readText(expectedFile); + + assertEquals(expectedText, text); + + if (!svatIdsFile.delete()) { + throw new RuntimeException("Could not delete file with svatids"); + } + } + + private void runFileAdjustmentTest() { SwapStateFile swapStateFile = new SwapStateFile(); String sourceFileName = "init_svat.inp"; swapStateFile.initialize(testRunDataDir, new String[]{sourceFileName}); @@ -29,12 +65,12 @@ public void testEdit() { assertNotNull(exchangeItem); double[] valuesAsDoubles = exchangeItem.getValuesAsDoubles(); assertNotNull(valuesAsDoubles); - assertEquals(14, valuesAsDoubles.length); - double[] multiplicationFactors = new double[valuesAsDoubles.length]; - for (int i = 0; i < multiplicationFactors.length; i++) { - multiplicationFactors[i] = 1 + 1.0 / (i + 1); + assertEquals(9, valuesAsDoubles.length); + double[] additions = new double[valuesAsDoubles.length]; + for (int i = 0; i < additions.length; i++) { + additions[i] = 1001; } - exchangeItem.multiplyValues(multiplicationFactors); + exchangeItem.axpyOnValues(1, additions); swapStateFile.finish(); File sourceFile = new File(testRunDataDir, sourceFileName); diff --git a/model_metaswap/java/test/org/openda/model_metaswap/testData/init_svat.inp b/model_metaswap/java/test/org/openda/model_metaswap/testData/init_svat.inp index 7f3f78288..8ee6e50a0 100644 --- a/model_metaswap/java/test/org/openda/model_metaswap/testData/init_svat.inp +++ b/model_metaswap/java/test/org/openda/model_metaswap/testData/init_svat.inp @@ -1,15 +1,10 @@ -Saved_State, tdac= 0.0000000, version=V7.3.1 , unsacode=0.4618015 - 207106 19.50602 8 0.8397783 0.1150785E-02 0.1150785E-02 0.000000 T 0.000000 730.9990 0.000000 0.5000000E-01 0.5000000E-01 0.000000 0.000000 -0.8603770 -0.8603770 -0.8459430 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.000000 0.7587735E-02 0.2770546E-01 0.5076489E-01 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.7587735E-02 0.2770546E-01 0.5076489E-01 0.1332984E-03 -0.5933025E-04 -0.1623941E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.9885151E-04 19.50602 -0.3931762E-02 0.9750066E-04 0.000000 - 207107 19.33045 13 0.2954777 0.000000 0.000000 0.9991611 T 0.000000 730.9990 0.000000 0.3000000 0.3000000 0.3000000 0.3000000 -0.8357596 -0.8357596 -0.8028657 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.000000 0.2322074E-01 0.4646318E-01 0.5039223E-01 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.2322074E-01 0.4646318E-01 0.5039223E-01 0.1332984E-03 -0.3585286E-03 -0.4193589E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4439334E-03 19.33045 -0.3699563E-02 0.000000 0.1217736E-03 - 207108 19.18302 10 0.7698057 0.2718639E-03 0.2718639E-03 0.9999999 T 0.000000 720.9990 0.000000 0.2000000 0.2000000 0.2230000 0.2230000 -0.9232715 -0.5131373 -0.6995649 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.1382279E-04 0.000000 0.1666558E-01 0.3369270E-01 0.3211979E-01 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.1666558E-01 0.3369270E-01 0.3211979E-01 0.3172502E-04 0.000000 -0.5840921E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 0.9761060E-03 19.18302 -0.7413799E-02 0.2320515E-04 0.000000 - 207109 19.52993 11 0.9006545 0.1150785E-02 0.1150785E-02 0.000000 T 0.000000 723.9990 0.000000 0.5000000E-01 0.5000000E-01 0.000000 0.000000 -0.9609551 -0.7654589 -0.6904747 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.000000 0.4348781E-02 0.3196095E-01 0.6249241E-01 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.4348781E-02 0.3196095E-01 0.6249241E-01 0.1332984E-03 0.000000 -0.5069391E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 0.2171163E-03 19.52993 0.000000 0.9750066E-04 0.000000 - 207110 19.54663 25 0.7084233 0.1147513E-02 0.1147513E-02 0.000000 T 0.000000 723.9990 0.000000 0.5000000E-01 0.5000000E-01 0.000000 0.000000 -1.255370 -1.153041 -4.241650 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.000000 0.7033203E-02 0.4018101E-01 0.4393426 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.7033203E-02 0.4018101E-01 0.4393426 0.1335393E-03 0.000000 -0.7530567E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.8557374E-03 19.54663 -0.7180587E-03 0.9769585E-04 0.000000 - 207111 19.68418 19 0.2581946 0.2710888E-03 0.2710888E-03 0.9999999 T 0.000000 720.9990 0.000000 0.2000000 0.2000000 0.2230000 0.2230000 -1.511203 -0.8899747 -1.184848 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.1383069E-04 0.000000 0.3087497E-01 0.4808572E-01 0.1537189 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.3087497E-01 0.4808572E-01 0.1537189 0.3178235E-04 0.000000 -0.7302721E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1721197E-03 19.68418 -0.7138399E-02 0.2325161E-04 0.000000 - 207112 19.84553 7 0.9446620 0.2710888E-03 0.2710888E-03 0.9999999 T 0.000000 720.9990 0.000000 0.2000000 0.2000000 0.2230000 0.2230000 -0.6895193 -0.6171628 -0.6606391 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.1383069E-04 0.000000 0.1985624E-01 0.2805428E-01 0.8312432E-02 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.1985624E-01 0.2805428E-01 0.8312432E-02 0.3178235E-04 0.000000 -0.4057659E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6122190E-03 19.84553 -0.6934337E-02 0.2325161E-04 0.000000 - 207113 19.78426 3 0.9574056 0.2710888E-03 0.2710888E-03 0.9999999 T 0.000000 720.9990 0.000000 0.2000000 0.2000000 0.2230000 0.2230000 -0.2879411 -0.2183181 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.1383069E-04 0.000000 0.1508240E-01 0.8491351E-02 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.1508240E-01 0.8491351E-02 0.000000 0.3178235E-04 0.000000 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 0.2887748E-03 19.78426 0.000000 0.2325161E-04 0.000000 - 207114 19.85884 5 0.2115626 0.2950235E-03 0.2950235E-03 0.9999999 T 0.000000 720.9990 0.000000 0.2000000 0.2000000 0.2230000 0.2230000 -0.4099635 -0.3495639 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.5972692E-04 0.000000 0.1439268E-01 0.1207967E-01 0.1305752E-03 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.1439268E-01 0.1207967E-01 0.1305752E-03 0.4617314E-04 0.000000 -0.8196374E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.6339937E-03 19.85884 -0.4532152E-02 0.2329881E-04 0.000000 - 207115 19.53634 4 0.4366263 0.2950235E-03 0.2950235E-03 0.9999999 T 0.000000 720.9990 0.000000 0.2000000 0.2000000 0.2230000 0.2230000 -0.3361574 -0.2377030 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.5972692E-04 0.000000 0.1685615E-01 0.1065987E-01 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.1685615E-01 0.1065987E-01 0.000000 0.4617314E-04 0.000000 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 0.3068389E-02 19.53634 0.000000 0.2329881E-04 0.000000 - 207116 19.62134 5 0.4866402 0.2950235E-03 0.2950235E-03 0.9999999 T 0.000000 720.9990 0.000000 0.2000000 0.2000000 0.2230000 0.2230000 -0.4417331 -0.3736331 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.5972692E-04 0.000000 0.2022729E-01 0.1669393E-01 0.3210638E-03 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.2022729E-01 0.1669393E-01 0.3210638E-03 0.4617314E-04 0.000000 -0.6474967E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 0.3684591E-02 19.62134 -0.4793910E-03 0.2329881E-04 0.000000 - 207117 20.12403 5 0.6597515 0.1248412E-02 0.1248412E-02 0.000000 T 0.000000 723.9990 0.000000 0.5000000E-01 0.5000000E-01 0.000000 0.000000 -0.5298444 -0.5298444 -0.5295858 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.000000 0.5695430E-02 0.1922567E-01 0.1553429E-01 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.5695430E-02 0.1922567E-01 0.1553429E-01 0.1940048E-03 -0.7369649E-04 -0.2985327E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 0.8753677E-03 20.12403 -0.9168052E-03 0.9789417E-04 0.000000 - 207118 20.52016 4 0.4983848 0.2808624E-03 0.2808624E-03 0.9999999 T 0.000000 720.9990 0.000000 0.2000000 0.2000000 0.2230000 0.2230000 -0.3372103 -0.2524879 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.8018519E-04 0.000000 0.1055392E-01 0.6614680E-02 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.1055392E-01 0.6614680E-02 0.000000 0.5261960E-04 0.000000 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.1908906E-03 20.52016 -0.4338291E-02 0.2334674E-04 0.000000 - 207119 20.68848 5 0.3152092 0.2808624E-03 0.2808624E-03 0.9999999 T 0.000000 720.9990 0.000000 0.2000000 0.2000000 0.2230000 0.2230000 -0.4208303 -0.3493218 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.8018519E-04 0.000000 0.1162122E-01 0.1117104E-01 0.1935558E-03 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.1162122E-01 0.1117104E-01 0.1935558E-03 0.5261960E-04 0.000000 -0.5693454E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 0.1487734E-02 20.68848 -0.5248159E-02 0.2334674E-04 0.000000 +Saved_State, tdac= 310.0000000, version=V7.3.3.2 , unsacode=0.4618015 + 1 -0.8235401 16 0.7354024 0.000000 0.000000 0.8839978 F 0.000000 309.9990 0.000000 0.2000000 0.2000000 0.2000000 0.2000000 -85.03055 -157.5665 -158.3454 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.2000000E-02 0.6423438E-01 0.1103365 0.7629367E-01 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.6423438E-01 0.1103365 0.7629367E-01 0.2000000E-02 0.6702658E-03 0.8776899E-03 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 -0.8235402 -0.3751701E-02 0.000000 0.4026632E-03 + 2 -0.5915389 16 0.5153887 0.000000 0.000000 0.8816882 F 0.000000 309.9990 0.000000 0.2000000 0.2000000 0.2000000 0.2000000 -84.51031 -157.4035 -112.1327 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.2000000E-02 0.7450714E-01 0.8718438E-01 0.1057264 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.7450714E-01 0.8718438E-01 0.1057264 0.2000000E-02 0.6358884E-03 0.6448366E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 -0.5915389 0.000000 0.000000 0.4016112E-03 + 3 -0.5533270 18 0.3326957E-01 0.000000 0.000000 0.8799960 F 0.000000 309.9990 0.000000 0.2000000 0.2000000 0.2000000 0.2000000 -84.56480 -157.6756 -13.02668 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.2000000E-02 0.7495250E-01 0.9136210E-01 0.1285640 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.7495250E-01 0.9136210E-01 0.1285640 0.2000000E-02 0.4917238E-03 0.5091060E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 -0.5533268 0.000000 0.000000 0.4009226E-03 + 4 -0.5369097 18 0.3690963 0.000000 0.000000 0.8796993 F 0.000000 309.9990 0.000000 0.2000000 0.2000000 0.2000000 0.2000000 -84.66550 -157.7240 -9.003483 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.2000000E-02 0.7502381E-01 0.9213376E-01 0.1337943 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.7502381E-01 0.9213376E-01 0.1337943 0.2000000E-02 0.4681373E-03 0.4941994E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 -0.5369096 0.000000 0.000000 0.4007874E-03 + 5 -0.5155597 18 0.5559703E-01 0.000000 0.000000 0.8799743 F 0.000000 309.9990 0.000000 0.2000000 0.2000000 0.2000000 0.2000000 -84.57245 -157.6790 -11.01412 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.2000000E-02 0.7495732E-01 0.9141341E-01 0.1288201 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.7495732E-01 0.9141341E-01 0.1288201 0.2000000E-02 0.4903299E-03 0.5119590E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 -0.5155597 0.000000 0.000000 0.4009127E-03 + 6 -0.3850709 14 0.5507103 0.000000 0.000000 0.9999999 F 0.000000 299.9990 0.000000 0.2000000 0.2000000 0.2000000 0.2000000 -1.332792 -1.541619 -1.563627 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.1400000E-03 0.2000000E-02 0.3269792E-01 0.5978274E-01 0.4826918E-01 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.3269792E-01 0.5978274E-01 0.4826918E-01 0.2000000E-02 -0.2474061E-03 0.3585012E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.3850709 -0.8886825E-02 0.000000 0.000000 + 7 -1.089436 21 0.3971787 0.000000 0.000000 0.8731077 F 0.000000 309.9990 0.000000 0.2000000 0.2000000 0.2000000 0.2000000 -94.48472 -158.2114 -158.4839 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.2000000E-02 0.6514014E-01 0.1344540 0.1870877 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.6514014E-01 0.1344540 0.1870877 0.2000000E-02 0.3791025E-03 0.5034527E-03 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 -1.089436 -0.1161498E-02 0.000000 0.3976249E-03 + 8 -0.9156086 23 0.2280432 0.000000 0.000000 0.8763977 F 0.000000 309.9990 0.000000 0.2000000 0.2000000 0.2000000 0.2000000 -86.32730 -158.2571 -158.4894 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.2000000E-02 0.7589021E-01 0.1042763 0.2847985 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.7589021E-01 0.1042763 0.2847985 0.2000000E-02 0.1602560E-03 0.1810878E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 -0.9156086 -0.9357281E-03 0.000000 0.3991232E-03 + 9 -0.7399067 22 0.9953368E-01 0.000000 0.000000 0.000000 F 0.000000 302.9990 0.000000 0.5000000E-01 0.5000000E-01 0.000000 0.000000 -1.620014 -1.918802 -3.723360 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.2000000E-02 0.8001670E-02 0.6550072E-01 0.2647994 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.8001670E-02 0.6550072E-01 0.2647994 0.2000000E-02 -0.2488358E-03 -0.1449971E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 -0.7399068 0.000000 0.000000 0.000000 diff --git a/model_metaswap/java/test/org/openda/model_metaswap/testData/init_svat_expected.inp b/model_metaswap/java/test/org/openda/model_metaswap/testData/init_svat_expected.inp index 99eda44fa..35c3e4c08 100644 --- a/model_metaswap/java/test/org/openda/model_metaswap/testData/init_svat_expected.inp +++ b/model_metaswap/java/test/org/openda/model_metaswap/testData/init_svat_expected.inp @@ -1,15 +1,10 @@ -Saved_State, tdac= 0.0000000, version=V7.3.1 , unsacode=0.4618015 - 207106 19.50602 8 0.8397783 0.1150785E-02 0.1150785E-02 0.000000 T 0.000000 730.9990 0.000000 0.5000000E-01 0.5000000E-01 0.000000 0.000000 -1.7207540E00 -0.8603770 -0.8459430 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.000000 0.7587735E-02 0.2770546E-01 0.5076489E-01 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.7587735E-02 0.2770546E-01 0.5076489E-01 0.1332984E-03 -0.5933025E-04 -0.1623941E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.7158307E-03 -0.9885151E-04 19.50602 -0.3931762E-02 0.9750066E-04 0.000000 - 207107 19.33045 13 0.2954777 0.000000 0.000000 0.9991611 T 0.000000 730.9990 0.000000 0.3000000 0.3000000 0.3000000 0.3000000 -1.2536394E00 -0.8357596 -0.8028657 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.000000 0.2322074E-01 0.4646318E-01 0.5039223E-01 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.2322074E-01 0.4646318E-01 0.5039223E-01 0.1332984E-03 -0.3585286E-03 -0.4193589E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4452773E-03 0.4439334E-03 19.33045 -0.3699563E-02 0.000000 0.1217736E-03 - 207108 19.18302 10 0.7698057 0.2718639E-03 0.2718639E-03 0.9999999 T 0.000000 720.9990 0.000000 0.2000000 0.2000000 0.2230000 0.2230000 -1.2310287E00 -0.5131373 -0.6995649 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.1382279E-04 0.000000 0.1666558E-01 0.3369270E-01 0.3211979E-01 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.1666558E-01 0.3369270E-01 0.3211979E-01 0.3172502E-04 0.000000 -0.5840921E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 -0.8101874E-03 0.9761060E-03 19.18302 -0.7413799E-02 0.2320515E-04 0.000000 - 207109 19.52993 11 0.9006545 0.1150785E-02 0.1150785E-02 0.000000 T 0.000000 723.9990 0.000000 0.5000000E-01 0.5000000E-01 0.000000 0.000000 -1.2011939E00 -0.7654589 -0.6904747 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.000000 0.4348781E-02 0.3196095E-01 0.6249241E-01 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.4348781E-02 0.3196095E-01 0.6249241E-01 0.1332984E-03 0.000000 -0.5069391E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 -0.6591358E-03 0.2171163E-03 19.52993 0.000000 0.9750066E-04 0.000000 - 207110 19.54663 25 0.7084233 0.1147513E-02 0.1147513E-02 0.000000 T 0.000000 723.9990 0.000000 0.5000000E-01 0.5000000E-01 0.000000 0.000000 -1.5064440E00 -1.153041 -4.241650 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.000000 0.7033203E-02 0.4018101E-01 0.4393426 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.7033203E-02 0.4018101E-01 0.4393426 0.1335393E-03 0.000000 -0.7530567E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.7354501E-03 0.8557374E-03 19.54663 -0.7180587E-03 0.9769585E-04 0.000000 - 207111 19.68418 19 0.2581946 0.2710888E-03 0.2710888E-03 0.9999999 T 0.000000 720.9990 0.000000 0.2000000 0.2000000 0.2230000 0.2230000 -1.7630702E00 -0.8899747 -1.184848 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.1383069E-04 0.000000 0.3087497E-01 0.4808572E-01 0.1537189 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.3087497E-01 0.4808572E-01 0.1537189 0.3178235E-04 0.000000 -0.7302721E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1831988E-03 0.1721197E-03 19.68418 -0.7138399E-02 0.2325161E-04 0.000000 - 207112 19.84553 7 0.9446620 0.2710888E-03 0.2710888E-03 0.9999999 T 0.000000 720.9990 0.000000 0.2000000 0.2000000 0.2230000 0.2230000 -7.8802206E-01 -0.6171628 -0.6606391 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.1383069E-04 0.000000 0.1985624E-01 0.2805428E-01 0.8312432E-02 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.1985624E-01 0.2805428E-01 0.8312432E-02 0.3178235E-04 0.000000 -0.4057659E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6391637E-03 -0.6122190E-03 19.84553 -0.6934337E-02 0.2325161E-04 0.000000 - 207113 19.78426 3 0.9574056 0.2710888E-03 0.2710888E-03 0.9999999 T 0.000000 720.9990 0.000000 0.2000000 0.2000000 0.2230000 0.2230000 -3.2393374E-01 -0.2183181 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.1383069E-04 0.000000 0.1508240E-01 0.8491351E-02 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.1508240E-01 0.8491351E-02 0.000000 0.3178235E-04 0.000000 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 -0.6155627E-03 0.2887748E-03 19.78426 0.000000 0.2325161E-04 0.000000 - 207114 19.85884 5 0.2115626 0.2950235E-03 0.2950235E-03 0.9999999 T 0.000000 720.9990 0.000000 0.2000000 0.2000000 0.2230000 0.2230000 -4.5551500E-01 -0.3495639 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.5972692E-04 0.000000 0.1439268E-01 0.1207967E-01 0.1305752E-03 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.1439268E-01 0.1207967E-01 0.1305752E-03 0.4617314E-04 0.000000 -0.8196374E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.8829601E-03 -0.6339937E-03 19.85884 -0.4532152E-02 0.2329881E-04 0.000000 - 207115 19.53634 4 0.4366263 0.2950235E-03 0.2950235E-03 0.9999999 T 0.000000 720.9990 0.000000 0.2000000 0.2000000 0.2230000 0.2230000 -3.6977314E-01 -0.2377030 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.5972692E-04 0.000000 0.1685615E-01 0.1065987E-01 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.1685615E-01 0.1065987E-01 0.000000 0.4617314E-04 0.000000 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 -0.6302290E-03 0.3068389E-02 19.53634 0.000000 0.2329881E-04 0.000000 - 207116 19.62134 5 0.4866402 0.2950235E-03 0.2950235E-03 0.9999999 T 0.000000 720.9990 0.000000 0.2000000 0.2000000 0.2230000 0.2230000 -4.8189065E-01 -0.3736331 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.5972692E-04 0.000000 0.2022729E-01 0.1669393E-01 0.3210638E-03 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.2022729E-01 0.1669393E-01 0.3210638E-03 0.4617314E-04 0.000000 -0.6474967E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 -0.6879289E-03 0.3684591E-02 19.62134 -0.4793910E-03 0.2329881E-04 0.000000 - 207117 20.12403 5 0.6597515 0.1248412E-02 0.1248412E-02 0.000000 T 0.000000 723.9990 0.000000 0.5000000E-01 0.5000000E-01 0.000000 0.000000 -5.7399810E-01 -0.5298444 -0.5295858 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.000000 0.5695430E-02 0.1922567E-01 0.1553429E-01 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.5695430E-02 0.1922567E-01 0.1553429E-01 0.1940048E-03 -0.7369649E-04 -0.2985327E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 -0.9238226E-03 0.8753677E-03 20.12403 -0.9168052E-03 0.9789417E-04 0.000000 - 207118 20.52016 4 0.4983848 0.2808624E-03 0.2808624E-03 0.9999999 T 0.000000 720.9990 0.000000 0.2000000 0.2000000 0.2230000 0.2230000 -3.6314955E-01 -0.2524879 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.8018519E-04 0.000000 0.1055392E-01 0.6614680E-02 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.1055392E-01 0.6614680E-02 0.000000 0.5261960E-04 0.000000 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.5730065E-03 -0.1908906E-03 20.52016 -0.4338291E-02 0.2334674E-04 0.000000 - 207119 20.68848 5 0.3152092 0.2808624E-03 0.2808624E-03 0.9999999 T 0.000000 720.9990 0.000000 0.2000000 0.2000000 0.2230000 0.2230000 -4.5088961E-01 -0.3493218 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.8018519E-04 0.000000 0.1162122E-01 0.1117104E-01 0.1935558E-03 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.1162122E-01 0.1117104E-01 0.1935558E-03 0.5261960E-04 0.000000 -0.5693454E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 -0.6205873E-03 0.1487734E-02 20.68848 -0.5248159E-02 0.2334674E-04 0.000000 +Saved_State, tdac= 310.0000000, version=V7.3.3.2 , unsacode=0.4618015 + 1 -0.8235401 16 0.7354024 0.000000 0.000000 0.8839978 F 0.000000 309.9990 0.000000 0.2000000 0.2000000 0.2000000 0.2000000 -85.03055 -157.5665 -158.3454 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.2000000E-02 1.0010642E03 0.1103365 0.7629367E-01 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.6423438E-01 0.1103365 0.7629367E-01 0.2000000E-02 0.6702658E-03 0.8776899E-03 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 0.1383048E-02 -0.8235402 -0.3751701E-02 0.000000 0.4026632E-03 + 2 -0.5915389 16 0.5153887 0.000000 0.000000 0.8816882 F 0.000000 309.9990 0.000000 0.2000000 0.2000000 0.2000000 0.2000000 -84.51031 -157.4035 -112.1327 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.2000000E-02 1.0010745E03 0.8718438E-01 0.1057264 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.7450714E-01 0.8718438E-01 0.1057264 0.2000000E-02 0.6358884E-03 0.6448366E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 0.4930161E-03 -0.5915389 0.000000 0.000000 0.4016112E-03 + 3 -0.5533270 18 0.3326957E-01 0.000000 0.000000 0.8799960 F 0.000000 309.9990 0.000000 0.2000000 0.2000000 0.2000000 0.2000000 -84.56480 -157.6756 -13.02668 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.2000000E-02 1.0010750E03 0.9136210E-01 0.1285640 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.7495250E-01 0.9136210E-01 0.1285640 0.2000000E-02 0.4917238E-03 0.5091060E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 0.3862757E-03 -0.5533268 0.000000 0.000000 0.4009226E-03 + 4 -0.5369097 18 0.3690963 0.000000 0.000000 0.8796993 F 0.000000 309.9990 0.000000 0.2000000 0.2000000 0.2000000 0.2000000 -84.66550 -157.7240 -9.003483 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.2000000E-02 1.0010750E03 0.9213376E-01 0.1337943 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.7502381E-01 0.9213376E-01 0.1337943 0.2000000E-02 0.4681373E-03 0.4941994E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 0.4377240E-03 -0.5369096 0.000000 0.000000 0.4007874E-03 + 5 -0.5155597 18 0.5559703E-01 0.000000 0.000000 0.8799743 F 0.000000 309.9990 0.000000 0.2000000 0.2000000 0.2000000 0.2000000 -84.57245 -157.6790 -11.01412 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.2000000E-02 1.0010750E03 0.9141341E-01 0.1288201 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.7495732E-01 0.9141341E-01 0.1288201 0.2000000E-02 0.4903299E-03 0.5119590E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 0.4158614E-03 -0.5155597 0.000000 0.000000 0.4009127E-03 + 6 -0.3850709 14 0.5507103 0.000000 0.000000 0.9999999 F 0.000000 299.9990 0.000000 0.2000000 0.2000000 0.2000000 0.2000000 -1.332792 -1.541619 -1.563627 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.1400000E-03 0.2000000E-02 1.0010327E03 0.5978274E-01 0.4826918E-01 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.3269792E-01 0.5978274E-01 0.4826918E-01 0.2000000E-02 -0.2474061E-03 0.3585012E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.4027432E-03 -0.3850709 -0.8886825E-02 0.000000 0.000000 + 7 -1.089436 21 0.3971787 0.000000 0.000000 0.8731077 F 0.000000 309.9990 0.000000 0.2000000 0.2000000 0.2000000 0.2000000 -94.48472 -158.2114 -158.4839 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.2000000E-02 1.0010651E03 0.1344540 0.1870877 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.6514014E-01 0.1344540 0.1870877 0.2000000E-02 0.3791025E-03 0.5034527E-03 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 0.1091840E-02 -1.089436 -0.1161498E-02 0.000000 0.3976249E-03 + 8 -0.9156086 23 0.2280432 0.000000 0.000000 0.8763977 F 0.000000 309.9990 0.000000 0.2000000 0.2000000 0.2000000 0.2000000 -86.32730 -158.2571 -158.4894 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.2000000E-02 1.0010759E03 0.1042763 0.2847985 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.7589021E-01 0.1042763 0.2847985 0.2000000E-02 0.1602560E-03 0.1810878E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 0.5460173E-03 -0.9156086 -0.9357281E-03 0.000000 0.3991232E-03 + 9 -0.7399067 22 0.9953368E-01 0.000000 0.000000 0.000000 F 0.000000 302.9990 0.000000 0.5000000E-01 0.5000000E-01 0.000000 0.000000 -1.620014 -1.918802 -3.723360 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 -9999.000 0.000000 0.2000000E-02 1.0010080E03 0.6550072E-01 0.2647994 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.8001670E-02 0.6550072E-01 0.2647994 0.2000000E-02 -0.2488358E-03 -0.1449971E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 0.2206476E-03 -0.7399068 0.000000 0.000000 0.000000 diff --git a/model_nemo/java/model_nemo.iml b/model_nemo/java/model_nemo.iml index db71116c1..d7d40db68 100644 --- a/model_nemo/java/model_nemo.iml +++ b/model_nemo/java/model_nemo.iml @@ -10,15 +10,7 @@ - - - - - - - - - + \ No newline at end of file diff --git a/model_nemo/java/src/org/openda/model_nemo/NemoModelInstance.java b/model_nemo/java/src/org/openda/model_nemo/NemoModelInstance.java index e4048c7c1..27c4ac739 100644 --- a/model_nemo/java/src/org/openda/model_nemo/NemoModelInstance.java +++ b/model_nemo/java/src/org/openda/model_nemo/NemoModelInstance.java @@ -201,8 +201,8 @@ public IVector getObservedValues(IObservationDescriptions observationDescription int offset_tb = 225424-1; // get values of sshb // - IPrevExchangeItem sshbExchange = this.getExchangeItem("sshb"); - IPrevExchangeItem tbExchange = this.getExchangeItem("tb"); + IExchangeItem sshbExchange = this.getExchangeItem("sshb"); + IExchangeItem tbExchange = this.getExchangeItem("tb"); double [] sshb=sshbExchange.getValuesAsDoubles(); diff --git a/model_nemo/java/src/org/openda/model_nemo/NemoNetcdfStochObserver.java b/model_nemo/java/src/org/openda/model_nemo/NemoNetcdfStochObserver.java index 56a294386..c0be77901 100644 --- a/model_nemo/java/src/org/openda/model_nemo/NemoNetcdfStochObserver.java +++ b/model_nemo/java/src/org/openda/model_nemo/NemoNetcdfStochObserver.java @@ -345,7 +345,7 @@ void initValues(){ * * @return All exchange items in the stoch. observer. */ - public List getExchangeItems() { + public List getExchangeItems() { throw new RuntimeException("not yet implemented"); } diff --git a/model_nemo/java/test/org/openda/model_nemo/NemoWrapperTest.java b/model_nemo/java/test/org/openda/model_nemo/NemoWrapperTest.java index 5d0e75739..30fcf19d1 100644 --- a/model_nemo/java/test/org/openda/model_nemo/NemoWrapperTest.java +++ b/model_nemo/java/test/org/openda/model_nemo/NemoWrapperTest.java @@ -26,7 +26,7 @@ import org.openda.exchange.timeseries.NoosTimeSeriesFormatter; import org.openda.exchange.timeseries.TimeSeries; import org.openda.exchange.timeseries.TimeSeriesFormatter; -import org.openda.interfaces.IPrevExchangeItem; +import org.openda.interfaces.IExchangeItem; import org.openda.utils.OpenDaTestSupport; import java.io.File; @@ -53,12 +53,12 @@ public void testReadInput() { String args[] = {}; ioObject.initialize(testRunDataDir, "SQB_00010368_restart.nc", args); - IPrevExchangeItem[] exchangeItems = ioObject.getExchangeItems(); + IExchangeItem[] exchangeItems = ioObject.getExchangeItems(); for(int item=0;item - - - - - - - - - + \ No newline at end of file diff --git a/model_openfoam/java/src/org/openda/model_openfoam/CsvTimeSeriesDataObject.java b/model_openfoam/java/src/org/openda/model_openfoam/CsvTimeSeriesDataObject.java index e46540a8e..1cf40b1b1 100644 --- a/model_openfoam/java/src/org/openda/model_openfoam/CsvTimeSeriesDataObject.java +++ b/model_openfoam/java/src/org/openda/model_openfoam/CsvTimeSeriesDataObject.java @@ -29,11 +29,12 @@ import org.openda.exchange.timeseries.TimeSeriesSet; import org.openda.exchange.timeseries.TimeSeries; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; import java.io.File; import java.util.Iterator; +import java.util.Objects; import java.util.Set; import java.util.regex.Pattern; @@ -75,7 +76,7 @@ public void initialize(File workingDir, String[] arguments) { timeSeriesSet.add(series); } else if (file.exists() && file.isDirectory()) { logger.debug("Finding files in directory: " + file.getAbsolutePath()); - for (File myFile : file.listFiles() ) { + for (File myFile : Objects.requireNonNull(file.listFiles())) { if (myFile.isFile()) { TimeSeries series = csvFormatter.readFile(myFile); series.setProperty(PROPERTY_PATHNAME, myFile.getAbsolutePath()); @@ -184,7 +185,7 @@ public TimeSeriesSet getTimeSeriesSet() { /** * @param set - * The TimeSeriesSet to set in this IoObject + * The TimeSeriesSet to set in this DataObject */ public void setTimeSeriesSet(TimeSeriesSet set) { this.timeSeriesSet = set; diff --git a/model_openfoam/java/src/org/openda/model_openfoam/CsvTimeSeriesFormatter.java b/model_openfoam/java/src/org/openda/model_openfoam/CsvTimeSeriesFormatter.java index 9acce7603..02d5196f4 100644 --- a/model_openfoam/java/src/org/openda/model_openfoam/CsvTimeSeriesFormatter.java +++ b/model_openfoam/java/src/org/openda/model_openfoam/CsvTimeSeriesFormatter.java @@ -2,7 +2,7 @@ import org.openda.exchange.timeseries.TimeSeries; import org.openda.exchange.timeseries.TimeSeriesFormatter; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; import org.openda.exchange.timeseries.TimeUtils; import java.io.*; diff --git a/model_openfoam/java/src/org/openda/model_openfoam/DictionaryDataObject.java b/model_openfoam/java/src/org/openda/model_openfoam/DictionaryDataObject.java index 4e37c2d9e..ec1641695 100755 --- a/model_openfoam/java/src/org/openda/model_openfoam/DictionaryDataObject.java +++ b/model_openfoam/java/src/org/openda/model_openfoam/DictionaryDataObject.java @@ -26,7 +26,6 @@ import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.IDataObject; import org.openda.exchange.DoubleExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.interfaces.IExchangeItem; import java.text.MessageFormat; @@ -86,9 +85,9 @@ public class DictionaryDataObject implements IDataObject{ * @param arguments list of other arguments: *

    *
  1. The name of the file containing the data - * for this IoObject (relative to the working directory).
  2. + * for this DataObject (relative to the working directory). *
  3. Optional, a referenceDate in ISO 8601 notatation, e.g - * for this IoObject (relative to the working directory).
  4. + * for this DataObject (relative to the working directory). * *
*/ @@ -186,11 +185,11 @@ public void initialize(File workingDir, String[] arguments) { /** {@inheritDoc} */ - public IPrevExchangeItem[] getExchangeItems() { + public IExchangeItem[] getExchangeItems() { int n = this.items.size(); Set keys = this.items.keySet(); - IPrevExchangeItem[] result=new IPrevExchangeItem[n]; + IExchangeItem[] result=new IExchangeItem[n]; int i=0; for(String key : keys){ result[i]=this.items.get(key); @@ -213,7 +212,7 @@ public String[] getExchangeItemIDs() { /** {@inheritDoc} */ - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { //TODO: select on role return items.keySet().toArray(new String[items.size()]); } diff --git a/model_openfoam/java/src/org/openda/model_openfoam/DictionaryNoisyDataObject.java b/model_openfoam/java/src/org/openda/model_openfoam/DictionaryNoisyDataObject.java index 10dfd6fe4..9e23d0aca 100755 --- a/model_openfoam/java/src/org/openda/model_openfoam/DictionaryNoisyDataObject.java +++ b/model_openfoam/java/src/org/openda/model_openfoam/DictionaryNoisyDataObject.java @@ -27,7 +27,6 @@ import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.IMyObservable; import org.openda.utils.IMyObserver; @@ -109,9 +108,9 @@ public void update(IMyObservable object, Object arg){ * @param arguments list of other arguments: *
    *
  1. The name of the file containing the data - * for this IoObject (relative to the working directory).
  2. + * for this DataObject (relative to the working directory). *
  3. Optional, a referenceDate in ISO 8601 notatation, e.g - * for this IoObject (relative to the working directory).
  4. + * for this DataObject (relative to the working directory). * *
*/ @@ -253,10 +252,10 @@ public void initialize(File workingDir, String[] arguments) { /** {@inheritDoc} */ - public IPrevExchangeItem[] getExchangeItems() { + public IExchangeItem[] getExchangeItems() { int n = this.items.size(); - IPrevExchangeItem[] result=new IPrevExchangeItem[n]; + IExchangeItem[] result=new IExchangeItem[n]; int i=0; for(String key : this.items.keySet()){ @@ -281,7 +280,7 @@ public String[] getExchangeItemIDs() { /** {@inheritDoc} */ - public String[] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String[] getExchangeItemIDs(IExchangeItem.Role role) { //TODO: select on role return this.getExchangeItemIDs(); } diff --git a/model_openfoam/java/src/org/openda/model_openfoam/DictionaryTimeSeriesDataObject.java b/model_openfoam/java/src/org/openda/model_openfoam/DictionaryTimeSeriesDataObject.java index f99b80086..57d863054 100755 --- a/model_openfoam/java/src/org/openda/model_openfoam/DictionaryTimeSeriesDataObject.java +++ b/model_openfoam/java/src/org/openda/model_openfoam/DictionaryTimeSeriesDataObject.java @@ -27,7 +27,6 @@ import org.openda.exchange.timeseries.TimeUtils; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import java.io.BufferedWriter; import java.io.File; @@ -87,9 +86,9 @@ public class DictionaryTimeSeriesDataObject implements IDataObject{ * @param arguments list of other arguments: *
    *
  1. The name of the file containing the data - * for this IoObject (relative to the working directory).
  2. + * for this DataObject (relative to the working directory). *
  3. Optional, a referenceDate in ISO 8601 notatation, e.g - * for this IoObject (relative to the working directory).
  4. + * for this DataObject (relative to the working directory). * *
*/ @@ -239,7 +238,7 @@ public IExchangeItem getDataObjectExchangeItem(String exchangeItemID) { /** {@inheritDoc} */ - public String [] getExchangeItemIDs(IPrevExchangeItem.Role role) { + public String [] getExchangeItemIDs(IExchangeItem.Role role) { return getExchangeItemIDs(); } @@ -307,7 +306,7 @@ public TimeSeriesSet getTimeSeriesSet() { /** * @param set - * The TimeSeriesSet to set in this IoObject + * The TimeSeriesSet to set in this DataObject */ public void setTimeSeriesSet(TimeSeriesSet set) { this.timeSeriesSet = set; diff --git a/model_openfoam/java/src/org/openda/model_openfoam/MeshDataObject.java b/model_openfoam/java/src/org/openda/model_openfoam/MeshDataObject.java index 77df05378..e21ac079f 100755 --- a/model_openfoam/java/src/org/openda/model_openfoam/MeshDataObject.java +++ b/model_openfoam/java/src/org/openda/model_openfoam/MeshDataObject.java @@ -33,7 +33,7 @@ import org.openda.interfaces.IArray; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; import org.openda.utils.Array; @@ -86,7 +86,7 @@ public class MeshDataObject implements IDataObject { * @param arguments list of other arguments: *
    *
  1. The name of the file containing the data - * for this IoObject (relative to the working directory).
  2. + * for this DataObject (relative to the working directory). *
*/ public void initialize(File workingDir, String[] arguments) { diff --git a/model_openfoam/java/src/org/openda/model_openfoam/ProbeDataObject.java b/model_openfoam/java/src/org/openda/model_openfoam/ProbeDataObject.java index a221ab6ec..1a26265ad 100755 --- a/model_openfoam/java/src/org/openda/model_openfoam/ProbeDataObject.java +++ b/model_openfoam/java/src/org/openda/model_openfoam/ProbeDataObject.java @@ -30,7 +30,7 @@ import org.openda.interfaces.IComposableDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem.Role; +import org.openda.interfaces.IExchangeItem.Role; import java.io.*; import java.util.*; @@ -104,7 +104,7 @@ public class ProbeDataObject implements IComposableDataObject { * @param arguments list of other arguments: *
    *
  1. The name of the file containing the data - * for this IoObject (relative to the working directory).
  2. + * for this DataObject (relative to the working directory). *
*/ public void initialize(File workingDir, String[] arguments) { diff --git a/model_openfoam/java/test/org/openda/model_openfoam/MeshDataObjectTest.java b/model_openfoam/java/test/org/openda/model_openfoam/MeshDataObjectTest.java index 29ed73ce5..d18422bb5 100755 --- a/model_openfoam/java/test/org/openda/model_openfoam/MeshDataObjectTest.java +++ b/model_openfoam/java/test/org/openda/model_openfoam/MeshDataObjectTest.java @@ -3,7 +3,6 @@ import junit.framework.TestCase; import org.openda.interfaces.IDataObject; import org.openda.interfaces.IExchangeItem; -import org.openda.interfaces.IPrevExchangeItem; import org.openda.utils.OpenDaTestSupport; import java.io.File; @@ -50,11 +49,11 @@ public void testGetExchangeItemIDs() { public void testGetExchangeItemIDs1() { IDataObject scalarObject = new MeshDataObject(); scalarObject.initialize(testRunDataDir, new String[]{"results/OPENFOAM_TIME_DIR/T"} ); - String[] ids = scalarObject.getExchangeItemIDs(IPrevExchangeItem.Role.InOut); + String[] ids = scalarObject.getExchangeItemIDs(IExchangeItem.Role.InOut); assertEquals("T", ids[0]); IDataObject vectorObject = new MeshDataObject(); vectorObject.initialize(testRunDataDir, new String[]{"results/OPENFOAM_TIME_DIR/U"} ); - ids = vectorObject.getExchangeItemIDs(IPrevExchangeItem.Role.InOut); + ids = vectorObject.getExchangeItemIDs(IExchangeItem.Role.InOut); Arrays.sort(ids); assertEquals("U1", ids[0]); assertEquals("U2", ids[1]); diff --git a/model_openfoam/tests/steadyToyProblem/DUD.oda b/model_openfoam/tests/steadyToyProblem/DUD.oda new file mode 100644 index 000000000..c6b5dfeb0 --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/DUD.oda @@ -0,0 +1,23 @@ + + + + + stochObserver + generatedStochObsConfig.xml + + + stochModel + openfoamDUDStochModel.xml + + + ./algorithm + dudAlgorithm.xml + + + + + . + DUD_results.py + + + diff --git a/model_openfoam/tests/steadyToyProblem/EnKF.oda b/model_openfoam/tests/steadyToyProblem/EnKF.oda new file mode 100644 index 000000000..f90729319 --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/EnKF.oda @@ -0,0 +1,20 @@ + + + + ./stochObserver + generatedStochObsConfig.xml + + + ./stochModel + openfoamStochModel.xml + + + ./algorithm + EnKFAlgorithm.xml + + + + . + EnKF_results.py + + diff --git a/model_openfoam/tests/steadyToyProblem/README.md b/model_openfoam/tests/steadyToyProblem/README.md new file mode 100644 index 000000000..9733b7cfd --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/README.md @@ -0,0 +1,20 @@ +This example was created as a ToyProblem for testing using these versions of OpenDA and OpenFOAM: + +* OpenDA 2.4.4.1 +* OpenFOAM v1712 + +It is not tested (yet) for OpenDA 3.0 and/or newer releases of OpenFOAM. + + + +The OpenFOAM model is a simplified geometry representing a room in a data-center. There is a false floor, a CRAC unit introducing cooled air into the room, an 'alley' with 4 server racks that produce heat and 4 temperature sensors close to the ceiling. + +The OpenDA configuration files are for a Black Box coupling (see Chapter "OpenDA black box wrapper cookbook" in OpenDA_documentation.pdf). Some of the OpenFOAM input files contain lines ending with: + +​ //#oda:keyword + +OpenDA is able to modify such lines, using the wrapper code as available in ~/model_openfoam/java/src/org/openda/model_openfoam. + +Heat is produced by the server racks, the modeling of this process is in file ~/system/HEATING. We have run OpenFOAM with certain parameters for the heat production and use the output of the temperature sensors for this run as 'measurements'. + +If you start the OpenDA-OpenFOAM run with slightly different settings for the heat production (either calibration with DUD.oda or Kalman Filtering with EnKF.oda) you can check that the values in files ~/work\*/\*/HEATING are indeed updated by OpenDA. \ No newline at end of file diff --git a/model_openfoam/tests/steadyToyProblem/Simulation.oda b/model_openfoam/tests/steadyToyProblem/Simulation.oda new file mode 100644 index 000000000..e71fa758d --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/Simulation.oda @@ -0,0 +1,20 @@ + + + + ./stochObserver + dcimStochObsConfig.xml + + + ./stochModel + openfoamStochModel.xml + + + ./algorithm + simulationAlgorithm.xml + + + + . + Simulation_results.m + + diff --git a/model_openfoam/tests/steadyToyProblem/algorithm/EnKFAlgorithm.xml b/model_openfoam/tests/steadyToyProblem/algorithm/EnKFAlgorithm.xml new file mode 100644 index 000000000..a2de11543 --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/algorithm/EnKFAlgorithm.xml @@ -0,0 +1,12 @@ + + + + + + + 4 + + + diff --git a/model_openfoam/tests/steadyToyProblem/algorithm/dudAlgorithm.xml b/model_openfoam/tests/steadyToyProblem/algorithm/dudAlgorithm.xml new file mode 100644 index 000000000..64781f381 --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/algorithm/dudAlgorithm.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/model_openfoam/tests/steadyToyProblem/algorithm/simulationAlgorithm.xml b/model_openfoam/tests/steadyToyProblem/algorithm/simulationAlgorithm.xml new file mode 100644 index 000000000..b67978ffb --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/algorithm/simulationAlgorithm.xml @@ -0,0 +1,7 @@ + + + + + + diff --git a/model_openfoam/tests/steadyToyProblem/stochModel/HeatNoiseConfig.xml b/model_openfoam/tests/steadyToyProblem/stochModel/HeatNoiseConfig.xml new file mode 100644 index 000000000..b99f80adb --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/stochModel/HeatNoiseConfig.xml @@ -0,0 +1,8 @@ + + + 0.0,0.0001157407407,...,0.0003472222222 + + + diff --git a/model_openfoam/tests/steadyToyProblem/stochModel/bin/start_openfoam.sh b/model_openfoam/tests/steadyToyProblem/stochModel/bin/start_openfoam.sh new file mode 100755 index 000000000..d1d45ebb9 --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/stochModel/bin/start_openfoam.sh @@ -0,0 +1,69 @@ +#!/bin/bash +usage="$(basename "$0") [-h] [-d] [-p nrprocs] [-s solver] [-v]-- script to run OpenFOAM case within OpenDA + +where: + -h show this help text + -d dryrun + -p number of parallel processes + -s solver + -v verbose +" +# exit on error +set -e + +# Initialize our own variables: +dryrun=0 +verbose=0 +nrprocs=1 +solver='' + +# A POSIX variable +OPTIND=1 # Reset in case getopts has been used previously in the shell. +while getopts "h?dp:s:v" opt; do + case "$opt" in + d) dryrun=1;verbose=1; + ;; + h|\?) + # show_help + echo "$usage" + exit 0 + ;; + p) nrprocs=$OPTARG + ;; + s) solver=$OPTARG + ;; + v) verbose=1 + ;; + esac +done + +if [ nrprocs -gt 1 ]; then + count=0 + count=`find . -maxdepth 1 -type d -name 'processor[0-9]*' | wc -l` + + if [ $verbose -eq 1 ]; then echo "Found ${count} existing processor directories."; fi + if [ $verbose -eq 1 ]; then echo "Starting job on ${nrprocs} processors."; fi + + if [ "$count" -ne "$nrprocs" ]; then + if [ "$verbose" -eq 1 ]; then echo "decomposePar"; fi; + if [ "$dryrun" -eq 0 ]; then decomposePar > decomposePar.log; fi; + else + if [ "$verbose" -eq 1 ]; then echo "decomposePar -fields"; fi; + echo "decomposePar -fields"; + if [ "$dryrun" -eq 0 ]; then decomposePar -fields > decomposePar.log; fi; + decomposePar --fields + fi +fi + +if [ $nrprocs -eq 1 ]; then + if [ "$verbose" -eq 1 ]; then echo "${solver}"; fi + if [ "$dryrun" -eq 0 ]; then ${solver} | tee >(grep '^Time =') > ${solver}.log; fi +else + if [ "$verbose" -eq 1 ]; then echo "mpirun -np ${nrprocs} ${solver} -parallel"; fi + if [ "$dryrun" -eq 0 ]; then mpirun -np ${nrprocs} ${solver} | tee >(grep '^Time =') > ${solver}.log; fi +fi + +if [ nrprocs -gt 1 ]; then + if [ "$verbose" -eq 1 ]; then echo "reconstructPar -latestTime"; fi + if [ "$dryrun" -eq 0 ]; then reconstructPar -latestTime | tee >(grep '^Time =') > reconstructPar.log; fi +fi diff --git a/model_openfoam/tests/steadyToyProblem/stochModel/model/0/T b/model_openfoam/tests/steadyToyProblem/stochModel/model/0/T new file mode 100644 index 000000000..c3f1c0f8c --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/stochModel/model/0/T @@ -0,0 +1,49 @@ +/*--------------------------------*4D-COOL*----------------------------------*\ +|------------------------------OpenFOAM v 1712 -------------------------------| +\*--------------------------------*4D-COOL*----------------------------------*/ +FoamFile +{ +version 2.0; +format ascii; +class volScalarField; +object T; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [ 0 0 0 1 0 0 0 ]; + +internalField uniform 295.15;//22 Graden Celsius. + +boundaryField +{ + ".*" + { + type zeroGradient; + value $internalField; + } + cyclic + { + type cyclic; + value $internalField; + } + CRAC_Supply + { + type inletOutlet; + inletValue uniform 295.15;// 22 C + value uniform 295.15; + } + CRAC_Return + { + type inletOutlet; + inletValue uniform 307.15;// 34 C + value uniform 295.15; + } + "open.*" + { + type inletOutlet; + inletValue uniform 285.15; + value $internalField; + } +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/model_openfoam/tests/steadyToyProblem/stochModel/model/0/U b/model_openfoam/tests/steadyToyProblem/stochModel/model/0/U new file mode 100644 index 000000000..1ac6db6b4 --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/stochModel/model/0/U @@ -0,0 +1,49 @@ +/*--------------------------------*4D-COOL*----------------------------------*\ +|------------------------------OpenFOAM v 1712 -------------------------------| +\*--------------------------------*4D-COOL*----------------------------------*/ +FoamFile +{ +version 2.0; +format ascii; +class volVectorField; +object U; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [ 0 1 -1 0 0 0 0 ]; + +internalField uniform ( 0 0 0 ); + +boundaryField +{ + wall + { + type fixedValue; + value $internalField; + } + cyclic + { + type cyclic; + value $internalField; + } + + CRAC_Return + { + type pressureInletOutletVelocity; + value uniform (0 0 -2); + } + CRAC_Supply + { + type flowRateInletVelocity; + volumetricFlowRate 2.222222; + value uniform (0 0 -2); + } + "open.*" + { + type pressureInletOutletVelocity; + value $internalField; + } +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/model_openfoam/tests/steadyToyProblem/stochModel/model/0/alphat b/model_openfoam/tests/steadyToyProblem/stochModel/model/0/alphat new file mode 100644 index 000000000..4561ff2a5 --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/stochModel/model/0/alphat @@ -0,0 +1,43 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1712 | +| \\ / A nd | Web: www.OpenFOAM.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + location "0"; + object alphat; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [ 0 2 -1 0 0 0 0 ]; + +internalField uniform 0.001; + +boundaryField +{ + wall + { + type alphatJayatillekeWallFunction; + Prt 0.9; + value $internalField; + } + cyclic + { + type cyclic; + value $internalField; + } + "CRAC.*" + { + type calculated; + value $internalField; + } +} + + +// ************************************************************************* // diff --git a/model_openfoam/tests/steadyToyProblem/stochModel/model/0/k b/model_openfoam/tests/steadyToyProblem/stochModel/model/0/k new file mode 100644 index 000000000..d0a379461 --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/stochModel/model/0/k @@ -0,0 +1,49 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1712 | +| \\ / A nd | Web: www.OpenFOAM.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + location "0"; + object k; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [ 0 2 -2 0 0 0 0 ]; + +internalField uniform 0.06; + +boundaryField +{ + wall//".*" + { + type kqRWallFunction; + value $internalField; + } + cyclic + { + type cyclic; + value $internalField; + } + CRAC_Return + { + type inletOutlet; + inletValue $internalField;// tbd + value $internalField; + } + CRAC_Supply + { + type turbulentIntensityKineticEnergyInlet; + value $internalField; + intensity 0.1; + } +} + + +// ************************************************************************* // diff --git a/model_openfoam/tests/steadyToyProblem/stochModel/model/0/nut b/model_openfoam/tests/steadyToyProblem/stochModel/model/0/nut new file mode 100644 index 000000000..d65d30a07 --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/stochModel/model/0/nut @@ -0,0 +1,42 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1712 | +| \\ / A nd | Web: www.OpenFOAM.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + location "0"; + object nut; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [ 0 2 -1 0 0 0 0 ]; + +internalField uniform 0.001; + +boundaryField +{ + wall + { + type nutUSpaldingWallFunction; + value $internalField; + } + cyclic + { + type cyclic; + value $internalField; + } + "CRAC.*" + { + type calculated; + value $internalField; + } +} + + +// ************************************************************************* // diff --git a/model_openfoam/tests/steadyToyProblem/stochModel/model/0/omega b/model_openfoam/tests/steadyToyProblem/stochModel/model/0/omega new file mode 100644 index 000000000..57994afdd --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/stochModel/model/0/omega @@ -0,0 +1,49 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1712 | +| \\ / A nd | Web: www.OpenFOAM.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + location "0"; + object omega; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [ 0 0 -1 0 0 0 0 ]; + +internalField uniform 6.389; + +boundaryField +{ + wall//".*" + { + type omegaWallFunction; + value $internalField; + } + cyclic + { + type cyclic; + value $internalField; + } + CRAC_Return + { + type inletOutlet; + inletValue $internalField;// tbd + value $internalField; + } + CRAC_Supply + { + type turbulentMixingLengthFrequencyInlet; + value $internalField; + mixingLength 0.07; + } +} + + +// ************************************************************************* // diff --git a/model_openfoam/tests/steadyToyProblem/stochModel/model/0/p b/model_openfoam/tests/steadyToyProblem/stochModel/model/0/p new file mode 100644 index 000000000..16e4ebfb8 --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/stochModel/model/0/p @@ -0,0 +1,37 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1712 | +| \\ / A nd | Web: www.OpenFOAM.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + location "0"; + object p; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [ 0 2 -2 0 0 0 0 ]; + +internalField uniform 0; + +boundaryField +{ + ".*" + { + type calculated; + value $internalField; + } + cyclic + { + type cyclic; + value $internalField; + } +} + + +// ************************************************************************* // diff --git a/model_openfoam/tests/steadyToyProblem/stochModel/model/0/p_rgh b/model_openfoam/tests/steadyToyProblem/stochModel/model/0/p_rgh new file mode 100644 index 000000000..d59bd39e4 --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/stochModel/model/0/p_rgh @@ -0,0 +1,86 @@ +/*--------------------------------*4D-COOL*----------------------------------*\ +|------------------------------OpenFOAM v 1712 -------------------------------| +\*--------------------------------*4D-COOL*----------------------------------*/ +FoamFile +{ +version 2.0; +format ascii; +class volScalarField; +object p_rgh; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [ 0 2 -2 0 0 0 0 ]; + +internalField uniform 0; + +boundaryField +{ + ".*" + { + type fixedFluxPressure; + value uniform 0; + } +"tileX0Y0.*" +{ + type porousBafflePressure; + patchType cyclic; + jump uniform 0; + D 0; + I 214.25; + length 0.01; + value uniform 0; +} +"tileX1Y1.*" +{ + type porousBafflePressure; + patchType cyclic; + jump uniform 0; + D 0; + I 428.5; + length 0.01; + value uniform 0; +} +"tileX2Y0.*" +{ + type porousBafflePressure; + patchType cyclic; + jump uniform 0; + D 0; + I 214.25; + length 0.01; + value uniform 0; +} +"tileX3Y0.*" +{ + type porousBafflePressure; + patchType cyclic; + jump uniform 0; + D 0; + I 214.25; + length 0.01; + value uniform 0; +} + CRAC_Return + { + type totalPressure; + p0 uniform 0; + gamma 1.4; + value $internalField; + rho rhok; + } + "openNatural.*" + { + type totalPressure; + p0 uniform 0.0; + value $internalField; + } + "openRoof.*" + { + type totalPressure; + p0 uniform 0; + value $internalField; + } +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/model_openfoam/tests/steadyToyProblem/stochModel/model/checkMesh.log b/model_openfoam/tests/steadyToyProblem/stochModel/model/checkMesh.log new file mode 100644 index 000000000..cbd472960 --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/stochModel/model/checkMesh.log @@ -0,0 +1,123 @@ +/*---------------------------------------------------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1712 | +| \\ / A nd | Web: www.OpenFOAM.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +Build : v1712 +Arch : "LSB;label=32;scalar=64" +Exec : checkMesh -case /results/34_e7d070f4f8534a27b2692aad04a61def/steadyToyProblem -constant +Date : Jul 07 2020 +Time : 12:08:39 +Host : "293cbf513829" +PID : 1187 +I/O : uncollated +Case : /results/34_e7d070f4f8534a27b2692aad04a61def/steadyToyProblem +nProcs : 1 +trapFpe: Floating point exception trapping enabled (FOAM_SIGFPE). +fileModificationChecking : Monitoring run-time modified files using timeStampMaster (fileModificationSkew 10) +allowSystemOperations : Allowing user-supplied system call operations + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +Create time + +Create mesh for time = constant + +Time = constant + +Mesh stats + points: 9177 + faces: 25472 + internal faces: 21760 + cells: 7872 + faces per cell: 6 + boundary patches: 16 + point zones: 0 + face zones: 16 + cell zones: 7 + +Overall number of cells of each type: + hexahedra: 7872 + prisms: 0 + wedges: 0 + pyramids: 0 + tet wedges: 0 + tetrahedra: 0 + polyhedra: 0 + +Checking topology... + Boundary definition OK. + Cell to face addressing OK. + Point usage OK. + Upper triangular ordering OK. + Face vertices OK. + Number of regions: 1 (OK). + +Checking patch topology for multiply connected surfaces... + Patch Faces Points Surface topology + Wand 1568 1659 ok (non-closed singly connected) + Vloer 400 441 ok (non-closed singly connected) + Tegelvloer 352 405 ok (non-closed singly connected) + Tegelvloer_shadow 352 405 ok (non-closed singly connected) + Plafond 400 441 ok (non-closed singly connected) + CRAC_Wand 96 117 ok (non-closed singly connected) + CRAC_Supply 16 25 ok (non-closed singly connected) + CRAC_Return 16 25 ok (non-closed singly connected) + Top_Koude_Gang 32 45 ok (non-closed singly connected) + Top_Koude_Gang_shadow32 45 ok (non-closed singly connected) + Top_Servers 64 90 ok (non-closed singly connected) + Top_Servers_shadow 64 90 ok (non-closed singly connected) + Wand_Tussen_Servers 64 90 ok (non-closed singly connected) + Wand_Tussen_Servers_shadow64 90 ok (non-closed singly connected) + Wand_Tussen_Alley_En_Ruimte96 117 ok (non-closed singly connected) + Wand_Tussen_Alley_En_Ruimte_shadow96 117 ok (non-closed singly connected) + +Checking faceZone topology for multiply connected surfaces... + FaceZone Faces Points Surface topology + tileX0Y0 4 9 ok (non-closed singly connected) + tileX0Y1 4 9 ok (non-closed singly connected) + tileX1Y0 4 9 ok (non-closed singly connected) + tileX1Y1 4 9 ok (non-closed singly connected) + tileX2Y0 4 9 ok (non-closed singly connected) + tileX2Y1 4 9 ok (non-closed singly connected) + tileX3Y0 4 9 ok (non-closed singly connected) + tileX3Y1 4 9 ok (non-closed singly connected) + Inlet_rackX0Y0 32 45 ok (non-closed singly connected) + Inlet_rackX0Y1 32 45 ok (non-closed singly connected) + Inlet_rackX1Y0 32 45 ok (non-closed singly connected) + Inlet_rackX1Y1 32 45 ok (non-closed singly connected) + Outlet_rackX0Y0 32 45 ok (non-closed singly connected) + Outlet_rackX0Y1 32 45 ok (non-closed singly connected) + Outlet_rackX1Y0 32 45 ok (non-closed singly connected) + Outlet_rackX1Y1 32 45 ok (non-closed singly connected) + +Checking basic cellZone addressing... + CellZone Cells Points BoundingBox + rackX0Y0 128 225 (4.8 1.2 0) (6 2.4 2.4) + rackX0Y1 128 225 (4.8 3.6 0) (6 4.8 2.4) + rackX1Y0 128 225 (3.6 1.2 0) (4.8 2.4 2.4) + rackX1Y1 128 225 (3.6 3.6 0) (4.8 4.8 2.4) + COLD_PLENUM 1600 2205 (0 0 -1.2) (6 6 2.6645352e-16) + COLD_ALLEY 256 405 (3.6 2.4 0) (6 3.6 2.4) + HOT_ROOM 5504 6697 (0 0 0) (6 6 4.8) + +Checking geometry... + Overall domain bounding box (0 0 -1.2) (6 6 4.8) + Mesh has 3 geometric (non-empty/wedge) directions (1 1 1) + Mesh has 3 solution (non-empty) directions (1 1 1) + Boundary openness (-1.3459061e-17 9.554272e-18 1.719769e-17) OK. + Max cell openness = 8.6350685e-17 OK. + Max aspect ratio = 1 OK. + Minimum face area = 0.09. Maximum face area = 0.09. Face area magnitudes OK. + Min volume = 0.027. Max volume = 0.027. Total volume = 212.544. Cell volumes OK. + Mesh non-orthogonality Max: 0 average: 0 + Non-orthogonality check OK. + Face pyramids OK. + Max skewness = 1.7763568e-14 OK. + Coupled point location match (average 0) OK. + +Mesh OK. + +End + diff --git a/model_openfoam/tests/steadyToyProblem/stochModel/model/constant/g b/model_openfoam/tests/steadyToyProblem/stochModel/model/constant/g new file mode 100644 index 000000000..fa8e0319f --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/stochModel/model/constant/g @@ -0,0 +1,22 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1712 | +| \\ / A nd | Web: www.OpenFOAM.org | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class uniformDimensionedVectorField; + location "constant"; + object g; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 1 -2 0 0 0 0]; +value ( 0 0 -9.81 ); + + +// ************************************************************************* // diff --git a/model_openfoam/tests/steadyToyProblem/stochModel/model/constant/polyMesh/boundary b/model_openfoam/tests/steadyToyProblem/stochModel/model/constant/polyMesh/boundary new file mode 100644 index 000000000..29e97ab89 --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/stochModel/model/constant/polyMesh/boundary @@ -0,0 +1,276 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1712 | +| \\ / A nd | Web: www.OpenFOAM.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class polyBoundaryMesh; + location "constant/polyMesh"; + object boundary; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +32 +( + Wand + { + type wall; + inGroups 1(wall); + nFaces 1568; + startFace 21728; + } + Vloer + { + type wall; + inGroups 1(wall); + nFaces 400; + startFace 23296; + } + Tegelvloer + { + type wall; + inGroups 1(wall); + nFaces 352; + startFace 23696; + } + Tegelvloer_shadow + { + type wall; + inGroups 1(wall); + nFaces 352; + startFace 24048; + } + Plafond + { + type wall; + inGroups 1(wall); + nFaces 400; + startFace 24400; + } + CRAC_Wand + { + type wall; + inGroups 1(wall); + nFaces 96; + startFace 24800; + } + CRAC_Supply + { + type patch; + nFaces 16; + startFace 24896; + } + CRAC_Return + { + type patch; + nFaces 16; + startFace 24912; + } + Top_Koude_Gang + { + type wall; + inGroups 1(wall); + nFaces 32; + startFace 24928; + } + Top_Koude_Gang_shadow + { + type wall; + inGroups 1(wall); + nFaces 32; + startFace 24960; + } + Top_Servers + { + type wall; + inGroups 1(wall); + nFaces 64; + startFace 24992; + } + Top_Servers_shadow + { + type wall; + inGroups 1(wall); + nFaces 64; + startFace 25056; + } + Wand_Tussen_Servers + { + type wall; + inGroups 1(wall); + nFaces 64; + startFace 25120; + } + Wand_Tussen_Servers_shadow + { + type wall; + inGroups 1(wall); + nFaces 64; + startFace 25184; + } + Wand_Tussen_Alley_En_Ruimte + { + type wall; + inGroups 1(wall); + nFaces 96; + startFace 25248; + } + Wand_Tussen_Alley_En_Ruimte_shadow + { + type wall; + inGroups 1(wall); + nFaces 96; + startFace 25344; + } + tileX0Y0_master + { + type cyclic; + inGroups 2(cyclic tileX0Y0); + nFaces 4; + startFace 25440; + matchTolerance 0.0001; + transform unknown; + neighbourPatch tileX0Y0_slave; + coupleGroup tileX0Y0; + } + tileX0Y0_slave + { + type cyclic; + inGroups 2(cyclic tileX0Y0); + nFaces 4; + startFace 25444; + matchTolerance 0.0001; + transform unknown; + neighbourPatch tileX0Y0_master; + coupleGroup tileX0Y0; + } + tileX0Y1_master + { + type wall; + inGroups 2(wall tileX0Y1); + nFaces 4; + startFace 25448; + } + tileX0Y1_slave + { + type wall; + inGroups 2(wall tileX0Y1); + nFaces 4; + startFace 25452; + } + tileX1Y0_master + { + type wall; + inGroups 2(wall tileX1Y0); + nFaces 4; + startFace 25456; + } + tileX1Y0_slave + { + type wall; + inGroups 2(wall tileX1Y0); + nFaces 4; + startFace 25460; + } + tileX1Y1_master + { + type cyclic; + inGroups 2(cyclic tileX1Y1); + nFaces 4; + startFace 25464; + matchTolerance 0.0001; + transform unknown; + neighbourPatch tileX1Y1_slave; + coupleGroup tileX1Y1; + } + tileX1Y1_slave + { + type cyclic; + inGroups 2(cyclic tileX1Y1); + nFaces 4; + startFace 25468; + matchTolerance 0.0001; + transform unknown; + neighbourPatch tileX1Y1_master; + coupleGroup tileX1Y1; + } + tileX2Y0_master + { + type cyclic; + inGroups 2(cyclic tileX2Y0); + nFaces 4; + startFace 25472; + matchTolerance 0.0001; + transform unknown; + neighbourPatch tileX2Y0_slave; + coupleGroup tileX2Y0; + } + tileX2Y0_slave + { + type cyclic; + inGroups 2(cyclic tileX2Y0); + nFaces 4; + startFace 25476; + matchTolerance 0.0001; + transform unknown; + neighbourPatch tileX2Y0_master; + coupleGroup tileX2Y0; + } + tileX2Y1_master + { + type wall; + inGroups 2(wall tileX2Y1); + nFaces 4; + startFace 25480; + } + tileX2Y1_slave + { + type wall; + inGroups 2(wall tileX2Y1); + nFaces 4; + startFace 25484; + } + tileX3Y0_master + { + type cyclic; + inGroups 2(cyclic tileX3Y0); + nFaces 4; + startFace 25488; + matchTolerance 0.0001; + transform unknown; + neighbourPatch tileX3Y0_slave; + coupleGroup tileX3Y0; + } + tileX3Y0_slave + { + type cyclic; + inGroups 2(cyclic tileX3Y0); + nFaces 4; + startFace 25492; + matchTolerance 0.0001; + transform unknown; + neighbourPatch tileX3Y0_master; + coupleGroup tileX3Y0; + } + tileX3Y1_master + { + type wall; + inGroups 2(wall tileX3Y1); + nFaces 4; + startFace 25496; + } + tileX3Y1_slave + { + type wall; + inGroups 2(wall tileX3Y1); + nFaces 4; + startFace 25500; + } +) + +// ************************************************************************* // diff --git a/model_openfoam/tests/steadyToyProblem/stochModel/model/constant/polyMesh/cellZones b/model_openfoam/tests/steadyToyProblem/stochModel/model/constant/polyMesh/cellZones new file mode 100644 index 000000000..f2ebdf923 --- /dev/null +++ b/model_openfoam/tests/steadyToyProblem/stochModel/model/constant/polyMesh/cellZones @@ -0,0 +1,7963 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1712 | +| \\ / A nd | Web: www.OpenFOAM.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class regIOobject; + location "constant/polyMesh"; + object cellZones; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +7 +( +rackX0Y0 +{ + type cellZone; +cellLabels List