Skip to content

Commit

Permalink
fix runVis
Browse files Browse the repository at this point in the history
  • Loading branch information
fmhr committed Sep 21, 2023
1 parent 5043fe1 commit 324f363
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
19 changes: 8 additions & 11 deletions runVis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ import (
)

func RunVis(cnf *Config, seed int) (map[string]float64, error) {
rtn, err := runVis(cnf, seed)
if err != nil {
return rtn, err
}
fmt.Fprintln(os.Stderr, mapString(rtn))
fmt.Println(rtn["Score"]) // ここだけ標準出力
return rtn, nil
return runVis(cnf, seed)
}

// runVis は指定された設定とシードに基づいてコマンドを実行して、
Expand All @@ -32,7 +26,10 @@ func runVis(cnf *Config, seed int) (map[string]float64, error) {
// vis
infile := cnf.InfilePath + fmt.Sprintf("%04d.txt", seed)
outfile := cnf.OutfilePath + fmt.Sprintf("%04d.out", seed)
outVis := vis(cnf, infile, outfile)
outVis, err := vis(cnf, infile, outfile)
if err != nil {
return nil, fmt.Errorf("vis failed: %v", err)
}
// visの結果をpairに追加
sc, err := extractData(string(outVis))
if err != nil {
Expand Down Expand Up @@ -62,14 +59,14 @@ func mapString(data map[string]float64) string {
return str
}

func vis(cnf *Config, infile, outfile string) []byte {
func vis(cnf *Config, infile, outfile string) ([]byte, error) {
cmdStr := fmt.Sprintf(cnf.VisPath+" %s %s", infile, outfile)
cmd := exec.Command("sh", "-c", cmdStr)
out, err := cmd.CombinedOutput()
if err != nil {
log.Fatal(fmt.Errorf("cmd.Run() for command %q failed with: %v", cmdStr, err))
return nil, fmt.Errorf("cmd.Run() for command %q failed with: %v", cmdStr, err)
}
return out
return out, nil
}

func RunVis10(cnf *Config) error {
Expand Down
18 changes: 13 additions & 5 deletions script.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fj

import (
"flag"
"fmt"
"log"
"os"
)
Expand Down Expand Up @@ -47,14 +48,17 @@ func Fj() {
// 1つのseedを実行
if len(seeds) == 0 {
var err error
var rtn map[string]float64
if cnf.Reactive {
_, err = ReactiveRun(cnf, *seed)
rtn, err = ReactiveRun(cnf, *seed)
} else {
_, err = RunVis(cnf, *seed)
rtn, err = RunVis(cnf, *seed)
}
if err != nil {
log.Fatal(err)
}
fmt.Fprintln(os.Stderr, mapString(rtn))
fmt.Println(rtn["Score"]) // ここだけ標準出力
} else {
// 複数のseedを並列実行
//if cnf.Reactive {
Expand All @@ -68,9 +72,13 @@ func Fj() {
GenerateConfig()
case "gen":
Gen(cnf, *seed)
case "gcloud":
// TODO
gcloud()
case "cloud":
log.Println("cloud mode")
rtn, err := CloudRun(cnf, *seed)
if err != nil {
log.Fatal(err)
}
log.Println(rtn)
default:
flag.Usage()
}
Expand Down

0 comments on commit 324f363

Please sign in to comment.