add utility function to get the units tag value from a potential file

This commit is contained in:
Axel Kohlmeyer
2020-06-14 06:22:47 -04:00
parent d84b4a3fff
commit 0481184862
3 changed files with 53 additions and 9 deletions

View File

@ -539,7 +539,7 @@ std::string utils::get_potential_file_path(const std::string& path) {
/* ----------------------------------------------------------------------
read first line of potential file
if has DATE field, print following word
if it has a DATE field, return the following word
------------------------------------------------------------------------- */
std::string utils::get_potential_date(const std::string & path, const std::string & potential_name) {
@ -562,6 +562,31 @@ std::string utils::get_potential_date(const std::string & path, const std::strin
return "";
}
/* ----------------------------------------------------------------------
read first line of potential file
if it has UNITS field, return following word
------------------------------------------------------------------------- */
std::string utils::get_potential_units(const std::string & path, const std::string & potential_name) {
TextFileReader reader(path, potential_name);
reader.ignore_comments = false;
char * line = nullptr;
while ((line = reader.next_line())) {
ValueTokenizer values(line);
while (values.has_next()) {
std::string word = values.next_string();
if (word == "UNITS:") {
if (values.has_next()) {
std::string units = values.next_string();
return units;
}
}
}
}
return "";
}
/* ------------------------------------------------------------------ */
extern "C" {