本文整理汇总了C++中DataSetList::AddOrAppendSets方法的典型用法代码示例。如果您正苦于以下问题:C++ DataSetList::AddOrAppendSets方法的具体用法?C++ DataSetList::AddOrAppendSets怎么用?C++ DataSetList::AddOrAppendSets使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataSetList
的用法示例。
在下文中一共展示了DataSetList::AddOrAppendSets方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
// DataIO_Std::Read_Mat3x3()
int DataIO_Std::Read_Mat3x3(std::string const& fname,
DataSetList& datasetlist, std::string const& dsname)
{
// Buffer file
BufferedLine buffer;
if (buffer.OpenFileRead( fname )) return 1;
mprintf("\tAttempting to read 3x3 matrix data.\n");
// Skip comments
const char* linebuffer = buffer.Line();
while (linebuffer != 0 && linebuffer[0] == '#')
linebuffer = buffer.Line();
// Check that number of columns (9) is correct.
int ntokens = buffer.TokenizeLine( SEPARATORS );
if (ntokens < 1) {
mprinterr("Error: Could not tokenize line.\n");
return 1;
}
int ncols = ntokens;
bool hasIndex;
if (ncols == 9)
hasIndex = false;
else if (ncols == 10) {
hasIndex = true;
mprintf("Warning: Not reading 3x3 matrix data indices.\n");
} else {
mprinterr("Error: Expected 9 columns of 3x3 matrix data, got %i.\n", ncols);
return 1;
}
// Create data set
DataSet_Mat3x3* ds = new DataSet_Mat3x3();
if (ds == 0) return 1;
ds->SetMeta( dsname );
// Read 3x3 matrix data
double mat[9];
std::fill(mat, mat, 0.0);
size_t ndata = 0;
while (linebuffer != 0) {
if (hasIndex)
ntokens = sscanf(linebuffer, "%*f %lf %lf %lf %lf %lf %lf %lf %lf %lf",
mat, mat+1, mat+2, mat+3, mat+4, mat+5, mat+6, mat+7, mat+8);
else
ntokens = sscanf(linebuffer, "%lf %lf %lf %lf %lf %lf %lf %lf %lf",
mat, mat+1, mat+2, mat+3, mat+4, mat+5, mat+6, mat+7, mat+8);
if (ntokens != 9) {
mprinterr("Error: In 3x3 matrix file, line %i: expected 9 values, got %i\n",
buffer.LineNumber(), ntokens);
break;
}
ds->Add( ndata++, mat );
linebuffer = buffer.Line();
}
return (datasetlist.AddOrAppendSets("", DataSetList::Darray(), DataSetList::DataListType(1, ds)));
}
示例2: ReadData
//.........这里部分代码省略.........
finalE = true;
// Check for '| TI region 2' to prevent reading duplicate energies
if ( strncmp(ptr, "| TI region 2", 14) == 0 ) {
while (ptr != 0 && !(ptr[0] == ' ' && ptr[1] == '-'))
ptr = buffer.Line();
if (ptr == 0) return EOF_ERROR();
}
// Record set for energy post-processing
if (imin == 5 && strncmp(ptr, "minimizing", 10) == 0)
nstep = atoi( ptr + 22 );
// MAIN OUTPUT ROUTINE
// If the trigger has been reached print output.
// For imin0 and imin1 the first trigger will have no data.
// If the end of the file has been reached print then exit.
if ( strncmp(ptr, Trigger, 8) == 0 || finalE ) {
if (frame > -1) {
// Store all energies present.
for (int i = 0; i < (int)N_FIELDTYPES; i++) {
if (EnergyExists[i]) {
if (inputSets[i] == 0) {
MetaData md( dsname, Enames[i] );
md.SetLegend( dsname + "_" + Enames[i] );
inputSets[i] = new DataSet_double();
inputSets[i]->SetMeta( md );
}
// Since energy terms can appear and vanish over the course of the
// mdout file, resize if necessary.
if (frame > (int)inputSets[i]->Size())
((DataSet_double*)inputSets[i])->Resize( frame );
((DataSet_double*)inputSets[i])->AddElement( Energy[i] );
}
}
TimeVals.push_back( time );
nstep += ntpr;
}
frame++;
if (finalE) break;
}
// Check for NSTEP in minimization or post-processing. Values will be
// on the next line. NOTE: NSTEP means something different for imin=5.
if ((imin == 1 || imin == 5) && strncmp(ptr, " NSTEP", 8) == 0) {
ptr = buffer.Line(); // Get next line
//sscanf(ptr, " %6lf %13lE %13lE %13lE", Energy+NSTEP, Energy+EPtot, Energy+RMS, Energy+GMAX);
sscanf(ptr, " %i %lE %lE %lE", &minStep, Energy+EPtot, Energy+RMS, Energy+GMAX);
EnergyExists[EPtot] = true;
EnergyExists[RMS] = true;
EnergyExists[GMAX] = true;
ptr = buffer.Line();
}
// Tokenize line, scan through until '=' is reached; value after is target.
int ntokens = buffer.TokenizeLine(" ");
if (ntokens > 0) {
int nidx = 0;
Name[0].clear();
Name[1].clear();
for (int tidx = 0; tidx < ntokens; tidx++) {
const char* tkn = buffer.NextToken();
if (tkn[0] == '=') {
FieldType Eindex = getEindex(Name);
tkn = buffer.NextToken();
++tidx;
if (tkn == 0)
mprintf("Warning: No numerical value, line %i column %i. Skipping.\n",
buffer.LineNumber(), tidx+1);
else if (tkn[0] == '*' || tkn[0] == 'N') // Assume if number begins with N it is NaN
mprintf("Warning: Numerical overflow detected, line %i column %i. Skipping.\n",
buffer.LineNumber(), tidx+1);
else {
if (Eindex != N_FIELDTYPES) {
Energy[Eindex] = atof( tkn );
EnergyExists[Eindex] = true;
}
}
nidx = 0;
Name[0].clear();
Name[1].clear();
} else {
if (nidx > 1) break; // Two tokens, no '=' found. Not an E line.
Name[nidx++].assign( tkn );
}
}
}
// Set time
switch (imin) {
case 5: time = (double)nstep + t0; break;
case 1: time = (double)minStep + t0; break;
case 0: time = ((double)nstep * dt) + t0; break;
}
// Read in next line
ptr = buffer.Line();
}
mprintf("\t%i frames\n", frame);
buffer.CloseFile();
std::string Xlabel;
if (imin == 5) Xlabel.assign("Set");
else if (imin == 1) Xlabel.assign("Nstep");
else Xlabel.assign("Time"); // imin == 0
if (datasetlist.AddOrAppendSets( Xlabel, TimeVals, inputSets )) return 1;
return 0;
}
示例3: ReadData
int DataIO_XVG::ReadData(FileName const& fname,
DataSetList& datasetlist, std::string const& dsname)
{
std::vector<std::string> Legends;
BufferedLine infile;
if (infile.OpenFileRead( fname )) return 1;
const char* ptr = infile.Line();
if (ptr == 0) return 1;
// Skip any comments
while (ptr != 0 && ptr[0] == '#')
ptr = infile.Line();
// Try to get set legends
while (ptr != 0 && ptr[0] == '@') {
ArgList line(ptr, " \t");
if (line.Nargs() > 3 && line[1][0] == 's') {
std::string legend = line.GetStringKey("legend");
if (!legend.empty()) {
// Spaces will cause issues with data set selection.
for (std::string::iterator s = legend.begin(); s != legend.end(); ++s)
if (*s == ' ') *s = '_';
Legends.push_back( legend );
}
}
ptr = infile.Line();
}
if (Legends.empty()) {
mprinterr("Error: No set legends found in XVG file.\n");
return 1;
}
if (ptr == 0) {
mprinterr("Error: No data in XVG file.\n");
return 1;
}
// Create 1 data set for each legend
DataSetList::DataListType inputSets;
for (unsigned int i = 0; i != Legends.size(); i++) {
MetaData md( dsname, i );
md.SetLegend( Legends[i] );
DataSet_double* ds = new DataSet_double();
if (ds == 0) return 1;
ds->SetMeta( md );
inputSets.push_back( ds );
}
mprintf("\t%s has %zu columns of data.\n", fname.base(), inputSets.size());
// Should now be positioned at first line of data. Assume first column is time values.
DataSetList::Darray Xvals;
int expectedCols = (int)inputSets.size() + 1;
while (ptr != 0) {
int ncols = infile.TokenizeLine(" \t");
if (ncols != expectedCols)
mprinterr("Error: Line %i: %i columns != expected # cols %i\n", infile.LineNumber(),
ncols, expectedCols);
else {
Xvals.push_back( atof( infile.NextToken() ) );
for (unsigned int i = 0; i != inputSets.size(); i++)
((DataSet_double*)inputSets[i])->AddElement( atof( infile.NextToken() ) );
}
ptr = infile.Line();
}
infile.CloseFile();
return (datasetlist.AddOrAppendSets( "", Xvals, inputSets ));
}
示例4: Read_Vector
// DataIO_Std::Read_Vector()
int DataIO_Std::Read_Vector(std::string const& fname,
DataSetList& datasetlist, std::string const& dsname)
{
// Buffer file
BufferedLine buffer;
if (buffer.OpenFileRead( fname )) return 1;
mprintf("\tAttempting to read vector data.\n");
// Skip comments
const char* linebuffer = buffer.Line();
while (linebuffer != 0 && linebuffer[0] == '#')
linebuffer = buffer.Line();
// Determine format. Expect 3 (VXYZ), 6 (VXYZ OXYZ), or
// 9 (VXYZ OXYZ VXYZ+OXYZ) values, optionally with indices.
int ntokens = buffer.TokenizeLine( SEPARATORS );
int ncols = ntokens; // Number of columns of vector data.
int nv = 0; // Number of columns to actually read from (3 or 6).
bool hasIndex;
if (ntokens < 1) {
mprinterr("Error: Could not tokenize line.\n");
return 1;
}
if (ncols == 3 || ncols == 6 || ncols == 9)
hasIndex = false;
else if (ncols == 4 || ncols == 7 || ncols == 10) {
hasIndex = true;
mprintf("Warning: Not reading vector data indices.\n");
} else {
mprinterr("Error: Expected 3, 6, or 9 columns of vector data, got %i.\n", ncols);
return 1;
}
if (ncols >= 6) {
nv = 6;
mprintf("\tReading vector X Y Z and origin X Y Z values.\n");
} else {
nv = 3;
mprintf("\tReading vector X Y Z values.\n");
}
// Create set
DataSet_Vector* ds = new DataSet_Vector();
if (ds == 0) return 1;
ds->SetMeta( dsname );
// Read vector data
double vec[6];
std::fill(vec, vec+6, 0.0);
size_t ndata = 0;
while (linebuffer != 0) {
if (hasIndex)
ntokens = sscanf(linebuffer, "%*f %lf %lf %lf %lf %lf %lf",
vec, vec+1, vec+2, vec+3, vec+4, vec+5);
else
ntokens = sscanf(linebuffer, "%lf %lf %lf %lf %lf %lf",
vec, vec+1, vec+2, vec+3, vec+4, vec+5);
if (ntokens != nv) {
mprinterr("Error: In vector file, line %i: expected %i values, got %i\n",
buffer.LineNumber(), nv, ntokens);
break;
}
ds->Add( ndata++, vec );
linebuffer = buffer.Line();
}
return (datasetlist.AddOrAppendSets("", DataSetList::Darray(), DataSetList::DataListType(1, ds)));
}
示例5: md
//.........这里部分代码省略.........
mprinterr("Error: Specified index column %i is out of range (%i columns).\n",
indexcol_+1, ntoken);
return 1;
}
if (!onlycols_.Empty() && !onlycols_.InRange(indexcol_)) {
mprinterr("Error: Index column %i specified, but not in given column range '%s'\n",
indexcol_+1, onlycols_.RangeArg());
return 1;
}
}
// Determine the type of data stored in each column. Assume numbers should
// be read with double precision.
MetaData md( dsname );
DataSetList::DataListType inputSets;
unsigned int nsets = 0;
for (int col = 0; col != ntoken; ++col) {
std::string token( buffer.NextToken() );
if (!onlycols_.Empty() && !onlycols_.InRange( col )) {
mprintf("\tSkipping column %i\n", col+1);
inputSets.push_back( 0 );
} else {
md.SetIdx( col+1 );
if (hasLabels) md.SetLegend( labels[col] );
if ( col == indexcol_ ) {
// Always save the index column as floating point
inputSets.push_back( new DataSet_double() );
} else if (validInteger(token)) {
// Integer number
inputSets.push_back( datasetlist.Allocate(DataSet::INTEGER) );
} else if (validDouble(token)) {
// Floating point number
inputSets.push_back( new DataSet_double() );
} else {
// Assume string. Not allowed for index column.
if (col == indexcol_) {
mprintf("Warning: '%s' index column %i has string values. No indices will be read.\n",
buffer.Filename().full(), indexcol_+1);
indexcol_ = -1;
}
inputSets.push_back( new DataSet_string() );
}
inputSets.back()->SetMeta( md );
nsets++;
}
}
if (inputSets.empty() || nsets == 0) {
mprinterr("Error: No data detected.\n");
return 1;
}
// Read in data
while (linebuffer != 0) {
if ( buffer.TokenizeLine( SEPARATORS ) != ntoken ) {
PrintColumnError(buffer.LineNumber());
break;
}
// Convert data in columns
for (int i = 0; i < ntoken; ++i) {
const char* token = buffer.NextToken();
if (inputSets[i] != 0) {
if (inputSets[i]->Type() == DataSet::DOUBLE)
((DataSet_double*)inputSets[i])->AddElement( atof(token) );
else if (inputSets[i]->Type() == DataSet::INTEGER)
((DataSet_integer*)inputSets[i])->AddElement( atoi(token) );
else
((DataSet_string*)inputSets[i])->AddElement( std::string(token) );
}
}
//Ndata++;
linebuffer = buffer.Line();
}
buffer.CloseFile();
mprintf("\tDataFile %s has %i columns, %i lines.\n", buffer.Filename().full(),
ntoken, buffer.LineNumber());
// Create list containing only data sets.
DataSetList::DataListType mySets;
DataSet_double* Xptr = 0;
for (int idx = 0; idx != (int)inputSets.size(); idx++) {
if (inputSets[idx] != 0) {
if ( idx != indexcol_ )
mySets.push_back( inputSets[idx] );
else
Xptr = (DataSet_double*)inputSets[idx];
}
}
mprintf("\tRead %zu data sets.\n", mySets.size());
std::string Xlabel;
if (indexcol_ != -1 && indexcol_ < labels.Nargs())
Xlabel = labels[indexcol_];
if (Xptr == 0)
datasetlist.AddOrAppendSets(Xlabel, DataSetList::Darray(), mySets);
else {
datasetlist.AddOrAppendSets(Xlabel, Xptr->Data(), mySets);
delete Xptr;
}
return 0;
}