about summary refs log tree commit diff
diff options
context:
space:
mode:
authoremile <hanemile@protonmail.com>2018-10-08 15:37:21 +0200
committeremile <hanemile@protonmail.com>2018-10-08 15:37:21 +0200
commit8ced9944d4d43c3a4e6711c23dce8846e5509108 (patch)
tree90636c680859c159ee8bdf13a6ca2383f107032c
parente9fa0eda64e39ad36bd8db7b183cb98ab432cd73 (diff)
Deleted csv.go (complete cleanup)
-rw-r--r--csv.go60
-rw-r--r--main.go79
2 files changed, 5 insertions, 134 deletions
diff --git a/csv.go b/csv.go
deleted file mode 100644
index e9d60cb..0000000
--- a/csv.go
+++ /dev/null
@@ -1,60 +0,0 @@
-// 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/main.go b/main.go
index e07f7a4..c06fc8f 100644
--- a/main.go
+++ b/main.go
@@ -1,84 +1,15 @@
 package main
 
 import (
+	"./structs"
 	"fmt"
-	"encoding/csv"
-	"os"
-	"strconv"
 )
 
-// force struct storing a force vector
-type force struct{
-	x, y	float64
-}
-
-// coordinate struct storing the position of stars
-type coord struct{
-	x, y	float64
-}
-
-// star struct storing information about the star
-type star struct{
-	c	coord
-	f	force
-	mass	float64
-}
-
 func main() {
-	// stars_arr is a slice storing the stars
-	stars_arr := []star{
-		star{coord{1.0, 1.0}, force{0, 0}, 1000000},
-		star{coord{3.0, 2.5}, force{0, 0}, 1000000},
-		star{coord{1.0, 4.5}, force{0, 0}, 1000000},
+	// the slice starsSlice stores the star structures
+	starsSlice := []structs.Star{
+		{structs.Coord{X: 100, Y: 100}, structs.Force{0, 0}, 1000},
 	}
 
-	// Open all the files from data/* and use their content as stars
-	b, err := os.Open("data/structure03.ita.uni-heidelberg.de_26635.csv")
-
-	// Error handling for opening files
-	if err != nil {
-		panic(err)
-	}
-
-	// Close the file after reading it's content
-	defer b.Close()
-
-	// Read the lines using a csv-reader
-	lines, err := csv.NewReader(b).ReadAll()
-
-	// CSV-Reader error handler
-	if err != nil {
-		panic(err)
-	}
-
-	for i := 0; i < 3; i++ {
-		fmt.Println(i)
-
-		// Iterate over all the lines in the given files, convert the data to float64 and
-		// append the data to the stars_arr
-		for _, line := range lines {
-
-			// convert to float64
-			x, _ := strconv.ParseFloat(line[0], 64)
-			y, _ := strconv.ParseFloat(line[0], 64)
-
-			// Define a temporary star that gets appended to the stars_arr
-			temp_star := star{
-				coord{x,y},
-				force{0,0},
-				1000000,
-			}
-
-			// Append the stars
-			stars_arr = append(stars_arr, temp_star)
-		}
-
-	}
-
-	// calculate the forces acting
-
-	calc_all_forces(stars_arr)
-
-	print_arr(stars_arr)
-
+	fmt.Println(starsSlice)
 }