detect and flag short reads with missing lines in utils::read_lines_from_file()

This commit is contained in:
Axel Kohlmeyer
2023-06-22 10:48:07 -04:00
parent 558298ac04
commit ffda6596da

View File

@ -272,6 +272,7 @@ int utils::read_lines_from_file(FILE *fp, int nlines, int nmax, char *buffer, in
{
char *ptr = buffer;
*ptr = '\0';
int mylines = 0;
if (me == 0) {
if (fp) {
@ -282,13 +283,15 @@ int utils::read_lines_from_file(FILE *fp, int nlines, int nmax, char *buffer, in
ptr += strlen(ptr);
// ensure buffer is null terminated. null char is start of next line.
*ptr = '\0';
// count line
++mylines;
}
}
}
int n = strlen(buffer);
MPI_Bcast(&n, 1, MPI_INT, 0, comm);
if (n == 0) return 1;
if ((n == 0) || (nlines != mylines)) return 1;
MPI_Bcast(buffer, n + 1, MPI_CHAR, 0, comm);
return 0;
}
@ -879,8 +882,8 @@ char *utils::expand_type(const char *file, int line, const std::string &str, int
caller decides what to do if arg is not a COMPUTE or FIX reference
------------------------------------------------------------------------- */
int utils::check_grid_reference(char *errstr, char *ref, int nevery,
char *&id, int &igrid, int &idata, int &index, LAMMPS *lmp)
int utils::check_grid_reference(char *errstr, char *ref, int nevery, char *&id, int &igrid,
int &idata, int &index, LAMMPS *lmp)
{
ArgInfo argi(ref, ArgInfo::COMPUTE | ArgInfo::FIX);
index = argi.get_index1();
@ -911,19 +914,24 @@ int utils::check_grid_reference(char *errstr, char *ref, int nevery,
int dim;
igrid = icompute->get_grid_by_name(gname, dim);
if (igrid < 0)
lmp->error->all(FLERR,"{} compute {} does not recognize grid name {}",errstr,idcompute,gname);
lmp->error->all(FLERR, "{} compute {} does not recognize grid name {}", errstr, idcompute,
gname);
int ncol;
idata = icompute->get_griddata_by_name(igrid, dname, ncol);
if (idata < 0)
lmp->error->all(FLERR,"{} compute {} does not recognize data name {}",errstr,idcompute,dname);
lmp->error->all(FLERR, "{} compute {} does not recognize data name {}", errstr, idcompute,
dname);
if (argi.get_dim() == 0 && ncol)
lmp->error->all(FLERR,"{} compute {} data {} is not per-grid vector",errstr,idcompute,dname);
lmp->error->all(FLERR, "{} compute {} data {} is not per-grid vector", errstr, idcompute,
dname);
if (argi.get_dim() && ncol == 0)
lmp->error->all(FLERR,"{} compute {} data {} is not per-grid array",errstr,idcompute,dname);
lmp->error->all(FLERR, "{} compute {} data {} is not per-grid array", errstr, idcompute,
dname);
if (argi.get_dim() && argi.get_index1() > ncol)
lmp->error->all(FLERR,"{} compute {} array {} is accessed out-of-range",errstr,idcompute,dname);
lmp->error->all(FLERR, "{} compute {} array {} is accessed out-of-range", errstr, idcompute,
dname);
id = utils::strdup(idcompute);
return ArgInfo::COMPUTE;
@ -1360,8 +1368,9 @@ bool utils::is_double(const std::string &str)
{
if (str.empty()) return false;
return strmatch(str, "^[+-]?\\d+\\.?\\d*$") || strmatch(str, "^[+-]?\\d+\\.?\\d*[eE][+-]?\\d+$") ||
strmatch(str, "^[+-]?\\d*\\.?\\d+$") || strmatch(str, "^[+-]?\\d*\\.?\\d+[eE][+-]?\\d+$");
return strmatch(str, "^[+-]?\\d+\\.?\\d*$") ||
strmatch(str, "^[+-]?\\d+\\.?\\d*[eE][+-]?\\d+$") || strmatch(str, "^[+-]?\\d*\\.?\\d+$") ||
strmatch(str, "^[+-]?\\d*\\.?\\d+[eE][+-]?\\d+$");
}
/* ----------------------------------------------------------------------