mirror of
https://gitlab.com/scemama/QCaml.git
synced 2024-12-22 12:23:31 +01:00
Improved reading basis
This commit is contained in:
parent
bdece8ea60
commit
a692242b51
@ -20,7 +20,7 @@ exception No_shell
|
||||
exception Malformed_shell of string
|
||||
|
||||
|
||||
let read_shell line_stream =
|
||||
let read_shell ?element line_stream =
|
||||
try
|
||||
|
||||
let shell, n =
|
||||
@ -40,9 +40,15 @@ let read_shell line_stream =
|
||||
let line = Stream.next line_stream in
|
||||
try Scanf.sscanf line " %_d %f %f "
|
||||
(fun exponent coefficient -> { exponent ; coefficient })
|
||||
with _ -> raise (Malformed_shell (Printf.sprintf
|
||||
"Expected %d %c contractions, error at contraction %d:\n%s"
|
||||
n shell (n-i+1) line))
|
||||
with _ -> raise (Malformed_shell
|
||||
(match element with
|
||||
| Some element -> Printf.sprintf
|
||||
"In %s: Expected %d %c contractions.\nError at contraction %d:\n%s"
|
||||
(Element.to_string element) n shell (n-i+1) line
|
||||
| None -> Printf.sprintf
|
||||
"Expected %d %c contractions.\nError at contraction %d:\n%s"
|
||||
n shell (n-i+1) line
|
||||
))
|
||||
in
|
||||
contraction :: loop (pred i)
|
||||
in
|
||||
@ -54,20 +60,26 @@ let read_shell line_stream =
|
||||
|
||||
|
||||
|
||||
let read_element line_stream =
|
||||
let rec read_element line_stream =
|
||||
try
|
||||
|
||||
let line = Stream.next line_stream in
|
||||
let element =
|
||||
Scanf.sscanf line " %s " Element.of_string
|
||||
in
|
||||
if String.length line = 0 || line.[0] = '!' then
|
||||
read_element line_stream
|
||||
else
|
||||
let element =
|
||||
try
|
||||
Scanf.sscanf line " %s " Element.of_string
|
||||
with
|
||||
| Element.ElementError _ -> Element.X
|
||||
in
|
||||
|
||||
let rec loop () =
|
||||
match read_shell line_stream with
|
||||
| Some shell -> shell :: loop ()
|
||||
| None -> []
|
||||
in
|
||||
Some (element, Array.of_list (loop ()) )
|
||||
let rec loop () =
|
||||
match read_shell line_stream ~element with
|
||||
| Some shell -> shell :: loop ()
|
||||
| None -> []
|
||||
in
|
||||
Some (element, Array.of_list (loop ()) )
|
||||
|
||||
with
|
||||
| Stream.Failure -> None
|
||||
|
@ -100,7 +100,7 @@ Some
|
||||
*)
|
||||
|
||||
|
||||
val read_shell : string Stream.t -> general_contracted_shell option
|
||||
val read_shell : ?element:Element.t -> string Stream.t -> general_contracted_shell option
|
||||
(** Reads a shell from the input [string Stream]. The [string Stream] is a
|
||||
stream of lines, like a text file split on the end-of-line character.
|
||||
For example,
|
||||
|
Loading…
Reference in New Issue
Block a user