1. Sergey Astanin
  2. hs-matrix-market

Commits

Sergey Astanin  committed a59217b

Read matrix comments too.

  • Participants
  • Parent commits 51d55c5
  • Branches default

Comments (0)

Files changed (1)

File MatrixMarket.hs

View file
 data Matrix = MM
   { mm'data :: MatrixData
   , mm'symmetry :: Symmetry
+  , mm'comments :: [String]
   } deriving (Show)
 
 -- | Matrix' data block.
   where
   readMM' s =
     let hdr  = safeHead $ lines s
-        lins = filter (not . (`startsWith` "%")) $ lines s  -- skip comments
+        (clins,lins) = span (`startsWith` "%") $ lines s
+        coms = map (drop 1) (drop 1 clins)  -- comments
         toks = concatMap words lins
     in  case words . map toLower $ hdr of
         ("%%matrixmarket":"matrix":fmt:fieldq:symq:_) ->
               sy = lookup symq symmetries :: Maybe Symmetry
               p' = uncurry <$> p <*> nr :: Maybe ([String] -> Maybe MatrixData)
               d = join $ p' <*> (Just toks) :: Maybe MatrixData
-              m = MM <$> d <*> sy :: Maybe Matrix
+              m = MM <$> d <*> sy <*> (Just coms) :: Maybe Matrix
           in  case m of
               Just m' -> Right m'
               Nothing -> Left $