PageRenderTime 68ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/contrib/exodusii/5.22b/exodus/cbind/test/testrd-nsided.c

https://bitbucket.org/vijaysm/libmesh
C | 1153 lines | 836 code | 236 blank | 81 comment | 152 complexity | 5bdb1864dc175aae4ab9bd823d0e0fd4 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-3.0, MPL-2.0-no-copyleft-exception, GPL-2.0
  1. /*
  2. * Copyright (c) 2005 Sandia Corporation. Under the terms of Contract
  3. * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Governement
  4. * retains certain rights in this software.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. *
  13. * * Redistributions in binary form must reproduce the above
  14. * copyright notice, this list of conditions and the following
  15. * disclaimer in the documentation and/or other materials provided
  16. * with the distribution.
  17. *
  18. * * Neither the name of Sandia Corporation nor the names of its
  19. * contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  25. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  26. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  27. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  28. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  29. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  30. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  32. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. */
  35. /*****************************************************************************
  36. *
  37. * testrd - read exodus file test-nsided.exo created by testwt-nsided
  38. *
  39. *****************************************************************************/
  40. #include <stdlib.h>
  41. #include <stdio.h>
  42. #include <string.h>
  43. #include "netcdf.h"
  44. #include <assert.h>
  45. #include "exodusII.h"
  46. int main (int argc, char **argv)
  47. {
  48. int exoid, num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets;
  49. int num_side_sets, error, nnodes;
  50. int i, j, k;
  51. int *elem_map = NULL;
  52. int *connect = NULL;
  53. int *node_list = NULL;
  54. int *node_ctr_list = NULL;
  55. int *elem_list = NULL;
  56. int *side_list = NULL;
  57. int *ids = NULL;
  58. int *nnpe = NULL;
  59. int *num_nodes_per_set = NULL;
  60. int *num_elem_per_set = NULL;
  61. int *num_df_per_set = NULL;
  62. int *node_ind = NULL;
  63. int *elem_ind = NULL;
  64. int *df_ind = NULL;
  65. int num_qa_rec, num_info;
  66. int num_glo_vars, num_nod_vars, num_ele_vars;
  67. int num_nset_vars, num_sset_vars;
  68. int *truth_tab = NULL;
  69. int num_time_steps;
  70. int *num_elem_in_block = NULL;
  71. int *num_nodes_per_elem = NULL;
  72. int *num_attr = NULL;
  73. int num_nodes_in_set, num_elem_in_set;
  74. int num_sides_in_set, num_df_in_set;
  75. int list_len, elem_list_len, df_list_len;
  76. int node_num, time_step, var_index, beg_time, end_time, elem_num;
  77. int CPU_word_size,IO_word_size;
  78. int num_props, prop_value, *prop_values;
  79. int idum;
  80. float time_value, *time_values, *var_values;
  81. float *x, *y, *z;
  82. float *attrib, *dist_fact;
  83. float version, fdum;
  84. char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
  85. char *block_names[10], *nset_names[10], *sset_names[10];
  86. char *attrib_names[10];
  87. char *elem_type[10];
  88. char name[MAX_STR_LENGTH+1];
  89. char title[MAX_LINE_LENGTH+1];
  90. char *cdum = 0;
  91. char *prop_names[3];
  92. CPU_word_size = 0; /* sizeof(float) */
  93. IO_word_size = 0; /* use what is stored in file */
  94. ex_opts (EX_VERBOSE | EX_ABORT );
  95. /* open EXODUS II files */
  96. exoid = ex_open ("test-nsided.exo", /* filename path */
  97. EX_READ, /* access mode = READ */
  98. &CPU_word_size, /* CPU word size */
  99. &IO_word_size, /* IO word size */
  100. &version); /* ExodusII library version */
  101. printf ("\nafter ex_open\n");
  102. if (exoid < 0) exit(1);
  103. printf ("test.exo is an EXODUSII file; version %4.2f\n",
  104. version);
  105. printf (" I/O word size %1d\n",IO_word_size);
  106. ex_inquire(exoid,EX_INQ_LIB_VERS, &idum, &version, cdum);
  107. printf ("EXODUSII Library API; version %4.2f (%d)\n", version, idum);
  108. /* read database parameters */
  109. error = ex_get_init (exoid, title, &num_dim, &num_nodes, &num_elem,
  110. &num_elem_blk, &num_node_sets, &num_side_sets);
  111. printf ("after ex_get_init, error = %3d\n", error);
  112. printf ("database parameters:\n");
  113. printf ("title = '%s'\n",title);
  114. printf ("num_dim = %3d\n",num_dim);
  115. printf ("num_nodes = %3d\n",num_nodes);
  116. printf ("num_elem = %3d\n",num_elem);
  117. printf ("num_elem_blk = %3d\n",num_elem_blk);
  118. printf ("num_node_sets = %3d\n",num_node_sets);
  119. printf ("num_side_sets = %3d\n",num_side_sets);
  120. /* read nodal coordinates values and names from database */
  121. x = (float *) calloc(num_nodes, sizeof(float));
  122. y = (float *) calloc(num_nodes, sizeof(float));
  123. if (num_dim >= 3)
  124. z = (float *) calloc(num_nodes, sizeof(float));
  125. else
  126. z = 0;
  127. error = ex_get_coord (exoid, x, y, z);
  128. printf ("\nafter ex_get_coord, error = %3d\n", error);
  129. printf ("x coords = \n");
  130. for (i=0; i<num_nodes; i++)
  131. {
  132. printf ("%5.1f\n", x[i]);
  133. }
  134. printf ("y coords = \n");
  135. for (i=0; i<num_nodes; i++)
  136. {
  137. printf ("%5.1f\n", y[i]);
  138. }
  139. if (num_dim >= 3)
  140. {
  141. printf ("z coords = \n");
  142. for (i=0; i<num_nodes; i++)
  143. {
  144. printf ("%5.1f\n", z[i]);
  145. }
  146. }
  147. free (x);
  148. free (y);
  149. if (num_dim >= 3)
  150. free (z);
  151. for (i=0; i<num_dim; i++)
  152. {
  153. coord_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
  154. }
  155. error = ex_get_coord_names (exoid, coord_names);
  156. printf ("\nafter ex_get_coord_names, error = %3d\n", error);
  157. printf ("x coord name = '%s'\n", coord_names[0]);
  158. printf ("y coord name = '%s'\n", coord_names[1]);
  159. for (i=0; i<num_dim; i++)
  160. free(coord_names[i]);
  161. {
  162. int num_attrs = 0;
  163. error = ex_get_attr_param(exoid, EX_NODAL, 0, &num_attrs);
  164. printf (" after ex_get_attr_param, error = %d\n", error);
  165. printf ("num nodal attributes = %d\n", num_attrs);
  166. if (num_attrs > 0) {
  167. for (j=0; j<num_attrs; j++) {
  168. attrib_names[j] = (char *)calloc ((MAX_STR_LENGTH+1), sizeof(char));
  169. }
  170. error = ex_get_attr_names (exoid, EX_NODAL, 0, attrib_names);
  171. printf (" after ex_get_attr_names, error = %d\n", error);
  172. if (error == 0) {
  173. attrib = (float *) calloc(num_nodes,sizeof(float));
  174. for (j=0; j<num_attrs; j++) {
  175. printf ("nodal attribute %d = '%s'\n", j, attrib_names[j]);
  176. error = ex_get_one_attr(exoid, EX_NODAL, 0, j+1, attrib);
  177. printf (" after ex_get_one_attr, error = %d\n", error);
  178. for (i=0; i < num_nodes; i++) {
  179. printf ("%5.1f\n", attrib[i]);
  180. }
  181. free(attrib_names[j]);
  182. }
  183. free(attrib);
  184. }
  185. }
  186. }
  187. /* read element order map */
  188. elem_map = (int *) calloc(num_elem, sizeof(int));
  189. error = ex_get_map (exoid, elem_map);
  190. printf ("\nafter ex_get_map, error = %3d\n", error);
  191. for (i=0; i<num_elem; i++) {
  192. printf ("elem_map(%d) = %d \n", i, elem_map[i]);
  193. }
  194. free (elem_map);
  195. /* read element block parameters */
  196. if (num_elem_blk > 0) {
  197. ids = (int *) calloc(num_elem_blk, sizeof(int));
  198. num_elem_in_block = (int *) calloc(num_elem_blk, sizeof(int));
  199. num_nodes_per_elem = (int *) calloc(num_elem_blk, sizeof(int));
  200. num_attr = (int *) calloc(num_elem_blk, sizeof(int));
  201. for (i=0; i<num_elem_blk; i++) {
  202. elem_type[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
  203. }
  204. error = ex_get_elem_blk_ids (exoid, ids);
  205. printf ("\nafter ex_get_elem_blk_ids, error = %3d\n", error);
  206. for (i=0; i<num_elem_blk; i++) {
  207. block_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
  208. }
  209. error = ex_get_names(exoid, EX_ELEM_BLOCK, block_names);
  210. printf ("\nafter ex_get_names, error = %3d\n", error);
  211. for (i=0; i<num_elem_blk; i++) {
  212. ex_get_name(exoid, EX_ELEM_BLOCK, ids[i], name);
  213. if (strcmp(name, block_names[i]) != 0) {
  214. printf ("error in ex_get_name for block id %d\n", ids[i]);
  215. }
  216. error = ex_get_elem_block (exoid, ids[i], elem_type[i],
  217. &(num_elem_in_block[i]),
  218. &(num_nodes_per_elem[i]), &(num_attr[i]));
  219. printf ("\nafter ex_get_elem_block, error = %d\n", error);
  220. printf ("element block id = %2d\n",ids[i]);
  221. printf ("element type = '%s'\n", elem_type[i]);
  222. printf ("num_elem_in_block = %2d\n",num_elem_in_block[i]);
  223. printf ("num_total_nodes_per_block = %2d\n",num_nodes_per_elem[i]);
  224. printf ("num_attr = %2d\n",num_attr[i]);
  225. printf ("name = '%s'\n",block_names[i]);
  226. free(block_names[i]);
  227. }
  228. /* read element block properties */
  229. error = ex_inquire (exoid, EX_INQ_EB_PROP, &num_props, &fdum, cdum);
  230. printf ("\nafter ex_inquire, error = %d\n", error);
  231. printf ("\nThere are %2d properties for each element block\n", num_props);
  232. for (i=0; i<num_props; i++) {
  233. prop_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
  234. }
  235. error = ex_get_prop_names(exoid,EX_ELEM_BLOCK,prop_names);
  236. printf ("after ex_get_prop_names, error = %d\n", error);
  237. for (i=1; i<num_props; i++) {/* Prop 1 is id; skip that here */
  238. for (j=0; j<num_elem_blk; j++) {
  239. error = ex_get_prop(exoid, EX_ELEM_BLOCK, ids[j], prop_names[i],
  240. &prop_value);
  241. printf (" after ex_get_prop, error = %d\n", error);
  242. if (error == 0)
  243. printf ("element block %2d, property(%2d): '%s'= %5d\n",
  244. j+1, i+1, prop_names[i], prop_value);
  245. else
  246. printf ("after ex_get_prop, error = %d\n", error);
  247. }
  248. }
  249. for (i=0; i<num_props; i++)
  250. free(prop_names[i]);
  251. }
  252. /* read element connectivity */
  253. for (i=0; i<num_elem_blk; i++) {
  254. if (num_elem_in_block[i] > 0) {
  255. if (strcmp(elem_type[i], "NSIDED") == 0 || strcmp(elem_type[i], "nsided") == 0) {
  256. connect = (int *) calloc((num_nodes_per_elem[i]), sizeof(int));
  257. nnpe = (int *) calloc(num_elem_in_block[i], sizeof(int));
  258. error = ex_get_entity_count_per_polyhedra(exoid, EX_ELEM_BLOCK, ids[i], nnpe);
  259. printf ("\nafter ex_get_entity_count_per_polyhedra, error = %d\n", error);
  260. nnodes = 0;
  261. for (j=0; j < num_elem_in_block[i]; j++) {
  262. nnodes += nnpe[j];
  263. }
  264. assert(nnodes == num_nodes_per_elem[i]);
  265. error = ex_get_elem_conn (exoid, ids[i], connect);
  266. printf ("\nafter ex_get_elem_conn, error = %d\n", error);
  267. printf ("connect array for elem block %2d\n", ids[i]);
  268. nnodes = 0;
  269. for (j=0; j < num_elem_in_block[i]; j++) {
  270. printf("Element %d, %d nodes:\t", j+1, nnpe[j]);
  271. for (k=0; k < nnpe[j]; k++) {
  272. printf("%3d ", connect[nnodes+k]);
  273. }
  274. printf("\n");
  275. nnodes += nnpe[j];
  276. }
  277. free(nnpe);
  278. } else {
  279. connect = (int *) calloc((num_nodes_per_elem[i] * num_elem_in_block[i]),
  280. sizeof(int));
  281. error = ex_get_elem_conn (exoid, ids[i], connect);
  282. printf ("\nafter ex_get_elem_conn, error = %d\n", error);
  283. printf ("connect array for elem block %2d\n", ids[i]);
  284. for (j=0; j<num_nodes_per_elem[i]; j++) {
  285. printf ("%3d\n", connect[j]);
  286. }
  287. }
  288. free (connect);
  289. }
  290. }
  291. /* read element block attributes */
  292. for (i=0; i<num_elem_blk; i++) {
  293. if (num_attr[i] > 0) {
  294. for (j=0; j<num_attr[i]; j++)
  295. attrib_names[j] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
  296. attrib = (float *) calloc(num_attr[i]*num_elem_in_block[i],sizeof(float));
  297. error = ex_get_elem_attr (exoid, ids[i], attrib);
  298. printf ("\n after ex_get_elem_attr, error = %d\n", error);
  299. if (error == 0) {
  300. error = ex_get_elem_attr_names (exoid, ids[i], attrib_names);
  301. printf (" after ex_get_elem_attr_names, error = %d\n", error);
  302. if (error == 0) {
  303. printf ("element block %d attribute '%s' = %6.4f\n", ids[i], attrib_names[0], *attrib);
  304. }
  305. }
  306. free (attrib);
  307. for (j=0; j<num_attr[i]; j++)
  308. free (attrib_names[j]);
  309. }
  310. }
  311. if (num_elem_blk > 0) {
  312. free (ids);
  313. free (num_nodes_per_elem);
  314. free (num_attr);
  315. }
  316. /* read individual node sets */
  317. if (num_node_sets > 0) {
  318. ids = (int *) calloc(num_node_sets, sizeof(int));
  319. error = ex_get_node_set_ids (exoid, ids);
  320. printf ("\nafter ex_get_node_set_ids, error = %3d\n", error);
  321. for (i=0; i<num_node_sets; i++) {
  322. nset_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
  323. }
  324. error = ex_get_names(exoid, EX_NODE_SET, nset_names);
  325. printf ("\nafter ex_get_names, error = %3d\n", error);
  326. for (i=0; i<num_node_sets; i++)
  327. {
  328. ex_get_name(exoid, EX_NODE_SET, ids[i], name);
  329. if (strcmp(name, nset_names[i]) != 0) {
  330. printf ("error in ex_get_name for nodeset id %d\n", ids[i]);
  331. }
  332. error = ex_get_node_set_param (exoid, ids[i],
  333. &num_nodes_in_set, &num_df_in_set);
  334. printf ("\nafter ex_get_node_set_param, error = %3d\n", error);
  335. printf ("\nnode set %2d parameters: \n", ids[i]);
  336. printf ("num_nodes = %2d\n", num_nodes_in_set);
  337. printf ("name = '%s'\n", nset_names[i]);
  338. free(nset_names[i]);
  339. node_list = (int *) calloc(num_nodes_in_set, sizeof(int));
  340. dist_fact = (float *) calloc(num_nodes_in_set, sizeof(float));
  341. error = ex_get_node_set (exoid, ids[i], node_list);
  342. printf ("\nafter ex_get_node_set, error = %3d\n", error);
  343. if (num_df_in_set > 0)
  344. {
  345. error = ex_get_node_set_dist_fact (exoid, ids[i], dist_fact);
  346. printf ("\nafter ex_get_node_set_dist_fact, error = %3d\n", error);
  347. }
  348. printf ("\nnode list for node set %2d\n", ids[i]);
  349. for (j=0; j<num_nodes_in_set; j++)
  350. {
  351. printf ("%3d\n", node_list[j]);
  352. }
  353. if (num_df_in_set > 0)
  354. {
  355. printf ("dist factors for node set %2d\n", ids[i]);
  356. for (j=0; j<num_nodes_in_set; j++)
  357. {
  358. printf ("%5.2f\n", dist_fact[j]);
  359. }
  360. }
  361. else
  362. printf ("no dist factors for node set %2d\n", ids[i]);
  363. free (node_list);
  364. free (dist_fact);
  365. {
  366. int num_attrs = 0;
  367. error = ex_get_attr_param(exoid, EX_NODE_SET, ids[i], &num_attrs);
  368. printf (" after ex_get_attr_param, error = %d\n", error);
  369. printf ("num nodeset attributes for nodeset %d = %d\n", ids[i], num_attrs);
  370. if (num_attrs > 0) {
  371. for (j=0; j<num_attrs; j++) {
  372. attrib_names[j] = (char *)calloc ((MAX_STR_LENGTH+1), sizeof(char));
  373. }
  374. error = ex_get_attr_names (exoid, EX_NODE_SET, ids[i], attrib_names);
  375. printf (" after ex_get_attr_names, error = %d\n", error);
  376. if (error == 0) {
  377. attrib = (float *) calloc(num_nodes_in_set,sizeof(float));
  378. for (j=0; j<num_attrs; j++) {
  379. printf ("nodeset attribute %d = '%s'\n", j, attrib_names[j]);
  380. error = ex_get_one_attr(exoid, EX_NODE_SET, ids[i], j+1, attrib);
  381. printf (" after ex_get_one_attr, error = %d\n", error);
  382. for (k=0; k < num_nodes_in_set; k++) {
  383. printf ("%5.1f\n", attrib[k]);
  384. }
  385. free(attrib_names[j]);
  386. }
  387. free(attrib);
  388. }
  389. }
  390. }
  391. }
  392. free(ids);
  393. /* read node set properties */
  394. error = ex_inquire (exoid, EX_INQ_NS_PROP, &num_props, &fdum, cdum);
  395. printf ("\nafter ex_inquire, error = %d\n", error);
  396. printf ("\nThere are %2d properties for each node set\n", num_props);
  397. for (i=0; i<num_props; i++)
  398. {
  399. prop_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
  400. }
  401. prop_values = (int *) calloc (num_node_sets, sizeof(int));
  402. error = ex_get_prop_names(exoid,EX_NODE_SET,prop_names);
  403. printf ("after ex_get_prop_names, error = %d\n", error);
  404. for (i=0; i<num_props; i++)
  405. {
  406. error = ex_get_prop_array(exoid, EX_NODE_SET, prop_names[i],
  407. prop_values);
  408. if (error == 0)
  409. for (j=0; j<num_node_sets; j++)
  410. printf ("node set %2d, property(%2d): '%s'= %5d\n",
  411. j+1, i+1, prop_names[i], prop_values[j]);
  412. else
  413. printf ("after ex_get_prop_array, error = %d\n", error);
  414. }
  415. for (i=0; i<num_props; i++)
  416. free(prop_names[i]);
  417. free(prop_values);
  418. /* read concatenated node sets; this produces the same information as
  419. * the above code which reads individual node sets
  420. */
  421. error = ex_inquire (exoid, EX_INQ_NODE_SETS, &num_node_sets, &fdum, cdum);
  422. printf ("\nafter ex_inquire, error = %3d\n",error);
  423. ids = (int *) calloc(num_node_sets, sizeof(int));
  424. num_nodes_per_set = (int *) calloc(num_node_sets, sizeof(int));
  425. num_df_per_set = (int *) calloc(num_node_sets, sizeof(int));
  426. node_ind = (int *) calloc(num_node_sets, sizeof(int));
  427. df_ind = (int *) calloc(num_node_sets, sizeof(int));
  428. error = ex_inquire (exoid, EX_INQ_NS_NODE_LEN, &list_len, &fdum, cdum);
  429. printf ("\nafter ex_inquire: EX_INQ_NS_NODE_LEN = %d, error = %3d\n",
  430. list_len, error);
  431. node_list = (int *) calloc(list_len, sizeof(int));
  432. error = ex_inquire (exoid, EX_INQ_NS_DF_LEN, &list_len, &fdum, cdum);
  433. printf ("\nafter ex_inquire: EX_INQ_NS_DF_LEN = %d, error = %3d\n",
  434. list_len, error);
  435. dist_fact = (float *) calloc(list_len, sizeof(float));
  436. error = ex_get_concat_node_sets (exoid,ids,num_nodes_per_set,num_df_per_set,
  437. node_ind, df_ind, node_list, dist_fact);
  438. printf ("\nafter ex_get_concat_node_sets, error = %3d\n", error);
  439. printf ("\nconcatenated node set info\n");
  440. printf ("ids = \n");
  441. for (i=0; i<num_node_sets; i++) printf ("%3d\n", ids[i]);
  442. printf ("num_nodes_per_set = \n");
  443. for (i=0; i<num_node_sets; i++) printf ("%3d\n", num_nodes_per_set[i]);
  444. printf ("node_ind = \n");
  445. for (i=0; i<num_node_sets; i++) printf ("%3d\n", node_ind[i]);
  446. printf ("node_list = \n");
  447. for (i=0; i<list_len; i++) printf ("%3d\n", node_list[i]);
  448. printf ("dist_fact = \n");
  449. for (i=0; i<list_len; i++) printf ("%5.3f\n", dist_fact[i]);
  450. free (ids);
  451. free (df_ind);
  452. free (node_ind);
  453. free (num_df_per_set);
  454. free (node_list);
  455. free (dist_fact);
  456. }
  457. /* read individual side sets */
  458. if (num_side_sets > 0) {
  459. ids = (int *) calloc(num_side_sets, sizeof(int));
  460. error = ex_get_side_set_ids (exoid, ids);
  461. printf ("\nafter ex_get_side_set_ids, error = %3d\n", error);
  462. for (i=0; i<num_side_sets; i++) {
  463. sset_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
  464. }
  465. error = ex_get_names(exoid, EX_SIDE_SET, sset_names);
  466. printf ("\nafter ex_get_names, error = %3d\n", error);
  467. for (i=0; i<num_side_sets; i++)
  468. {
  469. ex_get_name(exoid, EX_SIDE_SET, ids[i], name);
  470. if (strcmp(name, sset_names[i]) != 0) {
  471. printf ("error in ex_get_name for sideset id %d\n", ids[i]);
  472. }
  473. error = ex_get_side_set_param (exoid, ids[i], &num_sides_in_set,
  474. &num_df_in_set);
  475. printf ("\nafter ex_get_side_set_param, error = %3d\n", error);
  476. printf ("side set %2d parameters:\n",ids[i]);
  477. printf ("name = '%s'\n", sset_names[i]);
  478. printf ("num_sides = %3d\n",num_sides_in_set);
  479. printf ("num_dist_factors = %3d\n", num_df_in_set);
  480. free(sset_names[i]);
  481. /* Note: The # of elements is same as # of sides! */
  482. num_elem_in_set = num_sides_in_set;
  483. elem_list = (int *) calloc(num_elem_in_set, sizeof(int));
  484. side_list = (int *) calloc(num_sides_in_set, sizeof(int));
  485. node_ctr_list = (int *) calloc(num_elem_in_set, sizeof(int));
  486. node_list = (int *) calloc(num_elem_in_set*21, sizeof(int));
  487. dist_fact = (float *) calloc(num_df_in_set, sizeof(float));
  488. error = ex_get_side_set (exoid, ids[i], elem_list, side_list);
  489. printf ("\nafter ex_get_side_set, error = %3d\n", error);
  490. if (num_df_in_set > 0) {
  491. error = ex_get_side_set_dist_fact (exoid, ids[i], dist_fact);
  492. printf ("\nafter ex_get_side_set_dist_fact, error = %3d\n", error);
  493. }
  494. printf ("element list for side set %2d\n", ids[i]);
  495. for (j=0; j<num_elem_in_set; j++)
  496. {
  497. printf ("%3d\n", elem_list[j]);
  498. }
  499. printf ("side list for side set %2d\n", ids[i]);
  500. for (j=0; j<num_sides_in_set; j++)
  501. {
  502. printf ("%3d\n", side_list[j]);
  503. }
  504. if (num_df_in_set > 0)
  505. {
  506. printf ("dist factors for side set %2d\n", ids[i]);
  507. for (j=0; j<num_df_in_set; j++)
  508. {
  509. printf ("%5.3f\n", dist_fact[j]);
  510. }
  511. }
  512. else
  513. printf ("no dist factors for side set %2d\n", ids[i]);
  514. free (elem_list);
  515. free (side_list);
  516. free (node_ctr_list);
  517. free (node_list);
  518. free (dist_fact);
  519. }
  520. /* read side set properties */
  521. error = ex_inquire (exoid, EX_INQ_SS_PROP, &num_props, &fdum, cdum);
  522. printf ("\nafter ex_inquire, error = %d\n", error);
  523. printf ("\nThere are %2d properties for each side set\n", num_props);
  524. for (i=0; i<num_props; i++) {
  525. prop_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
  526. }
  527. error = ex_get_prop_names(exoid,EX_SIDE_SET,prop_names);
  528. printf ("after ex_get_prop_names, error = %d\n", error);
  529. for (i=0; i<num_props; i++) {
  530. for (j=0; j<num_side_sets; j++)
  531. {
  532. error = ex_get_prop(exoid, EX_SIDE_SET, ids[j], prop_names[i],
  533. &prop_value);
  534. if (error == 0)
  535. printf ("side set %2d, property(%2d): '%s'= %5d\n",
  536. j+1, i+1, prop_names[i], prop_value);
  537. else
  538. printf ("after ex_get_prop, error = %d\n", error);
  539. }
  540. }
  541. for (i=0; i<num_props; i++)
  542. free(prop_names[i]);
  543. free (ids);
  544. error = ex_inquire (exoid, EX_INQ_SIDE_SETS, &num_side_sets, &fdum, cdum);
  545. printf ("\nafter ex_inquire: EX_INQ_SIDE_SETS = %d, error = %d\n",
  546. num_side_sets, error);
  547. if (num_side_sets > 0) {
  548. error = ex_inquire(exoid, EX_INQ_SS_ELEM_LEN, &elem_list_len, &fdum, cdum);
  549. printf ("\nafter ex_inquire: EX_INQ_SS_ELEM_LEN = %d, error = %d\n",
  550. elem_list_len, error);
  551. error = ex_inquire(exoid, EX_INQ_SS_DF_LEN, &df_list_len, &fdum, cdum);
  552. printf ("\nafter ex_inquire: EX_INQ_SS_DF_LEN = %d, error = %d\n",
  553. df_list_len, error);
  554. }
  555. /* read concatenated side sets; this produces the same information as
  556. * the above code which reads individual side sets
  557. */
  558. /* concatenated side set read */
  559. if (num_side_sets > 0) {
  560. ids = (int *) calloc(num_side_sets, sizeof(int));
  561. num_elem_per_set = (int *) calloc(num_side_sets, sizeof(int));
  562. num_df_per_set = (int *) calloc(num_side_sets, sizeof(int));
  563. elem_ind = (int *) calloc(num_side_sets, sizeof(int));
  564. df_ind = (int *) calloc(num_side_sets, sizeof(int));
  565. elem_list = (int *) calloc(elem_list_len, sizeof(int));
  566. side_list = (int *) calloc(elem_list_len, sizeof(int));
  567. dist_fact = (float *) calloc(df_list_len, sizeof(float));
  568. error = ex_get_concat_side_sets (exoid, ids, num_elem_per_set,
  569. num_df_per_set, elem_ind, df_ind,
  570. elem_list, side_list, dist_fact);
  571. printf ("\nafter ex_get_concat_side_sets, error = %3d\n", error);
  572. printf ("concatenated side set info\n");
  573. printf ("ids = \n");
  574. for (i=0; i<num_side_sets; i++) printf ("%3d\n", ids[i]);
  575. printf ("num_elem_per_set = \n");
  576. for (i=0; i<num_side_sets; i++) printf ("%3d\n", num_elem_per_set[i]);
  577. printf ("num_dist_per_set = \n");
  578. for (i=0; i<num_side_sets; i++) printf ("%3d\n", num_df_per_set[i]);
  579. printf ("elem_ind = \n");
  580. for (i=0; i<num_side_sets; i++) printf ("%3d\n", elem_ind[i]);
  581. printf ("dist_ind = \n");
  582. for (i=0; i<num_side_sets; i++) printf ("%3d\n", df_ind[i]);
  583. printf ("elem_list = \n");
  584. for (i=0; i<elem_list_len; i++) printf ("%3d\n", elem_list[i]);
  585. printf ("side_list = \n");
  586. for (i=0; i<elem_list_len; i++) printf ("%3d\n", side_list[i]);
  587. printf ("dist_fact = \n");
  588. for (i=0; i<df_list_len; i++) printf ("%5.3f\n", dist_fact[i]);
  589. free (ids);
  590. free (num_df_per_set);
  591. free (df_ind);
  592. free (elem_ind);
  593. free (elem_list);
  594. free (side_list);
  595. free (dist_fact);
  596. }
  597. }
  598. /* end of concatenated side set read */
  599. /* read QA records */
  600. ex_inquire (exoid, EX_INQ_QA, &num_qa_rec, &fdum, cdum);
  601. for (i=0; i<num_qa_rec; i++)
  602. {
  603. for (j=0; j<4; j++)
  604. {
  605. qa_record[i][j] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
  606. }
  607. }
  608. error = ex_get_qa (exoid, qa_record);
  609. printf ("\nafter ex_get_qa, error = %3d\n", error);
  610. printf ("QA records = \n");
  611. for (i=0; i<num_qa_rec; i++)
  612. {
  613. for (j=0; j<4; j++)
  614. {
  615. printf (" '%s'\n", qa_record[i][j]);
  616. free(qa_record[i][j]);
  617. }
  618. }
  619. /* read information records */
  620. error = ex_inquire (exoid, EX_INQ_INFO, &num_info, &fdum, cdum);
  621. printf ("\nafter ex_inquire, error = %3d\n", error);
  622. for (i=0; i<num_info; i++)
  623. {
  624. info[i] = (char *) calloc ((MAX_LINE_LENGTH+1), sizeof(char));
  625. }
  626. error = ex_get_info (exoid, info);
  627. printf ("\nafter ex_get_info, error = %3d\n", error);
  628. printf ("info records = \n");
  629. for (i=0; i<num_info; i++)
  630. {
  631. printf (" '%s'\n", info[i]);
  632. free(info[i]);
  633. }
  634. /* read global variables parameters and names */
  635. error = ex_get_var_param (exoid, "g", &num_glo_vars);
  636. printf ("\nafter ex_get_var_param, error = %3d\n", error);
  637. for (i=0; i<num_glo_vars; i++)
  638. {
  639. var_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
  640. }
  641. error = ex_get_var_names (exoid, "g", num_glo_vars, var_names);
  642. printf ("\nafter ex_get_var_names, error = %3d\n", error);
  643. printf ("There are %2d global variables; their names are :\n",
  644. num_glo_vars);
  645. for (i=0; i<num_glo_vars; i++)
  646. {
  647. printf (" '%s'\n", var_names[i]);
  648. free(var_names[i]);
  649. }
  650. /* read nodal variables parameters and names */
  651. num_nod_vars = 0;
  652. if (num_nodes > 0) {
  653. error = ex_get_var_param (exoid, "n", &num_nod_vars);
  654. printf ("\nafter ex_get_var_param, error = %3d\n", error);
  655. for (i=0; i<num_nod_vars; i++)
  656. {
  657. var_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
  658. }
  659. error = ex_get_var_names (exoid, "n", num_nod_vars, var_names);
  660. printf ("\nafter ex_get_var_names, error = %3d\n", error);
  661. printf ("There are %2d nodal variables; their names are :\n", num_nod_vars);
  662. for (i=0; i<num_nod_vars; i++)
  663. {
  664. printf (" '%s'\n", var_names[i]);
  665. free(var_names[i]);
  666. }
  667. }
  668. /* read element variables parameters and names */
  669. num_ele_vars = 0;
  670. if (num_elem > 0) {
  671. error = ex_get_var_param (exoid, "e", &num_ele_vars);
  672. printf ("\nafter ex_get_var_param, error = %3d\n", error);
  673. for (i=0; i<num_ele_vars; i++)
  674. {
  675. var_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
  676. }
  677. error = ex_get_var_names (exoid, "e", num_ele_vars, var_names);
  678. printf ("\nafter ex_get_var_names, error = %3d\n", error);
  679. printf ("There are %2d element variables; their names are :\n",
  680. num_ele_vars);
  681. for (i=0; i<num_ele_vars; i++)
  682. {
  683. printf (" '%s'\n", var_names[i]);
  684. free(var_names[i]);
  685. }
  686. /* read element variable truth table */
  687. if (num_ele_vars > 0) {
  688. truth_tab = (int *) calloc ((num_elem_blk*num_ele_vars), sizeof(int));
  689. error = ex_get_elem_var_tab (exoid, num_elem_blk, num_ele_vars, truth_tab);
  690. printf ("\nafter ex_get_elem_var_tab, error = %3d\n", error);
  691. printf ("This is the element variable truth table:\n");
  692. k = 0;
  693. for (i=0; i<num_elem_blk*num_ele_vars; i++)
  694. {
  695. printf ("%2d\n", truth_tab[k++]);
  696. }
  697. free (truth_tab);
  698. }
  699. }
  700. /* read nodeset variables parameters and names */
  701. num_nset_vars = 0;
  702. if (num_node_sets > 0) {
  703. error = ex_get_var_param (exoid, "m", &num_nset_vars);
  704. printf ("\nafter ex_get_var_param, error = %3d\n", error);
  705. if (num_nset_vars > 0) {
  706. for (i=0; i<num_nset_vars; i++)
  707. {
  708. var_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
  709. }
  710. error = ex_get_var_names (exoid, "m", num_nset_vars, var_names);
  711. printf ("\nafter ex_get_var_names, error = %3d\n", error);
  712. printf ("There are %2d nodeset variables; their names are :\n",
  713. num_nset_vars);
  714. for (i=0; i<num_nset_vars; i++)
  715. {
  716. printf (" '%s'\n", var_names[i]);
  717. free(var_names[i]);
  718. }
  719. /* read nodeset variable truth table */
  720. if (num_nset_vars > 0) {
  721. truth_tab = (int *) calloc ((num_node_sets*num_nset_vars), sizeof(int));
  722. error = ex_get_nset_var_tab (exoid, num_node_sets, num_nset_vars, truth_tab);
  723. printf ("\nafter ex_get_nset_var_tab, error = %3d\n", error);
  724. printf ("This is the nodeset variable truth table:\n");
  725. k = 0;
  726. for (i=0; i<num_node_sets*num_nset_vars; i++)
  727. {
  728. printf ("%2d\n", truth_tab[k++]);
  729. }
  730. free (truth_tab);
  731. }
  732. }
  733. }
  734. /* read sideset variables parameters and names */
  735. num_sset_vars = 0;
  736. if (num_side_sets > 0) {
  737. error = ex_get_var_param (exoid, "s", &num_sset_vars);
  738. printf ("\nafter ex_get_var_param, error = %3d\n", error);
  739. if (num_sset_vars > 0) {
  740. for (i=0; i<num_sset_vars; i++)
  741. {
  742. var_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
  743. }
  744. error = ex_get_var_names (exoid, "s", num_sset_vars, var_names);
  745. printf ("\nafter ex_get_var_names, error = %3d\n", error);
  746. printf ("There are %2d sideset variables; their names are :\n",
  747. num_sset_vars);
  748. for (i=0; i<num_sset_vars; i++)
  749. {
  750. printf (" '%s'\n", var_names[i]);
  751. free(var_names[i]);
  752. }
  753. /* read sideset variable truth table */
  754. if (num_sset_vars > 0) {
  755. truth_tab = (int *) calloc ((num_side_sets*num_sset_vars), sizeof(int));
  756. error = ex_get_sset_var_tab (exoid, num_side_sets, num_sset_vars, truth_tab);
  757. printf ("\nafter ex_get_sset_var_tab, error = %3d\n", error);
  758. printf ("This is the sideset variable truth table:\n");
  759. k = 0;
  760. for (i=0; i<num_side_sets*num_sset_vars; i++)
  761. {
  762. printf ("%2d\n", truth_tab[k++]);
  763. }
  764. free (truth_tab);
  765. }
  766. }
  767. }
  768. /* determine how many time steps are stored */
  769. error = ex_inquire (exoid, EX_INQ_TIME, &num_time_steps, &fdum, cdum);
  770. printf ("\nafter ex_inquire, error = %3d\n", error);
  771. printf ("There are %2d time steps in the database.\n", num_time_steps);
  772. /* read time value at one time step */
  773. time_step = 3;
  774. error = ex_get_time (exoid, time_step, &time_value);
  775. printf ("\nafter ex_get_time, error = %3d\n", error);
  776. printf ("time value at time step %2d = %5.3f\n", time_step, time_value);
  777. /* read time values at all time steps */
  778. time_values = (float *) calloc (num_time_steps, sizeof(float));
  779. error = ex_get_all_times (exoid, time_values);
  780. printf ("\nafter ex_get_all_times, error = %3d\n", error);
  781. printf ("time values at all time steps are:\n");
  782. for (i=0; i<num_time_steps; i++) printf ("%5.3f\n", time_values[i]);
  783. free (time_values);
  784. /* read all global variables at one time step */
  785. var_values = (float *) calloc (num_glo_vars, sizeof(float));
  786. error = ex_get_glob_vars (exoid, time_step, num_glo_vars, var_values);
  787. printf ("\nafter ex_get_glob_vars, error = %3d\n", error);
  788. printf ("global variable values at time step %2d\n", time_step);
  789. for (i=0; i<num_glo_vars; i++) printf ("%5.3f\n", var_values[i]);
  790. free (var_values);
  791. /* read a single global variable through time */
  792. var_index = 1;
  793. beg_time = 1;
  794. end_time = -1;
  795. var_values = (float *) calloc (num_time_steps, sizeof(float));
  796. error = ex_get_glob_var_time (exoid, var_index, beg_time, end_time,
  797. var_values);
  798. printf ("\nafter ex_get_glob_var_time, error = %3d\n", error);
  799. printf ("global variable %2d values through time:\n", var_index);
  800. for (i=0; i<num_time_steps; i++) printf ("%5.3f\n", var_values[i]);
  801. free (var_values);
  802. /* read a nodal variable at one time step */
  803. if (num_nodes > 0) {
  804. var_values = (float *) calloc (num_nodes, sizeof(float));
  805. error = ex_get_nodal_var (exoid, time_step, var_index, num_nodes,
  806. var_values);
  807. printf ("\nafter ex_get_nodal_var, error = %3d\n", error);
  808. printf ("nodal variable %2d values at time step %2d\n", var_index,
  809. time_step);
  810. for (i=0; i<num_nodes; i++) printf ("%5.3f\n", var_values[i]);
  811. free (var_values);
  812. /* read a nodal variable through time */
  813. var_values = (float *) calloc (num_time_steps, sizeof(float));
  814. node_num = 1;
  815. error = ex_get_nodal_var_time (exoid, var_index, node_num, beg_time,
  816. end_time, var_values);
  817. printf ("\nafter ex_get_nodal_var_time, error = %3d\n", error);
  818. printf ("nodal variable %2d values for node %2d through time:\n", var_index,
  819. node_num);
  820. for (i=0; i<num_time_steps; i++) printf ("%5.3f\n", var_values[i]);
  821. free (var_values);
  822. }
  823. /* read an element variable at one time step */
  824. if (num_elem_blk > 0) {
  825. ids = (int *) calloc(num_elem_blk, sizeof(int));
  826. error = ex_get_elem_blk_ids (exoid, ids);
  827. printf ("\n after ex_get_elem_blk_ids, error = %3d\n", error);
  828. for (i=0; i<num_elem_blk; i++)
  829. {
  830. if (num_elem_in_block[i] > 0) {
  831. var_values = (float *) calloc (num_elem_in_block[i], sizeof(float));
  832. error = ex_get_elem_var (exoid, time_step, var_index, ids[i],
  833. num_elem_in_block[i], var_values);
  834. printf ("\nafter ex_get_elem_var, error = %3d\n", error);
  835. if (!error)
  836. {
  837. printf
  838. ("element variable %2d values of element block %2d at time step %2d\n",
  839. var_index, ids[i], time_step);
  840. for (j=0; j<num_elem_in_block[i]; j++)
  841. printf ("%5.3f\n", var_values[j]);
  842. }
  843. free (var_values);
  844. }
  845. }
  846. free (num_elem_in_block);
  847. free(ids);
  848. }
  849. /* read an element variable through time */
  850. if (num_ele_vars > 0) {
  851. var_values = (float *) calloc (num_time_steps, sizeof(float));
  852. var_index = 2;
  853. elem_num = 2;
  854. error = ex_get_elem_var_time (exoid, var_index, elem_num, beg_time,
  855. end_time, var_values);
  856. printf ("\nafter ex_get_elem_var_time, error = %3d\n", error);
  857. printf ("element variable %2d values for element %2d through time:\n",
  858. var_index, elem_num);
  859. for (i=0; i<num_time_steps; i++) printf ("%5.3f\n", var_values[i]);
  860. free (var_values);
  861. }
  862. /* read a sideset variable at one time step */
  863. if (num_sset_vars > 0) {
  864. ids = (int *) calloc(num_side_sets, sizeof(int));
  865. error = ex_get_side_set_ids (exoid, ids);
  866. printf ("\n after ex_get_side_set_ids, error = %3d\n", error);
  867. for (i=0; i<num_side_sets; i++)
  868. {
  869. var_values = (float *) calloc (num_elem_per_set[i], sizeof(float));
  870. error = ex_get_sset_var (exoid, time_step, var_index, ids[i],
  871. num_elem_per_set[i], var_values);
  872. printf ("\nafter ex_get_sset_var, error = %3d\n", error);
  873. if (!error)
  874. {
  875. printf
  876. ("sideset variable %2d values of sideset %2d at time step %2d\n",
  877. var_index, ids[i], time_step);
  878. for (j=0; j<num_elem_per_set[i]; j++)
  879. printf ("%5.3f\n", var_values[j]);
  880. }
  881. free (var_values);
  882. }
  883. free (num_elem_per_set);
  884. free(ids);
  885. }
  886. /* read a nodeset variable at one time step */
  887. if (num_nset_vars > 0) {
  888. ids = (int *) calloc(num_node_sets, sizeof(int));
  889. error = ex_get_node_set_ids (exoid, ids);
  890. printf ("\n after ex_get_node_set_ids, error = %3d\n", error);
  891. for (i=0; i<num_node_sets; i++)
  892. {
  893. var_values = (float *) calloc (num_nodes_per_set[i], sizeof(float));
  894. error = ex_get_nset_var (exoid, time_step, var_index, ids[i],
  895. num_nodes_per_set[i], var_values);
  896. printf ("\nafter ex_get_nset_var, error = %3d\n", error);
  897. if (!error)
  898. {
  899. printf
  900. ("nodeset variable %2d values of nodeset %2d at time step %2d\n",
  901. var_index, ids[i], time_step);
  902. for (j=0; j<num_nodes_per_set[i]; j++)
  903. printf ("%5.3f\n", var_values[j]);
  904. }
  905. free (var_values);
  906. }
  907. free(ids);
  908. }
  909. if (num_node_sets > 0)
  910. free (num_nodes_per_set);
  911. for (i=0; i<num_elem_blk; i++) {
  912. free(elem_type[i]);
  913. }
  914. error = ex_close (exoid);
  915. printf ("\nafter ex_close, error = %3d\n", error);
  916. return 0;
  917. }