28 #include "libmesh/libmesh_config.h" 30 #ifdef LIBMESH_HAVE_EXODUS_API 32 #include "libmesh/ignore_warnings.h" 34 #include "exodusII_int.h" 35 #include "libmesh/restore_warnings.h" 37 #include "libmesh/getpot.h" 39 #define EXODUS_DIM 0x8 55 int main(
int argc,
char ** argv)
57 GetPot cl(argc, argv);
60 if (!cl.search(
"--input"))
62 std::cerr <<
"No --input argument found!" << std::endl;
65 const char * meshname = cl.next(
"");
67 if (!cl.search(
"--oldid"))
69 std::cerr <<
"No --oldid argument found!" << std::endl;
72 long oldid = cl.next(0);
74 if (!cl.search(
"--newid"))
76 std::cerr <<
"No --newid argument found!" << std::endl;
79 long newid = cl.next(0);
81 unsigned char flags = 0;
82 if (cl.search(
"--nodesetonly"))
84 if (cl.search(
"--sidesetonly"))
86 if (cl.search(
"--blockonly"))
88 if (cl.search(
"--dim"))
93 flags =
NODES | SIDES | BLOCKS;
99 flags != EXODUS_DIM &&
100 flags != (
NODES | SIDES | BLOCKS))
102 std::cerr <<
"Only one of the following options may be active [--nodesetonly | --sidesetonly | --blockonly | --dim]!" << std::endl;
107 std::string var_name, dim_name;
109 int nc_id, var_id, dim_id;
112 status = nc_open (meshname, NC_WRITE, &nc_id);
115 for (
unsigned char mask = 8; mask; mask/=2)
118 switch (flags & mask)
121 dim_name = DIM_NUM_EL_BLK;
122 var_name = VAR_ID_EL_BLK;
125 dim_name = DIM_NUM_SS;
126 var_name = VAR_SS_IDS;
129 dim_name = DIM_NUM_NS;
130 var_name = VAR_NS_IDS;
133 dim_name = DIM_NUM_DIM;
142 status = nc_inq_dimid (nc_id, dim_name.c_str(), &dim_id);
145 status = nc_inq_dimlen (nc_id, dim_id, &dim_len);
148 if ((flags & mask) != EXODUS_DIM)
151 std::vector<long> var_vals(dim_len);
153 status = nc_inq_varid (nc_id, var_name.c_str(), &var_id);
156 status = nc_get_var_long (nc_id, var_id, var_vals.data());
160 for (
unsigned int i=0; i<dim_len; ++i)
161 if (var_vals[i] == oldid)
165 status = nc_put_var_long (nc_id, var_id, var_vals.data());
173 if (dim_len == (
size_t)oldid)
190 std::string random_dim_name;
192 random_dim_name = std::string(
"ignored_num_dim_") + random_dim_name;
195 status = nc_rename_dim(nc_id, dim_id, random_dim_name.c_str());
200 status = nc_def_dim (nc_id, dim_name.c_str(), newid, &dummy);
204 status = nc_enddef(nc_id);
213 return (
status != NC_NOERR);
216 #else // LIBMESH_HAVE_EXODUS_API 218 int main(
int,
char **)
220 std::cerr <<
"Error: meshid requires libMesh configured with --enable-exodus" << std::endl;
222 #endif // LIBMESH_HAVE_EXODUS_API 228 std::cout <<
"Error " << error <<
" occurred while working with the netCDF API" << std::endl;
229 std::cout << message << std::endl;
238 std::cout <<
"Usage: " << progname
239 <<
" --input inputmesh --oldid <n> --newid <n> [--nodesetonly | --sidesetonly | --blockonly]" 248 static const char alphanum[] =
250 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 251 "abcdefghijklmnopqrstuvwxyz";
254 srand( static_cast<unsigned>(time(
nullptr)) );
257 for (
int i = 0; i < len; ++i)
259 unsigned int alphai =
static_cast<unsigned int> 260 (rand() / (RAND_MAX+1.0) * (
sizeof(alphanum)-1));
261 s[i] = alphanum[alphai];
int main(int argc, char **argv)
void gen_random_string(std::string &s, const int len)
void usage_error(const char *progname)
void handle_error(int error, std::string message)