diff options
author | hanemile <hanemile@chaosdorf.de> | 2018-09-28 18:13:27 +0200 |
---|---|---|
committer | hanemile <hanemile@chaosdorf.de> | 2018-09-28 18:13:27 +0200 |
commit | 9563a5ff02bd5d4415bf18158a952bfbc02dfc5c (patch) | |
tree | bf5b0eb411fc3e7909262d1b8ef659216ad9fa11 | |
parent | c73e675866d056374ab8be170ed46110f1107bc8 (diff) |
save_as_csv saves the given stars in the given slice to the given path
-rw-r--r-- | force.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/force.go b/force.go index 16ee30e..47bbed3 100644 --- a/force.go +++ b/force.go @@ -58,3 +58,19 @@ func calc_all_forces(arr []star) { go forces(arr, index) } } + +// save_as_csv saves all the information stored in the given array to the given path. +// If no error occures, the return value is nil +func save_as_csv(stars_arr []star, path string) error { + + var filename string = path + ".txt" + var content string + + // Iterate over all the stars in the given array and add the info the the content that will be saved + for _, elem := range stars_arr { + content += fmt.Sprintf("%f,%f,%f,%f,%f\n", elem.c.x, elem.c.y, elem.f.x, elem.f.y, elem.mass) + } + + // Return the error and write the data to disc + return ioutil.WriteFile(filename, []byte(content), 0600) +} |