/** Set the x-column format string. First check the maximum digit width * based on the calculated maximum x_value from maxframes, xstep, and * xmin. Then check how many digits the precision might add. The minimum * x-column width is set at 8. The x-column is left-aligned (no leading * space) by default. */ void DataIO::SetupXcolumn() { // Determine the character width necessary to hold the largest X value int max_xval = maxFrames_ + (int)xoffset_; if (xstep_ > 1) max_xval *= (int)xstep_; max_xval += (int)xmin_; xcol_width_ = DigitWidth( max_xval ); // Check if the precision is enough to support the step size if (xstep_ < 1.0) { double precision_exponent = fabs( log10( xstep_ ) ); ++precision_exponent; int prec_exp_width = (int)precision_exponent; // Cast to int implicitly rounds down if (prec_exp_width > xcol_precision_) xcol_precision_ = prec_exp_width; } // If the width for the x column plus the characters needed for precision // (plus 1 for decimal point) would be greater than 8, increment the // X column width by (precision+1). if (xcol_precision_ != 0) { int precision_width = xcol_width_ + xcol_precision_ + 1; if ( precision_width > 8) xcol_width_ = precision_width; } // Default width for x col is at least 8 if (xcol_width_ < 8) xcol_width_ = 8; // Set X column data format string, left-aligned (no leading space) SetDoubleFormatString(x_format_, xcol_width_, xcol_precision_, 0, true); }
void TextFormat::SetCoordFormat(size_t maxFrames, double min, double step, int default_width, int default_precision) { int col_precision = default_precision; // Determine maximum coordinate. double maxCoord = (step * (double)maxFrames) + min; // Determine character width necessary to hold largest coordinate. int col_width = DigitWidth( (long int)maxCoord ); // Check if the precision is enough to support the step size. if (step < 1.0) { int prec_exp_width = FloatWidth( step ); if (prec_exp_width > col_precision) col_precision = prec_exp_width; } // If the width for the column plus the characters needed for precision // (plus 1 for decimal point) would be greated than default_width, increment // the column width by (precision+1). if (col_precision != 0) { int precision_width = col_width + col_precision + 1; if (precision_width > default_width) col_width = precision_width; } // Default width for column is at least default_width. if (col_width < default_width) col_width = default_width; // Set column data format string, left-aligned (no leading space). type_ = DOUBLE; width_ = col_width; precision_ = col_precision; align_ = RIGHT; SetFormatString(); }
/** Create a name based on the given defaultName and # of DataSets, * i.e. defaultName_XXXXX */ std::string DataSetList::GenerateDefaultName(std::string const& defaultName) const { // Determine # chars needed to hold text version of set number (min 5). size_t extsize = (size_t) DigitWidth( size() ); if (extsize < 5) extsize = 5; if (defaultName.empty()) return ( "D" + integerToString(size(), extsize) ); else return ( defaultName + "_" + integerToString(size(), extsize) ); }
// DataIO_Std::WriteCmatrix() int DataIO_Std::WriteCmatrix(CpptrajFile& file, DataSetList const& Sets) { for (DataSetList::const_iterator ds = Sets.begin(); ds != Sets.end(); ++ds) { if ( (*ds)->Group() != DataSet::CLUSTERMATRIX) { mprinterr("Error: Write of cluster matrix and other sets to same file not supported.\n" "Error: Skipping '%s'\n", (*ds)->legend()); continue; } DataSet_Cmatrix const& cm = static_cast<DataSet_Cmatrix const&>( *(*ds) ); int nrows = cm.OriginalNframes(); int col_width = std::max(3, DigitWidth( nrows ) + 1); int dat_width = std::max(cm.Format().Width(), (int)cm.Meta().Legend().size()) + 1; WriteNameToBuffer(file, "F1", col_width, true); WriteNameToBuffer(file, "F2", col_width, false); WriteNameToBuffer(file, cm.Meta().Legend(), dat_width, false); if (cm.SieveType() != ClusterSieve::NONE) file.Printf(" nframes %i", cm.OriginalNframes()); file.Printf("\n"); TextFormat col_fmt(TextFormat::INTEGER, col_width); TextFormat dat_fmt = cm.Format(); dat_fmt.SetFormatAlign(TextFormat::RIGHT); dat_fmt.SetFormatWidth( dat_width ); std::string total_fmt = col_fmt.Fmt() + col_fmt.Fmt() + dat_fmt.Fmt() + "\n"; //mprintf("DEBUG: format '%s'\n", total_fmt.c_str()); ClusterSieve::SievedFrames const& frames = cm.FramesToCluster(); int ntotal = (int)frames.size(); for (int idx1 = 0; idx1 != ntotal; idx1++) { int row = frames[idx1]; for (int idx2 = idx1 + 1; idx2 != ntotal; idx2++) { int col = frames[idx2]; file.Printf(total_fmt.c_str(), row+1, col+1, cm.GetFdist(col, row)); } } } return 0; }