20 lines
457 B
OCaml
20 lines
457 B
OCaml
|
open! Base
|
||
|
|
||
|
let parse s =
|
||
|
Stdlib.Scanf.sscanf s "%s@ t=%f" (fun _ t -> t /. 1000.)
|
||
|
|
||
|
let%test_unit "parse temperature" =
|
||
|
[%test_eq: float ] (parse "brol\nmore junk text t=18241") 18.241
|
||
|
|
||
|
|
||
|
let read_temperature file_name =
|
||
|
let open Lwt.Infix in
|
||
|
let rec aux () =
|
||
|
Lwt_io.with_file ~mode:Lwt_io.Input file_name (fun ic ->
|
||
|
Lwt_io.read_all ic >>= function
|
||
|
| None -> aux ()
|
||
|
| Some s -> Lwt.return (parse s)
|
||
|
)
|
||
|
in
|
||
|
aux
|