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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 127 - (view) (download)
Original Path: trunk/src/compiler/image-info/run-dnorm_sml.in

1 : jhr 127 (* run-dnorm_sml.in
2 :     *
3 :     * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *
6 :     * This module supports running the dnorm program on a nrrd file.
7 :     *)
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 :     (* search path for the dnorm executable *)
21 :     val path = [
22 :     "@DIDEROT_ROOT@/bin/dnorm", "@prefix@/bin/dnorm"
23 :     ]
24 :    
25 :     fun findExe () = (
26 :     case List.find (fn p => OS.FileSys.access(p, [OS.FileSys.A_EXEC])) path
27 :     of SOME cmd => cmd
28 :     | NONE => raise Fail "unable to find dnorm executable"
29 :     (* end case *))
30 :    
31 :     fun run srcFile = let
32 :     val proc = Unix.execute (findExe(), ["-h", "-i", srcFile])
33 :     val inS = Unix.textInstreamOf proc
34 :     fun stripWS ss = SS.string (SS.dropl Char.isSpace (SS.dropr Char.isSpace ss))
35 :     fun read content = (case TextIO.inputLine inS
36 :     of SOME "\n" => read content (* dnorm outputs an extra blank line at the end *)
37 :     | SOME ln => (
38 :     case SS.fields (fn #":" => true | _ => false) (SS.full ln)
39 :     of [name, value] =>
40 :     read((SS.string name, stripWS value)::content)
41 :     | _ => raise Fail(concat["bogus nrrd header line \"", String.toString ln, "\""])
42 :     (* end case *))
43 :     | NONE => List.rev content
44 :     (* end case *))
45 :     val info = (case TextIO.inputLine inS
46 :     of SOME version => {
47 :     version = stripWS(SS.full version),
48 :     header = read []
49 :     }
50 :     | NONE => raise Fail "bogus nrrd file"
51 :     (* end case *))
52 :     val sts = Unix.reap proc
53 :     in
54 :     if OS.Process.isSuccess sts
55 :     then info
56 :     else raise Fail "error running dnorm"
57 :     end
58 :    
59 :     end

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