Update from HH
[Flyspeck/.git] / formal_lp / old / formal_interval / interval_m / report.hl
1 (* port of error.cc 
2     basic procedures to print messages to the standard output
3    and to count errors.
4
5 *)
6
7 module Report = struct
8
9 let time_string () =   Printf.sprintf "time(%.0f)" (Sys.time());;
10
11 let (get_error_count,reset_error_count,inc_error_count) =
12   let error_count = ref 0 in
13     ((fun _ -> !error_count),(fun _ -> error_count := 0),
14    (fun _ -> error_count:= !error_count + 1));;
15
16 let (get_corner_count,reset_corner_count,inc_corner_count) =
17   let corner_count = ref 0 in
18     ((fun _ -> !corner_count),(fun _ -> corner_count := 0),
19    (fun _ -> corner_count:= !corner_count + 1));;
20
21 let diagnostic_string () = 
22   let d = get_error_count() in
23   if (d>0) then Printf.sprintf "(errors %d)" (get_error_count())  else "(no errors)";;
24
25 let report s =
26   Format.print_string s; Format.print_newline(); Format.print_flush();;
27
28 let report_timed s = report (s^" "^(time_string()));;
29
30 let report_error = 
31   let error_max = 25 in  (* was 200, recurse.cc had a separate counter limit at 25 *)
32     fun s ->
33       let ec = get_error_count() in
34       (inc_error_count(); report_timed (Printf.sprintf "error(%d) --\n%s" ec s); 
35        Pervasives.ignore(get_error_count() < error_max or raise Fatal));;
36   
37 let report_fatal s = 
38   ( inc_error_count(); report_timed ("error --\n"^s); raise Fatal);;
39
40 end;;