PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/vijaysm/libmesh
C | 455 lines | 270 code | 107 blank | 78 comment | 28 complexity | 3a43af111aca7198ca463da61d665be6 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. * testrdwt - test reading from one ExodusII file and writing to another
  38. * ExodusII file open concurrently
  39. *
  40. * author - Sandia National Laboratories
  41. * Larry A. Schoof - Original
  42. *
  43. * environment - UNIX
  44. *
  45. * entry conditions -
  46. *
  47. * exit conditions -
  48. *
  49. * revision history -
  50. *
  51. * This is a test program for the C binding of the EXODUS II
  52. * database read and write routines. It tests reading from an open EXODUSII
  53. * file and writing to another concurrently opened EXODUSII file.
  54. *
  55. *
  56. *****************************************************************************/
  57. #include <stdlib.h>
  58. #include <stdio.h>
  59. #include "exodusII.h"
  60. #include "netcdf.h"
  61. int main (int argc, char **argv)
  62. {
  63. int exoid, exoid2, num_dim, num_nodes, num_elem, num_elem_blk;
  64. int num_elem_in_block, num_node_sets, num_nodes_per_elem, num_attr;
  65. int num_side_sets, error;
  66. int i, j;
  67. int *elem_map, *connect, *node_list, *node_ctr_list, *elem_list, *side_list;
  68. int *ids;
  69. int num_nodes_in_set, num_elem_in_set;
  70. int num_sides_in_set, num_df_in_set;
  71. int num_qa_rec, num_info;
  72. int CPU_word_size,IO_word_size;
  73. int num_props, prop_value, *prop_values;
  74. float *x, *y, *z;
  75. float *dist_fact;
  76. float version, fdum;
  77. char *coord_names[3], *qa_record[2][4], *info[3];
  78. char title[MAX_LINE_LENGTH+1], elem_type[MAX_STR_LENGTH+1];
  79. char *prop_names[3];
  80. char *cdum = 0;
  81. /* Specify compute and i/o word size */
  82. CPU_word_size = 0; /* sizeof(float) */
  83. IO_word_size = 4; /* float */
  84. /* open EXODUS II file for reading */
  85. ex_opts (EX_VERBOSE | EX_ABORT);
  86. exoid = ex_open ("test.exo", /* filename path */
  87. EX_READ, /* access mode */
  88. &CPU_word_size, /* CPU float word size in bytes */
  89. &IO_word_size, /* I/O float word size in bytes */
  90. &version); /* returned version number */
  91. printf ("after ex_open for test.exo\n");
  92. printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);
  93. /* create EXODUS II file for writing */
  94. exoid2= ex_create ("test2.exo", /* filename path */
  95. EX_CLOBBER, /* create mode */
  96. &CPU_word_size, /* CPU float word size in bytes */
  97. &IO_word_size); /* I/O float word size in bytes */
  98. printf ("after ex_create for test2.exo, exoid = %d\n", exoid2);
  99. /* ncopts = NC_VERBOSE; */
  100. /* read initialization parameters */
  101. error = ex_get_init (exoid, title, &num_dim, &num_nodes, &num_elem,
  102. &num_elem_blk, &num_node_sets, &num_side_sets);
  103. printf ("after ex_get_init, error = %d\n", error);
  104. /* write initialization parameters */
  105. error = ex_put_init (exoid2, title, num_dim, num_nodes, num_elem,
  106. num_elem_blk, num_node_sets, num_side_sets);
  107. printf ("after ex_put_init, error = %d\n", error);
  108. /* read nodal coordinate values */
  109. x = (float *) calloc(num_nodes, sizeof(float));
  110. y = (float *) calloc(num_nodes, sizeof(float));
  111. if (num_dim >= 3)
  112. z = (float *) calloc(num_nodes, sizeof(float));
  113. else
  114. z = 0;
  115. error = ex_get_coord (exoid, x, y, z);
  116. printf ("\nafter ex_get_coord, error = %3d\n", error);
  117. /* write nodal coordinate values */
  118. error = ex_put_coord (exoid2, x, y, z);
  119. printf ("after ex_put_coord, error = %d\n", error);
  120. free (x);
  121. free (y);
  122. if (num_dim >= 3)
  123. free (z);
  124. /* read nodal coordinate names */
  125. for (i=0; i<num_dim; i++)
  126. {
  127. coord_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
  128. }
  129. error = ex_get_coord_names (exoid, coord_names);
  130. printf ("\nafter ex_get_coord_names, error = %3d\n", error);
  131. /* write nodal coordinate names */
  132. error = ex_put_coord_names (exoid2, coord_names);
  133. printf ("after ex_put_coord_names, error = %d\n", error);
  134. for (i=0; i<num_dim; i++) {
  135. free(coord_names[i]);
  136. }
  137. /* read element order map */
  138. elem_map = (int *) calloc(num_elem, sizeof(int));
  139. error = ex_get_map (exoid, elem_map);
  140. printf ("\nafter ex_get_map, error = %3d\n", error);
  141. /* write element order map */
  142. error = ex_put_map (exoid2, elem_map);
  143. printf ("after ex_put_map, error = %d\n", error);
  144. free (elem_map);
  145. /* read and write element block parameters and element connectivity */
  146. ids = (int *) calloc(num_elem_blk, sizeof(int));
  147. error = ex_get_elem_blk_ids (exoid, ids);
  148. printf ("\nafter ex_get_elem_blk_ids, error = %3d\n", error);
  149. for (i=0; i<num_elem_blk; i++)
  150. {
  151. error = ex_get_elem_block (exoid, ids[i], elem_type,
  152. &num_elem_in_block,
  153. &num_nodes_per_elem, &num_attr);
  154. printf ("\nafter ex_get_elem_block, error = %d\n", error);
  155. error = ex_put_elem_block (exoid2, ids[i], elem_type, num_elem_in_block,
  156. num_nodes_per_elem, num_attr);
  157. printf ("after ex_put_elem_block, error = %d\n", error);
  158. connect = (int *) calloc((num_nodes_per_elem * num_elem_in_block),
  159. sizeof(int));
  160. error = ex_get_elem_conn (exoid, ids[i], connect);
  161. printf ("\nafter ex_get_elem_conn, error = %d\n", error);
  162. error = ex_put_elem_conn (exoid2, ids[i], connect);
  163. printf ("after ex_put_elem_conn, error = %d\n", error);
  164. free (connect);
  165. }
  166. /* read and write element block properties */
  167. error = ex_inquire (exoid, EX_INQ_EB_PROP, &num_props, &fdum, cdum);
  168. printf ("\nafter ex_inquire, error = %d\n", error);
  169. for (i=0; i<num_props; i++)
  170. {
  171. prop_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
  172. }
  173. error = ex_get_prop_names(exoid,EX_ELEM_BLOCK,prop_names);
  174. printf ("after ex_get_prop_names, error = %d\n", error);
  175. error = ex_put_prop_names(exoid2,EX_ELEM_BLOCK,num_props,prop_names);
  176. printf ("after ex_put_prop_names, error = %d\n", error);
  177. for (i=0; i<num_props; i++)
  178. {
  179. for (j=0; j<num_elem_blk; j++)
  180. {
  181. error = ex_get_prop(exoid, EX_ELEM_BLOCK, ids[j], prop_names[i],
  182. &prop_value);
  183. printf ("after ex_get_prop, error = %d\n", error);
  184. if (i>0) { /* first property is the ID which is already stored */
  185. error = ex_put_prop(exoid2, EX_ELEM_BLOCK, ids[j], prop_names[i],
  186. prop_value);
  187. printf ("after ex_put_prop, error = %d\n", error);
  188. }
  189. }
  190. }
  191. for (i=0; i<num_props; i++)
  192. free(prop_names[i]);
  193. free (ids);
  194. /* read and write individual node sets */
  195. ids = (int *) calloc(num_node_sets, sizeof(int));
  196. error = ex_get_node_set_ids (exoid, ids);
  197. printf ("\nafter ex_get_node_set_ids, error = %3d\n", error);
  198. for (i=0; i<num_node_sets; i++)
  199. {
  200. error = ex_get_node_set_param (exoid, ids[i],
  201. &num_nodes_in_set, &num_df_in_set);
  202. printf ("\nafter ex_get_node_set_param, error = %3d\n", error);
  203. error = ex_put_node_set_param (exoid2, ids[i], num_nodes_in_set,
  204. num_df_in_set);
  205. printf ("after ex_put_node_set_param, error = %d\n", error);
  206. node_list = (int *) calloc(num_nodes_in_set, sizeof(int));
  207. dist_fact = (float *) calloc(num_nodes_in_set, sizeof(float));
  208. error = ex_get_node_set (exoid, ids[i], node_list);
  209. printf ("\nafter ex_get_node_set, error = %3d\n", error);
  210. error = ex_put_node_set (exoid2, ids[i], node_list);
  211. printf ("after ex_put_node_set, error = %d\n", error);
  212. if (num_df_in_set > 0)
  213. {
  214. error = ex_get_node_set_dist_fact (exoid, ids[i], dist_fact);
  215. printf ("\nafter ex_get_node_set_dist_fact, error = %3d\n", error);
  216. error = ex_put_node_set_dist_fact (exoid2, ids[i], dist_fact);
  217. printf ("after ex_put_node_set, error = %d\n", error);
  218. }
  219. free (node_list);
  220. free (dist_fact);
  221. }
  222. free(ids);
  223. /* read node set properties */
  224. error = ex_inquire (exoid, EX_INQ_NS_PROP, &num_props, &fdum, cdum);
  225. printf ("\nafter ex_inquire, error = %d\n", error);
  226. for (i=0; i<num_props; i++)
  227. {
  228. prop_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
  229. }
  230. prop_values = (int *) calloc (num_node_sets, sizeof(int));
  231. error = ex_get_prop_names(exoid,EX_NODE_SET,prop_names);
  232. printf ("after ex_get_prop_names, error = %d\n", error);
  233. error = ex_put_prop_names(exoid2,EX_NODE_SET,num_props,prop_names);
  234. printf ("after ex_put_prop_names, error = %d\n", error);
  235. for (i=0; i<num_props; i++)
  236. {
  237. error = ex_get_prop_array(exoid, EX_NODE_SET, prop_names[i],
  238. prop_values);
  239. printf ("after ex_get_prop_array, error = %d\n", error);
  240. error = ex_put_prop_array(exoid2, EX_NODE_SET, prop_names[i], prop_values);
  241. printf ("after ex_put_prop_array, error = %d\n", error);
  242. }
  243. for (i=0; i<num_props; i++)
  244. free(prop_names[i]);
  245. free(prop_values);
  246. /* read and write individual side sets */
  247. ids = (int *) calloc(num_side_sets, sizeof(int));
  248. error = ex_get_side_set_ids (exoid, ids);
  249. printf ("\nafter ex_get_side_set_ids, error = %3d\n", error);
  250. for (i=0; i<num_side_sets; i++)
  251. {
  252. error = ex_get_side_set_param (exoid, ids[i], &num_sides_in_set,
  253. &num_df_in_set);
  254. printf ("\nafter ex_get_side_set_param, error = %3d\n", error);
  255. error = ex_put_side_set_param (exoid2, ids[i], num_sides_in_set,
  256. num_df_in_set);
  257. printf ("after ex_put_side_set_param, error = %d\n", error);
  258. /* Note: The # of elements is same as # of sides! */
  259. num_elem_in_set = num_sides_in_set;
  260. elem_list = (int *) calloc(num_elem_in_set, sizeof(int));
  261. side_list = (int *) calloc(num_sides_in_set, sizeof(int));
  262. node_ctr_list = (int *) calloc(num_elem_in_set, sizeof(int));
  263. node_list = (int *) calloc(num_elem_in_set*21, sizeof(int));
  264. dist_fact = (float *) calloc(num_df_in_set, sizeof(float));
  265. error = ex_get_side_set (exoid, ids[i], elem_list, side_list);
  266. printf ("\nafter ex_get_side_set, error = %3d\n", error);
  267. error = ex_put_side_set (exoid2, ids[i], elem_list, side_list);
  268. printf ("after ex_put_side_set, error = %d\n", error);
  269. error = ex_get_side_set_node_list (exoid, ids[i], node_ctr_list,
  270. node_list);
  271. printf ("\nafter ex_get_side_set_node_list, error = %3d\n", error);
  272. if (num_df_in_set > 0)
  273. {
  274. error = ex_get_side_set_dist_fact (exoid, ids[i], dist_fact);
  275. printf ("\nafter ex_get_side_set_dist_fact, error = %3d\n", error);
  276. error = ex_put_side_set_dist_fact (exoid2, ids[i], dist_fact);
  277. printf ("after ex_put_side_set_dist_fact, error = %d\n", error);
  278. }
  279. free (elem_list);
  280. free (side_list);
  281. free (node_ctr_list);
  282. free (node_list);
  283. free (dist_fact);
  284. }
  285. /* read side set properties */
  286. error = ex_inquire (exoid, EX_INQ_SS_PROP, &num_props, &fdum, cdum);
  287. printf ("\nafter ex_inquire, error = %d\n", error);
  288. for (i=0; i<num_props; i++)
  289. {
  290. prop_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
  291. }
  292. error = ex_get_prop_names(exoid,EX_SIDE_SET,prop_names);
  293. printf ("after ex_get_prop_names, error = %d\n", error);
  294. for (i=0; i<num_props; i++)
  295. {
  296. for (j=0; j<num_side_sets; j++)
  297. {
  298. error = ex_get_prop(exoid, EX_SIDE_SET, ids[j], prop_names[i],
  299. &prop_value);
  300. printf ("after ex_get_prop, error = %d\n", error);
  301. if (i>0) { /* first property is ID so it is already stored */
  302. error = ex_put_prop(exoid2, EX_SIDE_SET, ids[j], prop_names[i],
  303. prop_value);
  304. printf ("after ex_put_prop, error = %d\n", error);
  305. }
  306. }
  307. }
  308. for (i=0; i<num_props; i++)
  309. free(prop_names[i]);
  310. free (ids);
  311. /* read and write QA records */
  312. ex_inquire (exoid, EX_INQ_QA, &num_qa_rec, &fdum, cdum);
  313. for (i=0; i<num_qa_rec; i++) {
  314. for (j=0; j<4; j++) {
  315. qa_record[i][j] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
  316. }
  317. }
  318. error = ex_get_qa (exoid, qa_record);
  319. printf ("\nafter ex_get_qa, error = %3d\n", error);
  320. error = ex_put_qa (exoid2, num_qa_rec, qa_record);
  321. printf ("after ex_put_qa, error = %d\n", error);
  322. for (i=0; i<num_qa_rec; i++) {
  323. for (j=0; j<4; j++) {
  324. free(qa_record[i][j]);
  325. }
  326. }
  327. /* read and write information records */
  328. error = ex_inquire (exoid, EX_INQ_INFO, &num_info, &fdum, cdum);
  329. printf ("\nafter ex_inquire, error = %3d\n", error);
  330. for (i=0; i<num_info; i++)
  331. {
  332. info[i] = (char *) calloc ((MAX_LINE_LENGTH+1), sizeof(char));
  333. }
  334. error = ex_get_info (exoid, info);
  335. printf ("\nafter ex_get_info, error = %3d\n", error);
  336. error = ex_put_info (exoid2, num_info, info);
  337. printf ("after ex_put_info, error = %d\n", error);
  338. for (i=0; i<num_info; i++)
  339. {
  340. free(info[i]);
  341. }
  342. /* close the EXODUS files */
  343. error = ex_close (exoid);
  344. printf ("after ex_close, error = %d\n", error);
  345. error = ex_close (exoid2);
  346. printf ("after ex_close (2), error = %d\n", error);
  347. return 0;
  348. }