Skip to content
Stable.csv@modelscript/csv
Parser WASM GLR
Diagnostics Typecheck
DAE Arena AST Only
Simulation Co-sim / Export
Projections Modelica, DAE
Live ExampleBatteryPackDriveCycle.csv

EV Battery Pack WLTP Telemetry Time-Series

Synchronized multi-channel sensor log recording pack bus voltage, discharge current, state of charge, and peak cell temperature.

Playground
Source (8 lines)
1time,voltage_v,current_a,soc_pct,temp_c
20.0,798.4,0.0,92.0,24.2
310.0,784.1,145.0,91.4,25.1
420.0,771.6,230.0,90.3,26.8
530.0,765.2,265.0,88.9,28.9
640.0,779.0,95.0,88.1,30.2
750.0,794.5,-85.0,88.7,30.8
860.0,788.2,60.0,88.3,31.1
Multi-Channel Telemetry Trajectory Plot
MULTI-CHANNEL SENSOR TELEMETRY (pack_voltage [V], current [A], temp [°C]) voltage_v (765–798 V) current_a temp_c 0 s 20 s 40 s 60 s
Drag to pan · Click % to reset

CSV Tabular Data (.csv) ​

@modelscript/csv (languages/csv) elevates empirical measurement series, calibration look-up tables, and parameter sweeps into first-class typed symbols inside the WorkspaceIndex.


Capabilities ​

  1. Native GLR Parsing & Delimiter Auto-Detection: Parses RFC 4180 CSV documents into linear-memory CST rows and cells (csv_document, header_row, data_row, field, quoted_field) while detectDelimiter (languages/csv/src/measurements.ts) automatically detects comma (,), semicolon (;), or tab (\t) delimiters and handles quoted strings with escaped "" sequences.
  2. Modelica Package Generation (parseCsvToModelica): Converts any CSV dataset directly into a strongly typed Modelica package containing:
    • constant Integer numRows and constant Integer numCols
    • A 2D constant Real values[numRows, numCols] matrix suitable for Modelica.Blocks.Tables.CombiTable1D / CombiTable2D
    • Sanitized 1D column vectors (constant Real <colName>[numRows]) with automatic duplicate-name disambiguation
  3. Salsa Virtual Component Queries (CSVVirtualComponent): Exposes every CSV column as a queryable virtual symbol in the QueryEngine (languages/csv/src/queries.ts):
    • resolvedType: Infers "Real", "Integer", "Boolean", or "String" from column cells
    • classInstance: Maps to "Modelica.Blocks.Sources.CombiTimeTable"
    • variability: Returns "constant"
    • causality: Returns "output"
    • resolvedArrayDimensions / arrayDimensions: Returns [rowCount]
    • effectiveModification: Synthesizes { table: "[[...]]" } array literals from column data
  4. Bidirectional Cell Writeback (writeback): When a parameter or table entry is modified during calibration or optimization, csvLanguage.writeback (languages/csv/src/language.ts) updates the exact [row, col] cell or column header in place while preserving the file's original delimiter and line endings.

Semantic Linter & Diagnostic Codes ​

lintCsv(sourceText) (languages/csv/src/linter.ts) performs six structural and numerical integrity checks on CSV datasets:

CodeSeverityCondition Checked
CSV_UNCLOSED_QUOTEerrorA quoted field contains an unclosed " at the end of a line
CSV_EMPTY_HEADERwarningA column in the header row has an empty name
CSV_DUPLICATE_HEADERwarningTwo or more columns share the same header identifier
CSV_COLUMN_COUNT_MISMATCHerrorA data row contains fewer or more cells than the header row
CSV_INVALID_NUMERIC_CELLerrorA cell in a numeric column (where row 1 is numeric) contains non-numeric text, NaN, or Infinity
CSV_NON_MONOTONIC_TIMEwarningThe first column (time / t) is not strictly monotonically increasing (ti<ti−1)

Polyglot TGG Rules ​

@modelscript/csv registers 2 bidirectional Triple Graph Grammar (TGG) rules in languages/csv/src/language.ts:

Rule NameSource (csv)Target (modelica)Semantics
CsvDocumentToModelicaPackageCSVDocumentClassDefinition (package)Projects a CSV file into a Modelica data package with values[numRows, numCols]
CsvVirtualComponentToModelicaComponentCSVVirtualComponentComponentClause (parameter Real)Binds a typed CSV column to a Modelica parameter vector or CombiTimeTable source

Command Line Interface ​

bash
# Lint CSV datasets for column mismatches, unclosed quotes, and non-monotonic time
msx lint trajectory_data.csv

# Output simulation trajectories directly to standard CSV format
msx simulate CircuitModel.mo --stop-time=1.0 --step-size=0.001 --format=csv -o sim_results.csv

Open-Core under the GNU AGPL v3 License; Enterprise Edition (ee/) under the ModelScript Enterprise License. • Trademark Policy