-
Notifications
You must be signed in to change notification settings - Fork 2
/
comtrade.go
40 lines (36 loc) · 977 Bytes
/
comtrade.go
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
package comtrade
type Comtrade struct {
Conf *ComtradeCfg
Data *Data
}
func ParseComtrade(configurePath, datafilePath string) (comtrade *Comtrade, err error) {
c := &Comtrade{}
c.Conf, err = c.parseComtradeConfig(configurePath)
if err != nil {
return nil, err
}
c.Data, err = c.parseComtradeData(datafilePath)
if err != nil {
return nil, err
}
return c, nil
}
func (c *Comtrade) parseComtradeConfig(configurePath string) (*ComtradeCfg, error) {
comtradeConfig, err := ParseComtradeCfg(configurePath)
if err != nil {
return nil, err
}
return comtradeConfig, nil
}
func (c *Comtrade) parseComtradeData(datafilePath string) (*Data, error) {
creator, ok := Parsers[c.Conf.Ft]
if !ok {
return nil, ErrUnknownTypeOfData
}
parser := creator()
comtradeData, err := parser.Parse(datafilePath, c.Conf.GetAnalogNum(), c.Conf.GetDigitalNum(), c.Conf.GetEndSamp()[len(c.Conf.GetEndSamp())-1])
if err != nil {
return nil, err
}
return comtradeData, nil
}