1
0
Fork 0
mirror of https://github.com/cosmo-sims/MUSIC.git synced 2024-09-19 17:03:46 +02:00

replaced all sprintf by snprintf, cleaned up some other warnings

This commit is contained in:
Oliver Hahn 2023-02-14 17:51:46 -08:00
parent 6b32a7d6e4
commit 16bdb25e21
23 changed files with 2742 additions and 2797 deletions

View file

@ -191,7 +191,7 @@ constraint_set::constraint_set( config_file& cf, transfer_function *ptf )
{ {
char temp1[128]; char temp1[128];
std::string temp2; std::string temp2;
sprintf(temp1,"constraint[%u].type",i); snprintf(temp1,128,"constraint[%u].type",i);
if( cf.contains_key( "constraints", temp1 ) ) if( cf.contains_key( "constraints", temp1 ) )
{ {
std::string str_type = cf.get_value<std::string>( "constraints", temp1 ); std::string str_type = cf.get_value<std::string>( "constraints", temp1 );
@ -204,17 +204,17 @@ constraint_set::constraint_set( config_file& cf, transfer_function *ptf )
new_c.type = constr_type_map[ str_type ]; new_c.type = constr_type_map[ str_type ];
//... read position of constraint //... read position of constraint
sprintf(temp1,"constraint[%u].pos",i); snprintf(temp1,128,"constraint[%u].pos",i);
temp2 = cf.get_value<std::string>( "constraints", temp1 ); temp2 = cf.get_value<std::string>( "constraints", temp1 );
sscanf(temp2.c_str(), "%lf,%lf,%lf", &new_c.x, &new_c.y, &new_c.z); sscanf(temp2.c_str(), "%lf,%lf,%lf", &new_c.x, &new_c.y, &new_c.z);
if( new_c.type == halo) if( new_c.type == halo)
{ {
//.. halo type constraints take mass and collapse redshift //.. halo type constraints take mass and collapse redshift
sprintf(temp1,"constraint[%u].mass",i); snprintf(temp1,128,"constraint[%u].mass",i);
double mass = cf.get_value<double>( "constraints", temp1 ); double mass = cf.get_value<double>( "constraints", temp1 );
sprintf(temp1,"constraint[%u].zform",i); snprintf(temp1,128,"constraint[%u].zform",i);
double zcoll = cf.get_value<double>( "constraints", temp1 ); double zcoll = cf.get_value<double>( "constraints", temp1 );
new_c.Rg = pow((mass/pow(2.*M_PI,1.5)/rhom),1./3.); new_c.Rg = pow((mass/pow(2.*M_PI,1.5)/rhom),1./3.);
@ -226,15 +226,15 @@ constraint_set::constraint_set( config_file& cf, transfer_function *ptf )
else if( new_c.type == peak ) else if( new_c.type == peak )
{ {
//... peak type constraints take a scale and a peak height //... peak type constraints take a scale and a peak height
//sprintf(temp1,"constraint[%u].Rg",i); //snprintf(temp1,128,"constraint[%u].Rg",i);
//new_c.Rg = cf.get_value<double>( "constraints", temp1 ); //new_c.Rg = cf.get_value<double>( "constraints", temp1 );
//double mass = pow(new_c.Rg,3.0)*rhom*pow(2.*M_PI,1.5); //double mass = pow(new_c.Rg,3.0)*rhom*pow(2.*M_PI,1.5);
sprintf(temp1,"constraint[%u].mass",i); snprintf(temp1,128,"constraint[%u].mass",i);
double mass = cf.get_value<double>( "constraints", temp1 ); double mass = cf.get_value<double>( "constraints", temp1 );
new_c.Rg = pow((mass/pow(2.*M_PI,1.5)/rhom),1./3.); new_c.Rg = pow((mass/pow(2.*M_PI,1.5)/rhom),1./3.);
double Rtophat = pow(mass/4.0*3.0/M_PI/rhom,1./3.); double Rtophat = pow(mass/4.0*3.0/M_PI/rhom,1./3.);
sprintf(temp1,"constraint[%u].nu",i); snprintf(temp1,128,"constraint[%u].nu",i);
double nu = cf.get_value<double>( "constraints", temp1 ); double nu = cf.get_value<double>( "constraints", temp1 );
std::vector<double> z,sigma; std::vector<double> z,sigma;

View file

@ -133,7 +133,7 @@ public:
char out[1024]; char out[1024];
va_list argptr; va_list argptr;
va_start(argptr, str); va_start(argptr, str);
vsprintf(out, str, argptr); vsnprintf(out, 1024, str, argptr );
va_end(argptr); va_end(argptr);
std::string out_string = std::string(out); std::string out_string = std::string(out);
out_string.erase(std::remove(out_string.begin(), out_string.end(), '\n'), out_string.erase(std::remove(out_string.begin(), out_string.end(), '\n'),

View file

@ -231,12 +231,12 @@ void store_grid_structure(config_file &cf, const refinement_hierarchy &rh)
{ {
for (int j = 0; j < 3; ++j) for (int j = 0; j < 3; ++j)
{ {
sprintf(str1, "offset(%d,%d)", i, j); snprintf(str1, 128, "offset(%d,%d)", i, j);
sprintf(str2, "%ld", rh.offset(i, j)); snprintf(str2, 128, "%ld", rh.offset(i, j));
cf.insert_value("setup", str1, str2); cf.insert_value("setup", str1, str2);
sprintf(str1, "size(%d,%d)", i, j); snprintf(str1, 128, "size(%d,%d)", i, j);
sprintf(str2, "%ld", rh.size(i, j)); snprintf(str2, 128, "%ld", rh.size(i, j));
cf.insert_value("setup", str1, str2); cf.insert_value("setup", str1, str2);
} }
} }
@ -391,7 +391,7 @@ int main(int argc, const char *argv[])
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
char logfname[128]; char logfname[128];
sprintf(logfname, "%s_log.txt", argv[1]); snprintf(logfname, 128, "%s_log.txt", argv[1]);
music::logger::set_output(logfname); music::logger::set_output(logfname);
time_t ltime = time(NULL); time_t ltime = time(NULL);
music::ilog.Print("Opening log file \'%s\'.", logfname); music::ilog.Print("Opening log file \'%s\'.", logfname);
@ -484,11 +484,11 @@ int main(int argc, const char *argv[])
// //
{ {
char tmpstr[128]; char tmpstr[128];
sprintf(tmpstr, "%.12g", cosmo.pnorm); snprintf(tmpstr, 128, "%.12g", cosmo.pnorm);
cf.insert_value("cosmology", "pnorm", tmpstr); cf.insert_value("cosmology", "pnorm", tmpstr);
sprintf(tmpstr, "%.12g", cosmo.dplus); snprintf(tmpstr, 128, "%.12g", cosmo.dplus);
cf.insert_value("cosmology", "dplus", tmpstr); cf.insert_value("cosmology", "dplus", tmpstr);
sprintf(tmpstr, "%.12g", cosmo.vfact); snprintf(tmpstr, 128, "%.12g", cosmo.vfact);
cf.insert_value("cosmology", "vfact", tmpstr); cf.insert_value("cosmology", "vfact", tmpstr);
} }

View file

@ -1347,11 +1347,11 @@ public:
} }
char strtmp[32]; char strtmp[32];
sprintf(strtmp, "%ld", xshift_[0]); snprintf(strtmp, 32, "%ld", xshift_[0]);
cf_.insert_value("setup", "shift_x", strtmp); cf_.insert_value("setup", "shift_x", strtmp);
sprintf(strtmp, "%ld", xshift_[1]); snprintf(strtmp, 32, "%ld", xshift_[1]);
cf_.insert_value("setup", "shift_y", strtmp); cf_.insert_value("setup", "shift_y", strtmp);
sprintf(strtmp, "%ld", xshift_[2]); snprintf(strtmp, 32, "%ld", xshift_[2]);
cf_.insert_value("setup", "shift_z", strtmp); cf_.insert_value("setup", "shift_z", strtmp);
rshift_[0] = -(double)xshift_[0] / ncoarse; rshift_[0] = -(double)xshift_[0] / ncoarse;

File diff suppressed because it is too large Load diff

View file

@ -367,7 +367,7 @@ double solver<S, I, O>::compute_error(const MeshvarBnd<real_t> &u, const Meshvar
ny = u.size(1), ny = u.size(1),
nz = u.size(2); nz = u.size(2);
double err = 0.0, err2 = 0.0; double err = 0.0; //, err2 = 0.0;
size_t count = 0; size_t count = 0;
double h = 1.0 / (1ul << ilevel), h2 = h * h; double h = 1.0 / (1ul << ilevel), h2 = h * h;
@ -642,5 +642,3 @@ void solver<S, I, O>::make_periodic(MeshvarBnd<real_t> *u)
} }
END_MULTIGRID_NAMESPACE END_MULTIGRID_NAMESPACE

View file

@ -61,7 +61,7 @@ protected:
char str[128]; char str[128];
for( unsigned i=levelmin_; i<=levelmax_; ++i ) for( unsigned i=levelmin_; i<=levelmax_; ++i )
{ {
sprintf( str, "%s(%u,%d)", name.c_str(), i, icomp ); snprintf( str, 128, "%s(%u,%d)", name.c_str(), i, icomp );
*oit = cf_.get_value<unsigned>( "setup", str ); *oit = cf_.get_value<unsigned>( "setup", str );
++oit; ++oit;
} }

View file

@ -227,7 +227,6 @@ template<typename T >
inline void HDFReadSelect( const std::string Filename, const std::string ObjName, const std::vector<unsigned>& ii, std::vector<T> &Data ){ inline void HDFReadSelect( const std::string Filename, const std::string ObjName, const std::vector<unsigned>& ii, std::vector<T> &Data ){
hid_t HDF_Type, HDF_FileID, HDF_DatasetID, HDF_DataspaceID, HDF_MemspaceID; hid_t HDF_Type, HDF_FileID, HDF_DatasetID, HDF_DataspaceID, HDF_MemspaceID;
hsize_t HDF_StorageSize;
HDF_Type = GetDataType<T>(); HDF_Type = GetDataType<T>();

View file

@ -320,7 +320,7 @@ public:
void write_dm_velocity( int coord, const grid_hierarchy& gh ) void write_dm_velocity( int coord, const grid_hierarchy& gh )
{ {
char nyxname[256]; char nyxname[256];
sprintf( nyxname, "ParticleVelocities_%c", (char)('x'+coord) ); snprintf( nyxname, 256, "ParticleVelocities_%c", (char)('x'+coord) );
double vunit = 1.0/(1.225e2*sqrt(the_sim_header.omega_m/the_sim_header.a_start)); double vunit = 1.0/(1.225e2*sqrt(the_sim_header.omega_m/the_sim_header.a_start));
@ -331,7 +331,7 @@ public:
void write_dm_position( int coord, const grid_hierarchy& gh ) void write_dm_position( int coord, const grid_hierarchy& gh )
{ {
char nyxname[256]; char nyxname[256];
sprintf( nyxname, "ParticleDisplacements_%c", (char)('x'+coord) ); snprintf( nyxname, 256,"ParticleDisplacements_%c", (char)('x'+coord) );
//dump_grid_data( nyxname, gh ); //dump_grid_data( nyxname, gh );
dump_grid_data(the_sim_header.particle_idx+coord, nyxname, gh); dump_grid_data(the_sim_header.particle_idx+coord, nyxname, gh);
@ -349,7 +349,7 @@ public:
double vunit = 1.0/(1.225e2*sqrt(the_sim_header.omega_m/the_sim_header.a_start)); double vunit = 1.0/(1.225e2*sqrt(the_sim_header.omega_m/the_sim_header.a_start));
char nyxname[256]; char nyxname[256];
sprintf( nyxname, "GridVelocities_%c", (char)('x'+coord) ); snprintf( nyxname, 256, "GridVelocities_%c", (char)('x'+coord) );
dump_grid_data(coord+1, nyxname, gh); dump_grid_data(coord+1, nyxname, gh);
} }
@ -363,7 +363,7 @@ public:
void write_gas_density( const grid_hierarchy& gh ) void write_gas_density( const grid_hierarchy& gh )
{ {
char nyxname[256]; char nyxname[256];
sprintf( nyxname, "density" ); snprintf( nyxname, 256, "density" );
//FIXME factor and add have to be adjusted to the //FIXME factor and add have to be adjusted to the
//corresponding nyx units... //corresponding nyx units...
dump_grid_data(0, nyxname, gh); dump_grid_data(0, nyxname, gh);

View file

@ -300,12 +300,12 @@ protected:
// generate all temp file names // generate all temp file names
char fnx[256], fny[256], fnz[256], fnvx[256], fnvy[256], fnvz[256]; char fnx[256], fny[256], fnz[256], fnvx[256], fnvy[256], fnvz[256];
sprintf(fnx, "___ic_temp_%05d.bin", 100 * id_dm_pos + 0); snprintf(fnx, 256, "___ic_temp_%05d.bin", 100 * id_dm_pos + 0);
sprintf(fny, "___ic_temp_%05d.bin", 100 * id_dm_pos + 1); snprintf(fny, 256, "___ic_temp_%05d.bin", 100 * id_dm_pos + 1);
sprintf(fnz, "___ic_temp_%05d.bin", 100 * id_dm_pos + 2); snprintf(fnz, 256, "___ic_temp_%05d.bin", 100 * id_dm_pos + 2);
sprintf(fnvx, "___ic_temp_%05d.bin", 100 * id_dm_vel + 0); snprintf(fnvx, 256, "___ic_temp_%05d.bin", 100 * id_dm_vel + 0);
sprintf(fnvy, "___ic_temp_%05d.bin", 100 * id_dm_vel + 1); snprintf(fnvy, 256, "___ic_temp_%05d.bin", 100 * id_dm_vel + 1);
sprintf(fnvz, "___ic_temp_%05d.bin", 100 * id_dm_vel + 2); snprintf(fnvz, 256, "___ic_temp_%05d.bin", 100 * id_dm_vel + 2);
// create buffers for temporary data // create buffers for temporary data
T_store *tmp1, *tmp2, *tmp3, *tmp4, *tmp5, *tmp6; T_store *tmp1, *tmp2, *tmp3, *tmp4, *tmp5, *tmp6;
@ -420,12 +420,12 @@ protected:
// generate all temp file names // generate all temp file names
char fnx[256], fny[256], fnz[256], fnvx[256], fnvy[256], fnvz[256]; char fnx[256], fny[256], fnz[256], fnvx[256], fnvy[256], fnvz[256];
sprintf(fnx, "___ic_temp_%05d.bin", 100 * id_gas_pos + 0); snprintf(fnx, 256, "___ic_temp_%05d.bin", 100 * id_gas_pos + 0);
sprintf(fny, "___ic_temp_%05d.bin", 100 * id_gas_pos + 1); snprintf(fny, 256, "___ic_temp_%05d.bin", 100 * id_gas_pos + 1);
sprintf(fnz, "___ic_temp_%05d.bin", 100 * id_gas_pos + 2); snprintf(fnz, 256, "___ic_temp_%05d.bin", 100 * id_gas_pos + 2);
sprintf(fnvx, "___ic_temp_%05d.bin", 100 * id_gas_vel + 0); snprintf(fnvx, 256, "___ic_temp_%05d.bin", 100 * id_gas_vel + 0);
sprintf(fnvy, "___ic_temp_%05d.bin", 100 * id_gas_vel + 1); snprintf(fnvy, 256, "___ic_temp_%05d.bin", 100 * id_gas_vel + 1);
sprintf(fnvz, "___ic_temp_%05d.bin", 100 * id_gas_vel + 2); snprintf(fnvz, 256, "___ic_temp_%05d.bin", 100 * id_gas_vel + 2);
// create buffers for temporary data // create buffers for temporary data
T_store *tmp1, *tmp2, *tmp3, *tmp4, *tmp5, *tmp6; T_store *tmp1, *tmp2, *tmp3, *tmp4, *tmp5, *tmp6;
@ -645,7 +645,7 @@ public:
double xfac = (double)header_.NGRIDC; double xfac = (double)header_.NGRIDC;
char temp_fname[256]; char temp_fname[256];
sprintf(temp_fname, "___ic_temp_%05d.bin", 100 * id_dm_pos + coord); snprintf(temp_fname, 256, "___ic_temp_%05d.bin", 100 * id_dm_pos + coord);
std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc); std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc);
size_t blksize = sizeof(T_store) * nptot; size_t blksize = sizeof(T_store) * nptot;
@ -709,7 +709,7 @@ public:
double vfac = (header_.aexpN * header_.NGRIDC) / (100.0); double vfac = (header_.aexpN * header_.NGRIDC) / (100.0);
char temp_fname[256]; char temp_fname[256];
sprintf(temp_fname, "___ic_temp_%05d.bin", 100 * id_dm_vel + coord); snprintf(temp_fname, 256, "___ic_temp_%05d.bin", 100 * id_dm_vel + coord);
std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc); std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc);
size_t blksize = sizeof(T_store) * nptot; size_t blksize = sizeof(T_store) * nptot;
@ -772,7 +772,7 @@ public:
double xfac = (double)header_.NGRIDC; double xfac = (double)header_.NGRIDC;
char temp_fname[256]; char temp_fname[256];
sprintf(temp_fname, "___ic_temp_%05d.bin", 100 * id_gas_pos + coord); snprintf(temp_fname, 256, "___ic_temp_%05d.bin", 100 * id_gas_pos + coord);
std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc); std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc);
size_t blksize = sizeof(T_store) * nptot; size_t blksize = sizeof(T_store) * nptot;
@ -836,7 +836,7 @@ public:
double vfac = (header_.aexpN * header_.NGRIDC) / (100.0); double vfac = (header_.aexpN * header_.NGRIDC) / (100.0);
char temp_fname[256]; char temp_fname[256];
sprintf(temp_fname, "___ic_temp_%05d.bin", 100 * id_gas_vel + coord); snprintf(temp_fname, 256, "___ic_temp_%05d.bin", 100 * id_gas_vel + coord);
std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc); std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc);
size_t blksize = sizeof(T_store) * nptot; size_t blksize = sizeof(T_store) * nptot;

View file

@ -297,12 +297,12 @@ class cart_output_plugin : public output_plugin
// generate all temp file names // generate all temp file names
char fnx[256],fny[256],fnz[256],fnvx[256],fnvy[256],fnvz[256]; char fnx[256],fny[256],fnz[256],fnvx[256],fnvy[256],fnvz[256];
sprintf( fnx, "___ic_temp_%05d.bin", 100*id_dm_pos+0 ); snprintf( fnx, 256, "___ic_temp_%05d.bin", 100*id_dm_pos+0 );
sprintf( fny, "___ic_temp_%05d.bin", 100*id_dm_pos+1 ); snprintf( fny, 256, "___ic_temp_%05d.bin", 100*id_dm_pos+1 );
sprintf( fnz, "___ic_temp_%05d.bin", 100*id_dm_pos+2 ); snprintf( fnz, 256, "___ic_temp_%05d.bin", 100*id_dm_pos+2 );
sprintf( fnvx, "___ic_temp_%05d.bin", 100*id_dm_vel+0 ); snprintf( fnvx, 256, "___ic_temp_%05d.bin", 100*id_dm_vel+0 );
sprintf( fnvy, "___ic_temp_%05d.bin", 100*id_dm_vel+1 ); snprintf( fnvy, 256, "___ic_temp_%05d.bin", 100*id_dm_vel+1 );
sprintf( fnvz, "___ic_temp_%05d.bin", 100*id_dm_vel+2 ); snprintf( fnvz, 256, "___ic_temp_%05d.bin", 100*id_dm_vel+2 );
// create buffers for temporary data // create buffers for temporary data
T_store *tmp1, *tmp2, *tmp3, *tmp4, *tmp5, *tmp6; T_store *tmp1, *tmp2, *tmp3, *tmp4, *tmp5, *tmp6;
@ -422,13 +422,13 @@ class cart_output_plugin : public output_plugin
// generate all temp file names // generate all temp file names
char fnx[256],fny[256],fnz[256],fnvx[256],fnvy[256],fnvz[256],fnpma[256]; //add fields here char fnx[256],fny[256],fnz[256],fnvx[256],fnvy[256],fnvz[256],fnpma[256]; //add fields here
sprintf( fnx, "___ic_temp_%05d.bin", 100*id_gas_pos+0 ); snprintf( fnx, 256, "___ic_temp_%05d.bin", 100*id_gas_pos+0 );
sprintf( fny, "___ic_temp_%05d.bin", 100*id_gas_pos+1 ); snprintf( fny, 256, "___ic_temp_%05d.bin", 100*id_gas_pos+1 );
sprintf( fnz, "___ic_temp_%05d.bin", 100*id_gas_pos+2 ); snprintf( fnz, 256, "___ic_temp_%05d.bin", 100*id_gas_pos+2 );
sprintf( fnvx, "___ic_temp_%05d.bin", 100*id_gas_vel+0 ); snprintf( fnvx, 256, "___ic_temp_%05d.bin", 100*id_gas_vel+0 );
sprintf( fnvy, "___ic_temp_%05d.bin", 100*id_gas_vel+1 ); snprintf( fnvy, 256, "___ic_temp_%05d.bin", 100*id_gas_vel+1 );
sprintf( fnvz, "___ic_temp_%05d.bin", 100*id_gas_vel+2 ); snprintf( fnvz, 256, "___ic_temp_%05d.bin", 100*id_gas_vel+2 );
sprintf( fnpma, "___ic_temp_%05d.bin", 100*id_gas_pma ); //add fields here snprintf( fnpma,256, "___ic_temp_%05d.bin", 100*id_gas_pma ); //add fields here
// create buffers for temporary data // create buffers for temporary data
T_store *tmp1, *tmp2, *tmp3, *tmp4, *tmp5, *tmp6, *tmp7; //add fields here T_store *tmp1, *tmp2, *tmp3, *tmp4, *tmp5, *tmp6, *tmp7; //add fields here
@ -668,7 +668,7 @@ class cart_output_plugin : public output_plugin
double xfac = (double) header_.NGRIDC; double xfac = (double) header_.NGRIDC;
char temp_fname[256]; char temp_fname[256];
sprintf( temp_fname, "___ic_temp_%05d.bin", 100*id_dm_pos+coord ); snprintf( temp_fname, 256, "___ic_temp_%05d.bin", 100*id_dm_pos+coord );
std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc ); std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc );
size_t blksize = sizeof(T_store)*nptot; size_t blksize = sizeof(T_store)*nptot;
@ -746,7 +746,7 @@ class cart_output_plugin : public output_plugin
//snl exit(1); //snl exit(1);
char temp_fname[256]; char temp_fname[256];
sprintf( temp_fname, "___ic_temp_%05d.bin", 100*id_dm_vel+coord ); snprintf( temp_fname, 256, "___ic_temp_%05d.bin", 100*id_dm_vel+coord );
std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc ); std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc );
size_t blksize = sizeof(T_store)*nptot; size_t blksize = sizeof(T_store)*nptot;
@ -819,7 +819,7 @@ class cart_output_plugin : public output_plugin
} }
char temp_fname[256]; char temp_fname[256];
sprintf( temp_fname, "___ic_temp_%05d.bin", 100*id_gas_vel+coord ); snprintf( temp_fname, 256, "___ic_temp_%05d.bin", 100*id_gas_vel+coord );
std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc ); std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc );
size_t blksize = sizeof(T_store)*nptot; size_t blksize = sizeof(T_store)*nptot;
@ -873,7 +873,7 @@ class cart_output_plugin : public output_plugin
// write gas positions to cell centers // write gas positions to cell centers
for (int coord=0; coord < 3; coord++ ) { for (int coord=0; coord < 3; coord++ ) {
sprintf( temp_fname, "___ic_temp_%05d.bin", 100*id_gas_pos+coord ); snprintf( temp_fname, 256, "___ic_temp_%05d.bin", 100*id_gas_pos+coord );
std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc ); std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc );
ofs_temp.write( (char *)&blksize, sizeof(size_t) ); ofs_temp.write( (char *)&blksize, sizeof(size_t) );
@ -924,7 +924,7 @@ class cart_output_plugin : public output_plugin
{ {
double pmafac = header_.Omb0 / header_.Om0 ; double pmafac = header_.Omb0 / header_.Om0 ;
double pma; double pma;
sprintf( temp_fname, "___ic_temp_%05d.bin", 100*id_gas_pma); snprintf( temp_fname, 256, "___ic_temp_%05d.bin", 100*id_gas_pma);
std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc ); std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc );
ofs_temp.write( (char *)&blksize, sizeof(size_t) ); ofs_temp.write( (char *)&blksize, sizeof(size_t) );

View file

@ -106,11 +106,11 @@ protected:
size_t nsz[3] = {size_t(ng[2]), size_t(ng[1]), size_t(ng[0])}; size_t nsz[3] = {size_t(ng[2]), size_t(ng[1]), size_t(ng[0])};
if (levelmin_ != levelmax_) if (levelmin_ != levelmax_)
sprintf(enzoname, "%s.%d", fieldname.c_str(), ilevel - levelmin_); snprintf(enzoname, 256, "%s.%d", fieldname.c_str(), ilevel - levelmin_);
else else
sprintf(enzoname, "%s", fieldname.c_str()); snprintf(enzoname, 256, "%s", fieldname.c_str());
sprintf(filename, "%s/%s", fname_.c_str(), enzoname); snprintf(filename, 512, "%s/%s", fname_.c_str(), enzoname);
HDFCreateFile(filename); HDFCreateFile(filename);
write_sim_header(filename, the_sim_header); write_sim_header(filename, the_sim_header);
@ -221,11 +221,11 @@ protected:
size_t nsz[3] = {size_t(ng[2]), size_t(ng[1]), size_t(ng[0])}; size_t nsz[3] = {size_t(ng[2]), size_t(ng[1]), size_t(ng[0])};
if (levelmin_ != levelmax_) if (levelmin_ != levelmax_)
sprintf(enzoname, "%s.%d", fieldname.c_str(), ilevel - levelmin_); snprintf(enzoname, 256, "%s.%d", fieldname.c_str(), ilevel - levelmin_);
else else
sprintf(enzoname, "%s", fieldname.c_str()); snprintf(enzoname, 256, "%s", fieldname.c_str());
sprintf(filename, "%s/%s", fname_.c_str(), enzoname); snprintf(filename, 512, "%s/%s", fname_.c_str(), enzoname);
HDFCreateFile(filename); HDFCreateFile(filename);
write_sim_header(filename, the_sim_header); write_sim_header(filename, the_sim_header);
@ -355,7 +355,7 @@ public:
// write out a parameter file // write out a parameter file
sprintf(filename, "%s/parameter_file.txt", fname_.c_str()); snprintf(filename, 256, "%s/parameter_file.txt", fname_.c_str());
std::ofstream ofs(filename, std::ios::trunc); std::ofstream ofs(filename, std::ios::trunc);
@ -551,7 +551,7 @@ public:
void write_dm_velocity(int coord, const grid_hierarchy &gh) void write_dm_velocity(int coord, const grid_hierarchy &gh)
{ {
char enzoname[256]; char enzoname[256];
sprintf(enzoname, "ParticleVelocities_%c", (char)('x' + coord)); snprintf(enzoname, 256, "ParticleVelocities_%c", (char)('x' + coord));
double vunit = 1.0 / (1.225e2 * sqrt(the_sim_header.omega_m / the_sim_header.a_start)); double vunit = 1.0 / (1.225e2 * sqrt(the_sim_header.omega_m / the_sim_header.a_start));
@ -561,7 +561,7 @@ public:
void write_dm_position(int coord, const grid_hierarchy &gh) void write_dm_position(int coord, const grid_hierarchy &gh)
{ {
char enzoname[256]; char enzoname[256];
sprintf(enzoname, "ParticleDisplacements_%c", (char)('x' + coord)); snprintf(enzoname, 256, "ParticleDisplacements_%c", (char)('x' + coord));
dump_grid_data(enzoname, gh); dump_grid_data(enzoname, gh);
} }
@ -579,7 +579,7 @@ public:
double vunit = 1.0 / (1.225e2 * sqrt(the_sim_header.omega_m / the_sim_header.a_start)); double vunit = 1.0 / (1.225e2 * sqrt(the_sim_header.omega_m / the_sim_header.a_start));
char enzoname[256]; char enzoname[256];
sprintf(enzoname, "GridVelocities_%c", (char)('x' + coord)); snprintf(enzoname, 256, "GridVelocities_%c", (char)('x' + coord));
dump_grid_data(enzoname, gh, vunit); dump_grid_data(enzoname, gh, vunit);
} }
@ -592,7 +592,7 @@ public:
{ {
char enzoname[256]; char enzoname[256];
sprintf(enzoname, "GridDensity"); snprintf(enzoname, 256, "GridDensity");
dump_grid_data(enzoname, gh, the_sim_header.omega_b / the_sim_header.omega_m, 1.0); dump_grid_data(enzoname, gh, the_sim_header.omega_b / the_sim_header.omega_m, 1.0);
} }

View file

@ -134,7 +134,7 @@ protected:
assert(n2dist[i] == 0); assert(n2dist[i] == 0);
} }
std::ifstream &open_and_check(std::string ffname, size_t npart, size_t offset = 0) std::ifstream open_and_check(std::string ffname, size_t npart, size_t offset = 0)
{ {
std::ifstream ifs(ffname.c_str(), std::ios::binary); std::ifstream ifs(ffname.c_str(), std::ios::binary);
size_t blk; size_t blk;
@ -284,8 +284,8 @@ protected:
/*** positions ***/ /*** positions ***/
sprintf(fc, "___ic_temp_%05d.bin", 100 * id_dm_pos + icomp); snprintf(fc, 256, "___ic_temp_%05d.bin", 100 * id_dm_pos + icomp);
sprintf(fb, "___ic_temp_%05d.bin", 100 * id_gas_pos + icomp); snprintf(fb, 256, "___ic_temp_%05d.bin", 100 * id_gas_pos + icomp);
iffs1.open(fc, nptot, npfine * sizeof(T_store)); iffs1.open(fc, nptot, npfine * sizeof(T_store));
iffs2.open(fb, nptot, npfine * sizeof(T_store)); iffs2.open(fb, nptot, npfine * sizeof(T_store));
@ -315,8 +315,8 @@ protected:
/*** velocities ***/ /*** velocities ***/
sprintf(fc, "___ic_temp_%05d.bin", 100 * id_dm_vel + icomp); snprintf(fc, 256, "___ic_temp_%05d.bin", 100 * id_dm_vel + icomp);
sprintf(fb, "___ic_temp_%05d.bin", 100 * id_gas_vel + icomp); snprintf(fb, 256, "___ic_temp_%05d.bin", 100 * id_gas_vel + icomp);
iffs1.open(fc, nptot, npfine * sizeof(T_store)); iffs1.open(fc, nptot, npfine * sizeof(T_store));
iffs2.open(fb, nptot, npfine * sizeof(T_store)); iffs2.open(fb, nptot, npfine * sizeof(T_store));
@ -359,20 +359,20 @@ protected:
char fnx[256], fny[256], fnz[256], fnvx[256], fnvy[256], fnvz[256], fnm[256]; char fnx[256], fny[256], fnz[256], fnvx[256], fnvy[256], fnvz[256], fnm[256];
char fnbx[256], fnby[256], fnbz[256], fnbvx[256], fnbvy[256], fnbvz[256]; char fnbx[256], fnby[256], fnbz[256], fnbvx[256], fnbvy[256], fnbvz[256];
sprintf(fnx, "___ic_temp_%05d.bin", 100 * id_dm_pos + 0); snprintf(fnx, 256, "___ic_temp_%05d.bin", 100 * id_dm_pos + 0);
sprintf(fny, "___ic_temp_%05d.bin", 100 * id_dm_pos + 1); snprintf(fny, 256, "___ic_temp_%05d.bin", 100 * id_dm_pos + 1);
sprintf(fnz, "___ic_temp_%05d.bin", 100 * id_dm_pos + 2); snprintf(fnz, 256, "___ic_temp_%05d.bin", 100 * id_dm_pos + 2);
sprintf(fnvx, "___ic_temp_%05d.bin", 100 * id_dm_vel + 0); snprintf(fnvx, 256,"___ic_temp_%05d.bin", 100 * id_dm_vel + 0);
sprintf(fnvy, "___ic_temp_%05d.bin", 100 * id_dm_vel + 1); snprintf(fnvy, 256,"___ic_temp_%05d.bin", 100 * id_dm_vel + 1);
sprintf(fnvz, "___ic_temp_%05d.bin", 100 * id_dm_vel + 2); snprintf(fnvz, 256,"___ic_temp_%05d.bin", 100 * id_dm_vel + 2);
sprintf(fnm, "___ic_temp_%05d.bin", 100 * id_dm_mass); snprintf(fnm, 256, "___ic_temp_%05d.bin", 100 * id_dm_mass);
sprintf(fnbx, "___ic_temp_%05d.bin", 100 * id_gas_pos + 0); snprintf(fnbx, 256,"___ic_temp_%05d.bin", 100 * id_gas_pos + 0);
sprintf(fnby, "___ic_temp_%05d.bin", 100 * id_gas_pos + 1); snprintf(fnby, 256,"___ic_temp_%05d.bin", 100 * id_gas_pos + 1);
sprintf(fnbz, "___ic_temp_%05d.bin", 100 * id_gas_pos + 2); snprintf(fnbz, 256,"___ic_temp_%05d.bin", 100 * id_gas_pos + 2);
sprintf(fnbvx, "___ic_temp_%05d.bin", 100 * id_gas_vel + 0); snprintf(fnbvx,256,"___ic_temp_%05d.bin", 100 * id_gas_vel + 0);
sprintf(fnbvy, "___ic_temp_%05d.bin", 100 * id_gas_vel + 1); snprintf(fnbvy,256,"___ic_temp_%05d.bin", 100 * id_gas_vel + 1);
sprintf(fnbvz, "___ic_temp_%05d.bin", 100 * id_gas_vel + 2); snprintf(fnbvz,256,"___ic_temp_%05d.bin", 100 * id_gas_vel + 2);
pistream iffs1, iffs2, iffs3; pistream iffs1, iffs2, iffs3;
@ -440,7 +440,7 @@ protected:
if (nfiles_ > 1) if (nfiles_ > 1)
{ {
char ffname[256]; char ffname[256];
sprintf(ffname, "%s.%d", fname_.c_str(), ifile); snprintf(ffname, 256, "%s.%d", fname_.c_str(), ifile);
ofs_.open(ffname, std::ios::binary | std::ios::trunc); ofs_.open(ffname, std::ios::binary | std::ios::trunc);
} }
else else
@ -833,7 +833,7 @@ public:
for (unsigned ifile = 0; ifile < nfiles_; ++ifile) for (unsigned ifile = 0; ifile < nfiles_; ++ifile)
{ {
char ffname[256]; char ffname[256];
sprintf(ffname, "%s.%d", fname_.c_str(), ifile); snprintf(ffname, 256, "%s.%d", fname_.c_str(), ifile);
ofs_.open(ffname, std::ios::binary | std::ios::trunc); ofs_.open(ffname, std::ios::binary | std::ios::trunc);
if (!ofs_.good()) if (!ofs_.good())
{ {
@ -1011,7 +1011,7 @@ public:
temp_dat.reserve(block_buf_size_); temp_dat.reserve(block_buf_size_);
char temp_fname[256]; char temp_fname[256];
sprintf(temp_fname, "___ic_temp_%05d.bin", 100 * id_dm_mass); snprintf(temp_fname, 256, "___ic_temp_%05d.bin", 100 * id_dm_mass);
std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc); std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc);
size_t blksize = sizeof(T_store) * npcoarse; size_t blksize = sizeof(T_store) * npcoarse;
@ -1090,7 +1090,7 @@ public:
temp_data.reserve(block_buf_size_); temp_data.reserve(block_buf_size_);
char temp_fname[256]; char temp_fname[256];
sprintf(temp_fname, "___ic_temp_%05d.bin", 100 * id_dm_pos + coord); snprintf(temp_fname, 256, "___ic_temp_%05d.bin", 100 * id_dm_pos + coord);
std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc); std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc);
size_t blksize = sizeof(T_store) * npart; size_t blksize = sizeof(T_store) * npart;
@ -1167,7 +1167,7 @@ public:
size_t nwritten = 0; size_t nwritten = 0;
char temp_fname[256]; char temp_fname[256];
sprintf(temp_fname, "___ic_temp_%05d.bin", 100 * id_dm_vel + coord); snprintf(temp_fname, 256, "___ic_temp_%05d.bin", 100 * id_dm_vel + coord);
std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc); std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc);
size_t blksize = sizeof(T_store) * npart; size_t blksize = sizeof(T_store) * npart;
@ -1245,7 +1245,7 @@ public:
size_t nwritten = 0; size_t nwritten = 0;
char temp_fname[256]; char temp_fname[256];
sprintf(temp_fname, "___ic_temp_%05d.bin", 100 * id_gas_vel + coord); snprintf(temp_fname, 256, "___ic_temp_%05d.bin", 100 * id_gas_vel + coord);
std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc); std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc);
size_t blksize = sizeof(T_store) * npart; size_t blksize = sizeof(T_store) * npart;
@ -1314,7 +1314,7 @@ public:
temp_data.reserve(block_buf_size_); temp_data.reserve(block_buf_size_);
char temp_fname[256]; char temp_fname[256];
sprintf(temp_fname, "___ic_temp_%05d.bin", 100 * id_gas_pos + coord); snprintf(temp_fname, 256, "___ic_temp_%05d.bin", 100 * id_gas_pos + coord);
std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc); std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc);
size_t blksize = sizeof(T_store) * npart; size_t blksize = sizeof(T_store) * npart;

View file

@ -115,7 +115,7 @@ protected:
nc_pf[nfiles - 1] += ncoarse - nc_assigned; nc_pf[nfiles - 1] += ncoarse - nc_assigned;
} }
std::ifstream &open_and_check(std::string ffname, size_t npart) std::ifstream open_and_check(std::string ffname, size_t npart)
{ {
std::ifstream ifs(ffname.c_str(), std::ios::binary); std::ifstream ifs(ffname.c_str(), std::ios::binary);
unsigned long long blk, expected; unsigned long long blk, expected;
@ -253,20 +253,20 @@ protected:
char fnx[256], fny[256], fnz[256], fnvx[256], fnvy[256], fnvz[256], fnm[256]; char fnx[256], fny[256], fnz[256], fnvx[256], fnvy[256], fnvz[256], fnm[256];
char fnbx[256], fnby[256], fnbz[256], fnbvx[256], fnbvy[256], fnbvz[256]; char fnbx[256], fnby[256], fnbz[256], fnbvx[256], fnbvy[256], fnbvz[256];
sprintf(fnx, "___ic_temp_%05d.bin", 100 * id_dm_pos + 0); snprintf(fnx, 256, "___ic_temp_%05d.bin", 100 * id_dm_pos + 0);
sprintf(fny, "___ic_temp_%05d.bin", 100 * id_dm_pos + 1); snprintf(fny, 256, "___ic_temp_%05d.bin", 100 * id_dm_pos + 1);
sprintf(fnz, "___ic_temp_%05d.bin", 100 * id_dm_pos + 2); snprintf(fnz, 256, "___ic_temp_%05d.bin", 100 * id_dm_pos + 2);
sprintf(fnvx, "___ic_temp_%05d.bin", 100 * id_dm_vel + 0); snprintf(fnvx,256, "___ic_temp_%05d.bin", 100 * id_dm_vel + 0);
sprintf(fnvy, "___ic_temp_%05d.bin", 100 * id_dm_vel + 1); snprintf(fnvy,256, "___ic_temp_%05d.bin", 100 * id_dm_vel + 1);
sprintf(fnvz, "___ic_temp_%05d.bin", 100 * id_dm_vel + 2); snprintf(fnvz,256, "___ic_temp_%05d.bin", 100 * id_dm_vel + 2);
sprintf(fnm, "___ic_temp_%05d.bin", 100 * id_dm_mass); snprintf(fnm, 256, "___ic_temp_%05d.bin", 100 * id_dm_mass);
sprintf(fnbx, "___ic_temp_%05d.bin", 100 * id_gas_pos + 0); snprintf(fnbx, 256, "___ic_temp_%05d.bin", 100 * id_gas_pos + 0);
sprintf(fnby, "___ic_temp_%05d.bin", 100 * id_gas_pos + 1); snprintf(fnby, 256, "___ic_temp_%05d.bin", 100 * id_gas_pos + 1);
sprintf(fnbz, "___ic_temp_%05d.bin", 100 * id_gas_pos + 2); snprintf(fnbz, 256, "___ic_temp_%05d.bin", 100 * id_gas_pos + 2);
sprintf(fnbvx, "___ic_temp_%05d.bin", 100 * id_gas_vel + 0); snprintf(fnbvx,256, "___ic_temp_%05d.bin", 100 * id_gas_vel + 0);
sprintf(fnbvy, "___ic_temp_%05d.bin", 100 * id_gas_vel + 1); snprintf(fnbvy,256, "___ic_temp_%05d.bin", 100 * id_gas_vel + 1);
sprintf(fnbvz, "___ic_temp_%05d.bin", 100 * id_gas_vel + 2); snprintf(fnbvz,256, "___ic_temp_%05d.bin", 100 * id_gas_vel + 2);
pistream iffs1, iffs2, iffs3; pistream iffs1, iffs2, iffs3;
@ -342,7 +342,7 @@ protected:
if (nfiles_ > 1) if (nfiles_ > 1)
{ {
char ffname[256]; char ffname[256];
sprintf(ffname, "%s.%d", fname_.c_str(), ifile); snprintf(ffname, 256, "%s.%d", fname_.c_str(), ifile);
ofs_.open(ffname, std::ios::binary | std::ios::trunc); ofs_.open(ffname, std::ios::binary | std::ios::trunc);
} }
else else
@ -720,7 +720,7 @@ public:
for (unsigned ifile = 0; ifile < nfiles_; ++ifile) for (unsigned ifile = 0; ifile < nfiles_; ++ifile)
{ {
char ffname[256]; char ffname[256];
sprintf(ffname, "%s.%d", fname_.c_str(), ifile); snprintf(ffname, 256,"%s.%d", fname_.c_str(), ifile);
ofs_.open(ffname, std::ios::binary | std::ios::trunc); ofs_.open(ffname, std::ios::binary | std::ios::trunc);
if (!ofs_.good()) if (!ofs_.good())
{ {
@ -833,7 +833,7 @@ public:
temp_dat.reserve(block_buf_size_); temp_dat.reserve(block_buf_size_);
char temp_fname[256]; char temp_fname[256];
sprintf(temp_fname, "___ic_temp_%05d.bin", 100 * id_dm_mass); snprintf(temp_fname, 256, "___ic_temp_%05d.bin", 100 * id_dm_mass);
std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc); std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc);
unsigned long long blksize = sizeof(T_store) * npcoarse; unsigned long long blksize = sizeof(T_store) * npcoarse;
@ -936,7 +936,7 @@ public:
double xfac = header_.BoxSize; double xfac = header_.BoxSize;
char temp_fname[256]; char temp_fname[256];
sprintf(temp_fname, "___ic_temp_%05d.bin", 100 * id_dm_pos + coord); snprintf(temp_fname, 256, "___ic_temp_%05d.bin", 100 * id_dm_pos + coord);
std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc); std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc);
//... if baryons are present, then stagger the two fields //... if baryons are present, then stagger the two fields
@ -1141,7 +1141,7 @@ public:
unsigned long long blksize; unsigned long long blksize;
char temp_fname[256]; char temp_fname[256];
sprintf(temp_fname, "___ic_temp_%05d.bin", 100 * id_dm_vel + coord); snprintf(temp_fname, 256, "___ic_temp_%05d.bin", 100 * id_dm_vel + coord);
std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc); std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc);
if (!do_glass_) if (!do_glass_)
@ -1292,7 +1292,7 @@ public:
unsigned nwritten = 0; unsigned nwritten = 0;
char temp_fname[256]; char temp_fname[256];
sprintf(temp_fname, "___ic_temp_%05d.bin", 100 * id_gas_vel + coord); snprintf(temp_fname, 256, "___ic_temp_%05d.bin", 100 * id_gas_vel + coord);
std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc); std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc);
unsigned long long blksize; unsigned long long blksize;
@ -1459,7 +1459,7 @@ public:
temp_data.reserve(block_buf_size_); temp_data.reserve(block_buf_size_);
char temp_fname[256]; char temp_fname[256];
sprintf(temp_fname, "___ic_temp_%05d.bin", 100 * id_gas_pos + coord); snprintf(temp_fname, 256, "___ic_temp_%05d.bin", 100 * id_gas_pos + coord);
std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc); std::ofstream ofs_temp(temp_fname, std::ios::binary | std::ios::trunc);
unsigned long long blksize; unsigned long long blksize;

View file

@ -43,9 +43,9 @@
typedef float MyFloat; typedef float MyFloat;
typedef long long MyIDType; typedef long long MyIDType;
const int vert[8][3] = { {0,0,0}, {0,0,1}, {0,1,0}, {0,1,1}, {1,0,0}, {1,0,1}, {1,1,0}, {1,1,1} }; // const int vert[8][3] = { {0,0,0}, {0,0,1}, {0,1,0}, {0,1,1}, {1,0,0}, {1,0,1}, {1,1,0}, {1,1,1} };
const MyIDType vert_long[8][3] = { {0,0,0}, {0,0,1}, {0,1,0}, {0,1,1}, {1,0,0}, {1,0,1}, {1,1,0}, {1,1,1} }; const MyIDType vert_long[8][3] = { {0,0,0}, {0,0,1}, {0,1,0}, {0,1,1}, {1,0,0}, {1,0,1}, {1,1,0}, {1,1,1} };
const int conn[][4] = { {1,0,2,4}, {3,1,2,4}, {3,5,1,4}, {3,6,5,4}, {3,2,6,4}, {3,7,5,6} }; // const int conn[][4] = { {1,0,2,4}, {3,1,2,4}, {3,5,1,4}, {3,6,5,4}, {3,2,6,4}, {3,7,5,6} };
std::map<MyIDType,size_t> idmap; std::map<MyIDType,size_t> idmap;
@ -513,7 +513,7 @@ protected:
} }
std::ifstream& open_and_check( std::string ffname, size_t blksize, size_t offset=0 ) std::ifstream open_and_check( std::string ffname, size_t blksize, size_t offset=0 )
{ {
std::ifstream ifs( ffname.c_str(), std::ios::binary ); std::ifstream ifs( ffname.c_str(), std::ios::binary );
size_t blk; size_t blk;
@ -594,17 +594,17 @@ protected:
char fnx[256],fny[256],fnz[256],fnvx[256],fnvy[256],fnvz[256],fnm[256]; char fnx[256],fny[256],fnz[256],fnvx[256],fnvy[256],fnvz[256],fnm[256];
char fnc[256], fnl[256], fnlid[256]; char fnc[256], fnl[256], fnlid[256];
sprintf( fnx, "___ic_temp_%05d.bin", 100*id_dm_pos+0 ); snprintf( fnx, 256, "___ic_temp_%05d.bin", 100*id_dm_pos+0 );
sprintf( fny, "___ic_temp_%05d.bin", 100*id_dm_pos+1 ); snprintf( fny, 256, "___ic_temp_%05d.bin", 100*id_dm_pos+1 );
sprintf( fnz, "___ic_temp_%05d.bin", 100*id_dm_pos+2 ); snprintf( fnz, 256, "___ic_temp_%05d.bin", 100*id_dm_pos+2 );
sprintf( fnvx, "___ic_temp_%05d.bin", 100*id_dm_vel+0 ); snprintf( fnvx,256, "___ic_temp_%05d.bin", 100*id_dm_vel+0 );
sprintf( fnvy, "___ic_temp_%05d.bin", 100*id_dm_vel+1 ); snprintf( fnvy,256, "___ic_temp_%05d.bin", 100*id_dm_vel+1 );
sprintf( fnvz, "___ic_temp_%05d.bin", 100*id_dm_vel+2 ); snprintf( fnvz,256, "___ic_temp_%05d.bin", 100*id_dm_vel+2 );
sprintf( fnm, "___ic_temp_%05d.bin", 100*id_dm_mass ); snprintf( fnm, 256, "___ic_temp_%05d.bin", 100*id_dm_mass );
sprintf( fnc, "___ic_temp_%05d.bin", 100*id_dm_conn ); snprintf( fnc, 256, "___ic_temp_%05d.bin", 100*id_dm_conn );
sprintf( fnl, "___ic_temp_%05d.bin", 100*id_dm_level ); snprintf( fnl, 256, "___ic_temp_%05d.bin", 100*id_dm_level );
sprintf( fnlid, "___ic_temp_%05d.bin", 100*id_dm_lagrangeid ); snprintf( fnlid, 256, "___ic_temp_%05d.bin", 100*id_dm_lagrangeid );
pistream iffs1, iffs2, iffs3; pistream iffs1, iffs2, iffs3;
@ -663,7 +663,7 @@ protected:
if( nfiles_ > 1 ) if( nfiles_ > 1 )
{ {
char ffname[256]; char ffname[256];
sprintf(ffname,"%s.%d",fname_.c_str(), ifile); snprintf(ffname,256,"%s.%d",fname_.c_str(), ifile);
ofs_.open(ffname, std::ios::binary|std::ios::trunc ); ofs_.open(ffname, std::ios::binary|std::ios::trunc );
}else{ }else{
ofs_.open(fname_.c_str(), std::ios::binary|std::ios::trunc ); ofs_.open(fname_.c_str(), std::ios::binary|std::ios::trunc );
@ -939,7 +939,7 @@ public:
for( unsigned ifile=0; ifile<nfiles_; ++ifile ) for( unsigned ifile=0; ifile<nfiles_; ++ifile )
{ {
char ffname[256]; char ffname[256];
sprintf(ffname,"%s.%d",fname_.c_str(), ifile); snprintf(ffname,256,"%s.%d",fname_.c_str(), ifile);
ofs_.open(ffname, std::ios::binary|std::ios::trunc ); ofs_.open(ffname, std::ios::binary|std::ios::trunc );
if(!ofs_.good()) if(!ofs_.good())
{ {
@ -1062,7 +1062,7 @@ public:
if( P[ip].Level != ilevel || !P[ip].can_refine() ) if( P[ip].Level != ilevel || !P[ip].can_refine() )
continue; continue;
MyIDType lidsum = 0, xc[3] = {0,0,0}; MyIDType xc[3] = {0,0,0};
bool foundall = true; bool foundall = true;
bool dorefine = true; bool dorefine = true;
@ -1116,7 +1116,7 @@ public:
break; break;
} }
lidsum += lid; // lidsum += lid;
} }
if( !foundall ) continue; if( !foundall ) continue;
@ -1206,7 +1206,7 @@ public:
temp_dat.reserve(block_buf_size_); temp_dat.reserve(block_buf_size_);
char temp_fname[256]; char temp_fname[256];
sprintf( temp_fname, "___ic_temp_%05d.bin", 100*id_dm_mass ); snprintf( temp_fname, 256, "___ic_temp_%05d.bin", 100*id_dm_mass );
std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc ); std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc );
double mfac = header_.Omega0 * rhoc * pow(header_.BoxSize,3.); double mfac = header_.Omega0 * rhoc * pow(header_.BoxSize,3.);
@ -1264,7 +1264,7 @@ public:
temp_dat.reserve(block_buf_size_); temp_dat.reserve(block_buf_size_);
char temp_fname[256]; char temp_fname[256];
sprintf( temp_fname, "___ic_temp_%05d.bin", 100*id_dm_conn ); snprintf( temp_fname, 256, "___ic_temp_%05d.bin", 100*id_dm_conn );
std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc ); std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc );
size_t blksize = sizeof(long long)*num_p*8; size_t blksize = sizeof(long long)*num_p*8;
@ -1323,7 +1323,7 @@ public:
temp_dat.reserve(block_buf_size_); temp_dat.reserve(block_buf_size_);
char temp_fname[256]; char temp_fname[256];
sprintf( temp_fname, "___ic_temp_%05d.bin", 100*id_dm_level ); snprintf( temp_fname, 256, "___ic_temp_%05d.bin", 100*id_dm_level );
std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc ); std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc );
size_t blksize = sizeof(int)*num_p; size_t blksize = sizeof(int)*num_p;
@ -1369,7 +1369,7 @@ public:
temp_dat.reserve(block_buf_size_); temp_dat.reserve(block_buf_size_);
char temp_fname[256]; char temp_fname[256];
sprintf( temp_fname, "___ic_temp_%05d.bin", 100*id_dm_lagrangeid ); snprintf( temp_fname, 256,"___ic_temp_%05d.bin", 100*id_dm_lagrangeid );
std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc ); std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc );
size_t blksize = sizeof(size_t)*num_p; size_t blksize = sizeof(size_t)*num_p;
@ -1420,7 +1420,7 @@ public:
double xfac = header_.BoxSize; double xfac = header_.BoxSize;
char temp_fname[256]; char temp_fname[256];
sprintf( temp_fname, "___ic_temp_%05d.bin", 100*id_dm_pos+coord ); snprintf( temp_fname, 256, "___ic_temp_%05d.bin", 100*id_dm_pos+coord );
std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc ); std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc );
// write all particle masses // write all particle masses
@ -1486,7 +1486,7 @@ public:
temp_dat.reserve(block_buf_size_); temp_dat.reserve(block_buf_size_);
char temp_fname[256]; char temp_fname[256];
sprintf( temp_fname, "___ic_temp_%05d.bin", 100*id_dm_vel+coord ); snprintf( temp_fname, 256, "___ic_temp_%05d.bin", 100*id_dm_vel+coord );
std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc ); std::ofstream ofs_temp( temp_fname, std::ios::binary|std::ios::trunc );
// write all particle masses // write all particle masses

View file

@ -70,11 +70,11 @@ public:
for( unsigned ilevel=0; ilevel<=levelmax_; ++ilevel ) for( unsigned ilevel=0; ilevel<=levelmax_; ++ilevel )
{ {
if( coord == 0 ) if( coord == 0 )
sprintf(sstr,"level_%03d_DM_vx",ilevel); snprintf(sstr,128, "level_%03d_DM_vx",ilevel);
else if( coord == 1 ) else if( coord == 1 )
sprintf(sstr,"level_%03d_DM_vy",ilevel); snprintf(sstr,128, "level_%03d_DM_vy",ilevel);
else if( coord == 2 ) else if( coord == 2 )
sprintf(sstr,"level_%03d_DM_vz",ilevel); snprintf(sstr,128, "level_%03d_DM_vz",ilevel);
write2HDF5( fname_, sstr, *gh.get_grid(ilevel) ); write2HDF5( fname_, sstr, *gh.get_grid(ilevel) );
} }
@ -87,11 +87,11 @@ public:
for( unsigned ilevel=0; ilevel<=levelmax_; ++ilevel ) for( unsigned ilevel=0; ilevel<=levelmax_; ++ilevel )
{ {
if( coord == 0 ) if( coord == 0 )
sprintf(sstr,"level_%03d_DM_dx",ilevel); snprintf(sstr,128,"level_%03d_DM_dx",ilevel);
else if( coord == 1 ) else if( coord == 1 )
sprintf(sstr,"level_%03d_DM_dy",ilevel); snprintf(sstr,128,"level_%03d_DM_dy",ilevel);
else if( coord == 2 ) else if( coord == 2 )
sprintf(sstr,"level_%03d_DM_dz",ilevel); snprintf(sstr,128,"level_%03d_DM_dz",ilevel);
write2HDF5( fname_, sstr, *gh.get_grid(ilevel) ); write2HDF5( fname_, sstr, *gh.get_grid(ilevel) );
} }
@ -103,7 +103,7 @@ public:
for( unsigned ilevel=0; ilevel<=levelmax_; ++ilevel ) for( unsigned ilevel=0; ilevel<=levelmax_; ++ilevel )
{ {
sprintf(sstr,"level_%03d_DM_rho",ilevel); snprintf(sstr,128,"level_%03d_DM_rho",ilevel);
write2HDF5( fname_, sstr, *gh.get_grid(ilevel) ); write2HDF5( fname_, sstr, *gh.get_grid(ilevel) );
} }
@ -191,7 +191,7 @@ public:
for( unsigned ilevel=0; ilevel<=levelmax_; ++ilevel ) for( unsigned ilevel=0; ilevel<=levelmax_; ++ilevel )
{ {
sprintf(sstr,"level_%03d_DM_potential",ilevel); snprintf(sstr,128,"level_%03d_DM_potential",ilevel);
write2HDF5( fname_, sstr, *gh.get_grid(ilevel) ); write2HDF5( fname_, sstr, *gh.get_grid(ilevel) );
} }
} }
@ -202,7 +202,7 @@ public:
for( unsigned ilevel=0; ilevel<=levelmax_; ++ilevel ) for( unsigned ilevel=0; ilevel<=levelmax_; ++ilevel )
{ {
sprintf(sstr,"level_%03d_BA_potential",ilevel); snprintf(sstr,128,"level_%03d_BA_potential",ilevel);
write2HDF5( fname_, sstr, *gh.get_grid(ilevel) ); write2HDF5( fname_, sstr, *gh.get_grid(ilevel) );
} }
} }
@ -216,11 +216,11 @@ public:
for( unsigned ilevel=0; ilevel<=levelmax_; ++ilevel ) for( unsigned ilevel=0; ilevel<=levelmax_; ++ilevel )
{ {
if( coord == 0 ) if( coord == 0 )
sprintf(sstr,"level_%03d_BA_vx",ilevel); snprintf(sstr,128,"level_%03d_BA_vx",ilevel);
else if( coord == 1 ) else if( coord == 1 )
sprintf(sstr,"level_%03d_BA_vy",ilevel); snprintf(sstr,128,"level_%03d_BA_vy",ilevel);
else if( coord == 2 ) else if( coord == 2 )
sprintf(sstr,"level_%03d_BA_vz",ilevel); snprintf(sstr,128,"level_%03d_BA_vz",ilevel);
write2HDF5( fname_, sstr, *gh.get_grid(ilevel) ); write2HDF5( fname_, sstr, *gh.get_grid(ilevel) );
} }
@ -235,7 +235,7 @@ public:
for( unsigned ilevel=0; ilevel<=levelmax_; ++ilevel ) for( unsigned ilevel=0; ilevel<=levelmax_; ++ilevel )
{ {
sprintf(sstr,"level_%03d_BA_rho",ilevel); snprintf(sstr,128,"level_%03d_BA_rho",ilevel);
write2HDF5( fname_, sstr, *gh.get_grid(ilevel) ); write2HDF5( fname_, sstr, *gh.get_grid(ilevel) );
} }
} }

View file

@ -13,7 +13,6 @@
#include <fstream> #include <fstream>
#include "output.hh" #include "output.hh"
//! Implementation of class grafic2_output_plugin //! Implementation of class grafic2_output_plugin
/*! /*!
This class implements a grafic-2 (cf. Bertschinger 2001) compatible This class implements a grafic-2 (cf. Bertschinger 2001) compatible
@ -22,571 +21,556 @@
class grafic2_output_plugin : public output_plugin class grafic2_output_plugin : public output_plugin
{ {
protected: protected:
typedef struct
{
typedef struct{
int n1, n2, n3; int n1, n2, n3;
float dxini0; float dxini0;
float xoff10,xoff20,xoff30; float xoff10, xoff20, xoff30;
float astart0,omega_m0,omega_l0,h00; float astart0, omega_m0, omega_l0, h00;
}header; } header;
bool bhavehydro_; bool bhavehydro_;
//float metal_floor_; // float metal_floor_;
int passive_variable_index_; int passive_variable_index_;
float passive_variable_value_; float passive_variable_value_;
void write_file_header( std::ofstream& ofs, unsigned ilevel, const grid_hierarchy& gh ) void write_file_header(std::ofstream &ofs, unsigned ilevel, const grid_hierarchy &gh)
{ {
header loc_head; header loc_head;
double double
boxlength = cf_.get_value<double>("setup","boxlength"), boxlength = cf_.get_value<double>("setup", "boxlength"),
H0 = cf_.get_value<double>("cosmology","H0"), H0 = cf_.get_value<double>("cosmology", "H0"),
zstart = cf_.get_value<double>("setup","zstart"), zstart = cf_.get_value<double>("setup", "zstart"),
astart = 1.0/(1.0+zstart), astart = 1.0 / (1.0 + zstart),
omegam = cf_.get_value<double>("cosmology","Omega_m"), omegam = cf_.get_value<double>("cosmology", "Omega_m"),
omegaL = cf_.get_value<double>("cosmology","Omega_L"); omegaL = cf_.get_value<double>("cosmology", "Omega_L");
loc_head.n1 = gh.get_grid(ilevel)->size(0); loc_head.n1 = gh.get_grid(ilevel)->size(0);
loc_head.n2 = gh.get_grid(ilevel)->size(1); loc_head.n2 = gh.get_grid(ilevel)->size(1);
loc_head.n3 = gh.get_grid(ilevel)->size(2); loc_head.n3 = gh.get_grid(ilevel)->size(2);
loc_head.dxini0 = boxlength / (H0*0.01) / pow(2.0,ilevel); loc_head.dxini0 = boxlength / (H0 * 0.01) / pow(2.0, ilevel);
loc_head.xoff10 = gh.offset_abs(ilevel,0) * loc_head.dxini0; loc_head.xoff10 = gh.offset_abs(ilevel, 0) * loc_head.dxini0;
loc_head.xoff20 = gh.offset_abs(ilevel,1) * loc_head.dxini0; loc_head.xoff20 = gh.offset_abs(ilevel, 1) * loc_head.dxini0;
loc_head.xoff30 = gh.offset_abs(ilevel,2) * loc_head.dxini0; loc_head.xoff30 = gh.offset_abs(ilevel, 2) * loc_head.dxini0;
loc_head.astart0 = astart; loc_head.astart0 = astart;
loc_head.omega_m0 = omegam; loc_head.omega_m0 = omegam;
loc_head.omega_l0 = omegaL; loc_head.omega_l0 = omegaL;
loc_head.h00 = H0; loc_head.h00 = H0;
int blksz = sizeof(header); int blksz = sizeof(header);
ofs.write( reinterpret_cast<char*> (&blksz), sizeof(int) ); ofs.write(reinterpret_cast<char *>(&blksz), sizeof(int));
ofs.write( reinterpret_cast<char*> (&loc_head), blksz ); ofs.write(reinterpret_cast<char *>(&loc_head), blksz);
ofs.write( reinterpret_cast<char*> (&blksz), sizeof(int) ); ofs.write(reinterpret_cast<char *>(&blksz), sizeof(int));
} }
void write_sliced_array( std::ofstream& ofs, unsigned ilevel, const grid_hierarchy& gh, float fac = 1.0f ) void write_sliced_array(std::ofstream &ofs, unsigned ilevel, const grid_hierarchy &gh, float fac = 1.0f)
{ {
unsigned n1,n2,n3; unsigned n1, n2, n3;
n1 = gh.get_grid(ilevel)->size(0); n1 = gh.get_grid(ilevel)->size(0);
n2 = gh.get_grid(ilevel)->size(1); n2 = gh.get_grid(ilevel)->size(1);
n3 = gh.get_grid(ilevel)->size(2); n3 = gh.get_grid(ilevel)->size(2);
std::vector<float> data(n1*n2,0.0f); std::vector<float> data(n1 * n2, 0.0f);
for( unsigned i=0; i<n3; ++i ) for (unsigned i = 0; i < n3; ++i)
{ {
data.clear(); data.clear();
for( unsigned j=0; j<n2; ++j ) for (unsigned j = 0; j < n2; ++j)
for( unsigned k=0; k<n1; ++k ) for (unsigned k = 0; k < n1; ++k)
data[j*n1+k] = (*gh.get_grid(ilevel))(k,j,i) * fac; data[j * n1 + k] = (*gh.get_grid(ilevel))(k, j, i) * fac;
unsigned blksize = n1*n2*sizeof(float); unsigned blksize = n1 * n2 * sizeof(float);
ofs.write( reinterpret_cast<char*> (&blksize), sizeof(unsigned) );
ofs.write( reinterpret_cast<char*> (&data[0]), blksize );
ofs.write( reinterpret_cast<char*> (&blksize), sizeof(unsigned) );
ofs.write(reinterpret_cast<char *>(&blksize), sizeof(unsigned));
ofs.write(reinterpret_cast<char *>(&data[0]), blksize);
ofs.write(reinterpret_cast<char *>(&blksize), sizeof(unsigned));
} }
} }
size_t restrict_mask( size_t n1, size_t n2, size_t n3, size_t o1, size_t o2, size_t o3, size_t restrict_mask(size_t n1, size_t n2, size_t n3, size_t o1, size_t o2, size_t o3,
size_t n1c, size_t n2c, size_t n3c, const float* finemask, float* coarsemask ) size_t n1c, size_t n2c, size_t n3c, const float *finemask, float *coarsemask)
{ {
//unsigned n1p = n1/2, n2p = n2/2, n3p = n3/2; // unsigned n1p = n1/2, n2p = n2/2, n3p = n3/2;
for( size_t i=0; i<n1c*n2c*n3c; ++i ) for (size_t i = 0; i < n1c * n2c * n3c; ++i)
coarsemask[i] = 0.0f; coarsemask[i] = 0.0f;
for( size_t i=0; i<n1; ++i ) for (size_t i = 0; i < n1; ++i)
{ {
size_t ii=i/2+o1; size_t ii = i / 2 + o1;
for( size_t j=0; j<n2; ++j ) for (size_t j = 0; j < n2; ++j)
{ {
size_t jj=j/2+o2; size_t jj = j / 2 + o2;
for( size_t k=0; k<n3; ++k ) for (size_t k = 0; k < n3; ++k)
{ {
size_t kk=k/2+o3; size_t kk = k / 2 + o3;
if( finemask[ (i*n2+j)*n3+k ] ) if (finemask[(i * n2 + j) * n3 + k])
coarsemask[(ii*n2c+jj)*n3c+kk] += 1.0f; coarsemask[(ii * n2c + jj) * n3c + kk] += 1.0f;
} }
} }
}
size_t count_ref = 0;
for( size_t i=0; i<n1c*n2c*n3c; ++i )
if( coarsemask[i] > 0.1f )
{
coarsemask[i] = 1.0f;
++count_ref;
}
return count_ref;
}
void write_refinement_mask( const grid_hierarchy& gh )
{
// generate mask for highest level
char ff[256];
size_t n1,n2,n3;
n1 = gh.get_grid(gh.levelmax())->size(0);
n2 = gh.get_grid(gh.levelmax())->size(1);
n3 = gh.get_grid(gh.levelmax())->size(2);
std::vector<float> data(n1*n2*n3,0.0f);
// do finest level
{
// get mask for levelmax
for( size_t i=0; i<n1; ++i )
for( size_t j=0; j<n2; ++j )
for( size_t k=0; k<n3; ++k )
if( gh.is_in_mask(gh.levelmax(),i,j,k) && !gh.is_refined(gh.levelmax(),i,j,k) )
data[(i*n2+j)*n3+k] = 1.0;
else
data[(i*n2+j)*n3+k] = 0.0;
// write mask
sprintf(ff,"%s/level_%03d/ic_refmap",fname_.c_str(), gh.levelmax() );
std::ofstream ofs(ff,std::ios::binary|std::ios::trunc);
write_file_header( ofs, gh.levelmax(), gh );
std::ofstream ofs_metals;
if( passive_variable_value_ > 0.0f )
{
sprintf(ff,"%s/level_%03d/ic_pvar_%05d",fname_.c_str(), gh.levelmax(), passive_variable_index_ );
ofs_metals.open(ff,std::ios::binary|std::ios::trunc);
write_file_header( ofs_metals, gh.levelmax(), gh );
}
std::vector<float> block(n1*n2,0.0f);
for( unsigned k=0; k<n3; ++k )
{
for( unsigned j=0; j<n2; ++j )
for( unsigned i=0; i<n1; ++i )
block[j*n1+i] = data[(i*n2+j)*n3+k];
unsigned blksize = n1*n2*sizeof(float);
ofs.write( reinterpret_cast<char*> (&blksize), sizeof(unsigned) );
ofs.write( reinterpret_cast<char*> (&block[0]), blksize );
ofs.write( reinterpret_cast<char*> (&blksize), sizeof(unsigned) );
if( passive_variable_value_ > 0.0f ){
for( unsigned j=0; j<n2; ++j )
for( unsigned i=0; i<n1; ++i )
block[j*n1+i] = data[(i*n2+j)*n3+k] * passive_variable_value_;
unsigned blksize = n1*n2*sizeof(float);
ofs_metals.write( reinterpret_cast<char*> (&blksize), sizeof(unsigned) );
ofs_metals.write( reinterpret_cast<char*> (&block[0]), blksize );
ofs_metals.write( reinterpret_cast<char*> (&blksize), sizeof(unsigned) );
} }
}
}
// do all coarser levels size_t count_ref = 0;
for( unsigned ilevel=levelmax_-1; ilevel>=levelmin_; --ilevel ) for (size_t i = 0; i < n1c * n2c * n3c; ++i)
{ if (coarsemask[i] > 0.1f)
size_t n1c,n2c,n3c,o1,o2,o3; {
n1c = gh.get_grid(ilevel)->size(0); coarsemask[i] = 1.0f;
n2c = gh.get_grid(ilevel)->size(1); ++count_ref;
n3c = gh.get_grid(ilevel)->size(2); }
return count_ref;
}
n1 = gh.get_grid(ilevel+1)->size(0); void write_refinement_mask(const grid_hierarchy &gh)
n2 = gh.get_grid(ilevel+1)->size(1); {
n3 = gh.get_grid(ilevel+1)->size(2);
o1 = gh.get_grid(ilevel+1)->offset(0); // generate mask for highest level
o2 = gh.get_grid(ilevel+1)->offset(1); char ff[256];
o3 = gh.get_grid(ilevel+1)->offset(2);
std::vector<float> data_coarse( n1c*n2c*n3c, 0.0f ); size_t n1, n2, n3;
n1 = gh.get_grid(gh.levelmax())->size(0);
n2 = gh.get_grid(gh.levelmax())->size(1);
n3 = gh.get_grid(gh.levelmax())->size(2);
/*if( ilevel <= levelmax_-2 ) std::vector<float> data(n1 * n2 * n3, 0.0f);
{
for( size_t i=0; i<n1*n2*n3; ++i )
data[i] = 0.0;
for( unsigned i=2; i<n1-2; ++i ) // do finest level
for( unsigned j=2; j<n2-2; ++j ) {
for( unsigned k=2; k<n3-2; ++k ) // get mask for levelmax
data[(i*n2+j)*n3+k] = 1.0; for (size_t i = 0; i < n1; ++i)
}*/ for (size_t j = 0; j < n2; ++j)
for (size_t k = 0; k < n3; ++k)
if (gh.is_in_mask(gh.levelmax(), i, j, k) && !gh.is_refined(gh.levelmax(), i, j, k))
data[(i * n2 + j) * n3 + k] = 1.0;
else
data[(i * n2 + j) * n3 + k] = 0.0;
size_t nref; // write mask
nref = restrict_mask( n1, n2, n3, o1, o2, o3, n1c, n2c, n3c, &data[0], &data_coarse[0] ); snprintf(ff, 256, "%s/level_%03d/ic_refmap", fname_.c_str(), gh.levelmax());
std::ofstream ofs(ff, std::ios::binary | std::ios::trunc);
write_file_header(ofs, gh.levelmax(), gh);
music::ilog.Print("%f of cells on level %d are refined",(double)nref/(n1c*n2c*n3c),ilevel); std::ofstream ofs_metals;
sprintf(ff,"%s/level_%03d/ic_refmap",fname_.c_str(), ilevel ); if (passive_variable_value_ > 0.0f)
std::ofstream ofs(ff,std::ios::binary|std::ios::trunc); {
write_file_header( ofs, ilevel, gh ); snprintf(ff, 256, "%s/level_%03d/ic_pvar_%05d", fname_.c_str(), gh.levelmax(), passive_variable_index_);
ofs_metals.open(ff, std::ios::binary | std::ios::trunc);
write_file_header(ofs_metals, gh.levelmax(), gh);
}
std::ofstream ofs_metals; std::vector<float> block(n1 * n2, 0.0f);
if( passive_variable_value_ > 0.0f ) for (unsigned k = 0; k < n3; ++k)
{ {
sprintf(ff,"%s/level_%03d/ic_pvar_%05d",fname_.c_str(), ilevel, passive_variable_index_ ); for (unsigned j = 0; j < n2; ++j)
ofs_metals.open(ff,std::ios::binary|std::ios::trunc); for (unsigned i = 0; i < n1; ++i)
write_file_header( ofs_metals, ilevel, gh ); block[j * n1 + i] = data[(i * n2 + j) * n3 + k];
}
unsigned blksize = n1 * n2 * sizeof(float);
std::vector<float> block(n1c*n2c,0.0f); ofs.write(reinterpret_cast<char *>(&blksize), sizeof(unsigned));
for( unsigned i=0; i<n3c; ++i ) ofs.write(reinterpret_cast<char *>(&block[0]), blksize);
{ ofs.write(reinterpret_cast<char *>(&blksize), sizeof(unsigned));
for( unsigned j=0; j<n2c; ++j )
for( unsigned k=0; k<n1c; ++k )
block[j*n1c+k] = data_coarse[(k*n2c+j)*n3c+i];
unsigned blksize = n1c*n2c*sizeof(float); if (passive_variable_value_ > 0.0f)
{
ofs.write( reinterpret_cast<char*> (&blksize), sizeof(unsigned) ); for (unsigned j = 0; j < n2; ++j)
ofs.write( reinterpret_cast<char*> (&block[0]), blksize ); for (unsigned i = 0; i < n1; ++i)
ofs.write( reinterpret_cast<char*> (&blksize), sizeof(unsigned) ); block[j * n1 + i] = data[(i * n2 + j) * n3 + k] * passive_variable_value_;
if( passive_variable_value_ > 0.0f ){ unsigned blksize = n1 * n2 * sizeof(float);
for( unsigned j=0; j<n2c; ++j ) ofs_metals.write(reinterpret_cast<char *>(&blksize), sizeof(unsigned));
for( unsigned k=0; k<n1c; ++k ) ofs_metals.write(reinterpret_cast<char *>(&block[0]), blksize);
block[j*n1c+k] = data_coarse[(k*n2c+j)*n3c+i] * passive_variable_value_; ofs_metals.write(reinterpret_cast<char *>(&blksize), sizeof(unsigned));
}
unsigned blksize = n1c*n2c*sizeof(float); }
ofs_metals.write( reinterpret_cast<char*> (&blksize), sizeof(unsigned) );
ofs_metals.write( reinterpret_cast<char*> (&block[0]), blksize );
ofs_metals.write( reinterpret_cast<char*> (&blksize), sizeof(unsigned) );
} }
}
data.swap( data_coarse ); // do all coarser levels
for (unsigned ilevel = levelmax_ - 1; ilevel >= levelmin_; --ilevel)
{
size_t n1c, n2c, n3c, o1, o2, o3;
n1c = gh.get_grid(ilevel)->size(0);
n2c = gh.get_grid(ilevel)->size(1);
n3c = gh.get_grid(ilevel)->size(2);
} n1 = gh.get_grid(ilevel + 1)->size(0);
} n2 = gh.get_grid(ilevel + 1)->size(1);
n3 = gh.get_grid(ilevel + 1)->size(2);
void write_ramses_namelist( const grid_hierarchy& gh ) o1 = gh.get_grid(ilevel + 1)->offset(0);
o2 = gh.get_grid(ilevel + 1)->offset(1);
o3 = gh.get_grid(ilevel + 1)->offset(2);
std::vector<float> data_coarse(n1c * n2c * n3c, 0.0f);
/*if( ilevel <= levelmax_-2 )
{
for( size_t i=0; i<n1*n2*n3; ++i )
data[i] = 0.0;
for( unsigned i=2; i<n1-2; ++i )
for( unsigned j=2; j<n2-2; ++j )
for( unsigned k=2; k<n3-2; ++k )
data[(i*n2+j)*n3+k] = 1.0;
}*/
size_t nref;
nref = restrict_mask(n1, n2, n3, o1, o2, o3, n1c, n2c, n3c, &data[0], &data_coarse[0]);
music::ilog.Print("%f of cells on level %d are refined", (double)nref / (n1c * n2c * n3c), ilevel);
snprintf(ff, 256, "%s/level_%03d/ic_refmap", fname_.c_str(), ilevel);
std::ofstream ofs(ff, std::ios::binary | std::ios::trunc);
write_file_header(ofs, ilevel, gh);
std::ofstream ofs_metals;
if (passive_variable_value_ > 0.0f)
{
snprintf(ff, 256, "%s/level_%03d/ic_pvar_%05d", fname_.c_str(), ilevel, passive_variable_index_);
ofs_metals.open(ff, std::ios::binary | std::ios::trunc);
write_file_header(ofs_metals, ilevel, gh);
}
std::vector<float> block(n1c * n2c, 0.0f);
for (unsigned i = 0; i < n3c; ++i)
{
for (unsigned j = 0; j < n2c; ++j)
for (unsigned k = 0; k < n1c; ++k)
block[j * n1c + k] = data_coarse[(k * n2c + j) * n3c + i];
unsigned blksize = n1c * n2c * sizeof(float);
ofs.write(reinterpret_cast<char *>(&blksize), sizeof(unsigned));
ofs.write(reinterpret_cast<char *>(&block[0]), blksize);
ofs.write(reinterpret_cast<char *>(&blksize), sizeof(unsigned));
if (passive_variable_value_ > 0.0f)
{
for (unsigned j = 0; j < n2c; ++j)
for (unsigned k = 0; k < n1c; ++k)
block[j * n1c + k] = data_coarse[(k * n2c + j) * n3c + i] * passive_variable_value_;
unsigned blksize = n1c * n2c * sizeof(float);
ofs_metals.write(reinterpret_cast<char *>(&blksize), sizeof(unsigned));
ofs_metals.write(reinterpret_cast<char *>(&block[0]), blksize);
ofs_metals.write(reinterpret_cast<char *>(&blksize), sizeof(unsigned));
}
}
data.swap(data_coarse);
}
}
void write_ramses_namelist(const grid_hierarchy &gh)
{ {
//... also write the refinement options to a dummy namelist file //... also write the refinement options to a dummy namelist file
char ff[256]; char ff[256];
sprintf(ff,"%s/ramses.nml",fname_.c_str() ); snprintf(ff, 256, "%s/ramses.nml", fname_.c_str());
std::ofstream ofst(ff,std::ios::trunc); std::ofstream ofst(ff, std::ios::trunc);
// -- RUN_PARAMS -- // // -- RUN_PARAMS -- //
ofst ofst
<< "&RUN_PARAMS\n" << "&RUN_PARAMS\n"
<< "cosmo=.true.\n" << "cosmo=.true.\n"
<< "pic=.true.\n" << "pic=.true.\n"
<< "poisson=.true.\n"; << "poisson=.true.\n";
if( bhavehydro_ ) if (bhavehydro_)
ofst << "hydro=.true.\n"; ofst << "hydro=.true.\n";
else else
ofst << "hydro=.false.\n"; ofst << "hydro=.false.\n";
ofst ofst
<< "nrestart=0\n" << "nrestart=0\n"
<< "nremap=1\n" << "nremap=1\n"
<< "nsubcycle="; << "nsubcycle=";
for( unsigned ilevel=gh.levelmin(); ilevel<=gh.levelmax(); ++ilevel ) for (unsigned ilevel = gh.levelmin(); ilevel <= gh.levelmax(); ++ilevel)
ofst << "1,"; ofst << "1,";
ofst << "1,2\n"; ofst << "1,2\n";
ofst ofst
<< "ncontrol=1\n" << "ncontrol=1\n"
<< "verbose=.false.\n/\n\n"; << "verbose=.false.\n/\n\n";
// -- INIT_PARAMS -- // // -- INIT_PARAMS -- //
ofst ofst
<< "&INIT_PARAMS\n" << "&INIT_PARAMS\n"
<< "filetype=\'grafic\'\n"; << "filetype=\'grafic\'\n";
for( unsigned i=gh.levelmin();i<=gh.levelmax(); ++i) for (unsigned i = gh.levelmin(); i <= gh.levelmax(); ++i)
{ {
sprintf(ff,"initfile(%d)=\'%s/level_%03d\'\n",i-gh.levelmin()+1,fname_.c_str(), i ); snprintf(ff, 256, "initfile(%d)=\'%s/level_%03d\'\n", i - gh.levelmin() + 1, fname_.c_str(), i);
ofst << std::string(ff); ofst << std::string(ff);
} }
ofst << "/\n\n"; ofst << "/\n\n";
unsigned naddref = 8; // initialize with settings for 10 additional levels of refinement
unsigned nexpand = (cf_.get_value<unsigned>("setup", "padding") - 1) / 2;
unsigned naddref = 8; // initialize with settings for 10 additional levels of refinement // -- AMR_PARAMS -- //
unsigned nexpand = (cf_.get_value<unsigned>("setup","padding")-1)/2; ofst << "&AMR_PARAMS\n"
<< "levelmin=" << gh.levelmin() << "\n"
<< "levelmax=" << gh.levelmax() + naddref << "\n"
<< "nexpand=";
// -- AMR_PARAMS -- // if (gh.levelmax() == gh.levelmin())
ofst << "&AMR_PARAMS\n" ofst << "1";
<< "levelmin=" << gh.levelmin() << "\n" else
<< "levelmax=" << gh.levelmax()+naddref << "\n" {
<< "nexpand="; for (unsigned ilevel = gh.levelmin(); ilevel < gh.levelmax() - 1; ++ilevel)
ofst << nexpand << ",";
ofst << "1,1";
}
if( gh.levelmax() == gh.levelmin() ) ofst << "\n"
ofst << "1"; << "ngridtot=2000000\n"
else << "nparttot=3000000\n"
{ << "/\n\n";
for( unsigned ilevel=gh.levelmin(); ilevel<gh.levelmax()-1; ++ilevel )
ofst << nexpand << ",";
ofst << "1,1";
} ofst << "&REFINE_PARAMS\n"
<< "m_refine=" << gh.levelmax() - gh.levelmin() + 1 + naddref << "*8.,\n";
ofst << "\n" if (bhavehydro_)
<< "ngridtot=2000000\n" ofst << "ivar_refine=" << 5 + passive_variable_index_ << "\n"
<< "nparttot=3000000\n" << "var_cut_refine=" << passive_variable_value_ * 0.01 << "\n";
<< "/\n\n"; else
ofst << "ivar_refine=0\n";
ofst << "&REFINE_PARAMS\n"
<< "m_refine=" << gh.levelmax()-gh.levelmin()+1+naddref << "*8.,\n";
if( bhavehydro_ )
ofst << "ivar_refine=" << 5+passive_variable_index_ << "\n"
<< "var_cut_refine=" << passive_variable_value_*0.01 << "\n";
else
ofst << "ivar_refine=0\n";
ofst << "mass_cut_refine=" << 2.0/pow(2,3*gh.levelmax()) << "\n"
<< "interpol_var=1\n"
<< "interpol_type=0\n"
<< "/\n\n";
ofst << "mass_cut_refine=" << 2.0 / pow(2, 3 * gh.levelmax()) << "\n"
<< "interpol_var=1\n"
<< "interpol_type=0\n"
<< "/\n\n";
music::ilog.Print("The grafic2 output plug-in wrote the grid data to a partial"); music::ilog.Print("The grafic2 output plug-in wrote the grid data to a partial");
music::ilog.Print(" RAMSES namelist file \'%s\'",fname_.c_str() ); music::ilog.Print(" RAMSES namelist file \'%s\'", fname_.c_str());
} }
void write_ramses_namelist_old( const grid_hierarchy& gh ) void write_ramses_namelist_old(const grid_hierarchy &gh)
{ {
//... also write the refinement options to a dummy namelist file //... also write the refinement options to a dummy namelist file
char ff[256]; char ff[256];
sprintf(ff,"%s/ramses.nml",fname_.c_str() ); snprintf(ff, 256, "%s/ramses.nml", fname_.c_str());
std::ofstream ofst(ff,std::ios::trunc); std::ofstream ofst(ff, std::ios::trunc);
ofst ofst
<< "&INIT_PARAMS\n" << "&INIT_PARAMS\n"
<< "filetype=\'grafic\'\n"; << "filetype=\'grafic\'\n";
for( unsigned i=gh.levelmin();i<=gh.levelmax(); ++i) for (unsigned i = gh.levelmin(); i <= gh.levelmax(); ++i)
{ {
sprintf(ff,"initfile(%d)=\'%s/level_%03d\'\n",i-gh.levelmin()+1,fname_.c_str(), i ); snprintf(ff, 256, "initfile(%d)=\'%s/level_%03d\'\n", i - gh.levelmin() + 1, fname_.c_str(), i);
ofst << std::string(ff); ofst << std::string(ff);
} }
ofst << "/\n\n"; ofst << "/\n\n";
double xc, yc, zc, l;
double xc,yc,zc,l;
ofst ofst
<< "&AMR_PARAMS\n" << "&AMR_PARAMS\n"
<< "levelmin=" << gh.levelmin() << "\n" << "levelmin=" << gh.levelmin() << "\n"
<< "levelmax=" << gh.levelmax() << "\n" << "levelmax=" << gh.levelmax() << "\n"
<< "ngridtot=2000000\n" << "ngridtot=2000000\n"
<< "nparttot=3000000\n" << "nparttot=3000000\n"
<< "nexpand=1\n/\n\n"; << "nexpand=1\n/\n\n";
const size_t fprec = 12, fwid = 16; const size_t fprec = 12, fwid = 16;
if( gh.levelmax() > gh.levelmin() ) if (gh.levelmax() > gh.levelmin())
{ {
l = (double)(1l<<(gh.levelmin()+1)); l = (double)(1l << (gh.levelmin() + 1));
xc = ((double)gh.offset_abs(gh.levelmin()+1,0)+0.5*(double)gh.size(gh.levelmin()+1,0))/l; xc = ((double)gh.offset_abs(gh.levelmin() + 1, 0) + 0.5 * (double)gh.size(gh.levelmin() + 1, 0)) / l;
yc = ((double)gh.offset_abs(gh.levelmin()+1,1)+0.5*(double)gh.size(gh.levelmin()+1,1))/l; yc = ((double)gh.offset_abs(gh.levelmin() + 1, 1) + 0.5 * (double)gh.size(gh.levelmin() + 1, 1)) / l;
zc = ((double)gh.offset_abs(gh.levelmin()+1,2)+0.5*(double)gh.size(gh.levelmin()+1,2))/l; zc = ((double)gh.offset_abs(gh.levelmin() + 1, 2) + 0.5 * (double)gh.size(gh.levelmin() + 1, 2)) / l;
ofst << "&REFINE_PARAMS\n" ofst << "&REFINE_PARAMS\n"
<< "m_refine= "<< std::setw(fwid) << std::setprecision(fprec) << 0.0; << "m_refine= " << std::setw(fwid) << std::setprecision(fprec) << 0.0;
for (unsigned i = gh.levelmin() + 1; i < gh.levelmax(); ++i)
for( unsigned i=gh.levelmin()+1;i<gh.levelmax(); ++i)
ofst << "," << std::setw(fwid) << std::setprecision(fprec) << 0.0; ofst << "," << std::setw(fwid) << std::setprecision(fprec) << 0.0;
ofst << "\nx_refine= "<< std::setw(fwid) << std::setprecision(fprec) << xc; ofst << "\nx_refine= " << std::setw(fwid) << std::setprecision(fprec) << xc;
for( unsigned i=gh.levelmin()+1;i<gh.levelmax(); ++i) for (unsigned i = gh.levelmin() + 1; i < gh.levelmax(); ++i)
{ {
l = (double)(1l<<(i+1)); l = (double)(1l << (i + 1));
xc = ((double)gh.offset_abs(i+1,0)+0.5*(double)gh.size(i+1,0))/l; xc = ((double)gh.offset_abs(i + 1, 0) + 0.5 * (double)gh.size(i + 1, 0)) / l;
ofst << ","<< std::setw(fwid) << std::setprecision(fprec) << xc; ofst << "," << std::setw(fwid) << std::setprecision(fprec) << xc;
} }
ofst << "\ny_refine= "<< std::setw(fwid) << std::setprecision(fprec) << yc; ofst << "\ny_refine= " << std::setw(fwid) << std::setprecision(fprec) << yc;
for( unsigned i=gh.levelmin()+1;i<gh.levelmax(); ++i) for (unsigned i = gh.levelmin() + 1; i < gh.levelmax(); ++i)
{ {
l = (double)(1l<<(i+1)); l = (double)(1l << (i + 1));
yc = ((double)gh.offset_abs(i+1,1)+0.5*(double)gh.size(i+1,1))/l; yc = ((double)gh.offset_abs(i + 1, 1) + 0.5 * (double)gh.size(i + 1, 1)) / l;
ofst << ","<< std::setw(fwid) << std::setprecision(fprec) << yc; ofst << "," << std::setw(fwid) << std::setprecision(fprec) << yc;
} }
ofst << "\nz_refine= "<< std::setw(fwid) << std::setprecision(fprec) << zc; ofst << "\nz_refine= " << std::setw(fwid) << std::setprecision(fprec) << zc;
for( unsigned i=gh.levelmin()+1;i<gh.levelmax(); ++i) for (unsigned i = gh.levelmin() + 1; i < gh.levelmax(); ++i)
{ {
l = (double)(1l<<(i+1)); l = (double)(1l << (i + 1));
zc = ((double)gh.offset_abs(i+1,2)+0.5*(double)gh.size(i+1,2))/l; zc = ((double)gh.offset_abs(i + 1, 2) + 0.5 * (double)gh.size(i + 1, 2)) / l;
ofst << ","<< std::setw(fwid) << std::setprecision(fprec) << zc; ofst << "," << std::setw(fwid) << std::setprecision(fprec) << zc;
} }
ofst << "\nr_refine= "; ofst << "\nr_refine= ";
for(unsigned i=gh.levelmin();i<gh.levelmax(); ++i ) for (unsigned i = gh.levelmin(); i < gh.levelmax(); ++i)
{ {
size_t nmax = std::min(gh.size(i+1,0),std::min(gh.size(i+1,1),gh.size(i+1,2))); size_t nmax = std::min(gh.size(i + 1, 0), std::min(gh.size(i + 1, 1), gh.size(i + 1, 2)));
double r = (nmax-4.0)/(double)(1l<<(i+1)); double r = (nmax - 4.0) / (double)(1l << (i + 1));
if( i==gh.levelmin() ) if (i == gh.levelmin())
ofst << std::setw(fwid) << std::setprecision(fprec) << r; ofst << std::setw(fwid) << std::setprecision(fprec) << r;
else else
ofst << "," << std::setw(fwid) << std::setprecision(fprec) << r; ofst << "," << std::setw(fwid) << std::setprecision(fprec) << r;
} }
ofst << "\nexp_refine=" << std::setw(fwid) << std::setprecision(fprec) << 10.0; ofst << "\nexp_refine=" << std::setw(fwid) << std::setprecision(fprec) << 10.0;
for( unsigned i=gh.levelmin()+1;i<gh.levelmax(); ++i) for (unsigned i = gh.levelmin() + 1; i < gh.levelmax(); ++i)
ofst << "," << std::setw(fwid) << std::setprecision(fprec) << 10.0; ofst << "," << std::setw(fwid) << std::setprecision(fprec) << 10.0;
ofst << "\n/\n"; ofst << "\n/\n";
} }
sprintf(ff,"%s/ramses.nml",fname_.c_str() ); snprintf(ff, 256, "%s/ramses.nml", fname_.c_str());
std::cout << " - The grafic2 output plug-in wrote the grid data to a partial\n" std::cout << " - The grafic2 output plug-in wrote the grid data to a partial\n"
<< " RAMSES namelist file \'" << ff << "\'\n"; << " RAMSES namelist file \'" << ff << "\'\n";
} }
public: public:
grafic2_output_plugin(config_file &cf)
grafic2_output_plugin( config_file& cf ) : output_plugin(cf)
: output_plugin( cf )
{ {
// create directory structure // create directory structure
remove( fname_.c_str() ); remove(fname_.c_str());
mkdir( fname_.c_str(), 0777 ); mkdir(fname_.c_str(), 0777);
for(unsigned ilevel=levelmin_; ilevel<=levelmax_; ++ilevel ) for (unsigned ilevel = levelmin_; ilevel <= levelmax_; ++ilevel)
{ {
char fp[256]; char fp[256];
sprintf(fp,"%s/level_%03d",fname_.c_str(), ilevel ); snprintf(fp,256, "%s/level_%03d", fname_.c_str(), ilevel);
mkdir( fp, 0777 ); mkdir(fp, 0777);
} }
bhavehydro_ = cf.get_value<bool>("setup", "baryons");
bhavehydro_ = cf.get_value<bool>("setup","baryons"); // metal_floor_ = cf.get_value_safe<float>("output","ramses_metal_floor",1e-5);
//metal_floor_ = cf.get_value_safe<float>("output","ramses_metal_floor",1e-5); passive_variable_index_ = cf.get_value_safe<int>("output", "ramses_pvar_idx", 1);
passive_variable_index_ = cf.get_value_safe<int>("output","ramses_pvar_idx",1); passive_variable_value_ = cf.get_value_safe<float>("output", "ramses_pvar_val", 1.0f);
passive_variable_value_ = cf.get_value_safe<float>("output","ramses_pvar_val",1.0f);
} }
/*~grafic2_output_plugin() /*~grafic2_output_plugin()
{ }*/ { }*/
void write_dm_position(int coord, const grid_hierarchy &gh)
void write_dm_position( int coord, const grid_hierarchy& gh )
{ {
double double
boxlength = cf_.get_value<double>("setup","boxlength"); boxlength = cf_.get_value<double>("setup", "boxlength");
for(unsigned ilevel=levelmin_; ilevel<=levelmax_; ++ilevel ) for (unsigned ilevel = levelmin_; ilevel <= levelmax_; ++ilevel)
{ {
char ff[256]; char ff[256];
sprintf(ff,"%s/level_%03d/ic_posc%c",fname_.c_str(), ilevel, (char)('x'+coord) ); snprintf(ff, 256, "%s/level_%03d/ic_posc%c", fname_.c_str(), ilevel, (char)('x' + coord));
std::ofstream ofs(ff,std::ios::binary|std::ios::trunc); std::ofstream ofs(ff, std::ios::binary | std::ios::trunc);
write_file_header( ofs, ilevel, gh ); write_file_header(ofs, ilevel, gh);
write_sliced_array( ofs, ilevel, gh, boxlength ); write_sliced_array(ofs, ilevel, gh, boxlength);
} }
} }
void write_dm_velocity( int coord, const grid_hierarchy& gh ) void write_dm_velocity(int coord, const grid_hierarchy &gh)
{ {
double double
boxlength = cf_.get_value<double>("setup","boxlength"); boxlength = cf_.get_value<double>("setup", "boxlength");
for(unsigned ilevel=levelmin_; ilevel<=levelmax_; ++ilevel ) for (unsigned ilevel = levelmin_; ilevel <= levelmax_; ++ilevel)
{ {
char ff[256]; char ff[256];
sprintf(ff,"%s/level_%03d/ic_velc%c",fname_.c_str(), ilevel, (char)('x'+coord) ); snprintf(ff, 256, "%s/level_%03d/ic_velc%c", fname_.c_str(), ilevel, (char)('x' + coord));
std::ofstream ofs(ff,std::ios::binary|std::ios::trunc); std::ofstream ofs(ff, std::ios::binary | std::ios::trunc);
write_file_header( ofs, ilevel, gh ); write_file_header(ofs, ilevel, gh);
write_sliced_array( ofs, ilevel, gh, boxlength ); write_sliced_array(ofs, ilevel, gh, boxlength);
} }
} }
void write_gas_velocity( int coord, const grid_hierarchy& gh ) void write_gas_velocity(int coord, const grid_hierarchy &gh)
{ {
double double
boxlength = cf_.get_value<double>("setup","boxlength"); boxlength = cf_.get_value<double>("setup", "boxlength");
for(unsigned ilevel=levelmin_; ilevel<=levelmax_; ++ilevel ) for (unsigned ilevel = levelmin_; ilevel <= levelmax_; ++ilevel)
{ {
char ff[256]; char ff[256];
sprintf(ff,"%s/level_%03d/ic_velb%c",fname_.c_str(), ilevel, (char)('x'+coord) ); snprintf(ff, 256, "%s/level_%03d/ic_velb%c", fname_.c_str(), ilevel, (char)('x' + coord));
std::ofstream ofs(ff,std::ios::binary|std::ios::trunc); std::ofstream ofs(ff, std::ios::binary | std::ios::trunc);
write_file_header( ofs, ilevel, gh ); write_file_header(ofs, ilevel, gh);
write_sliced_array( ofs, ilevel, gh, boxlength ); write_sliced_array(ofs, ilevel, gh, boxlength);
} }
} }
void write_gas_density( const grid_hierarchy& gh ) void write_gas_density(const grid_hierarchy &gh)
{ {
for(unsigned ilevel=levelmin_; ilevel<=levelmax_; ++ilevel ) for (unsigned ilevel = levelmin_; ilevel <= levelmax_; ++ilevel)
{ {
char ff[256]; char ff[256];
sprintf(ff,"%s/level_%03d/ic_deltab",fname_.c_str(), ilevel ); snprintf(ff, 256, "%s/level_%03d/ic_deltab", fname_.c_str(), ilevel);
std::ofstream ofs(ff,std::ios::binary|std::ios::trunc); std::ofstream ofs(ff, std::ios::binary | std::ios::trunc);
write_file_header( ofs, ilevel, gh ); write_file_header(ofs, ilevel, gh);
write_sliced_array( ofs, ilevel, gh ); write_sliced_array(ofs, ilevel, gh);
} }
} }
void write_dm_density(const grid_hierarchy &gh)
void write_dm_density( const grid_hierarchy& gh )
{ {
if(! bhavehydro_ ) if (!bhavehydro_)
write_gas_density(gh); write_gas_density(gh);
if( cf_.get_value_safe<bool>("output","ramses_nml",true) ) if (cf_.get_value_safe<bool>("output", "ramses_nml", true))
write_ramses_namelist(gh); write_ramses_namelist(gh);
else if( cf_.get_value_safe<bool>("output","ramses_old_nml",false) ) else if (cf_.get_value_safe<bool>("output", "ramses_old_nml", false))
write_ramses_namelist_old(gh); write_ramses_namelist_old(gh);
if( gh.levelmin() != gh.levelmax() ) if (gh.levelmin() != gh.levelmax())
write_refinement_mask( gh ); write_refinement_mask(gh);
} }
void write_dm_mass( const grid_hierarchy& gh ) void write_dm_mass(const grid_hierarchy &gh)
{ /* do nothing, not used... */ } { /* do nothing, not used... */
}
void write_dm_potential( const grid_hierarchy& gh ) void write_dm_potential(const grid_hierarchy &gh)
{ /* do nothing, not used... */ } { /* do nothing, not used... */
}
void write_gas_potential( const grid_hierarchy& gh ) void write_gas_potential(const grid_hierarchy &gh)
{ /* do nothing, not used... */ } { /* do nothing, not used... */
}
void write_gas_position( int coord, const grid_hierarchy& gh ) void write_gas_position(int coord, const grid_hierarchy &gh)
{ /* do nothing, not used... */ } { /* do nothing, not used... */
}
void finalize( void )
{ }
void finalize(void)
{
}
}; };
namespace{ namespace
{
output_plugin_creator_concrete<grafic2_output_plugin> creator("grafic2"); output_plugin_creator_concrete<grafic2_output_plugin> creator("grafic2");
} }

File diff suppressed because it is too large Load diff

View file

@ -270,8 +270,8 @@ protected:
/*** positions ***/ /*** positions ***/
sprintf (fc, "___ic_temp_%05d.bin", 100 * id_dm_pos + icomp); snprintf (fc, 256, "___ic_temp_%05d.bin", 100 * id_dm_pos + icomp);
sprintf (fb, "___ic_temp_%05d.bin", 100 * id_gas_pos + icomp); snprintf (fb, 256, "___ic_temp_%05d.bin", 100 * id_gas_pos + icomp);
iffs1.open (fc, nptot, npfine * sizeof (T_store)); iffs1.open (fc, nptot, npfine * sizeof (T_store));
iffs2.open (fb, nptot, npfine * sizeof (T_store)); iffs2.open (fb, nptot, npfine * sizeof (T_store));
@ -301,8 +301,8 @@ protected:
/*** velocities ***/ /*** velocities ***/
sprintf (fc, "___ic_temp_%05d.bin", 100 * id_dm_vel + icomp); snprintf (fc, 256, "___ic_temp_%05d.bin", 100 * id_dm_vel + icomp);
sprintf (fb, "___ic_temp_%05d.bin", 100 * id_gas_vel + icomp); snprintf (fb, 256, "___ic_temp_%05d.bin", 100 * id_gas_vel + icomp);
iffs1.open (fc, nptot, npfine * sizeof (T_store)); iffs1.open (fc, nptot, npfine * sizeof (T_store));
iffs2.open (fb, nptot, npfine * sizeof (T_store)); iffs2.open (fb, nptot, npfine * sizeof (T_store));
@ -351,21 +351,21 @@ protected:
char fnbx[256], fnby[256], fnbz[256], fnbvx[256], fnbvy[256], fnbvz[256], char fnbx[256], fnby[256], fnbz[256], fnbvx[256], fnbvy[256], fnbvz[256],
fnbm[256]; fnbm[256];
sprintf (fnx, "___ic_temp_%05d.bin", 100 * id_dm_pos + 0); snprintf (fnx, 256, "___ic_temp_%05d.bin", 100 * id_dm_pos + 0);
sprintf (fny, "___ic_temp_%05d.bin", 100 * id_dm_pos + 1); snprintf (fny, 256, "___ic_temp_%05d.bin", 100 * id_dm_pos + 1);
sprintf (fnz, "___ic_temp_%05d.bin", 100 * id_dm_pos + 2); snprintf (fnz, 256, "___ic_temp_%05d.bin", 100 * id_dm_pos + 2);
sprintf (fnvx, "___ic_temp_%05d.bin", 100 * id_dm_vel + 0); snprintf (fnvx,256, "___ic_temp_%05d.bin", 100 * id_dm_vel + 0);
sprintf (fnvy, "___ic_temp_%05d.bin", 100 * id_dm_vel + 1); snprintf (fnvy,256, "___ic_temp_%05d.bin", 100 * id_dm_vel + 1);
sprintf (fnvz, "___ic_temp_%05d.bin", 100 * id_dm_vel + 2); snprintf (fnvz,256, "___ic_temp_%05d.bin", 100 * id_dm_vel + 2);
sprintf (fnm, "___ic_temp_%05d.bin", 100 * id_dm_mass); snprintf (fnm, 256, "___ic_temp_%05d.bin", 100 * id_dm_mass);
sprintf (fnbx, "___ic_temp_%05d.bin", 100 * id_gas_pos + 0); snprintf (fnbx, 256, "___ic_temp_%05d.bin", 100 * id_gas_pos + 0);
sprintf (fnby, "___ic_temp_%05d.bin", 100 * id_gas_pos + 1); snprintf (fnby, 256, "___ic_temp_%05d.bin", 100 * id_gas_pos + 1);
sprintf (fnbz, "___ic_temp_%05d.bin", 100 * id_gas_pos + 2); snprintf (fnbz, 256, "___ic_temp_%05d.bin", 100 * id_gas_pos + 2);
sprintf (fnbvx, "___ic_temp_%05d.bin", 100 * id_gas_vel + 0); snprintf (fnbvx,256, "___ic_temp_%05d.bin", 100 * id_gas_vel + 0);
sprintf (fnbvy, "___ic_temp_%05d.bin", 100 * id_gas_vel + 1); snprintf (fnbvy,256, "___ic_temp_%05d.bin", 100 * id_gas_vel + 1);
sprintf (fnbvz, "___ic_temp_%05d.bin", 100 * id_gas_vel + 2); snprintf (fnbvz,256, "___ic_temp_%05d.bin", 100 * id_gas_vel + 2);
sprintf (fnbm, "___ic_temp_%05d.bin", 100 * id_gas_mass); snprintf (fnbm, 256, "___ic_temp_%05d.bin", 100 * id_gas_mass);
pistream ifs_x, ifs_y, ifs_z, ifs_vx, ifs_vy, ifs_vz, ifs_m; pistream ifs_x, ifs_y, ifs_z, ifs_vx, ifs_vy, ifs_vz, ifs_m;
@ -641,13 +641,13 @@ public:
unsigned levelmax = cf_.get_value<unsigned>("setup","levelmax"); unsigned levelmax = cf_.get_value<unsigned>("setup","levelmax");
sprintf(tempstr,"size(%d,0)",levelmax); snprintf(tempstr,256,"size(%d,0)",levelmax);
nfine[0] = cf_.get_value<unsigned>("setup",tempstr); nfine[0] = cf_.get_value<unsigned>("setup",tempstr);
sprintf(tempstr,"size(%d,1)",levelmax); snprintf(tempstr,256,"size(%d,1)",levelmax);
nfine[1] = cf_.get_value<unsigned>("setup",tempstr); nfine[1] = cf_.get_value<unsigned>("setup",tempstr);
sprintf(tempstr,"size(%d,2)",levelmax); snprintf(tempstr,256,"size(%d,2)",levelmax);
nfine[2] = cf_.get_value<unsigned>("setup",tempstr); nfine[2] = cf_.get_value<unsigned>("setup",tempstr);
if( nfine[0]!=nfine[1] || nfine[0]!=nfine[2] ) if( nfine[0]!=nfine[1] || nfine[0]!=nfine[2] )
@ -658,7 +658,7 @@ public:
double resfac = (double)nfine[0]/(double)np_resample_; double resfac = (double)nfine[0]/(double)np_resample_;
sprintf(tempstr,"%g",resfac*0.5); snprintf(tempstr,256,"%g",resfac*0.5);
cf_.insert_value("setup","baryon_staggering",std::string(tempstr)); cf_.insert_value("setup","baryon_staggering",std::string(tempstr));
cf_.insert_value("output","glass_cicdeconvolve","yes"); cf_.insert_value("output","glass_cicdeconvolve","yes");
@ -716,7 +716,7 @@ public:
temp_dat.reserve (block_buf_size_); temp_dat.reserve (block_buf_size_);
char temp_fname[256]; char temp_fname[256];
sprintf (temp_fname, "___ic_temp_%05d.bin", 100 * id_dm_mass); snprintf(temp_fname, 256, "___ic_temp_%05d.bin", 100 * id_dm_mass);
std::ofstream ofs_temp (temp_fname, std::ios::binary | std::ios::trunc); std::ofstream ofs_temp (temp_fname, std::ios::binary | std::ios::trunc);
@ -801,7 +801,7 @@ public:
temp_dat.reserve (block_buf_size_); temp_dat.reserve (block_buf_size_);
char temp_fname[256]; char temp_fname[256];
sprintf (temp_fname, "___ic_temp_%05d.bin", 100 * id_gas_mass); snprintf(temp_fname, 256, "___ic_temp_%05d.bin", 100 * id_gas_mass);
ofs_temp.open (temp_fname, std::ios::binary | std::ios::trunc); ofs_temp.open (temp_fname, std::ios::binary | std::ios::trunc);
@ -950,7 +950,7 @@ public:
char temp_fname[256]; char temp_fname[256];
sprintf (temp_fname, "___ic_temp_%05d.bin", 100 * id_dm_pos + coord); snprintf(temp_fname, 256, "___ic_temp_%05d.bin", 100 * id_dm_pos + coord);
std::ofstream ofs_temp (temp_fname, std::ios::binary | std::ios::trunc); std::ofstream ofs_temp (temp_fname, std::ios::binary | std::ios::trunc);
size_t blksize = sizeof (T_store) * nptot; size_t blksize = sizeof (T_store) * nptot;
@ -1063,7 +1063,7 @@ public:
double vfac = 2.894405 / (100.0 * astart_); double vfac = 2.894405 / (100.0 * astart_);
char temp_fname[256]; char temp_fname[256];
sprintf (temp_fname, "___ic_temp_%05d.bin", 100 * id_dm_vel + coord); snprintf(temp_fname, 256, "___ic_temp_%05d.bin", 100 * id_dm_vel + coord);
std::ofstream ofs_temp (temp_fname, std::ios::binary | std::ios::trunc); std::ofstream ofs_temp (temp_fname, std::ios::binary | std::ios::trunc);
size_t blksize = sizeof (T_store) * nptot; size_t blksize = sizeof (T_store) * nptot;
@ -1174,7 +1174,7 @@ public:
double vfac = 2.894405 / (100.0 * astart_); double vfac = 2.894405 / (100.0 * astart_);
char temp_fname[256]; char temp_fname[256];
sprintf (temp_fname, "___ic_temp_%05d.bin", 100 * id_gas_vel + coord); snprintf(temp_fname, 256, "___ic_temp_%05d.bin", 100 * id_gas_vel + coord);
std::ofstream ofs_temp (temp_fname, std::ios::binary | std::ios::trunc); std::ofstream ofs_temp (temp_fname, std::ios::binary | std::ios::trunc);
size_t blksize = sizeof (T_store) * npart; size_t blksize = sizeof (T_store) * npart;
@ -1268,7 +1268,7 @@ public:
char temp_fname[256]; char temp_fname[256];
sprintf (temp_fname, "___ic_temp_%05d.bin", 100 * id_gas_pos + coord); snprintf(temp_fname, 256, "___ic_temp_%05d.bin", 100 * id_gas_pos + coord);
std::ofstream ofs_temp (temp_fname, std::ios::binary | std::ios::trunc); std::ofstream ofs_temp (temp_fname, std::ios::binary | std::ios::trunc);
size_t blksize = sizeof (T_store) * npart; size_t blksize = sizeof (T_store) * npart;

View file

@ -92,7 +92,7 @@ void RNG_music::parse_random_parameters(void)
char seedstr[128]; char seedstr[128];
std::string tempstr; std::string tempstr;
bool noseed = false; bool noseed = false;
sprintf(seedstr, "seed[%d]", i); snprintf(seedstr,128, "seed[%d]", i);
if (pcf_->contains_key("random", seedstr)) if (pcf_->contains_key("random", seedstr))
tempstr = pcf_->get_value<std::string>("random", seedstr); tempstr = pcf_->get_value<std::string>("random", seedstr);
else else
@ -277,7 +277,7 @@ void RNG_music::store_rnd(int ilevel, rng *prng)
k0 = -lfac * shift[2]; k0 = -lfac * shift[2];
char fname[128]; char fname[128];
sprintf(fname, "grafic_wnoise_%04d.bin", ilevel); snprintf(fname, 128, "grafic_wnoise_%04d.bin", ilevel);
music::ulog.Print("Storing white noise field for grafic in file \'%s\'...", fname); music::ulog.Print("Storing white noise field for grafic in file \'%s\'...", fname);
@ -323,7 +323,7 @@ void RNG_music::store_rnd(int ilevel, rng *prng)
k0 = prefh_->offset_abs(ilevel, 2) - lfac * shift[2]; k0 = prefh_->offset_abs(ilevel, 2) - lfac * shift[2];
char fname[128]; char fname[128];
sprintf(fname, "grafic_wnoise_%04d.bin", ilevel); snprintf(fname, 128,"grafic_wnoise_%04d.bin", ilevel);
music::ulog.Print("Storing white noise field for grafic in file \'%s\'...", fname); music::ulog.Print("Storing white noise field for grafic in file \'%s\'...", fname);
music::dlog.Print("(%d,%d,%d) -- (%d,%d,%d) -- lfac = %d", nx, ny, nz, i0, j0, k0, lfac); music::dlog.Print("(%d,%d,%d) -- (%d,%d,%d) -- lfac = %d", nx, ny, nz, i0, j0, k0, lfac);
@ -370,7 +370,7 @@ void RNG_music::store_rnd(int ilevel, rng *prng)
k0 = -lfac * shift[2]; k0 = -lfac * shift[2];
char fname[128]; char fname[128];
sprintf(fname, "wnoise_%04d.bin", ilevel); snprintf(fname, 128,"wnoise_%04d.bin", ilevel);
music::ulog.Print("Storing white noise field in file \'%s\'...", fname); music::ulog.Print("Storing white noise field in file \'%s\'...", fname);
@ -416,7 +416,7 @@ void RNG_music::store_rnd(int ilevel, rng *prng)
k0 = prefh_->offset_abs(ilevel, 2) - lfac * shift[2] - margin[2]; k0 = prefh_->offset_abs(ilevel, 2) - lfac * shift[2] - margin[2];
char fname[128]; char fname[128];
sprintf(fname, "wnoise_%04d.bin", ilevel); snprintf(fname, 128,"wnoise_%04d.bin", ilevel);
music::ulog.Print("Storing white noise field in file \'%s\'...", fname); music::ulog.Print("Storing white noise field in file \'%s\'...", fname);
@ -500,7 +500,7 @@ void RNG_music::fill_grid(int ilevel, DensityGrid<real_t> &A)
if (disk_cached_) if (disk_cached_)
{ {
char fname[128]; char fname[128];
sprintf(fname, "wnoise_%04d.bin", ilevel); snprintf(fname, 128,"wnoise_%04d.bin", ilevel);
music::ulog.Print("Loading white noise from file \'%s\'...", fname); music::ulog.Print("Loading white noise from file \'%s\'...", fname);

View file

@ -264,7 +264,7 @@ music_wnoise_generator<T>::music_wnoise_generator(unsigned res, std::string rand
if (nx != res_ || ny != res_ || nz != res_) if (nx != res_ || ny != res_ || nz != res_)
{ {
char errmsg[128]; char errmsg[128];
sprintf(errmsg, "White noise file dimensions do not match level dimensions: %ux%ux%u vs. %u**3", nx, ny, nz, res_); snprintf(errmsg,128, "White noise file dimensions do not match level dimensions: %ux%ux%u vs. %u**3", nx, ny, nz, res_);
throw std::runtime_error(errmsg); throw std::runtime_error(errmsg);
} }

View file

@ -7,7 +7,9 @@
#include "densities.hh" #include "densities.hh"
#include "HDF_IO.hh" #include "HDF_IO.hh"
const int maxdim = 60, maxlev = 50, maxpow = 3 * maxdim; //const int maxdim = 60, maxlev = 50, maxpow = 3 * maxdim;
const int maxdim = 60, maxpow = 3 * maxdim;
typedef int rand_offset_[5]; typedef int rand_offset_[5];
typedef struct typedef struct
{ {

View file

@ -238,7 +238,7 @@ protected:
real_t krgood( real_t mu, real_t q, real_t dlnr, real_t kr ) real_t krgood( real_t mu, real_t q, real_t dlnr, real_t kr )
{ {
double krnew = kr; double krnew = kr;
complex cdgamma, zm, zp; complex zm, zp;
double arg, iarg, xneg, xpos, y; double arg, iarg, xneg, xpos, y;
gsl_sf_result g_a, g_p; gsl_sf_result g_a, g_p;
@ -321,7 +321,6 @@ protected:
std::ofstream ofsk(ofname.c_str()); std::ofstream ofsk(ofname.c_str());
double sum_in = 0.0;
ofsk << "# The power spectrum definition is smaller than CAMB by a factor 8 pi^3." ofsk << "# The power spectrum definition is smaller than CAMB by a factor 8 pi^3."
<< std::endl; << std::endl;
@ -335,8 +334,6 @@ protected:
RE(in[i]) = del*pow(k,1.5-q); RE(in[i]) = del*pow(k,1.5-q);
IM(in[i]) = 0.0; IM(in[i]) = 0.0;
sum_in += RE(in[i]);
ofsk << std::setw(16) << k <<std::setw(16) << del*del << std::setw(16) << T << std::endl; ofsk << std::setw(16) << k <<std::setw(16) << del*del << std::setw(16) << T << std::endl;
} }
ofsk.close(); ofsk.close();