PageRenderTime 70ms CodeModel.GetById 3ms app.highlight 59ms RepoModel.GetById 2ms app.codeStats 0ms

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

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