| 1 |
// Copyright(C) 1999-2024 National Technology & Engineering Solutions |
| 2 |
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 3 |
// NTESS, the U.S. Government retains certain rights in this software. |
| 4 |
// |
| 5 |
// See packages/seacas/LICENSE for details |
| 6 |
|
| 7 |
#include "EJ_SystemInterface.h" |
| 8 |
#include "EJ_Version.h" // for qainfo |
| 9 |
#include "EJ_vector3d.h" // for vector3d |
| 10 |
#include <SL_tokenize.h> // for tokenize |
| 11 |
#include <algorithm> // for sort, find, transform |
| 12 |
#include <cctype> // for tolower |
| 13 |
#include <copyright.h> |
| 14 |
#include <cstddef> // for size_t |
| 15 |
#include <cstdlib> // for exit, strtod, strtoul, abs, etc |
| 16 |
#include <cstring> // for strchr, strlen |
| 17 |
#include <fmt/format.h> |
| 18 |
#include <iosfwd> // for ostream |
| 19 |
#include <utility> // for pair, make_pair |
| 20 |
#include <vector> // for vector |
| 21 |
|
| 22 |
namespace { |
| 23 |
bool str_equal(const std::string &s1, const std::string &s2) |
| 24 |
{ |
| 25 |
return (s1.size() == s2.size()) && |
| 26 |
std::equal(s1.begin(), s1.end(), s2.begin(), |
| 27 |
[](char a, char b) { return std::tolower(a) == std::tolower(b); }); |
| 28 |
} |
| 29 |
|
| 30 |
void parse_variable_names(const char *tokens, StringIdVector *variable_list); |
| 31 |
void parse_offset(const char *tokens, vector3d *offset); |
| 32 |
void parse_integer_list(const char *tokens, std::vector<int> *list); |
| 33 |
void parse_part_list(const char *tokens, std::vector<int> *list); |
| 34 |
void parse_omissions(const char *tokens, Omissions *omissions, const std::string &basename, |
| 35 |
bool require_ids); |
| 36 |
} // namespace |
| 37 |
|
| 38 |
SystemInterface::SystemInterface() |
| 39 |
{ |
| 40 |
offset_.x = 0.0; |
| 41 |
offset_.y = 0.0; |
| 42 |
offset_.z = 0.0; |
| 43 |
enroll_options(); |
| 44 |
} |
| 45 |
|
| 46 |
void SystemInterface::enroll_options() |
| 47 |
{ |
| 48 |
options_.usage("[options] list_of_files_to_join"); |
| 49 |
|
| 50 |
options_.enroll("help", GetLongOption::NoValue, "Print this summary and exit", nullptr); |
| 51 |
|
| 52 |
options_.enroll("version", GetLongOption::NoValue, "Print version and exit", nullptr); |
| 53 |
|
| 54 |
options_.enroll("output", GetLongOption::MandatoryValue, "Name of output file to create", |
| 55 |
"ejoin-out.e", nullptr, true); |
| 56 |
|
| 57 |
options_.enroll( |
| 58 |
"extract_blocks", GetLongOption::MandatoryValue, |
| 59 |
"Use only the specified part/block pairs. The specification is\n" |
| 60 |
"\t\tp#:block_id1:block_id2,p#:block_id1. For example, to\n" |
| 61 |
"\t\tExtract block ids 1,3,4 from part 1; blocks 2 3 4 from part 2;\n" |
| 62 |
"\t\tand block 8 from part5, specify\n" |
| 63 |
"\t\t\t '-extract_blocks p1:1:3:4,p2:2:3:4,p5:8'\n" |
| 64 |
"\t\tIf an extract is specified, then only that id(s) will be used for that part.", |
| 65 |
nullptr); |
| 66 |
|
| 67 |
options_.enroll("omit_blocks", GetLongOption::MandatoryValue, |
| 68 |
"Omit the specified part/block pairs. The specification is\n" |
| 69 |
"\t\tp#:block_id1:block_id2,p#:block_id1. For example, to\n" |
| 70 |
"\t\tOmit block id 1,3,4 from part 1; block 2 3 4 from part 2;\n" |
| 71 |
"\t\tand block 8 from part5, specify\n" |
| 72 |
"\t\t\t '-omit_blocks p1:1:3:4,p2:2:3:4,p5:8'", |
| 73 |
nullptr); |
| 74 |
|
| 75 |
options_.enroll("omit_assemblies", GetLongOption::OptionalValue, |
| 76 |
"If no value, then don't transfer any assemblies to output file.\n" |
| 77 |
"\t\tIf just p#,p#,... specified, then omit assemblies on specified parts\n" |
| 78 |
"\t\tIf p#:id1:id2,p#:id2,id4... then omit the assemblies with the specified\n" |
| 79 |
"\t\tid in the specified parts.", |
| 80 |
nullptr, "ALL"); |
| 81 |
|
| 82 |
options_.enroll( |
| 83 |
"omit_part_assemblies", GetLongOption::NoValue, |
| 84 |
"Do not create an assembly for each input part containing the blocks in that part.\n" |
| 85 |
"\t\tDefault is to create the part assemblies.", |
| 86 |
nullptr); |
| 87 |
|
| 88 |
options_.enroll("omit_nodesets", GetLongOption::OptionalValue, |
| 89 |
"If no value, then don't transfer any nodesets to output file.\n" |
| 90 |
"\t\tIf just p#,p#,... specified, then omit sets on specified parts\n" |
| 91 |
"\t\tIf p#:id1:id2,p#:id2,id4... then omit the sets with the specified\n" |
| 92 |
"\t\tid in the specified parts.", |
| 93 |
nullptr, "ALL"); |
| 94 |
|
| 95 |
options_.enroll("omit_sidesets", GetLongOption::OptionalValue, |
| 96 |
"If no value, then don't transfer any sidesets to output file.\n" |
| 97 |
"\t\tIf just p#,p#,... specified, then omit sets on specified parts\n" |
| 98 |
"\t\tIf p#:id1:id2,p#:id2,id4... then omit the sets with the specified\n" |
| 99 |
"\t\tid in the specified parts.", |
| 100 |
nullptr, "ALL"); |
| 101 |
|
| 102 |
options_.enroll("convert_nodal_to_nodesets", GetLongOption::MandatoryValue, |
| 103 |
"For each part listed (or ALL),\n" |
| 104 |
"\t\tcreate a nodeset containing the nodes of that part\n" |
| 105 |
"\t\tand output the nodal fields as nodeset fields instead of nodal fields.\n" |
| 106 |
"\t\tFormat is comma-separated list of parts (1-based), or ALL", |
| 107 |
nullptr, nullptr, true); |
| 108 |
|
| 109 |
options_.enroll("match_node_ids", GetLongOption::NoValue, |
| 110 |
"Combine nodes if their global ids match.", nullptr); |
| 111 |
|
| 112 |
options_.enroll("match_node_coordinates", GetLongOption::NoValue, |
| 113 |
"Combine nodes if they are within tolerance distance of each other.", nullptr); |
| 114 |
|
| 115 |
#if 0 |
| 116 |
options_.enroll("match_elem_ids", GetLongOption::NoValue, |
| 117 |
"Combine elements if their global ids match and they are compatible.\n" |
| 118 |
"\t\tCompatible = same element type, nodes of the two elements match", |
| 119 |
nullptr); |
| 120 |
|
| 121 |
options_.enroll("match_element_coordinates", GetLongOption::NoValue, |
| 122 |
"Combine elements if their centroids are within tolerance distance\n" |
| 123 |
"\t\tand they are compatible (same element type, nodes match).", |
| 124 |
nullptr); |
| 125 |
#endif |
| 126 |
|
| 127 |
options_.enroll("tolerance", GetLongOption::MandatoryValue, |
| 128 |
"Maximum distance between two nodes to be considered colocated.", nullptr, |
| 129 |
nullptr, true); |
| 130 |
|
| 131 |
options_.enroll( |
| 132 |
"block_prefix", GetLongOption::MandatoryValue, |
| 133 |
"Prefix used on the input block names of second and subsequent meshes to make them\n" |
| 134 |
"\t\tunique. Default is 'p'. Example: block1, p2_block1, p3_block1.", |
| 135 |
"p"); |
| 136 |
|
| 137 |
options_.enroll("offset", GetLongOption::MandatoryValue, |
| 138 |
"Comma-separated x,y,z offset for coordinates of second and subsequent meshes.\n" |
| 139 |
"\t\tThe offset will be multiplied by the part number-1 so:\n" |
| 140 |
"\t\tP1: no offset; P2: 1x, 1y, 1z; P3: 2x, 2y, 2z; P(n+1): nx, ny, nz", |
| 141 |
nullptr, nullptr, true); |
| 142 |
|
| 143 |
options_.enroll("steps", GetLongOption::MandatoryValue, |
| 144 |
"Specify subset of timesteps to transfer to output file.\n" |
| 145 |
"\t\tFormat is beg:end:step. 1:10:2 --> 1,3,5,7,9\n" |
| 146 |
"\t\tIf the 'beg' or 'end' is < 0, then it is the \"-Nth\" step...\n" |
| 147 |
"\t\t-1 is \"first last\" or last, -3 is \"third last\"\n" |
| 148 |
"\t\tTo copy just the last 3 steps, do: `-steps -3:-1`\n" |
| 149 |
"\t\tEnter LAST for last step", |
| 150 |
"1:", nullptr, true); |
| 151 |
|
| 152 |
options_.enroll("gvar", GetLongOption::MandatoryValue, |
| 153 |
"Comma-separated list of global variables to be joined or ALL or NONE.", nullptr); |
| 154 |
|
| 155 |
options_.enroll("evar", GetLongOption::MandatoryValue, |
| 156 |
"Comma-separated list of element variables to be joined or ALL or NONE.\n" |
| 157 |
"\t\tVariables can be limited to certain blocks by appending a\n" |
| 158 |
"\t\tcolon followed by the block id. E.g. -evar sigxx:10:20", |
| 159 |
nullptr); |
| 160 |
|
| 161 |
options_.enroll("nvar", GetLongOption::MandatoryValue, |
| 162 |
"Comma-separated list of nodal variables to be joined or ALL or NONE.", nullptr); |
| 163 |
|
| 164 |
options_.enroll("nsetvar", GetLongOption::MandatoryValue, |
| 165 |
"Comma-separated list of nodeset variables to be joined or ALL or NONE.\n" |
| 166 |
"\t\tVariables can be limited to certain sets by appending a\n" |
| 167 |
"\t\tcolon followed by the nodeset id. E.g. -nsetvar sigxx:10:20", |
| 168 |
nullptr); |
| 169 |
|
| 170 |
options_.enroll("ssetvar", GetLongOption::MandatoryValue, |
| 171 |
"Comma-separated list of sideset variables to be joined or ALL or NONE.\n" |
| 172 |
"\t\tVariables can be limited to certain sidesets by appending a\n" |
| 173 |
"\t\tcolon followed by the sideset id. E.g. -ssetvar sigxx:10:20", |
| 174 |
nullptr); |
| 175 |
|
| 176 |
options_.enroll( |
| 177 |
"info_records", GetLongOption::OptionalValue, |
| 178 |
"If no value specified or not present,\n" |
| 179 |
"\t\tthen don't transfer any information records to output file.\n" |
| 180 |
"\t\tIf 'p#,p#,...' specified, then only transfer information records on specified parts\n" |
| 181 |
"\t\tIf 'all' specified, then transfer all information records", |
| 182 |
nullptr, "NONE"); |
| 183 |
|
| 184 |
options_.enroll("ignore_element_ids", GetLongOption::NoValue, |
| 185 |
"Ignore the element id maps on the input database and just use a 1..#elements id " |
| 186 |
"map on output.\n" |
| 187 |
"\t\tMuch faster for large models if do not need specific element global ids", |
| 188 |
nullptr, nullptr, true); |
| 189 |
|
| 190 |
options_.enroll("netcdf4", GetLongOption::NoValue, |
| 191 |
"Create output database using the HDF5-based " |
| 192 |
"netcdf which allows for up to 2.1 GB " |
| 193 |
"nodes and elements", |
| 194 |
nullptr); |
| 195 |
|
| 196 |
options_.enroll("64-bit", GetLongOption::NoValue, |
| 197 |
"True if forcing the use of 64-bit integers for the output file", nullptr); |
| 198 |
|
| 199 |
options_.enroll("zlib", GetLongOption::NoValue, |
| 200 |
"Use the Zlib / libz compression method if compression is enabled (default) " |
| 201 |
"[exodus only, enables netcdf-4].", |
| 202 |
nullptr); |
| 203 |
|
| 204 |
options_.enroll("szip", GetLongOption::NoValue, |
| 205 |
"Use SZip compression. [exodus only, enables netcdf-4]", nullptr); |
| 206 |
options_.enroll("zstd", GetLongOption::NoValue, |
| 207 |
"Use Zstd compression. [exodus only, enables netcdf-4, experimental]", nullptr); |
| 208 |
options_.enroll("bzip2", GetLongOption::NoValue, |
| 209 |
"Use Bzip2 compression. [exodus only, enables netcdf-4, experimental]", nullptr); |
| 210 |
|
| 211 |
options_.enroll("compress", GetLongOption::MandatoryValue, |
| 212 |
"Specify the compression level to be used. Values depend on algorithm:\n" |
| 213 |
"\t\tzlib/bzip2: 0..9\t\tszip: even, 4..32\t\tzstd: -131072..22", |
| 214 |
nullptr); |
| 215 |
|
| 216 |
options_.enroll("quantize_nsd", GetLongOption::MandatoryValue, |
| 217 |
"Use the lossy quantize compression method. Value specifies number of digits to " |
| 218 |
"retain (1..15) [exodus only]", |
| 219 |
nullptr, nullptr, true); |
| 220 |
|
| 221 |
options_.enroll("disable_field_recognition", GetLongOption::NoValue, |
| 222 |
"Do not try to combine scalar fields into higher-order fields such as\n" |
| 223 |
"\t\tvectors or tensors based on the field suffix", |
| 224 |
nullptr); |
| 225 |
|
| 226 |
options_.enroll("copyright", GetLongOption::NoValue, "Show copyright and license data.", nullptr); |
| 227 |
} |
| 228 |
|
| 229 |
bool SystemInterface::parse_options(int argc, char **argv) |
| 230 |
{ |
| 231 |
int option_index = options_.parse(argc, argv); |
| 232 |
if (option_index < 1) { |
| 233 |
return false; |
| 234 |
} |
| 235 |
|
| 236 |
if (options_.retrieve("help") != nullptr) { |
| 237 |
options_.usage(); |
| 238 |
fmt::print( |
| 239 |
stderr, |
| 240 |
"\n\tCan also set options via EJOIN_OPTIONS environment variable.\n" |
| 241 |
"\n\tDocumentation: https://sandialabs.github.io/seacas-docs/sphinx/html/index.html#ejoin\n" |
| 242 |
"\n\t->->-> Send email to [email protected] for ejoin support.<-<-<-\n"); |
| 243 |
exit(EXIT_SUCCESS); |
| 244 |
} |
| 245 |
|
| 246 |
if (options_.retrieve("version") != nullptr) { |
| 247 |
// Version is printed up front, just exit... |
| 248 |
exit(0); |
| 249 |
} |
| 250 |
|
| 251 |
if (options_.retrieve("copyright") != nullptr) { |
| 252 |
fmt::print("{}", copyright("2010-2021")); |
| 253 |
exit(EXIT_SUCCESS); |
| 254 |
} |
| 255 |
|
| 256 |
// Parse remaining options as directory paths. |
| 257 |
// Note that inputFiles_.size() is the number of parts which can be used in |
| 258 |
// parsing of other options... |
| 259 |
|
| 260 |
if (option_index < argc) { |
| 261 |
while (option_index < argc) { |
| 262 |
inputFiles_.emplace_back(argv[option_index++]); |
| 263 |
} |
| 264 |
} |
| 265 |
else { |
| 266 |
fmt::print(stderr, "\nERROR: no files specified\n\n"); |
| 267 |
return false; |
| 268 |
} |
| 269 |
|
| 270 |
size_t part_count = inputFiles_.size(); |
| 271 |
blockOmissions_.resize(part_count); |
| 272 |
blockInclusions_.resize(part_count); |
| 273 |
nsetOmissions_.resize(part_count); |
| 274 |
ssetOmissions_.resize(part_count); |
| 275 |
assemblyOmissions_.resize(part_count); |
| 276 |
|
| 277 |
// Get options from environment variable also... |
| 278 |
char *options = getenv("EJOIN_OPTIONS"); |
| 279 |
if (options != nullptr) { |
| 280 |
fmt::print( |
| 281 |
stderr, |
| 282 |
"\nThe following options were specified via the EJOIN_OPTIONS environment variable:\n" |
| 283 |
"\t{}\n\n", |
| 284 |
options); |
| 285 |
options_.parse(options, GetLongOption::basename(*argv)); |
| 286 |
} |
| 287 |
|
| 288 |
outputName_ = options_.get_option_value("output", outputName_); |
| 289 |
blockPrefix_ = options_.get_option_value("block_prefix", blockPrefix_); |
| 290 |
|
| 291 |
{ |
| 292 |
const char *temp = options_.retrieve("offset"); |
| 293 |
if (temp != nullptr) { |
| 294 |
parse_offset(temp, &offset_); |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
tolerance_ = options_.get_option_value("tolerance", tolerance_); |
| 299 |
|
| 300 |
{ |
| 301 |
const char *temp = options_.retrieve("steps"); |
| 302 |
if (temp != nullptr) { |
| 303 |
parse_step_option(temp); |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
{ |
| 308 |
const char *temp = options_.retrieve("convert_nodal_to_nodesets"); |
| 309 |
if (temp != nullptr) { |
| 310 |
parse_integer_list(temp, &nodesetConvertParts_); |
| 311 |
std::sort(nodesetConvertParts_.begin(), nodesetConvertParts_.end()); |
| 312 |
} |
| 313 |
} |
| 314 |
|
| 315 |
{ |
| 316 |
const char *temp = options_.retrieve("info_records"); |
| 317 |
if (temp != nullptr) { |
| 318 |
parse_part_list(temp, &infoRecordParts_); |
| 319 |
std::sort(infoRecordParts_.begin(), infoRecordParts_.end()); |
| 320 |
} |
| 321 |
} |
| 322 |
|
| 323 |
{ |
| 324 |
const char *temp = options_.retrieve("omit_blocks"); |
| 325 |
if (temp != nullptr) { |
| 326 |
parse_omissions(temp, &blockOmissions_, "block", true); |
| 327 |
} |
| 328 |
} |
| 329 |
|
| 330 |
{ |
| 331 |
const char *temp = options_.retrieve("omit_assemblies"); |
| 332 |
if (temp != nullptr) { |
| 333 |
if (str_equal("ALL", temp)) { |
| 334 |
omitAssemblies_ = true; |
| 335 |
} |
| 336 |
else { |
| 337 |
parse_omissions(temp, &assemblyOmissions_, "assembly", true); |
| 338 |
} |
| 339 |
} |
| 340 |
else { |
| 341 |
omitAssemblies_ = false; |
| 342 |
} |
| 343 |
} |
| 344 |
|
| 345 |
if (options_.retrieve("omit_part_assemblies") != nullptr) { |
| 346 |
createAssemblies_ = false; |
| 347 |
} |
| 348 |
|
| 349 |
{ |
| 350 |
const char *temp = options_.retrieve("extract_blocks"); |
| 351 |
if (temp != nullptr) { |
| 352 |
parse_omissions(temp, &blockInclusions_, "block", true); |
| 353 |
} |
| 354 |
} |
| 355 |
|
| 356 |
{ |
| 357 |
const char *temp = options_.retrieve("omit_nodesets"); |
| 358 |
if (temp != nullptr) { |
| 359 |
if (str_equal("ALL", temp)) { |
| 360 |
omitNodesets_ = true; |
| 361 |
} |
| 362 |
else { |
| 363 |
parse_omissions(temp, &nsetOmissions_, "nodelist", false); |
| 364 |
} |
| 365 |
} |
| 366 |
else { |
| 367 |
omitNodesets_ = false; |
| 368 |
} |
| 369 |
} |
| 370 |
|
| 371 |
{ |
| 372 |
const char *temp = options_.retrieve("omit_sidesets"); |
| 373 |
if (temp != nullptr) { |
| 374 |
if (str_equal("ALL", temp)) { |
| 375 |
omitSidesets_ = true; |
| 376 |
} |
| 377 |
else { |
| 378 |
parse_omissions(temp, &ssetOmissions_, "surface", false); |
| 379 |
} |
| 380 |
} |
| 381 |
else { |
| 382 |
omitSidesets_ = false; |
| 383 |
} |
| 384 |
} |
| 385 |
|
| 386 |
{ |
| 387 |
const char *temp = options_.retrieve("gvar"); |
| 388 |
if (temp != nullptr) { |
| 389 |
parse_variable_names(temp, &globalVarNames_); |
| 390 |
} |
| 391 |
} |
| 392 |
|
| 393 |
{ |
| 394 |
const char *temp = options_.retrieve("nvar"); |
| 395 |
if (temp != nullptr) { |
| 396 |
parse_variable_names(temp, &nodeVarNames_); |
| 397 |
} |
| 398 |
} |
| 399 |
|
| 400 |
{ |
| 401 |
const char *temp = options_.retrieve("evar"); |
| 402 |
if (temp != nullptr) { |
| 403 |
parse_variable_names(temp, &elemVarNames_); |
| 404 |
} |
| 405 |
} |
| 406 |
|
| 407 |
{ |
| 408 |
const char *temp = options_.retrieve("nsetvar"); |
| 409 |
if (temp != nullptr) { |
| 410 |
parse_variable_names(temp, &nsetVarNames_); |
| 411 |
} |
| 412 |
} |
| 413 |
|
| 414 |
{ |
| 415 |
const char *temp = options_.retrieve("ssetvar"); |
| 416 |
if (temp != nullptr) { |
| 417 |
parse_variable_names(temp, &ssetVarNames_); |
| 418 |
} |
| 419 |
} |
| 420 |
|
| 421 |
disableFieldRecognition_ = options_.retrieve("disable_field_recognition") != nullptr; |
| 422 |
useNetcdf4_ = options_.retrieve("netcdf4") != nullptr; |
| 423 |
ignoreElementIds_ = options_.retrieve("ignore_element_ids") != nullptr; |
| 424 |
|
| 425 |
if (options_.retrieve("64-bit") != nullptr) { |
| 426 |
ints64bit_ = true; |
| 427 |
} |
| 428 |
|
| 429 |
zlib_ = (options_.retrieve("zlib") != nullptr); |
| 430 |
szip_ = (options_.retrieve("szip") != nullptr); |
| 431 |
zstd_ = (options_.retrieve("zstd") != nullptr); |
| 432 |
bz2_ = (options_.retrieve("bzip2") != nullptr); |
| 433 |
|
| 434 |
if (szip_ + zlib_ + zstd_ + bz2_ > 1) { |
| 435 |
fmt::print(stderr, |
| 436 |
"ERROR: Only one of 'szip' or 'zlib' or 'zstd' or 'bzip2' can be specified.\n"); |
| 437 |
} |
| 438 |
|
| 439 |
{ |
| 440 |
const char *temp = options_.retrieve("compress"); |
| 441 |
if (temp != nullptr) { |
| 442 |
compressionLevel_ = std::strtol(temp, nullptr, 10); |
| 443 |
if (!szip_ && !zlib_ && !zstd_ && !bz2_) { |
| 444 |
zlib_ = true; |
| 445 |
} |
| 446 |
|
| 447 |
if (zlib_ || bz2_) { |
| 448 |
if (compressionLevel_ < 0 || compressionLevel_ > 9) { |
| 449 |
fmt::print(stderr, |
| 450 |
"ERROR: Bad compression level {}, valid value is between 0 and 9 inclusive " |
| 451 |
"for gzip/zlib/bzip2 compression.\n", |
| 452 |
compressionLevel_); |
| 453 |
return false; |
| 454 |
} |
| 455 |
} |
| 456 |
else if (szip_) { |
| 457 |
if (compressionLevel_ % 2 != 0) { |
| 458 |
fmt::print( |
| 459 |
stderr, |
| 460 |
"ERROR: Bad compression level {}. Must be an even value for szip compression.\n", |
| 461 |
compressionLevel_); |
| 462 |
return false; |
| 463 |
} |
| 464 |
if (compressionLevel_ < 4 || compressionLevel_ > 32) { |
| 465 |
fmt::print(stderr, |
| 466 |
"ERROR: Bad compression level {}, valid value is between 4 and 32 inclusive " |
| 467 |
"for szip compression.\n", |
| 468 |
compressionLevel_); |
| 469 |
return false; |
| 470 |
} |
| 471 |
} |
| 472 |
} |
| 473 |
} |
| 474 |
|
| 475 |
{ |
| 476 |
const char *temp = options_.retrieve("quantize_nsd"); |
| 477 |
if (temp != nullptr) { |
| 478 |
quantizeNSD_ = std::strtol(temp, nullptr, 10); |
| 479 |
if (!szip_ && !zlib_ && !zstd_ && !bz2_) { |
| 480 |
zlib_ = true; |
| 481 |
} |
| 482 |
} |
| 483 |
} |
| 484 |
|
| 485 |
if (options_.retrieve("match_node_ids") != nullptr) { |
| 486 |
matchNodeIds_ = true; |
| 487 |
matchNodeXYZ_ = false; |
| 488 |
} |
| 489 |
else { |
| 490 |
matchNodeIds_ = false; |
| 491 |
} |
| 492 |
|
| 493 |
if (options_.retrieve("match_node_coordinates") != nullptr) { |
| 494 |
matchNodeXYZ_ = true; |
| 495 |
matchNodeIds_ = false; |
| 496 |
} |
| 497 |
else { |
| 498 |
matchNodeXYZ_ = false; |
| 499 |
} |
| 500 |
|
| 501 |
#if 0 |
| 502 |
if (options_.retrieve("match_elem_ids")) { |
| 503 |
matchElemIds_ = true; |
| 504 |
matchElemXYZ_ = false; |
| 505 |
} else { |
| 506 |
matchElemIds_ = false; |
| 507 |
} |
| 508 |
|
| 509 |
if (options_.retrieve("match_elem_coordinates")) { |
| 510 |
matchElemXYZ_ = true; |
| 511 |
matchElemIds_ = false; |
| 512 |
} else { |
| 513 |
matchElemXYZ_ = false; |
| 514 |
} |
| 515 |
#endif |
| 516 |
|
| 517 |
return true; |
| 518 |
} |
| 519 |
|
| 520 |
bool SystemInterface::convert_nodes_to_nodesets(int part_number) const |
| 521 |
{ |
| 522 |
if (nodesetConvertParts_.empty()) { |
| 523 |
return false; |
| 524 |
} |
| 525 |
if (nodesetConvertParts_[0] == 0) { |
| 526 |
return true; |
| 527 |
} |
| 528 |
return std::find(nodesetConvertParts_.cbegin(), nodesetConvertParts_.cend(), part_number) != |
| 529 |
nodesetConvertParts_.cend(); |
| 530 |
} |
| 531 |
|
| 532 |
void SystemInterface::parse_step_option(const char *tokens) |
| 533 |
{ |
| 534 |
//: The defined formats for the count attribute are:<br> |
| 535 |
//: <ul> |
| 536 |
//: <li><missing> -- default -- 1 <= count <= oo (all steps)</li> |
| 537 |
//: <li>"X" -- X <= count <= X (just step X) LAST for last step.</li> |
| 538 |
//: <li>"X:Y" -- X to Y by 1</li> |
| 539 |
//: <li>"X:" -- X to oo by 1</li> |
| 540 |
//: <li>":Y" -- 1 to Y by 1</li> |
| 541 |
//: <li>"::Z" -- 1 to oo by Z</li> |
| 542 |
//: </ul> |
| 543 |
//: The step must always be > 0 |
| 544 |
//: If the 'from' or 'to' is < 0, then it is the "-Nth" step... |
| 545 |
//: -1 is "first last" or last |
| 546 |
//: -4 is "fourth last step" |
| 547 |
//: To copy just the last 3 steps, do: `-steps -3:-1` |
| 548 |
|
| 549 |
// Break into tokens separated by ":" |
| 550 |
|
| 551 |
// Default is given in constructor above... |
| 552 |
|
| 553 |
if (tokens != nullptr) { |
| 554 |
if (strchr(tokens, ':') != nullptr) { |
| 555 |
// The string contains a separator |
| 556 |
|
| 557 |
std::array<int, 3> vals{stepMin_, stepMax_, stepInterval_}; |
| 558 |
|
| 559 |
int j = 0; |
| 560 |
for (auto &val : vals) { |
| 561 |
// Parse 'i'th field |
| 562 |
char tmp_str[128]; |
| 563 |
|
| 564 |
int k = 0; |
| 565 |
while (tokens[j] != '\0' && tokens[j] != ':') { |
| 566 |
tmp_str[k++] = tokens[j++]; |
| 567 |
} |
| 568 |
|
| 569 |
tmp_str[k] = '\0'; |
| 570 |
if (strlen(tmp_str) > 0) { |
| 571 |
val = strtol(tmp_str, nullptr, 0); |
| 572 |
} |
| 573 |
|
| 574 |
if (tokens[j++] == '\0') { |
| 575 |
break; // Reached end of string |
| 576 |
} |
| 577 |
} |
| 578 |
stepMin_ = vals[0]; |
| 579 |
stepMax_ = vals[1]; |
| 580 |
stepInterval_ = abs(vals[2]); // step is always positive... |
| 581 |
} |
| 582 |
else if (str_equal("LAST", tokens)) { |
| 583 |
stepMin_ = stepMax_ = -1; |
| 584 |
} |
| 585 |
else { |
| 586 |
// Does not contain a separator, min == max |
| 587 |
stepMin_ = stepMax_ = strtol(tokens, nullptr, 0); |
| 588 |
} |
| 589 |
} |
| 590 |
} |
| 591 |
|
| 592 |
void SystemInterface::show_version() |
| 593 |
{ |
| 594 |
fmt::print("EJoin\n" |
| 595 |
"\t(A code for merging Exodus databases; with or without results data.)\n" |
| 596 |
"\t(Version: {}) Modified: {}\n\n", |
| 597 |
qainfo[2], qainfo[1]); |
| 598 |
} |
| 599 |
|
| 600 |
namespace { |
| 601 |
std::string LowerCase(const std::string &name) |
| 602 |
{ |
| 603 |
std::string s = name; |
| 604 |
std::transform(s.begin(), s.end(), // source |
| 605 |
s.begin(), // destination |
| 606 |
::tolower); // operation |
| 607 |
return s; |
| 608 |
} |
| 609 |
|
| 610 |
using StringVector = std::vector<std::string>; |
| 611 |
void parse_variable_names(const char *tokens, StringIdVector *variable_list) |
| 612 |
{ |
| 613 |
// Break into tokens separated by "," |
| 614 |
if (tokens != nullptr) { |
| 615 |
std::string token_string(tokens); |
| 616 |
StringVector var_list = SLIB::tokenize(token_string, ","); |
| 617 |
|
| 618 |
// At this point, var_list is either a single string, or a string |
| 619 |
// separated from 1 or more block ids with ":" delimiter. |
| 620 |
// For example, sigxx:1:10:100 would indicate that the variable |
| 621 |
// "sigxx" should be written only for blocks with id 1, 10, and |
| 622 |
// 100. "sigxx" would indicate that the variable should be |
| 623 |
// written for all blocks. |
| 624 |
auto I = var_list.begin(); |
| 625 |
while (I != var_list.end()) { |
| 626 |
StringVector name_id = SLIB::tokenize(*I, ":"); |
| 627 |
std::string var_name = LowerCase(name_id[0]); |
| 628 |
if (name_id.size() == 1) { |
| 629 |
(*variable_list).emplace_back(var_name, 0); |
| 630 |
} |
| 631 |
else { |
| 632 |
for (size_t i = 1; i < name_id.size(); i++) { |
| 633 |
// Convert string to integer... |
| 634 |
int id = std::stoi(name_id[i]); |
| 635 |
(*variable_list).emplace_back(var_name, id); |
| 636 |
} |
| 637 |
} |
| 638 |
++I; |
| 639 |
} |
| 640 |
// Sort the list... |
| 641 |
std::sort( |
| 642 |
variable_list->begin(), variable_list->end(), |
| 643 |
[](const std::pair<std::string, size_t> &t1, const std::pair<std::string, size_t> &t2) { |
| 644 |
return t1.first < t2.first || (!(t2.first < t1.first) && t1.second < t2.second); |
| 645 |
}); |
| 646 |
} |
| 647 |
} |
| 648 |
|
| 649 |
void parse_offset(const char *tokens, vector3d *offset) |
| 650 |
{ |
| 651 |
// Break into tokens separated by "," |
| 652 |
if (tokens != nullptr) { |
| 653 |
std::string token_string(tokens); |
| 654 |
StringVector var_list = SLIB::tokenize(token_string, ","); |
| 655 |
|
| 656 |
// At this point, var_list should contain 1,2,or 3 strings |
| 657 |
// corresponding to the x, y, and z coordinate offsets. |
| 658 |
if (var_list.size() != 3) { |
| 659 |
fmt::print(stderr, |
| 660 |
"ERROR: Incorrect number of offset components specified--3 required.\n\n"); |
| 661 |
offset->x = offset->y = offset->z = 0.0; |
| 662 |
return; |
| 663 |
} |
| 664 |
|
| 665 |
std::string offx = var_list[0]; |
| 666 |
std::string offy = var_list[1]; |
| 667 |
std::string offz = var_list[2]; |
| 668 |
double x = std::stod(offx); |
| 669 |
double y = std::stod(offy); |
| 670 |
double z = std::stod(offz); |
| 671 |
|
| 672 |
offset->x = x; |
| 673 |
offset->y = y; |
| 674 |
offset->z = z; |
| 675 |
} |
| 676 |
} |
| 677 |
|
| 678 |
void parse_integer_list(const char *tokens, std::vector<int> *list) |
| 679 |
{ |
| 680 |
// Break into tokens separated by "," |
| 681 |
if (tokens != nullptr) { |
| 682 |
if (LowerCase(tokens) == "all") { |
| 683 |
(*list).push_back(0); |
| 684 |
return; |
| 685 |
} |
| 686 |
|
| 687 |
std::string token_string(tokens); |
| 688 |
StringVector part_list = SLIB::tokenize(token_string, ","); |
| 689 |
|
| 690 |
auto I = part_list.begin(); |
| 691 |
while (I != part_list.end()) { |
| 692 |
int id = std::stoi(*I); |
| 693 |
(*list).push_back(id); |
| 694 |
++I; |
| 695 |
} |
| 696 |
} |
| 697 |
} |
| 698 |
|
| 699 |
void parse_part_list(const char *tokens, std::vector<int> *list) |
| 700 |
{ |
| 701 |
// Break into tokens separated by "," |
| 702 |
// Tokens will be of the form "p$" or "all" |
| 703 |
if (tokens != nullptr) { |
| 704 |
if (LowerCase(tokens) == "all") { |
| 705 |
(*list).push_back(0); |
| 706 |
return; |
| 707 |
} |
| 708 |
|
| 709 |
std::string token_string(tokens); |
| 710 |
StringVector part_list = SLIB::tokenize(token_string, ","); |
| 711 |
|
| 712 |
auto I = part_list.begin(); |
| 713 |
while (I != part_list.end()) { |
| 714 |
std::string part = *I; |
| 715 |
if (part[0] == 'p' || part[0] == 'P') { |
| 716 |
std::string part_id(part, 1); |
| 717 |
int part_num = std::stoi(part_id); |
| 718 |
list->push_back(part_num); |
| 719 |
} |
| 720 |
else { |
| 721 |
fmt::print(stderr, |
| 722 |
"ERROR: Bad syntax ({}) specifying part number. Use 'p'+ part_number\n" |
| 723 |
" For example -info_records p1,p2,p7\n", |
| 724 |
part); |
| 725 |
exit(EXIT_FAILURE); |
| 726 |
} |
| 727 |
++I; |
| 728 |
} |
| 729 |
} |
| 730 |
} |
| 731 |
|
| 732 |
void parse_omissions(const char *tokens, Omissions *omissions, const std::string &basename, |
| 733 |
bool require_ids) |
| 734 |
{ |
| 735 |
// to Omit block id 1,3,4 from part 1; block 2 3 4 from part 2; |
| 736 |
// and block 8 from part5, specify |
| 737 |
// '-omit_blocks p1:1:3:4,p2:2:3:4,p5:8' |
| 738 |
|
| 739 |
// Break into tokens separated by "," Each token will then be a |
| 740 |
// ":" separated list of blocks to be omitted for the specified |
| 741 |
// part. |
| 742 |
|
| 743 |
// If "require_ids" is true, then there must be at least one id |
| 744 |
// following the part specification. If false, then it is OK to |
| 745 |
// just specify a part number and all entities (typically nset or |
| 746 |
// sset) will be omitted on that part. |
| 747 |
|
| 748 |
if (tokens == nullptr) { |
| 749 |
return; |
| 750 |
} |
| 751 |
|
| 752 |
std::string token_string(tokens); |
| 753 |
StringVector part_block_list = SLIB::tokenize(token_string, ","); |
| 754 |
|
| 755 |
// Now, for each token in 'part_block_list', split by ":" |
| 756 |
// The result should be a string starting with 'p' followed by an |
| 757 |
// integer indicating the part followed by 1 or more strings which |
| 758 |
// are the block ids of the blocks to be omitted for that part. |
| 759 |
// |
| 760 |
// Parts are 1-based. Store the results in the 'omissions' set as |
| 761 |
// the pair (part#, block_id). |
| 762 |
auto I = part_block_list.begin(); |
| 763 |
while (I != part_block_list.end()) { |
| 764 |
StringVector part_block = SLIB::tokenize(*I, ":"); |
| 765 |
if (part_block.empty() || (part_block[0][0] != 'p' && part_block[0][0] != 'P')) { |
| 766 |
fmt::print(stderr, "ERROR: Bad syntax specifying the part number. Use 'p' + part number\n" |
| 767 |
" For example -omit_blocks p1:1:2:3,p2:2:3:4\n"); |
| 768 |
exit(EXIT_FAILURE); |
| 769 |
} |
| 770 |
if (require_ids && part_block.size() == 1) { |
| 771 |
fmt::print(stderr, |
| 772 |
"ERROR: No block ids were found following the part specification.\n" |
| 773 |
" for part {}\n", |
| 774 |
part_block[0]); |
| 775 |
exit(EXIT_FAILURE); |
| 776 |
} |
| 777 |
|
| 778 |
// Extract the part number... |
| 779 |
std::string part(part_block[0], 1); |
| 780 |
int part_num = std::stoi(part) - 1; |
| 781 |
|
| 782 |
// If no blocks specified for a part, then omit all entities for |
| 783 |
// this part. Since don't know how many entities there are, |
| 784 |
// store the id as '0' to signify all. |
| 785 |
if (part_block.size() == 1) { |
| 786 |
(*omissions)[part_num].emplace_back("ALL"); |
| 787 |
} |
| 788 |
else { |
| 789 |
// Get the list of blocks to omit for this part... |
| 790 |
auto J = part_block.begin(); |
| 791 |
++J; // Skip p# |
| 792 |
while (J != part_block.end()) { |
| 793 |
std::string block = *J; |
| 794 |
std::string name = basename + '_' + block; |
| 795 |
(*omissions)[part_num].push_back(name); |
| 796 |
++J; |
| 797 |
} |
| 798 |
} |
| 799 |
++I; |
| 800 |
} |
| 801 |
} |
| 802 |
} // namespace |