diff --git a/models/lookup/lookup.dat b/models/lookup/lookup.dat index f887b0a4..0c1bfb5c 100644 --- a/models/lookup/lookup.dat +++ b/models/lookup/lookup.dat @@ -8,7 +8,7 @@ b 6 0 7 1.19209e-08 8 0.1 -9 0.899999 +9 0.9 10 -1 d 0 0 @@ -72,7 +72,43 @@ f 10 20 FINAL TIME 0 10 -g1 +g at 0 backward +0 0 +1 0 +2 0 +3 0 +4 0 +5 0 +6 0 +7 0 +8 0 +9 0 +10 0 +g at 0 forward +0 0 +1 0 +2 0 +3 0 +4 0 +5 0 +6 0 +7 0 +8 0 +9 0 +10 0 +g at 0pt5 backward +0 0 +1 0 +2 0 +3 0 +4 0 +5 0 +6 0 +7 0 +8 0 +9 0 +10 0 +g at 0pt5 forward 0 1 1 1 2 1 @@ -84,31 +120,19 @@ g1 8 1 9 1 10 1 -g2 -0 2 -1 2 -2 2 -3 2 -4 2 -5 2 -6 2 -7 2 -8 2 -9 2 -10 2 -g3 -0 2 -1 2 -2 2 -3 2 -4 2 -5 2 -6 2 -7 2 -8 2 -9 2 -10 2 -g4 +g at 1pt0 backward +0 1 +1 1 +2 1 +3 1 +4 1 +5 1 +6 1 +7 1 +8 1 +9 1 +10 1 +g at 1pt0 forward 0 1 1 1 2 1 @@ -120,7 +144,7 @@ g4 8 1 9 1 10 1 -g5 +g at 1pt5 backward 0 1 1 1 2 1 @@ -132,7 +156,31 @@ g5 8 1 9 1 10 1 -g6 +g at 1pt5 forward +0 2 +1 2 +2 2 +3 2 +4 2 +5 2 +6 2 +7 2 +8 2 +9 2 +10 2 +g at 2pt0 backward +0 2 +1 2 +2 2 +3 2 +4 2 +5 2 +6 2 +7 2 +8 2 +9 2 +10 2 +g at 2pt0 forward 0 2 1 2 2 2 @@ -144,6 +192,54 @@ g6 8 2 9 2 10 2 +g at 2pt5 backward +0 2 +1 2 +2 2 +3 2 +4 2 +5 2 +6 2 +7 2 +8 2 +9 2 +10 2 +g at 2pt5 forward +0 2 +1 2 +2 2 +3 2 +4 2 +5 2 +6 2 +7 2 +8 2 +9 2 +10 2 +g at minus 1 backward +0 0 +1 0 +2 0 +3 0 +4 0 +5 0 +6 0 +7 0 +8 0 +9 0 +10 0 +g at minus 1 forward +0 0 +1 0 +2 0 +3 0 +4 0 +5 0 +6 0 +7 0 +8 0 +9 0 +10 0 i 0 0 1 0.1 @@ -172,3 +268,87 @@ SAVEPER 10 1 TIME STEP 0 1 +withlookup at 0 +0 0 +1 0 +2 0 +3 0 +4 0 +5 0 +6 0 +7 0 +8 0 +9 0 +10 0 +withlookup at 0pt5 +0 0.5 +1 0.5 +2 0.5 +3 0.5 +4 0.5 +5 0.5 +6 0.5 +7 0.5 +8 0.5 +9 0.5 +10 0.5 +withlookup at 1pt0 +0 1 +1 1 +2 1 +3 1 +4 1 +5 1 +6 1 +7 1 +8 1 +9 1 +10 1 +withlookup at 1pt5 +0 1.5 +1 1.5 +2 1.5 +3 1.5 +4 1.5 +5 1.5 +6 1.5 +7 1.5 +8 1.5 +9 1.5 +10 1.5 +withlookup at 2pt0 +0 2 +1 2 +2 2 +3 2 +4 2 +5 2 +6 2 +7 2 +8 2 +9 2 +10 2 +withlookup at 2pt5 +0 2 +1 2 +2 2 +3 2 +4 2 +5 2 +6 2 +7 2 +8 2 +9 2 +10 2 +withlookup at minus 1 +0 0 +1 0 +2 0 +3 0 +4 0 +5 0 +6 0 +7 0 +8 0 +9 0 +10 0 diff --git a/models/lookup/lookup.mdl b/models/lookup/lookup.mdl index 03ebb7ec..f1d45165 100755 --- a/models/lookup/lookup.mdl +++ b/models/lookup/lookup.mdl @@ -52,39 +52,114 @@ f = c[A1](i) ~ ~ :SUPPLEMENTARY | -g((0,1),(1,1),(2,2)) +g((0,0),(1,1),(2,2)) ~ ~ lookup definition | -g1 = LOOKUP FORWARD(g,-1) - ~ - ~ ~ :SUPPLEMENTARY +g at minus 1 forward = LOOKUP FORWARD(g,-1) + ~ + ~ ~ :SUPPLEMENTARY | -g2 = LOOKUP FORWARD(g,1.5) - ~ - ~ ~ :SUPPLEMENTARY +g at 0 forward = LOOKUP FORWARD(g,0) + ~ + ~ ~ :SUPPLEMENTARY | -g3 = LOOKUP FORWARD(g,2.5) - ~ - ~ ~ :SUPPLEMENTARY +g at 0pt5 forward = LOOKUP FORWARD(g,0.5) + ~ + ~ ~ :SUPPLEMENTARY | -g4 = LOOKUP BACKWARD(g,-1) - ~ - ~ ~ :SUPPLEMENTARY +g at 1pt0 forward = LOOKUP FORWARD(g,1.0) + ~ + ~ ~ :SUPPLEMENTARY | -g5 = LOOKUP BACKWARD(g,1.5) - ~ - ~ ~ :SUPPLEMENTARY +g at 1pt5 forward = LOOKUP FORWARD(g,1.5) + ~ + ~ ~ :SUPPLEMENTARY | -g6 = LOOKUP BACKWARD(g,2.5) - ~ - ~ ~ :SUPPLEMENTARY +g at 2pt0 forward = LOOKUP FORWARD(g,2.0) + ~ + ~ ~ :SUPPLEMENTARY + | + +g at 2pt5 forward = LOOKUP FORWARD(g,2.5) + ~ + ~ ~ :SUPPLEMENTARY + | + +g at minus 1 backward = LOOKUP BACKWARD(g,-1) + ~ + ~ ~ :SUPPLEMENTARY + | + +g at 0 backward = LOOKUP BACKWARD(g,0) + ~ + ~ ~ :SUPPLEMENTARY + | + +g at 0pt5 backward = LOOKUP BACKWARD(g,0.5) + ~ + ~ ~ :SUPPLEMENTARY + | + +g at 1pt0 backward = LOOKUP BACKWARD(g,1.0) + ~ + ~ ~ :SUPPLEMENTARY + | + +g at 1pt5 backward = LOOKUP BACKWARD(g,1.5) + ~ + ~ ~ :SUPPLEMENTARY + | + +g at 2pt0 backward = LOOKUP BACKWARD(g,2.0) + ~ + ~ ~ :SUPPLEMENTARY + | + +g at 2pt5 backward = LOOKUP BACKWARD(g,2.5) + ~ + ~ ~ :SUPPLEMENTARY + | + +withlookup at minus 1 = WITH LOOKUP ( -1, ([(0,0)-(2,2)],(0,0),(1,1),(2,2)) ) + ~ + ~ ~ :SUPPLEMENTARY + | + +withlookup at 0 = WITH LOOKUP ( 0, ([(0,0)-(2,2)],(0,0),(1,1),(2,2)) ) + ~ + ~ ~ :SUPPLEMENTARY + | + +withlookup at 0pt5 = WITH LOOKUP ( 0.5, ([(0,0)-(2,2)],(0,0),(1,1),(2,2)) ) + ~ + ~ ~ :SUPPLEMENTARY + | + +withlookup at 1pt0 = WITH LOOKUP ( 1.0, ([(0,0)-(2,2)],(0,0),(1,1),(2,2)) ) + ~ + ~ ~ :SUPPLEMENTARY + | + +withlookup at 1pt5 = WITH LOOKUP ( 1.5, ([(0,0)-(2,2)],(0,0),(1,1),(2,2)) ) + ~ + ~ ~ :SUPPLEMENTARY + | + +withlookup at 2pt0 = WITH LOOKUP ( 2.0, ([(0,0)-(2,2)],(0,0),(1,1),(2,2)) ) + ~ + ~ ~ :SUPPLEMENTARY + | + +withlookup at 2pt5 = WITH LOOKUP ( 2.5, ([(0,0)-(2,2)],(0,0),(1,1),(2,2)) ) + ~ + ~ ~ :SUPPLEMENTARY | ******************************************************** @@ -119,16 +194,47 @@ V300 Do not put anything below this section - it will be ignored *View 1 $192-192-192,0,Times New Roman|12||0-0-0|0-0-0|0-0-255|-1--1--1|-1--1--1|0,0,100,0 ///---\\\ -:L<%^E!@ -1:lookup.vdf -9:lookup -15:0,0,0,0,0,0 -19:100,0 -27:2, -34:0, -4:Time -5:d -24:0 -25:10 -26:10 -6:A1 +:L<%^E!@ +1:lookup.vdfx +9:lookup +15:0,0,0,0,0,0 +19:100,0 +27:2, +34:0, +42:0 +72:0 +73:0 +4:Time +5:c[DimA] +76:0 +77:0 +78:0 +79:0 +80:0 +81:0 +24:0 +25:10 +26:10 +57:1 +54:0 +55:0 +82:0 +86:0 +59:0 +56:0 +58:0 +71:0 +44:65001 +46:0 +45:0 +49:0 +50:0 +51: +52: +53: +43:lookup +47:lookup +48: +75: +43:lookup +6:A1 diff --git a/src/c/vensim.c b/src/c/vensim.c index c2babb3c..fe4f951c 100644 --- a/src/c/vensim.c +++ b/src/c/vensim.c @@ -94,6 +94,7 @@ void __print_lookup(Lookup* lookup) { } } } + double __lookup(double* data, size_t n, double input, LookupMode mode) { // Interpolate the y value from an array of (x,y) pairs. // NOTE: The x values are assumed to be monotonically increasing. @@ -124,11 +125,7 @@ double __lookup(double* data, size_t n, double input, LookupMode mode) { } case Forward: { // Return the next y value without interpolating. - if (xi + 3 < max) { - return data[xi + 3]; - } else { - return data[max - 1]; - } + return data[xi + 1]; } case Backward: // Return the previous y value without interpolating. @@ -140,6 +137,7 @@ double __lookup(double* data, size_t n, double input, LookupMode mode) { // The input is greater than all the x values, so return the high end of the range. return data[max - 1]; } + double _LOOKUP_INVERT(Lookup* lookup, double y) { if (lookup->inverted_data == NULL) { // Invert the matrix and cache it.