Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

regex and system()

regex and system()

Hi,
this should be my last open problem:

From my final simulation I want to keep only a few variables in a .csv file, so I do:

Code:


system("mymodel -override startTime=243,stopTime=391,outputFormat=csv,variableFilter=mixer21.Out.*|mixer22.Out.*|effluentsink1.Out.*|sludgesink1.Out.* -iif start.mat -r results.csv")

When I filter only for one class of variables, e.g. mixer21.Out.* it works just fine, I get all my 16 state variables for that subsystem. Unfortunately it gives me an error (255) when I try more using the pipe (|). I have to admit I'm not very keen on regex. Is it a problem that using "system" my call to variableFilter is already within a string and I can't use the quote sign for the regex? Well, I didn't get it to work with "simulate" either... .

Any comments?

Thank you.
André

Re: regex and system()

You can use quote sign inside quotes using \", example: "some text \"quoted text\" some more text".
You could also try to escape the pipe use \\| instead of |.

Re: regex and system()

Alternatively you can use -overrideFile fileWithOverrideValues.txt which you can generate to contain:

Code:


startTime=243
stopTime=391
outputFormat=csv
variableFilter=mixer21.Out.*|mixer22.Out.*|effluentsink1.Out.*|sludgesink1.Out.*

Then you don't run into issues with command line escaping or the max size of the command line.

Re: regex and system()

thank you for the hint.
escaping the quote sign works "a little". I get 2 out of 4 variable classes.
escaping the pipe doesn't work.

I'll try the file approach on thursday, when I'm back.

Edited by: lambu0815 - Aug-25-15 14:59:15

Re: regex and system()

I have to correct myself, escaping the quote sign does do the trick, I had a typo in two of the 4 variable names (sinks do not have outputs, right?).
Thank you!
(well - no need trying the overrideFile approach)

Edited by: lambu0815 - Aug-27-15 06:58:18
There are 0 guests and 0 other users also viewing this topic
You are here: