コード例 #1
0
ファイル: wsserver.go プロジェクト: wiless/webplot
func socketListener(ws *websocket.Conn) {

	for {

		log.Printf("Connection Opened from %v", ws.RemoteAddr())
		activePlotter = ws
		cnt := 0
		for {

			in := bufio.NewReader(os.Stdin)
			fmt.Printf("WebPlot > ")
			str, _ := in.ReadString('\n')
			var plotcmd PlotInfo
			// log.Println("Input Command ", str)
			str = strings.TrimSpace(str)

			if strings.Contains(str, "SIN") {
				log.Printf("YOU ARE IN ", str)
				plotcmd.Type = "plot"
				plotcmd.HoldOn = (str == "SINH")
				plotcmd.Handle = 120
				plotcmd.Y = vlib.RandNFVec(100, 1)
				plotcmd.Options.Color = "red"
				plotcmd.Options.Title = fmt.Sprintf("Figure %d - (%d)", plotcmd.Handle, cnt)
				cnt++
				log.Println(plotcmd.Y)
				data, err := json.Marshal(plotcmd)

				if err != nil {
					log.Println("Err is ", err)
					break
				}
				activePlotter.Write(data)
			}

			if str == "COS" {
				plotcmd.Type = "plot"
				plotcmd.HoldOn = true
				plotcmd.Handle = rand.Intn(100)
				plotcmd.Y = vlib.RandNFVec(100, 1)
				plotcmd.Options.Color = "red"
				plotcmd.Options.Title = fmt.Sprintf("Figure %d", cnt)
				cnt++
				log.Println(plotcmd.Y)
				data, err := json.Marshal(plotcmd)

				if err != nil {
					log.Println("Err is ", err)
					break
				}
				activePlotter.Write(data)
			}

		}

	}
}
コード例 #2
0
ファイル: testcdf.go プロジェクト: istdev/stats
func main() {
	t := time.Now()
	var matlab *vlib.Matlab
	x := vlib.RandNFVec(701, 1.0)
	// x = x.Scale(2)
	xx, yy := stats.CDF(x)
	matlab = vlib.NewMatlab("xx.m")
	matlab.Export("x", xx)
	matlab.Export("y", yy)
	matlab.Command("plot([-Inf x Inf],[0 0 y])")
	matlab.Close()
	fmt.Printf("time = %v", time.Since(t))
}
コード例 #3
0
ファイル: wsserver.go プロジェクト: wiless/webplot
func socketListener(ws *websocket.Conn) {

	// var fa FeedArray
	// SubscriberLists[ws] = fa
	for {

		log.Printf("Connection Opened from %v", ws.RemoteAddr())
		activePlotter = ws
		cnt := 0
		for {

			in := bufio.NewReader(os.Stdin)
			fmt.Printf("Enter Message : ")
			str, _ := in.ReadString('\n')
			var plotcmd PlotInfo
			log.Println("Input Command ", str)
			str = strings.TrimSpace(str)

			if strings.Contains(str, "SIN") {
				log.Printf("YOU ARE IN ", str)
				plotcmd.Type = "plot"
				plotcmd.HoldOn = (str == "SINH")
				plotcmd.Handle = 120
				plotcmd.Y = vlib.RandNFVec(100, 1)
				plotcmd.Options.Color = "red"
				plotcmd.Options.Title = fmt.Sprintf("Figure %d - (%d)", plotcmd.Handle, cnt)
				cnt++
				log.Println(plotcmd.Y)
				data, err := json.Marshal(plotcmd)

				if err != nil {
					log.Println("Err is ", err)
					break
				}
				activePlotter.Write(data)
			}

			if str == "COS" {
				plotcmd.Type = "plot"
				plotcmd.HoldOn = true
				plotcmd.Handle = rand.Intn(100)
				plotcmd.Y = vlib.RandNFVec(100, 1)
				plotcmd.Options.Color = "red"
				plotcmd.Options.Title = fmt.Sprintf("Figure %d", cnt)
				cnt++
				log.Println(plotcmd.Y)
				data, err := json.Marshal(plotcmd)

				if err != nil {
					log.Println("Err is ", err)
					break
				}
				activePlotter.Write(data)
			}

		}
		// {

		// for {
		// 	msg := make([]byte, 1024)
		// 	n, _ := ws.Read(msg)
		// 	if n > 0 {
		// 		log.Printf("Read Message  %s", msg[:n])

		// 		var f FeedInfo
		// 		jerr := json.Unmarshal(msg[0:n], &f)
		// 		if jerr == nil {
		// 			fa = append(fa, f)
		// 			SubscriberLists[ws] = fa
		// 			log.Printf("Updated subscriptions for %v with %v ", ws.RemoteAddr(), fa)
		// 		} else {
		// 			fmt.Println("Error in Unmarshalling ", jerr, " See text ", string(msg[:n]))
		// 			f.ID = 0
		// 			f.FieldNames = []string{"Dummy"}
		// 			fa = append(fa, f)
		// 			SubscriberLists[ws] = fa
		// 			log.Printf("DUMMY Updated subscriptions (%v) for %v with %v ", ws, ws.RemoteAddr(), fa)

		// 		}
		// 	}

		// }
		// }

	}
}