Make dump custom/gz, custom/zstd compatible to 'buffer no' option
This commit is contained in:
@ -133,7 +133,35 @@ void DumpCustomGZ::write_header(bigint ndump)
|
||||
|
||||
void DumpCustomGZ::write_data(int n, double *mybuf)
|
||||
{
|
||||
writer.write(mybuf, n);
|
||||
if (buffer_flag == 1) {
|
||||
writer.write(mybuf, 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 < nfield; j++) {
|
||||
int written = 0;
|
||||
if (vtype[j] == Dump::INT) {
|
||||
written = snprintf(vbuffer, VBUFFER_SIZE, vformat[j], static_cast<int> (mybuf[m]));
|
||||
} else if (vtype[j] == Dump::DOUBLE) {
|
||||
written = snprintf(vbuffer, VBUFFER_SIZE, vformat[j], mybuf[m]);
|
||||
} else if (vtype[j] == Dump::STRING) {
|
||||
written = snprintf(vbuffer, VBUFFER_SIZE, vformat[j], typenames[(int) mybuf[m]]);
|
||||
} else if (vtype[j] == Dump::BIGINT) {
|
||||
written = snprintf(vbuffer, VBUFFER_SIZE, vformat[j], static_cast<bigint> (mybuf[m]));
|
||||
}
|
||||
|
||||
if (written > 0) {
|
||||
writer.write(vbuffer, written);
|
||||
} else if (written < 0) {
|
||||
error->one(FLERR, "Error while writing dump custom/gz output");
|
||||
}
|
||||
m++;
|
||||
}
|
||||
writer.write("\n", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
@ -146,7 +146,35 @@ void DumpCustomZstd::write_header(bigint ndump)
|
||||
|
||||
void DumpCustomZstd::write_data(int n, double *mybuf)
|
||||
{
|
||||
writer.write(mybuf, n);
|
||||
if (buffer_flag == 1) {
|
||||
writer.write(mybuf, 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 < nfield; j++) {
|
||||
int written = 0;
|
||||
if (vtype[j] == Dump::INT) {
|
||||
written = snprintf(vbuffer, VBUFFER_SIZE, vformat[j], static_cast<int> (mybuf[m]));
|
||||
} else if (vtype[j] == Dump::DOUBLE) {
|
||||
written = snprintf(vbuffer, VBUFFER_SIZE, vformat[j], mybuf[m]);
|
||||
} else if (vtype[j] == Dump::STRING) {
|
||||
written = snprintf(vbuffer, VBUFFER_SIZE, vformat[j], typenames[(int) mybuf[m]]);
|
||||
} else if (vtype[j] == Dump::BIGINT) {
|
||||
written = snprintf(vbuffer, VBUFFER_SIZE, vformat[j], static_cast<bigint> (mybuf[m]));
|
||||
}
|
||||
|
||||
if (written > 0) {
|
||||
writer.write(vbuffer, written);
|
||||
} else if (written < 0) {
|
||||
error->one(FLERR, "Error while writing dump custom/gz output");
|
||||
}
|
||||
m++;
|
||||
}
|
||||
writer.write("\n", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
@ -87,6 +87,35 @@ TEST_F(DumpCustomCompressTest, compressed_with_time_run1)
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpCustomCompressTest, compressed_no_buffer_run1)
|
||||
{
|
||||
if (!COMPRESS_BINARY) GTEST_SKIP();
|
||||
|
||||
auto base_name = "no_buffer_custom_run1.melt";
|
||||
auto text_file = text_dump_filename(base_name);
|
||||
auto compressed_file = compressed_dump_filename(base_name);
|
||||
auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz";
|
||||
|
||||
if(compression_style == "custom/zstd") {
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, fields, fields, "buffer no", "buffer no checksum yes", 1);
|
||||
} else {
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, fields, "buffer no", 1);
|
||||
}
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpCustomCompressTest, compressed_triclinic_run1)
|
||||
{
|
||||
if (!COMPRESS_BINARY) GTEST_SKIP();
|
||||
|
||||
Reference in New Issue
Block a user