diff --git a/models/arrays_cname/arrays_cname.dat b/models/arrays_cname/arrays_cname.dat index 4ae53bc3..d4c73e05 100644 --- a/models/arrays_cname/arrays_cname.dat +++ b/models/arrays_cname/arrays_cname.dat @@ -101,6 +101,222 @@ inputAB[A3,B2] 0 18 inputAB[A3,B3] 0 19 +ndim4[A1,B1,C1,D1] +0 4 +ndim4[A1,B1,C1,D2] +0 4 +ndim4[A1,B1,C1,D3] +0 4 +ndim4[A1,B1,C1,D4] +0 4 +ndim4[A1,B1,C2,D1] +0 4 +ndim4[A1,B1,C2,D2] +0 4 +ndim4[A1,B1,C2,D3] +0 4 +ndim4[A1,B1,C2,D4] +0 4 +ndim4[A1,B1,C3,D1] +0 4 +ndim4[A1,B1,C3,D2] +0 4 +ndim4[A1,B1,C3,D3] +0 4 +ndim4[A1,B1,C3,D4] +0 4 +ndim4[A1,B2,C1,D1] +0 4 +ndim4[A1,B2,C1,D2] +0 4 +ndim4[A1,B2,C1,D3] +0 4 +ndim4[A1,B2,C1,D4] +0 4 +ndim4[A1,B2,C2,D1] +0 4 +ndim4[A1,B2,C2,D2] +0 4 +ndim4[A1,B2,C2,D3] +0 4 +ndim4[A1,B2,C2,D4] +0 4 +ndim4[A1,B2,C3,D1] +0 4 +ndim4[A1,B2,C3,D2] +0 4 +ndim4[A1,B2,C3,D3] +0 4 +ndim4[A1,B2,C3,D4] +0 4 +ndim4[A1,B3,C1,D1] +0 4 +ndim4[A1,B3,C1,D2] +0 4 +ndim4[A1,B3,C1,D3] +0 4 +ndim4[A1,B3,C1,D4] +0 4 +ndim4[A1,B3,C2,D1] +0 4 +ndim4[A1,B3,C2,D2] +0 4 +ndim4[A1,B3,C2,D3] +0 4 +ndim4[A1,B3,C2,D4] +0 4 +ndim4[A1,B3,C3,D1] +0 4 +ndim4[A1,B3,C3,D2] +0 4 +ndim4[A1,B3,C3,D3] +0 4 +ndim4[A1,B3,C3,D4] +0 4 +ndim4[A2,B1,C1,D1] +0 4 +ndim4[A2,B1,C1,D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[A3,B1,C3,D3] +0 4 +ndim4[A3,B1,C3,D4] +0 4 +ndim4[A3,B2,C1,D1] +0 4 +ndim4[A3,B2,C1,D2] +0 4 +ndim4[A3,B2,C1,D3] +0 4 +ndim4[A3,B2,C1,D4] +0 4 +ndim4[A3,B2,C2,D1] +0 4 +ndim4[A3,B2,C2,D2] +0 4 +ndim4[A3,B2,C2,D3] +0 4 +ndim4[A3,B2,C2,D4] +0 4 +ndim4[A3,B2,C3,D1] +0 4 +ndim4[A3,B2,C3,D2] +0 4 +ndim4[A3,B2,C3,D3] +0 4 +ndim4[A3,B2,C3,D4] +0 4 +ndim4[A3,B3,C1,D1] +0 4 +ndim4[A3,B3,C1,D2] +0 4 +ndim4[A3,B3,C1,D3] +0 4 +ndim4[A3,B3,C1,D4] +0 4 +ndim4[A3,B3,C2,D1] +0 4 +ndim4[A3,B3,C2,D2] +0 4 +ndim4[A3,B3,C2,D3] +0 4 +ndim4[A3,B3,C2,D4] +0 4 +ndim4[A3,B3,C3,D1] +0 4 +ndim4[A3,B3,C3,D2] +0 4 +ndim4[A3,B3,C3,D3] +0 4 +ndim4[A3,B3,C3,D4] +0 4 o[B1] 0 42 1 42 diff --git a/models/arrays_cname/arrays_cname.mdl b/models/arrays_cname/arrays_cname.mdl index cfe32687..a347137d 100755 --- a/models/arrays_cname/arrays_cname.mdl +++ b/models/arrays_cname/arrays_cname.mdl @@ -150,6 +150,11 @@ z[C2, DimA, DimB]= ~ 2D constant array with additional index subscript (2/2) | +ndim4[DimA, DimB, DimC, DimD] = 4 + ~ + ~ 4D constant array + | + INITIAL TIME = 0 ~~| FINAL TIME = 1 ~~| TIME STEP = 1 ~~| diff --git a/models/arrays_cname/arrays_cname_spec.json b/models/arrays_cname/arrays_cname_spec.json index 6270cc30..30bc5d1a 100644 --- a/models/arrays_cname/arrays_cname_spec.json +++ b/models/arrays_cname/arrays_cname_spec.json @@ -30,6 +30,7 @@ "_sc[1][2]", "_sc[2][0]", "_sc[2][1]", - "_sc[2][2]" + "_sc[2][2]", + "_ndim4[2][2][2][3]" ] } diff --git a/models/arrays_varname/arrays_varname.dat b/models/arrays_varname/arrays_varname.dat index aac7ccf6..d4c73e05 100644 --- a/models/arrays_varname/arrays_varname.dat +++ b/models/arrays_varname/arrays_varname.dat @@ -101,6 +101,222 @@ inputAB[A3,B2] 0 18 inputAB[A3,B3] 0 19 +ndim4[A1,B1,C1,D1] +0 4 +ndim4[A1,B1,C1,D2] +0 4 +ndim4[A1,B1,C1,D3] +0 4 +ndim4[A1,B1,C1,D4] +0 4 +ndim4[A1,B1,C2,D1] +0 4 +ndim4[A1,B1,C2,D2] +0 4 +ndim4[A1,B1,C2,D3] +0 4 +ndim4[A1,B1,C2,D4] +0 4 +ndim4[A1,B1,C3,D1] +0 4 +ndim4[A1,B1,C3,D2] +0 4 +ndim4[A1,B1,C3,D3] +0 4 +ndim4[A1,B1,C3,D4] +0 4 +ndim4[A1,B2,C1,D1] +0 4 +ndim4[A1,B2,C1,D2] +0 4 +ndim4[A1,B2,C1,D3] +0 4 +ndim4[A1,B2,C1,D4] +0 4 +ndim4[A1,B2,C2,D1] +0 4 +ndim4[A1,B2,C2,D2] +0 4 +ndim4[A1,B2,C2,D3] +0 4 +ndim4[A1,B2,C2,D4] +0 4 +ndim4[A1,B2,C3,D1] +0 4 +ndim4[A1,B2,C3,D2] +0 4 +ndim4[A1,B2,C3,D3] +0 4 +ndim4[A1,B2,C3,D4] +0 4 +ndim4[A1,B3,C1,D1] +0 4 +ndim4[A1,B3,C1,D2] +0 4 +ndim4[A1,B3,C1,D3] +0 4 +ndim4[A1,B3,C1,D4] +0 4 +ndim4[A1,B3,C2,D1] +0 4 +ndim4[A1,B3,C2,D2] +0 4 +ndim4[A1,B3,C2,D3] +0 4 +ndim4[A1,B3,C2,D4] +0 4 +ndim4[A1,B3,C3,D1] +0 4 +ndim4[A1,B3,C3,D2] +0 4 +ndim4[A1,B3,C3,D3] +0 4 +ndim4[A1,B3,C3,D4] +0 4 +ndim4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] +0 4 +ndim4[A3,B1,C3,D2] +0 4 +ndim4[A3,B1,C3,D3] +0 4 +ndim4[A3,B1,C3,D4] +0 4 +ndim4[A3,B2,C1,D1] +0 4 +ndim4[A3,B2,C1,D2] +0 4 +ndim4[A3,B2,C1,D3] +0 4 +ndim4[A3,B2,C1,D4] +0 4 +ndim4[A3,B2,C2,D1] +0 4 +ndim4[A3,B2,C2,D2] +0 4 +ndim4[A3,B2,C2,D3] +0 4 +ndim4[A3,B2,C2,D4] +0 4 +ndim4[A3,B2,C3,D1] +0 4 +ndim4[A3,B2,C3,D2] +0 4 +ndim4[A3,B2,C3,D3] +0 4 +ndim4[A3,B2,C3,D4] +0 4 +ndim4[A3,B3,C1,D1] +0 4 +ndim4[A3,B3,C1,D2] +0 4 +ndim4[A3,B3,C1,D3] +0 4 +ndim4[A3,B3,C1,D4] +0 4 +ndim4[A3,B3,C2,D1] +0 4 +ndim4[A3,B3,C2,D2] +0 4 +ndim4[A3,B3,C2,D3] +0 4 +ndim4[A3,B3,C2,D4] +0 4 +ndim4[A3,B3,C3,D1] +0 4 +ndim4[A3,B3,C3,D2] +0 4 +ndim4[A3,B3,C3,D3] +0 4 +ndim4[A3,B3,C3,D4] +0 4 o[B1] 0 42 1 42 @@ -341,6 +557,24 @@ s3iii[A1,B1,C1] SAVEPER 0 1 1 1 +sc[C1,C1] +0 11 +sc[C1,C2] +0 12 +sc[C1,C3] +0 13 +sc[C2,C1] +0 21 +sc[C2,C2] +0 22 +sc[C2,C3] +0 23 +sc[C3,C1] +0 31 +sc[C3,C2] +0 32 +sc[C3,C3] +0 33 t[A2] 0 1 t[A3] @@ -393,3 +627,39 @@ y[D4,A2] 0 42 y[D4,A3] 0 43 +z[C1,A1,B1] +0 110 +z[C1,A1,B2] +0 111 +z[C1,A1,B3] +0 112 +z[C1,A2,B1] +0 120 +z[C1,A2,B2] +0 121 +z[C1,A2,B3] +0 122 +z[C1,A3,B1] +0 130 +z[C1,A3,B2] +0 131 +z[C1,A3,B3] +0 132 +z[C2,A1,B1] +0 210 +z[C2,A1,B2] +0 211 +z[C2,A1,B3] +0 212 +z[C2,A2,B1] +0 220 +z[C2,A2,B2] +0 221 +z[C2,A2,B3] +0 222 +z[C2,A3,B1] +0 230 +z[C2,A3,B2] +0 231 +z[C2,A3,B3] +0 232 diff --git a/models/arrays_varname/arrays_varname.mdl b/models/arrays_varname/arrays_varname.mdl index f387533b..2191c7b4 100755 --- a/models/arrays_varname/arrays_varname.mdl +++ b/models/arrays_varname/arrays_varname.mdl @@ -2,6 +2,7 @@ DimA: A1, A2, A3 -> DimB ~~| DimB: B1, B2, B3 ~~| DimC: C1, C2, C3 ~~| +DimC': DimC ~~| DimD: D1, D2, D3, D4 ~~| SubA: A2, A3 ~~| DimX: SubA, A1 ~~| @@ -93,6 +94,14 @@ s[DimA,DimD]= ~ 2D constant array | +sc[DimC,DimC']= + 11,12,13; + 21,22,23; + 31,32,33; + ~ + ~ 2D constant array where dimensions have matching subscript names + | + s1d[DimA] = 1 ~~| s1i[A1] = 1 ~~| @@ -125,7 +134,52 @@ y[DimD,DimA]= ~ 2D constant array with dimensions not in normal order | +z[C1, DimA, DimB]= + 110, 111, 112; + 120, 121, 122; + 130, 131, 132; + ~ + ~ 2D constant array with additional index subscript (1/2) + | + +z[C2, DimA, DimB]= + 210, 211, 212; + 220, 221, 222; + 230, 231, 232; + ~ + ~ 2D constant array with additional index subscript (2/2) + | + +ndim4[DimA, DimB, DimC, DimD] = 4 + ~ + ~ 4D constant array + | + INITIAL TIME = 0 ~~| FINAL TIME = 1 ~~| TIME STEP = 1 ~~| SAVEPER = TIME STEP ~~| + +\\\---/// Sketch information - do not modify anything except names +V300 Do not put anything below this section - it will be ignored +*View 1 +$0-0-0,0,|0||0-0-0|0-0-0|0-0-0|0-0-0|0-0-0|0,0,100,0 +///---\\\ +:L<%^E!@ +9:arrays_varname +15:0,0,0,0,0,0 +19:100,0 +27:2, +34:0, +5:FINAL TIME +35:Date +36:YYYY-MM-DD +37:2000 +38:1 +39:1 +40:2 +41:0 +42:1 +24:0 +25:0 +26:0 diff --git a/models/arrays_varname/arrays_varname_spec.json b/models/arrays_varname/arrays_varname_spec.json index 9bb3fd65..844f034c 100644 --- a/models/arrays_varname/arrays_varname_spec.json +++ b/models/arrays_varname/arrays_varname_spec.json @@ -1,5 +1,5 @@ { "name": "Arrays test model (where the spec file contains Vensim variable names)", "inputVarNames": ["inputA[A1]", "inputA[A2]", "inputA[A3]"], - "outputVarNames": ["Time", "a[A1]", "a[A2]", "a[A3]", "f[A1,B1]", "f[A1,B2]", "f[A1,B3]", "h"] + "outputVarNames": ["Time", "a[A1]", "a[A2]", "a[A3]", "f[A1,B1]", "f[A1,B2]", "f[A1,B3]", "h", "ndim4[A3,B3,C3,D4]"] } diff --git a/src/Model.js b/src/Model.js index df170807..acf80cd9 100644 --- a/src/Model.js +++ b/src/Model.js @@ -635,15 +635,12 @@ function vensimName(cVarName) { // Convert a C variable name to a Vensim name. let result = cVarName // Get the variable name and subscripts with regexes. - let m = cVarName.match(/(_[A-Za-z0-9_]+)(\[\d+\])?(\[\d+\])?/) + let m = cVarName.match(/(_[A-Za-z0-9_]+)((\[\d+\])*)/) if (m) { let varName = m[1] let indexNumbers = [] - if (m[2]) { - indexNumbers.push(m[2].replace('[', '').replace(']', '')) - if (m[3]) { - indexNumbers.push(m[3].replace('[', '').replace(']', '')) - } + for (let x of m[2].matchAll(/\[(\d+)\]/g)) { + indexNumbers.push(x[1]) } // Get the subscript families and look up the subscript names. let subscripts = []