diff --git a/ackwork/ackwork_test.go b/ackwork/ackwork_test.go
index 9fa6916b6d19d8097523b306fdc33fcf2432449d..f6238b82ea33739745a33e493b80774c97eb5a25 100644
--- a/ackwork/ackwork_test.go
+++ b/ackwork/ackwork_test.go
@@ -3,10 +3,23 @@
package ackwork
import (
+ "fmt"
+ "os"
"strings"
"testing"
)
+
+var tstTmpDir string
+
+func init() {
+ var err error
+ if tstTmpDir, err = os.MkdirTemp(".", "test_tmp*"); err != nil {
+ fmt.Fprintln (os.Stderr, "Failed to create temporary directory", tstTmpDir)
+ os.Exit(1)
+ }
+}
+
func TestErr(t *testing.T) {
rdrErr := strings.NewReader("\nrubbish")
if err := realmain(rdrErr); err == nil {
@@ -59,16 +72,20 @@ n_step 100000`, "phasetrans"},
}
+// addTestPath makes some of the loops below a bit more readable
+func addTestPath (s string) string {
+ return tstTmpDir + string (os.PathSeparator) + s
+}
// add OutNames uses the basename field and makes output names for
// the value and x trajectory plot files and the csv file
func addOutNames (s gentest) string {
-// a :=
+
ret := s.params
for _, ss := range []string {"xPltName", "fOutName"} {
- ret += "\n" + ss + " " + s.basename
+ ret += "\n" + ss + " " + addTestPath(s.basename)
}
- ret += "\nfPltName" + " " + s.basename + "_fval"
+ ret += "\nfPltName" + " " + addTestPath(s.basename) + "_fval"
return ret + "\n"
}
func Test1(t *testing.T) {
diff --git a/ackwork/dorun.go b/ackwork/dorun.go
index ad540e92f6d2f1b7757d02f83f4af93f28f49eff..e38b569c1270813a5804c782cc92d600ca77656f 100644
--- a/ackwork/dorun.go
+++ b/ackwork/dorun.go
@@ -45,6 +45,17 @@ type cprm struct { // parameters calculated from input
xplotme bool // Are we plotting X trajectories
}
+// isNotSane checks for obviously silly parameters
+func isNotSane (mcPrm *mcPrm) error {
+ if mcPrm.fOutName == "" && mcPrm.fPltName == "" && mcPrm.xPltName == "" {
+ return fmt.Errorf ("All output files are empty. You would not see anything")
+ }
+ if mcPrm.iniTmp < 0 {
+ return fmt.Errorf ("negative initial temperature %g", mcPrm.iniTmp)
+ }
+ return nil
+}
+
// setupRun does things like get the cooling rate, seed the random numbers.
func setupRun(mcPrm *mcPrm, cprm *cprm) error {
const finalTempErr = "Final temp %g higher than initial temp %g"
@@ -69,12 +80,13 @@ func setupRun(mcPrm *mcPrm, cprm *cprm) error {
coolrate *= math.Log(fnlTmp / iniTmp)
cprm.coolMult = math.Exp(-coolrate)
}
-
- if mcPrm.fOutName, err = setSuffix(mcPrm.fOutName, ".csv"); err != nil {
- return err
- }
- if cprm.fOutRaw, err = os.Create(mcPrm.fOutName); err != nil {
- return err
+ if mcPrm.fOutName != "" {
+ if mcPrm.fOutName, err = setSuffix(mcPrm.fOutName, ".csv"); err != nil {
+ return err
+ }
+ if cprm.fOutRaw, err = os.Create(mcPrm.fOutName); err != nil {
+ return err
+ }
}
cprm.fOut = bufio.NewWriter(cprm.fOutRaw)
if mcPrm.fPltName != "" {
@@ -100,6 +112,7 @@ func setupRun(mcPrm *mcPrm, cprm *cprm) error {
n_dim := len(mcPrm.xIni)
cprm.plotXtrj = make([]float32, 0, int(n_alloc)*n_dim)
}
+ if err != isNotSane(mcPrm) { return err }
return nil
}
@@ -147,7 +160,9 @@ func saveStep(cprm *cprm, n uint32, tmprtr float64, x []float32, fTrial float64)
if cprm.xplotme { // The trajectory
cprm.plotXtrj = append(cprm.plotXtrj, x...)
}
- printfVal(cprm.fOut, x, n, tmprtr, fTrial)
+ if cprm.fOut != nil {
+ printfVal(cprm.fOut, x, n, tmprtr, fTrial)
+ }
}
// nRunAdj will try to adjust the step size, given our history of accept/reject.
diff --git a/ackwork/rdprm.go b/ackwork/rdprm.go
index bfaed295e7bd1799eaae66692004932db07e6dab..7936eb68a173be6e6c67682972856592c98c97e0 100644
--- a/ackwork/rdprm.go
+++ b/ackwork/rdprm.go
@@ -27,7 +27,7 @@ var cmdDflt = []struct {
{"x_ini", "3,4,5"},
{"x_delta", "0.5"},
{"seed", "1637"},
- {"foutname", "mcrun"},
+ {"foutname", ""},
{"fpltname", ""}, // empty means no plots of function
{"xpltname", ""},
{"verbose", ""},