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