Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ackley_mc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Torda, Prof. Dr. Andrew Ernest
ackley_mc
Commits
a0570d0c
Commit
a0570d0c
authored
3 years ago
by
Andrew E. Torda
Browse files
Options
Downloads
Plain Diff
Merge branch 'windows_expt' into devel. Error message about file creation on windows.
parents
1e67c06d
5fbcc2ec
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+1
-1
1 addition, 1 deletion
.gitignore
Makefile
+1
-0
1 addition, 0 deletions
Makefile
README.md
+2
-2
2 additions, 2 deletions
README.md
mc_work/dorun.go
+41
-2
41 additions, 2 deletions
mc_work/dorun.go
with
45 additions
and
5 deletions
.gitignore
+
1
−
1
View file @
a0570d0c
test_tmp*
ackley
ackley_mc
ackley_mc.exe
*.csv
/ackley_mc.exe
This diff is collapsed.
Click to expand it.
Makefile
+
1
−
0
View file @
a0570d0c
...
...
@@ -34,6 +34,7 @@ clean:
$(
GO
)
clean
rm
-rf
bin/
*
rm
-rf
examples/
*
.csv
rm
-rf
*
.csv
rm
-rf
*
/
*
_delme.
*
rm
-rf
*
/test_tmp
*
rm
-rf
/tmp/go-build[0-9]
*
...
...
This diff is collapsed.
Click to expand it.
README.md
+
2
−
2
View file @
a0570d0c
...
...
@@ -18,11 +18,11 @@ I do not have a mac for testing, so this is limited to linux and windows. It is
cd ackley_mc
go build .
and you should end up with an executable called
`ackley_mc`
or
`ackley_mc.exe`
under windows. To build without graphics
:
and you should end up with an executable called
`ackley_mc`
or
`ackley_mc.exe`
under windows. To build without graphics
,
git clone git@gitlab.rrz.uni-hamburg.de:Bae5157/ackley_mc.git
cd ackley_mc
go build
-tags=no_gfx
.
go build .
### Graphics yes / no ?
...
...
This diff is collapsed.
Click to expand it.
mc_work/dorun.go
+
41
−
2
View file @
a0570d0c
...
...
@@ -4,8 +4,10 @@ package mcwork
import
(
"bufio"
"bytes"
"errors"
"fmt"
"io"
"io/fs"
"math"
"math/rand"
"os"
...
...
@@ -62,6 +64,43 @@ func isNotSane(mcPrm *McPrm) error {
return
nil
}
// fExists returns true if the file exists.
// It is part of the exercise, working around file permissions on windows
func
fExists
(
name
string
)
bool
{
var
err
error
if
_
,
err
:=
os
.
Stat
(
name
);
err
==
nil
{
return
true
}
if
errors
.
Is
(
err
,
fs
.
ErrNotExist
)
{
return
false
}
return
true
}
// createFix is a wrapper around os.Create() which I seem to need for windows.
// On windows, I cannot overwrite an existing file. To be very exact, the
// O_CREATE fails if a file exists. O_TRUNC also fails.
func
createFix
(
name
string
)
(
*
os
.
File
,
error
)
{
var
rErr
=
`Remove the file %s and try again. This only happens on windows: %w`
var
f
*
os
.
File
var
err
error
if
f
,
err
=
os
.
Create
(
name
);
err
==
nil
{
return
f
,
nil
// Most common path (no problem)
}
if
!
fExists
(
name
)
{
// does not exist, but we have a real error.
return
nil
,
err
// Return original error
}
// Next step try to remove original file
if
e
:=
os
.
Remove
(
name
);
e
!=
nil
{
return
nil
,
fmt
.
Errorf
(
rErr
,
name
,
e
)
}
if
f
,
err
=
os
.
Create
(
name
);
err
==
nil
{
// second attempt, after removing name
return
f
,
nil
}
return
nil
,
err
}
// setupRun does things like get the cooling rate, seed the random numbers.
func
setupRun
(
mcPrm
*
McPrm
,
cprm
*
cprm
)
error
{
var
err
error
...
...
@@ -83,8 +122,8 @@ func setupRun(mcPrm *McPrm, cprm *cprm) error {
if
mcPrm
.
fOutName
,
err
=
setSuffix
(
mcPrm
.
fOutName
,
".csv"
);
err
!=
nil
{
return
err
}
if
cprm
.
fOutRaw
,
err
=
os
.
C
reate
(
mcPrm
.
fOutName
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Trying to create file: %w"
,
err
)
if
cprm
.
fOutRaw
,
err
=
c
reate
Fix
(
mcPrm
.
fOutName
);
err
!=
nil
{
return
err
}
cprm
.
fOut
=
bufio
.
NewWriter
(
cprm
.
fOutRaw
)
cprm
.
doTxtFval
=
true
// other parts of code can see that we are writing to file
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment