mirror of
https://github.com/cosmo-sims/MUSIC.git
synced 2024-09-19 17:03:46 +02:00
added some more checks for errors in the .conf files
This commit is contained in:
parent
d4c0e2b701
commit
1fb3a02770
4 changed files with 56 additions and 20 deletions
|
@ -62,7 +62,10 @@ public:
|
|||
if( cf.containsKey("setup","region_point_shift") )
|
||||
{
|
||||
std::string point_shift = cf.getValue<std::string>("setup","region_point_shift");
|
||||
sscanf( point_shift.c_str(), "%d,%d,%d", &shift[0],&shift[1],&shift[2] );
|
||||
if(sscanf( point_shift.c_str(), "%d,%d,%d", &shift[0],&shift[1],&shift[2] )!=3){
|
||||
LOGERR("Error parsing triple for region_point_shift");
|
||||
throw std::runtime_error("Error parsing triple for region_point_shift");
|
||||
}
|
||||
unsigned point_levelmin = cf.getValue<unsigned>("setup","region_point_levelmin");
|
||||
|
||||
apply_shift( pp.size()/3, &pp[0], shift, point_levelmin );
|
||||
|
|
|
@ -572,7 +572,10 @@ public:
|
|||
if( cf.containsKey("setup","region_point_shift") )
|
||||
{
|
||||
std::string point_shift = cf.getValue<std::string>("setup","region_point_shift");
|
||||
sscanf( point_shift.c_str(), "%d,%d,%d", &shift[0],&shift[1],&shift[2] );
|
||||
if(sscanf( point_shift.c_str(), "%d,%d,%d", &shift[0],&shift[1],&shift[2] )!=3){
|
||||
LOGERR("Error parsing triple for region_point_shift");
|
||||
throw std::runtime_error("Error parsing triple for region_point_shift");
|
||||
}
|
||||
unsigned point_levelmin = cf.getValue<unsigned>("setup","region_point_levelmin");
|
||||
|
||||
apply_shift( pp.size()/3, &pp[0], shift, point_levelmin );
|
||||
|
@ -589,14 +592,25 @@ public:
|
|||
std::string strtmp;
|
||||
|
||||
strtmp = cf.getValue<std::string>("setup","region_ellipsoid_matrix[0]");
|
||||
sscanf( strtmp.c_str(), "%lf,%lf,%lf", &A[0],&A[1],&A[2] );
|
||||
if(sscanf( strtmp.c_str(), "%lf,%lf,%lf", &A[0],&A[1],&A[2] )!=3){
|
||||
LOGERR("Error parsing triple for region_ellipsoid_matrix[0]");
|
||||
throw std::runtime_error("Error parsing triple for region_ellipsoid_matrix[0]");
|
||||
}
|
||||
strtmp = cf.getValue<std::string>("setup","region_ellipsoid_matrix[1]");
|
||||
sscanf( strtmp.c_str(), "%lf,%lf,%lf", &A[3],&A[4],&A[5] );
|
||||
if(sscanf( strtmp.c_str(), "%lf,%lf,%lf", &A[3],&A[4],&A[5] )!=3){
|
||||
LOGERR("Error parsing triple for region_ellipsoid_matrix[1]");
|
||||
throw std::runtime_error("Error parsing triple for region_ellipsoid_matrix[1]");
|
||||
}
|
||||
strtmp = cf.getValue<std::string>("setup","region_ellipsoid_matrix[2]");
|
||||
sscanf( strtmp.c_str(), "%lf,%lf,%lf", &A[6],&A[7],&A[8] );
|
||||
|
||||
if(sscanf( strtmp.c_str(), "%lf,%lf,%lf", &A[6],&A[7],&A[8] )!=3){
|
||||
LOGERR("Error parsing triple for region_ellipsoid_matrix[2]");
|
||||
throw std::runtime_error("Error parsing triple for region_ellipsoid_matrix[2]");
|
||||
}
|
||||
strtmp = cf.getValue<std::string>("setup","region_ellipsoid_center");
|
||||
sscanf( strtmp.c_str(), "%lf,%lf,%lf", &c[0],&c[1],&c[2] );
|
||||
if(sscanf( strtmp.c_str(), "%lf,%lf,%lf", &c[0],&c[1],&c[2] )!=3){
|
||||
LOGERR("Error parsing triple for region_ellipsoid_center");
|
||||
throw std::runtime_error("Error parsing triple for region_ellipsoid_center");
|
||||
}
|
||||
|
||||
pellip_[levelmax_] = new min_ellipsoid( A, c );
|
||||
|
||||
|
|
16
random.cc
16
random.cc
|
@ -1384,25 +1384,33 @@ void random_number_generator<rng,T>::parse_rand_parameters( void )
|
|||
{
|
||||
char seedstr[128];
|
||||
std::string tempstr;
|
||||
bool noseed = false;
|
||||
sprintf(seedstr,"seed[%d]",i);
|
||||
if( pcf_->containsKey( "random", seedstr ) )
|
||||
tempstr = pcf_->getValue<std::string>( "random", seedstr );
|
||||
else
|
||||
else{
|
||||
// "-2" means that no seed entry was found for that level
|
||||
tempstr = std::string("-2");
|
||||
noseed = true;
|
||||
}
|
||||
|
||||
if( is_number( tempstr ) )
|
||||
{
|
||||
long ltemp;
|
||||
pcf_->convert( tempstr, ltemp );
|
||||
rngfnames_.push_back( "" );
|
||||
if( ltemp < 0 )
|
||||
if( noseed )//ltemp < 0 )
|
||||
//... generate some dummy seed which only depends on the level, negative so we know it's not
|
||||
//... an actual seed and thus should not be used as a constraint for coarse levels
|
||||
//rngseeds_.push_back( -abs((unsigned)(ltemp-i)%123+(unsigned)(ltemp+827342523521*i)%123456789) );
|
||||
rngseeds_.push_back( -abs((long)(ltemp-i)%123+(long)(ltemp+7342523521*i)%123456789) );
|
||||
else
|
||||
else{
|
||||
if( ltemp <= 0 ){
|
||||
LOGERR("Specified seed [random]/%s needs to be a number >0!",seedstr);
|
||||
throw std::runtime_error("Seed values need to be >0");
|
||||
}
|
||||
rngseeds_.push_back( ltemp );
|
||||
}
|
||||
}else{
|
||||
rngfnames_.push_back( tempstr );
|
||||
rngseeds_.push_back(-1);
|
||||
|
@ -1415,7 +1423,7 @@ void random_number_generator<rng,T>::parse_rand_parameters( void )
|
|||
levelmin_seed_ = -1;
|
||||
for( unsigned ilevel = 0; ilevel < rngseeds_.size(); ++ilevel )
|
||||
{
|
||||
if( levelmin_seed_ < 0 && (rngfnames_[ilevel].size() > 0 || rngseeds_[ilevel] > 0) )
|
||||
if( levelmin_seed_ < 0 && (rngfnames_[ilevel].size() > 0 || rngseeds_[ilevel] >= 0) )
|
||||
levelmin_seed_ = ilevel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,12 +94,18 @@ public:
|
|||
{
|
||||
temp = pcf_->getValue<std::string>( "setup", "ref_extent" );
|
||||
std::remove_if(temp.begin(),temp.end(),isspace);
|
||||
sscanf( temp.c_str(), "%lf,%lf,%lf", &lxref_[0],&lxref_[1],&lxref_[2] );
|
||||
if(sscanf( temp.c_str(), "%lf,%lf,%lf", &lxref_[0],&lxref_[1],&lxref_[2] )!=3){
|
||||
LOGERR("Error parsing triple for ref_extent");
|
||||
throw std::runtime_error("Error parsing triple for ref_extent");
|
||||
}
|
||||
bhave_nref_ = false;
|
||||
}else if( pcf_->containsKey("setup","ref_dims") ){
|
||||
temp = pcf_->getValue<std::string>("setup","ref_dims");
|
||||
std::remove_if(temp.begin(),temp.end(),isspace);
|
||||
sscanf( temp.c_str(), "%ld,%ld,%ld", &lnref_[0],&lnref_[1],&lnref_[2] );
|
||||
if(sscanf( temp.c_str(), "%ld,%ld,%ld", &lnref_[0],&lnref_[1],&lnref_[2] )!=3){
|
||||
LOGERR("Error parsing triple for ref_dims");
|
||||
throw std::runtime_error("Error parsing triple for ref_dims");
|
||||
}
|
||||
bhave_nref_ = true;
|
||||
|
||||
lxref_[0] = lnref_[0] * 1.0/(double)(1<<levelmax_);
|
||||
|
@ -111,7 +117,10 @@ public:
|
|||
{
|
||||
temp = pcf_->getValue<std::string>( "setup", "ref_center" );
|
||||
std::remove_if(temp.begin(),temp.end(),isspace);
|
||||
sscanf( temp.c_str(), "%lf,%lf,%lf", &xcref_[0], &xcref_[1], &xcref_[2] );
|
||||
if(sscanf( temp.c_str(), "%lf,%lf,%lf", &xcref_[0], &xcref_[1], &xcref_[2] )!=3){
|
||||
LOGERR("Error parsing triple for ref_center");
|
||||
throw std::runtime_error("Error parsing triple for ref_center");
|
||||
}
|
||||
x0ref_[0] = fmod( xcref_[0]-0.5*lxref_[0]+1.0,1.0);
|
||||
x0ref_[1] = fmod( xcref_[1]-0.5*lxref_[1]+1.0,1.0);
|
||||
x0ref_[2] = fmod( xcref_[2]-0.5*lxref_[2]+1.0,1.0);
|
||||
|
@ -119,8 +128,10 @@ public:
|
|||
}else if( pcf_->containsKey("setup","ref_offset") ){
|
||||
temp = pcf_->getValue<std::string>( "setup", "ref_offset" );
|
||||
std::remove_if(temp.begin(),temp.end(),isspace);
|
||||
sscanf( temp.c_str(), "%lf,%lf,%lf", &x0ref_[0], &x0ref_[1], &x0ref_[2] );
|
||||
|
||||
if(sscanf( temp.c_str(), "%lf,%lf,%lf", &x0ref_[0], &x0ref_[1], &x0ref_[2] )!=3){
|
||||
LOGERR("Error parsing triple for ref_offset");
|
||||
throw std::runtime_error("Error parsing triple for ref_offset");
|
||||
}
|
||||
xcref_[0] = fmod( x0ref_[0]+0.5*lxref_[0], 1.0 );
|
||||
xcref_[1] = fmod( x0ref_[1]+0.5*lxref_[1], 1.0 );
|
||||
xcref_[2] = fmod( x0ref_[2]+0.5*lxref_[2], 1.0 );
|
||||
|
|
Loading…
Reference in a new issue