hnutmeg-0.3.7.0
Safe HaskellNone
LanguageHaskell2010

Data.NutMeg

Description

Read Binary NutMeg Data

Synopsis

Data Types

type NutMeg = [(String, Plot)] Source #

A NutMeg file consists of a list of Plots [(Plotname, Plot@)] Plotnames do not have to be unique in a NutMeg file. Data may be lost by turning this into a Map.

type Plot = Map String Wave Source #

A Plot inside a NutMeg file consists of uniquely identified waveforms: [(Variable Name, Waveform)]

type RealPlot = Map String (Vector Double) Source #

Type alias for real valued Plot

type ComplexPlot = Map String (Vector (Complex Double)) Source #

Type alias for complex valued Plot

data Wave Source #

Wrapper around Real or Complex valued Vector, so they can be stored in the same List.

Constructors

RealWave !(Vector Double)

Real valued (Double) wave form

ComplexWave !(Vector (Complex Double))

Complex valued ('Complex Double') wave form

Instances

Instances details
Eq Wave Source # 
Instance details

Defined in Data.NutMeg

Methods

(==) :: Wave -> Wave -> Bool #

(/=) :: Wave -> Wave -> Bool #

Show Wave Source # 
Instance details

Defined in Data.NutMeg

Methods

showsPrec :: Int -> Wave -> ShowS #

show :: Wave -> String #

showList :: [Wave] -> ShowS #

Generic Wave Source # 
Instance details

Defined in Data.NutMeg

Associated Types

type Rep Wave :: Type -> Type #

Methods

from :: Wave -> Rep Wave x #

to :: Rep Wave x -> Wave #

NFData Wave Source # 
Instance details

Defined in Data.NutMeg

Methods

rnf :: Wave -> () #

type Rep Wave Source # 
Instance details

Defined in Data.NutMeg

type Rep Wave = D1 ('MetaData "Wave" "Data.NutMeg" "hnutmeg-0.3.7.0-ELSBlxD0euVIEs9ZoUwVOs" 'False) (C1 ('MetaCons "RealWave" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 (Vector Double))) :+: C1 ('MetaCons "ComplexWave" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 (Vector (Complex Double)))))

data Flag Source #

Flag indicating whether a plot is real or complex valued

Constructors

Real'

Real valued (Double) plot

Complex'

Complex valued ('Complex Double') plot

Instances

Instances details
Bounded Flag Source # 
Instance details

Defined in Data.NutMeg

Eq Flag Source # 
Instance details

Defined in Data.NutMeg

Methods

(==) :: Flag -> Flag -> Bool #

(/=) :: Flag -> Flag -> Bool #

Read Flag Source # 
Instance details

Defined in Data.NutMeg

Show Flag Source # 
Instance details

Defined in Data.NutMeg

Methods

showsPrec :: Int -> Flag -> ShowS #

show :: Flag -> String #

showList :: [Flag] -> ShowS #

Generic Flag Source # 
Instance details

Defined in Data.NutMeg

Associated Types

type Rep Flag :: Type -> Type #

Methods

from :: Flag -> Rep Flag x #

to :: Rep Flag x -> Flag #

NFData Flag Source # 
Instance details

Defined in Data.NutMeg

Methods

rnf :: Flag -> () #

type Rep Flag Source # 
Instance details

Defined in Data.NutMeg

type Rep Flag = D1 ('MetaData "Flag" "Data.NutMeg" "hnutmeg-0.3.7.0-ELSBlxD0euVIEs9ZoUwVOs" 'False) (C1 ('MetaCons "Real'" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Complex'" 'PrefixI 'False) (U1 :: Type -> Type))

data Field Source #

Data Field identifier in NutMeg (binary) Files

Constructors

Title

Title of the NutMeg file, usually first line of netlist

Date

Date of creation

Plotname

Name of a Plot

Flags

Whether the Plot is Real or Complex

NoVariables

No. Variables in the Plot

NoPoints

No. Points per Variable

Variables

String representation of Variables in the Plot

Binary

Binary Data, Double or 'Complex Double' encoded in Big Endian

Instances

Instances details
Bounded Field Source # 
Instance details

Defined in Data.NutMeg

Enum Field Source # 
Instance details

Defined in Data.NutMeg

Eq Field Source # 
Instance details

Defined in Data.NutMeg

Methods

(==) :: Field -> Field -> Bool #

(/=) :: Field -> Field -> Bool #

Ord Field Source # 
Instance details

Defined in Data.NutMeg

Methods

compare :: Field -> Field -> Ordering #

(<) :: Field -> Field -> Bool #

(<=) :: Field -> Field -> Bool #

(>) :: Field -> Field -> Bool #

(>=) :: Field -> Field -> Bool #

max :: Field -> Field -> Field #

min :: Field -> Field -> Field #

Show Field Source # 
Instance details

Defined in Data.NutMeg

Methods

showsPrec :: Int -> Field -> ShowS #

show :: Field -> String #

showList :: [Field] -> ShowS #

Generic Field Source # 
Instance details

Defined in Data.NutMeg

Associated Types

type Rep Field :: Type -> Type #

Methods

from :: Field -> Rep Field x #

to :: Rep Field x -> Field #

NFData Field Source # 
Instance details

Defined in Data.NutMeg

Methods

rnf :: Field -> () #

type Rep Field Source # 
Instance details

Defined in Data.NutMeg

type Rep Field = D1 ('MetaData "Field" "Data.NutMeg" "hnutmeg-0.3.7.0-ELSBlxD0euVIEs9ZoUwVOs" 'False) (((C1 ('MetaCons "Title" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Date" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Plotname" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Flags" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "NoVariables" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "NoPoints" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Variables" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Binary" 'PrefixI 'False) (U1 :: Type -> Type))))

Read raw binary data

readFile :: FilePath -> IO NutMeg Source #

Read a binary nutmeg .raw file

Parsing NutMeg binary data

extractPlots :: ByteString -> NutMeg -> NutMeg Source #

Read The first plot encountered in ByteString String: ((Plotname, Plot), Remianing ByteString)

extractPlot Source #

Arguments

:: Flag

Real or Complex Data

-> Int

No. Variables

-> Int

No. Points

-> ByteString

Binary Data

-> [Wave]

Wave forms

Extract the wave forms from binary data given header information

parseHeader :: [ByteString] -> ((String, Flag, Int, Int), [String]) Source #

Extract Plot header information: ((Plotname, Flag, No. Variables, No. Points), [Variable Names])

readField :: Field -> ByteString -> String Source #

Read a NutMeg field from a ByteString

Accessing Plot data

asVector :: Wave -> Either (Vector (Complex Double)) (Vector Double) Source #

Convert Waveform to unboxed Vector, fails horribly if types are incorrect

vectorize :: Plot -> Either ComplexPlot RealPlot Source #

Get rid of Wave type and convert to either 'Complex Double' or Double Vector, depending on Wave type.

flattenPlots :: [String] -> NutMeg -> Plot Source #

Concatenate the Waves of a given list of Plot names. This will only work if the keys line up.

flattenPlots' :: NutMeg -> Plot Source #

Concatenate waves of all Plots in NutMeg. Probably won't work as intended when variable names of the Plots don't line up

asRealPlot :: Plot -> RealPlot Source #

Unsafe extraction of Right value for real valued plots. Check with isReal before using, to be sure

asComplexPlot :: Plot -> ComplexPlot Source #

Unsafe extraction of Left value for complex valued plots. Check with isComplex before using, to be sure

Utilities

concat :: Wave -> Wave -> Wave Source #

Joins two Waves of the same type: wave1 ++ wave2 Attempting to concatenate a Real and Complex wave will result in an error

isReal :: Plot -> Bool Source #

Check whether Plot is real valued

isComplex :: Plot -> Bool Source #

Check whether Plot is complex valued

isReal' :: Wave -> Bool Source #

Check whether waveform is real valued

isComplex' :: Wave -> Bool Source #

Check whether waveform is complex valued

byteSwap :: ByteString -> ByteString Source #

Swap Bytes of Big-Endian encoded ByteString Thanks Noughtmare: https://stackoverflow.com/a/71341067

castByteStringToVector :: Storable a => ByteString -> Vector a Source #

Swap bytes and cast to vector (slow)