コード例 #1
0
ファイル: exgpem.c プロジェクト: hs9906/paraview
int ex_get_partial_elem_map (int   exoid,
           int   map_id,
           int ent_start,
           int ent_count, 
           int  *elem_map)
{
   int dimid, var_id, id_ndx, iresult;
   long num_elem, start[1], count[1]; 
   nclong *longs;
   char errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

   /* See if file contains any elements...*/
   if ((dimid = ncdimid (exoid, DIM_NUM_ELEM)) == -1)
   {
     return (EX_NOERR);
   }

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

  /* Check input parameters for a valid range of numbers */
  if (ent_start <= 0 || ent_start > num_elem) {
    exerrval = EX_FATAL;
    sprintf(errmsg,
      "Error: start count is invalid in file id %d",
      exoid);
    ex_err("ex_get_partial_elem_map",errmsg,exerrval);
    return (EX_FATAL);
  }
  if (ent_count < 0) {
    exerrval = EX_FATAL;
    sprintf(errmsg,
      "Error: Invalid count value in file id %d",
      exoid);
    ex_err("ex_get_partial_elem_map",errmsg,exerrval);
    return (EX_FATAL);
  }
  if (ent_start+ent_count-1 > num_elem) {
    exerrval = EX_FATAL;
    sprintf(errmsg,
      "Error: start+count-1 is larger than element count in file id %d",
      exoid);
    ex_err("ex_get_partial_elem_map",errmsg,exerrval);
    return (EX_FATAL);
  }

/* first check if any element maps have been defined */

   if ((dimid = ncdimid (exoid, DIM_NUM_EM))  == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Warning: no element maps defined in file id %d",
             exoid);
     ex_err("ex_get_partial_elem_map",errmsg,exerrval);
     return (EX_WARN);
   }

/* Lookup index of element map id property array */

   id_ndx = ex_id_lkup(exoid,VAR_EM_PROP(1),map_id);
   if (exerrval != 0) 
   {

      sprintf(errmsg,
              "Error: failed to locate element map id %d in %s in file id %d",
               map_id,VAR_EM_PROP(1),exoid);
      ex_err("ex_get_partial_elem_map",errmsg,exerrval);
      return (EX_FATAL);
   }

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

   if ((var_id = ncvarid (exoid, VAR_ELEM_MAP(id_ndx))) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to locate element map %d in file id %d",
             map_id,exoid);
     ex_err("ex_get_partial_elem_map",errmsg,exerrval);
     return (EX_FATAL);
   }


/* read in the element map */

/* 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] = ent_start-1;
   count[0] = ent_count;

   if (sizeof(int) == sizeof(nclong)) {
     iresult = ncvarget (exoid, var_id, start, count, elem_map);
   } else {
     if (!(longs = malloc(ent_count * sizeof(nclong)))) {
       exerrval = EX_MEMFAIL;
       sprintf(errmsg,
               "Error: failed to allocate memory for element map for file id %d",
               exoid);
       ex_err("ex_get_partial_elem_map",errmsg,exerrval);
       return (EX_FATAL);
     }
      iresult = ncvarget (exoid, var_id, start, count, longs);
   }

   if (iresult == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to get element map in file id %d",
             exoid);
     ex_err("ex_get_partial_elem_map",errmsg,exerrval);
     return (EX_FATAL);
   }

   if (sizeof(int) != sizeof(nclong)) {
      ltoi (longs, elem_map, ent_count);
      free (longs);
   }

   return (EX_NOERR);

}
コード例 #2
0
ファイル: exgset.c プロジェクト: CPFDSoftware-Tony/gmv
int ex_get_set (int   exoid,
                int   set_type,
                int   set_id,
                int  *set_entry_list,
                int  *set_extra_list)
{

    int dimid, entry_list_id, extra_list_id, iresult;
    int set_id_ndx;
    long num_entry_in_set, count[1], start[1];
    nclong *longs;
    char errmsg[MAX_ERR_LENGTH];
    char* typeName;
    char* dimptr;
    char* idsptr;
    char* numentryptr;
    char* entryptr;
    char* extraptr;

    exerrval = 0; /* clear error code */

    /* setup pointers based on set_type
     NOTE: there is another block that sets more stuff later ... */
    if (set_type == EX_NODE_SET) {
        typeName = "node";
        dimptr = DIM_NUM_NS;
        idsptr = VAR_NS_IDS;
    }
    else if (set_type == EX_EDGE_SET) {
        typeName = "edge";
        dimptr = DIM_NUM_ES;
        idsptr = VAR_ES_IDS;
    }
    else if (set_type == EX_FACE_SET) {
        typeName = "face";
        dimptr = DIM_NUM_FS;
        idsptr = VAR_FS_IDS;
    }
    else if (set_type == EX_SIDE_SET) {
        typeName = "side";
        dimptr = DIM_NUM_SS;
        idsptr = VAR_SS_IDS;
    }
    else if (set_type == EX_ELEM_SET) {
        typeName = "elem";
        dimptr = DIM_NUM_ELS;
        idsptr = VAR_ELS_IDS;
    }
    else {
        exerrval = EX_FATAL;
        sprintf(errmsg,
                "Error: invalid set type (%d)", set_type);
        ex_err("ex_put_set_param",errmsg,exerrval);
        return (EX_FATAL);
    }

    /* first check if any sets are specified */

    if ((dimid = ncdimid (exoid, dimptr)) == -1)
    {
        exerrval = ncerr;
        sprintf(errmsg,
                "Warning: no %s sets stored in file id %d",
                typeName, exoid);
        ex_err("ex_get_set",errmsg,exerrval);
        return (EX_WARN);
    }

    /* Lookup index of set id in VAR_*S_IDS array */

    set_id_ndx = ex_id_lkup(exoid,idsptr,set_id);
    if (exerrval != 0)
    {
        if (exerrval == EX_NULLENTITY)
        {
            sprintf(errmsg,
                    "Warning: %s set %d is NULL in file id %d",
                    typeName, set_id,exoid);
            ex_err("ex_get_set",errmsg,EX_MSG);
            return (EX_WARN);
        }
        else
        {

            sprintf(errmsg,
                    "Error: failed to locate %s set id %d in VAR_*S_IDS array in file id %d",
                    typeName, set_id,exoid);
            ex_err("ex_get_set",errmsg,exerrval);
            return (EX_FATAL);
        }
    }

    /* setup more pointers based on set_type */

    if (set_type == EX_NODE_SET) {
        numentryptr = DIM_NUM_NOD_NS(set_id_ndx);
        entryptr = VAR_NODE_NS(set_id_ndx);
        extraptr = NULL;
    }
    else if (set_type == EX_EDGE_SET) {
        numentryptr = DIM_NUM_EDGE_ES(set_id_ndx);
        entryptr = VAR_EDGE_ES(set_id_ndx);
        extraptr = VAR_ORNT_ES(set_id_ndx);
    }
    else if (set_type == EX_FACE_SET) {
        numentryptr = DIM_NUM_FACE_FS(set_id_ndx);
        entryptr = VAR_FACE_FS(set_id_ndx);
        extraptr = VAR_ORNT_FS(set_id_ndx);
    }
    else if (set_type == EX_SIDE_SET) {
        numentryptr = DIM_NUM_SIDE_SS(set_id_ndx);
        entryptr = VAR_ELEM_SS(set_id_ndx);
        extraptr = VAR_SIDE_SS(set_id_ndx);
    }
    if (set_type == EX_ELEM_SET) {
        numentryptr = DIM_NUM_ELE_ELS(set_id_ndx);
        entryptr = VAR_ELEM_ELS(set_id_ndx);
        extraptr = NULL;
    }

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

    if ((dimid = ncdimid (exoid, numentryptr)) == -1)
    {
        exerrval = ncerr;
        sprintf(errmsg,
                "Error: failed to locate number of entries in %s set %d in file id %d",
                typeName, set_id,exoid);
        ex_err("ex_get_set",errmsg,exerrval);
        return (EX_FATAL);
    }

    if (ncdiminq (exoid, dimid, (char *) 0, &num_entry_in_set) == -1)
    {
        exerrval = ncerr;
        sprintf(errmsg,
                "Error: failed to get number of entries in %s set %d in file id %d",
                typeName, set_id,exoid);
        ex_err("ex_get_set",errmsg,exerrval);
        return (EX_FATAL);
    }

    if ((entry_list_id = ncvarid (exoid, entryptr)) == -1)
    {
        exerrval = ncerr;
        sprintf(errmsg,
                "Error: failed to locate entry list for %s set %d in file id %d",
                typeName, set_id,exoid);
        ex_err("ex_get_set",errmsg,exerrval);
        return (EX_FATAL);
    }

    /* only do extra list for edge, face and side sets */

    if (extraptr)
    {
        if ((extra_list_id = ncvarid (exoid, extraptr)) == -1)
        {
            exerrval = ncerr;
            sprintf(errmsg,
                    "Error: failed to locate extra list for %s set %d in file id %d",
                    typeName, set_id,exoid);
            ex_err("ex_get_set",errmsg,exerrval);
            return (EX_FATAL);
        }
    }


    /* read in the entry list and extra list arrays */

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

    if (sizeof(int) == sizeof(nclong)) {
        iresult = ncvarget(exoid, entry_list_id, start, count, set_entry_list);
    } else {
        if (!(longs = malloc(num_entry_in_set * sizeof(nclong)))) {
            exerrval = EX_MEMFAIL;
            sprintf(errmsg,
                    "Error: failed to allocate memory for entry list for %s set %d for file id %d",
                    typeName, set_id, exoid);
            ex_err("ex_get_set",errmsg,exerrval);
            return (EX_FATAL);
        }
        iresult = ncvarget (exoid, entry_list_id, start, count, longs);
    }

    if (iresult)
    {
        exerrval = ncerr;
        sprintf(errmsg,
                "Error: failed to get entry list for %s set %d in file id %d",
                typeName, set_id,exoid);
        ex_err("ex_get_set",errmsg,exerrval);
        return (EX_FATAL);
    }

    /* only do extra list for edge, face and side sets */

    if (extraptr)
    {
        if (sizeof(int) != sizeof(nclong)) {
            ltoi (longs, set_entry_list, num_entry_in_set);
        }

        if (sizeof(int) == sizeof(nclong)) {
            iresult = ncvarget(exoid, extra_list_id, start, count, set_extra_list);
        } else {
            iresult = ncvarget (exoid, extra_list_id, start, count, longs);
        }

        if (iresult == -1)
        {
            exerrval = ncerr;
            sprintf(errmsg,
                    "Error: failed to get extra list for %s set %d in file id %d",
                    typeName, set_id,exoid);
            ex_err("ex_get_set",errmsg,exerrval);
            return (EX_FATAL);
        }
    }

    if (sizeof(int) != sizeof(nclong)) {
        ltoi (longs, set_extra_list, num_entry_in_set);
        free (longs);
    }

    return (EX_NOERR);

}
コード例 #3
0
ファイル: exgssi.c プロジェクト: unidevop/sjtu-project-pipe
int ex_get_side_set_ids (int  exoid,
                         int *ids)
{
   int dimid, varid, iresult;
   long num_side_sets, start[1], count[1]; 
   nclong *longs;
   char errmsg[MAX_ERR_LENGTH];

   exerrval = 0;        /* clear error code */

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

   if ((dimid = ncdimid (exoid, DIM_NUM_SS)) < 0)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Warning: no side sets stored in file id %d", exoid);
     ex_err("ex_get_side_set_ids",errmsg,exerrval);
     return (EX_WARN);
   }

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


   if ((varid = ncvarid (exoid, VAR_SS_IDS)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to locate side set ids in file id %d", exoid);
     ex_err("ex_get_side_set_ids",errmsg,exerrval);
     return (EX_FATAL);
   }


/* read in the side set ids  */

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

   if (sizeof(int) == sizeof(nclong)) {
      iresult = ncvarget (exoid, varid, start, count, ids);
   } else {
     if (!(longs = malloc(num_side_sets * sizeof(nclong)))) {
       exerrval = EX_MEMFAIL;
       sprintf(errmsg,
               "Error: failed to allocate memory for side set ids for file id %d",
               exoid);
       ex_err("ex_get_side_set_ids",errmsg,exerrval);
       return (EX_FATAL);
     }
     iresult = ncvarget (exoid, varid, start, count, longs);
   }

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

   if (sizeof(int) != sizeof(nclong)) {
      ltoi (longs, ids, num_side_sets);
      free (longs);
   }

   return(EX_NOERR);
}
コード例 #4
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);
}
コード例 #5
0
ファイル: exgnnm.c プロジェクト: unidevop/sjtu-project-pipe
int ex_get_node_num_map (int  exoid,
                int *node_map)
{
   int numnodedim, mapid, i, iresult;
   long num_nodes,  start[1], count[1]; 
   nclong *longs;
   char errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

/* inquire id's of previously defined dimensions and variables  */
   if ((numnodedim = ncdimid (exoid, DIM_NUM_NODES)) == -1)
   {
     return (EX_NOERR);
   }

   if (ncdiminq (exoid, numnodedim, (char *) 0, &num_nodes) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to get number of nodes in file id %d",
             exoid);
     ex_err("ex_get_node_num_map",errmsg,exerrval);
     return (EX_FATAL);
   }


   if ((mapid = ncvarid (exoid, VAR_NODE_NUM_MAP)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
  "Warning: node numbering map not stored in file id %d; returning default map",
             exoid);
     ex_err("ex_get_node_num_map",errmsg,exerrval);

/* generate default map of 1..n, where n is num_nodes */
     for (i=0; i<num_nodes; i++)
        node_map[i] = i+1;

     return (EX_WARN);
   }


/* read in the node numbering map  */

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

   if (sizeof(int) == sizeof(nclong)) {
      iresult = ncvarget (exoid, mapid, start, count, node_map);
   } else {
     if (!(longs = malloc(num_nodes * sizeof(nclong)))) {
       exerrval = EX_MEMFAIL;
       sprintf(errmsg,
               "Error: failed to allocate memory for node numbering map for file id %d",
               exoid);
       ex_err("ex_get_node_num_map",errmsg,exerrval);
       return (EX_FATAL);
     }
      iresult = ncvarget (exoid, mapid, start, count, longs);
   }

   if (iresult == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to get node numbering map in file id %d",
             exoid);
     ex_err("ex_get_node_num_map",errmsg,exerrval);
     return (EX_FATAL);
   }

   if (sizeof(int) != sizeof(nclong)) {
      ltoi (longs, node_map, num_nodes);
      free (longs);
   }


   return(EX_NOERR);

}
コード例 #6
0
ファイル: exgotv.c プロジェクト: CPFDSoftware-Tony/gmv
int ex_get_object_truth_vector (int  exoid,
				const char *obj_type,
				int  entity_id,
				int  num_var,
				int *var_vec)
{
   int varid, tabid, i, iresult, ent_ndx;
   long num_var_db = -1;
   long start[2], count[2]; 
   nclong *longs;
   char errmsg[MAX_ERR_LENGTH];
   const char* routine = "ex_get_object_truth_vector";

   /*
    * The ent_type and the var_name are used to build the netcdf
    * variables name.  Normally this is done via a macro defined in
    * exodusII_int.h
    */
   const char* ent_type = NULL;
   const char* var_name = NULL;

   exerrval = 0; /* clear error code */
   
   if (*obj_type == 'e' || *obj_type == 'E') {
     varid = ex_get_dimension(exoid, DIM_NUM_ELE_VAR,  "element variables", &num_var_db, routine);
     tabid = ncvarid (exoid, VAR_ELEM_TAB);
     var_name = "vals_elem_var";
     ent_ndx = ex_id_lkup(exoid, VAR_ID_EL_BLK, entity_id);
     ent_type = "eb";
   }
   else if (*obj_type == 'm' || *obj_type == 'M') {
     varid = ex_get_dimension(exoid, DIM_NUM_NSET_VAR, "nodeset variables", &num_var_db, routine);
     tabid = ncvarid (exoid, VAR_NSET_TAB);
     var_name = "vals_nset_var";
     ent_ndx = ex_id_lkup(exoid, VAR_NS_IDS, entity_id);
     ent_type = "ns";
   }
   else if (*obj_type == 's' || *obj_type == 'S') {
     varid = ex_get_dimension(exoid, DIM_NUM_SSET_VAR, "sideset variables", &num_var_db, routine);
     tabid = ncvarid (exoid, VAR_SSET_TAB);
     var_name = "vals_sset_var";
     ent_ndx = ex_id_lkup(exoid, VAR_SS_IDS, entity_id);
     ent_type = "ss";
   }
   else {       /* invalid variable type */
     exerrval = EX_BADPARAM;
     sprintf(errmsg,
	     "Error: Invalid variable type %c specified in file id %d",
	     *obj_type, exoid);
     ex_err("ex_get_varid",errmsg,exerrval);
     return (EX_WARN);
   }
   
   if (varid == -1) {
     exerrval = ncerr;
     return (EX_WARN);
   }


   if (num_var_db != num_var) {
     exerrval = EX_FATAL;
     sprintf(errmsg,
	     "Error: # of variables doesn't match those defined in file id %d", exoid);
     ex_err("ex_get_object_truth_vector",errmsg,exerrval);
     return (EX_FATAL);
   }

   if (tabid == -1) {
     /* since truth vector isn't stored in the data file, derive it dynamically */
     for (i=0; i<num_var; i++) {
       /* NOTE: names are 1-based */
       if ((tabid = ncvarid (exoid, ex_catstr2(var_name, i+1, ent_type, ent_ndx))) == -1) {
	 
	 /* variable doesn't exist; put a 0 in the truth vector */
	 var_vec[i] = 0;
       } else {
	 /* variable exists; put a 1 in the truth vector */
	 var_vec[i] = 1;
       }
     }
   } else {

     /* read in the truth vector */

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

     /* If this is a null entity, then 'ent_ndx' will be negative.
      * We don't care in this routine, so make it positive and continue...
      */
     if (ent_ndx < 0) ent_ndx = -ent_ndx;
     
     start[0] = ent_ndx-1;
     start[1] = 0;

     count[0] = 1;
     count[1] = num_var;

     if (sizeof(int) == sizeof(nclong)) {
        iresult = ncvarget (exoid, tabid, start, count, var_vec);
     } else {
       if (!(longs = malloc (num_var * sizeof(nclong)))) {
         exerrval = EX_MEMFAIL;
         sprintf(errmsg,
                 "Error: failed to allocate memory for truth vector for file id %d",
                 exoid);
         ex_err("ex_get_object_truth_vector",errmsg,exerrval);
         return (EX_FATAL);
       }
       iresult = ncvarget (exoid, tabid, start, count, longs);
     }
     
     if (iresult == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
               "Error: failed to get truth vector from file id %d", exoid);
       ex_err("ex_get_object_truth_vector",errmsg,exerrval);
       return (EX_FATAL);
     }

     if (sizeof(int) != sizeof(nclong)) {
       ltoi (longs, var_vec, num_var);
       free (longs);
     }

   } 


   return (EX_NOERR);

}
コード例 #7
0
ファイル: exgns.c プロジェクト: unidevop/sjtu-project-pipe
int ex_get_node_set (int   exoid,
                     int   node_set_id,
                     int  *node_set_node_list)
{
   int dimid, node_list_id, node_set_id_ndx, iresult;
   long num_nodes_in_set, start[1], count[1]; 
   nclong *longs;
   char errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

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

   if ((dimid = ncdimid (exoid, DIM_NUM_NS))  == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Warning: no node sets defined in file id %d",
             exoid);
     ex_err("ex_get_node_set",errmsg,exerrval);
     return (EX_WARN);
   }

/* Lookup index of node set id in VAR_NS_IDS array */

   node_set_id_ndx = ex_id_lkup(exoid,VAR_NS_IDS,node_set_id);
   if (exerrval != 0) 
   {
     if (exerrval == EX_NULLENTITY)
     {
       sprintf(errmsg,
              "Warning: node set %d is NULL in file id %d",
               node_set_id,exoid);
       ex_err("ex_get_node_set",errmsg,EX_MSG);
       return (EX_WARN);
     }
     else
     {

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

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

   if ((dimid = ncdimid (exoid, DIM_NUM_NOD_NS(node_set_id_ndx))) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
         "Error: failed to locate number of nodes in node set %d in file id %d",
             node_set_id,exoid);
     ex_err("ex_get_node_set",errmsg,exerrval);
     return (EX_FATAL);
   }

   if (ncdiminq (exoid, dimid, (char *) 0, &num_nodes_in_set) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to get number of nodes in set %d in file id %d",
             node_set_id, exoid);
     ex_err("ex_get_node_set",errmsg,exerrval);
     return (EX_FATAL);
   }


   if ((node_list_id = ncvarid (exoid, VAR_NODE_NS(node_set_id_ndx))) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to locate node set %d node list in file id %d",
             node_set_id,exoid);
     ex_err("ex_get_node_set",errmsg,exerrval);
     return (EX_FATAL);
   }


/* read in the node list array */

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

   if (sizeof(int) == sizeof(nclong)) {
     iresult = ncvarget (exoid, node_list_id, start, count, node_set_node_list);
   } else {
     if (!(longs = malloc(num_nodes_in_set * sizeof(nclong)))) {
       exerrval = EX_MEMFAIL;
       sprintf(errmsg,
               "Error: failed to allocate memory for node set node list for file id %d",
               exoid);
       ex_err("ex_get_node_set",errmsg,exerrval);
       return (EX_FATAL);
     }
      iresult = ncvarget (exoid, node_list_id, start, count, longs);
   }

   if (iresult == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to get node set node list in file id %d",
             exoid);
     ex_err("ex_get_node_set",errmsg,exerrval);
     return (EX_FATAL);
   }

   if (sizeof(int) != sizeof(nclong)) {
      ltoi (longs, node_set_node_list, num_nodes_in_set);
      free (longs);
   }

   return (EX_NOERR);

}
コード例 #8
0
ファイル: exgconn.c プロジェクト: CPFDSoftware-Tony/gmv
int ex_get_conn( int   exoid,
                 int   blk_type,
                 int   blk_id,
                 int*  nodeconn,
                 int*  edgeconn,
                 int*  faceconn )
{
   int numblkentriesdim, connid, econnid, fconnid, blk_id_ndx, iresult;
   int numnodperentdim, numedgperentdim, numfacperentdim;
   int iexit = (EX_NOERR); /* exit status */
   long num_entries_this_blk, num_nodes_per_entry, num_edges_per_entry, num_faces_per_entry;
   long start[2], count[2]; 
   nclong *longs;
   char errmsg[MAX_ERR_LENGTH];

   const char* tname;
   const char* vblkids;
   const char* dnumblkent;
   const char* dnumnodent;
   const char* dnumedgent;
   const char* dnumfacent;
   const char* vnodeconn;
   const char* vedgeconn;
   const char* vfaceconn;

   /* Should we warn if edgeconn or faceconn are non-NULL?
    * No, fail silently so the same code can be used to read any type of block info.
    * However, we will warn if edgeconn or faceconn are NULL but num_edges_per_entry
    * or num_faces_per_entry (respectively) are positive.
    */
   switch (blk_type) {
   case EX_EDGE_BLOCK:
     tname = "edge";
     vblkids = VAR_ID_ED_BLK;
     break;
   case EX_FACE_BLOCK:
     tname = "face";
     vblkids = VAR_ID_FA_BLK;
     break;
   case EX_ELEM_BLOCK:
     tname = "element";
     vblkids = VAR_ID_EL_BLK;
     break;
   default:
     exerrval = EX_BADPARAM;
     sprintf( errmsg, "Error: Invalid block type (%d) specified in file id %d", blk_type, exoid );
     ex_err( "ex_get_conn", errmsg, exerrval );
     return (EX_FATAL);
   }

   exerrval = 0; /* clear error code */

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

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

   switch (blk_type) {
   case EX_EDGE_BLOCK:
     dnumblkent = DIM_NUM_ED_IN_EBLK(blk_id_ndx);
     dnumnodent = DIM_NUM_NOD_PER_ED(blk_id_ndx);
     dnumedgent = 0;
     dnumfacent = 0;
     vnodeconn = VAR_EBCONN(blk_id_ndx);
     vedgeconn = 0;
     vfaceconn = 0;
     break;
   case EX_FACE_BLOCK:
     dnumblkent = DIM_NUM_FA_IN_FBLK(blk_id_ndx);
     dnumnodent = DIM_NUM_NOD_PER_FA(blk_id_ndx);
     dnumedgent = 0;
     dnumfacent = 0;
     vnodeconn = VAR_FBCONN(blk_id_ndx);
     vedgeconn = 0;
     vfaceconn = 0;
     break;
   case EX_ELEM_BLOCK:
     dnumblkent = DIM_NUM_EL_IN_BLK(blk_id_ndx);
     dnumnodent = DIM_NUM_NOD_PER_EL(blk_id_ndx);
     dnumedgent = DIM_NUM_EDG_PER_EL(blk_id_ndx);
     dnumfacent = DIM_NUM_FAC_PER_EL(blk_id_ndx);
     vnodeconn = VAR_CONN(blk_id_ndx);
     vedgeconn = VAR_ECONN(blk_id_ndx);
     vfaceconn = VAR_FCONN(blk_id_ndx);
     break;
   }
/* inquire id's of previously defined dimensions  */

   if ((numblkentriesdim = ncdimid (exoid, dnumblkent)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
     "Error: failed to locate number of elements in %s block %d in file id %d",
              tname,blk_id,exoid);
     ex_err("ex_get_conn",errmsg, exerrval);
     return(EX_FATAL);
   }

   if (ncdiminq (exoid, numblkentriesdim, (char *) 0, &num_entries_this_blk) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
           "Error: failed to get number of entries in %s block %d in file id %d",
             tname,blk_id,exoid);
     ex_err("ex_get_conn",errmsg,exerrval);
     return(EX_FATAL);
   }


   if ((numnodperentdim = ncdimid (exoid, dnumnodent)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
      "Error: failed to locate number of nodes/elem for block %d in file id %d",
             blk_id,exoid);
     ex_err("ex_get_conn",errmsg,exerrval);
     return(EX_FATAL);
   }

   if (ncdiminq (exoid, numnodperentdim, (char *) 0, &num_nodes_per_entry) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
       "Error: failed to get number of nodes/elem for block %d in file id %d",
             blk_id,exoid);
     ex_err("ex_get_conn",errmsg, exerrval);
     return(EX_FATAL);
   }

   if ( dnumedgent ) {
     num_edges_per_entry = 0;
     if ((numedgperentdim = ncdimid (exoid, dnumedgent)) == -1) {
       numedgperentdim = -1;
     } else {
       if (ncdiminq (exoid, numedgperentdim, (char *) 0, &num_edges_per_entry) == -1) {
         exerrval = ncerr;
         sprintf(errmsg,
           "Error: failed to get number of edges/entry for %s block %d in file id %d",
           tname,blk_id,exoid);
         ex_err("ex_get_conn",errmsg, exerrval);
         return(EX_FATAL);
       }
       if ( num_edges_per_entry < 0 )
         num_edges_per_entry = 0;
     }
     if ( num_edges_per_entry > 0 && (!edgeconn) ) {
       exerrval = EX_BADPARAM;
       sprintf( errmsg, "Edge connectivity present but NULL pointer passed for file id %d", exoid );
       ex_err( "ex_get_conn", errmsg, exerrval );
       iexit = exerrval;
     }
   }

   if ( dnumfacent ) {
     num_faces_per_entry = 0;
     if ((numfacperentdim = ncdimid (exoid, dnumfacent)) == -1) {
       numfacperentdim = -1;
     } else {
       if (ncdiminq (exoid, numfacperentdim, (char *) 0, &num_faces_per_entry) == -1) {
         exerrval = ncerr;
         sprintf(errmsg,
           "Error: failed to get number of faces/entry for %s block %d in file id %d",
           tname,blk_id,exoid);
         ex_err("ex_get_conn",errmsg, exerrval);
         return(EX_FATAL);
       }
       if ( num_faces_per_entry < 0 )
         num_faces_per_entry = 0;
     }
     if ( num_faces_per_entry > 0 && (!faceconn) ) {
       exerrval = EX_BADPARAM;
       sprintf( errmsg, "Face connectivity present but NULL pointer passed for file id %d", exoid );
       ex_err( "ex_get_conn", errmsg, exerrval );
       iexit = exerrval;
     }
   }


   if ((connid = ncvarid (exoid, vnodeconn)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
        "Error: failed to locate connectivity array for block %d in file id %d",
             blk_id,exoid);
     ex_err("ex_get_conn",errmsg, exerrval);
     return(EX_FATAL);
   }

   if ( edgeconn && (numedgperentdim > 0) && ((econnid = ncvarid (exoid, vedgeconn)) == -1) )
   {
     exerrval = ncerr;
     sprintf(errmsg,
        "Error: failed to locate edge connectivity array for %s block %d in file id %d",
             tname,blk_id,exoid);
     ex_err("ex_get_conn",errmsg, exerrval);
     return(EX_FATAL);
   }

   if ( faceconn && (numfacperentdim > 0) && ((fconnid = ncvarid (exoid, vfaceconn)) == -1) )
   {
     exerrval = ncerr;
     sprintf(errmsg,
        "Error: failed to locate face connectivity array for %s block %d in file id %d",
             tname,blk_id,exoid);
     ex_err("ex_get_conn",errmsg, exerrval);
     return(EX_FATAL);
   }


/* read in the connectivity array */

/* 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;
   start[1] = 0;

   if ( edgeconn && num_edges_per_entry ) {
     count[0] = num_entries_this_blk;
     count[1] = num_edges_per_entry;

     if (sizeof(int) == sizeof(nclong)) {
       iresult = ncvarget (exoid, econnid, start, count, edgeconn);
     } else {
       if (!(longs = malloc (num_entries_this_blk*num_edges_per_entry * sizeof(nclong)))) {
         exerrval = EX_MEMFAIL;
         sprintf(errmsg,
           "Error: failed to allocate memory for edge connectivity array for file id %d",
           exoid);
         ex_err("ex_get_conn",errmsg,exerrval);
         return (EX_FATAL);
       }
       iresult = ncvarget (exoid, econnid, start, count, longs);
     }

     if (iresult == -1)
       {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to get edge connectivity array for block %d in file id %d",
         blk_id,exoid);
       ex_err("ex_get_conn",errmsg, exerrval);
       return(EX_FATAL);
       }

     if (sizeof(int) != sizeof(nclong)) {
       ltoi (longs, edgeconn, num_entries_this_blk*num_edges_per_entry);
       free (longs);
     }
   }

   if ( faceconn && num_faces_per_entry ) {
     count[0] = num_entries_this_blk;
     count[1] = num_faces_per_entry;

     if (sizeof(int) == sizeof(nclong)) {
       iresult = ncvarget (exoid, fconnid, start, count, faceconn);
     } else {
       if (!(longs = malloc (num_entries_this_blk*num_faces_per_entry * sizeof(nclong)))) {
         exerrval = EX_MEMFAIL;
         sprintf(errmsg,
           "Error: failed to allocate memory for face connectivity array of %s blockfor file id %d",
           tname,exoid);
         ex_err("ex_get_conn",errmsg,exerrval);
         return (EX_FATAL);
       }
       iresult = ncvarget (exoid, fconnid, start, count, longs);
     }

     if (iresult == -1)
       {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to get face connectivity array for %s block %d in file id %d",
         tname,blk_id,exoid);
       ex_err("ex_get_conn",errmsg, exerrval);
       return(EX_FATAL);
       }

     if (sizeof(int) != sizeof(nclong)) {
       ltoi (longs, faceconn, num_entries_this_blk*num_faces_per_entry);
       free (longs);
     }
   }

   if ( nodeconn && num_nodes_per_entry ) {
     count[0] = num_entries_this_blk;
     count[1] = num_nodes_per_entry;

     if (sizeof(int) == sizeof(nclong)) {
       iresult = ncvarget (exoid, connid, start, count, nodeconn);
     } else {
       if (!(longs = malloc (num_entries_this_blk*num_nodes_per_entry * sizeof(nclong)))) {
         exerrval = EX_MEMFAIL;
         sprintf(errmsg,
           "Error: failed to allocate memory for element connectivity array for file id %d",
           exoid);
         ex_err("ex_get_conn",errmsg,exerrval);
         return (EX_FATAL);
       }
       iresult = ncvarget (exoid, connid, start, count, longs);
     }

     if (iresult == -1)
       {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to get connectivity array for block %d in file id %d",
         blk_id,exoid);
       ex_err("ex_get_conn",errmsg, exerrval);
       return(EX_FATAL);
       }

     if (sizeof(int) != sizeof(nclong)) {
       ltoi (longs, nodeconn, num_entries_this_blk*num_nodes_per_entry);
       free (longs);
     }
   }

   return iexit;
}
コード例 #9
0
int ex_get_var_tab (int  exoid,
		    const char *var_type,
		    int  num_blk,
		    int  num_var,
		    int *var_tab)
{
   int dimid, varid, tabid, i, j, iresult;
   long num_entity = -1;
   long num_var_db = -1;
   long start[2], count[2]; 
   nclong *longs;
   char errmsg[MAX_ERR_LENGTH];
   const char* routine = "ex_get_var_tab";

   /*
    * The ent_type and the var_name are used to build the netcdf
    * variables name.  Normally this is done via a macro defined in
    * exodusII_int.h
    */
   const char* ent_type = NULL;
   const char* var_name = NULL;

   exerrval = 0; /* clear error code */
   
   if (*var_type == 'e' || *var_type == 'E') {
     dimid = ex_get_dimension(exoid, DIM_NUM_EL_BLK,   "element", &num_entity, routine);
     varid = ex_get_dimension(exoid, DIM_NUM_ELE_VAR,  "element variables", &num_var_db, routine);
     tabid = ncvarid (exoid, VAR_ELEM_TAB);
     var_name = "vals_elem_var";
     ent_type = "eb";
   }
   else if (*var_type == 'm' || *var_type == 'M') {
     dimid = ex_get_dimension(exoid, DIM_NUM_NS,       "nodeset", &num_entity, routine);
     varid = ex_get_dimension(exoid, DIM_NUM_NSET_VAR, "nodeset variables", &num_var_db, routine);
     tabid = ncvarid (exoid, VAR_NSET_TAB);
     var_name = "vals_nset_var";
     ent_type = "ns";
   }
   else if (*var_type == 's' || *var_type == 'S') {
     dimid = ex_get_dimension(exoid, DIM_NUM_SS,       "sideset", &num_entity, routine);
     varid = ex_get_dimension(exoid, DIM_NUM_SSET_VAR, "sideset variables", &num_var_db, routine);
     tabid = ncvarid (exoid, VAR_SSET_TAB);
     var_name = "vals_sset_var";
     ent_type = "ss";
   }
   else {       /* invalid variable type */
     exerrval = EX_BADPARAM;
     sprintf(errmsg,
	     "Error: Invalid variable type %c specified in file id %d",
	     *var_type, exoid);
     ex_err("ex_get_varid",errmsg,exerrval);
     return (EX_WARN);
   }
   
   if (dimid == -1) {
     exerrval = ncerr;
     return (EX_FATAL);
   }

   if (varid == -1) {
     exerrval = ncerr;
     return (EX_WARN);
   }

   if (num_entity != num_blk) {
     exerrval = EX_FATAL;
     sprintf(errmsg,
         "Error: # of blocks doesn't match those defined in file id %d", exoid);
     ex_err("ex_get_var_tab",errmsg,exerrval);
     return (EX_FATAL);
   }

   if (num_var_db != num_var) {
     exerrval = EX_FATAL;
     sprintf(errmsg,
	     "Error: # of variables doesn't match those defined in file id %d", exoid);
     ex_err("ex_get_var_tab",errmsg,exerrval);
     return (EX_FATAL);
   }

   if (tabid == -1) {
     /* since truth table isn't stored in the data file, derive it dynamically */
     for (j=0; j<num_blk; j++) {
       
       for (i=0; i<num_var; i++) {
         /* NOTE: names are 1-based */
	 if ((tabid = ncvarid (exoid, ex_catstr2(var_name, i+1, ent_type, j+1))) == -1) {

	   /* variable doesn't exist; put a 0 in the truth table */
           var_tab[j*num_var+i] = 0;
	 } else {
	   
	   /* variable exists; put a 1 in the truth table */
           var_tab[j*num_var+i] = 1;
	 }
       }
     }
   } else {

     /* read in the truth table */

     /*
      * 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;
     start[1] = 0;

     count[0] = num_blk;
     count[1] = num_var;

     if (sizeof(int) == sizeof(nclong)) {
        iresult = ncvarget (exoid, tabid, start, count, var_tab);
     } else {
       if (!(longs = static_cast<nclong*>(malloc (num_blk*num_var * sizeof(nclong))))) {
         exerrval = EX_MEMFAIL;
         sprintf(errmsg,
                 "Error: failed to allocate memory for truth table for file id %d",
                 exoid);
         ex_err("ex_get_var_tab",errmsg,exerrval);
         return (EX_FATAL);
       }
       iresult = ncvarget (exoid, tabid, start, count, longs);
     }
     
     if (iresult == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
               "Error: failed to get truth table from file id %d", exoid);
       ex_err("ex_get_var_tab",errmsg,exerrval);
       return (EX_FATAL);
     }

     if (sizeof(int) != sizeof(nclong)) {
       ltoi (longs, var_tab, num_blk*num_var);
       free (longs);
     }

   } 


   return (EX_NOERR);

}