Unverified Commit d4dbc32b authored by Axel Kohlmeyer's avatar Axel Kohlmeyer Committed by GitHub
Browse files

Merge pull request #1672 from akohlmey/dump-with-unit

Add ITEM: UNITS line to native text format dumps
parents eab66f27 c37d0011
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -21,7 +21,8 @@ dump ID group-ID style N file args :pre

ID = user-assigned name for the dump :ulb,l
group-ID = ID of the group of atoms to be dumped :l
style = {atom} or {atom/gz} or {atom/mpiio} or {cfg} or {cfg/gz} or {cfg/mpiio} or {custom} or {custom/gz} or {custom/mpiio} or {dcd} or {h5md} or {image} or {local} or {molfile} or {movie} or {netcdf} or {netcdf/mpiio} or {vtk} or {xtc} or {xyz} or {xyz/gz} or {xyz/mpiio} :l
style = {atom} or {atom/gz} or {atom/mpiio} or {cfg} or {cfg/gz} or
{cfg/mpiio} or {custom} or {custom/gz} or {custom/mpiio} or {dcd} or {h5md} or {image} or {local} or {local/gz} or {molfile} or {movie} or {netcdf} or {netcdf/mpiio} or {vtk} or {xtc} or {xyz} or {xyz/gz} or {xyz/mpiio} :l
N = dump every this many timesteps :l
file = name of file to write dump info to :l
args = list of arguments for a particular style :l
+17 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ keyword = {append} or {at} or {buffer} or {delay} or {element} or {every} or {fi
  {sfactor} arg = coordinate scaling factor (> 0.0)
  {thermo} arg = {yes} or {no}
  {tfactor} arg = time scaling factor (> 0.0)
  {units} arg = {yes} or {no}
  {sort} arg = {off} or {id} or N or -N
     off = no sorting of per-atom lines within a snapshot
     id = sort per-atom lines by atom ID
@@ -620,6 +621,21 @@ threshold criterion is met. Otherwise it is not met.

:line

The {units} keyword only applies to the dump {atom}, {custom}, and
{local} styles (and their COMPRESS package versions {atom/gz},
{custom/gz} and {local/gz}). If set to {yes}, each individual dump
file will contain two extra lines at the very beginning with:

ITEM: UNITS
\<units style\> :pre

This will output the current selected "units"_units.html style
to the dump file and thus allows visualization and post-processing
tools to determine the choice of units of the data in the dump file.
The default setting is {no}.

:line

The {unwrap} keyword only applies to the dump {dcd} and {xtc} styles.
If set to {yes}, coordinates will be written "unwrapped" by the image
flags for each atom.  Unwrapped means that if the atom has passed through
@@ -924,6 +940,7 @@ scale = yes
sort = off for dump styles {atom}, {custom}, {cfg}, and {local}
sort = id for dump styles {dcd}, {xtc}, and {xyz}
thresh = none
units = no
unwrap = no :ul

acolor = * red/green/blue/yellow/aqua/cyan
+9 −10
Original line number Diff line number Diff line
@@ -108,27 +108,26 @@ void DumpAtomGZ::openfile()
void DumpAtomGZ::write_header(bigint ndump)
{
  if ((multiproc) || (!multiproc && me == 0)) {
    if (domain->triclinic == 0) {
    if (unit_flag && !unit_count) {
      ++unit_count;
      gzprintf(gzFp,"ITEM: UNITS\n%s\n",update->unit_style);
    }
    gzprintf(gzFp,"ITEM: TIMESTEP\n");
    gzprintf(gzFp,BIGINT_FORMAT "\n",update->ntimestep);
    gzprintf(gzFp,"ITEM: NUMBER OF ATOMS\n");
    gzprintf(gzFp,BIGINT_FORMAT "\n",ndump);
    if (domain->triclinic == 0) {
      gzprintf(gzFp,"ITEM: BOX BOUNDS %s\n",boundstr);
      gzprintf(gzFp,"%g %g\n",boxxlo,boxxhi);
      gzprintf(gzFp,"%g %g\n",boxylo,boxyhi);
      gzprintf(gzFp,"%g %g\n",boxzlo,boxzhi);
      gzprintf(gzFp,"ITEM: ATOMS %s\n",columns);
    } else {
      gzprintf(gzFp,"ITEM: TIMESTEP\n");
      gzprintf(gzFp,BIGINT_FORMAT "\n",update->ntimestep);
      gzprintf(gzFp,"ITEM: NUMBER OF ATOMS\n");
      gzprintf(gzFp,BIGINT_FORMAT "\n",ndump);
      gzprintf(gzFp,"ITEM: BOX BOUNDS xy xz yz %s\n",boundstr);
      gzprintf(gzFp,"%g %g %g\n",boxxlo,boxxhi,boxxy);
      gzprintf(gzFp,"%g %g %g\n",boxylo,boxyhi,boxxz);
      gzprintf(gzFp,"%g %g %g\n",boxzlo,boxzhi,boxyz);
      gzprintf(gzFp,"ITEM: ATOMS %s\n",columns);
    }
    gzprintf(gzFp,"ITEM: ATOMS %s\n",columns);
  }
}

+9 −10
Original line number Diff line number Diff line
@@ -108,27 +108,26 @@ void DumpCustomGZ::openfile()
void DumpCustomGZ::write_header(bigint ndump)
{
  if ((multiproc) || (!multiproc && me == 0)) {
    if (domain->triclinic == 0) {
    if (unit_flag && !unit_count) {
      ++unit_count;
      gzprintf(gzFp,"ITEM: UNITS\n%s\n",update->unit_style);
    }
    gzprintf(gzFp,"ITEM: TIMESTEP\n");
    gzprintf(gzFp,BIGINT_FORMAT "\n",update->ntimestep);
    gzprintf(gzFp,"ITEM: NUMBER OF ATOMS\n");
    gzprintf(gzFp,BIGINT_FORMAT "\n",ndump);
    if (domain->triclinic == 0) {
      gzprintf(gzFp,"ITEM: BOX BOUNDS %s\n",boundstr);
      gzprintf(gzFp,"%-1.16g %-1.16g\n",boxxlo,boxxhi);
      gzprintf(gzFp,"%-1.16g %-1.16g\n",boxylo,boxyhi);
      gzprintf(gzFp,"%-1.16g %-1.16g\n",boxzlo,boxzhi);
      gzprintf(gzFp,"ITEM: ATOMS %s\n",columns);
    } else {
      gzprintf(gzFp,"ITEM: TIMESTEP\n");
      gzprintf(gzFp,BIGINT_FORMAT "\n",update->ntimestep);
      gzprintf(gzFp,"ITEM: NUMBER OF ATOMS\n");
      gzprintf(gzFp,BIGINT_FORMAT "\n",ndump);
      gzprintf(gzFp,"ITEM: BOX BOUNDS xy xz yz %s\n",boundstr);
      gzprintf(gzFp,"%-1.16g %-1.16g %-1.16g\n",boxxlo,boxxhi,boxxy);
      gzprintf(gzFp,"%-1.16g %-1.16g %-1.16g\n",boxylo,boxyhi,boxxz);
      gzprintf(gzFp,"%-1.16g %-1.16g %-1.16g\n",boxzlo,boxzhi,boxyz);
      gzprintf(gzFp,"ITEM: ATOMS %s\n",columns);
    }
    gzprintf(gzFp,"ITEM: ATOMS %s\n",columns);
  }
}

+171 −0
Original line number Diff line number Diff line
/* ----------------------------------------------------------------------
   LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
   http://lammps.sandia.gov, Sandia National Laboratories
   Steve Plimpton, sjplimp@sandia.gov

   Copyright (2003) Sandia Corporation.  Under the terms of Contract
   DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
   certain rights in this software.  This software is distributed under
   the GNU General Public License.

   See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */

#include "dump_local_gz.h"
#include "domain.h"
#include "error.h"
#include "update.h"

#include <cstring>

using namespace LAMMPS_NS;

DumpLocalGZ::DumpLocalGZ(LAMMPS *lmp, int narg, char **arg) :
  DumpLocal(lmp, narg, arg)
{
  gzFp = NULL;

  if (!compressed)
    error->all(FLERR,"Dump local/gz only writes compressed files");
}


/* ---------------------------------------------------------------------- */

DumpLocalGZ::~DumpLocalGZ()
{
  if (gzFp) gzclose(gzFp);
  gzFp = NULL;
  fp = NULL;
}


/* ----------------------------------------------------------------------
   generic opening of a dump file
   ASCII or binary or gzipped
   some derived classes override this function
------------------------------------------------------------------------- */

void DumpLocalGZ::openfile()
{
  // single file, already opened, so just return

  if (singlefile_opened) return;
  if (multifile == 0) singlefile_opened = 1;

  // if one file per timestep, replace '*' with current timestep

  char *filecurrent = filename;
  if (multiproc) filecurrent = multiname;

  if (multifile) {
    char *filestar = filecurrent;
    filecurrent = new char[strlen(filestar) + 16];
    char *ptr = strchr(filestar,'*');
    *ptr = '\0';
    if (padflag == 0)
      sprintf(filecurrent,"%s" BIGINT_FORMAT "%s",
              filestar,update->ntimestep,ptr+1);
    else {
      char bif[8],pad[16];
      strcpy(bif,BIGINT_FORMAT);
      sprintf(pad,"%%s%%0%d%s%%s",padflag,&bif[1]);
      sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
    }
    *ptr = '*';
    if (maxfiles > 0) {
      if (numfiles < maxfiles) {
        nameslist[numfiles] = new char[strlen(filecurrent)+1];
        strcpy(nameslist[numfiles],filecurrent);
        ++numfiles;
      } else {
        remove(nameslist[fileidx]);
        delete[] nameslist[fileidx];
        nameslist[fileidx] = new char[strlen(filecurrent)+1];
        strcpy(nameslist[fileidx],filecurrent);
        fileidx = (fileidx + 1) % maxfiles;
      }
    }
  }

  // each proc with filewriter = 1 opens a file

  if (filewriter) {
    if (append_flag) {
      gzFp = gzopen(filecurrent,"ab9");
    } else {
      gzFp = gzopen(filecurrent,"wb9");
    }

    if (gzFp == NULL) error->one(FLERR,"Cannot open dump file");
  } else gzFp = NULL;

  // delete string with timestep replaced

  if (multifile) delete [] filecurrent;
}

void DumpLocalGZ::write_header(bigint ndump)
{
  if ((multiproc) || (!multiproc && me == 0)) {
    if (unit_flag && !unit_count) {
      ++unit_count;
      gzprintf(gzFp,"ITEM: UNITS\n%s\n",update->unit_style);
    }
    gzprintf(gzFp,"ITEM: TIMESTEP\n");
    gzprintf(gzFp,BIGINT_FORMAT "\n",update->ntimestep);
    gzprintf(gzFp,"ITEM: NUMBER OF ATOMS\n");
    gzprintf(gzFp,BIGINT_FORMAT "\n",ndump);
    if (domain->triclinic == 0) {
      gzprintf(gzFp,"ITEM: BOX BOUNDS %s\n",boundstr);
      gzprintf(gzFp,"%-1.16g %-1.16g\n",boxxlo,boxxhi);
      gzprintf(gzFp,"%-1.16g %-1.16g\n",boxylo,boxyhi);
      gzprintf(gzFp,"%-1.16g %-1.16g\n",boxzlo,boxzhi);
    } else {
      gzprintf(gzFp,"ITEM: BOX BOUNDS xy xz yz %s\n",boundstr);
      gzprintf(gzFp,"%-1.16g %-1.16g %-1.16g\n",boxxlo,boxxhi,boxxy);
      gzprintf(gzFp,"%-1.16g %-1.16g %-1.16g\n",boxylo,boxyhi,boxxz);
      gzprintf(gzFp,"%-1.16g %-1.16g %-1.16g\n",boxzlo,boxzhi,boxyz);
    }
    gzprintf(gzFp,"ITEM: %s %s\n",label,columns);
  }
}

/* ---------------------------------------------------------------------- */

void DumpLocalGZ::write_data(int n, double *mybuf)
{
  if (buffer_flag == 1) {
    gzwrite(gzFp,mybuf,sizeof(char)*n);

  } else {
    int i,j;
    int m = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < size_one; j++) {
        if (vtype[j] == INT)
          gzprintf(gzFp,vformat[j],static_cast<int> (mybuf[m]));
        else gzprintf(gzFp,vformat[j],mybuf[m]);
        m++;
      }
      gzprintf(gzFp,"\n");
    }
  }
}

/* ---------------------------------------------------------------------- */

void DumpLocalGZ::write()
{
  DumpLocal::write();
  if (filewriter) {
    if (multifile) {
      gzclose(gzFp);
      gzFp = NULL;
    } else {
      if (flush_flag)
        gzflush(gzFp,Z_SYNC_FLUSH);
    }
  }
}
Loading