| 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 |
* |
| 10 |
* expecpp - ex_put_entity_count_per_polyhedra |
| 11 |
* |
| 12 |
*****************************************************************************/ |
| 13 |
|
| 14 |
#include "exodusII.h" // for ex_err, etc |
| 15 |
#include "exodusII_int.h" // for EX_FATAL, exi_id_lkup, etc |
| 16 |
|
| 17 |
/*! |
| 18 |
* writes out the number of entities (nodes/faces) per polyhedra |
| 19 |
* (nsided/nfaced) in this element block to the database. |
| 20 |
* \param exoid exodus file id |
| 21 |
* \param blk_type type of block (face, or element) |
| 22 |
* \param blk_id block identifier |
| 23 |
* \param entity_counts entity_per_polyhedra count array |
| 24 |
*/ |
| 25 |
|
| 26 |
int ex_put_entity_count_per_polyhedra(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, |
| 27 |
const int *entity_counts) |
| 28 |
{ |
| 29 |
int npeid = -1, blk_id_ndx, status; |
| 30 |
char errmsg[MAX_ERR_LENGTH]; |
| 31 |
|
| 32 |
EX_FUNC_ENTER(); |
| 33 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 34 |
EX_FUNC_LEAVE(EX_FATAL); |
| 35 |
} |
| 36 |
|
| 37 |
blk_id_ndx = exi_id_lkup(exoid, blk_type, blk_id); |
| 38 |
if (blk_id_ndx <= 0) { |
| 39 |
ex_get_err(NULL, NULL, &status); |
| 40 |
|
| 41 |
if (status != 0) { |
| 42 |
if (status == EX_NULLENTITY) { |
| 43 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 44 |
"Warning: entity_counts array not allowed for NULL %s block %" PRId64 |
| 45 |
" in file id %d", |
| 46 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 47 |
ex_err_fn(exoid, __func__, errmsg, EX_NULLENTITY); |
| 48 |
EX_FUNC_LEAVE(EX_WARN); |
| 49 |
} |
| 50 |
|
| 51 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 52 |
"ERROR: failed to locate %s block id %" PRId64 " in id array in file id %d", |
| 53 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 54 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 55 |
EX_FUNC_LEAVE(EX_FATAL); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
/* inquire id's of previously defined dimensions */ |
| 60 |
switch (blk_type) { |
| 61 |
case EX_ELEM_BLOCK: status = nc_inq_varid(exoid, VAR_EBEPEC(blk_id_ndx), &npeid); break; |
| 62 |
case EX_FACE_BLOCK: status = nc_inq_varid(exoid, VAR_FBEPEC(blk_id_ndx), &npeid); break; |
| 63 |
default: |
| 64 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 65 |
"Internal ERROR: unrecognized block type in switch: %d in file id %d", blk_type, |
| 66 |
exoid); |
| 67 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 68 |
EX_FUNC_LEAVE(EX_FATAL); |
| 69 |
} |
| 70 |
if (status != NC_NOERR) { |
| 71 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 72 |
"ERROR: failed to locate entity_counts array for %s block %" PRId64 " in file id %d", |
| 73 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 74 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 75 |
EX_FUNC_LEAVE(EX_FATAL); |
| 76 |
} |
| 77 |
|
| 78 |
status = nc_put_var_int(exoid, npeid, entity_counts); |
| 79 |
if (status != NC_NOERR) { |
| 80 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 81 |
"ERROR: failed to write node counts array for %s block %" PRId64 " in file id %d", |
| 82 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 83 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 84 |
EX_FUNC_LEAVE(EX_FATAL); |
| 85 |
} |
| 86 |
EX_FUNC_LEAVE(EX_NOERR); |
| 87 |
} |