Ejemplo n.º 1
0
Excn::ExodusFile::ExodusFile(int processor)
  : myProcessor_(processor)
{
  SMART_ASSERT(processor < processorCount_)(processor)(processorCount_);
  SMART_ASSERT(fileids_.size() == (size_t)processorCount_);
  if (!keepOpen_ && processor != 0) {
    float version = 0.0;
    int cpu_word_size = cpuWordSize_;
    int io_word_size_var  = ioWordSize_;
    int mode = EX_READ;
    mode |= mode64bit_;
    
    fileids_[processor] = ex_open(filenames_[processor].c_str(),
				  mode, &cpu_word_size,
				  &io_word_size_var, &version);
    if (fileids_[processor] < 0) {
      std::cerr << "Cannot open file '" << filenames_[processor]
	   << "' - exiting" << std::endl;
      exit(1);
    }
    ex_set_max_name_length(fileids_[processor], maximumNameLength_);
    
    SMART_ASSERT(io_word_size_var  == ioWordSize_);
    SMART_ASSERT(cpu_word_size == cpuWordSize_);
  }
}
Ejemplo n.º 2
0
bool Excn::ExodusFile::create_output(const SystemInterface& si)
  // Create output file...
{
  outputFilename_ = si.outputName_;

  int mode = EX_CLOBBER | exodusMode_;
  if (si.ints_64_bit())
    mode |= EX_ALL_INT64_DB;
  
  std::cout << "Output:   '" << outputFilename_ << "'" << std::endl;
  outputId_ = ex_create(outputFilename_.c_str(), mode,
			&cpuWordSize_, &ioWordSize_);
  if (outputId_ < 0) {
    std::cerr << "Cannot open file '" << outputFilename_ << "'" << std::endl;
    return false;
  }
  std::cout << "IO Word size is " << ioWordSize_ << " bytes.\n";
  ex_set_max_name_length(outputId_, maximumNameLength_);
  return true;
}
Ejemplo n.º 3
0
Excn::ExodusFile::ExodusFile(size_t which)
  : myLocation_(which)
{
  SMART_ASSERT(which < filenames_.size())(which)(filenames_.size());
  SMART_ASSERT(fileids_.size() == filenames_.size());
  if (!keepOpen_ && which != 0) {
    float version = 0.0;
    int cpu_word_size = cpuWordSize_;
    int io_wrd_size  = ioWordSize_;
    fileids_[which] = ex_open(filenames_[which].c_str(),
				  EX_READ|exodusMode_, &cpu_word_size,
				  &io_wrd_size, &version);
    if (fileids_[which] < 0) {
      std::cerr << "Cannot open file '" << filenames_[which]
	   << "' - exiting" << std::endl;
      exit(1);
    }
    ex_set_max_name_length(fileids_[which], maximumNameLength_);

    SMART_ASSERT(io_wrd_size  == ioWordSize_);
    SMART_ASSERT(cpu_word_size == cpuWordSize_);
  }
}
Ejemplo n.º 4
0
Archivo: oned.c Proyecto: certik/exodus
int main (int argc, char **argv)
{
   int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
   int num_elem_in_block[10], num_nodes_per_elem[10];
   int num_nodes_in_nset[10];
   int num_node_sets, num_side_sets;
   int i, j, k, m, *elem_map, *connect;
   int node_list[100];
   int ebids[10], nsids[10];
   int  num_qa_rec, num_info;
   int num_glo_vars, num_nod_vars, num_ele_vars, num_nset_vars;
   int *truth_tab;
   int whole_time_step, num_time_steps;
   int CPU_word_size,IO_word_size;
   int prop_array[2];

   float *glob_var_vals, *nodal_var_vals, *elem_var_vals;
   float *nset_var_vals;
   float time_value;
   float x[100];
   float attrib[10], dist_fact[100];
   char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
   char *block_names[10], *nset_names[10];
   char *prop_names[2], *attrib_names[2];
   char *title = "This is a test";
   ex_opts (EX_VERBOSE | EX_ABORT );

/* Specify compute and i/o word size */

   CPU_word_size = 0;                   /* sizeof(float) */
   IO_word_size = 4;                    /* (4 bytes) */

/* create EXODUS II file */

   exoid = ex_create ("oned.e",         /* filename path */
                       EX_CLOBBER,      /* create mode */
                       &CPU_word_size,  /* CPU float word size in bytes */
                       &IO_word_size);  /* I/O float word size in bytes */
   printf ("after ex_create for oned.e, exoid = %d\n", exoid);
   printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);

   EXCHECK(ex_set_max_name_length(exoid, 40));
   /* ncopts = NC_VERBOSE; */

/* initialize file with parameters */

   num_dim = 1;
   num_nodes = 10;
   num_elem = 10; /* 9 lines plus a point */
   num_elem_blk = 3;
   num_node_sets = 2;
   num_side_sets = 0;

   
   EXCHECK(ex_put_init (exoid, title, num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets, num_side_sets));

   for (i=0; i < num_nodes; i++) {
     x[i] = exp((float)i/10.0);
   }
   
   EXCHECK(ex_put_coord (exoid, x, NULL, NULL));
   
   coord_names[0] = "xcoor";
   EXCHECK(ex_put_coord_names (exoid, coord_names));
   
   /* Add nodal attributes */
   EXCHECK(ex_put_attr_param(exoid, EX_NODAL, 0, 1));
   
   EXCHECK(ex_put_one_attr(exoid, EX_NODAL, 0, 1, x));
   
   attrib_names[0] = "Node_attr_1";
   EXCHECK(ex_put_attr_names (exoid, EX_NODAL, 0, attrib_names));

   /* write element order map */
   elem_map = (int *) calloc(num_elem, sizeof(int));

   for (i=1; i<=num_elem; i++) {
     elem_map[i-1] = 10*i;
   }

   EXCHECK(ex_put_map (exoid, elem_map));
   free (elem_map);

   /* write element block parameters */
   block_names[0] = "left_side";
   block_names[1] = "right_side";
   block_names[2] = "center";

   num_elem_in_block[0] = 4;
   num_elem_in_block[1] = 5;
   num_elem_in_block[2] = 1;

   num_nodes_per_elem[0] = 2;
   num_nodes_per_elem[1] = 2;
   num_nodes_per_elem[2] = 1;

   ebids[0] = 10;
   ebids[1] = 20;
   ebids[2] = 30;

   EXCHECK(ex_put_elem_block (exoid, ebids[0], "line",  num_elem_in_block[0], num_nodes_per_elem[0], 1));
   EXCHECK(ex_put_elem_block (exoid, ebids[1], "line",  num_elem_in_block[1], num_nodes_per_elem[1], 1));
   EXCHECK(ex_put_elem_block (exoid, ebids[2], "point", num_elem_in_block[2], num_nodes_per_elem[2], 0));

   /* Write element block names */
   EXCHECK(ex_put_names(exoid, EX_ELEM_BLOCK, block_names));
   
   /* write element block properties */
   prop_names[0] = "DENSITY";
   EXCHECK(ex_put_prop_names(exoid,EX_ELEM_BLOCK,1,prop_names));
   EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], prop_names[0], 1.345));
   EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], prop_names[0], 10.995));
   EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], prop_names[0], 0.001));


   /* write element connectivity */
   connect = (int *) calloc(18, sizeof(int));
   for (i=0; i < num_elem*2; i+=2) {
     connect[i]   = i/2+1;
     connect[i+1] = i/2+2;
   }

   EXCHECK(ex_put_conn (exoid, EX_ELEM_BLOCK, ebids[0], connect, NULL, NULL));
   EXCHECK(ex_put_conn (exoid, EX_ELEM_BLOCK, ebids[1], connect+8, NULL, NULL));

   /* Circle */
   connect[0] = 5;
   EXCHECK(ex_put_conn (exoid, EX_ELEM_BLOCK, ebids[2], connect, NULL, NULL));

   /* write element block attributes */
   for (i=0; i < num_elem; i++) {
     attrib[i] = 3.14159 * i;
   }
   EXCHECK(ex_put_attr (exoid, EX_ELEM_BLOCK, ebids[0], attrib));
   EXCHECK(ex_put_attr (exoid, EX_ELEM_BLOCK, ebids[1], attrib+num_elem_in_block[0]));

   attrib_names[0] = "THICKNESS";
   EXCHECK(ex_put_attr_names (exoid, EX_ELEM_BLOCK, ebids[0], attrib_names));
   attrib_names[0] = "WIDTH";
   EXCHECK(ex_put_attr_names (exoid, EX_ELEM_BLOCK, ebids[1], attrib_names));

   /* write individual node sets */
   num_nodes_in_nset[0] = 5;
   num_nodes_in_nset[1] = 3;

   nsids[0] = 20;
   nsids[1] = 21;

   EXCHECK(ex_put_node_set_param (exoid, nsids[0], 5, 5));

   node_list[0] = 1;
   node_list[1] = 3;
   node_list[2] = 5;
   node_list[3] = 7;
   node_list[4] = 9;

   dist_fact[0] = 1.0;
   dist_fact[1] = 2.0;
   dist_fact[2] = 3.0;
   dist_fact[3] = 4.0;
   dist_fact[4] = 5.0;

   EXCHECK(ex_put_node_set (exoid, nsids[0], node_list));
   EXCHECK(ex_put_node_set_dist_fact (exoid, nsids[0], dist_fact));

   EXCHECK(ex_put_node_set_param (exoid, nsids[1], 3, 3));

   node_list[0] = 2;
   node_list[1] = 4;
   node_list[2] = 6;

   dist_fact[0] = 1.0;
   dist_fact[1] = 2.0;
   dist_fact[2] = 3.0;

   EXCHECK(ex_put_node_set (exoid, nsids[1], node_list));
   EXCHECK(ex_put_node_set_dist_fact (exoid, nsids[1], dist_fact));

   /* Write node set names */
   nset_names[0] = "all_odd_nodes";
   nset_names[1] = "some_even_nodes";

   EXCHECK(ex_put_names(exoid, EX_NODE_SET, nset_names));
   EXCHECK(ex_put_prop(exoid, EX_NODE_SET, nsids[0], "FACE", 4));

   EXCHECK(ex_put_prop(exoid, EX_NODE_SET, nsids[1], "FACE", 5));

   prop_array[0] = 1000;
   prop_array[1] = 2000;

   EXCHECK(ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array));
   /* Add nodeset attributes */
   EXCHECK(ex_put_attr_param(exoid, EX_NODE_SET, nsids[0], 1));
   
   EXCHECK(ex_put_attr(exoid, EX_NODE_SET, nsids[0], x));
   
   attrib_names[0] = "Nodeset_attribute";
   EXCHECK(ex_put_attr_names (exoid, EX_NODE_SET, nsids[0], attrib_names));

   /* write QA records; test empty and just blank-filled records */
   num_qa_rec = 2;

   qa_record[0][0] = "TESTWT";
   qa_record[0][1] = "testwt";
   qa_record[0][2] = "07/07/93";
   qa_record[0][3] = "15:41:33";
   qa_record[1][0] = "";
   qa_record[1][1] = "                            ";
   qa_record[1][2] = "";
   qa_record[1][3] = "                        ";

   EXCHECK(ex_put_qa (exoid, num_qa_rec, qa_record));

   /* write information records; test empty and just blank-filled records */
   num_info = 3;


   info[0] = "This is the first information record.";
   info[1] = "";
   info[2] = "                                     ";

   EXCHECK(ex_put_info (exoid, num_info, info));


   /* write results variables parameters and names */
   num_glo_vars = 1;

   var_names[0] = "glo_vars";

   EXCHECK(ex_put_variable_param (exoid, EX_GLOBAL, num_glo_vars));
   EXCHECK(ex_put_variable_names (exoid, EX_GLOBAL, num_glo_vars, var_names));

   num_nod_vars = 2;
   /*              12345678901234567890123456789012 */
   var_names[0] = "node_variable_a_very_long_name_0";
   var_names[1] = "nod_var1";

   EXCHECK(ex_put_variable_param (exoid, EX_NODAL, num_nod_vars));
   EXCHECK(ex_put_variable_names (exoid, EX_NODAL, num_nod_vars, var_names));

   num_ele_vars = 3;
   /*              0        1         2         3   */
   /*              12345678901234567890123456789012 */
   var_names[0] = "this_variable_name_is_short";
   var_names[1] = "this_variable_name_is_just_right";
   var_names[2] = "this_variable_name_is_tooooo_long";

   EXCHECK(ex_put_variable_param (exoid, EX_ELEM_BLOCK, num_ele_vars));
   EXCHECK(ex_put_variable_names (exoid, EX_ELEM_BLOCK, num_ele_vars, var_names));

   num_nset_vars = 3;
     
   var_names[0] = "ns_var0";
   var_names[1] = "ns_var1";
   var_names[2] = "ns_var2";
     
   EXCHECK(ex_put_variable_param (exoid, EX_NODE_SET, num_nset_vars));
   EXCHECK(ex_put_variable_names (exoid, EX_NODE_SET, num_nset_vars, var_names));
   

   /* write element variable truth table */
   truth_tab = (int *) calloc ((num_elem_blk*num_ele_vars), sizeof(int));

   k = 0;
   for (i=0; i<num_elem_blk; i++)
   {
      for (j=0; j<num_ele_vars; j++)
      {
         truth_tab[k++] = 1;
      }
   }

   EXCHECK(ex_put_truth_table(exoid, EX_ELEM_BLOCK, num_elem_blk, num_ele_vars, truth_tab));

   free (truth_tab);


/* for each time step, write the analysis results;
 * the code below fills the arrays glob_var_vals, 
 * nodal_var_vals, and elem_var_vals with values for debugging purposes;
 */

   whole_time_step = 1;
   num_time_steps = 10;

   glob_var_vals = (float *) calloc (num_glo_vars, CPU_word_size);
   nodal_var_vals = (float *) calloc (num_nodes, CPU_word_size);
   elem_var_vals = (float *) calloc (num_elem, CPU_word_size);
   nset_var_vals = (float *) calloc (10, CPU_word_size);
   
   for (i=0; i<num_time_steps; i++)
   {
     time_value = (float)(i+1)/100.;

     /* write time value */
     EXCHECK(ex_put_time (exoid, whole_time_step, &time_value));

     /* write global variables */
     for (j=0; j<num_glo_vars; j++) {
       glob_var_vals[j] = (float)(j+2) * time_value;
     }

     EXCHECK(ex_put_var (exoid, whole_time_step, EX_GLOBAL, 0, 0, num_glo_vars, glob_var_vals));

     /* write nodal variables */
     for (k=1; k<=num_nod_vars; k++) {
       for (j=0; j<num_nodes; j++) {
         nodal_var_vals[j] = (float)k + ((float)(j+1) * time_value);
       }
       EXCHECK(ex_put_var (exoid, whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals));
     }

     /* write element variables */
     for (k=1; k<=num_ele_vars; k++) {
       for (j=0; j<num_elem_blk; j++) {
         for (m=0; m<num_elem_in_block[j]; m++) {
           elem_var_vals[m] = (float)(k+1) + (float)(j+2) + 
                              ((float)(m+1)*time_value);
         }
         EXCHECK(ex_put_var (exoid, whole_time_step, EX_ELEM_BLOCK, k, ebids[j], num_elem_in_block[j], elem_var_vals));
       }
     }

     /* write nodeset variables */
     for (k=1; k<=num_nset_vars; k++) {
       for (j=0; j<num_node_sets; j++) {
         for (m=0; m<num_nodes_in_nset[j]; m++) {
           nset_var_vals[m] = (float)(k+3) + (float)(j+4) + 
                              ((float)(m+1)*time_value);
         }
         EXCHECK(ex_put_var (exoid, whole_time_step, EX_NODE_SET, k, nsids[j],  num_nodes_in_nset[j], nset_var_vals));
       }
     }

     whole_time_step++;

     /* update the data file; this should be done at the end of every time step
      * to ensure that no data is lost if the analysis dies
      */
     EXCHECK(ex_update (exoid));
   }

   free(glob_var_vals);
   free(nodal_var_vals);
   free(elem_var_vals);
   free(nset_var_vals);


/* close the EXODUS files */
   EXCHECK(ex_close (exoid));
   return 0;
}
Ejemplo n.º 5
0
void NemSpread<T,INT>::read_restart_params()

/* Function which reads the restart variable parameters for the EXODUS II
 * database which contains the results information. Allocate necessary
 * memory on each processor.
 *
 *----------------------------------------------------------------------------
 *
 * Functions called:
 *
 * compare_mesh_param -- function which checks that parameters in
 *                       the restart EXODUS II file are the same as in
 *                       the mesh EXODUS II file
 * read_var_param -- function which reads the time indicies, number
 *                   of variables, and their names from the restart file
 *
 *----------------------------------------------------------------------------
 */

{
    const char  *yo="read_restart_params";

    int    exoid, cpu_ws=0;
    float  vers;
    int    max_name_length = 0;

    /* Open the ExodusII file */
    cpu_ws = io_ws;
    int mode = EX_READ | int64api;
    if ((exoid=ex_open(Exo_Res_File, mode, &cpu_ws, &io_ws, &vers)) < 0) {
        fprintf(stderr, "%s: Could not open file %s for restart info\n",
                yo, Exo_Res_File);
        exit(1);
    }

    max_name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH);
    ex_set_max_name_length(exoid, max_name_length);

    /*
     * Just do a rudimentary check to figure out if the mesh parameters
     * in the results file are the same as the mesh parameters in the
     * mesh file.
     */
    if (strcmp(ExoFile, Exo_Res_File) != 0)
        if (!compare_mesh_param(exoid)) {
            fprintf(stderr, "%s: Mesh parameters in mesh and result files"
                    " differ\n", yo);
            exit(1);
        }

    /* get the time, and the variable names */
    if (read_var_param(exoid, max_name_length) < 0) {
        fprintf(stderr, "%s: Error occured while reading variable parameters\n",
                yo);
        exit(1);
    }

    /* Close the ExodusII file */
    ex_close(exoid);

    return;
}
Ejemplo n.º 6
0
int main (int argc, char **argv)
{
  int exoid, num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets;
  int num_side_sets, error;
  int i, j, k, node_ctr;
  int *elem_map, *connect, *node_list, *node_ctr_list, *elem_list, *side_list;
  int *ids; 
  int *num_nodes_per_set = NULL;
  int *num_elem_per_set = NULL;
  int *num_df_per_set = NULL;
  int *node_ind = NULL;
  int *elem_ind = NULL;
  int *df_ind = NULL;
  int num_qa_rec, num_info;
  int num_glo_vars, num_nod_vars, num_ele_vars;
  int num_nset_vars, num_sset_vars;
  int *truth_tab;
  int num_time_steps;
  int *num_elem_in_block = NULL;
  int *num_nodes_per_elem = NULL;
  int *num_attr = NULL;
  int num_nodes_in_set, num_elem_in_set;
  int num_sides_in_set, num_df_in_set;
  int list_len, elem_list_len, node_list_len, df_list_len;
  int node_num, time_step, var_index, beg_time, end_time, elem_num;
  int CPU_word_size,IO_word_size;
  int num_props, prop_value, *prop_values;
  int idum;
  int max_name_length;
  
  float time_value, *time_values, *var_values;
  float *x, *y, *z;
  float *attrib, *dist_fact;
  float version, fdum;

  char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
  char *block_names[10], *nset_names[10], *sset_names[10];
  char *attrib_names[10];
  char title[MAX_LINE_LENGTH+1], elem_type[MAX_STR_LENGTH+1];
  char title_chk[MAX_LINE_LENGTH+1];
  char *cdum = 0;
  char *prop_names[3];
  char *name = NULL;

  CPU_word_size = 0;                    /* sizeof(float) */
  IO_word_size = 0;                     /* use what is stored in file */

  ex_opts (EX_VERBOSE | EX_ABORT );

  /* open EXODUS II files */
  exoid = ex_open ("test.exo",  /* filename path */
                   EX_READ,             /* access mode = READ */
                   &CPU_word_size,      /* CPU word size */
                   &IO_word_size,       /* IO word size */
                   &version);           /* ExodusII library version */

  printf ("\nafter ex_open\n");
  if (exoid < 0) exit(1);


				   
  printf ("test.exo is an EXODUSII file; version %4.2f\n",
          version);
  /*   printf ("         CPU word size %1d\n",CPU_word_size);  */
  printf ("         I/O word size %1d\n",IO_word_size);
  ex_inquire(exoid,EX_INQ_API_VERS, &idum, &version, cdum);
  printf ("EXODUSII API; version %4.2f\n", version);

  ex_inquire(exoid,EX_INQ_LIB_VERS, &idum, &version, cdum);
  printf ("EXODUSII Library API; version %4.2f (%d)\n", version, idum);

  /* Query size of names used in this file */
  {
    int max_all_name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_ALLOWED_NAME_LENGTH);
    int max_use_name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH);
    printf ("This file can use at most %d-character names\n", max_all_name_length);
    printf ("The maximum name length used is %d-character names\n", max_use_name_length);

    max_name_length = max_use_name_length;
    ex_set_max_name_length(exoid, max_name_length);
  }
  
  name = (char *) calloc(max_name_length+1, sizeof(char));
  
  /* read database parameters */
  error = ex_get_init (exoid, title, &num_dim, &num_nodes, &num_elem,
                       &num_elem_blk, &num_node_sets, &num_side_sets);

  printf ("after ex_get_init, error = %3d\n", error);

  printf ("database parameters:\n");
  printf ("title =  '%s'\n",title);
  printf ("num_dim = %3d\n",num_dim);
  printf ("num_nodes = %3d\n",num_nodes);
  printf ("num_elem = %3d\n",num_elem);
  printf ("num_elem_blk = %3d\n",num_elem_blk);
  printf ("num_node_sets = %3d\n",num_node_sets);
  printf ("num_side_sets = %3d\n",num_side_sets);

  /* Check that ex_inquire gives same title */
  error = ex_inquire (exoid, EX_INQ_TITLE, &idum, &fdum, title_chk);
  printf ("after ex_inquire, error = %3d\n", error);
  if (strcmp(title, title_chk) != 0) {
    printf ("error in ex_inquire for EX_INQ_TITLE\n");
  }
  
  /* read nodal coordinates values and names from database */

  x = (float *) calloc(num_nodes, sizeof(float));
  y = (float *) calloc(num_nodes, sizeof(float));
  if (num_dim >= 3)
    z = (float *) calloc(num_nodes, sizeof(float));
  else
    z = 0;

  error = ex_get_coord (exoid, x, y, z);
  printf ("\nafter ex_get_coord, error = %3d\n", error);

  printf ("x coords = \n");
  for (i=0; i<num_nodes; i++)
    {
      printf ("%5.1f\n", x[i]);
    }

  printf ("y coords = \n");
  for (i=0; i<num_nodes; i++)
    {
      printf ("%5.1f\n", y[i]);
    }

  if (num_dim >= 3)
    {
      printf ("z coords = \n");
      for (i=0; i<num_nodes; i++)
        {
          printf ("%5.1f\n", z[i]);
        }
    }

  /*
    error = ex_get_1_coord (exoid, 2, x, y, z);
    printf ("\nafter ex_get_1_coord, error = %3d\n", error);

    printf ("x coord of node 2 = \n");
    printf ("%f \n", x[0]);

    printf ("y coord of node 2 = \n");
    printf ("%f \n", y[0]);
  */
  free (x);
  free (y);
  if (num_dim >= 3)
    free (z);


  for (i=0; i<num_dim; i++)
    {
      coord_names[i] = (char *) calloc ((max_name_length+1), sizeof(char));
    }

  error = ex_get_coord_names (exoid, coord_names);
  printf ("\nafter ex_get_coord_names, error = %3d\n", error);
  printf ("x coord name = '%s'\n", coord_names[0]);
  printf ("y coord name = '%s'\n", coord_names[1]);
  if (num_dim >2)
    printf ("z coord name = '%s'\n", coord_names[2]);

  for (i=0; i<num_dim; i++)
    free(coord_names[i]);

  {
    int num_attrs = 0;
    error = ex_get_attr_param(exoid, EX_NODAL, 0, &num_attrs);
    printf (" after ex_get_attr_param, error = %d\n", error);
    printf ("num nodal attributes = %d\n", num_attrs);
    if (num_attrs > 0) {
      for (j=0; j<num_attrs; j++) {
	attrib_names[j] = (char *)calloc ((max_name_length+1), sizeof(char));
      }
      error = ex_get_attr_names (exoid, EX_NODAL, 0, attrib_names);
      printf (" after ex_get_attr_names, error = %d\n", error);
      
      if (error == 0) {
	attrib = (float *) calloc(num_nodes,sizeof(float));
	for (j=0; j<num_attrs; j++) {
	  printf ("nodal attribute %d = '%s'\n", j, attrib_names[j]);
	  error = ex_get_one_attr(exoid, EX_NODAL, 0, j+1, attrib);
	  printf (" after ex_get_one_attr, error = %d\n", error);
	  for (i=0; i < num_nodes; i++) {
	    printf ("%5.1f\n", attrib[i]);
	  }
	  free(attrib_names[j]);
	}
	free(attrib);
      }
    }
  }
  
  /* read element order map */

  elem_map = (int *) calloc(num_elem, sizeof(int));

  error = ex_get_map (exoid, elem_map);
  printf ("\nafter ex_get_map, error = %3d\n", error);

  for (i=0; i<num_elem; i++)
    {
      printf ("elem_map(%d) = %d \n", i, elem_map[i]);
    }

  free (elem_map);

  /* read element block parameters */

  if (num_elem_blk > 0) {
    ids = (int *) calloc(num_elem_blk, sizeof(int));
    num_elem_in_block = (int *) calloc(num_elem_blk, sizeof(int));
    num_nodes_per_elem = (int *) calloc(num_elem_blk, sizeof(int));
    num_attr = (int *) calloc(num_elem_blk, sizeof(int));
     
    error = ex_get_elem_blk_ids (exoid, ids);
    printf ("\nafter ex_get_elem_blk_ids, error = %3d\n", error);
     
    for (i=0; i<num_elem_blk; i++) {
      block_names[i] = (char *) calloc ((max_name_length+1), sizeof(char));
    }

    error = ex_get_names(exoid, EX_ELEM_BLOCK, block_names);
    printf ("\nafter ex_get_names, error = %3d\n", error);
    
    for (i=0; i<num_elem_blk; i++)
      {
	ex_get_name(exoid, EX_ELEM_BLOCK, ids[i], name);
	if (strcmp(name, block_names[i]) != 0) {
	  printf ("error in ex_get_name for block id %d\n", ids[i]);
	}
        error = ex_get_elem_block (exoid, ids[i], elem_type,
                                   &(num_elem_in_block[i]), 
                                   &(num_nodes_per_elem[i]), &(num_attr[i]));
        printf ("\nafter ex_get_elem_block, error = %d\n", error);
         
        printf ("element block id = %2d\n",ids[i]);
        printf ("element type = '%s'\n", elem_type);
        printf ("num_elem_in_block = %2d\n",num_elem_in_block[i]);
        printf ("num_nodes_per_elem = %2d\n",num_nodes_per_elem[i]);
        printf ("num_attr = %2d\n",num_attr[i]);
        printf ("name = '%s'\n",block_names[i]);
	free(block_names[i]);
      }
     
    /* read element block properties */
    error = ex_inquire (exoid, EX_INQ_EB_PROP, &num_props, &fdum, cdum);
    printf ("\nafter ex_inquire, error = %d\n", error);
    printf ("\nThere are %2d properties for each element block\n", num_props);
     
    for (i=0; i<num_props; i++)
      {
        prop_names[i] = (char *) calloc ((max_name_length+1), sizeof(char));
      }
     
    error = ex_get_prop_names(exoid,EX_ELEM_BLOCK,prop_names);
    printf ("after ex_get_prop_names, error = %d\n", error);
     
     
    for (i=1; i<num_props; i++) /* Prop 1 is id; skip that here */
      {
        for (j=0; j<num_elem_blk; j++)
          {
            error = ex_get_prop(exoid, EX_ELEM_BLOCK, ids[j], prop_names[i],
                                &prop_value);
            if (error == 0)
              printf ("element block %2d, property(%2d): '%s'= %5d\n",
                      j+1, i+1, prop_names[i], prop_value);
            else
              printf ("after ex_get_prop, error = %d\n", error);
          }
      }
     
    for (i=0; i<num_props; i++)
      free(prop_names[i]);
  }
   
  /* read element connectivity */

  for (i=0; i<num_elem_blk; i++)
    {
      if (num_elem_in_block[i] > 0) {
	connect = (int *) calloc((num_nodes_per_elem[i] * num_elem_in_block[i]), 
				 sizeof(int));
	
	error = ex_get_elem_conn (exoid, ids[i], connect);
	printf ("\nafter ex_get_elem_conn, error = %d\n", error);
	
	
	printf ("connect array for elem block %2d\n", ids[i]);
	
	for (j=0; j<num_nodes_per_elem[i]; j++)
	  {
	    printf ("%3d\n", connect[j]);
	  }
	/*
	  error = ex_get_1_elem_conn (exoid, 1, ids[i], connect);
	  printf ("\nafter ex_get_elem_conn, error = %d\n", error);
	  
	  printf ("node list for first element of element block %d \n ", ids[i]);
	  for (j=0; j<num_nodes_per_elem[i]; j++)
	  {
	  printf ("%d \n", connect[j]);
	  }
	*/
	free (connect);
      }
    }

  /* read element block attributes */

  for (i=0; i<num_elem_blk; i++)
    {
      if (num_elem_in_block[i] > 0) {
	for (j=0; j<num_attr[i]; j++)
	  attrib_names[j] = (char *) calloc ((max_name_length+1), sizeof(char));
	
	attrib = (float *) calloc(num_attr[i]*num_elem_in_block[i],sizeof(float));
	error = ex_get_elem_attr (exoid, ids[i], attrib);
	printf ("\n after ex_get_elem_attr, error = %d\n", error);
	
	if (error == 0) {
	  error = ex_get_elem_attr_names (exoid, ids[i], attrib_names);
	  printf (" after ex_get_elem_attr_names, error = %d\n", error);
	  
	  if (error == 0) {
	    printf ("element block %d attribute '%s' = %6.4f\n", ids[i], attrib_names[0], *attrib);
	  }
	}
	free (attrib);
	for (j=0; j<num_attr[i]; j++)
	  free (attrib_names[j]);
      }
    }
      
  if (num_elem_blk > 0) {
    free (ids);
    free (num_nodes_per_elem);
    free (num_attr);
  }

  /* read individual node sets */
  if (num_node_sets > 0) {
    ids = (int *) calloc(num_node_sets, sizeof(int));

    error = ex_get_node_set_ids (exoid, ids);
    printf ("\nafter ex_get_node_set_ids, error = %3d\n", error);

    for (i=0; i<num_node_sets; i++) {
      nset_names[i] = (char *) calloc ((max_name_length+1), sizeof(char));
    }

    error = ex_get_names(exoid, EX_NODE_SET, nset_names);
    printf ("\nafter ex_get_names, error = %3d\n", error);

    for (i=0; i<num_node_sets; i++)
      {
	ex_get_name(exoid, EX_NODE_SET, ids[i], name);
	if (strcmp(name, nset_names[i]) != 0) {
	  printf ("error in ex_get_name for nodeset id %d\n", ids[i]);
	}

        error = ex_get_node_set_param (exoid, ids[i], 
                                       &num_nodes_in_set, &num_df_in_set);
        printf ("\nafter ex_get_node_set_param, error = %3d\n", error);

        printf ("\nnode set %2d parameters: \n", ids[i]);
        printf ("num_nodes = %2d\n", num_nodes_in_set);
	printf ("name = '%s'\n", nset_names[i]);
	free(nset_names[i]);
        node_list = (int *) calloc(num_nodes_in_set, sizeof(int));
        dist_fact = (float *) calloc(num_nodes_in_set, sizeof(float));

        error = ex_get_node_set (exoid, ids[i], node_list);
        printf ("\nafter ex_get_node_set, error = %3d\n", error);

        if (num_df_in_set > 0)
          {
            error = ex_get_node_set_dist_fact (exoid, ids[i], dist_fact);
            printf ("\nafter ex_get_node_set_dist_fact, error = %3d\n", error);
          }

        printf ("\nnode list for node set %2d\n", ids[i]);

        for (j=0; j<num_nodes_in_set; j++)
          {
            printf ("%3d\n", node_list[j]);
          }

        if (num_df_in_set > 0)
          {
            printf ("dist factors for node set %2d\n", ids[i]);

            for (j=0; j<num_df_in_set; j++)
              {
                printf ("%5.2f\n", dist_fact[j]);
              }
          }
        else
          printf ("no dist factors for node set %2d\n", ids[i]);

        free (node_list);
        free (dist_fact);

	{
	  int num_attrs = 0;
	  error = ex_get_attr_param(exoid, EX_NODE_SET, ids[i], &num_attrs);
	  printf (" after ex_get_attr_param, error = %d\n", error);
	  printf ("num nodeset attributes for nodeset %d = %d\n", ids[i], num_attrs);
	  if (num_attrs > 0) {
	    for (j=0; j<num_attrs; j++) {
	      attrib_names[j] = (char *)calloc ((max_name_length+1), sizeof(char));
	    }
	    error = ex_get_attr_names (exoid, EX_NODE_SET, ids[i], attrib_names);
	    printf (" after ex_get_attr_names, error = %d\n", error);
	    
	    if (error == 0) {
	      attrib = (float *) calloc(num_nodes_in_set,sizeof(float));
	      for (j=0; j<num_attrs; j++) {
		printf ("nodeset attribute %d = '%s'\n", j, attrib_names[j]);
		error = ex_get_one_attr(exoid, EX_NODE_SET, ids[i], j+1, attrib);
		printf (" after ex_get_one_attr, error = %d\n", error);
		for (k=0; k < num_nodes_in_set; k++) {
		  printf ("%5.1f\n", attrib[k]);
		}
		free(attrib_names[j]);
	      }
	      free(attrib);
	    }
	  }
	}
      }
    free(ids);

    /* read node set properties */
    error = ex_inquire (exoid, EX_INQ_NS_PROP, &num_props, &fdum, cdum);
    printf ("\nafter ex_inquire, error = %d\n", error);
    printf ("\nThere are %2d properties for each node set\n", num_props);

    for (i=0; i<num_props; i++)
      {
        prop_names[i] = (char *) calloc ((max_name_length+1), sizeof(char));
      }
    prop_values = (int *) calloc (num_node_sets, sizeof(int));

    error = ex_get_prop_names(exoid,EX_NODE_SET,prop_names);
    printf ("after ex_get_prop_names, error = %d\n", error);


    for (i=0; i<num_props; i++)
      {
        error = ex_get_prop_array(exoid, EX_NODE_SET, prop_names[i],
                                  prop_values);
        if (error == 0)
          for (j=0; j<num_node_sets; j++)
            printf ("node set %2d, property(%2d): '%s'= %5d\n",
                    j+1, i+1, prop_names[i], prop_values[j]);
        else
          printf ("after ex_get_prop_array, error = %d\n", error);
      }
    for (i=0; i<num_props; i++)
      free(prop_names[i]);
    free(prop_values);

    /* read concatenated node sets; this produces the same information as
     * the above code which reads individual node sets
     */

    error = ex_inquire (exoid, EX_INQ_NODE_SETS, &num_node_sets, &fdum, cdum);
    printf ("\nafter ex_inquire, error = %3d\n",error);

    ids = (int *) calloc(num_node_sets, sizeof(int));
    num_nodes_per_set = (int *) calloc(num_node_sets, sizeof(int));
    num_df_per_set = (int *) calloc(num_node_sets, sizeof(int));
    node_ind = (int *) calloc(num_node_sets, sizeof(int));
    df_ind = (int *) calloc(num_node_sets, sizeof(int));

    error = ex_inquire (exoid, EX_INQ_NS_NODE_LEN, &list_len, &fdum, cdum);
    printf ("\nafter ex_inquire: EX_INQ_NS_NODE_LEN = %d, error = %3d\n",
            list_len, error);
    node_list = (int *) calloc(list_len, sizeof(int));

    error = ex_inquire (exoid, EX_INQ_NS_DF_LEN, &list_len, &fdum, cdum);
    printf ("\nafter ex_inquire: EX_INQ_NS_DF_LEN = %d, error = %3d\n",
            list_len, error);
    dist_fact = (float *) calloc(list_len, sizeof(float));

    error = ex_get_concat_node_sets (exoid,ids,num_nodes_per_set,num_df_per_set,
                                     node_ind, df_ind, node_list, dist_fact);
    printf ("\nafter ex_get_concat_node_sets, error = %3d\n", error);

    printf ("\nconcatenated node set info\n");

    printf ("ids = \n");
    for (i=0; i<num_node_sets; i++) printf ("%3d\n", ids[i]);

    printf ("num_nodes_per_set = \n");
    for (i=0; i<num_node_sets; i++) printf ("%3d\n", num_nodes_per_set[i]);

    printf ("node_ind = \n");
    for (i=0; i<num_node_sets; i++) printf ("%3d\n", node_ind[i]);

    printf ("node_list = \n");
    for (i=0; i<list_len; i++) printf ("%3d\n", node_list[i]);

    printf ("dist_fact = \n");
    for (i=0; i<list_len; i++) printf ("%5.3f\n", dist_fact[i]);

    free (ids);
    free (df_ind);
    free (node_ind);
    free (num_df_per_set);
    free (node_list);
    free (dist_fact);
  }

  /* read individual side sets */

  if (num_side_sets > 0) {
    ids = (int *) calloc(num_side_sets, sizeof(int));
    
    error = ex_get_side_set_ids (exoid, ids);
    printf ("\nafter ex_get_side_set_ids, error = %3d\n", error);
    
    for (i=0; i<num_side_sets; i++) {
      sset_names[i] = (char *) calloc ((max_name_length+1), sizeof(char));
    }

    error = ex_get_names(exoid, EX_SIDE_SET, sset_names);
    printf ("\nafter ex_get_names, error = %3d\n", error);

    for (i=0; i<num_side_sets; i++)
      {
	ex_get_name(exoid, EX_SIDE_SET, ids[i], name);
	if (strcmp(name, sset_names[i]) != 0) {
	  printf ("error in ex_get_name for sideset id %d\n", ids[i]);
	}

        error = ex_get_side_set_param (exoid, ids[i], &num_sides_in_set, 
                                       &num_df_in_set);
        printf ("\nafter ex_get_side_set_param, error = %3d\n", error);
        
        printf ("side set %2d parameters:\n",ids[i]);
	printf ("name = '%s'\n", sset_names[i]);
        printf ("num_sides = %3d\n",num_sides_in_set);
        printf ("num_dist_factors = %3d\n", num_df_in_set);
	free(sset_names[i]);
        
        
        /* Note: The # of elements is same as # of sides!  */
        num_elem_in_set = num_sides_in_set;
        elem_list = (int *) calloc(num_elem_in_set, sizeof(int));
        side_list = (int *) calloc(num_sides_in_set, sizeof(int));
        node_ctr_list = (int *) calloc(num_elem_in_set, sizeof(int));
        node_list = (int *) calloc(num_elem_in_set*21, sizeof(int));
        dist_fact = (float *) calloc(num_df_in_set, sizeof(float));
        
        error = ex_get_side_set (exoid, ids[i], elem_list, side_list);
        printf ("\nafter ex_get_side_set, error = %3d\n", error);
        
        error = ex_get_side_set_node_list (exoid, ids[i], node_ctr_list,
                                           node_list);
        printf ("\nafter ex_get_side_set_node_list, error = %3d\n", error);
        
        if (num_df_in_set > 0)
          {
            error = ex_get_side_set_dist_fact (exoid, ids[i], dist_fact);
            printf ("\nafter ex_get_side_set_dist_fact, error = %3d\n", error);
          }
        
        printf ("element list for side set %2d\n", ids[i]);
        for (j=0; j<num_elem_in_set; j++)
          {
            printf ("%3d\n", elem_list[j]);
          }
        
        printf ("side list for side set %2d\n", ids[i]);
        for (j=0; j<num_sides_in_set; j++)
          {
            printf ("%3d\n", side_list[j]);
          }
        
        node_ctr = 0;
        printf ("node list for side set %2d\n", ids[i]);
        for (k=0; k<num_elem_in_set; k++)
          {
            for (j=0; j<node_ctr_list[k]; j++)
              {
                printf ("%3d\n", node_list[node_ctr+j]);
              }
            node_ctr += node_ctr_list[k];
          }
        
        if (num_df_in_set > 0)
          {
            printf ("dist factors for side set %2d\n", ids[i]);
            
            for (j=0; j<num_df_in_set; j++)
              {
                printf ("%5.3f\n", dist_fact[j]);
              }
          }
        else
          printf ("no dist factors for side set %2d\n", ids[i]);
        
        free (elem_list);
        free (side_list);
        free (node_ctr_list);
        free (node_list);
        free (dist_fact);
        
      }
    
    /* read side set properties */
    error = ex_inquire (exoid, EX_INQ_SS_PROP, &num_props, &fdum, cdum);
    printf ("\nafter ex_inquire, error = %d\n", error);
    printf ("\nThere are %2d properties for each side set\n", num_props);
    
    for (i=0; i<num_props; i++)
      {
        prop_names[i] = (char *) calloc ((max_name_length+1), sizeof(char));
      }
    
    error = ex_get_prop_names(exoid,EX_SIDE_SET,prop_names);
    printf ("after ex_get_prop_names, error = %d\n", error);


    for (i=0; i<num_props; i++)
      {
        for (j=0; j<num_side_sets; j++)
          {
            error = ex_get_prop(exoid, EX_SIDE_SET, ids[j], prop_names[i],
                                &prop_value);
            if (error == 0)
              printf ("side set %2d, property(%2d): '%s'= %5d\n",
                      j+1, i+1, prop_names[i], prop_value);
            else
              printf ("after ex_get_prop, error = %d\n", error);
          }
      }
    for (i=0; i<num_props; i++)
      free(prop_names[i]);
    free (ids);

    error = ex_inquire (exoid, EX_INQ_SIDE_SETS, &num_side_sets, &fdum, cdum);
    printf ("\nafter ex_inquire: EX_INQ_SIDE_SETS = %d,  error = %d\n",
            num_side_sets, error);

    if (num_side_sets > 0)
      {
        error = ex_inquire(exoid, EX_INQ_SS_ELEM_LEN, &elem_list_len, &fdum, cdum);
        printf ("\nafter ex_inquire: EX_INQ_SS_ELEM_LEN = %d,  error = %d\n",
                elem_list_len, error);

        error = ex_inquire(exoid, EX_INQ_SS_NODE_LEN, &node_list_len, &fdum, cdum);
        printf ("\nafter ex_inquire: EX_INQ_SS_NODE_LEN = %d,  error = %d\n",
                node_list_len, error);

        error = ex_inquire(exoid, EX_INQ_SS_DF_LEN, &df_list_len, &fdum, cdum);
        printf ("\nafter ex_inquire: EX_INQ_SS_DF_LEN = %d,  error = %d\n",
                df_list_len, error);
      }

    /* read concatenated side sets; this produces the same information as
     * the above code which reads individual side sets
     */

    /* concatenated side set read */

    if (num_side_sets > 0) {
      ids = (int *) calloc(num_side_sets, sizeof(int));
      num_elem_per_set = (int *) calloc(num_side_sets, sizeof(int));
      num_df_per_set = (int *) calloc(num_side_sets, sizeof(int));
      elem_ind = (int *) calloc(num_side_sets, sizeof(int));
      df_ind = (int *) calloc(num_side_sets, sizeof(int));
      elem_list = (int *) calloc(elem_list_len, sizeof(int));
      side_list = (int *) calloc(elem_list_len, sizeof(int));
      dist_fact = (float *) calloc(df_list_len, sizeof(float));
     
      error = ex_get_concat_side_sets (exoid, ids, num_elem_per_set, 
                                       num_df_per_set, elem_ind, df_ind, 
                                       elem_list, side_list, dist_fact);
      printf ("\nafter ex_get_concat_side_sets, error = %3d\n", error);
     
      printf ("concatenated side set info\n");
     
      printf ("ids = \n");
      for (i=0; i<num_side_sets; i++) printf ("%3d\n", ids[i]);
     
      printf ("num_elem_per_set = \n");
      for (i=0; i<num_side_sets; i++) printf ("%3d\n", num_elem_per_set[i]);
     
      printf ("num_dist_per_set = \n");
      for (i=0; i<num_side_sets; i++) printf ("%3d\n", num_df_per_set[i]);
     
      printf ("elem_ind = \n");
      for (i=0; i<num_side_sets; i++) printf ("%3d\n", elem_ind[i]);
     
      printf ("dist_ind = \n");
      for (i=0; i<num_side_sets; i++) printf ("%3d\n", df_ind[i]);
     
      printf ("elem_list = \n");
      for (i=0; i<elem_list_len; i++) printf ("%3d\n", elem_list[i]);
     
      printf ("side_list = \n");
      for (i=0; i<elem_list_len; i++) printf ("%3d\n", side_list[i]);
     
      printf ("dist_fact = \n");
      for (i=0; i<df_list_len; i++) printf ("%5.3f\n", dist_fact[i]);
     
      free (ids);
      free (num_df_per_set);
      free (df_ind);
      free (elem_ind);
      free (elem_list);
      free (side_list);
      free (dist_fact);
    }
  }   
  /* end of concatenated side set read */

  /* read QA records */

  ex_inquire (exoid, EX_INQ_QA, &num_qa_rec, &fdum, cdum);

  for (i=0; i<num_qa_rec; i++)
    {
      for (j=0; j<4; j++)
        {
          qa_record[i][j] = (char *) calloc ((max_name_length+1), sizeof(char));
        }
    }

  error = ex_get_qa (exoid, qa_record); 
  printf ("\nafter ex_get_qa, error = %3d\n", error);

  printf ("QA records = \n");
  for (i=0; i<num_qa_rec; i++) 
    {
      for (j=0; j<4; j++)
        {
          printf (" '%s'\n", qa_record[i][j]);
          free(qa_record[i][j]);
        }
    }

  /* read information records */

  error = ex_inquire (exoid, EX_INQ_INFO, &num_info, &fdum, cdum);
  printf ("\nafter ex_inquire, error = %3d\n", error);

  for (i=0; i<num_info; i++)
    {
      info[i] = (char *) calloc ((MAX_LINE_LENGTH+1), sizeof(char));
    }

  error = ex_get_info (exoid, info); 
  printf ("\nafter ex_get_info, error = %3d\n", error);

  printf ("info records = \n");
  for (i=0; i<num_info; i++)
    {
      printf (" '%s'\n", info[i]);
      free(info[i]);
    }

  /* read global variables parameters and names */

  error = ex_get_var_param (exoid, "g", &num_glo_vars);
  printf ("\nafter ex_get_var_param, error = %3d\n", error);

  for (i=0; i<num_glo_vars; i++)
    {
      var_names[i] = (char *) calloc ((max_name_length+1), sizeof(char));
    }

  error = ex_get_var_names (exoid, "g", num_glo_vars, var_names);
  printf ("\nafter ex_get_var_names, error = %3d\n", error);

  printf ("There are %2d global variables; their names are :\n", 
          num_glo_vars);
  for (i=0; i<num_glo_vars; i++)
    {
      printf (" '%s'\n", var_names[i]);
      free(var_names[i]);
    }

  /* read nodal variables parameters and names */
  num_nod_vars = 0;
  if (num_nodes > 0) {
    error = ex_get_var_param (exoid, "n", &num_nod_vars);
    printf ("\nafter ex_get_var_param, error = %3d\n", error);

    for (i=0; i<num_nod_vars; i++)
      {
        var_names[i] = (char *) calloc ((max_name_length+1), sizeof(char));
      }

    error = ex_get_var_names (exoid, "n", num_nod_vars, var_names);
    printf ("\nafter ex_get_var_names, error = %3d\n", error);

    printf ("There are %2d nodal variables; their names are :\n", num_nod_vars);
    for (i=0; i<num_nod_vars; i++)
      {
        printf (" '%s'\n", var_names[i]);
        free(var_names[i]);
      }
  }

  /* read element variables parameters and names */

  num_ele_vars = 0;
  if (num_elem > 0) {
    error = ex_get_var_param (exoid, "e", &num_ele_vars);
    printf ("\nafter ex_get_var_param, error = %3d\n", error);
     
    for (i=0; i<num_ele_vars; i++)
      {
        var_names[i] = (char *) calloc ((max_name_length+1), sizeof(char));
      }
     
    error = ex_get_var_names (exoid, "e", num_ele_vars, var_names);
    printf ("\nafter ex_get_var_names, error = %3d\n", error);
     
    printf ("There are %2d element variables; their names are :\n", 
            num_ele_vars);
    for (i=0; i<num_ele_vars; i++)
      {
        printf (" '%s'\n", var_names[i]);
        free(var_names[i]);
      }

    /* read element variable truth table */

    if (num_ele_vars > 0) {
      truth_tab = (int *) calloc ((num_elem_blk*num_ele_vars), sizeof(int));
     
      error = ex_get_elem_var_tab (exoid, num_elem_blk, num_ele_vars, truth_tab);
      printf ("\nafter ex_get_elem_var_tab, error = %3d\n", error);
     
      printf ("This is the element variable truth table:\n");
     
      k = 0;
      for (i=0; i<num_elem_blk*num_ele_vars; i++)
        {
          printf ("%2d\n", truth_tab[k++]);
        }
      free (truth_tab);
    }
  }

  /* read nodeset variables parameters and names */

  num_nset_vars = 0;
  if (num_node_sets > 0) {
    error = ex_get_var_param (exoid, "m", &num_nset_vars);
    printf ("\nafter ex_get_var_param, error = %3d\n", error);
     
    if (num_nset_vars > 0) {
      for (i=0; i<num_nset_vars; i++)
	{
	  var_names[i] = (char *) calloc ((max_name_length+1), sizeof(char));
	}
     
      error = ex_get_var_names (exoid, "m", num_nset_vars, var_names);
      printf ("\nafter ex_get_var_names, error = %3d\n", error);
     
      printf ("There are %2d nodeset variables; their names are :\n", 
	      num_nset_vars);
      for (i=0; i<num_nset_vars; i++)
	{
	  printf (" '%s'\n", var_names[i]);
	  free(var_names[i]);
	}

      /* read nodeset variable truth table */

      if (num_nset_vars > 0) {
	truth_tab = (int *) calloc ((num_node_sets*num_nset_vars), sizeof(int));
     
	error = ex_get_nset_var_tab (exoid, num_node_sets, num_nset_vars, truth_tab);
	printf ("\nafter ex_get_nset_var_tab, error = %3d\n", error);
     
	printf ("This is the nodeset variable truth table:\n");
     
	k = 0;
	for (i=0; i<num_node_sets*num_nset_vars; i++)
	  {
	    printf ("%2d\n", truth_tab[k++]);
	  }
	free (truth_tab);
      }
    }
  }

  /* read sideset variables parameters and names */

  num_sset_vars = 0;
  if (num_side_sets > 0) {
    error = ex_get_var_param (exoid, "s", &num_sset_vars);
    printf ("\nafter ex_get_var_param, error = %3d\n", error);
     
    if (num_sset_vars > 0) {
      for (i=0; i<num_sset_vars; i++)
	{
	  var_names[i] = (char *) calloc ((max_name_length+1), sizeof(char));
	}
     
      error = ex_get_var_names (exoid, "s", num_sset_vars, var_names);
      printf ("\nafter ex_get_var_names, error = %3d\n", error);
     
      printf ("There are %2d sideset variables; their names are :\n", 
	      num_sset_vars);
      for (i=0; i<num_sset_vars; i++)
	{
	  printf (" '%s'\n", var_names[i]);
	  free(var_names[i]);
	}

      /* read sideset variable truth table */

      if (num_sset_vars > 0) {
	truth_tab = (int *) calloc ((num_side_sets*num_sset_vars), sizeof(int));
     
	error = ex_get_sset_var_tab (exoid, num_side_sets, num_sset_vars, truth_tab);
	printf ("\nafter ex_get_sset_var_tab, error = %3d\n", error);
     
	printf ("This is the sideset variable truth table:\n");
     
	k = 0;
	for (i=0; i<num_side_sets*num_sset_vars; i++)
	  {
	    printf ("%2d\n", truth_tab[k++]);
	  }
	free (truth_tab);
      }
    }
  }

  /* determine how many time steps are stored */

  error = ex_inquire (exoid, EX_INQ_TIME, &num_time_steps, &fdum, cdum);
  printf ("\nafter ex_inquire, error = %3d\n", error);
  printf ("There are %2d time steps in the database.\n", num_time_steps);

  /* read time value at one time step */

  time_step = 3;
  error = ex_get_time (exoid, time_step, &time_value);
  printf ("\nafter ex_get_time, error = %3d\n", error);

  printf ("time value at time step %2d = %5.3f\n", time_step, time_value);

  /* read time values at all time steps */

  time_values = (float *) calloc (num_time_steps, sizeof(float));

  error = ex_get_all_times (exoid, time_values);
  printf ("\nafter ex_get_all_times, error = %3d\n", error);

  printf ("time values at all time steps are:\n");
  for (i=0; i<num_time_steps; i++) printf ("%5.3f\n", time_values[i]);

  free (time_values);

  /* read all global variables at one time step */

  var_values = (float *) calloc (num_glo_vars, sizeof(float));

  error = ex_get_glob_vars (exoid, time_step, num_glo_vars, var_values);
  printf ("\nafter ex_get_glob_vars, error = %3d\n", error);

  printf ("global variable values at time step %2d\n", time_step);
  for (i=0; i<num_glo_vars; i++) printf ("%5.3f\n", var_values[i]);

  free (var_values); 

  /* read a single global variable through time */

  var_index = 1;
  beg_time = 1;
  end_time = -1;

  var_values = (float *) calloc (num_time_steps, sizeof(float));

  error = ex_get_glob_var_time (exoid, var_index, beg_time, end_time, 
                                var_values);
  printf ("\nafter ex_get_glob_var_time, error = %3d\n", error);

  printf ("global variable %2d values through time:\n", var_index);
  for (i=0; i<num_time_steps; i++) printf ("%5.3f\n", var_values[i]);

  free (var_values); 

  /* read a nodal variable at one time step */

  if (num_nodes > 0) {
    var_values = (float *) calloc (num_nodes, sizeof(float));

    error = ex_get_nodal_var (exoid, time_step, var_index, num_nodes, 
                              var_values);
    printf ("\nafter ex_get_nodal_var, error = %3d\n", error);

    printf ("nodal variable %2d values at time step %2d\n", var_index, 
            time_step);
    for (i=0; i<num_nodes; i++) printf ("%5.3f\n", var_values[i]);

    free (var_values); 

    /* read a nodal variable through time */

    var_values = (float *) calloc (num_time_steps, sizeof(float));

    node_num = 1;
    error = ex_get_nodal_var_time (exoid, var_index, node_num, beg_time, 
                                   end_time, var_values);
    printf ("\nafter ex_get_nodal_var_time, error = %3d\n", error);

    printf ("nodal variable %2d values for node %2d through time:\n", var_index,
            node_num);
    for (i=0; i<num_time_steps; i++) printf ("%5.3f\n", var_values[i]);

    free (var_values); 
  }
  /* read an element variable at one time step */

  if (num_elem_blk > 0) {
    ids = (int *) calloc(num_elem_blk, sizeof(int));
     
    error = ex_get_elem_blk_ids (exoid, ids);
    printf ("\n after ex_get_elem_blk_ids, error = %3d\n", error);
     
    for (i=0; i<num_elem_blk; i++)
      {
	if (num_elem_in_block[i] > 0) {
	  var_values = (float *) calloc (num_elem_in_block[i], sizeof(float));
         
	  error = ex_get_elem_var (exoid, time_step, var_index, ids[i], 
				   num_elem_in_block[i], var_values);
	  printf ("\nafter ex_get_elem_var, error = %3d\n", error);
         
	  if (!error)
	    {
	      printf 
		("element variable %2d values of element block %2d at time step %2d\n",
		 var_index, ids[i], time_step);
	      for (j=0; j<num_elem_in_block[i]; j++) 
		printf ("%5.3f\n", var_values[j]);
	    }
         
	  free (var_values);
	}
      }
    free (num_elem_in_block);
    free(ids);
  }
  /* read an element variable through time */

  if (num_ele_vars > 0) {
    var_values = (float *) calloc (num_time_steps, sizeof(float));
     
    var_index = 2;
    elem_num = 2;
    error = ex_get_elem_var_time (exoid, var_index, elem_num, beg_time, 
                                  end_time, var_values);
    printf ("\nafter ex_get_elem_var_time, error = %3d\n", error);
     
    printf ("element variable %2d values for element %2d through time:\n", 
            var_index, elem_num);
    for (i=0; i<num_time_steps; i++) printf ("%5.3f\n", var_values[i]);
     
    free (var_values);
  }
   
  /* read a sideset variable at one time step */

  if (num_sset_vars > 0) {
    ids = (int *) calloc(num_side_sets, sizeof(int));
     
    error = ex_get_side_set_ids (exoid, ids);
    printf ("\n after ex_get_side_set_ids, error = %3d\n", error);
     
    for (i=0; i<num_side_sets; i++)
      {
        var_values = (float *) calloc (num_elem_per_set[i], sizeof(float));
         
        error = ex_get_sset_var (exoid, time_step, var_index, ids[i], 
                                 num_elem_per_set[i], var_values);
        printf ("\nafter ex_get_sset_var, error = %3d\n", error);
         
        if (!error)
          {
            printf 
              ("sideset variable %2d values of sideset %2d at time step %2d\n",
               var_index, ids[i], time_step);
            for (j=0; j<num_elem_per_set[i]; j++) 
              printf ("%5.3f\n", var_values[j]);
          }
         
        free (var_values); 
      }
    free (num_elem_per_set);
    free(ids);
  }

  /* read a nodeset variable at one time step */

  if (num_nset_vars > 0) {
    ids = (int *) calloc(num_node_sets, sizeof(int));
     
    error = ex_get_node_set_ids (exoid, ids);
    printf ("\n after ex_get_node_set_ids, error = %3d\n", error);
     
    for (i=0; i<num_node_sets; i++)
      {
        var_values = (float *) calloc (num_nodes_per_set[i], sizeof(float));
         
        error = ex_get_nset_var (exoid, time_step, var_index, ids[i], 
                                 num_nodes_per_set[i], var_values);
        printf ("\nafter ex_get_nset_var, error = %3d\n", error);
         
        if (!error)
          {
            printf 
              ("nodeset variable %2d values of nodeset %2d at time step %2d\n",
               var_index, ids[i], time_step);
            for (j=0; j<num_nodes_per_set[i]; j++) 
              printf ("%5.3f\n", var_values[j]);
          }
         
        free (var_values); 
      }
    free(ids);
  }
  if (num_node_sets > 0)
    free (num_nodes_per_set);

  free (name);
  error = ex_close (exoid);
  printf ("\nafter ex_close, error = %3d\n", error);
  return 0;
}
Ejemplo n.º 7
0
template <typename INT> void ExoII_Read<INT>::Get_Init_Data()
{
  SMART_ASSERT(Check_State());
  SMART_ASSERT(file_id >= 0);

  // Determine max size of entity and variable names on the database
  int name_length = ex_inquire_int(file_id, EX_INQ_DB_MAX_USED_NAME_LENGTH);
  ex_set_max_name_length(file_id, name_length);

  ex_init_params info;
  info.title[0] = '\0';

  int err = ex_get_init_ext(file_id, &info);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get init data!"
              << " Error number = " << err << ".  Aborting..." << '\n';
    exit(1);
  }

  dimension       = info.num_dim;
  num_nodes       = info.num_nodes;
  num_elmts       = info.num_elem;
  num_elmt_blocks = info.num_elem_blk;
  num_node_sets   = info.num_node_sets;
  num_side_sets   = info.num_side_sets;
  title           = info.title;

  if (err > 0 && !interface.quiet_flag)
    std::cout << "EXODIFF WARNING: was issued, number = " << err << '\n';
  if (dimension < 1 || dimension > 3 || num_elmt_blocks < 0 || num_node_sets < 0 ||
      num_side_sets < 0) {
    std::cout << "EXODIFF ERROR: Init data appears corrupt:" << '\n'
              << "         dimension = " << dimension << '\n'
              << "         num_nodes = " << num_nodes << '\n'
              << "         num_elmts = " << num_elmts << '\n'
              << "         num_elmt_blocks = " << num_elmt_blocks << '\n'
              << "         num_node_sets = " << num_node_sets << '\n'
              << "         num_side_sets = " << num_side_sets << '\n'
              << " ... Aborting..." << '\n';
    exit(1);
  }

  int num_qa   = ex_inquire_int(file_id, EX_INQ_QA);
  int num_info = ex_inquire_int(file_id, EX_INQ_INFO);

  if (num_qa < 0 || num_info < 0) {
    std::cout << "EXODIFF ERROR: inquire data appears corrupt:" << '\n'
              << "         num_qa = " << num_qa << '\n'
              << "         num_info = " << num_info << '\n'
              << " ... Aborting..." << '\n';
    exit(1);
  }

  //                   Coordinate Names...

  char **coords = get_name_array(3, name_length);
  err           = ex_get_coord_names(file_id, coords);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get coordinate"
              << " names!  Aborting..." << '\n';
    exit(1);
  }

  coord_names.clear();
  for (size_t i = 0; i < dimension; ++i) {
    coord_names.push_back(coords[i]);
  }
  free_name_array(coords, 3);

  //                 Element Block Data...

  if (eblocks)
    delete[] eblocks;
  eblocks = nullptr;
  if (num_elmt_blocks > 0) {
    eblocks = new Exo_Block<INT>[num_elmt_blocks];
    SMART_ASSERT(eblocks != nullptr);
    std::vector<INT> ids(num_elmt_blocks);

    err = ex_get_ids(file_id, EX_ELEM_BLOCK, TOPTR(ids));

    if (err < 0) {
      std::cout << "EXODIFF ERROR: Failed to get element"
                << " block ids!  Aborting..." << '\n';
      exit(1);
    }

    size_t e_count = 0;
    for (size_t b = 0; b < num_elmt_blocks; ++b) {
      if (ids[b] <= EX_INVALID_ID) {
        std::cout << "EXODIFF  WARNING:  Element block Id "
                  << "for block index " << b << " is " << ids[b]
                  << " which is negative. This was returned by call to ex_get_elem_blk_ids()."
                  << '\n';
      }

      eblocks[b].initialize(file_id, ids[b]);
      e_count += eblocks[b].Size();
    }

    if (e_count != num_elmts && !interface.quiet_flag) {
      std::cout << "EXODIFF WARNING: Total number of elements " << num_elmts
                << " does not equal the sum of the number of elements "
                << "in each block " << e_count << '\n';
    }

    // Gather the attribute names (even though not all attributes are on all blocks)
    std::set<std::string> names;
    for (size_t b = 0; b < num_elmt_blocks; ++b) {
      for (int a = 0; a < eblocks[b].attr_count(); a++) {
        names.insert(eblocks[b].Get_Attribute_Name(a));
      }
    }
    elmt_atts.resize(names.size());
    std::copy(names.begin(), names.end(), elmt_atts.begin());
  }

  //                     Node & Side sets...

  if (nsets)
    delete[] nsets;
  nsets = nullptr;
  if (num_node_sets > 0) {
    nsets = new Node_Set<INT>[num_node_sets];
    SMART_ASSERT(nsets != nullptr);
    std::vector<INT> ids(num_node_sets);

    err = ex_get_ids(file_id, EX_NODE_SET, TOPTR(ids));

    if (err < 0) {
      std::cout << "EXODIFF ERROR: Failed to get "
                << "nodeset ids!  Aborting..." << '\n';
      exit(1);
    }

    for (size_t nset = 0; nset < num_node_sets; ++nset) {
      if (ids[nset] <= EX_INVALID_ID) {
        std::cout << "EXODIFF  WARNING: Nodeset Id "
                  << "for nodeset index " << nset << " is " << ids[nset]
                  << " which is negative.  This was returned by call to ex_get_ids()." << '\n';
      }

      nsets[nset].initialize(file_id, ids[nset]);
    }
  }

  if (ssets)
    delete[] ssets;
  ssets = nullptr;
  if (num_side_sets) {
    ssets = new Side_Set<INT>[num_side_sets];
    SMART_ASSERT(ssets != nullptr);
    std::vector<INT> ids(num_side_sets);

    err = ex_get_ids(file_id, EX_SIDE_SET, TOPTR(ids));

    if (err < 0) {
      std::cout << "EXODIFF ERROR: Failed to get "
                << "sideset ids!  Aborting..." << '\n';
      exit(1);
    }

    for (size_t sset = 0; sset < num_side_sets; ++sset) {
      if (ids[sset] <= EX_INVALID_ID) {
        std::cout << "EXODIFF  WARNING:  Sideset Id "
                  << "for sideset index " << sset << " is " << ids[sset]
                  << " which is negative. This was returned by call to ex_get_ids()." << '\n';
      }
      ssets[sset].initialize(file_id, ids[sset]);
    }
  }

  //  **************  RESULTS info  ***************  //

  int num_global_vars, num_nodal_vars, num_elmt_vars, num_ns_vars, num_ss_vars;

  err = ex_get_variable_param(file_id, EX_GLOBAL, &num_global_vars);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get number of"
              << " global variables!  Aborting..." << '\n';
    exit(1);
  }

  err = ex_get_variable_param(file_id, EX_NODAL, &num_nodal_vars);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get number of"
              << " nodal variables!  Aborting..." << '\n';
    exit(1);
  }

  err = ex_get_variable_param(file_id, EX_ELEM_BLOCK, &num_elmt_vars);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get number of"
              << " element variables!  Aborting..." << '\n';
    exit(1);
  }

  err = ex_get_variable_param(file_id, EX_NODE_SET, &num_ns_vars);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get number of"
              << " nodeset variables!  Aborting..." << '\n';
    exit(1);
  }

  err = ex_get_variable_param(file_id, EX_SIDE_SET, &num_ss_vars);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get number of"
              << " sideset variables!  Aborting..." << '\n';
    exit(1);
  }

  if (num_global_vars < 0 || num_nodal_vars < 0 || num_elmt_vars < 0 || num_ns_vars < 0 ||
      num_ss_vars < 0) {
    std::cout << "EXODIFF ERROR: Data appears corrupt for"
              << " number of variables !" << '\n'
              << "\tnum global vars  = " << num_global_vars << '\n'
              << "\tnum nodal vars   = " << num_nodal_vars << '\n'
              << "\tnum element vars = " << num_elmt_vars << '\n'
              << " ... Aborting..." << '\n';
    exit(1);
  }

  read_vars(file_id, EX_GLOBAL, "Global", num_global_vars, global_vars);
  read_vars(file_id, EX_NODAL, "Nodal", num_nodal_vars, nodal_vars);
  read_vars(file_id, EX_ELEM_BLOCK, "Element", num_elmt_vars, elmt_vars);
  read_vars(file_id, EX_NODE_SET, "Nodeset", num_ns_vars, ns_vars);
  read_vars(file_id, EX_SIDE_SET, "Sideset", num_ss_vars, ss_vars);

  // Times:
  num_times = ex_inquire_int(file_id, EX_INQ_TIME);
  if (num_times < 0) {
    std::cout << "EXODIFF ERROR: Number of time steps came"
              << " back negative (" << num_times << ")!  Aborting..." << '\n';
    exit(1);
  }

  if ((num_global_vars > 0 || num_nodal_vars > 0 || num_elmt_vars > 0 || num_ns_vars > 0 ||
       num_ss_vars > 0) &&
      num_times == 0) {
    std::cout << "EXODIFF Consistency error -- The database contains transient variables, but no "
                 "timesteps!"
              << '\n';
    exit(1);
  }

  if (num_times) {
    times = new double[num_times];
    SMART_ASSERT(times != nullptr);
    err = ex_get_all_times(file_id, times);
  }

  if (num_nodal_vars) {
    if (num_times == 0) {
      std::cout << "EXODIFF Consistency error--The database contains " << num_nodal_vars
                << " nodal variables, but there are no time steps defined." << '\n';
    }
    if (num_times) {
      results = new double *[num_nodal_vars];
      for (int i   = 0; i < num_nodal_vars; ++i)
        results[i] = nullptr;
    }
  }

} // End of EXODIFF
Ejemplo n.º 8
0
bool Excn::ExodusFile::initialize(const SystemInterface& si, int start_part, int part_count)
{
  processorCount_ = si.processor_count(); // Total number processors
  partCount_      = part_count;      // Total parts we are processing
  startPart_      = start_part;      // Which one to start with
  SMART_ASSERT(partCount_ + startPart_ <= processorCount_)(partCount_)(startPart_)(processorCount_);
  
  // EPU always wants entity (block, set, map) ids as 64-bit quantities...
  mode64bit_ = EX_IDS_INT64_API;
  if (si.int64()) {
    mode64bit_ |= EX_ALL_INT64_API;

    // For output...
    mode64bit_ |= EX_ALL_INT64_DB;
  }

  // See if we can keep files open 
  int max_files = get_free_descriptor_count();
  if (partCount_ <= max_files) {
    keepOpen_ = true;
    if (si.debug() & 1)
      std::cout << "Files kept open... (Max open = " << max_files << ")\n\n";
  } else {
    keepOpen_ = false;
    std::cout << "Single file mode... (Max open = " << max_files << ")\n"
	      << "Consider using the -subcycle option for faster execution...\n\n";
  }

  fileids_.resize(processorCount_);
  filenames_.resize(processorCount_);

  std::string curdir = si.cwd();
  std::string file_prefix = si.basename();
  std::string exodus_suffix = si.exodus_suffix();
  
  std::string root_dir = si.root_dir();
  std::string sub_dir  = si.sub_dir();

  ParallelDisks disks;
  disks.Raid_Offset(si.raid_offset());
  disks.Number_of_Raids(si.raid_count());

  float version = 0.0;

  // create exo names
  for(int p = 0; p < partCount_; p++) {
    std::string name = file_prefix;
    if (!exodus_suffix.empty()) {
      name += "." + exodus_suffix;
    }

    int proc = p + startPart_;
    disks.rename_file_for_mp(root_dir, sub_dir, name, proc,
			     processorCount_); 
    filenames_[p] = name;

    if (p == 0) {
      int cpu_word_size  = sizeof(float);
      int io_word_size_var   = 0;
      int mode = EX_READ;
      mode |= mode64bit_;
      int exoid = ex_open(filenames_[p].c_str(),
			  mode, &cpu_word_size,
			  &io_word_size_var, &version);
      if (exoid < 0) {
	std::cerr << "Cannot open file '" << filenames_[p] << "'" << std::endl;
	return false;
      }

      int int64db = ex_int64_status(exoid) & EX_ALL_INT64_DB;
      if (int64db) {
	// If anything stored on input db as 64-bit int, then output db will have
	// everything stored as 64-bit ints and all API functions will use 64-bit
	mode64bit_ |= EX_ALL_INT64_API;
	mode64bit_ |= EX_ALL_INT64_DB;
      }
      
      int max_name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH);
      if (max_name_length > maximumNameLength_)
	maximumNameLength_ = max_name_length;

      ex_close(exoid);

      if (io_word_size_var < (int)sizeof(float))
	io_word_size_var = sizeof(float);

      ioWordSize_ = io_word_size_var;
      cpuWordSize_ = io_word_size_var;
    }

    if (keepOpen_ || p == 0) {
      int io_word_size_var   = 0;
      int mode = EX_READ;
      // All entity ids (block, sets) are read/written as 64-bit...
      mode |= mode64bit_;
      fileids_[p] = ex_open(filenames_[p].c_str(),
			    mode, &cpuWordSize_,
			    &io_word_size_var, &version);
      if (fileids_[p] < 0) {
	std::cerr << "Cannot open file '" << filenames_[p] << "'" << std::endl;
	return false;
      }
      ex_set_max_name_length(fileids_[p], maximumNameLength_);
      SMART_ASSERT(ioWordSize_ == io_word_size_var)(ioWordSize_)(io_word_size_var);
    }
    
    if (si.debug()&64 || p==0 || p==partCount_-1) {
      std::cout << "Input(" << p << "): '" << name.c_str() << "'" << std::endl;
      if (!(si.debug()&64) && p==0)
	std::cout << "..." << std::endl;
    }
  }

  if (mode64bit_ & EX_ALL_INT64_DB) {
    std::cout << "Input files contain 8-byte integers.\n";
    si.set_int64();
  }

  return true;
}
Ejemplo n.º 9
0
/*
//  Read and EXODUSII database and return a TECPLOT file
*/
void tec(int exoid, const char *filename)
{

  int     i, j, k, idum;
  int     ndim, nnode, nelem, nblk, nnset, neset, nvar, ntime, itime;
  char    title[MAX_LINE_LENGTH + 1];
  char *  nameco[3], **varnames = NULL;
  double *x[3], **q             = NULL, *time;
  int *   elem_id = NULL, *node_per_elem = NULL, *elem_per_blk = NULL, *attr_per_blk = NULL;
  int **  icon = NULL, *ic = NULL, izone;
  char ** elem_type = NULL;
  int     name_size = 0;
  FILE *  tecfile   = NULL;

  void teczone(int, int, int, char *, int, int, int *, int, double **, int, double **, FILE *);

  /*
   * FIRST, READ THE EXODUS DATA BASE
   */

  /*
   *  Open the output file, if we can
   */
  tecfile = fopen(filename, "w");
  if (tecfile == NULL) {
    printf("\nCannot open file %s for writing\n\n", filename);
    exit(1);
  }

  /*
   * Determine max name size used in databsae...
   */
  name_size = ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH);
  ex_set_max_name_length(exoid, name_size);

  /*
   *  Read database size, get coordinates and connectivity
   */
  memset(title, 0, MAX_LINE_LENGTH + 1);
  ex_get_init(exoid, title, &ndim, &nnode, &nelem, &nblk, &nnset, &neset);
  x[0] = x[1] = x[2] = NULL;
  for (i = 0; i < ndim; i++) {
    nameco[i] = (char *)malloc((name_size + 1) * sizeof(char));
    x[i]      = (double *)malloc(nnode * sizeof(double));
  }
  ex_get_coord_names(exoid, nameco);
  if (strlen(nameco[0]) == 0)
    strcpy(nameco[0], "X");
  if (strlen(nameco[1]) == 0)
    strcpy(nameco[1], "Y");
  if (ndim > 2)
    if (strlen(nameco[2]) == 0)
      strcpy(nameco[2], "Z");
  ex_get_coord(exoid, x[0], x[1], x[2]);

  elem_id       = (int *)malloc(nblk * sizeof(int));
  node_per_elem = (int *)malloc(nblk * sizeof(int));
  elem_per_blk  = (int *)malloc(nblk * sizeof(int));
  attr_per_blk  = (int *)malloc(nblk * sizeof(int));
  elem_type     = (char **)malloc(nblk * sizeof(char *));
  icon          = (int **)malloc(nblk * sizeof(int *));
  for (i         = 0; i < nblk; i++)
    elem_type[i] = (char *)malloc((name_size + 1) * sizeof(char));
  ex_get_elem_blk_ids(exoid, elem_id);
  for (i = 0; i < nblk; i++) {
    ex_get_elem_block(exoid, elem_id[i], elem_type[i], &elem_per_blk[i], &node_per_elem[i],
                      &attr_per_blk[i]);

    icon[i] = (int *)malloc(elem_per_blk[i] * node_per_elem[i] * sizeof(int));
    ex_get_elem_conn(exoid, elem_id[i], icon[i]);
  }

  /*
   *  Read time step information
   */
  ntime = ex_inquire_int(exoid, EX_INQ_TIME);
  if (ntime > 0) {
    time = (double *)malloc(ntime * sizeof(double));
    ex_get_all_times(exoid, time);
  }

  /*
   *  Read number of nodal variables and save space
   */
  nvar = 0;
  ex_get_var_param(exoid, "n", &nvar);
  if (nvar > 0) {
    varnames = (char **)malloc(nvar * sizeof(char *));
    q        = (double **)malloc(nvar * sizeof(double *));
    for (i = 0; i < nvar; i++) {
      varnames[i] = (char *)malloc((name_size + 1) * sizeof(char));
      q[i]        = (double *)malloc(nnode * sizeof(double));
    }
    ex_get_var_names(exoid, "n", nvar, varnames);
  }

  /* /////////////////////////////////////////////////////////////////////
  //  PROMPT USER FOR INFO AND WRITE TECPLOT FILE
  /////////////////////////////////////////////////////////////////////
  */

  /*
   *  Write the TECPLOT header information
   */

  assert(strlen(title) < (MAX_LINE_LENGTH + 1));
  fprintf(tecfile, "TITLE = \"%s\"\n", title);
  fprintf(tecfile, "VARIABLES = ");
  for (i = 0; i < ndim; i++) {
    fprintf(tecfile, "\"%s\"", nameco[i]);
    if (i < (ndim - 1))
      fprintf(tecfile, ", ");
  }
  if (nvar == 0)
    fprintf(tecfile, "\n");
  else
    fprintf(tecfile, ",\n            ");

  idum = 0;
  for (i = 0; i < nvar; i++) {
    idum += strlen(varnames[i]);
    assert(idum < 1022);

    fprintf(tecfile, "\"%s\"", varnames[i]);
    if (i < (nvar - 1)) {
      if ((i + 1) % 4 == 0) {
        idum = 0;
        fprintf(tecfile, ",\n            ");
      }
      else
        fprintf(tecfile, ", ");
    }
  }
  fprintf(tecfile, "\n");

  /*
   *  Select a time step
   */
  izone = 0;
  if (ntime == 0) {
    printf("\nNo solution variables available, saving mesh only\n\n");
    izone = 1;
  }
  else {
    printf("\nTime step information:\n\n");
    for (i = 0; i < ntime; i++)
      printf("   Time step %5d, time = %e\n", i + 1, time[i]);
    do {
      printf("\nSelect time step number to save,\n");
      printf("  or 0 for zone animation of all time steps: ");
      scanf("%d", &itime);
      printf("\n");
    } while (itime < 0 || itime > ntime);
    printf("\n");
    if (itime == 0)
      izone = 0;
    else
      izone = 1;
  }

  /*
   *  Write time steps
   */

  if (izone == 0) {

    /*
     *  Collapse the zones into one
     */

    /*
     *  Make sure we are using all the same element types
     *  Create one master connectivity array
     */
    for (i = 1; i < nblk; i++)
      if (strcmp(elem_type[0], elem_type[i]) != 0) {
        printf("\nCannot create zone animation because\n");
        ;
        printf("\n  there are multiple element types.");
        exit(1);
      }
    ic = (int *)malloc(nelem * node_per_elem[0] * sizeof(int));
    k  = 0;
    for (j = 0; j < nblk; j++)
      for (i    = 0; i < node_per_elem[j] * elem_per_blk[j]; i++)
        ic[k++] = icon[j][i];
    assert(k == nelem * node_per_elem[0]);

    if (itime == 0) {
      for (j = 0; j < ntime; j++) {
        for (i = 0; i < nvar; i++)
          ex_get_nodal_var(exoid, j + 1, i + 1, nnode, q[i]);

        i = 0;
        teczone(1, nnode, j + 1, elem_type[i], node_per_elem[i], nelem, ic, ndim, x, nvar, q,
                tecfile);
      }
      printf("\n");
    }

    free(ic);
  }
  else if (izone == 1) {

    /*
      ||  Write out each zone individually
    */
    for (i = 0; i < nvar; i++)
      ex_get_nodal_var(exoid, itime, i + 1, nnode, q[i]);

    for (i = 0; i < nblk; i++)
      teczone(nblk, nnode, elem_id[i], elem_type[i], node_per_elem[i], elem_per_blk[i], icon[i],
              ndim, x, nvar, q, tecfile);
    printf("\n");
  }

  /* /////////////////////////////////////////////////////////////////////
  //  CLEAN UP
  /////////////////////////////////////////////////////////////////////
  */

  fclose(tecfile);

  /*
   *  Free up allocated memory
   */
  for (i = 0; i < ndim; i++) {
    free(nameco[i]);
    free(x[i]);
  }
  free(elem_id);
  free(node_per_elem);
  free(elem_per_blk);
  free(attr_per_blk);
  if (elem_type != NULL) {
    for (i = 0; i < nblk; i++) {
      free(elem_type[i]);
    }
    free(elem_type);
  }
  if (icon != NULL) {
    for (i = 0; i < nblk; i++) {
      free(icon[i]);
    }
    free(icon);
  }
  if (nvar > 0) {
    if (varnames != NULL) {
      for (i = 0; i < nvar; i++) {
        free(varnames[i]);
      }
      free(varnames);
    }
    if (q != NULL) {
      for (i = 0; i < nvar; i++) {
        free(q[i]);
      }
      free(q);
    }
  }
}
Ejemplo n.º 10
0
bool Excn::ExodusFile::initialize(const SystemInterface& si)
{
  // See if we can keep files open 
  size_t max_files = get_free_descriptor_count();
  if (si.inputFiles_.size() <= max_files) {
    keepOpen_ = true;
    if (si.debug() & 1)
      std::cout << "Files kept open... (Max open = " << max_files << ")\n\n";
  } else {
    keepOpen_ = false;
    std::cout << "Single file mode... (Max open = " << max_files << ")\n"
	      << "Consider using the -subcycle option for faster execution...\n\n";
  }

  float version = 0.0;

  // create exo names
  filenames_.resize(si.inputFiles_.size());
  fileids_.resize(si.inputFiles_.size());
  
  int int_byte_size_api = 4;
  if (si.ints_64_bit())
    int_byte_size_api = 8;
  
  int overall_max_name_length = 0;
  for(size_t p = 0; p < si.inputFiles_.size(); p++) {
    std::string name = si.inputFiles_[p];

    filenames_[p] = name;

    if (p == 0) {
      int cpu_word_size  = sizeof(float);
      int io_wrd_size   = 0;
      int exoid = ex_open(filenames_[p].c_str(),
			  EX_READ, &cpu_word_size,
			  &io_wrd_size, &version);
      if (exoid < 0) {
	std::cerr << "Cannot open file '" << filenames_[p] << "'" << std::endl;
	return false;
      }

      int max_name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH);
      if (max_name_length > overall_max_name_length)
	overall_max_name_length = max_name_length;

      ex_close(exoid);

      if (io_wrd_size < (int)sizeof(float))
	io_wrd_size = sizeof(float);

      ioWordSize_ = io_wrd_size;
      cpuWordSize_ = io_wrd_size;

      if (ex_int64_status(exoid & EX_ALL_INT64_DB) || si.ints_64_bit()) {
	exodusMode_ = EX_ALL_INT64_API;
      }
    }

    if (keepOpen_ || p == 0) {
      int io_wrd_size   = 0;
      int mode = EX_READ | exodusMode_;

      fileids_[p] = ex_open(filenames_[p].c_str(),
			    mode, &cpuWordSize_,
			    &io_wrd_size, &version);
      if (fileids_[p] < 0) {
	std::cerr << "Cannot open file '" << filenames_[p] << "'" << std::endl;
	return false;
      }

      SMART_ASSERT(ioWordSize_ == io_wrd_size)(ioWordSize_)(io_wrd_size);
    }
    
    std::cout << "Part " << p+1 << ": '" << name.c_str() << "'" << std::endl;
  }

  maximumNameLength_ = overall_max_name_length;
  for(size_t p = 0; p < si.inputFiles_.size(); p++) {
    ex_set_max_name_length(fileids_[p], maximumNameLength_);
  }

  return true;
}