PageRenderTime 53ms CodeModel.GetById 2ms app.highlight 45ms RepoModel.GetById 1ms app.codeStats 0ms

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

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