/
main.go
88 lines (73 loc) · 1.88 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright ©2017 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"flag"
"fmt"
"os"
"go-hep.org/x/hep/slha"
)
func handle(err error) {
if err != nil {
printf("**error: %v\n", err)
panic(err)
}
}
func printf(format string, args ...interface{}) (int, error) {
return fmt.Fprintf(os.Stderr, format, args...)
}
func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
fmt.Fprintf(os.Stderr, " $ %s <path-to-SLHA-file>\n", os.Args[0])
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() <= 0 {
printf("**error** need an input file name\n")
flag.Usage()
os.Exit(1)
}
fname := flag.Arg(0)
f, err := os.Open(fname)
if err != nil {
printf("could not open file [%s]: %v\n", fname, err)
os.Exit(1)
}
defer f.Close()
data, err := slha.Decode(f)
if err != nil {
printf("could not decode file [%s]: %v\n", fname, err)
os.Exit(1)
}
spinfo := data.Blocks.Get("SPINFO")
if spinfo != nil {
value, err := spinfo.Get(1)
handle(err)
fmt.Printf("spinfo: %s -- %q\n", value.Interface(), value.Comment())
}
modsel := data.Blocks.Get("MODSEL")
if modsel != nil {
value, err := modsel.Get(1)
handle(err)
fmt.Printf("modsel: %d -- %q\n", value.Interface(), value.Comment())
}
mass := data.Blocks.Get("MASS")
if mass != nil {
value, err := mass.Get(5)
handle(err)
fmt.Printf("mass[pdgid=5]: %v -- %q\n", value.Interface(), value.Comment())
}
nmix := data.Blocks.Get("NMIX")
if nmix != nil {
value, err := nmix.Get(1, 2)
handle(err)
fmt.Printf("nmix[1,2] = %v -- %q\n", value.Interface(), value.Comment())
}
}
// Output:
// spinfo: SOFTSUSY -- "spectrum calculator"
// modsel: 1 -- "sugra"
// mass[pdgid=5]: 4.88991651 -- "b-quark pole mass calculated from mb(mb)_Msbar"
// nmix[1,2] = -0.0531103553 -- "N_12"