本文整理汇总了C++中DataSetList::Allocate方法的典型用法代码示例。如果您正苦于以下问题:C++ DataSetList::Allocate方法的具体用法?C++ DataSetList::Allocate怎么用?C++ DataSetList::Allocate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataSetList
的用法示例。
在下文中一共展示了DataSetList::Allocate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: md
// DataIO_Std::Read_1D()
int DataIO_Std::Read_1D(std::string const& fname,
DataSetList& datasetlist, std::string const& dsname)
{
ArgList labels;
bool hasLabels = false;
// Buffer file
BufferedLine buffer;
if (buffer.OpenFileRead( fname )) return 1;
// Read the first line. Attempt to determine the number of columns
const char* linebuffer = buffer.Line();
if (linebuffer == 0) return 1;
int ntoken = buffer.TokenizeLine( SEPARATORS );
if ( ntoken == 0 ) {
mprinterr("Error: No columns detected in %s\n", buffer.Filename().full());
return 1;
}
// Try to skip past any comments. If line begins with a '#', assume it
// contains labels.
bool isCommentLine = true;
const char* ptr = linebuffer;
while (isCommentLine) {
// Skip past any whitespace
while ( *ptr != '\0' && isspace(*ptr) ) ++ptr;
// Assume these are column labels until proven otherwise.
if (*ptr == '#') {
labels.SetList(ptr+1, SEPARATORS );
if (!labels.empty()) {
hasLabels = true;
// If first label is Frame assume it is the index column
if (labels[0] == "Frame" && indexcol_ == -1)
indexcol_ = 0;
}
linebuffer = buffer.Line();
ptr = linebuffer;
if (ptr == 0) {
mprinterr("Error: No data found in file.\n");
return 1;
}
} else
// Not a recognized comment character, assume data.
isCommentLine = false;
}
// Special case: check if labels are '#F1 F2 <name> [nframes <#>]'. If so, assume
// this is a cluster matrix file.
if ((labels.Nargs() == 3 || labels.Nargs() == 5) && labels[0] == "F1" && labels[1] == "F2")
{
mprintf("Warning: Header format '#F1 F2 <name>' detected, assuming cluster pairwise matrix.\n");
return IS_ASCII_CMATRIX;
}
// Column user args start from 1
if (indexcol_ > -1)
mprintf("\tUsing column %i as index column.\n", indexcol_ + 1);
// Should be at first data line. Tokenize the line.
ntoken = buffer.TokenizeLine( SEPARATORS );
// If # of data columns does not match # labels, clear labels.
if ( !labels.empty() && ntoken != labels.Nargs() ) {
labels.ClearList();
hasLabels = false;
}
// Index column checks
if (indexcol_ != -1 ) {
if (indexcol_ >= ntoken) {
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 {
//.........这里部分代码省略.........