Skip to content
Snippets Groups Projects
Commit c7f23622 authored by Andrew E. Torda's avatar Andrew E. Torda
Browse files

Simplifying main loop - moved print statements to their own function.

parent efbd0c80
No related branches found
No related tags found
No related merge requests found
...@@ -134,6 +134,16 @@ func nRunAdj(mcPrm *mcPrm, runAcc float64, xDlta float32) float32 { ...@@ -134,6 +134,16 @@ func nRunAdj(mcPrm *mcPrm, runAcc float64, xDlta float32) float32 {
return xDlta return xDlta
} }
// printfVal is just the loop to print out the function value and coordinates
// probably for later plotting.
func printfVal (fOut io.Writer, x []float32, n uint32, tmprtr float64, fOld float64) {
fmt.Fprintf(fOut, "%d,%.4g,%.5g", n, tmprtr, fOld)
for _, xx := range x {
fmt.Fprintf(fOut, ",%.2g", xx)
}
fmt.Fprintln(fOut)
}
// doRun does a Monte Carlo run. Although single precision is fine for the // doRun does a Monte Carlo run. Although single precision is fine for the
// coordinates and function, we use double precision for the temperature. // coordinates and function, we use double precision for the temperature.
func doRun(mcPrm *mcPrm) error { func doRun(mcPrm *mcPrm) error {
...@@ -166,16 +176,12 @@ func doRun(mcPrm *mcPrm) error { ...@@ -166,16 +176,12 @@ func doRun(mcPrm *mcPrm) error {
var acc bool var acc bool
nout-- nout--
if nout == 0 { // Do we want to print out results on this step ? if nout == 0 { // Do we want to print out results on this step ?
fmt.Fprintf(cprm.fOut, "%d,%.4g,%.5g", n, tmprtr, fOld) printfVal (cprm.fOut, x, n, tmprtr, fOld)
for _, xx := range x {
fmt.Fprintf(cprm.fOut, ",%.2g", xx)
}
fmt.Fprintln(cprm.fOut)
nout = cprm.nEvery nout = cprm.nEvery
} }
nRunAcc-- nRunAcc--
if nRunAcc == 0 { // Do we want to try adjusting the step size ? if nRunAcc == 0 { // Do we want to try adjusting the step size ?
xDlta = nRunAdj(mcPrm, runAcc, xDlta) // mucking about here xDlta = nRunAdj(mcPrm, runAcc, xDlta)
nRunAcc = nRunAccAdj // Reset the counter nRunAcc = nRunAccAdj // Reset the counter
} }
newx(x, xT, cprm.rand, xDlta) newx(x, xT, cprm.rand, xDlta)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment