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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions core/java/src/org/openda/blackbox/interfaces/IKeyDateType.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@
* Interface class for key types processing startDate and endDate
*/
public interface IKeyDateType {
/**
* Set start date
*
* @param date double value representing the start date
*/
public void setStartDate(double date);
/**
* Set start date
*
* @param date double value representing the start date
*/
void setStartDate(double date);

/**
* Set end date
* @param date double value representing the end date
*/
public void setEndDate(double date);
/**
* Set end date
* @param date double value representing the end date
*/
void setEndDate(double date);

/**
* Compute string representation of value
* @return interpreted output string
*/
public String calculateValue();
/**
* Compute string representation of value
* @return interpreted output string
*/
String calculateValue();
}
14 changes: 7 additions & 7 deletions core/java/src/org/openda/blackbox/interfaces/IKeyType.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
* Interface class for all key types
*/
public interface IKeyType {
/**
* Returns an interpreted string, where the interpretation of the input string is dependent on the key type.
*
* @param value input string containing a value
* @return interpreted output string
*/
public String getValueAsString(String value);
/**
* Returns an interpreted string, where the interpretation of the input string is dependent on the key type.
*
* @param value input string containing a value
* @return interpreted output string
*/
String getValueAsString(String value);
}
14 changes: 7 additions & 7 deletions core/java/src/org/openda/blackbox/interfaces/IModelFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@
*/
public interface IModelFactory extends IConfigurable {

/**
* Create an instance of the Model
* @param arguments Arguments for this instance. (arguments == null) or (arguments.length == 0) means: no arguments.
* @param outputLevel The level of output to be produced by the new instance (default, suppressed, etc.)
/**
* Create an instance of the Model
* @param arguments Arguments for this instance. (arguments == null) or (arguments.length == 0) means: no arguments.
* @param outputLevel The level of output to be produced by the new instance (default, suppressed, etc.)
* @return The Model instance
*/
IModelInstance getInstance(String[] arguments, IStochModelFactory.OutputLevel outputLevel);
*/
IModelInstance getInstance(String[] arguments, IStochModelFactory.OutputLevel outputLevel);

/**
* Shut down the model factory.
*/
void finish();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
* after the initialize method of the (stoch)ModelFactory has been called.
*/
public interface ITimeHorizonConsumer {
public void setTimeHorizon(ITime timeHorizon);
void setTimeHorizon(ITime timeHorizon);
}
26 changes: 13 additions & 13 deletions core/java/src/org/openda/blackbox/interfaces/IoObjectInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@
*/
public interface IoObjectInterface {

/**
* Initialize the IoObject
* @param workingDir Working directory
* @param fileName The name of the file containing the data (relative to the working dir.)
* @param arguments Additional arguments (may be null zero-length)
*/
public void initialize(File workingDir, String fileName, String[] arguments);
/**
* Initialize the IoObject
* @param workingDir Working directory
* @param fileName The name of the file containing the data (relative to the working dir.)
* @param arguments Additional arguments (may be null zero-length)
*/
void initialize(File workingDir, String fileName, String[] arguments);

/**
* Ask which elements can be accessed
* @return The list of element identifiers that can be accessed
*/
public IPrevExchangeItem[] getExchangeItems(); //
/**
* Ask which elements can be accessed
* @return The list of element identifiers that can be accessed
*/
IPrevExchangeItem[] getExchangeItems(); //

public void finish();
void finish();
}
32 changes: 16 additions & 16 deletions core/java/src/org/openda/blackbox/interfaces/SelectorInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@
*/
public interface SelectorInterface {

/**
* Initalize the selector
* @param workingDir Working directory
* @param arguments Configuration arguments
*/
void initialize(File workingDir, String[] arguments);
/**
* Initalize the selector
* @param workingDir Working directory
* @param arguments Configuration arguments
*/
void initialize(File workingDir, String[] arguments);

/**
* Apply this selector
* @param inputObject The input object for the selection
* @return The resulting selection
*/
public Object select(Object inputObject);
* @param inputObject The input object for the selection
* @return The resulting selection
*/
Object select(Object inputObject);

/**
* Apply this selector in the inversion way
* @param selection Result of a previous select() call
* @return The adjusted original input for the selection
*/
public Object deselect(Object selection);
/**
* Apply this selector in the inversion way
* @param selection Result of a previous select() call
* @return The adjusted original input for the selection
*/
Object deselect(Object selection);

}
8 changes: 4 additions & 4 deletions core/java/src/org/openda/blackbox/wrapper/ArmaNoiseModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ public class ArmaNoiseModel {

private static DistributedCounter instanceCount = new DistributedCounter(0);

private int stateVectorSize = Integer.MIN_VALUE;
private double[] armaConstants = null;
private int stateVectorSize;
private double[] armaConstants;
private boolean useRandomSeed = false;

private NormalDistribution normalDistribution = null;

private int instanceNumber = Integer.MIN_VALUE;
private int instanceNumber;
private int realizationCounter = 0;

// state vector for each previous arma step,
// and 1 for the current state (index 0)
private double[][] noiseStateVector = null;
private double[][] noiseStateVector;

private ITime currentTime = null;
private File logFile = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,35 +71,24 @@
@SuppressWarnings("unused")
public class AsciiKeywordDataObject implements IDataObject{

private static final Logger logger = LoggerFactory.getLogger(AsciiKeywordDataObject.class);
MessageFormat logFormatter = new MessageFormat("");
private static final Logger logger = LoggerFactory.getLogger(AsciiKeywordDataObject.class);
private MessageFormat logFormatter = new MessageFormat("");

private String fileName = null;
private String fileName = null;
private static final String keyWordPrefix ="#oda:";
private static final String multiplexId ="@";
private static final String arrayRegex = "\\[|\\]|\\s|,|\\(|\\)";
private HashMap<String,IExchangeItem> items = new LinkedHashMap<>();
private HashMap<String,Integer> multiplexColumn = new LinkedHashMap<>();
private HashMap<String,Integer> multiplexColumn = new LinkedHashMap<>();
private ArrayList<String> fileContent = new ArrayList<>();
private double referenceMjd = 0.0;
private static final double SECONDS_TO_DAYS = 1.0 / 24.0 / 60.0 / 60.0;
private final List<String> timeExchangeItemIds = Arrays.asList("oda:startTime","oda:endTime");
private boolean convertTime = false;
static private final String WITH_DELIMITER = "((?<=%1$s)|(?=%1$s))";

/**
* Reads OpenFoam results generated by the sample utility.
*
* @param workingDir the working directory.
* @param arguments list of other arguments:
* <ol>
* <li>The name of the file containing the data
* for this IoObject (relative to the working directory).</li>
* <li>Optional, a referenceDate in ISO 8601 notatation, e.g
* for this IoObject (relative to the working directory).</li>
*
* </ol>
*/
/** {@inheritDoc}
*/
public void initialize(File workingDir, String[] arguments) {

if ( arguments.length == 0 ) {
Expand All @@ -117,7 +106,7 @@ public void initialize(File workingDir, String[] arguments) {
try{
inputFile = new File(workingDir,fileName);
if(!inputFile.isFile()){
throw new IOException("Can not find file " + inputFile);
throw new IOException("Cannot find file " + inputFile);
}
this.fileName = inputFile.getCanonicalPath();
}catch (Exception e) {
Expand All @@ -128,17 +117,13 @@ public void initialize(File workingDir, String[] arguments) {
Scanner scanner = new Scanner(inputFile);
scanner.useLocale(Locale.US);

//FileInputStream in = new FileInputStream(inputFile);
//BufferedReader buff = new BufferedReader(new InputStreamReader(in));

String line;
logger.debug("Reading file");
logger.debug("Reading file");
while (scanner.hasNext()) {

line = scanner.nextLine();
fileContent.add(line);
int locationIndex = line.indexOf(keyWordPrefix);
//Scanner lineScanner = new Scanner(line);
if (locationIndex > 0) {
logger.trace("Read line: "+ line);
String valueString="";
Expand All @@ -150,15 +135,14 @@ public void initialize(File workingDir, String[] arguments) {
Vector<Double> values = new Vector<>();
Vector<Integer> column = new Vector<>();
for ( int index=0; index < parts.length ;index++) {
//for ( String part : parts) {
if (!parts[index].isEmpty()) {
try {
Double value = Double.parseDouble(parts[index]);
values.add(value);
column.add(index);
logger.debug("Found value part " + parts[index]);
} catch (NumberFormatException e) {
logger.trace("Skipping " + parts[index]);
logger.trace("Skipping " + parts[index]);
}
}
}
Expand Down Expand Up @@ -188,7 +172,7 @@ public void initialize(File workingDir, String[] arguments) {
} catch (Exception e) {
throw new RuntimeException("Problem reading from file " + fileName+" : "+e.getClass());
}
}
}

/** {@inheritDoc}
*/
Expand All @@ -214,32 +198,30 @@ 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) {
//TODO: select on role
return items.keySet().toArray(new String[items.size()]);
return items.keySet().toArray(new String[0]);
}

/** {@inheritDoc}
*/
public void finish() {
//write to file
//write to file
File outputFile = new File(fileName);
try{
if(outputFile.isFile()){
if ( ! outputFile.delete() ) throw new RuntimeException("Cannot delete " + outputFile);
}
if (outputFile.isFile() && !outputFile.delete()) throw new RuntimeException("Cannot delete " + outputFile);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}catch (Exception e) {
logger.error("DictionaryDataObject: trouble removing file " + this.fileName +" :\n" + e.getMessage());
}
try {
FileWriter writer = new FileWriter(outputFile);
BufferedWriter out = new BufferedWriter(writer);
for (String line: fileContent){
for (String line: fileContent){
int locationIndex = line.indexOf(keyWordPrefix);
//Scanner lineScanner = new Scanner(line);
if (locationIndex > 0) {
Expand All @@ -251,21 +233,21 @@ public void finish() {
String[] parts = line.split(String.format(WITH_DELIMITER, arrayRegex));
if (multiplexColumn.containsKey(key)) {
int index = multiplexColumn.get(key);
Double paramValue = (Double) items.get(key).getValues();
if (timeExchangeItemIds.contains(key) && convertTime) {
logger.debug("Converting to MJD: " + key);
paramValue = (paramValue - referenceMjd ) / SECONDS_TO_DAYS;
}
logger.debug("Store value: " + paramValue);
parts[index] = Double.toString(paramValue);
Double paramValue = (Double) items.get(key).getValues();
if (timeExchangeItemIds.contains(key) && convertTime) {
logger.debug("Converting to MJD: " + key);
paramValue = (paramValue - referenceMjd ) / SECONDS_TO_DAYS;
}
logger.debug("Store value: " + paramValue);
parts[index] = Double.toString(paramValue);
}
int nr = 1;
while (multiplexColumn.containsKey(key + multiplexId + nr)) {
String id = key + multiplexId + nr;
int index = multiplexColumn.get(id);
Double paramValue = (Double) items.get(id).getValues();
logger.debug("Store value part: " + paramValue);
parts[index] = Double.toString(paramValue);
parts[index] = Double.toString(paramValue);
nr++;
}
StringBuilder builder = new StringBuilder();
Expand All @@ -276,15 +258,15 @@ public void finish() {
logger.trace("Write line: " + outputLine);
out.write(outputLine);
}
else {
//Write Line
out.write(line + "\n");
}
}
else {
//Write Line
out.write(line + "\n");
}
}
out.close();
} catch (Exception e) {

throw new RuntimeException("DictionaryDataObject: Problem writing to file " + this.fileName+" :\n" + e.getMessage());
}
}
}
}
Loading