10 #include <application/exceptions.hpp>
17 std::ifstream ifile(fname.c_str());
18 return ifile.is_open();
22 for (
char const*
cp = line; *
cp; ++
cp) {
23 if (!std::isspace(*
cp))
return false;
31 std::stringstream msg;
33 throw NotFoundError(
"DecommentFile", fname);
36 std::ifstream file(fname.c_str(), std::ios::in);
42 while (c !=
'\n' && file) file.get(c);
51 std::ifstream inp(fname.c_str(), std::ios::in);
53 std::getline(inp, line);
54 if (line.empty())
return 0;
55 int cols = line[0] == c ? 0 : 1;
57 for (
int i = 1; i < line.length(); ++i)
58 if (line[i - 1] == c && line[i] != c) cols++;
63 std::ifstream inp(fname.c_str(), std::ios::in);
67 while (std::getline(inp, line)) ++rows;
72 int len = strlen(buf);
73 for (
int i = 0; i < len; ++i)
74 if (buf[i] == c_old) buf[i] = c_new;
79 int len = strlen(line);
81 while (len > 0 && (line[len - 1] ==
'\n' || line[len - 1] ==
'\r'))
84 while (isspace(*
p))
p++;
88 while (*pp !=
'#' && *pp) pp++;
93 char*
NextLine(
char* line,
int num, FILE* stream) {
95 while (fgets(line, num, stream) != NULL) {
97 if (strlen(
p) > 0)
break;
105 std::ifstream input(fname.c_str(), std::ios::in);
106 std::stringstream ss, msg;
107 std::string line, sbuffer;
108 std::vector<std::string> field;
110 if (!input.is_open()) {
111 throw NotFoundError(
"read_data_vector", fname);
114 getline(input, line);
118 field.push_back(sbuffer);
122 while (getline(input, line)) {
123 if (line.empty())
continue;
125 for (std::vector<std::string>::iterator f = field.begin(); f != field.end();
129 amap[*f].push_back(value);
int GetNumCols(std::string fname, char c)
get number of columns in a data table
std::string DecommentFile(std::string fname)
decomment a file
int GetNumRows(std::string fname)
get number of rows in a data table
bool FileExists(std::string fname)
test file existance
char * StripLine(char *line)
void replaceChar(char *buf, char c_old, char c_new)
replace a character in a string
char * NextLine(char *line, int num, FILE *stream)
bool IsBlankLine(char const *line)
test a blank line
DataVector read_data_vector(std::string fname)
std::map< std::string, std::vector< double > > DataVector