Implemented #322
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Anthony Scemama 2024-03-16 15:21:40 +01:00
parent fdd6392d57
commit a29c67a738
1 changed files with 86 additions and 54 deletions

View File

@ -129,15 +129,23 @@ let set str s =
(** Creates the temporary file for interactive editing *)
let create_temp_file ezfio_filename fields =
let temp_filename = Filename.temp_file "qp_edit_" ".rst" in
let create_temp_file ?filename ezfio_filename fields =
let temp_filename =
match filename with
| None -> Filename.temp_file "qp_edit_" ".rst"
| Some f -> f
in
let () =
match filename with
| None -> at_exit (fun () -> Sys.remove temp_filename)
| _ -> ()
in
begin
let oc = open_out temp_filename in
(file_header ezfio_filename) :: (List.map get fields)
|> String.concat "\n"
|> Printf.fprintf oc "%s";
close_out oc;
at_exit (fun () -> Sys.remove temp_filename);
temp_filename
end
@ -145,12 +153,12 @@ let create_temp_file ezfio_filename fields =
let run check_only ?ndet ?state ezfio_filename =
let run check_only ?ndet ?state ?read ?write ezfio_filename =
(* Set check_only if the arguments are not empty *)
let check_only =
match ndet, state with
| None, None -> check_only
match ndet, state, read with
| None, None, None -> check_only
| _ -> true
in
@ -230,22 +238,30 @@ let run check_only ?ndet ?state ezfio_filename =
(* Create the temp file *)
let temp_filename =
create_temp_file ezfio_filename tasks
match read, write with
| None, None -> create_temp_file ezfio_filename tasks
| Some filename, None -> filename
| None, filename -> create_temp_file ?filename ezfio_filename tasks
| x, y -> failwith "read and write options are incompatible"
in
let () =
match check_only with
| true -> ()
| false ->
begin
(* Open the temp file with external editor *)
let editor =
try Sys.getenv "EDITOR"
with Not_found -> "vi"
in
match check_only with
| true -> ()
| false ->
Printf.sprintf "%s %s" editor temp_filename
|> Sys.command |> ignore
;
end
in
if write = None then
(* Re-read the temp file *)
let temp_string =
let ic = open_in temp_filename in
@ -312,6 +328,16 @@ let () =
doc="Checks the input data";
arg=Without_arg; }};
{{
short='w'; long="write"; opt=Optional;
doc="Writes the qp_edit file to a file\"";
arg=With_arg "<string>"; }};
{{
short='r'; long="read"; opt=Optional;
doc="Reads the file and applies it to the EZFIO\"";
arg=With_arg "<string>"; }};
{{ short='n'; long="ndet"; opt=Optional;
doc="Truncates the wavefunction to the target number of determinants";
arg=With_arg "<int>"; }};
@ -328,6 +354,12 @@ let () =
end;
(* Handle options *)
let write =
Command_line.get "write"
in
let read =
Command_line.get "read"
in
let ndet =
match Command_line.get "ndet" with
| None -> None
@ -353,7 +385,7 @@ let () =
(* Run the program *)
try
if (not c) then create_backup ezfio_filename;
run c ?ndet ?state ezfio_filename
run c ?ndet ?state ?read ?write ezfio_filename
with
| Failure exc
| Invalid_argument exc ->