Skip to content

Commit 5a32c6f

Browse files
Fix #3934
1 parent c3bd84a commit 5a32c6f

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
@@ -363,11 +363,24 @@ function parseFMIVariableName(name::AbstractString)
363363
name = replace(name, "." => "__")
364364
der = 0
365365
if startswith(name, "der(")
366-
idx = findfirst(',', name)
366+
367+
# account for multi-dimensional array variable derivatives, e.g. der(x[1,2], 2)
368+
array_variable_pattern = r"\[\d+?,\d+?\]"
369+
patternmatches = match(array_variable_pattern, name)
370+
if (patternmatches !== nothing)
371+
safe_array_index_str = replace(String(patternmatches.match), "," => "_")
372+
safe_name = replace(name, array_variable_pattern => safe_array_index_str)
373+
else
374+
safe_name = name
375+
end
376+
377+
378+
idx = findfirst(',', safe_name)
367379
if idx === nothing
368380
name = @view name[5:(end - 1)]
369381
der = 1
370382
else
383+
371384
der = parse(Int, @view name[(idx + 1):(end - 1)])
372385
name = @view name[5:(idx - 1)]
373386
end

0 commit comments

Comments
 (0)