37 #include <boost/numeric/ublas/vector.hpp>
38 #include <boost/numeric/ublas/matrix.hpp>
40 #include <o2scl/misc.h>
41 #include <o2scl/interp.h>
43 #ifndef DOXYGEN_NO_O2NS
47 template<
class vec_t>
class table;
66 #ifndef DOXYGEN_NO_O2NS
188 template<
class vec_t=std::vector<
double> >
class table {
213 size_t nc=t.get_nconsts();
214 for(
size_t i=0;i<nc;i++) {
217 t.get_constant(i,name,val);
225 for(
size_t i=0;i<t.get_ncolumns();i++) {
228 std::string cname=t.get_column_name(i);
234 atree.insert(make_pair(cname,s));
241 for(
size_t j=0;j<t.get_nlines();j++) {
242 it->second.dat[j]=t.get(cname,j);
261 size_t nc=t.get_nconsts();
262 for(
size_t i=0;i<nc;i++) {
265 t.get_constant(i,name,val);
273 for(
size_t i=0;i<t.get_ncolumns();i++) {
276 std::string cname=t.get_column_name(i);
282 atree.insert(make_pair(cname,s));
289 for(
size_t j=0;j<t.get_nlines();j++) {
290 it->second.dat[j]=t.get(cname,j);
317 void set(std::string scol,
size_t row,
double val) {
320 "' not finite for column '"+
321 scol+
"' in table::set(string,size_t,double)").c_str(),
336 if (it==
atree.end()) {
340 if (it==
atree.end()) {
341 O2SCL_ERR((((std::string)
"Refused to add column '")+scol+
342 "' in table::set(string,size_t,double).").c_str(),
347 it->second.dat[row]=val;
354 void set(
size_t icol,
size_t row,
double val) {
358 "' not finite and index "+
szttos(icol)+
359 " too large in table::set(size_t,size_t,double)").c_str(),
364 "' in table::set(size_t,size_t,double)").c_str(),
367 if (icol>=
atree.size()) {
368 std::string err=((std::string)
"Column out of range, ")+
szttos(icol)+
369 ">="+
szttos(
atree.size())+
", in table::set(size_t,size_t,double).";
382 alist[icol]->second.dat[row]=val;
389 double get(std::string scol,
size_t row)
const {
392 if (it==
atree.end()) {
393 O2SCL_ERR((((std::string)
"Column '")+scol+
394 "' not found in table::get().").c_str(),
398 tmp=it->second.dat[row];
406 double get(
size_t icol,
size_t row)
const {
407 if (icol>=
atree.size()) {
408 std::string err=((std::string)
"Column out of range, ")+
409 itos(icol)+
">="+
itos(
atree.size())+
", in table::get(size_t,size_t).";
414 std::string err=((std::string)
"Column out of range, ")+
419 return alist[icol]->second.dat[row];
476 template<
class vec2_t>
477 void get_row(std::string scol,
double val, vec2_t &row)
const {
479 int irow=
lookup(scol,val);
481 O2SCL_ERR((((std::string)
"Column '")+scol+
482 "' not found in table::get_row() const.").c_str(),
499 template<
class vec2_t>
500 void get_row(
size_t irow, vec2_t &row)
const {
504 "' not found in table::get_row().").c_str(),
511 row.allocate(
atree.size());
512 for(i=0,it=
atree.begin();it!=
atree.end();it++,i++) {
513 row[i]=(it->second.dat)[irow];
563 temp_col[j]=it->second.dat[j];
567 it->second.dat.resize(maxlines+llines);
571 it->second.dat[j]=temp_col[j];
590 if (it==
atree.end()) {
591 O2SCL_ERR((((std::string)
"Column '")+scol+
592 "' not found in table::get_column() const.").c_str(),
596 return it->second.dat;
614 #if !O2SCL_NO_RANGE_CHECK
615 if (icol>=
atree.size()) {
618 " in table::operator[size_t] const. Size: "+
620 " (index should be less than size).").c_str(),
exc_eindex);
623 return (
alist[icol]->second.dat);
642 #if !O2SCL_NO_RANGE_CHECK
643 if (it==
atree.end()) {
644 O2SCL_ERR((((std::string)
"Column '")+scol+
"' not found in table::"+
648 return (it->second.dat);
659 O2SCL_ERR((((std::string)
"Column '")+head+
660 "' already present in table::new_column().").c_str(),
663 for(
int i=0;i<((int)head.size());i++) {
664 if (head[i]==
' ' || head[i]==
'\t' || head[i]==
'\n' || head[i]==
'\r'
665 || head[i]==
'\v' || head[i]==
'\f') {
666 O2SCL_ERR((((std::string)
"Invalid column name '")+head+
667 "' in table::new_column().").c_str(),
674 atree.insert(make_pair(head,s));
691 size_t sz, vec2_t &v) {
695 "table::new_column(string,size_t,vec2_t)",
701 if (ret!=0)
return ret;
706 for(
size_t i=0;i<mxl;i++) {
716 if (icol+1>
atree.size()) {
719 return alist[icol]->first;
733 if (its==
atree.end()) {
734 O2SCL_ERR((((std::string)
"Column '")+scol+
735 " not found in table::delete_column().").c_str(),
739 if (v.size()!=its->second.dat.size()) {
740 O2SCL_ERR2(
"Vector sizes not commensurate in ",
743 std::swap(its->second.dat,v);
752 if (its==
atree.end()) {
753 O2SCL_ERR((((std::string)
"Column '")+src+
754 " not found in table::delete_column().").c_str(),
760 std::swap(its->second.dat,itd->second.dat);
774 if (it==
atree.end()) {
775 O2SCL_ERR((((std::string)
"Column '")+scol+
776 " not found in table::delete_column().").c_str(),
783 vit+=it->second.index;
788 alist[
alist.size()-1]->second.index=it->second.index;
809 if (icol+1>
atree.size()) {
813 for(
size_t i=0;i<icol;i++) it++;
827 "' not finite for column '"+
828 scol+
"' in table::init_column()").c_str(),
exc_einval);
832 if (it==
atree.end()) {
833 O2SCL_ERR((((std::string)
"Column '")+scol+
834 "' not found in table::init_column()").c_str(),
838 for(
size_t i=0;i<
nlines;i++) {
839 it->second.dat[i]=val;
855 if (it==
atree.end())
return false;
867 if (it==
atree.end()) {
868 O2SCL_ERR(
"Column not found in table::lookup_column().",
871 return it->second.index;
881 if (its==
atree.end()) {
882 O2SCL_ERR((((std::string)
"Column '")+src+
883 " not found in table::copy_column().").c_str(),
888 if (itd==
atree.end()) {
889 O2SCL_ERR((((std::string)
"Destination column '")+dest+
890 " not found in table::copy_column().").c_str(),
894 for(
size_t i=0;i<
nlines;i++) {
895 itd->second.dat[i]=its->second.dat[i];
905 template<
class resize_vec_t>
908 for(
size_t i=0;i<
nlines;i++) {
909 v[i]=this->
get(scol,i);
916 template<
class vec2_t>
918 for(
size_t i=0;i<
nlines;i++) {
919 this->
set(scol,i,v[i]);
938 template<
class vec2_t>
940 std::string src_index, std::string src_col,
941 std::string dest_index, std::string dest_col=
"") {
943 if (dest_col==
"") dest_col=src_col;
949 for(
size_t i=0;i<
nlines;i++) {
950 set(dest_col,i,source.interp(src_index,
get(dest_index,i),src_col));
972 for(
int i=((
int)
nlines)-2;i>=((int)n);i--) {
987 for(
int i=0;i<((int)
atree.size());i++) {
988 set(i,dest,
get(i,src));
1003 size_t irow=
lookup(scol,val);
1013 for(
int i=((
int)irow);i<((int)
nlines)-1;i++) {
1014 it->second.dat[i]=it->second.dat[i+1];
1032 size_t new_nlines=0;
1033 for(
size_t i=0;i<
nlines;i++) {
1040 if (i!=new_nlines) {
1042 it->second.dat[new_nlines]=it->second.dat[i];
1073 O2SCL_ERR2(
"Row specifications beyond end of table in ",
1074 "table::delete_rows(size_t,size_t).",
exc_einval);
1076 size_t new_nlines=0;
1077 for(
size_t i=0;i<
nlines;i++) {
1078 if ((row_start<=row_end && (i<row_start || i>row_end)) ||
1079 (row_start>row_end && (i<row_start && i>row_end))) {
1081 it->second.dat[new_nlines]=it->second.dat[i];
1112 std::istringstream *is=
new std::istringstream(newheads);
1114 while((*is) >> head) {
1120 O2SCL_ERR2(
"At least one new column failed in ",
1141 for(
size_t i=0;i<nv;i++) {
1142 (*this).set(i,
nlines-1,v[i]);
1169 "' not finite for column '"+
1170 scol+
"' in table::ordered_lookup()").c_str(),
exc_einval);
1174 if (it==
atree.end()) {
1175 O2SCL_ERR((((std::string)
"Column '")+scol+
1176 " not found in table::ordered_lookup().").c_str(),
1189 size_t lookup(std::string scol,
double val)
const {
1192 "' not finite for column '"+
1193 scol+
"' in table::lookup()").c_str(),
exc_einval);
1197 if (it==
atree.end()) {
1198 O2SCL_ERR((((std::string)
"Column '")+scol+
" not found in "+
1207 const vec_t &ov=it->second.dat;
1219 double best=ov[i], bdiff=fabs(ov[i]-val);
1224 bdiff=fabs(ov[i]-val);
1232 double lookup_val(std::string scol,
double val, std::string scol2)
const {
1236 "' not finite for column '"+
1237 scol+
"' in table::lookup_val()").c_str(),
exc_einval);
1241 if (it==
atree.end()) {
1242 O2SCL_ERR((((std::string)
"Column '")+scol+
" not found in "+
1246 return get(scol2,it->second.dat->lookup(val));
1259 size_t mlookup(std::string scol,
double val, std::vector<size_t> &results,
1260 double threshold=0.0)
const {
1264 "' not finite for column '"+
1265 scol+
"' in table::mlookup()").c_str(),
exc_einval);
1269 if (it==
atree.end()) {
1270 O2SCL_ERR((((std::string)
"Column '")+scol+
" not found in "+
1274 if (threshold==0.0) {
1276 if (it->second.dat[i]==val) {
1277 results.push_back(i);
1282 if (fabs(it->second.dat[i]-val)<threshold) {
1283 results.push_back(i);
1287 return results.size();
1317 double interp(std::string sx,
double x0, std::string sy) {
1321 O2SCL_ERR((((std::string)
"Columns '")+sx+
"' or '"+sy+
1322 "' not found in table::interp().").c_str(),
1337 ity->second.dat,
itype);
1355 O2SCL_ERR((((std::string)
"Columns '")+sx+
"' or '"+sy+
1356 "' not found in table::interp_const().").c_str(),
1368 ret=sic->interp(x0);
1376 double interp(
size_t ix,
double x0,
size_t iy) {
1391 void deriv(std::string x, std::string y, std::string yp) {
1392 aiter itx, ity, ityp;
1397 ityp=
atree.find(yp);
1406 for(
int i=0;i<((int)
nlines);i++) {
1407 ityp->second.dat[i]=
deriv(ix,(itx->second.dat)[i],iy);
1418 double deriv(std::string sx,
double x0, std::string sy) {
1422 O2SCL_ERR((((std::string)
"Columns '")+sx+
"' or '"+sy+
1423 "' not found in table::deriv().").c_str(),
1456 O2SCL_ERR((((std::string)
"Columns '")+sx+
"' or '"+sy+
1457 "' not found in table::deriv_const().").c_str(),
1477 double deriv(
size_t ix,
double x0,
size_t iy) {
1493 void deriv2(std::string x, std::string y, std::string yp) {
1494 aiter itx, ity, ityp;
1499 ityp=
atree.find(yp);
1508 for(
int i=0;i<((int)
nlines);i++) {
1509 ityp->second.dat[i]=
deriv2(ix,itx->second.dat[i],iy);
1520 double deriv2(std::string sx,
double x0, std::string sy) {
1524 O2SCL_ERR((((std::string)
"Columns '")+sx+
"' or '"+sy+
1525 "' not found in table::deriv2().").c_str(),
1558 O2SCL_ERR((((std::string)
"Columns '")+sx+
"' or '"+sy+
1559 "' not found in table::deriv2_const().").c_str(),
1579 double deriv2(
size_t ix,
double x0,
size_t iy) {
1597 double integ(std::string sx,
double x1,
double x2, std::string sy) {
1601 O2SCL_ERR((((std::string)
"Columns '")+sx+
"' or '"+sy+
1602 "' not found in table::integ().").c_str(),
1607 std::string msg=((std::string)
"Value x1=")+
dtos(x1)+
" or x2="+
1608 dtos(x2)+
" not finite in table.integ().";
1633 std::string sy)
const {
1637 O2SCL_ERR((((std::string)
"Columns '")+sx+
"' or '"+sy+
1638 "' not found in table::integ_const().").c_str(),
1678 void integ(std::string x, std::string y, std::string ynew) {
1679 aiter itx, ity, itynew;
1684 itynew=
atree.find(ynew);
1693 for(
size_t i=0;i<
nlines;i++) {
1694 itynew->second.dat[i]=
integ(ix,(itx->second.dat)[0],
1695 (itx->second.dat)[i],iy);
1704 double max(std::string scol)
const {
1708 O2SCL_ERR((((std::string)
"Column '")+scol+
1714 for(i=0;i<((int)
nlines);i++) {
1719 }
else if (dcol[i]>ret) {
1725 O2SCL_ERR((((std::string)
"No finite values in column '")+scol+
1735 double min(std::string scol)
const {
1739 O2SCL_ERR((((std::string)
"Column '")+scol+
1745 for(i=0;i<((int)
nlines);i++) {
1750 }
else if (dcol[i]<ret) {
1756 O2SCL_ERR((((std::string)
"No finite values in column '")+scol+
1777 size_t bottom)
const {
1789 sublines=bottom-top+1;
1791 O2SCL_ERR2(
"Can't make a subtable of an empty table. ",
1792 "Returning 0 in table::subtable().",
1797 O2SCL_ERR2(
"Requested row beyond nlines. Adjusting ",
1798 "and continuing in table::subtable().",
exc_einval);
1802 std::istringstream *is;
1803 is=
new std::istringstream(list);
1806 while((*is) >> head) {
1807 it=
atree.find(head);
1808 if (it==
atree.end()) {
1810 ((((std::string)
"Couldn't find column named ")+head+
1811 " in table::subtable(). Returning 0.").c_str(),
1816 at->new_column(head);
1817 vec_t &dcol=at->get_column(head);
1818 for(i=0;i<sublines;i++) {
1819 dcol[i]=it->second.dat[i+top];
1822 if (at->get_ncolumns()==0) {
1823 O2SCL_ERR(
"Subtable has no columns in table::subtable().",
1827 at->nlines=sublines;
1845 for(
int j=0;j<((int)
nlines);j++) {
1846 it->second.dat[j]=0.0;
1915 for(
size_t i=0;i<ncols;i++) {
1916 for(
size_t j=0;j<nlins;j++) {
1917 data_copy(i,j)=
get(i,j);
1923 vec_t &data=it->second.dat;
1925 for(
size_t i=0;i<ncols;i++) {
1926 for(
size_t j=0;j<nlins;j++) {
1927 set(i,j,data_copy(i,order[j]));
1946 if (it==
atree.end()) {
1947 O2SCL_ERR((((std::string)
"Column '")+scol+
1948 " not found in table::sort_column().").c_str(),
1973 virtual void summary(std::ostream *out,
size_t ncol=79)
const {
1976 (*out) <<
"1 constant:" << std::endl;
1978 (*out) <<
constants.size() <<
" constants:" << std::endl;
1980 std::map<std::string,double>::const_iterator mit;
1982 (*out) << mit->first <<
" " << mit->second << std::endl;
1990 (*out) <<
"No columns." << std::endl;
1995 (*out) <<
"1 column: " << std::endl;
1997 (*out) << nh <<
" columns: " << std::endl;
1999 std::string *h=
new std::string[nh];
2000 for(
size_t i=0;i<nh;i++) {
2004 std::vector<std::string> h2;
2010 for(
size_t i=0;i<nh2;i++) {
2011 (*out) << h2[i] << std::endl;
2017 if (
get_nlines()==0) (*out) <<
"No lines of data." << std::endl;
2018 else if (
get_nlines()==1) (*out) <<
"One line of data." << std::endl;
2019 (*out) <<
get_nlines() <<
" lines of data." << std::endl;
2041 bool err_on_notfound=
true) {
2046 if (err_on_notfound) {
2047 std::string err=((std::string)
"No constant with name '")+name+
2048 "' in table::set_constant().";
2065 virtual void get_constant(
size_t ix, std::string &name,
double &val)
const {
2067 std::map<std::string,double>::const_iterator cit=
constants.begin();
2068 for(
size_t i=0;i<ix;i++) cit++;
2092 std::istringstream *is;
2095 std::vector<std::string> onames, nnames;
2097 is=
new std::istringstream(line);
2098 while ((*is) >> cname) {
2099 onames.push_back(cname);
2101 std::cout <<
"Read possible column name: " << cname << std::endl;
2108 for(
size_t i=0;i<onames.size();i++) {
2114 if (n_nums==onames.size()) {
2117 std::cout <<
"First row looks like it contains numerical values."
2119 std::cout <<
"Creating generic column names: ";
2122 for(
size_t i=0;i<onames.size();i++) {
2123 nnames.push_back(((std::string)
"c")+
szttos(i+1));
2124 if (verbose>0) std::cout << nnames[i] <<
" ";
2127 if (verbose>0) std::cout << std::endl;
2130 for(
size_t i=0;i<nnames.size();i++) {
2135 for(
size_t i=0;i<onames.size();i++) {
2143 for(
size_t i=0;i<onames.size();i++) {
2144 std::string temps=onames[i];
2147 nnames.push_back(temps);
2148 if (temps!=onames[i] && verbose>0) {
2149 std::cout <<
"Converted column named '" << onames[i] <<
"' to '"
2150 << temps <<
"'." << std::endl;
2155 for(
size_t i=0;i<nnames.size();i++) {
2162 while ((fin) >> data) {
2183 O2SCL_ERR2(
"Size of table and list do not match in ",
2188 if (it->second.index!=
alist[it->second.index]->second.index) {
2189 O2SCL_ERR((((std::string)
"Problem with iterator for entry '")+
2190 it->first+
"' in list in table::check_synchro().").c_str(),
2194 for(
int i=0;i<((int)
atree.size());i++) {
2195 if (
alist[i]->second.index!=i) {
2196 O2SCL_ERR((((std::string)
"Problem with index of entry ")+
2197 itos(i)+
" in list in table::check_synchro().").c_str(),
2206 virtual const char *
type() {
return "table"; }
2240 std::vector<std::string> funcs, names;
2243 std::istringstream is(list);
2244 while(is >> stemp) funcs.push_back(stemp);
2245 for(
size_t i=0;i<(funcs.size());i++) {
2246 names.push_back(funcs[i].substr(0,funcs[i].find(
"=")));
2247 funcs[i]=funcs[i].substr(funcs[i].find(
"=")+1,
2248 funcs[i].length()-funcs[i].find(
"=")-1);
2249 if (names[i].length()==0 || funcs[i].length()==0) {
2263 bool one_success=
true;
2264 while(one_success==
true) {
2268 std::vector<fparser_column> newcols;
2285 for(
size_t i=0;i<(funcs.size());i++) {
2287 if (funcs[i].length()>0 && fp.Parse(funcs[i],vars)+1==0) {
2298 fp2->Parse(funcs[i],vars);
2302 newcols.push_back(m);
2314 for(
size_t i=0;i<
nlines;i++) {
2317 for(
size_t j=0;j<
atree.size();j++) {
2318 vals[j]=(*this)[j][i];
2322 for(
size_t j=0;j<(newcols.size());j++) {
2323 (*newcols[j].col)[i]=newcols[j].fpp->Eval(vals);
2325 (*newcols[j].col)[i]=0.0;
2326 }
else if (newcols[j].fpp->EvalError()!=0) {
2327 (*newcols[j].col)[i]=0.0;
2334 for(
size_t i=0;i<(newcols.size());i++) {
2335 delete newcols[i].fpp;
2345 std::string bad_function;
2346 bool all_empty=
true;
2347 for(
size_t i=0;i<funcs.size();i++) {
2348 if (funcs[i].length()>1) {
2349 bad_function=funcs[i];
2353 if (all_empty==
false) {
2354 O2SCL_ERR((((std::string)
"Column '")+bad_function+
2355 "' failed in table::functions_columns().").c_str(),
2379 vec_t &colp=it2->second.dat;
2381 double *vals=
new double[((int)
atree.size())];
2387 while(it!=
atree.end()) {
2395 ret=fp.Parse(
function,vlist)+1;
2397 std::string s=((std::string)
"Failed to parse function '")+
function+
2398 "'\n in table::function_column().\n Error '"+
itos(ret)+
2399 "' from FunctionParser: "+fp.ErrorMsg()+
".";
2405 for(j=0;j<((int)
nlines);j++) {
2406 for(i=0,it=
atree.begin();it!=
atree.end();it++,i++) {
2407 vals[i]=it->second.dat[j];
2409 double temp=fp.Eval(vals);
2410 colp[j]=fp.Eval(vals);
2413 }
else if (fp.EvalError()!=0) {
2426 template<
class vec2_t>
2428 bool throw_on_err=
true) {
2432 std::string vlist=it->first;
2434 while(it!=
atree.end()) {
2441 int ret=fp.Parse(
function,vlist)+1;
2444 std::string s=((std::string)
"Failed to parse function '")+
function+
2445 "' with variable list '"+vlist+
2446 "' in table::function_ubvector().\n Error '"+
itos(ret)+
2447 "' from FunctionParser: "+fp.ErrorMsg()+
".";
2459 double *vals=
new double[
atree.size()];
2462 for(
size_t j=0;j<
nlines;j++) {
2465 vals[i]=it->second.dat[j];
2468 vec[j]=fp.Eval(vals);
2469 if (fp.EvalError()!=0) {
2487 double *vals=
new double[((int)
atree.size())];
2499 while(it!=
atree.end()) {
2509 ret=fp.Parse(
function,vlist);
2512 std::string s=((std::string)
"Failed to parse function '")+
function+
2513 "'\n in table::row_function().\n Error '"+
itos(ret)+
2514 "' from FunctionParser: "+fp.ErrorMsg()+
".";
2519 for(i=0,it=
atree.begin();it!=
atree.end();it++,i++) {
2520 vals[i]=it->second.dat[row];
2522 double dret=fp.Eval(vals);
2523 if (fp.EvalError()!=0) {
2524 O2SCL_ERR((((std::string)
"Failed to evaluate in table::")+
2525 "row_function(). Error from FunctionParser: "+
2544 double *vals=
new double[((int)
atree.size())];
2556 while(it!=
atree.end()) {
2566 ret=fp.Parse(
function,vlist);
2569 std::string s=((std::string)
"Failed to parse function '")+
function+
2570 "'\n in table::row_function().\n Error '"+
itos(ret)+
2571 "' from FunctionParser: "+fp.ErrorMsg()+
".";
2576 double best_val=0.0;
2578 for(
size_t row=0;row<
nlines-1;row++) {
2579 for(i=0,it=
atree.begin();it!=
atree.end();it++,i++) {
2580 vals[i]=it->second.dat[row];
2582 double dtemp=fp.Eval(vals);
2583 if (fp.EvalError()!=0) {
2585 O2SCL_ERR((((std::string)
"Failed to evaluate in table::row_")+
2586 "function(). Error from FunctionParser: "+
2594 if (dtemp>best_val) {
2609 friend void o2scl_hdf::hdf_output
2615 friend void o2scl_hdf::hdf_output_data
2623 #ifndef DOXYGEN_INTERNAL
2639 std::map<std::string,double>::const_iterator mit;
2641 fp.AddConstant(mit->first,mit->second);
2660 alist[it->second.index]=it;
2669 if (s==
"abs" || s==
"acos" || s==
"acosh" || s==
"asin" ||
2670 s==
"asinh" || s==
"atan" || s==
"atan2" || s==
"atanh" ||
2671 s==
"ceil" || s==
"cos" || s==
"cosh" || s==
"cot" || s==
"csc" ||
2672 s==
"eval" || s==
"exp" || s==
"floor" || s==
"if" || s==
"int" ||
2673 s==
"log" || s==
"log10" || s==
"max" || s==
"min" || s==
"sec" ||
2674 s==
"sin" || s==
"sinh" || s==
"sqrt" || s==
"tan" || s==
"tanh") {
2675 s=((std::string)
"v_")+s;
2676 }
else if (s[0]>=
'0' && s[0]<=
'9') {
2677 s=((std::string)
"v_")+s;
2680 for(
size_t i=0;i<s.length();i++) {
2681 if (!isalpha(s[i]) && !isdigit(s[i]) && s[i]!=
'_') s[i]=
'_';
2693 for(
size_t i=0;i<cnames.size();i++) {
2694 if (colx==cnames[i]) {
2702 }
while (done==
false);
2723 typedef typename std::map<std::string,col,string_comp>::iterator
aiter;
2725 typedef typename std::map<std::string,col,string_comp>::const_iterator
2728 typedef typename std::vector<aiter>::iterator
aviter;
2738 std::map<std::string,col,string_comp>
atree;
2748 if (it==
atree.end()) {
2749 O2SCL_ERR((((std::string)
"Column '")+lname+
2750 " not found in table::get_iterator().").c_str(),
2758 if (it==
atree.end()) {
2759 O2SCL_ERR((((std::string)
"Column '")+lname+
2760 " not found in table::get_col_struct().").c_str(),
2764 return &(it->second);
2797 #ifndef DOXYGEN_NO_O2NS
void delete_rows(size_t row_start, size_t row_end)
Delete all rows between row_start and row_end .
virtual void delete_column(std::string scol)
Delete column named scol .
size_t nlines
The size of presently used memory.
aiter begin()
Return the beginning of the column tree.
void deriv(std::string x, std::string y, std::string yp)
Make a new column yp which is the derivative . .
Parse a mathematical function specified in a string.
void clear_table()
Clear the table and the column names (but leave constants)
std::map< std::string, col, string_comp >::iterator aiter
Map iterator type.
double integ_const(size_t ix, double x1, double x2, size_t iy) const
The integral of the function iy(ix) from ix=x1 to ix=x2.
void copy_to_column(vec2_t &v, std::string scol)
Copy to a column from a generic vector object.
virtual size_t get_nconsts() const
Get the number of constants.
double deriv_const(size_t ix, double x0, size_t iy) const
The first derivative of the function iy(ix) at ix=x0.
std::string intp_coly
The last y-column interpolated.
void set_fp_consts(FunctionParser &fp) const
Internal function to set function parser constants equal to internal constants.
double integ(size_t ix, double x1, double x2, size_t iy)
The integral of the function iy(ix) from ix=x1 to ix=x2.
interp_vec< vec_t > * si
Interpolation object.
void clear_all()
Clear everything.
double interp_const(std::string sx, double x0, std::string sy) const
Interpolate x0 from sx into sy.
double deriv(std::string sx, double x0, std::string sy)
The first derivative of the function sy(sx) at sx=x0.
virtual double integ(const double x1, const double x2) const
Give the value of the integral .
void hdf_input_data(hdf_file &hf, o2scl::table< vec_t > &t)
Internal function for inputting a o2scl::table object.
void zero_table()
Zero the data entries but keep the column names and nlines fixed.
void set_nlines(size_t il)
Set the number of lines.
void functions_columns(std::string list)
Create new columns or recompute from a list of functions.
void new_row(size_t n)
Insert a row before row n.
size_t get_nlines() const
Return the number of lines.
double max(std::string scol) const
Return column maximum. Makes no assumptions about ordering .
vec_t * col
Array of columns.
sanity check failed - shouldn't happen
aiter get_iterator(std::string lname)
Return the iterator for a column.
bool is_finite(double x)
Return false if x is infinite or not a number.
virtual double deriv2(const double x0) const
Give the value of the second derivative .
invalid argument supplied by user
void deriv2(std::string x, std::string y, std::string yp)
Make a new column yp which is - O(log(C)*R).
virtual int set_constant(std::string name, double val, bool err_on_notfound=true)
Add a constant.
void set_nlines_auto(size_t il)
Set the number of lines, increasing the size more agressively.
double deriv(size_t ix, double x0, size_t iy)
The first derivative of the function iy(ix) at ix=x0.
std::string intp_colx
The last x-column interpolated.
size_t mlookup(std::string scol, double val, std::vector< size_t > &results, double threshold=0.0) const
Exhaustively search column col for many occurences of val .
virtual void remove_constant(std::string name)
Remove a constant.
A class for representing permutations.
void get_row(size_t irow, vec2_t &row) const
Returns a copy of row number irow. .
void make_fp_varname(std::string &s)
Ensure a variable name does not match a function or contain non-alphanumeric characters.
int new_column(std::string name, size_t sz, vec2_t &v)
Add a new column by copying data from another vector.
bool is_column(std::string scol) const
Return true if scol is a column in the current table table .
const vec_t & get_column(std::string scol) const
Returns a reference to the column named col. .
table & operator=(const table &t)
Copy constructor.
double row_function(std::string function, size_t row) const
Compute a value by applying a function to a row.
Generic "not found" result.
size_t ordered_lookup(std::string scol, double val) const
Look for a value in an ordered column .
vec_t empty_col
An empty vector for get_column()
void check_synchro() const
Return 0 if the tree and list are properly synchronized.
std::vector< aiter > alist
The list of tree iterators.
const vec_t & operator[](std::string scol) const
Returns the column named scol (const version). .
FunctionParser * fpp
Array of function parser objects.
double integ(std::string sx, double x1, double x2, std::string sy)
The integral of the function sy(sx) from sx=x1 to sx=x2.
size_t get_interp_type() const
Get the interpolation type.
virtual double get_constant(std::string name) const
Get a constant.
std::string get_column_name(size_t icol) const
Returns the name of column col .
void clear_data()
Remove all of the data by setting the number of lines to zero.
void reset_list()
Set the elements of alist with the appropriate iterators from atree. .
std::map< std::string, double > constants
The list of constants.
virtual void summary(std::ostream *out, size_t ncol=79) const
Output a summary of the information stored.
void vector_sort_index(size_t n, const vec_t &data, vec_size_t &order)
Create a permutation which sorts a vector (in increasing order)
size_t get_maxlines()
Return the maximum number of lines before a reallocation is required.
Cubic spline for natural boundary conditions.
double interp(std::string sx, double x0, std::string sy)
Interpolate x0 from sx into sy.
void column_to_vector(std::string scol, resize_vec_t &v) const
Copy a column to a generic vector object.
virtual void get_constant(size_t ix, std::string &name, double &val) const
Get a constant by index.
void function_vector(std::string function, vec2_t &vec, bool throw_on_err=true)
Compute a column from a function specified in a string.
size_t maxlines
The size of allocated memory.
void sort_column(std::string scol)
Individually sort the column scol.
void line_of_names(std::string newheads)
Read a new set of names from newheads.
void init_column(std::string scol, double val)
Initialize all values of column named scol to val .
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
double deriv2_const(size_t ix, double x0, size_t iy) const
The second derivative of the function iy(ix) at ix=x0.
size_t lookup(std::string scol, double val) const
Exhaustively search column col for the value val .
Column structure for table [protected].
std::string dtos(double x, int prec=6, bool auto_prec=false)
Convert a double to a string.
double deriv2(std::string sx, double x0, std::string sy)
The second derivative of the function sy(sx) at sx=x0.
table< vec_t > * subtable(std::string list, size_t top, size_t bottom) const
Make a subtable.
virtual void copy_column(std::string src, std::string dest)
Copy data from column named src to column named dest, creating a new column if necessary ...
col * get_col_struct(std::string lname)
Return the column structure for a column.
double interp(size_t ix, double x0, size_t iy)
Interpolate x0 from ix into iy .
table(const table &t)
Copy constructor.
virtual const char * type()
Return the type, "table".
void screenify(size_t nin, const string_arr_t &in_cols, std::vector< std::string > &out_cols, size_t max_size=80)
Reformat the columns for output of width size.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
void make_unique_name(std::string &colx, std::vector< std::string > &cnames)
Make sure a name is unique.
void line_of_data(size_t nv, const vec2_t &v)
Read a line of data from an array.
double deriv_const(std::string sx, double x0, std::string sy) const
The first derivative of the function sy(sx) at sx=x0.
void copy_row(size_t src, size_t dest)
Copy the data in row src to row dest.
virtual void add_constant(std::string name, double val)
Add a constant, or if the constant already exists, change its value.
void delete_row(std::string scol, double val)
Delete the row with the entry closest to the value val in column scol .
void set_interp_type(size_t interp_type)
Set the base interpolation objects.
struct o2scl::table::fparser_column_struct fparser_column
Structure for functions_columns() [protected].
double deriv2_const(std::string sx, double x0, std::string sy) const
The second derivative of the function sy(sx) at sx=x0.
bool is_number(std::string s)
Return true if the string s is likely a integral or floating point number.
size_t lookup(int icol, double val) const
Exhaustively search column col for the value val .
double deriv2(size_t ix, double x0, size_t iy)
The second derivative of the function iy(ix) at ix=x0.
std::string get_sorted_name(size_t icol) const
Returns the name of column col in sorted order. .
double lookup_val(std::string scol, double val, std::string scol2) const
Search column col for the value val and return value in col2.
void delete_rows(std::string func)
Delete all rows where func evaluates to a number greater than 0.5 .
void delete_row(size_t irow)
Delete the row of index irow .
size_t get_ncolumns() const
Return the number of columns.
void new_column(std::string head)
Add a new column owned by the table table .
const vec_t & operator[](size_t icol) const
Returns the column of index icol (const version). .
aiter end()
Return the end of the column tree.
double integ_const(std::string sx, double x1, double x2, std::string sy) const
The integral of the function sy(sx) from sx=x1 to sx=x2.
void function_column(std::string function, std::string scol)
Make a column from the function specified in function and add it to the table.
void integ(std::string x, std::string y, std::string ynew)
The integral of the function iy(ix)
virtual double deriv(const double x0) const
Give the value of the derivative .
Searching class for monotonic data with caching.
Structure for functions_columns() [protected].
Store data in an O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl...
void set(std::string scol, size_t row, double val)
Set row row of column named col to value val . .
table(size_t cmaxlines=0)
Create a new table with space for nlines<=cmaxlines.
size_t function_find_row(std::string function) const
Compute a value by applying a function to a row.
void get_row(std::string scol, double val, vec2_t &row) const
Returns a copy of the row with value val in column col. .
bool intp_set
True if the interpolation object is up-to-date.
size_t lookup_column(std::string lname) const
Find the index for column named name .
virtual double eval(const double x0) const
Give the value of the function .
std::map< std::string, col, string_comp > atree
The tree of columns.
Invalid index for array or matrix.
size_t itype
Current interpolation type.
std::map< std::string, col, string_comp >::const_iterator aciter
Const map iterator type.
double stod(std::string s, bool err_on_fail=true)
Convert a string to a double.
virtual int read_generic(std::istream &fin, int verbose=0)
Clear the current table and read from a generic data file.
void add_col_from_table(table< vec2_t > &source, std::string src_index, std::string src_col, std::string dest_index, std::string dest_col="")
Insert a column from a separate table, interpolating it into a new column.
std::string itos(int x)
Convert an integer to a string.
static const double x2[5]
static const double x1[5]
double min(std::string scol) const
Return column minimum. Makes no assumptions about ordering .
std::string szttos(size_t x)
Convert a size_t to a string.
void hdf_input(hdf_file &hf, o2scl::table< vec_t > &t, std::string name)
Input a o2scl::table object from a hdf_file.
vec_t dat
Pointer to column.
std::vector< aiter >::iterator aviter
Vector iterator type.
void clear_constants()
CLear all constants.
void vector_sort_double(size_t n, vec_t &data)
Sort a vector of doubles (in increasing order)
void set(size_t icol, size_t row, double val)
Set row row of column number icol to value val . .
void inc_maxlines(size_t llines)
Manually increase the maximum number of lines.
virtual void swap_column_data(std::string scol, vec_t &v)
Swap the data in column scol with that in vector v.
size_t ordered_lookup(const double x0) const
Find the index of x0 in the ordered array x.
void sort_table(std::string scol)
Sort the entire table by the column scol.
double interp_const(size_t ix, double x0, size_t iy) const
Interpolate x0 from ix into iy .
virtual void rename_column(std::string src, std::string dest)
Rename column named src to dest .