int ex_get_all_times(int exoid, void *time_values)
{
  int  varid;
  int  status;
  char errmsg[MAX_ERR_LENGTH];

  EX_FUNC_ENTER();
  ex_check_valid_file_id(exoid, __func__);

  if ((status = nc_inq_varid(exoid, VAR_WHOLE_TIME, &varid)) != NC_NOERR) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate time variable %s in file id %d",
             VAR_WHOLE_TIME, exoid);
    ex_err(__func__, errmsg, status);
    EX_FUNC_LEAVE(EX_FATAL);
  }

  /*read time values */
  if (ex_comp_ws(exoid) == 4) {
    status = nc_get_var_float(exoid, varid, time_values);
  }
  else {
    status = nc_get_var_double(exoid, varid, time_values);
  }

  if (status != NC_NOERR) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get time values from file id %d", exoid);
    ex_err(__func__, errmsg, status);
    EX_FUNC_LEAVE(EX_FATAL);
  }

  EX_FUNC_LEAVE(EX_NOERR);
}
Ejemplo n.º 2
0
int ex_put_varid_var(int   exoid,
                     int   time_step,
                     int   varid,
                     int   num_entity,
                     const void *var_vals)
{
  size_t start[2], count[2];
  int status;
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  start[0] = --time_step;
  start[1] = 0;
  
  count[0] = 1;
  count[1] = num_entity;

  if (ex_comp_ws(exoid) == 4) {
    status = nc_put_vara_float(exoid, varid, start, count, var_vals);
  } else {
    status = nc_put_vara_double(exoid, varid, start, count, var_vals);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to store variables with varid %d in file id %d",
            varid, exoid);
    ex_err("ex_put_varid_var",errmsg,exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
int ex_get_all_times (int   exoid,
                      void *time_values)
{
   int varid;
   int status;
   char errmsg[MAX_ERR_LENGTH];

  exerrval = 0;

  if ((status = nc_inq_varid(exoid, VAR_WHOLE_TIME, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,"Error: failed to locate time variable %s in file id %d",
            VAR_WHOLE_TIME, exoid);
    ex_err("ex_get_all_times",errmsg,exerrval);
    return(EX_FATAL);
  }

  /*read time values */
  if (ex_comp_ws(exoid) == 4) {
    status = nc_get_var_float(exoid, varid, time_values);
  } else {
    status = nc_get_var_double(exoid, varid, time_values);
  }
    
  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
           "Error: failed to get time values from file id %d",
            exoid);
    ex_err("ex_get_all_times",errmsg,exerrval);
    return(EX_FATAL);
  }

  return (EX_NOERR);
}
int ex_get_glob_vars (int   exoid,
                      int   time_step,
                      int   num_glob_vars,
                      void *glob_var_vals)
{
   int varid;
   int status;
   size_t start[2], count[2];
   char errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

   /* inquire previously defined variable */
   if ((status = nc_inq_varid (exoid, VAR_GLO_VAR, &varid)) != NC_NOERR) {
     exerrval = status;
     sprintf(errmsg,
            "Warning: failed to locate global variables in file id %d",
            exoid);
     ex_err("ex_get_glob_vars",errmsg,exerrval);
     return (EX_WARN);
   }

   /* Verify that time_step is within bounds */
   {
    int num_time_steps = ex_inquire_int (exoid, EX_INQ_TIME);
    if (time_step <= 0 || time_step > num_time_steps) {
      sprintf(errmsg,
              "ERROR: time_step is out-of-range. Value = %d, valid range is 1 to %d in file id %d",
              time_step, num_time_steps, exoid);
      ex_err("ex_get_nodal_var",errmsg,EX_BADPARAM);
      return (EX_FATAL);
    }
  }

   /* read values of global variables */
   start[0] = --time_step;
   start[1] = 0;

   count[0] = 1;
   count[1] = num_glob_vars;

   if (ex_comp_ws(exoid) == 4) {
     status = nc_get_vara_float(exoid, varid, start, count, glob_var_vals);
   } else {
     status = nc_get_vara_double(exoid, varid, start, count, glob_var_vals);
   }

   if (status != NC_NOERR) {
     exerrval = status;
     sprintf(errmsg,
            "Error: failed to get global variable values from file id %d",
            exoid);
     ex_err("ex_get_glob_vars",errmsg,exerrval);
     return (EX_FATAL);
   }
   return (EX_NOERR);
}
Ejemplo n.º 5
0
int ex_get_glob_var_time (int   exoid,
                          int   glob_var_index,
                          int   beg_time_step,
                          int   end_time_step,
                          void *glob_var_vals)
{
  int status;
   int varid;
   size_t start[2], count[2];
   char  errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

   if (end_time_step < 0) {
     /* user is requesting the maximum time step;  we find this out using the
      * database inquire function to get the number of time steps
      */
     end_time_step = ex_inquire_int(exoid, EX_INQ_TIME);
   }

   end_time_step--;

   /* read values of global variables */
   start[0] = --beg_time_step;
   start[1] = --glob_var_index;

   count[0] = end_time_step - beg_time_step + 1;
   count[1] = 1;

   /* inquire previously defined variable */
   if ((status = nc_inq_varid (exoid, VAR_GLO_VAR, &varid)) != NC_NOERR) {
     exerrval = status;
     sprintf(errmsg,
            "Error: failed to locate global variables in file id %d",
             exoid);
     ex_err("ex_get_glob_var_time",errmsg,exerrval);
     return (EX_WARN);
   }

   if (ex_comp_ws(exoid) == 4) {
     status = nc_get_vara_float(exoid, varid, start, count, glob_var_vals);
   } else {
     status = nc_get_vara_double(exoid, varid, start, count, glob_var_vals);
   }

   if (status != NC_NOERR) {
     exerrval = status;
     sprintf(errmsg,
            "Error: failed to get global variable %d values from file id %d",
            glob_var_index, exoid);
     ex_err("ex_get_glob_var_time",errmsg,exerrval);
     return (EX_FATAL);
   }
   return (EX_NOERR);
}
Ejemplo n.º 6
0
int ex_get_glob_vars_int(int exoid, int time_step, int num_glob_vars, void *glob_var_vals)
{
  int    varid;
  int    status;
  size_t start[2], count[2];
  char   errmsg[MAX_ERR_LENGTH];

  EX_FUNC_ENTER();
  ex_check_valid_file_id(exoid, __func__);

  /* inquire previously defined variable */
  if ((status = nc_inq_varid(exoid, VAR_GLO_VAR, &varid)) != NC_NOERR) {
    snprintf(errmsg, MAX_ERR_LENGTH, "Warning: failed to locate global variables in file id %d",
             exoid);
    ex_err(__func__, errmsg, status);
    EX_FUNC_LEAVE(EX_WARN);
  }

  /* Verify that time_step is within bounds */
  {
    int num_time_steps = ex_inquire_int(exoid, EX_INQ_TIME);
    if (time_step <= 0 || time_step > num_time_steps) {
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: time_step is out-of-range. Value = %d, valid "
               "range is 1 to %d in file id %d",
               time_step, num_time_steps, exoid);
      ex_err(__func__, errmsg, EX_BADPARAM);
      EX_FUNC_LEAVE(EX_FATAL);
    }
  }

  /* read values of global variables */
  start[0] = --time_step;
  start[1] = 0;

  count[0] = 1;
  count[1] = num_glob_vars;

  if (ex_comp_ws(exoid) == 4) {
    status = nc_get_vara_float(exoid, varid, start, count, glob_var_vals);
  }
  else {
    status = nc_get_vara_double(exoid, varid, start, count, glob_var_vals);
  }

  if (status != NC_NOERR) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get global variable values from file id %d",
             exoid);
    ex_err(__func__, errmsg, status);
    EX_FUNC_LEAVE(EX_FATAL);
  }
  EX_FUNC_LEAVE(EX_NOERR);
}
Ejemplo n.º 7
0
int ex_get_nodal_varid_var(int   exoid,
                           int   time_step,
                           int   nodal_var_index,
                           int   num_nodes, 
                           int   varid,
                           void *nodal_var_vals)
{
  int status;
  size_t start[3], count[3];
  char errmsg[MAX_ERR_LENGTH];
  
  exerrval = 0; /* clear error code */

  /* inquire previously defined variable */

  if (ex_large_model(exoid) == 0) {
    start[0] = --time_step;
    start[1] = --nodal_var_index;
    start[2] = 0;

    count[0] = 1;
    count[1] = 1;
    count[2] = num_nodes;
  } else {

    start[0] = --time_step;
    start[1] = 0;

    count[0] = 1;
    count[1] = num_nodes;
  }

  if (ex_comp_ws(exoid) == 4) {
    status = nc_get_vara_float(exoid, varid, start, count, nodal_var_vals);
  } else {
    status = nc_get_vara_double(exoid, varid, start, count, nodal_var_vals);
  }

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

  return (EX_NOERR);
}
Ejemplo n.º 8
0
Archivo: exggv.c Proyecto: RCBiczok/VTK
int ex_get_glob_vars (int   exoid,
                      int   time_step,
                      int   num_glob_vars,
                      void *glob_var_vals)
{
    int varid;
    int status;
    size_t start[2], count[2];
    char errmsg[MAX_ERR_LENGTH];

    exerrval = 0; /* clear error code */

    /* inquire previously defined variable */
    if ((status = nc_inq_varid (exoid, VAR_GLO_VAR, &varid)) != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
                "Warning: failed to locate global variables in file id %d",
                exoid);
        ex_err("ex_get_glob_vars",errmsg,exerrval);
        return (EX_WARN);
    }

    /* read values of global variables */
    start[0] = --time_step;
    start[1] = 0;

    count[0] = 1;
    count[1] = num_glob_vars;

    if (ex_comp_ws(exoid) == 4) {
        status = nc_get_vara_float(exoid, varid, start, count, glob_var_vals);
    } else {
        status = nc_get_vara_double(exoid, varid, start, count, glob_var_vals);
    }

    if (status != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to get global variable values from file id %d",
                exoid);
        ex_err("ex_get_glob_vars",errmsg,exerrval);
        return (EX_FATAL);
    }
    return (EX_NOERR);
}
Ejemplo n.º 9
0
int ex_put_time (int   exoid,
                 int   time_step,
                 const void *time_value)
{
  int status;
  int varid; 
  size_t start[1];
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  /* inquire previously defined variable */
  if ((status = nc_inq_varid(exoid, VAR_WHOLE_TIME, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to locate time variable in file id %d", exoid);
    ex_err("ex_put_time",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* store time value */
  start[0] = --time_step;

  if (ex_comp_ws(exoid) == 4) {
    status = nc_put_var1_float(exoid, varid, start, time_value);
  } else {
    status = nc_put_var1_double(exoid, varid, start, time_value);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to store time value in file id %d", exoid);
    ex_err("ex_put_time",errmsg,exerrval);
    return (EX_FATAL);
  }


  return (EX_NOERR);
}
Ejemplo n.º 10
0
int ex_get_nodal_var (int   exoid,
                      int   time_step,
                      int   nodal_var_index,
                      int   num_nodes, 
                      void *nodal_var_vals)
{
  int varid;
  int status;
  size_t start[3], count[3];
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  /* inquire previously defined variable */

  if (ex_large_model(exoid) == 0) {
    /* read values of the nodal variable */
    if ((status = nc_inq_varid(exoid, VAR_NOD_VAR, &varid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Warning: could not find nodal variables in file id %d",
              exoid);
      ex_err("ex_get_nodal_var",errmsg,exerrval);
      return (EX_WARN);
    }

    start[0] = --time_step;
    start[1] = --nodal_var_index;
    start[2] = 0;

    count[0] = 1;
    count[1] = 1;
    count[2] = num_nodes;

  } else {
    /* read values of the nodal variable  -- stored as separate variables... */
    /* Get the varid.... */
    if ((status = nc_inq_varid(exoid, VAR_NOD_VAR_NEW(nodal_var_index), &varid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Warning: could not find nodal variable %d in file id %d",
              nodal_var_index, exoid);
      ex_err("ex_get_nodal_var",errmsg,exerrval);
      return (EX_WARN);
    }

    start[0] = --time_step;
    start[1] = 0;

    count[0] = 1;
    count[1] = num_nodes;
  }

  if (ex_comp_ws(exoid) == 4) {
    status = nc_get_vara_float(exoid, varid, start, count, nodal_var_vals);
  } else {
    status = nc_get_vara_double(exoid, varid, start, count, nodal_var_vals);
  }

  if (status != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to get nodal variables in file id %d",
              exoid);
      ex_err("ex_get_nodal_var",errmsg,exerrval);
      return (EX_FATAL);
    }
  return (EX_NOERR);
}
Ejemplo n.º 11
0
int ex_put_partial_side_set_df(int exoid, ex_entity_id side_set_id, int64_t start_num,
                               int64_t num_df_to_get, void *side_set_dist_fact)
{
  int    status;
  int    dimid, side_set_id_ndx;
  int    dist_id;
  size_t num_df_in_set, start[1], count[1];
  char   errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

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

  if ((status = nc_inq_dimid(exoid, DIM_NUM_SS, &dimid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: no side sets specified in file id %d", exoid);
    ex_err("ex_put_partial_side_set_df", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* Lookup index of side set id in VAR_SS_IDS array */

  if ((side_set_id_ndx = ex_id_lkup(exoid, EX_SIDE_SET, side_set_id)) < 0) {
    if (exerrval == EX_NULLENTITY) {
      snprintf(errmsg, MAX_ERR_LENGTH,
               "Warning: no data allowed for NULL side set %" PRId64 " in file id %d", side_set_id,
               exoid);
      ex_err("ex_put_side_set_fact", errmsg, EX_NULLENTITY);
      return (EX_WARN);
    }
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to locate side set id %" PRId64 " in VAR_SS_IDS array in file id %d",
             side_set_id, exoid);
    ex_err("ex_put_partial_side_set_df", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* inquire id's of previously defined dimension and variable */

  if ((status = nc_inq_dimid(exoid, DIM_NUM_DF_SS(side_set_id_ndx), &dimid)) != NC_NOERR) {
    if (status == NC_EBADDIM) {
      exerrval = EX_BADPARAM;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "Warning: no dist factors defined for side set %" PRId64 " in file id %d",
               side_set_id, exoid);
      ex_err("ex_put_partial_side_set_df", errmsg, exerrval);
      return (EX_WARN);
    }
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to locate number of dist factors in side set %" PRId64 " in file id %d",
             side_set_id, exoid);
    ex_err("ex_put_partial_side_set_df", errmsg, exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_inq_dimlen(exoid, dimid, &num_df_in_set)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to get number of dist factors in side set %" PRId64 " in file id %d",
             side_set_id, exoid);
    ex_err("ex_put_partial_side_set_df", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* Check input parameters for a valid range of numbers */
  if (start_num < 0 || (num_df_to_get > 0 && start_num > num_df_in_set)) {
    exerrval = EX_BADPARAM;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Invalid input");
    ex_err("ex_put_partial_side_set_df", errmsg, exerrval);
    return (EX_FATAL);
  }

  if (num_df_to_get < 0) {
    exerrval = EX_BADPARAM;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Invalid number of df's to put!");
    ex_err("ex_put_partial_side_set_df", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* start_num now starts at 1, not 0 */
  if ((start_num + num_df_to_get) > num_df_in_set + 1) {
    exerrval = EX_BADPARAM;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: request larger than number of df's in set!");
    ex_err("ex_put_partial_side_set_df", errmsg, exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_inq_varid(exoid, VAR_FACT_SS(side_set_id_ndx), &dist_id)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to locate dist factors list for side set %" PRId64 " in file id %d",
             side_set_id, exoid);
    ex_err("ex_put_partial_side_set_df", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* write out the distribution factors array */
  start[0] = --start_num;
  count[0] = num_df_to_get;
  if (num_df_to_get == 0) {
    start[0] = 0;
  }

  if (ex_comp_ws(exoid) == 4) {
    status = nc_put_vara_float(exoid, dist_id, start, count, side_set_dist_fact);
  }
  else {
    status = nc_put_vara_double(exoid, dist_id, start, count, side_set_dist_fact);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to store dist factors for side set %" PRId64 " in file id %d",
             side_set_id, exoid);
    ex_err("ex_put_partial_side_set_df", errmsg, exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
int ex_put_elem_var_slab (int   exoid,
		          int   time_step,
		          int   elem_var_index,
		          ex_entity_id   elem_blk_id,
                          int64_t   start_pos,
		          int64_t   num_vals,
		          void *elem_var_vals)
{
  int status;
  int varid, dimid,time_dim, numelbdim, dims[2], elem_blk_id_ndx;
  size_t num_elem_blk, num_elem_var, start[2], count[2];
  int *elem_var_tab;
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  /* Determine index of elem_blk_id in VAR_ID_EL_BLK array */
  if ((elem_blk_id_ndx = ex_id_lkup(exoid, EX_ELEM_BLOCK, elem_blk_id)) < 0) {
    if (exerrval == EX_NULLENTITY) {
      sprintf(errmsg,
	      "Warning: no variables allowed for NULL block %"PRId64" in file id %d",
	      elem_blk_id, exoid);
      ex_err("ex_put_elem_var_slab", errmsg, EX_NULLENTITY);
      return (EX_WARN);
    } 
      sprintf(errmsg,
	      "Error: failed to locate element block id %"PRId64" in %s array in file id %d",
	      elem_blk_id, VAR_ID_EL_BLK, exoid);
      ex_err("ex_put_elem_var_slab", errmsg, exerrval);
      return (EX_FATAL);
    
  }

  if ((status = nc_inq_varid (exoid,
			      VAR_ELEM_VAR(elem_var_index, elem_blk_id_ndx), &varid)) != NC_NOERR) {
    if (status == NC_ENOTVAR) { /* variable doesn't exist, create it! */

      /*    inquire previously defined dimensions */

      /* check for the existance of an element variable truth table */
      if ((status = nc_inq_varid (exoid, VAR_ELEM_TAB, &varid)) == NC_NOERR) {
	/* find out number of element blocks and element variables */
	if ((status = nc_inq_dimid (exoid, DIM_NUM_EL_BLK, &dimid)) != NC_NOERR) {
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: failed to locate number of element blocks in file id %d",
		  exoid);
	  ex_err("ex_put_elem_var_slab", errmsg, exerrval);
	  return (EX_FATAL);
	}

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

	if ((status = nc_inq_dimid (exoid, DIM_NUM_ELE_VAR, &dimid)) != NC_NOERR) {
	  exerrval = EX_BADPARAM;
	  sprintf(errmsg,
		  "Error: no element variables stored in file id %d",
		  exoid);
	  ex_err("ex_put_elem_var_slab", errmsg, exerrval);
	  return (EX_FATAL);
	}

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

	if (!(elem_var_tab =
	      (int *)malloc(num_elem_blk*num_elem_var*sizeof(int)))) {
	  exerrval = EX_MEMFAIL;
	  sprintf(errmsg,
		  "Error: failed to allocate memory for element variable truth table in file id %d",
		  exoid);
	  ex_err("ex_put_elem_var_slab", errmsg, exerrval);
	  return (EX_FATAL);
	}

	/*   read in the element variable truth table */
	if ((status = nc_get_var_int(exoid, varid, elem_var_tab)) != NC_NOERR) {
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: failed to get truth table from file id %d", exoid);
	  ex_err("ex_put_elem_var_slab", errmsg, exerrval);
	  return (EX_FATAL);
	}

	if (elem_var_tab[num_elem_var*(elem_blk_id_ndx-1)+elem_var_index-1] == 0L) {
	  free(elem_var_tab);
	  exerrval = EX_BADPARAM;
	  sprintf(errmsg,
		  "Error: Invalid element variable %d, block %"PRId64" in file id %d",
		  elem_var_index, elem_blk_id, exoid);
	  ex_err("ex_put_elem_var_slab", errmsg, exerrval);
	  return (EX_FATAL);
	}
	free(elem_var_tab);
      }

      if ((status = nc_inq_dimid (exoid, DIM_TIME, &time_dim)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to locate time dimension in file id %d", exoid);
	ex_err("ex_put_elem_var_slab", errmsg, exerrval);
	goto error_ret;		/* exit define mode and return */
      }

      if ((status = nc_inq_dimid(exoid, DIM_NUM_EL_IN_BLK(elem_blk_id_ndx), &numelbdim)) != NC_NOERR) {
	if (status == NC_EBADDIM) {
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: number of elements in element block %"PRId64" not defined in file id %d",
		  elem_blk_id, exoid);
	  ex_err("ex_put_elem_var_slab", errmsg, exerrval);
	} else {
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: failed to locate number of elements in element block %"PRId64" in file id %d",
		  elem_blk_id, exoid);
	  ex_err("ex_put_elem_var_slab", errmsg, exerrval);
	}
	goto error_ret;
      }

      /*    variable doesn't exist so put file into define mode  */
      if ((status = nc_redef (exoid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to put file id %d into define mode", exoid);
	ex_err("ex_put_elem_var_slab", errmsg, exerrval);
	return (EX_FATAL);
      }


      /*    define netCDF variable to store element variable values */
      dims[0] = time_dim;
      dims[1] = numelbdim;
      if ((status = nc_def_var(exoid, VAR_ELEM_VAR(elem_var_index, elem_blk_id_ndx),
			       nc_flt_code(exoid), 2, dims, &varid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define element variable %d in file id %d",
		elem_var_index, exoid);
	ex_err("ex_put_elem_var_slab", errmsg, exerrval);
	goto error_ret;
      }
      ex_compress_variable(exoid, varid, 2);


      /*    leave define mode  */
      if ((status = nc_enddef(exoid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to complete element variable %s definition to file id %d",
		VAR_ELEM_VAR(elem_var_index, elem_blk_id_ndx), exoid);
	ex_err("ex_put_elem_var_slab", errmsg, exerrval);
	return (EX_FATAL);
      }
    } else {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate element variable %s in file id %d",
	      VAR_ELEM_VAR(elem_var_index, elem_blk_id_ndx),exoid);
      ex_err("ex_put_elem_var_slab", errmsg, exerrval);
      return (EX_FATAL);
    }
  }

  /* store element variable values */
  start[0] = --time_step;
  start[1] = --start_pos;

  count[0] = 1;
  count[1] = num_vals;

  if (ex_comp_ws(exoid) == 4) {
    status = nc_put_vara_float(exoid, varid, start, count, elem_var_vals);
  } else {
    status = nc_put_vara_double(exoid, varid, start, count, elem_var_vals);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to store element variable %d in file id %d", 
	    elem_var_index, exoid);
    ex_err("ex_put_elem_var_slab", errmsg, exerrval);
    return (EX_FATAL);
  }

  return (EX_NOERR);

  /* Fatal error: exit definition mode and return */
 error_ret:
  if (nc_enddef (exoid) != NC_NOERR)     /* exit define mode */
    {
      sprintf(errmsg,
	      "Error: failed to complete definition for file id %d", exoid);
      ex_err("ex_put_elem_var_slab", errmsg, exerrval);
    }
  return (EX_FATAL);
}
Ejemplo n.º 13
0
int ex_put_attr (int   exoid,
		 ex_entity_type blk_type,
		 int   blk_id,
		 const void *attrib)
{
  int status;
  int attrid, blk_id_ndx = 0;
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  if ( blk_type != EX_NODAL ) {
    /* Determine index of blk_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 attributes allowed for NULL %s %d in file id %d",
                ex_name_of_object(blk_type),blk_id,exoid);
        ex_err("ex_put_attr",errmsg,EX_MSG);
        return (EX_WARN);              /* no attributes for this block */
      } else {
        sprintf(errmsg,
		"Error: no %s id %d in in file id %d",
                ex_name_of_object(blk_type), blk_id, exoid);
        ex_err("ex_put_attr",errmsg,exerrval);
        return (EX_FATAL);
      }
    }
  }

  switch (blk_type) {
  case EX_SIDE_SET:
    status = nc_inq_varid (exoid, VAR_SSATTRIB(blk_id_ndx), &attrid);
    break;
  case EX_NODE_SET:
    status = nc_inq_varid (exoid, VAR_NSATTRIB(blk_id_ndx), &attrid);
    break;
  case EX_EDGE_SET:
    status = nc_inq_varid (exoid, VAR_ESATTRIB(blk_id_ndx), &attrid);
    break;
  case EX_FACE_SET:
    status = nc_inq_varid (exoid, VAR_FSATTRIB(blk_id_ndx), &attrid);
    break;
  case EX_ELEM_SET:
    status = nc_inq_varid (exoid, VAR_ELSATTRIB(blk_id_ndx), &attrid);
    break;
  case EX_NODAL:
    status = nc_inq_varid (exoid, VAR_NATTRIB, &attrid);
    break;
  case EX_EDGE_BLOCK:
    status = nc_inq_varid (exoid, VAR_EATTRIB(blk_id_ndx), &attrid);
    break;
  case EX_FACE_BLOCK:
    status = nc_inq_varid (exoid, VAR_FATTRIB(blk_id_ndx), &attrid);
    break;
  case EX_ELEM_BLOCK:
    status = nc_inq_varid (exoid, VAR_ATTRIB(blk_id_ndx), &attrid);
    break;
  default:
    sprintf(errmsg,
      "Error: Called with invalid blk_type %d", blk_type );
    ex_err("ex_put_attr",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to locate attribute variable for %s %d in file id %d",
            ex_name_of_object(blk_type),blk_id,exoid);
    ex_err("ex_put_attr",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* write out the attributes  */
  if (ex_comp_ws(exoid) == 4) {
    status = nc_put_var_float(exoid, attrid, attrib);
  } else {
    status = nc_put_var_double(exoid, attrid, attrib);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to put attributes for %s %d in file id %d",
            ex_name_of_object(blk_type),blk_id,exoid);
    ex_err("ex_put_attr",errmsg,exerrval);
    return (EX_FATAL);
  }
  return(EX_NOERR);
}
Ejemplo n.º 14
0
int ex_get_partial_node_set_df  (int   exoid,
                           ex_entity_id node_set_id,
                           int64_t   start_num,
                           int64_t   num_df_to_get,
                           void *node_set_dist_fact)
{
  int status;
  int dimid, dist_id, node_set_id_ndx;
  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_df",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_df",errmsg,EX_MSG);
      return (EX_WARN);
    } else {

      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_df",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_df",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 node set %"PRId64" in file id %d",
            node_set_id, exoid);
    ex_err("ex_get_partial_node_set_df",errmsg,exerrval);
    return (EX_FATAL);
  }

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

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

  /* start_num now starts at 1, not 0 */
  if ((start_num + num_df_to_get - 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_df",errmsg,exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_inq_varid (exoid, VAR_FACT_NS(node_set_id_ndx), &dist_id)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Warning: dist factors not stored for node set %"PRId64" in file id %d",
            node_set_id,exoid);
    ex_err("ex_get_partial_node_set_df",errmsg,exerrval);
    return (EX_WARN);          /* complain - but not too loud */
  }


  /* read in the distribution factors array */
  start[0] = --start_num;
  count[0] = num_df_to_get;

  if (ex_comp_ws(exoid) == 4) {
    status = nc_get_vara_float(exoid, dist_id, start, count, node_set_dist_fact);
  } else {
    status = nc_get_vara_double(exoid, dist_id, start, count, node_set_dist_fact);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get distribution factors in file id %d",
            exoid);
    ex_err("ex_get_partial_node_set_df",errmsg,exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
Ejemplo n.º 15
0
int ex_get_attr( int   exoid,
                 ex_entity_type obj_type,
                 ex_entity_id   obj_id,
                 void* attrib )

{
  int status;
  int attrid, obj_id_ndx;
  char errmsg[MAX_ERR_LENGTH];
  const char* vattrbname;

  exerrval = 0; /* clear error code */

  /* Determine index of obj_id in vobjids array */
  if (obj_type == EX_NODAL) {
    obj_id_ndx = 0;
  } else {
    obj_id_ndx = ex_id_lkup(exoid,obj_type,obj_id);
    
    if (exerrval != 0) {
      if (exerrval == EX_NULLENTITY) {
	sprintf(errmsg,
		"Warning: no attributes found for NULL %s %"PRId64" in file id %d",
		ex_name_of_object(obj_type),obj_id,exoid);
	ex_err("ex_get_attr",errmsg,EX_NULLENTITY);
	return (EX_WARN);              /* no attributes for this object */
      } 
	sprintf(errmsg,
		"Warning: failed to locate %s id %"PRId64" in id array in file id %d",
		ex_name_of_object(obj_type),obj_id, exoid);
	ex_err("ex_get_attr",errmsg,exerrval);
	return (EX_WARN);
      
    }
  }

  switch (obj_type) {
  case EX_SIDE_SET:
    vattrbname = VAR_SSATTRIB(obj_id_ndx);
    break;
  case EX_NODE_SET:
    vattrbname = VAR_NSATTRIB(obj_id_ndx);
    break;
  case EX_EDGE_SET:
    vattrbname = VAR_ESATTRIB(obj_id_ndx);
    break;
  case EX_FACE_SET:
    vattrbname = VAR_FSATTRIB(obj_id_ndx);
    break;
  case EX_ELEM_SET:
    vattrbname = VAR_ELSATTRIB(obj_id_ndx);
    break;
  case EX_NODAL:
    vattrbname = VAR_NATTRIB;
    break;
  case EX_EDGE_BLOCK:
    vattrbname = VAR_EATTRIB(obj_id_ndx);
    break;
  case EX_FACE_BLOCK:
    vattrbname = VAR_FATTRIB(obj_id_ndx);
    break;
  case EX_ELEM_BLOCK:
    vattrbname = VAR_ATTRIB(obj_id_ndx);
    break;
  default:
    exerrval = 1005;
    sprintf(errmsg,
	    "Internal Error: unrecognized object type in switch: %d in file id %d",
	    obj_type,exoid);
    ex_err("ex_get_attr",errmsg,EX_MSG);
    return (EX_FATAL);              /* number of attributes not defined */
  }

  /* inquire id's of previously defined dimensions  */
  if ((status = nc_inq_varid(exoid, vattrbname, &attrid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to locate attributes for %s %"PRId64" in file id %d",
            ex_name_of_object(obj_type), obj_id,exoid);
    ex_err("ex_get_attr",errmsg,exerrval);
    return (EX_FATAL);
  }


  /* read in the attributes */
  if (ex_comp_ws(exoid) == 4) {
    status = nc_get_var_float(exoid, attrid, attrib);
  } else {
    status = nc_get_var_double(exoid, attrid, attrib);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get attributes for %s %"PRId64" in file id %d",
            ex_name_of_object(obj_type),obj_id,exoid);
    ex_err("ex_get_attr",errmsg,exerrval);
    return (EX_FATAL);
  }
  return(EX_NOERR);
}
Ejemplo n.º 16
0
int ex_get_var(int exoid, int time_step, ex_entity_type var_type, int var_index,
               ex_entity_id obj_id, int64_t num_entry_this_obj, void *var_vals)
{
  int    status;
  int    varid, obj_id_ndx;
  size_t start[2], count[2];
  char   errmsg[MAX_ERR_LENGTH];

  ex_check_valid_file_id(exoid);

  if (var_type == EX_NODAL) {
    /* FIXME: Special case: ignore obj_id, possible large_file complications,
     * etc. */
    return ex_get_nodal_var_int(exoid, time_step, var_index, num_entry_this_obj, var_vals);
  }
  if (var_type == EX_GLOBAL) {
    /* FIXME: Special case: all vars stored in 2-D single array. */
    return ex_get_glob_vars_int(exoid, time_step, num_entry_this_obj, var_vals);
  }

  exerrval = 0; /* clear error code */

  /* Determine index of obj_id in VAR_ID_EL_BLK array */
  obj_id_ndx = ex_id_lkup(exoid, var_type, obj_id);
  if (exerrval != 0) {
    if (exerrval == EX_NULLENTITY) {
      snprintf(errmsg, MAX_ERR_LENGTH,
               "Warning: no %s variables for NULL block %" PRId64 " in file id %d",
               ex_name_of_object(var_type), obj_id, exoid);
      ex_err("ex_get_var", errmsg, EX_NULLENTITY);
      return (EX_WARN);
    }
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to locate %s id %" PRId64 " in id variable in file id %d",
             ex_name_of_object(var_type), obj_id, exoid);
    ex_err("ex_get_var", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* inquire previously defined variable */

  if ((status = nc_inq_varid(exoid, ex_name_var_of_object(var_type, var_index, obj_id_ndx),
                             &varid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate %s %" PRId64 " var %d in file id %d",
             ex_name_of_object(var_type), obj_id, var_index, exoid);
    ex_err("ex_get_var", errmsg, exerrval);
    return (EX_FATAL);
  }

/* Verify that time_step is within bounds */
#ifndef NDEBUG
  {
    int num_time_steps = ex_inquire_int(exoid, EX_INQ_TIME);
    if (time_step <= 0 || time_step > num_time_steps) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: time_step is out-of-range. Value = %d, valid "
                                       "range is 1 to %d in file id %d",
               time_step, num_time_steps, exoid);
      ex_err("ex_get_var", errmsg, EX_BADPARAM);
      return (EX_FATAL);
    }
  }
#endif

  /* read values of element variable */
  start[0] = --time_step;
  start[1] = 0;

  count[0] = 1;
  count[1] = num_entry_this_obj;

  if (ex_comp_ws(exoid) == 4) {
    status = nc_get_vara_float(exoid, varid, start, count, var_vals);
  }
  else {
    status = nc_get_vara_double(exoid, varid, start, count, var_vals);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to get %s %" PRId64 " variable %d in file id %d",
             ex_name_of_object(var_type), obj_id, var_index, exoid);
    ex_err("ex_get_var", errmsg, exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
Ejemplo n.º 17
0
 int ex_get_coordinate_frames( int exoid,
			       int *nframes,
			       void_int *cf_ids,
			       void* pt_coordinates,
			       char* tags)

{
  int status;
  int dimid; /* ID of the dimension of # frames */
  char errmsg[MAX_ERR_LENGTH];
  int varids;                    /* variable id for the frame ids  */
  size_t start=0;                /* start value for varputs        */
  size_t count=0;                /* number vars to put in varput   */

  /* get the dimensions */
  assert( nframes !=NULL );
  status = nc_inq_dimid(exoid, DIM_NUM_CFRAMES, &dimid);
  if (status != NC_NOERR){
    *nframes=0;
    return EX_NOERR;
  }

  (void)nc_inq_dimlen(exoid,dimid,&count);
  *nframes=(int)count;

  if ( count==0 )
    return (EX_NOERR);

  if ( cf_ids ) {
    if ((status = nc_inq_varid(exoid,VAR_FRAME_IDS, &varids))!= NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to read number coordinate ids from file id %d",
              exoid);
      ex_err(PROCNAME,errmsg,exerrval);
      return (EX_FATAL);
    }

    if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
      status = nc_get_var_longlong(exoid,varids,cf_ids);
    } else {
      status = nc_get_var_int(exoid,varids,cf_ids);
    }

    if (status != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to read coordinate frame ids from file id %d",
              exoid);
      ex_err(PROCNAME,errmsg,exerrval);
      return (EX_FATAL);
    }
  }

  if ( tags )
    if ( (status = nc_inq_varid(exoid,VAR_FRAME_TAGS,&varids))!= NC_NOERR  ||
         (nc_get_vara_text(exoid,varids,&start,&count,tags) != NC_NOERR)) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to read number coordinate tags from file id %d",
              exoid);
      ex_err(PROCNAME,errmsg,exerrval);
      return (EX_FATAL);
    }

  if (pt_coordinates ){
    if ( (status = nc_inq_varid(exoid,VAR_FRAME_COORDS,&varids))!= NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to read number coordinate tags from file id %d",
              exoid);
      ex_err(PROCNAME,errmsg,exerrval);
      return (EX_FATAL);
    }

    if (ex_comp_ws(exoid) == 4) {
      status = nc_get_var_float(exoid,varids,pt_coordinates);
    } else {
      status = nc_get_var_double(exoid,varids,pt_coordinates);
    }

    if (status != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to read number coordinate tags from file id %d",
              exoid);
      ex_err(PROCNAME,errmsg,exerrval);
      return (EX_FATAL);
    }
  }

  return (EX_NOERR);
}
Ejemplo n.º 18
0
int ex_put_coord (int   exoid,
                  const void *x_coor,
                  const void *y_coor,
                  const void *z_coor)
{
  int status;
  int coordid;
  int coordidx, coordidy, coordidz;

  int numnoddim, ndimdim;
  size_t i, num_nod, num_dim, start[2], count[2];
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

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

  if ((status = nc_inq_dimid(exoid, DIM_NUM_NODES, &numnoddim)) != NC_NOERR) {
    /* If not found, then this file is storing 0 nodes.
       Return immediately */
    return (EX_NOERR);
  }

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

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

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

  /* write out the coordinates  */
  if (ex_large_model(exoid) == 0) {
    if ((status = nc_inq_varid(exoid, VAR_COORD, &coordid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to locate nodal coordinates in file id %d", exoid);
      ex_err("ex_put_coord",errmsg,exerrval);
      return (EX_FATAL);
    } 

    for (i=0; i<num_dim; i++) {
      char *which = 0;
      start[0] = i;
      start[1] = 0;

      count[0] = 1;
      count[1] = num_nod;

      if (i == 0 && x_coor != NULL) {
	which = "X";
	if (ex_comp_ws(exoid) == 4) {
	  status = nc_put_vara_float(exoid, coordid, start, count, x_coor);
	} else {
	  status = nc_put_vara_double(exoid, coordid, start, count, x_coor);
	}
      }	  
      else if (i == 1 && y_coor != NULL) {
	which = "Y";
	if (ex_comp_ws(exoid) == 4) {
	  status = nc_put_vara_float(exoid, coordid, start, count, y_coor);
	} else {
	  status = nc_put_vara_double(exoid, coordid, start, count, y_coor);
	}
      }
      else if (i == 2 && z_coor != NULL) {
	which = "Z";
	if (ex_comp_ws(exoid) == 4) {
	  status = nc_put_vara_float(exoid, coordid, start, count, z_coor);
	} else {
	  status = nc_put_vara_double(exoid, coordid, start, count, z_coor);
	}
      }
	  
      if (status != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to put %s coord array in file id %d", which, exoid);
	ex_err("ex_put_coord",errmsg,exerrval);
	return (EX_FATAL);
      }
    }
  } else {
    if ((status = nc_inq_varid(exoid, VAR_COORD_X, &coordidx)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate x nodal coordinates in file id %d", exoid);
      ex_err("ex_put_coord",errmsg,exerrval);
      return (EX_FATAL);
    }

    if (num_dim > 1) {
      if ((status = nc_inq_varid(exoid, VAR_COORD_Y, &coordidy)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to locate y nodal coordinates in file id %d", exoid);
	ex_err("ex_put_coord",errmsg,exerrval);
	return (EX_FATAL);
      }
    } else {
      coordidy = 0;
    }
    if (num_dim > 2) {
      if ((status = nc_inq_varid(exoid, VAR_COORD_Z, &coordidz)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to locate z nodal coordinates in file id %d", exoid);
	ex_err("ex_put_coord",errmsg,exerrval);
	return (EX_FATAL);
      }
    } else {
      coordidz = 0;
    }

    /* write out the coordinates  */
    for (i=0; i<num_dim; i++) {
      const void *coor = NULL;
      char *which = NULL;
       
      if (i == 0) {
	coor = x_coor;
	which = "X";
	coordid = coordidx;
      } else if (i == 1) {
	coor = y_coor;
	which = "Y";
	coordid = coordidy;
      } else if (i == 2) {
	coor = z_coor;
	which = "Z";
	coordid = coordidz;
      }

      if (coor != NULL && coordid != 0) {
	if (ex_comp_ws(exoid) == 4) {
	  status = nc_put_var_float(exoid, coordid, coor);
	} else {
	  status = nc_put_var_double(exoid, coordid, coor);
	}

	if (status != NC_NOERR) {
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: failed to put %s coord array in file id %d", which, exoid);
	  ex_err("ex_put_coord",errmsg,exerrval);
	  return (EX_FATAL);
	}
      }
    }
  }
  return (EX_NOERR);
}
Ejemplo n.º 19
0
int ex_get_var_time( int   exoid,
                     ex_entity_type var_type,
                     int   var_index,
                     int64_t   id,
                     int   beg_time_step, 
                     int   end_time_step,
                     void* var_vals )
{
  int dimid, varid, numel = 0, offset;
  int status;
  int *stat_vals;
  size_t num_obj, i;
  size_t num_entries_this_obj = 0;
  size_t start[2], count[2];
  char errmsg[MAX_ERR_LENGTH];
  const char* varobjids;
  const char* varobstat;

  switch (var_type) {
  case EX_GLOBAL:
    return ex_get_glob_var_time( exoid, var_index, beg_time_step, end_time_step, var_vals );
  case EX_NODAL:
    return ex_get_nodal_var_time( exoid, var_index, id, beg_time_step, end_time_step, var_vals );
  case EX_EDGE_BLOCK:
    varobjids =   VAR_ID_ED_BLK; 
    varobstat = VAR_STAT_ED_BLK;
    break;
  case EX_FACE_BLOCK:
    varobjids =   VAR_ID_FA_BLK; 
    varobstat = VAR_STAT_FA_BLK;
    break;
  case EX_ELEM_BLOCK:
    varobjids =   VAR_ID_EL_BLK; 
    varobstat = VAR_STAT_EL_BLK;
    break;
  case EX_NODE_SET:
    varobjids =      VAR_NS_IDS; 
    varobstat =      VAR_NS_STAT;
    break;
  case EX_EDGE_SET:
    varobjids =      VAR_ES_IDS;
    varobstat =      VAR_ES_STAT;
    break;
  case EX_FACE_SET:
    varobjids =      VAR_FS_IDS; 
    varobstat =      VAR_FS_STAT;
    break;
  case EX_SIDE_SET:
    varobjids =      VAR_SS_IDS; 
    varobstat =      VAR_SS_STAT;
    break;
  case EX_ELEM_SET:
    varobjids =      VAR_ELS_IDS; 
    varobstat =      VAR_ELS_STAT;
    break;
  default:
    exerrval = EX_BADPARAM;
    sprintf( errmsg, "Error: Invalid variable type (%d) specified for file id %d", var_type, exoid );
    ex_err( "ex_get_var_time", errmsg, exerrval );
    return (EX_FATAL);
  }

  exerrval = 0; /* clear error code */

  /* assume entry number is 1-based (the first entry of an object is 1, not 0);
   * adjust so it is 0-based
   */
  id--;

  /* find what object the entry is in */

  /* first, find out how many objects there are */
  status = ex_get_dimension(exoid, ex_dim_num_objects(var_type), ex_name_of_object(var_type),
			    &num_obj, &dimid, "ex_get_var_time");
  if (status != NC_NOERR) return status;

  /* get the array of object ids */
  /* don't think we need this anymore since the netcdf variable names 
     associated with objects don't contain the object ids */

  if ((status = nc_inq_varid (exoid, varobjids, &varid )) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to locate %s ids in file id %d",
	    ex_name_of_object(var_type),exoid);
    ex_err("ex_get_var_time",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* allocate space for stat array */
  if (!(stat_vals = malloc((int)num_obj*sizeof(int)))) {
    exerrval = EX_MEMFAIL;
    sprintf(errmsg,
	    "Error: failed to allocate memory for %s status array for file id %d",
	    ex_name_of_object(var_type),exoid);
    ex_err("ex_get_var_time",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* get variable id of status array */
  if (nc_inq_varid (exoid, varobstat, &varid) == NC_NOERR) {
    /* if status array exists, use it, otherwise assume, object exists
       to be backward compatible */

    if ((status = nc_get_var_int(exoid, varid, stat_vals)) != NC_NOERR) {
      exerrval = status;
      free(stat_vals);
      sprintf(errmsg,
	      "Error: failed to get %s status array from file id %d",
	      ex_name_of_object(var_type),exoid);
      ex_err("ex_get_var_time",errmsg,exerrval);
      return (EX_FATAL);
    }
  }
  else { /* default: status is true */
    for(i=0;i<num_obj;i++)
      stat_vals[i]=1;
  }

  /* loop through each object until id is found;  since entry
   * numbers are sequential (beginning with 1) id is in obj_i
   * when id_first_i <= id <= id_last_i, where
   * id_first_i is the entry number of the first entry in 
   * obj_i and id_last_i is the entry number of the last
   * entry in obj_i
   */

  i = 0;
  if (stat_vals[i] != 0)  {
    if ((status = nc_inq_dimid(exoid, ex_dim_num_entries_in_object(var_type,i+1), &dimid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate number of entries in %"ST_ZU"th %s in file id %d",
	      i, ex_name_of_object(var_type), exoid);
      ex_err("ex_get_var_time",errmsg,exerrval);
      free(stat_vals);
      return (EX_FATAL);
    }

    if ((status = nc_inq_dimlen(exoid, dimid, &num_entries_this_obj)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to get number of entries in %"ST_ZU"th %s in file id %d",
	      i, ex_name_of_object(var_type), exoid);
      ex_err("ex_get_var_time",errmsg,exerrval);
      free(stat_vals);
      return (EX_FATAL);
    }
  } /* End NULL object check */

  numel = num_entries_this_obj;

  while (numel <= id) {
    if (stat_vals[++i] != 0) {
      if ((status = nc_inq_dimid(exoid,ex_dim_num_entries_in_object(var_type,i+1), &dimid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to locate number of entries in %"ST_ZU"th %s in file id %d",
		i, ex_name_of_object(var_type), exoid);
	ex_err("ex_get_var_time",errmsg,exerrval);
	free(stat_vals);
	return (EX_FATAL);
      }

      if ((status = nc_inq_dimlen(exoid, dimid, &num_entries_this_obj)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get number of entries in %"ST_ZU"th %s in file id %d",
		i, ex_name_of_object(var_type), exoid);
	ex_err("ex_get_var_time",errmsg,exerrval);
	free(stat_vals);
	return (EX_FATAL);
      }
      numel += num_entries_this_obj;
    }
  }
  offset = id - (numel - num_entries_this_obj);

  /* inquire previously defined variable */
  if ((status = nc_inq_varid(exoid,ex_name_var_of_object(var_type,var_index,i+1), &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to locate variable %"ST_ZU" for %dth %s in file id %d",
	    i, var_index,ex_name_of_object(var_type),exoid);
    ex_err("ex_get_var_time",errmsg,exerrval);
    free(stat_vals);
    return (EX_FATAL);
  }

  free(stat_vals);

  /* read values of object variable */
  start[0] = --beg_time_step;
  start[1] = offset;

  if (end_time_step < 0) {
    /* user is requesting the maximum time step;  we find this out using the
     * database inquire function to get the number of time steps;  the ending
     * time step number is 1 less due to 0 based array indexing in C
     */
    end_time_step = ex_inquire_int (exoid, EX_INQ_TIME);
  }

  end_time_step--;

  count[0] = end_time_step - beg_time_step + 1;
  count[1] = 1;

  if (ex_comp_ws(exoid) == 4) {
    status = nc_get_vara_float(exoid, varid, start, count, var_vals);
  } else {
    status = nc_get_vara_double(exoid, varid, start, count, var_vals);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to get %s variable values in file id %d",
	    ex_name_of_object(var_type),exoid);
    ex_err("ex_get_var_time",errmsg,exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
Ejemplo n.º 20
0
int ex_get_concat_sets (int   exoid,
                        ex_entity_type set_type,
                        struct ex_set_specs* set_specs)
{
  int status, dimid;
  void_int  *num_entries_per_set = set_specs->num_entries_per_set;
  void_int  *num_dist_per_set = set_specs->num_dist_per_set;
  void_int  *sets_entry_index = set_specs->sets_entry_index;
  void_int  *sets_dist_index = set_specs->sets_dist_index;

  void *sets_dist_fact = set_specs->sets_dist_fact; 

  int num_sets, i;
  float  *flt_dist_fact;
  double *dbl_dist_fact;
  char errmsg[MAX_ERR_LENGTH];
  ex_inquiry ex_inq_val;

  exerrval = 0; /* clear error code */

  /* setup pointers based on set_type 
     NOTE: there is another block that sets more stuff later ... */

  if (set_type == EX_NODE_SET) {
    ex_inq_val = EX_INQ_NODE_SETS;
  }
  else if (set_type == EX_EDGE_SET) {
    ex_inq_val = EX_INQ_EDGE_SETS;
  }
  else if (set_type == EX_FACE_SET) {
    ex_inq_val = EX_INQ_FACE_SETS;
  }
  else if (set_type == EX_SIDE_SET) {
    ex_inq_val = EX_INQ_SIDE_SETS;
  }
  else if (set_type == EX_ELEM_SET) {
    ex_inq_val = EX_INQ_ELEM_SETS;
  }
  else {
    exerrval = EX_FATAL;
    sprintf(errmsg,
	    "Error: invalid set type (%d)", set_type);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* first check if any sets are specified */

  if ((status = nc_inq_dimid(exoid, ex_dim_num_objects(set_type), &dimid)) != NC_NOERR) {
    exerrval = status;
    if (status == NC_EBADDIM) {
      sprintf(errmsg,
	      "Warning: no %ss defined for file id %d",
	      ex_name_of_object(set_type), exoid);
      ex_err("ex_get_concat_sets",errmsg,exerrval);
      return (EX_WARN);
    } else {
      sprintf(errmsg,
	      "Error: failed to locate %ss defined in file id %d", 
	      ex_name_of_object(set_type), exoid);
      ex_err("ex_get_concat_sets",errmsg,exerrval);
      return (EX_FATAL);
    }
  }

  /* inquire how many sets have been stored */

  num_sets = ex_inquire_int(exoid, ex_inq_val);
  if (num_sets < 0) {
    sprintf(errmsg,
            "Error: failed to get number of %ss defined for file id %d",
	    ex_name_of_object(set_type), exoid);
    /* use error val from inquire */
    ex_err("ex_get_concat_sets",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (ex_get_ids (exoid, set_type, set_specs->sets_ids) != NC_NOERR) {
    sprintf(errmsg,
            "Error: failed to get %s ids for file id %d",
	    ex_name_of_object(set_type), exoid);
    /* use error val from inquire */
    ex_err("ex_get_concat_sets",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
    ((int64_t*)sets_entry_index)[0] = 0;
    ((int64_t*)sets_dist_index)[0] = 0;
  } else {
    ((int*)sets_entry_index)[0] = 0;
    ((int*)sets_dist_index)[0] = 0;
  }

  for (i=0; i<num_sets; i++) {
    int set_id;
    if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
      set_id = ((int64_t*)set_specs->sets_ids)[i];
    } else {
      set_id = ((int*)set_specs->sets_ids)[i];
    }

    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
      if (ex_get_set_param(exoid, set_type, set_id, 
			   &(((int64_t*)num_entries_per_set)[i]),
			   &(((int64_t*)num_dist_per_set)[i])) != NC_NOERR)
	return(EX_FATAL); /* error will be reported by sub */
      
      if (i < num_sets-1) {
	/* fill in entry and dist factor index arrays */
	((int64_t*)sets_entry_index)[i+1] = ((int64_t*)sets_entry_index)[i]+((int64_t*)num_entries_per_set)[i];
	((int64_t*)sets_dist_index)[i+1] = ((int64_t*)sets_dist_index)[i]+((int64_t*)num_dist_per_set)[i];
      }

      if (((int64_t*)num_entries_per_set)[i] == 0) /* NULL  set? */
	continue;

      {
	/* Now, use ExodusII call to get sets */
	int64_t *sets_entry_list = set_specs->sets_entry_list;
	int64_t *sets_extra_list = set_specs->sets_extra_list;
	int64_t *sets_extra = sets_extra_list ? &((int64_t*)sets_extra_list)[((int64_t*)sets_entry_index)[i]] : NULL;
	status = ex_get_set(exoid, set_type, set_id,
			    &(sets_entry_list[((int64_t*)sets_entry_index)[i]]),
			    sets_extra);
      }
    } else {
      if (ex_get_set_param(exoid, set_type, set_id, 
			   &(((int*)num_entries_per_set)[i]),
			   &(((int*)num_dist_per_set)[i])) != NC_NOERR)
	return(EX_FATAL); /* error will be reported by sub */
      
      if (i < num_sets-1) {
	/* fill in entry and dist factor index arrays */
	((int*)sets_entry_index)[i+1] = ((int*)sets_entry_index)[i]+((int*)num_entries_per_set)[i];
	((int*)sets_dist_index)[i+1] = ((int*)sets_dist_index)[i]+((int*)num_dist_per_set)[i];
      }

      if (((int*)num_entries_per_set)[i] == 0) /* NULL  set? */
	continue;

      {
	/* Now, use ExodusII call to get sets */
	int *sets_entry_list = set_specs->sets_entry_list;
	int *sets_extra_list = set_specs->sets_extra_list;
	int *sets_extra = sets_extra_list ? &((int*)sets_extra_list)[((int*)sets_entry_index)[i]] : NULL;
	status = ex_get_set(exoid, set_type, set_id,
			    &(sets_entry_list[((int*)sets_entry_index)[i]]),
			    sets_extra);
      }
    }

    if (status != NC_NOERR)
      return(EX_FATAL); /* error will be reported by subroutine */
    
    /* get distribution factors for this set */
    if (sets_dist_fact != 0) {
      size_t df_idx;
      size_t num_dist;
      if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
	df_idx = ((int64_t*)sets_dist_index)[i];
	num_dist = ((int64_t*)num_dist_per_set)[i];
      } else {
	df_idx = ((int*)sets_dist_index)[i];
	num_dist = ((int*)num_dist_per_set)[i];
      }
      if (num_dist > 0) {      /* only get df if they exist */
	if (ex_comp_ws(exoid) == sizeof(float)) {
	  flt_dist_fact = sets_dist_fact;
	  status = ex_get_set_dist_fact(exoid, set_type, set_id,
					&(flt_dist_fact[df_idx]));
	} else {
	  dbl_dist_fact = sets_dist_fact;
	  status = ex_get_set_dist_fact(exoid, set_type, set_id,
					&(dbl_dist_fact[df_idx]));
	}
	if (status != NC_NOERR) {
	  return(EX_FATAL); /* error will be reported by subroutine */
	}
      }
    }
  }
  return(EX_NOERR);
}
Ejemplo n.º 21
0
int ex_put_var (int   exoid,
		int   time_step,
		ex_entity_type var_type,
		int   var_index,
		ex_entity_id   obj_id,
		int64_t   num_entries_this_obj,
		const void *var_vals)
{
  int varid;
  size_t start[2], count[2];
  int status;
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  switch (var_type) {
  case EX_GLOBAL:
    if ( num_entries_this_obj <= 0 ) {
      exerrval = EX_MSG;
      sprintf(errmsg,
	      "Warning: no global variables specified for file id %d",
	      exoid);
      ex_err("ex_put_glob_vars",errmsg,exerrval);

      return (EX_WARN);
    }

    /* inquire previously defined variable */
    if ((status = nc_inq_varid (exoid, VAR_GLO_VAR, &varid)) != NC_NOERR) {
      if (status == NC_ENOTVAR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: no global variables defined in file id %d",
		exoid);
	ex_err("ex_put_glob_vars",errmsg,exerrval);
      } else {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get global variables parameters in file id %d",
		exoid);
	ex_err("ex_put_glob_vars",errmsg,exerrval);
      }
      return (EX_FATAL);
    }
    break;
  case EX_NODAL:
    return ex_put_nodal_var(exoid, time_step, var_index, num_entries_this_obj, var_vals);
    break;
  case EX_EDGE_BLOCK:
    status = ex_look_up_var(exoid, var_type, var_index, obj_id,
			    VAR_ID_ED_BLK,VAR_EBLK_TAB,DIM_NUM_ED_BLK,DIM_NUM_EDG_VAR, &varid);
    break;
  case EX_FACE_BLOCK:
    status = ex_look_up_var(exoid, var_type, var_index, obj_id,
		   VAR_ID_FA_BLK,VAR_FBLK_TAB,DIM_NUM_FA_BLK,DIM_NUM_FAC_VAR, &varid);
    break;
  case EX_ELEM_BLOCK:
    status = ex_look_up_var(exoid, var_type, var_index, obj_id,
		   VAR_ID_EL_BLK,VAR_ELEM_TAB,DIM_NUM_EL_BLK,DIM_NUM_ELE_VAR, &varid);
    break;
  case EX_NODE_SET:
    status = ex_look_up_var(exoid, var_type, var_index, obj_id,
		   VAR_NS_IDS,VAR_NSET_TAB,DIM_NUM_NS,DIM_NUM_NSET_VAR, &varid);
    break;
  case EX_EDGE_SET:
    status = ex_look_up_var(exoid, var_type, var_index, obj_id,
		   VAR_ES_IDS,VAR_ESET_TAB,DIM_NUM_ES,DIM_NUM_ESET_VAR, &varid);
    break;
  case EX_FACE_SET:
    status = ex_look_up_var(exoid, var_type, var_index, obj_id,
		   VAR_FS_IDS,VAR_FSET_TAB,DIM_NUM_FS,DIM_NUM_FSET_VAR, &varid);
    break;
  case EX_SIDE_SET:
    status = ex_look_up_var(exoid, var_type, var_index, obj_id,
		   VAR_SS_IDS,VAR_SSET_TAB,DIM_NUM_SS,DIM_NUM_SSET_VAR, &varid);
    break;
  case EX_ELEM_SET:
    status = ex_look_up_var(exoid, var_type, var_index, obj_id,
		   VAR_ELS_IDS,VAR_ELSET_TAB,DIM_NUM_ELS,DIM_NUM_ELSET_VAR, &varid);
    break;
  default:
    exerrval = EX_MSG;
    sprintf( errmsg, "Error: invalid variable type (%d) specified for file id %d",
	     var_type, exoid );
    ex_err( "ex_put_var", errmsg, exerrval );
    return (EX_FATAL);
  }

  if (status != EX_NOERR) {
    return status;
  }    

  /* store element variable values */
  start[0] = --time_step;
  start[1] = 0;

  if ( var_type == EX_GLOBAL ) {
    /* global variables may be written
     * - all at once (by setting var_index to 1 and num_entries_this_obj to num_glob, or
     * - one at a time (by setting var_index to the desired index and num_entries_this_obj to 1.
     */
    count[0] = var_index;
  } else {
    count[0] = 1;
  }
  count[1] = num_entries_this_obj;

  if (ex_comp_ws(exoid) == 4) {
    status = nc_put_vara_float(exoid, varid, start, count, var_vals);
  } else {
    status = nc_put_vara_double(exoid, varid, start, count, var_vals);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to store %s %"PRId64" variable %d in file id %d",
	    ex_name_of_object(var_type), obj_id, var_index,exoid);
    ex_err("ex_put_var",errmsg,exerrval);
    return (EX_FATAL);
  }

  return (EX_NOERR);
}
Ejemplo n.º 22
0
int ex_get_partial_var( int   exoid,
		  int   time_step,
		  ex_entity_type var_type,
		  int   var_index,
		  ex_entity_id   obj_id, 
		  int64_t   start_index,
		  int64_t   num_entities,
		  void* var_vals )
{
  int status = 0;
  int varid, obj_id_ndx;
  size_t start[2], count[2];
  char errmsg[MAX_ERR_LENGTH];

  if (num_entities == 0)
    return status;
  
  if (var_type == EX_NODAL) {
    /* FIXME: Special case: ignore obj_id, possible large_file complications, etc. */
    return ex_get_partial_nodal_var( exoid, time_step, var_index, start_index, num_entities, var_vals );
  } else if (var_type == EX_GLOBAL) {
    /* FIXME: Special case: all vars stored in 2-D single array. */
    return ex_get_glob_vars( exoid, time_step, num_entities, var_vals );
  }
   
  exerrval = 0; /* clear error code */

  /* Determine index of obj_id in VAR_ID_EL_BLK array */
  obj_id_ndx = ex_id_lkup(exoid,var_type,obj_id);
  if (exerrval != 0) {
    if (exerrval == EX_NULLENTITY) {
      sprintf(errmsg,
	      "Warning: no %s variables for NULL block %"PRId64" in file id %d",
	      ex_name_of_object(var_type), obj_id,exoid);
      ex_err("ex_get_partial_var",errmsg,EX_NULLENTITY);
      return (EX_WARN);
    } else {
      sprintf(errmsg,
	      "Error: failed to locate %s id %"PRId64" in id variable in file id %d",
	      ex_name_of_object(var_type), obj_id, exoid);
      ex_err("ex_get_partial_var",errmsg,exerrval);
      return (EX_FATAL);
    }
  }

  /* inquire previously defined variable */

  if((status = nc_inq_varid(exoid, ex_name_var_of_object(var_type,var_index,
							 obj_id_ndx), &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to locate %s %"PRId64" var %d in file id %d",
	    ex_name_of_object(var_type),obj_id,var_index,exoid); 
    ex_err("ex_get_partial_var",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* read values of element variable */
  start[0] = --time_step;
  start[1] = start_index-1;

  count[0] = 1;
  count[1] = num_entities;

  if (ex_comp_ws(exoid) == 4) {
    status = nc_get_vara_float(exoid, varid, start, count, var_vals);
  } else {
    status = nc_get_vara_double(exoid, varid, start, count, var_vals);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to get %s %"PRId64" variable %d in file id %d", 
	    ex_name_of_object(var_type), obj_id, var_index,exoid);
    ex_err("ex_get_partial_var",errmsg,exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
Ejemplo n.º 23
0
int ex_put_partial_var(int exoid, int time_step, ex_entity_type var_type, int var_index,
                       ex_entity_id obj_id, int64_t start_index, int64_t num_entities,
                       const void *var_vals)
{
  int    varid, dimid, time_dim, numobjdim, dims[2], obj_id_ndx;
  size_t num_obj;
  size_t num_obj_var;
  size_t num_entity;
  size_t start[2], count[2];
  int *  obj_var_truth_tab;
  int    status;
  char   errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

#define EX_LOOK_UP_VAR(VOBJID, VVAR, VOBJTAB, DNUMOBJ, DNUMOBJVAR)                                 \
  /* Determine index of obj_id in VOBJID array */                                                  \
  obj_id_ndx = ex_id_lkup(exoid, var_type, obj_id);                                                \
  if (exerrval != 0) {                                                                             \
    if (exerrval == EX_NULLENTITY) {                                                               \
      snprintf(errmsg, MAX_ERR_LENGTH,                                                             \
               "Warning: no variables allowed for NULL block %" PRId64 " in file id %d", obj_id,   \
               exoid);                                                                             \
      ex_err("ex_put_partial_var", errmsg, EX_NULLENTITY);                                         \
      return (EX_WARN);                                                                            \
    }                                                                                              \
    else {                                                                                         \
      snprintf(errmsg, MAX_ERR_LENGTH,                                                             \
               "ERROR: failed to locate %s id %" PRId64 " in %s array in file id %d",              \
               ex_name_of_object(var_type), obj_id, VOBJID, exoid);                                \
      ex_err("ex_put_partial_var", errmsg, exerrval);                                              \
      return (EX_FATAL);                                                                           \
    }                                                                                              \
  }                                                                                                \
                                                                                                   \
  if ((status = nc_inq_varid(exoid, VVAR(var_index, obj_id_ndx), &varid)) != NC_NOERR) {           \
    if (status == NC_ENOTVAR) /* variable doesn't exist, create it! */                             \
    {                                                                                              \
      /* check for the existance of an TNAME variable truth table */                               \
      if (nc_inq_varid(exoid, VOBJTAB, &varid) == NC_NOERR) {                                      \
        /* find out number of TNAMEs and TNAME variables */                                        \
        status = ex_get_dimension(exoid, DNUMOBJ, ex_name_of_object(var_type), &num_obj, &dimid,   \
                                  "ex_put_partial_var");                                           \
        if (status != NC_NOERR)                                                                    \
          return status;                                                                           \
                                                                                                   \
        status = ex_get_dimension(exoid, DNUMOBJVAR, ex_name_of_object(var_type), &num_obj_var,    \
                                  &dimid, "ex_put_partial_var");                                   \
        if (status != NC_NOERR)                                                                    \
          return status;                                                                           \
                                                                                                   \
        if (!(obj_var_truth_tab = malloc(num_obj * num_obj_var * sizeof(int)))) {                  \
          exerrval = EX_MEMFAIL;                                                                   \
          snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to allocate memory for %s variable "     \
                                           "truth table in file id %d",                            \
                   ex_name_of_object(var_type), exoid);                                            \
          ex_err("ex_put_partial_var", errmsg, exerrval);                                          \
          return (EX_FATAL);                                                                       \
        }                                                                                          \
                                                                                                   \
        /*   read in the TNAME variable truth table */                                             \
        if ((status = nc_get_var_int(exoid, varid, obj_var_truth_tab)) != NC_NOERR) {              \
          exerrval = status;                                                                       \
          snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get truth table from file id %d",     \
                   exoid);                                                                         \
          ex_err("ex_put_partial_var", errmsg, exerrval);                                          \
          return (EX_FATAL);                                                                       \
        }                                                                                          \
                                                                                                   \
        if (obj_var_truth_tab[num_obj_var * (obj_id_ndx - 1) + var_index - 1] == 0L) {             \
          free(obj_var_truth_tab);                                                                 \
          exerrval = EX_BADPARAM;                                                                  \
          snprintf(errmsg, MAX_ERR_LENGTH,                                                         \
                   "ERROR: Invalid %s variable %d, %s %" PRId64 " in file id %d",                  \
                   ex_name_of_object(var_type), var_index, ex_name_of_object(var_type), obj_id,    \
                   exoid);                                                                         \
          ex_err("ex_put_partial_var", errmsg, exerrval);                                          \
          return (EX_FATAL);                                                                       \
        }                                                                                          \
        free(obj_var_truth_tab);                                                                   \
      }                                                                                            \
                                                                                                   \
      if ((status = nc_inq_dimid(exoid, DIM_TIME, &time_dim)) != NC_NOERR) {                       \
        exerrval = status;                                                                         \
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate time dimension in file id %d",   \
                 exoid);                                                                           \
        ex_err("ex_put_partial_var", errmsg, exerrval);                                            \
        goto error_ret; /* exit define mode and return */                                          \
      }                                                                                            \
                                                                                                   \
      ex_get_dimension(exoid, ex_dim_num_entries_in_object(var_type, obj_id_ndx),                  \
                       ex_name_of_object(var_type), &num_entity, &numobjdim,                       \
                       "ex_put_partial_var");                                                      \
                                                                                                   \
      /*    variable doesn't exist so put file into define mode  */                                \
      if ((status = nc_redef(exoid)) != NC_NOERR) {                                                \
        exerrval = status;                                                                         \
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to put file id %d into define mode",       \
                 exoid);                                                                           \
        ex_err("ex_put_partial_var", errmsg, exerrval);                                            \
        return (EX_FATAL);                                                                         \
      }                                                                                            \
                                                                                                   \
      /* define netCDF variable to store TNAME variable values */                                  \
      dims[0] = time_dim;                                                                          \
      dims[1] = numobjdim;                                                                         \
      if ((status = nc_def_var(exoid, VVAR(var_index, obj_id_ndx), nc_flt_code(exoid), 2, dims,    \
                               &varid)) != NC_NOERR) {                                             \
        exerrval = status;                                                                         \
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define %s variable %d in file id %d",   \
                 ex_name_of_object(var_type), var_index, exoid);                                   \
        ex_err("ex_put_partial_var", errmsg, exerrval);                                            \
        goto error_ret;                                                                            \
      }                                                                                            \
      ex_compress_variable(exoid, varid, 2);                                                       \
                                                                                                   \
      /*    leave define mode  */                                                                  \
                                                                                                   \
      if ((status = nc_enddef(exoid)) != NC_NOERR) {                                               \
        exerrval = status;                                                                         \
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete %s variable %s definition "    \
                                         "to file id %d",                                          \
                 ex_name_of_object(var_type), VVAR(var_index, obj_id_ndx), exoid);                 \
        ex_err("ex_put_partial_var", errmsg, exerrval);                                            \
        return (EX_FATAL);                                                                         \
      }                                                                                            \
    }                                                                                              \
    else {                                                                                         \
      exerrval = status;                                                                           \
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate %s variable %s in file id %d",     \
               ex_name_of_object(var_type), VVAR(var_index, obj_id_ndx), exoid);                   \
      ex_err("ex_put_partial_var", errmsg, exerrval);                                              \
      return (EX_FATAL);                                                                           \
    }                                                                                              \
  }

  switch (var_type) {
  case EX_GLOBAL:
    if (num_entities <= 0) {
      exerrval = EX_MSG;
      snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no global variables specified for file id %d",
               exoid);
      ex_err("ex_put_partial_var", errmsg, exerrval);

      return (EX_WARN);
    }
    /* inquire previously defined variable */

    if ((status = nc_inq_varid(exoid, VAR_GLO_VAR, &varid)) != NC_NOERR) {
      if (status == NC_ENOTVAR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: no global variables defined in file id %d", exoid);
        ex_err("ex_put_partial_var", errmsg, exerrval);
      }
      else {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to get global variables parameters in file id %d", exoid);
        ex_err("ex_put_partial_var", errmsg, exerrval);
      }
      return (EX_FATAL);
    }
    break;
  case EX_NODAL:
    return ex_put_partial_nodal_var_int(exoid, time_step, var_index, start_index, num_entities,
                                        var_vals);
    break;
  case EX_EDGE_BLOCK:
    EX_LOOK_UP_VAR(VAR_ID_ED_BLK, VAR_EDGE_VAR, VAR_EBLK_TAB, DIM_NUM_ED_BLK, DIM_NUM_EDG_VAR);
    break;
  case EX_FACE_BLOCK:
    EX_LOOK_UP_VAR(VAR_ID_FA_BLK, VAR_FACE_VAR, VAR_FBLK_TAB, DIM_NUM_FA_BLK, DIM_NUM_FAC_VAR);
    break;
  case EX_ELEM_BLOCK:
    EX_LOOK_UP_VAR(VAR_ID_EL_BLK, VAR_ELEM_VAR, VAR_ELEM_TAB, DIM_NUM_EL_BLK, DIM_NUM_ELE_VAR);
    break;
  case EX_NODE_SET:
    EX_LOOK_UP_VAR(VAR_NS_IDS, VAR_NS_VAR, VAR_NSET_TAB, DIM_NUM_NS, DIM_NUM_NSET_VAR);
    break;
  case EX_EDGE_SET:
    EX_LOOK_UP_VAR(VAR_ES_IDS, VAR_ES_VAR, VAR_ESET_TAB, DIM_NUM_ES, DIM_NUM_ESET_VAR);
    break;
  case EX_FACE_SET:
    EX_LOOK_UP_VAR(VAR_FS_IDS, VAR_FS_VAR, VAR_FSET_TAB, DIM_NUM_FS, DIM_NUM_FSET_VAR);
    break;
  case EX_SIDE_SET:
    EX_LOOK_UP_VAR(VAR_SS_IDS, VAR_SS_VAR, VAR_SSET_TAB, DIM_NUM_SS, DIM_NUM_SSET_VAR);
    break;
  case EX_ELEM_SET:
    EX_LOOK_UP_VAR(VAR_ELS_IDS, VAR_ELS_VAR, VAR_ELSET_TAB, DIM_NUM_ELS, DIM_NUM_ELSET_VAR);
    break;
  default:
    exerrval = EX_MSG;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: invalid variable type (%d) specified for file id %d",
             var_type, exoid);
    ex_err("ex_put_partial_var", errmsg, exerrval);
    return (EX_FATAL);
  }
  /* store element variable values */

  start[0] = --time_step;
  start[1] = start_index - 1;
  if (var_type == EX_GLOBAL) {
    /* global variables may be written
     * - all at once (by setting var_index to 1 and num_entries_this_obj to
     * num_glob, or
     * - one at a time (by setting var_index to the desired index and
     * num_entries_this_obj to 1.
     */
    count[0] = var_index;
  }
  else {
    count[0] = 1;
  }
  count[1] = num_entities;
  if (count[1] == 0) {
    start[1] = 0;
  }

  if (ex_comp_ws(exoid) == 4) {
    status = nc_put_vara_float(exoid, varid, start, count, var_vals);
  }
  else {
    status = nc_put_vara_double(exoid, varid, start, count, var_vals);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to store %s %" PRId64 " variable %d in file id %d",
             ex_name_of_object(var_type), obj_id, var_index, exoid);
    ex_err("ex_put_partial_var", errmsg, exerrval);
    return (EX_FATAL);
  }

  return (EX_NOERR);

/* Fatal error: exit definition mode and return */
error_ret:
  if (nc_enddef(exoid) != NC_NOERR) /* exit define mode */
  {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete definition for file id %d", exoid);
    ex_err("ex_put_partial_var", errmsg, exerrval);
  }
  return (EX_FATAL);
}
Ejemplo n.º 24
0
int ex_get_concat_sets (int   exoid,
                        int   set_type,
                        struct ex_set_specs* set_specs)
{
   int  *set_ids = set_specs->sets_ids;
   int  *num_entries_per_set = set_specs->num_entries_per_set;
   int  *num_dist_per_set = set_specs->num_dist_per_set;
   int  *sets_entry_index = set_specs->sets_entry_index;
   int  *sets_dist_index = set_specs->sets_dist_index;
   int  *sets_entry_list = set_specs->sets_entry_list;
   int  *sets_extra_list = set_specs->sets_extra_list;
   void *sets_dist_fact = set_specs->sets_dist_fact;
   char *cdum;
   int num_sets, i;
   float fdum;
   float  *flt_dist_fact;
   double *dbl_dist_fact;
   char errmsg[MAX_ERR_LENGTH];
   char* typeName;
   char* dimptr;
   char* idsptr;
   int ex_inq_val;
   int *extra_list;   

   exerrval = 0; /* clear error code */

   cdum = 0; /* initialize even though it is not used */

  /* setup pointers based on set_type 
    NOTE: there is another block that sets more stuff later ... */

   if (set_type == EX_NODE_SET) {
     typeName = "node";
     ex_inq_val = EX_INQ_NODE_SETS;
     dimptr = DIM_NUM_NS;
     idsptr = VAR_NS_IDS;
   }
   else if (set_type == EX_EDGE_SET) {
     typeName = "edge";
     ex_inq_val = EX_INQ_EDGE_SETS;
     dimptr = DIM_NUM_ES;
     idsptr = VAR_ES_IDS;
   }
   else if (set_type == EX_FACE_SET) {
     typeName = "face";
     ex_inq_val = EX_INQ_FACE_SETS;
     dimptr = DIM_NUM_FS;
     idsptr = VAR_FS_IDS;
   }
   else if (set_type == EX_SIDE_SET) {
     typeName = "side";
     ex_inq_val = EX_INQ_SIDE_SETS;
     dimptr = DIM_NUM_SS;
     idsptr = VAR_SS_IDS;
   }
   else if (set_type == EX_ELEM_SET) {
     typeName = "elem";
     ex_inq_val = EX_INQ_ELEM_SETS;
     dimptr = DIM_NUM_ELS;
     idsptr = VAR_ELS_IDS;
   }
   else {
     exerrval = EX_FATAL;
     sprintf(errmsg,
             "Error: invalid set type (%d)", set_type);
     ex_err("ex_put_set_param",errmsg,exerrval);
     return (EX_FATAL);
   }

/* first check if any sets are specified */

   if (ncdimid (exoid, dimptr)  == -1)
   {
     if (ncerr == NC_EBADDIM)
     {
       exerrval = ncerr;
       sprintf(errmsg,
               "Warning: no %s sets defined for file id %d", typeName, exoid);
       ex_err("ex_get_concat_sets",errmsg,exerrval);
       return (EX_WARN);
     }
     else
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Error: failed to locate %s sets defined in file id %d", 
               typeName, exoid);
       ex_err("ex_get_concat_sets",errmsg,exerrval);
       return (EX_FATAL);
     }
   }

/* inquire how many sets have been stored */

   if (ex_inquire(exoid, ex_inq_val, &num_sets, &fdum, cdum) == -1)
   {
     sprintf(errmsg,
            "Error: failed to get number of %s sets defined for file id %d",
             typeName, exoid);
     /* use error val from inquire */
     ex_err("ex_get_concat_sets",errmsg,exerrval);
     return (EX_FATAL);
   }

   if (ex_get_ids (exoid, set_type, set_ids) == -1)
   {
     sprintf(errmsg,
            "Error: failed to get %s set ids for file id %d",
             typeName, exoid);
     /* use error val from inquire */
     ex_err("ex_get_concat_sets",errmsg,exerrval);
     return (EX_FATAL);
   }

   sets_entry_index[0] = 0;
   sets_dist_index[0] = 0;

   for (i=0; i<num_sets; i++)
   {
     if (ex_get_set_param(exoid, set_type, set_ids[i], 
                       &(num_entries_per_set[i]), &(num_dist_per_set[i])) == -1)
       return(EX_FATAL); /* error will be reported by sub */

     if (i < num_sets-1)
     {
       /* fill in entry and dist factor index arrays */
       sets_entry_index[i+1] = sets_entry_index[i]+num_entries_per_set[i];
       sets_dist_index[i+1] = sets_dist_index[i]+num_dist_per_set[i];
     }

     if (num_entries_per_set[i] == 0) /* NULL  set? */
       continue;

     /* Now, use ExodusII call to get sets */

     if (set_type == EX_EDGE_SET || set_type == EX_FACE_SET ||
         set_type == EX_SIDE_SET)
       extra_list = &(sets_extra_list[sets_entry_index[i]]);
     else
       extra_list = NULL;

     if (ex_comp_ws(exoid) == sizeof(float))
     {
       if (ex_get_set(exoid, set_type, set_ids[i],
                         &(sets_entry_list[sets_entry_index[i]]),
                         &(sets_extra_list[sets_entry_index[i]])) == -1)
         return(EX_FATAL); /* error will be reported by subroutine */

       /* get distribution factors for this set */
       flt_dist_fact = sets_dist_fact;
       if (num_dist_per_set[i] > 0)       /* only get df if they exist */
       {
         if (ex_get_set_dist_fact(exoid, set_type, set_ids[i],
                               &(flt_dist_fact[sets_dist_index[i]])) == -1)
         {
           exerrval = ncerr;
           sprintf(errmsg,
                  "Error: failed to get %s set %d dist factors in file id %d",
                   typeName, set_ids[i], exoid);
           ex_err("ex_get_concat_sets",errmsg,exerrval);
           return(EX_FATAL);
         }
       } else {  /* fill distribution factor array with 1's */
       }
     }
     else if (ex_comp_ws(exoid) == sizeof(double))
     {
       if (ex_get_set(exoid, set_type, set_ids[i],
                      &(sets_entry_list[sets_entry_index[i]]),
                      &(sets_extra_list[sets_entry_index[i]])) == -1)
         return(EX_FATAL); /* error will be reported by subroutine */

       /* get distribution factors for this set */
       dbl_dist_fact = sets_dist_fact;
       if (num_dist_per_set[i] > 0)       /* only get df if they exist */
       {
         if (ex_get_set_dist_fact(exoid, set_type, set_ids[i],
                               &(dbl_dist_fact[sets_dist_index[i]])) == -1)
         {
           exerrval = ncerr;
           sprintf(errmsg,
                  "Error: failed to get %s set %d dist factors in file id %d",
                   typeName, set_ids[i], exoid);
           ex_err("ex_get_concat_sets",errmsg,exerrval);
           return(EX_FATAL);
         }
       } else {  /* fill distribution factor array with 1's */
       }
     }
   }

   return(EX_NOERR);

}
int ex_get_partial_coord(int exoid, int64_t start_node_num, int64_t num_nodes, void *x_coor,
                         void *y_coor, void *z_coor)
{
  int status;
  int coordid;
  int coordidx, coordidy, coordidz;

  int    numnoddim, ndimdim;
  size_t num_nod;
  size_t num_dim, start[2], count[2], i;
  char   errmsg[MAX_ERR_LENGTH];

  EX_FUNC_ENTER();
  ex_check_valid_file_id(exoid, __func__);

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

  if (nc_inq_dimid(exoid, DIM_NUM_NODES, &numnoddim) != NC_NOERR) {
    /* If not found, then this file is storing 0 nodes.
       Return immediately */
    EX_FUNC_LEAVE(EX_NOERR);
  }

  if ((status = nc_inq_dimlen(exoid, numnoddim, &num_nod)) != NC_NOERR) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of nodes in file id %d", exoid);
    ex_err(__func__, errmsg, status);
    EX_FUNC_LEAVE(EX_FATAL);
  }

  --start_node_num;
  if (start_node_num + num_nodes > num_nod) {
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: start index (%" PRId64 ") + node count (%" PRId64
             ") is larger than total number of nodes (%" ST_ZU ") in file id %d",
             start_node_num, num_nodes, num_nod, exoid);
    ex_err(__func__, errmsg, EX_BADPARAM);
    EX_FUNC_LEAVE(EX_FATAL);
  }

  if (ex_get_dimension(exoid, DIM_NUM_DIM, "dimension count", &num_dim, &ndimdim, __func__) !=
      NC_NOERR) {
    EX_FUNC_LEAVE(EX_FATAL);
  }

  /* read in the coordinates  */
  if (ex_large_model(exoid) == 0) {
    if ((status = nc_inq_varid(exoid, VAR_COORD, &coordid)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate nodal coordinates in file id %d",
               exoid);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(EX_FATAL);
    }

    for (i = 0; i < num_dim; i++) {
      char *which;
      start[0] = i;
      start[1] = start_node_num;

      count[0] = 1;
      count[1] = num_nodes;
      if (count[1] == 0) {
        start[1] = 0;
      }

      if (i == 0 && x_coor != NULL) {
        which = "X";
        if (ex_comp_ws(exoid) == 4) {
          status = nc_get_vara_float(exoid, coordid, start, count, x_coor);
        }
        else {
          status = nc_get_vara_double(exoid, coordid, start, count, x_coor);
        }
      }
      else if (i == 1 && y_coor != NULL) {
        which = "Y";
        if (ex_comp_ws(exoid) == 4) {
          status = nc_get_vara_float(exoid, coordid, start, count, y_coor);
        }
        else {
          status = nc_get_vara_double(exoid, coordid, start, count, y_coor);
        }
      }
      else if (i == 2 && z_coor != NULL) {
        which = "Z";
        if (ex_comp_ws(exoid) == 4) {
          status = nc_get_vara_float(exoid, coordid, start, count, z_coor);
        }
        else {
          status = nc_get_vara_double(exoid, coordid, start, count, z_coor);
        }
      }

      if (status != NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get %s coord array in file id %d", which,
                 exoid);
        ex_err(__func__, errmsg, status);
        EX_FUNC_LEAVE(EX_FATAL);
      }
    }
  }
  else {
    if ((status = nc_inq_varid(exoid, VAR_COORD_X, &coordidx)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate x nodal coordinates in file id %d",
               exoid);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(EX_FATAL);
    }

    if (num_dim > 1) {
      if ((status = nc_inq_varid(exoid, VAR_COORD_Y, &coordidy)) != NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to locate y nodal coordinates in file id %d", exoid);
        ex_err(__func__, errmsg, status);
        EX_FUNC_LEAVE(EX_FATAL);
      }
    }
    else {
      coordidy = 0;
    }

    if (num_dim > 2) {
      if ((status = nc_inq_varid(exoid, VAR_COORD_Z, &coordidz)) != NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to locate z nodal coordinates in file id %d", exoid);
        ex_err(__func__, errmsg, status);
        EX_FUNC_LEAVE(EX_FATAL);
      }
    }
    else {
      coordidz = 0;
    }

    /* write out the coordinates  */
    for (i = 0; i < num_dim; i++) {
      void *coor  = NULL;
      char *which = NULL;

      start[0] = start_node_num;
      count[0] = num_nodes;
      if (count[0] == 0) {
        start[0] = 0;
      }

      if (i == 0) {
        coor    = x_coor;
        which   = "X";
        coordid = coordidx;
      }
      else if (i == 1) {
        coor    = y_coor;
        which   = "Y";
        coordid = coordidy;
      }
      else if (i == 2) {
        coor    = z_coor;
        which   = "Z";
        coordid = coordidz;
      }

      if (coor != NULL && coordid != 0) {
        if (ex_comp_ws(exoid) == 4) {
          status = nc_get_vara_float(exoid, coordid, start, count, coor);
        }
        else {
          status = nc_get_vara_double(exoid, coordid, start, count, coor);
        }

        if (status != NC_NOERR) {
          snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get %s coord array in file id %d",
                   which, exoid);
          ex_err(__func__, errmsg, status);
          EX_FUNC_LEAVE(EX_FATAL);
        }
      }
    }
  }
  EX_FUNC_LEAVE(EX_NOERR);
}
Ejemplo n.º 26
0
int ex_put_n_nodal_var (int   exoid,
                        int   time_step,
                        int   nodal_var_index,
                        int   start_node,
                        int   num_nodes, 
                        const void *nodal_var_vals)

{
  int status;
  int varid;
  size_t start[3], count[3];
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  if (ex_large_model(exoid) == 0) {
    /* write values of the nodal variable */
    if ((status = nc_inq_varid(exoid, VAR_NOD_VAR, &varid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Warning: could not find nodal variables in file id %d",
              exoid);
      ex_err("ex_put_n_nodal_var",errmsg,exerrval);
      return (EX_WARN);
    }
    start[0] = --time_step;
    start[1] = --nodal_var_index;
    start[2] = --start_node;

    count[0] = 1;
    count[1] = 1;
    count[2] = num_nodes;
  } else {
    /* nodal variables stored separately, find variable for this variable
       index */
    if ((status = nc_inq_varid(exoid, VAR_NOD_VAR_NEW(nodal_var_index), &varid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Warning: could not find nodal variable %d in file id %d",
              nodal_var_index, exoid);
      ex_err("ex_put_n_nodal_var",errmsg,exerrval);
      return (EX_WARN);
    }

    start[0] = --time_step;
    start[1] = --start_node;

    count[0] = 1;
    count[1] = num_nodes;
  }

  if (ex_comp_ws(exoid) == 4) {
    status = nc_put_vara_float(exoid, varid, start, count, nodal_var_vals);
  } else {
    status = nc_put_vara_double(exoid, varid, start, count, nodal_var_vals);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to store nodal variables in file id %d",
            exoid);
    ex_err("ex_put_n_nodal_var",errmsg,exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
Ejemplo n.º 27
0
int ex_get_partial_attr(int exoid, ex_entity_type obj_type, ex_entity_id obj_id, int64_t start_num,
                        int64_t num_ent, void *attrib)

{
  int         status;
  int         attrid, obj_id_ndx;
  int         temp;
  size_t      num_entries_this_obj, num_attr;
  size_t      start[2], count[2];
  char        errmsg[MAX_ERR_LENGTH];
  const char *dnumobjent;
  const char *dnumobjatt;
  const char *vattrbname;

  ex_check_valid_file_id(exoid);

  exerrval = 0; /* clear error code */

  if (num_ent == 0) {
    return 0;
  }
  /* Determine index of obj_id in vobjids array */
  if (obj_type != EX_NODAL) {
    obj_id_ndx = ex_id_lkup(exoid, obj_type, obj_id);
    if (exerrval != 0) {
      if (exerrval == EX_NULLENTITY) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "Warning: no attributes found for NULL %s %" PRId64 " in file id %d",
                 ex_name_of_object(obj_type), obj_id, exoid);
        ex_err("ex_get_partial_attr", errmsg, EX_NULLENTITY);
        return (EX_WARN); /* no attributes for this object */
      }
      snprintf(errmsg, MAX_ERR_LENGTH,
               "Warning: failed to locate %s id%" PRId64 " in id array in file id %d",
               ex_name_of_object(obj_type), obj_id, exoid);
      ex_err("ex_get_partial_attr", errmsg, exerrval);
      return (EX_WARN);
    }
  }

  switch (obj_type) {
  case EX_SIDE_SET:
    dnumobjent = DIM_NUM_SIDE_SS(obj_id_ndx);
    dnumobjatt = DIM_NUM_ATT_IN_SS(obj_id_ndx);
    vattrbname = VAR_SSATTRIB(obj_id_ndx);
    break;
  case EX_NODE_SET:
    dnumobjent = DIM_NUM_NOD_NS(obj_id_ndx);
    dnumobjatt = DIM_NUM_ATT_IN_NS(obj_id_ndx);
    vattrbname = VAR_NSATTRIB(obj_id_ndx);
    break;
  case EX_EDGE_SET:
    dnumobjent = DIM_NUM_EDGE_ES(obj_id_ndx);
    dnumobjatt = DIM_NUM_ATT_IN_ES(obj_id_ndx);
    vattrbname = VAR_ESATTRIB(obj_id_ndx);
    break;
  case EX_FACE_SET:
    dnumobjent = DIM_NUM_FACE_FS(obj_id_ndx);
    dnumobjatt = DIM_NUM_ATT_IN_FS(obj_id_ndx);
    vattrbname = VAR_FSATTRIB(obj_id_ndx);
    break;
  case EX_ELEM_SET:
    dnumobjent = DIM_NUM_ELE_ELS(obj_id_ndx);
    dnumobjatt = DIM_NUM_ATT_IN_ELS(obj_id_ndx);
    vattrbname = VAR_ELSATTRIB(obj_id_ndx);
    break;
  case EX_NODAL:
    dnumobjent = DIM_NUM_NODES;
    dnumobjatt = DIM_NUM_ATT_IN_NBLK;
    vattrbname = VAR_NATTRIB;
    break;
  case EX_EDGE_BLOCK:
    dnumobjent = DIM_NUM_ED_IN_EBLK(obj_id_ndx);
    dnumobjatt = DIM_NUM_ATT_IN_EBLK(obj_id_ndx);
    vattrbname = VAR_EATTRIB(obj_id_ndx);
    break;
  case EX_FACE_BLOCK:
    dnumobjent = DIM_NUM_FA_IN_FBLK(obj_id_ndx);
    dnumobjatt = DIM_NUM_ATT_IN_FBLK(obj_id_ndx);
    vattrbname = VAR_FATTRIB(obj_id_ndx);
    break;
  case EX_ELEM_BLOCK:
    dnumobjent = DIM_NUM_EL_IN_BLK(obj_id_ndx);
    dnumobjatt = DIM_NUM_ATT_IN_BLK(obj_id_ndx);
    vattrbname = VAR_ATTRIB(obj_id_ndx);
    break;
  default:
    exerrval = 1005;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "Internal ERROR: unrecognized object type in switch: %d in file id %d", obj_type,
             exoid);
    ex_err("ex_get_partial_attr", errmsg, EX_MSG);
    return (EX_FATAL); /* number of attributes not defined */
  }

  /* inquire id's of previously defined dimensions  */
  if (ex_get_dimension(exoid, dnumobjent, "entries", &num_entries_this_obj, &temp,
                       "ex_get_partial_attr") != NC_NOERR) {
    return EX_FATAL;
  }

  if (start_num + num_ent - 1 > num_entries_this_obj) {
    exerrval = EX_BADPARAM;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: start index (%" PRId64 ") + count (%" PRId64
             ") is larger than total number of entities (%" ST_ZU ") in file id %d",
             start_num, num_ent, num_entries_this_obj, exoid);
    ex_err("ex_get_partial_attr", errmsg, exerrval);
    return (EX_FATAL);
  }

  if (ex_get_dimension(exoid, dnumobjatt, "attributes", &num_attr, &temp, "ex_get_partial_attr") !=
      NC_NOERR) {
    return EX_FATAL;
  }

  if ((status = nc_inq_varid(exoid, vattrbname, &attrid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to locate attributes for %s %" PRId64 " in file id %d",
             ex_name_of_object(obj_type), obj_id, exoid);
    ex_err("ex_get_partial_attr", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* read in the attributes */
  start[0] = start_num - 1;
  start[1] = 0;

  count[0] = num_ent;
  count[1] = num_attr;

  if (ex_comp_ws(exoid) == 4) {
    status = nc_get_vara_float(exoid, attrid, start, count, attrib);
  }
  else {
    status = nc_get_vara_double(exoid, attrid, start, count, attrib);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to get attributes for %s %" PRId64 " in file id %d",
             ex_name_of_object(obj_type), obj_id, exoid);
    ex_err("ex_get_partial_attr", errmsg, exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
Ejemplo n.º 28
0
int ex_get_partial_elem_attr(int exoid, ex_entity_id elem_blk_id, int64_t start_elem_num,
                             int64_t num_elems, void *attrib)

{
  int    numelbdim, numattrdim, attrid, elem_blk_id_ndx, status;
  size_t num_elem_this_blk, num_attr, start[2], count[2];
  char   errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  /* Determine index of elem_blk_id in VAR_ID_EL_BLK array */
  if ((elem_blk_id_ndx = ex_id_lkup(exoid, EX_ELEM_BLOCK, elem_blk_id)) < 0) {
    if (exerrval == EX_NULLENTITY) {
      snprintf(errmsg, MAX_ERR_LENGTH,
               "Warning: no attributes found for NULL block %" PRId64 " in file id %d", elem_blk_id,
               exoid);
      ex_err("ex_get_partial_elem_attr", errmsg, EX_NULLENTITY);
      return (EX_WARN); /* no attributes for this element block */
    }
    snprintf(errmsg, MAX_ERR_LENGTH,
             "Warning: failed to locate element block %" PRId64 " in %s array in file id %d",
             elem_blk_id, VAR_ID_EL_BLK, exoid);
    ex_err("ex_get_partial_elem_attr", errmsg, exerrval);
    return (EX_WARN);
  }

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

  if ((status = nc_inq_dimid(exoid, DIM_NUM_EL_IN_BLK(elem_blk_id_ndx), &numelbdim)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to locate number of elements for block %" PRId64 " in file id %d",
             elem_blk_id, exoid);
    ex_err("ex_get_partial_elem_attr", errmsg, exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_inq_dimlen(exoid, numelbdim, &num_elem_this_blk)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to get number of elements for block %" PRId64 " in file id %d",
             elem_blk_id, exoid);
    ex_err("ex_get_partial_elem_attr", errmsg, exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_BLK(elem_blk_id_ndx), &numattrdim)) !=
      NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "Warning: no attributes found for block %" PRId64 " in file id %d", elem_blk_id,
             exoid);
    ex_err("ex_get_partial_elem_attr", errmsg, EX_MSG);
    return (EX_WARN); /* no attributes for this element block */
  }

  if ((status = nc_inq_dimlen(exoid, numattrdim, &num_attr)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to get number of attributes for block %" PRId64 " in file id %d",
             elem_blk_id, exoid);
    ex_err("ex_get_partial_elem_attr", errmsg, exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_inq_varid(exoid, VAR_ATTRIB(elem_blk_id_ndx), &attrid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to locate attributes for block %" PRId64 " in file id %d", elem_blk_id,
             exoid);
    ex_err("ex_get_partial_elem_attr", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* do some error checking */
  if (num_elem_this_blk < (start_elem_num + num_elems - 1)) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: requested attributes from too many elements in "
                                     "this block, %" PRId64 "",
             elem_blk_id);
    ex_err("ex_get_partial_elem_attr", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* read in the attributes */

  start[0] = --start_elem_num;
  start[1] = 0;

  count[0] = num_elems;
  count[1] = num_attr;

  if (ex_comp_ws(exoid) == 4) {
    status = nc_get_vara_float(exoid, attrid, start, count, attrib);
  }
  else {
    status = nc_get_vara_double(exoid, attrid, start, count, attrib);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to get attributes for block %" PRId64 " in file id %d", elem_blk_id,
             exoid);
    ex_err("ex_get_partial_elem_attr", errmsg, exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
Ejemplo n.º 29
0
int ex_put_partial_set_dist_fact (int   exoid,
                                  ex_entity_type set_type,
                                  ex_entity_id   set_id,
                                  int64_t   offset,
                                  int64_t   num_to_put,
                                  const void *set_dist_fact)
{
    int status;
    int dimid, set_id_ndx;
    int dist_id;
    size_t start[1], count[1];
    char errmsg[MAX_ERR_LENGTH];
    char* factptr = NULL;

    exerrval = 0; /* clear error code */

    /* first check if any sets are specified */
    if ((status = nc_inq_dimid(exoid, ex_dim_num_objects(set_type), &dimid)) != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
                "Error: no %ss specified in file id %d",
                ex_name_of_object(set_type), exoid);
        ex_err("ex_put_set_dist_fact",errmsg,exerrval);
        return (EX_FATAL);
    }

    /* Lookup index of set id in VAR_*S_IDS array */
    set_id_ndx = ex_id_lkup(exoid,set_type,set_id);
    if (exerrval != 0) {
        if (exerrval == EX_NULLENTITY) {
            sprintf(errmsg,
                    "Warning: no data allowed for NULL %s %"PRId64" in file id %d",
                    ex_name_of_object(set_type), set_id,exoid);
            ex_err("ex_put_set_fact",errmsg,EX_NULLENTITY);
            return (EX_WARN);
        } else {
            sprintf(errmsg,
                    "Error: failed to locate %s id %"PRId64" in VAR_*S_IDS array in file id %d",
                    ex_name_of_object(set_type), set_id,exoid);
            ex_err("ex_put_set_dist_fact",errmsg,exerrval);
            return (EX_FATAL);
        }
    }

    /* setup more pointers based on set_type */
    if (set_type == EX_NODE_SET) {
        /* note we are using DIM_NUM_NODE_NS instead of DIM_NUM_DF_NS */
        factptr = VAR_FACT_NS(set_id_ndx);
    }
    else if (set_type == EX_EDGE_SET) {
        factptr = VAR_FACT_ES(set_id_ndx);
    }
    else if (set_type == EX_FACE_SET) {
        factptr = VAR_FACT_FS(set_id_ndx);
    }
    else if (set_type == EX_SIDE_SET) {
        factptr = VAR_FACT_SS(set_id_ndx);
    }
    if (set_type == EX_ELEM_SET) {
        factptr = VAR_FACT_ELS(set_id_ndx);
    }

    /* find id of distribution factors variable
     */

    if ((status = nc_inq_varid(exoid, factptr, &dist_id)) != NC_NOERR) {
        /* this test is only needed for node set because we're using
           DIM_NUM_NOD_NS instead of  DIM_NUM_DF_NS*/
        if (status == NC_ENOTVAR) {
            exerrval = EX_BADPARAM;
            sprintf(errmsg,
                    "Warning: no dist factors defined for %s %"PRId64" in file id %d",
                    ex_name_of_object(set_type), set_id, exoid);
            ex_err("ex_put_set_dist_fact",errmsg,exerrval);
            return (EX_WARN);
        } else  {
            exerrval = status;
            sprintf(errmsg,
                    "Error: failed to locate dist factors list for %s %"PRId64" in file id %d",
                    ex_name_of_object(set_type), set_id,exoid);
            ex_err("ex_put_set_dist_fact",errmsg,exerrval);
            return (EX_FATAL);
        }
    }

    start[0] = offset-1;
    count[0] = num_to_put;
    if (num_to_put == 0)
        start[0] = 0;

    /* write out the distribution factors array */
    if (ex_comp_ws(exoid) == 4) {
        status = nc_put_vara_float(exoid, dist_id, start, count, set_dist_fact);
    } else {
        status = nc_put_vara_double(exoid, dist_id, start, count, set_dist_fact);
    }

    if (status != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to store dist factors for %s %"PRId64" in file id %d",
                ex_name_of_object(set_type), set_id,exoid);
        ex_err("ex_put_partial_set_dist_fact",errmsg,exerrval);
        return (EX_FATAL);
    }
    return (EX_NOERR);
}
Ejemplo n.º 30
0
int ex_get_nodal_var_time (int   exoid,
                           int   nodal_var_index,
                           int   node_number,
                           int   beg_time_step,
                           int   end_time_step,
                           void *nodal_var_vals)
{
    int status;
    int varid;
    size_t start[3], count[3];
    float fdum;
    char *cdum = 0;
    char errmsg[MAX_ERR_LENGTH];

    /* inquire previously defined variable */
    if (end_time_step < 0) {

        /* user is requesting the maximum time step;  we find this out using the
         * database inquire function to get the number of time steps;  the ending
         * time step number is 1 less due to 0 based array indexing in C
         */
        if ((status = ex_inquire (exoid, EX_INQ_TIME, &end_time_step, &fdum, cdum)) != NC_NOERR) {
            exerrval = status;
            sprintf(errmsg,
                    "Error: failed to get number of time steps in file id %d",
                    exoid);
            ex_err("ex_get_nodal_var_time",errmsg,exerrval);
            return (EX_FATAL);
        }
    }

    end_time_step--;

    if (ex_large_model(exoid) == 0) {
        /* read values of the nodal variable;
         * assume node number is 1-based (first node is numbered 1);  adjust
         * so it is 0-based
         */
        if ((status = nc_inq_varid(exoid, VAR_NOD_VAR, &varid)) != NC_NOERR) {
            exerrval = status;
            sprintf(errmsg,
                    "Warning: could not find nodal variable %d in file id %d",
                    nodal_var_index, exoid);
            ex_err("ex_get_nodal_var",errmsg,exerrval);
            return (EX_WARN);
        }

        start[0] = --beg_time_step;
        start[1] = --nodal_var_index;
        start[2] = --node_number;

        count[0] = end_time_step - beg_time_step + 1;
        count[1] = 1;
        count[2] = 1;
    } else {
        if ((status = nc_inq_varid(exoid, VAR_NOD_VAR_NEW(nodal_var_index), &varid)) != NC_NOERR) {
            exerrval = status;
            sprintf(errmsg,
                    "Warning: could not find nodal variable %d in file id %d",
                    nodal_var_index, exoid);
            ex_err("ex_get_nodal_var",errmsg,exerrval);
            return (EX_WARN);
        }

        /* read values of the nodal variable;
         * assume node number is 1-based (first node is numbered 1);  adjust
         * so it is 0-based
         */

        start[0] = --beg_time_step;
        start[1] = --node_number;

        count[0] = end_time_step - beg_time_step + 1;
        count[1] = 1;
    }

    if (ex_comp_ws(exoid) == 4) {
        status = nc_get_vara_float(exoid, varid, start, count, nodal_var_vals);
    } else {
        status = nc_get_vara_double(exoid, varid, start, count, nodal_var_vals);
    }

    if (status != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to get nodal variables in file id %d",
                exoid);
        ex_err("ex_get_nodal_var_time",errmsg,exerrval);
        return (EX_FATAL);
    }
    return (EX_NOERR);
}