PageRenderTime 51ms CodeModel.GetById 2ms app.highlight 42ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/vijaysm/libmesh
C | 920 lines | 477 code | 205 blank | 238 comment | 17 complexity | 89c8227b24739c1606147e5c2b2bceab MD5 | raw file
  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* testwt1 - test write an ExodusII database file
 38*
 39* author - Sandia National Laboratories
 40*          Larry A. Schoof - Original
 41*          Vic Yarberry    - Added headers and error logging
 42*               7/7/93          Modified for use with Exodus 2.00
 43*
 44*          
 45* environment - UNIX
 46*
 47* entry conditions - 
 48*
 49* exit conditions - 
 50*
 51* revision history - 
 52*
 53*  This is a test program for the C binding of the EXODUS II 
 54*  database write routines.
 55*
 56*
 57*****************************************************************************/
 58
 59
 60#include <stdlib.h>
 61#include <stdio.h>
 62#include "netcdf.h"
 63#include "exodusII.h"
 64
 65int main (int argc, char **argv)
 66{
 67   int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
 68   int num_elem_in_block[10], num_nodes_per_elem[10], num_attr[10];
 69   int num_node_sets, num_side_sets, error;
 70   int num_node_maps, num_elem_maps;
 71   int i, j, k, m, *elem_map, *connect, *node_map;
 72   int node_list[100],elem_list[100],side_list[100];
 73   int id, ebids[10], ids[10];
 74   int num_nodes_per_set[10], num_elem_per_set[10];
 75   int num_df_per_set[10];
 76   int df_ind[10], node_ind[10], elem_ind[10];
 77   int num_qa_rec, num_info;
 78   int num_glo_vars, num_nod_vars, num_ele_vars;
 79   int *truth_tab;
 80   int whole_time_step, num_time_steps;
 81   int CPU_word_size,IO_word_size;
 82   int prop_array[2];
 83
 84   float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
 85   float time_value;
 86   float x[100], y[100], z[100];
 87   float attrib[100], dist_fact[100];
 88   char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
 89   char *emap_names[2];
 90   char *prop_names[2];
 91
 92
 93   ex_opts (EX_VERBOSE | EX_ABORT);
 94
 95/* Specify compute and i/o word size */
 96
 97   CPU_word_size = 0;                   /* sizeof(float) */
 98   IO_word_size = 4;                    /* (4 bytes) */
 99
100/* create EXODUS II file */
101
102   exoid = ex_create ("test.exo",       /* filename path */
103                       EX_CLOBBER,      /* create mode */
104                       &CPU_word_size,  /* CPU float word size in bytes */
105                       &IO_word_size);  /* I/O float word size in bytes */
106   printf ("after ex_create for test.exo, exoid = %d\n", exoid);
107   printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);
108
109/*   ncopts = NC_VERBOSE;  */
110
111/* initialize file with parameters */
112
113   num_dim = 3;
114   num_nodes = 28;
115   num_elem = 8;
116   num_elem_blk = 7;
117   num_node_sets = 2;
118   num_side_sets = 5;
119   /* num_side_sets = 6; Uncomment to test NULL side sets */
120
121   error = ex_put_init (exoid, "This is testwt1", num_dim, num_nodes, num_elem,
122                        num_elem_blk, num_node_sets, num_side_sets);
123
124   printf ("after ex_put_init, error = %d\n", error);
125
126/* write nodal coordinates values and names to database */
127
128/* Quad #1 */
129   x[0] = 0.0; y[0] = 0.0; z[0] = 0.0;
130   x[1] = 1.0; y[1] = 0.0; z[1] = 0.0;
131   x[2] = 1.0; y[2] = 1.0; z[2] = 0.0;
132   x[3] = 0.0; y[3] = 1.0; z[3] = 0.0;
133
134/* Quad #2 */
135   x[4]  =  1.0; y[4]  =  0.0; z[4]  =  0.0;
136   x[5]  =  2.0; y[5]  =  0.0; z[5]  =  0.0;
137   x[6]  =  2.0; y[6]  =  1.0; z[6]  =  0.0;
138   x[7]  =  1.0; y[7]  =  1.0; z[7]  =  0.0;
139
140/* Hex #1 */
141   x[8]  =  0.0; y[8]  =  0.0; z[8]  =  0.0;
142   x[9]  = 10.0; y[9]  =  0.0; z[9]  =  0.0;
143   x[10] = 10.0; y[10] =  0.0; z[10] =-10.0;
144   x[11] =  1.0; y[11] =  0.0; z[11] =-10.0;
145   x[12] =  1.0; y[12] = 10.0; z[12] =  0.0;
146   x[13] = 10.0; y[13] = 10.0; z[13] =  0.0;
147   x[14] = 10.0; y[14] = 10.0; z[14] =-10.0;
148   x[15] =  1.0; y[15] = 10.0; z[15] =-10.0;
149
150/* Tetra #1 */
151   x[16] =  0.0; y[16] =  0.0; z[16] =  0.0;
152   x[17] =  1.0; y[17] =  0.0; z[17] =  5.0;
153   x[18] = 10.0; y[18] =  0.0; z[18] =  2.0;
154   x[19] =  7.0; y[19] =  5.0; z[19] =  3.0;
155
156/* Circle #1 */
157   x[20] = 100.0; y[20] = 100.0; z[20] = 0.0;
158
159/* Sphere #1 */
160   x[21] = 50.0; y[21] = 50.0; z[21] = 20.0;
161
162/* Wedge #1 */
163   x[22] =  3.0; y[22] =  0.0; z[22] =  6.0;
164   x[23] =  6.0; y[23] =  0.0; z[23] =  0.0;
165   x[24] =  0.0; y[24] =  0.0; z[24] =  0.0;
166   x[25] =  3.0; y[25] =  2.0; z[25] =  6.0;
167   x[26] =  6.0; y[26] =  2.0; z[26] =  2.0;
168   x[27] =  0.0; y[27] =  2.0; z[27] =  0.0;
169
170   error = ex_put_coord (exoid, x, y, z);
171   printf ("after ex_put_coord, error = %d\n", error);
172
173
174   coord_names[0] = "xcoor";
175   coord_names[1] = "ycoor";
176   coord_names[2] = "zcoor";
177
178   error = ex_put_coord_names (exoid, coord_names);
179   printf ("after ex_put_coord_names, error = %d\n", error);
180
181
182/* write node and element map parameters */
183
184   num_node_maps = 1;
185   num_elem_maps = 2;
186
187   error = ex_put_map_param (exoid, num_node_maps, num_elem_maps);
188
189   printf ("after ex_put_map_param, error = %d\n", error);
190
191/* write element map properties */
192
193   prop_names[0] = "ORDER";
194   prop_names[1] = "NUMBER";
195   error = ex_put_prop_names(exoid,EX_ELEM_MAP,2,prop_names);
196   printf ("after ex_put_prop_names, error = %d\n", error);
197
198/* write element order map */
199
200   elem_map = (int *) calloc(num_elem, sizeof(int));
201
202   for (i=1; i<=num_elem; i++)
203   {
204      elem_map[i-1] = i;
205   }
206
207   id = 111;
208   error = ex_put_elem_map (exoid, id, elem_map);
209   printf ("after ex_put_elem_map, error = %d\n", error);
210
211   free (elem_map);
212
213   error = ex_put_prop(exoid, EX_ELEM_MAP, id, "ORDER", 1);
214   printf ("after ex_put_prop, error = %d\n", error);
215
216/* write element numbering map */
217
218   elem_map = (int *) calloc(num_elem, sizeof(int));
219
220   for (i=1; i<=num_elem; i++)
221   {
222      elem_map[i-1] = i*2;
223   }
224
225   id = 222;
226   /* Output the map 1 element at a time... */
227   for (i=1; i <= num_elem; i++) {
228     error = ex_put_partial_elem_map (exoid, id, i, 1, &elem_map[i-1]);
229     printf ("after ex_put_partial_elem_map, error = %d\n", error);
230   }
231
232   free (elem_map);
233
234   error = ex_put_prop(exoid, EX_ELEM_MAP, id, "NUMBER", 1);
235   printf ("after ex_put_prop, error = %d\n", error);
236
237/* write element map names */
238   emap_names[0] = "Element_Map_111";
239   emap_names[1] = "Element_Map_222";
240
241   error = ex_put_names(exoid, EX_ELEM_MAP, emap_names);
242   printf ("after ex_put_names, error = %d\n", error);
243
244/* write node map properties */
245
246   prop_names[0] = "NUMBER";
247   error = ex_put_prop_names(exoid,EX_NODE_MAP,1,prop_names);
248   printf ("after ex_put_prop_names, error = %d\n", error);
249
250/* write node numbering map */
251
252   node_map = (int *) calloc(num_nodes, sizeof(int));
253
254   for (i=1; i<=num_nodes; i++)
255   {
256      node_map[i-1] = i*3;
257   }
258
259   id = 333;
260   error = ex_put_node_map (exoid, id, node_map);
261   printf ("after ex_put_node_map, error = %d\n", error);
262
263   error = ex_put_name(exoid, EX_NODE_MAP, id, "Node_Map_111");
264   printf ("after ex_put_name, error = %d\n", error);
265
266   free (node_map);
267
268   error = ex_put_prop(exoid, EX_NODE_MAP, id, "NUMBER", 1);
269   printf ("after ex_put_prop, error = %d\n", error);
270
271
272/* write element block parameters */
273
274   num_elem_in_block[0] = 1; /* element 1: Quad 1 */
275   num_elem_in_block[1] = 2; /* elements 2, 3: Quad 1 & 2 */
276   num_elem_in_block[2] = 1; /* element 4: Hex    */
277   num_elem_in_block[3] = 1; /* element 5: Tetra  */
278   num_elem_in_block[4] = 1; /* element 6: Circle */
279   num_elem_in_block[5] = 1; /* element 7: Sphere */
280   num_elem_in_block[6] = 1; /* element 8: Wedge  */
281
282   num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads  */
283   num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads  */
284   num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes  */
285   num_nodes_per_elem[3] = 4; /* elements in block #3 are 4-node tetras */
286   num_nodes_per_elem[4] = 1; /* elements in block #4 are 1-node circles */
287   num_nodes_per_elem[5] = 1; /* elements in block #5 are 1-node spheres */
288   num_nodes_per_elem[6] = 6; /* elements in block #6 are 6-node wedges */
289
290   ebids[0] = 10;
291   ebids[1] = 11;
292   ebids[2] = 12;
293   ebids[3] = 13;
294   ebids[4] = 14;
295   ebids[5] = 15;
296   ebids[6] = 16;
297
298   num_attr[0] = 3;
299   num_attr[1] = 3;
300   num_attr[2] = 3;
301   num_attr[3] = 3;
302   num_attr[4] = 3;
303   num_attr[5] = 3;
304   num_attr[6] = 3;
305
306   error = ex_put_elem_block (exoid, ebids[0], "quad", num_elem_in_block[0],
307                              num_nodes_per_elem[0], num_attr[0]);
308   printf ("after ex_put_elem_block, error = %d\n", error);
309
310   error = ex_put_elem_block (exoid, ebids[1], "quad", num_elem_in_block[1],
311                               num_nodes_per_elem[1], num_attr[1]);
312   printf ("after ex_put_elem_block, error = %d\n", error);
313
314   error = ex_put_elem_block (exoid, ebids[2], "hex", num_elem_in_block[2],
315                               num_nodes_per_elem[2], num_attr[2]);
316   printf ("after ex_put_elem_block, error = %d\n", error);
317
318   error = ex_put_elem_block (exoid, ebids[3], "tetra", num_elem_in_block[3],
319                               num_nodes_per_elem[3], num_attr[3]);
320   printf ("after ex_put_elem_block, error = %d\n", error);
321
322   error = ex_put_elem_block (exoid, ebids[4], "circle", num_elem_in_block[4],
323                               num_nodes_per_elem[4], num_attr[4]);
324   printf ("after ex_put_elem_block, error = %d\n", error);
325
326   error = ex_put_elem_block (exoid, ebids[5], "sphere", num_elem_in_block[5],
327                               num_nodes_per_elem[5], num_attr[5]);
328   printf ("after ex_put_elem_block, error = %d\n", error);
329
330   error = ex_put_elem_block (exoid, ebids[6], "wedge", num_elem_in_block[6],
331                               num_nodes_per_elem[6], num_attr[6]);
332   printf ("after ex_put_elem_block, error = %d\n", error);
333
334/* write element block properties */
335
336   prop_names[0] = "MATL";
337   prop_names[1] = "DENSITY";
338   error = ex_put_prop_names(exoid,EX_ELEM_BLOCK,2,prop_names);
339   printf ("after ex_put_prop_names, error = %d\n", error);
340
341   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], "MATL", 10);
342   printf ("after ex_put_prop, error = %d\n", error);
343   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], "MATL", 20);
344   printf ("after ex_put_prop, error = %d\n", error);
345   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], "MATL", 30);
346   printf ("after ex_put_prop, error = %d\n", error);
347   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[3], "MATL", 40);
348   printf ("after ex_put_prop, error = %d\n", error);
349   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[4], "MATL", 50);
350   printf ("after ex_put_prop, error = %d\n", error);
351   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[5], "MATL", 60);
352   printf ("after ex_put_prop, error = %d\n", error);
353   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[6], "MATL", 70);
354   printf ("after ex_put_prop, error = %d\n", error);
355
356/* write element connectivity */
357
358   connect = (int *) calloc(8, sizeof(int));
359   connect[0] = 1; connect[1] = 2; connect[2] = 3; connect[3] = 4;
360
361   error = ex_put_elem_conn (exoid, ebids[0], connect);
362   printf ("after ex_put_elem_conn, error = %d\n", error);
363
364   connect[0] = 1; connect[1] = 2; connect[2] = 3; connect[3] = 4;
365   connect[4] = 5; connect[5] = 6; connect[6] = 7; connect[7] = 8;
366
367   error = ex_put_elem_conn (exoid, ebids[1], connect);
368   printf ("after ex_put_elem_conn, error = %d\n", error);
369
370   connect[0] = 9; connect[1] = 10; connect[2] = 11; connect[3] = 12;
371   connect[4] = 13; connect[5] = 14; connect[6] = 15; connect[7] = 16;
372
373   error = ex_put_elem_conn (exoid, ebids[2], connect);
374   printf ("after ex_put_elem_conn, error = %d\n", error);
375
376   connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20;
377
378   error = ex_put_elem_conn (exoid, ebids[3], connect);
379   printf ("after ex_put_elem_conn, error = %d\n", error);
380
381   connect[0] = 21;
382
383   error = ex_put_elem_conn (exoid, ebids[4], connect);
384   printf ("after ex_put_elem_conn, error = %d\n", error);
385
386   connect[0] = 22;
387
388   error = ex_put_elem_conn (exoid, ebids[5], connect);
389   printf ("after ex_put_elem_conn, error = %d\n", error);
390
391   connect[0] = 23; connect[1] = 24; connect[2] = 25;
392   connect[3] = 26; connect[4] = 27; connect[5] = 28;
393
394   error = ex_put_elem_conn (exoid, ebids[6], connect);
395   printf ("after ex_put_elem_conn, error = %d\n", error);
396
397   free (connect);
398
399
400/* write element block attributes  (3 per block) */
401
402   attrib[0] = 1.0; attrib[1] = 2.0; attrib[2] = 3.0;
403   attrib[3] = 1.11; attrib[4] = 2.11; attrib[5] = 3.11;
404   attrib[6] = 1.12; attrib[7] = 2.12; attrib[8] = 3.12;
405   attrib[9] = 1.2; attrib[10] = 2.2; attrib[11] = 3.2;
406   attrib[12] = 1.3; attrib[13] = 2.3; attrib[14] = 3.3;
407   attrib[15] = 1.4; attrib[16] = 2.4; attrib[17] = 3.4;
408   attrib[18] = 1.5; attrib[19] = 2.5; attrib[20] = 3.5;
409   attrib[21] = 1.6; attrib[22] = 2.6; attrib[23] = 3.6;
410
411   error = ex_put_elem_attr (exoid, ebids[0], &attrib[0]);
412   printf ("after ex_put_elem_attr, error = %d\n", error);
413
414   error = ex_put_elem_attr (exoid, ebids[1], &attrib[3]);
415   printf ("after ex_put_elem_attr, error = %d\n", error);
416
417   error = ex_put_elem_attr (exoid, ebids[2], &attrib[9]);
418   printf ("after ex_put_elem_attr, error = %d\n", error);
419
420   error = ex_put_elem_attr (exoid, ebids[3], &attrib[12]);
421   printf ("after ex_put_elem_attr, error = %d\n", error);
422
423   error = ex_put_elem_attr (exoid, ebids[4], &attrib[15]);
424   printf ("after ex_put_elem_attr, error = %d\n", error);
425
426   error = ex_put_elem_attr (exoid, ebids[5], &attrib[18]);
427   printf ("after ex_put_elem_attr, error = %d\n", error);
428
429   error = ex_put_elem_attr (exoid, ebids[6], &attrib[21]);
430   printf ("after ex_put_elem_attr, error = %d\n", error);
431
432/* write individual node sets */
433
434   /* COMMENTED OUT ...
435
436   error = ex_put_node_set_param (exoid, 20, 5, 5);
437   printf ("after ex_put_node_set_param, error = %d\n", error);
438
439   node_list[0] = 10; node_list[1] = 11; node_list[2] = 12; 
440   node_list[3] = 13; node_list[4] = 14; 
441
442   dist_fact[0] = 1.0; dist_fact[1] = 2.0; dist_fact[2] = 3.0;
443   dist_fact[3] = 4.0; dist_fact[4] = 5.0;
444
445   error = ex_put_node_set (exoid, 20, node_list);
446   printf ("after ex_put_node_set, error = %d\n", error);
447   error = ex_put_node_set_dist_fact (exoid, 20, dist_fact);
448   printf ("after ex_put_node_set_dist_fact, error = %d\n", error);
449
450   error = ex_put_node_set_param (exoid, 21, 3, 3);
451   printf ("after ex_put_node_set_param, error = %d\n", error);
452
453   node_list[0] = 20; node_list[1] = 21; node_list[2] = 22; 
454
455   dist_fact[0] = 1.1; dist_fact[1] = 2.1; dist_fact[2] = 3.1;
456
457   error = ex_put_node_set (exoid, 21, node_list);
458   printf ("after ex_put_node_set, error = %d\n", error);
459   error = ex_put_node_set_dist_fact (exoid, 21, dist_fact);
460   printf ("after ex_put_node_set_dist_fact, error = %d\n", error);
461
462   error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4);
463   printf ("after ex_put_prop, error = %d\n", error);
464   error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5);
465   printf ("after ex_put_prop, error = %d\n", error);
466
467   prop_array[0] = 1000;
468   prop_array[1] = 2000;
469
470   error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
471   printf ("after ex_put_prop_array, error = %d\n", error);
472
473   END COMMENTED OUT SECTION */
474
475/* write concatenated node sets; this produces the same information as
476 * the above code which writes individual node sets
477 */
478
479/* THIS SECTION IS NOT COMMENTED OUT */
480
481   ids[0] = 20; ids[1] = 21;
482
483   num_nodes_per_set[0] = 5;
484   num_nodes_per_set[1] = 3;
485   /* num_nodes_per_set[1] = 0; Uncomment to test NULL node sets */
486
487   node_ind[0] = 0; node_ind[1] = 5;
488
489   node_list[0] = 10; node_list[1] = 11; node_list[2] = 12; 
490   node_list[3] = 13; node_list[4] = 14; 
491   node_list[5] = 20; node_list[6] = 21; node_list[7] = 22;
492
493   num_df_per_set[0] = 5; num_df_per_set[1] = 3;
494
495   df_ind[0] = 0; df_ind[1] = 5;
496
497   dist_fact[0] = 1.0; dist_fact[1] = 2.0; dist_fact[2] = 3.0; 
498   dist_fact[3] = 4.0; dist_fact[4] = 5.0; 
499   dist_fact[5] = 1.1; dist_fact[6] = 2.1; dist_fact[7] = 3.1;
500
501   error = ex_put_concat_node_sets (exoid, ids, num_nodes_per_set,
502                                    num_df_per_set, node_ind,
503                                    df_ind, node_list, dist_fact);
504   printf ("after ex_put_concat_node_sets, error = %d\n", error);
505
506   error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4);
507   printf ("after ex_put_prop, error = %d\n", error);
508   error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5);
509   printf ("after ex_put_prop, error = %d\n", error);
510
511   prop_array[0] = 1000;
512   prop_array[1] = 2000;
513
514   error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
515   printf ("after ex_put_prop_array, error = %d\n", error);
516
517   /* END NOT COMMENTED OUT SECTION */
518
519
520/* write individual side sets */
521
522   /* COMMENTED OUT SECTION ...
523
524   error = ex_put_side_set_param (exoid, 30, 2, 4);
525   printf ("after ex_put_side_set_param, error = %d\n", error);
526
527   elem_list[0] = 1; elem_list[1] = 1;
528
529   node_list[0] = 1; node_list[1] = 2;
530   node_list[2] = 5; node_list[3] = 6;
531
532   side_list[0] = 1; side_list[1] = 1;
533
534   dist_fact[0] = 30.0; dist_fact[1] = 30.1; dist_fact[2] = 30.2;
535   dist_fact[3] = 30.3;
536
537   error = ex_put_side_set (exoid, 30, elem_list, side_list);
538   printf ("after ex_put_side_set, error = %d\n", error);
539
540   error = ex_put_side_set_dist_fact (exoid, 30, dist_fact);
541   printf ("after ex_put_side_set_dist_fact, error = %d\n", error);
542
543
544   error = ex_put_side_set_param (exoid, 31, 2, 4);
545   printf ("after ex_put_side_set_param, error = %d\n", error);
546
547   elem_list[0] = 2; elem_list[1] = 2;
548
549   node_list[0] = 6; node_list[1] = 7;
550   node_list[2] = 7; node_list[3] = 8;
551
552   side_list[0] = 3; side_list[1] = 3;
553
554   dist_fact[0] = 31.0; dist_fact[1] = 31.1; dist_fact[2] = 31.2;
555   dist_fact[3] = 31.3;
556
557   error = ex_put_side_set (exoid, 31, elem_list, side_list);
558   printf ("after ex_put_side_set, error = %d\n", error);
559
560   error = ex_put_side_set_dist_fact (exoid, 31, dist_fact);
561   printf ("after ex_put_side_set_dist_fact, error = %d\n", error);
562
563   error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100);
564   printf ("after ex_put_prop, error = %d\n", error);
565
566   error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101);
567   printf ("after ex_put_prop, error = %d\n", error);
568
569   END COMMENTED OUT SECTION */
570
571/* write concatenated side sets; this produces the same information as
572 * the above code which writes individual side sets
573 */
574
575/* THIS SECTION IS NOT COMMENTED OUT */
576
577   ids[0] = 30;
578   ids[1] = 31;
579   ids[2] = 32;
580   ids[3] = 33;
581   ids[4] = 34;
582   ids[5] = 35;
583
584   /* side set #1  - quad */
585   node_list[0] = 8; node_list[1] = 5; elem_list[0] = 3;
586   node_list[2] = 6; node_list[3] = 7; elem_list[1] = 3;
587
588   /* side set #2  - quad/hex, spanning 2 element types  */
589   node_list[4] = 2; node_list[5] = 3; elem_list[2] = 1; 
590   node_list[6] = 7; node_list[7] = 8; elem_list[3] = 3;
591
592   /* side set #3  - hex */
593   node_list[ 8] =  9; node_list[ 9] = 12;
594   node_list[10] = 11; node_list[11] = 10; elem_list[4] = 4;
595
596   node_list[12] = 11; node_list[13] = 12;
597   node_list[14] = 16; node_list[15] = 15; elem_list[5] = 4;
598 
599   node_list[16] = 16; node_list[17] = 15;
600   node_list[18] = 11; node_list[19] = 12; elem_list[6] = 4;
601
602   node_list[20] = 10; node_list[21] = 11;
603   node_list[22] = 15; node_list[23] = 14; elem_list[7] = 4;
604
605   node_list[24] = 13; node_list[25] = 16;
606   node_list[26] = 12; node_list[27] =  9; elem_list[8] = 4;
607
608   node_list[28] = 14; node_list[29] = 13;
609   node_list[30] =  9; node_list[31] = 10; elem_list[9] = 4;
610
611   node_list[32] = 16; node_list[33] = 13;
612   node_list[34] = 14; node_list[35] = 15; elem_list[10] = 4;
613
614   /* side set #4  - tetras */
615   node_list[36] = 17; node_list[37] = 18;
616   node_list[38] = 20;                     elem_list[11] = 5;
617
618   node_list[39] = 18; node_list[40] = 19;
619   node_list[41] = 20;                     elem_list[12] = 5;
620
621   node_list[42] = 20; node_list[43] = 19;
622   node_list[44] = 17;                     elem_list[13] = 5;
623
624   node_list[45] = 19; node_list[46] = 18;
625   node_list[47] = 17;                     elem_list[14] = 5;
626
627   /* side set #5  - circle and sphere */
628   node_list[48] = 21;                     elem_list[15] = 6;
629   node_list[49] = 22;                     elem_list[16] = 7;
630
631   /* side set #6  - wedges */
632   node_list[50] = 27; node_list[51] = 26;
633   node_list[52] = 23; node_list[53] = 24; elem_list[17] = 8;
634
635   node_list[54] = 28; node_list[55] = 27;
636   node_list[56] = 24; node_list[57] = 25; elem_list[18] = 8;
637
638   node_list[58] = 28; node_list[59] = 25;
639   node_list[60] = 23; node_list[61] = 26; elem_list[19] = 8;
640
641   node_list[62] = 25; node_list[63] = 24;
642   node_list[64] = 23;                     elem_list[20] = 8;
643
644   node_list[65] = 26; node_list[66] = 27;
645   node_list[67] = 28;                     elem_list[21] = 8;
646
647   node_ind[0] = 0;
648   node_ind[1] = 4;
649   node_ind[2] = 8;
650   node_ind[3] = 36;
651   node_ind[4] = 47;
652   node_ind[5] = 49;
653
654   num_elem_per_set[0] = 2; /* two sides uses 2 elements */
655   num_elem_per_set[1] = 2;
656   num_elem_per_set[2] = 7;
657   num_elem_per_set[3] = 4;
658   num_elem_per_set[4] = 2;
659   num_elem_per_set[5] = 5;
660   /* num_elem_per_set[5] = 0; Uncomment to test NULL side sets */
661
662   num_nodes_per_set[0] = 4;
663   num_nodes_per_set[1] = 4;
664   num_nodes_per_set[2] = 28;
665   num_nodes_per_set[3] = 12;
666   num_nodes_per_set[4] =  2;
667   num_nodes_per_set[5] = 18;
668
669   elem_ind[0] = 0;
670   elem_ind[1] = 2;
671   elem_ind[2] = 4;
672   elem_ind[3] = 11;
673   elem_ind[4] = 15;
674   elem_ind[5] = 17;
675
676/* side set 0 
677   side_list[0]= 4; side_list[1]= 2;*/
678/* side set 1
679   side_list[2]= 2; side_list[3]= 3; */
680/* side set 2 
681   side_list[4]= 5; side_list[5]= 3;
682   side_list[6]= 3; side_list[7]= 2;
683   side_list[8]= 4; side_list[9]= 1;
684   side_list[10]= 6;*/
685/* side set 3
686   side_list[11]= 1; side_list[12]= 2;
687   side_list[13]= 3; side_list[14]= 4; */
688/* side set 4
689   side_list[15] = 1; side_list[16] = 1; */
690/* side set 5 
691   side_list[17]= 1; side_list[18]= 2;
692   side_list[19]= 3; side_list[20]= 4;
693   side_list[21]= 5; */
694
695   error = ex_cvt_nodes_to_sides(exoid,
696                         num_elem_per_set,
697                         num_nodes_per_set,
698                         elem_ind,
699                         node_ind,
700                         elem_list,
701                         node_list,
702                         side_list);
703   printf ("after ex_cvt_nodes_to_sides, error = %d\n", error);
704
705   /* for (i=0;i<num_side_sets;i++)
706   {
707     printf("side set %d\n",i);
708     for (j=0;j<num_elem_per_set[i];j++)
709       printf("  side_list[%d]: %d\n",j,side_list[j+elem_ind[i]]);
710   } */
711
712   num_df_per_set[0] = 4;
713   num_df_per_set[1] = 4;
714   num_df_per_set[2] = 0;
715   num_df_per_set[3] = 0;
716   num_df_per_set[4] = 0;
717   num_df_per_set[5] = 0;
718
719   df_ind[0] = 0;
720   df_ind[1] = 4;
721
722   /* side set #1 df */
723   dist_fact[0] = 30.0; dist_fact[1] = 30.1;
724   dist_fact[2] = 30.2; dist_fact[3] = 30.3;
725
726   /* side set #2 df */
727   dist_fact[4] = 31.0; dist_fact[5] = 31.1;
728   dist_fact[6] = 31.2; dist_fact[7] = 31.3;
729
730   error = ex_put_concat_side_sets (exoid, ids, num_elem_per_set,
731                                    num_df_per_set, elem_ind, df_ind,
732                                    elem_list, side_list, dist_fact);
733   printf ("after ex_put_concat_side_sets, error = %d\n", error);
734
735   error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100);
736   printf ("after ex_put_prop, error = %d\n", error);
737
738   error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101);
739   printf ("after ex_put_prop, error = %d\n", error);
740
741   /* END COMMENTED OUT SECTION */
742
743/* write QA records */
744
745   num_qa_rec = 2;
746
747
748   qa_record[0][0] = "TESTWT1";
749   qa_record[0][1] = "testwt1";
750   qa_record[0][2] = "03/16/94";
751   qa_record[0][3] = "15:41:33";
752   qa_record[1][0] = "FASTQ";
753   qa_record[1][1] = "fastq";
754   qa_record[1][2] = "07/07/93";
755   qa_record[1][3] = "16:41:33";
756
757   error = ex_put_qa (exoid, num_qa_rec, qa_record);
758   printf ("after ex_put_qa, error = %d\n", error);
759
760
761/* write information records */
762
763   num_info = 3;
764
765
766   info[0] = "This is the first information record.";
767   info[1] = "This is the second information record.";
768   info[2] = "This is the third information record.";
769
770   error = ex_put_info (exoid, num_info, info);
771   printf ("after ex_put_info, error = %d\n", error);
772
773
774
775/* write results variables parameters and names */
776
777   num_glo_vars = 1;
778
779   var_names[0] = "glo vars";
780
781   error = ex_put_var_param (exoid, "g", num_glo_vars);
782   printf ("after ex_put_var_param, error = %d\n", error);
783   error = ex_put_var_name(exoid, "g", 1, var_names[0]);
784   printf ("after ex_put_var_name, error = %d\n", error);
785
786
787   num_nod_vars = 2;
788
789   var_names[0] = "nod_var0";
790   var_names[1] = "nod_var1";
791
792   error = ex_put_var_param (exoid, "n", num_nod_vars);
793   printf ("after ex_put_var_param, error = %d\n", error);
794   error = ex_put_var_names (exoid, "n", num_nod_vars, var_names);
795   printf ("after ex_put_var_names, error = %d\n", error);
796
797   num_ele_vars = 3;
798
799   var_names[0] = "ele_var0";
800   var_names[1] = "ele_var1";
801   var_names[2] = "ele_var2";
802
803   error = ex_put_var_param (exoid, "e", num_ele_vars);
804   printf ("after ex_put_var_param, error = %d\n", error);
805   error = ex_put_var_names (exoid, "e", num_ele_vars, var_names);
806   printf ("after ex_put_var_names, error = %d\n", error);
807
808
809/* write element variable truth table */
810
811   truth_tab = (int *) calloc ((num_elem_blk*num_ele_vars), sizeof(int));
812
813   k = 0;
814   for (i=0; i<num_elem_blk; i++)
815   {
816      for (j=0; j<num_ele_vars; j++)
817      {
818         truth_tab[k] = k+1;
819         k++;
820      }
821   }
822
823   truth_tab[6] = 0;
824
825   /* commented out to test ex_get_elem_var_tab in testrd1
826   error = ex_put_elem_var_tab (exoid, num_elem_blk, num_ele_vars, truth_tab);
827   printf ("after ex_put_elem_var_tab, error = %d\n", error); */
828
829   free (truth_tab);
830
831
832/* for each time step, write the analysis results;
833 * the code below fills the arrays glob_var_vals, 
834 * nodal_var_vals, and elem_var_vals with values for debugging purposes;
835 * obviously the analysis code will populate these arrays
836 */
837
838   whole_time_step = 1;
839   num_time_steps = 10;
840
841   glob_var_vals = (float *) calloc (num_glo_vars, CPU_word_size);
842   nodal_var_vals = (float *) calloc (num_nodes, CPU_word_size);
843   elem_var_vals = (float *) calloc (4, CPU_word_size);
844
845   for (i=0; i<num_time_steps; i++)
846   {
847     time_value = (float)(i+1)/100.;
848
849/* write time value */
850
851     error = ex_put_time (exoid, whole_time_step, &time_value);
852     printf ("after ex_put_time, error = %d\n", error);
853
854/* write global variables */
855
856     for (j=0; j<num_glo_vars; j++)
857     {
858       glob_var_vals[j] = (float)(j+2) * time_value;
859     }
860
861     error = ex_put_glob_vars (exoid, whole_time_step, num_glo_vars, 
862                               glob_var_vals);
863     printf ("after ex_put_glob_vars, error = %d\n", error);
864
865/* write nodal variables */
866
867     for (k=1; k<=num_nod_vars; k++)
868     {
869       for (j=0; j<num_nodes; j++)
870       {
871         nodal_var_vals[j] = (float)k + ((float)(j+1) * time_value);
872       }
873
874       error = ex_put_nodal_var (exoid, whole_time_step, k, num_nodes,
875                                 nodal_var_vals);
876       printf ("after ex_put_nodal_var, error = %d\n", error);
877     }
878
879/* write element variables */
880
881     for (k=1; k<=num_ele_vars; k++)
882     {
883       for (j=0; j<num_elem_blk; j++)
884       {
885         for (m=0; m<num_elem_in_block[j]; m++)
886         {
887           elem_var_vals[m] = (float)(k+1) + (float)(j+2) + 
888                              ((float)(m+1)*time_value);
889           /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
890         }
891         if (k == 1 && j == 2)
892           continue; /* skip element block 3, variable 1 */
893         else
894         {
895           error = ex_put_elem_var (exoid, whole_time_step, k, ebids[j],
896                                  num_elem_in_block[j], elem_var_vals);
897           printf ("after ex_put_elem_var, error = %d\n", error);
898         }
899       }
900     }
901
902     whole_time_step++;
903
904/* update the data file; this should be done at the end of every time step
905 * to ensure that no data is lost if the analysis dies
906 */
907     error = ex_update (exoid);
908     printf ("after ex_update, error = %d\n", error);
909   }
910   free(glob_var_vals);
911   free(nodal_var_vals);
912   free(elem_var_vals);
913
914
915/* close the EXODUS files
916 */
917   error = ex_close (exoid);
918   printf ("after ex_close, error = %d\n", error);
919   return 0;
920}