1 /*
2  * Copyright (c) 2005 Sandia Corporation. Under the terms of Contract
3  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Governement
4  * retains certain rights in this software.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *
13  *     * Redistributions in binary form must reproduce the above
14  *       copyright notice, this list of conditions and the following
15  *       disclaimer in the documentation and/or other materials provided
16  *       with the distribution.
17  *
18  *     * Neither the name of Sandia Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  */
35 /*
36  *
37  *****************************************************************************/
38 
39 #include <stdlib.h>
40 #include "exodusII.h"
41 #include "exodusII_int.h"
42 
43 /*
44  *  reads the element block ids from the database
45  */
46 
ex_get_ids(int exoid,ex_entity_type obj_type,void_int * ids)47 int ex_get_ids (int  exoid,
48 		ex_entity_type obj_type,
49 		void_int *ids)
50 {
51   int varid, status;
52   char errmsg[MAX_ERR_LENGTH];
53 
54   const char* varidobj;
55 
56   exerrval = 0; /* clear error code */
57 
58   switch (obj_type) {
59   case EX_EDGE_BLOCK:
60     varidobj = VAR_ID_ED_BLK;
61     break;
62   case EX_FACE_BLOCK:
63     varidobj = VAR_ID_FA_BLK;
64     break;
65   case EX_ELEM_BLOCK:
66     varidobj = VAR_ID_EL_BLK;
67     break;
68   case EX_NODE_SET:
69     varidobj = VAR_NS_IDS;
70     break;
71   case EX_EDGE_SET:
72     varidobj = VAR_ES_IDS;
73     break;
74   case EX_FACE_SET:
75     varidobj = VAR_FS_IDS;
76     break;
77   case EX_SIDE_SET:
78     varidobj = VAR_SS_IDS;
79     break;
80   case EX_ELEM_SET:
81     varidobj = VAR_ELS_IDS;
82     break;
83   case EX_NODE_MAP:
84     varidobj = VAR_NM_PROP(1);
85     break;
86   case EX_EDGE_MAP:
87     varidobj = VAR_EDM_PROP(1);
88     break;
89   case EX_FACE_MAP:
90     varidobj = VAR_FAM_PROP(1);
91     break;
92   case EX_ELEM_MAP:
93     varidobj = VAR_EM_PROP(1);
94     break;
95   default:/* invalid variable type */
96     exerrval = EX_BADPARAM;
97     sprintf(errmsg, "Error: Invalid type specified in file id %d", exoid);
98     ex_err("ex_get_ids",errmsg,exerrval);
99     return(EX_FATAL);
100   }
101 
102   /* Determine if there are any 'obj-type' objects */
103   if ((status = nc_inq_dimid (exoid, ex_dim_num_objects(obj_type), &varid)) != NC_NOERR) {
104     exerrval = status;
105     sprintf(errmsg,
106             "Warning: no %s defined in file id %d",
107 	    ex_name_of_object(obj_type), exoid);
108     ex_err("ex_get_ids",errmsg,exerrval);
109     return (EX_WARN);
110   }
111 
112 
113   /* inquire id's of previously defined dimensions and variables  */
114   if ((status = nc_inq_varid(exoid, varidobj, &varid)) != NC_NOERR) {
115     exerrval = status;
116     sprintf(errmsg,
117 	    "Error: failed to locate %s ids variable in file id %d",
118 	    ex_name_of_object(obj_type),exoid);
119     ex_err("ex_get_ids",errmsg,exerrval);
120     return (EX_FATAL);
121   }
122 
123   /* read in the element block ids  */
124   if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
125     status = nc_get_var_longlong(exoid, varid, ids);
126   } else {
127     status = nc_get_var_int(exoid, varid, ids);
128   }
129 
130   if (status != NC_NOERR) {
131     exerrval = status;
132     sprintf(errmsg,
133 	    "Error: failed to return %s ids in file id %d",
134 	    ex_name_of_object(obj_type),exoid);
135     ex_err("ex_get_ids",errmsg,exerrval);
136     return (EX_FATAL);
137   }
138   return(EX_NOERR);
139 }
140