diff --git a/models/directlookups/directlookups.dat b/models/directlookups/directlookups.dat index e6019688..92f938de 100644 --- a/models/directlookups/directlookups.dat +++ b/models/directlookups/directlookups.dat @@ -1,4 +1,4 @@ -b[A1] +b 2020 0 2021 0.033333 2022 0.066667 @@ -30,72 +30,168 @@ b[A1] 2048 0.933333 2049 0.966667 2050 1 -b[A2] -2020 0 -2021 0 -2022 0.034483 -2023 0.068966 -2024 0.103448 -2025 0.137931 -2026 0.172414 -2027 0.206897 -2028 0.241379 -2029 0.275862 -2030 0.310345 -2031 0.344828 -2032 0.37931 -2033 0.413793 -2034 0.448276 -2035 0.482759 -2036 0.517241 -2037 0.551724 -2038 0.586207 -2039 0.62069 -2040 0.655172 -2041 0.689655 -2042 0.724138 -2043 0.758621 -2044 0.793103 -2045 0.827586 -2046 0.862069 -2047 0.896552 -2048 0.931034 -2049 0.965517 -2050 1 -b[A3] -2020 0 -2021 0.008492 -2022 0.011317 -2023 0.015069 -2024 0.020039 -2025 0.026606 -2026 0.03525 -2027 0.04657 -2028 0.0613 -2029 0.080307 -2030 0.104569 -2031 0.135111 -2032 0.172899 -2033 0.218658 -2034 0.272653 -2035 0.33445 -2036 0.402756 -2037 0.475409 -2038 0.549591 -2039 0.622244 -2040 0.69055 -2041 0.752347 -2042 0.806342 -2043 0.852101 -2044 0.889889 -2045 0.920431 -2046 0.944693 -2047 0.9637 -2048 0.97843 -2049 0.98975 -2050 0.998394 +c +2020 2035 +2021 2035 +2022 2035 +2023 2035 +2024 2035 +2025 2035 +2026 2035 +2027 2035 +2028 2035 +2029 2035 +2030 2035 +2031 2035 +2032 2035 +2033 2035 +2034 2035 +2035 2035 +2036 2035 +2037 2035 +2038 2035 +2039 2035 +2040 2035 +2041 2035 +2042 2035 +2043 2035 +2044 2035 +2045 2035 +2046 2035 +2047 2035 +2048 2035 +2049 2035 +2050 2035 +d +2020 0.3 +2021 0.3 +2022 0.3 +2023 0.3 +2024 0.3 +2025 0.3 +2026 0.3 +2027 0.3 +2028 0.3 +2029 0.3 +2030 0.3 +2031 0.3 +2032 0.3 +2033 0.3 +2034 0.3 +2035 0.3 +2036 0.3 +2037 0.3 +2038 0.3 +2039 0.3 +2040 0.3 +2041 0.3 +2042 0.3 +2043 0.3 +2044 0.3 +2045 0.3 +2046 0.3 +2047 0.3 +2048 0.3 +2049 0.3 +2050 0.3 +e +2020 0.266667 +2021 0.266667 +2022 0.266667 +2023 0.266667 +2024 0.266667 +2025 0.266667 +2026 0.266667 +2027 0.266667 +2028 0.266667 +2029 0.266667 +2030 0.266667 +2031 0.266667 +2032 0.266667 +2033 0.266667 +2034 0.266667 +2035 0.266667 +2036 0.266667 +2037 0.266667 +2038 0.266667 +2039 0.266667 +2040 0.266667 +2041 0.266667 +2042 0.266667 +2043 0.266667 +2044 0.266667 +2045 0.266667 +2046 0.266667 +2047 0.266667 +2048 0.266667 +2049 0.266667 +2050 0.266667 +f +2020 0.269999 +2021 0.269999 +2022 0.269999 +2023 0.269999 +2024 0.269999 +2025 0.269999 +2026 0.269999 +2027 0.269999 +2028 0.269999 +2029 0.269999 +2030 0.269999 +2031 0.269999 +2032 0.269999 +2033 0.269999 +2034 0.269999 +2035 0.269999 +2036 0.269999 +2037 0.269999 +2038 0.269999 +2039 0.269999 +2040 0.269999 +2041 0.269999 +2042 0.269999 +2043 0.269999 +2044 0.269999 +2045 0.269999 +2046 0.269999 +2047 0.269999 +2048 0.269999 +2049 0.269999 +2050 0.269999 FINAL TIME 2020 2050 +h +2020 1 +2021 1 +2022 1 +2023 1 +2024 1 +2025 1 +2026 1 +2027 1 +2028 1 +2029 1 +2030 1 +2031 1 +2032 1 +2033 1 +2034 1 +2035 1 +2036 1 +2037 1 +2038 1 +2039 1 +2040 1 +2041 1 +2042 1 +2043 1 +2044 1 +2045 1 +2046 1 +2047 1 +2048 1 +2049 1 +2050 1 INITIAL TIME 2020 2020 SAVEPER diff --git a/models/directlookups/directlookups.mdl b/models/directlookups/directlookups.mdl index f78e09a9..1d153490 100644 --- a/models/directlookups/directlookups.mdl +++ b/models/directlookups/directlookups.mdl @@ -1,8 +1,45 @@ {UTF-8} DimA: A1, A2, A3 ~~| -a[DimA] = GET DIRECT LOOKUPS('lookup_data.csv', ',', '1', 'E2') ~~| -b[DimA] = a[DimA](Time) ~~~:SUPPLEMENTARY| +a[DimA] = GET DIRECT LOOKUPS('lookup_data.csv', ',', '1', 'E2') + ~ + ~ subscript currently required for GET DIRECT LOOKUPS + | + +b = a[A1](Time) + ~ + ~ access the lookup + | + +c = LOOKUP INVERT(a[A1], 0.5) + ~ + ~ look up y for an x value (returns 2035) + | + +d = LOOKUP FORWARD(a[A1], 2028.1) + ~ + ~ look up using the next x without interpolation (returns 0.3) + | + +e = LOOKUP FORWARD(a[A1], 2028) + ~ + ~ no effect when the x value exists in the lookup (returns 0.266667) + | + +f = a[A1](2028.1) + ~ + ~ regular lookups extrapolate by default + | + +g((0,0),(1,1),(2,2)) + ~ + ~ lookup definition + | + +h = LOOKUP FORWARD(g, 1) + ~ + ~ non-subscripted look up + | ******************************************************** .Control diff --git a/packages/compile/src/generate/equation-gen.js b/packages/compile/src/generate/equation-gen.js index 3730ed5c..f3a93a77 100644 --- a/packages/compile/src/generate/equation-gen.js +++ b/packages/compile/src/generate/equation-gen.js @@ -983,8 +983,9 @@ export default class EquationGen extends ModelReader { // Push the var name on the stack and then emit it. let id = ctx.Id().getText() let varName = canonicalName(id) + let functionName = this.currentFunctionName() if (isDimension(varName)) { - if (this.currentFunctionName() === '_ELMCOUNT') { + if (functionName === '_ELMCOUNT') { // Emit the size of the dimension in place of the dimension name. this.emit(`${sub(varName).size}`) } else { @@ -997,8 +998,8 @@ export default class EquationGen extends ModelReader { } } else { this.varNames.push(varName) - if (this.currentFunctionName() === '_VECTOR_SELECT') { - let argIndex = this.argIndexForFunctionName('_VECTOR_SELECT') + if (functionName === '_VECTOR_SELECT') { + let argIndex = this.argIndexForFunctionName(functionName) if (argIndex === 0) { this.vsSelectionArray = this.currentVarName() super.visitVar(ctx) @@ -1007,30 +1008,42 @@ export default class EquationGen extends ModelReader { } else { super.visitVar(ctx) } - } else if (this.currentFunctionName() === '_VECTOR_ELM_MAP') { - if (this.argIndexForFunctionName('_VECTOR_ELM_MAP') === 1) { + } else if (functionName === '_VECTOR_ELM_MAP') { + if (this.argIndexForFunctionName(functionName) === 1) { this.vemOffset = this.currentVarName() } super.visitVar(ctx) - } else if (this.currentFunctionName() === '_VECTOR_SORT_ORDER') { - if (this.argIndexForFunctionName('_VECTOR_SORT_ORDER') === 0) { + } else if (functionName === '_VECTOR_SORT_ORDER') { + if (this.argIndexForFunctionName(functionName) === 0) { this.vsoVarName = this.currentVarName() this.vsoTmpName = newTmpVarName() this.emit(this.vsoTmpName) } super.visitVar(ctx) - } else if (this.currentFunctionName() === '_ALLOCATE_AVAILABLE') { - if (this.argIndexForFunctionName('_ALLOCATE_AVAILABLE') === 0) { + } else if (functionName === '_ALLOCATE_AVAILABLE') { + if (this.argIndexForFunctionName(functionName) === 0) { this.aaRequestArray = this.currentVarName() this.aaTmpName = newTmpVarName() this.emit(this.aaTmpName) - } else if (this.argIndexForFunctionName('_ALLOCATE_AVAILABLE') === 1) { + } else if (this.argIndexForFunctionName(functionName) === 1) { this.aaPriorityArray = this.currentVarName() } super.visitVar(ctx) - } else if (this.currentFunctionName() === '_GET_DATA_BETWEEN_TIMES') { + } else if (functionName === '_GET_DATA_BETWEEN_TIMES') { this.emit(this.currentVarName()) super.visitVar(ctx) + } else if ( + functionName === '_LOOKUP_FORWARD' || + functionName === '_LOOKUP_BACKWARD' || + functionName === '_LOOKUP_INVERT' + ) { + let argIndex = this.argIndexForFunctionName(functionName) + if (argIndex === 0) { + this.emit(this.currentVarName()) + super.visitVar(ctx) + } else { + emitVar() + } } else { emitVar() }