Skip to content

Commit

Permalink
Update function list in save.go (mumax#176)
Browse files Browse the repository at this point in the history
Hi, I would like to propose to add function based on the SaveAs, but for the snapshot.
  • Loading branch information
kkingstoun authored and godsic committed Sep 18, 2018
1 parent 025ad53 commit 6797a71
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions engine/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func init() {
DeclROnly("OVF2_TEXT", OVF2_TEXT, "OutputFormat = OVF2_TEXT sets text OVF2 output")
DeclROnly("DUMP", DUMP, "OutputFormat = DUMP sets text DUMP output")
DeclFunc("Snapshot", Snapshot, "Save image of quantity")
DeclFunc("SnapshotAs", SnapshotAs, "Save image of quantity with custom filename")
DeclVar("SnapshotFormat", &SnapshotFormat, "Image format for snapshots: jpg, png or gif.")
}

Expand Down Expand Up @@ -83,6 +84,20 @@ func Snapshot(q Quantity) {
autonum[q]++
}

func SnapshotAs(q Quantity, fname string) {
if !strings.HasPrefix(fname, OD()) {
fname = OD() + fname // don't clean, turns http:// in http:/
}

if path.Ext(fname) == "" {
fname += ("." + StringFromOutputFormat[outputFormat])
}
s := ValueOf(q)
defer cuda.Recycle(s)
data := s.HostCopy() // must be copy (asyncio)
queOutput(func() { snapshot_sync(fname, data) })
}

// synchronous snapshot
func snapshot_sync(fname string, output *data.Slice) {
f, err := httpfs.Create(fname)
Expand Down

0 comments on commit 6797a71

Please sign in to comment.