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

SCM Repository

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

Annotation of /trunk/src/compiler/nrrd/run-dnorm_sml.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3349 - (view) (download)

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

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