Skip to content

Commit

Permalink
EXODUS: Better support for renaming assemblies
Browse files Browse the repository at this point in the history
  • Loading branch information
gsjaardema committed May 26, 2023
1 parent 47f0911 commit 0a56d09
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
6 changes: 3 additions & 3 deletions packages/seacas/libraries/exodus/include/exodusII.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
#endif

/* EXODUS version number */
#define EXODUS_VERSION "8.20"
#define EXODUS_VERSION "8.21"
#define EXODUS_VERSION_MAJOR 8
#define EXODUS_VERSION_MINOR 20
#define EXODUS_VERSION_MINOR 21
#define EXODUS_RELEASE_DATE "May 1, 2023"

#define EX_API_VERS 8.20f
#define EX_API_VERS 8.21f
#define EX_API_VERS_NODOT (100 * EXODUS_VERSION_MAJOR + EXODUS_VERSION_MINOR)
#define EX_VERS EX_API_VERS

Expand Down
54 changes: 47 additions & 7 deletions packages/seacas/libraries/exodus/src/ex_put_name.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright(C) 1999-2020, 2022 National Technology & Engineering Solutions
* Copyright(C) 1999-2020, 2022, 2023 National Technology & Engineering Solutions
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
* NTESS, the U.S. Government retains certain rights in this software.
*
Expand Down Expand Up @@ -28,6 +28,51 @@
#include "exodusII.h" // for ex_err, etc
#include "exodusII_int.h" // for EX_FATAL, ex__id_lkup, etc

int ex__put_assembly_name(int exoid, ex_entity_type obj_type, ex_entity_id entity_id,
const char *name)
{
/* Internal function to handle renaming of an existing assembly.
Note that assembly must exist or an error will be returned.
*/
/* See if an assembly with this id has already been defined or exists on file... */
int entlst_id = 0;
int status = 0;
char errmsg[MAX_ERR_LENGTH];
if (nc_inq_varid(exoid, VAR_ENTITY_ASSEMBLY(entity_id), &entlst_id) == NC_NOERR) {
if ((status = nc_redef(exoid)) != NC_NOERR) {
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to put file id %d into define mode", exoid);
ex_err_fn(exoid, __func__, errmsg, status);
EX_FUNC_LEAVE(EX_FATAL);
}
size_t length = strlen(name) + 1;
if ((status = nc_put_att_text(exoid, entlst_id, EX_ATTRIBUTE_NAME, length, name)) != NC_NOERR) {
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store assembly name %s in file id %d",
name, exoid);
ex_err_fn(exoid, __func__, errmsg, status);
if ((status = ex__leavedef(exoid, __func__)) != NC_NOERR) {
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to exit define mode in file id %d", exoid);
ex_err_fn(exoid, __func__, errmsg, status);
EX_FUNC_LEAVE(EX_FATAL);
}
EX_FUNC_LEAVE(EX_FATAL);
}
/* Update the maximum_name_length attribute on the file. */
ex__update_max_name_length(exoid, length - 1);
if ((status = ex__leavedef(exoid, __func__)) != NC_NOERR) {
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to exit define mode in file id %d", exoid);
ex_err_fn(exoid, __func__, errmsg, status);
EX_FUNC_LEAVE(EX_FATAL);
}
EX_FUNC_LEAVE(EX_NOERR);
}

/* Assembly not found... */
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: %s id %" PRId64 " not found in file id %d",
ex_name_of_object(obj_type), entity_id, exoid);
ex_err_fn(exoid, __func__, errmsg, EX_LOOKUPFAIL);
EX_FUNC_LEAVE(EX_FATAL);
}

/*!
* writes the name of the specified entity to the database. The entity
* with id `entity_id` must exist before calling ex_put_name().
Expand All @@ -51,12 +96,7 @@ int ex_put_name(int exoid, ex_entity_type obj_type, ex_entity_id entity_id, cons
}

switch (obj_type) {
case EX_ASSEMBLY:
snprintf(errmsg, MAX_ERR_LENGTH,
"ERROR: Assembly name is written using `ex_put_assembly()` function");
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
EX_FUNC_LEAVE(EX_FATAL);
break;
case EX_ASSEMBLY: return ex__put_assembly_name(exoid, obj_type, entity_id, name); break;
case EX_EDGE_BLOCK: vobj = VAR_NAME_ED_BLK; break;
case EX_FACE_BLOCK: vobj = VAR_NAME_FA_BLK; break;
case EX_ELEM_BLOCK: vobj = VAR_NAME_EL_BLK; break;
Expand Down

0 comments on commit 0a56d09

Please sign in to comment.