1 /*
2  * Copyright (c) 2005-2017 National Technology & Engineering Solutions
3  * of Sandia, LLC (NTESS).  Under the terms of Contract DE-NA0003525 with
4  * NTESS, the U.S. Government 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 NTESS 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"     // for ex_err, etc
55 #include "exodusII_int.h" // for EX_FATAL, etc
56 #include "vtk_netcdf.h"       // for nc_inq_varid, NC_NOERR
57 #include <stddef.h>       // for size_t
58 #include <stdio.h>
59 #include <string.h> // for NULL
60 
61 /*!
62  * writes the entity names to the database
63  * \param exoid       exodus file id
64  * \param obj_type    object type
65  * \param names       ptr array of entity names
66  */
67 
ex_put_names(int exoid,ex_entity_type obj_type,char * names[])68 int ex_put_names(int exoid, ex_entity_type obj_type, char *names[])
69 {
70   int    status;
71   int    varid;
72   size_t num_entity;
73   char   errmsg[MAX_ERR_LENGTH];
74 
75   const char *vname = NULL;
76 
77   EX_FUNC_ENTER();
78   ex_check_valid_file_id(exoid, __func__);
79 
80   switch (obj_type) {
81   /*  ======== BLOCKS ========= */
82   case EX_EDGE_BLOCK: vname = VAR_NAME_ED_BLK; break;
83   case EX_FACE_BLOCK: vname = VAR_NAME_FA_BLK; break;
84   case EX_ELEM_BLOCK:
85     vname = VAR_NAME_EL_BLK;
86     break;
87 
88   /*  ======== SETS ========= */
89   case EX_NODE_SET: vname = VAR_NAME_NS; break;
90   case EX_EDGE_SET: vname = VAR_NAME_ES; break;
91   case EX_FACE_SET: vname = VAR_NAME_FS; break;
92   case EX_SIDE_SET: vname = VAR_NAME_SS; break;
93   case EX_ELEM_SET:
94     vname = VAR_NAME_ELS;
95     break;
96 
97   /*  ======== MAPS ========= */
98   case EX_NODE_MAP: vname = VAR_NAME_NM; break;
99   case EX_EDGE_MAP: vname = VAR_NAME_EDM; break;
100   case EX_FACE_MAP: vname = VAR_NAME_FAM; break;
101   case EX_ELEM_MAP:
102     vname = VAR_NAME_EM;
103     break;
104 
105   /*  ======== ERROR (Invalid type) ========= */
106   default:
107     snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Invalid type specified in file id %d", exoid);
108     ex_err(__func__, errmsg, EX_BADPARAM);
109     EX_FUNC_LEAVE(EX_FATAL);
110   }
111 
112   ex_get_dimension(exoid, ex_dim_num_objects(obj_type), ex_name_of_object(obj_type), &num_entity,
113                    &varid, __func__);
114 
115   if ((status = nc_inq_varid(exoid, vname, &varid)) != NC_NOERR) {
116     snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate %s names in file id %d",
117              ex_name_of_object(obj_type), exoid);
118     ex_err(__func__, errmsg, status);
119     EX_FUNC_LEAVE(EX_FATAL);
120   }
121 
122   /* write EXODUS entitynames */
123   status = ex_put_names_internal(exoid, varid, num_entity, names, obj_type, "", __func__);
124 
125   EX_FUNC_LEAVE(status);
126 }
127