diff --git a/tools/restart2data.cpp b/tools/restart2data.cpp index 7500093493..05ebcaaef7 100644 --- a/tools/restart2data.cpp +++ b/tools/restart2data.cpp @@ -35,9 +35,15 @@ #define MAX_GROUP 32 +// these should match settings in src/lmptype.h + +typedef int tagint; +typedef int64_t bigint; + // same as write_restart.cpp -enum{VERSION,UNITS,NTIMESTEP,DIMENSION,NPROCS,PROCGRID_0,PROCGRID_1,PROCGRID_2, +enum{VERSION,SMALLINT,TAGINT,BIGINT, + UNITS,NTIMESTEP,DIMENSION,NPROCS,PROCGRID_0,PROCGRID_1,PROCGRID_2, NEWTON_PAIR,NEWTON_BOND,XPERIODIC,YPERIODIC,ZPERIODIC, BOUNDARY_00,BOUNDARY_01,BOUNDARY_10,BOUNDARY_11,BOUNDARY_20,BOUNDARY_21, ATOM_STYLE,NATOMS,NTYPES, @@ -65,7 +71,8 @@ class Data { // global settings char *version; - int ntimestep; + int size_smallint,size_tagint,size_bigint; + bigint ntimestep; int nprocs; char *unit_style; int dimension; @@ -79,8 +86,8 @@ class Data { int style_ellipsoid,style_full,style_granular; int style_hybrid,style_molecular,style_peri; - uint64_t natoms; - uint64_t nbonds,nangles,ndihedrals,nimpropers; + bigint natoms; + bigint nbonds,nangles,ndihedrals,nimpropers; int ntypes,nbondtypes,nangletypes,ndihedraltypes,nimpropertypes; int bond_per_atom,angle_per_atom,dihedral_per_atom,improper_per_atom; int triclinic; @@ -183,7 +190,8 @@ class Data { double *mass,*shape,*dipole; double *x,*y,*z,*vx,*vy,*vz; double *omegax,*omegay,*omegaz; - int *tag,*type,*mask,*image; + tagint *tag; + int *type,*mask,*image; int *molecule; double *q,*mux,*muy,*muz,*radius,*density,*vfrac,*rmass; double *s0,*x0x,*x0y,*x0z; @@ -287,7 +295,7 @@ int atom_peri(double *, Data &, int); int read_int(FILE *fp); double read_double(FILE *fp); char *read_char(FILE *fp); -uint64_t read_uint64(FILE *fp); +bigint read_bigint(FILE *fp); // --------------------------------------------------------------------- // main program @@ -332,6 +340,14 @@ int main (int argc, char **argv) Data data; header(fp,data); + if (data.size_smallint != sizeof(int) || + data.size_tagint != sizeof(tagint) || + data.size_bigint != sizeof(bigint)) { + printf("ERROR: Data type sizes in restart file " + "are incompatible with restart2data.cpp\n"); + return 1; + } + groups(fp); type_arrays(fp,data); force_fields(fp,data); @@ -434,8 +450,11 @@ void header(FILE *fp, Data &data) printf(" restart2data version = %s\n",version); } } + else if (flag == SMALLINT) data.size_smallint = read_int(fp); + else if (flag == TAGINT) data.size_tagint = read_int(fp); + else if (flag == BIGINT) data.size_bigint = read_int(fp); else if (flag == UNITS) data.unit_style = read_char(fp); - else if (flag == NTIMESTEP) data.ntimestep = read_int(fp); + else if (flag == NTIMESTEP) data.ntimestep = read_bigint(fp); else if (flag == DIMENSION) data.dimension = read_int(fp); else if (flag == NPROCS) data.nprocs = read_int(fp); else if (flag == PROCGRID_0) data.px = read_int(fp); @@ -478,18 +497,18 @@ void header(FILE *fp, Data &data) } } - else if (flag == NATOMS) data.natoms = read_uint64(fp); + else if (flag == NATOMS) data.natoms = read_bigint(fp); else if (flag == NTYPES) data.ntypes = read_int(fp); - else if (flag == NBONDS) data.nbonds = read_uint64(fp); + else if (flag == NBONDS) data.nbonds = read_bigint(fp); else if (flag == NBONDTYPES) data.nbondtypes = read_int(fp); else if (flag == BOND_PER_ATOM) data.bond_per_atom = read_int(fp); - else if (flag == NANGLES) data.nangles = read_uint64(fp); + else if (flag == NANGLES) data.nangles = read_bigint(fp); else if (flag == NANGLETYPES) data.nangletypes = read_int(fp); else if (flag == ANGLE_PER_ATOM) data.angle_per_atom = read_int(fp); - else if (flag == NDIHEDRALS) data.ndihedrals = read_uint64(fp); + else if (flag == NDIHEDRALS) data.ndihedrals = read_bigint(fp); else if (flag == NDIHEDRALTYPES) data.ndihedraltypes = read_int(fp); else if (flag == DIHEDRAL_PER_ATOM) data.dihedral_per_atom = read_int(fp); - else if (flag == NIMPROPERS) data.nimpropers = read_uint64(fp); + else if (flag == NIMPROPERS) data.nimpropers = read_bigint(fp); else if (flag == NIMPROPERTYPES) data.nimpropertypes = read_int(fp); else if (flag == IMPROPER_PER_ATOM) data.improper_per_atom = read_int(fp); else if (flag == BOXLO_0) data.xlo = read_double(fp); @@ -2599,11 +2618,19 @@ void Data::stats() printf(" Restart file version = %s\n",version); printf(" Ntimestep = %d\n",ntimestep); printf(" Nprocs = %d\n",nprocs); - printf(" Natoms = %lu\n",natoms); - printf(" Nbonds = %lu\n",nbonds); - printf(" Nangles = %lu\n",nangles); - printf(" Ndihedrals = %lu\n",ndihedrals); - printf(" Nimpropers = %lu\n",nimpropers); + if (size_bigint == 8) { + printf(" Natoms = %ld\n",natoms); + printf(" Nbonds = %ld\n",nbonds); + printf(" Nangles = %ld\n",nangles); + printf(" Ndihedrals = %ld\n",ndihedrals); + printf(" Nimpropers = %ld\n",nimpropers); + } else if (size_bigint == 4) { + printf(" Natoms = %d\n",natoms); + printf(" Nbonds = %d\n",nbonds); + printf(" Nangles = %d\n",nangles); + printf(" Ndihedrals = %d\n",ndihedrals); + printf(" Nimpropers = %d\n",nimpropers); + } printf(" Unit style = %s\n",unit_style); printf(" Atom style = %s\n",atom_style); printf(" Pair style = %s\n",pair_style); @@ -2626,16 +2653,30 @@ void Data::stats() void Data::write(FILE *fp, FILE *fp2) { - fprintf(fp,"LAMMPS data file from restart file: timestep = %d, procs = %d\n", - ntimestep,nprocs); + if (size_bigint == 8) + fprintf(fp, + "LAMMPS data file from restart file: timestep = %ld, procs = %d\n", + ntimestep,nprocs); + else + fprintf(fp, + "LAMMPS data file from restart file: timestep = %d, procs = %d\n", + ntimestep,nprocs); fprintf(fp,"\n"); - fprintf(fp,"%lu atoms\n",natoms); - if (nbonds) fprintf(fp,"%lu bonds\n",nbonds); - if (nangles) fprintf(fp,"%lu angles\n",nangles); - if (ndihedrals) fprintf(fp,"%lu dihedrals\n",ndihedrals); - if (nimpropers) fprintf(fp,"%lu impropers\n",nimpropers); + if (size_bigint == 8) { + fprintf(fp,"%ld atoms\n",natoms); + if (nbonds) fprintf(fp,"%ld bonds\n",nbonds); + if (nangles) fprintf(fp,"%ld angles\n",nangles); + if (ndihedrals) fprintf(fp,"%ld dihedrals\n",ndihedrals); + if (nimpropers) fprintf(fp,"%ld impropers\n",nimpropers); + } else if (size_bigint == 4) { + fprintf(fp,"%d atoms\n",natoms); + if (nbonds) fprintf(fp,"%d bonds\n",nbonds); + if (nangles) fprintf(fp,"%d angles\n",nangles); + if (ndihedrals) fprintf(fp,"%d dihedrals\n",ndihedrals); + if (nimpropers) fprintf(fp,"%d impropers\n",nimpropers); + } else fprintf(fp,"\n"); @@ -3484,10 +3525,9 @@ char *read_char(FILE *fp) return value; } -uint64_t read_uint64(FILE *fp) +bigint read_bigint(FILE *fp) { - uint64_t value; - fread(&value,sizeof(uint64_t),1,fp); + bigint value; + fread(&value,sizeof(bigint),1,fp); return value; } -