Theoretica
Mathematical Library
Loading...
Searching...
No Matches
csv.h File Reference

CSV file format support. More...

#include <fstream>
#include <iomanip>
#include <algorithm>
#include "./error.h"
#include "../algebra/vec.h"
#include "../algebra/mat.h"
#include "../statistics/histogram.h"
#include "./data_table.h"
#include "./strings.h"

Go to the source code of this file.

Namespaces

namespace  theoretica
 Main namespace of the library which contains all functions and objects.
 
namespace  theoretica::io
 Input and output module.
 

Functions

std::vector< std::string > theoretica::io::parse_csv (const std::string &line, char delimiter=',')
 Parse a CSV line handling quoted fields.
 
std::string theoretica::io::quote_csv (const std::string &str)
 Given a string entry, sanitize it for printing to a CSV file.
 
template<typename Type , unsigned int N>
void theoretica::io::write_csv (const std::string &filename, const vec< Type, N > &v, unsigned int precision=8)
 Write a vector to file in the CSV format.
 
template<typename Type , unsigned int N>
void theoretica::io::write_csv (const std::string &filename, const std::string &header, const vec< Type, N > &v, unsigned int precision=8)
 Write a vector to file in the CSV format, with a column header.
 
template<typename Type , unsigned int N, enable_real< Type > = true>
void theoretica::io::read_csv (const std::string &filename, vec< Type, N > &v)
 Read a vector from a file in the CSV format.
 
template<typename Type , unsigned int N, enable_real< Type > = true>
void theoretica::io::read_csv (const std::string &filename, const std::string &col_name, vec< Type, N > &v, bool trim_nan=true)
 Read a specific column of a CSV file as a vector.
 
template<typename Type , unsigned int N, unsigned int M>
void theoretica::io::write_csv (const std::string &filename, const mat< Type, N, M > &A, const std::string &delimiter=", ", unsigned int precision=8)
 Write a matrix to file in the CSV format.
 
template<unsigned int N, unsigned int K>
void theoretica::io::read_csv (const std::string &filename, mat< real, N, K > &A)
 Read a matrix from a file in the CSV format.
 
void theoretica::io::write_csv (const std::string &filename, const data_table &table, const std::string &delimiter=", ", unsigned int precision=8)
 Write a data_table to file in the CSV format.
 
void theoretica::io::read_csv (const std::string &filename, data_table &table)
 Read a data_table from a file in the CSV format.
 
void theoretica::io::write_csv (const std::string &filename, const histogram &hist, bool normalized=false, bool lower_extreme=false, const std::string &delimiter=", ", unsigned int precision=8)
 Write histogram data to file in the CSV format.
 
void theoretica::io::read_csv (const std::string &filename, histogram &hist, bool lower_extreme=false)
 Read a histogram from file, expecting a CSV format with columns "bins", "counts", "number", "average", "tss", "min" and "max", as written by write_csv(histogram).
 
template<typename Type >
Type theoretica::io::read_csv (const std::string &filename)
 Read a generic data structure from a file in the CSV format, specifying the target type.
 

Detailed Description

CSV file format support.