| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "exodusII.h" // for ex_err, ex_name_of_object, etc |
| 10 |
#include "exodusII_int.h" // for exi_check_valid_file_id, etc |
| 11 |
|
| 12 |
/*! |
| 13 |
* reads the distribution factors for a single set |
| 14 |
*/ |
| 15 |
|
| 16 |
int ex_get_partial_set_dist_fact(int exoid, ex_entity_type set_type, ex_entity_id set_id, |
| 17 |
int64_t offset, int64_t num_to_put, void *set_dist_fact) |
| 18 |
{ |
| 19 |
|
| 20 |
int dimid, dist_id, set_id_ndx; |
| 21 |
int status; |
| 22 |
size_t start[1], count[1]; |
| 23 |
char errmsg[MAX_ERR_LENGTH]; |
| 24 |
char *factptr = NULL; |
| 25 |
|
| 26 |
EX_FUNC_ENTER(); |
| 27 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 28 |
EX_FUNC_LEAVE(EX_FATAL); |
| 29 |
} |
| 30 |
|
| 31 |
/* first check if any sets are specified */ |
| 32 |
if ((status = nc_inq_dimid(exoid, exi_dim_num_objects(set_type), &dimid)) != NC_NOERR) { |
| 33 |
snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no %s sets stored in file id %d", |
| 34 |
ex_name_of_object(set_type), exoid); |
| 35 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 36 |
EX_FUNC_LEAVE(EX_WARN); |
| 37 |
} |
| 38 |
|
| 39 |
/* Lookup index of set id in VAR_*S_IDS array */ |
| 40 |
set_id_ndx = exi_id_lkup(exoid, set_type, set_id); |
| 41 |
if (set_id_ndx <= 0) { |
| 42 |
ex_get_err(NULL, NULL, &status); |
| 43 |
|
| 44 |
if (status != 0) { |
| 45 |
if (status == EX_NULLENTITY) { |
| 46 |
snprintf(errmsg, MAX_ERR_LENGTH, "Warning: %s set %" PRId64 " is NULL in file id %d", |
| 47 |
ex_name_of_object(set_type), set_id, exoid); |
| 48 |
ex_err_fn(exoid, __func__, errmsg, EX_NULLENTITY); |
| 49 |
EX_FUNC_LEAVE(EX_WARN); |
| 50 |
} |
| 51 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 52 |
"ERROR: failed to locate %s set %" PRId64 " in VAR_*S_IDS array in file id %d", |
| 53 |
ex_name_of_object(set_type), set_id, exoid); |
| 54 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 55 |
EX_FUNC_LEAVE(EX_FATAL); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
/* setup more pointers based on set_type */ |
| 60 |
if (set_type == EX_NODE_SET) { |
| 61 |
factptr = VAR_FACT_NS(set_id_ndx); |
| 62 |
} |
| 63 |
else if (set_type == EX_EDGE_SET) { |
| 64 |
factptr = VAR_FACT_ES(set_id_ndx); |
| 65 |
} |
| 66 |
else if (set_type == EX_FACE_SET) { |
| 67 |
factptr = VAR_FACT_FS(set_id_ndx); |
| 68 |
} |
| 69 |
else if (set_type == EX_SIDE_SET) { |
| 70 |
factptr = VAR_FACT_SS(set_id_ndx); |
| 71 |
} |
| 72 |
if (set_type == EX_ELEM_SET) { |
| 73 |
factptr = VAR_FACT_ELS(set_id_ndx); |
| 74 |
} |
| 75 |
|
| 76 |
/* inquire id's of previously defined dimensions and variables */ |
| 77 |
if ((status = nc_inq_varid(exoid, factptr, &dist_id)) != NC_NOERR) { |
| 78 |
/* not an error for node sets because this is how we check that df's exist |
| 79 |
*/ |
| 80 |
if (set_type == EX_NODE_SET) { |
| 81 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 82 |
"Warning: dist factors not stored for %s set %" PRId64 " in file id %d", |
| 83 |
ex_name_of_object(set_type), set_id, exoid); |
| 84 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 85 |
EX_FUNC_LEAVE(EX_WARN); /* complain - but not too loud */ |
| 86 |
} |
| 87 |
/* is an error for other sets */ |
| 88 |
|
| 89 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 90 |
"ERROR: failed to locate dist factors list for %s set %" PRId64 " in file id %d", |
| 91 |
ex_name_of_object(set_type), set_id, exoid); |
| 92 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 93 |
EX_FUNC_LEAVE(EX_FATAL); |
| 94 |
} |
| 95 |
|
| 96 |
/* read in the distribution factors array */ |
| 97 |
start[0] = offset - 1; |
| 98 |
count[0] = num_to_put; |
| 99 |
if (count[0] == 0) { |
| 100 |
start[0] = 0; |
| 101 |
} |
| 102 |
if (exi_comp_ws(exoid) == 4) { |
| 103 |
status = nc_get_vara_float(exoid, dist_id, start, count, set_dist_fact); |
| 104 |
} |
| 105 |
else { |
| 106 |
status = nc_get_vara_double(exoid, dist_id, start, count, set_dist_fact); |
| 107 |
} |
| 108 |
|
| 109 |
if (status != NC_NOERR) { |
| 110 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 111 |
"ERROR: failed to get dist factors list for %s set %" PRId64 " in file id %d", |
| 112 |
ex_name_of_object(set_type), set_id, exoid); |
| 113 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 114 |
EX_FUNC_LEAVE(EX_FATAL); |
| 115 |
} |
| 116 |
EX_FUNC_LEAVE(EX_NOERR); |
| 117 |
} |