Unverified Commit 439eee3b authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

get rid of BIGINT_FORMAT and use std::string.replace() to expand time step in...

get rid of BIGINT_FORMAT and use std::string.replace() to expand time step in data  and restart file names
parent ad15385f
Loading
Loading
Loading
Loading
+24 −35
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
#include "write_data.h"
#include <mpi.h>
#include <cstring>
#include <string>
#include "atom.h"
#include "atom_vec.h"
#include "force.h"
@@ -32,6 +33,8 @@
#include "thermo.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
#include "fmt/format.h"

using namespace LAMMPS_NS;

@@ -58,14 +61,10 @@ void WriteData::command(int narg, char **arg)

  // if filename contains a "*", replace with current timestep

  char *ptr;
  int n = strlen(arg[0]) + 16;
  char *file = new char[n];

  if ((ptr = strchr(arg[0],'*'))) {
    *ptr = '\0';
    sprintf(file,"%s" BIGINT_FORMAT "%s",arg[0],update->ntimestep,ptr+1);
  } else strcpy(file,arg[0]);
  std::string file = arg[0];
  std::size_t found = file.find("*");
  if (found != std::string::npos)
    file.replace(found,1,fmt::format("{}",update->ntimestep));

  // read optional args
  // noinit is a hidden arg, only used by -r command-line switch
@@ -124,9 +123,7 @@ void WriteData::command(int narg, char **arg)
    if (domain->triclinic) domain->lamda2x(atom->nlocal+atom->nghost);
  }

  write(file);

  delete [] file;
  write(file.c_str());
}

/* ----------------------------------------------------------------------
@@ -134,7 +131,7 @@ void WriteData::command(int narg, char **arg)
   might later let it be directly called within run/minimize loop
------------------------------------------------------------------------- */

void WriteData::write(char *file)
void WriteData::write(const char *file)
{
  // special case where reneighboring is not done in integrator
  //   on timestep data file is written (due to build_once being set)
@@ -235,34 +232,26 @@ void WriteData::write(char *file)

void WriteData::header()
{
  fprintf(fp,"LAMMPS data file via write_data, version %s, "
          "timestep = " BIGINT_FORMAT "\n",
          universe->version,update->ntimestep);

  fprintf(fp,"\n");
  fmt::print(fp,"LAMMPS data file via write_data, version {}, "
             "timestep = {}\n\n",universe->version,update->ntimestep);

  fprintf(fp,BIGINT_FORMAT " atoms\n",atom->natoms);
  fprintf(fp,"%d atom types\n",atom->ntypes);
  fmt::print(fp,"{} atoms\n{} atom types\n",atom->natoms,atom->ntypes);

  // do not write molecular topology info for atom_style template

  if (atom->molecular == 1) {
    if (atom->nbonds || atom->nbondtypes) {
      fprintf(fp,BIGINT_FORMAT " bonds\n",nbonds);
      fprintf(fp,"%d bond types\n",atom->nbondtypes);
    }
    if (atom->nangles || atom->nangletypes) {
      fprintf(fp,BIGINT_FORMAT " angles\n",nangles);
      fprintf(fp,"%d angle types\n",atom->nangletypes);
    }
    if (atom->ndihedrals || atom->ndihedraltypes) {
      fprintf(fp,BIGINT_FORMAT " dihedrals\n",ndihedrals);
      fprintf(fp,"%d dihedral types\n",atom->ndihedraltypes);
    }
    if (atom->nimpropers || atom->nimpropertypes) {
      fprintf(fp,BIGINT_FORMAT " impropers\n",nimpropers);
      fprintf(fp,"%d improper types\n",atom->nimpropertypes);
    }
    if (atom->nbonds || atom->nbondtypes)
      fmt::print(fp,"{} bonds\n{} bond types\n",
                 nbonds,atom->nbondtypes);
    if (atom->nangles || atom->nangletypes)
      fmt::print(fp,"{} angles\n{} angle types\n",
                 nangles,atom->nangletypes);
    if (atom->ndihedrals || atom->ndihedraltypes)
      fmt::print(fp,"{} dihedrals\n{} dihedral types\n",
                 ndihedrals,atom->ndihedraltypes);
    if (atom->nimpropers || atom->nimpropertypes)
      fmt::print(fp,"{} impropers\n{} improper types\n",
                 nimpropers,atom->nimpropertypes);
  }

  if (fixflag)
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ class WriteData : protected Pointers {
 public:
  WriteData(class LAMMPS *);
  void command(int, char **);
  void write(char *);
  void write(const char *);

 private:
  int me,nprocs;
+11 −11
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
#include "write_restart.h"
#include <mpi.h>
#include <cstring>
#include <string>
#include "atom.h"
#include "atom_vec.h"
#include "group.h"
@@ -35,6 +36,8 @@
#include "mpiio.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
#include "fmt/format.h"

#include "lmprestart.h"

@@ -63,15 +66,10 @@ void WriteRestart::command(int narg, char **arg)

  // if filename contains a "*", replace with current timestep

  char *ptr;
  int n = strlen(arg[0]) + 16;
  char *file = new char[n];

  if ((ptr = strchr(arg[0],'*'))) {
    *ptr = '\0';
    sprintf(file,"%s" BIGINT_FORMAT "%s",arg[0],update->ntimestep,ptr+1);
    *ptr = '*'; // must restore arg[0] so it can be correctly parsed below
  } else strcpy(file,arg[0]);
  std::string file = arg[0];
  std::size_t found = file.find("*");
  if (found != std::string::npos)
    file.replace(found,1,fmt::format("{}",update->ntimestep));

  // check for multiproc output and an MPI-IO filename

@@ -115,8 +113,10 @@ void WriteRestart::command(int narg, char **arg)

  // write single restart file

  write(file);
  delete [] file;
  char *fname = new char[file.size()+1];
  strcpy(fname,file.c_str());
  write(fname);
  delete[] fname;
}

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