hepevt (empty) → 0.1
raw patch · 4 files changed
+133/−0 lines, 4 filesdep +bytestringdep +haskell2010setup-changed
Dependencies added: bytestring, haskell2010
Files
- Data/HEPEVT.hs +50/−0
- LICENSE +19/−0
- Setup.hs +2/−0
- hepevt.cabal +62/−0
+ Data/HEPEVT.hs view
@@ -0,0 +1,50 @@+{-|++This modules provides a pure haskell implementation of a reader and writer for+the ASCII HEPEVT file format.++-}+module Data.HEPEVT (+ Event,++ parseEventFile,+ parseEvents,+) where++import qualified Data.ByteString.Char8 as S++type Event = ([Double], [[Double]])++parseEventFile :: String -> IO [Event]+parseEventFile fname = do+ S.readFile fname >>= return . parseEvents fname++data Line = Meta String | E [Double] | P [Double] | V [Double] | Blank+ deriving (Show, Eq)++parseLine :: String -> Line+parseLine line =+ let ws = words line in+ parseLine' ws line+ where+ parseLine' ("E":xs) _ = E $ map parseDouble xs+ parseLine' ("P":xs) _ = P $ map parseDouble xs+ parseLine' ("V":xs) _ = V $ map parseDouble xs+ parseLine' _ line = if length line > 1 then Meta line else Blank++getLines :: [String] -> [Line]+getLines = map parseLine++type ParseState = [Event]++parseEvents :: String -> S.ByteString -> [Event]+parseEvents fname dat =+ let ls = S.split '\n' dat in + reverse $ foldl process [] $ getLines (map S.unpack ls)+ where+ process events (E ds) = (ds, []):events+ process ((el, vl):events) (V ds) = (el, ds:vl):events+ process events _ = events++parseDouble :: String -> Double+parseDouble = read . reverse . dropWhile (=='.') . reverse
+ LICENSE view
@@ -0,0 +1,19 @@+Copyright (c) 2011 Scott Lawrence <bytbox@gmail.com>++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ hepevt.cabal view
@@ -0,0 +1,62 @@+-- hepevt.cabal auto-generated by cabal init. For additional options,+-- see+-- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.+-- The name of the package.+Name: hepevt++-- The package version. See the Haskell package versioning policy+-- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for+-- standards guiding when and how versions should be incremented.+Version: 0.1++-- A short (one-line) description of the package.+Synopsis: HEPEVT parser and writer++-- A longer description of the package.+Description: This package implements a parser and writer for the ASCII HEPEVT event log file format++-- The license under which the package is released.+License: MIT++-- The file containing the license text.+License-file: LICENSE++-- The package author(s).+Author: Scott Lawrence++-- An email address to which users can send suggestions, bug reports,+-- and patches.+Maintainer: bytbox@gmail.com++-- A copyright notice.+-- Copyright: ++Category: Physics++Build-type: Simple++-- Extra files to be distributed with the package, such as examples or+-- a README.+-- Extra-source-files: ++-- Constraint on the version of Cabal needed to build this package.+Cabal-version: >=1.6+++Library+ -- Modules exported by the library.+ Exposed-modules: Data.HEPEVT+ + -- Packages needed in order to build this package.+ Build-depends: haskell2010 >= 1.0, bytestring>=0.9+ + -- Modules not exported by this package.+ -- Other-modules: + + -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.+ -- Build-tools: ++source-repository head+ type: git+ location: https://github.com/bytbox/hepevt.hs.git+