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 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 /*
  2 # <<BEGIN-copyright>>
  3 # <<END-copyright>>
  4 */
  5 
  6 #include <iostream>
  7 #include <stdlib.h>
  8 
  9 #include "GIDI_settings.hh"
 10 
 11 /*
 12 =========================================================
 13 */
 14 GIDI_settings_group::GIDI_settings_group( std::string const &label, int size1 ) {
 15 
 16     initialize( label, size1, size1, NULL );
 17 }
 18 /*
 19 =========================================================
 20 */
 21 GIDI_settings_group::GIDI_settings_group( std::string const &label, int length, double const *boundaries ) {
 22 
 23     initialize( label, length, length, boundaries );
 24 }
 25 /*
 26 =========================================================
 27 */
 28 GIDI_settings_group::GIDI_settings_group( std::string const &label, std::vector<double> const &boundaries) {
 29 
 30     int size1 = (int) boundaries.size( );
 31 
 32     initialize( label, size1, size1, &(boundaries[0]) );
 33 }
 34 /*
 35 =========================================================
 36 */
 37 GIDI_settings_group::GIDI_settings_group( GIDI_settings_group const &group ) {
 38 
 39     initialize( group.mLabel, group.size( ), group.size( ), &(group.mBoundaries[0]) );
 40 }
 41 /*
 42 =========================================================
 43 */
 44 void GIDI_settings_group::initialize( std::string const &label, int size1, int length, double const *boundaries ) {
 45 
 46     int i1;
 47 
 48     mLabel = label;
 49     if( size1 < length ) size1 = length;
 50     if( size1 < 0 ) size1 = 0;
 51     mBoundaries.resize( size1, 0 );
 52     for( i1 = 0; i1 < length; ++i1 ) mBoundaries[i1] = boundaries[i1];
 53 }
 54 /*
 55 =========================================================
 56 */
 57 GIDI_settings_group& GIDI_settings_group::operator=( const GIDI_settings_group &group ) {
 58   if ( this != &group ) {
 59     initialize( group.mLabel, group.size(), group.size(), &(group.mBoundaries[0]) );
 60   }
 61   return *this;
 62 }
 63 /*
 64 =========================================================
 65 */
 66 GIDI_settings_group::~GIDI_settings_group( ) {
 67 
 68 }
 69 /*
 70 =========================================================
 71 */
 72 int GIDI_settings_group::getGroupIndexFromEnergy( double energy, bool encloseOutOfRange ) const {
 73 
 74     int iMin = 0, iMid, iMax = (int) mBoundaries.size( ), iMaxM1 = iMax - 1;
 75 
 76     if( iMax == 0 ) return( -3 );
 77     if( energy < mBoundaries[0] ) {
 78         if( encloseOutOfRange ) return( 0 );
 79         return( -2 );
 80     }
 81     if( energy > mBoundaries[iMaxM1] ) {
 82         if( encloseOutOfRange ) return( iMax - 2 );
 83         return( -1 );
 84     }
 85     while( 1 ) { // Loop checking, 11.06.2015, T. Koi
 86         iMid = ( iMin + iMax ) >> 1;
 87         if( iMid == iMin ) break;
 88         if( energy < mBoundaries[iMid] ) {
 89             iMax = iMid; }
 90         else {
 91             iMin = iMid;
 92         }
 93     }
 94     if( iMin == iMaxM1 ) iMin--;
 95     return( iMin );
 96 }
 97 /*
 98 =========================================================
 99 */
100 void GIDI_settings_group::print( bool outline, int valuesPerLine ) const {
101 
102     int nbs = size( );
103     char buffer[128];
104 
105     std::cout << "GROUP: label = '" << mLabel << "': length = " << nbs << std::endl;
106     if( outline ) return;
107     for( int ib = 0; ib < nbs; ib++ ) {
108         snprintf( buffer, sizeof buffer, "%16.8e", mBoundaries[ib] );
109         std::cout << buffer;
110         if( ( ( ib + 1 ) % valuesPerLine ) == 0 ) std::cout << std::endl;
111     }
112     if( nbs % valuesPerLine ) std::cout << std::endl;
113 }
114 
115 #if 0
116 /*  ---- GIDI_settings_groups_from_bdfls ----  */
117 /*
118 =========================================================
119 */
120 GIDI_settings_groups_from_bdfls::GIDI_settings_groups_from_bdfls( std::string const &fileName ) {
121 
122     initialize( fileName.c_str( ) );
123 }
124 /*
125 =========================================================
126 */
127 GIDI_settings_groups_from_bdfls::GIDI_settings_groups_from_bdfls( char const *fileName ) {
128 
129     initialize( fileName );
130 }
131 /*
132 =========================================================
133 */
134 GIDI_settings_groups_from_bdfls::GIDI_settings_groups_from_bdfls( cbdfls_file const *bdfls ) {
135 
136     initialize2( bdfls );
137 }
138 /*
139 =========================================================
140 */
141 void GIDI_settings_groups_from_bdfls::initialize( char const *fileName ) {
142 
143     cbdfls_file *bdfls;
144     cbdflsErrors Error;
145 
146     if( ( bdfls = cbdflsOpen( fileName, &Error ) ) == NULL ) throw Error;
147     initialize2( bdfls );
148     cbdflsRelease( bdfls );
149 }
150 /*
151 =========================================================
152 */
153 void GIDI_settings_groups_from_bdfls::initialize2( cbdfls_file const *bdfls ) {
154 
155     int ng, ngbs, *gids;
156     double *boundaries;
157     std::string label( "" );
158     char cLabel[100];
159 
160     ng = cbdflsGIDs( (cbdfls_file *) bdfls, &gids );
161     for( int ig = 0; ig < ng; ++ig ) {
162         ngbs = cbdflsGetGroup( (cbdfls_file *) bdfls, gids[ig], &boundaries );
163         snprintf( cLabel, sizeof xLabel, "LLNL_gid_%.3d", gids[ig] );
164         label = cLabel;
165         mGroups.push_back( GIDI_settings_group( label, ngbs, boundaries ) );
166     }
167 }
168 /*
169 =========================================================
170 */
171 GIDI_settings_groups_from_bdfls::~GIDI_settings_groups_from_bdfls( ) {
172 
173 }
174 /*
175 =========================================================
176 */
177 GIDI_settings_group GIDI_settings_groups_from_bdfls::getViaGID( int gid ) const {
178 
179     std::string label( "" );
180     char cLabel[100];
181 
182     snprintf( cLabel, sizeof cLabel, "LLNL_gid_%.3d", gid );
183     label = cLabel;
184     for( int ig = 0; ig < (int) mGroups.size( ); ++ig ) {
185         if( mGroups[ig].isLabel( label ) ) return( mGroups[ig] );
186     }
187     throw 1;
188 }
189 /*
190 =========================================================
191 */
192 std::vector<std::string> GIDI_settings_groups_from_bdfls::getLabels( void ) const {
193 
194     int size = (int) mGroups.size( );
195     std::vector<std::string> labels( size );
196 
197     for( int if1 = 0; if1 < size; ++if1 ) labels[if1] = mGroups[if1].getLabel( );
198     return( labels );
199 }
200 /*
201 =========================================================
202 */
203 std::vector<int> GIDI_settings_groups_from_bdfls::getGIDs( void ) const {
204 
205     int size = (int) mGroups.size( );
206     std::vector<int> fids( size );
207     char *e;
208 
209     for( int if1 = 0; if1 < size; ++if1 ) {
210         fids[if1] = (int) strtol( &(mGroups[if1].getLabel( ).c_str( )[9]), &e, 10 );
211     }
212     return( fids );
213 }
214 /*
215 =========================================================
216 */
217 void GIDI_settings_groups_from_bdfls::print( bool outline, int valuesPerLine ) const {
218 
219     int ngs = (int) mGroups.size( );
220 
221     std::cout << "BDFLS GROUPs: number of groups = " << ngs << std::endl;
222     for( int if1 = 0; if1 < ngs ; ++if1 ) mGroups[if1].print( outline, valuesPerLine );
223 }
224 #endif
225