-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
71 lines (56 loc) · 1.94 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
package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"text/template"
)
func check(e error) {
if e != nil {
panic(e)
}
}
type CodeItems struct {
Structname string
Structdata string
}
func main() {
Funcnames := []string{"JanusChemCarbTest"}
// Funcnames := []string{"JanusAgeDatapoint", "JanusAgeProfile", "JanusChemCarb", "JanusCoreImage", "JanusCoreSummary",
// "JanusCryomagSection", "JanusDhtApct", "JanusGraSection", "JanusIcpSample", "JanusMadSection",
// "JanusMs2fSection", "JanusMsclSection", "JanusMslSection", "JanusNcrSection", "JanusNgrSection",
// "JanusPaleoImage", "JanusPaleoOccurrence", "JanusPaleoSample", "JanusPrimeDataImage",
// "JanusPwlSection", "JanusPws1Section", "JanusPws2Section", "JanusPws3Section",
// "JanusRscSection", "JanusSample", "JanusSedThinSectionSample", "JanusShearStrengthAvs",
// "JanusShearStrengthPen", "JanusShearStrengthTor", "JanusSmearSlide", "JanusTensorCore",
// "JanusThermalConductivity", "JanusThinSectionImage", "JanusVcdHardRockImage",
// "JanusVcdImage", "JanusVcdStructureImage", "JanusXrdImage", "JanusXrfSample"}
// loop here....
for _, entry := range Funcnames {
qrytmp, err := ioutil.ReadFile("template.txt")
check(err)
fmt.Printf("Create from entry %s \n", entry)
structFile := fmt.Sprintf("./inputStage2/%s.txt", entry)
structData, err := ioutil.ReadFile(structFile)
check(err)
structEntry := CodeItems{Structname: entry, Structdata: string(structData)}
var buff = bytes.NewBufferString("")
t, err := template.New("go func template").Parse(string(qrytmp))
if err != nil {
log.Printf("go func template creation failed: %s", err)
}
err = t.Execute(buff, structEntry)
qry := string(buff.Bytes())
// write to a file
filename := fmt.Sprintf("./output/%s.go", entry)
f, err := os.Create(filename)
check(err)
defer f.Close()
n2, err := f.Write([]byte(qry))
check(err)
fmt.Printf("Wrote %s with size %d\n", filename, n2)
f.Sync()
}
}