| 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 |
* expatt - ex_put_attr |
| 11 |
* |
| 12 |
* entry conditions - |
| 13 |
* input parameters: |
| 14 |
* int exoid exodus file id |
| 15 |
* int blk_type block type |
| 16 |
* int blk_id block id |
| 17 |
* float* attrib array of attributes |
| 18 |
* |
| 19 |
* exit conditions - |
| 20 |
* |
| 21 |
* revision history - |
| 22 |
* |
| 23 |
* |
| 24 |
*****************************************************************************/ |
| 25 |
|
| 26 |
#include "exodusII.h" // for ex_err, etc |
| 27 |
#include "exodusII_int.h" // for EX_FATAL, exi_comp_ws, etc |
| 28 |
|
| 29 |
/*! |
| 30 |
* writes the attributes for an edge/face/element block |
| 31 |
* \param exoid exodus file id |
| 32 |
* \param blk_type block type |
| 33 |
* \param blk_id block id |
| 34 |
* \param attrib array of attributes |
| 35 |
*/ |
| 36 |
|
| 37 |
int ex_put_attr(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, const void *attrib) |
| 38 |
{ |
| 39 |
int status; |
| 40 |
int attrid, blk_id_ndx; |
| 41 |
char errmsg[MAX_ERR_LENGTH]; |
| 42 |
|
| 43 |
EX_FUNC_ENTER(); |
| 44 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 45 |
EX_FUNC_LEAVE(EX_FATAL); |
| 46 |
} |
| 47 |
|
| 48 |
if (blk_type != EX_NODAL) { |
| 49 |
/* Determine index of blk_id in VAR_ID_EL_BLK array */ |
| 50 |
blk_id_ndx = exi_id_lkup(exoid, blk_type, blk_id); |
| 51 |
if (blk_id_ndx <= 0) { |
| 52 |
ex_get_err(NULL, NULL, &status); |
| 53 |
|
| 54 |
if (status != 0) { |
| 55 |
if (status == EX_NULLENTITY) { |
| 56 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 57 |
"Warning: no attributes allowed for NULL %s %" PRId64 " in file id %d", |
| 58 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 59 |
ex_err_fn(exoid, __func__, errmsg, EX_NULLENTITY); |
| 60 |
EX_FUNC_LEAVE(EX_WARN); /* no attributes for this block */ |
| 61 |
} |
| 62 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: no %s id %" PRId64 " in in file id %d", |
| 63 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 64 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 65 |
EX_FUNC_LEAVE(EX_FATAL); |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
switch (blk_type) { |
| 71 |
case EX_SIDE_SET: status = nc_inq_varid(exoid, VAR_SSATTRIB(blk_id_ndx), &attrid); break; |
| 72 |
case EX_NODE_SET: status = nc_inq_varid(exoid, VAR_NSATTRIB(blk_id_ndx), &attrid); break; |
| 73 |
case EX_EDGE_SET: status = nc_inq_varid(exoid, VAR_ESATTRIB(blk_id_ndx), &attrid); break; |
| 74 |
case EX_FACE_SET: status = nc_inq_varid(exoid, VAR_FSATTRIB(blk_id_ndx), &attrid); break; |
| 75 |
case EX_ELEM_SET: status = nc_inq_varid(exoid, VAR_ELSATTRIB(blk_id_ndx), &attrid); break; |
| 76 |
case EX_NODAL: status = nc_inq_varid(exoid, VAR_NATTRIB, &attrid); break; |
| 77 |
case EX_EDGE_BLOCK: status = nc_inq_varid(exoid, VAR_EATTRIB(blk_id_ndx), &attrid); break; |
| 78 |
case EX_FACE_BLOCK: status = nc_inq_varid(exoid, VAR_FATTRIB(blk_id_ndx), &attrid); break; |
| 79 |
case EX_ELEM_BLOCK: status = nc_inq_varid(exoid, VAR_ATTRIB(blk_id_ndx), &attrid); break; |
| 80 |
default: |
| 81 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 82 |
"Internal ERROR: unrecognized object type in switch: %d in file id %d", blk_type, |
| 83 |
exoid); |
| 84 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 85 |
EX_FUNC_LEAVE(EX_FATAL); /* number of attributes not defined */ |
| 86 |
} |
| 87 |
|
| 88 |
if (status != NC_NOERR) { |
| 89 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 90 |
"ERROR: failed to locate attribute variable for %s %" PRId64 " in file id %d", |
| 91 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 92 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 93 |
EX_FUNC_LEAVE(EX_FATAL); |
| 94 |
} |
| 95 |
|
| 96 |
/* write out the attributes */ |
| 97 |
if (exi_comp_ws(exoid) == 4) { |
| 98 |
status = nc_put_var_float(exoid, attrid, attrib); |
| 99 |
} |
| 100 |
else { |
| 101 |
status = nc_put_var_double(exoid, attrid, attrib); |
| 102 |
} |
| 103 |
|
| 104 |
if (status != NC_NOERR) { |
| 105 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 106 |
"ERROR: failed to put attributes for %s %" PRId64 " in file id %d", |
| 107 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 108 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 109 |
EX_FUNC_LEAVE(EX_FATAL); |
| 110 |
} |
| 111 |
EX_FUNC_LEAVE(EX_NOERR); |
| 112 |
} |