Please use a helper variable for the length of the filename.
```C++
/* 3 is the suffix length including the dot */
const int fileNameLength=fname.size()-3;
if (fname.rfind(".h5") != fileNameLength)
```