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

SCM Repository

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

Annotation of /branches/pure-cfg/src/compiler/fields/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 :     * This module supports running the dnorm program on a nrrd file.
9 :     *)
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 :     (* search path for the dnorm executable *)
23 : jhr 632 val paths = [
24 :     "@DIDEROT_ROOT@/bin", "@prefix@/bin"
25 : jhr 127 ]
26 :    
27 : jhr 632 (* FIXME: with SML/NJ 110.73, we'll be able to use PathUtil.findExe *)
28 :     fun findExe () = let
29 :     fun isExe p = OS.FileSys.access(p, [OS.FileSys.A_EXEC])
30 :     in
31 :     case PathUtil.existsFile isExe paths "dnorm"
32 :     of SOME cmd => cmd
33 :     | NONE => raise Fail "unable to find dnorm executable"
34 :     (* end case *)
35 :     end
36 : jhr 127
37 : jhr 708 fun run srcFile = if OS.FileSys.access(srcFile, [OS.FileSys.A_READ])
38 :     then let
39 :     val proc = Unix.execute (findExe(), ["-h", "-i", srcFile])
40 :     val inS = Unix.textInstreamOf proc
41 :     fun stripWS ss = SS.string (SS.dropl Char.isSpace (SS.dropr Char.isSpace ss))
42 :     fun read content = (case TextIO.inputLine inS
43 :     of SOME "\n" => read content (* dnorm outputs an extra blank line at the end *)
44 :     | SOME ln => (
45 :     case SS.fields (fn #":" => true | _ => false) (SS.full ln)
46 :     of [name, value] =>
47 :     read((SS.string name, stripWS value)::content)
48 :     | _ => raise Fail(concat["bogus nrrd header line \"", String.toString ln, "\""])
49 :     (* end case *))
50 :     | NONE => List.rev content
51 :     (* end case *))
52 :     val info = (case TextIO.inputLine inS
53 :     of SOME version => {
54 :     version = stripWS(SS.full version),
55 :     header = read []
56 :     }
57 :     | NONE => raise Fail "bogus nrrd file"
58 :     (* end case *))
59 :     val sts = Unix.reap proc
60 :     in
61 :     if OS.Process.isSuccess sts
62 :     then info
63 :     else raise Fail "error running dnorm"
64 :     end
65 :     else raise Fail(concat["image file \"", srcFile, "\" not found"])
66 : jhr 127 end

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