Skip to content

Commit ea660a6

Browse files
Fix #3934
1 parent f41cdf5 commit ea660a6

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

ext/MTKFMIExt.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,24 @@ function parseFMIVariableName(name::AbstractString)
362362
name = replace(name, "." => "__")
363363
der = 0
364364
if startswith(name, "der(")
365-
idx = findfirst(',', name)
365+
366+
# account for multi-dimensional array variable derivatives, e.g. der(x[1,2], 2)
367+
array_variable_pattern = r"\[\d+?,\d+?\]"
368+
patternmatches = match(array_variable_pattern, name)
369+
if (patternmatches !== nothing)
370+
safe_array_index_str = replace(String(patternmatches.match), "," => "_")
371+
safe_name = replace(name, array_variable_pattern => safe_array_index_str)
372+
else
373+
safe_name = name
374+
end
375+
376+
377+
idx = findfirst(',', safe_name)
366378
if idx === nothing
367379
name = @view name[5:(end - 1)]
368380
der = 1
369381
else
382+
370383
der = parse(Int, @view name[(idx + 1):(end - 1)])
371384
name = @view name[5:(idx - 1)]
372385
end

0 commit comments

Comments
 (0)