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 #include <o2scl/shunting_yard.h> 45 #ifndef DOXYGEN_NO_O2NS 49 template<
class vec_t>
class table;
68 #ifndef DOXYGEN_NO_O2NS 182 template<
class vec_t=std::vector<
double> >
class table {
200 if (intp_set==
true) {
209 constants=t.constants;
215 nlines=t.get_nlines();
218 for(
size_t i=0;i<t.get_ncolumns();i++) {
221 std::string cname=t.get_column_name(i);
225 s.
dat.resize(nlines);
226 s.
index=atree.size();
227 atree.insert(make_pair(cname,s));
230 aiter it=atree.find(cname);
234 for(
size_t j=0;j<t.get_nlines();j++) {
235 it->second.dat[j]=t.get(cname,j);
255 constants=t.constants;
258 nlines=t.get_nlines();
264 for(
size_t i=0;i<t.get_ncolumns();i++) {
267 std::string cname=t.get_column_name(i);
271 s.
dat.resize(nlines);
272 s.
index=atree.size();
273 atree.insert(make_pair(cname,s));
276 aiter it=atree.find(cname);
280 for(
size_t j=0;j<t.get_nlines();j++) {
281 it->second.dat[j]=t.get(cname,j);
308 void set(std::string scol,
size_t row,
double val) {
312 " beyond end of table (nlines="+
o2scl::szttos(nlines)+
") in "+
313 "table::set(string,size_t,double).";
318 aiter it=atree.find(scol);
319 if (it==atree.end()) {
320 O2SCL_ERR((((std::string)
"Column '")+scol+
321 "' not found in table::set(string,size_t,double).").c_str(),
326 if ((intp_colx==scol || intp_coly==scol) && intp_set==
true) {
331 #if !O2SCL_NO_RANGE_CHECK 332 if (row>=it->second.dat.size()) {
333 O2SCL_ERR(
"Vector size failure in table::set(string,size_t,double).",
337 it->second.dat[row]=val;
345 void set(
size_t icol,
size_t row,
double val) {
348 O2SCL_ERR2(
"Specified row beyond end of table in ",
349 "table::set(size_t,size_t,double).",
exc_einval);
353 if (icol>=atree.size()) {
354 std::string err=((std::string)
"Column index ")+
szttos(icol)+
355 ">="+
szttos(atree.size())+
", in table::set(size_t,size_t,double).";
359 std::string scol=get_column_name(icol);
360 if ((intp_colx==scol || intp_coly==scol) && intp_set==
true) {
365 #if !O2SCL_NO_RANGE_CHECK 366 if (row>=alist[icol]->second.dat.size()) {
367 O2SCL_ERR(
"Vector size failure in table::set(size_t,size_t,double).",
371 alist[icol]->second.dat[row]=val;
384 template<
class size_vec_t>
void set_row(
size_t row, size_vec_t &v) {
385 if (row>=get_nlines()) {
386 std::string err=((std::string)
"Row out of range, ")+
387 szttos(row)+
">="+
szttos(get_nlines())+
", in table::set_row().";
390 for(
size_t i=0;i<get_ncolumns() && i<v.size();i++) {
391 alist[i]->second.dat[row]=v[i];
399 double get(std::string scol,
size_t row)
const {
401 aciter it=atree.find(scol);
402 if (it==atree.end()) {
403 O2SCL_ERR((((std::string)
"Column '")+scol+
404 "' not found in table::get(string,size_t).").c_str(),
409 std::string err=((std::string)
"Row out of range, ")+
410 szttos(row)+
">="+
szttos(nlines)+
", in table::get(string,size_t).";
413 #if !O2SCL_NO_RANGE_CHECK 414 if (row>=it->second.dat.size()) {
415 O2SCL_ERR(
"Vector size failure in table::get().",
419 tmp=it->second.dat[row];
427 double get(
size_t icol,
size_t row)
const {
428 if (icol>=atree.size()) {
429 std::string err=((std::string)
"Column out of range, ")+
430 szttos(icol)+
">="+
szttos(atree.size())+
", in table::get(size_t,size_t).";
434 std::string err=((std::string)
"Row out of range, ")+
435 szttos(row)+
">="+
szttos(nlines)+
", in table::get(size_t,size_t).";
438 return alist[icol]->second.dat[row];
465 inc_maxlines(il-maxlines);
498 template<
class resize_vec_t>
499 void get_row(std::string scol,
double val, resize_vec_t &row)
const {
501 int irow=lookup(scol,val);
503 O2SCL_ERR((((std::string)
"Column '")+scol+
"' not found in "+
504 "table::get_row(string,double,vec_t) const.").c_str(),
524 template<
class resize_vec_t>
525 void get_row(
size_t irow, resize_vec_t &row)
const {
529 "' not found in table::get_row(size_t,vec_t).").c_str(),
536 row.resize(atree.size());
537 for(i=0,it=atree.begin();it!=atree.end();it++,i++) {
538 row[i]=(it->second.dat)[irow];
557 size_t inc=il-maxlines;
558 if (inc<maxlines) inc=maxlines;
583 for(
aiter it=atree.begin();it!=atree.end();it++) {
586 temp_col.resize(maxlines+llines);
587 for(
size_t j=0;j<maxlines;j++) {
588 temp_col[j]=it->second.dat[j];
592 it->second.dat.resize(maxlines+llines);
595 for(
size_t j=0;j<maxlines;j++) {
596 it->second.dat[j]=temp_col[j];
614 if (llines==maxlines)
return;
616 O2SCL_ERR2(
"Cannot set maximum number of lines to be smaller ",
617 "than current size in table::set_maxlines().",
627 for(
aiter it=atree.begin();it!=atree.end();it++) {
630 temp_col.resize(llines);
631 for(
size_t j=0;j<nlines;j++) {
632 temp_col[j]=it->second.dat[j];
636 it->second.dat.resize(llines);
639 for(
size_t j=0;j<nlines;j++) {
640 it->second.dat[j]=temp_col[j];
658 aciter it=atree.find(scol);
659 if (it==atree.end()) {
660 O2SCL_ERR((((std::string)
"Column '")+scol+
661 "' not found in table::get_column() const.").c_str(),
665 return it->second.dat;
682 const vec_t &operator[] (
size_t icol)
const {
683 #if !O2SCL_NO_RANGE_CHECK 684 if (icol>=atree.size()) {
687 " in table::operator[size_t] const. Size: "+
689 " (index should be less than size).").c_str(),
exc_eindex);
693 return (alist[icol]->second.dat);
711 aciter it=atree.find(scol);
712 #if !O2SCL_NO_RANGE_CHECK 713 if (it==atree.end()) {
714 O2SCL_ERR((((std::string)
"Column '")+scol+
"' not found in table::"+
719 return (it->second.dat);
729 if (head.length()==0) {
730 O2SCL_ERR2(
"Cannot add column with empty name in ",
733 if (is_column(head)==
true) {
734 O2SCL_ERR((((std::string)
"Column '")+head+
735 "' already present in table::new_column().").c_str(),
738 for(
int i=0;i<((int)head.size());i++) {
739 if (head[i]==
' ' || head[i]==
'\t' || head[i]==
'\n' || head[i]==
'\r' 740 || head[i]==
'\v' || head[i]==
'\f') {
741 O2SCL_ERR((((std::string)
"Invalid column name '")+head+
742 "' in table::new_column().").c_str(),
747 s.
dat.resize(maxlines);
748 s.
index=((int)atree.size());
749 atree.insert(make_pair(head,s));
750 aiter it=atree.find(head);
769 size_t sz, vec2_t &v) {
773 "table::new_column(string,size_t,vec2_t)",
778 int ret=new_column(name);
779 if (ret!=0)
return ret;
783 if (sz>get_nlines()) mxl=get_nlines();
784 for(
size_t i=0;i<mxl;i++) {
797 if (icol+1>atree.size()) {
799 " larger than number of "+
800 "columns in table::get_column_name().").c_str(),
803 return alist[icol]->first;
816 aiter its=atree.find(scol);
817 if (its==atree.end()) {
818 O2SCL_ERR((((std::string)
"Column '")+scol+
819 " not found in table::swap_column_data().").c_str(),
823 if (v.size()!=its->second.dat.size()) {
824 O2SCL_ERR2(
"Vector sizes not commensurate in ",
827 std::swap(its->second.dat,v);
835 aiter its=atree.find(src);
836 if (its==atree.end()) {
837 O2SCL_ERR((((std::string)
"Column '")+src+
838 " not found in table::rename_column().").c_str(),
843 aiter itd=atree.find(dest);
844 std::swap(its->second.dat,itd->second.dat);
857 aiter it=atree.find(scol);
858 if (it==atree.end()) {
859 O2SCL_ERR((((std::string)
"Column '")+scol+
860 " not found in table::delete_column().").c_str(),
867 vit+=it->second.index;
872 alist[alist.size()-1]->second.index=it->second.index;
881 if ((intp_colx==scol || intp_coly==scol) && intp_set==
true) {
893 if (icol+1>atree.size()) {
897 for(
size_t i=0;i<icol;i++) it++;
917 aiter it=atree.find(scol);
918 if (it==atree.end()) {
919 O2SCL_ERR((((std::string)
"Column '")+scol+
920 "' not found in table::init_column()").c_str(),
924 for(
size_t i=0;i<nlines;i++) {
925 it->second.dat[i]=val;
927 if (intp_set && (scol==intp_colx || scol==intp_coly)) {
940 aciter it=atree.find(scol);
941 if (it==atree.end())
return false;
952 aciter it=atree.find(lname);
953 if (it==atree.end()) {
954 O2SCL_ERR(
"Column not found in table::lookup_column().",
957 return it->second.index;
965 if (!is_column(dest)) new_column(dest);
966 aiter its=atree.find(src);
967 if (its==atree.end()) {
968 O2SCL_ERR((((std::string)
"Column '")+src+
969 " not found in table::copy_column().").c_str(),
973 aiter itd=atree.find(dest);
974 if (itd==atree.end()) {
975 O2SCL_ERR((((std::string)
"Destination column '")+dest+
976 " not found in table::copy_column().").c_str(),
980 for(
size_t i=0;i<nlines;i++) {
981 itd->second.dat[i]=its->second.dat[i];
991 template<
class resize_vec_t>
994 for(
size_t i=0;i<nlines;i++) {
995 v[i]=this->
get(scol,i);
1005 template<
class vec2_t>
1007 for(
size_t i=0;i<nlines;i++) {
1008 this->
set(scol,i,v[i]);
1023 template<
class vec2_t>
1025 std::string src_index, std::string src_col,
1026 std::string dest_index, std::string dest_col=
"") {
1028 if (dest_col==
"") dest_col=src_col;
1031 if (!is_column(dest_col)) new_column(dest_col);
1034 for(
size_t i=0;i<nlines;i++) {
1035 set(dest_col,i,source.interp(src_index,
get(dest_index,i),src_col));
1045 template<
class vec2_t>
1047 bool allow_extrap=
true, std::string dest_index=
"") {
1049 if (dest_index==
"") dest_index=src_index;
1052 double min=source.min(src_index);
1053 double max=source.max(src_index);
1054 if (allow_extrap==
false) {
1055 if (!std::isfinite(min) || !std::isfinite(max)) {
1056 O2SCL_ERR2(
"Minimum or maximum of source index not finite ",
1062 std::vector<std::string> col_list;
1063 for(
size_t i=0;i<source.get_ncolumns();i++) {
1064 std::string col_name=source.get_column_name(i);
1065 if (col_name!=src_index && col_name!=dest_index &&
1066 is_column(col_name)==
false) {
1067 col_list.push_back(col_name);
1072 for(
size_t i=0;i<col_list.size();i++) {
1073 new_column(col_list[i]);
1074 for(
size_t j=0;j<get_nlines();j++) {
1075 double val=
get(dest_index,j);
1076 if (allow_extrap || (val>=min && val<=max)) {
1077 set(col_list[i],j,source.interp(src_index,val,col_list[i]));
1097 if (nlines>=maxlines) inc_maxlines(maxlines);
1100 for(
int i=((
int)nlines)-2;i>=((int)n);i--) {
1120 for(
int i=0;i<((int)atree.size());i++) {
1121 set(i,dest,
get(i,src));
1136 size_t irow=lookup(scol,val);
1149 std::string str=((std::string)
"Cannot delete row ")+
1152 "table::delete_row(size_t).";
1155 for(
aiter it=atree.begin();it!=atree.end();it++) {
1157 for(
int i=((
int)irow);i<((int)nlines)-1;i++) {
1158 it->second.dat[i]=it->second.dat[i+1];
1162 if (intp_set==
true) {
1176 size_t new_nlines=0;
1177 for(
size_t i=0;i<nlines;i++) {
1178 double val=row_function(func,i);
1184 if (i!=new_nlines) {
1185 for(
aiter it=atree.begin();it!=atree.end();it++) {
1186 it->second.dat[new_nlines]=it->second.dat[i];
1193 if (intp_set==
true) {
1209 template<
class vec2_t>
1213 for(
size_t i=0;i<get_ncolumns();i++) {
1214 std::string cname=get_column_name(i);
1215 if (dest.is_column(cname)==
false) {
1216 dest.new_column(cname);
1220 size_t new_lines=dest.get_nlines();
1221 for(
size_t i=0;i<nlines;i++) {
1222 double val=row_function(func,i);
1224 dest.set_nlines_auto(new_lines+1);
1225 for(
size_t j=0;j<get_ncolumns();j++) {
1226 std::string cname=get_column_name(j);
1227 dest.set(cname,new_lines);
1252 if (row_start>=nlines || row_end>=nlines) {
1253 O2SCL_ERR2(
"Row specifications beyond end of table in ",
1254 "table::delete_rows_ends(size_t,size_t).",
exc_einval);
1256 size_t new_nlines=0;
1257 for(
size_t i=0;i<nlines;i++) {
1258 if ((row_start<=row_end && (i<row_start || i>row_end)) ||
1259 (row_start>row_end && (i<row_start && i>row_end))) {
1260 for(
aiter it=atree.begin();it!=atree.end();it++) {
1261 it->second.dat[new_nlines]=it->second.dat[i];
1267 if (intp_set==
true) {
1283 template<
class vec_
size_t>
1287 for(
size_t j=0;j<row_list.size();j++) {
1288 if (row_list[j]>nlines) {
1289 O2SCL_ERR(
"Invalid row in table<>::delete_rows_list(vec_size_t &)",
1296 size_t new_nlines=0;
1297 for(
size_t i=0;i<nlines;i++) {
1299 for(
size_t j=0;j<row_list.size();j++) {
1300 if (row_list[j]==i) found=
true;
1303 for(
aiter it=atree.begin();it!=atree.end();it++) {
1304 it->second.dat[new_nlines]=it->second.dat[i];
1312 if (intp_set==
true) {
1326 double tol_abs=1.0e-20,
1328 std::vector<size_t> list;
1329 for(
size_t i=0;i<nlines;i++) {
1330 for(
size_t j=i+1;j<nlines;j++) {
1332 if (i<nlines && j<nlines && j>i) {
1333 for(
aiter it=atree.begin();it!=atree.end() && match==
true;it++) {
1334 if (fabs(it->second.dat[i])>tol_abs ||
1335 fabs(it->second.dat[j])>tol_abs) {
1336 if (fabs(it->second.dat[i]-it->second.dat[j])/
1337 fabs(it->second.dat[i]+it->second.dat[j])>tol_rel) {
1346 std::cout <<
"Match between rows " << i <<
" and " << j
1349 for(
size_t k=0;k<get_ncolumns();k++) {
1350 std::cout << k <<
" " <<
get(k,i) <<
" " <<
get(k,j)
1358 if (list.size()>0) {
1359 delete_rows_list(list);
1360 }
else if (verbose>0) {
1361 std::cout <<
"No matches found." << std::endl;
1375 std::vector<size_t> row_list;
1376 for(
size_t i=0;i<nlines-1;i++) {
1378 for(
aiter it=atree.begin();it!=atree.end() && match==
true;it++) {
1379 if (it->second.dat[i+1]!=it->second.dat[i]) match=
false;
1381 if (match) row_list.push_back(i+1);
1384 delete_rows_list(row_list);
1407 std::istringstream is(newheads);
1413 O2SCL_ERR2(
"At least one new column failed in ",
1434 if (maxlines==0) inc_maxlines(1);
1435 if (nlines>=maxlines) inc_maxlines(maxlines);
1442 if (nlines<maxlines && nv<=(atree.size())) {
1444 set_nlines_auto(nlines+1);
1445 for(
size_t i=0;i<nv;i++) {
1446 (*this).set(i,nlines-1,v[i]);
1466 line_of_data(v.size(),v);
1485 if (!std::isfinite(val)) {
1487 "' not finite for column '"+
1488 scol+
"' in table::ordered_lookup()").c_str(),
exc_einval);
1491 aciter it=atree.find(scol);
1492 if (it==atree.end()) {
1493 O2SCL_ERR((((std::string)
"Column '")+scol+
1494 " not found in table::ordered_lookup().").c_str(),
1507 size_t lookup(std::string scol,
double val)
const {
1508 if (!std::isfinite(val)) {
1510 "' not finite for column '"+
1511 scol+
"' in table::lookup()").c_str(),
exc_einval);
1514 aciter it=atree.find(scol);
1515 if (it==atree.end()) {
1516 O2SCL_ERR((((std::string)
"Column '")+scol+
" not found in "+
1525 const vec_t &ov=it->second.dat;
1529 while(!std::isfinite(ov[i]) && i<nlines-1) i++;
1537 double bdiff=fabs(ov[i]-val);
1538 for(;i<nlines;i++) {
1539 if (std::isfinite(ov[i]) && fabs(ov[i]-val)<bdiff) {
1541 bdiff=fabs(ov[i]-val);
1549 double lookup_val(std::string scol,
double val, std::string scol2)
const {
1551 if (!std::isfinite(val)) {
1553 "' not finite for column '"+
1554 scol+
"' in table::lookup_val()").c_str(),
exc_einval);
1557 aciter it=atree.find(scol);
1558 if (it==atree.end()) {
1559 O2SCL_ERR((((std::string)
"Column '")+scol+
" not found in "+
1563 return get(scol2,it->second.dat->lookup(val));
1570 return lookup(get_column_name(icol),val);
1576 size_t mlookup(std::string scol,
double val, std::vector<size_t> &results,
1577 double threshold=0.0)
const {
1579 if (!std::isfinite(val)) {
1581 "' not finite for column '"+
1582 scol+
"' in table::mlookup()").c_str(),
exc_einval);
1585 aciter it=atree.find(scol);
1586 if (it==atree.end()) {
1587 O2SCL_ERR((((std::string)
"Column '")+scol+
" not found in "+
1591 if (threshold==0.0) {
1592 for(i=0;i<nlines;i++) {
1593 if (it->second.dat[i]==val) {
1594 results.push_back(i);
1598 for(i=0;i<nlines;i++) {
1599 if (fabs(it->second.dat[i]-val)<threshold) {
1600 results.push_back(i);
1604 return results.size();
1635 double interp(std::string sx,
double x0, std::string sy) {
1637 aiter itx=atree.find(sx), ity=atree.find(sy);
1638 if (itx==atree.end() || ity==atree.end()) {
1639 O2SCL_ERR((((std::string)
"Columns '")+sx+
"' or '"+sy+
1640 "' not found in table::interp().").c_str(),
1644 if (!std::isfinite(x0)) {
1648 if (intp_set==
false || sx!=intp_colx || sy!=intp_coly) {
1649 if (intp_set==
true) {
1655 ity->second.dat,itype);
1672 aciter itx=atree.find(sx), ity=atree.find(sy);
1673 if (itx==atree.end() || ity==atree.end()) {
1674 O2SCL_ERR((((std::string)
"Columns '")+sx+
"' or '"+sy+
1675 "' not found in table::interp_const().").c_str(),
1679 if (!std::isfinite(x0)) {
1693 double interp(
size_t ix,
double x0,
size_t iy) {
1694 return interp(get_column_name(ix),x0,get_column_name(iy));
1701 return interp_const(get_column_name(ix),x0,get_column_name(iy));
1708 void deriv(std::string x, std::string y, std::string yp) {
1709 aiter itx, ity, ityp;
1714 ityp=atree.find(yp);
1716 if (itx==atree.end() || ity==atree.end() || ityp==atree.end()) {
1717 O2SCL_ERR(
"Column not found in table::deriv(string,string,string).",
1722 size_t ix=lookup_column(x);
1723 size_t iy=lookup_column(y);
1724 for(
int i=0;i<((int)nlines);i++) {
1725 ityp->second.dat[i]=deriv(ix,(itx->second.dat)[i],iy);
1738 double deriv(std::string sx,
double x0, std::string sy) {
1740 aiter itx=atree.find(sx), ity=atree.find(sy);
1741 if (itx==atree.end() || ity==atree.end()) {
1742 O2SCL_ERR((((std::string)
"Columns '")+sx+
"' or '"+sy+
1743 "' not found in table::deriv(string,double,string).").c_str(),
1747 if (!std::isfinite(x0)) {
1748 O2SCL_ERR(
"x0 not finite in table::deriv(string,double,string).",
1752 if (intp_set==
false || sx!=intp_colx || sy!=intp_coly) {
1753 if (intp_set==
true) {
1759 (nlines,itx->second.dat,ity->second.dat,itype);
1777 aciter itx=atree.find(sx), ity=atree.find(sy);
1778 if (itx==atree.end() || ity==atree.end()) {
1779 O2SCL_ERR((((std::string)
"Columns '")+sx+
"' or '"+sy+
1780 "' not found in table::deriv_const().").c_str(),
1784 if (!std::isfinite(x0)) {
1789 (nlines,itx->second.dat,ity->second.dat,itype);
1801 double deriv(
size_t ix,
double x0,
size_t iy) {
1802 return deriv(get_column_name(ix),x0,get_column_name(iy));
1813 return deriv_const(get_column_name(ix),x0,get_column_name(iy));
1822 void deriv2(std::string x, std::string y, std::string yp) {
1823 aiter itx, ity, ityp;
1828 ityp=atree.find(yp);
1830 if (itx==atree.end() || ity==atree.end() || ityp==atree.end()) {
1831 O2SCL_ERR(
"Column not found in table::deriv2(string,string,string).",
1836 size_t ix=lookup_column(x);
1837 size_t iy=lookup_column(y);
1838 for(
int i=0;i<((int)nlines);i++) {
1839 ityp->second.dat[i]=deriv2(ix,itx->second.dat[i],iy);
1852 double deriv2(std::string sx,
double x0, std::string sy) {
1854 aiter itx=atree.find(sx), ity=atree.find(sy);
1855 if (itx==atree.end() || ity==atree.end()) {
1856 O2SCL_ERR((((std::string)
"Columns '")+sx+
"' or '"+sy+
1857 "' not found in table::deriv2(string,double,string).").c_str(),
1861 if (!std::isfinite(x0)) {
1862 O2SCL_ERR(
"x0 not finite in table::deriv2(string,double,string).",
1866 if (intp_set==
false || sx!=intp_colx || sy!=intp_coly) {
1867 if (intp_set==
true) {
1873 (nlines,itx->second.dat,ity->second.dat,itype);
1891 aciter itx=atree.find(sx), ity=atree.find(sy);
1892 if (itx==atree.end() || ity==atree.end()) {
1893 O2SCL_ERR((((std::string)
"Columns '")+sx+
"' or '"+sy+
1894 "' not found in table::deriv2_const().").c_str(),
1898 if (!std::isfinite(x0)) {
1903 (nlines,itx->second.dat,ity->second.dat,itype);
1915 double deriv2(
size_t ix,
double x0,
size_t iy) {
1916 return deriv2(get_column_name(ix),x0,get_column_name(iy));
1927 return deriv2_const(get_column_name(ix),x0,get_column_name(iy));
1937 double integ(std::string sx,
double x1,
double x2, std::string sy) {
1939 aiter itx=atree.find(sx), ity=atree.find(sy);
1940 if (itx==atree.end() || ity==atree.end()) {
1941 O2SCL_ERR((((std::string)
"Columns '")+sx+
"' or '"+sy+
1942 "' not found in table::integ"+
1943 "(string,double,double,string).").c_str(),
1947 if (!std::isfinite(x1) || !std::isfinite(x2)) {
1948 std::string msg=((std::string)
"Value x1=")+
dtos(x1)+
" or x2="+
1949 dtos(x2)+
" not finite in table.integ(string,double,double,string).";
1952 if (intp_set==
false || sx!=intp_colx || sy!=intp_coly) {
1953 if (intp_set==
true) {
1959 (nlines,itx->second.dat,ity->second.dat,itype);
1964 ret=si->
integ(x1,x2);
1977 std::string sy)
const {
1979 aciter itx=atree.find(sx), ity=atree.find(sy);
1980 if (itx==atree.end() || ity==atree.end()) {
1981 O2SCL_ERR((((std::string)
"Columns '")+sx+
"' or '"+sy+
1982 "' not found in table::integ_const().").c_str(),
1986 if (!std::isfinite(x1) || !std::isfinite(x2)) {
1991 (nlines,itx->second.dat,ity->second.dat,itype);
1992 ret=sic.
integ(x1,x2);
2004 return integ(get_column_name(ix),x1,x2,
2005 get_column_name(iy));
2017 return integ_const(get_column_name(ix),x1,x2,
2018 get_column_name(iy));
2029 void integ(std::string x, std::string y, std::string ynew) {
2030 aiter itx, ity, itynew;
2035 itynew=atree.find(ynew);
2037 if (itx==atree.end() || ity==atree.end() || itynew==atree.end()) {
2038 O2SCL_ERR(
"Column not found in table::integ(string,string,string).",
2043 size_t ix=lookup_column(x);
2044 size_t iy=lookup_column(y);
2045 for(
size_t i=0;i<nlines;i++) {
2046 itynew->second.dat[i]=integ(ix,(itx->second.dat)[0],
2047 (itx->second.dat)[i],iy);
2056 double max(std::string scol)
const {
2059 if (is_column(scol)==
false) {
2060 O2SCL_ERR((((std::string)
"Column '")+scol+
2064 const vec_t &dcol=get_column(scol);
2066 for(i=0;i<((int)nlines);i++) {
2067 if (std::isfinite(dcol[i])) {
2071 }
else if (dcol[i]>ret) {
2077 O2SCL_ERR((((std::string)
"No finite values in column '")+scol+
2087 double min(std::string scol)
const {
2090 if (is_column(scol)==
false) {
2091 O2SCL_ERR((((std::string)
"Column '")+scol+
2095 const vec_t &dcol=get_column(scol);
2097 for(i=0;i<((int)nlines);i++) {
2098 if (std::isfinite(dcol[i])) {
2102 }
else if (dcol[i]<ret) {
2108 O2SCL_ERR((((std::string)
"No finite values in column '")+scol+
2139 sublines=bottom-top+1;
2141 O2SCL_ERR2(
"Can't make a subtable of an empty table. ",
2142 "Returning 0 in table::subtable().",
2146 if (bottom+1>nlines) {
2147 O2SCL_ERR2(
"Requested row beyond nlines. Adjusting ",
2148 "and continuing in table::subtable().",
exc_einval);
2152 std::istringstream is(list);
2154 tnew.set_nlines(sublines);
2156 it=atree.find(head);
2157 if (it==atree.end()) {
2159 ((((std::string)
"Couldn't find column named ")+head+
2160 " in table::subtable(). Returning 0.").c_str(),
2163 tnew.new_column(head);
2164 vec_t &dcol=tnew.get_column(head);
2165 for(i=0;i<sublines;i++) {
2166 dcol[i]=it->second.dat[i+top];
2169 if (tnew.get_ncolumns()==0) {
2170 O2SCL_ERR(
"Subtable has no columns in table::subtable().",
2174 tnew.nlines=sublines;
2189 for(it=atree.begin();it!=atree.end();it++) {
2190 for(
int j=0;j<((int)nlines);j++) {
2191 it->second.dat[j]=0.0;
2217 if (intp_set==
true) {
2232 if (intp_set==
true) {
2257 size_t ncols=get_ncolumns(), nlins=get_nlines();
2261 for(
size_t i=0;i<ncols;i++) {
2262 for(
size_t j=0;j<nlins;j++) {
2263 data_copy(i,j)=
get(i,j);
2268 aiter it=atree.find(scol);
2269 vec_t &data=it->second.dat;
2271 for(
size_t i=0;i<ncols;i++) {
2272 for(
size_t j=0;j<nlins;j++) {
2273 set(i,j,data_copy(i,order[j]));
2289 aiter it=atree.find(scol);
2290 if (it==atree.end()) {
2291 O2SCL_ERR((((std::string)
"Column '")+scol+
2292 " not found in table::sort_column().").c_str(),
2299 if (intp_set && (scol==intp_colx || scol==intp_coly)) {
2317 virtual void summary(std::ostream *out,
size_t ncol=79)
const {
2319 if (constants.size()==1) {
2320 (*out) <<
"1 constant:" << std::endl;
2322 (*out) << constants.size() <<
" constants:" << std::endl;
2324 std::map<std::string,double>::const_iterator mit;
2325 for(mit=constants.begin();mit!=constants.end();mit++) {
2326 (*out) << mit->first <<
" " << mit->second << std::endl;
2330 size_t nh=get_ncolumns(), nh2;
2334 (*out) <<
"No columns." << std::endl;
2339 (*out) <<
"1 column: " << std::endl;
2341 (*out) << nh <<
" columns: " << std::endl;
2343 std::vector<std::string> h(nh);
2344 for(
size_t i=0;i<nh;i++) {
2345 h[i]=
szttos(i)+
". "+get_column_name(i);
2348 std::vector<std::string> h2;
2354 for(
size_t i=0;i<nh2;i++) {
2355 (*out) << h2[i] << std::endl;
2360 if (get_nlines()==0) (*out) <<
"No lines of data." << std::endl;
2361 else if (get_nlines()==1) (*out) <<
"One line of data." << std::endl;
2362 (*out) << get_nlines() <<
" lines of data." << std::endl;
2374 if (constants.find(name)!=constants.end()) {
2375 constants.find(name)->second=val;
2378 constants.insert(make_pair(name,val));
2393 bool err_on_notfound=
true) {
2394 if (constants.find(name)!=constants.end()) {
2395 constants.find(name)->second=val;
2398 if (err_on_notfound) {
2399 std::string err=((std::string)
"No constant with name '")+name+
2400 "' in table::set_constant().";
2408 if (constants.find(name)==constants.end()) {
2416 if (constants.find(name)==constants.end()) {
2417 std::string err=((std::string)
"No constant with name '")+name+
2418 "' in table::get_constant(string).";
2421 return constants.find(name)->second;
2426 return constants.size();
2430 virtual void get_constant(
size_t ix, std::string &name,
double &val)
const {
2431 if (ix<constants.size()) {
2432 std::map<std::string,double>::const_iterator cit=constants.begin();
2433 for(
size_t i=0;i<ix;i++) cit++;
2438 O2SCL_ERR(
"Index too large in table::get_constant(size_t,string,double).",
2445 if (constants.find(name)==constants.end()) {
2449 constants.erase(name);
2464 std::vector<std::string> onames, nnames;
2466 std::istringstream is(line);
2467 while (is >> cname) {
2468 onames.push_back(cname);
2470 std::cout <<
"Read possible column name: " << cname << std::endl;
2476 for(
size_t i=0;i<onames.size();i++) {
2482 if (n_nums==onames.size()) {
2485 std::cout <<
"First row looks like it contains numerical values." 2487 std::cout <<
"Creating generic column names: ";
2490 for(
size_t i=0;i<onames.size();i++) {
2491 nnames.push_back(((std::string)
"c")+
szttos(i+1));
2492 if (verbose>0) std::cout << nnames[i] <<
" ";
2495 if (verbose>0) std::cout << std::endl;
2498 for(
size_t i=0;i<nnames.size();i++) {
2499 new_column(nnames[i]);
2503 set_nlines_auto(irow+1);
2504 for(
size_t i=0;i<onames.size();i++) {
2512 for(
size_t i=0;i<onames.size();i++) {
2513 std::string temps=onames[i];
2514 make_fp_varname(temps);
2515 make_unique_name(temps,nnames);
2516 nnames.push_back(temps);
2517 if (temps!=onames[i] && verbose>0) {
2518 std::cout <<
"Converted column named '" << onames[i] <<
"' to '" 2519 << temps <<
"'." << std::endl;
2524 for(
size_t i=0;i<nnames.size();i++) {
2525 new_column(nnames[i]);
2531 while ((fin) >> data) {
2532 set_nlines_auto(irow+1);
2534 for(
size_t i=1;i<get_ncolumns();i++) {
2552 if (atree.size()!=alist.size()) {
2553 O2SCL_ERR2(
"Size of table and list do not match in ",
2557 for(
aciter it=atree.begin();it!=atree.end();it++) {
2558 if (it->second.index!=alist[it->second.index]->second.index) {
2559 O2SCL_ERR((((std::string)
"Problem with iterator for entry '")+
2560 it->first+
"' in list in table::check_synchro().").c_str(),
2564 for(
int i=0;i<((int)atree.size());i++) {
2565 if (alist[i]->second.index!=i) {
2566 O2SCL_ERR((((std::string)
"Problem with index of entry ")+
2567 itos(i)+
" in list in table::check_synchro().").c_str(),
2578 if (maxlines<nlines) {
2579 O2SCL_ERR2(
"Value of maxlines smaller than nlines ",
2582 if (atree.size()!=alist.size()) {
2583 O2SCL_ERR2(
"Size of table and list do not match in ",
2587 for(
aciter it=atree.begin();it!=atree.end();it++) {
2588 if (it->second.dat.size()!=maxlines) {
2589 O2SCL_ERR2(
"Vector with size different than maxlines ",
2592 if (it->second.index!=alist[it->second.index]->second.index) {
2593 O2SCL_ERR((((std::string)
"Problem with iterator for entry '")+
2594 it->first+
"' in list in table::is_valid().").c_str(),
2598 for(
int i=0;i<((int)atree.size());i++) {
2599 if (alist[i]->second.index!=i) {
2600 O2SCL_ERR((((std::string)
"Problem with index of entry ")+
2601 itos(i)+
" in list in table::is_valid().").c_str(),
2610 virtual const char *
type() {
return "table"; }
2647 std::vector<std::string> funcs, names;
2650 std::istringstream is(list);
2651 while(is >> stemp) funcs.push_back(stemp);
2652 for(
size_t i=0;i<(funcs.size());i++) {
2653 names.push_back(funcs[i].substr(0,funcs[i].find(
"=")));
2654 funcs[i]=funcs[i].substr(funcs[i].find(
"=")+1,
2655 funcs[i].length()-funcs[i].find(
"=")-1);
2656 if (names[i].length()==0 || funcs[i].length()==0) {
2663 std::map<std::string,double> vars;
2664 std::map<std::string,double>::const_iterator mit;
2665 for(mit=constants.begin();mit!=constants.end();mit++) {
2666 vars[mit->first]=mit->second;
2669 std::vector<calculator> calcs(funcs.size());
2670 std::vector<vec_t> newcols(funcs.size());
2672 for(
size_t j=0;j<funcs.size();j++) {
2673 calcs[j].compile(funcs[j].c_str(),&vars);
2674 newcols[j].resize(maxlines);
2678 for(
size_t i=0;i<nlines;i++) {
2681 for(
size_t j=0;j<atree.size();j++) {
2682 vars[get_column_name(j)]=(*this)[j][i];
2686 for(
size_t j=0;j<funcs.size();j++) {
2687 newcols[j][i]=calcs[j].eval(&vars);
2691 for(
size_t j=0;j<funcs.size();j++) {
2692 if (!is_column(names[j])) {
2693 new_column(names[j]);
2695 swap_column_data(names[j],newcols[j]);
2714 if (!is_column(scol)) {
2719 aiter it2=atree.find(scol);
2720 vec_t &colp=it2->second.dat;
2723 function_vector(
function,colp);
2741 template<
class resize_vec_t>
2743 bool throw_on_err=
true) {
2747 std::map<std::string,double> vars;
2748 std::map<std::string,double>::const_iterator mit;
2749 for(mit=constants.begin();mit!=constants.end();mit++) {
2750 vars[mit->first]=mit->second;
2752 calc.
compile(
function.c_str(),&vars);
2755 if (vec.size()<nlines) vec.resize(nlines);
2758 std::vector<double> vals(atree.size());
2761 for(
size_t j=0;j<nlines;j++) {
2762 for(
aciter it=atree.begin();it!=atree.end();it++) {
2763 vars[it->first]=it->second.dat[j];
2765 vec[j]=calc.
eval(&vars);
2777 std::map<std::string,double> vars;
2778 std::map<std::string,double>::const_iterator mit;
2779 for(mit=constants.begin();mit!=constants.end();mit++) {
2780 vars[mit->first]=mit->second;
2782 calc.
compile(
function.c_str(),&vars);
2784 for(
aciter it=atree.begin();it!=atree.end();it++) {
2785 vars[it->first]=it->second.dat[row];
2788 double dret=calc.
eval(&vars);
2798 std::map<std::string,double> vars;
2799 std::map<std::string,double>::const_iterator mit;
2800 for(mit=constants.begin();mit!=constants.end();mit++) {
2801 vars[mit->first]=mit->second;
2803 calc.
compile(
function.c_str(),&vars);
2805 double best_val=0.0;
2807 for(
size_t row=0;row<nlines-1;row++) {
2808 for(
aciter it=atree.begin();it!=atree.end();it++) {
2809 vars[it->first]=it->second.dat[row];
2811 double dtemp=calc.
eval(&vars);
2815 if (dtemp>best_val) {
2828 friend void o2scl_hdf::hdf_output
2834 friend void o2scl_hdf::hdf_output_data
2842 #ifndef DOXYGEN_INTERNAL 2855 for(it=atree.begin();it!=atree.end();it++) {
2856 alist[it->second.index]=it;
2865 if (s==
"abs" || s==
"acos" || s==
"acosh" || s==
"asin" ||
2866 s==
"asinh" || s==
"atan" || s==
"atan2" || s==
"atanh" ||
2867 s==
"ceil" || s==
"cos" || s==
"cosh" || s==
"cot" || s==
"csc" ||
2868 s==
"eval" || s==
"exp" || s==
"floor" || s==
"if" || s==
"int" ||
2869 s==
"log" || s==
"log10" || s==
"max" || s==
"min" || s==
"sec" ||
2870 s==
"sin" || s==
"sinh" || s==
"sqrt" || s==
"tan" || s==
"tanh") {
2871 s=((std::string)
"v_")+s;
2872 }
else if (s[0]>=
'0' && s[0]<=
'9') {
2873 s=((std::string)
"v_")+s;
2876 for(
size_t i=0;i<s.length();i++) {
2877 if (!isalpha(s[i]) && !isdigit(s[i]) && s[i]!=
'_') s[i]=
'_';
2889 for(
size_t i=0;i<cnames.size();i++) {
2890 if (colx==cnames[i]) {
2898 }
while (done==
false);
2940 typedef typename std::map<std::string,
col,
2941 std::greater<std::string> >::iterator
aiter;
2943 typedef typename std::map<std::string,col,
2944 std::greater<std::string> >::const_iterator
2947 typedef typename std::vector<aiter>::iterator
aviter;
2957 std::map<std::string,col,std::greater<std::string> >
atree;
2966 aiter it=atree.find(lname);
2967 if (it==atree.end()) {
2968 O2SCL_ERR((((std::string)
"Column '")+lname+
2969 " not found in table::get_iterator().").c_str(),
2976 aiter it=atree.find(lname);
2977 if (it==atree.end()) {
2978 O2SCL_ERR((((std::string)
"Column '")+lname+
2979 " not found in table::get_col_struct().").c_str(),
2983 return &(it->second);
2988 aiter
end() {
return atree.end(); }
3021 template<
class vec_t=std::vector<
double> >
3047 std::vector<std::string> cols) {
3055 std::vector<std::string> cols) {
3057 col_ptrs.resize(nc);
3058 for(
size_t i=0;i<nc;i++) {
3059 col_ptrs[i]=&t[cols[i]];
3084 O2SCL_ERR(
"Row exceeds max in matrix_view_table::operator().",
3088 O2SCL_ERR(
"Column exceeds max in matrix_view_table::operator().",
3091 const vec_t *cp=col_ptrs[col];
3097 #ifndef DOXYGEN_NO_O2NS 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 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 named yp which is the derivative formed from columns named x and y ...
double max(std::string scol) const
Return column maximum. Makes no assumptions about ordering, .
size_t size2()
Return the number of columns.
const vec_t & operator[](std::string scol) const
Returns the column named scol (const version). .
void line_of_data(const vec2_t &v)
Read a line of data and store in a new row of the table.
void copy_to_column(vec2_t &v, std::string scol)
Copy to a column from a generic vector object.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
void is_valid() const
Check if the table object appears to be valid.
std::string intp_coly
The last y-column interpolated.
size_t get_nlines() const
Return the number of lines.
double integ(size_t ix, double x1, double x2, size_t iy)
Compute the integral of the function defined by x-values stored in column with index ix and y-values ...
interp_vec< vec_t > * si
Interpolation object.
double min(std::string scol) const
Return column minimum. Makes no assumptions about ordering, .
double deriv(std::string sx, double x0, std::string sy)
Compute the first derivative of the function defined by x-values stored in column named sx and y-valu...
virtual void clear()
Clear everything.
double integ_const(size_t ix, double x1, double x2, size_t iy) const
Compute the integral of the function defined by x-values stored in column with index ix and y-values ...
void hdf_input_data(hdf_file &hf, o2scl::table< vec_t > &t)
Internal function for inputting a o2scl::table object.
void compile(const char *expr, std::map< std::string, double > *vars=0, bool debug=false, std::map< std::string, int > opPrec=opPrecedence)
Compile expression expr using variables specified in vars.
void copy_rows(std::string func, table< vec2_t > &dest)
Copy all rows matching a particular condition to a new table.
virtual double deriv2(const double x0) const
Give the value of the second derivative .
void subtable(std::string list, size_t top, size_t bottom, table< vec_t > &tnew) const
Make a subtable.
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.
sanity check failed - shouldn't happen
int function_vector(std::string function, resize_vec_t &vec, bool throw_on_err=true)
Compute a column from a function specified in a string.
aiter get_iterator(std::string lname)
Return the iterator for a column.
double deriv_const(std::string sx, double x0, std::string sy) const
Compute the first derivative of the function defined by x-values stored in column named sx and y-valu...
invalid argument supplied by user
A simple matrix view object.
matrix_view_table(o2scl::table< vec_t > &t, std::vector< std::string > cols)
Create a matrix view object from the specified table and list of columns.
void deriv2(std::string x, std::string y, std::string yp)
Create a new column named yp which is equal to the second derivative of the function defined by x-val...
virtual int set_constant(std::string name, double val, bool err_on_notfound=true)
Set a constant equal to a value, but don't add it if not already present.
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)
Compute the first derivative of the function defined by x-values stored in column with index ix and y...
std::string intp_colx
The last x-column interpolated.
virtual void remove_constant(std::string name)
Remove a constant.
double integ_const(std::string sx, double x1, double x2, std::string sy) const
Compute the integral of the function defined by x-values stored in column named sx and y-values store...
A class for representing permutations.
virtual ~table()
Table destructor.
void make_fp_varname(std::string &s)
Ensure a variable name does not match a function or contain non-alphanumeric characters.
void delete_idadj_rows()
Delete all rows which are identical to adjacent rows.
double interp_const(size_t ix, double x0, size_t iy) const
Interpolate value x0 from column with index ix into column with index iy .
virtual double deriv(const double x0) const
Give the value of the derivative .
int new_column(std::string name, size_t sz, vec2_t &v)
Add a new column by copying data from another vector.
virtual size_t get_nconsts() const
Get the number of constants.
table & operator=(const table &t)
Copy constructor.
double interp_const(std::string sx, double x0, std::string sy) const
Interpolate value x0 from column named sx into column named sy (const version)
std::map< std::string, col, std::greater< std::string > >::const_iterator aciter
Const map iterator type.
void check_synchro() const
Check if the tree and list are properly synchronized.
Generic "not found" result.
void insert_table(table< vec2_t > &source, std::string src_index, bool allow_extrap=true, std::string dest_index="")
Insert columns from a source table into the new table by interpolation (or extrapolation) ...
vec_t empty_col
An empty vector for get_column()
std::vector< aiter > alist
The list of tree iterators.
const vec_t & get_column(std::string scol) const
Returns a reference to the column named col. .
size_t get_interp_type() const
Get the interpolation type.
double integ(std::string sx, double x1, double x2, std::string sy)
Compute the integral of the function defined by x-values stored in column named sx and y-values store...
virtual double get_constant(std::string name) const
Get a constant.
virtual void clear_table()
Clear the table and the column names (but leave constants)
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.
void vector_sort_index(size_t n, const vec_t &data, vec_size_t &order)
Create a permutation which sorts the first n elements of a vector (in increasing order) ...
size_t get_maxlines()
Return the maximum number of lines before a reallocation is required.
View a o2scl::table object as a matrix.
Cubic spline for natural boundary conditions.
double interp(std::string sx, double x0, std::string sy)
Interpolate value x0 from column named sx into column named sy.
o2scl::table< vec_t > * tp
Pointer to the table.
size_t maxlines
The size of allocated memory.
void sort_column(std::string scol)
Individually sort the column scol.
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 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.
Column structure for table [protected].
The O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl namespace ...
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)
Compute the second derivative of the function defined by x-values stored in column named sx and y-val...
size_t ordered_lookup(std::string scol, double val) const
Look for a value in an ordered column .
virtual double integ(const double x1, const double x2) const
Give the value of the integral .
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 value x0 from column with index ix into column with index iy .
void get_row(std::string scol, double val, resize_vec_t &row) const
Returns a copy of the row with value val in column col. .
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.
double eval(std::map< std::string, double > *vars=0)
Evalate the previously compiled expression using variables specified in vars.
#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.
std::vector< const vec_t * > col_ptrs
Pointers to each column.
const double & operator()(size_t row, size_t col) const
Return a reference to the element at row row and column col.
void line_of_data(size_t nv, const vec2_t &v)
Read a line of data from the first nv entries in a vector and store as a new row in the table...
col & operator=(const col &c)
Copy constructor for assignment operator.
size_t delete_rows_tolerance(double tol_rel=1.0e-12, double tol_abs=1.0e-20, int verbose=0)
Exaustively search for groups of rows which match within a specified tolerance and remove all but one...
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.
bool is_number(std::string s)
Return true if the string s is likely a integral or floating point number.
size_t ordered_lookup(const double x0) const
Find the index of x0 in the ordered array x.
Evaluate a mathematical expression in a string.
double deriv2(size_t ix, double x0, size_t iy)
Compute the second derivative of the function defined by x-values stored in column with index ix and ...
double deriv2_const(size_t ix, double x0, size_t iy) const
Compute the second derivative of the function defined by x-values stored in column with index ix and ...
void delete_row(size_t irow)
Delete the row of index irow .
size_t get_ncolumns() const
Return the number of columns.
double stod(std::string s)
Convert a string to a double.
virtual bool is_constant(std::string name) const
Test if name is a constant.
void new_column(std::string head)
Add a new column owned by the table table .
virtual void summary(std::ostream *out, size_t ncol=79) const
Output a summary of the information stored.
aiter end()
Return the end of the column tree.
void set_maxlines(size_t llines)
Manually set the maximum number of lines.
void column_to_vector(std::string scol, resize_vec_t &v) const
Copy a column to a generic vector object.
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)
Create a new column named ynew which is equal to the integral of the function defined by x-values sto...
bool is_column(std::string scol) const
Return true if scol is a column in the current table table .
size_t size1()
Return the number of rows.
void delete_rows_func(std::string func)
Delete all rows where func evaluates to a number greater than 0.5 .
Searching class for monotonic data with caching.
size_t lookup(int icol, double val) const
Exhaustively search column col for the value val .
std::map< std::string, col, std::greater< std::string > >::iterator aiter
Map iterator type.
virtual void get_constant(size_t ix, std::string &name, double &val) const
Get a constant by index.
Store data in an O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$sc...
void set_row(size_t row, size_vec_t &v)
Set an entire row of data.
table(size_t cmaxlines=0)
Create a new table with space for nlines<=cmaxlines.
bool intp_set
True if the interpolation object is up-to-date.
double row_function(std::string function, size_t row) const
Compute a value by applying a function to a row.
std::map< std::string, col, std::greater< std::string > > atree
The tree of columns.
void get_row(size_t irow, resize_vec_t &row) const
Returns a copy of row number irow. .
size_t function_find_row(std::string function) const
Find a row which maximizes a function.
Invalid index for array or matrix.
col(const col &c)
Copy constructor.
size_t itype
Current interpolation type.
void delete_rows_list(vec_size_t &row_list)
Delete all rows in a specified list.
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]
matrix_view_table()
Create a matrix view object from the specified table and list of columns.
virtual double eval(const double x0) const
Give the value of the function .
std::string get_column_name(size_t icol) const
Returns the name of column col .
static const double x1[5]
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)
double deriv2_const(std::string sx, double x0, std::string sy) const
The Compute the second derivative of the function defined by x-values stored in column named sx and y...
double deriv_const(size_t ix, double x0, size_t iy) const
Compute the first derivative of the function defined by x-values stored in column with index ix and y...
size_t lookup_column(std::string lname) const
Find the index for column named name .
size_t lookup(std::string scol, double val) const
Exhaustively search column col for the value val .
Interpolation class for general vectors.
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.
std::string get_sorted_name(size_t icol) const
Returns the name of column col in sorted order. .
size_t nc
The number of columns.
void delete_rows_ends(size_t row_start, size_t row_end)
Delete all rows between row_start and row_end .
void sort_table(std::string scol)
Sort the entire table by the column scol.
virtual void rename_column(std::string src, std::string dest)
Rename column named src to dest .