From b2943be7c1cf3654f04104eb0d1336a30ecfb2bd Mon Sep 17 00:00:00 2001 From: Yohai Meiron Date: Sat, 28 Mar 2020 01:34:37 -0400 Subject: [PATCH] Improved HDF5 reader and added ASCII writer with custom precision --- io.cpp | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/io.cpp b/io.cpp index b1286af..dce1d55 100644 --- a/io.cpp +++ b/io.cpp @@ -1,4 +1,5 @@ #include "hdf5.h" +#include #include #include #include @@ -6,6 +7,18 @@ struct double3 {double x,y,z; }; +void ascii_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, int precision=10) +{ + int id_width = (int)log10(N-1) + 1; + char string_template[256]; + sprintf(string_template, "%%0%dd%%%d.%dE%%%d.%dE%%%d.%dE%%%d.%dE%%%d.%dE%%%d.%dE%%%d.%dE\n", id_width, precision+7, precision, precision+8, precision, precision+8, precision, precision+8, precision, precision+8, precision, precision+8, precision, precision+8, precision); + printf("%d\n", step_num); + printf("%d\n", N); + printf("%.16E\n", t); + for (int i=0; i