Record and export numeric outputs to csv file

Hi all I am doing a simulation on microgrids and I would like to export parameters like solar(Power), wind(Power), user load(Power), battery state of charge etc into a csv file for data analysis purposes like energy forecasting. I have tried using the “ToFile” function however I have encountered the following issues that I could not solve:

  1. The CSV file gets overwritten everytime i run my simulation.

  2. Some of the parameters have the wrong display names on the first column of the file

  3. I am unable to get the computer’s time and use them in the CSV file as timestamps to show when the data was recorded.

What are the possible solutions I can try? Can I try and do a c-script or state machine? Any advise would be appreciated! Thanks everyone

Please see my responses below. Feel free to attach any example models that may clarify some of your questions, especially on point #2.

> 1. The CSV file gets overwritten everytime i run my simulation.

This is the default behavior. If one is doing multiple simulation runs, typically one would use a simulation script. Then in the simulation script you could modify the ToFile name according to the test conditions or test number. The Filename can be an arbitrary octave string when the Filename parameter is set to Evaluate.

If the goal is to manually tweak something in the model, re-run the simulation, and then save the results, one option is to construct the file name in the model initialization commands based upon the relevant settings. Another approach would be to have the filename be a function of run-time or run-number. I personally find this less attractive as the user will have to write down which run # corresponds to which conditions. This can also generate many large files.

One can construct a string denoting the time at the start of simulation using octave. One would set this as the Filename and set the filename parameter to evaluate.

timeStr = strftime (“%y_%m_%d_%r”, localtime (time ()));

csvName = [‘SimRun’,timeStr]

> 2. Some of the parameters have the wrong display names on the first column of the file

The CSV file names come from the name of the upstream component. You can modify the component name to get the desired description in the header.

> 3. I am unable to get the computer’s time and use them in the CSV file as timestamps to show when the data was recorded.

Is there a reason to have the local time reported at every simulation step? The only case I’ve heard this in the past is as a proxy to find where the simulation may become slow. Does modifying the filename, noted above, address this concern?