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

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

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