示例#1
0
int ex_get_prop_names (int    exoid,
                       int    obj_type,
                       char **prop_names)
{
   int i, num_props, propid;
   char var_name[12];

   char errmsg[MAX_ERR_LENGTH];

   exerrval = 0;

/* determine which type of object property names are desired for */

   num_props = ex_get_num_props (exoid, obj_type);

   for (i=0; i<num_props; i++)
   {
     switch (obj_type)
     {
       case EX_ELEM_BLOCK:
         strcpy (var_name, VAR_EB_PROP(i+1));
         break;
       case EX_NODE_SET:
         strcpy (var_name, VAR_NS_PROP(i+1));
         break;
       case EX_SIDE_SET:
         strcpy (var_name, VAR_SS_PROP(i+1));
         break;
       case EX_ELEM_MAP:
         strcpy (var_name, VAR_EM_PROP(i+1));
         break;
       case EX_NODE_MAP:
         strcpy (var_name, VAR_NM_PROP(i+1));
         break;
       default:
         exerrval = EX_BADPARAM;
         sprintf(errmsg, "Error: object type %d not supported; file id %d",
           obj_type, exoid);
         ex_err("ex_get_prop_names",errmsg,EX_BADPARAM);
         return(EX_FATAL);
     }

     if ((propid = ncvarid (exoid, var_name)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
          "Error: failed to locate property array %s in file id %d",
               var_name, exoid);
       ex_err("ex_get_prop_names",errmsg,exerrval);
       return (EX_FATAL);
     }

/*   for each property, read the "name" attribute of property array variable */

     if ((ncattget (exoid, propid, ATT_PROP_NAME, prop_names[i])) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Error: failed to get property name in file id %d", exoid);
       ex_err("ex_get_prop_names",errmsg,exerrval);
       return (EX_FATAL);
     }
   }

   return (EX_NOERR);

}
示例#2
0
int ex_get_prop_array(int exoid, ex_entity_type obj_type, const char *prop_name, void_int *values)
{
  int   num_props, i, propid, status;
  int   found = EX_FALSE;
  char *name;
  char  tmpstr[MAX_STR_LENGTH + 1];

  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  /* open appropriate variable, depending on obj_type and prop_name */

  num_props = ex_get_num_props(exoid, obj_type);

  for (i = 1; i <= num_props; i++) {
    switch (obj_type) {
    case EX_ELEM_BLOCK: name = VAR_EB_PROP(i); break;
    case EX_EDGE_BLOCK: name = VAR_ED_PROP(i); break;
    case EX_FACE_BLOCK: name = VAR_FA_PROP(i); break;
    case EX_NODE_SET: name   = VAR_NS_PROP(i); break;
    case EX_EDGE_SET: name   = VAR_ES_PROP(i); break;
    case EX_FACE_SET: name   = VAR_FS_PROP(i); break;
    case EX_ELEM_SET: name   = VAR_ELS_PROP(i); break;
    case EX_SIDE_SET: name   = VAR_SS_PROP(i); break;
    case EX_ELEM_MAP: name   = VAR_EM_PROP(i); break;
    case EX_FACE_MAP: name   = VAR_FAM_PROP(i); break;
    case EX_EDGE_MAP: name   = VAR_EDM_PROP(i); break;
    case EX_NODE_MAP: name   = VAR_NM_PROP(i); break;
    default:
      exerrval = EX_BADPARAM;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: object type %d not supported; file id %d", obj_type,
               exoid);
      ex_err("ex_get_prop_array", errmsg, exerrval);
      return (EX_FATAL);
    }

    if ((status = nc_inq_varid(exoid, name, &propid)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate property array %s in file id %d",
               name, exoid);
      ex_err("ex_get_prop_array", errmsg, exerrval);
      return (EX_FATAL);
    }

    /*   compare stored attribute name with passed property name   */
    memset(tmpstr, 0, MAX_STR_LENGTH + 1);
    if ((status = nc_get_att_text(exoid, propid, ATT_PROP_NAME, tmpstr)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get property name in file id %d", exoid);
      ex_err("ex_get_prop_array", errmsg, exerrval);
      return (EX_FATAL);
    }

    if (strcmp(tmpstr, prop_name) == 0) {
      found = EX_TRUE;
      break;
    }
  }

  /* if property is not found, return warning */
  if (!found) {
    exerrval = EX_BADPARAM;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "Warning: object type %d, property %s not defined in file id %d", obj_type, prop_name,
             exoid);
    ex_err("ex_get_prop_array", errmsg, exerrval);
    return (EX_WARN);
  }

  /* read num_obj values from property variable */
  if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
    status = nc_get_var_longlong(exoid, propid, values);
  }
  else {
    status = nc_get_var_int(exoid, propid, values);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to read values in %s property array in file id %d",
             ex_name_of_object(obj_type), exoid);
    ex_err("ex_get_prop_array", errmsg, exerrval);
    return (EX_FATAL);
  }

  return (EX_NOERR);
}
示例#3
0
int ex_put_prop_array(int exoid, ex_entity_type obj_type, const char *prop_name,
                      const void_int *values)
{
  int    oldfill = 0;
  int    temp;
  int    num_props, i, propid, dimid, dims[1], status;
  int    found = EX_FALSE;
  int    int_type;
  size_t num_obj;
  char * name;
  char   tmpstr[MAX_STR_LENGTH + 1];

  char errmsg[MAX_ERR_LENGTH];

  EX_FUNC_ENTER();
  ex_check_valid_file_id(exoid, __func__);

  /* check if property has already been created */

  num_props = ex_get_num_props(exoid, obj_type);

  /* inquire id of previously defined dimension (number of objects) */
  status = ex_get_dimension(exoid, ex_dim_num_objects(obj_type), ex_name_of_object(obj_type),
                            &num_obj, &dimid, __func__);
  if (status != NC_NOERR) {
    EX_FUNC_LEAVE(status);
  }

  for (i = 1; i <= num_props; i++) {
    switch (obj_type) {
    case EX_ELEM_BLOCK: name = VAR_EB_PROP(i); break;
    case EX_FACE_BLOCK: name = VAR_FA_PROP(i); break;
    case EX_EDGE_BLOCK: name = VAR_ED_PROP(i); break;
    case EX_NODE_SET: name = VAR_NS_PROP(i); break;
    case EX_EDGE_SET: name = VAR_ES_PROP(i); break;
    case EX_FACE_SET: name = VAR_FS_PROP(i); break;
    case EX_ELEM_SET: name = VAR_ELS_PROP(i); break;
    case EX_SIDE_SET: name = VAR_SS_PROP(i); break;
    case EX_ELEM_MAP: name = VAR_EM_PROP(i); break;
    case EX_FACE_MAP: name = VAR_FAM_PROP(i); break;
    case EX_EDGE_MAP: name = VAR_EDM_PROP(i); break;
    case EX_NODE_MAP: name = VAR_NM_PROP(i); break;
    default:
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: object type %d not supported; file id %d", obj_type,
               exoid);
      ex_err(__func__, errmsg, EX_BADPARAM);
      EX_FUNC_LEAVE(EX_FATAL);
    }

    if ((status = nc_inq_varid(exoid, name, &propid)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get property array id in file id %d",
               exoid);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(EX_FATAL);
    }

    /* compare stored attribute name with passed property name   */
    memset(tmpstr, 0, MAX_STR_LENGTH + 1);
    if ((status = nc_get_att_text(exoid, propid, ATT_PROP_NAME, tmpstr)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get property name in file id %d", exoid);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(EX_FATAL);
    }

    if (strcmp(tmpstr, prop_name) == 0) {
      found = EX_TRUE;
      break;
    }
  }

  /* if property array has not been created, create it */
  if (!found) {

    /* put netcdf file into define mode  */
    if ((status = nc_redef(exoid)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to place file id %d into define mode", exoid);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(EX_FATAL);
    }

    /*   create a variable with a name xx_prop#, where # is the new number   */
    /*   of properties                                                       */
    switch (obj_type) {
    case EX_ELEM_BLOCK: name = VAR_EB_PROP(num_props + 1); break;
    case EX_FACE_BLOCK: name = VAR_FA_PROP(num_props + 1); break;
    case EX_EDGE_BLOCK: name = VAR_ED_PROP(num_props + 1); break;
    case EX_NODE_SET: name = VAR_NS_PROP(num_props + 1); break;
    case EX_EDGE_SET: name = VAR_ES_PROP(num_props + 1); break;
    case EX_FACE_SET: name = VAR_FS_PROP(num_props + 1); break;
    case EX_ELEM_SET: name = VAR_ELS_PROP(num_props + 1); break;
    case EX_SIDE_SET: name = VAR_SS_PROP(num_props + 1); break;
    case EX_ELEM_MAP: name = VAR_EM_PROP(num_props + 1); break;
    case EX_FACE_MAP: name = VAR_FAM_PROP(num_props + 1); break;
    case EX_EDGE_MAP: name = VAR_EDM_PROP(num_props + 1); break;
    case EX_NODE_MAP: name = VAR_NM_PROP(num_props + 1); break;
    default:
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: object type %d not supported; file id %d", obj_type,
               exoid);
      ex_err(__func__, errmsg, EX_BADPARAM);
      goto error_ret; /* Exit define mode and return */
    }

    dims[0] = dimid;
    nc_set_fill(exoid, NC_FILL, &oldfill); /* fill with zeros per routine spec */

    int_type = NC_INT;
    if (ex_int64_status(exoid) & EX_IDS_INT64_DB) {
      int_type = NC_INT64;
    }

    if ((status = nc_def_var(exoid, name, int_type, 1, dims, &propid)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to create property array variable in file id %d", exoid);
      ex_err(__func__, errmsg, status);
      goto error_ret; /* Exit define mode and return */
    }
    nc_set_fill(exoid, oldfill, &temp); /* default: nofill */

    /*   store property name as attribute of property array variable */
    if ((status = nc_put_att_text(exoid, propid, ATT_PROP_NAME, strlen(prop_name) + 1,
                                  prop_name)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store property name %s in file id %d",
               prop_name, exoid);
      ex_err(__func__, errmsg, status);
      goto error_ret; /* Exit define mode and return */
    }

    /* leave define mode  */

    if ((status = nc_enddef(exoid)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to leave define mode in file id %d", exoid);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(EX_FATAL);
    }
  }

  /* put num_obj values in property array */
  if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
    status = nc_put_var_longlong(exoid, propid, values);
  }
  else {
    status = nc_put_var_int(exoid, propid, values);
  }

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

  EX_FUNC_LEAVE(EX_NOERR);

/* Fatal error: exit definition mode and return */
error_ret:
  nc_set_fill(exoid, oldfill, &temp);            /* default: nofill */
  if ((status = 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(__func__, errmsg, status);
  }
  EX_FUNC_LEAVE(EX_FATAL);
}
示例#4
0
int ex_put_prop_array (int   exoid,
                       int   obj_type,
                       const char *prop_name,
                       const int  *values)
{
   int num_props, i, propid, dimid, dims[1], iresult;
   int found = FALSE;
   long start[1], count[1], num_obj; 
   nclong *lptr;
   char name[MAX_VAR_NAME_LENGTH+1];
   char tmpstr[MAX_STR_LENGTH+1];
   char obj_stype[MAX_VAR_NAME_LENGTH+1];
   char dim_name[MAX_VAR_NAME_LENGTH+1];

   char errmsg[MAX_ERR_LENGTH];

   exerrval  = 0; /* clear error code */

/* check if property has already been created */

   num_props = ex_get_num_props(exoid, obj_type);

   switch (obj_type)
   {
     case EX_ELEM_BLOCK:
       strcpy (obj_stype, VAR_ID_EL_BLK);
       strcpy (dim_name, DIM_NUM_EL_BLK);
       break;
     case EX_NODE_SET:
       strcpy (obj_stype, VAR_NS_IDS);
       strcpy (dim_name, DIM_NUM_NS);
       break;
     case EX_SIDE_SET:
       strcpy (obj_stype, VAR_SS_IDS);
       strcpy (dim_name, DIM_NUM_SS);
       break;
     case EX_ELEM_MAP:
       strcpy (obj_stype, VAR_EM_PROP(1));
       strcpy (dim_name, DIM_NUM_EM);
       break;
     case EX_NODE_MAP:
       strcpy (obj_stype, VAR_NM_PROP(1));
       strcpy (dim_name, DIM_NUM_NM);
       break;
     default:
       exerrval = EX_BADPARAM;
       sprintf(errmsg, "Error: object type %d not supported; file id %d",
               obj_type, exoid);
       ex_err("ex_put_prop_array",errmsg,exerrval);
       return (EX_FATAL);
   }
/*   inquire id of previously defined dimension (number of objects) */

     if ((dimid = ncdimid (exoid, dim_name)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Error: failed to locate number of %s objects in file id %d",
               obj_stype, exoid);
       ex_err("ex_put_prop_array",errmsg, exerrval);
       return (EX_FATAL);
     }

/*   get number of objects */

     if (ncdiminq (exoid, dimid, dim_name, &num_obj) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Error: failed to get number of %s objects in file id %d",
               obj_stype, exoid);
       ex_err("ex_put_prop_array",errmsg, exerrval);
       return (EX_FATAL);
     }



   for (i=1; i<=num_props; i++)
   {
     switch (obj_type){
       case EX_ELEM_BLOCK:
         strcpy (name, VAR_EB_PROP(i));
         break;
       case EX_NODE_SET:
         strcpy (name, VAR_NS_PROP(i));
         break;
       case EX_SIDE_SET:
         strcpy (name, VAR_SS_PROP(i));
         break;
       case EX_ELEM_MAP:
         strcpy (name, VAR_EM_PROP(i));
         break;
       case EX_NODE_MAP:
         strcpy (name, VAR_NM_PROP(i));
         break;
       default:
         exerrval = EX_BADPARAM;
         sprintf(errmsg, "Error: object type %d not supported; file id %d",
           obj_type, exoid);
         ex_err("ex_put_prop_array",errmsg,exerrval);
         return(EX_FATAL);
     }

     if ((propid = ncvarid (exoid, name)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
          "Error: failed to get property array id in file id %d",
               exoid);
       ex_err("ex_put_prop_array",errmsg,exerrval);
       return (EX_FATAL);
     }

/*   compare stored attribute name with passed property name   */

     memset(tmpstr, 0, MAX_STR_LENGTH+1);
     if ((ncattget (exoid, propid, ATT_PROP_NAME, tmpstr)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Error: failed to get property name in file id %d", exoid);
       ex_err("ex_put_prop_array",errmsg,exerrval);
       return (EX_FATAL);
     }

     if (strcmp(tmpstr, prop_name) == 0) 
     {
       found = TRUE;
       break;
     }
   }

/* if property array has not been created, create it */

   if (!found)
   {
/* put netcdf file into define mode  */

     if (ncredef (exoid) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,"Error: failed to place file id %d into define mode",exoid);
       ex_err("ex_put_prop_array",errmsg,exerrval);
       return (EX_FATAL);
     }

/*   create a variable with a name xx_prop#, where # is the new number   */
/*   of properties                                                       */

     switch (obj_type){
       case EX_ELEM_BLOCK:
         strcpy (name, VAR_EB_PROP(num_props+1));
         break;
       case EX_NODE_SET:
         strcpy (name, VAR_NS_PROP(num_props+1));
         break;
       case EX_SIDE_SET:
         strcpy (name, VAR_SS_PROP(num_props+1));
         break;
       case EX_ELEM_MAP:
         strcpy (name, VAR_EM_PROP(num_props+1));
         break;
       case EX_NODE_MAP:
         strcpy (name, VAR_NM_PROP(num_props+1));
         break;
       default:
         exerrval = EX_BADPARAM;
         sprintf(errmsg, "Error: object type %d not supported; file id %d",
           obj_type, exoid);
         ex_err("ex_put_prop_array",errmsg,exerrval);
         goto error_ret;        /* Exit define mode and return */
     }

     dims[0] = dimid;
     ncsetfill(exoid, NC_FILL); /* fill with zeros per routine spec */

     if ((propid = ncvardef (exoid, name, NC_LONG, 1, dims)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
          "Error: failed to create property array variable in file id %d",
               exoid);
       ex_err("ex_put_prop_array",errmsg,exerrval);
       goto error_ret;  /* Exit define mode and return */
     }
     ncsetfill(exoid, NC_NOFILL); /* default: nofill */


/*   store property name as attribute of property array variable */

     if ((ncattput (exoid, propid, ATT_PROP_NAME, NC_CHAR,
                    strlen(prop_name)+1, prop_name)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Error: failed to store property name %s in file id %d",
               prop_name,exoid);
       ex_err("ex_put_prop_array",errmsg,exerrval);
       goto error_ret;  /* Exit define mode and return */
     }

/* leave define mode  */

     if (ncendef (exoid) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to leave define mode in file id %d",
          exoid);
       ex_err("ex_put_prop_array",errmsg,exerrval);
       return (EX_FATAL);
     }

   }

/* put num_obj values in property array */

/* this contortion is necessary because netCDF is expecting nclongs; fortunately
   it's necessary only when ints and nclongs aren't the same size  */

   start[0] = 0;
   count[0] = num_obj;

   if (sizeof(int) == sizeof(nclong)) {
      iresult = ncvarput (exoid, propid, start, count, values);
   } else {
      lptr = itol (values, (int)num_obj);
      iresult = ncvarput (exoid, propid, start, count, lptr);
      free(lptr);
   }

   if (iresult == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to store property values in file id %d",
             exoid);
     ex_err("ex_put_prop_array",errmsg,exerrval);
     return (EX_FATAL);
   }


   return (EX_NOERR);

/* Fatal error: exit definition mode and return */
error_ret:
  ncsetfill(exoid, NC_NOFILL); /* default: nofill */
  if (ncendef (exoid) == -1)     /* exit define mode */
  {
    sprintf(errmsg,
           "Error: failed to complete definition for file id %d",
            exoid);
    ex_err("ex_put_prop_array",errmsg,exerrval);
  }
  return (EX_FATAL);
}
示例#5
0
static int ex_inquire_internal (int      exoid,
				int      req_info,
				int64_t *ret_int,
				float   *ret_float,
				char    *ret_char)
{
  int dimid, varid, tmp_num;
  void_int *ids = NULL;
  size_t i;
  size_t ldum = 0;
  size_t num_sets, idum;
  int *stat_vals;
  char  errmsg[MAX_ERR_LENGTH];
  int status;
  char tmp_title[2048];

  exerrval = 0; /* clear error code */

  if (ret_char)  *ret_char  = '\0';  /* Only needs to be non-null for TITLE */
  
  if (!ret_int) {
    exerrval = EX_BADPARAM;
    sprintf(errmsg,
	    "Warning: integer argument is NULL which is not allowed.");
    ex_err("ex_inquire",errmsg,exerrval);
    return (EX_FATAL);
  }
    

  switch (req_info) {
  case EX_INQ_FILE_TYPE:

    /* obsolete call */
    /*returns "r" for regular EXODUS II file or "h" for history EXODUS file*/
    exerrval = EX_BADPARAM;
    sprintf(errmsg,
	    "Warning: file type inquire is obsolete");
    ex_err("ex_inquire",errmsg,exerrval);
    return (EX_WARN);

  case EX_INQ_API_VERS:
    /* returns the EXODUS II API version number */
    if (!ret_float) {
      exerrval = EX_BADPARAM;
      sprintf(errmsg,
	      "Warning: float argument is NULL for EX_INQ_API_VERS which is not allowed.");
      ex_err("ex_inquire",errmsg,exerrval);
      return (EX_FATAL);
    }

    if (nc_get_att_float(exoid, NC_GLOBAL, ATT_API_VERSION, ret_float) != NC_NOERR)
      {  /* try old (prior to db version 2.02) attribute name */
	if ((status = nc_get_att_float (exoid, NC_GLOBAL, ATT_API_VERSION_BLANK,ret_float)) != NC_NOERR) {
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: failed to get EXODUS API version for file id %d", exoid);
	  ex_err("ex_inquire",errmsg,exerrval);
	  return (EX_FATAL);
	}
      }

    break;

  case EX_INQ_DB_VERS:
    /* returns the EXODUS II database version number */
    if (!ret_float) {
      exerrval = EX_BADPARAM;
      sprintf(errmsg,
	      "Warning: float argument is NULL for EX_INQ_DB_VERS which is not allowed.");
      ex_err("ex_inquire",errmsg,exerrval);
      return (EX_FATAL);
    }

    if ((status = nc_get_att_float (exoid, NC_GLOBAL, ATT_VERSION, ret_float)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to get EXODUS database version for file id %d", exoid);
      ex_err("ex_inquire",errmsg,exerrval);
      return (EX_FATAL);
    }
    break;

  case EX_INQ_LIB_VERS:
    /* returns the EXODUS II Library version number */
    if (ret_float)
      flt_cvt(ret_float, EX_API_VERS);

    *ret_int = EX_API_VERS_NODOT;
    break;

  case EX_INQ_DB_MAX_ALLOWED_NAME_LENGTH:
    /* Return the MAX_NAME_LENGTH size for this database
       It will not include the space for the trailing null, so if it
       is defined as 33 on the database, 32 will be returned.
    */
    if ((status = nc_inq_dimid(exoid, DIM_STR_NAME, &dimid)) != NC_NOERR) {
      /* If not found, then an older database */
      *ret_int = 32;
    }
    else {
      /* Get the name string length */
      size_t name_length = 0;
      if ((status = nc_inq_dimlen(exoid,dimid,&name_length)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get name string length in file id %d", exoid);
	ex_err("ex_inquire",errmsg,exerrval);
	return (EX_FATAL);
      }
      else {
	*ret_int = name_length-1;
      }
    }
    break;

  case EX_INQ_DB_MAX_USED_NAME_LENGTH:
    /* Return the value of the ATT_MAX_NAME_LENGTH attribute (if it
       exists) which is the maximum length of any entity, variable,
       attribute, property name written to this database.  If the
       attribute does not exist, then '32' is returned.  The length
       does not include the trailing null.
    */
    {
      nc_type att_type = NC_NAT;
      size_t att_len = 0;
	
      *ret_int = 32; /* Default size consistent with older databases */

      status = nc_inq_att(exoid, NC_GLOBAL, ATT_MAX_NAME_LENGTH, &att_type, &att_len);
      if (status == NC_NOERR && att_type == NC_INT) {
	/* The attribute exists, return it... */
	nc_get_att_longlong(exoid, NC_GLOBAL, ATT_MAX_NAME_LENGTH, (long long*)ret_int);
      }
    }
    break;

  case EX_INQ_MAX_READ_NAME_LENGTH:
    {
      /* Returns the user-specified maximum size of names that will be
       * returned to the user by any of the ex_get_ routines.  If the
       * name is longer than this value, it will be truncated. The
       * default if not set by the client is 32 characters. The value
       * does not include the trailing null.
       */
      struct file_item* file = ex_find_file_item(exoid);

      if (!file ) {
	exerrval = EX_BADFILEID;
	sprintf(errmsg,"Error: unknown file id %d for ex_inquire_int().",exoid);
	ex_err("ex_intquire",errmsg,exerrval);
	*ret_int = 0;
      }
      else {
	*ret_int = file->maximum_name_length;
      }
    }
    break;

  case EX_INQ_TITLE:
    if (!ret_char) {
      sprintf(errmsg,
	      "Error: Requested title, but character pointer was null for file id %d", exoid);
      ex_err("ex_inquire",errmsg,exerrval);
      return (EX_FATAL);
    } else {
      /* returns the title of the database */
      if ((status = nc_get_att_text (exoid, NC_GLOBAL, ATT_TITLE, tmp_title)) != NC_NOERR) {
	*ret_char = '\0';
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get database title for file id %d", exoid);
	ex_err("ex_inquire",errmsg,exerrval);
	return (EX_FATAL);
      } else {
	strncpy(ret_char, tmp_title, MAX_LINE_LENGTH+1);
	ret_char[MAX_LINE_LENGTH] = '\0';
      }
    }
    break;

  case EX_INQ_DIM:
    /* returns the dimensionality (2 or 3, for 2-d or 3-d) of the database */
    if (ex_get_dimension(exoid, DIM_NUM_DIM, "database dimensionality", &ldum, &dimid, "ex_inquire") != NC_NOERR)
      return EX_FATAL;
    *ret_int = ldum;
    break;

  case EX_INQ_NODES:
    /* returns the number of nodes */
    if (ex_get_dimension(exoid, DIM_NUM_NODES, "nodes", &ldum, &dimid, NULL) != NC_NOERR)
      *ret_int = 0;
    else
      *ret_int = ldum;
    break;

  case EX_INQ_ELEM:
    /* returns the number of elements */
    if (ex_get_dimension(exoid, DIM_NUM_ELEM, "elements", &ldum, &dimid, NULL) != NC_NOERR)
      *ret_int = 0;
    else
      *ret_int = ldum;
    break;

  case EX_INQ_ELEM_BLK:
    /* returns the number of element blocks */
    if (ex_get_dimension(exoid, DIM_NUM_EL_BLK, "element blocks", &ldum, &dimid, NULL) != NC_NOERR)
      *ret_int = 0;
    else
      *ret_int = ldum;
    break;

  case EX_INQ_NODE_SETS:
    /* returns the number of node sets */
    if (ex_get_dimension(exoid, DIM_NUM_NS, "node sets", &ldum, &dimid, NULL) != NC_NOERR)
      *ret_int = 0;
    else
      *ret_int = ldum;
    break;

  case EX_INQ_NS_NODE_LEN:
    /* returns the length of the concatenated node sets node list */
    ex_get_concat_set_len(exoid, ret_int,"node",EX_NODE_SET,DIM_NUM_NS,VAR_NS_STAT,"num_nod_ns",0);
    break;

  case EX_INQ_NS_DF_LEN:
    /*     returns the length of the concatenated node sets dist factor list */

    /*
      Determine the concatenated node sets distribution factor length:

      2. Check see if the dist factor variable for a node set id exists.
      3. If it exists, goto step 4, else the length is zero.
      4. Get the dimension of the number of nodes in the node set -0
      use this value as the length as by definition they are the same.
      5. Sum the individual lengths for the total list length.
    */

    *ret_int = 0;    /* default value if no node sets defined */

    if (nc_inq_dimid (exoid, DIM_NUM_NS, &dimid) == NC_NOERR) {
      if ((status = nc_inq_dimlen(exoid, dimid, &num_sets)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get number of node sets in file id %d",
		exoid);
	ex_err("ex_inquire",errmsg,exerrval);
	return (EX_FATAL);
      }


      for (i=0; i<num_sets; i++) {
	if ((status = nc_inq_varid (exoid, VAR_FACT_NS(i+1), &varid)) != NC_NOERR) {
	  if (status == NC_ENOTVAR) {
	    idum = 0;        /* this dist factor doesn't exist */
	  } else {
	    *ret_int = 0;
	    exerrval = status;
	    sprintf(errmsg,
		    "Error: failed to locate number of dist fact for %"ST_ZU"'th node set in file id %d",
		    i, exoid);
	    ex_err("ex_inquire",errmsg,exerrval);
	    return (EX_FATAL);
	  }
	} else {
	  if ((status = nc_inq_dimid (exoid, DIM_NUM_NOD_NS(i+1), &dimid)) != NC_NOERR) {
	    *ret_int = 0;
	    exerrval = status;
	    sprintf(errmsg,
		    "Error: failed to locate number of nodes in %"ST_ZU"'th node set in file id %d",
		    i, exoid);
	    ex_err("ex_inquire",errmsg,exerrval);
	    return (EX_FATAL);
	  }
	  if ((status = nc_inq_dimlen (exoid, dimid, &idum)) != NC_NOERR) {
	    *ret_int = 0;
	    exerrval = status;
	    sprintf(errmsg,
		    "Error: failed to get number of nodes in %"ST_ZU"'th node set in file id %d",
		    i,exoid);
	    ex_err("ex_inquire",errmsg,exerrval);
	    return (EX_FATAL);
	  }
	}
	*ret_int += idum;
      }
    }

    break;

  case EX_INQ_SIDE_SETS:
    /* returns the number of side sets */
    if (ex_get_dimension(exoid, DIM_NUM_SS, "side sets", &ldum, &dimid, NULL) != NC_NOERR)
      *ret_int = 0;
    else
      *ret_int = ldum;
    break;

  case EX_INQ_SS_NODE_LEN:

    /*     returns the length of the concatenated side sets node list */

    *ret_int = 0;     /* default return value */

    if (nc_inq_dimid (exoid, DIM_NUM_SS, &dimid) == NC_NOERR) {
      if ((status = nc_inq_dimlen(exoid, dimid, &num_sets)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get number of side sets in file id %d",
		exoid);
	ex_err("ex_inquire",errmsg,exerrval);
	return (EX_FATAL);
      }


      if (!(ids = malloc(num_sets*sizeof(int64_t)))) { /* May be getting 2x what is needed, but should be OK */
	exerrval = EX_MEMFAIL;
	sprintf(errmsg,
		"Error: failed to allocate memory for side set ids for file id %d",
		exoid);
	ex_err("ex_inquire",errmsg,exerrval);
	return (EX_FATAL);
      }

      if (ex_get_side_set_ids (exoid, ids) == EX_FATAL) {
	sprintf(errmsg,
		"Error: failed to get side set ids in file id %d",
		exoid);
	ex_err("ex_inquire",errmsg,exerrval);
	free(ids);
	return (EX_FATAL);
      }

      /* allocate space for stat array */
      if (!(stat_vals = malloc((int)num_sets*sizeof(int)))) {
	exerrval = EX_MEMFAIL;
	free (ids);
	sprintf(errmsg,
		"Error: failed to allocate memory for side set status array for file id %d",
		exoid);
	ex_err("ex_inquire",errmsg,exerrval);
	return (EX_FATAL);
      }
      /* get variable id of status array */
      if ((status = nc_inq_varid (exoid, VAR_SS_STAT, &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 (ids);
	  free(stat_vals);
	  sprintf(errmsg,
		  "Error: failed to get element block status array from file id %d",
		  exoid);
	  ex_err("ex_inquire",errmsg,exerrval);
	  return (EX_FATAL);
	}
      }
      else /* default: status is true */
	for(i=0;i<num_sets;i++)
	  stat_vals[i]=1;

      /* walk id list, get each side set node length and sum for total */

      for (i=0; i<num_sets; i++) {
	ex_entity_id id;
	if (stat_vals[i] == 0) /* is this object null? */
	  continue;

	if (ex_int64_status(exoid) & EX_IDS_INT64_API)
	  id = ((int64_t*)ids)[i];
	else
	  id = ((int*)ids)[i];
	  
	if ((status = ex_get_side_set_node_list_len(exoid, id, &tmp_num)) != NC_NOERR) {
	  *ret_int = 0;
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: failed to side set %"PRId64" node length in file id %d",
		  id,exoid);
	  ex_err("ex_inquire",errmsg,exerrval);
	  free(stat_vals);
	  free(ids);
	  return (EX_FATAL);
	}
	*ret_int += tmp_num;
      }

      free(stat_vals);
      free (ids);
    }

    break;

  case EX_INQ_SS_ELEM_LEN:
    /*     returns the length of the concatenated side sets element list */
    ex_get_concat_set_len(exoid, ret_int,"side",EX_SIDE_SET,DIM_NUM_SS,VAR_SS_STAT,"num_side_ss",0);
    break;

  case EX_INQ_SS_DF_LEN:

    /*     returns the length of the concatenated side sets dist factor list */

    /*
      Determine the concatenated side sets distribution factor length:

      1. Get the side set ids list.
      2. Check see if the dist factor dimension for a side set id exists.
      3. If it exists, goto step 4, else set the individual length to zero.
      4. Sum the dimension value into the running total length.
    */

    *ret_int = 0;

    /* first check see if any side sets exist */

    if (nc_inq_dimid (exoid, DIM_NUM_SS, &dimid) == NC_NOERR) {
      if ((status = nc_inq_dimlen (exoid, dimid, &num_sets)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get number of side sets in file id %d",
		exoid);
	ex_err("ex_inquire",errmsg,exerrval);
	return (EX_FATAL);
      }

      for (i=0; i<num_sets; i++) {
	if ((status = nc_inq_dimid (exoid, DIM_NUM_DF_SS(i+1), &dimid)) != NC_NOERR) {
	  if (status == NC_EBADDIM) {
	    ldum = 0;        /* this dist factor doesn't exist */
	  } else {
	    *ret_int = 0;
	    exerrval = status;
	    sprintf(errmsg,
		    "Error: failed to locate number of dist fact for %"ST_ZU"'th side set in file id %d",
		    i, exoid);
	    ex_err("ex_inquire",errmsg,exerrval);
	    return (EX_FATAL);
	  }
	} else {
	  if ((status = nc_inq_dimlen (exoid, dimid, &ldum)) != NC_NOERR) {
	    *ret_int = 0;
	    exerrval = status;
	    sprintf(errmsg,
		    "Error: failed to get number of dist factors in %"ST_ZU"'th side set in file id %d",
		    i, exoid);
	    ex_err("ex_inquire",errmsg,exerrval);
	    return (EX_FATAL);
	  }
	}
	*ret_int += ldum;
      }
    }

    break;

  case EX_INQ_QA:
    /* returns the number of QA records */
    if (ex_get_dimension(exoid, DIM_NUM_QA, "QA records", &ldum, &dimid, NULL) != NC_NOERR)
      *ret_int = 0;
    else
      *ret_int = ldum;
    break;

  case EX_INQ_INFO:
    /* returns the number of information records */
    if (ex_get_dimension(exoid, DIM_NUM_INFO, "info records", &ldum, &dimid, NULL) != NC_NOERR)
      *ret_int = 0;
    else
      *ret_int = ldum;
    break;

  case EX_INQ_TIME:
    /*     returns the number of time steps stored in the database */
    if (ex_get_dimension(exoid, DIM_TIME, "time dimension", &ldum, &dimid, "ex_inquire") != NC_NOERR)
      return EX_FATAL;
    *ret_int = ldum;
    break;

  case EX_INQ_EB_PROP:
    /* returns the number of element block properties */
    *ret_int = ex_get_num_props (exoid, EX_ELEM_BLOCK);
    break;

  case EX_INQ_NS_PROP:
    /* returns the number of node set properties */
    *ret_int = ex_get_num_props (exoid, EX_NODE_SET);
    break;

  case EX_INQ_SS_PROP:
    /* returns the number of side set properties */
    *ret_int = ex_get_num_props (exoid, EX_SIDE_SET);
    break;

  case EX_INQ_ELEM_MAP:
    /* returns the number of element maps */
    if (ex_get_dimension(exoid, DIM_NUM_EM, "element maps", &ldum, &dimid, NULL) != NC_NOERR)
      *ret_int = 0;
    else
      *ret_int = ldum;
    break;

  case EX_INQ_EM_PROP:
    /* returns the number of element map properties */
    *ret_int = ex_get_num_props (exoid, EX_ELEM_MAP);
    break;

  case EX_INQ_NODE_MAP:
    /* returns the number of node maps */
    if (ex_get_dimension(exoid, DIM_NUM_NM, "node maps", &ldum, &dimid, NULL) != NC_NOERR)
      *ret_int = 0;
    else
      *ret_int = ldum;
    break;

  case EX_INQ_NM_PROP:
    /* returns the number of node map properties */
    *ret_int = ex_get_num_props (exoid, EX_NODE_MAP);
    break;

  case EX_INQ_EDGE:
    /* returns the number of edges (defined across all edge blocks). */
    if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_EDGE, 1) != EX_NOERR) return EX_FATAL;
    break;

  case EX_INQ_EDGE_BLK:
    /* returns the number of edge blocks. */
    if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_ED_BLK, 1) != EX_NOERR) return EX_FATAL;
    break;

  case EX_INQ_EDGE_SETS:
    /* returns the number of edge sets. */
    if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_ES, 1) != EX_NOERR) return EX_FATAL;
    break;

  case EX_INQ_ES_LEN:
    /* returns the length of the concatenated edge set edge list. */
    ex_get_concat_set_len(exoid, ret_int,"edge",EX_EDGE_SET,DIM_NUM_ES,VAR_ES_STAT,"num_edge_es",0);
    break;

  case EX_INQ_ES_DF_LEN:
    /* returns the length of the concatenated edge set distribution factor list. */
    ex_get_concat_set_len(exoid, ret_int,"edge",EX_EDGE_SET,DIM_NUM_ES,VAR_ES_STAT,"num_df_es",1);
    break;

  case EX_INQ_EDGE_PROP:
    /* returns the number of integer properties stored for each edge block. This includes the "ID" property. */
    *ret_int = ex_get_num_props( exoid, EX_EDGE_BLOCK );
    break;

  case EX_INQ_ES_PROP:
    /* returns the number of integer properties stored for each edge set.. This includes the "ID" property */
    *ret_int = ex_get_num_props( exoid, EX_EDGE_SET );
    break;

  case EX_INQ_FACE:
    /* returns the number of faces (defined across all face blocks). */
    if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_FACE, 1) != EX_NOERR) return EX_FATAL;
    break;

  case EX_INQ_FACE_BLK:
    /* returns the number of face blocks. */
    if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_FA_BLK, 1) != EX_NOERR) return EX_FATAL;
    break;

  case EX_INQ_FACE_SETS:
    /* returns the number of face sets. */
    if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_FS, 1) != EX_NOERR) return EX_FATAL;
    break;

  case EX_INQ_FS_LEN:
    /* returns the length of the concatenated edge set edge list. */
    ex_get_concat_set_len(exoid, ret_int,"face",EX_FACE_SET,DIM_NUM_FS,VAR_FS_STAT,"num_face_fs",0);
    break;

  case EX_INQ_FS_DF_LEN:
    /* returns the length of the concatenated edge set distribution factor list. */
    ex_get_concat_set_len(exoid, ret_int,"face",EX_FACE_SET,DIM_NUM_FS,VAR_FS_STAT,"num_df_fs",1);
    break;

  case EX_INQ_FACE_PROP:
    /* returns the number of integer properties stored for each edge block. This includes the "ID" property. */
    *ret_int = ex_get_num_props( exoid, EX_FACE_BLOCK );
    break;

  case EX_INQ_FS_PROP:
    /* returns the number of integer properties stored for each edge set.. This includes the "ID" property */
    *ret_int = ex_get_num_props( exoid, EX_FACE_SET );
    break;

  case EX_INQ_ELEM_SETS:
    /* returns the number of element sets. */
    if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_ELS, 1) != EX_NOERR) return EX_FATAL;
    break;

  case EX_INQ_ELS_LEN:
    /* returns the length of the concatenated element set element list. */
    ex_get_concat_set_len(exoid, ret_int,"element",EX_ELEM_SET,DIM_NUM_ELS,VAR_ELS_STAT,"num_ele_els",0);
    break;

  case EX_INQ_ELS_DF_LEN:
    /* returns the length of the concatenated element set distribution factor list. */
    ex_get_concat_set_len(exoid, ret_int,"element",EX_ELEM_SET,DIM_NUM_ELS,VAR_ELS_STAT,"num_df_els",1);
    break;

  case EX_INQ_ELS_PROP:
    /* returns the number of integer properties stored for each element set. */
    *ret_int = ex_get_num_props( exoid, EX_ELEM_SET );
    break;

  case EX_INQ_EDGE_MAP:
    /* returns the number of edge maps. */
    if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_EDM, 1) != EX_NOERR) return EX_FATAL;
    break;

  case EX_INQ_FACE_MAP:
    /*     returns the number of face maps. */
    if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_FAM, 1) != EX_NOERR) return EX_FATAL;
    break;

  case EX_INQ_COORD_FRAMES:
    /* return the number of coordinate frames */
    if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_CFRAMES, 1) != EX_NOERR) return EX_FATAL;
    break;

  default:
    *ret_int = 0;
    exerrval = EX_FATAL;
    sprintf(errmsg, "Error: invalid inquiry %d", req_info);
    ex_err("ex_inquire",errmsg,exerrval);
    return(EX_FATAL);
  }
  return (EX_NOERR);
}
示例#6
0
文件: exinq.c 项目: hs9906/paraview
int ex_inquire (int   exoid,
                int   req_info,
                int  *ret_int,
                void *ret_float,
                char *ret_char)
{
   int dimid, varid, i, tmp_num, *ids;
   long ldum, num_sets, start[2], count[2];
   nclong *stat_vals;
   char  errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

   switch (req_info)
   {
     case EX_INQ_FILE_TYPE:

       /* obsolete call */
       /*returns "r" for regular EXODUS II file or "h" for history EXODUS file*/

       *ret_char = '\0';
       exerrval = EX_BADPARAM;
       sprintf(errmsg,
              "Warning: file type inquire is obsolete");
       ex_err("ex_inquire",errmsg,exerrval);
       return (EX_WARN);

     case EX_INQ_API_VERS:

/*     returns the EXODUS II API version number */

       if (ncattget (exoid, NC_GLOBAL, ATT_API_VERSION, ret_float) == -1)
       {  /* try old (prior to db version 2.02) attribute name */
         if (ncattget (exoid, NC_GLOBAL, ATT_API_VERSION_BLANK,ret_float) == -1)
         {
           exerrval = ncerr;
           sprintf(errmsg,
             "Error: failed to get EXODUS API version for file id %d", exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }
       }

       break;

     case EX_INQ_DB_VERS:

/*     returns the EXODUS II database version number */

       if (ncattget (exoid, NC_GLOBAL, ATT_VERSION, ret_float) == -1)
       {
         exerrval = ncerr;
         sprintf(errmsg,
          "Error: failed to get EXODUS database version for file id %d", exoid);
         ex_err("ex_inquire",errmsg,exerrval);
         return (EX_FATAL);
       }

       break;

     case EX_INQ_LIB_VERS:

/*     returns the EXODUS II Library version number */

       flt_cvt((float *)ret_float, EX_API_VERS);

       break;

     case EX_INQ_TITLE:

/*     returns the title of the database */

       if (ncattget (exoid, NC_GLOBAL, ATT_TITLE, ret_char) == -1)
       {
         *ret_char = '\0';
         exerrval = ncerr;
         sprintf(errmsg,
             "Error: failed to get database title for file id %d", exoid);
         ex_err("ex_inquire",errmsg,exerrval);
         return (EX_FATAL);
       }

       break;

     case EX_INQ_DIM:

/*     returns the dimensionality (2 or 3, for 2-d or 3-d) of the database */

       if ((dimid = ncdimid (exoid, DIM_NUM_DIM)) == -1)
       {
         *ret_int = 0;
         exerrval = ncerr;
         sprintf(errmsg,
                "Error: failed to locate database dimensionality in file id %d",
                exoid);
         ex_err("ex_inquire",errmsg,exerrval);
         return (EX_FATAL);
       }

       if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
       {
         *ret_int = 0;
         exerrval = ncerr;
         sprintf(errmsg,
            "Error: failed to get database dimensionality for file id %d",
            exoid);
         ex_err("ex_inquire",errmsg,exerrval);
         return (EX_FATAL);
       }
       *ret_int = ldum;

       break;

     case EX_INQ_NODES:

/*     returns the number of nodes */

       if ((dimid = ncdimid (exoid, DIM_NUM_NODES)) == -1)
       {
         *ret_int = 0;
       } else {

         if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
           {
             *ret_int = 0;
             exerrval = ncerr;
             sprintf(errmsg,
                     "Error: failed to get number of nodes for file id %d",
                     exoid);
             ex_err("ex_inquire",errmsg,exerrval);
             return (EX_FATAL);
           }
         *ret_int = ldum;
       }
       break;

     case EX_INQ_ELEM:

/*     returns the number of elements */

       if ((dimid = ncdimid (exoid, DIM_NUM_ELEM)) == -1)
       {
         *ret_int = 0;
       } else {

         if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
           {
             *ret_int = 0;
             exerrval = ncerr;
             sprintf(errmsg,
                     "Error: failed to get number of elements for file id %d",
                     exoid);
             ex_err("ex_inquire",errmsg,exerrval);
             return (EX_FATAL);
           }
         *ret_int = ldum;
       }
       break;

     case EX_INQ_ELEM_BLK:

/*     returns the number of element blocks */

       if ((dimid = ncdimid (exoid, DIM_NUM_EL_BLK)) == -1)
       {
         *ret_int = 0;
       } else {

         if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
           {
             *ret_int = 0;
             exerrval = ncerr;
             sprintf(errmsg,
                     "Error: failed to get number of element blocks for file id %d",
                     exoid);
             ex_err("ex_inquire",errmsg,exerrval);
             return (EX_FATAL);
           }
         *ret_int = ldum;
       }

       break;

     case EX_INQ_NODE_SETS:

/*     returns the number of node sets */

       if ((dimid = ncdimid (exoid, DIM_NUM_NS)) < 0)
         *ret_int = 0;      /* no node sets defined */
       else
       {
         if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
         {
           *ret_int = 0;
           exerrval = ncerr;
           sprintf(errmsg,
                 "Error: failed to get number of node sets in file id %d",
                  exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }
         *ret_int = ldum;
       }

       break;

     case EX_INQ_NS_NODE_LEN:

/*     returns the length of the concatenated node sets node list */

       *ret_int = 0;       /* default value if no node sets are defined */
       if ((dimid = ncdimid (exoid, DIM_NUM_NS)) != -1 )
       {
         if (ncdiminq (exoid, dimid, (char *) 0, &num_sets) == -1)
         {
           exerrval = ncerr;
           sprintf(errmsg,
                 "Error: failed to get number of node sets in file id %d",
                  exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }


         if (!(ids =  malloc(num_sets*sizeof(int))))
         {
           exerrval = EX_MEMFAIL;
           sprintf(errmsg,
             "Error: failed to allocate memory for node set ids for file id %d",
              exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }

         if (ex_get_node_set_ids (exoid, ids) == EX_FATAL)
         {
           sprintf(errmsg,
                   "Error: failed to get node sets in file id %d",
                    exoid);
           /* pass back error code from ex_get_node_set_ids (in exerrval) */
           ex_err("ex_inquire",errmsg,exerrval);
           free (ids);
           return (EX_FATAL);
         }
         /* allocate space for stat array */
         if (!(stat_vals = malloc((int)num_sets*sizeof(nclong))))
         {
           exerrval = EX_MEMFAIL;
           free (ids);
           sprintf(errmsg,
    "Error: failed to allocate memory for node set status array for file id %d",
                   exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }

         /* get variable id of status array */
         if ((varid = ncvarid (exoid, VAR_NS_STAT)) != -1)
         {
         /* if status array exists, use it, otherwise assume, object exists
            to be backward compatible */

           start[0] = 0;
           start[1] = 0;
           count[0] = num_sets;
           count[1] = 0;

           if (ncvarget (exoid, varid, start, count, (void *)stat_vals) == -1)
           {
             exerrval = ncerr;
             free (ids);
             free(stat_vals);
             sprintf(errmsg,
                   "Error: failed to get node set status array from file id %d",
                     exoid);
             ex_err("ex_inquire",errmsg,exerrval);
             return (EX_FATAL);
           }
         }
         else /* default: status is true */
           for(i=0;i<num_sets;i++)
             stat_vals[i]=1;

         for (i=0; i<num_sets; i++)
         {

           if (stat_vals[i] == 0) /* is this object null? */
              continue;

           if ((dimid = ncdimid (exoid, DIM_NUM_NOD_NS(i+1))) == -1)
           {
             *ret_int = 0;
             exerrval = ncerr;
             sprintf(errmsg,
         "Error: failed to locate number of nodes in node set %d in file id %d",
                  ids[i],exoid);
             ex_err("ex_inquire",errmsg,exerrval);
             free (ids);
             free (stat_vals);
             return (EX_FATAL);
           }

           if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
           {
             *ret_int = 0;
             exerrval = ncerr;
             sprintf(errmsg,
            "Error: failed to get number of nodes in node set %d in file id %d",
                  ids[i],exoid);
             ex_err("ex_inquire",errmsg,exerrval);
             free (stat_vals);
             free (ids);
             return (EX_FATAL);
           }

           *ret_int += ldum;
         }

         free (stat_vals);
         free (ids);
       }

       break;

     case EX_INQ_NS_DF_LEN:

/*     returns the length of the concatenated node sets dist factor list */

/*
     Determine the concatenated node sets distribution factor length:

        1. Get the node set ids list.
        2. Check see if the dist factor variable for a node set id exists.
        3. If it exists, goto step 4, else the length is zero.
        4. Get the dimension of the number of nodes in the node set -0
             use this value as the length as by definition they are the same.
        5. Sum the individual lengths for the total list length.
*/

       *ret_int = 0;    /* default value if no node sets defined */

       if ((dimid = ncdimid (exoid, DIM_NUM_NS))  != -1)
       {
         if (ncdiminq (exoid, dimid, (char *) 0, &num_sets) == -1)
         {
           exerrval = ncerr;
           sprintf(errmsg,
                 "Error: failed to get number of node sets in file id %d",
                  exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }


         if (!(ids = malloc(num_sets*sizeof(int))))
         {
           exerrval = EX_MEMFAIL;
           sprintf(errmsg,
             "Error: failed to allocate memory for node set ids for file id %d",
              exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }

         if (ex_get_node_set_ids (exoid, ids) == EX_FATAL)
         {
           sprintf(errmsg,
                   "Error: failed to get node sets in file id %d",
                    exoid);
           /* pass back error code from ex_get_node_set_ids (in exerrval) */
           ex_err("ex_inquire",errmsg,exerrval);
           free (ids);
           return (EX_FATAL);
         }

         for (i=0; i<num_sets; i++)
         {
           if (ncvarid (exoid, VAR_FACT_NS(i+1)) == -1)
           {
             if (ncerr == NC_ENOTVAR)
             {
               ldum = 0;        /* this dist factor doesn't exist */
             }
             else
             {
               *ret_int = 0;
               exerrval = ncerr;
               sprintf(errmsg,
    "Error: failed to locate number of dist fact for node set %d in file id %d",
                        ids[i], exoid);
               ex_err("ex_inquire",errmsg,exerrval);
               free (ids);
               return (EX_FATAL);
             }
           }
           else
           {
             if ((dimid = ncdimid (exoid, DIM_NUM_NOD_NS(i+1))) == -1)
             {
               *ret_int = 0;
               exerrval = ncerr;
               sprintf(errmsg,
         "Error: failed to locate number of nodes in node set %d in file id %d",
                       ids[i], exoid);
               ex_err("ex_inquire",errmsg,exerrval);
               free (ids);
               return (EX_FATAL);
             }
             if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
             {
               *ret_int = 0;
               exerrval = ncerr;
               sprintf(errmsg,
            "Error: failed to get number of nodes in node set %d in file id %d",
                       ids[i],exoid);
               ex_err("ex_inquire",errmsg,exerrval);
               free(ids);
               return (EX_FATAL);
             }
           }
           *ret_int += ldum;
         }
         free(ids);
       }

       break;

     case EX_INQ_SIDE_SETS:

/*     returns the number of side sets */

       *ret_int = 0;     /* default return value */

       if ((dimid = ncdimid (exoid, DIM_NUM_SS)) != -1)
       {
         if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
         {
           exerrval = ncerr;
           sprintf(errmsg,
                 "Error: failed to get number of side sets in file id %d",
                  exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }
         *ret_int = ldum;
       }

       break;

     case EX_INQ_SS_NODE_LEN:

/*     returns the length of the concatenated side sets node list */

       *ret_int = 0;     /* default return value */

       if ((dimid = ncdimid (exoid, DIM_NUM_SS)) != -1)
       {
         if (ncdiminq (exoid, dimid, (char *) 0, &num_sets) == -1)
         {
           exerrval = ncerr;
           sprintf(errmsg,
                 "Error: failed to get number of side sets in file id %d",
                  exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }


         if (!(ids = malloc(num_sets*sizeof(int))))
         {
           exerrval = EX_MEMFAIL;
           sprintf(errmsg,
             "Error: failed to allocate memory for side set ids for file id %d",
              exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }

         if (ex_get_side_set_ids (exoid, ids) == EX_FATAL)
         {
           sprintf(errmsg,
                  "Error: failed to get side set ids in file id %d",
                   exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           free(ids);
           return (EX_FATAL);
         }

         /* allocate space for stat array */
         if (!(stat_vals = malloc((int)num_sets*sizeof(nclong))))
         {
           exerrval = EX_MEMFAIL;
           free (ids);
           sprintf(errmsg,
    "Error: failed to allocate memory for side set status array for file id %d",
                   exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }
         /* get variable id of status array */
         if ((varid = ncvarid (exoid, VAR_SS_STAT)) != -1)
         {
         /* if status array exists, use it, otherwise assume, object exists
            to be backward compatible */

           start[0] = 0;
           start[1] = 0;
           count[0] = num_sets;
           count[1] = 0;

           if (ncvarget (exoid, varid, start, count, (void *)stat_vals) == -1)
           {
             exerrval = ncerr;
             free (ids);
             free(stat_vals);
             sprintf(errmsg,
             "Error: failed to get element block status array from file id %d",
                     exoid);
             ex_err("ex_inquire",errmsg,exerrval);
             return (EX_FATAL);
           }
         }
         else /* default: status is true */
           for(i=0;i<num_sets;i++)
             stat_vals[i]=1;

         /* walk id list, get each side set node length and sum for total */

         for (i=0; i<num_sets; i++)
         {
           if (stat_vals[i] == 0) /* is this object null? */
             continue;

           if (ex_get_side_set_node_list_len(exoid, ids[i], &tmp_num) == -1)
           {
             *ret_int = 0;
             exerrval = ncerr;
             sprintf(errmsg,
                 "Error: failed to side set %d node length in file id %d",
                  ids[i],exoid);
             ex_err("ex_inquire",errmsg,exerrval);
             free(stat_vals);
             free(ids);
             return (EX_FATAL);
           }
           *ret_int += tmp_num;
         }

         free(stat_vals);
         free (ids);
       }

       break;

     case EX_INQ_SS_ELEM_LEN:
/*     returns the length of the concatenated side sets element list */
       EX_GET_CONCAT_SET_LEN(ret_int,"side",EX_SIDE_SET,DIM_NUM_SS,VAR_SS_STAT,DIM_NUM_SIDE_SS,0);
       break;

     case EX_INQ_SS_DF_LEN:

/*     returns the length of the concatenated side sets dist factor list */

/*
     Determine the concatenated side sets distribution factor length:

        1. Get the side set ids list.
        2. Check see if the dist factor dimension for a side set id exists.
        3. If it exists, goto step 4, else set the individual length to zero.
        4. Sum the dimension value into the running total length.
*/

       *ret_int = 0;

       /* first check see if any side sets exist */

       if ((dimid = ncdimid (exoid, DIM_NUM_SS))  != -1)
       {
         if (ncdiminq (exoid, dimid, (char *) 0, &num_sets) == -1)
         {
           exerrval = ncerr;
           sprintf(errmsg,
                 "Error: failed to get number of side sets in file id %d",
                  exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }


         if (!(ids = malloc(num_sets*sizeof(int))))
         {
           exerrval = EX_MEMFAIL;
           sprintf(errmsg,
             "Error: failed to allocate memory for side set ids for file id %d",
              exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }

         if (ex_get_side_set_ids (exoid, ids) == EX_FATAL)
         {
           sprintf(errmsg,
                   "Error: failed to get side sets in file id %d",
                    exoid);
           /* pass back error code from ex_get_side_set_ids (in exerrval) */
           ex_err("ex_inquire",errmsg,exerrval);
           free (ids);
           return (EX_FATAL);
         }

         for (i=0; i<num_sets; i++)
         {
           if ((dimid = ncdimid (exoid, DIM_NUM_DF_SS(i+1))) == -1)
           {
             if (ncerr == NC_EBADDIM)
             {
               ldum = 0;        /* this dist factor doesn't exist */
             }
             else
             {
               *ret_int = 0;
               exerrval = ncerr;
               sprintf(errmsg,
    "Error: failed to locate number of dist fact for side set %d in file id %d",
                        ids[i], exoid);
               ex_err("ex_inquire",errmsg,exerrval);
               free (ids);
               return (EX_FATAL);
             }
           }
           else
           {
             if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
             {
               *ret_int = 0;
               exerrval = ncerr;
               sprintf(errmsg,
     "Error: failed to get number of dist factors in side set %d in file id %d",
                       ids[i], exoid);
               ex_err("ex_inquire",errmsg,exerrval);
               free (ids);
               return (EX_FATAL);
             }
           }
           *ret_int += ldum;
         }
         free (ids);
       }

       break;

     case EX_INQ_QA:

/*     returns the number of QA records */

       if ((dimid = ncdimid (exoid, DIM_NUM_QA)) < 0)
         *ret_int = 0;      /* no QA records stored */
       else
       {
         if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
         {
           *ret_int = 0;
           exerrval = ncerr;
           sprintf(errmsg,
                  "Error: failed to get number of QA records in file id %d",
                   exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }
         *ret_int = ldum;
       }

       break;

     case EX_INQ_INFO:

/*     returns the number of information records */

       if ((dimid = ncdimid (exoid, DIM_NUM_INFO)) < 0)
         *ret_int = 0;        /* no information records stored */
       else
       {
         if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
         {
           *ret_int = 0;
           exerrval = ncerr;
           sprintf(errmsg,
                  "Error: failed to get number of info records in file id %d",
                   exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }
         *ret_int = ldum;
       }
       break;

     case EX_INQ_TIME:

/*     returns the number of time steps stored in the database; we find 
 *     this out by inquiring the maximum record number of the "unlimited" 
 *     dimension
 */

       if ((dimid = ncdimid (exoid, DIM_TIME)) == -1)
       {
         *ret_int = 0;
         exerrval = ncerr;
         sprintf(errmsg,
                "Error: failed to locate time dimension in file id %d", exoid);
         ex_err("ex_inquire",errmsg,exerrval);
         return (EX_FATAL);
       }

       if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
       {
         *ret_int = 0;
         exerrval = ncerr;
         sprintf(errmsg,
                "Error: failed to get time dimension in file id %d",
                 exoid);
         ex_err("ex_inquire",errmsg,exerrval);
         return (EX_FATAL);
       }
       *ret_int = ldum;

       break;
     case EX_INQ_EB_PROP:

/*     returns the number of element block properties */

       *ret_int = ex_get_num_props (exoid, EX_ELEM_BLOCK);
       break;

     case EX_INQ_NS_PROP:

/*     returns the number of node set properties */

       *ret_int = ex_get_num_props (exoid, EX_NODE_SET);
       break;

     case EX_INQ_SS_PROP:

/*     returns the number of side set properties */

       *ret_int = ex_get_num_props (exoid, EX_SIDE_SET);
       break;

     case EX_INQ_ELEM_MAP:

/*     returns the number of element maps */

       if ((dimid = ncdimid (exoid, DIM_NUM_EM)) == -1)
       {
         /* no element maps so return 0 */

         *ret_int = 0;
         return (EX_NOERR);
       }

       if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
       {
         *ret_int = 0;
         exerrval = ncerr;
         sprintf(errmsg,
           "Error: failed to get number of element maps for file id %d",
           exoid);
         ex_err("ex_inquire",errmsg,exerrval);
         return (EX_FATAL);
       }
       *ret_int = ldum;

       break;

     case EX_INQ_EM_PROP:

/*     returns the number of element map properties */

       *ret_int = ex_get_num_props (exoid, EX_ELEM_MAP);
       break;

     case EX_INQ_NODE_MAP:

/*     returns the number of node maps */

       if ((dimid = ncdimid (exoid, DIM_NUM_NM)) == -1)
       {
         /* no node maps so return 0 */

         *ret_int = 0;
         return (EX_NOERR);
       }

       if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
       {
         *ret_int = 0;
         exerrval = ncerr;
         sprintf(errmsg,
           "Error: failed to get number of node maps for file id %d",
           exoid);
         ex_err("ex_inquire",errmsg,exerrval);
         return (EX_FATAL);
       }
       *ret_int = ldum;

       break;

     case EX_INQ_NM_PROP:
/*     returns the number of element map properties */
       *ret_int = ex_get_num_props (exoid, EX_NODE_MAP);
       break;

     case EX_INQ_EDGE:
/*     returns the number of edges (defined across all edge blocks). */
       EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_EDGE, 1);
       break;

     case EX_INQ_EDGE_BLK:
/*     returns the number of edge blocks. */
       EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_ED_BLK, 1);
       break;

     case EX_INQ_EDGE_SETS:
/*     returns the number of edge sets. */
       EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_ES, 1);
       break;

     case EX_INQ_ES_LEN:
/*     returns the length of the concatenated edge set edge list. */
       EX_GET_CONCAT_SET_LEN(ret_int,"edge",EX_EDGE_SET,DIM_NUM_ES,VAR_ES_STAT,DIM_NUM_EDGE_ES,0);
       break;

     case EX_INQ_ES_DF_LEN:
/*     returns the length of the concatenated edge set distribution factor list. */
       EX_GET_CONCAT_SET_LEN(ret_int,"edge",EX_EDGE_SET,DIM_NUM_ES,VAR_ES_STAT,DIM_NUM_DF_ES,1);
       break;

     case EX_INQ_EDGE_PROP:
/*     returns the number of integer properties stored for each edge block. This includes the "ID" property. */
       *ret_int = ex_get_num_props( exoid, EX_EDGE_BLOCK );
       break;

     case EX_INQ_ES_PROP:
/*     returns the number of integer properties stored for each edge set.. This includes the "ID" property */
       *ret_int = ex_get_num_props( exoid, EX_EDGE_SET );
       break;

     case EX_INQ_FACE:
/*     returns the number of faces (defined across all face blocks). */
       EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_FACE, 1);
       break;

     case EX_INQ_FACE_BLK:
/*     returns the number of edge blocks. */
       EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_FA_BLK, 1);
       break;

     case EX_INQ_FACE_SETS:
/*     returns the number of edge sets. */
       EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_FS, 1);
       break;

     case EX_INQ_FS_LEN:
/*     returns the length of the concatenated edge set edge list. */
       EX_GET_CONCAT_SET_LEN(ret_int,"face",EX_FACE_SET,DIM_NUM_FS,VAR_FS_STAT,DIM_NUM_FACE_FS,0);
       break;

     case EX_INQ_FS_DF_LEN:
/*     returns the length of the concatenated edge set distribution factor list. */
       EX_GET_CONCAT_SET_LEN(ret_int,"face",EX_FACE_SET,DIM_NUM_FS,VAR_FS_STAT,DIM_NUM_DF_FS,1);
       break;

     case EX_INQ_FACE_PROP:
/*     returns the number of integer properties stored for each edge block. This includes the "ID" property. */
       *ret_int = ex_get_num_props( exoid, EX_FACE_BLOCK );
       break;

     case EX_INQ_FS_PROP:
/*     returns the number of integer properties stored for each edge set.. This includes the "ID" property */
       *ret_int = ex_get_num_props( exoid, EX_FACE_SET );
       break;

     case EX_INQ_ELEM_SETS:
/*     returns the number of element sets. */
       EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_ELS, 1);
       break;

     case EX_INQ_ELS_LEN:
/*     returns the length of the concatenated element set element list. */
       EX_GET_CONCAT_SET_LEN(ret_int,"element",EX_ELEM_SET,DIM_NUM_ELS,VAR_ELS_STAT,DIM_NUM_ELE_ELS,0);
       break;

     case EX_INQ_ELS_DF_LEN:
/*     returns the length of the concatenated element set distribution factor list. */
       EX_GET_CONCAT_SET_LEN(ret_int,"element",EX_ELEM_SET,DIM_NUM_ELS,VAR_ELS_STAT,DIM_NUM_DF_ELS,1);
       break;

    case EX_INQ_ELS_PROP:
/*     returns the number of integer properties stored for each element set. */
       *ret_int = ex_get_num_props( exoid, EX_ELEM_SET );
       break;

    case EX_INQ_EDGE_MAP:
/*     returns the number of edge sets. */
       EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_EDM, 1);
       break;

    case EX_INQ_FACE_MAP:
/*     returns the number of edge sets. */
       EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_FAM, 1);
       break;


     default:
       *ret_int = 0;
       exerrval = EX_FATAL;
       sprintf(errmsg, "Error: invalid inquiry %d", req_info);
       ex_err("ex_inquire",errmsg,exerrval);
       return(EX_FATAL);
   }
   return (EX_NOERR);
}
示例#7
0
int ex_get_prop_array (int   exoid,
                       int   obj_type,
                       const char *prop_name,
                       int  *values)
{
   int num_props, i, propid, dimid, iresult;
   int found = FALSE;
   long start[1], count[1], num_obj; 
   nclong *longs;
   char name[MAX_VAR_NAME_LENGTH+1];
   char tmpstr[MAX_VAR_NAME_LENGTH+1];
   char obj_stype[MAX_VAR_NAME_LENGTH+1];
   char dim_name[MAX_VAR_NAME_LENGTH+1];

   char errmsg[MAX_ERR_LENGTH];

   exerrval  = 0; /* clear error code */

/* open appropriate variable, depending on obj_type and prop_name */

   num_props = ex_get_num_props(exoid, obj_type);

   switch (obj_type)
   {
     case EX_ELEM_BLOCK:
       strcpy (obj_stype, VAR_ID_EL_BLK);
       strcpy (dim_name, DIM_NUM_EL_BLK);
       break;
     case EX_NODE_SET:
       strcpy (obj_stype, VAR_NS_IDS);
       strcpy (dim_name, DIM_NUM_NS);
       break;
     case EX_SIDE_SET:
       strcpy (obj_stype, VAR_SS_IDS);
       strcpy (dim_name, DIM_NUM_SS);
       break;
     case EX_ELEM_MAP:
       strcpy (obj_stype, VAR_EM_PROP(1));
       strcpy (dim_name, DIM_NUM_EM);
       break;
     case EX_NODE_MAP:
       strcpy (obj_stype, VAR_NM_PROP(1));
       strcpy (dim_name, DIM_NUM_NM);
       break;
     default:
       exerrval = EX_BADPARAM;
       sprintf(errmsg, "Error: object type %d not supported; file id %d",
               obj_type, exoid);
       ex_err("ex_get_prop_array",errmsg,exerrval);
       return (EX_FATAL);
   }


   for (i=1; i<=num_props; i++)
   {
     switch (obj_type){
       case EX_ELEM_BLOCK:
         strcpy (name, VAR_EB_PROP(i));
         break;
       case EX_NODE_SET:
         strcpy (name, VAR_NS_PROP(i));
         break;
       case EX_SIDE_SET:
         strcpy (name, VAR_SS_PROP(i));
         break;
       case EX_ELEM_MAP:
         strcpy (name, VAR_EM_PROP(i));
         break;
       case EX_NODE_MAP:
         strcpy (name, VAR_NM_PROP(i));
         break;
       default:
         exerrval = EX_BADPARAM;
         sprintf(errmsg, "Error: object type %d not supported; file id %d",
           obj_type, exoid);
         ex_err("ex_get_prop_array",errmsg,exerrval);
         return(EX_FATAL);
     }

     if ((propid = ncvarid (exoid, name)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
          "Error: failed to locate property array %s in file id %d",
               name, exoid);
       ex_err("ex_get_prop_array",errmsg,exerrval);
       return (EX_FATAL);
     }

/*   compare stored attribute name with passed property name   */

     memset(tmpstr, 0, MAX_VAR_NAME_LENGTH+1);
     if ((ncattget (exoid, propid, ATT_PROP_NAME, tmpstr)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Error: failed to get property name in file id %d", exoid);
       ex_err("ex_get_prop_array",errmsg,exerrval);
       return (EX_FATAL);
     }

     if (strcmp(tmpstr, prop_name) == 0) 
     {
       found = TRUE;
       break;
     }
   }

/* if property is not found, return warning */

   if (!found)
   {
     exerrval = EX_BADPARAM;
     sprintf(errmsg,
       "Warning: object type %d, property %s not defined in file id %d",
        obj_type, prop_name, exoid);
     ex_err("ex_get_prop_array",errmsg,exerrval);
     return (EX_WARN);
   }

   if ((dimid = ncdimid (exoid, dim_name)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
     "Error: failed to locate number of objects in file id %d",
              exoid);
     ex_err("ex_get_prop_array",errmsg, exerrval);
     return(EX_FATAL);
   }

/*   get number of objects */

   if (ncdiminq (exoid, dimid, dim_name, &num_obj) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to get number of %s objects in file id %d",
             obj_stype, exoid);
     ex_err("ex_get_prop_array",errmsg, exerrval);
     return (EX_FATAL);
   }

/* read num_obj values from property variable */

/* application code has allocated an array of ints but netcdf is expecting
   a pointer to nclongs;  if ints are different sizes than nclongs,
   we must allocate an array of nclongs then convert them to ints with ltoi */

   start[0] = 0;
   count[0] = num_obj;

   if (sizeof(int) == sizeof(nclong)) {
      iresult = ncvarget (exoid, propid, start, count, values);
   } else {
     if (!(longs = static_cast<nclong*>(malloc(num_obj * sizeof(nclong))))) {
       exerrval = EX_MEMFAIL;
       sprintf(errmsg,
               "Error: failed to allocate memory for %s property array for file id %d",
               obj_stype, exoid);
       ex_err("ex_get_prop_array",errmsg,exerrval);
       return (EX_FATAL);
     }
     iresult = ncvarget (exoid, propid, start, count, longs);
   }

   if (iresult == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to read values in %s property array in file id %d",
             obj_stype, exoid);
     ex_err("ex_get_prop_array",errmsg,exerrval);
     return (EX_FATAL);
   }

   if (sizeof(int) != sizeof(nclong)) {
      ltoi (longs, values, num_obj);
      free (longs);
   }

   return (EX_NOERR);
}
示例#8
0
int ex_put_prop (int   exoid,
                 ex_entity_type obj_type,
                 ex_entity_id   obj_id,
                 const char *prop_name,
                 ex_entity_id   value)
{
  int status;
  int oldfill = 0;
  int temp;
  int found = FALSE;
  int num_props, i, dimid, propid, dims[1];
  int int_type;
  size_t start[1]; 
  size_t prop_name_len, name_length;
  char name[MAX_VAR_NAME_LENGTH+1];
  char tmpstr[MAX_STR_LENGTH+1];
  char dim_name[MAX_VAR_NAME_LENGTH+1];
  long long vals[1];

  char errmsg[MAX_ERR_LENGTH];

  exerrval  = 0; /* clear error code */

  /* check if property has already been created */

  num_props = ex_get_num_props(exoid, obj_type);

  if (num_props > 1) {  /* any properties other than the default 1? */

    for (i=1; i<=num_props; i++) {
      switch (obj_type) {
      case EX_ELEM_BLOCK:
	strcpy (name, VAR_EB_PROP(i));
	break;
      case EX_EDGE_BLOCK:
	strcpy (name, VAR_ED_PROP(i));
	break;
      case EX_FACE_BLOCK:
	strcpy (name, VAR_FA_PROP(i));
	break;
      case EX_NODE_SET:
	strcpy (name, VAR_NS_PROP(i));
	break;
      case EX_EDGE_SET:
	strcpy (name, VAR_ES_PROP(i));
	break;
      case EX_FACE_SET:
	strcpy (name, VAR_FS_PROP(i));
	break;
      case EX_ELEM_SET:
	strcpy (name, VAR_ELS_PROP(i));
	break;
      case EX_SIDE_SET:
	strcpy (name, VAR_SS_PROP(i));
	break;
      case EX_ELEM_MAP:
	strcpy (name, VAR_EM_PROP(i));
	break;
      case EX_FACE_MAP:
	strcpy (name, VAR_FAM_PROP(i));
	break;
      case EX_EDGE_MAP:
	strcpy (name, VAR_EDM_PROP(i));
	break;
      case EX_NODE_MAP:
	strcpy (name, VAR_NM_PROP(i));
	break;
      default:
	exerrval = EX_BADPARAM;
	sprintf(errmsg, "Error: object type %d not supported; file id %d",
		obj_type, exoid);
	ex_err("ex_put_prop",errmsg,exerrval);
	return(EX_FATAL);
      }

      if ((status = nc_inq_varid(exoid, name, &propid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get property array id in file id %d",
		exoid);
	ex_err("ex_put_prop",errmsg,exerrval);
	return (EX_FATAL);
      }

      /*   compare stored attribute name with passed property name   */
      memset(tmpstr, 0, MAX_STR_LENGTH+1);
      if ((status = nc_get_att_text(exoid, propid, ATT_PROP_NAME, tmpstr)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get property name in file id %d", exoid);
	ex_err("ex_put_prop",errmsg,exerrval);
	return (EX_FATAL);
      }

      if (strcmp(tmpstr, prop_name) == 0) {
	found = TRUE;
	break;
      }
    }
  }

  /* if property array has not been created, create it */
  if (!found) {

    name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_ALLOWED_NAME_LENGTH)+1;

    /* put netcdf file into define mode  */
    if ((status = nc_redef (exoid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,"Error: failed to place file id %d into define mode",exoid);
      ex_err("ex_put_prop",errmsg,exerrval);
      return (EX_FATAL);
    }

    /*   create a variable with a name xx_prop#, where # is the new number   */
    /*   of the property                                                     */

    switch (obj_type){
    case EX_ELEM_BLOCK:
      strcpy (name, VAR_EB_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_EL_BLK);
      break;
    case EX_FACE_BLOCK:
      strcpy (name, VAR_FA_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_FA_BLK);
      break;
    case EX_EDGE_BLOCK:
      strcpy (name, VAR_ED_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_ED_BLK);
      break;
    case EX_NODE_SET:
      strcpy (name, VAR_NS_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_NS);
      break;
    case EX_EDGE_SET:
      strcpy (name, VAR_ES_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_ES);
      break;
    case EX_FACE_SET:
      strcpy (name, VAR_FS_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_FS);
      break;
    case EX_ELEM_SET:
      strcpy (name, VAR_ELS_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_ELS);
      break;
    case EX_SIDE_SET:
      strcpy (name, VAR_SS_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_SS);
      break;
    case EX_ELEM_MAP:
      strcpy (name, VAR_EM_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_EM);
      break;
    case EX_FACE_MAP:
      strcpy (name, VAR_FAM_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_FAM);
      break;
    case EX_EDGE_MAP:
      strcpy (name, VAR_EDM_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_EDM);
      break;
    case EX_NODE_MAP:
      strcpy (name, VAR_NM_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_NM);
      break;
    default:
      exerrval = EX_BADPARAM;
      sprintf(errmsg, "Error: object type %d not supported; file id %d",
	      obj_type, exoid);
      ex_err("ex_put_prop",errmsg,exerrval);
      goto error_ret;        /* Exit define mode and return */
    }

    /*   inquire id of previously defined dimension (number of objects) */
    if ((status = nc_inq_dimid(exoid, dim_name, &dimid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate number of objects in file id %d",
	      exoid);
      ex_err("ex_put_prop",errmsg, exerrval);
      goto error_ret;  /* Exit define mode and return */
    }

    dims[0] = dimid;
    nc_set_fill(exoid, NC_FILL, &oldfill); /* fill with zeros per routine spec */

    int_type = NC_INT;
    if (ex_int64_status(exoid) & EX_IDS_INT64_DB) {
      int_type = NC_INT64;
    }

    if ((status = nc_def_var(exoid, name, int_type, 1, dims, &propid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to create property array variable in file id %d",
	      exoid);
      ex_err("ex_put_prop",errmsg,exerrval);
      goto error_ret;  /* Exit define mode and return */
    }

    vals[0] = 0; /* fill value */
    /*   create attribute to cause variable to fill with zeros per routine spec */
    if ((status = nc_put_att_longlong(exoid, propid, _FillValue, int_type, 1, vals)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to create property name fill attribute in file id %d",
	      exoid);
      ex_err("ex_put_prop",errmsg,exerrval);
      goto error_ret;  /* Exit define mode and return */
    }

    /*   Check that the property name length is less than MAX_NAME_LENGTH */
    prop_name_len = strlen(prop_name)+1;
    if (prop_name_len > name_length) {
      fprintf(stderr,
	      "Warning: The property name '%s' is too long.\n\tIt will be truncated from %d to %d characters\n",
	      prop_name, (int)prop_name_len-1, (int)name_length-1);
      prop_name_len = name_length;
    }

    /*   store property name as attribute of property array variable */
    if ((status = nc_put_att_text(exoid, propid, ATT_PROP_NAME, 
				  prop_name_len, (void*)prop_name)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to store property name %s in file id %d",
	      prop_name,exoid);
      ex_err("ex_put_prop",errmsg,exerrval);
      goto error_ret;  /* Exit define mode and return */
    }

    ex_update_max_name_length(exoid, prop_name_len-1);
    
    /* leave define mode  */
    if ((status = nc_enddef (exoid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to leave define mode in file id %d",
	      exoid);
      ex_err("ex_put_prop",errmsg,exerrval);
      return (EX_FATAL);
    }

    nc_set_fill(exoid, oldfill, &temp); /* default: nofill */
  }

  /* find index into property array using obj_id; put value in property */
  /* array at proper index; ex_id_lkup returns an index that is 1-based,*/
  /* but netcdf expects 0-based arrays so subtract 1                    */

  /* special case: property name ID - check for duplicate ID assignment */
  if (strcmp("ID",prop_name) == 0) {
    start[0] = ex_id_lkup (exoid, obj_type, value);
    if (exerrval != EX_LOOKUPFAIL)   /* found the id */
      {
	exerrval = EX_BADPARAM;
	sprintf(errmsg,
		"Warning: attempt to assign duplicate %s ID %"PRId64" in file id %d",
		ex_name_of_object(obj_type), value, exoid);
	ex_err("ex_put_prop",errmsg,exerrval);
	return (EX_WARN);
      }
  }

  start[0] = ex_id_lkup (exoid, obj_type, obj_id);
  if (exerrval != 0) {
    if (exerrval == EX_NULLENTITY) {
      sprintf(errmsg,
	      "Warning: no properties allowed for NULL %s id %"PRId64" in file id %d",
	      ex_name_of_object(obj_type), obj_id,exoid);
      ex_err("ex_put_prop",errmsg,EX_MSG);
      return (EX_WARN);
    } else {
      sprintf(errmsg,
	      "Error: failed to find value %"PRId64" in %s property array in file id %d",
	      obj_id, ex_name_of_object(obj_type), exoid);
      ex_err("ex_put_prop",errmsg,exerrval);
      return (EX_FATAL);
    }
  }

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

  /* value is of type 'ex_entity_id' which is a typedef to int64_t or long long */
  status = nc_put_var1_longlong(exoid, propid, start, (long long*)&value);

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

  return (EX_NOERR);

  /* Fatal error: exit definition mode and return */
 error_ret:
  nc_set_fill(exoid, oldfill, &temp); /* default: nofill */

  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_prop",errmsg,exerrval);
  }
  return (EX_FATAL);
}
示例#9
0
int ex_get_prop (int   exoid,
                 ex_entity_type obj_type,
                 ex_entity_id   obj_id,
                 const char *prop_name,
                 void_int  *value)
{
   int status;
   int num_props, i, propid;
   int found = EX_FALSE;
   size_t start[1]; 
   char name[MAX_VAR_NAME_LENGTH+1];
   char tmpstr[MAX_STR_LENGTH+1];

   char errmsg[MAX_ERR_LENGTH];

   exerrval  = 0; /* clear error code */

   /* open appropriate variable, depending on obj_type and prop_name */
   num_props = ex_get_num_props(exoid,obj_type);

   for (i=1; i<=num_props; i++) {
     switch (obj_type){
       case EX_ELEM_BLOCK:
         strcpy (name, VAR_EB_PROP(i));
         break;
       case EX_EDGE_BLOCK:
         strcpy (name, VAR_ED_PROP(i));
         break;
       case EX_FACE_BLOCK:
         strcpy (name, VAR_FA_PROP(i));
         break;
       case EX_NODE_SET:
         strcpy (name, VAR_NS_PROP(i));
         break;
       case EX_EDGE_SET:
         strcpy (name, VAR_ES_PROP(i));
         break;
       case EX_FACE_SET:
         strcpy (name, VAR_FS_PROP(i));
         break;
       case EX_ELEM_SET:
         strcpy (name, VAR_ELS_PROP(i));
         break;
       case EX_SIDE_SET:
         strcpy (name, VAR_SS_PROP(i));
         break;
       case EX_ELEM_MAP:
         strcpy (name, VAR_EM_PROP(i));
         break;
       case EX_FACE_MAP:
         strcpy (name, VAR_FAM_PROP(i));
         break;
       case EX_EDGE_MAP:
         strcpy (name, VAR_EDM_PROP(i));
         break;
       case EX_NODE_MAP:
         strcpy (name, VAR_NM_PROP(i));
         break;
       default:
         exerrval = EX_BADPARAM;
         sprintf(errmsg, "Error: object type %d not supported; file id %d",
           obj_type, exoid);
         ex_err("ex_get_prop",errmsg,exerrval);
         return(EX_FATAL);
     }

     if ((status = nc_inq_varid(exoid, name, &propid)) != NC_NOERR) {
       exerrval = status;
       sprintf(errmsg,
          "Error: failed to locate property array %s in file id %d",
               name, exoid);
       ex_err("ex_get_prop",errmsg,exerrval);
       return (EX_FATAL);
     }

     /*   compare stored attribute name with passed property name   */
     memset(tmpstr, 0, MAX_STR_LENGTH+1);
     if ((status = nc_get_att_text(exoid, propid, ATT_PROP_NAME, tmpstr)) != NC_NOERR) {
       exerrval = status;
       sprintf(errmsg,
              "Error: failed to get property name in file id %d", exoid);
       ex_err("ex_get_prop",errmsg,exerrval);
       return (EX_FATAL);
     }

     if (strcmp(tmpstr, prop_name) == 0) {
       found = EX_TRUE;
       break;
     }
   }

   /* if property is not found, return warning */
   if (!found) {
     exerrval = EX_BADPARAM;
     sprintf(errmsg,
       "Warning: %s property %s not defined in file id %d",
	     ex_name_of_object(obj_type), prop_name, exoid);
     ex_err("ex_get_prop",errmsg,exerrval);
     return (EX_WARN);
   }

   /* find index into property array using obj_id; read value from property */
   /* array at proper index; ex_id_lkup returns an index that is 1-based,   */
   /* but netcdf expects 0-based arrays so subtract 1                       */
   start[0] = ex_id_lkup (exoid, obj_type, obj_id);
   if (exerrval != 0)  {
     if (exerrval == EX_NULLENTITY) {
       sprintf(errmsg,
              "Warning: %s id %"PRId64" is NULL in file id %d",
               ex_name_of_object(obj_type), obj_id, exoid);
       ex_err("ex_get_prop",errmsg,EX_NULLENTITY);
       return (EX_WARN);
     } else {
       exerrval = status;
       sprintf(errmsg,
             "Error: failed to locate id %"PRId64" in %s property array in file id %d",
               obj_id, ex_name_of_object(obj_type), exoid);
       ex_err("ex_get_prop",errmsg,exerrval);
       return (EX_FATAL);
     }
   }
   start[0] = start[0] - 1;

   if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
     long long l_val;
     status = nc_get_var1_longlong (exoid, propid, start, &l_val);
     if (status == NC_NOERR) {
       int64_t *val = (int64_t*)value;
       *val = l_val;
     }
   } else {
     int     i_val;
     status = nc_get_var1_int (exoid, propid, start, &i_val);
     if (status == NC_NOERR) {
       int *val = (int*)value;
       *val = i_val;
     }
   }

   if (status != NC_NOERR) {
     exerrval = status;
     sprintf(errmsg,
            "Error: failed to read value in %s property array in file id %d",
             ex_name_of_object(obj_type), exoid);
     ex_err("ex_get_prop",errmsg,exerrval);
     return (EX_FATAL);
   }

   return (EX_NOERR);
}
示例#10
0
int ex_put_prop (int   exoid,
                 int   obj_type,
                 int   obj_id,
                 const char *prop_name,
                 int   value)
{
   int found = FALSE;
   int num_props, i, dimid, propid, dims[1];
   long start[1]; 
   nclong ldum;
   char name[MAX_VAR_NAME_LENGTH+1];
   char obj_stype[MAX_VAR_NAME_LENGTH+1];
   char obj_vtype[MAX_VAR_NAME_LENGTH+1];
   char tmpstr[MAX_VAR_NAME_LENGTH+1];
   char dim_name[MAX_VAR_NAME_LENGTH+1];

   char errmsg[MAX_ERR_LENGTH];

   exerrval  = 0; /* clear error code */

/* check if property has already been created */

   num_props = ex_get_num_props(exoid, obj_type);

   switch (obj_type)
   {
     case EX_ELEM_BLOCK:
       strcpy (obj_vtype, VAR_ID_EL_BLK);
       strcpy (obj_stype, "element block");
       break;
     case EX_NODE_SET:
       strcpy (obj_vtype, VAR_NS_IDS);
       strcpy (obj_stype, "node set");
       break;
     case EX_SIDE_SET:
       strcpy (obj_vtype, VAR_SS_IDS);
       strcpy (obj_stype, "side set");
       break;
     case EX_ELEM_MAP:
       strcpy (obj_vtype, VAR_EM_PROP(1));
       strcpy (obj_stype, "element map");
       break;
     case EX_NODE_MAP:
       strcpy (obj_vtype, VAR_NM_PROP(1));
       strcpy (obj_stype, "node map");
       break;
     default:
       exerrval = EX_BADPARAM;
       sprintf(errmsg, "Error: object type %d not supported; file id %d",
               obj_type, exoid);
       ex_err("ex_put_prop",errmsg,exerrval);
       return(EX_FATAL);
   }

   if (num_props > 1)   /* any properties other than the default 1? */
   {

   for (i=1; i<=num_props; i++)
   {
     switch (obj_type)
     {
       case EX_ELEM_BLOCK:
         strcpy (name, VAR_EB_PROP(i));
         break;
       case EX_NODE_SET:
         strcpy (name, VAR_NS_PROP(i));
         break;
       case EX_SIDE_SET:
         strcpy (name, VAR_SS_PROP(i));
         break;
       case EX_ELEM_MAP:
         strcpy (name, VAR_EM_PROP(i));
         break;
       case EX_NODE_MAP:
         strcpy (name, VAR_NM_PROP(i));
         break;
       default:
         exerrval = EX_BADPARAM;
         sprintf(errmsg, "Error: object type %d not supported; file id %d",
                 obj_type, exoid);
         ex_err("ex_put_prop",errmsg,exerrval);
         return(EX_FATAL);
     }

     if ((propid = ncvarid (exoid, name)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
          "Error: failed to get property array id in file id %d",
               exoid);
       ex_err("ex_put_prop",errmsg,exerrval);
       return (EX_FATAL);
     }

/*   compare stored attribute name with passed property name   */

     if ((ncattget (exoid, propid, ATT_PROP_NAME, tmpstr)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Error: failed to get property name in file id %d", exoid);
       ex_err("ex_put_prop",errmsg,exerrval);
       return (EX_FATAL);
     }

     if (strcmp(tmpstr, prop_name) == 0) 
     {
       found = TRUE;
       break;
     }
   }
   }

/* if property array has not been created, create it */

   if (!found)
   {
/* put netcdf file into define mode  */

     if (ncredef (exoid) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,"Error: failed to place file id %d into define mode",exoid);
       ex_err("ex_put_prop",errmsg,exerrval);
       return (EX_FATAL);
     }

/*   create a variable with a name xx_prop#, where # is the new number   */
/*   of the property                                                     */

     switch (obj_type){
       case EX_ELEM_BLOCK:
         strcpy (name, VAR_EB_PROP(num_props+1));
         strcpy (dim_name, DIM_NUM_EL_BLK);
         break;
       case EX_NODE_SET:
         strcpy (name, VAR_NS_PROP(num_props+1));
         strcpy (dim_name, DIM_NUM_NS);
         break;
       case EX_SIDE_SET:
         strcpy (name, VAR_SS_PROP(num_props+1));
         strcpy (dim_name, DIM_NUM_SS);
         break;
       case EX_ELEM_MAP:
         strcpy (name, VAR_EM_PROP(num_props+1));
         strcpy (dim_name, DIM_NUM_EM);
         break;
       case EX_NODE_MAP:
         strcpy (name, VAR_NM_PROP(num_props+1));
         strcpy (dim_name, DIM_NUM_NM);
         break;
       default:
         exerrval = EX_BADPARAM;
         sprintf(errmsg, "Error: object type %d not supported; file id %d",
           obj_type, exoid);
         ex_err("ex_put_prop",errmsg,exerrval);
         goto error_ret;        /* Exit define mode and return */
     }

/*   inquire id of previously defined dimension (number of objects) */

     if ((dimid = ncdimid (exoid, dim_name)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
       "Error: failed to locate number of objects in file id %d",
                exoid);
       ex_err("ex_put_prop",errmsg, exerrval);
       goto error_ret;  /* Exit define mode and return */
     }

     dims[0] = dimid;
     ncsetfill(exoid, NC_FILL); /* fill with zeros per routine spec */

     if ((propid = ncvardef (exoid, name, NC_LONG, 1, dims)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
          "Error: failed to create property array variable in file id %d",
               exoid);
       ex_err("ex_put_prop",errmsg,exerrval);
       goto error_ret;  /* Exit define mode and return */
     }
     ncsetfill(exoid, NC_NOFILL); /* default: nofill */

/*   store property name as attribute of property array variable */

     if ((ncattput (exoid, propid, ATT_PROP_NAME, NC_CHAR,
                    strlen(prop_name)+1, prop_name)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Error: failed to store property name %s in file id %d",
               prop_name,exoid);
       ex_err("ex_put_prop",errmsg,exerrval);
       goto error_ret;  /* Exit define mode and return */
     }

/* leave define mode  */

     if (ncendef (exoid) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to leave define mode in file id %d",
          exoid);
       ex_err("ex_put_prop",errmsg,exerrval);
       return (EX_FATAL);
     }

   }

/* find index into property array using obj_id; put value in property */
/* array at proper index; ex_id_lkup returns an index that is 1-based,*/
/* but netcdf expects 0-based arrays so subtract 1                    */

   /* special case: property name ID - check for duplicate ID assignment */
   if (strcmp("ID",prop_name) == 0)
   {
     start[0] = ex_id_lkup (exoid, obj_vtype, value);
     if (exerrval != EX_LOOKUPFAIL)   /* found the id */
     {
       exerrval = EX_BADPARAM;
       sprintf(errmsg,
              "Warning: attempt to assign duplicate %s ID %d in file id %d",
               obj_stype, value, exoid);
       ex_err("ex_put_prop",errmsg,exerrval);
       return (EX_WARN);
     }
   }

   start[0] = ex_id_lkup (exoid, obj_vtype, obj_id);
   if (exerrval != 0) 
   {
     if (exerrval == EX_NULLENTITY)
     {
       sprintf(errmsg,
              "Warning: no properties allowed for NULL %s id %d in file id %d",
               obj_stype, obj_id,exoid);
       ex_err("ex_put_prop",errmsg,EX_MSG);
       return (EX_WARN);
     }
     else
     {

       exerrval = ncerr;
       sprintf(errmsg,
            "Error: failed to find value %d in %s property array in file id %d",
               obj_id, obj_stype, exoid);
       ex_err("ex_put_prop",errmsg,exerrval);
       return (EX_FATAL);
     }
   }

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

   ldum = (nclong)value;
   if (ncvarput1 (exoid, propid, start, &ldum) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to store property value in file id %d",
             exoid);
     ex_err("ex_put_prop",errmsg,exerrval);
     return (EX_FATAL);
   }

   return (EX_NOERR);

/* Fatal error: exit definition mode and return */
error_ret:
  ncsetfill(exoid, NC_NOFILL); /* default: nofill */

  if (ncendef (exoid) == -1)     /* exit define mode */
  {
    sprintf(errmsg,
           "Error: failed to complete definition for file id %d",
            exoid);
    ex_err("ex_put_prop",errmsg,exerrval);
  }
  return (EX_FATAL);
}
示例#11
0
文件: exgpn.c 项目: 151706061/VTK
int ex_get_prop_names (int    exoid,
                       ex_entity_type obj_type,
                       char **prop_names)
{
  int status;
  int i, num_props, propid;
  char var_name[12];
  size_t att_len;
  nc_type att_type;

  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0;

  /* determine which type of object property names are desired for */

  num_props = ex_get_num_props (exoid, obj_type);

  for (i=0; i<num_props; i++) {
    switch (obj_type) {
    case EX_ELEM_BLOCK:
      strcpy (var_name, VAR_EB_PROP(i+1));
      break;
    case EX_FACE_BLOCK:
      strcpy (var_name, VAR_FA_PROP(i+1));
      break;
    case EX_EDGE_BLOCK:
      strcpy (var_name, VAR_ED_PROP(i+1));
      break;
    case EX_NODE_SET:
      strcpy (var_name, VAR_NS_PROP(i+1));
      break;
    case EX_SIDE_SET:
      strcpy (var_name, VAR_SS_PROP(i+1));
      break;
    case EX_EDGE_SET:
      strcpy (var_name, VAR_ES_PROP(i+1));
      break;
    case EX_FACE_SET:
      strcpy (var_name, VAR_FS_PROP(i+1));
      break;
    case EX_ELEM_SET:
      strcpy (var_name, VAR_ELS_PROP(i+1));
      break;
    case EX_ELEM_MAP:
      strcpy (var_name, VAR_EM_PROP(i+1));
      break;
    case EX_FACE_MAP:
      strcpy (var_name, VAR_FAM_PROP(i+1));
      break;
    case EX_EDGE_MAP:
      strcpy (var_name, VAR_EDM_PROP(i+1));
      break;
    case EX_NODE_MAP:
      strcpy (var_name, VAR_NM_PROP(i+1));
      break;
    default:
      exerrval = EX_BADPARAM;
      sprintf(errmsg, "Error: object type %d not supported; file id %d",
        obj_type, exoid);
      ex_err("ex_get_prop_names",errmsg,EX_BADPARAM);
      return(EX_FATAL);
    }

    if ((status = nc_inq_varid(exoid, var_name, &propid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
        "Error: failed to locate property array %s in file id %d",
        var_name, exoid);
      ex_err("ex_get_prop_names",errmsg,exerrval);
      return (EX_FATAL);
    }

    /*   for each property, read the "name" attribute of property array variable */
    if ((status = nc_inq_att(exoid, propid, ATT_PROP_NAME, &att_type, &att_len)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
        "Error: failed to get property attributes (type, len) in file id %d", exoid);
      ex_err("ex_get_prop_names",errmsg,exerrval);
      return (EX_FATAL);
    }

    if (att_len-1 <= ex_max_name_length) {
      /* Client has large enough char string to hold text... */
      if ((status = nc_get_att_text(exoid, propid, ATT_PROP_NAME, prop_names[i])) != NC_NOERR) {
  exerrval = status;
  sprintf(errmsg,
    "Error: failed to get property name in file id %d", exoid);
  ex_err("ex_get_prop_names",errmsg,exerrval);
  return (EX_FATAL);
      }
    }
    else {
      /* FIXME */
      exerrval = NC_ESTS;
      sprintf(errmsg,
        "Error: property name length exceeds space available to store it in file id %d", exoid);
      ex_err("ex_get_prop_names",errmsg,exerrval);
      return (EX_FATAL);
    }
  }
  return (EX_NOERR);
}