Extends header of new binary format of dump atom
This commit is contained in:
@ -166,13 +166,44 @@ void DumpAtom::write_data(int n, double *mybuf)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void DumpAtom::header_binary(bigint ndump)
|
||||
void DumpAtom::format_magic_string_binary()
|
||||
{
|
||||
// use negative ntimestep as marker for new format
|
||||
bigint fmtlen = strlen("DUMPATOM");
|
||||
bigint fmtlen = strlen(MAGIC_STRING);
|
||||
bigint marker = -fmtlen;
|
||||
fwrite(&marker, sizeof(bigint), 1, fp);
|
||||
fwrite("DUMPATOM",sizeof(char),fmtlen,fp);
|
||||
fwrite(MAGIC_STRING, sizeof(char), fmtlen, fp);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void DumpAtom::format_endian_binary()
|
||||
{
|
||||
int endian = ENDIAN;
|
||||
fwrite(&endian, sizeof(int), 1, fp);
|
||||
}
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void DumpAtom::format_revision_binary()
|
||||
{
|
||||
int revision = FORMAT_REVISION;
|
||||
fwrite(&revision, sizeof(int), 1, fp);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void DumpAtom::header_format_binary()
|
||||
{
|
||||
format_magic_string_binary();
|
||||
format_endian_binary();
|
||||
format_revision_binary();
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void DumpAtom::header_binary(bigint ndump)
|
||||
{
|
||||
header_format_binary();
|
||||
fwrite(&update->ntimestep,sizeof(bigint),1,fp);
|
||||
fwrite(&ndump,sizeof(bigint),1,fp);
|
||||
fwrite(&domain->triclinic,sizeof(int),1,fp);
|
||||
@ -197,11 +228,7 @@ void DumpAtom::header_binary(bigint ndump)
|
||||
|
||||
void DumpAtom::header_binary_triclinic(bigint ndump)
|
||||
{
|
||||
// use negative ntimestep as marker for new format
|
||||
bigint fmtlen = strlen("DUMPATOM");
|
||||
bigint marker = -fmtlen;
|
||||
fwrite(&marker,sizeof(bigint),1,fp);
|
||||
fwrite("DUMPATOM",sizeof(char),fmtlen,fp);
|
||||
header_format_binary();
|
||||
fwrite(&update->ntimestep,sizeof(bigint),1,fp);
|
||||
fwrite(&ndump,sizeof(bigint),1,fp);
|
||||
fwrite(&domain->triclinic,sizeof(int),1,fp);
|
||||
|
||||
@ -28,6 +28,10 @@ class DumpAtom : public Dump {
|
||||
public:
|
||||
DumpAtom(LAMMPS *, int, char**);
|
||||
|
||||
const char * MAGIC_STRING = "DUMPATOM";
|
||||
const int FORMAT_REVISION = 0x0002;
|
||||
const int ENDIAN = 0x0001;
|
||||
|
||||
protected:
|
||||
int scale_flag; // 1 if atom coords are scaled, 0 if no
|
||||
int image_flag; // 1 if append box count to atom coords, 0 if no
|
||||
@ -41,6 +45,11 @@ class DumpAtom : public Dump {
|
||||
int convert_string(int, double *);
|
||||
void write_data(int, double *);
|
||||
|
||||
void header_format_binary();
|
||||
void format_magic_string_binary();
|
||||
void format_endian_binary();
|
||||
void format_revision_binary();
|
||||
|
||||
typedef void (DumpAtom::*FnPtrHeader)(bigint);
|
||||
FnPtrHeader header_choice; // ptr to write header functions
|
||||
void header_binary(bigint);
|
||||
|
||||
@ -91,13 +91,15 @@ int main(int narg, char **arg)
|
||||
delete [] filetxt;
|
||||
|
||||
// detect newer format
|
||||
char * formatname = nullptr;
|
||||
char * magic_string = nullptr;
|
||||
char * columns = nullptr;
|
||||
|
||||
|
||||
// loop over snapshots in file
|
||||
|
||||
while (1) {
|
||||
int endian = 0x0001;
|
||||
int revision = 0x0001;
|
||||
|
||||
fread(&ntimestep,sizeof(bigint),1,fp);
|
||||
|
||||
@ -112,12 +114,18 @@ int main(int narg, char **arg)
|
||||
// detect newer format
|
||||
if (ntimestep < 0) {
|
||||
// first bigint encodes negative format name length
|
||||
bigint formatlen = -ntimestep;
|
||||
bigint magic_string_len = -ntimestep;
|
||||
|
||||
delete [] formatname;
|
||||
formatname = new char[formatlen + 1];
|
||||
fread(formatname, sizeof(char), formatlen, fp);
|
||||
formatname[formatlen] = '\0';
|
||||
delete [] magic_string;
|
||||
magic_string = new char[magic_string_len + 1];
|
||||
fread(magic_string, sizeof(char), magic_string_len, fp);
|
||||
magic_string[magic_string_len] = '\0';
|
||||
|
||||
// read endian flag
|
||||
fread(&endian, sizeof(int), 1, fp);
|
||||
|
||||
// read revision number
|
||||
fread(&revision, sizeof(int), 1, fp);
|
||||
|
||||
// read the real ntimestep
|
||||
fread(&ntimestep,sizeof(bigint),1,fp);
|
||||
@ -139,7 +147,7 @@ int main(int narg, char **arg)
|
||||
}
|
||||
fread(&size_one,sizeof(int),1,fp);
|
||||
|
||||
if (formatname) {
|
||||
if (magic_string && revision > 0x0001) {
|
||||
// newer format includes columns string
|
||||
int len = 0;
|
||||
fread(&len, sizeof(int), 1, fp);
|
||||
@ -220,7 +228,7 @@ int main(int narg, char **arg)
|
||||
}
|
||||
printf("\n");
|
||||
delete [] columns;
|
||||
delete [] formatname;
|
||||
delete [] magic_string;
|
||||
}
|
||||
|
||||
if (buf) delete [] buf;
|
||||
|
||||
Reference in New Issue
Block a user