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 * expnam - ex_put_names
38 *
39 * environment - UNIX
40 *
41 * entry conditions -
42 * input parameters:
43 * int exoid exodus file id
44 * int obj_type object type
45 * char* names ptr array of entity names
46 *
47 * exit conditions -
48 *
49 * revision history -
50 *
51 *
52 *****************************************************************************/
53
54 #include "exodusII.h"
55 #include "exodusII_int.h"
56 #include <string.h>
57
58 /*!
59 * writes the entity names to the database
60 * \param exoid exodus file id
61 * \param obj_type object type
62 * \param names ptr array of entity names
63 */
64
ex_put_names(int exoid,ex_entity_type obj_type,char * names[])65 int ex_put_names (int exoid,
66 ex_entity_type obj_type,
67 char* names[])
68 {
69 int status;
70 int varid;
71 size_t num_entity;
72 char errmsg[MAX_ERR_LENGTH];
73
74 const char *vname = NULL;
75
76 const char *routine = "ex_put_names";
77
78 exerrval = 0; /* clear error code */
79
80 switch (obj_type) {
81 /* ======== BLOCKS ========= */
82 case EX_EDGE_BLOCK:
83 vname = VAR_NAME_ED_BLK;
84 break;
85 case EX_FACE_BLOCK:
86 vname = VAR_NAME_FA_BLK;
87 break;
88 case EX_ELEM_BLOCK:
89 vname = VAR_NAME_EL_BLK;
90 break;
91
92 /* ======== SETS ========= */
93 case EX_NODE_SET:
94 vname = VAR_NAME_NS;
95 break;
96 case EX_EDGE_SET:
97 vname = VAR_NAME_ES;
98 break;
99 case EX_FACE_SET:
100 vname = VAR_NAME_FS;
101 break;
102 case EX_SIDE_SET:
103 vname = VAR_NAME_SS;
104 break;
105 case EX_ELEM_SET:
106 vname = VAR_NAME_ELS;
107 break;
108
109 /* ======== MAPS ========= */
110 case EX_NODE_MAP:
111 vname = VAR_NAME_NM;
112 break;
113 case EX_EDGE_MAP:
114 vname = VAR_NAME_EDM;
115 break;
116 case EX_FACE_MAP:
117 vname = VAR_NAME_FAM;
118 break;
119 case EX_ELEM_MAP:
120 vname = VAR_NAME_EM;
121 break;
122
123 /* ======== ERROR (Invalid type) ========= */
124 default:
125 exerrval = EX_BADPARAM;
126 sprintf(errmsg,
127 "Error: Invalid type specified in file id %d", exoid);
128 ex_err(routine,errmsg,exerrval);
129 return(EX_FATAL);
130 }
131
132 ex_get_dimension(exoid, ex_dim_num_objects(obj_type), ex_name_of_object(obj_type),
133 &num_entity, &varid, routine);
134
135 if ((status = nc_inq_varid(exoid, vname, &varid)) != NC_NOERR) {
136 exerrval = status;
137 sprintf(errmsg,
138 "Error: failed to locate %s names in file id %d",
139 ex_name_of_object(obj_type), exoid);
140 ex_err(routine,errmsg,exerrval);
141 return (EX_FATAL);
142 }
143
144 /* write EXODUS entitynames */
145 status = ex_put_names_internal(exoid, varid, num_entity, names, obj_type, "", routine);
146
147 return(status);
148 }
149