From: WANG Date: Fri, 27 Sep 2013 15:07:30 +0000 (+0200) Subject: Bugs fixed for stdin and stdout. X-Git-Url: https://scm.cri.ensmp.fr/git/Faustine.git/commitdiff_plain/e3449439410ee92986e5ef95fc933813dfa6c67b?hp=c55d1f23d06e85b0e21cdf5cbc5c8efb6ac3bc1a Bugs fixed for stdin and stdout. --- diff --git a/examples/dilation/Makefile b/examples/dilation/Makefile index 3d2c6dd..93a2ece 100644 --- a/examples/dilation/Makefile +++ b/examples/dilation/Makefile @@ -2,10 +2,8 @@ SRC = dilation.dsp IMGIN = letter_j.png LINES = 150 -BASENAME = output -FORMAT = csv +CSVOUT = dilation.csv CSVIN = $(IMGIN:.png=.csv) -CSVOUT = $(BASENAME)1.$(FORMAT) IMGOUT = $(SRC:.dsp=.png) all: $(IMGOUT) @@ -14,10 +12,10 @@ $(IMGOUT): $(CSVOUT) octave -qf img_write.m $(CSVOUT): $(SRC) $(CSVIN) - faustine -f $(SRC) -i $(CSVIN) -l $(LINES) --oformat $(FORMAT) --obasename $(BASENAME) + faustine -f $(SRC) -l $(LINES) < $(CSVIN) 1> $@ $(CSVIN): $(IMGIN) octave -qf img_read.m clean:: - rm -f gmon.out $(IMGOUT) $(BASENAME)* + rm -f gmon.out $(IMGOUT) $(CSVOUT) diff --git a/examples/dilation/img_write.m b/examples/dilation/img_write.m index 574f59d..85d5b81 100644 --- a/examples/dilation/img_write.m +++ b/examples/dilation/img_write.m @@ -1,4 +1,4 @@ a = imread('letter_j.png' ); -b = csvread('output1.csv' ); +b = csvread('dilation.csv' ); imwrite(b, 'dilation.png'); diff --git a/examples/primitives/Makefile b/examples/primitives/Makefile index fb73fc3..7494e85 100644 --- a/examples/primitives/Makefile +++ b/examples/primitives/Makefile @@ -2,14 +2,12 @@ EXAMPLE = primitives SRC = $(EXAMPLE).dsp SAMPLES = 30 -BASENAME = output -FORMAT = csv -CSVOUT = $(BASENAME)1.$(FORMAT) +FILEOUT = primitives.csv -all: $(CSVOUT) +all: $(FILEOUT) -$(CSVOUT): $(SRC) - faustine -f $(SRC) -l $(SAMPLES) --oformat $(FORMAT) --obasename $(BASENAME) +$(FILEOUT): $(SRC) + faustine -f $(SRC) -l $(SAMPLES) 1> $@ 2> toto.txt clean:: - rm -f gmon.out output* + rm -f gmon.out $(FILEOUT) diff --git a/examples/sinwave/Makefile b/examples/sinwave/Makefile index 064b7c8..cdd957c 100644 --- a/examples/sinwave/Makefile +++ b/examples/sinwave/Makefile @@ -7,7 +7,7 @@ WAVOUT = $(BASENAME)1.$(FORMAT) all: $(WAVOUT) $(WAVOUT): $(SRC) - faustine -f $< --obasename $(BASENAME) --oformat $(FORMAT) + faustine -f $< > sin.wav clean:: - rm -f gmon.out $(BASENAME)* + rm -f gmon.out $(BASENAME)* *.wav *~ diff --git a/interpreter/aux.ml b/interpreter/aux.ml index 5321349..0564c30 100644 --- a/interpreter/aux.ml +++ b/interpreter/aux.ml @@ -34,3 +34,9 @@ let remainder_float : float -> float -> float = if (abs_float r) > ((abs_float f2) /. 2.) then (if r *. f2 > 0. then (r -. f2) else (r +. f2)) else r;; + +let format_of_file : string -> string = + fun (path : string) -> + let fragments = Str.split (Str.regexp "\.") path in + let n = List.length fragments in + List.nth fragments (n - 1);; diff --git a/interpreter/faustio.ml b/interpreter/faustio.ml index 47e07ce..9539bf3 100644 --- a/interpreter/faustio.ml +++ b/interpreter/faustio.ml @@ -79,7 +79,7 @@ class waveio : io_type = Array.init n (fun i -> _dir ^ _basename ^ (string_of_int (i + 1)) ^ ".wav") else if n = 1 then - let () = Unix.unlink "_filename" in [|(_filename ^ ".wav")|] + let () = Unix.unlink _filename in [|_filename|] else raise (Faustine_IO_Error ("The process has several output signals, however stdout supports only one output signal. Please remove the '> " ^ _filename ^ "'.")) in @@ -141,7 +141,7 @@ class csvio : io_type = Array.init n (fun i -> _dir ^ _basename ^ (string_of_int (i + 1)) ^ ".csv") else if n = 1 then - let () = Unix.unlink _filename in [|(_filename ^ ".csv")|] + let () = Unix.unlink _filename in [|_filename|] else raise (Faustine_IO_Error ("The process has several output signals, however stdout supports only one output signal. Please remove the '> " ^ _filename ^ "'.")) in @@ -171,15 +171,9 @@ class iomanager = val mutable _format = "" val mutable _basename = "" - method private grab_format : string -> string = - fun (path : string) -> - let fragments = Str.split (Str.regexp "\.") path in - let n = List.length fragments in - List.nth fragments (n - 1) - method read : string list -> beam_type = fun (paths : string list) -> - let formats = List.map self#grab_format paths in + let formats = List.map format_of_file paths in let read_one : string -> string -> beam_type = fun (format : string) -> fun (path : string) -> @@ -206,12 +200,19 @@ class iomanager = method write : rate array -> data -> string array = fun (rates : rate array) -> fun (data : data) -> - if _format = "" then - raise (Invalid_argument "output format unset.") - else if _format = "wav" then - wave#write rates data - else if _format = "csv" then - csv#write rates data - else raise (Invalid_argument "unknown format.") - + if _output_filename = "" then ( + if _format = "" then + raise (Invalid_argument "output format unset.") + else if _format = "wav" then + wave#write rates data + else if _format = "csv" then + csv#write rates data + else raise (Invalid_argument "unknown format.")) + else ( + let format = format_of_file _output_filename in + if format = "wav" then + wave#write rates data + else if format = "csv" then + csv#write rates data + else raise (Invalid_argument ("unknown format" ^ format))) end;; diff --git a/interpreter/main.ml b/interpreter/main.ml index 2f102f3..3c5ef42 100644 --- a/interpreter/main.ml +++ b/interpreter/main.ml @@ -35,7 +35,7 @@ let inputs = ref [];; let time_max = ref 0xFFFF;; let dir_output = ref "";; let format_output = ref "csv";; -let basename_output = ref "output";; +let basename_output = ref "";; let output = ref "";; let option_usage = "usage: " ^ Sys.argv.(0)