Cleaned up energy control as well as many other things
This commit is contained in:
parent
df5d89a0c8
commit
d046c189b3
4 changed files with 99 additions and 7556 deletions
18
io.cpp
18
io.cpp
|
|
@ -24,7 +24,7 @@ bool is_hdf5(std::string file_name)
|
|||
return result;
|
||||
}
|
||||
|
||||
void ascii_read(const std::string file_name, int *step_num, int *N, double *t, double *m, double3 *x, double3 *v)
|
||||
void ascii_read(const std::string file_name, int& step_num, int& N, double& t, double **m, double3 **x, double3 **v)
|
||||
{
|
||||
char rest[512];
|
||||
int result;
|
||||
|
|
@ -34,21 +34,25 @@ void ascii_read(const std::string file_name, int *step_num, int *N, double *t, d
|
|||
std::string str;
|
||||
|
||||
std::getline(file, str);
|
||||
result = sscanf(str.c_str(), "%d%s", step_num, rest);
|
||||
result = sscanf(str.c_str(), "%d%s", &step_num, rest);
|
||||
if (result!=1) throw std::runtime_error("Error parsing line 1: expected one integer");
|
||||
|
||||
std::getline(file, str);
|
||||
result = sscanf(str.c_str(), "%d%s", N, rest);
|
||||
result = sscanf(str.c_str(), "%d%s", &N, rest);
|
||||
if (result!=1) throw std::runtime_error("Error parsing line 2: expected one integer");
|
||||
|
||||
std::getline(file, str);
|
||||
result = sscanf(str.c_str(), "%lf%s", t, rest);
|
||||
result = sscanf(str.c_str(), "%lf%s", &t, rest);
|
||||
if (result!=1) throw std::runtime_error("Error parsing line 3: expected one real number");
|
||||
|
||||
*m = new double[N];
|
||||
*x = new double3[N];
|
||||
*v = new double3[N];
|
||||
|
||||
int i = -1;
|
||||
while (std::getline(file, str)) {
|
||||
if (++i > *N) throw std::runtime_error("Error parsing line " + std::to_string(i+4) + ": particle out of range");
|
||||
result = sscanf(str.c_str(), "%*s %lf %lf %lf %lf %lf %lf %lf%s", &m[i], &x[i][0], &x[i][1], &x[i][2], &v[i][0], &v[i][1], &v[i][2], rest);
|
||||
if (++i > N) throw std::runtime_error("Error parsing line " + std::to_string(i+4) + ": particle out of range");
|
||||
result = sscanf(str.c_str(), "%*s %lf %lf %lf %lf %lf %lf %lf%s", &(*m)[i], &(*x)[i][0], &(*x)[i][1], &(*x)[i][2], &(*v)[i][0], &(*v)[i][1], &(*v)[i][2], rest);
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
|
@ -145,7 +149,7 @@ void h5_read(const std::string file_name, int *step_num, int *N, double *t, doub
|
|||
void h5_write(const std::string file_name, const int step_num, const int N, const double t, const double *m, const double3 *x, const double3 *v, const double *pot, const double3 *acc, const double3 *jrk, const int extra_mode=0, const bool use_double_precision=true)
|
||||
{
|
||||
#ifdef HAS_HDF5
|
||||
hid_t file_id, group_id, attribute_id, dataset_id, dataspace_id;
|
||||
hid_t file_id, group_id, attribute_id, dataspace_id;
|
||||
hsize_t dims[2] = {(hsize_t)N, 3};
|
||||
|
||||
hid_t h5_float_type;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue