3 #include "readcolumns.h"
5 int readcolumns(
const char * fname, std::string delims,
char comment,
const char * format, ...)
13 std::string argstr, tmpstr;
19 nargs = strlen(format);
27 fin.getline(tmpline, 1024);
30 pos = tmpstr.find(comment,0);
31 opos = tmpstr.find_first_not_of(delims+comment, 0);
34 if(opos == -1 || opos > pos)
continue;
36 if(opos < 0)
continue;
43 for(
int i = 0; i < nargs; i++)
48 intptrptr = va_arg(ap,
int**);
49 (*intptrptr) =
new int[nlines];
52 dblptrptr = va_arg(ap,
double **);
53 (*dblptrptr) =
new double[nlines];
56 std::cerr <<
"Unrecognized format specifier in readcol\n";
71 for(
int i=0; i < nlines; i++)
73 fin.getline(tmpline, 1024);
77 pos = tmpstr.find(comment,0);
78 opos = tmpstr.find_first_not_of(delims+comment, 0);
81 if(opos == -1 || opos > pos)
98 for(
int j = 0; j < nargs; j++)
100 pos = tmpstr.find_first_of(delims+
'\n', opos);
102 if(pos == -1) pos = tmpstr.length();
104 argstr = tmpstr.substr(opos, pos-opos);
107 opos = tmpstr.find_first_not_of(delims+
'\n', pos+1);
108 if(opos == -1) opos = tmpstr.length();
114 intptrptr = va_arg(ap,
int**);
115 (*intptrptr)[i] = atoi(argstr.c_str());
118 dblptrptr = va_arg(ap,
double **);
119 (*dblptrptr)[i] = strtod(argstr.c_str(), 0);
122 std::cerr <<
"Unrecognized format specifier in readcol\n";