PageRenderTime 69ms CodeModel.GetById 2ms app.highlight 60ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/vijaysm/libmesh
C | 1218 lines | 842 code | 263 blank | 113 comment | 108 complexity | d2dc20df1bf2fd179bcd71660740f25a 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
  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];
  69   int num_face_in_sset[10], num_nodes_in_nset[10];
  70   int num_node_sets, num_side_sets, error;
  71   int i, j, k, m, *elem_map, *connect;
  72   int node_list[100],elem_list[100],side_list[100];
  73   int ebids[10], ssids[10], nsids[10];
  74   int  num_qa_rec, num_info;
  75   int num_glo_vars, num_nod_vars, num_ele_vars, num_sset_vars, num_nset_vars;
  76   int *truth_tab;
  77   int whole_time_step, num_time_steps;
  78   int CPU_word_size,IO_word_size;
  79   int prop_array[2];
  80
  81   float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
  82   float *sset_var_vals, *nset_var_vals;
  83   float time_value;
  84   float x[100], y[100], z[100];
  85   float attrib[1], dist_fact[100];
  86   char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
  87   char *block_names[10], *nset_names[10], *sset_names[10];
  88   char *prop_names[2], *attrib_names[2];
  89   char *title = "This is a test";
  90   ex_opts (EX_VERBOSE | EX_ABORT );
  91
  92/* Specify compute and i/o word size */
  93
  94   CPU_word_size = 0;                   /* sizeof(float) */
  95   IO_word_size = 4;                    /* (4 bytes) */
  96
  97/* create EXODUS II file */
  98
  99   exoid = ex_create ("test.exo",       /* filename path */
 100                       EX_CLOBBER,      /* create mode */
 101                       &CPU_word_size,  /* CPU float word size in bytes */
 102                       &IO_word_size);  /* I/O float word size in bytes */
 103   printf ("after ex_create for test.exo, exoid = %d\n", exoid);
 104   printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);
 105
 106   /* ncopts = NC_VERBOSE; */
 107
 108/* initialize file with parameters */
 109
 110   num_dim = 3;
 111   num_nodes = 33;
 112   num_elem = 7;
 113   num_elem_blk = 7;
 114   num_node_sets = 2;
 115   num_side_sets = 5;
 116
 117   
 118   error = ex_put_init (exoid, title, num_dim, num_nodes, num_elem,
 119                        num_elem_blk, num_node_sets, num_side_sets);
 120
 121   printf ("after ex_put_init, error = %d\n", error);
 122
 123   if (error) {
 124     ex_close (exoid);
 125     exit(-1);
 126   }
 127
 128/* write nodal coordinates values and names to database */
 129
 130/* Quad #1 */
 131   x[0] = 0.0; y[0] = 0.0; z[0] = 0.0;
 132   x[1] = 1.0; y[1] = 0.0; z[1] = 0.0;
 133   x[2] = 1.0; y[2] = 1.0; z[2] = 0.0;
 134   x[3] = 0.0; y[3] = 1.0; z[3] = 0.0;
 135
 136/* Quad #2 */
 137   x[4]  =  1.0; y[4]  =  0.0; z[4]  =  0.0;
 138   x[5]  =  2.0; y[5]  =  0.0; z[5]  =  0.0;
 139   x[6]  =  2.0; y[6]  =  1.0; z[6]  =  0.0;
 140   x[7]  =  1.0; y[7]  =  1.0; z[7]  =  0.0;
 141
 142/* Hex #1 */
 143   x[8]  =  0.0; y[8]  =  0.0; z[8]  =  0.0;
 144   x[9]  = 10.0; y[9]  =  0.0; z[9]  =  0.0;
 145   x[10] = 10.0; y[10] =  0.0; z[10] =-10.0;
 146   x[11] =  1.0; y[11] =  0.0; z[11] =-10.0;
 147   x[12] =  1.0; y[12] = 10.0; z[12] =  0.0;
 148   x[13] = 10.0; y[13] = 10.0; z[13] =  0.0;
 149   x[14] = 10.0; y[14] = 10.0; z[14] =-10.0;
 150   x[15] =  1.0; y[15] = 10.0; z[15] =-10.0;
 151
 152/* Tetra #1 */
 153   x[16] =  0.0; y[16] =  0.0; z[16] =  0.0;
 154   x[17] =  1.0; y[17] =  0.0; z[17] =  5.0;
 155   x[18] = 10.0; y[18] =  0.0; z[18] =  2.0;
 156   x[19] =  7.0; y[19] =  5.0; z[19] =  3.0;
 157
 158/* Wedge #1 */
 159   x[20] =  3.0; y[20] =  0.0; z[20] =  6.0;
 160   x[21] =  6.0; y[21] =  0.0; z[21] =  0.0;
 161   x[22] =  0.0; y[22] =  0.0; z[22] =  0.0;
 162   x[23] =  3.0; y[23] =  2.0; z[23] =  6.0;
 163   x[24] =  6.0; y[24] =  2.0; z[24] =  2.0;
 164   x[25] =  0.0; y[25] =  2.0; z[25] =  0.0;
 165
 166/* Tetra #2 */
 167   x[26] =  2.7; y[26] =  1.7; z[26] =  2.7;
 168   x[27] =  6.0; y[27] =  1.7; z[27] =  3.3;
 169   x[28] =  5.7; y[28] =  1.7; z[28] =  1.7;
 170   x[29] =  3.7; y[29] =  0.0; z[29] =  2.3;
 171
 172/* 3d Tri */
 173   x[30] =  0.0; y[30] =  0.0; z[30] =  0.0;
 174   x[31] = 10.0; y[31] =  0.0; z[31] =  0.0;
 175   x[32] = 10.0; y[32] = 10.0; z[32] = 10.0;
 176
 177   for (i=0; i < num_nodes; i+=11) {
 178     error = ex_put_n_coord (exoid, i+1, 11, &x[i], &y[i], &z[i]);
 179     printf ("after ex_put_coord, error = %d\n", error);
 180   }
 181
 182   if (error) {
 183     ex_close (exoid);
 184     exit(-1);
 185   }
 186
 187   coord_names[0] = "xcoor";
 188   coord_names[1] = "ycoor";
 189   coord_names[2] = "zcoor";
 190
 191   error = ex_put_coord_names (exoid, coord_names);
 192   printf ("after ex_put_coord_names, error = %d\n", error);
 193
 194   if (error) {
 195     ex_close (exoid);
 196     exit(-1);
 197   }
 198
 199   /* Add nodal attributes */
 200   error = ex_put_attr_param(exoid, EX_NODAL, 0, 2);
 201   printf ("after ex_put_attr_param, error = %d\n", error);
 202
 203   if (error) {
 204     ex_close (exoid);
 205     exit(-1);
 206   }
 207   
 208   for (i=0; i < num_nodes; i+=11) {
 209     error = ex_put_n_one_attr(exoid, EX_NODAL, 0, i+1, 11, 1, &x[i]);
 210     if (error) {
 211       ex_close (exoid);
 212       exit(-1);
 213     }
 214     
 215     error = ex_put_n_one_attr(exoid, EX_NODAL, 0, i+1, 11, 2, &y[i]);
 216     if (error) {
 217       ex_close (exoid);
 218       exit(-1);
 219     }
 220   }
 221   
 222   {
 223     attrib_names[0] = "Node_attr_1";
 224     attrib_names[1] = "Node_attr_2";
 225     error = ex_put_attr_names (exoid, EX_NODAL, 0, attrib_names);
 226     if (error) {
 227       ex_close (exoid);
 228       exit(-1);
 229     }
 230   }
 231
 232/* write element order map */
 233
 234   elem_map = (int *) calloc(num_elem, sizeof(int));
 235
 236   for (i=1; i<=num_elem; i++)
 237   {
 238      elem_map[i-1] = i;
 239   }
 240
 241   error = ex_put_map (exoid, elem_map);
 242   printf ("after ex_put_map, error = %d\n", error);
 243
 244   if (error) {
 245     ex_close (exoid);
 246     exit(-1);
 247   }
 248
 249   free (elem_map);
 250
 251
 252/* write element block parameters */
 253
 254/*                   1234567890123456789012345678901234567890 */
 255   block_names[0] = "block_1";
 256   block_names[1] = "block_2";
 257   block_names[2] = "block_3";
 258   block_names[3] = "block_4";
 259   block_names[4] = "block_5";
 260   block_names[5] = "block_6";
 261   block_names[6] = "block_7";
 262
 263   num_elem_in_block[0] = 1;
 264   num_elem_in_block[1] = 1;
 265   num_elem_in_block[2] = 1;
 266   num_elem_in_block[3] = 1;
 267   num_elem_in_block[4] = 1;
 268   num_elem_in_block[5] = 1;
 269   num_elem_in_block[6] = 1;
 270
 271   num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads  */
 272   num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads  */
 273   num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes  */
 274   num_nodes_per_elem[3] = 4; /* elements in block #4 are 4-node tetras */
 275   num_nodes_per_elem[4] = 6; /* elements in block #5 are 6-node wedges */
 276   num_nodes_per_elem[5] = 8; /* elements in block #6 are 8-node tetras */
 277   num_nodes_per_elem[6] = 3; /* elements in block #7 are 3-node tris   */
 278
 279   ebids[0] = 10;
 280   ebids[1] = 11;
 281   ebids[2] = 12;
 282   ebids[3] = 13;
 283   ebids[4] = 14;
 284   ebids[5] = 15;
 285   ebids[6] = 16;
 286
 287   error = ex_put_elem_block (exoid, ebids[0], "quad", num_elem_in_block[0],
 288                              num_nodes_per_elem[0], 1);
 289   printf ("after ex_put_elem_block, error = %d\n", error);
 290
 291   if (error) {
 292     ex_close (exoid);
 293     exit(-1);
 294   }
 295
 296   error = ex_put_elem_block (exoid, ebids[1], "quad", num_elem_in_block[1],
 297                               num_nodes_per_elem[1], 1);
 298   printf ("after ex_put_elem_block, error = %d\n", error);
 299
 300   if (error) {
 301     ex_close (exoid);
 302     exit(-1);
 303   }
 304
 305   error = ex_put_elem_block (exoid, ebids[2], "hex", num_elem_in_block[2],
 306                               num_nodes_per_elem[2], 1);
 307   printf ("after ex_put_elem_block, error = %d\n", error);
 308
 309   if (error) {
 310     ex_close (exoid);
 311     exit(-1);
 312   }
 313
 314   error = ex_put_elem_block (exoid, ebids[3], "tetra", num_elem_in_block[3],
 315                               num_nodes_per_elem[3], 1);
 316   printf ("after ex_put_elem_block, error = %d\n", error);
 317
 318   if (error) {
 319     ex_close (exoid);
 320     exit(-1);
 321   }
 322
 323   error = ex_put_elem_block (exoid, ebids[4], "wedge", num_elem_in_block[4],
 324                               num_nodes_per_elem[4], 1);
 325   printf ("after ex_put_elem_block, error = %d\n", error);
 326
 327   if (error) {
 328     ex_close (exoid);
 329     exit(-1);
 330   }
 331
 332   error = ex_put_elem_block (exoid, ebids[5], "tetra", num_elem_in_block[5],
 333                               num_nodes_per_elem[5], 1);
 334   printf ("after ex_put_elem_block, error = %d\n", error);
 335
 336   if (error) {
 337     ex_close (exoid);
 338     exit(-1);
 339   }
 340
 341   error = ex_put_elem_block (exoid, ebids[6], "tri", num_elem_in_block[6],
 342                               num_nodes_per_elem[6], 1);
 343   printf ("after ex_put_elem_block, error = %d\n", error);
 344
 345   if (error) {
 346     ex_close (exoid);
 347     exit(-1);
 348   }
 349
 350   /* Write element block names */
 351   error = ex_put_names(exoid, EX_ELEM_BLOCK, block_names);
 352   printf ("after ex_put_names, error = %d\n", error);
 353
 354   if (error) {
 355     ex_close (exoid);
 356     exit(-1);
 357   }
 358   
 359/* write element block properties */
 360
 361   /*               12345678901234567890123456789012 */
 362   prop_names[0] = "MATERIAL_PROPERTY_LONG_NAME_32CH";
 363   prop_names[1] = "DENSITY";
 364   error = ex_put_prop_names(exoid,EX_ELEM_BLOCK,2,prop_names);
 365   printf ("after ex_put_prop_names, error = %d\n", error);
 366
 367   if (error) {
 368     ex_close (exoid);
 369     exit(-1);
 370   }
 371
 372   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], prop_names[0], 10);
 373   printf ("after ex_put_prop, error = %d\n", error);
 374   if (error) {
 375     ex_close (exoid);
 376     exit(-1);
 377   }
 378
 379   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], prop_names[0], 20);
 380   printf ("after ex_put_prop, error = %d\n", error);
 381   if (error) {
 382     ex_close (exoid);
 383     exit(-1);
 384   }
 385
 386   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], prop_names[0], 30);
 387   printf ("after ex_put_prop, error = %d\n", error);
 388   if (error) {
 389     ex_close (exoid);
 390     exit(-1);
 391   }
 392
 393   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[3], prop_names[0], 40);
 394   printf ("after ex_put_prop, error = %d\n", error);
 395   if (error) {
 396     ex_close (exoid);
 397     exit(-1);
 398   }
 399
 400   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[4], prop_names[0], 50);
 401   printf ("after ex_put_prop, error = %d\n", error);
 402   if (error) {
 403     ex_close (exoid);
 404     exit(-1);
 405   }
 406
 407   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[5], prop_names[0], 60);
 408   printf ("after ex_put_prop, error = %d\n", error);
 409   if (error) {
 410     ex_close (exoid);
 411     exit(-1);
 412   }
 413
 414   error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[6], prop_names[0], 70);
 415   printf ("after ex_put_prop, error = %d\n", error);
 416   if (error) {
 417     ex_close (exoid);
 418     exit(-1);
 419   }
 420
 421
 422/* write element connectivity */
 423
 424   connect = (int *) calloc(8, sizeof(int));
 425   connect[0] = 1; connect[1] = 2; connect[2] = 3; connect[3] = 4;
 426
 427   error = ex_put_elem_conn (exoid, ebids[0], connect);
 428   printf ("after ex_put_elem_conn, error = %d\n", error);
 429   if (error) {
 430     ex_close (exoid);
 431     exit(-1);
 432   }
 433
 434
 435   connect[0] = 5; connect[1] = 6; connect[2] = 7; connect[3] = 8;
 436
 437   error = ex_put_elem_conn (exoid, ebids[1], connect);
 438   printf ("after ex_put_elem_conn, error = %d\n", error);
 439
 440   if (error) {
 441     ex_close (exoid);
 442     exit(-1);
 443   }
 444
 445   connect[0] = 9; connect[1] = 10; connect[2] = 11; connect[3] = 12;
 446   connect[4] = 13; connect[5] = 14; connect[6] = 15; connect[7] = 16;
 447
 448   error = ex_put_elem_conn (exoid, ebids[2], connect);
 449   printf ("after ex_put_elem_conn, error = %d\n", error);
 450
 451   if (error) {
 452     ex_close (exoid);
 453     exit(-1);
 454   }
 455
 456   connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20;
 457
 458   error = ex_put_elem_conn (exoid, ebids[3], connect);
 459   printf ("after ex_put_elem_conn, error = %d\n", error);
 460
 461   if (error) {
 462     ex_close (exoid);
 463     exit(-1);
 464   }
 465
 466   connect[0] = 21; connect[1] = 22; connect[2] = 23;
 467   connect[3] = 24; connect[4] = 25; connect[5] = 26;
 468
 469   error = ex_put_elem_conn (exoid, ebids[4], connect);
 470   printf ("after ex_put_elem_conn, error = %d\n", error);
 471
 472   if (error) {
 473     ex_close (exoid);
 474     exit(-1);
 475   }
 476
 477   connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20;
 478   connect[4] = 27; connect[5] = 28; connect[6] = 30; connect[7] = 29;
 479
 480   error = ex_put_elem_conn (exoid, ebids[5], connect);
 481   printf ("after ex_put_elem_conn, error = %d\n", error);
 482
 483   if (error) {
 484     ex_close (exoid);
 485     exit(-1);
 486   }
 487
 488   connect[0] = 31; connect[1] = 32; connect[2] = 33;
 489
 490   error = ex_put_elem_conn (exoid, ebids[6], connect);
 491   printf ("after ex_put_elem_conn, error = %d\n", error);
 492
 493   if (error) {
 494     ex_close (exoid);
 495     exit(-1);
 496   }
 497
 498   free (connect);
 499
 500
 501/* write element block attributes */
 502
 503   attrib[0] = 3.14159;
 504   error = ex_put_elem_attr (exoid, ebids[0], attrib);
 505   printf ("after ex_put_elem_attr, error = %d\n", error);
 506   if (error) {
 507     ex_close (exoid);
 508     exit(-1);
 509   }
 510
 511   error = ex_put_elem_attr (exoid, ebids[0], attrib);
 512   printf ("after ex_put_elem_attr, error = %d\n", error);
 513   if (error) {
 514     ex_close (exoid);
 515     exit(-1);
 516   }
 517
 518   attrib[0] = 6.14159;
 519   error = ex_put_elem_attr (exoid, ebids[1], attrib);
 520   printf ("after ex_put_elem_attr, error = %d\n", error);
 521
 522   if (error) {
 523     ex_close (exoid);
 524     exit(-1);
 525   }
 526
 527   error = ex_put_elem_attr (exoid, ebids[2], attrib);
 528   printf ("after ex_put_elem_attr, error = %d\n", error);
 529
 530   if (error) {
 531     ex_close (exoid);
 532     exit(-1);
 533   }
 534
 535   error = ex_put_elem_attr (exoid, ebids[3], attrib);
 536   printf ("after ex_put_elem_attr, error = %d\n", error);
 537
 538   if (error) {
 539     ex_close (exoid);
 540     exit(-1);
 541   }
 542
 543   error = ex_put_elem_attr (exoid, ebids[4], attrib);
 544   printf ("after ex_put_elem_attr, error = %d\n", error);
 545
 546   if (error) {
 547     ex_close (exoid);
 548     exit(-1);
 549   }
 550
 551   error = ex_put_elem_attr (exoid, ebids[5], attrib);
 552   printf ("after ex_put_elem_attr, error = %d\n", error);
 553
 554   if (error) {
 555     ex_close (exoid);
 556     exit(-1);
 557   }
 558
 559   error = ex_put_elem_attr (exoid, ebids[6], attrib);
 560   printf ("after ex_put_elem_attr, error = %d\n", error);
 561
 562   if (error) {
 563     ex_close (exoid);
 564     exit(-1);
 565   }
 566
 567   attrib_names[0] = "THICKNESS";
 568   for (i=0; i < 7; i++) {
 569     error = ex_put_elem_attr_names (exoid, ebids[i], attrib_names);
 570     printf ("after ex_put_elem_attr_names, error = %d\n", error);
 571     if (error) {
 572       ex_close (exoid);
 573       exit(-1);
 574     }
 575   }
 576
 577/* write individual node sets */
 578
 579
 580   num_nodes_in_nset[0] = 5;
 581   num_nodes_in_nset[1] = 3;
 582
 583   nsids[0] = 20;
 584   nsids[1] = 21;
 585
 586   error = ex_put_node_set_param (exoid, nsids[0], 5, 5);
 587   printf ("after ex_put_node_set_param, error = %d\n", error);
 588
 589   if (error) {
 590     ex_close (exoid);
 591     exit(-1);
 592   }
 593
 594   node_list[0] = 10; node_list[1] = 11; node_list[2] = 12; 
 595   node_list[3] = 13; node_list[4] = 14; 
 596
 597   dist_fact[0] = 1.0; dist_fact[1] = 2.0; dist_fact[2] = 3.0;
 598   dist_fact[3] = 4.0; dist_fact[4] = 5.0;
 599
 600   error = ex_put_node_set (exoid, nsids[0], node_list);
 601   printf ("after ex_put_node_set, error = %d\n", error);
 602   if (error) {
 603     ex_close (exoid);
 604     exit(-1);
 605   }
 606
 607   error = ex_put_node_set_dist_fact (exoid, nsids[0], dist_fact);
 608   printf ("after ex_put_node_set_dist_fact, error = %d\n", error);
 609   if (error) {
 610     ex_close (exoid);
 611     exit(-1);
 612   }
 613
 614
 615   error = ex_put_node_set_param (exoid, nsids[1], 3, 3);
 616   printf ("after ex_put_node_set_param, error = %d\n", error);
 617
 618   if (error) {
 619     ex_close (exoid);
 620     exit(-1);
 621   }
 622
 623   node_list[0] = 20; node_list[1] = 21; node_list[2] = 22; 
 624
 625   dist_fact[0] = 1.1; dist_fact[1] = 2.1; dist_fact[2] = 3.1;
 626
 627   error = ex_put_node_set (exoid, nsids[1], node_list);
 628   printf ("after ex_put_node_set, error = %d\n", error);
 629   if (error) {
 630     ex_close (exoid);
 631     exit(-1);
 632   }
 633
 634   error = ex_put_node_set_dist_fact (exoid, nsids[1], dist_fact);
 635   printf ("after ex_put_node_set_dist_fact, error = %d\n", error);
 636   if (error) {
 637     ex_close (exoid);
 638     exit(-1);
 639   }
 640
 641
 642   /* Write node set names */
 643   nset_names[0] = "nset_1";
 644   nset_names[1] = "nset_2";
 645
 646   error = ex_put_names(exoid, EX_NODE_SET, nset_names);
 647   printf ("after ex_put_names, error = %d\n", error);
 648
 649   if (error) {
 650     ex_close (exoid);
 651     exit(-1);
 652   }
 653   
 654   error = ex_put_prop(exoid, EX_NODE_SET, nsids[0], "FACE", 4);
 655   printf ("after ex_put_prop, error = %d\n", error);
 656   if (error) {
 657     ex_close (exoid);
 658     exit(-1);
 659   }
 660
 661   error = ex_put_prop(exoid, EX_NODE_SET, nsids[1], "FACE", 5);
 662   printf ("after ex_put_prop, error = %d\n", error);
 663
 664   if (error) {
 665     ex_close (exoid);
 666     exit(-1);
 667   }
 668
 669   prop_array[0] = 1000;
 670   prop_array[1] = 2000;
 671
 672   error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
 673   printf ("after ex_put_prop_array, error = %d\n", error);
 674   if (error) {
 675     ex_close (exoid);
 676     exit(-1);
 677   }
 678
 679   /* Add nodeset attributes */
 680   error = ex_put_attr_param(exoid, EX_NODE_SET, nsids[0], 1);
 681   printf ("after ex_put_attr_param, error = %d\n", error);
 682
 683   if (error) {
 684     ex_close (exoid);
 685     exit(-1);
 686   }
 687   
 688   error = ex_put_attr(exoid, EX_NODE_SET, nsids[0], x);
 689   if (error) {
 690     ex_close (exoid);
 691     exit(-1);
 692   }
 693   
 694   {
 695     attrib_names[0] = "Nodeset_attribute";
 696     error = ex_put_attr_names (exoid, EX_NODE_SET, nsids[0], attrib_names);
 697     if (error) {
 698       ex_close (exoid);
 699       exit(-1);
 700     }
 701   }
 702
 703/* write individual side sets */
 704   num_face_in_sset[0] =  2;
 705   num_face_in_sset[1] =  2;
 706   num_face_in_sset[2] =  7;
 707   num_face_in_sset[3] =  8;
 708   num_face_in_sset[4] = 10;
 709   
 710   ssids[0] = 30;
 711   ssids[1] = 31;
 712   ssids[2] = 32;
 713   ssids[3] = 33;
 714   ssids[4] = 34;
 715
 716   /* side set #1  - quad */
 717
 718   error = ex_put_side_set_param (exoid, ssids[0], 2, 4);
 719   printf ("after ex_put_side_set_param, error = %d\n", error);
 720
 721   if (error) {
 722     ex_close (exoid);
 723     exit(-1);
 724   }
 725
 726   elem_list[0] = 2; elem_list[1] = 2;
 727
 728   side_list[0] = 4; side_list[1] = 2;
 729
 730   dist_fact[0] = 30.0; dist_fact[1] = 30.1; dist_fact[2] = 30.2;
 731   dist_fact[3] = 30.3;
 732
 733   error = ex_put_side_set (exoid, 30, elem_list, side_list);
 734   printf ("after ex_put_side_set, error = %d\n", error);
 735
 736   if (error) {
 737     ex_close (exoid);
 738     exit(-1);
 739   }
 740
 741   error = ex_put_side_set_dist_fact (exoid, 30, dist_fact);
 742   printf ("after ex_put_side_set_dist_fact, error = %d\n", error);
 743
 744   if (error) {
 745     ex_close (exoid);
 746     exit(-1);
 747   }
 748
 749
 750   /* side set #2  - quad, spanning 2 elements  */
 751
 752   error = ex_put_side_set_param (exoid, 31, 2, 4);
 753   printf ("after ex_put_side_set_param, error = %d\n", error);
 754
 755   if (error) {
 756     ex_close (exoid);
 757     exit(-1);
 758   }
 759
 760   elem_list[0] = 1; elem_list[1] = 2;
 761
 762   side_list[0] = 2; side_list[1] = 3;
 763
 764   dist_fact[0] = 31.0; dist_fact[1] = 31.1; dist_fact[2] = 31.2;
 765   dist_fact[3] = 31.3;
 766
 767   error = ex_put_side_set (exoid, 31, elem_list, side_list);
 768   printf ("after ex_put_side_set, error = %d\n", error);
 769
 770   if (error) {
 771     ex_close (exoid);
 772     exit(-1);
 773   }
 774
 775   error = ex_put_side_set_dist_fact (exoid, 31, dist_fact);
 776   printf ("after ex_put_side_set_dist_fact, error = %d\n", error);
 777
 778   if (error) {
 779     ex_close (exoid);
 780     exit(-1);
 781   }
 782
 783
 784   /* side set #3  - hex */
 785
 786   error = ex_put_side_set_param (exoid, 32, 7, 0);
 787   printf ("after ex_put_side_set_param, error = %d\n", error);
 788
 789   if (error) {
 790     ex_close (exoid);
 791     exit(-1);
 792   }
 793
 794   elem_list[0] = 3; elem_list[1] = 3;
 795   elem_list[2] = 3; elem_list[3] = 3;
 796   elem_list[4] = 3; elem_list[5] = 3;
 797   elem_list[6] = 3;
 798
 799   side_list[0] = 5; side_list[1] = 3;
 800   side_list[2] = 3; side_list[3] = 2;
 801   side_list[4] = 4; side_list[5] = 1;
 802   side_list[6] = 6;
 803
 804   error = ex_put_side_set (exoid, 32, elem_list, side_list);
 805   printf ("after ex_put_side_set, error = %d\n", error);
 806
 807   if (error) {
 808     ex_close (exoid);
 809     exit(-1);
 810   }
 811
 812
 813   /* side set #4  - tetras */
 814
 815   error = ex_put_side_set_param (exoid, 33, 8, 0);
 816   printf ("after ex_put_side_set_param, error = %d\n", error);
 817
 818   if (error) {
 819     ex_close (exoid);
 820     exit(-1);
 821   }
 822
 823   elem_list[0] = 4; elem_list[1] = 4;
 824   elem_list[2] = 4; elem_list[3] = 4;
 825   elem_list[4] = 6; elem_list[5] = 6;
 826   elem_list[6] = 6; elem_list[7] = 6;
 827
 828   side_list[0] = 1; side_list[1] = 2;
 829   side_list[2] = 3; side_list[3] = 4;
 830   side_list[4] = 1; side_list[5] = 2;
 831   side_list[6] = 3; side_list[7] = 4;
 832
 833   error = ex_put_side_set (exoid, 33, elem_list, side_list);
 834   printf ("after ex_put_side_set, error = %d\n", error);
 835
 836   if (error) {
 837     ex_close (exoid);
 838     exit(-1);
 839   }
 840
 841
 842   /* side set #5  - wedges and tris */
 843
 844   error = ex_put_side_set_param (exoid, 34, 10, 0);
 845   printf ("after ex_put_side_set_param, error = %d\n", error);
 846
 847   if (error) {
 848     ex_close (exoid);
 849     exit(-1);
 850   }
 851
 852   elem_list[0] = 5; elem_list[1] = 5;
 853   elem_list[2] = 5; elem_list[3] = 5;
 854   elem_list[4] = 5; elem_list[5] = 7;
 855   elem_list[6] = 7; elem_list[7] = 7;
 856   elem_list[8] = 7; elem_list[9] = 7;
 857
 858   side_list[0] = 1; side_list[1] = 2;
 859   side_list[2] = 3; side_list[3] = 4;
 860   side_list[4] = 5; side_list[5] = 1;
 861   side_list[6] = 2; side_list[7] = 3;
 862   side_list[8] = 4; side_list[9] = 5;
 863
 864   error = ex_put_side_set (exoid, 34, elem_list, side_list);
 865   printf ("after ex_put_side_set, error = %d\n", error);
 866
 867   if (error) {
 868     ex_close (exoid);
 869     exit(-1);
 870   }
 871
 872   /* Write side set names */
 873   sset_names[0] = "sset_1";
 874   sset_names[1] = "sset_2";
 875   sset_names[2] = "sset_3";
 876   sset_names[3] = "sset_4";
 877   sset_names[4] = "sset_5";
 878
 879   error = ex_put_names(exoid, EX_SIDE_SET, sset_names);
 880   printf ("after ex_put_names, error = %d\n", error);
 881
 882   if (error) {
 883     ex_close (exoid);
 884     exit(-1);
 885   }
 886   
 887   error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100);
 888   printf ("after ex_put_prop, error = %d\n", error);
 889
 890   if (error) {
 891     ex_close (exoid);
 892     exit(-1);
 893   }
 894
 895   error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101);
 896   printf ("after ex_put_prop, error = %d\n", error);
 897
 898   if (error) {
 899     ex_close (exoid);
 900     exit(-1);
 901   }
 902
 903
 904/* write QA records; test empty and just blank-filled records */
 905
 906   num_qa_rec = 2;
 907
 908
 909   qa_record[0][0] = "TESTWT";
 910   qa_record[0][1] = "testwt";
 911   qa_record[0][2] = "07/07/93";
 912   qa_record[0][3] = "15:41:33";
 913   qa_record[1][0] = "";
 914   qa_record[1][1] = "                            ";
 915   qa_record[1][2] = "";
 916   qa_record[1][3] = "                        ";
 917
 918   error = ex_put_qa (exoid, num_qa_rec, qa_record);
 919   printf ("after ex_put_qa, error = %d\n", error);
 920
 921   if (error) {
 922     ex_close (exoid);
 923     exit(-1);
 924   }
 925
 926
 927/* write information records; test empty and just blank-filled records */
 928
 929   num_info = 3;
 930
 931
 932   info[0] = "This is the first information record.";
 933   info[1] = "";
 934   info[2] = "                                     ";
 935
 936   error = ex_put_info (exoid, num_info, info);
 937   printf ("after ex_put_info, error = %d\n", error);
 938
 939   if (error) {
 940     ex_close (exoid);
 941     exit(-1);
 942   }
 943
 944
 945
 946/* write results variables parameters and names */
 947
 948   num_glo_vars = 1;
 949
 950   var_names[0] = "glo_vars";
 951
 952   error = ex_put_variable_param (exoid, EX_GLOBAL, num_glo_vars);
 953   printf ("after ex_put_variable_param, error = %d\n", error);
 954   if (error) {
 955     ex_close (exoid);
 956     exit(-1);
 957   }
 958
 959   error = ex_put_variable_names (exoid, EX_GLOBAL, num_glo_vars, var_names);
 960   printf ("after ex_put_variable_names, error = %d\n", error);
 961   if (error) {
 962     ex_close (exoid);
 963     exit(-1);
 964   }
 965
 966
 967
 968   num_nod_vars = 2;
 969   /*              12345678901234567890123456789012 */
 970   var_names[0] = "node_variable_a_very_long_name_0";
 971   var_names[1] = "nod_var1";
 972
 973   error = ex_put_variable_param (exoid, EX_NODAL, num_nod_vars);
 974   printf ("after ex_put_variable_param, error = %d\n", error);
 975   if (error) {
 976     ex_close (exoid);
 977     exit(-1);
 978   }
 979
 980   error = ex_put_variable_names (exoid, EX_NODAL, num_nod_vars, var_names);
 981   printf ("after ex_put_variable_names, error = %d\n", error);
 982   if (error) {
 983     ex_close (exoid);
 984     exit(-1);
 985   }
 986
 987
 988   num_ele_vars = 3;
 989
 990   var_names[0] = "ele_var0";
 991   var_names[1] = "ele_var1";
 992   var_names[2] = "ele_var2";
 993
 994   error = ex_put_variable_param (exoid, EX_ELEM_BLOCK, num_ele_vars);
 995   printf ("after ex_put_variable_param, error = %d\n", error);
 996   if (error) {
 997     ex_close (exoid);
 998     exit(-1);
 999   }
1000
1001   error = ex_put_variable_names (exoid, EX_ELEM_BLOCK, num_ele_vars, var_names);
1002   printf ("after ex_put_variable_names, error = %d\n", error);
1003   if (error) {
1004     ex_close (exoid);
1005     exit(-1);
1006   }
1007
1008   {
1009     num_nset_vars = 3;
1010     
1011     var_names[0] = "ns_var0";
1012     var_names[1] = "ns_var1";
1013     var_names[2] = "ns_var2";
1014     
1015     error = ex_put_variable_param (exoid, EX_NODE_SET, num_nset_vars);
1016     printf ("after ex_put_variable_param, error = %d\n", error);
1017     if (error) {
1018       ex_close (exoid);
1019       exit(-1);
1020     }
1021     
1022     error = ex_put_variable_names (exoid, EX_NODE_SET, num_nset_vars, var_names);
1023     printf ("after ex_put_variable_names, error = %d\n", error);
1024     if (error) {
1025       ex_close (exoid);
1026       exit(-1);
1027     }
1028   }
1029   
1030   {
1031     num_sset_vars = 3;
1032
1033     var_names[0] = "ss_var0";
1034     var_names[1] = "ss_var1";
1035     var_names[2] = "ss_var2";
1036     
1037     error = ex_put_variable_param (exoid, EX_SIDE_SET, num_sset_vars);
1038     printf ("after ex_put_variable_param, error = %d\n", error);
1039     if (error) {
1040       ex_close (exoid);
1041       exit(-1);
1042     }
1043     
1044     error = ex_put_variable_names (exoid, EX_SIDE_SET, num_sset_vars, var_names);
1045     printf ("after ex_put_variable_names, error = %d\n", error);
1046     if (error) {
1047       ex_close (exoid);
1048       exit(-1);
1049     }
1050   }
1051
1052
1053
1054/* write element variable truth table */
1055
1056   truth_tab = (int *) calloc ((num_elem_blk*num_ele_vars), sizeof(int));
1057
1058   k = 0;
1059   for (i=0; i<num_elem_blk; i++)
1060   {
1061      for (j=0; j<num_ele_vars; j++)
1062      {
1063         truth_tab[k++] = 1;
1064      }
1065   }
1066
1067   error = ex_put_elem_var_tab (exoid, num_elem_blk, num_ele_vars, truth_tab);
1068   printf ("after ex_put_elem_var_tab, error = %d\n", error);
1069
1070   if (error) {
1071     ex_close (exoid);
1072     exit(-1);
1073   }
1074
1075   free (truth_tab);
1076
1077
1078/* for each time step, write the analysis results;
1079 * the code below fills the arrays glob_var_vals, 
1080 * nodal_var_vals, and elem_var_vals with values for debugging purposes;
1081 * obviously the analysis code will populate these arrays
1082 */
1083
1084   whole_time_step = 1;
1085   num_time_steps = 10;
1086
1087   glob_var_vals = (float *) calloc (num_glo_vars, CPU_word_size);
1088   nodal_var_vals = (float *) calloc (num_nodes, CPU_word_size);
1089   elem_var_vals = (float *) calloc (4, CPU_word_size);
1090   sset_var_vals = (float *) calloc (10, CPU_word_size);
1091   nset_var_vals = (float *) calloc (10, CPU_word_size);
1092   
1093   for (i=0; i<num_time_steps; i++)
1094   {
1095     time_value = (float)(i+1)/100.;
1096
1097/* write time value */
1098
1099     error = ex_put_time (exoid, whole_time_step, &time_value);
1100     printf ("after ex_put_time, error = %d\n", error);
1101
1102     if (error) {
1103       ex_close (exoid);
1104       exit(-1);
1105     }
1106
1107/* write global variables */
1108
1109     for (j=0; j<num_glo_vars; j++) {
1110       glob_var_vals[j] = (float)(j+2) * time_value;
1111     }
1112
1113     error = ex_put_glob_vars (exoid, whole_time_step, num_glo_vars, 
1114                               glob_var_vals);
1115     printf ("after ex_put_glob_vars, error = %d\n", error);
1116
1117     if (error) {
1118       ex_close (exoid);
1119       exit(-1);
1120     }
1121
1122     /* write nodal variables */
1123     for (k=1; k<=num_nod_vars; k++) {
1124       for (j=0; j<num_nodes; j++) {
1125         nodal_var_vals[j] = (float)k + ((float)(j+1) * time_value);
1126       }
1127       error = ex_put_var(exoid, whole_time_step, EX_NODAL,
1128			  k, 0, num_nodes, nodal_var_vals);
1129       printf ("after ex_put_nodal_var, error = %d\n", error);
1130       if (error) {
1131         ex_close (exoid);
1132         exit(-1);
1133       }
1134     }
1135
1136     /* write element variables */
1137     for (k=1; k<=num_ele_vars; k++) {
1138       for (j=0; j<num_elem_blk; j++) {
1139         for (m=0; m<num_elem_in_block[j]; m++) {
1140           elem_var_vals[m] = (float)(k+1) + (float)(j+2) + 
1141                              ((float)(m+1)*time_value);
1142           /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */
1143         }
1144         error = ex_put_var(exoid, whole_time_step, EX_ELEM_BLOCK,
1145			    k, ebids[j], num_elem_in_block[j], elem_var_vals);
1146         printf ("after ex_put_elem_var, error = %d\n", error);
1147         if (error) {
1148           ex_close (exoid);
1149           exit(-1);
1150         }
1151       }
1152     }
1153
1154     /* write sideset variables */
1155     for (k=1; k<=num_sset_vars; k++) {
1156       for (j=0; j<num_side_sets; j++) {
1157         for (m=0; m<num_face_in_sset[j]; m++) {
1158           sset_var_vals[m] = (float)(k+2) + (float)(j+3) + 
1159                              ((float)(m+1)*time_value);
1160           /* printf("sset_var_vals[%d]: %f\n",m,sset_var_vals[m]); */
1161         }
1162         error = ex_put_var(exoid, whole_time_step, EX_SIDE_SET,
1163			    k, ssids[j], num_face_in_sset[j], sset_var_vals);
1164         printf ("after ex_put_sset_var, error = %d\n", error);
1165         if (error) {
1166           ex_close (exoid);
1167           exit(-1);
1168         }
1169       }
1170     }
1171
1172     /* write nodeset variables */
1173     for (k=1; k<=num_nset_vars; k++) {
1174       for (j=0; j<num_node_sets; j++) {
1175         for (m=0; m<num_nodes_in_nset[j]; m++) {
1176           nset_var_vals[m] = (float)(k+3) + (float)(j+4) + 
1177	     ((float)(m+1)*time_value);
1178           /* printf("nset_var_vals[%d]: %f\n",m,nset_var_vals[m]); */
1179         }
1180         error = ex_put_var(exoid, whole_time_step, EX_NODE_SET,
1181			    k, nsids[j], num_nodes_in_nset[j], nset_var_vals);
1182         printf ("after ex_put_nset_var, error = %d\n", error);
1183         if (error) {
1184           ex_close (exoid);
1185           exit(-1);
1186         }
1187       }
1188     }
1189
1190     whole_time_step++;
1191
1192/* update the data file; this should be done at the end of every time step
1193 * to ensure that no data is lost if the analysis dies
1194 */
1195     error = ex_update (exoid);
1196     printf ("after ex_update, error = %d\n", error);
1197     if (error) {
1198       ex_close (exoid);
1199       exit(-1);
1200     }
1201   }
1202   free(glob_var_vals);
1203   free(nodal_var_vals);
1204   free(elem_var_vals);
1205   free(sset_var_vals);
1206   free(nset_var_vals);
1207
1208
1209/* close the EXODUS files
1210 */
1211   error = ex_close (exoid);
1212   printf ("after ex_close, error = %d\n", error);
1213   if (error) {
1214     ex_close (exoid);
1215     exit(-1);
1216   }
1217   return 0;
1218}