package main

import (
"fmt"
//"go_sat_test/testpackage"
"go_sat_test/satellite"
"io/ioutil"
"strings"
"time"
"math"
)

func readlines(file string) []string {

	content, _ := ioutil.ReadFile(file)
    str := string(content)
    lines := strings.Split(str, "\n")
	return lines
	
}


func main() {


        var lines = readlines("tle.txt")     
	    //sat := satellite.ParseTLE(lines[1],lines[2],satellite.GravityWGS84)
        sat := satellite.TLEToSat(lines[1], lines[2],satellite.GravityWGS84 )
		fmt.Printf("%s\n",lines[0])
		fmt.Printf("%s\n",strings.Trim(lines[1],"\r"))
		fmt.Printf("%s\n",strings.Trim(lines[2],"\r"))
		
		//fmt.Printf("NORADID: %v\n", sat.satnum)
		t := time.Now()
		t := t.UTC()
		fmt.Printf("Second: %v\n", t.Second())
		year,month,day := t.Date()		
		
        //position, velocity := satellite.Propagate(sat, year, int(month), day, t.Hour(), t.Minute(), t.Second())
		position, _:= satellite.Propagate(sat, year, int(month), day, t.Hour(), t.Minute(), t.Second())
	
	//position, velocity := satellite.Propagate(sat, 2024, 1, 3, 12, 23, 43)
		latlong := satellite.LatLong {40.0534* math.Pi / 180,29.2903* math.Pi / 180}
		jday :=satellite.JDay(year, int(month), day, t.Hour(), t.Minute(), t.Second())
        pos := satellite.ECIToLookAngles(position, latlong,0, jday)
		
		gst := satellite.GSTimeFromDate(year, int(month), day,t.Hour(), t.Minute(), t.Second())
		_, _, latlng := satellite.ECIToLLA(position, gst)		

        //fmt.Printf("Position: %v\n", position)
	    //fmt.Printf("Velocity: %v\n", velocity)
		fmt.Printf("Lat: %v Lng: %v\n", latlng.Latitude*180/math.Pi, latlng.Longitude*180/math.Pi)
		fmt.Printf("Az: %v El: %v\n", pos.Az,pos.El)

	


        /*var data testpackage.MyData

	var x = testpackage.Sum(10,30)
	var y = testpackage.Sub(40,30)
	fmt.Print(x)
	fmt.Print(y)
        data.Val1 = x
        data.Val2 = y
	fmt.Print(data.Val1)
	fmt.Print(data.Val2)*/


}