Last active
August 29, 2015 13:57
-
-
Save rhz/9865996 to your computer and use it in GitHub Desktop.
KaSim: show all digits for float numbers (eg time) in output file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git main/main.ml main/main.ml | |
index fa98968..86c90ff 100644 | |
--- main/main.ml | |
+++ main/main.ml | |
@@ -37,6 +37,7 @@ let main = | |
("-load-sim", Arg.String (fun file -> Parameter.marshalizedInFile := file) , "load simulation package instead of kappa files") ; | |
("-make-sim", Arg.String (fun file -> Parameter.marshalizedOutFile := file) , "save kappa files as a simulation package") ; | |
("--implicit-signature", Arg.Unit (fun () -> Parameter.implicitSignature := true), "Program will guess agent signatures automatically") ; | |
+ ("--float-precision", Arg.Int (fun p -> Parameter.floatPrecision := Some p), "Use given precision to print floating point numbers (e.g. time)") ; | |
("-seed", Arg.Int (fun i -> Parameter.seedValue := Some i), "Seed for the random number generator") ; | |
("--eclipse", Arg.Unit (fun () -> Parameter.eclipseMode:= true), "enable this flag for running KaSim behind eclipse plugin") ; | |
("--emacs-mode", Arg.Unit (fun () -> Parameter.emacsMode:= true), "enable this flag for running KaSim using emacs-mode") ; | |
diff --git main/parameter.ml main/parameter.ml | |
index af17a82..b934aac 100644 | |
--- main/parameter.ml | |
+++ main/parameter.ml | |
@@ -56,6 +56,7 @@ let implicitSignature = ref false | |
let dotOutput = ref false | |
let fluxModeOn = ref false | |
let snapshotHighres = ref true | |
+let (floatPrecision:int option ref) = ref None | |
let causalModeOn = ref false | |
let weakCompression = ref false | |
diff --git simulation/plot.ml simulation/plot.ml | |
index b401d35..94e1d6c 100644 | |
--- simulation/plot.ml | |
+++ simulation/plot.ml | |
@@ -52,7 +52,9 @@ let output state time event plot env counter = | |
end | |
| Some d -> d | |
in | |
- Printf.fprintf d "%c%E" !Parameter.plotSepChar time ; | |
+ match !Parameter.floatPrecision with | |
+ | None -> Printf.fprintf d "%c%E" !Parameter.plotSepChar time | |
+ | Some p -> Printf.fprintf d "%c%.*E" !Parameter.plotSepChar p time ; | |
List.iter | |
(fun obs -> | |
let inst = fun v_i -> State.instance_number v_i state env | |
@@ -67,9 +69,11 @@ let output state time event plot env counter = | |
| Dynamics.VAR f -> f inst values time event (Counter.null_event counter) (Sys.time()) v_of_token | |
in | |
match v with | |
- | Num.I x -> Printf.fprintf d "%c%d" !Parameter.plotSepChar x | |
- | Num.F x -> Printf.fprintf d "%c%E" !Parameter.plotSepChar x | |
| Num.I64 x -> Printf.fprintf d "%c%Ld" !Parameter.plotSepChar x | |
+ | Num.I x -> Printf.fprintf d "%c%d" !Parameter.plotSepChar x | |
+ | Num.F x -> match !Parameter.floatPrecision with | |
+ | None -> Printf.fprintf d "%c%E" !Parameter.plotSepChar x | |
+ | Some p -> Printf.fprintf d "%c%.*E" !Parameter.plotSepChar p x | |
) state.observables ; | |
Printf.fprintf d "\n" ; | |
flush d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried git apply --check float-precision.patch and it says fatal: corrupt at line 53.
Could you submit a pull request or fix this?
Cheers
J