gompcreader

package module
v0.0.0-...-a138baf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2015 License: MIT Imports: 10 Imported by: 0

README

Minor Planet Center Reader

Build Status License Docs

Overview

Simple Go library to read the minor planet center data files.

The go docs should be reasonable. If some thing doesn't seem to work please raise a bug.

The expected input files can be obtained here: http://www.minorplanetcenter.net/iau/MPCORB.html Either the gziped or unzipped files should work automatically, file type detection is done by simple file extension only.

Example

package main

import (
	"flag"
	"fmt"
	"io"
	"log"

	"github.com/wselwood/gompcreader"
)

var inputfile = flag.String("in", "", "the minor planet center file to read")

func main() {

	flag.Parse()

	if *inputfile == "" {
		log.Fatal("No input file provided. Use the -in /path/to/file")
	}

	mpcReader, err := gompcreader.NewMpcReader(*inputfile)
	if err != nil {
		log.Fatal("error creating mpcReader ", err)
	}
	defer mpcReader.Close()

	var count int64
	result, err := mpcReader.ReadEntry()
	for err == nil {
		fmt.Printf("%s:%s\n", result.ID, result.ReadableDesignation)
		result, err = mpcReader.ReadEntry()
		count = count + 1
	}

	if err != nil && err != io.EOF {
		log.Fatal(fmt.Sprintf("error reading line %d\n", count), err)
	}

	fmt.Printf("read %d records\n", count)
}

Documentation

Overview

Package gompcreader provides a simple method to read the Minor Planet Center data files.

Designed to load the files from http://www.minorplanetcenter.net/iau/MPCORB.html and http://www.minorplanetcenter.net/iau/ECS/MPCAT/MPCAT.html

This will not read the comets files or the observations files. If you try you will probably find the first call to ReadEntry() returns io.EOF as it has skipped all the records in the file.

This can handle both the gzipped and uncompressed versions of the files. If you need speed and don't care about space use the uncompressed versions.

To read a file first construct a MpcReader using the NewMpcReader(string) function. This requires the path to a file.

Each record is read using the ReadEntry() function. Note this may consume more than one line from the file if the next line is not the correct length. These are usually the comments at the top of the file or the blank section sperators. When you get to the end of the file this will return io.EOF.

Finaly when you are done with the reader you should Close() it. This should normally be defered.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MinorPlanet

type MinorPlanet struct {
	ID                           string
	AbsoluteMagnitude            float64
	Slope                        float64
	Epoch                        time.Time
	MeanAnomalyEpoch             float64
	ArgumentOfPerihelion         float64
	LongitudeOfTheAscendingNode  float64
	InclinationToTheEcliptic     float64
	OrbitalEccentricity          float64
	MeanDailyMotion              float64
	SemimajorAxis                float64
	UncertaintyParameter         string
	Reference                    string
	NumberOfObservations         int64
	NumberOfOppositions          int64
	RMSResidual                  float64
	CoarseIndicatorOfPerturbers  string
	PreciseIndicatorOfPerturbers string
	ComputerName                 string
	HexDigitFlags                int64
	ReadableDesignation          string
	DateOfLastObservation        time.Time
	YearOfFirstObservation       int64
	YearOfLastObservation        int64
	ArcLength                    int64
}

MinorPlanet is the result of reading a record from a file

type MpcReader

type MpcReader struct {
	// contains filtered or unexported fields
}

MpcReader is a simple data structure to keep track of readers and scanners for reading the requested file. Should be constructed using NewMpcReader(string) and closed using Close() before disposal.

func NewMpcReader

func NewMpcReader(filePath string) (*MpcReader, error)

NewMpcReader is used to create a new minor planet center reader.

This takes a path as a string to the file and returns the reader structure.

If there is a problem opening the file it will return nil for the reader and an error indicating what went wrong.

This will automatically detect if the file extension suggests a gziped version of the file and open it correctly.

func (*MpcReader) Close

func (reader *MpcReader) Close()

Close the reader down. This will clean up the open file handle.

This should be defered just after NewMpcReader has been called

func (*MpcReader) ReadEntry

func (reader *MpcReader) ReadEntry() (*MinorPlanet, error)

ReadEntry returns the next minor planet from the file or error if there is a problem reading the record.

Note: this will return an io.EOF when the end of the file is reached.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL