I need to run several hundred iterations (or more) of a simulation that reads its parameters from an .xml file. This file has ~83k lines.
A sample of a parameter from this simulation is:
<ScalarVariable
name = "nr_resources_init"
valueReference = "2721"
description = "Initial available non-recoverable resources"
variability = "parameter" isDiscrete = "true"
causality = "internal" isValueChangeable = "true"
alias = "noAlias"
classIndex = "1415" classType = "rPar"
isProtected = "false" hideResult = "false"
fileName = "[path to model file]" startLine = "4602" startColumn = "9" endLine = "4602" endColumn = "119" fileWritable = "true">
<Real start="1000000000000.0" fixed="true" useNominal="false" unit="ton" />
</ScalarVariable>
Because of the following...:
- The simulations are run with an executable that automatically reads the .xml for its initial state (parameters).
- From Fortran I would need to search and replace the values ("1000000000000" from the "Real" subnode in the example) of the parameters ("nr_resources_init") and then call the executable with a system call.
- The .xml is automatically generated (only once) before the simulations and it will always have the same structure. Therefore, I think that using regex for this search&replace won't be an issue.
... I considered that using an "XML heavy library" would be an overkill and it may not be the fastest option. Therefore, I tried using sed and perl but couldn't find the correct regex.
What's the best/fastest way to replace the value of a given parameter with a given new value programmatically from Fortran or using system calls?