Пример #1
0
real_t* exodus_file_read_face_field(exodus_file_t* file,
                                    int time_index,
                                    const char* field_name)
{
  // Find the variable index.
  int index = 0;
  while (index < file->face_var_names->size)
  {
    if (strcmp(field_name, file->face_var_names->data[index]) == 0)
      break;
    ++index;
  }

  // Fetch the field data.
  if (index < file->face_var_names->size)
  {
    int offset = 0;
    real_t* field = polymec_malloc(sizeof(real_t) * file->num_faces);
    memset(field, 0, sizeof(real_t) * file->num_faces);
    for (int i = 0; i < file->num_face_blocks; ++i)
    {
      int N;
      ex_get_block(file->ex_id, EX_FACE_BLOCK, file->face_block_ids[i], NULL, &N, NULL, NULL, NULL, NULL);
      ex_get_var(file->ex_id, time_index, EX_FACE_BLOCK, index+1, i, N, &field[offset]);
      offset += N;
    }
    return field;
  }
  else
    return NULL;
}
Пример #2
0
void exodus_file_write_face_field(exodus_file_t* file,
                                  int time_index,
                                  const char* field_name,
                                  real_t* field_data)
{
  ASSERT(file->writing);

  // Find the variable index if it already exists.
  int index = 0;
  while (index < file->face_var_names->size)
  {
    if (strcmp(field_name, file->face_var_names->data[index]) == 0)
      break;
    ++index;
  }

  // Append the variable to our list if we didn't find it.
  if (index >= file->face_var_names->size)
    string_array_append_with_dtor(file->face_var_names, string_dup(field_name), string_free);

  // Insert the data.
  int offset = 0;
  for (int i = 0; i < file->num_face_blocks; ++i)
  {
    int N;
    ex_get_block(file->ex_id, EX_FACE_BLOCK, file->face_block_ids[i], NULL, &N, NULL, NULL, NULL, NULL);
    ex_put_var(file->ex_id, time_index, EX_FACE_BLOCK, index+1, i, N, &field_data[offset]);
    offset += N;
  }
}
Пример #3
0
int ex_get_elem_block (int   exoid,
                       int   elem_blk_id,
                       char *elem_type,
                       int  *num_elem_this_blk, 
                       int  *num_nodes_per_elem,
                       int  *num_attr)

{
  return ex_get_block( exoid, EX_ELEM_BLOCK, elem_blk_id, elem_type,
    num_elem_this_blk, num_nodes_per_elem, 0, 0, num_attr );
}
Пример #4
0
int cReadEdgeFace(int argc, char *argv[])
{
  int            exoid;
  int            appWordSize  = 8;
  int            diskWordSize = 8;
  float          exoVersion;
  int            itmp[5];
  int *          ids;
  int            nids;
  int            obj;
  int            i, j;
  int            num_timesteps;
  int            ti;
  char **        obj_names;
  char **        var_names;
  int            have_var_names;
  int            num_vars;    /* number of variables per object */
  int            num_entries; /* number of values per variable per object */
  double *       entry_vals;  /* variable values for each entry of an object */
  ex_init_params modelParams;

  exoid = ex_open(EX_TEST_FILENAME, EX_READ, &appWordSize, &diskWordSize, &exoVersion);
  if (exoid <= 0) {
    fprintf(stderr, "Unable to open \"%s\" for reading.\n", EX_TEST_FILENAME);
    return 1;
  }

  EXCHECK(ex_get_init_ext(exoid, &modelParams), "Unable to read database parameters.\n");

  fprintf(stdout, "Title: <%s>\n"
                  "Dimension: %" PRId64 "\n"
                  "Nodes: %" PRId64 "\n"
                  "Edges: %" PRId64 "\n"
                  "Faces: %" PRId64 "\n"
                  "Elements: %" PRId64 "\n"
                  "Edge Blocks: %" PRId64 "\n"
                  "Face Blocks: %" PRId64 "\n"
                  "Element Blocks: %" PRId64 "\n"
                  "Node Sets: %" PRId64 "\n"
                  "Edge Sets: %" PRId64 "\n"
                  "Face Sets: %" PRId64 "\n"
                  "Side Sets: %" PRId64 "\n"
                  "Element Sets: %" PRId64 "\n"
                  "Node Maps: %" PRId64 "\n"
                  "Edge Maps: %" PRId64 "\n"
                  "Face Maps: %" PRId64 "\n"
                  "Element Maps: %" PRId64 "\n",
          modelParams.title, modelParams.num_dim, modelParams.num_nodes, modelParams.num_edge,
          modelParams.num_face, modelParams.num_elem, modelParams.num_edge_blk,
          modelParams.num_face_blk, modelParams.num_elem_blk, modelParams.num_node_sets,
          modelParams.num_edge_sets, modelParams.num_face_sets, modelParams.num_side_sets,
          modelParams.num_elem_sets, modelParams.num_node_maps, modelParams.num_edge_maps,
          modelParams.num_face_maps, modelParams.num_elem_maps);

  num_timesteps = ex_inquire_int(exoid, EX_INQ_TIME);

  /* *** NEW API *** */
  for (i = 0; i < sizeof(obj_types) / sizeof(obj_types[0]); ++i) {
    int *truth_tab = 0;
    have_var_names = 0;

    EXCHECK(ex_inquire(exoid, obj_sizes[i], &nids, 0, 0),
            "Object ID list size could not be determined.\n");

    if (!nids) {
      fprintf(stdout, "=== %ss: none\n\n", obj_typenames[i]);
      continue;
    }
    else {
      fprintf(stdout, "=== %ss: %d\n", obj_typenames[i], nids);
    }

    ids       = (int *)malloc(nids * sizeof(int));
    obj_names = (char **)malloc(nids * sizeof(char *));
    for (obj         = 0; obj < nids; ++obj)
      obj_names[obj] = (char *)malloc((MAX_STR_LENGTH + 1) * sizeof(char));

    EXCHECK(ex_get_ids(exoid, obj_types[i], ids), "Could not read object ids.\n");
    EXCHECK(ex_get_names(exoid, obj_types[i], obj_names), "Could not read object ids.\n");

    if ((OBJECT_IS_BLOCK(i)) || (OBJECT_IS_SET(i))) {
      int *tp;
      EXCHECK(ex_get_var_param(exoid, obj_typestr[i], &num_vars),
              "Could not read number of variables.\n");

      if (num_vars && num_timesteps > 0) {
        truth_tab = (int *)malloc(num_vars * nids * sizeof(int));
        EXCHECK(ex_get_var_tab(exoid, obj_typestr[i], nids, num_vars, truth_tab),
                "Could not read truth table.\n");
        tp = truth_tab;
        fprintf(stdout, "Truth:");
        for (obj = 0; obj < nids; ++obj) {
          for (j = 0; j < num_vars; ++j, ++tp) {
            fprintf(stdout, " %d", *tp);
          }
          fprintf(stdout, "\n      ");
        }
        fprintf(stdout, "\n");

        var_names = (char **)malloc(num_vars * sizeof(char *));
        for (j         = 0; j < num_vars; ++j)
          var_names[j] = (char *)malloc((MAX_STR_LENGTH + 1) * sizeof(char));

        EXCHECK(ex_get_var_names(exoid, obj_typestr[i], num_vars, var_names),
                "Could not read variable names.\n");
        have_var_names = 1;
      }
    }

    if (!have_var_names)
      var_names = 0;

    for (obj = 0; obj < nids; ++obj) {
      if (obj_names[obj])
        fprintf(stdout, "%s %3d (%s): ", obj_typenames[i], ids[obj], obj_names[obj]);
      else
        fprintf(stdout, "%s %3d: ", obj_typenames[i], ids[obj]);

      if (OBJECT_IS_BLOCK(i)) {
        int *nconn;
        int *econn;
        int *fconn;
        int  ele;
        int  ctr;
        int  num_attrs;
        if (obj_types[i] == EX_ELEM_BLOCK) {
          EXCHECK(ex_get_block(exoid, obj_types[i], ids[obj], 0, itmp, itmp + 1, itmp + 2, itmp + 3,
                               &num_attrs),
                  "Could not read block params.\n");
          fprintf(stdout,
                  "Entries: %3d Nodes/entry: %d Edges/entry: %d Faces/entry: %d Attributes: %d",
                  itmp[0], itmp[1], itmp[2], itmp[3], num_attrs);
        }
        else {
          EXCHECK(ex_get_block(exoid, obj_types[i], ids[obj], 0, itmp, itmp + 1, 0, 0, &num_attrs),
                  "Could not read block params.\n");
          fprintf(stdout, "Entries: %3d Nodes/entry: %d Attributes: %d", itmp[0], itmp[1],
                  num_attrs);
          itmp[2] = itmp[3] = 0;
        }
        fprintf(stdout, "\n   ");
        num_entries = itmp[0];
        nconn       = itmp[1] ? (int *)malloc(itmp[1] * num_entries * sizeof(int)) : 0;
        econn       = itmp[2] ? (int *)malloc(itmp[2] * num_entries * sizeof(int)) : 0;
        fconn       = itmp[3] ? (int *)malloc(itmp[3] * num_entries * sizeof(int)) : 0;
        EXCHECK(ex_get_conn(exoid, obj_types[i], ids[obj], nconn, econn, fconn),
                "Could not read connectivity.\n");
        for (ele = 0; ele < num_entries; ++ele) {
          for (ctr = 0; ctr < itmp[1]; ++ctr) {
            fprintf(stdout, " %2d", nconn[ele * itmp[1] + ctr]);
          }
          if (itmp[2]) {
            fprintf(stdout, "  ++");
            for (ctr = 0; ctr < itmp[2]; ++ctr) {
              fprintf(stdout, " %2d", econn[ele * itmp[2] + ctr]);
            }
          }
          if (itmp[3]) {
            fprintf(stdout, "  ++");
            for (ctr = 0; ctr < itmp[3]; ++ctr) {
              fprintf(stdout, " %2d", fconn[ele * itmp[3] + ctr]);
            }
          }
          fprintf(stdout, "\n   ");
        }
        free(nconn);
        free(econn);
        free(fconn);

        if (num_attrs) {
          char ** attr_names;
          double *attr;
          attr       = (double *)malloc(num_entries * num_attrs * sizeof(double));
          attr_names = (char **)malloc(num_attrs * sizeof(char *));
          for (j          = 0; j < num_attrs; ++j)
            attr_names[j] = (char *)malloc((MAX_STR_LENGTH + 1) * sizeof(char));

          EXCHECK(ex_get_attr_names(exoid, obj_types[i], ids[obj], attr_names),
                  "Could not read attributes names.\n");
          EXCHECK(ex_get_attr(exoid, obj_types[i], ids[obj], attr),
                  "Could not read attribute values.\n");

          fprintf(stdout, "\n      Attributes:\n      ID ");
          for (j = 0; j < num_attrs; ++j)
            fprintf(stdout, " %s", attr_names[j]);
          fprintf(stdout, "\n");
          for (j = 0; j < num_entries; ++j) {
            int k;
            fprintf(stdout, "      %2d ", j + 1);
            for (k = 0; k < num_attrs; ++k) {
              fprintf(stdout, " %4.1f", attr[j * num_attrs + k]);
            }
            fprintf(stdout, "\n");
          }

          for (j = 0; j < num_attrs; ++j)
            free(attr_names[j]);
          free(attr_names);
          free(attr);
        }
      }
      else if (OBJECT_IS_SET(i)) {
        int     num_df;
        int *   set_entry;
        int *   set_extra;
        double *set_df;
        EXCHECK(ex_get_set_param(exoid, obj_types[i], ids[obj], &num_entries, &num_df),
                "Could not read set parameters.\n");

        set_entry = (int *)malloc(num_entries * sizeof(int));
        set_extra = (obj_types[i] != EX_NODE_SET && obj_types[i] != EX_ELEM_SET)
                        ? (int *)malloc(num_entries * sizeof(int))
                        : 0;
        EXCHECK(ex_get_set(exoid, obj_types[i], ids[obj], set_entry, set_extra),
                "Could not read set.\n");
        fprintf(stdout, "Entries: %3d Distribution factors: %3d\n", num_entries, num_df);
        if (set_extra) {
          for (j = 0; j < num_entries; ++j)
            fprintf(stdout, "      %2d %2d\n", set_entry[j], set_extra[j]);
        }
        else {
          for (j = 0; j < num_entries; ++j)
            fprintf(stdout, "      %2d\n", set_entry[j]);
        }
        free(set_entry);
        free(set_extra);

        set_df = num_df ? (double *)malloc(num_df * sizeof(double)) : 0;
        if (set_df) {
          EXCHECK(ex_get_set_dist_fact(exoid, obj_types[i], ids[obj], set_df),
                  "Could not read set distribution factors.\n");
          fprintf(stdout, "\n    Distribution factors:\n");
          for (j = 0; j < num_df; ++j)
            fprintf(stdout, "      %4.1f\n", set_df[j]);
          free(set_df);
        }
      }
      else { /* object is map */
        int *map;
        switch (obj_types[i]) {
        case EX_NODE_MAP: num_entries = modelParams.num_nodes; break;
        case EX_EDGE_MAP: num_entries = modelParams.num_edge; break;
        case EX_FACE_MAP: num_entries = modelParams.num_face; break;
        case EX_ELEM_MAP: num_entries = modelParams.num_elem; break;
        default: num_entries          = 0;
        }
        if (num_entries) {
          fprintf(stdout, "Entries: %3d\n                :", num_entries);
          map = (int *)malloc(num_entries * sizeof(int));
          EXCHECK(ex_get_num_map(exoid, obj_types[i], ids[obj], map), "Could not read map.\n");
          for (j = 0; j < num_entries; ++j) {
            fprintf(stdout, " %d", map[j]);
          }
        }
        else {
          fprintf(stdout, "Entries: none");
        }
      }
      fprintf(stdout, "\n");

      /* Read results variables */
      if (((OBJECT_IS_BLOCK(i)) || (OBJECT_IS_SET(i))) && num_vars && num_timesteps > 0) {
        /* Print out all the time values to exercise get_var */
        entry_vals = (double *)malloc(num_entries * sizeof(double));
        for (j = 0; j < num_vars; ++j) {
          int k;
          if (!truth_tab[num_vars * obj + j])
            continue;

          fprintf(stdout, "      Variable: %s", var_names[j]);
          for (ti = 1; ti <= num_timesteps; ++ti) {
            EXCHECK(ex_get_var(exoid, ti, obj_types[i], 1 + j, ids[obj], num_entries, entry_vals),
                    "Could not read variable values.\n");

            fprintf(stdout, "\n       @t%d ", ti);
            for (k = 0; k < num_entries; ++k) {
              fprintf(stdout, " %4.1f", entry_vals[k]);
            }
          }
          fprintf(stdout, "\n");
        }
        fprintf(stdout, "\n");
        free(entry_vals);
      }
    }

    if (((OBJECT_IS_BLOCK(i)) || (OBJECT_IS_SET(i))) && num_vars && num_timesteps > 0) {
      /* Print out one element's time values to exercise get_var_time */
      entry_vals = (double *)malloc(num_timesteps * sizeof(double));
      EXCHECK(ex_inquire(exoid, obj_sizeinq[i], itmp, 0, 0), "Inquire failed.\n");
      itmp[1] = 11;
      while (itmp[1] > itmp[0])
        itmp[1] /= 2;
      for (j = 0; j < num_vars; ++j) {
        /* FIXME: This works for the dataset created by CreateEdgeFace, but not for any dataset in
         * general since
         * NULL truth table entries may mean the referenced elements don't have variable values.
         */
        EXCHECK(ex_get_var_time(exoid, obj_types[i], j + 1, itmp[1], 1, num_timesteps, entry_vals),
                "Could not read variable over time.\n");
        fprintf(stdout, "    Variable over time: %s  Entry: %3d ", var_names[j], itmp[1]);
        for (ti = 1; ti <= num_timesteps; ++ti)
          fprintf(stdout, " @t%d: %4.1f", ti, entry_vals[ti - 1]);
        fprintf(stdout, "\n");
      }
      free(entry_vals);
    }

    if (var_names) {
      for (j = 0; j < num_vars; ++j)
        free(var_names[j]);
      free(var_names);
    }
    free(truth_tab);
    free(ids);

    for (obj = 0; obj < nids; ++obj)
      free(obj_names[obj]);
    free(obj_names);

    fprintf(stdout, "\n");
  }

  EXCHECK(ex_close(exoid), "Unable to close database.\n");

  return 0;
}
Пример #5
0
void NemSpread<T,INT>::read_restart_data ()

/* Function which reads the restart variable data from the EXODUS II
 * database which contains the results information. Then distribute
 * it to the processors, and write it to the parallel exodus files.
 *
 *----------------------------------------------------------------------------
 *
 * Functions called:
 *
 * read_vars -- function which reads the variable values from the restart
 *              file, and then distributes them to the processors
 *
 * write_var_timestep -- function which writes out the variables for a
 *                       to a parallel ExodusII file.
 *
 *----------------------------------------------------------------------------
 */

{
    const char  *yo="read_restart_data";

    /* need to get the element block ids and counts */
    std::vector<INT> eb_ids_global(globals.Num_Elem_Blk);
    std::vector<INT> eb_cnts_global(globals.Num_Elem_Blk);
    std::vector<INT> ss_ids_global(globals.Num_Side_Set);
    std::vector<INT> ss_cnts_global(globals.Num_Side_Set);
    std::vector<INT> ns_ids_global(globals.Num_Node_Set);
    std::vector<INT> ns_cnts_global(globals.Num_Node_Set);

    INT ***eb_map_ptr = NULL, **eb_cnts_local = NULL;
    int    exoid=0, *par_exoid = NULL;

    float  vers;
    char   cTemp[512];

    /* computing precision should be the same as the database precision
     *
     * EXCEPTION: if the io_ws is smaller than the machine precision,
     * ie - database with io_ws == 4 on a Cray (sizeof(float) == 8),
     * then the cpu_ws must be the machine precision.
     */
    int cpu_ws;
    if (io_ws < (int)sizeof(float)) cpu_ws = sizeof(float);
    else                            cpu_ws = io_ws;

    /* 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);
        }
    }

    /* allocate space for the global variables */
    Restart_Info.Glob_Vals.resize(Restart_Info.NVar_Glob);

    if (Restart_Info.NVar_Elem > 0 ) {

        /* allocate storage space */
        Restart_Info.Elem_Vals.resize(Proc_Info[2]);

        /* now allocate storage for the values */
        for (int iproc = 0; iproc <Proc_Info[2]; iproc++) {
            size_t array_size = Restart_Info.NVar_Elem *
                                (globals.Num_Internal_Elems[iproc] + globals.Num_Border_Elems[iproc]);
            Restart_Info.Elem_Vals[iproc].resize(array_size);
        }

        /*
         * at this point, I need to broadcast the global element block ids
         * and counts to the processors. I know that this is redundant data
         * since they will all receive this information in read_mesh, but
         * the variables which contain that information are static in
         * el_exoII_io.c, and cannot be used here. So, take a second and
         * broadcast all of this out.
         *
         * I want to do this here so that it is done only once no matter
         * how many time steps are retrieved
         */

        /* Get the Element Block IDs from the input file */
        if (ex_get_ids (exoid, EX_ELEM_BLOCK, TOPTR(eb_ids_global)) < 0)
        {
            fprintf(stderr, "%s: unable to get element block IDs", yo);
            exit(1);
        }

        /* Get the count of elements in each element block */
        for (int cnt = 0; cnt < globals.Num_Elem_Blk; cnt++) {
            if (ex_get_block(exoid, EX_ELEM_BLOCK, eb_ids_global[cnt], cTemp,
                             &(eb_cnts_global[cnt]), NULL, NULL, NULL, NULL) < 0) {
                fprintf(stderr, "%s: unable to get element count for block id "ST_ZU"",
                        yo, (size_t)eb_ids_global[cnt]);
                exit(1);
            }
        }

        /*
         * in order to speed up finding matches in the global element
         * number map, set up an array of pointers to the start of
         * each element block's global element number map. That way
         * only entries for the current element block have to be searched
         */
        eb_map_ptr = (INT ***) array_alloc (__FILE__, __LINE__, 2,Proc_Info[2],
                                            globals.Num_Elem_Blk, sizeof(INT *));
        if (!eb_map_ptr) {
            fprintf(stderr, "[%s]: ERROR, insufficient memory!\n", yo);
            exit(1);
        }
        eb_cnts_local = (INT **) array_alloc (__FILE__, __LINE__, 2,Proc_Info[2],
                                              globals.Num_Elem_Blk, sizeof(INT));
        if (!eb_cnts_local) {
            fprintf(stderr, "[%s]: ERROR, insufficient memory!\n", yo);
            exit(1);
        }

        /*
         * for now, assume that element blocks have been
         * stored in the same order as the global blocks
         */
        for (int iproc = 0; iproc <Proc_Info[2]; iproc++) {
            int    ifound = 0;
            size_t offset = 0;
            int    ilocal;
            for (int cnt = 0; cnt < globals.Num_Elem_Blk; cnt++) {
                for (ilocal = ifound; ilocal < globals.Proc_Num_Elem_Blk[iproc]; ilocal++) {
                    if (globals.Proc_Elem_Blk_Ids[iproc][ilocal] == eb_ids_global[cnt])
                        break;
                }

                if (ilocal < globals.Proc_Num_Elem_Blk[iproc]) {
                    eb_map_ptr[iproc][cnt] = &globals.GElems[iproc][offset];
                    eb_cnts_local[iproc][cnt] = globals.Proc_Num_Elem_In_Blk[iproc][ilocal];
                    offset += globals.Proc_Num_Elem_In_Blk[iproc][ilocal];
                    ifound = ilocal; /* don't search the same part of the list over */
                }
                else {
                    eb_map_ptr[iproc][cnt] = NULL;
                    eb_cnts_local[iproc][cnt] = 0;
                }
            }
        }

    } /* End: "if (Restart_Info.NVar_Elem > 0 )" */

    if (Restart_Info.NVar_Node > 0 ) {
        /* allocate storage space */
        Restart_Info.Node_Vals.resize(Proc_Info[2]);

        /* now allocate storage for the values */
        for (int iproc = 0; iproc <Proc_Info[2]; iproc++) {
            size_t array_size = Restart_Info.NVar_Node * (globals.Num_Internal_Nodes[iproc] +
                                globals.Num_Border_Nodes[iproc] + globals.Num_External_Nodes[iproc]);
            Restart_Info.Node_Vals[iproc].resize(array_size);
        }
    }

    if (Restart_Info.NVar_Sset > 0 ) {

        /* allocate storage space */
        Restart_Info.Sset_Vals.resize(Proc_Info[2]);

        /* now allocate storage for the values */
        for (int iproc = 0; iproc <Proc_Info[2]; iproc++) {
            size_t array_size = Restart_Info.NVar_Sset * globals.Proc_SS_Elem_List_Length[iproc];

            Restart_Info.Sset_Vals[iproc].resize(array_size);
        }

        /*
         * at this point, I need to broadcast the ids and counts to the
         * processors. I know that this is redundant data since they will
         * all receive this information in read_mesh, but the variables
         * which contain that information are static in el_exoII_io.c, and
         * cannot be used here. So, take a second and broadcast all of
         * this out.
         *
         * I want to do this here so that it is done only once no matter
         * how many time steps are retrieved
         */

        /* Get the Sideset IDs from the input file */
        if (ex_get_ids (exoid, EX_SIDE_SET, TOPTR(ss_ids_global)) < 0) {
            fprintf(stderr, "%s: unable to get sideset IDs", yo);
            exit(1);
        }

        /* Get the count of elements in each sideset */
        for (int cnt = 0; cnt < globals.Num_Side_Set; cnt++) {
            if (ex_get_set_param(exoid, EX_SIDE_SET,
                                 ss_ids_global[cnt],
                                 &(ss_cnts_global[cnt]), NULL) < 0) {
                fprintf(stderr, "%s: unable to get element count for sideset id "ST_ZU"",
                        yo, (size_t)ss_ids_global[cnt]);
                exit(1);
            }
        }
    } /* End: "if (Restart_Info.NVar_Sset > 0 )" */


    if (Restart_Info.NVar_Nset > 0 ) {

        /* allocate storage space */
        Restart_Info.Nset_Vals.resize(Proc_Info[2]);

        /* now allocate storage for the values */
        for (int iproc = 0; iproc <Proc_Info[2]; iproc++) {
            size_t array_size = Restart_Info.NVar_Nset * globals.Proc_NS_List_Length[iproc];
            Restart_Info.Nset_Vals[iproc].resize(array_size);
        }

        /*
         * at this point, I need to broadcast the ids and counts to the
         * processors. I know that this is redundant data since they will
         * all receive this information in read_mesh, but the variables
         * which contain that information are static in el_exoII_io.c, and
         * cannot be used here. So, take a second and broadcast all of
         * this out.
         *
         * I want to do this here so that it is done only once no matter
         * how many time steps are retrieved
         */

        /* Get the Nodeset IDs from the input file */
        if (ex_get_ids (exoid, EX_NODE_SET, TOPTR(ns_ids_global)) < 0) {
            fprintf(stderr, "%s: unable to get nodeset IDs", yo);
            exit(1);
        }

        /* Get the count of elements in each nodeset */
        for (int cnt = 0; cnt < globals.Num_Node_Set; cnt++) {
            if (ex_get_set_param(exoid, EX_NODE_SET,
                                 ns_ids_global[cnt],
                                 &(ns_cnts_global[cnt]), NULL) < 0) {
                fprintf(stderr, "%s: unable to get element count for nodeset id "ST_ZU"",
                        yo, (size_t)ns_ids_global[cnt]);
                exit(1);
            }
        }
    } /* End: "if (Restart_Info.NVar_Nset > 0 )" */


    /*
     * NOTE: A possible place to speed this up would be to
     * get the global node and element lists here, and broadcast
     * them out only once.
     */

    par_exoid = (int*)malloc(Proc_Info[2] * sizeof(int));
    if(!par_exoid) {
        fprintf(stderr, "[%s]: ERROR, insufficient memory!\n",
                yo);
        exit(1);
    }

    /* See if any '/' in the name.  IF present, isolate the basename of the file */
    if (strrchr(PIO_Info.Scalar_LB_File_Name, '/') != NULL) {
        /* There is a path separator.  Get the portion after the
         * separator
         */
        strcpy(cTemp, strrchr(PIO_Info.Scalar_LB_File_Name, '/')+1);
    } else {
        /* No separator; this is already just the basename... */
        strcpy(cTemp, PIO_Info.Scalar_LB_File_Name);
    }

    if (strlen(PIO_Info.Exo_Extension) == 0)
        add_fname_ext(cTemp, ".par");
    else
        add_fname_ext(cTemp, PIO_Info.Exo_Extension);

    int open_file_count = get_free_descriptor_count();
    if (open_file_count >Proc_Info[5]) {
        printf("All output files opened simultaneously.\n");
        for (int iproc=Proc_Info[4]; iproc <Proc_Info[4]+Proc_Info[5]; iproc++) {

            gen_par_filename(cTemp, Par_Nem_File_Name, Proc_Ids[iproc],
                             Proc_Info[0]);

            /* Open the parallel Exodus II file for writing */
            cpu_ws = io_ws;
            int mode = EX_WRITE | int64api | int64db;
            if ((par_exoid[iproc]=ex_open(Par_Nem_File_Name, mode, &cpu_ws,
                                          &io_ws, &vers)) < 0) {
                fprintf(stderr,"[%d] %s Could not open parallel Exodus II file: %s\n",
                        iproc, yo, Par_Nem_File_Name);
                exit(1);
            }
        }
    } else {
        printf("All output files opened one-at-a-time.\n");
    }

    /* Now loop over the number of time steps */
    for (int time_idx = 0; time_idx < Restart_Info.Num_Times; time_idx++) {

        double start_t = second ();

        /* read and distribute the variables for this time step */
        if (read_vars(exoid, Restart_Info.Time_Idx[time_idx],
                      TOPTR(eb_ids_global), TOPTR(eb_cnts_global), eb_map_ptr,
                      eb_cnts_local,
                      TOPTR(ss_ids_global), TOPTR(ss_cnts_global),
                      TOPTR(ns_ids_global), TOPTR(ns_cnts_global)) < 0) {
            fprintf(stderr, "%s: Error occured while reading variables\n",
                    yo);
            exit(1);
        }
        double end_t   = second () - start_t;
        printf ("\tTime to read  vars for timestep %d: %f (sec.)\n", (time_idx+1), end_t);

        start_t = second ();
        for (int iproc=Proc_Info[4]; iproc <Proc_Info[4]+Proc_Info[5]; iproc++) {

            if (open_file_count <Proc_Info[5]) {
                gen_par_filename(cTemp, Par_Nem_File_Name, Proc_Ids[iproc],
                                 Proc_Info[0]);

                /* Open the parallel Exodus II file for writing */
                cpu_ws = io_ws;
                int mode = EX_WRITE | int64api | int64db;
                if ((par_exoid[iproc]=ex_open(Par_Nem_File_Name, mode, &cpu_ws,
                                              &io_ws, &vers)) < 0) {
                    fprintf(stderr,"[%d] %s Could not open parallel Exodus II file: %s\n",
                            iproc, yo, Par_Nem_File_Name);
                    exit(1);
                }
            }

            /*
             * Write out the variable data for the time steps in this
             * block to each parallel file.
             */
            write_var_timestep(par_exoid[iproc], iproc, (time_idx+1),
                               TOPTR(eb_ids_global), TOPTR(ss_ids_global), TOPTR(ns_ids_global));

            if (iproc%10 == 0 || iproc ==Proc_Info[2]-1)
                printf("%d", iproc);
            else
                printf(".");

            if (open_file_count <Proc_Info[5]) {
                if (ex_close(par_exoid[iproc]) == -1) {
                    fprintf(stderr, "[%d] %s Could not close the parallel Exodus II file.\n",
                            iproc, yo);
                    exit(1);
                }
            }
        } /* End "for (iproc=0; iproc <Proc_Info[2]; iproc++)" */

        end_t   = second () - start_t;
        printf ("\n\tTime to write vars for timestep %d: %f (sec.)\n", (time_idx+1), end_t);

    }
    if (Restart_Info.NVar_Elem > 0 ) {
        safe_free((void **) &eb_map_ptr);
        safe_free((void **) &eb_cnts_local);
    }

    /* Close the restart exodus II file */
    if (ex_close(exoid) == -1) {
        fprintf(stderr, "%sCould not close the restart Exodus II file\n",
                yo);
        exit(1);
    }

    if (open_file_count >Proc_Info[5]) {
        for (int iproc=Proc_Info[4]; iproc <Proc_Info[4]+Proc_Info[5]; iproc++) {
            /* Close the parallel exodus II file */
            if (ex_close(par_exoid[iproc]) == -1) {
                fprintf(stderr, "[%d] %s Could not close the parallel Exodus II file.\n",
                        iproc, yo);
                exit(1);
            }
        }
    }
    if (par_exoid != NULL) {
        free(par_exoid);
        par_exoid = NULL;
    }
}
Пример #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 *connect, *node_list, *node_ctr_list, *elem_list, *side_list;
  int *ids;
  int *num_elem_per_set;
  int *num_df_per_set;
  int *elem_ind, *df_ind;
  int *num_elem_in_block, *num_nodes_per_elem, *num_attr;
  int  num_elem_in_set;
  int  num_sides_in_set, num_df_in_set;
  int  elem_list_len = 0;
  int  node_list_len = 0;
  int  df_list_len   = 0;
  int  CPU_word_size, IO_word_size;
  int  idum;

  float *dist_fact;
  float  version, fdum;

  char  title[MAX_LINE_LENGTH + 1], elem_type[MAX_STR_LENGTH + 1];
  char *cdum = 0;

  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);

  /* 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);

  /* read element block parameters */

  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_ids(exoid, EX_ELEM_BLOCK, ids);
  printf("\nafter ex_get_elem_blk_ids, error = %3d\n", error);

  for (i = 0; i < num_elem_blk; i++) {
    error = ex_get_block(exoid, EX_ELEM_BLOCK, ids[i], elem_type, &(num_elem_in_block[i]),
                         &(num_nodes_per_elem[i]), NULL, NULL, &(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]);
  }

  /* read element connectivity */

  for (i = 0; i < num_elem_blk; i++) {
    connect = (int *)calloc((num_nodes_per_elem[i] * num_elem_in_block[i]), sizeof(int));

    error = ex_get_conn(exoid, EX_ELEM_BLOCK, ids[i], connect, NULL, NULL);
    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]);
    }
    free(connect);
  }
  free(ids);
  free(num_elem_in_block);
  free(num_nodes_per_elem);
  free(num_attr);

  /* read individual side sets */

  ids = (int *)calloc(num_side_sets, sizeof(int));

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

  for (i = 0; i < num_side_sets; i++) {
    error = ex_get_set_param(exoid, EX_SIDE_SET, 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("num_sides = %3d\n", num_sides_in_set);
    printf("num_dist_factors = %3d\n", num_df_in_set);

    /* 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_set(exoid, EX_SIDE_SET, 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_set_dist_fact(exoid, EX_SIDE_SET, 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++) {
      printf("%3d nodes for side %3d\n", node_ctr_list[k], 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);
  }
  free(ids);

  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 */

  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));

  {
    struct ex_set_specs set_specs;

    set_specs.sets_ids            = ids;
    set_specs.num_entries_per_set = num_elem_per_set;
    set_specs.num_dist_per_set    = num_df_per_set;
    set_specs.sets_entry_index    = elem_ind;
    set_specs.sets_dist_index     = df_ind;
    set_specs.sets_entry_list     = elem_list;
    set_specs.sets_extra_list     = side_list;
    set_specs.sets_dist_fact      = dist_fact;

    error = ex_get_concat_sets(exoid, EX_SIDE_SET, &set_specs);
  }
  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_elem_per_set);
  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 */

  error = ex_close(exoid);
  printf("\nafter ex_close, error = %3d\n", error);
  return 0;
}
Пример #7
0
int main(int argc, char **argv)
{
  int  exoid, num_dim, num_nodes, num_elem_blk;
  int *num_elem_in_block, *num_face_in_block, *num_nodes_per_elem, *num_edges_per_elem,
      *num_faces_per_elem, *num_attr;
  int  error, nnodes;
  int  i, j, k;
  int *connect, *fconnect;
  int *ids, *nnpe, *nnpf;
  int  num_qa_rec, num_info;
  int  CPU_word_size, IO_word_size;
  int  idum;

  float *x, *y, *z;
  float  version, fdum;

  char *coord_names[3], *qa_record[2][4], *info[3];
  char *block_names[10];
  char *elem_type[10];
  char  name[MAX_STR_LENGTH + 1];
  char *cdum = 0;

  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-nfaced.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("         I/O word size %1d\n", IO_word_size);

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

  /* read database parameters */
  {
    ex_init_params par;
    error = ex_get_init_ext(exoid, &par);

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

    printf("database parameters:\n");
    printf("title =  '%s'\n", par.title);
    printf("num_dim = %" PRId64 "\n", par.num_dim);
    printf("num_nodes = %" PRId64 "\n", par.num_nodes);
    printf("num_edge = %" PRId64 "\n", par.num_edge);
    printf("num_face = %" PRId64 "\n", par.num_face);
    printf("num_elem = %" PRId64 "\n", par.num_elem);
    printf("num_elem_blk = %" PRId64 "\n", par.num_elem_blk);
    printf("num_node_sets = %" PRId64 "\n", par.num_node_sets);
    printf("num_side_sets = %" PRId64 "\n", par.num_side_sets);

    num_dim      = par.num_dim;
    num_nodes    = par.num_nodes;
    num_elem_blk = par.num_elem_blk;
  }

  assert(num_dim == 3);

  /* read nodal coordinates values and names from database */

  x = (float *)calloc(num_nodes, sizeof(float));
  y = (float *)calloc(num_nodes, sizeof(float));
  z = (float *)calloc(num_nodes, sizeof(float));

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

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

  free(x);
  free(y);
  free(z);

  for (i = 0; i < num_dim; i++) {
    coord_names[i] = (char *)calloc((MAX_STR_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]);
  printf("z coord name = '%s'\n", coord_names[2]);

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

  /* 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_face_in_block  = (int *)calloc(num_elem_blk, sizeof(int));
    num_nodes_per_elem = (int *)calloc(num_elem_blk, sizeof(int));
    num_edges_per_elem = (int *)calloc(num_elem_blk, sizeof(int));
    num_faces_per_elem = (int *)calloc(num_elem_blk, sizeof(int));
    num_attr           = (int *)calloc(num_elem_blk, sizeof(int));

    for (i = 0; i < num_elem_blk; i++) {
      elem_type[i]   = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
      block_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
    }

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

    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_block(exoid, EX_ELEM_BLOCK, ids[i], elem_type[i], &(num_elem_in_block[i]),
                           &(num_nodes_per_elem[i]), &(num_edges_per_elem[i]),
                           &(num_faces_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 block type = '%s'\n", elem_type[i]);
      printf("num_elem_in_block = %2d\n", num_elem_in_block[i]);
      printf("num_total_nodes_per_block = %2d\n", num_nodes_per_elem[i]);
      printf("num_total_edges_per_block = %2d\n", num_edges_per_elem[i]);
      printf("num_total_faces_per_block = %2d\n", num_faces_per_elem[i]);
      printf("num_attr = %2d\n", num_attr[i]);
      printf("name = '%s'\n", block_names[i]);
    }
  }

  /* read connectivity */
  for (i = 0; i < num_elem_blk; i++) {
    if (num_elem_in_block[i] > 0) {
      if (strcmp(elem_type[i], "NFACED") == 0 || strcmp(elem_type[i], "nfaced") == 0) {
        int nfaces = 0;
        connect    = (int *)calloc((num_faces_per_elem[i]), sizeof(int));

        nnpe  = (int *)calloc(num_elem_in_block[i], sizeof(int));
        error = ex_get_entity_count_per_polyhedra(exoid, EX_ELEM_BLOCK, ids[i], nnpe);
        printf("\nafter ex_get_entity_count_per_polyhedra, error = %d\n", error);

        for (j = 0; j < num_elem_in_block[i]; j++) {
          nfaces += nnpe[j];
        }
        assert(nfaces == num_faces_per_elem[i]);

        error = ex_get_conn(exoid, EX_ELEM_BLOCK, ids[i], NULL, NULL, connect);
        printf("\nafter ex_get_conn, error = %d\n", error);

        printf("face connectivity array for elem block %2d\n", ids[i]);
        nfaces = 0;
        for (j = 0; j < num_elem_in_block[i]; j++) {
          printf("Element %d, %d faces:\t", j + 1, nnpe[j]);
          for (k = 0; k < nnpe[j]; k++) {
            printf("%3d ", connect[nfaces + k]);
          }
          printf("\n");
          nfaces += nnpe[j];
        }

        /* Now get the faces and their connectivity... */
        /*
         * Convention is that the faces for an nfaced block are in a
         * face block which has the same id as the element block...
         * (Or, at least let's try that for awhile and see if it works...)
         */

        /* NOTE: We are overwriting the element block data here... */
        error = ex_get_block(exoid, EX_FACE_BLOCK, ids[i], elem_type[i], &(num_face_in_block[i]),
                             &(num_nodes_per_elem[i]), NULL, NULL, &(num_attr[i]));

        printf("\nafter ex_get_block (EX_FACE_BLOCK), error = %d\n", error);

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

        printf("\tface block id = %2d\n", ids[i]);
        printf("\tface block type = '%s'\n", elem_type[i]);
        printf("\tnum_face_in_block = %2d\n", num_face_in_block[i]);
        printf("\tnum_total_nodes_per_block = %2d\n", num_nodes_per_elem[i]);
        printf("\tnum_attr = %2d\n", num_attr[i]);
        printf("\tname = '%s'\n", block_names[i]);

        fconnect = (int *)calloc((num_nodes_per_elem[i]), sizeof(int));
        nnpf     = (int *)calloc(num_face_in_block[i], sizeof(int));
        error    = ex_get_entity_count_per_polyhedra(exoid, EX_FACE_BLOCK, ids[i], nnpf);
        printf("\nafter ex_get_entity_count_per_polyhedra, error = %d\n", error);

        nnodes = 0;
        for (j = 0; j < num_face_in_block[i]; j++) {
          nnodes += nnpf[j];
        }
        assert(nnodes == num_nodes_per_elem[i]);

        error = ex_get_conn(exoid, EX_FACE_BLOCK, ids[i], fconnect, NULL, NULL);
        printf("\nafter ex_get_conn, error = %d\n", error);

        printf("node connectivity array for face block %2d\n", ids[i]);
        nnodes = 0;
        for (j = 0; j < num_face_in_block[i]; j++) {
          printf("Face %d, %d nodes:\t", j + 1, nnpf[j]);
          for (k = 0; k < nnpf[j]; k++) {
            printf("%3d ", fconnect[nnodes + k]);
          }
          printf("\n");
          nnodes += nnpf[j];
        }
        free(fconnect);
        free(nnpe);
        free(nnpf);
      }
      else {
        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]);
        }
      }
      free(connect);
    }
  }

  for (i = 0; i < num_elem_blk; i++) {
    free(elem_type[i]);
    free(block_names[i]);
  }
  if (num_elem_blk > 0) {
    free(ids);
    free(num_nodes_per_elem);
    free(num_edges_per_elem);
    free(num_faces_per_elem);
    free(num_attr);
  }

  /* 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_STR_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]);
  }

  error = ex_close(exoid);
  printf("\nafter ex_close, error = %3d\n", error);
  return 0;
}
Пример #8
0
fe_mesh_t* exodus_file_read_mesh(exodus_file_t* file)
{
  // Create the "host" FE mesh.
  fe_mesh_t* mesh = fe_mesh_new(file->comm, file->num_nodes);

  // Count up the number of polyhedral blocks.
  int num_poly_blocks = 0;
  for (int i = 0; i < file->num_elem_blocks; ++i)
  {
    int elem_block = file->elem_block_ids[i];
    char elem_type_name[MAX_NAME_LENGTH+1];
    int num_elem, num_nodes_per_elem, num_faces_per_elem;
    ex_get_block(file->ex_id, EX_ELEM_BLOCK, elem_block, 
                 elem_type_name, &num_elem,
                 &num_nodes_per_elem, NULL,
                 &num_faces_per_elem, NULL);
    fe_mesh_element_t elem_type = get_element_type(elem_type_name);
    if (elem_type == FE_POLYHEDRON)
      ++num_poly_blocks;
  }

  // If we have any polyhedral element blocks, we read a single face 
  // block that incorporates all of the polyhedral elements.
  if (num_poly_blocks > 0)
  {
    // Dig up the face block corresponding to this element block.
    char face_type[MAX_NAME_LENGTH+1];
    int num_faces, num_nodes;
    ex_get_block(file->ex_id, EX_FACE_BLOCK, file->face_block_ids[0], face_type, &num_faces,
                 &num_nodes, NULL, NULL, NULL);
    if (string_ncasecmp(face_type, "nsided", 6) != 0)
    {
      fe_mesh_free(mesh);
      ex_close(file->ex_id);
      polymec_error("Invalid face type for polyhedral element block.");
    }

    // Find the number of nodes for each face in the block.
    int* num_face_nodes = polymec_malloc(sizeof(int) * num_faces);
    ex_get_entity_count_per_polyhedra(file->ex_id, EX_FACE_BLOCK, 
                                      file->face_block_ids[0], 
                                      num_face_nodes);

    // Read face->node connectivity information.
    int face_node_size = 0;
    for (int i = 0; i < num_faces; ++i)
      face_node_size += num_face_nodes[i];
    int* face_nodes = polymec_malloc(sizeof(int) * face_node_size);
    ex_get_conn(file->ex_id, EX_FACE_BLOCK, 1, face_nodes, NULL, NULL);
    for (int i = 0; i < face_node_size; ++i)
      face_nodes[i] -= 1;
    fe_mesh_set_face_nodes(mesh, num_faces, num_face_nodes, face_nodes);

    // Clean up.
    polymec_free(num_face_nodes);
  }

  // Go over the element blocks and feel out the data.
  for (int i = 0; i < file->num_elem_blocks; ++i)
  {
    int elem_block = file->elem_block_ids[i];
    char elem_type_name[MAX_NAME_LENGTH+1];
    int num_elem, num_nodes_per_elem, num_faces_per_elem;
    ex_get_block(file->ex_id, EX_ELEM_BLOCK, elem_block, 
                 elem_type_name, &num_elem,
                 &num_nodes_per_elem, NULL,
                 &num_faces_per_elem, NULL);

    // Get the type of element for this block.
    fe_mesh_element_t elem_type = get_element_type(elem_type_name);
    fe_block_t* block = NULL;
    char block_name[MAX_NAME_LENGTH+1];
    if (elem_type == FE_POLYHEDRON)
    {
      // Find the number of faces for each element in the block.
      int* num_elem_faces = polymec_malloc(sizeof(int) * num_elem);
      ex_get_entity_count_per_polyhedra(file->ex_id, EX_ELEM_BLOCK, elem_block, 
                                        num_elem_faces);

      // Get the element->face connectivity.
      int elem_face_size = 0;
      for (int j = 0; j < num_elem; ++j)
        elem_face_size += num_elem_faces[j];
      int* elem_faces = polymec_malloc(sizeof(int) * elem_face_size);
      ex_get_conn(file->ex_id, EX_ELEM_BLOCK, elem_block, NULL, NULL, elem_faces);

      // Subtract 1 from each element face.
      for (int j = 0; j < elem_face_size; ++j)
        elem_faces[j] -= 1;

      // Create the element block.
      block = polyhedral_fe_block_new(num_elem, num_elem_faces, elem_faces);
    }
    else if (elem_type != FE_INVALID)
    {
      // Get the element's nodal mapping.
      int* node_conn = polymec_malloc(sizeof(int) * num_elem * num_nodes_per_elem);
      ex_get_conn(file->ex_id, EX_ELEM_BLOCK, elem_block, node_conn, NULL, NULL);
      
      // Subtract 1 from each element node.
      for (int j = 0; j < num_elem * num_nodes_per_elem; ++j)
        node_conn[j] -= 1;

      // Build the element block.
      block = fe_block_new(num_elem, elem_type, num_nodes_per_elem, node_conn);
    }
    else
    {
      fe_mesh_free(mesh);
      ex_close(file->ex_id);
      polymec_error("Block %d contains an invalid (3D) element type.", elem_block);
    }

    // Fish out the element block name if it has one, or make a default.
    ex_get_name(file->ex_id, EX_ELEM_BLOCK, elem_block, block_name);
    if (strlen(block_name) == 0)
      sprintf(block_name, "block_%d", elem_block);

    // Add the element block to the mesh.
    fe_mesh_add_block(mesh, block_name, block);
  }

  // Fetch node positions and compute geometry.
  real_t x[file->num_nodes], y[file->num_nodes], z[file->num_nodes];
  ex_get_coord(file->ex_id, x, y, z);
  point_t* X = fe_mesh_node_positions(mesh);
  for (int n = 0; n < file->num_nodes; ++n)
  {
    X[n].x = x[n];
    X[n].y = y[n];
    X[n].z = z[n];
  }

  // Fetch sets of entities.
  for (int i = 1; i <= file->num_elem_sets; ++i)
    fetch_set(file, EX_ELEM_SET, i, mesh, fe_mesh_create_element_set);
  for (int i = 1; i <= file->num_face_sets; ++i)
    fetch_set(file, EX_FACE_SET, i, mesh, fe_mesh_create_face_set);
  for (int i = 1; i <= file->num_edge_sets; ++i)
    fetch_set(file, EX_EDGE_SET, i, mesh, fe_mesh_create_edge_set);
  for (int i = 1; i <= file->num_node_sets; ++i)
    fetch_set(file, EX_NODE_SET, i, mesh, fe_mesh_create_node_set);
  for (int i = 1; i <= file->num_side_sets; ++i)
    fetch_set(file, EX_SIDE_SET, i, mesh, fe_mesh_create_side_set);

  return mesh;
}
Пример #9
0
bool exodus_file_query(const char* filename,
                       size_t* real_size,
                       float* version,
                       int* num_mpi_processes,
                       real_array_t* times)
{
  set_ex_opts();

  if (!file_exists(filename))
    return false;

  bool valid = true;
  bool is_parallel = false;
  int my_real_size = (int)sizeof(real_t);
  int io_real_size = 0;
#if POLYMEC_HAVE_MPI
  MPI_Info info;
  MPI_Info_create(&info);
  int id = ex_open_par(filename, EX_READ, &my_real_size,
                       &io_real_size, version, 
                       MPI_COMM_WORLD, info);

  // Did that work? If not, try the serial opener.
  if (id < 0)
  {
    MPI_Info_free(&info);
    id = ex_open(filename, EX_READ, &my_real_size,
                 &io_real_size, version);
  }
  else
    is_parallel = true;
#else
  int id = ex_open(filename, EX_READ, &my_real_size,
                   &io_real_size, version);
#endif

  if (id < 0)
    valid = false;
  else
  {
    *real_size = (size_t)io_real_size;

    // Make sure that the file has 3D data.
    ex_init_params mesh_info;
    int status = ex_get_init_ext(id, &mesh_info);
    if ((status < 0) || (mesh_info.num_dim != 3))
      valid = false;
    else
    {
      // Make sure that each of the element blocks in this file have 
      // valid 3D element types.
      int num_elem_blocks = (int)mesh_info.num_elem_blk;
      int elem_block_ids[num_elem_blocks];
      ex_get_ids(id, EX_ELEM_BLOCK, elem_block_ids);
      for (int i = 0; i < num_elem_blocks; ++i)
      {
        int elem_block = elem_block_ids[i];
        char elem_type_name[MAX_NAME_LENGTH+1];
        int num_elem, num_nodes_per_elem, num_faces_per_elem;
        ex_get_block(id, EX_ELEM_BLOCK, elem_block, 
                     elem_type_name, &num_elem,
                     &num_nodes_per_elem, NULL,
                     &num_faces_per_elem, NULL);
        fe_mesh_element_t elem_type = get_element_type(elem_type_name);
        if (elem_type == FE_INVALID)
        {
          valid = false;
          break;
        }
      }
      
      if (valid)
      {
        // Query the number of processes for which this file has data.
        // Recently, we've had to add guards to check to see whether 
        // DIM_NUM_PROCS exists in the file. If it doesn't, we assume that 
        // the file corresponds to a serial data set.
        int num_proc_in_file;
        char file_type[2];
        int dim_id, status1 = nc_inq_dimid(id, DIM_NUM_PROCS, &dim_id);
        if (status1 == NC_NOERR)
        {
          ex_get_init_info(id, num_mpi_processes, &num_proc_in_file, file_type);
          if (is_parallel)
          {
            ASSERT(*num_mpi_processes == num_proc_in_file);
          }
        }
        else
        {
          *num_mpi_processes = num_proc_in_file = 1;
        }

        if (times != NULL)
        {
          // Ask for the times within the file.
          int num_times = (int)ex_inquire_int(id, EX_INQ_TIME);
          real_array_resize(times, num_times);
          if (num_times > 0)
          {
            ex_get_all_times(id, times->data);
          }
        }
      }
    }

    ex_close(id);
  }

#if POLYMEC_HAVE_MPI
  if (is_parallel)
    MPI_Info_free(&info);
#endif

  return valid;
}
Пример #10
0
int main(int argc, char **argv)
{
    MPI_Comm mpi_comm = MPI_COMM_WORLD;
    MPI_Info mpi_info = MPI_INFO_NULL;

    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;

    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  name[MAX_STR_LENGTH + 1];
    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];

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

    ex_opts(EX_VERBOSE | EX_ABORT);

    /* Initialize MPI. */
    MPI_Init(&argc, &argv);

    /* open EXODUS II files */
    exoid = ex_open_par("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 */
                        mpi_comm, mpi_info);

    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);

    /* 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 = %d\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));
    if (num_dim >= 2)
        y = (float *)calloc(num_nodes, sizeof(float));
    else
        y = 0;

    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]);
    }

    if (num_dim >= 2) {
        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);
    if (num_dim >= 2)
        free(y);
    if (num_dim >= 3)
        free(z);

    for (i = 0; i < num_dim; i++) {
        coord_names[i] = (char *)calloc((MAX_STR_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]);
    if (num_dim > 1)
        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_STR_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_ids(exoid, EX_ELEM_BLOCK, ids);
        printf("\nafter ex_get_elem_blk_ids, error = %3d\n", error);

        for (i = 0; i < num_elem_blk; i++) {
            printf("Block # %d is id %d\n", i, ids[i]);
            block_names[i] = (char *)calloc((MAX_STR_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_block(exoid, EX_ELEM_BLOCK, ids[i], elem_type, &(num_elem_in_block[i]),
                                 &(num_nodes_per_elem[i]), &(num_attr[i]));
            printf("\nafter ex_get_elem_block, id = %d, error = %d\n", ids[i], 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_STR_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_conn(exoid, EX_ELEM_BLOCK, 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_STR_LENGTH + 1), sizeof(char));

            attrib = (float *)calloc(num_attr[i] * num_elem_in_block[i], sizeof(float));
            error  = ex_get_attr(exoid, EX_ELEM_BLOCK, ids[i], attrib);
            printf("\n after ex_get_elem_attr, error = %d\n", error);

            if (error == 0) {
                error = ex_get_attr_names(exoid, EX_ELEM_BLOCK, 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_ids(exoid, EX_NODE_SET, 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_STR_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_set_param(exoid, EX_NODE_SET, 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_set(exoid, EX_NODE_SET, ids[i], node_list);
            printf("\nafter ex_get_node_set, error = %3d\n", error);

            if (num_df_in_set > 0) {
                error = ex_get_set_dist_fact(exoid, EX_NODE_SET, 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_nodes_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_STR_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_STR_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_ids(exoid, EX_SIDE_SET, 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_STR_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_set_param(exoid, EX_SIDE_SET, 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_set(exoid, EX_SIDE_SET, 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_set_dist_fact(exoid, EX_SIDE_SET, 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_STR_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_STR_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_variable_param(exoid, EX_GLOBAL, &num_glo_vars);
    printf("\nafter ex_get_variable_param, error = %3d\n", error);

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

    error = ex_get_variable_names(exoid, EX_GLOBAL, num_glo_vars, var_names);
    printf("\nafter ex_get_variable_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_variable_param(exoid, EX_NODE_SET, &num_nod_vars);
        printf("\nafter ex_get_variable_param, error = %3d\n", error);

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

        error = ex_get_variable_names(exoid, EX_NODAL, num_nod_vars, var_names);
        printf("\nafter ex_get_variable_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_variable_param(exoid, EX_ELEM_BLOCK, &num_ele_vars);
        printf("\nafter ex_get_variable_param, error = %3d\n", error);

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

        error = ex_get_variable_names(exoid, EX_ELEM_BLOCK, num_ele_vars, var_names);
        printf("\nafter ex_get_variable_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_truth_table(exoid, EX_ELEM_BLOCK, 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_variable_param(exoid, "m", &num_nset_vars);
        printf("\nafter ex_get_variable_param, error = %3d\n", error);

        if (num_nset_vars > 0) {
            for (i = 0; i < num_nset_vars; i++) {
                var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
            }

            error = ex_get_variable_names(exoid, "m", num_nset_vars, var_names);
            printf("\nafter ex_get_variable_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_truth_table(exoid, EX_NODE_SET, 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_variable_param(exoid, EX_SIDE_SET, &num_sset_vars);
        printf("\nafter ex_get_variable_param, error = %3d\n", error);

        if (num_sset_vars > 0) {
            for (i = 0; i < num_sset_vars; i++) {
                var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
            }

            error = ex_get_variable_names(exoid, EX_SIDE_SET, num_sset_vars, var_names);
            printf("\nafter ex_get_variable_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_truth_table(exoid, EX_SIDE_SET, 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_var(exoid, time_step, EX_NODAL, var_index, 1, 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_var_time(exoid, EX_NODAL, 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_ids(exoid, EX_ELEM_BLOCK, 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_var(exoid, time_step, EX_ELEM_BLOCK, 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_var_time(exoid, EX_ELEM_BLOCK, 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_ids(exoid, EX_SIDE_SET, 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_var(exoid, time_step, EX_SIDE_SET, 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_ids(exoid, EX_NODE_SET, 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_var(exoid, time_step, EX_NODE_SET, 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);

    error = ex_close(exoid);
    printf("\nafter ex_close, error = %3d\n", error);
    MPI_Finalize();
    return 0;
}