PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

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