/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . Application Test-fileHandler-ranks1 Description Test IO ranks and ranks selection \*---------------------------------------------------------------------------*/ #include "argList.H" #include "fileName.H" #include "fileOperation.H" #include "IOstreams.H" #include "ITstream.H" #include "OSspecific.H" #include "Pstream.H" #include "SHA1.H" #include "stringOps.H" using namespace Foam; // Parse space, comma, semicolon separated list of integers, floats etc... template static List splitStringToList(const std::string& str) { const SubStrings items = stringOps::splitAny(str, " ,;"); DynamicList values(items.size()); for (const auto& item : items) { const std::string s(item.str()); PrimitiveType val; if (Foam::read(s, val)) { values.push_back(val); } else { // Report errors? Could get noisy... } } return List(std::move(values)); } //- Construct by parsing string for scalar ranges // The individual items are space, comma or semicolon delimited. static labelList parseIOranks ( const Foam::string& str, label numProcs = -1 ) { bool byHostName = false; labelList ranks; // Info<< "parsing: " << str << endl; if (!str.empty()) { if (str.contains('(')) { // Looks like a list - tokenise it ITstream is(str); if (!is.empty()) { is >> ranks; } } else if (str == "host") { // Select by host byHostName = true; } else { // Manual parse ranks = splitStringToList