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 1997 - (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 :     * 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 : jhr 1116 val paths = [
22 :     "@DIDEROT_ROOT@/bin", "@prefix@/bin"
23 : jhr 127 ]
24 :    
25 : jhr 1783 fun findExe () = (case PathUtil.findExe paths "dnorm"
26 :     of SOME cmd => cmd
27 :     | NONE => raise Fail "unable to find dnorm executable"
28 :     (* end case *))
29 : jhr 1116
30 :     fun run srcFile = if OS.FileSys.access(srcFile, [OS.FileSys.A_READ])
31 :     then 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 :     else raise Fail(concat["image file \"", srcFile, "\" not found"])
59 : jhr 1783
60 : jhr 127 end

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