Unverified Commit e4a3a518 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

more use of fmtlib and std::string

parent 4816c5c7
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -848,16 +848,12 @@ bool Info::is_active(const char *category, const char *name)

  if (!match && lmp->suffix_enable) {
    if (lmp->suffix) {
      char *name_w_suffix = new char [len + 2 + strlen(lmp->suffix)];
      sprintf(name_w_suffix,"%s/%s",name,lmp->suffix);
      if (strcmp(style,name_w_suffix) == 0) match = 1;
      delete[] name_w_suffix;
      std::string name_w_suffix = name + std::string("/") + lmp->suffix;
      if (name_w_suffix == style) match = 1;
    }
    if (!match && lmp->suffix2) {
      char *name_w_suffix = new char [len + 2 + strlen(lmp->suffix2)];
      sprintf(name_w_suffix,"%s/%s",name,lmp->suffix2);
      if (strcmp(style,name_w_suffix) == 0) match = 1;
      delete[] name_w_suffix;
      std::string name_w_suffix = name + std::string("/") + lmp->suffix2;
      if (name_w_suffix == style) match = 1;
    }
  }
  return match ? true : false;
+3 −6
Original line number Diff line number Diff line
@@ -227,11 +227,8 @@ void Input::file()

    // execute the command

    if (execute_command()) {
      char *str = new char[maxline+32];
      sprintf(str,"Unknown command: %s",line);
      error->all(FLERR,str);
    }
    if (execute_command())
      error->all(FLERR,fmt::format("Unknown command: {}",line));
  }
}

@@ -1249,7 +1246,7 @@ char *shell_failed_message(const char* cmd, int errnum)
  const char *errmsg = strerror(errnum);
  int len = strlen(cmd)+strlen(errmsg)+64;
  char *msg = new char[len];
  sprintf(msg,"Shell command '%s' failed with error '%s'", cmd, errmsg);
  snprintf(msg, len, "Shell command '%s' failed with error '%s'", cmd, errmsg);
  return msg;
}

+8 −8
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include "atom.h"
#include "comm.h"
#include "force.h"
@@ -25,6 +26,7 @@
#include "error.h"
#include "suffix.h"
#include "domain.h"
#include "fmt/format.h"

using namespace LAMMPS_NS;

@@ -307,10 +309,10 @@ void KSpace::qsum_qsq(int warning_flag)
  // so issue warning or error

  if (fabs(qsum) > SMALL) {
    char str[128];
    sprintf(str,"System is not charge neutral, net charge = %g",qsum);
    if (!warn_nonneutral) error->all(FLERR,str);
    if (warn_nonneutral == 1 && comm->me == 0) error->warning(FLERR,str);
    std::string message = fmt::format("System is not charge neutral, net "
                                      "charge = {}",qsum);
    if (!warn_nonneutral) error->all(FLERR,message);
    if (warn_nonneutral == 1 && comm->me == 0) error->warning(FLERR,message);
    warn_nonneutral = 2;
  }
}
@@ -324,12 +326,10 @@ double KSpace::estimate_table_accuracy(double q2_over_sqrt, double spr)
  double table_accuracy = 0.0;
  int nctb = force->pair->ncoultablebits;
  if (comm->me == 0) {
    char str[128];
    if (nctb)
      sprintf(str,"  using %d-bit tables for long-range coulomb",nctb);
      error->message(FLERR,fmt::format("  using {}-bit tables for long-range coulomb",nctb));
    else
      sprintf(str,"  using polynomial approximation for long-range coulomb");
    error->message(FLERR,str);
      error->message(FLERR,"  using polynomial approximation for long-range coulomb");
  }

  if (nctb) {
+2 −5
Original line number Diff line number Diff line
@@ -667,15 +667,12 @@ LAMMPS::~LAMMPS()

  double totalclock = MPI_Wtime() - initclock;
  if ((me == 0) && (screen || logfile)) {
    char outtime[128];
    int seconds = fmod(totalclock,60.0);
    totalclock  = (totalclock - seconds) / 60.0;
    int minutes = fmod(totalclock,60.0);
    int hours = (totalclock - minutes) / 60.0;
    sprintf(outtime,"Total wall time: "
            "%d:%02d:%02d\n", hours, minutes, seconds);
    if (screen) fputs(outtime,screen);
    if (logfile) fputs(outtime,logfile);
    utils::logmesg(this,fmt::format("Total wall time: {}:{:02d}:{:02d}\n",
                                    hours, minutes, seconds));
  }

  if (universe->nworlds == 1) {
+24 −28
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@

#include "modify.h"
#include <cstring>
#include <string>
#include "style_compute.h"
#include "style_fix.h"
#include "atom.h"
@@ -836,18 +837,17 @@ void Modify::add_fix(int narg, char **arg, int trysuffix)
    int match = 0;
    if (strcmp(arg[2],fix[ifix]->style) == 0) match = 1;
    if (!match && trysuffix && lmp->suffix_enable) {
      char estyle[256];
      if (lmp->suffix) {
        sprintf(estyle,"%s/%s",arg[2],lmp->suffix);
        if (strcmp(estyle,fix[ifix]->style) == 0) match = 1;
        std::string estyle = arg[2] + std::string("/") + lmp->suffix;
        if (estyle == fix[ifix]->style) match = 1;
      }
      if (lmp->suffix2) {
        sprintf(estyle,"%s/%s",arg[2],lmp->suffix2);
        if (strcmp(estyle,fix[ifix]->style) == 0) match = 1;
        std::string estyle = arg[2] + std::string("/") + lmp->suffix2;
        if (estyle == fix[ifix]->style) match = 1;
      }
    }
    if (!match) error->all(FLERR,
                           "Replacing a fix, but new style != old style");
    if (!match)
      error->all(FLERR,"Replacing a fix, but new style != old style");

    if (fix[ifix]->igroup != igroup && comm->me == 0)
      error->warning(FLERR,"Replacing a fix, but new group != old group");
@@ -870,26 +870,24 @@ void Modify::add_fix(int narg, char **arg, int trysuffix)

  if (trysuffix && lmp->suffix_enable) {
    if (lmp->suffix) {
      int n = strlen(arg[2])+strlen(lmp->suffix)+2;
      char *estyle = new char[n];
      sprintf(estyle,"%s/%s",arg[2],lmp->suffix);
      std::string estyle = arg[2] + std::string("/") + lmp->suffix;
      if (fix_map->find(estyle) != fix_map->end()) {
        FixCreator fix_creator = (*fix_map)[estyle];
        fix[ifix] = fix_creator(lmp,narg,arg);
        delete[] fix[ifix]->style;
        fix[ifix]->style = estyle;
      } else delete[] estyle;
        fix[ifix]->style = new char[estyle.size()+1];
        strcpy(fix[ifix]->style,estyle.c_str());
      }
    }
    if (fix[ifix] == NULL && lmp->suffix2) {
      int n = strlen(arg[2])+strlen(lmp->suffix2)+2;
      char *estyle = new char[n];
      sprintf(estyle,"%s/%s",arg[2],lmp->suffix2);
      std::string estyle = arg[2] + std::string("/") + lmp->suffix2;
      if (fix_map->find(estyle) != fix_map->end()) {
        FixCreator fix_creator = (*fix_map)[estyle];
        fix[ifix] = fix_creator(lmp,narg,arg);
        delete[] fix[ifix]->style;
        fix[ifix]->style = estyle;
      } else delete[] estyle;
        fix[ifix]->style = new char[estyle.size()+1];
        strcpy(fix[ifix]->style,estyle.c_str());
      }
    }
  }

@@ -1164,7 +1162,7 @@ int Modify::check_rigid_list_overlap(int *select)

  int n = 0;
  for (int ifix = 0; ifix < nfix; ifix++) {
    if (strncmp("rigid",fix[ifix]->style,5) == 0) {
    if (utils::strmatch(fix[ifix]->style,"^rigid")) {
      const int * const body = (const int *)fix[ifix]->extract("body",dim);
      if ((body == NULL) || (dim != 1)) break;

@@ -1209,26 +1207,24 @@ void Modify::add_compute(int narg, char **arg, int trysuffix)

  if (trysuffix && lmp->suffix_enable) {
    if (lmp->suffix) {
      int n = strlen(arg[2])+strlen(lmp->suffix)+2;
      char *estyle = new char[n];
      sprintf(estyle,"%s/%s",arg[2],lmp->suffix);
      std::string estyle = arg[2] + std::string("/") + lmp->suffix;
      if (compute_map->find(estyle) != compute_map->end()) {
        ComputeCreator compute_creator = (*compute_map)[estyle];
        compute[ncompute] = compute_creator(lmp,narg,arg);
        delete[] compute[ncompute]->style;
        compute[ncompute]->style = estyle;
      } else delete[] estyle;
        compute[ncompute]->style = new char[estyle.size()+1];
        strcpy(compute[ncompute]->style,estyle.c_str());
      }
    }
    if (compute[ncompute] == NULL && lmp->suffix2) {
      int n = strlen(arg[2])+strlen(lmp->suffix2)+2;
      char *estyle = new char[n];
      sprintf(estyle,"%s/%s",arg[2],lmp->suffix2);
      std::string estyle = arg[2] + std::string("/") + lmp->suffix2;
      if (compute_map->find(estyle) != compute_map->end()) {
        ComputeCreator compute_creator = (*compute_map)[estyle];
        compute[ncompute] = compute_creator(lmp,narg,arg);
        delete[] compute[ncompute]->style;
        compute[ncompute]->style = estyle;
      } else delete[] estyle;
        compute[ncompute]->style = new char[estyle.size()+1];
        strcpy(compute[ncompute]->style,estyle.c_str());
      }
    }
  }

Loading