summaryrefslogtreecommitdiffstats
path: root/sources/fabrice/simulator/simulGraphes.ml
diff options
context:
space:
mode:
authorlefessan <lefessan@30fcff6e-8de6-41c7-acce-77ff6d1dd07b>2011-04-11 15:24:45 +0000
committerlefessan <lefessan@30fcff6e-8de6-41c7-acce-77ff6d1dd07b>2011-04-11 15:24:45 +0000
commit1b3bbda12e948e4d9fe34a4c59b9dac9e7b64e8f (patch)
treeb1e44c5b779b593f4065c28e790f15b2ac7b777d /sources/fabrice/simulator/simulGraphes.ml
parentdecfef69b25175e672a3216d85b9b4c7e1165b98 (diff)
downloadpacemaker-1b3bbda12e948e4d9fe34a4c59b9dac9e7b64e8f.tar.gz
Added sources of simulator and emulator
git-svn-id: https://scm.gforge.inria.fr/svn/pacemaker@2 30fcff6e-8de6-41c7-acce-77ff6d1dd07b
Diffstat (limited to 'sources/fabrice/simulator/simulGraphes.ml')
-rw-r--r--sources/fabrice/simulator/simulGraphes.ml129
1 files changed, 129 insertions, 0 deletions
diff --git a/sources/fabrice/simulator/simulGraphes.ml b/sources/fabrice/simulator/simulGraphes.ml
new file mode 100644
index 0000000..e179d48
--- /dev/null
+++ b/sources/fabrice/simulator/simulGraphes.ml
@@ -0,0 +1,129 @@
+
+let int_of_string s =
+ try
+ int_of_string s
+ with e ->
+ failwith (Printf.sprintf "int_of_string: error with [%s]" (String.escaped s))
+
+let on_file filename =
+ let ic = open_in filename in
+ let count = ref 0 in
+ let mins = ref [||] in
+ let maxs = ref [||] in
+ (try
+ let line = input_line ic in
+ incr count;
+ let line = String2.split_simplify line ' ' in
+ mins := Array.create (List.length line) 0.;
+ maxs := Array.create (List.length line) 0.;
+ let mins = !mins in
+ let maxs = !maxs in
+ List2.iteri (fun i x ->
+ let x = float_of_string x in
+ mins.(i) <- x;
+ maxs.(i) <- x) line;
+ while true do
+ let line = input_line ic in
+ incr count;
+ let line = String2.split_simplify line ' ' in
+ List2.iteri (fun i x ->
+ let x = float_of_string x in
+ mins.(i) <- min x mins.(i);
+ maxs.(i) <- max x maxs.(i)) line;
+ done
+
+ with End_of_file -> ());
+ !count, !mins, !maxs
+
+
+let value_per_time x_of_y filename int_table element =
+ Printf.printf "%s...\n%!" filename;
+ let oc = open_out (Printf.sprintf "%s.txt" filename) in
+ let maximum = ref int_table.(0) in
+ let nrounds = Array.length int_table in
+ for round = 0 to nrounds - 1 do
+ maximum := max !maximum int_table.(round);
+ output_string oc (Printf.sprintf "%d %s\n" round
+ (x_of_y int_table.(round)))
+ done;
+ close_out oc;
+
+ let oc = open_out (Printf.sprintf "%s.plot" filename) in
+ output_string oc (Printf.sprintf "
+set out '%s.eps'
+set terminal postscript eps enhanced \"Helvetica\" 14
+set out '%s.eps'
+set yrange [0:%s+1]
+set xrange [0:%d]
+set ylabel 'Number of %s'
+set xlabel 'Time (minutes)'
+
+set data style lines
+
+plot \"%s.txt\" using ($1):($2) title '%s'
+ " filename filename (x_of_y !maximum) nrounds element filename element);
+ close_out oc
+
+
+
+ let npoints = 1000
+
+let cdf_of_list x_of_y filename int_list options xlabel ylabel end_plot =
+ Printf.printf "%s...\n%!" filename;
+ match int_list with
+ [] -> Printf.printf " not enough data\n"
+ | init :: _ ->
+ let int_list = List.sort compare int_list in
+ let nints = List.length int_list in
+
+ let oc = open_out (Printf.sprintf "%s.txt" filename) in
+ let maximum = ref init in
+ List2.iteri (fun i x ->
+ maximum := max !maximum x;
+ output_string oc (Printf.sprintf "%d %s\n" i
+ (x_of_y x))
+ ) int_list;
+ close_out oc;
+
+ let every =
+ if nints > npoints then
+ Printf.sprintf " every %d " (nints / npoints) else "" in
+
+ let oc = open_out (Printf.sprintf "%s.plot" filename) in
+ output_string oc (Printf.sprintf "
+set out '%s.eps'
+set terminal postscript eps enhanced \"Helvetica\" 14
+set out '%s.eps'
+set yrange [1:%s+1]
+set xrange [0:%d]
+set ylabel '%s'
+set xlabel '%s'
+set data style lines
+
+%s
+
+plot \"%s.txt\" %s using ($1):($2) %s
+ " filename filename (x_of_y !maximum) (nints+2) ylabel xlabel options filename every end_plot);
+ close_out oc
+
+
+let for_every every filename =
+ let ic = open_in filename in
+ let nlines = ref 0 in
+ let line = ref "" in
+ try
+ while true do
+ line := input_line ic;
+ incr nlines
+ done
+ with End_of_file ->
+ close_in ic;
+ if !nlines > 0 then
+ let x = (!nlines - 1) mod every in
+ if x > 0 then
+ let oc = open_out_gen [Open_append] 0o644 filename in
+ for i = x to every-1 do
+ Printf.printf "adding line\n";
+ Printf.fprintf oc "%s\n" !line
+ done;
+ close_out oc