PageRenderTime 65ms CodeModel.GetById 2ms app.highlight 55ms RepoModel.GetById 1ms app.codeStats 1ms

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

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