Skip to content

Commit

Permalink
EXODUS: Address static analyzer suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
gsjaardema committed Dec 5, 2023
1 parent 84aaf08 commit 39d2e30
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,25 @@
int exi_get_glob_vars_multi_time(int exoid, int num_glob_vars, int beg_time_step, int end_time_step,
void *glob_var_vals)
{
int varid;
int status;
size_t start[2], count[2];
char errmsg[MAX_ERR_LENGTH];

EX_FUNC_ENTER();
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
EX_FUNC_LEAVE(EX_FATAL);
}

/* inquire previously defined variable */
int varid;
int status;
if ((status = nc_inq_varid(exoid, VAR_GLO_VAR, &varid)) != NC_NOERR) {
char errmsg[MAX_ERR_LENGTH];
snprintf(errmsg, MAX_ERR_LENGTH, "Warning: failed to locate global variables in file id %d",
exoid);
ex_err_fn(exoid, __func__, errmsg, status);
EX_FUNC_LEAVE(EX_WARN);
}

/* read values of global variables */
start[0] = --beg_time_step;
start[1] = 0;

count[0] = end_time_step - beg_time_step;
count[1] = num_glob_vars;
size_t start[] = {--beg_time_step, 0};
size_t count[] = {end_time_step - beg_time_step, num_glob_vars};

if (exi_comp_ws(exoid) == 4) {
status = nc_get_vara_float(exoid, varid, start, count, glob_var_vals);
Expand All @@ -66,6 +61,7 @@ int exi_get_glob_vars_multi_time(int exoid, int num_glob_vars, int beg_time_step
}

if (status != NC_NOERR) {
char errmsg[MAX_ERR_LENGTH];
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get global variable values from file id %d",
exoid);
ex_err_fn(exoid, __func__, errmsg, status);
Expand Down
23 changes: 12 additions & 11 deletions packages/seacas/libraries/exodus/src/ex__get_nodal_var_multi_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,28 @@ error = exi_get_nodal_var_multi_time(exoid, var_index, num_nodes,
int exi_get_nodal_var_multi_time(int exoid, int nodal_var_index, int64_t num_nodes,
int beg_time_step, int end_time_step, void *nodal_var_vals)
{
int varid;
int status;
size_t start[3], count[3];
char errmsg[MAX_ERR_LENGTH];

if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
EX_FUNC_LEAVE(EX_FATAL);
}

/* inquire previously defined variable */

/* Need to see how this works in the parallel-aware exodus... */
if (num_nodes == 0) {
return (EX_NOERR);
return EX_NOERR;
}

size_t start[3];
size_t count[3];
int status;
int varid;
if (ex_large_model(exoid) == 0) {
/* read values of the nodal variable */
if ((status = nc_inq_varid(exoid, VAR_NOD_VAR, &varid)) != NC_NOERR) {
char errmsg[MAX_ERR_LENGTH];
snprintf(errmsg, MAX_ERR_LENGTH, "Warning: could not find nodal variables in file id %d",
exoid);
ex_err_fn(exoid, __func__, errmsg, status);
return (EX_WARN);
return EX_WARN;
}

start[0] = --beg_time_step;
Expand All @@ -104,10 +103,11 @@ int exi_get_nodal_var_multi_time(int exoid, int nodal_var_index, int64_t num_nod
/* read values of the nodal variable -- stored as separate variables... */
/* Get the varid.... */
if ((status = nc_inq_varid(exoid, VAR_NOD_VAR_NEW(nodal_var_index), &varid)) != NC_NOERR) {
char errmsg[MAX_ERR_LENGTH];
snprintf(errmsg, MAX_ERR_LENGTH, "Warning: could not find nodal variable %d in file id %d",
nodal_var_index, exoid);
ex_err_fn(exoid, __func__, errmsg, status);
return (EX_WARN);
return EX_WARN;
}

start[0] = --beg_time_step;
Expand All @@ -125,9 +125,10 @@ int exi_get_nodal_var_multi_time(int exoid, int nodal_var_index, int64_t num_nod
}

if (status != NC_NOERR) {
char errmsg[MAX_ERR_LENGTH];
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get nodal variables in file id %d", exoid);
ex_err_fn(exoid, __func__, errmsg, status);
return (EX_FATAL);
return EX_FATAL;
}
return (EX_NOERR);
return EX_NOERR;
}
27 changes: 14 additions & 13 deletions packages/seacas/libraries/exodus/src/ex_copy.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright(C) 1999-2022 National Technology & Engineering Solutions
* Copyright(C) 1999-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 @@ -173,7 +173,7 @@ int ex_copy_transient(int in_exoid, int out_exoid)
}

/*! \cond INTERNAL */
int cpy_variable_data(int in_exoid, int out_exoid, int in_large, int mesh_only)
static int cpy_variable_data(int in_exoid, int out_exoid, int in_large, int mesh_only)
{
int nvars; /* number of variables */
EXCHECKI(nc_inq(in_exoid, NULL, &nvars, NULL, NULL));
Expand Down Expand Up @@ -212,7 +212,7 @@ int cpy_variable_data(int in_exoid, int out_exoid, int in_large, int mesh_only)
}

/*! \cond INTERNAL */
int cpy_variables(int in_exoid, int out_exoid, int in_large, int mesh_only)
static int cpy_variables(int in_exoid, int out_exoid, int in_large, int mesh_only)
{
int recdimid; /* id of unlimited dimension */
int nvars; /* number of variables */
Expand Down Expand Up @@ -253,7 +253,7 @@ int cpy_variables(int in_exoid, int out_exoid, int in_large, int mesh_only)
/*! \endcond */

/*! \cond INTERNAL */
int cpy_dimension(int in_exoid, int out_exoid, int mesh_only)
static int cpy_dimension(int in_exoid, int out_exoid, int mesh_only)
{
int dim_out_id; /* dimension id */

Expand Down Expand Up @@ -339,7 +339,7 @@ int cpy_dimension(int in_exoid, int out_exoid, int mesh_only)
}

/*! \cond INTERNAL */
int cpy_global_att(int in_exoid, int out_exoid)
static int cpy_global_att(int in_exoid, int out_exoid)
{
struct ncatt att; /* attribute */

Expand Down Expand Up @@ -389,7 +389,7 @@ int cpy_global_att(int in_exoid, int out_exoid)
/*! \endcond */

/*! \cond INTERNAL */
int cpy_att(int in_id, int out_id, int var_in_id, int var_out_id)
static int cpy_att(int in_id, int out_id, int var_in_id, int var_out_id)
{
/* Routine to copy all the attributes from the input netCDF
file to the output netCDF file. If var_in_id == NC_GLOBAL,
Expand Down Expand Up @@ -418,7 +418,7 @@ int cpy_att(int in_id, int out_id, int var_in_id, int var_out_id)
/*! \endcond */

/*! \internal */
int cpy_coord_def(int in_id, int out_id, int rec_dim_id, char *var_nm, int in_large)
static int cpy_coord_def(int in_id, int out_id, int rec_dim_id, char *var_nm, int in_large)
{
/* Handle easiest situation first: in_large matches out_large (1) */
if (in_large == 1) {
Expand Down Expand Up @@ -476,7 +476,7 @@ int cpy_coord_def(int in_id, int out_id, int rec_dim_id, char *var_nm, int in_la
/*! \endcond */

/*! \internal */
int cpy_var_def(int in_id, int out_id, int rec_dim_id, char *var_nm)
static int cpy_var_def(int in_id, int out_id, int rec_dim_id, char *var_nm)
{
/* Routine to copy the variable metadata from an input netCDF file
* to an output netCDF file.
Expand Down Expand Up @@ -547,7 +547,7 @@ int cpy_var_def(int in_id, int out_id, int rec_dim_id, char *var_nm)
} /* end cpy_var_def() */

/*! \internal */
int cpy_var_val(int in_id, int out_id, char *var_nm)
static int cpy_var_val(int in_id, int out_id, char *var_nm)
{
void *void_ptr = NULL;
/* Routine to copy the variable data from an input netCDF file
Expand Down Expand Up @@ -727,7 +727,7 @@ int cpy_var_val(int in_id, int out_id, char *var_nm)
} /* end cpy_var_val() */

/*! \internal */
int cpy_coord_val(int in_id, int out_id, char *var_nm, int in_large)
static int cpy_coord_val(int in_id, int out_id, char *var_nm, int in_large)
{
/* Routine to copy the coordinate data from an input netCDF file
* to an output netCDF file.
Expand Down Expand Up @@ -794,7 +794,7 @@ int cpy_coord_val(int in_id, int out_id, char *var_nm, int in_large)
} /* end cpy_coord_val() */

/*! \internal */
void update_structs(int out_exoid)
static void update_structs(int out_exoid)
{
update_internal_structs(out_exoid, EX_INQ_EDGE_BLK, exi_get_counter_list(EX_EDGE_BLOCK));
update_internal_structs(out_exoid, EX_INQ_FACE_BLK, exi_get_counter_list(EX_FACE_BLOCK));
Expand All @@ -815,7 +815,8 @@ void update_structs(int out_exoid)
}

/*! \internal */
void update_internal_structs(int out_exoid, ex_inquiry inqcode, struct exi_list_item **ctr_list)
static void update_internal_structs(int out_exoid, ex_inquiry inqcode,
struct exi_list_item **ctr_list)
{
int64_t number = ex_inquire_int(out_exoid, inqcode);
if (number > 0) {
Expand All @@ -825,7 +826,7 @@ void update_internal_structs(int out_exoid, ex_inquiry inqcode, struct exi_list_
}
}

size_t type_size(nc_type type)
static size_t type_size(nc_type type)
{
if (type == NC_CHAR) {
return sizeof(char); /* OK */
Expand Down
Loading

0 comments on commit 39d2e30

Please sign in to comment.