how to save data during about 1000 simulations times

87 views
Skip to first unread message

Nissa wang

unread,
Apr 5, 2014, 9:13:58 AM4/5/14
to ns-3-...@googlegroups.com
I'm working on a simulation,now i want to record  a data in about 1000 time.How can I record them into a file.

Tommaso Pecorella

unread,
Apr 5, 2014, 12:50:38 PM4/5/14
to ns-3-...@googlegroups.com
I promised to be calm and to not mock people. Sometimes I think it's harder than quit smoking.

On Saturday, April 5, 2014 3:13:58 PM UTC+2, Nissa wang wrote:
I'm working on a simulation,now i want to record  a data in about 1000 time.How can I record them into a file.

Read the tutorial. Read the manual. Open a file. Write stuff in the file.
In the examples there are many... examples (oh, rly?) with periodic functions.

Nissa wang

unread,
Apr 5, 2014, 1:20:17 PM4/5/14
to ns-3-...@googlegroups.com
OK,I know the logging or Tracing files to use. But my question is different.I am not write many value to a files in a simulations.
what  i do was record a data value in  a file in about 1000 times. The value in the logging or Tracing  files is always overwrited by the new simulation. How can I save 1000 times' simulations values in  file?

在 2014年4月6日星期日UTC+8上午12时50分38秒,Tommaso Pecorella写道:

Ivo Calado

unread,
Apr 5, 2014, 2:26:12 PM4/5/14
to ns-3-...@googlegroups.com
Nissa,
   a simple workaround would be you save the logs of each simulation of a different file, where the filename you pass as an argument.


--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.



--
Ivo Calado

Quidquid latine dictum sit, altum viditur

Putt's Law:
       Technology is dominated by two types of people:
               Those who understand what they do not manage.
               Those who manage what they do not understand.

Konstantinos

unread,
Apr 5, 2014, 2:30:57 PM4/5/14
to ns-3-...@googlegroups.com
You just need to tell that the file will be the same and data will be APPENDED each time, not write over.
Depending on how you create/write to the file, there is a different way to accomplish that.

Nissa wang

unread,
Apr 5, 2014, 2:36:23 PM4/5/14
to ns-3-...@googlegroups.com
OK,thank you very much for your reply.but the method you propose is not suited in my simulation. For every simulation time,i just want write a value obtained during simualtion to the file. If i use different filenames,it will be a nightmare for me to open about 1000 files to copy a value everytime.

在 2014年4月6日星期日UTC+8上午2时26分12秒,Ivo Calado写道:

Nissa wang

unread,
Apr 5, 2014, 2:40:42 PM4/5/14
to ns-3-...@googlegroups.com
then,how can i have the data appended ,not write over everyime.For the logging and tracing are always write over in different independent simulations.

在 2014年4月6日星期日UTC+8上午2时30分57秒,Konstantinos写道:

Konstantinos

unread,
Apr 5, 2014, 4:05:52 PM4/5/14
to ns-3-...@googlegroups.com


On Saturday, April 5, 2014 7:36:23 PM UTC+1, Nissa wang wrote:
OK,thank you very much for your reply.but the method you propose is not suited in my simulation. For every simulation time,i just want write a value obtained during simualtion to the file. If i use different filenames,it will be a nightmare for me to open about 1000 files to copy a value everytime.


You can use a bash script to read files in a loop.

Tommaso Pecorella

unread,
Apr 5, 2014, 4:12:03 PM4/5/14
to ns-3-...@googlegroups.com
LMGIFY (feel free to google the acronym)

http://www.cplusplus.com/doc/tutorial/files/

T.

Nissa wang

unread,
Apr 5, 2014, 7:01:31 PM4/5/14
to ns-3-...@googlegroups.com
Hi Tommaso,
Thanks very much for the link you show to me. And it's very helpful. The following is the c++ and python script i used to control writing data value to a file in seeral simulations.
1.  ofstream myfile;
    myfile.open ("example.txt",ios::out | ios::app | ios::binary);
   myfile <<time_value<< ",\n";

    myfile.close();
2.#!/usr/bin/python

import sys
import os


#define function
def start_simulation(data):
os.system('./waf --run "scratch/newadhoc --RngRun=%d" ' % (data))

for rng in range(1,6):
start_simulation(rng)
print '#%d' % (rng)
3.the value in the example.txt.the value of time_value in 1.
30.061,
30.0125,
30.0366,
30.0156,
30.0734,


在 2014年4月6日星期日UTC+8上午4时12分03秒,Tommaso Pecorella写道:

Nissa wang

unread,
Apr 5, 2014, 7:06:05 PM4/5/14
to ns-3-...@googlegroups.com
Thank you for your help.As for as i don not know how to read files in a loop, i used " ofstream myfile" provided by  Tommaso Pecorella. Finally,problem was solved.
Thank you for your both.

在 2014年4月6日星期日UTC+8上午4时05分52秒,Konstantinos写道:

Ivo Calado

unread,
Apr 7, 2014, 12:48:24 PM4/7/14
to ns-3-...@googlegroups.com
Nissa, I missunderstood your question. I though you wanted to save a lot of data on each simulation. As Tommaso said, you can use ofstream to output data directly to a file or you can flush data to the stderr or stdout and redirect the data from outside of simulation program.

Ex.:
./waf --run "simulation" >> file (appends the output from stdout into file)
./waf --run "simulation" 2>> file (appends the output from stderr into file)

Cheers,
   Ivo
Reply all
Reply to author
Forward
0 new messages