| 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_partial_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, ex_name_of_object, etc |
| 27 |
#include "exodusII_int.h" // for exi_check_valid_file_id, 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 start_entity the starting index (1-based) of the attribute to be written |
| 35 |
* \param num_entity the number of entities to write attributes |
| 36 |
* \param attrib array of attributes |
| 37 |
*/ |
| 38 |
|
| 39 |
int ex_put_partial_attr(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, |
| 40 |
int64_t start_entity, int64_t num_entity, const void *attrib) |
| 41 |
{ |
| 42 |
int status; |
| 43 |
int attrid; |
| 44 |
int blk_id_ndx = 0; |
| 45 |
int numattrdim; |
| 46 |
size_t start[2], count[2]; |
| 47 |
size_t num_attr; |
| 48 |
char errmsg[MAX_ERR_LENGTH]; |
| 49 |
|
| 50 |
EX_FUNC_ENTER(); |
| 51 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 52 |
EX_FUNC_LEAVE(EX_FATAL); |
| 53 |
} |
| 54 |
|
| 55 |
if (blk_type != EX_NODAL) { |
| 56 |
/* Determine index of blk_id in VAR_ID_EL_BLK array */ |
| 57 |
blk_id_ndx = exi_id_lkup(exoid, blk_type, blk_id); |
| 58 |
if (blk_id_ndx <= 0) { |
| 59 |
ex_get_err(NULL, NULL, &status); |
| 60 |
|
| 61 |
if (status != 0) { |
| 62 |
if (status == EX_NULLENTITY) { |
| 63 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 64 |
"Warning: no attributes allowed for NULL %s %" PRId64 " in file id %d", |
| 65 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 66 |
ex_err_fn(exoid, __func__, errmsg, EX_NULLENTITY); |
| 67 |
EX_FUNC_LEAVE(EX_WARN); /* no attributes for this block */ |
| 68 |
} |
| 69 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: no %s id %" PRId64 " in in file id %d", |
| 70 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 71 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 72 |
EX_FUNC_LEAVE(EX_FATAL); |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
switch (blk_type) { |
| 78 |
case EX_SIDE_SET: status = nc_inq_varid(exoid, VAR_SSATTRIB(blk_id_ndx), &attrid); break; |
| 79 |
case EX_NODE_SET: status = nc_inq_varid(exoid, VAR_NSATTRIB(blk_id_ndx), &attrid); break; |
| 80 |
case EX_EDGE_SET: status = nc_inq_varid(exoid, VAR_ESATTRIB(blk_id_ndx), &attrid); break; |
| 81 |
case EX_FACE_SET: status = nc_inq_varid(exoid, VAR_FSATTRIB(blk_id_ndx), &attrid); break; |
| 82 |
case EX_ELEM_SET: status = nc_inq_varid(exoid, VAR_ELSATTRIB(blk_id_ndx), &attrid); break; |
| 83 |
case EX_NODAL: status = nc_inq_varid(exoid, VAR_NATTRIB, &attrid); break; |
| 84 |
case EX_EDGE_BLOCK: status = nc_inq_varid(exoid, VAR_EATTRIB(blk_id_ndx), &attrid); break; |
| 85 |
case EX_FACE_BLOCK: status = nc_inq_varid(exoid, VAR_FATTRIB(blk_id_ndx), &attrid); break; |
| 86 |
case EX_ELEM_BLOCK: status = nc_inq_varid(exoid, VAR_ATTRIB(blk_id_ndx), &attrid); break; |
| 87 |
default: |
| 88 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 89 |
"Internal ERROR: unrecognized object type in switch: %d in file id %d", blk_type, |
| 90 |
exoid); |
| 91 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 92 |
EX_FUNC_LEAVE(EX_FATAL); /* number of attributes not defined */ |
| 93 |
} |
| 94 |
|
| 95 |
if (status != NC_NOERR) { |
| 96 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 97 |
"ERROR: failed to locate attribute variable for %s %" PRId64 " in file id %d", |
| 98 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 99 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 100 |
EX_FUNC_LEAVE(EX_FATAL); |
| 101 |
} |
| 102 |
|
| 103 |
/* Determine number of attributes */ |
| 104 |
switch (blk_type) { |
| 105 |
case EX_SIDE_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_SS(blk_id_ndx), &numattrdim); break; |
| 106 |
case EX_NODE_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_NS(blk_id_ndx), &numattrdim); break; |
| 107 |
case EX_EDGE_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_ES(blk_id_ndx), &numattrdim); break; |
| 108 |
case EX_FACE_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_FS(blk_id_ndx), &numattrdim); break; |
| 109 |
case EX_ELEM_SET: |
| 110 |
status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_ELS(blk_id_ndx), &numattrdim); |
| 111 |
break; |
| 112 |
case EX_NODAL: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_NBLK, &numattrdim); break; |
| 113 |
case EX_EDGE_BLOCK: |
| 114 |
status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_EBLK(blk_id_ndx), &numattrdim); |
| 115 |
break; |
| 116 |
case EX_FACE_BLOCK: |
| 117 |
status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_FBLK(blk_id_ndx), &numattrdim); |
| 118 |
break; |
| 119 |
case EX_ELEM_BLOCK: |
| 120 |
status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_BLK(blk_id_ndx), &numattrdim); |
| 121 |
break; |
| 122 |
default: |
| 123 |
/* No need for error message, handled in previous switch; just to quiet |
| 124 |
* compiler. */ |
| 125 |
EX_FUNC_LEAVE(EX_FATAL); |
| 126 |
} |
| 127 |
|
| 128 |
if (status != NC_NOERR) { |
| 129 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 130 |
"ERROR: number of attributes not defined for %s %" PRId64 " in file id %d", |
| 131 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 132 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 133 |
EX_FUNC_LEAVE(EX_FATAL); /* number of attributes not defined */ |
| 134 |
} |
| 135 |
|
| 136 |
if ((status = nc_inq_dimlen(exoid, numattrdim, &num_attr)) != NC_NOERR) { |
| 137 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 138 |
"ERROR: failed to get number of attributes for %s %" PRId64 " in file id %d", |
| 139 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 140 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 141 |
EX_FUNC_LEAVE(EX_FATAL); |
| 142 |
} |
| 143 |
|
| 144 |
/* write out the attributes */ |
| 145 |
start[0] = --start_entity; |
| 146 |
start[1] = 0; |
| 147 |
|
| 148 |
count[0] = num_entity; |
| 149 |
count[1] = num_attr; |
| 150 |
if (count[0] == 0) { |
| 151 |
start[0] = 0; |
| 152 |
} |
| 153 |
|
| 154 |
if (exi_comp_ws(exoid) == 4) { |
| 155 |
status = nc_put_vara_float(exoid, attrid, start, count, attrib); |
| 156 |
} |
| 157 |
else { |
| 158 |
status = nc_put_vara_double(exoid, attrid, start, count, attrib); |
| 159 |
} |
| 160 |
|
| 161 |
if (status != NC_NOERR) { |
| 162 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 163 |
"ERROR: failed to put attributes for %s %" PRId64 " in file id %d", |
| 164 |
ex_name_of_object(blk_type), blk_id, exoid); |
| 165 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 166 |
EX_FUNC_LEAVE(EX_FATAL); |
| 167 |
} |
| 168 |
EX_FUNC_LEAVE(EX_NOERR); |
| 169 |
} |