For example, the following code segment will initialize an element block with an ID of 10, write out the connectivity array, and write out the element attributes array:
int id, error, exoid, num_elem_in_blk, num_nodes_per_elem, *connect, num_attr;
float *attrib;
\comment{write element block parameters}
id = 10;
num_elem_in_blk = 2;
num_nodes_per_elem = 4; \comment{elements are 4-node shells}
num_attr = 1; \comment{one attribute per element}
error = ex_put_elem_block(exoid, id, "SHELL", num_elem_in_blk,
num_nodes_per_elem, num_attr);
\comment{write element connectivity}
connect = (int *)calloc(num_elem_in_blk*num_nodes_per_elem, sizeof(int));
\comment{fill connect with node numbers; nodes for first elemen}
connect[0] = 1; connect[1] = 2; connect[2] = 3; connect[3] = 4;
\comment{nodes for second element}
connect[4] = 5; connect[5] = 6; connect[6] = 7; connect[7] = 8;
error = ex_put_elem_conn (exoid, id, connect);
\comment{write element block attributes}
attrib = (float *) calloc (num_attr*num_elem_in_blk, sizeof(float));
for (i=0, cnt=0; i < num_elem_in_blk; i++) {
for (j=0; j < num_attr; j++, cnt++) {
attrib[cnt] = 1.0;
}
}
error = ex_put_elem_attr (exoid, id, attrib);
\comment{Same result using non-deprecated code}
error = ex_put_block(exoid, EX_ELEM_BLOCK, id, "SHELL", num_elem_in_blk,
num_nodes_per_elem, 0, 0, num_attr);
error = ex_put_conn (exoid, EX_ELEM_BLOCK, id, connect);
error = ex_put_attr (exoid, EX_ELEM_BLOCK, id, attrib);