Giter Site home page Giter Site logo

gospss's Introduction

GoSPSS

This package can read an IBM Statistics data file in to golang to handle it any which way you want.

Example 1:

Read data line by line.

package main

import (
	"fmt"
	"io"
	"log"
	"os"
	"github.com/hektorinho/gospss"
)

const TEST_FILE = "data/data7.sav"

func main() {
  	f, err := os.OpenFile(TEST_FILE, os.O_RDONLY, 0777)
	if err != nil {
		log.Panicf("failed to open %s ::: err >>> %s\n", TEST_FILE, err)
	}
	defer f.Close()
  
	r, err := NewReader(f)
	if err != nil {
		log.Panicf("failed to read %s ::: err >>> %s\n", TEST_FILE, err)
	}

	for i := 0; ; i++ {
		data, err := r.Read()
		if err == io.EOF {
			break
		}
		if err != nil {
			log.Panicf("err >>> %s\n", err)
		}
		
		// Handle your data ...
		fmt.Println(i, data)
	}
}

Example 2:

Read all data and header information.

package main

import (
	"fmt"
	"io"
	"log"
	"os"
	"github.com/hektorinho/gospss"
)

const TEST_FILE = "data/data7.savz"

func main() {
  	f, err := os.OpenFile(TEST_FILE, os.O_RDONLY, 0777)
	if err != nil {
		log.Panicf("failed to open %s ::: err >>> %s\n", TEST_FILE, err)
	}
	defer f.Close()
  
	r, err := NewReader(f)
	if err != nil {
		log.Panicf("failed to read %s ::: err >>> %s\n", TEST_FILE, err)
	}

	// Exposes all header information
	header := r.Header()
	fmt.Println(header.Fileheader.ncases)

	// Reads the whole data file in to a list of gospss.Row.
	rows, err := r.ReadAll()
	if err != nil {
		log.Panicf("failed to read all records %s ::: err >>> %s", TEST_FILE, err)
	}
	for i, row := range rows[0:4] {
		fmt.Printf("row %d, data >>> %v\n", i, row)
	}
}

gospss's People

Contributors

hektorinho avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.