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