1: package com.aimms.aimmssdk.examples.procedureargs; 2: 3: import com.aimms.aimmssdk.*; 4: import org.slf4j.Logger; 5: import org.slf4j.LoggerFactory; 6: 7: /** 8: * This example demonstrates the use of a procedure with arguments. 9: * Procedure arguments can be supplied in two ways: 10: * - Locals can be retrieved using getArgument. This yields an IData object 11: * which can be cast to the actual class and can be used to read/write data directly into 12: * those locals. 13: * - Global arguments can be used. 14: */ 15: class ProcedureArgs { 16: 17: static private Logger logger = LoggerFactory.getLogger(ProcedureArgs.class); 18: 19: static void run(ISession session) { 20: // retrieve the procedure 21: IProcedure maxCheck = session.openProcedure("MaxCheck"); 22: 23: // MaxCheck verifies that all values of P1(argument0) are less or equal to MaxValue(argument1). 24: // If so, it returns 1, else it returns 0. 25: 26: // the formal signature of MaxCheck: 27: // argument0: input; double parameter over FilledSet 28: // argument1: input; double parameter Scalar 29: 30: // Since we do not have scalar to supply as second argument, we use the argument of the procedure directly: 31: IData arg = maxCheck.getArgument(1); 32: assert (arg.getType() == DataType.tScalar); 33: assert (arg.getValueType() == ValueType.vtDouble); 34: IScalarData maxValue = (IScalarData) (arg); 35: maxValue.setValue(50.0); 36: 37: // We also need to open the parameter to be checked. 38: IMultiDimData testparameter = session.openMultiDim("FilledParameter"); 39: 40: // Determine whether filledparameter has no value over 50: 41: int result = maxCheck.run(testparameter, maxValue); 42: 43: // Since the maximum is 9 the result will be true: 44: logger.info("result={}; expected 1", result); 45: assert (result == 1); 46: 47: // Determine whether filledparameter does have a value over 5: 48: maxValue.setValue(5.0); 49: result = maxCheck.run(testparameter, maxValue); 50: 51: // Since the maximum is 9 the result will be false: 52: logger.info("result={}; expected 0", result); 53: assert (result == 0); 54: 55: testparameter.close(); 56: 57: // A procedure will close its arguments, so MaxValue does not need to be closed, although it is allowed. 58: maxValue.close(); 59: maxCheck.close(); 60: } 61: }