1 /*
2 * Copyright (c) 1998 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 /* Function(s) contained in this file:
39 *
40 * ex_put_n_node_set()
41 *
42 *****************************************************************************
43 *
44 * Variable Index:
45 *
46 * exoid - The NetCDF ID of an already open NemesisI file.
47 * node_set_id - ID of node set to read.
48 * start_node_num - The starting index of the nodes to be read.
49 * num_nodes - The number of nodes to read in.
50 * node_set_node_list - List of node IDs in node set.
51 */
52 /*****************************************************************************/
53 /*****************************************************************************/
54 /*****************************************************************************/
55 #include <stdio.h>
56 #include <stdlib.h>
57
58 #include "exodusII.h"
59 #include "exodusII_int.h"
60
61 /*
62 * writes the node list for a single node set
63 */
64
ex_put_n_node_set(int exoid,ex_entity_id node_set_id,int64_t start_node_num,int64_t num_nodes,const void_int * node_set_node_list)65 int ex_put_n_node_set (int exoid,
66 ex_entity_id node_set_id,
67 int64_t start_node_num,
68 int64_t num_nodes,
69 const void_int *node_set_node_list)
70 {
71 int dimid, node_list_id, node_set_id_ndx, status;
72 size_t num_nodes_in_set, start[1], count[1];
73 char errmsg[MAX_ERR_LENGTH];
74
75 exerrval = 0; /* clear error code */
76
77 /* first check if any node sets are specified */
78
79 if ((status = nc_inq_dimid (exoid, DIM_NUM_NS, &dimid)) != NC_NOERR) {
80 exerrval = status;
81 sprintf(errmsg,
82 "Error: no node sets specified in file id %d",
83 exoid);
84 ex_err("ex_put_n_node_set",errmsg,exerrval);
85 return (EX_FATAL);
86 }
87
88 /* Lookup index of node set id in VAR_NS_IDS array */
89 if ((node_set_id_ndx = ex_id_lkup(exoid, EX_NODE_SET, node_set_id)) < 0)
90 {
91 if (exerrval == EX_NULLENTITY) {
92 sprintf(errmsg,
93 "Warning: no data allowed for NULL node set %"PRId64" in file id %d",
94 node_set_id, exoid);
95 ex_err("ex_put_n_node_set",errmsg,EX_MSG);
96 return (EX_WARN);
97 } else {
98 sprintf(errmsg,
99 "Error: failed to locate node set id %"PRId64" in VAR_NS_IDS array in file id %d",
100 node_set_id, exoid);
101 ex_err("ex_put_n_node_set",errmsg,exerrval);
102 return (EX_FATAL);
103 }
104 }
105
106 /* inquire id's of previously defined dimensions */
107
108 if ((status = nc_inq_dimid (exoid, DIM_NUM_NOD_NS(node_set_id_ndx), &dimid)) != NC_NOERR) {
109 exerrval = status;
110 sprintf(errmsg,
111 "Error: failed to locate number of nodes in set %"PRId64" in file id %d",
112 node_set_id, exoid);
113 ex_err("ex_put_n_node_set",errmsg,exerrval);
114 return (EX_FATAL);
115 }
116
117 if ((status = nc_inq_dimlen(exoid, dimid, &num_nodes_in_set)) != NC_NOERR) {
118 exerrval = status;
119 sprintf(errmsg,
120 "Error: failed to get number of nodes in set %"PRId64" in file id %d",
121 node_set_id, exoid);
122 ex_err("ex_put_n_node_set",errmsg,exerrval);
123 return (EX_FATAL);
124 }
125
126 /* Check input parameters for a valid range of numbers */
127 if (start_node_num < 0 || start_node_num > num_nodes_in_set) {
128 fprintf(stderr, "ERROR: Invalid input to function ex_get_n_node_set!\n");
129 return -1;
130 }
131
132 if (num_nodes < 0) {
133 fprintf(stderr, "ERROR: Invalid number of nodes in nodes set!\n");
134 return -1;
135 }
136
137 /* start_node_num now starts at 1, not 0 */
138 if ((start_node_num + num_nodes - 1) > num_nodes_in_set) {
139 fprintf(stderr, "ERROR: request larger than number of nodes in set!\n");
140 return -1;
141 }
142
143 /* inquire if variable for node set node list has been defined */
144 if ((status = nc_inq_varid (exoid, VAR_NODE_NS(node_set_id_ndx), &node_list_id)) != NC_NOERR) {
145 /* variable doesn't exist */
146 exerrval = status;
147 sprintf(errmsg,
148 "Error: failed to locate node set %"PRId64" node list in file id %d",
149 node_set_id, exoid);
150 ex_err("ex_put_n_node_set",errmsg,exerrval);
151 return (EX_FATAL);
152 }
153
154 /* write out the node list array */
155 start[0] = --start_node_num;
156 count[0] = num_nodes;
157
158 if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
159 status = nc_put_vara_longlong(exoid, node_list_id, start, count, node_set_node_list);
160 } else {
161 status = nc_put_vara_int(exoid, node_list_id, start, count, node_set_node_list);
162 }
163
164 if (status != NC_NOERR) {
165 exerrval = status;
166 sprintf(errmsg,
167 "Error: failed to store node set %"PRId64" node list in file id %d",
168 node_set_id, exoid);
169 ex_err("ex_put_n_node_set",errmsg,exerrval);
170 return (EX_FATAL);
171 }
172 return (EX_NOERR);
173 }
174