diff --git a/src/EquationGen.js b/src/EquationGen.js index 52be92f5..975e548e 100644 --- a/src/EquationGen.js +++ b/src/EquationGen.js @@ -330,10 +330,10 @@ export default class EquationGen extends ModelReader { // If direct data exists for this variable, copy it from the workbook into one or more lookups. let result = [] if (this.mode === 'init-lookups') { - let { tag, sheetName, timeRowOrCol, startCell } = this.var.directDataArgs - let workbook = this.directData.get(tag) + let { file, tab, timeRowOrCol, startCell } = this.var.directDataArgs + let workbook = this.directData.get(file) if (workbook) { - let sheet = workbook.Sheets[sheetName] + let sheet = workbook.Sheets[tab] if (sheet) { let indexNum = 0 if (!R.isEmpty(this.var.subscripts)) { @@ -344,10 +344,10 @@ export default class EquationGen extends ModelReader { } result.push(this.generateDirectDataLookup(sheet, timeRowOrCol, startCell, indexNum)) } else { - throw new Error(`ERROR: Direct data worksheet ${sheetName} tagged ${tag} not found`) + throw new Error(`ERROR: Direct data worksheet ${tab} tagged ${file} not found`) } } else { - throw new Error(`ERROR: Direct data workbook tagged ${tag} not found`) + throw new Error(`ERROR: Direct data workbook tagged ${file} not found`) } } return result diff --git a/src/EquationReader.js b/src/EquationReader.js index 9c4cf204..b102e835 100644 --- a/src/EquationReader.js +++ b/src/EquationReader.js @@ -127,13 +127,17 @@ export default class EquationReader extends ModelReader { this.expandDelayFunction(fn, args) } else if (fn === '_GET_DIRECT_DATA') { // Extract string constant arguments into an object used in code generation. + // For Excel files, the file argument names an indirect "?" file tag from the model settings. + // For CSV files, it gives a relative pathname in the model directory. + // For Excel files, the tab argument names an Excel worksheet. + // For CSV files, it gives the delimiter character. let args = R.map( arg => matchRegex(arg, /'(.*)'/), R.map(expr => expr.getText(), ctx.expr()) ) this.var.directDataArgs = { - tag: args[0], - sheetName: args[1], + file: args[0], + tab: args[1], timeRowOrCol: args[2], startCell: args[3] } diff --git a/src/sde-generate.js b/src/sde-generate.js index be96aa73..9f6d8271 100644 --- a/src/sde-generate.js +++ b/src/sde-generate.js @@ -107,12 +107,12 @@ export let generate = async (model, opts) => { extData = new Map([...extData, ...data]) } } - // Attach Excel workbook data to directData entries by tag name. + // Attach Excel workbook data to directData entries by file name. let directData = new Map() if (spec.directData) { - for (let [tag, xlsxFilename] of Object.entries(spec.directData)) { + for (let [file, xlsxFilename] of Object.entries(spec.directData)) { let pathname = path.join(modelDirname, xlsxFilename) - directData.set(tag, readXlsx(pathname)) + directData.set(file, readXlsx(pathname)) } } // Produce a runnable model with the "genc" and "preprocess" options.