Unverified Commit 9291d2a9 authored by Richard Berger's avatar Richard Berger
Browse files

Simplify count_words, add trim_and_count_words

The original count_words function (before it was put into utils::) also trimmed
comments. For compatibility this behaviour was retained at first. However, due
to the name the trimming is not immediatly apparent and many times not
wanted.

Therefore, this commit replaces count_words with an implementation that
just does what it says. If a comment should be trimmed there is a
trim_comment function. For convenience, a trim_and_count_words function was
added and is now used where the old behaviour was needed.
parent 3c6ce73c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2489,7 +2489,7 @@ void FixRigidSmall::readfile(int which, double **array, int *inbody)
    buf = buffer;
    next = strchr(buf,'\n');
    *next = '\0';
    int nwords = utils::count_words(buf);
    int nwords = utils::trim_and_count_words(buf);
    *next = '\n';

    if (nwords != ATTRIBUTE_PERBODY)
+2 −2
Original line number Diff line number Diff line
@@ -568,7 +568,7 @@ void PairSNAP::read_files(char *coefffilename, char *paramfilename)
    MPI_Bcast(&n,1,MPI_INT,0,world);
    MPI_Bcast(line,n,MPI_CHAR,0,world);

    nwords = utils::count_words(line);
    nwords = utils::trim_and_count_words(line);
    if (nwords != 3)
      error->all(FLERR,"Incorrect format in SNAP coefficient file");

@@ -610,7 +610,7 @@ void PairSNAP::read_files(char *coefffilename, char *paramfilename)
      MPI_Bcast(&n,1,MPI_INT,0,world);
      MPI_Bcast(line,n,MPI_CHAR,0,world);

      nwords = utils::count_words(line);
      nwords = utils::trim_and_count_words(line);
      if (nwords != 1)
        error->all(FLERR,"Incorrect format in SNAP coefficient file");

+1 −1
Original line number Diff line number Diff line
@@ -441,7 +441,7 @@ void NEBSpin::readfile(char *file, int flag)
    buf = buffer;
    next = strchr(buf,'\n');
    *next = '\0';
    int nwords = utils::count_words(buf);
    int nwords = utils::trim_and_count_words(buf);
    *next = '\n';

    if (nwords != ATTRIBUTE_PERLINE)
+3 −3
Original line number Diff line number Diff line
@@ -1089,7 +1089,7 @@ void Atom::data_atoms(int n, char *buf, tagint id_offset, tagint mol_offset,

  next = strchr(buf,'\n');
  *next = '\0';
  int nwords = utils::count_words(buf);
  int nwords = utils::trim_and_count_words(buf);
  *next = '\n';

  if (nwords != avec->size_data_atom && nwords != avec->size_data_atom + 3)
@@ -1239,7 +1239,7 @@ void Atom::data_vels(int n, char *buf, tagint id_offset)

  next = strchr(buf,'\n');
  *next = '\0';
  int nwords = utils::count_words(buf);
  int nwords = utils::trim_and_count_words(buf);
  *next = '\n';

  if (nwords != avec->size_data_vel)
@@ -1591,7 +1591,7 @@ void Atom::data_bonus(int n, char *buf, AtomVec *avec_bonus, tagint id_offset)

  next = strchr(buf,'\n');
  *next = '\0';
  int nwords = utils::count_words(buf);
  int nwords = utils::trim_and_count_words(buf);
  *next = '\n';

  if (nwords != avec_bonus->size_data_bonus)
+1 −1
Original line number Diff line number Diff line
@@ -218,7 +218,7 @@ void FixPropertyAtom::read_data_section(char *keyword, int n, char *buf,

  next = strchr(buf,'\n');
  *next = '\0';
  int nwords = utils::count_words(buf);
  int nwords = utils::trim_and_count_words(buf);
  *next = '\n';

  if (nwords != nvalue+1) {
Loading