Skip to content

Commit

Permalink
Stricter check for F(REAL):REAL model function.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpyat2 committed Jul 14, 2024
1 parent 1fa7a9e commit 6baa274
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions plugin/src/org/aavso/tools/vstar/external/plugin/VeLaObSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import org.aavso.tools.vstar.util.help.Help;
import org.aavso.tools.vstar.util.locale.LocaleProps;
import org.aavso.tools.vstar.util.prefs.NumericPrecisionPrefs;
import org.aavso.tools.vstar.vela.FunctionExecutor;
import org.aavso.tools.vstar.vela.Operand;
import org.aavso.tools.vstar.vela.Type;
import org.aavso.tools.vstar.vela.VeLaInterpreter;
Expand Down Expand Up @@ -248,13 +249,22 @@ private VeLaInterpreter createVeLaInterpreter(String veLaCode) throws Observatio

// Evaluate the VeLa model code.
vela.program(veLaCode);

// Has a model function been defined?
if (!vela.lookupFunctions(FUNC_NAME).isPresent()) {
throw new ObservationReadError("A function " + FUNC_NAME + "(T:REAL):REAL is not defined in the model");

// Check if a model function "FUNC_NAME(T:REAL):REAL" is defined
Optional<List<FunctionExecutor>> functions = vela.lookupFunctions(FUNC_NAME);
if (functions.isPresent()) {
List<FunctionExecutor> funcExecutors = functions.get();
if (funcExecutors.size() == 1) {
FunctionExecutor executor = funcExecutors.get(0);
List<Type> paramTypes = executor.getParameterTypes();
if (paramTypes != null && paramTypes.size() == 1 && paramTypes.get(0) == Type.REAL) {
Optional<Type> returnType = executor.getReturnType();
if (returnType.isPresent() && returnType.get() == Type.REAL)
return vela;
}
}
}

return vela;
throw new ObservationReadError("A (non-overloaded) model function " + FUNC_NAME + "(T:REAL):REAL must be defined");
}

class VeLaModelObsRetriever extends AbstractObservationRetriever {
Expand Down

0 comments on commit 6baa274

Please sign in to comment.