Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_get_blobs.c

raw
1 /*
2 * Copyright(C) 1999-2020, 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_blob, ex_err, etc
10 #include "exodusII_int.h" // for EX_FATAL, etc
11
12 /*!
13 * writes the blob parameters and optionally blob data for all blobs
14 * assumes that `blob` is large enough to contain all blobs.
15 * \param exoid exodus file id
16 * \param *blob array of ex_blob structures
17 */
18 int ex_get_blobs(int exoid, ex_blob *blob)
19 {
20 /* Determine number of blobs on database */
21 int num_blob = ex_inquire_int(exoid, EX_INQ_BLOB);
22 if (num_blob < 0) {
23 char errmsg[MAX_ERR_LENGTH];
24 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to inquire BLOB count in file id %d", exoid);
25 ex_err_fn(exoid, __func__, errmsg, num_blob);
26 return EX_FATAL;
27 }
28
29 if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
30 int64_t *ids = calloc(num_blob, sizeof(int64_t));
31 ex_get_ids(exoid, EX_BLOB, ids);
32 for (int i = 0; i < num_blob; i++) {
33 blob[i].id = ids[i];
34 }
35 free(ids);
36 }
37 else {
38 int *ids = calloc(num_blob, sizeof(int));
39 ex_get_ids(exoid, EX_BLOB, ids);
40 for (int i = 0; i < num_blob; i++) {
41 blob[i].id = ids[i];
42 }
43 free(ids);
44 }
45
46 for (int i = 0; i < num_blob; i++) {
47 int status = ex_get_blob(exoid, &blob[i]);
48 if (status != EX_NOERR) {
49 return status;
50 }
51 }
52 return EX_NOERR;
53 }