reverse formatting on irrelevant files

This commit is contained in:
nw13slx
2021-12-11 14:10:47 -05:00
parent eff26ba0b3
commit e9f0351b67
2 changed files with 42 additions and 72 deletions

View File

@ -72,11 +72,11 @@
struct compress_info {
/// identifier for the different compression algorithms
enum styles { NONE, GZIP, BZIP2, ZSTD, XZ, LZMA, LZ4 };
const std::string extension; ///< filename extension for the current algorithm
const std::string command; ///< command to perform compression or decompression
const std::string extension; ///< filename extension for the current algorithm
const std::string command; ///< command to perform compression or decompression
const std::string compressflags; ///< flags to append to compress from stdin to stdout
const std::string uncompressflags; ///< flags to decompress file to stdout
const int style; ///< compression style flag
const int style; ///< compression style flag
};
// clang-format off
@ -230,16 +230,16 @@ std::string platform::os_info()
if (platform::file_is_readable("/etc/os-release")) {
try {
TextFileReader reader("/etc/os-release", "");
while (true) {
auto words = reader.next_values(0, "=");
if ((words.count() > 1) && (words.next_string() == "PRETTY_NAME")) {
buf += " " + utils::trim(words.next_string());
break;
TextFileReader reader("/etc/os-release","");
while (true) {
auto words = reader.next_values(0,"=");
if ((words.count() > 1) && (words.next_string() == "PRETTY_NAME")) {
buf += " " + utils::trim(words.next_string());
break;
}
}
}
} catch (std::exception &e) {
; // EOF but keyword not found
; // EOF but keyword not found
}
}
@ -427,11 +427,11 @@ std::string platform::compress_info()
std::string buf = "Available compression formats:\n\n";
bool none_found = true;
for (const auto &cmpi : compress_styles) {
if (cmpi.style == ::compress_info::NONE) continue;
if (find_exe_path(cmpi.command).size()) {
none_found = false;
buf += fmt::format("Extension: .{:6} Command: {}\n", cmpi.extension, cmpi.command);
}
if (cmpi.style == ::compress_info::NONE) continue;
if (find_exe_path(cmpi.command).size()) {
none_found = false;
buf += fmt::format("Extension: .{:6} Command: {}\n", cmpi.extension, cmpi.command);
}
}
if (none_found) buf += "None\n";
return buf;
@ -450,7 +450,7 @@ int platform::putenv(const std::string &vardef)
if (found == std::string::npos)
return _putenv_s(vardef.c_str(), "1");
else
return _putenv_s(vardef.substr(0, found).c_str(), vardef.substr(found + 1).c_str());
return _putenv_s(vardef.substr(0, found).c_str(), vardef.substr(found+1).c_str());
#else
if (found == std::string::npos)
return setenv(vardef.c_str(), "", 1);
@ -472,7 +472,7 @@ int platform::unsetenv(const std::string &variable)
const char *ptr = getenv(variable.c_str());
if (!ptr) return -1;
// empty _putenv_s() definition deletes variable
return _putenv_s(variable.c_str(), "");
return _putenv_s(variable.c_str(),"");
#else
return ::unsetenv(variable.c_str());
#endif
@ -579,10 +579,8 @@ void *platform::dlopen(const std::string &fname)
std::string platform::dlerror()
{
const char *errmesg = ::dlerror();
if (errmesg)
return {errmesg};
else
return {""};
if (errmesg) return {errmesg};
else return {""};
}
// close a shared object
@ -986,8 +984,6 @@ FILE *platform::compressed_read(const std::string &file)
if (find_exe_path(compress.command).size())
// put quotes around file name so that they may contain blanks
fp = popen((compress.command + compress.uncompressflags + "\"" + file + "\""), "r");
else
fp = popen("", "r");
#endif
return fp;
}

View File

@ -67,21 +67,18 @@ int main(int narg, char **arg)
int maxbuf = 0;
double *buf = nullptr;
if (narg == 1)
{
if (narg == 1) {
printf("Syntax: binary2txt file1 file2 ...\n");
return 1;
}
// loop over files
for (int iarg = 1; iarg < narg; iarg++)
{
for (int iarg = 1; iarg < narg; iarg++) {
printf("%s:", arg[iarg]);
fflush(stdout);
FILE *fp = fopen(arg[iarg], "rb");
if (!fp)
{
if (!fp) {
printf("ERROR: Could not open %s\n", arg[iarg]);
return 1;
}
@ -100,8 +97,7 @@ int main(int narg, char **arg)
// loop over snapshots in file
while (true)
{
while (true) {
int endian = 0x0001;
int revision = 0x0001;
@ -109,16 +105,14 @@ int main(int narg, char **arg)
// detect end-of-file
if (feof(fp))
{
if (feof(fp)) {
fclose(fp);
fclose(fptxt);
break;
}
// detect newer format
if (ntimestep < 0)
{
if (ntimestep < 0) {
// first bigint encodes negative format name length
bigint magic_string_len = -ntimestep;
@ -146,23 +140,20 @@ int main(int narg, char **arg)
fread(&yhi, sizeof(double), 1, fp);
fread(&zlo, sizeof(double), 1, fp);
fread(&zhi, sizeof(double), 1, fp);
if (triclinic)
{
if (triclinic) {
fread(&xy, sizeof(double), 1, fp);
fread(&xz, sizeof(double), 1, fp);
fread(&yz, sizeof(double), 1, fp);
}
fread(&size_one, sizeof(int), 1, fp);
if (magic_string && revision > 0x0001)
{
if (magic_string && revision > 0x0001) {
// newer format includes units string, columns string
// and time
int len = 0;
fread(&len, sizeof(int), 1, fp);
if (len > 0)
{
if (len > 0) {
// has units
delete[] unit_style;
unit_style = new char[len + 1];
@ -175,8 +166,7 @@ int main(int narg, char **arg)
char flag = 0;
fread(&flag, sizeof(char), 1, fp);
if (flag)
{
if (flag) {
double time;
fread(&time, sizeof(double), 1, fp);
fprintf(fptxt, "ITEM: TIME\n%.16g\n", time);
@ -197,10 +187,8 @@ int main(int narg, char **arg)
fprintf(fptxt, BIGINT_FORMAT "\n", natoms);
m = 0;
for (int idim = 0; idim < 3; idim++)
{
for (int iside = 0; iside < 2; iside++)
{
for (int idim = 0; idim < 3; idim++) {
for (int iside = 0; iside < 2; iside++) {
if (boundary[idim][iside] == 0)
boundstr[m++] = 'p';
else if (boundary[idim][iside] == 1)
@ -214,15 +202,12 @@ int main(int narg, char **arg)
}
boundstr[8] = '\0';
if (!triclinic)
{
if (!triclinic) {
fprintf(fptxt, "ITEM: BOX BOUNDS %s\n", boundstr);
fprintf(fptxt, "%-1.16e %-1.16e\n", xlo, xhi);
fprintf(fptxt, "%-1.16e %-1.16e\n", ylo, yhi);
fprintf(fptxt, "%-1.16e %-1.16e\n", zlo, zhi);
}
else
{
} else {
fprintf(fptxt, "ITEM: BOX BOUNDS xy xz yz %s\n", boundstr);
fprintf(fptxt, "%-1.16e %-1.16e %-1.16e\n", xlo, xhi, xy);
fprintf(fptxt, "%-1.16e %-1.16e %-1.16e\n", ylo, yhi, xz);
@ -236,17 +221,13 @@ int main(int narg, char **arg)
// loop over processor chunks in file
for (i = 0; i < nchunk; i++)
{
for (i = 0; i < nchunk; i++) {
fread(&n, sizeof(int), 1, fp);
// extend buffer to fit chunk size
if (n > maxbuf)
{
if (buf)
delete[] buf;
if (n > maxbuf) {
if (buf) delete[] buf;
buf = new double[n];
maxbuf = n;
}
@ -256,17 +237,11 @@ int main(int narg, char **arg)
fread(buf, sizeof(double), n, fp);
n /= size_one;
m = 0;
std::string line = "";
for (j = 0; j < n; j++)
{
for (k = 0; k < size_one; k++)
{
if (k + 1 < size_one)
{
for (j = 0; j < n; j++) {
for (k = 0; k < size_one; k++) {
if (k + 1 < size_one) {
fprintf(fptxt, "%g ", buf[m++]);
}
else
{
} else {
fprintf(fptxt, "%g", buf[m++]);
}
}
@ -286,7 +261,6 @@ int main(int narg, char **arg)
unit_style = nullptr;
}
if (buf)
delete[] buf;
if (buf) delete[] buf;
return 0;
}