-let csvread = fun (ic : in_channel) ->
- let string_list = ref [] in
- try
- while true do
- string_list := !string_list @ [(input_line ic)]
- done;
- [||]
- with End_of_file ->
- (*let () = print_endline(List.nth !string_list 0) in*)
- Array.of_list (List.map float_of_string !string_list);;
-
-let read_input_csv = fun argv ->
- let n_input = (Array.length argv) - 4 in
- if n_input < 0 then
- raise Missing_Expression
- else if n_input = 0 then
- ([], [])
- else
- (* open csv file *)
- let file_string_array = Array.sub argv 4 n_input in
- let make_chemin s = io_macro_to_string Input_Route_string ^ s in
- let file_chemin_string_array = Array.map make_chemin file_string_array in
- let file_array = Array.map open_in file_chemin_string_array in
- let file_list = Array.to_list file_array in
-
- (* read sample rates and data *)
- let rate_list = Array.to_list (Array.create n_input 0) in
- let data_float_array_list = List.map csvread file_list in
- let _ = List.map close_in file_list in
- (rate_list, data_float_array_list);;
-
-
-let write_output_csv = fun channel_int_list -> fun data_float_array_list ->
- let () = print_string(" Faustine -> Writing csv files...") in
- let tic = Sys.time () in
-
- (* make output txt file names : output0, output1, ... *)
- let n_output = List.length data_float_array_list in
- let n_array = Array.init n_output (fun n -> n) in
- let make_file_name i = "output" ^ (string_of_int i) ^ ".csv" in
-
- (* make output wave file routes *)
- let make_chemin s = io_macro_to_string Output_Route_string ^ s in
- let file_name_string_array = Array.map make_file_name n_array in
- let file_chemin_string_array = Array.map make_chemin file_name_string_array in
- let file_chemin_string_list = Array.to_list file_chemin_string_array in
-
- (* open output channels *)
- let file_list = List.map open_out file_chemin_string_list in
- let data_string_array_list = List.map (Array.map string_of_float) data_float_array_list in
- let array_to_string = fun data_string_array -> fun channel_int ->
- let data_length = Array.length data_string_array in
- let rec to_string_rec =
- fun data -> fun channel -> fun n -> fun i -> fun column ->
- if i < n then
- (
- let element = data.(i) in
- if column < (channel - 1) then
- element ^ "," ^ (to_string_rec data channel n (i + 1) (column + 1))
- else if column = (channel - 1) then
- element ^ "\n" ^ (to_string_rec data channel n (i + 1) 0)
- else raise (Invalid_argument "write_output_txt.")
- )
- else "" in
- to_string_rec data_string_array channel_int data_length 0 0 in
-
- let data_string_list = List.map2 array_to_string data_string_array_list channel_int_list in
- let _ = List.map2 output_string file_list data_string_list in
- let _ = List.map close_out file_list in
- let toc = Sys.time () in
- print_endline(" Done. (duration: " ^ (string_of_float (toc -. tic)) ^ "s)");;