Skip to content

Commit ebbaa01

Browse files
fix: get direct data offset from the separated dimension (#114)
Fixes #113
1 parent 0d0d40e commit ebbaa01

3 files changed

Lines changed: 190 additions & 21 deletions

File tree

models/directdata/directdata.dat

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,130 @@ h
374374
2050 470
375375
INITIAL TIME
376376
1990 1990
377+
j[A1,B1]
378+
1990 610
379+
1991 609.333
380+
1992 608.667
381+
1993 608
382+
1994 607.333
383+
1995 606.667
384+
1996 606
385+
1997 605.333
386+
1998 604.667
387+
1999 604
388+
2000 603.333
389+
2001 602.667
390+
2002 602
391+
2003 601.333
392+
2004 600.667
393+
2005 600
394+
2006 599
395+
2007 598
396+
2008 597
397+
2009 596
398+
2010 595
399+
2011 594
400+
2012 593
401+
2013 592
402+
2014 591
403+
2015 590
404+
2016 590.2
405+
2017 590.4
406+
2018 590.6
407+
2019 590.8
408+
2020 591
409+
2021 591.2
410+
2022 591.4
411+
2023 591.6
412+
2024 591.8
413+
2025 592
414+
2026 592.2
415+
2027 592.4
416+
2028 592.6
417+
2029 592.8
418+
2030 593
419+
2031 592.5
420+
2032 592
421+
2033 591.5
422+
2034 591
423+
2035 590.5
424+
2036 590
425+
2037 589.5
426+
2038 589
427+
2039 588.5
428+
2040 588
429+
2041 587.5
430+
2042 587
431+
2043 586.5
432+
2044 586
433+
2045 585.5
434+
2046 585
435+
2047 584.5
436+
2048 584
437+
2049 583.5
438+
2050 583
439+
j[A1,B2]
440+
1990 210
441+
1991 209.333
442+
1992 208.667
443+
1993 208
444+
1994 207.333
445+
1995 206.667
446+
1996 206
447+
1997 205.333
448+
1998 204.667
449+
1999 204
450+
2000 203.333
451+
2001 202.667
452+
2002 202
453+
2003 201.333
454+
2004 200.667
455+
2005 200
456+
2006 199
457+
2007 198
458+
2008 197
459+
2009 196
460+
2010 195
461+
2011 194
462+
2012 193
463+
2013 192
464+
2014 191
465+
2015 190
466+
2016 189.667
467+
2017 189.333
468+
2018 189
469+
2019 188.667
470+
2020 188.333
471+
2021 188
472+
2022 187.667
473+
2023 187.333
474+
2024 187
475+
2025 186.667
476+
2026 186.333
477+
2027 186
478+
2028 185.667
479+
2029 185.333
480+
2030 185
481+
2031 184.75
482+
2032 184.5
483+
2033 184.25
484+
2034 184
485+
2035 183.75
486+
2036 183.5
487+
2037 183.25
488+
2038 183
489+
2039 182.75
490+
2040 182.5
491+
2041 182.25
492+
2042 182
493+
2043 181.75
494+
2044 181.5
495+
2045 181.25
496+
2046 181
497+
2047 180.75
498+
2048 180.5
499+
2049 180.25
500+
2050 180
377501
SAVEPER
378502
1990 1
379503
1991 1
@@ -490,3 +614,15 @@ g
490614
2040 17
491615
2045 35
492616
2050 47
617+
i[A1,B1]
618+
1990 610
619+
2005 600
620+
2015 590
621+
2030 593
622+
2050 583
623+
i[A1,B2]
624+
1990 210
625+
2005 200
626+
2015 190
627+
2030 185
628+
2050 180

models/directdata/directdata.mdl

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{UTF-8}
22
DimA: A1, A2 ~~|
3+
DimB: B1, B2 ~~|
34

45
a[DimA] := GET DIRECT DATA('?data', 'A Data', 'A', 'B2') ~~|
56
b[DimA] = a[DimA] * 10 ~~~:SUPPLEMENTARY|
@@ -13,6 +14,12 @@ f[DimA] = e[DimA] * 10 ~~~:SUPPLEMENTARY|
1314
g:= GET DIRECT DATA('g_data.csv', ',', 'A', 'B2') ~~|
1415
h = g * 10 ~~~:SUPPLEMENTARY|
1516

17+
i[A1, DimB] = GET DIRECT DATA('e_data.csv', ',', 'A', 'B2')
18+
~
19+
~ multiple LHS subscripts
20+
|
21+
j[A1, DimB] = i[A1, DimB] ~~~:SUPPLEMENTARY|
22+
1623
********************************************************
1724
.Control
1825
********************************************************~
@@ -27,32 +34,24 @@ TIME STEP = 1 ~~|
2734
\\\---/// Sketch information - do not modify anything except names
2835
V300 Do not put anything below this section - it will be ignored
2936
*View 1
30-
$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
37+
$192-192-192,0,Times New Roman|12||0-0-0|0-0-0|0-0-255|-1--1--1|-1--1--1|96,96,100,0
3138
///---\\\
3239
:L<%^E!@
33-
1:directdata.vdf
34-
9:directdata
35-
30:?data=data.xlsx
36-
15:0,0,0,0,0,0
37-
19:100,0
38-
27:0,
39-
34:0,
40+
1:directdata.vdfx
4041
4:Time
4142
5:FINAL TIME
42-
35:Date
43-
36:YYYY-MM-DD
44-
37:2000
45-
38:1
46-
39:1
47-
40:2
48-
41:0
49-
42:0
43+
6:A1
44+
6:B1
45+
9:directdata
46+
19:100,0
5047
24:1990
5148
25:2050
5249
26:2050
5350
57:1
5451
54:0
5552
55:0
53+
82:0
54+
86:0
5655
59:0
5756
56:0
5857
58:0
@@ -68,4 +67,30 @@ $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
6867
43:directdata
6968
47:directdata
7069
48:
71-
6:A1
70+
30:?data=data.xlsx
71+
15:0,0,0,0,0,0
72+
27:0,
73+
34:0,
74+
42:0
75+
72:0
76+
73:0
77+
35:Date
78+
36:YYYY-MM-DD
79+
37:2000
80+
38:1
81+
39:1
82+
40:2
83+
41:0
84+
95:0
85+
96:0
86+
97:0
87+
77:0
88+
78:0
89+
93:0
90+
94:0
91+
92:0
92+
91:0
93+
90:0
94+
87:0
95+
75:
96+
43:directdata

src/EquationGen.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,19 @@ export default class EquationGen extends ModelReader {
388388
// If the data was found, convert it to a lookup.
389389
if (getCellValue) {
390390
let indexNum = 0
391-
if (!R.isEmpty(this.var.subscripts)) {
391+
if (!R.isEmpty(this.var.separationDims)) {
392392
// Generate a lookup for a separated index in the variable's dimension.
393-
// TODO allow the index to be in either position of a 2D subscript
394-
let ind = sub(this.var.subscripts[0])
395-
indexNum = ind.value
393+
if (this.var.separationDims.length > 1) {
394+
console.error(`WARNING: direct data variable ${this.var.varName} separated on more than one dimension`)
395+
}
396+
let dimName = this.var.separationDims[0]
397+
for (let subscript of this.var.subscripts) {
398+
if (sub(subscript).family === dimName) {
399+
let ind = sub(subscript)
400+
indexNum = ind.value
401+
break
402+
}
403+
}
396404
}
397405
result.push(this.generateDirectDataLookup(getCellValue, timeRowOrCol, startCell, indexNum))
398406
}

0 commit comments

Comments
 (0)