mmio

package module
v0.0.0-...-274b57c Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: MIT Imports: 29 Imported by: 38

README

mmio

A set of commonly used io functions written in Go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayToPNG

func ArrayToPNG(fp string, v []float64, nr, nc int)

ArrayToPNG prints a 2D array (as row-major 1D array) to a png

func BitArray

func BitArray(b []byte) []bool

BitArray converts a slice of bytes to a slice of boolean

func BitArray1

func BitArray1(b byte) []bool

BitArray1 converts a byte into a slice of boolean

func BitArray1Rev

func BitArray1Rev(b []bool) byte

BitArray1Rev converts a slice of boolean to a byte https://stackoverflow.com/questions/73710132/golang-convert-8bool-to-byte

func BitArrayRev

func BitArrayRev(b []bool) []byte

BitArrayRev converts a slice of boolean to a slice of bytes

func CallResponse

func CallResponse(done chan interface{}) <-chan string

CallResponse is a pipeline that takes in a user's entry, and return it as a channel. ctrl-c ends the program modified from: https://www.reddit.com/r/golang/comments/4hktbe/read_user_input_until_he_press_ctrlc/

func CompressTarGZ

func CompressTarGZ(path string) (string, error)

CompressTarGZ converts a path to a *.tar.gz

func CompressTarGZext

func CompressTarGZext(path, ext string) (string, error)

CompressTarGZext converts files (with a given extension) in a path to a *.tar.gz

func CopyMapIF

func CopyMapIF(originalMap map[int]float64) (newMap map[int]float64)

CopyMapIF deep copies map[int]float64

func CreateEmpty

func CreateEmpty(filepath string) error

func DeleteAllInDirectory

func DeleteAllInDirectory(dir, ext string)

DeleteAllInDirectory deletes all files of a given extension in a specified directory exension format: ".***"

func DeleteAllSubdirectories

func DeleteAllSubdirectories(dir string)

DeleteAllSubdirectories deletes all subdirectories within a specified directory

func DeleteDir

func DeleteDir(dir string)

DeleteDir deletes a directory

func DeleteFile

func DeleteFile(fp string)

DeleteFile deletes the specified file or directory

func DirExists

func DirExists(path string) bool

DirExists checks if a directory exists

func DirList

func DirList(root string) ([]string, error)

DirList returns a list of subdirectories

func EndPprof

func EndPprof()

EndPprof ends pprof (set as a defer statement after NewPprof)

func EndTrace

func EndTrace()

EndTrace ends trace (set as a defer statement after NewTrace)

func ExtractTarGZ

func ExtractTarGZ(fp string) (string, error)

ExtractTarGZ extracts a *.tar.gz file to a directory from https://gist.github.com/indraniel/1a91458984179ab4cf80

func FileExists

func FileExists(path string) (int64, bool)

FileExists checks if a file exists and returns its size

func FileList

func FileList(path string) ([]string, error)

FileList returns a recursive list of files from a given directory

func FileListExt

func FileListExt(dir, ext string) ([]string, error)

FileListExt returns a list of files of a given extension from a directory. directories should end with "/" and extensions start with ".". exension format: ".***"

func FileName

func FileName(fp string, withExtension bool) string

FileName returns the file name

func FileRename

func FileRename(oldName, newName string, overwrite bool)

FileRename renames a file

func GetExtension

func GetExtension(fp string) string

GetExtension returns the file path extension returns with dot following extension

func GetFileDir

func GetFileDir(fp string) string

GetFileDir returns the directory that contains the given filepath

func GetInstance

func GetInstance(fnam string) *logger

GetInstance start log file outputting to ./mm.log

func HeapDump

func HeapDump(fp string)

HeapDump writes a heap profiling file

func InterfaceToFloat

func InterfaceToFloat(d []interface{}) []float64

InterfaceToFloat converts a slice of interface, and converts to float (assuming possible)

func IsDir

func IsDir(path string) bool

IsDir check if the entered path is a directory

func LineSegmentsToGeojson

func LineSegmentsToGeojson(lns map[int]mmaths.LineSegment, outfp string)

func LinesToAscii

func LinesToAscii(fp string, s []string) error

func LoadCSV

func LoadCSV(rc io.Reader, nHeaderLines int) (ch chan []string)

LoadCSV use: for rec := range LoadCSV(io.Reader(f)) {

func LoadCsvArray

func LoadCsvArray(fp string, nHeaderLines int) [][]string

func LoadGOB

func LoadGOB(fp string) (map[int]int, error)

LoadGOB saves map[int]int

func MMdate

func MMdate(d time.Time) string

MMdate returns a string date formatted yymmdd

func MMtime

func MMtime(d time.Time) string

MMtime returns a string date formatted yymmddhhmmss

func MakeDir

func MakeDir(path string) string

MakeDir checks if directory exists, if not, creates it

func MinMaxTime

func MinMaxTime() (_, _ time.Time)

MinMaxTime returns the limits of time.Time (see https://stackoverflow.com/questions/25065055/what-is-the-maximum-time-time-in-go/32620397#32620397)

func MinMaxTimeseries

func MinMaxTimeseries(ts TimeSeries) (_, _ time.Time)

MinMaxTimeseries returns the range of a Timeseries

func MonthDays

func MonthDays(year Yr, month Mo) int

MonthDays returns the number of days in a given month

func MoveFile

func MoveFile(sourcePath, destPath string) error

MoveFile moves a file (https://stackoverflow.com/questions/50740902/move-a-file-to-a-different-drive-with-go)

func NewPprof

func NewPprof() error

NewPprof starts a new pprof and outputs to file cpu.pprof

func NewTrace

func NewTrace()

NewTrace starts a new pprof and outputs to file cpu.trace

func OpenBinary

func OpenBinary(filepath string) *bytes.Reader

OpenBinary creates reader from filepath

func PrintMemUsage

func PrintMemUsage()

PrintMemUsage outputs the current, total and OS memory being used. As well as the number of garage collection cycles completed. from: https://golangcode.com/print-the-current-memory-usage/

func ReachedEOF

func ReachedEOF(b *bytes.Reader) bool

ReachedEOF tests to see if all reader data has been read

func ReadBinary

func ReadBinary(filepath string, data ...interface{}) error

ReadBinary general binary reader

func ReadBinaryFloat32s

func ReadBinaryFloat32s(filepath string, d int) ([][]float32, int, error)

ReadBinaryFloat32s reads an entire file and returns a slice of d dimensions

func ReadBinaryFloat64s

func ReadBinaryFloat64s(filepath string, d int) ([][]float64, int, error)

ReadBinaryFloats reads an entire file and returns a slice of d dimensions

func ReadBinaryFloats

func ReadBinaryFloats(filepath string) ([]float64, error)

ReadBinaryFloats reads an entire file and returns a slice of floats

func ReadBinaryIMAP

func ReadBinaryIMAP(filepath string) (map[int]int, error)

ReadBinaryIMAP reads a map[int]int for an entire file

func ReadBinaryInts

func ReadBinaryInts(filepath string, d int) ([][]int32, int, error)

ReadBinaryInts reads an entire file and returns a slice of d dimensions

func ReadBinaryRMAP

func ReadBinaryRMAP(filepath string) (map[int]float64, error)

ReadBinaryRMAP reads a map[int]float64 for an entire file

func ReadBinaryShorts

func ReadBinaryShorts(filepath string, d int) ([][]int16, int, error)

ReadBinaryShorts reads an entire file and returns a slice of d dimensions

func ReadBytes

func ReadBytes(b *bytes.Reader, n int) []byte

ReadBytes reads next n-byte array from buffer

func ReadCSV

func ReadCSV(filepath string, nHeaderLines int) ([][]float64, error)

ReadCSV general CSV reader (must be completely numeric)

func ReadCsvDateFloat

func ReadCsvDateFloat(csvfp string) (map[int64]float64, error)

ReadCsvDateFloat reads temporal csv file "date,value,flag,..."

func ReadCsvDateFloats

func ReadCsvDateFloats(csvfp string) (map[time.Time][]float64, error)

ReadCsvDateFloat reads temporal csv file "date,value,flag,..."

func ReadCsvStringFloat

func ReadCsvStringFloat(csvfp string) (map[string]float64, error)

ReadCsvStringFloat reads temporal csv file ith column type "<str>,<float>"

func ReadCsvStringInt

func ReadCsvStringInt(csvfp string) (map[string]int, error)

ReadCsvStringInt reads temporal csv file ith column type "<str>,<int>"

func ReadFloat32

func ReadFloat32(b *bytes.Reader) float32

ReadFloat32 reads next float32 from buffer

func ReadFloat64

func ReadFloat64(b *bytes.Reader) float64

ReadFloat64 reads next float64 from buffer

func ReadFloats

func ReadFloats(fp string) ([]float64, error)

ReadFloats is a simple routine that reads an float slice to an ascii file

func ReadGeojsonLines

func ReadGeojsonLines(fp string) [][][]float64

func ReadInt32

func ReadInt32(b *bytes.Reader) int32

ReadInt32 reads next int32 from buffer

func ReadInt32check

func ReadInt32check(b *bytes.Reader) (int32, bool)

ReadInt32check reads next int32 from buffer

func ReadInt64

func ReadInt64(b *bytes.Reader) int64

ReadInt64 reads next int64 from buffer

func ReadInt8

func ReadInt8(b *bytes.Reader) int8

ReadInt8 reads next int8 (signed byte) from buffer

func ReadInts

func ReadInts(fp string) ([]int, error)

ReadInts is a simple routine that reads an integer slice to an ascii file

func ReadLines

func ReadLines(b *bytes.Reader) []string

ReadLines reads and returns string lines from binary file

func ReadString

func ReadString(b *bytes.Reader) string

ReadString reads and returns string from binary file

func ReadTextLines

func ReadTextLines(fp string) ([]string, error)

ReadTextLines reads and returns string lines from binary file

func ReadUInt16

func ReadUInt16(b *bytes.Reader) uint16

ReadUInt16 reads next uint16 from buffer

func ReadUInt32

func ReadUInt32(b *bytes.Reader) uint32

ReadUInt32 reads next uint32 from buffer

func ReadUInt64

func ReadUInt64(b *bytes.Reader) uint64

ReadUInt64 reads next uint64 from buffer

func ReadUInt8

func ReadUInt8(b *bytes.Reader) uint8

ReadUInt8 reads next uint8 from buffer

func RemoveBOM

func RemoveBOM(r *bufio.Reader) error

RemoveBOM detects byte order mark (BOM) and moves ahead if exists

func RemoveExtension

func RemoveExtension(fp string) string

RemoveExtension returns the file path without its extension

func RemoveWhiteSpaces

func RemoveWhiteSpaces(s string) string

removes tabs, duplicate spaces, returns (\n) from: https://gosamples.dev/remove-duplicate-spaces/

func SaveGOB

func SaveGOB(fp string, d map[int]int) error

SaveGOB saves map[int]int

func Thousands

func Thousands(n int64) string

Thousands returns a string integer with thousand separators from: https://stackoverflow.com/questions/13020308/how-to-fmt-printf-an-integer-with-thousands-comma

func WriteBinary

func WriteBinary(filepath string, data ...interface{}) error

WriteBinary general binary writer

func WriteCSV

func WriteCSV(fp, h string, d ...[]interface{})

WriteCSV writes csv from a complete dataset

func WriteCSV2d

func WriteCSV2d(fp, h string, dat [][]interface{})

WriteCSV2d writes csv from a complete dataset dat[row][col]

func WriteCsvDateFloats

func WriteCsvDateFloats(csvfp, header string, t []time.Time, d ...[]float64) error

func WriteCsvFloats

func WriteCsvFloats(csvfp, header string, d ...[]float64) error

func WriteCsvFloats32

func WriteCsvFloats32(csvfp, header string, d ...[]float32) error

func WriteCsvIntInts

func WriteCsvIntInts(csvfp, header string, ii map[int]int) error

func WriteFloats

func WriteFloats(fp string, d []float64) error

WriteFloats is a simple routine that writes an float slice to an ascii file

func WriteIMAP

func WriteIMAP(filepath string, data map[int]int) error

WriteIMAP general map writer

func WriteInts

func WriteInts(fp string, d []int) error

WriteInts is a simple routine that writes an integer slice to an ascii file

func WriteLines

func WriteLines(fp string, s []string) error

func WriteRMAP

func WriteRMAP(filepath string, data map[int]float64, append bool) error

WriteRMAP general map writer

func WriteString

func WriteString(fp, content string) error

func WriteStrings

func WriteStrings(fp string, s []string) error

WriteStrings is a simple routine that writes a slice of strings to an ascii file

Types

type CSVwriter

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

CSVwriter general CSV writer

func NewCSVwriter

func NewCSVwriter(fp string) *CSVwriter

NewCSVwriter CSVwriter constructor

func (*CSVwriter) Close

func (w *CSVwriter) Close()

Close closes CSVwriter

func (*CSVwriter) WriteHead

func (w *CSVwriter) WriteHead(h string) error

WriteHead add header row to CSVwriter

func (*CSVwriter) WriteLine

func (w *CSVwriter) WriteLine(data ...interface{}) error

WriteLine general CSV line writer method for CSVwriter

type Instruct

type Instruct struct {
	Desc  string
	Param map[string][]string
}

func NewInstruct

func NewInstruct(filepath string) *Instruct

type Mo

type Mo = time.Month

Mo month

type TXTwriter

type TXTwriter struct {
	Writer *bufio.Writer
	// contains filtered or unexported fields
}

TXTwriter general text writer

func NewTXTwriter

func NewTXTwriter(fp string) (*TXTwriter, error)

NewTXTwriter constructor

func (*TXTwriter) Close

func (w *TXTwriter) Close()

Close closes TXTwriter

func (*TXTwriter) Write

func (w *TXTwriter) Write(s string) error

Write is a general textfile writer method for TXTwriter

func (*TXTwriter) WriteBytes

func (w *TXTwriter) WriteBytes(b []byte) error

WriteBytes general textfile line writer method for TXTwriter

func (*TXTwriter) WriteLine

func (w *TXTwriter) WriteLine(line string) error

WriteLine is a general textfile line writer method for TXTwriter

type TimeSeries

type TimeSeries map[time.Time]float64

TimeSeries is a collection of temporal data

type TimeSeriesMonthly

type TimeSeriesMonthly map[Yr]map[Mo]float64

TimeSeriesMonthly returns a monthly timeseries

func MonthlySumCount

func MonthlySumCount(ts TimeSeries) (_, _ TimeSeriesMonthly)

MonthlySumCount converts a timeseries to a sum TimeSeriesMonthly and a count TimeSeriesMonthly

type Timer

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

Timer is a common timer used for profiling

func NewTimer

func NewTimer() Timer

NewTimer constructs a Timer

func (*Timer) Lap

func (t *Timer) Lap(msg string)

Lap reports lap time (resets timer)

func (*Timer) Now

func (t *Timer) Now() string

func (*Timer) Print

func (t *Timer) Print(msg string)

Print reports current time

func (*Timer) PrintAndReset

func (t *Timer) PrintAndReset(msg string)

func (*Timer) Reset

func (t *Timer) Reset()

Reset start a timer

func (*Timer) T0

func (t *Timer) T0() time.Time

type Yr

type Yr int

Yr year

Jump to

Keyboard shortcuts

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