Skip to content

Commit

Permalink
feat: add support for external data variables that use subscript or d…
Browse files Browse the repository at this point in the history
…imension (#41)

Fixes #32
  • Loading branch information
chrispcampbell authored Sep 13, 2020
1 parent a6e0ca4 commit 035ab5c
Show file tree
Hide file tree
Showing 6 changed files with 492 additions and 31 deletions.
90 changes: 90 additions & 0 deletions models/extdata/data.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
Simple 1
0 1000
1 2000
2 3000
9 4000
10 5000
Simple 2
0 100
1 200
2 300
9 400
10 500
A Values[A1]
0 0
1 10
2 20
9 70
10 80
A Values[A2]
0 10
1 20
2 30
9 80
10 90
A Values[A3]
0 20
1 30
2 40
9 90
10 100
BC Values[B1,C1]
0 0
1 10
2 20
9 70
10 80
BC Values[B1,C2]
0 10
1 20
2 30
9 80
10 90
BC Values[B2,C1]
0 100
1 110
2 120
9 170
10 180
BC Values[B2,C2]
0 110
1 120
2 130
9 180
10 190
BC Values[B3,C1]
0 200
1 210
2 220
9 270
10 280
BC Values[B3,C2]
0 210
1 220
2 230
9 280
10 290
D Values[D1]
0 5000
1 5100
2 5200
9 5300
10 5400
D Values[D2]
0 6000
1 6100
2 6200
9 6300
10 6400
E Values[E1]
0 7000
1 7100
2 7200
9 7300
10 7400
E Values[E2]
0 8000
1 8100
2 8200
9 8300
10 8400
180 changes: 180 additions & 0 deletions models/extdata/extdata.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
A Totals
0 30
1 60
2 90
3 111.429
4 132.857
5 154.286
6 175.714
7 197.143
8 218.571
9 240
10 270
B1 Totals
0 10
1 30
2 50
3 64.2857
4 78.5714
5 92.8571
6 107.143
7 121.429
8 135.714
9 150
10 170
D Totals
0 11000
1 11200
2 11400
3 11428.6
4 11457.1
5 11485.7
6 11514.3
7 11542.9
8 11571.4
9 11600
10 11800
E1 Values
0 7000
1 7100
2 7200
3 7214.29
4 7228.57
5 7242.86
6 7257.14
7 7271.43
8 7285.71
9 7300
10 7400
E2 Values
0 8000
1 8100
2 8200
3 8214.29
4 8228.57
5 8242.86
6 8257.14
7 8271.43
8 8285.71
9 8300
10 8400
FINAL TIME
0 10
INITIAL TIME
0 0
SAVEPER
0 1
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
Simple Totals
0 1100
1 2200
2 3300
3 3457.14
4 3614.29
5 3771.43
6 3928.57
7 4085.71
8 4242.86
9 4400
10 5500
TIME STEP
0 1
A Values[A1]
0 0
1 10
2 20
9 70
10 80
A Values[A2]
0 10
1 20
2 30
9 80
10 90
A Values[A3]
0 20
1 30
2 40
9 90
10 100
BC Values[B1,C1]
0 0
1 10
2 20
9 70
10 80
BC Values[B1,C2]
0 10
1 20
2 30
9 80
10 90
BC Values[B2,C1]
0 100
1 110
2 120
9 170
10 180
BC Values[B2,C2]
0 110
1 120
2 130
9 180
10 190
BC Values[B3,C1]
0 200
1 210
2 220
9 270
10 280
BC Values[B3,C2]
0 210
1 220
2 230
9 280
10 290
D Values[D1]
0 5000
1 5100
2 5200
9 5300
10 5400
D Values[D2]
0 6000
1 6100
2 6200
9 6300
10 6400
E Values[E1]
0 7000
1 7100
2 7200
9 7300
10 7400
E Values[E2]
0 8000
1 8100
2 8200
9 8300
10 8400
Simple 1
0 1000
1 2000
2 3000
9 4000
10 5000
Simple 2
0 100
1 200
2 300
9 400
10 500
88 changes: 88 additions & 0 deletions models/extdata/extdata.mdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{UTF-8}

DimA: A1, A2, A3
~~|

DimB: B1, B2, B3
~~|

DimC: C1, C2
~~|

DimD: D1, D2 -> DimC
~~|

DimE: E1, E2
~~|

Simple 1
~~|

Simple 2
~~|

A Values[DimA]
~~|

BC Values[DimB,DimC]
~~|

D Values[DimD]
~~|

E Values[E1]
~~|

E Values[E2]
~~|

Simple Totals =
Simple 1 + Simple 2
~~|

A Totals =
SUM( A Values[DimA!] )
~~|

B1 Totals =
SUM( BC Values[B1,DimC!] )
~~|

D Totals =
SUM( D Values[DimD!] )
~~|

E1 Values =
E Values[E1]
~~|

E2 Values =
E Values[E2]
~~|

********************************************************
.Control
********************************************************~
Simulation Control Parameters
|

FINAL TIME = 10
~ Month
~ The final time for the simulation.
|

INITIAL TIME = 0
~ Month
~ The initial time for the simulation.
|

SAVEPER =
TIME STEP
~ Month [0,?]
~ The frequency with which output is stored.
|

TIME STEP = 1
~ Month [0,?]
~ The time step for the simulation.
|
6 changes: 6 additions & 0 deletions models/extdata/spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "extdata",
"externalDatfiles": [
"data.dat"
]
}
1 change: 1 addition & 0 deletions src/CodeGen.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ ${dimensionMappingsSection()}
// Lookup data arrays
${section(Model.lookupVars())}
${section(Model.dataVars())}
`
}

Expand Down
Loading

0 comments on commit 035ab5c

Please sign in to comment.