Add compression_level parameter to dump atom gz

This commit is contained in:
Richard Berger
2020-08-26 00:14:32 -04:00
parent 5cb8e73655
commit e0439ac94f
2 changed files with 27 additions and 2 deletions

View File

@ -15,8 +15,10 @@
#include "domain.h"
#include "error.h"
#include "update.h"
#include "force.h"
#include <cstring>
#include <fmt/format.h>
using namespace LAMMPS_NS;
@ -25,6 +27,8 @@ DumpAtomGZ::DumpAtomGZ(LAMMPS *lmp, int narg, char **arg) :
{
gzFp = NULL;
compression_level = 9;
if (!compressed)
error->all(FLERR,"Dump atom/gz only writes compressed files");
}
@ -89,12 +93,15 @@ void DumpAtomGZ::openfile()
// each proc with filewriter = 1 opens a file
if (filewriter) {
std::string mode;
if (append_flag) {
gzFp = gzopen(filecurrent,"ab9");
mode = fmt::format("ab{}", compression_level);
} else {
gzFp = gzopen(filecurrent,"wb9");
mode = fmt::format("wb{}", compression_level);
}
gzFp = gzopen(filecurrent, mode.c_str());
if (gzFp == NULL) error->one(FLERR,"Cannot open dump file");
} else gzFp = NULL;
@ -156,3 +163,18 @@ void DumpAtomGZ::write()
}
}
/* ---------------------------------------------------------------------- */
int DumpAtomGZ::modify_param(int narg, char **arg)
{
int consumed = DumpAtom::modify_param(narg, arg);
if(consumed == 0) {
if (strcmp(arg[0],"compression_level") == 0) {
if (narg < 2) error->all(FLERR,"Illegal dump_modify command");
compression_level = force->inumeric(FLERR,arg[1]);
if (compression_level <= 0) error->all(FLERR,"Illegal dump_modify command");
return 2;
}
}
return consumed;
}

View File

@ -31,12 +31,15 @@ class DumpAtomGZ : public DumpAtom {
virtual ~DumpAtomGZ();
protected:
int compression_level;
gzFile gzFp; // file pointer for the compressed output stream
virtual void openfile();
virtual void write_header(bigint);
virtual void write_data(int, double *);
virtual void write();
virtual int modify_param(int, char **);
};
}