Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_get_partial_var.c

raw
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 values of a single element variable for one element block at
14 * one time step in the database; assume the first time step and
15 * element variable index is 1
16 */
17
18 /*!
19 \ingroup ResultsData
20
21 * reads the values of a single variable for a partial block at one time
22 * step from the database; assume the first time step and variable index
23 * and start_index are 1
24 * \param exoid exodus file id
25 * \param time_step time step number
26 * \param var_type type (edge block, face block, edge set, ... )
27 * \param var_index element variable index
28 * \param obj_id element block id
29 * \param start_index index of first entity in block to read (1-based)
30 * \param num_entities number of entries to read in this block/set
31 * \param var_vals the values to read
32 */
33
34 int ex_get_partial_var(int exoid, int time_step, ex_entity_type var_type, int var_index,
35 ex_entity_id obj_id, int64_t start_index, int64_t num_entities,
36 void *var_vals)
37 {
38 int status = 0;
39 int varid, obj_id_ndx;
40 size_t start[2], count[2];
41 char errmsg[MAX_ERR_LENGTH];
42
43 EX_FUNC_ENTER();
44
45 #if !defined(PARALLEL_AWARE_EXODUS)
46 if (num_entities == 0) {
47 EX_FUNC_LEAVE(status);
48 }
49 #endif
50
51 if (var_type == EX_NODAL) {
52 /* FIXME: Special case: ignore obj_id, possible large_file complications,
53 * etc. */
54 status =
55 exi_get_partial_nodal_var(exoid, time_step, var_index, start_index, num_entities, var_vals);
56 EX_FUNC_LEAVE(status);
57 }
58 if (var_type == EX_GLOBAL) {
59 /* FIXME: Special case: all vars stored in 2-D single array. */
60 status = exi_get_glob_vars(exoid, time_step, num_entities, var_vals);
61 EX_FUNC_LEAVE(status);
62 }
63
64 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
65 EX_FUNC_LEAVE(EX_FATAL);
66 }
67
68 /* Determine index of obj_id in VAR_ID_EL_BLK array */
69 obj_id_ndx = exi_id_lkup(exoid, var_type, obj_id);
70 if (obj_id_ndx <= 0) {
71 ex_get_err(NULL, NULL, &status);
72
73 if (status != 0) {
74 if (status == EX_NULLENTITY) {
75 snprintf(errmsg, MAX_ERR_LENGTH,
76 "Warning: no %s variables for NULL block %" PRId64 " in file id %d",
77 ex_name_of_object(var_type), obj_id, exoid);
78 ex_err_fn(exoid, __func__, errmsg, EX_NULLENTITY);
79 EX_FUNC_LEAVE(EX_WARN);
80 }
81 snprintf(errmsg, MAX_ERR_LENGTH,
82 "ERROR: failed to locate %s id %" PRId64 " in id variable in file id %d",
83 ex_name_of_object(var_type), obj_id, exoid);
84 ex_err_fn(exoid, __func__, errmsg, status);
85 EX_FUNC_LEAVE(EX_FATAL);
86 }
87 }
88
89 /* inquire previously defined variable */
90
91 if ((status = nc_inq_varid(exoid, exi_name_var_of_object(var_type, var_index, obj_id_ndx),
92 &varid)) != NC_NOERR) {
93 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate %s %" PRId64 " var %d in file id %d",
94 ex_name_of_object(var_type), obj_id, var_index, exoid);
95 ex_err_fn(exoid, __func__, errmsg, status);
96 EX_FUNC_LEAVE(EX_FATAL);
97 }
98
99 /* read values of variable */
100 start[0] = --time_step;
101 start[1] = start_index - 1;
102
103 count[0] = 1;
104 count[1] = num_entities;
105 if (count[1] == 0) {
106 start[1] = 0;
107 }
108
109 if (exi_comp_ws(exoid) == 4) {
110 status = nc_get_vara_float(exoid, varid, start, count, var_vals);
111 }
112 else {
113 status = nc_get_vara_double(exoid, varid, start, count, var_vals);
114 }
115
116 if (status != NC_NOERR) {
117 snprintf(errmsg, MAX_ERR_LENGTH,
118 "ERROR: failed to get %s %" PRId64 " variable %d in file id %d",
119 ex_name_of_object(var_type), obj_id, var_index, exoid);
120 ex_err_fn(exoid, __func__, errmsg, status);
121 EX_FUNC_LEAVE(EX_FATAL);
122 }
123 EX_FUNC_LEAVE(EX_NOERR);
124 }