diff options
author | Alberto Ruiz <aruiz@um.es> | 2014-05-16 20:10:57 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2014-05-16 20:10:57 +0200 |
commit | d4d9082a8d7d3eed6cb5f188fc3b476847dcac27 (patch) | |
tree | 0a19bc18be429454fd59c16fd46e29e1e7bae722 /packages/hmatrix/src/Numeric/IO.hs | |
parent | 51f4cc7b4b301142b8df73568ffaa448f9e6dd50 (diff) |
GSL.LinearAlgebra reorganized
Diffstat (limited to 'packages/hmatrix/src/Numeric/IO.hs')
-rw-r--r-- | packages/hmatrix/src/Numeric/IO.hs | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/packages/hmatrix/src/Numeric/IO.hs b/packages/hmatrix/src/Numeric/IO.hs deleted file mode 100644 index 08d812b..0000000 --- a/packages/hmatrix/src/Numeric/IO.hs +++ /dev/null | |||
@@ -1,48 +0,0 @@ | |||
1 | ----------------------------------------------------------------------------- | ||
2 | -- | | ||
3 | -- Module : Numeric.IO | ||
4 | -- Copyright : (c) Alberto Ruiz 2010 | ||
5 | -- License : GPL | ||
6 | -- | ||
7 | -- Maintainer : Alberto Ruiz <aruiz@um.es> | ||
8 | -- Stability : provisional | ||
9 | -- Portability : portable | ||
10 | -- | ||
11 | -- Display, formatting and IO functions for numeric 'Vector' and 'Matrix' | ||
12 | -- | ||
13 | ----------------------------------------------------------------------------- | ||
14 | |||
15 | module Numeric.IO ( | ||
16 | dispf, disps, dispcf, vecdisp, latexFormat, format, | ||
17 | loadMatrix, saveMatrix, fromFile, fileDimensions, | ||
18 | readMatrix, fromArray2D, | ||
19 | fscanfVector, fprintfVector, freadVector, fwriteVector | ||
20 | ) where | ||
21 | |||
22 | import Data.Packed | ||
23 | import Data.Packed.IO | ||
24 | import System.Process(readProcess) | ||
25 | import Numeric.GSL.Vector | ||
26 | |||
27 | |||
28 | {- | obtains the number of rows and columns in an ASCII data file | ||
29 | (provisionally using unix's wc). | ||
30 | -} | ||
31 | fileDimensions :: FilePath -> IO (Int,Int) | ||
32 | fileDimensions fname = do | ||
33 | wcres <- readProcess "wc" ["-w",fname] "" | ||
34 | contents <- readFile fname | ||
35 | let tot = read . head . words $ wcres | ||
36 | c = length . head . dropWhile null . map words . lines $ contents | ||
37 | if tot > 0 | ||
38 | then return (tot `div` c, c) | ||
39 | else return (0,0) | ||
40 | |||
41 | -- | Loads a matrix from an ASCII file formatted as a 2D table. | ||
42 | loadMatrix :: FilePath -> IO (Matrix Double) | ||
43 | loadMatrix file = fromFile file =<< fileDimensions file | ||
44 | |||
45 | -- | Loads a matrix from an ASCII file (the number of rows and columns must be known in advance). | ||
46 | fromFile :: FilePath -> (Int,Int) -> IO (Matrix Double) | ||
47 | fromFile filename (r,c) = reshape c `fmap` fscanfVector filename (r*c) | ||
48 | |||