----------------------------------------------------------------------------
| 86 | |
| 87 | //---------------------------------------------------------------------------- |
| 88 | std::set<std::string> vtkIOSSFilesScanner::GetRelatedFiles( |
| 89 | const std::set<std::string>& originalSet, const std::vector<std::string>& directoryListing) |
| 90 | { |
| 91 | if (originalSet.empty()) |
| 92 | { |
| 93 | return originalSet; |
| 94 | } |
| 95 | |
| 96 | // Matches paths `{NAME}.e-s{RS}.{NUMRANKS}.{RANK}` or {NAME}.g-s{RS}.{NUMRANKS}.{RANK}` |
| 97 | // where `-s{RS}` and/or `.{NUMRANKS}.{RANK}` is optional. |
| 98 | vtksys::RegularExpression extensionRegexExodus( |
| 99 | R"(^(.*\.[eg][^-.]*)(-s.[0-9]+)?(\.[0-9]+(\.[0-9]+)?)?$)"); |
| 100 | vtksys::RegularExpression extensionRegexExodus2( |
| 101 | R"(^(.*\.exo[^-.]*)(-s.[0-9]+)?(\.[0-9]+(\.[0-9]+)?)?$)"); |
| 102 | vtksys::RegularExpression extensionRegexCGNS( |
| 103 | R"(^(.*\.cgns[^-.]*)(-s.[0-9]+)?(\.[0-9]+(\.[0-9]+)?)?$)"); |
| 104 | |
| 105 | // extract process count from the filename, if any, otherwise -1. |
| 106 | auto getProcessCount = [](const std::string& fname) |
| 107 | { |
| 108 | vtksys::RegularExpression procRegEx(R"(^.*\.([0-9]+)\.[0-9]+$)"); |
| 109 | if (procRegEx.find(fname)) |
| 110 | { |
| 111 | int procCount = 0; |
| 112 | VTK_FROM_CHARS_IF_ERROR_RETURN(procRegEx.match(1), procCount, 0); |
| 113 | return procCount; |
| 114 | } |
| 115 | return -1; |
| 116 | }; |
| 117 | |
| 118 | // get the files per directory |
| 119 | std::map<std::string /*directory*/, std::set<std::string> /* files*/> uniqueFilesPerDirectory; |
| 120 | for (const auto& filename : originalSet) |
| 121 | { |
| 122 | std::string unix_fname = filename; |
| 123 | vtksys::SystemTools::ConvertToUnixSlashes(unix_fname); |
| 124 | |
| 125 | auto prefix = vtksys::SystemTools::GetFilenamePath(unix_fname); |
| 126 | if (!prefix.empty()) |
| 127 | { |
| 128 | // add dir separator to make `join` easier later on. |
| 129 | prefix += "/"; |
| 130 | } |
| 131 | uniqueFilesPerDirectory[prefix].emplace(unix_fname); |
| 132 | } |
| 133 | |
| 134 | // get the prefixes per directory that are used to find other files related to this one. |
| 135 | std::map<std::string /*directory*/, std::map<std::string /*prefix*/, int>> prefixesPerDirectory; |
| 136 | for (const auto& uniqueFiles : uniqueFilesPerDirectory) |
| 137 | { |
| 138 | for (const auto& unix_fname : uniqueFiles.second) |
| 139 | { |
| 140 | const auto& directoryName = uniqueFiles.first; |
| 141 | // prefixes are used to find other files related to this one. |
| 142 | auto fname_wo_path = vtksys::SystemTools::GetFilenameName(unix_fname); |
| 143 | if (fname_wo_path.empty()) |
| 144 | { |
| 145 | // this happens if the unix_fname was not a full path. |