1
$\begingroup$

I want to run an external piece of code, which takes in a parameter file. It's structured like:

param1 1.0
param2 0.0
param3 2.0
param4 0.5

I want to execute the program with parameter files which vary some parameter in some range. What is the best way to generate such parameter file.

Solution by Henrik Schumacher:

Export["a.txt", 
 StringJoin[
  "param1 1
  param2 1.0
  param3 ", ToString[param3],"
  param4 1"],
"Text"]
$\endgroup$
  • $\begingroup$ Is this about Wolfram Mathematica? $\endgroup$ – Kuba May 7 '18 at 12:54
  • $\begingroup$ Yes, i am using the output of the program in mathematica. $\endgroup$ – Gladaed May 7 '18 at 12:56
  • $\begingroup$ Have a look for Run and RunThrough. Import["! <command>", "Text"] also works. $\endgroup$ – Henrik Schumacher May 7 '18 at 12:58
  • $\begingroup$ @HenrikSchumacher i am currently using Run to execute it, but i need to execute it with various parameter files, which i need to generate. Which command would be suited to do that? $\endgroup$ – Gladaed May 7 '18 at 13:00
  • $\begingroup$ You can generate parameter files with Export. E.g. Export[a.txt,<string>,"Text"]. And you can use ToString and StringJoin to generat e the string from Mathematica expressions. $\endgroup$ – Henrik Schumacher May 7 '18 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.