| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020 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 |
* reads the blob parameters and optionally blob data for one blob |
| 14 |
* \param exoid exodus file id |
| 15 |
* \param *blob ex_blob structure |
| 16 |
*/ |
| 17 |
|
| 18 |
int ex_get_blob(int exoid, ex_blob *blob) |
| 19 |
{ |
| 20 |
struct exi_file_item *file = NULL; |
| 21 |
int status = 0; |
| 22 |
int dimid = 0; |
| 23 |
size_t len = 0; |
| 24 |
char errmsg[MAX_ERR_LENGTH]; |
| 25 |
|
| 26 |
EX_FUNC_ENTER(); |
| 27 |
|
| 28 |
file = exi_find_file_item(exoid); |
| 29 |
if (!file) { |
| 30 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unknown file id %d.", exoid); |
| 31 |
ex_err_fn(exoid, __func__, errmsg, EX_BADFILEID); |
| 32 |
EX_FUNC_LEAVE(EX_FATAL); |
| 33 |
} |
| 34 |
|
| 35 |
/* First, locate varid of blob */ |
| 36 |
int entlst_id = 0; |
| 37 |
if ((status = nc_inq_varid(exoid, VAR_ENTITY_BLOB(blob->id), &entlst_id)) != NC_NOERR) { |
| 38 |
ex_get_err(NULL, NULL, &status); |
| 39 |
if (status != 0) { |
| 40 |
if (blob->name != NULL) { |
| 41 |
ex_copy_string(blob->name, "NULL", MAX_STR_LENGTH + 1); /* NULL element type name */ |
| 42 |
} |
| 43 |
blob->num_entry = 0; |
| 44 |
if (status == EX_NULLENTITY) { /* NULL element blob? */ |
| 45 |
EX_FUNC_LEAVE(EX_NOERR); |
| 46 |
} |
| 47 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 48 |
"ERROR: failed to locate blob id %" PRId64 " in id array in file id %d", blob->id, |
| 49 |
exoid); |
| 50 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 51 |
EX_FUNC_LEAVE(EX_FATAL); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
char *numentryptr = DIM_NUM_VALUES_BLOB(blob->id); |
| 56 |
if ((status = nc_inq_dimid(exoid, numentryptr, &dimid)) != NC_NOERR) { |
| 57 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 58 |
"ERROR: failed to locate number of entities in blob %" PRId64 " in file id %d", |
| 59 |
blob->id, exoid); |
| 60 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 61 |
EX_FUNC_LEAVE(EX_FATAL); |
| 62 |
} |
| 63 |
|
| 64 |
if ((status = nc_inq_dimlen(exoid, dimid, &len)) != NC_NOERR) { |
| 65 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 66 |
"ERROR: failed to get number of entities in blob %" PRId64 " in file id %d", blob->id, |
| 67 |
exoid); |
| 68 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 69 |
EX_FUNC_LEAVE(EX_FATAL); |
| 70 |
} |
| 71 |
|
| 72 |
blob->num_entry = len; |
| 73 |
|
| 74 |
/* look up entity list array for this blob id */ |
| 75 |
if ((status = nc_inq_varid(exoid, VAR_ENTITY_BLOB(blob->id), &entlst_id)) != NC_NOERR) { |
| 76 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 77 |
"ERROR: failed to locate entity list array for blob %" PRId64 " in file id %d", |
| 78 |
blob->id, exoid); |
| 79 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 80 |
EX_FUNC_LEAVE(EX_FATAL); |
| 81 |
} |
| 82 |
|
| 83 |
/* read the name */ |
| 84 |
if (blob->name != NULL) { |
| 85 |
int name_size = ex_inquire_int(exoid, EX_INQ_MAX_READ_NAME_LENGTH); |
| 86 |
char tmp_name[EX_MAX_NAME] = ""; |
| 87 |
if ((status = nc_get_att_text(exoid, entlst_id, EX_ATTRIBUTE_NAME, tmp_name)) != NC_NOERR) { |
| 88 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 89 |
"ERROR: failed to read blob name for blob %" PRId64 " in file id %d", blob->id, |
| 90 |
exoid); |
| 91 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 92 |
EX_FUNC_LEAVE(EX_FATAL); |
| 93 |
} |
| 94 |
ex_copy_string(blob->name, tmp_name, name_size + 1); |
| 95 |
} |
| 96 |
|
| 97 |
EX_FUNC_LEAVE(EX_NOERR); |
| 98 |
} |