-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodel.go
60 lines (51 loc) · 1.38 KB
/
model.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
package main
import (
"fmt"
"path/filepath"
"sort"
)
type Model struct {
HasAero bool `json:"HasAero"`
ImportedPaths []string `json:"ImportedPaths"`
Files *Files `json:"Files"`
Notes []string `json:"Notes"`
}
func NewModel() *Model {
return &Model{
ImportedPaths: []string{},
Notes: []string{},
}
}
func ParseModelFiles(path string) (*Model, error) {
// Parse model files
files, err := ParseFiles(path)
if err != nil {
return nil, fmt.Errorf("error importing OpenFAST model '%s': %w", path, err)
}
// Get imported paths
paths := []string{}
for p := range files.PathMap {
p, _ := filepath.Rel(filepath.Dir(path), p)
paths = append(paths, p)
}
sort.Slice(paths, func(i, j int) bool {
return filepath.Base(paths[i]) < filepath.Base(paths[j])
})
// Add notes from parsing
notes := []string{}
if len(files.AeroDyn)+len(files.AeroDyn14) == 0 {
notes = append(notes, "No AeroDyn or AeroDyn 14 files imported: aerodynamics option will be disabled in cases")
}
if len(files.InflowWind) == 0 {
notes = append(notes, "No InflowWind file imported: aerodynamics option will be disabled in cases")
}
// Initialize models structure
model := Model{
HasAero: ((len(files.AeroDyn)+len(files.AeroDyn14)) > 0 &&
len(files.InflowWind) > 0),
Files: files,
ImportedPaths: paths,
Notes: notes,
}
return &model, nil
}