| 1 |
/* |
| 2 |
* Copyright(C) 1999-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" |
| 10 |
#include "exodusII_int.h" |
| 11 |
|
| 12 |
/*! \cond INTERNAL */ |
| 13 |
static int exi_get_dimension_value(int exoid, int64_t *var, int default_value, |
| 14 |
const char *dimension_name, int missing_ok) |
| 15 |
{ |
| 16 |
int status; |
| 17 |
int dimid; |
| 18 |
|
| 19 |
if ((status = nc_inq_dimid(exoid, dimension_name, &dimid)) != NC_NOERR) { |
| 20 |
*var = default_value; |
| 21 |
if (missing_ok) { |
| 22 |
return EX_NOERR; |
| 23 |
} |
| 24 |
char errmsg[MAX_ERR_LENGTH]; |
| 25 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to retrieve dimension %s for file id %d", |
| 26 |
dimension_name, exoid); |
| 27 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 28 |
return EX_FATAL; |
| 29 |
} |
| 30 |
size_t idum; |
| 31 |
if ((status = nc_inq_dimlen(exoid, dimid, &idum)) != NC_NOERR) { |
| 32 |
*var = default_value; |
| 33 |
char errmsg[MAX_ERR_LENGTH]; |
| 34 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 35 |
"ERROR: failed to retrieve value for dimension %s for file id %d", dimension_name, |
| 36 |
exoid); |
| 37 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 38 |
return EX_FATAL; |
| 39 |
} |
| 40 |
*var = idum; |
| 41 |
return EX_NOERR; |
| 42 |
} |
| 43 |
|
| 44 |
static int ex_get_concat_set_len(int exoid, int64_t *set_length, const char *set_name, |
| 45 |
const char *set_num_dim, const char *set_stat_var, |
| 46 |
const char *set_size_root, int missing_ok) |
| 47 |
{ |
| 48 |
*set_length = 0; /* default return value */ |
| 49 |
|
| 50 |
int dimid; |
| 51 |
if (nc_inq_dimid(exoid, set_num_dim, &dimid) == NC_NOERR) { |
| 52 |
int status; |
| 53 |
size_t num_sets; |
| 54 |
if ((status = nc_inq_dimlen(exoid, dimid, &num_sets)) != NC_NOERR) { |
| 55 |
char errmsg[MAX_ERR_LENGTH]; |
| 56 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of %s sets in file id %d", |
| 57 |
set_name, exoid); |
| 58 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 59 |
return EX_FATAL; |
| 60 |
} |
| 61 |
|
| 62 |
/* Allocate space for stat array */ |
| 63 |
int *stat_vals = NULL; |
| 64 |
if (!(stat_vals = malloc((int)num_sets * sizeof(int)))) { |
| 65 |
char errmsg[MAX_ERR_LENGTH]; |
| 66 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 67 |
"ERROR: failed to allocate memory for %s set status " |
| 68 |
"array for file id %d", |
| 69 |
set_name, exoid); |
| 70 |
ex_err_fn(exoid, __func__, errmsg, EX_MEMFAIL); |
| 71 |
return EX_FATAL; |
| 72 |
} |
| 73 |
|
| 74 |
/* get variable id of status array */ |
| 75 |
int varid; |
| 76 |
if (nc_inq_varid(exoid, set_stat_var, &varid) == NC_NOERR) { |
| 77 |
/* if status array exists, use it, otherwise assume, object exists |
| 78 |
to be backward compatible */ |
| 79 |
if ((status = nc_get_var_int(exoid, varid, stat_vals)) != NC_NOERR) { |
| 80 |
free(stat_vals); |
| 81 |
char errmsg[MAX_ERR_LENGTH]; |
| 82 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get %s set status array from file id %d", |
| 83 |
set_name, exoid); |
| 84 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 85 |
return EX_FATAL; |
| 86 |
} |
| 87 |
} |
| 88 |
else { /* default: status is true */ |
| 89 |
for (size_t i = 0; i < num_sets; i++) { |
| 90 |
stat_vals[i] = 1; |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
for (size_t i = 0; i < num_sets; i++) { |
| 95 |
if (stat_vals[i] == 0) { /* is this object null? */ |
| 96 |
continue; |
| 97 |
} |
| 98 |
|
| 99 |
size_t idum; |
| 100 |
if (nc_inq_dimid(exoid, exi_catstr(set_size_root, i + 1), &dimid) != NC_NOERR) { |
| 101 |
if (missing_ok) { |
| 102 |
idum = 0; |
| 103 |
} |
| 104 |
else { |
| 105 |
*set_length = 0; |
| 106 |
free(stat_vals); |
| 107 |
return EX_FATAL; |
| 108 |
} |
| 109 |
} |
| 110 |
else { |
| 111 |
if (nc_inq_dimlen(exoid, dimid, &idum) != NC_NOERR) { |
| 112 |
*set_length = 0; |
| 113 |
free(stat_vals); |
| 114 |
return EX_FATAL; |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
*set_length += idum; |
| 119 |
} |
| 120 |
|
| 121 |
free(stat_vals); |
| 122 |
} |
| 123 |
return EX_NOERR; |
| 124 |
} |
| 125 |
|
| 126 |
static void flt_cvt(float *xptr, double x) { *xptr = (float)x; } |
| 127 |
/*! \endcond */ |
| 128 |
|
| 129 |
static int ex_inquire_internal(int exoid, int req_info, int64_t *ret_int, float *ret_float, |
| 130 |
char *ret_char) |
| 131 |
{ |
| 132 |
int dimid, varid; |
| 133 |
size_t ldum = 0; |
| 134 |
size_t num_sets, idum; |
| 135 |
int *stat_vals; |
| 136 |
char errmsg[MAX_ERR_LENGTH]; |
| 137 |
int status; |
| 138 |
int num_var; |
| 139 |
|
| 140 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 141 |
return EX_FATAL; |
| 142 |
} |
| 143 |
|
| 144 |
if (ret_char) { |
| 145 |
*ret_char = '\0'; /* Only needs to be non-null for TITLE and some GROUP NAME inquiries */ |
| 146 |
} |
| 147 |
if (!ret_int) { |
| 148 |
snprintf(errmsg, MAX_ERR_LENGTH, "Warning: integer argument is NULL which is not allowed."); |
| 149 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 150 |
return EX_FATAL; |
| 151 |
} |
| 152 |
|
| 153 |
int rootid = exoid & EX_FILE_ID_MASK; |
| 154 |
|
| 155 |
switch (req_info) { |
| 156 |
case EX_INQ_FILE_TYPE: |
| 157 |
|
| 158 |
/* obsolete call */ |
| 159 |
/*return "r" for regular EXODUS file or "h" for history EXODUS file*/ |
| 160 |
snprintf(errmsg, MAX_ERR_LENGTH, "Warning: file type inquire is obsolete"); |
| 161 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 162 |
return EX_WARN; |
| 163 |
|
| 164 |
case EX_INQ_API_VERS: |
| 165 |
/* returns the EXODUS API version number */ |
| 166 |
if (!ret_float) { |
| 167 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 168 |
"Warning: float argument is NULL for EX_INQ_API_VERS " |
| 169 |
"which is not allowed."); |
| 170 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 171 |
return EX_FATAL; |
| 172 |
} |
| 173 |
|
| 174 |
if (nc_get_att_float(rootid, NC_GLOBAL, ATT_API_VERSION, ret_float) != |
| 175 |
NC_NOERR) { /* try old (prior to db version 2.02) attribute name */ |
| 176 |
if ((status = nc_get_att_float(rootid, NC_GLOBAL, ATT_API_VERSION_BLANK, ret_float)) != |
| 177 |
NC_NOERR) { |
| 178 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get EXODUS API version for file id %d", |
| 179 |
rootid); |
| 180 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 181 |
return EX_FATAL; |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
break; |
| 186 |
|
| 187 |
case EX_INQ_DB_VERS: |
| 188 |
/* returns the EXODUS database version number */ |
| 189 |
if (!ret_float) { |
| 190 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 191 |
"Warning: float argument is NULL for EX_INQ_DB_VERS " |
| 192 |
"which is not allowed."); |
| 193 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 194 |
return EX_FATAL; |
| 195 |
} |
| 196 |
|
| 197 |
if ((status = nc_get_att_float(rootid, NC_GLOBAL, ATT_VERSION, ret_float)) != NC_NOERR) { |
| 198 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 199 |
"ERROR: failed to get EXODUS database version for file id %d", rootid); |
| 200 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 201 |
return EX_FATAL; |
| 202 |
} |
| 203 |
break; |
| 204 |
|
| 205 |
case EX_INQ_LIB_VERS: |
| 206 |
/* returns the EXODUS Library version number */ |
| 207 |
if (ret_float) { |
| 208 |
float version_major = EXODUS_VERSION_MAJOR; |
| 209 |
float version_minor = EXODUS_VERSION_MINOR; |
| 210 |
float version = version_major + version_minor / 100.0; |
| 211 |
flt_cvt(ret_float, version); |
| 212 |
} |
| 213 |
|
| 214 |
*ret_int = EX_API_VERS_NODOT; |
| 215 |
break; |
| 216 |
|
| 217 |
case EX_INQ_DB_MAX_ALLOWED_NAME_LENGTH: |
| 218 |
/* Return the MAX_NAME_LENGTH size for this database |
| 219 |
It will not include the space for the trailing null, so if it |
| 220 |
is defined as 33 on the database, 32 will be returned. |
| 221 |
*/ |
| 222 |
if (nc_inq_dimid(rootid, DIM_STR_NAME, &dimid) != NC_NOERR) { |
| 223 |
/* If not found, then an older database */ |
| 224 |
*ret_int = 32; |
| 225 |
} |
| 226 |
else { |
| 227 |
/* Get the name string length */ |
| 228 |
size_t name_length = 0; |
| 229 |
if ((status = nc_inq_dimlen(rootid, dimid, &name_length)) != NC_NOERR) { |
| 230 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get name string length in file id %d", |
| 231 |
exoid); |
| 232 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 233 |
return EX_FATAL; |
| 234 |
} |
| 235 |
|
| 236 |
*ret_int = name_length - 1; |
| 237 |
} |
| 238 |
break; |
| 239 |
|
| 240 |
case EX_INQ_DB_FLOAT_SIZE: { |
| 241 |
nc_get_att_longlong(rootid, NC_GLOBAL, ATT_FLT_WORDSIZE, (long long *)ret_int); |
| 242 |
} break; |
| 243 |
|
| 244 |
case EX_INQ_DB_MAX_USED_NAME_LENGTH: |
| 245 |
/* Return the value of the ATT_MAX_NAME_LENGTH attribute (if it |
| 246 |
exists) which is the maximum length of any entity, variable, |
| 247 |
attribute, property name written to this database. If the |
| 248 |
attribute does not exist, then '32' is returned. The length |
| 249 |
does not include the trailing null. |
| 250 |
*/ |
| 251 |
{ |
| 252 |
nc_type att_type = NC_NAT; |
| 253 |
size_t att_len = 0; |
| 254 |
|
| 255 |
*ret_int = 32; /* Default size consistent with older databases */ |
| 256 |
|
| 257 |
status = nc_inq_att(rootid, NC_GLOBAL, ATT_MAX_NAME_LENGTH, &att_type, &att_len); |
| 258 |
if (status == NC_NOERR && att_type == NC_INT) { |
| 259 |
/* The attribute exists, return it... */ |
| 260 |
nc_get_att_longlong(rootid, NC_GLOBAL, ATT_MAX_NAME_LENGTH, (long long *)ret_int); |
| 261 |
} |
| 262 |
} |
| 263 |
break; |
| 264 |
|
| 265 |
case EX_INQ_MAX_READ_NAME_LENGTH: { |
| 266 |
/* Returns the user-specified maximum size of names that will be |
| 267 |
* returned to the user by any of the ex_get_ routines. If the |
| 268 |
* name is longer than this value, it will be truncated. The |
| 269 |
* default if not set by the client is 32 characters. The value |
| 270 |
* does not include the trailing null. |
| 271 |
*/ |
| 272 |
struct exi_file_item *file = exi_find_file_item(rootid); |
| 273 |
|
| 274 |
if (!file) { |
| 275 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unknown file id %d for ex_inquire_int().", rootid); |
| 276 |
ex_err_fn(exoid, __func__, errmsg, EX_BADFILEID); |
| 277 |
*ret_int = 0; |
| 278 |
} |
| 279 |
else { |
| 280 |
*ret_int = file->maximum_name_length; |
| 281 |
} |
| 282 |
} break; |
| 283 |
|
| 284 |
case EX_INQ_TITLE: |
| 285 |
if (!ret_char) { |
| 286 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 287 |
"ERROR: Requested title, but character pointer was null " |
| 288 |
"for file id %d", |
| 289 |
rootid); |
| 290 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 291 |
return EX_FATAL; |
| 292 |
} |
| 293 |
else { |
| 294 |
/* returns the title of the database */ |
| 295 |
/* Title is stored at root level... */ |
| 296 |
char tmp_title[2048]; |
| 297 |
if ((status = nc_get_att_text(rootid, NC_GLOBAL, ATT_TITLE, tmp_title)) != NC_NOERR) { |
| 298 |
*ret_char = '\0'; |
| 299 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get database title for file id %d", |
| 300 |
exoid); |
| 301 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 302 |
return EX_FATAL; |
| 303 |
} |
| 304 |
ex_copy_string(ret_char, tmp_title, MAX_LINE_LENGTH + 1); |
| 305 |
} |
| 306 |
break; |
| 307 |
|
| 308 |
case EX_INQ_DIM: |
| 309 |
/* returns the dimensionality (2 or 3, for 2-d or 3-d) of the database */ |
| 310 |
if (exi_get_dimension(exoid, DIM_NUM_DIM, "database dimensionality", &ldum, &dimid, __func__) != |
| 311 |
NC_NOERR) { |
| 312 |
return EX_FATAL; |
| 313 |
} |
| 314 |
*ret_int = ldum; |
| 315 |
break; |
| 316 |
|
| 317 |
case EX_INQ_ASSEMBLY: |
| 318 |
/* returns the number of assemblies */ |
| 319 |
{ |
| 320 |
*ret_int = 0; |
| 321 |
struct exi_file_item *file = exi_find_file_item(exoid); |
| 322 |
if (file) { |
| 323 |
*ret_int = file->assembly_count; |
| 324 |
} |
| 325 |
} |
| 326 |
break; |
| 327 |
|
| 328 |
case EX_INQ_BLOB: |
| 329 |
/* returns the number of blobs */ |
| 330 |
{ |
| 331 |
*ret_int = 0; |
| 332 |
struct exi_file_item *file = exi_find_file_item(exoid); |
| 333 |
if (file) { |
| 334 |
*ret_int = file->blob_count; |
| 335 |
} |
| 336 |
} |
| 337 |
break; |
| 338 |
|
| 339 |
case EX_INQ_NODES: |
| 340 |
/* returns the number of nodes */ |
| 341 |
if (exi_get_dimension(exoid, DIM_NUM_NODES, "nodes", &ldum, &dimid, NULL) != NC_NOERR) { |
| 342 |
*ret_int = 0; |
| 343 |
} |
| 344 |
else { |
| 345 |
*ret_int = ldum; |
| 346 |
} |
| 347 |
break; |
| 348 |
|
| 349 |
case EX_INQ_ELEM: |
| 350 |
/* returns the number of elements */ |
| 351 |
if (exi_get_dimension(exoid, DIM_NUM_ELEM, "elements", &ldum, &dimid, NULL) != NC_NOERR) { |
| 352 |
*ret_int = 0; |
| 353 |
} |
| 354 |
else { |
| 355 |
*ret_int = ldum; |
| 356 |
} |
| 357 |
break; |
| 358 |
|
| 359 |
case EX_INQ_ELEM_BLK: |
| 360 |
/* returns the number of element blocks */ |
| 361 |
if (exi_get_dimension(exoid, DIM_NUM_EL_BLK, "element blocks", &ldum, &dimid, NULL) != |
| 362 |
NC_NOERR) { |
| 363 |
*ret_int = 0; |
| 364 |
} |
| 365 |
else { |
| 366 |
*ret_int = ldum; |
| 367 |
} |
| 368 |
break; |
| 369 |
|
| 370 |
case EX_INQ_NODE_SETS: |
| 371 |
/* returns the number of node sets */ |
| 372 |
if (exi_get_dimension(exoid, DIM_NUM_NS, "node sets", &ldum, &dimid, NULL) != NC_NOERR) { |
| 373 |
*ret_int = 0; |
| 374 |
} |
| 375 |
else { |
| 376 |
*ret_int = ldum; |
| 377 |
} |
| 378 |
break; |
| 379 |
|
| 380 |
case EX_INQ_NS_NODE_LEN: |
| 381 |
/* returns the length of the concatenated node sets node list */ |
| 382 |
ex_get_concat_set_len(exoid, ret_int, "node", DIM_NUM_NS, VAR_NS_STAT, "num_nod_ns", 0); |
| 383 |
break; |
| 384 |
|
| 385 |
case EX_INQ_NS_DF_LEN: |
| 386 |
/* returns the length of the concatenated node sets dist factor list */ |
| 387 |
|
| 388 |
/* |
| 389 |
Determine the concatenated node sets distribution factor length: |
| 390 |
|
| 391 |
2. Check see if the dist factor variable for a node set id exists. |
| 392 |
3. If it exists, goto step 4, else the length is zero. |
| 393 |
4. Get the dimension of the number of nodes in the node set -0 |
| 394 |
use this value as the length as by definition they are the same. |
| 395 |
5. Sum the individual lengths for the total list length. |
| 396 |
*/ |
| 397 |
|
| 398 |
*ret_int = 0; /* default value if no node sets defined */ |
| 399 |
|
| 400 |
if (nc_inq_dimid(exoid, DIM_NUM_NS, &dimid) == NC_NOERR) { |
| 401 |
if ((status = nc_inq_dimlen(exoid, dimid, &num_sets)) != NC_NOERR) { |
| 402 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of node sets in file id %d", |
| 403 |
exoid); |
| 404 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 405 |
return EX_FATAL; |
| 406 |
} |
| 407 |
|
| 408 |
for (size_t i = 0; i < num_sets; i++) { |
| 409 |
if ((status = nc_inq_varid(exoid, VAR_FACT_NS(i + 1), &varid)) != NC_NOERR) { |
| 410 |
if (status == NC_ENOTVAR) { |
| 411 |
idum = 0; /* this dist factor doesn't exist */ |
| 412 |
} |
| 413 |
else { |
| 414 |
*ret_int = 0; |
| 415 |
snprintf( |
| 416 |
errmsg, MAX_ERR_LENGTH, |
| 417 |
"ERROR: failed to locate number of dist fact for %zu'th node set in file id %d", i, |
| 418 |
exoid); |
| 419 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 420 |
return EX_FATAL; |
| 421 |
} |
| 422 |
} |
| 423 |
else { |
| 424 |
if ((status = nc_inq_dimid(exoid, DIM_NUM_NOD_NS(i + 1), &dimid)) != NC_NOERR) { |
| 425 |
*ret_int = 0; |
| 426 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 427 |
"ERROR: failed to locate number of nodes in %zu'th node set in file id %d", i, |
| 428 |
exoid); |
| 429 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 430 |
return EX_FATAL; |
| 431 |
} |
| 432 |
if ((status = nc_inq_dimlen(exoid, dimid, &idum)) != NC_NOERR) { |
| 433 |
*ret_int = 0; |
| 434 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 435 |
"ERROR: failed to get number of nodes in %zu'th node set in file id %d", i, |
| 436 |
exoid); |
| 437 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 438 |
return EX_FATAL; |
| 439 |
} |
| 440 |
} |
| 441 |
*ret_int += idum; |
| 442 |
} |
| 443 |
} |
| 444 |
|
| 445 |
break; |
| 446 |
|
| 447 |
case EX_INQ_SIDE_SETS: |
| 448 |
/* returns the number of side sets */ |
| 449 |
if (exi_get_dimension(exoid, DIM_NUM_SS, "side sets", &ldum, &dimid, NULL) != NC_NOERR) { |
| 450 |
*ret_int = 0; |
| 451 |
} |
| 452 |
else { |
| 453 |
*ret_int = ldum; |
| 454 |
} |
| 455 |
break; |
| 456 |
|
| 457 |
case EX_INQ_SS_NODE_LEN: |
| 458 |
|
| 459 |
/* returns the length of the concatenated side sets node list */ |
| 460 |
|
| 461 |
*ret_int = 0; /* default return value */ |
| 462 |
|
| 463 |
if (nc_inq_dimid(exoid, DIM_NUM_SS, &dimid) == NC_NOERR) { |
| 464 |
if ((status = nc_inq_dimlen(exoid, dimid, &num_sets)) != NC_NOERR) { |
| 465 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of side sets in file id %d", |
| 466 |
exoid); |
| 467 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 468 |
return EX_FATAL; |
| 469 |
} |
| 470 |
|
| 471 |
int *ids = NULL; |
| 472 |
if (!(ids = malloc(num_sets * sizeof(int64_t)))) { /* May be getting 2x what is |
| 473 |
needed, but should be OK */ |
| 474 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 475 |
"ERROR: failed to allocate memory for side set ids for file id %d", exoid); |
| 476 |
ex_err_fn(exoid, __func__, errmsg, EX_MEMFAIL); |
| 477 |
return EX_FATAL; |
| 478 |
} |
| 479 |
|
| 480 |
if (ex_get_ids(exoid, EX_SIDE_SET, ids) == EX_FATAL) { |
| 481 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get side set ids in file id %d", exoid); |
| 482 |
ex_err_fn(exoid, __func__, errmsg, EX_LASTERR); |
| 483 |
free(ids); |
| 484 |
return EX_FATAL; |
| 485 |
} |
| 486 |
|
| 487 |
/* allocate space for stat array */ |
| 488 |
if (!(stat_vals = malloc((int)num_sets * sizeof(int)))) { |
| 489 |
free(ids); |
| 490 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 491 |
"ERROR: failed to allocate memory for side set status " |
| 492 |
"array for file id %d", |
| 493 |
exoid); |
| 494 |
ex_err_fn(exoid, __func__, errmsg, EX_MEMFAIL); |
| 495 |
return EX_FATAL; |
| 496 |
} |
| 497 |
/* get variable id of status array */ |
| 498 |
if (nc_inq_varid(exoid, VAR_SS_STAT, &varid) == NC_NOERR) { |
| 499 |
/* if status array exists, use it, otherwise assume, object exists |
| 500 |
to be backward compatible */ |
| 501 |
|
| 502 |
if ((status = nc_get_var_int(exoid, varid, stat_vals)) != NC_NOERR) { |
| 503 |
free(ids); |
| 504 |
free(stat_vals); |
| 505 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 506 |
"ERROR: failed to get element block status array from file id %d", exoid); |
| 507 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 508 |
return EX_FATAL; |
| 509 |
} |
| 510 |
} |
| 511 |
else { /* default: status is true */ |
| 512 |
for (size_t i = 0; i < num_sets; i++) { |
| 513 |
stat_vals[i] = 1; |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
/* walk id list, get each side set node length and sum for total */ |
| 518 |
|
| 519 |
for (size_t i = 0; i < num_sets; i++) { |
| 520 |
ex_entity_id id; |
| 521 |
if (stat_vals[i] == 0) { /* is this object null? */ |
| 522 |
continue; |
| 523 |
} |
| 524 |
|
| 525 |
if (ex_int64_status(exoid) & EX_IDS_INT64_API) { |
| 526 |
int64_t tmp_len = 0; |
| 527 |
id = ((int64_t *)ids)[i]; |
| 528 |
status = ex_get_side_set_node_list_len(exoid, id, &tmp_len); |
| 529 |
if (status != EX_FATAL) { |
| 530 |
*ret_int += tmp_len; |
| 531 |
} |
| 532 |
} |
| 533 |
else { |
| 534 |
int tmp_len = 0; |
| 535 |
id = ((int *)ids)[i]; |
| 536 |
status = ex_get_side_set_node_list_len(exoid, id, &tmp_len); |
| 537 |
if (status != EX_FATAL) { |
| 538 |
*ret_int += tmp_len; |
| 539 |
} |
| 540 |
} |
| 541 |
|
| 542 |
if (status == EX_FATAL) { |
| 543 |
*ret_int = 0; |
| 544 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 545 |
"ERROR: failed to side set %" PRId64 " node length in file id %d", id, exoid); |
| 546 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 547 |
free(stat_vals); |
| 548 |
free(ids); |
| 549 |
return EX_FATAL; |
| 550 |
} |
| 551 |
} |
| 552 |
|
| 553 |
free(stat_vals); |
| 554 |
free(ids); |
| 555 |
} |
| 556 |
|
| 557 |
break; |
| 558 |
|
| 559 |
case EX_INQ_SS_ELEM_LEN: |
| 560 |
/* returns the length of the concatenated side sets element list */ |
| 561 |
ex_get_concat_set_len(exoid, ret_int, "side", DIM_NUM_SS, VAR_SS_STAT, "num_side_ss", 0); |
| 562 |
break; |
| 563 |
|
| 564 |
case EX_INQ_SS_DF_LEN: |
| 565 |
|
| 566 |
/* returns the length of the concatenated side sets dist factor list */ |
| 567 |
|
| 568 |
/* |
| 569 |
Determine the concatenated side sets distribution factor length: |
| 570 |
|
| 571 |
1. Get the side set ids list. |
| 572 |
2. Check see if the dist factor dimension for a side set id exists. |
| 573 |
3. If it exists, goto step 4, else set the individual length to zero. |
| 574 |
4. Sum the dimension value into the running total length. |
| 575 |
*/ |
| 576 |
|
| 577 |
*ret_int = 0; |
| 578 |
|
| 579 |
/* first check see if any side sets exist */ |
| 580 |
|
| 581 |
if (nc_inq_dimid(exoid, DIM_NUM_SS, &dimid) == NC_NOERR) { |
| 582 |
if ((status = nc_inq_dimlen(exoid, dimid, &num_sets)) != NC_NOERR) { |
| 583 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of side sets in file id %d", |
| 584 |
exoid); |
| 585 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 586 |
return EX_FATAL; |
| 587 |
} |
| 588 |
|
| 589 |
for (size_t i = 0; i < num_sets; i++) { |
| 590 |
if ((status = nc_inq_dimid(exoid, DIM_NUM_DF_SS(i + 1), &dimid)) != NC_NOERR) { |
| 591 |
if (status == NC_EBADDIM) { |
| 592 |
ldum = 0; /* this dist factor doesn't exist */ |
| 593 |
} |
| 594 |
else { |
| 595 |
*ret_int = 0; |
| 596 |
snprintf( |
| 597 |
errmsg, MAX_ERR_LENGTH, |
| 598 |
"ERROR: failed to locate number of dist fact for %zu'th side set in file id %d", i, |
| 599 |
exoid); |
| 600 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 601 |
return EX_FATAL; |
| 602 |
} |
| 603 |
} |
| 604 |
else { |
| 605 |
if ((status = nc_inq_dimlen(exoid, dimid, &ldum)) != NC_NOERR) { |
| 606 |
*ret_int = 0; |
| 607 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 608 |
"ERROR: failed to get number of dist factors in %zu'th side set in file id %d", |
| 609 |
i, exoid); |
| 610 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 611 |
return EX_FATAL; |
| 612 |
} |
| 613 |
} |
| 614 |
*ret_int += ldum; |
| 615 |
} |
| 616 |
} |
| 617 |
|
| 618 |
break; |
| 619 |
|
| 620 |
case EX_INQ_QA: |
| 621 |
/* returns the number of QA records */ |
| 622 |
if (exi_get_dimension(rootid, DIM_NUM_QA, "QA records", &ldum, &dimid, NULL) != NC_NOERR) { |
| 623 |
*ret_int = 0; |
| 624 |
} |
| 625 |
else { |
| 626 |
*ret_int = ldum; |
| 627 |
} |
| 628 |
break; |
| 629 |
|
| 630 |
case EX_INQ_INFO: |
| 631 |
/* returns the number of information records */ |
| 632 |
if (exi_get_dimension(rootid, DIM_NUM_INFO, "info records", &ldum, &dimid, NULL) != NC_NOERR) { |
| 633 |
*ret_int = 0; |
| 634 |
} |
| 635 |
else { |
| 636 |
*ret_int = ldum; |
| 637 |
} |
| 638 |
break; |
| 639 |
|
| 640 |
case EX_INQ_TIME: |
| 641 |
/* returns the number of time steps stored in the database */ |
| 642 |
if (exi_get_dimension(exoid, DIM_TIME, "time dimension", &ldum, &dimid, __func__) != NC_NOERR) { |
| 643 |
return EX_FATAL; |
| 644 |
} |
| 645 |
*ret_int = ldum; |
| 646 |
break; |
| 647 |
|
| 648 |
case EX_INQ_EB_PROP: |
| 649 |
/* returns the number of element block properties */ |
| 650 |
*ret_int = ex_get_num_props(exoid, EX_ELEM_BLOCK); |
| 651 |
break; |
| 652 |
|
| 653 |
case EX_INQ_NS_PROP: |
| 654 |
/* returns the number of node set properties */ |
| 655 |
*ret_int = ex_get_num_props(exoid, EX_NODE_SET); |
| 656 |
break; |
| 657 |
|
| 658 |
case EX_INQ_SS_PROP: |
| 659 |
/* returns the number of side set properties */ |
| 660 |
*ret_int = ex_get_num_props(exoid, EX_SIDE_SET); |
| 661 |
break; |
| 662 |
|
| 663 |
case EX_INQ_ELEM_MAP: |
| 664 |
/* returns the number of element maps */ |
| 665 |
if (exi_get_dimension(exoid, DIM_NUM_EM, "element maps", &ldum, &dimid, NULL) != NC_NOERR) { |
| 666 |
*ret_int = 0; |
| 667 |
} |
| 668 |
else { |
| 669 |
*ret_int = ldum; |
| 670 |
} |
| 671 |
break; |
| 672 |
|
| 673 |
case EX_INQ_EM_PROP: |
| 674 |
/* returns the number of element map properties */ |
| 675 |
*ret_int = ex_get_num_props(exoid, EX_ELEM_MAP); |
| 676 |
break; |
| 677 |
|
| 678 |
case EX_INQ_NODE_MAP: |
| 679 |
/* returns the number of node maps */ |
| 680 |
if (exi_get_dimension(exoid, DIM_NUM_NM, "node maps", &ldum, &dimid, NULL) != NC_NOERR) { |
| 681 |
*ret_int = 0; |
| 682 |
} |
| 683 |
else { |
| 684 |
*ret_int = ldum; |
| 685 |
} |
| 686 |
break; |
| 687 |
|
| 688 |
case EX_INQ_NM_PROP: |
| 689 |
/* returns the number of node map properties */ |
| 690 |
*ret_int = ex_get_num_props(exoid, EX_NODE_MAP); |
| 691 |
break; |
| 692 |
|
| 693 |
case EX_INQ_EDGE: |
| 694 |
/* returns the number of edges (defined across all edge blocks). */ |
| 695 |
if (exi_get_dimension_value(exoid, ret_int, 0, DIM_NUM_EDGE, 1) != EX_NOERR) { |
| 696 |
return EX_FATAL; |
| 697 |
} |
| 698 |
break; |
| 699 |
|
| 700 |
case EX_INQ_EDGE_BLK: |
| 701 |
/* returns the number of edge blocks. */ |
| 702 |
if (exi_get_dimension_value(exoid, ret_int, 0, DIM_NUM_ED_BLK, 1) != EX_NOERR) { |
| 703 |
return EX_FATAL; |
| 704 |
} |
| 705 |
break; |
| 706 |
|
| 707 |
case EX_INQ_EDGE_SETS: |
| 708 |
/* returns the number of edge sets. */ |
| 709 |
if (exi_get_dimension_value(exoid, ret_int, 0, DIM_NUM_ES, 1) != EX_NOERR) { |
| 710 |
return EX_FATAL; |
| 711 |
} |
| 712 |
break; |
| 713 |
|
| 714 |
case EX_INQ_ES_LEN: |
| 715 |
/* returns the length of the concatenated edge set edge list. */ |
| 716 |
ex_get_concat_set_len(exoid, ret_int, "edge", DIM_NUM_ES, VAR_ES_STAT, "num_edge_es", 0); |
| 717 |
break; |
| 718 |
|
| 719 |
case EX_INQ_ES_DF_LEN: |
| 720 |
/* returns the length of the concatenated edge set distribution factor list. |
| 721 |
*/ |
| 722 |
ex_get_concat_set_len(exoid, ret_int, "edge", DIM_NUM_ES, VAR_ES_STAT, "num_df_es", 1); |
| 723 |
break; |
| 724 |
|
| 725 |
case EX_INQ_EDGE_PROP: |
| 726 |
/* returns the number of integer properties stored for each edge block. This |
| 727 |
* includes the "ID" property. */ |
| 728 |
*ret_int = ex_get_num_props(exoid, EX_EDGE_BLOCK); |
| 729 |
break; |
| 730 |
|
| 731 |
case EX_INQ_ES_PROP: |
| 732 |
/* returns the number of integer properties stored for each edge set.. This |
| 733 |
* includes the "ID" property */ |
| 734 |
*ret_int = ex_get_num_props(exoid, EX_EDGE_SET); |
| 735 |
break; |
| 736 |
|
| 737 |
case EX_INQ_FACE: |
| 738 |
/* returns the number of faces (defined across all face blocks). */ |
| 739 |
if (exi_get_dimension_value(exoid, ret_int, 0, DIM_NUM_FACE, 1) != EX_NOERR) { |
| 740 |
return EX_FATAL; |
| 741 |
} |
| 742 |
break; |
| 743 |
|
| 744 |
case EX_INQ_FACE_BLK: |
| 745 |
/* returns the number of face blocks. */ |
| 746 |
if (exi_get_dimension_value(exoid, ret_int, 0, DIM_NUM_FA_BLK, 1) != EX_NOERR) { |
| 747 |
return EX_FATAL; |
| 748 |
} |
| 749 |
break; |
| 750 |
|
| 751 |
case EX_INQ_FACE_SETS: |
| 752 |
/* returns the number of face sets. */ |
| 753 |
if (exi_get_dimension_value(exoid, ret_int, 0, DIM_NUM_FS, 1) != EX_NOERR) { |
| 754 |
return EX_FATAL; |
| 755 |
} |
| 756 |
break; |
| 757 |
|
| 758 |
case EX_INQ_FS_LEN: |
| 759 |
/* returns the length of the concatenated edge set edge list. */ |
| 760 |
ex_get_concat_set_len(exoid, ret_int, "face", DIM_NUM_FS, VAR_FS_STAT, "num_face_fs", 0); |
| 761 |
break; |
| 762 |
|
| 763 |
case EX_INQ_FS_DF_LEN: |
| 764 |
/* returns the length of the concatenated edge set distribution factor list. |
| 765 |
*/ |
| 766 |
ex_get_concat_set_len(exoid, ret_int, "face", DIM_NUM_FS, VAR_FS_STAT, "num_df_fs", 1); |
| 767 |
break; |
| 768 |
|
| 769 |
case EX_INQ_FACE_PROP: |
| 770 |
/* returns the number of integer properties stored for each edge block. This |
| 771 |
* includes the "ID" property. */ |
| 772 |
*ret_int = ex_get_num_props(exoid, EX_FACE_BLOCK); |
| 773 |
break; |
| 774 |
|
| 775 |
case EX_INQ_FS_PROP: |
| 776 |
/* returns the number of integer properties stored for each edge set.. This |
| 777 |
* includes the "ID" property */ |
| 778 |
*ret_int = ex_get_num_props(exoid, EX_FACE_SET); |
| 779 |
break; |
| 780 |
|
| 781 |
case EX_INQ_ELEM_SETS: |
| 782 |
/* returns the number of element sets. */ |
| 783 |
if (exi_get_dimension_value(exoid, ret_int, 0, DIM_NUM_ELS, 1) != EX_NOERR) { |
| 784 |
return EX_FATAL; |
| 785 |
} |
| 786 |
break; |
| 787 |
|
| 788 |
case EX_INQ_ELS_LEN: |
| 789 |
/* returns the length of the concatenated element set element list. */ |
| 790 |
ex_get_concat_set_len(exoid, ret_int, "element", DIM_NUM_ELS, VAR_ELS_STAT, "num_ele_els", 0); |
| 791 |
break; |
| 792 |
|
| 793 |
case EX_INQ_ELS_DF_LEN: |
| 794 |
/* returns the length of the concatenated element set distribution factor |
| 795 |
* list. */ |
| 796 |
ex_get_concat_set_len(exoid, ret_int, "element", DIM_NUM_ELS, VAR_ELS_STAT, "num_df_els", 1); |
| 797 |
break; |
| 798 |
|
| 799 |
case EX_INQ_ELS_PROP: |
| 800 |
/* returns the number of integer properties stored for each element set. */ |
| 801 |
*ret_int = ex_get_num_props(exoid, EX_ELEM_SET); |
| 802 |
break; |
| 803 |
|
| 804 |
case EX_INQ_EDGE_MAP: |
| 805 |
/* returns the number of edge maps. */ |
| 806 |
if (exi_get_dimension_value(exoid, ret_int, 0, DIM_NUM_EDM, 1) != EX_NOERR) { |
| 807 |
return EX_FATAL; |
| 808 |
} |
| 809 |
break; |
| 810 |
|
| 811 |
case EX_INQ_FACE_MAP: |
| 812 |
/* returns the number of face maps. */ |
| 813 |
if (exi_get_dimension_value(exoid, ret_int, 0, DIM_NUM_FAM, 1) != EX_NOERR) { |
| 814 |
return EX_FATAL; |
| 815 |
} |
| 816 |
break; |
| 817 |
|
| 818 |
case EX_INQ_NUM_NODE_VAR: |
| 819 |
if (ex_get_variable_param(exoid, EX_NODAL, &num_var) != EX_NOERR) { |
| 820 |
return EX_FATAL; |
| 821 |
} |
| 822 |
*ret_int = num_var; |
| 823 |
break; |
| 824 |
|
| 825 |
case EX_INQ_NUM_EDGE_BLOCK_VAR: |
| 826 |
if (ex_get_variable_param(exoid, EX_EDGE_BLOCK, &num_var) != EX_NOERR) { |
| 827 |
return EX_FATAL; |
| 828 |
} |
| 829 |
*ret_int = num_var; |
| 830 |
break; |
| 831 |
|
| 832 |
case EX_INQ_NUM_FACE_BLOCK_VAR: |
| 833 |
if (ex_get_variable_param(exoid, EX_FACE_BLOCK, &num_var) != EX_NOERR) { |
| 834 |
return EX_FATAL; |
| 835 |
} |
| 836 |
*ret_int = num_var; |
| 837 |
break; |
| 838 |
|
| 839 |
case EX_INQ_NUM_ELEM_BLOCK_VAR: |
| 840 |
if (ex_get_variable_param(exoid, EX_ELEM_BLOCK, &num_var) != EX_NOERR) { |
| 841 |
return EX_FATAL; |
| 842 |
} |
| 843 |
*ret_int = num_var; |
| 844 |
break; |
| 845 |
|
| 846 |
case EX_INQ_NUM_NODE_SET_VAR: |
| 847 |
if (ex_get_variable_param(exoid, EX_NODE_SET, &num_var) != EX_NOERR) { |
| 848 |
return EX_FATAL; |
| 849 |
} |
| 850 |
*ret_int = num_var; |
| 851 |
break; |
| 852 |
|
| 853 |
case EX_INQ_NUM_EDGE_SET_VAR: |
| 854 |
if (ex_get_variable_param(exoid, EX_EDGE_SET, &num_var) != EX_NOERR) { |
| 855 |
return EX_FATAL; |
| 856 |
} |
| 857 |
*ret_int = num_var; |
| 858 |
break; |
| 859 |
|
| 860 |
case EX_INQ_NUM_FACE_SET_VAR: |
| 861 |
if (ex_get_variable_param(exoid, EX_FACE_SET, &num_var) != EX_NOERR) { |
| 862 |
return EX_FATAL; |
| 863 |
} |
| 864 |
*ret_int = num_var; |
| 865 |
break; |
| 866 |
|
| 867 |
case EX_INQ_NUM_ELEM_SET_VAR: |
| 868 |
if (ex_get_variable_param(exoid, EX_ELEM_SET, &num_var) != EX_NOERR) { |
| 869 |
return EX_FATAL; |
| 870 |
} |
| 871 |
*ret_int = num_var; |
| 872 |
break; |
| 873 |
|
| 874 |
case EX_INQ_NUM_SIDE_SET_VAR: |
| 875 |
if (ex_get_variable_param(exoid, EX_SIDE_SET, &num_var) != EX_NOERR) { |
| 876 |
return EX_FATAL; |
| 877 |
} |
| 878 |
*ret_int = num_var; |
| 879 |
break; |
| 880 |
|
| 881 |
case EX_INQ_NUM_GLOBAL_VAR: |
| 882 |
if (ex_get_variable_param(exoid, EX_GLOBAL, &num_var) != EX_NOERR) { |
| 883 |
return EX_FATAL; |
| 884 |
} |
| 885 |
*ret_int = num_var; |
| 886 |
break; |
| 887 |
|
| 888 |
case EX_INQ_COORD_FRAMES: |
| 889 |
/* return the number of coordinate frames */ |
| 890 |
if (exi_get_dimension_value(exoid, ret_int, 0, DIM_NUM_CFRAMES, 1) != EX_NOERR) { |
| 891 |
return EX_FATAL; |
| 892 |
} |
| 893 |
break; |
| 894 |
|
| 895 |
case EX_INQ_NUM_CHILD_GROUPS: { |
| 896 |
/* return number of groups contained in this (exoid) group */ |
| 897 |
int tmp_num = 0; |
| 898 |
#if NC_HAS_HDF5 |
| 899 |
nc_inq_grps(exoid, &tmp_num, NULL); |
| 900 |
#endif |
| 901 |
*ret_int = tmp_num; |
| 902 |
} break; |
| 903 |
|
| 904 |
case EX_INQ_GROUP_PARENT: { |
| 905 |
/* return id of parent of this (exoid) group; returns exoid if at root */ |
| 906 |
#if NC_HAS_HDF5 |
| 907 |
int tmp_num = exoid; |
| 908 |
nc_inq_grp_parent(exoid, &tmp_num); |
| 909 |
*ret_int = tmp_num; |
| 910 |
#else |
| 911 |
*ret_int = exoid; |
| 912 |
#endif |
| 913 |
} break; |
| 914 |
|
| 915 |
case EX_INQ_GROUP_ROOT: |
| 916 |
/* return id of root group "/" of this (exoid) group; returns exoid if at |
| 917 |
* root */ |
| 918 |
*ret_int = (unsigned)exoid & EX_FILE_ID_MASK; |
| 919 |
break; |
| 920 |
|
| 921 |
case EX_INQ_GROUP_NAME_LEN: { |
| 922 |
size_t len_name = 0; |
| 923 |
#if NC_HAS_HDF5 |
| 924 |
/* return name length of group exoid */ |
| 925 |
nc_inq_grpname_len(exoid, &len_name); |
| 926 |
#endif |
| 927 |
*ret_int = (int)len_name; |
| 928 |
} break; |
| 929 |
|
| 930 |
case EX_INQ_GROUP_NAME: |
| 931 |
/* return name of group exoid. "/" returned for root group */ |
| 932 |
/* Assumes that ret_char is large enough to hold name. */ |
| 933 |
if (!ret_char) { |
| 934 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 935 |
"ERROR: Requested group name, but character pointer was " |
| 936 |
"null for file id %d", |
| 937 |
exoid); |
| 938 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 939 |
return EX_FATAL; |
| 940 |
} |
| 941 |
#if NC_HAS_HDF5 |
| 942 |
nc_inq_grpname(exoid, ret_char); |
| 943 |
#endif |
| 944 |
break; |
| 945 |
|
| 946 |
case EX_INQ_FULL_GROUP_NAME_LEN: { |
| 947 |
size_t len_name = 0; |
| 948 |
#if NC_HAS_HDF5 |
| 949 |
/* return length of full group name which is the "/" separated path from |
| 950 |
* root |
| 951 |
* For example "/group1/subgroup1/subsubgroup1" |
| 952 |
* length does not include the NULL terminator byte. |
| 953 |
*/ |
| 954 |
nc_inq_grpname_full(exoid, &len_name, NULL); |
| 955 |
#endif |
| 956 |
*ret_int = (int)len_name; |
| 957 |
} break; |
| 958 |
|
| 959 |
case EX_INQ_FULL_GROUP_NAME: |
| 960 |
/* return full path name of group exoid which is the "/" separated path from |
| 961 |
* root |
| 962 |
* For example "/group1/subgroup1/subsubgroup1" |
| 963 |
* Assumes that ret_char is large enough to hold full path name. |
| 964 |
*/ |
| 965 |
if (!ret_char) { |
| 966 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 967 |
"ERROR: Requested group name, but character pointer was " |
| 968 |
"null for file id %d", |
| 969 |
exoid); |
| 970 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 971 |
return EX_FATAL; |
| 972 |
} |
| 973 |
#if NC_HAS_HDF5 |
| 974 |
nc_inq_grpname_full(exoid, NULL, ret_char); |
| 975 |
#endif |
| 976 |
break; |
| 977 |
|
| 978 |
case EX_INQ_FILE_FORMAT: { |
| 979 |
/* return netCDF file format. |
| 980 |
*/ |
| 981 |
int nc_format = 0; |
| 982 |
nc_inq_format(exoid, &nc_format); |
| 983 |
*ret_int = nc_format; |
| 984 |
} break; |
| 985 |
|
| 986 |
case EX_INQ_THREADSAFE: |
| 987 |
/* Return 1 if the library was compiled in thread-safe mode. |
| 988 |
* Return 0 otherwise |
| 989 |
*/ |
| 990 |
#if defined(EXODUS_THREADSAFE) |
| 991 |
*ret_int = 1; |
| 992 |
#else |
| 993 |
*ret_int = 0; |
| 994 |
#endif |
| 995 |
break; |
| 996 |
|
| 997 |
default: |
| 998 |
*ret_int = 0; |
| 999 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: invalid inquiry %d", req_info); |
| 1000 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 1001 |
return EX_FATAL; |
| 1002 |
} |
| 1003 |
return EX_NOERR; |
| 1004 |
} |
| 1005 |
|
| 1006 |
/*! |
| 1007 |
\ingroup Utilities |
| 1008 |
|
| 1009 |
A variant of ex_inquire() which queries integer-valued information only. \see |
| 1010 |
ex_inquire(). |
| 1011 |
\param[in] exoid exodus file ID returned from a previous call to |
| 1012 |
ex_create() or ex_open(). |
| 1013 |
\param[in] req_info A flag of type #ex_inquiry which designates what information is requested. |
| 1014 |
(See ex_inquire() documentation) |
| 1015 |
\return result of inquiry. |
| 1016 |
|
| 1017 |
As an example, the following will return the number of nodes, |
| 1018 |
elements, and element blocks stored in the exodus file : |
| 1019 |
|
| 1020 |
~~~{.c} |
| 1021 |
#include "exodusII.h" |
| 1022 |
int exoid; |
| 1023 |
int num_nodes = ex_inquire_int(exoid, EX_INQ_NODES); |
| 1024 |
int num_elems = ex_inquire_int(exoid, EX_INQ_ELEM); |
| 1025 |
int num_block = ex_inquire_int(exoid, EX_INQ_ELEM_BLK); |
| 1026 |
~~~ |
| 1027 |
|
| 1028 |
*/ |
| 1029 |
int64_t ex_inquire_int(int exoid, ex_inquiry req_info) |
| 1030 |
{ |
| 1031 |
char *cdummy = NULL; /* Needed just for function call, unused. */ |
| 1032 |
float fdummy = 0; /* Needed just for function call, unused. */ |
| 1033 |
int64_t ret_val = 0; |
| 1034 |
int error; |
| 1035 |
EX_FUNC_ENTER(); |
| 1036 |
error = ex_inquire_internal(exoid, req_info, &ret_val, &fdummy, cdummy); |
| 1037 |
if (error < 0) { |
| 1038 |
ret_val = error; |
| 1039 |
} |
| 1040 |
EX_FUNC_LEAVE(ret_val); |
| 1041 |
} |
| 1042 |
|
| 1043 |
/*! |
| 1044 |
\ingroup Utilities |
| 1045 |
|
| 1046 |
The function ex_inquire() is used to inquire values of certain |
| 1047 |
data entities in an exodus file. Memory must be allocated for the |
| 1048 |
returned values before this function is invoked.query database. |
| 1049 |
|
| 1050 |
\sa ex_inquire_int(), ex_inquiry. |
| 1051 |
|
| 1052 |
\return In case of an error, ex_inquire() returns a negative |
| 1053 |
number; a warning will return a positive number. |
| 1054 |
Possible causes of errors include: |
| 1055 |
- data file not properly opened with call to ex_create() or ex_open(). |
| 1056 |
- requested information not stored in the file. |
| 1057 |
- invalid request flag. |
| 1058 |
|
| 1059 |
\param[in] exoid exodus file ID returned from a previous call to ex_create() |
| 1060 |
or ex_open(). |
| 1061 |
\param[in] req_info A flag of type #ex_inquiry which designates what information is requested. It |
| 1062 |
must be one of the following constants in the table below. |
| 1063 |
|
| 1064 |
\param[out] ret_int Returned integer, if an integer value is requested |
| 1065 |
(according to req_info); otherwise, supply a dummy argument. |
| 1066 |
|
| 1067 |
\param[out] ret_float Returned float, if a float value is requested |
| 1068 |
(according to req_info); otherwise, supply a dummy |
| 1069 |
argument. This argument is always a float even if the |
| 1070 |
database IO and/or CPU word size is a double. |
| 1071 |
|
| 1072 |
\param[out] ret_char Returned character string, if a character value is |
| 1073 |
requested (according to req_info); |
| 1074 |
otherwise, supply a dummy argument. |
| 1075 |
|
| 1076 |
As an example, the following will return the number of element |
| 1077 |
block properties stored in the exodus file : |
| 1078 |
|
| 1079 |
~~~{.c} |
| 1080 |
#include "exodusII.h" |
| 1081 |
int error, exoid, num_props; |
| 1082 |
float fdum; |
| 1083 |
char *cdum; |
| 1084 |
|
| 1085 |
\comment{determine the number of element block properties} |
| 1086 |
error = ex_inquire (exoid, EX_INQ_EB_PROP, &num_props, |
| 1087 |
&fdum, cdum); |
| 1088 |
|
| 1089 |
\comment{...Another way to get the same information} |
| 1090 |
num_props = ex_inquire_int(exoid, EX_INQ_EB_PROP); |
| 1091 |
~~~ |
| 1092 |
|
| 1093 |
*/ |
| 1094 |
|
| 1095 |
int ex_inquire(int exoid, ex_inquiry req_info, void_int *ret_int, float *ret_float, char *ret_char) |
| 1096 |
{ |
| 1097 |
int ierr; |
| 1098 |
if (ex_int64_status(exoid) & EX_INQ_INT64_API) { |
| 1099 |
EX_FUNC_ENTER(); |
| 1100 |
ierr = ex_inquire_internal(exoid, req_info, ret_int, ret_float, ret_char); |
| 1101 |
EX_FUNC_LEAVE(ierr); |
| 1102 |
} |
| 1103 |
/* ret_int is a 32-bit int */ |
| 1104 |
int64_t tmp_int; |
| 1105 |
int *return_int = ret_int; |
| 1106 |
|
| 1107 |
EX_FUNC_ENTER(); |
| 1108 |
ierr = ex_inquire_internal(exoid, req_info, &tmp_int, ret_float, ret_char); |
| 1109 |
*return_int = (int)tmp_int; |
| 1110 |
EX_FUNC_LEAVE(ierr); |
| 1111 |
} |