GLAMERDOC++
Gravitational Lensing Code Library
|
namespace for input/output utilities More...
Functions | |
bool | file_exists (const std::string &name) |
template<class T > | |
void | read1columnfile (std::string filename, std::vector< T > &x, int skiplines=0, bool verbose=false) |
template<class T1 , class T2 > | |
void | read2columnfile (std::string filename, std::vector< T1 > &x, std::vector< T2 > &y, std::string delineator=" ", int skiplines=0, bool verbose=false) |
Read in data from an ASCII file with two columns. | |
template<class T1 , class T2 , class T3 > | |
void | read3columnfile (std::string filename, std::vector< T1 > &x, std::vector< T2 > &y, std::vector< T3 > &z, std::string delineator=" ", bool verbose=false) |
Read in data from an ASCII file with three columns. | |
int | NumberOfEntries (const std::string &string, char deliniator) |
int | CountColumns (std::string filename, char comment_char='#', char deliniator=' ') |
Count the number of columns in a ASCII data file. | |
void | ReadFileNames (std::string dir, const std::string filespec, std::vector< std::string > &filenames, bool verbose) |
Reads the file names in a directory that contain a specific sub string. | |
bool | check_directory (std::string dir) |
returns true if director exists and false if it doesn't | |
bool | make_directories (const std::string &root_dir) |
make a directory if it doesn't exist | |
template<typename T > | |
void | ReadASCII (std::vector< T > &data, std::string filename, int &columns, int &rows, char comment_char='#', int skiplines=0, size_t MaxNrows=std::numeric_limits< size_t >::max(), bool verbose=true) |
This function will read in all the numbers from a multi-column ,space seporated ASCII data file. | |
template<typename T > | |
int | ReadCSVnumerical1 (std::string filename, std::vector< std::vector< T > > &data, std::vector< std::string > &column_names, size_t MaxNumber=100000000, char comment_char='#', char deliniator=',', std::string replace="\\N", std::function< bool(std::vector< T > &)> accept=[](std::vector< T > &v){return true;}) |
Read numerical data from a csv file with a header. | |
template<typename T > | |
size_t | ReadCSVrange (std::string filename, std::vector< std::vector< T > > &ranges, std::vector< std::string > &column_names, size_t MaxNumber=100000000, char comment_char='#', char deliniator=',', std::string replace="\\N", std::function< bool(std::vector< T > &)> accept=[](std::vector< T > &v){return true;}) |
template<typename T > | |
int | ReadCSVnumerical2 (std::string filename, std::vector< std::vector< T > > &data, std::vector< std::string > &column_names, size_t Nmax=1000000, char comment_char='#', char deliniator=',', bool header=true, std::string reject="") |
Read numerical data from a csv file with a header. | |
template<typename T > | |
void | writeCSV (const std::string filename, const std::vector< std::string > header, std::vector< T * > &data) |
write a CSV data file for some data vectors | |
namespace for input/output utilities
int Utilities::IO::CountColumns | ( | std::string | filename, |
char | comment_char = '#', | ||
char | deliniator = ' ' ) |
Count the number of columns in a ASCII data file.
filename | name of file |
comment_char | comment charactor |
deliniator | deliniator between columns |
void Utilities::IO::read1columnfile | ( | std::string | filename, |
std::vector< T > & | x, | ||
int | skiplines = 0, | ||
bool | verbose = false ) |
filename | input file name |
x | vector that will contain the first column |
void Utilities::IO::read2columnfile | ( | std::string | filename, |
std::vector< T1 > & | x, | ||
std::vector< T2 > & | y, | ||
std::string | delineator = " ", | ||
int | skiplines = 0, | ||
bool | verbose = false ) |
Read in data from an ASCII file with two columns.
filename | input file name |
x | vector that will contain the first column |
y | vector that will contain the second column |
delineator | specific string the seporates columns, ex. ",", "|", etc. |
void Utilities::IO::read3columnfile | ( | std::string | filename, |
std::vector< T1 > & | x, | ||
std::vector< T2 > & | y, | ||
std::vector< T3 > & | z, | ||
std::string | delineator = " ", | ||
bool | verbose = false ) |
Read in data from an ASCII file with three columns.
filename | input file name |
x | vector that will contain the first column |
y | vector that will contain the second column |
z | vector that will contain the third column |
delineator | specific string the seporates columns, ex. ",", "|", etc. |
void Utilities::IO::ReadASCII | ( | std::vector< T > & | data, |
std::string | filename, | ||
int & | columns, | ||
int & | rows, | ||
char | comment_char = '#', | ||
int | skiplines = 0, | ||
size_t | MaxNrows = std::numeric_limits<size_t>::max(), | ||
bool | verbose = true ) |
This function will read in all the numbers from a multi-column ,space seporated ASCII data file.
It will skip the comment lines if they are at the head of the file. The number of columns and rows are returned. The entry at row r and column c will be stored at data[c + column*r].
This function is not particularly fast for large amounts of data. If the number of roaws is large it would be best to use data.reserve() to set the capacity of data large enough that no rellocation of memory occurs.
int Utilities::IO::ReadCSVnumerical1 | ( | std::string | filename, |
std::vector< std::vector< T > > & | data, | ||
std::vector< std::string > & | column_names, | ||
size_t | MaxNumber = 100000000, | ||
char | comment_char = '#', | ||
char | deliniator = ',', | ||
std::string | replace = "\\N", | ||
std::function< bool(std::vector< T > &)> | accept = [](std::vector<T> &v){return true;} ) |
Read numerical data from a csv file with a header.
It will skip the comment lines if they are at the head of the file. The number of columns and rows are returned. The entries will be stored at data[column][row].
Comments must only be before the data. There must be a line with the column names after the comments and before the data.
This function is not particularly fast for large amounts of data. If the number of rows is large it would be best to use data.reserve() to set the capacity of data large enough that no rellocation of memory occurs.
The accept function can be used to limit the amount of data added. If there is an object, a, used to make this selection this can be done like [&a](str::vector<T> &v}{return a.itsok(v[3],v[4]);} where v corresponds to a row in the data file in order.
return to first data line
clean blank spaces
filename | file name to be read |
data | output data |
column_names | list of column names |
MaxNumber | maximum number of entries read |
comment_char | comment charactor for header |
deliniator | deliniator between values |
replace | replace this string with zero |
accept | function that determines if a row should be accepted |
int Utilities::IO::ReadCSVnumerical2 | ( | std::string | filename, |
std::vector< std::vector< T > > & | data, | ||
std::vector< std::string > & | column_names, | ||
size_t | Nmax = 1000000, | ||
char | comment_char = '#', | ||
char | deliniator = ',', | ||
bool | header = true, | ||
std::string | reject = "" ) |
Read numerical data from a csv file with a header.
Same as ReadCSVnumerical1 except the order of the data storage is reversed data[row][column].
It will skip the comment lines if they are at the head of the file. The number of columns and rows are returned.
Comments must only be before the data. Then if header==true there should be a line of column names. If header!=true there are non column names.
This function is not particularly fast for large amounts of data. If the number of rows is large it would be best to use data.reserve() to set the capacity of data large enough that no rellocation of memory occurs.
clean blank spaces
filename | file name to be read |
data | output data |
column_names | list of column names |
comment_char | comment charactor for header |
deliniator | deliniator between values |
header | false if there are no column names |
reject | reject lines with this entry after striping black space |
size_t Utilities::IO::ReadCSVrange | ( | std::string | filename, |
std::vector< std::vector< T > > & | ranges, | ||
std::vector< std::string > & | column_names, | ||
size_t | MaxNumber = 100000000, | ||
char | comment_char = '#', | ||
char | deliniator = ',', | ||
std::string | replace = "\\N", | ||
std::function< bool(std::vector< T > &)> | accept = [](std::vector<T> &v){return true;} ) |
Finds ranges
return to first data line
clean blank spaces
filename | file name to be read |
ranges | output data |
column_names | list of column names |
MaxNumber | maximum number of entries read |
comment_char | comment charactor for header |
deliniator | deliniator between values |
replace | replace this string with zero |
accept | function that determines if a row should be accepted |
void Utilities::IO::ReadFileNames | ( | std::string | dir, |
const std::string | filespec, | ||
std::vector< std::string > & | filenames, | ||
bool | verbose ) |
Reads the file names in a directory that contain a specific sub string.
dir | path to directory containing fits files |
filespec | string of charactors in file name that are matched. It can be an empty string. |
filenames | output vector of PixelMaps |
void Utilities::IO::writeCSV | ( | const std::string | filename, |
const std::vector< std::string > | header, | ||
std::vector< T * > & | data ) |
write a CSV data file for some data vectors
example:
std::vector<std::string> header = {"alpha","kappa","gamma"};
std::vector<double> v1 = {1,2,3}; std::vector<double> v2 = {1.1,2.1,3.1}; std::vector<double> v3 = {3,4,5};
std::vector<std::vector<double> *> data; data.push_back(&v1); data.push_back(&v2); data.push_back(&v3); writeCSV(filename,header,data);
filename | output file path/name |
header | column labels |
data | objects must have operator [] |