git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@8159 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
@ -17,6 +17,7 @@
|
||||
#include "group.h"
|
||||
#include "error.h"
|
||||
#include "memory.h"
|
||||
#include "update.h"
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
@ -31,10 +32,30 @@ DumpXYZ::DumpXYZ(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg)
|
||||
sort_flag = 1;
|
||||
sortcol = 0;
|
||||
|
||||
char *str = (char *) "%d %g %g %g";
|
||||
if (format_default) delete [] format_default;
|
||||
|
||||
char *str = (char *) "%s %g %g %g";
|
||||
int n = strlen(str) + 1;
|
||||
format_default = new char[n];
|
||||
strcpy(format_default,str);
|
||||
|
||||
ntypes = atom->ntypes;
|
||||
typenames = NULL;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
DumpXYZ::~DumpXYZ()
|
||||
{
|
||||
delete[] format_default;
|
||||
format_default = NULL;
|
||||
|
||||
if (typenames) {
|
||||
for (int i = 1; i <= ntypes; i++)
|
||||
delete [] typenames[i];
|
||||
delete [] typenames;
|
||||
typenames = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -51,6 +72,17 @@ void DumpXYZ::init_style()
|
||||
strcpy(format,str);
|
||||
strcat(format,"\n");
|
||||
|
||||
// initialize typenames array to be backward compatible by default
|
||||
// a 32-bit int can be maximally 10 digits plus sign
|
||||
|
||||
if (typenames == NULL) {
|
||||
typenames = new char*[ntypes+1];
|
||||
for (int itype = 1; itype <= ntypes; itype++) {
|
||||
typenames[itype] = new char[12];
|
||||
sprintf(typenames[itype],"%d",itype);
|
||||
}
|
||||
}
|
||||
|
||||
// open single file, one time only
|
||||
|
||||
if (multifile == 0) openfile();
|
||||
@ -58,31 +90,45 @@ void DumpXYZ::init_style()
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
int DumpXYZ::modify_param(int narg, char **arg)
|
||||
{
|
||||
if (strcmp(arg[0],"element") == 0) {
|
||||
if (narg < ntypes+1)
|
||||
error->all(FLERR, "Dump modify element names do not match atom types");
|
||||
|
||||
if (typenames) {
|
||||
for (int i = 1; i <= ntypes; i++)
|
||||
delete [] typenames[i];
|
||||
|
||||
delete [] typenames;
|
||||
typenames = NULL;
|
||||
}
|
||||
|
||||
typenames = new char*[ntypes+1];
|
||||
for (int itype = 1; itype <= ntypes; itype++) {
|
||||
int n = strlen(arg[itype]) + 1;
|
||||
typenames[itype] = new char[n];
|
||||
strcpy(typenames[itype],arg[itype]);
|
||||
}
|
||||
|
||||
return ntypes+1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void DumpXYZ::write_header(bigint n)
|
||||
{
|
||||
if (me == 0) {
|
||||
fprintf(fp,BIGINT_FORMAT "\n",n);
|
||||
fprintf(fp,"Atoms\n");
|
||||
fprintf(fp,"Atoms. Timestep: " BIGINT_FORMAT "\n",update->ntimestep);
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
int DumpXYZ::count()
|
||||
{
|
||||
if (igroup == 0) return atom->nlocal;
|
||||
|
||||
int *mask = atom->mask;
|
||||
int nlocal = atom->nlocal;
|
||||
|
||||
int m = 0;
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) m++;
|
||||
return m;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void DumpXYZ::pack(int *ids)
|
||||
{
|
||||
int m,n;
|
||||
@ -112,7 +158,8 @@ void DumpXYZ::write_data(int n, double *mybuf)
|
||||
int m = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
fprintf(fp,format,
|
||||
static_cast<int> (mybuf[m+1]),mybuf[m+2],mybuf[m+3],mybuf[m+4]);
|
||||
typenames[static_cast<int> (mybuf[m+1])],
|
||||
mybuf[m+2],mybuf[m+3],mybuf[m+4]);
|
||||
m += size_one;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user