Update dump local and local/gz

This commit is contained in:
Richard Berger
2021-04-09 15:42:28 -04:00
parent d19cd8fb11
commit cf41ea6faf
5 changed files with 285 additions and 70 deletions

View File

@ -17,15 +17,13 @@
#ifdef LAMMPS_ZSTD
#include "dump_local_zstd.h"
#include "domain.h"
#include "dump_local_zstd.h"
#include "error.h"
#include "update.h"
#include <cstring>
using namespace LAMMPS_NS;
DumpLocalZstd::DumpLocalZstd(LAMMPS *lmp, int narg, char **arg) :
@ -42,7 +40,6 @@ DumpLocalZstd::~DumpLocalZstd()
{
}
/* ----------------------------------------------------------------------
generic opening of a dump file
ASCII or binary or gzipped
@ -145,7 +142,31 @@ void DumpLocalZstd::write_header(bigint ndump)
void DumpLocalZstd::write_data(int n, double *mybuf)
{
writer.write(mybuf, sizeof(char)*n);
if (buffer_flag == 1) {
writer.write(mybuf, sizeof(char)*n);
} else {
constexpr size_t VBUFFER_SIZE = 256;
char vbuffer[VBUFFER_SIZE];
int m = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < size_one; j++) {
int written = 0;
if (vtype[j] == Dump::INT) {
written = snprintf(vbuffer, VBUFFER_SIZE, vformat[j], static_cast<int> (mybuf[m]));
} else {
written = snprintf(vbuffer, VBUFFER_SIZE, vformat[j], mybuf[m]);
}
if (written > 0) {
writer.write(vbuffer, written);
} else if (written < 0) {
error->one(FLERR, "Error while writing dump local/gz output");
}
m++;
}
writer.write("\n", 1);
}
}
}
/* ---------------------------------------------------------------------- */
@ -184,7 +205,7 @@ int DumpLocalZstd::modify_param(int narg, char **arg)
return 2;
}
} catch (FileWriterException &e) {
error->one(FLERR, e.what());
error->one(FLERR, fmt::format("Illegal dump_modify command: {}", e.what()));
}
}
return consumed;