PageRenderTime 57ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

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

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