-
Notifications
You must be signed in to change notification settings - Fork 2
/
lt2csv.go
59 lines (43 loc) · 878 Bytes
/
lt2csv.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"flag"
"fmt"
"log"
"github.com/GaryBoone/GoStats/stats"
"github.com/rveen/ltspice"
)
func main() {
var header bool
flag.BoolVar(&header, "t", false, "Print text header")
flag.Parse()
file := ""
if len(flag.Args()) > 0 {
file = flag.Args()[0]
}
m, vars, err := ltspice.Raw(file)
if err != nil {
log.Println(err)
}
if m == nil {
log.Println("null matrix")
}
col := len(m)
row := len(m[0])
if header {
for j := 1; j < col; j++ {
mean := stats.StatsMean(m[j])
sdev := stats.StatsSampleStandardDeviation(m[j]) // This includes Bessel correction (which is ok!)
fmt.Printf("%-20s %30g %30g %30g\n", "'"+vars[j]+"'", mean, sdev, sdev/mean)
}
return
}
for i := 0; i < row; i++ {
for j := 0; j < col; j++ {
fmt.Printf("%g", m[j][i])
if j < col-1 {
fmt.Print(", ")
}
}
fmt.Println("")
}
}