40 for(
int i1 = 0; i1 < a_length; ++i1 ) m_boundaries.push_back( a_boundaries[i1] );
50 m_boundaries( a_boundaries ) {
59 m_label( a_group.
label( ) ),
60 m_boundaries( a_group.data( ) ) {
69 m_label( a_multiGroup.
label( ) ),
91 if(
this != &a_rhs ) {
92 m_label = a_rhs.
label( );
111 std::size_t iMin = 0, iMid, iMax = m_boundaries.
size( ), iMaxM1 = iMax - 1;
113 if( iMax == 0 )
return( -3 );
114 if( a_energy < m_boundaries[0] ) {
115 if( a_encloseOutOfRange )
return( 0 );
118 if( a_energy > m_boundaries[iMaxM1] ) {
119 if( a_encloseOutOfRange )
return(
static_cast<int>( iMax ) - 2 );
123 iMid = ( iMin + iMax ) >> 1;
124 if( iMid == iMin )
break;
125 if( a_energy < m_boundaries[iMid] ) {
131 if( iMin == iMaxM1 ) iMin--;
132 return(
static_cast<int>( iMin ) );
140void MultiGroup::set( std::string
const &a_label, std::vector<double>
const &a_boundaries ) {
143 m_boundaries = a_boundaries;
154void MultiGroup::print( std::string
const &a_indent,
bool a_outline,
unsigned int a_valuesPerLine )
const {
156 std::size_t nbs =
size( );
157 bool printIndent(
true );
159 std::cout << a_indent <<
"GROUP: label = '" << m_label <<
"': length = " << nbs << std::endl;
160 if( a_outline )
return;
161 for( std::size_t ib = 0; ib < nbs; ib++ ) {
162 if( printIndent ) std::cout << a_indent;
165 if( ( ( ib + 1 ) % a_valuesPerLine ) == 0 ) {
166 std::cout << std::endl;
170 if( nbs % a_valuesPerLine ) std::cout << std::endl;
185 initialize( a_fileName.c_str( ) );
196 initialize( a_fileName );
205void Groups_from_bdfls::initialize(
char const *a_fileName ) {
207 char buffer[132], *pEnd, cValue[16];
208 FILE *fIn = fopen( a_fileName,
"r" );
209 if( fIn ==
nullptr )
throw Exception(
"Groups_from_bdfls::initialize: Could not open bdfls file." );
213 if( fgets( buffer, 132, fIn ) ==
nullptr )
throw Exception(
"Groups_from_bdfls::initialize: fgets failed for gid." );
214 if( strlen( buffer ) > 73 ) {
215 if( buffer[72] ==
'1' )
break;
217 gid = (int) strtol( buffer, &pEnd, 10 );
218 if( gid == -1 )
throw Exception(
"Groups_from_bdfls::initialize: converting gid to long failed." );
221 long numberOfBoundaries( -1 );
222 if( fgets( buffer, 132, fIn ) ==
nullptr )
throw Exception(
"Groups_from_bdfls::initialize: fgets failed for numberOfBoundaries." );
223 numberOfBoundaries = strtol( buffer, &pEnd, 10 );
224 if( numberOfBoundaries == -1 )
throw Exception(
"Groups_from_bdfls::initialize: converting gid to long failed." );
226 std::size_t index( 0 );
227 std::vector<double> boundaries(
static_cast<std::size_t
>( numberOfBoundaries ) );
228 while( numberOfBoundaries > 0 ) {
230 if( numberOfBoundaries < 6 ) n1 = numberOfBoundaries;
231 if( fgets( buffer, 132, fIn ) ==
nullptr )
throw Exception(
"Groups_from_bdfls::initialize: fgets failed for boundaries." );
232 for( i1 = 0; i1 < n1; ++i1, ++index ) {
233 strncpy( cValue, &buffer[12*i1], 12 );
235 boundaries[index] = strtod( cValue, &pEnd );
237 numberOfBoundaries -= n1;
239 m_multiGroups.push_back( MultiGroup( label, boundaries ) );
261 for( std::size_t ig = 0; ig < m_multiGroups.size( ); ++ig ) {
262 if( m_multiGroups[ig].label( ) == a_label )
return( m_multiGroups[ig] );
264 throw Exception(
"Groups_from_bdfls::viaLabel: label not found." );
289 std::size_t size = m_multiGroups.size( );
290 std::vector<std::string> _labels( size );
292 for( std::size_t if1 = 0; if1 < size; ++if1 ) _labels[if1] = m_multiGroups[if1].label( );
304 std::size_t size = m_multiGroups.size( );
305 std::vector<int> fids( size );
308 for( std::size_t if1 = 0; if1 < size; ++if1 ) {
309 fids[if1] = (int) strtol( &(m_multiGroups[if1].label( ).c_str( )[9]), &e, 10 );
323 std::size_t ngs = m_multiGroups.size( );
325 std::cout <<
"BDFLS GROUPs: number of groups = " << ngs << std::endl;
326 for( std::size_t if1 = 0; if1 < ngs ; ++if1 ) m_multiGroups[if1].
print(
" ", a_outline, a_valuesPerLine );
MultiGroup viaLabel(std::string const &a_label) const
std::vector< std::string > labels() const
MultiGroup getViaGID(int a_gid) const
Groups_from_bdfls(std::string const &a_fileName)
std::vector< int > GIDs() const
void print(bool a_outline=true, unsigned int a_valuesPerLine=10) const
std::vector< double > const & boundaries() const
MultiGroup & operator=(MultiGroup const &a_rhs)
void print(std::string const &a_indent, bool a_outline=false, unsigned int a_valuesPerLine=10) const
void set(std::string const &a_label, std::vector< double > const &a_boundaries)
std::string const & label() const
int multiGroupIndexFromEnergy(double a_energy, bool a_encloseOutOfRange) const
std::string LLNL_gidToLabel(int a_gid)
std::string argumentsToString(char const *a_format,...)