detect yaml file output by file name

This commit is contained in:
Axel Kohlmeyer
2022-04-26 06:20:00 -04:00
parent 45de998aa9
commit a649fa3a79
3 changed files with 25 additions and 1 deletions

View File

@ -1009,6 +1009,7 @@ void FixAveTime::options(int iarg, int narg, char **arg)
noff = 0;
offlist = nullptr;
overwrite = 0;
yaml_flag = false;
format_user = nullptr;
format = (char *) " %g";
title1 = nullptr;
@ -1020,11 +1021,12 @@ void FixAveTime::options(int iarg, int narg, char **arg)
while (iarg < narg) {
if (strcmp(arg[iarg],"file") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/time command");
yaml_flag = utils::strmatch(arg[iarg+1],"\\.[yY][aA]?[mM][lL]$");
if (me == 0) {
fp = fopen(arg[iarg+1],"w");
if (fp == nullptr)
error->one(FLERR,"Cannot open fix ave/time file {}: {}",
arg[iarg+1], utils::getsyserror());
arg[iarg+1], utils::getsyserror());
}
iarg += 2;
} else if (strcmp(arg[iarg],"ave") == 0) {

View File

@ -48,6 +48,7 @@ class FixAveTime : public Fix {
int any_variable_length;
int all_variable_length;
int lockforever;
bool yaml_flag;
int ave, nwindow, startstep, mode;
int noff, overwrite;

View File

@ -519,6 +519,27 @@ TEST(Utils, strmatch_opt_char)
ASSERT_FALSE(utils::strmatch("x_name", "^[cfvid]2?_name"));
}
TEST(Utils, strmatch_yaml_suffix)
{
ASSERT_TRUE(utils::strmatch("test.yaml", "\\.[yY][aA]?[mM][lL]$"));
ASSERT_TRUE(utils::strmatch("test.yml", "\\.[yY][aA]?[mM][lL]$"));
ASSERT_TRUE(utils::strmatch("TEST.YAML", "\\.[yY][aA]?[mM][lL]$"));
ASSERT_TRUE(utils::strmatch("TEST.YML", "\\.[yY][aA]?[mM][lL]$"));
ASSERT_FALSE(utils::strmatch("test.yamlx", "\\.[yY][aA]?[mM][lL]$"));
ASSERT_FALSE(utils::strmatch("test.ymlx", "\\.[yY][aA]?[mM][lL]$"));
ASSERT_FALSE(utils::strmatch("TEST.YAMLX", "\\.[yY][aA]?[mM][lL]$"));
ASSERT_FALSE(utils::strmatch("TEST.YMLX", "\\.[yY][aA]?[mM][lL]$"));
ASSERT_FALSE(utils::strmatch("testyaml", "\\.[yY][aA]?[mM][lL]$"));
ASSERT_FALSE(utils::strmatch("testyml", "\\.[yY][aA]?[mM][lL]$"));
ASSERT_FALSE(utils::strmatch("TESTYAML", "\\.[yY][aA]?[mM][lL]$"));
ASSERT_FALSE(utils::strmatch("TESTYML", "\\.[yY][aA]?[mM][lL]$"));
ASSERT_FALSE(utils::strmatch("yaml.test", "\\.[yY][aA]?[mM][lL]$"));
ASSERT_FALSE(utils::strmatch("yml.test", "\\.[yY][aA]?[mM][lL]$"));
ASSERT_FALSE(utils::strmatch("YAML.TEST", "\\.[yY][aA]?[mM][lL]$"));
ASSERT_FALSE(utils::strmatch("YML.TEST", "\\.[yY][aA]?[mM][lL]$"));
ASSERT_FALSE(utils::strmatch("test", "\\.[yY][aA]?[mM][lL]$"));
}
TEST(Utils, strmatch_dot)
{
ASSERT_TRUE(utils::strmatch("rigid", ".igid"));