| 1 |
/* |
| 2 |
* Copyright(C) 1999-2022, 2024 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "exodusII.h" // for ex_assembly, ex_err, etc |
| 10 |
#include "exodusII_int.h" // for EX_FATAL, etc |
| 11 |
|
| 12 |
/*! |
| 13 |
* writes the assembly parameters and optionally assembly data for all assemblies |
| 14 |
* assumes that `assembly` is large enough to contain all assemblies. |
| 15 |
* \param exoid exodus file id |
| 16 |
* \param assembly array of ex_assembly structures |
| 17 |
*/ |
| 18 |
int ex_get_assemblies(int exoid, ex_assembly *assembly) |
| 19 |
{ |
| 20 |
/* Determine number of assemblies on database */ |
| 21 |
int num_assembly = (int)ex_inquire_int(exoid, EX_INQ_ASSEMBLY); |
| 22 |
int max_use_name_length = (int)ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH); |
| 23 |
|
| 24 |
if (num_assembly < 0) { |
| 25 |
char errmsg[MAX_ERR_LENGTH]; |
| 26 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to inquire ASSEMBLY count in file id %d", |
| 27 |
exoid); |
| 28 |
ex_err_fn(exoid, __func__, errmsg, num_assembly); |
| 29 |
return EX_FATAL; |
| 30 |
} |
| 31 |
|
| 32 |
if (ex_int64_status(exoid) & EX_IDS_INT64_API) { |
| 33 |
int64_t *ids = calloc(num_assembly, sizeof(int64_t)); |
| 34 |
ex_get_ids(exoid, EX_ASSEMBLY, ids); |
| 35 |
for (int i = 0; i < num_assembly; i++) { |
| 36 |
assembly[i].id = ids[i]; |
| 37 |
} |
| 38 |
free(ids); |
| 39 |
} |
| 40 |
else { |
| 41 |
int *ids = calloc(num_assembly, sizeof(int)); |
| 42 |
ex_get_ids(exoid, EX_ASSEMBLY, ids); |
| 43 |
for (int i = 0; i < num_assembly; i++) { |
| 44 |
assembly[i].id = ids[i]; |
| 45 |
} |
| 46 |
free(ids); |
| 47 |
} |
| 48 |
|
| 49 |
for (int i = 0; i < num_assembly; i++) { |
| 50 |
if (assembly[i].name == NULL) { |
| 51 |
assembly[i].name = calloc(max_use_name_length + 1, sizeof(char)); |
| 52 |
} |
| 53 |
|
| 54 |
int status = ex_get_assembly(exoid, &assembly[i]); |
| 55 |
if (status != EX_NOERR) { |
| 56 |
return status; |
| 57 |
} |
| 58 |
} |
| 59 |
return EX_NOERR; |
| 60 |
} |