Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/vis12/src/compiler/nrrd/run-dnorm_sml.in
ViewVC logotype

Annotation of /branches/vis12/src/compiler/nrrd/run-dnorm_sml.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2430 - (view) (download)

1 : jhr 127 (* run-dnorm_sml.in
2 :     *
3 : jhr 1784 * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 : jhr 127 * All rights reserved.
5 :     *
6 : jhr 2430 * This module supports running the teem command "unu dnorm" on a nrrd file.
7 : jhr 127 *)
8 :    
9 :     structure RunDNorm : sig
10 :    
11 :     val run : string -> {
12 :     version : string,
13 :     header : (string * string) list
14 :     }
15 :    
16 :     end = struct
17 :    
18 :     structure SS = Substring
19 :    
20 : jhr 1116 fun run srcFile = if OS.FileSys.access(srcFile, [OS.FileSys.A_READ])
21 :     then let
22 : jhr 2430 val unuCmd = OS.Path.concat(Paths.teemBin(), "unu")
23 :     val proc = Unix.execute (unuCmd, ["dnorm", "-h", "-i", srcFile])
24 : jhr 1116 val inS = Unix.textInstreamOf proc
25 :     fun stripWS ss = SS.string (SS.dropl Char.isSpace (SS.dropr Char.isSpace ss))
26 :     fun read content = (case TextIO.inputLine inS
27 :     of SOME "\n" => read content (* dnorm outputs an extra blank line at the end *)
28 :     | SOME ln => (
29 :     case SS.fields (fn #":" => true | _ => false) (SS.full ln)
30 :     of [name, value] =>
31 :     read((SS.string name, stripWS value)::content)
32 :     | _ => raise Fail(concat["bogus nrrd header line \"", String.toString ln, "\""])
33 :     (* end case *))
34 :     | NONE => List.rev content
35 :     (* end case *))
36 :     val info = (case TextIO.inputLine inS
37 :     of SOME version => {
38 :     version = stripWS(SS.full version),
39 :     header = read []
40 :     }
41 :     | NONE => raise Fail "bogus nrrd file"
42 :     (* end case *))
43 :     val sts = Unix.reap proc
44 :     in
45 :     if OS.Process.isSuccess sts
46 :     then info
47 :     else raise Fail "error running dnorm"
48 :     end
49 :     else raise Fail(concat["image file \"", srcFile, "\" not found"])
50 : jhr 1783
51 : jhr 127 end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0