diff options
author | hanemile <hanemile@protonmail.com> | 2018-10-04 16:01:07 +0200 |
---|---|---|
committer | hanemile <hanemile@protonmail.com> | 2018-10-04 16:01:07 +0200 |
commit | 457c652fe724107eefc3f4238c0af214752f0d99 (patch) | |
tree | c5de8765a8fad67ca4a5052b1ea95627d89437b5 | |
parent | 4aaa1d44ee9105ec623207fef2db7467a21fc455 (diff) |
functions used for reading an writing from allready existing files
-rw-r--r-- | csv.go | 60 | ||||
-rw-r--r-- | json.go | 1 | ||||
-rw-r--r-- | plot.go | 7 |
3 files changed, 68 insertions, 0 deletions
diff --git a/csv.go b/csv.go new file mode 100644 index 0000000..e9d60cb --- /dev/null +++ b/csv.go @@ -0,0 +1,60 @@ +// collection of functions reading allready existing stars from a .csv + +package main + +import ( + "encoding/csv" + "fmt" + "os" + "strconv" +) + +// open_stars_csv opens the file defined using the path argument, reads its content and returns +// an array of arrays containing the coordinates of the stars +func open_stars_csv(path string) ([][]string) { + + // open the file in the given path + b, err := os.Open(path) + + // handle errors + if err != nil { + fmt.Println("open_stars_csv panic") + panic(err) + } + + // close the file after reading it's content + defer b.Close() + + // open the file using a csv reader and read it's content + lines, err := csv.NewReader(b).ReadAll() + + // handle errors + if err != nil { + fmt.Println("read_csv panic") + panic(err) + } + + // return the content + return lines +} + +// add_csv_to_stars_arr adds the given stars to the given stars_arr +// the stars that should be added are expected to be stored in a[][]string +func add_csv_to_stars_arr(lines [][]string, stars_arr []star) { + for _, line := range lines { + + // convert the coordinates to float64 + x, _ := strconv.ParseFloat(line[0], 64) + y, _ := strconv.ParseFloat(line[1], 64) + + // create a temporary star for storing the information + temp_star := star{ + coord{x, y}, + force{0, 0}, + 1000000, + } + + // add the temporary star to the stars_arr + stars_arr = append(stars_arr, temp_star) + } +} \ No newline at end of file diff --git a/json.go b/json.go new file mode 100644 index 0000000..06ab7d0 --- /dev/null +++ b/json.go @@ -0,0 +1 @@ +package main diff --git a/plot.go b/plot.go new file mode 100644 index 0000000..0d3fcd8 --- /dev/null +++ b/plot.go @@ -0,0 +1,7 @@ +package plot + +import "fmt" + +func plo() { + fmt.Println("PLOT!") +} \ No newline at end of file |