-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimplevector.hs
More file actions
48 lines (39 loc) · 1.26 KB
/
Copy pathsimplevector.hs
File metadata and controls
48 lines (39 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{-# LANGUAGE BangPatterns, OverloadedStrings #-}
import Data.ByteString.Lex.Double (readDouble)
import Data.Vector.Binary
import Data.Binary
import qualified Data.ByteString.Char8 as L
import qualified Data.Vector.Unboxed as V
main = do
s <- L.readFile "dat"
let v = parse s :: V.Vector Int
print v
-- Fill a new vector from a file containing a list of numbers.
parse = V.unfoldr step
where
step !s = case L.readInt s of
Nothing -> Nothing
Just (!k, !t) -> Just (k, L.tail t)
toDouble :: L.ByteString -> Double
toInt xs = case L.readInt xs of
Just (d,s) -> d
Nothing -> 0
toDouble xs = case (readDouble.L.intercalate ".".L.split ',' $ xs) of
Just (d,s) -> d
Nothing -> 0
{-
let kpiData toX n = map (toX.(rows!!).(+53*n)) [1..52]
kpiName = map (\n -> rows!!(53*n)) $ [0..72]
kpiIndMap = M.fromList $ zip kpiName [0..]
-- take 2 decimals
trunc :: Double -> Double
trunc double = (fromInteger $ round $ double * (10^2)) / (10.0 ^^2)
-- reads double or put 0
toDouble :: String -> Double
toDouble xs = case (reads.chgComma.endBy "," $ xs :: [(Double,String)] ) of
[(d,s)] -> d
_ -> 0
where
chgComma [x,y] = x ++ "." ++ (take 2 y)
chgComma xs = concat xs
-}