hb

package
v1.2.9 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2021 License: BSD-3-Clause Imports: 8 Imported by: 0

README

Gosl. hb. Read/Write hb (go-binary gob) files

PkgGoDev

This package is inspired by the Hierarchical Data File (HDF) format but uses go-binary (gob) stream of gobs instead.

Data is stored in binary streams and then to files by providing a path and the data. Here, the order of commands is important.

Example of writing data:

f := Create("/tmp/gosl/hb", "basic01")
defer f.Close()
f.PutArray("/u", uSource)
f.PutArray("/displacements/u", []float64{4, 5, 6})
f.PutArray("/displacements/v", []float64{40, 50, 60})
f.PutArray("/time0/ip0/a0/u", []float64{7, 8, 9})
f.PutArray("/time1/ip0/b0/u", []float64{70, 80, 90})
f.PutInts("/someints", []int{100, 200, 300, 400})
f.PutInt("/data/oneint", 123)
f.PutFloat64("/data/onef64", 123.456)

Example of reading data (must be in the same order used during writing):

g := Open("/tmp/gosl/hb", "basic01")
defer g.Close()
u := g.GetArray("/u")
du := g.GetArray("/displacements/u")
dv := g.GetArray("/displacements/v")
t0i0a0u := g.GetArray("/time0/ip0/a0/u")
t1i0b0u := g.GetArray("/time1/ip0/b0/u")
someints := g.GetInts("/someints")
oneint := g.GetInt("/data/oneint")
onef64 := g.GetFloat64("/data/onef64")

API

Please see the documentation here

Documentation

Overview

Package hb implements a pseudo hierarchical binary (hb) data file format

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

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

File represents a HDF5 file

func Create

func Create(dirOut, fnameKey string) (o *File)

Create creates a new file, deleting existent one

Input:
  dirOut   -- directory name that will be created if non-existent
              Note: dirOut may contain environment variables
  fnameKey -- filename key; e.g. without extension

Output:
  returns a new File object where the filename will be:
    fnameKey + .hb

func Open

func Open(dirIn, fnameKey string) (o *File)

Open opens an existent file for read only

Input:
  dirIn    -- directory name where the file is located
              Note: dirIn may contain environment variables
  fnameKey -- filename key; e.g. without extension

Output:
  returns a new File object where the filename will be:
    fnameKey + .hb

func (*File) Close

func (o *File) Close()

Close closes file

func (File) Filename

func (o File) Filename() string

Filename returns the filename; i.e. fileNameKey + extension

func (File) Filepath

func (o File) Filepath() string

Filepath returns the full filepath, including directory name

func (*File) GetArray

func (o *File) GetArray(path string) (v []float64)

GetArray gets an array from file. Memory will be allocated

func (*File) GetDeep2

func (o *File) GetDeep2(path string) (a [][]float64)

GetDeep2 gets a Deep2 slice (that was serialized). Memory will be allocated

func (*File) GetDeep2raw

func (o *File) GetDeep2raw(path string) (m, n int, a []float64)

GetDeep2raw returns the serialized data corresponding to a Deep2 slice

func (*File) GetDeep3

func (o *File) GetDeep3(path string) (a [][][]float64)

GetDeep3 gets a deep slice with 3 levels from file. Memory will be allocated

func (*File) GetFloat64

func (o *File) GetFloat64(path string) float64

GetFloat64 gets one float64 from file

Note: this is a convenience function wrapping GetArray

func (*File) GetInt

func (o *File) GetInt(path string) int

GetInt gets one integer from file

Note: this is a convenience function wrapping GetInts

func (*File) GetIntAttribute

func (o *File) GetIntAttribute(path, key string) (val int)

GetIntAttribute gets int attribute

func (*File) GetInts

func (o *File) GetInts(path string) (v []int)

GetInts gets a slice of ints from file. Memory will be allocated

func (*File) GetIntsAttribute

func (o *File) GetIntsAttribute(path, key string) (vals []int)

GetIntsAttribute gets slice-of-ints attribute

func (*File) GetStringAttribute

func (o *File) GetStringAttribute(path, key string) (val string)

GetStringAttribute gets string attribute

func (*File) PutArray

func (o *File) PutArray(path string, v []float64)

PutArray puts an array with name described by path

Input:
  path -- path such as "/myvec" or "/group/myvec"
  v    -- slice of float64

func (*File) PutDeep2

func (o *File) PutDeep2(path string, a [][]float64)

PutDeep2 puts a Deep2 slice into file

Input:
  path -- HDF5 path such as "/myvec" or "/group/myvec"
  a    -- slice of slices of float64
Note: Slice will be serialized

func (*File) PutDeep3

func (o *File) PutDeep3(path string, a [][][]float64)

PutDeep3 puts a deep slice with 3 levels and name described in path into HDF5 file

Input:
  path -- HDF5 path such as "/myvec" or "/group/myvec"
  a    -- slice of slices of slices of float64
Note: Slice will be serialized

func (*File) PutFloat64

func (o *File) PutFloat64(path string, val float64)

PutFloat64 puts one float64 into file

Input:
  path -- path such as "/myvec" or "/group/myvec"
  val  -- value
Note: this is a convenience function wrapping PutArray

func (*File) PutInt

func (o *File) PutInt(path string, val int)

PutInt puts one integer into file

Input:
  path -- HDF5 path such as "/myvec" or "/group/myvec"
  val  -- value
Note: this is a convenience function wrapping PutInts

func (*File) PutInts

func (o *File) PutInts(path string, v []int)

PutInts puts a slice of integers into file

Input:
  path -- HDF5 path such as "/myvec" or "/group/myvec"
  v    -- slice of integers

func (*File) ReadArray

func (o *File) ReadArray(v []float64, path string) (dims []int)

ReadArray reads an array from file into existent pre-allocated memory

Input:
  path -- path such as "/myvec" or "/group/myvec"
Output:
  array -- values in pre-allocated array => must know dimension
  dims  -- dimensions (for confirmation)

func (*File) SetIntAttribute

func (o *File) SetIntAttribute(path, key string, val int)

SetIntAttribute sets int attibute

func (*File) SetIntsAttribute

func (o *File) SetIntsAttribute(path, key string, vals []int)

SetIntsAttribute sets slice-of-ints attibute

func (*File) SetStringAttribute

func (o *File) SetStringAttribute(path, key, val string)

SetStringAttribute sets a string attibute

Jump to

Keyboard shortcuts

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