summaryrefslogtreecommitdiff
path: root/packages/hmatrix/src/Numeric/IO.hs
diff options
context:
space:
mode:
Diffstat (limited to 'packages/hmatrix/src/Numeric/IO.hs')
-rw-r--r--packages/hmatrix/src/Numeric/IO.hs48
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
15module 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
22import Data.Packed
23import Data.Packed.IO
24import System.Process(readProcess)
25import 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-}
31fileDimensions :: FilePath -> IO (Int,Int)
32fileDimensions 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.
42loadMatrix :: FilePath -> IO (Matrix Double)
43loadMatrix 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).
46fromFile :: FilePath -> (Int,Int) -> IO (Matrix Double)
47fromFile filename (r,c) = reshape c `fmap` fscanfVector filename (r*c)
48