int ex_get_partial_node_set (int   exoid,
                       ex_entity_id node_set_id,
                       int64_t   start_node_num,
                       int64_t   num_nodes,
                       void_int  *node_set_node_list)
{
  int     dimid, node_list_id, node_set_id_ndx, status;
  size_t  num_nodes_in_set, start[1], count[1];
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  /* first check if any node sets are specified */

  if ((status = nc_inq_dimid (exoid, DIM_NUM_NS, &dimid))  != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Warning: no node sets defined in file id %d",
            exoid);
    ex_err("ex_get_partial_node_set",errmsg,exerrval);
    return (EX_WARN);
  }

  /* Lookup index of node set id in VAR_NS_IDS array */
  if ((node_set_id_ndx = ex_id_lkup(exoid, EX_NODE_SET, node_set_id)) < 0) {
    if (exerrval == EX_NULLENTITY) {
      sprintf(errmsg,
              "Warning: node set %"PRId64" is NULL in file id %d",
              node_set_id,exoid);
      ex_err("ex_get_partial_node_set",errmsg,EX_NULLENTITY);
      return (EX_WARN);
    } 

      sprintf(errmsg,
              "Error: failed to locate node set %"PRId64" in %s in file id %d",
              node_set_id,VAR_NS_IDS,exoid);
      ex_err("ex_get_partial_node_set",errmsg,exerrval);
      return (EX_FATAL);
    
  }

  /* inquire id's of previously defined dimensions and variables */
  if ((status = nc_inq_dimid (exoid, DIM_NUM_NOD_NS(node_set_id_ndx), &dimid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
         "Error: failed to locate number of nodes in node set %"PRId64" in file id %d",
            node_set_id,exoid);
    ex_err("ex_get_partial_node_set",errmsg,exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_inq_dimlen(exoid, dimid, &num_nodes_in_set)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get number of nodes in set %"PRId64" in file id %d",
            node_set_id, exoid);
    ex_err("ex_get_partial_node_set",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* Check input parameters for a valid range of numbers */
  if (start_node_num < 0 || start_node_num > num_nodes_in_set) {
    exerrval = EX_BADPARAM;
    sprintf(errmsg, "Error: Invalid input");
    ex_err("ex_get_partial_node_set",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (num_nodes < 0) {
    exerrval = EX_BADPARAM;
    sprintf(errmsg, "Error: Invalid number of nodes in nodes set!");
    ex_err("ex_get_partial_node_set",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* start_node_num now starts at 1, not 0 */
  if ((start_node_num + num_nodes - 1) > num_nodes_in_set) {
    exerrval = EX_BADPARAM;
    sprintf(errmsg, "Error: request larger than number of nodes in set!");
    ex_err("ex_get_partial_node_set",errmsg,exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_inq_varid (exoid, VAR_NODE_NS(node_set_id_ndx), &node_list_id)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to locate node set %"PRId64" node list in file id %d",
            node_set_id,exoid);
    ex_err("ex_get_partial_node_set",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* read in the node list array */
  start[0] = --start_node_num;
  count[0] = num_nodes;

  if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
    status = nc_get_vara_longlong(exoid, node_list_id, start, count, node_set_node_list);
  } else {
    status = nc_get_vara_int(exoid, node_list_id, start, count, node_set_node_list);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get node set node list in file id %d",
            exoid);
    ex_err("ex_get_partial_node_set",errmsg,exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
int ex_get_processor_node_maps(int exoid, void_int *node_mapi, void_int *node_mapb,
                               void_int *node_mape, int processor)
{
  const char *func_name = "ex_get_processor_node_maps";

  char    ftype[2];
  int     status, varid, dimid;
  size_t  start[1], count[1];
  int64_t varidx[2];
  int     nmstat;

  char errmsg[MAX_ERR_LENGTH];
  /*-----------------------------Execution begins-----------------------------*/

  ex_check_valid_file_id(exoid);

  exerrval = 0; /* clear error code */

  /* Get the file type */
  if (ex_get_file_type(exoid, ftype) != EX_NOERR) {
    exerrval = EX_MSG;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unable to find file type for file ID %d", exoid);
    ex_err(func_name, errmsg, exerrval);

    return (EX_FATAL);
  }

  /* Get the status of this node map */
  if ((status = nc_inq_varid(exoid, VAR_INT_N_STAT, &varid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" from file ID %d",
             VAR_INT_N_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (ftype[0] == 'p') {
    start[0] = 0;
  }
  else {
    start[0] = processor;
  }

  if (nc_get_var1_int(exoid, varid, start, &nmstat) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get status for \"%s\" in file ID %d",
             VAR_INT_N_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (nmstat == 1) {
    /* get the index */
    if (ex_get_idx(exoid, VAR_NODE_MAP_INT_IDX, varidx, processor) == -1) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to find index variable, \"%s\", in file ID %d", VAR_NODE_MAP_INT_IDX,
               exoid);
      ex_err(func_name, errmsg, exerrval);

      return (EX_FATAL);
    }

    /* check if I need to get the dimension */
    if (varidx[1] == -1) {
      if ((status = nc_inq_dimid(exoid, DIM_NUM_INT_NODES, &dimid)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_INT_NODES,
                 exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }

      if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to find length of dimension \"%s\" in file ID %d",
                 DIM_NUM_INT_NODES, exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }
      varidx[1] = count[0];
    }

    if ((status = nc_inq_varid(exoid, VAR_NODE_MAP_INT, &varid)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
               VAR_NODE_MAP_INT, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    start[0] = varidx[0];
    count[0] = varidx[1] - varidx[0];
    if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
      status = nc_get_vara_longlong(exoid, varid, start, count, node_mapi);
    }
    else {
      status = nc_get_vara_int(exoid, varid, start, count, node_mapi);
    }
    if (status != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d",
               VAR_NODE_MAP_INT, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

  } /* End "if (nmstat == 1)" */

  /* Get the status of this node map */
  if ((status = nc_inq_varid(exoid, VAR_BOR_N_STAT, &varid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" from file ID %d",
             VAR_BOR_N_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (ftype[0] == 'p') {
    start[0] = 0;
  }
  else {
    start[0] = processor;
  }

  if (nc_get_var1_int(exoid, varid, start, &nmstat) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get status for \"%s\" from file ID %d",
             VAR_BOR_N_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (nmstat == 1) {
    /* get the index */
    if (ex_get_idx(exoid, VAR_NODE_MAP_BOR_IDX, varidx, processor) == -1) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to find index variable, \"%s\", in file ID %d", VAR_NODE_MAP_BOR_IDX,
               exoid);
      ex_err(func_name, errmsg, exerrval);

      return (EX_FATAL);
    }

    /* check if I need to get the dimension */
    if (varidx[1] == -1) {
      if ((status = nc_inq_dimid(exoid, DIM_NUM_BOR_NODES, &dimid)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_BOR_NODES,
                 exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }

      if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to find length of dimension \"%s\" in file ID %d",
                 DIM_NUM_BOR_NODES, exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }
      varidx[1] = count[0];
    }

    if ((status = nc_inq_varid(exoid, VAR_NODE_MAP_BOR, &varid)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
               VAR_NODE_MAP_BOR, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    start[0] = varidx[0];
    count[0] = varidx[1] - varidx[0];
    if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
      status = nc_get_vara_longlong(exoid, varid, start, count, node_mapb);
    }
    else {
      status = nc_get_vara_int(exoid, varid, start, count, node_mapb);
    }
    if (status != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d",
               VAR_NODE_MAP_BOR, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }
  } /* End "if (nmstat == 1)" */

  /* Get the status of this node map */
  if ((status = nc_inq_varid(exoid, VAR_EXT_N_STAT, &varid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" from file ID %d",
             VAR_EXT_N_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (ftype[0] == 'p') {
    start[0] = 0;
  }
  else {
    start[0] = processor;
  }

  if (nc_get_var1_int(exoid, varid, start, &nmstat) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get status for \"%s\" from file ID %d",
             VAR_EXT_N_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (nmstat == 1) {
    /* get the index */
    if (ex_get_idx(exoid, VAR_NODE_MAP_EXT_IDX, varidx, processor) == -1) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to find index variable, \"%s\", in file ID %d", VAR_NODE_MAP_EXT_IDX,
               exoid);
      ex_err(func_name, errmsg, exerrval);

      return (EX_FATAL);
    }

    /* check if I need to get the dimension */
    if (varidx[1] == -1) {
      if ((status = nc_inq_dimid(exoid, DIM_NUM_EXT_NODES, &dimid)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_EXT_NODES,
                 exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }

      if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to find length of dimension \"%s\" in file ID %d",
                 DIM_NUM_EXT_NODES, exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }
      varidx[1] = count[0];
    }

    if ((status = nc_inq_varid(exoid, VAR_NODE_MAP_EXT, &varid)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
               VAR_NODE_MAP_EXT, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    start[0] = varidx[0];
    count[0] = varidx[1] - varidx[0];
    if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
      status = nc_get_vara_longlong(exoid, varid, start, count, node_mape);
    }
    else {
      status = nc_get_vara_int(exoid, varid, start, count, node_mape);
    }
    if (status != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d",
               VAR_NODE_MAP_EXT, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }
  } /* End "if (nmstat == 1)" */
  return (EX_NOERR);
}
int ex_get_cmap_params(int  exoid,
                       void_int *node_cmap_ids,
                       void_int *node_cmap_node_cnts,
                       void_int *elem_cmap_ids,
                       void_int *elem_cmap_elem_cnts,
                       int  processor
		       )
{
  const char   *func_name="ex_get_cmap_params";

  size_t  cnt, num_n_comm_maps, num_e_comm_maps, start[1], count[1];
  int64_t cmap_info_idx[2], cmap_data_idx[2];
  int     nmstat;
  int     status, map_idx, varid, dimid;

  char    errmsg[MAX_ERR_LENGTH];
  /*-----------------------------Execution begins-----------------------------*/

  exerrval = 0;	/* clear error code */

  /*****************************************************************************/
  /*****************************************************************************/
  /*                    Nodal communication map(s)                             */
  /*****************************************************************************/
  /*****************************************************************************/

  /* get the cmap information variables index */
  if (ex_get_idx(exoid, VAR_N_COMM_INFO_IDX, cmap_info_idx, processor) == -1) {
    sprintf(errmsg,
            "Error: failed to find index variable, \"%s\", in file ID %d",
            VAR_N_COMM_INFO_IDX, exoid);
    ex_err(func_name, errmsg, exerrval);

    return (EX_FATAL);
  }

  /* Get the number of nodal communications maps in the file */
  if ((status = nc_inq_dimid(exoid, DIM_NUM_N_CMAPS, &dimid)) == NC_NOERR) {
    /* check if I need to get the dimension of the nodal comm map */
    if (cmap_info_idx[1] == -1) {
      if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
		"Error: failed to find length of dimension \"%s\" in file ID %d",
                DIM_NUM_N_CMAPS, exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }

      /* set the end value for the node map */
      cmap_info_idx[1] = count[0];
    }  /* End "if (cmap_info_idx[1] == -1) */

    num_n_comm_maps = cmap_info_idx[1] - cmap_info_idx[0];

    if (num_n_comm_maps > 0) {
      count[0] = num_n_comm_maps;

      /* Get the variable ID for the vector of nodal comm map IDs */
      if ((status = nc_inq_varid(exoid, VAR_N_COMM_IDS, &varid)) != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to get variable ID for \"%s\" in file ID %d",
                VAR_N_COMM_IDS, exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }

      /* Get the vector of nodal communication map IDs */
      if (node_cmap_ids != NULL) {
        start[0] = cmap_info_idx[0];
	if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
	  status = nc_get_vara_longlong(exoid, varid, start, count, node_cmap_ids);
	} else {
	  status = nc_get_vara_int(exoid, varid, start, count, node_cmap_ids);
	}

        if (status != NC_NOERR) {
          exerrval = status;
          sprintf(errmsg,
                  "Error: failed to get variable \"%s\" from file ID %d",
                  VAR_N_COMM_IDS, exoid);
          ex_err(func_name, errmsg, exerrval);
          return (EX_FATAL);
        }

        if ((status = nc_inq_varid(exoid, VAR_N_COMM_STAT, &varid)) != NC_NOERR) {
          exerrval = status;
          sprintf(errmsg,
		  "Error: failed to find variable ID for \"%s\" from file ID %d",
                  VAR_N_COMM_STAT, exoid);
          ex_err(func_name, errmsg, exerrval);
          return (EX_FATAL);
        }

        if (node_cmap_node_cnts != NULL) {

          /* Get the node counts in each of the nodal communication maps */
          for(cnt=0; cnt < num_n_comm_maps; cnt++) {
	    int64_t cmap_id;
	    if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
	      cmap_id = ((int64_t*)node_cmap_ids)[cnt];
	    } else {
	      cmap_id = ((int*)node_cmap_ids)[cnt];
	    }

            if ((map_idx=ne_id_lkup(exoid, VAR_N_COMM_IDS, cmap_info_idx, cmap_id)) < 0) {
              exerrval = EX_MSG;
              sprintf(errmsg,
		      "Error: failed to find nodal comm map with ID %"PRId64" in file ID %d",
                      cmap_id, exoid);
              ex_err(func_name, errmsg, exerrval);
              return (EX_FATAL);
            }

            /* Check the status of the node map */
            start[0] = map_idx;
            if ((status = nc_get_var1_int(exoid, varid, start, &nmstat)) != NC_NOERR) {
              exerrval = status;
              sprintf(errmsg,
		      "Error: failed to get status for \"%s\" from file ID %d",
                      VAR_N_COMM_STAT, exoid);
              ex_err(func_name, errmsg, exerrval);
              return (EX_FATAL);
            }

            if (nmstat == 1) {

              /* get the cmap information variables index */
              if (ex_get_idx(exoid, VAR_N_COMM_DATA_IDX, cmap_data_idx,
                             map_idx) == -1) {
                exerrval = status;
                sprintf(errmsg,
			"Error: failed to find index variable, \"%s\", in file ID %d",
                        VAR_N_COMM_DATA_IDX, exoid);
                ex_err(func_name, errmsg, exerrval);

                return (EX_FATAL);
              }

              if (cmap_data_idx[1] == -1) {
                /*
                 * Find the dimension ID of the variable containing the
                 * node count
                 */
                if ((status = nc_inq_dimid(exoid, DIM_NCNT_CMAP, &dimid)) != NC_NOERR) {
                  exerrval = status;
                  sprintf(errmsg,
			  "Error: failed to find dimension ID for \"%s\" in file ID %d",
                          DIM_NCNT_CMAP, exoid);
                  ex_err(func_name, errmsg, exerrval);
                  return (EX_FATAL);
                }

		/* Find the value of the number of nodes in this nodal comm map */
                if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
                  exerrval = status;
                  sprintf(errmsg,
			  "Error: failed to find length of dimension \"%s\" in file ID %d",
                          DIM_NCNT_CMAP, exoid);
                  ex_err(func_name, errmsg, exerrval);
                  return (EX_FATAL);
                }

                cmap_data_idx[1] = count[0];
              }

	      if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
		((int64_t*)node_cmap_node_cnts)[cnt] = cmap_data_idx[1] - cmap_data_idx[0];
	      } else {
		((int*)node_cmap_node_cnts)[cnt] = cmap_data_idx[1] - cmap_data_idx[0];
	      }
            }
            else
	      if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
		((int64_t*)node_cmap_node_cnts)[cnt] = 0;
	      } else {
		((int*)node_cmap_node_cnts)[cnt] = 0;
	      }
          }  /* "for(cnt=0; cnt < num_n_comm_maps; cnt++)" */
        }  /* "if (node_cmap_node_cnts != NULL)" */
      }  /* "if (node_cmap_ids != NULL)" */
    }  /* "if (num_n_comm_maps > 0)" */
  } /* End "if ((dimid = nc_inq_dimid(exoid, DIM_NUM_N_CMAPS)) != -1)" */

  /*****************************************************************************/
  /*****************************************************************************/
  /*                Elemental communication map(s)                             */
  /*****************************************************************************/
  /*****************************************************************************/

  /* get the cmap information variables index */
  if (ex_get_idx(exoid, VAR_E_COMM_INFO_IDX, cmap_info_idx, processor) == -1) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to find index variable, \"%s\", in file ID %d",
            VAR_E_COMM_INFO_IDX, exoid);
    ex_err(func_name, errmsg, exerrval);

    return (EX_FATAL);
  }

  /* Get the number of elemental communications maps in the file */
  if ((status = nc_inq_dimid(exoid, DIM_NUM_E_CMAPS, &dimid)) == NC_NOERR) {
    /* check if I need to get the dimension of the nodal comm map */
    if (cmap_info_idx[1] == -1) {
      if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
		"Error: failed to find length of dimension \"%s\" in file ID %d",
                DIM_NUM_E_CMAPS, exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }

      /* set the end value for the node map */
      cmap_info_idx[1] = count[0];
    }  /* End "if (cmap_info_idx[1] == -1) */

    num_e_comm_maps = cmap_info_idx[1] - cmap_info_idx[0];

    if (num_e_comm_maps > 0) {
      count[0] = num_e_comm_maps;

      /* Get the variable ID for the vector of nodal comm map IDs */
      if ((status = nc_inq_varid(exoid, VAR_E_COMM_IDS, &varid)) != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to get variable ID for \"%s\" in file ID %d",
                VAR_E_COMM_IDS, exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }

      /* Get the vector of elemental communication map IDs */
      if (elem_cmap_ids != NULL) {
        start[0] = cmap_info_idx[0];
	if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
	  status = nc_get_vara_longlong(exoid, varid, start, count, elem_cmap_ids);
	} else {
	  status = nc_get_vara_int(exoid, varid, start, count, elem_cmap_ids);
	}
        if (status != NC_NOERR) {
          exerrval = status;
          sprintf(errmsg,
                  "Error: failed to get variable \"%s\" from file ID %d",
                  VAR_E_COMM_IDS, exoid);
          ex_err(func_name, errmsg, exerrval);
          return (EX_FATAL);
        }

        if ((status = nc_inq_varid(exoid, VAR_E_COMM_STAT, &varid)) != NC_NOERR) {
          exerrval = status;
          sprintf(errmsg,
		  "Error: failed to find variable ID for \"%s\" from file ID %d",
                  VAR_E_COMM_STAT, exoid);
          ex_err(func_name, errmsg, exerrval);
          return (EX_FATAL);
        }

        if (elem_cmap_elem_cnts != NULL) {
          /*
           * Get the element counts in each of the elemental
           * communication maps
           */
          for(cnt=0; cnt < num_e_comm_maps; cnt++) {
	    int64_t cmap_id;
	    if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
	      cmap_id = ((int64_t*)elem_cmap_ids)[cnt];
	    } else {
	      cmap_id = ((int*)elem_cmap_ids)[cnt];
	    }

            if ((map_idx=ne_id_lkup(exoid, VAR_E_COMM_IDS, cmap_info_idx,
				    cmap_id)) < 0) {
              exerrval = EX_MSG;
              sprintf(errmsg,
		      "Error: failed to find elemental comm map with ID %"PRId64" in file ID %d",
                      cmap_id, exoid);
              ex_err(func_name, errmsg, exerrval);
              return (EX_FATAL);
            }

            /* Check the status of the requested elemental map */
            start[0] = map_idx;
            if ((status = nc_get_var1_int(exoid, varid, start, &nmstat)) != NC_NOERR) {
              exerrval = status;
              sprintf(errmsg,
                      "Error: failed to get status for \"%s\" from file ID %d",
                      VAR_E_COMM_STAT, exoid);
              ex_err(func_name, errmsg, exerrval);
              return (EX_FATAL);
            }

            if (nmstat == 1) {

              /* get the cmap information variables index */
              if (ex_get_idx(exoid, VAR_E_COMM_DATA_IDX, cmap_data_idx,
                             map_idx) == -1) {
                exerrval = status;
                sprintf(errmsg,
			"Error: failed to find index variable, \"%s\", in file ID %d",
			VAR_E_COMM_DATA_IDX, exoid);
                ex_err(func_name, errmsg, exerrval);

                return (EX_FATAL);
              }

              if (cmap_data_idx[1] == -1) {
                /*
                 * Find the dimension ID of the variable containing the
                 * element count
                 */
                if ((status = nc_inq_dimid(exoid, DIM_ECNT_CMAP, &dimid)) != NC_NOERR) {
                  exerrval = status;
                  sprintf(errmsg,
			  "Error: failed to find dimension ID for \"%s\" in file ID %d",
                          DIM_ECNT_CMAP, exoid);
                  ex_err(func_name, errmsg, exerrval);
                  return (EX_FATAL);
                }

                /*
                 * Find the value of the number of elements in this elemental
                 * comm map
                 */
                if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
                  exerrval = status;
                  sprintf(errmsg,
			  "Error: failed to find length of dimension \"%s\" in file ID %d",
                          DIM_ECNT_CMAP, exoid);
                  ex_err(func_name, errmsg, exerrval);
                  return (EX_FATAL);
                }
                cmap_data_idx[1] = count[0];
              }
	      if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
		((int64_t*)elem_cmap_elem_cnts)[cnt] = cmap_data_idx[1] - cmap_data_idx[0];
	      } else {
		((int*)elem_cmap_elem_cnts)[cnt] = cmap_data_idx[1] - cmap_data_idx[0];
	      }
            }
            else
	      if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
		((int64_t*)elem_cmap_elem_cnts)[cnt] = 0;
	      } else {
		((int*)elem_cmap_elem_cnts)[cnt] = 0;
	      }
          }  /* "for(cnt=0; cnt < num_e_comm_maps; cnt++)" */
        }  /* "if (elem_cmap_elem_cnts != NULL)" */
      }  /* "if (elem_cmap_ids != NULL)" */
    }  /* "if (num_e_comm_maps > 0)" */
  } /* End "if ((dimid = nc_inq_dimid(exoid, DIM_NUM_E_CMAPS(processor))) != -1)" */
  return (EX_NOERR);
}
int ex_get_processor_elem_maps(int  exoid,
			       void_int *elem_mapi,
			       void_int *elem_mapb,
			       int  processor
			       )
{
  const char  *func_name="ex_get_processor_elem_maps";

  char    ftype[2];
  int     dimid, varid, status;
  size_t  start[1], count[1];
  int64_t varidx[2];
  int  emstat;

  char   errmsg[MAX_ERR_LENGTH];

  /* Get the file type */
  if (ex_get_file_type(exoid, ftype) != EX_NOERR) {
    exerrval = EX_MSG;
    sprintf(errmsg,
            "Error: unable to find file type for file ID %d",
            exoid);
    ex_err(func_name, errmsg, exerrval);

    return (EX_FATAL);
  }

  /* Check the status of the internal element map */
  if ((status = nc_inq_varid(exoid, VAR_INT_E_STAT, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to find variable ID for \"%s\" in file ID %d",
            VAR_INT_E_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (ftype[0] == 'p')
    start[0] = 0;
  else
    start[0] = processor;

  if ((status = nc_get_var1_int(exoid, varid, start, &emstat)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get status for \"%s\" from file ID %d",
            VAR_INT_E_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (emstat == 1) {
    /* get the index */
    if (ex_get_idx(exoid, VAR_ELEM_MAP_INT_IDX, varidx, processor) == -1) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to find index variable, \"%s\", in file ID %d",
              VAR_ELEM_MAP_INT_IDX, exoid);
      ex_err(func_name, errmsg, exerrval);

      return (EX_FATAL);
    }

    if (varidx[1] == -1) {
      /* Get the size of the internal element map */
      if ((status = nc_inq_dimid(exoid, DIM_NUM_INT_ELEMS, &dimid)) != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to find dimension ID for \"%s\" in file ID %d",
                DIM_NUM_INT_ELEMS, exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }

      if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
		"Error: failed to find length of dimension \"%s\" in file ID %d",
                DIM_NUM_INT_ELEMS, exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }

      varidx[1] = count[0];
    }

    /* Get the map */
    if ((status = nc_inq_varid(exoid, VAR_ELEM_MAP_INT, &varid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to find variable ID for \"%s\" in file ID %d",
              VAR_ELEM_MAP_INT, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    start[0] = varidx[0];
    count[0] = varidx[1] - varidx[0];
    if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
      status = nc_get_vara_longlong(exoid, varid, start, count, elem_mapi);
    } else {
      status = nc_get_vara_int(exoid, varid, start, count, elem_mapi);
    }

    if (status != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to get variable \"%s\" from file ID %d",
              VAR_ELEM_MAP_INT, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

  } /* End "if (emstat == 1)" */

  /* Check the status of the internal element map */
  if ((status = nc_inq_varid(exoid, VAR_BOR_E_STAT, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to find variable ID for \"%s\" in file ID %d",
            VAR_BOR_E_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (ftype[0] == 'p')
    start[0] = 0;
  else
    start[0] = processor;

  if ((status = nc_get_var1_int(exoid, varid, start, &emstat)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to get status for \"%s\" from file ID %d",
	    VAR_INT_E_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (emstat == 1) {
    /* get the index */
    if (ex_get_idx(exoid, VAR_ELEM_MAP_BOR_IDX, varidx, processor) == -1) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to find index variable, \"%s\", in file ID %d",
	      VAR_ELEM_MAP_BOR_IDX, exoid);
      ex_err(func_name, errmsg, exerrval);

      return (EX_FATAL);
    }

    if (varidx[1] == -1) {
      /* Get the size of the border element map */
      if ((status = nc_inq_dimid(exoid, DIM_NUM_BOR_ELEMS, &dimid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to find dimension ID for \"%s\" in file ID %d",
		DIM_NUM_BOR_ELEMS, exoid);
	ex_err(func_name, errmsg, exerrval);
	return (EX_FATAL);
      }

      if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to find length of dimension \"%s\" in file ID %d",
		DIM_NUM_BOR_ELEMS, exoid);
	ex_err(func_name, errmsg, exerrval);
	return (EX_FATAL);
      }

      varidx[1] = count[0];
    }

    /* Get the map */
    if ((status = nc_inq_varid(exoid, VAR_ELEM_MAP_BOR, &varid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to find variable ID for \"%s\" in file ID %d",
	      VAR_ELEM_MAP_BOR, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    start[0] = varidx[0];
    count[0] = varidx[1] - varidx[0];
    if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
      status = nc_get_vara_longlong(exoid, varid, start, count, elem_mapb);
    } else {
      status = nc_get_vara_int(exoid, varid, start, count, elem_mapb);
    }

    if (status != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to get variable \"%s\" from file ID %d",
	      VAR_ELEM_MAP_BOR, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }
  } /* End "if (emstat == 1)" */

  return (EX_NOERR);
}
Esempio n. 5
0
int ex_get_partial_conn( int   exoid,
		   ex_entity_type blk_type,
		   ex_entity_id   blk_id,
		   int64_t   start_num,
		   int64_t   num_ent,
		   void_int*  nodeconn,
		   void_int*  edgeconn,
		   void_int*  faceconn )
{
  int connid = -1;
  int econnid = -1;
  int fconnid = -1;

  int blk_id_ndx;
  int status = 0;

  int numnodperentdim = -1;
  int numedgperentdim = -1;
  int numfacperentdim = -1;

  int iexit = (EX_NOERR); /* exit status */

  size_t num_nodes_per_entry = 0;
  size_t num_edges_per_entry = 0;
  size_t num_faces_per_entry = 0;
  char errmsg[MAX_ERR_LENGTH];

  const char* dnumnodent = NULL;
  const char* dnumedgent = NULL;
  const char* dnumfacent = NULL;
  const char* vnodeconn = NULL;
  const char* vedgeconn = NULL;
  const char* vfaceconn = NULL;

  /* The partial connectivity input function can currently only handle nodal
   * connectivity.  Print a warning if edgeconn or faceconn is non-NULL
   */
  if (edgeconn != NULL || faceconn != NULL) {
    exerrval = 1005;
    sprintf(errmsg,
	    "Warning: ex_get_partial_conn only supports nodal connectivity at this time. %s %"PRId64" in file id %d",
	    ex_name_of_object(blk_type),blk_id,exoid);
    ex_err("ex_get_partial_conn",errmsg,EX_MSG);
  }

  exerrval = 0; /* clear error code */

  /* Locate index of element block id in VAR_ID_EL_BLK array */

  blk_id_ndx = ex_id_lkup(exoid,blk_type,blk_id);
  if (exerrval != 0) 
    {
      if (exerrval == EX_NULLENTITY)
	{
	  sprintf(errmsg,
		  "Warning: no connectivity array for NULL %s %"PRId64" in file id %d",
		  ex_name_of_object(blk_type),blk_id,exoid);
	  ex_err("ex_get_partial_conn",errmsg,EX_NULLENTITY);
	  return (EX_WARN); /* no connectivity array for this element block */
	}
      else
	{
	  sprintf(errmsg,
		  "Error: failed to locate %s id %"PRId64" in id array in file id %d",
		  ex_name_of_object(blk_type),blk_id,exoid);
	  ex_err("ex_get_partial_conn",errmsg,exerrval);
	  return (EX_FATAL);
	}
    }

  switch (blk_type) {
  case EX_EDGE_BLOCK:
    dnumnodent = DIM_NUM_NOD_PER_ED(blk_id_ndx);
    dnumedgent = 0;
    dnumfacent = 0;
    vnodeconn = VAR_EBCONN(blk_id_ndx);
    vedgeconn = 0;
    vfaceconn = 0;
    break;
  case EX_FACE_BLOCK:
    dnumnodent = DIM_NUM_NOD_PER_FA(blk_id_ndx);
    dnumedgent = 0;
    dnumfacent = 0;
    vnodeconn = VAR_FBCONN(blk_id_ndx);
    vedgeconn = 0;
    vfaceconn = 0;
    break;
  case EX_ELEM_BLOCK:
    dnumnodent = DIM_NUM_NOD_PER_EL(blk_id_ndx);
    dnumedgent = DIM_NUM_EDG_PER_EL(blk_id_ndx);
    dnumfacent = DIM_NUM_FAC_PER_EL(blk_id_ndx);
    vnodeconn = VAR_CONN(blk_id_ndx);
    vedgeconn = VAR_ECONN(blk_id_ndx);
    vfaceconn = VAR_FCONN(blk_id_ndx);
    break;
  default:
    exerrval = 1005;
    sprintf(errmsg,
	    "Internal Error: unrecognized block type in switch: %d in file id %d",
	    blk_type,exoid);
    ex_err("ex_get_partial_conn",errmsg,EX_MSG);
    return (EX_FATAL);              /* number of attributes not defined */
  }
  /* inquire id's of previously defined dimensions  */

  if ((status = nc_inq_dimid (exoid, dnumnodent, &numnodperentdim)) != NC_NOERR)
    {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate number of nodes/entity for %s %"PRId64" in file id %d",
	      ex_name_of_object(blk_type),blk_id,exoid);
      ex_err("ex_get_partial_conn",errmsg,exerrval);
      return(EX_FATAL);
    }

  if (nc_inq_dimlen(exoid, numnodperentdim, &num_nodes_per_entry) != NC_NOERR)
    {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to get number of nodes/entity for %s %"PRId64" in file id %d",
	      ex_name_of_object(blk_type),blk_id,exoid);
      ex_err("ex_get_partial_conn",errmsg, exerrval);
      return(EX_FATAL);
    }

  if ( edgeconn && dnumedgent ) {
    num_edges_per_entry = 0;
    if ((status = nc_inq_dimid(exoid, dnumedgent, &numedgperentdim)) != NC_NOERR) {
      numedgperentdim = -1;
    } else {
      if ((status = nc_inq_dimlen(exoid, numedgperentdim, &num_edges_per_entry)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get number of edges/entry for %s %"PRId64" in file id %d",
		ex_name_of_object(blk_type),blk_id,exoid);
	ex_err("ex_get_partial_conn",errmsg, exerrval);
	return(EX_FATAL);
      }
    }
  }

  if ( faceconn && dnumfacent ) {
    num_faces_per_entry = 0;
    if ((status = nc_inq_dimid(exoid, dnumfacent, &numfacperentdim)) != NC_NOERR) {
      numfacperentdim = -1;
    } else {
      if ((status = nc_inq_dimlen(exoid, numfacperentdim, &num_faces_per_entry)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get number of faces/entry for %s %"PRId64" in file id %d",
		ex_name_of_object(blk_type),blk_id,exoid);
	ex_err("ex_get_partial_conn",errmsg, exerrval);
	return(EX_FATAL);
      }
    }
  }


  if ((status = nc_inq_varid(exoid, vnodeconn, &connid)) != NC_NOERR)
    {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate connectivity array for %s %"PRId64" in file id %d",
	      ex_name_of_object(blk_type),blk_id,exoid);
      ex_err("ex_get_partial_conn",errmsg, exerrval);
      return(EX_FATAL);
    }

  status = 0;
  if (edgeconn && (numedgperentdim > 0) &&
      ((status = nc_inq_varid (exoid, vedgeconn, &econnid)) != NC_NOERR))
    {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate edge connectivity array for %s %"PRId64" in file id %d",
	      ex_name_of_object(blk_type),blk_id,exoid);
      ex_err("ex_get_partial_conn",errmsg, exerrval);
      return(EX_FATAL);
    }

  if (faceconn && (numfacperentdim > 0) &&
      ((status = nc_inq_varid (exoid, vfaceconn, &fconnid)) != NC_NOERR))
    {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate face connectivity array for %s %"PRId64" in file id %d",
	      ex_name_of_object(blk_type),blk_id,exoid);
      ex_err("ex_get_partial_conn",errmsg, exerrval);
      return(EX_FATAL);
    }


  /* read in the connectivity array */
  if ( edgeconn && num_edges_per_entry > 0) {
    size_t start[2], count[2];
    
    start[0] = (start_num-1);
    start[1] = 0;
    count[0] = num_ent;
    count[1] = num_edges_per_entry;

    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
      status = nc_get_vara_longlong(exoid, econnid, start, count, edgeconn);
    } else {
      status = nc_get_vara_int(exoid, econnid, start, count, edgeconn);
    }

    if (status != NC_NOERR)
      {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get edge connectivity array for %s %"PRId64" in file id %d",
		ex_name_of_object(blk_type),blk_id,exoid);
	ex_err("ex_get_partial_conn",errmsg, exerrval);
	return(EX_FATAL);
      }
  }

  if ( faceconn && num_faces_per_entry > 0) {
    size_t start[2], count[2];
    
    start[0] = start_num-1;
    start[1] = 0;
    count[0] = num_ent;
    count[1] = num_faces_per_entry;
     
    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
      status = nc_get_vara_longlong(exoid, fconnid, start, count, faceconn);
    } else {
      status = nc_get_vara_int(exoid, fconnid, start, count, faceconn);
    }
     
    if (status != NC_NOERR)
      {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get face connectivity array for %s %"PRId64" in file id %d",
		ex_name_of_object(blk_type),blk_id,exoid);
	ex_err("ex_get_partial_conn",errmsg, exerrval);
	return(EX_FATAL);
      }
  }

  if ( nodeconn && num_nodes_per_entry > 0) {
    size_t start[2], count[2];
     
    start[0] = start_num-1;
    start[1] = 0;
    count[0] = num_ent;
    count[1] = num_nodes_per_entry;
     
    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
      status = nc_get_vara_longlong(exoid, connid, start, count, nodeconn);
    } else {
      status = nc_get_vara_int(exoid, connid, start, count, nodeconn);
    }

    if (status != NC_NOERR)
      {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get connectivity array for %s %"PRId64" in file id %d",
		ex_name_of_object(blk_type),blk_id,exoid);
	ex_err("ex_get_partial_conn",errmsg, exerrval);
	return(EX_FATAL);
      }
  }

  return iexit;
}
NcValues* NcVar::get_rec(NcDim* rdim, long slice)
{
    int idx = dim_to_index(rdim);
    long size = num_dims();
    size_t* start = new size_t[size];
    long* startl = new long[size];
    for (int i=1; i < size ; i++) {
	start[i] = 0;
	startl[i] = 0;
    }
    start[idx] = slice;
    startl[idx] = slice;
    NcBool result = set_cur(startl);
    if (! result ) {
	delete [] start;
	delete [] startl;
	return 0;
    }

    long* edgel = edges();
    size_t* edge = new size_t[size];
    for (int i=1; i < size ; i++) {
	edge[i] = edgel[i];
    }
    edge[idx] = 1;
    edgel[idx] = 1;
    NcValues* valp = get_space(rec_size(rdim));
    int status;
    switch (type()) {
    case ncFloat:
	status = NcError::set_err(
				  nc_get_vara_float(the_file->id(), the_id, start, edge, 
				   (float *)valp->base())
				  );
	break;
    case ncDouble:
	status = NcError::set_err(
				  nc_get_vara_double(the_file->id(), the_id, start, edge, 
				    (double *)valp->base())
				  );
	break;
    case ncInt64:
	status = NcError::set_err(
				  nc_get_vara_longlong(the_file->id(), the_id, start, edge, 
				 (long long *)valp->base())
				  );
	break;
    case ncUInt64:
	status = NcError::set_err(
				  nc_get_vara_ulonglong(the_file->id(), the_id, start, edge, 
				 (unsigned long long *)valp->base())
				  );
	break;
    case ncInt:
	status = NcError::set_err(
				  nc_get_vara_int(the_file->id(), the_id, start, edge, 
				 (int *)valp->base())
				  );
	break;
    case ncShort:
	status = NcError::set_err(
				  nc_get_vara_short(the_file->id(), the_id, start, edge, 
				   (short *)valp->base())
				  );
	break;
    case ncByte:
	status = NcError::set_err(
				  nc_get_vara_schar(the_file->id(), the_id, start, edge, 
				   (signed char *)valp->base())
				  );
	break;
    case ncChar:
	status = NcError::set_err(
				  nc_get_vara_text(the_file->id(), the_id, start, edge, 
				   (char *)valp->base())
				  );
	break;
    case ncNoType:
    default:
	return 0;
    }
    delete [] start;
    delete [] startl;
    delete [] edge;
    delete [] edgel;
    if (status != NC_NOERR) {
	delete valp;
	return 0;
    }
    return valp;
} 
int ex_get_partial_node_num_map (int  exoid,
                           int64_t  start_ent,
                           int64_t  num_ents,
                           void_int *node_map)
{
  int     numnodedim, mapid, status;
  size_t  i;
  size_t  num_nodes,  start[1], count[1];
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  /* inquire id's of previously defined dimensions and variables  */

  if ((status = nc_inq_dimid (exoid, DIM_NUM_NODES, &numnodedim)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to locate number of nodes in file id %d",
            exoid);
    ex_err("ex_get_partial_node_num_map",errmsg,exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_inq_dimlen(exoid, numnodedim, &num_nodes)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get number of nodes in file id %d",
            exoid);
    ex_err("ex_get_partial_node_num_map",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* Check input parameters for a valid range of numbers */
  if (start_ent < 0 || start_ent > num_nodes) {
    fprintf(stderr, "ERROR: Invalid input to function"
                    "  ex_get_partial_node_num_map!\n");
    return (EX_FATAL);
  }

  if (num_ents < 0) {
    fprintf(stderr, "ERROR: Invalid number of entries in map!\n");
    return (EX_FATAL);
  }

  /* start_ent now starts at 1, not 0 */
  if ((start_ent + num_ents - 1) > num_nodes) {
    fprintf(stderr, "ERROR: request range invalid!\n");
    return (EX_FATAL);
  }

  if ((status = nc_inq_varid (exoid, VAR_NODE_NUM_MAP, &mapid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
  "Warning: node numbering map not stored in file id %d; returning default map",
            exoid);
    ex_err("ex_get_partial_node_num_map",errmsg,exerrval);

    /* generate default map of 1..n, where n is num_nodes */
    if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
      int64_t *lmap = (int64_t*)node_map;
      for (i=0; i<num_ents; i++) {
	lmap[i] = start_ent+i;
      }
    } else {
      int *lmap = (int*)node_map;
      for (i=0; i<num_ents; i++) {
	lmap[i] = start_ent+i;
      }
    }
    return (EX_WARN);
  }

  /* read in the node numbering map  */
  start[0] = --start_ent;
  count[0] = num_ents;

  if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
    status = nc_get_vara_longlong(exoid, mapid, start, count, node_map);
  } else {
    status = nc_get_vara_int(exoid, mapid, start, count, node_map);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get node numbering map in file id %d",
            exoid);
    ex_err("ex_get_partial_node_num_map",errmsg,exerrval);
    return (EX_FATAL);
  }
  return(EX_NOERR);
}
Esempio n. 8
0
int ex_get_idx(int exoid, const char *ne_var_name, int64_t *my_index, int pos)
{
  const char  *func_name="ex_get_idx";

  int      status;
  int      varid;
  size_t   start[1], count[1];
#if defined(NC_NETCDF4)
  long long varidx[2];
#else
  int varidx[2];
#endif
  char   errmsg[MAX_ERR_LENGTH];
/*-----------------------------Execution begins-----------------------------*/

  exerrval = 0; /* clear error code */

  /* set default values for idx */
  my_index[0] = 0;
  my_index[1] = -1;

  /*
   * assume that if there is an error returned, that this
   * means that this is a parallel file, and the index does
   * not exists. This is not an error
   */
  if ((status = nc_inq_varid(exoid, ne_var_name, &varid)) == NC_NOERR) {
    /* check if we are at the beginning of the index vector */
    if (pos == 0) {
      start[0] = pos;
      count[0] = 1;
    } else {
      start[0] = pos - 1;
      count[0] = 2;
    }

#if defined(NC_NETCDF4)
    status = nc_get_vara_longlong(exoid, varid, start, count, varidx);
#else
    status = nc_get_vara_int(exoid, varid, start, count, varidx);
#endif
    if (status != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to find variable \"%s\" in file ID %d",
              ne_var_name, exoid);
      ex_err(func_name, errmsg, exerrval);
      return -1;
    }

    if (pos == 0) {
      my_index[0] = 0;
      my_index[1] = varidx[0];
    } else {
      my_index[0] = varidx[0];
      my_index[1] = varidx[1];
    }
  }

  return 1;
}
int ex_get_partial_num_map (int  exoid,
			    ex_entity_type map_type,
			    ex_entity_id  map_id,
			    int64_t  ent_start,
			    int64_t  ent_count, 
			    void_int *map)
{
  int dimid, var_id, id_ndx, status;
  size_t num_mobj, start[1], count[1]; 
  char errmsg[MAX_ERR_LENGTH];
  const char* dim_map_size;
  const char* dim_num_maps;

  switch (map_type) {
  case EX_NODE_MAP:
    dim_map_size = DIM_NUM_NODES;
    dim_num_maps = DIM_NUM_NM;
    break;
  case EX_EDGE_MAP:
    dim_map_size = DIM_NUM_EDGE;
    dim_num_maps = DIM_NUM_EDM;
    break;
  case EX_FACE_MAP:
    dim_map_size = DIM_NUM_FACE;
    dim_num_maps = DIM_NUM_FAM;
    break;
  case EX_ELEM_MAP:
    dim_map_size = DIM_NUM_ELEM;
    dim_num_maps = DIM_NUM_EM;
    break;
  default:
    exerrval = EX_BADPARAM;
    sprintf( errmsg, "Bad map type (%d) specified", map_type );
    ex_err( "ex_get_partial_num_map", errmsg, exerrval );
    return (EX_FATAL);
  }

  exerrval = 0; /* clear error code */

  /* See if file contains any elements...*/
  if (nc_inq_dimid (exoid, dim_map_size, &dimid) != NC_NOERR) {
    return (EX_NOERR);
  }

  if ((status = nc_inq_dimlen(exoid, dimid, &num_mobj)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get number of mesh objects in file id %d", exoid);
    ex_err("ex_get_partial_num_map",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* Check input parameters for a valid range of numbers */
  if (ent_start <= 0 || ent_start > num_mobj) {
    exerrval = EX_FATAL;
    sprintf(errmsg,
	    "Error: start count is invalid in file id %d",
	    exoid);
    ex_err("ex_get_partial_num_map",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (ent_count < 0) {
    exerrval = EX_FATAL;
    sprintf(errmsg,
	    "Error: Invalid count value in file id %d",
	    exoid);
    ex_err("ex_get_partial_num_map",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (ent_start+ent_count-1 > num_mobj) {
    exerrval = EX_FATAL;
    sprintf(errmsg,
	    "Error: start+count-1 is larger than element count in file id %d",
	    exoid);
    ex_err("ex_get_partial_num_map",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* first check if any maps have been defined */
  if ((status = nc_inq_dimid (exoid, dim_num_maps, &dimid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Warning: no %ss defined in file id %d",
	    ex_name_of_object(map_type), exoid);
    ex_err("ex_get_partial_num_map",errmsg,exerrval);
    return (EX_WARN);
  }

  /* Lookup index of element map id property array */
  id_ndx = ex_id_lkup(exoid,map_type,map_id);
  if (exerrval != 0) {
    sprintf(errmsg,
	    "Error: failed to locate %s id %"PRId64" in id variable in file id %d",
	    ex_name_of_object(map_type),map_id,exoid);
    ex_err("ex_get_partial_num_map",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* inquire id's of previously defined dimensions and variables */
  if ((status = nc_inq_varid(exoid, ex_name_of_map(map_type,id_ndx), &var_id)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to locate %s %"PRId64" in file id %d",
	    ex_name_of_object(map_type),map_id,exoid);
    ex_err("ex_get_partial_num_map",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* read in the map */
  start[0] = ent_start-1;
  count[0] = ent_count;

  if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
    status = nc_get_vara_longlong(exoid, var_id, start, count, map);
  } else {
    status = nc_get_vara_int(exoid, var_id, start, count, map);
  }

  if (status == -1) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get %s in file id %d",
	    ex_name_of_object(map_type),exoid);
    ex_err("ex_get_partial_num_map",errmsg,exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
Esempio n. 10
0
int ex_get_elem_cmap(int exoid, ex_entity_id map_id, void_int *elem_ids, void_int *side_ids,
                     void_int *proc_ids, int processor)
{
  const char *func_name = "ex_get_elem_cmap";

  int     map_idx, dimid, varid[3], status;
  size_t  start[1], count[1];
  int64_t varidx[2];

  char errmsg[MAX_ERR_LENGTH];
  /*-----------------------------Execution begins-----------------------------*/

  exerrval = 0; /* clear error code */

  /* get the cmap information variables index */
  if (ex_get_idx(exoid, VAR_E_COMM_INFO_IDX, varidx, processor) == -1) {
    exerrval = -1;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find index variable, \"%s\", in file ID %d",
             VAR_E_COMM_INFO_IDX, exoid);
    ex_err(func_name, errmsg, exerrval);

    return (EX_FATAL);
  }

  /*
   * no need to check if the second index is -1 that is handled
   * in ne_id_lkup, where the dimension must be looked up anyways
   */

  /* Get the index of the elemental comm map with the given ID */
  if ((map_idx = ne_id_lkup(exoid, VAR_E_COMM_IDS, varidx, map_id)) < 0) {
    exerrval = EX_MSG;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to find elemental comm map with ID %" PRId64 " in file \
ID %d",
             map_id, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  /* get the cmap data variables index for this map */
  if (ex_get_idx(exoid, VAR_E_COMM_DATA_IDX, varidx, map_idx) == -1) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find index variable, \"%s\", in file ID %d",
             VAR_E_COMM_DATA_IDX, exoid);
    ex_err(func_name, errmsg, exerrval);

    return (EX_FATAL);
  }

  if (varidx[1] == -1) {
    /* Get the dimension of this elemental communication map */
    if ((status = nc_inq_dimid(exoid, DIM_ECNT_CMAP, &dimid)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_ECNT_CMAP, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to find length of dimension \"%s\" in file ID %d", DIM_ECNT_CMAP,
               exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    varidx[1] = count[0];
  }

  /* Get the variable ID for the elemental comm map node IDs */
  if ((status = nc_inq_varid(exoid, VAR_E_COMM_EIDS, &varid[0])) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
             VAR_E_COMM_EIDS, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  /* Get the variable ID for the elemental side set IDs */
  if ((status = nc_inq_varid(exoid, VAR_E_COMM_SIDS, &varid[1])) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
             VAR_E_COMM_SIDS, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  /* Get the variable ID for the elemental comm map processor IDs */
  if ((status = nc_inq_varid(exoid, VAR_E_COMM_PROC, &varid[2])) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
             VAR_E_COMM_PROC, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  /* Get the elemental comm map element IDs */
  start[0] = varidx[0];
  count[0] = varidx[1] - varidx[0];
  if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
    status = nc_get_vara_longlong(exoid, varid[0], start, count, elem_ids);
  }
  else {
    status = nc_get_vara_int(exoid, varid[0], start, count, elem_ids);
  }
  if (status != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d",
             VAR_E_COMM_EIDS, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  /* Get the elemental comm map side IDs */
  if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
    status = nc_get_vara_longlong(exoid, varid[1], start, count, side_ids);
  }
  else {
    status = nc_get_vara_int(exoid, varid[1], start, count, side_ids);
  }
  if (status != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d",
             VAR_E_COMM_SIDS, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  /* Get the elemental comm map processor IDs */
  if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
    status = nc_get_vara_longlong(exoid, varid[2], start, count, proc_ids);
  }
  else {
    status = nc_get_vara_int(exoid, varid[2], start, count, proc_ids);
  }
  if (status != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d",
             VAR_E_COMM_PROC, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
Esempio n. 11
0
int ex_get_partial_id_map ( int   exoid,
			    ex_entity_type map_type,
			    int64_t   start_entity_num,
			    int64_t   num_entities,
			    void_int*  map )
{
  int dimid, mapid, status;
  size_t i;
  size_t num_entries;
  size_t start[1], count[1];
  char errmsg[MAX_ERR_LENGTH];
  const char* dnumentries;
  const char* vmap;
  const char* tname;

  switch (map_type) {
  case EX_NODE_MAP:
    tname = "node";
    dnumentries = DIM_NUM_NODES;
    vmap = VAR_NODE_NUM_MAP;
    break;
  case EX_EDGE_MAP:
    tname = "edge";
    dnumentries = DIM_NUM_EDGE;
    vmap = VAR_EDGE_NUM_MAP;
    break;
  case EX_FACE_MAP:
    tname = "face";
    dnumentries = DIM_NUM_FACE;
    vmap = VAR_FACE_NUM_MAP;
    break;
  case EX_ELEM_MAP:
    tname = "element";
    dnumentries = DIM_NUM_ELEM;
    vmap = VAR_ELEM_NUM_MAP;
    break;
  default:
    exerrval = EX_BADPARAM;
    sprintf( errmsg,
	     "Error: Bad map type (%d) specified for file id %d",
	     map_type, exoid );
    ex_err( "ex_get_partial_id_map", errmsg, exerrval );
    return (EX_FATAL);
  }
  exerrval = 0; /* clear error code */

  /* See if any entries are stored in this file */
  if (nc_inq_dimid(exoid, dnumentries,&dimid) != NC_NOERR) {
    return (EX_NOERR);
  }

  if (nc_inq_varid (exoid, vmap, &mapid) != NC_NOERR) {
    if ((status = nc_inq_dimlen(exoid, dimid, &num_entries)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to get number of %ss in file id %d", tname, exoid);
      ex_err("ex_get_partial_id_map",errmsg,exerrval);
      return (EX_FATAL);
    }
    
    /* generate default map of 1..n, where n is num_entries */
    if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
      int64_t *lmap = (int64_t*)map;
      for (i=0; i < num_entities; i++) {
	lmap[i] = start_entity_num+i;
      }
    } else {
      int *lmap = (int*)map;
      for (i=0; i<num_entities; i++) {
	lmap[i] = start_entity_num+i;
      }
    }

    return (EX_NOERR);
  }

  start[0] = start_entity_num-1;
  count[0] = num_entities;

  /* read in the id map  */
  if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
    status = nc_get_vara_longlong(exoid, mapid, start, count, map);
  } else {
    status = nc_get_vara_int(exoid, mapid, start, count, map);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to get %s id map in file id %d",
	    tname, exoid);
    ex_err("ex_get_partial_id_map",errmsg,exerrval);
    return (EX_FATAL);
  }

  return(EX_NOERR);
}