comgo

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2020 License: MIT Imports: 12 Imported by: 0

README

Comgo

Comgo is a GO based tiny project for parsing COMTRADE files.

Description
COMTRADE - Common format for Transient Data Exchange for power systems
COMTRADE files

Each COMTRADE record has a set of up to four files associated with it.

Type Name Description Usage
xxxxxxxx.HDR Header file (Optional) ASCII text file (Desired format) Up to user
xxxxxxxx.CFG Configuration file (Essential) ASCII text file (Specific format) Interprets .DAT file
xxxxxxxx.DAT Data file (Essential) ASCII or binary format (Specific format) Store value for channels
xxxxxxxx.INF Information file (Optional) ASCII or binary format (Desired format) Contains extra information

Useful sites powergridapp, pycomtrade

Usage

a. Download and install it

    $ go get github.com/ValleyZw/comgo

b. Import it in your code

    import "github.com/ValleyZw/comgo"

c. Init private variable

    cfg := comgo.New()

d. Open and read cfg

    file, err := os.Open(cfgFile)
    err := cfg.ReadCFG(file)

e. Open and read dat

    file, err := os.Open(datFile)
    err := cfg.ReadDAT(file)

f. Get value of specific channel

points, err := cfg.GetAnalogChannelData(channelNum)

Documentation

Index

Constants

View Source
const TimeFormat = "02/01/2006T15:04:05.000000"

Variables

This section is empty.

Functions

func ByteToString

func ByteToString(b []byte) string

Convert []byte type file content to string Delete extra space

Types

type BinData

type BinData struct {
	Sample int32
	Stamp  int32
	Value  []int16
}

* BinData - Dat date structure * @Sample: Sample series * @Stamp: Time Stamp * @Value: Analog values: y = factorA * x + factorB

func (*BinData) GetSample

func (m *BinData) GetSample() int32

func (*BinData) GetStamp

func (m *BinData) GetStamp() int32

func (*BinData) GetValue

func (m *BinData) GetValue() []int16

type CFG

type CFG struct {
	StationName     string
	RecordDeviceId  string
	RevisionYear    uint16
	ChannelNumber   uint16
	AnalogDetail    *ChannelA
	DigitDetail     *ChannelD
	LineFrequency   uint16
	SampleRateNum   uint16
	SampleDetail    []SampleRate
	StartTime       time.Time
	TriggerTime     time.Time
	DataFileType    string
	TimeFactor      float64
	TimeCode        string
	LocalCode       string
	DataFileContent []byte
}

* CFG - Configuration parameters * @StationName: Name of the station * @RecordDeviceId: Identification of the recording device * @RevisionYear: COMTRADE standard revision year * @ChannelNumber: Number of channels * @ChannelType: Type of channels * @AnalogDetail: Analog channel details * @DigitDetail: Digit channel details * @LineFrequency: line frequency * @SampleRateNum: Sampling rate(s) * @SampleDetail: Number of samples at each rate * @StartTime: Date and time of first data point * @TriggerTime: Date and time of trigger point * @DataFileType: Data file type * @TimeFactor: Time Stamp multiplication factor * @DataFileContent: Store data file content

func NewCFG

func NewCFG() CFG

NewCFG returns configuration parameters of COMTRADE files.

func (*CFG) GetAnalogChannelData

func (cfg *CFG) GetAnalogChannelData(num uint16) (result []float64, err error)

Returns an array of numbers containing the data values of the channel number num is the number of the channel as in .cfg file

func (*CFG) GetAnalogChannelNames

func (cfg *CFG) GetAnalogChannelNames() []string

Return the names of all analog channel

func (*CFG) GetAnalogDetail

func (cfg *CFG) GetAnalogDetail() *ChannelA

func (*CFG) GetChannelNumber

func (cfg *CFG) GetChannelNumber() uint16

func (*CFG) GetDataFileContent

func (cfg *CFG) GetDataFileContent() []byte

func (*CFG) GetDataFileType

func (cfg *CFG) GetDataFileType() string

func (*CFG) GetDigitDetail

func (cfg *CFG) GetDigitDetail() *ChannelD

func (*CFG) GetLineFrequency

func (cfg *CFG) GetLineFrequency() uint16

func (*CFG) GetLocalCode

func (cfg *CFG) GetLocalCode() string

func (*CFG) GetRecordDeviceId

func (cfg *CFG) GetRecordDeviceId() string

func (*CFG) GetRevisionYear

func (cfg *CFG) GetRevisionYear() uint16

func (*CFG) GetSampleDetail

func (cfg *CFG) GetSampleDetail() []SampleRate

func (*CFG) GetSampleRateNum

func (cfg *CFG) GetSampleRateNum() uint16

func (*CFG) GetSamplingNumber

func (cfg *CFG) GetSamplingNumber() int

Return the number of samples only one sampling rate is taking into account

func (*CFG) GetSamplingRate

func (cfg *CFG) GetSamplingRate() float64

Return the sampling rate only one sampling rate is taking into account

func (*CFG) GetStartTime

func (cfg *CFG) GetStartTime() time.Time

func (*CFG) GetStationName

func (cfg *CFG) GetStationName() string

func (*CFG) GetTimeCode

func (cfg *CFG) GetTimeCode() string

func (*CFG) GetTimeCodeOffset

func (cfg *CFG) GetTimeCodeOffset() int64

GetTimeCodeOffset returns the time difference between local time and UTC in nanoseconds sample formats: “+10h30”, "-4t", “-7h15”, "0"

func (*CFG) GetTimeFactor

func (cfg *CFG) GetTimeFactor() float64

func (*CFG) GetTriggerTime

func (cfg *CFG) GetTriggerTime() time.Time

func (*CFG) ReadCFG

func (cfg *CFG) ReadCFG(rd io.Reader) (err error)

Reads the Comtrade header file (.cfg). return empty CFG and error if err != nil

func (*CFG) ReadDAT

func (cfg *CFG) ReadDAT(rd io.Reader) (err error)

Reads the contents of the Comtrade .dat file Store the contents in a private variable

type ChannelA

type ChannelA struct {
	ChannelTotal           uint16
	ChannelNumber          []uint16
	ChannelNames           []string
	ChannelPhases          []string
	ChannelElements        []string
	ChannelUnits           []string
	ConversionFactors      map[string][]float64
	TimeFactors            []float64
	ValueMin               []int
	ValueMax               []int
	Primary                []float64
	Secondary              []float64
	IsSecondaryMeasurement []bool
}

* ChannelA - Analog channel parameters * @ChannelTotal: Total number of channels * @ChannelNumber: Channel number series * @ChannelNames: Names of each channel * @ChannelPhases: Phases of each channel * @ChannelElements: Channel element (usually null) * @ChannelUnits: Units of each channel * @ConversionFactors: Conversion factor A and B * @TimeFactors: Time factors of each channels * @ValueMin: Min Value of each channels * @ValueMax: Max Value of each channels * @Primary: Primary ratios * @Secondary: Secondary ratios

func (*ChannelA) GetChannelElements

func (m *ChannelA) GetChannelElements() []string

func (*ChannelA) GetChannelNames

func (m *ChannelA) GetChannelNames() []string

func (*ChannelA) GetChannelNumber

func (m *ChannelA) GetChannelNumber() []uint16

func (*ChannelA) GetChannelPhases

func (m *ChannelA) GetChannelPhases() []string

func (*ChannelA) GetChannelTotal

func (m *ChannelA) GetChannelTotal() uint16

func (*ChannelA) GetChannelUnits

func (m *ChannelA) GetChannelUnits() []string

func (*ChannelA) GetConversionFactors

func (m *ChannelA) GetConversionFactors() map[string][]float64

func (*ChannelA) GetPrimary

func (m *ChannelA) GetPrimary() []float64

func (*ChannelA) GetSecondary

func (m *ChannelA) GetSecondary() []float64

func (*ChannelA) GetTimeFactors

func (m *ChannelA) GetTimeFactors() []float64

func (*ChannelA) GetValueMax

func (m *ChannelA) GetValueMax() []int

func (*ChannelA) GetValueMin

func (m *ChannelA) GetValueMin() []int

type ChannelD

type ChannelD struct {
	ChannelTotal    uint16
	ChannelNumber   []uint16
	ChannelNames    []string
	ChannelPhases   []string
	ChannelElements []string
	InitialState    []uint8
}

* ChannelD - Digit channel parameters * @ChannelTotal: Total number of channels * @ChannelNumber: Channel number series * @ChannelNames: Names of each channel * @ChannelPhases: Phases of each channel * @ChannelElements: Channel element (usually null)

func (*ChannelD) GetChannelElements

func (m *ChannelD) GetChannelElements() []string

func (*ChannelD) GetChannelNames

func (m *ChannelD) GetChannelNames() []string

func (*ChannelD) GetChannelNumber

func (m *ChannelD) GetChannelNumber() []uint16

func (*ChannelD) GetChannelPhases

func (m *ChannelD) GetChannelPhases() []string

func (*ChannelD) GetChannelTotal

func (m *ChannelD) GetChannelTotal() uint16

func (*ChannelD) GetInitialState

func (m *ChannelD) GetInitialState() []uint8

type SampleRate

type SampleRate struct {
	Rate   float64
	Number int
}

* SampleRate - Sampling rate and sampling number * @Rate: Sampling rate * @Number: Total number under current sampling rate

func (*SampleRate) GetNumber

func (m *SampleRate) GetNumber() int

func (*SampleRate) GetRate

func (m *SampleRate) GetRate() float64

Directories

Path Synopsis
examples
cg
wg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL