-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgomesh41.go
94 lines (84 loc) · 2.04 KB
/
gomesh41.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
89
90
91
92
93
94
package gomesh
import (
"bufio"
"errors"
"log"
"os"
"strconv"
"strings"
)
func Parse41(filename string) (* Msh, error) {
msh := Msh{}
file, err := os.Open(filename)
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
switch line {
case "$MeshFormat":
msh.Version, msh.IsAscii, msh.DataSize, err = ParseFormat(nextLineReader(scanner))
case "$Nodes":
msh.Nodes, err = ParseNodes41(scanner)
case "$Elements":
err = ParseElements41(scanner)
default:
log.Printf("WARN: Tag %v not implemented, skipping", line)
}
if err != nil {
log.Fatalf("Error in file parsing: %v", err)
}
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
return &msh, nil
}
func ParseNodes41(sc *bufio.Scanner) ([]Node, error) {
line := sc.Text()
meta := strings.Split(line, " ")
if len(meta) != 4 {
return nil, errors.New("nodes meta len!=4: " + line)
}
numEnts, err := strconv.Atoi(meta[0])
if err != nil {
return nil, errors.New("invalid numEnts: " + line)
}
numNods, err := strconv.Atoi(meta[1])
if err != nil {
return nil, errors.New("invalid numNods: " + line)
}
/* minNodeTag, err := strconv.Atoi(meta[2])
if err!= nil {
return nil, errors.New("invalid minNodeTag: "+ line)
}
maxNodeTag, err := strconv.Atoi(meta[3])
if err!= nil {
return nil, errors.New("invalid maxNodeTag: "+ line)
}*/
for i := 0; i < numEnts; i++ {
line := sc.Text()
meta := strings.Split(line, " ")
if len(meta) != 4 {
return nil, errors.New("ents meta len!=4: " + line)
}
for j := 0; j < numNods; j++ {
//read node tags
}
for j := 0; j < numNods; j++ {
//read coordinates for tags
}
//mesh.add entity()
return nil, errors.New("Not implemented")
}
sc.Text() // read last $EndNodes line
return nil, nil //TODO:
}
func ParseElements41(sc *bufio.Scanner) error {
line := sc.Text()
_ = strings.Split(line, " ")
sc.Text() // read last $EndNodes line
return errors.New("Not implemented") //TODO:
}