diff --git a/models/arrays_cname/arrays_cname.dat b/models/arrays_cname/arrays_cname.dat index aac7ccf6..8aa91ace 100644 --- a/models/arrays_cname/arrays_cname.dat +++ b/models/arrays_cname/arrays_cname.dat @@ -341,6 +341,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] diff --git a/models/arrays_cname/arrays_cname.mdl b/models/arrays_cname/arrays_cname.mdl index f387533b..5427444e 100755 --- a/models/arrays_cname/arrays_cname.mdl +++ b/models/arrays_cname/arrays_cname.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 ~~| diff --git a/models/arrays_cname/arrays_cname_spec.json b/models/arrays_cname/arrays_cname_spec.json index 3d9f08a9..6270cc30 100644 --- a/models/arrays_cname/arrays_cname_spec.json +++ b/models/arrays_cname/arrays_cname_spec.json @@ -1,5 +1,35 @@ { "name": "Arrays test model (where the spec file contains C names with numeric subscript indices)", "inputVars": ["_inputa[0]", "_inputa[1]", "_inputa[2]"], - "outputVars": ["_time", "_a[0]", "_a[1]", "_a[2]", "_f[0][0]", "_f[0][1]", "_f[0][2]", "_h"] + "outputVars": [ + "_time", + "_a[0]", + "_a[1]", + "_a[2]", + "_f[0][0]", + "_f[0][1]", + "_f[0][2]", + "_h", + "_s[0][0]", + "_s[0][1]", + "_s[0][2]", + "_s[0][3]", + "_s[1][0]", + "_s[1][1]", + "_s[1][2]", + "_s[1][3]", + "_s[2][0]", + "_s[2][1]", + "_s[2][2]", + "_s[2][3]", + "_sc[0][0]", + "_sc[0][1]", + "_sc[0][2]", + "_sc[1][0]", + "_sc[1][1]", + "_sc[1][2]", + "_sc[2][0]", + "_sc[2][1]", + "_sc[2][2]" + ] } diff --git a/src/EquationGen.js b/src/EquationGen.js index 76a58f09..c10c26e1 100644 --- a/src/EquationGen.js +++ b/src/EquationGen.js @@ -958,18 +958,17 @@ export default class EquationGen extends ModelReader { modelLHSReader.read(this.var.modelLHS) let cNames = modelLHSReader.names().map(Model.cName) // Visit dims in normal order. Find the ind in the dim. Compose the C array expression with numeric indices. - for (let dim of this.var.separationDims) { - let sepDim = sub(dim) - for (let ind of this.var.subscripts) { - let i = sepDim.value.indexOf(ind) - if (i >= 0) { - let indexNum = sub(ind).value - if (!cVarName) { - cVarName = `${this.var.varName}[${indexNum}]` - } else { - cVarName += `[${indexNum}]` - } - break + for (let i = 0; i < this.var.separationDims.length; i++) { + const dim = this.var.separationDims[i] + const sepDim = sub(dim) + const ind = this.var.subscripts[i] + const j = sepDim.value.indexOf(ind) + if (j >= 0) { + const indexNum = sub(ind).value + if (!cVarName) { + cVarName = `${this.var.varName}[${indexNum}]` + } else { + cVarName += `[${indexNum}]` } } }