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 * ne_gnnnm - ne_get_n_node_num_map
38 *
39 * environment - UNIX
40 *
41 * entry conditions -
42 * input parameters:
43 * int neid nemesis file id
44 *
45 * exit conditions -
46 * int* node_map node numbering map array
47 *
48 * revision history -
49 *
50 *
51 *****************************************************************************/
52 #include <stdio.h>
53 #include <stdlib.h>
54
55 #include "exodusII.h"
56 #include "exodusII_int.h"
57
58 #include "ne_nemesisI.h"
59
60 /*
61 * reads the node numbering map from the database
62 */
63
ne_get_n_node_num_map(int neid,int start_ent,int num_ents,int * node_map)64 int ne_get_n_node_num_map (int neid,
65 int start_ent,
66 int num_ents,
67 int *node_map)
68 {
69 int numnodedim, mapid, i, status;
70 size_t num_nodes, start[1], count[1];
71 char errmsg[MAX_ERR_LENGTH];
72
73 exerrval = 0; /* clear error code */
74
75 /* inquire id's of previously defined dimensions and variables */
76
77 if ((status = nc_inq_dimid (neid, DIM_NUM_NODES, &numnodedim)) != NC_NOERR) {
78 exerrval = status;
79 sprintf(errmsg,
80 "Error: failed to locate number of nodes in file id %d",
81 neid);
82 ex_err("ne_get_n_node_num_map",errmsg,exerrval);
83 return (EX_FATAL);
84 }
85
86 if ((status = nc_inq_dimlen(neid, numnodedim, &num_nodes)) != NC_NOERR) {
87 exerrval = status;
88 sprintf(errmsg,
89 "Error: failed to get number of nodes in file id %d",
90 neid);
91 ex_err("ne_get_n_node_num_map",errmsg,exerrval);
92 return (EX_FATAL);
93 }
94
95 /* Check input parameters for a valid range of numbers */
96 if (start_ent < 0 || start_ent > num_nodes) {
97 fprintf(stderr, "ERROR: Invalid input to function"
98 " ne_get_n_node_num_map!\n");
99 return -1;
100 }
101
102 if (num_ents < 0) {
103 fprintf(stderr, "ERROR: Invalid number of entries in map!\n");
104 return -1;
105 }
106
107 /* start_ent now starts at 1, not 0 */
108 if ((start_ent + num_ents - 1) > num_nodes) {
109 fprintf(stderr, "ERROR: request range invalid!\n");
110 return -1;
111 }
112
113 if ((status = nc_inq_varid (neid, VAR_NODE_NUM_MAP, &mapid)) != NC_NOERR) {
114 exerrval = status;
115 sprintf(errmsg,
116 "Warning: node numbering map not stored in file id %d; returning default map",
117 neid);
118 ex_err("ne_get_n_node_num_map",errmsg,exerrval);
119
120 /* generate default map of 1..n, where n is num_nodes */
121 for (i=0; i < num_ents; i++)
122 node_map[i] = start_ent+i;
123
124 return (EX_WARN);
125 }
126
127 /* read in the node numbering map */
128 start[0] = --start_ent;
129 count[0] = num_ents;
130
131 status = nc_get_vara_int(neid, mapid, start, count, node_map);
132
133 if (status != NC_NOERR) {
134 exerrval = status;
135 sprintf(errmsg,
136 "Error: failed to get node numbering map in file id %d",
137 neid);
138 ex_err("ne_get_n_node_num_map",errmsg,exerrval);
139 return (EX_FATAL);
140 }
141 return(EX_NOERR);
142 }
143