Correct next_line in PotentialFileReader

This commit is contained in:
Richard Berger 2020-05-27 13:03:17 -04:00
parent 6d339c8b03
commit 68e2c0bca8
No known key found for this signature in database
GPG Key ID: A9E83994E0BA0CAB
1 changed files with 23 additions and 7 deletions

View File

@ -51,17 +51,10 @@ char *PotentialFileReader::next_line(int nparams) {
int n = 0; int n = 0;
int nwords = 0; int nwords = 0;
do { char *ptr = fgets(line, MAXLINE, fp);
char *ptr = fgets(&line[n], MAXLINE - n, fp);
if (ptr == nullptr) { if (ptr == nullptr) {
// EOF // EOF
if (nwords > 0 && nwords < nparams) {
char str[128];
snprintf(str, 128, "Incorrect format in %s potential file", potential_name.c_str());
error->one(FLERR, str);
}
return nullptr; return nullptr;
} }
@ -70,12 +63,35 @@ char *PotentialFileReader::next_line(int nparams) {
nwords = utils::count_words(line); nwords = utils::count_words(line);
// skip line if blank if (nwords > 0) {
if (nwords == 0) n = strlen(line);
continue; }
n = strlen(line) + 1; while(nwords < nparams) {
} while (nwords < nparams); char *ptr = fgets(&line[n], MAXLINE - n, fp);
if (ptr == nullptr) {
// EOF
if (nwords > 0 && nwords < nparams) {
char str[128];
snprintf(str, 128, "Incorrect format in %s potential file! %d/%d parameters", potential_name.c_str(), nwords, nparams);
error->one(FLERR, str);
}
return nullptr;
}
// strip comment
if ((ptr = strchr(line, '#'))) *ptr = '\0';
nwords = utils::count_words(line);
// skip line if blank
if (nwords > 0) {
n = strlen(line);
}
}
return line; return line;
} }