mirror of
https://github.com/QuantumPackage/qp2.git
synced 2025-01-02 16:45:38 +01:00
This commit is contained in:
parent
fdd6392d57
commit
a29c67a738
@ -129,15 +129,23 @@ let set str s =
|
|||||||
|
|
||||||
|
|
||||||
(** Creates the temporary file for interactive editing *)
|
(** Creates the temporary file for interactive editing *)
|
||||||
let create_temp_file ezfio_filename fields =
|
let create_temp_file ?filename ezfio_filename fields =
|
||||||
let temp_filename = Filename.temp_file "qp_edit_" ".rst" in
|
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
|
begin
|
||||||
let oc = open_out temp_filename in
|
let oc = open_out temp_filename in
|
||||||
(file_header ezfio_filename) :: (List.map get fields)
|
(file_header ezfio_filename) :: (List.map get fields)
|
||||||
|> String.concat "\n"
|
|> String.concat "\n"
|
||||||
|> Printf.fprintf oc "%s";
|
|> Printf.fprintf oc "%s";
|
||||||
close_out oc;
|
close_out oc;
|
||||||
at_exit (fun () -> Sys.remove temp_filename);
|
|
||||||
temp_filename
|
temp_filename
|
||||||
end
|
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 *)
|
(* Set check_only if the arguments are not empty *)
|
||||||
let check_only =
|
let check_only =
|
||||||
match ndet, state with
|
match ndet, state, read with
|
||||||
| None, None -> check_only
|
| None, None, None -> check_only
|
||||||
| _ -> true
|
| _ -> true
|
||||||
in
|
in
|
||||||
|
|
||||||
@ -230,22 +238,30 @@ let run check_only ?ndet ?state ezfio_filename =
|
|||||||
|
|
||||||
(* Create the temp file *)
|
(* Create the temp file *)
|
||||||
let temp_filename =
|
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
|
in
|
||||||
|
|
||||||
|
|
||||||
|
let () =
|
||||||
|
match check_only with
|
||||||
|
| true -> ()
|
||||||
|
| false ->
|
||||||
|
begin
|
||||||
(* Open the temp file with external editor *)
|
(* Open the temp file with external editor *)
|
||||||
let editor =
|
let editor =
|
||||||
try Sys.getenv "EDITOR"
|
try Sys.getenv "EDITOR"
|
||||||
with Not_found -> "vi"
|
with Not_found -> "vi"
|
||||||
in
|
in
|
||||||
|
|
||||||
match check_only with
|
|
||||||
| true -> ()
|
|
||||||
| false ->
|
|
||||||
Printf.sprintf "%s %s" editor temp_filename
|
Printf.sprintf "%s %s" editor temp_filename
|
||||||
|> Sys.command |> ignore
|
|> Sys.command |> ignore
|
||||||
;
|
end
|
||||||
|
in
|
||||||
|
|
||||||
|
if write = None then
|
||||||
(* Re-read the temp file *)
|
(* Re-read the temp file *)
|
||||||
let temp_string =
|
let temp_string =
|
||||||
let ic = open_in temp_filename in
|
let ic = open_in temp_filename in
|
||||||
@ -312,6 +328,16 @@ let () =
|
|||||||
doc="Checks the input data";
|
doc="Checks the input data";
|
||||||
arg=Without_arg; }};
|
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;
|
{{ short='n'; long="ndet"; opt=Optional;
|
||||||
doc="Truncates the wavefunction to the target number of determinants";
|
doc="Truncates the wavefunction to the target number of determinants";
|
||||||
arg=With_arg "<int>"; }};
|
arg=With_arg "<int>"; }};
|
||||||
@ -328,6 +354,12 @@ let () =
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
(* Handle options *)
|
(* Handle options *)
|
||||||
|
let write =
|
||||||
|
Command_line.get "write"
|
||||||
|
in
|
||||||
|
let read =
|
||||||
|
Command_line.get "read"
|
||||||
|
in
|
||||||
let ndet =
|
let ndet =
|
||||||
match Command_line.get "ndet" with
|
match Command_line.get "ndet" with
|
||||||
| None -> None
|
| None -> None
|
||||||
@ -353,7 +385,7 @@ let () =
|
|||||||
(* Run the program *)
|
(* Run the program *)
|
||||||
try
|
try
|
||||||
if (not c) then create_backup ezfio_filename;
|
if (not c) then create_backup ezfio_filename;
|
||||||
run c ?ndet ?state ezfio_filename
|
run c ?ndet ?state ?read ?write ezfio_filename
|
||||||
with
|
with
|
||||||
| Failure exc
|
| Failure exc
|
||||||
| Invalid_argument exc ->
|
| Invalid_argument exc ->
|
||||||
|
Loading…
Reference in New Issue
Block a user