1 {-# LANGUAGE DeriveDataTypeable #-}
10 -- Get the version from Cabal.
11 import Paths_spline3 (version)
12 import Data.Version (showVersion)
14 import Data.String.Utils (startswith)
15 import System.Console.CmdArgs (
35 import System.Console.CmdArgs.Explicit (process)
36 import System.Environment (getArgs, withArgs)
37 import System.Exit (ExitCode(..), exitWith)
38 import System.IO (hPutStrLn, stderr)
52 deriving (Show, Data, Typeable)
56 "Interpolate volumetric data according to \"Local quasi-interpolation " ++
57 "by cubic C^1 splines on type-6 tetrahedral partitions.\" The defaults " ++
58 "are tailored to the MRI data contained in data/mri.bin from the " ++
59 "Stanford volume data archive at http://graphics.stanford.edu/data/voldata/."
61 program_name :: String
62 program_name = "spline3"
64 spline3_summary :: String
66 program_name ++ "-" ++ (showVersion version)
69 depth_help = "The size of the z dimension (default: 109)"
72 height_help = "The size of the y dimension (default: 256)"
76 "The magnification scale. A scale of 2 would result " ++
77 "in an image twice as large as the original. (default: 2)"
81 "The index of the two-dimensional slice to use if no depth is specified"
84 width_help = "The size of the x dimension (default: 256)"
86 arg_spec :: Mode (CmdArgs Args)
90 depth = 109 &= groupname "Dimensions" &= help depth_help,
91 height = 256 &= groupname "Dimensions" &= help height_help,
92 input = def &= typ "INPUT" &= argPos 0,
93 output = def &= typ "OUTPUT" &= argPos 1,
94 scale = 2 &= help scale_help,
95 slice = Nothing &= groupname "2D options" &= help slice_help,
96 width = 256 &= groupname "Dimensions" &= help width_help
98 &= program program_name
99 &= summary spline3_summary
100 &= details [description]
101 &= helpArg [groupname "Common flags"]
102 &= versionArg [groupname "Common flags"]
104 -- Infix notation won't work, the arguments are backwards!
105 is_missing_arg_error :: String -> Bool
106 is_missing_arg_error s =
107 startswith "Requires at least" s
111 show_help = withArgs ["--help"] apply_args
113 parse_args :: IO (CmdArgs Args)
116 let y = process arg_spec x
118 Right result -> return result
120 if (is_missing_arg_error err) then
121 -- Start this function over, pretending that --help was
123 withArgs ["--help"] parse_args
126 exitWith (ExitFailure exit_arg_parse_failed)
129 -- | Really get the command-line arguments. This calls 'parse_args'
130 -- first to replace the default "wrong number of arguments" error,
131 -- and then runs 'cmdArgsApply' on the result to do what the
132 -- 'cmdArgs' function usually does.
133 apply_args :: IO Args
135 parse_args >>= cmdArgsApply