Make dump atom/gz, atom/zstd compatible to 'buffer no' option
This commit is contained in:
@ -135,7 +135,33 @@ void DumpAtomGZ::write_header(bigint ndump)
|
||||
|
||||
void DumpAtomGZ::write_data(int n, double *mybuf)
|
||||
{
|
||||
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++) {
|
||||
int written = 0;
|
||||
if (image_flag == 1) {
|
||||
written = snprintf(vbuffer, VBUFFER_SIZE, format,
|
||||
static_cast<tagint> (mybuf[m]), static_cast<int> (mybuf[m+1]),
|
||||
mybuf[m+2],mybuf[m+3],mybuf[m+4], static_cast<int> (mybuf[m+5]),
|
||||
static_cast<int> (mybuf[m+6]), static_cast<int> (mybuf[m+7]));
|
||||
} else {
|
||||
written = snprintf(vbuffer, VBUFFER_SIZE, format,
|
||||
static_cast<tagint> (mybuf[m]), static_cast<int> (mybuf[m+1]),
|
||||
mybuf[m+2],mybuf[m+3],mybuf[m+4]);
|
||||
}
|
||||
if (written > 0) {
|
||||
writer.write(vbuffer, written);
|
||||
} else if (written < 0) {
|
||||
error->one(FLERR, "Error while writing dump atom/gz output");
|
||||
}
|
||||
|
||||
m += size_one;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
@ -143,7 +143,33 @@ void DumpAtomZstd::write_header(bigint ndump)
|
||||
|
||||
void DumpAtomZstd::write_data(int n, double *mybuf)
|
||||
{
|
||||
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++) {
|
||||
int written = 0;
|
||||
if (image_flag == 1) {
|
||||
written = snprintf(vbuffer, VBUFFER_SIZE, format,
|
||||
static_cast<tagint> (mybuf[m]), static_cast<int> (mybuf[m+1]),
|
||||
mybuf[m+2],mybuf[m+3],mybuf[m+4], static_cast<int> (mybuf[m+5]),
|
||||
static_cast<int> (mybuf[m+6]), static_cast<int> (mybuf[m+7]));
|
||||
} else {
|
||||
written = snprintf(vbuffer, VBUFFER_SIZE, format,
|
||||
static_cast<tagint> (mybuf[m]), static_cast<int> (mybuf[m+1]),
|
||||
mybuf[m+2],mybuf[m+3],mybuf[m+4]);
|
||||
}
|
||||
if (written > 0) {
|
||||
writer.write(vbuffer, written);
|
||||
} else if (written < 0) {
|
||||
error->one(FLERR, "Error while writing dump atom/gz output");
|
||||
}
|
||||
|
||||
m += size_one;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
@ -61,6 +61,34 @@ TEST_F(DumpAtomCompressTest, compressed_run0)
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpAtomCompressTest, compressed_no_buffer_run0)
|
||||
{
|
||||
if (!COMPRESS_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_file = text_dump_filename("no_buffer_run0.melt");
|
||||
auto compressed_file = compressed_dump_filename("no_buffer_run0.melt");
|
||||
|
||||
if(compression_style == "atom/zstd") {
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, "", "", "buffer no", "buffer no checksum yes", 0);
|
||||
} else {
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, "", "buffer no", 0);
|
||||
}
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_THAT(converted_file, Eq(converted_dump_filename("no_buffer_run0.melt")));
|
||||
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(DumpAtomCompressTest, compressed_multi_file_run1)
|
||||
{
|
||||
if (!COMPRESS_BINARY) GTEST_SKIP();
|
||||
|
||||
Reference in New Issue
Block a user