about summary refs log tree commit diff
diff options
context:
space:
mode:
authorhanemile <hanemile@chaosdorf.de>2018-09-28 18:20:54 +0200
committerhanemile <hanemile@chaosdorf.de>2018-09-28 18:20:54 +0200
commite61ac4dbdc01d0e15b1cf7b9d37d94b794596d24 (patch)
tree5ffb1a604ca115d94c9a70df6e216a3be9abd6ce
parentd3401f4e1b42ce7fab780062b18c3ca2959edbd0 (diff)
read the stars from a file and add them to the stars_arr, then calculate the forces acting inbetween all of them
-rw-r--r--main.go53
1 files changed, 52 insertions, 1 deletions
diff --git a/main.go b/main.go
index 5a59c25..e07f7a4 100644
--- a/main.go
+++ b/main.go
@@ -2,6 +2,9 @@ package main
 
 import (
 	"fmt"
+	"encoding/csv"
+	"os"
+	"strconv"
 )
 
 // force struct storing a force vector
@@ -29,5 +32,53 @@ func main() {
 		star{coord{1.0, 4.5}, force{0, 0}, 1000000},
 	}
 
-	fmt.Println(stars_arr)
+	// 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)
+
 }