Debian Codegraph @

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

raw
1 /*
2 * Copyright(C) 1999-2021 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 /*!
10 *
11 * expfrm - ex_put_coordinate_frames: write coordinate frames
12 *
13 * \param exoid exodus file id
14 * \param nframes number of coordinate frames in model
15 * \param cf_ids coordinate ids
16 * \param pt_coordinates pointer to coordinates. 9 values per coordinate frame
17 * \param tags character tag for each frame. 'r' - rectangular, 'c' -
18 *cylindrical, 's' - spherical
19 *
20 * returns -
21 * EX_NOERR for no error
22 * EX_FATAL for fatal errors
23 * 1 number frames < 0
24 *
25 *****************************************************************************/
26
27 #include "exodusII.h" // for ex_err, EXERRVAL, etc
28 #include "exodusII_int.h" // for EX_FATAL, EX_NOERR, etc
29
30 int ex_put_coordinate_frames(int exoid, int nframes, const void_int *cf_ids,
31 const void *pt_coordinates, const char *tags)
32 {
33 char errmsg[MAX_ERR_LENGTH]; /* buffer for error messages */
34
35 EX_FUNC_ENTER();
36
37 if (exoid < 0) {
38 EX_FUNC_LEAVE(exoid);
39 }
40
41 if (nframes == 0) { /* write nothing */
42 EX_FUNC_LEAVE(EX_NOERR);
43 }
44
45 if (nframes < 0) {
46 EX_FUNC_LEAVE(1);
47 }
48
49 assert(cf_ids != NULL);
50 assert(pt_coordinates != NULL);
51 assert(tags != NULL);
52
53 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
54 EX_FUNC_LEAVE(EX_FATAL);
55 }
56
57 /* make the definitions */
58 /* go into define mode. define num_frames, num_frames9 */
59 int status;
60 if ((status = exi_redef(exoid, __func__)) != NC_NOERR) {
61 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to place file id %d into define mode", exoid);
62 ex_err_fn(exoid, __func__, errmsg, status);
63 EX_FUNC_LEAVE(EX_FATAL);
64 }
65
66 int dim, dim9; /* dimension id for nframes, nframes*9 */
67 if ((status = nc_def_dim(exoid, DIM_NUM_CFRAMES, nframes, &dim)) != NC_NOERR ||
68 (nc_def_dim(exoid, DIM_NUM_CFRAME9, nframes * 9, &dim9) != NC_NOERR)) {
69 snprintf(errmsg, MAX_ERR_LENGTH,
70 "ERROR: failed to define number of coordinate frames in file id %d", exoid);
71 ex_err_fn(exoid, __func__, errmsg, status);
72 goto error_ret;
73 }
74
75 int int_type = NC_INT;
76 if (ex_int64_status(exoid) & EX_IDS_INT64_DB) {
77 int_type = NC_INT64;
78 }
79
80 /* define the variables. coordinates, tags and ids */
81 int varcoords; /* variable id for the coordinates */
82 int varids; /* variable id for the frame ids */
83 int vartags; /* variable id for the frame tags */
84 if (nc_def_var(exoid, VAR_FRAME_COORDS, nc_flt_code(exoid), 1, &dim9, &varcoords) != NC_NOERR ||
85 (nc_def_var(exoid, VAR_FRAME_IDS, int_type, 1, &dim, &varids) != NC_NOERR) ||
86 (nc_def_var(exoid, VAR_FRAME_TAGS, NC_CHAR, 1, &dim, &vartags) != NC_NOERR)) {
87 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define coordinate frames in file id %d",
88 exoid);
89 ex_err_fn(exoid, __func__, errmsg, EX_FATAL);
90 goto error_ret; /* exit define mode and return */
91 }
92
93 /* leave define mode */
94 if ((status = exi_leavedef(exoid, __func__)) != NC_NOERR) {
95 EX_FUNC_LEAVE(EX_FATAL);
96 }
97
98 /* check variables consistency */
99 for (int i = 0; i < nframes; i++) {
100 if (strchr("RrCcSs", tags[i]) == NULL) {
101 snprintf(errmsg, MAX_ERR_LENGTH, "Warning: Unrecognized coordinate frame tag: '%c'.",
102 tags[i]);
103 ex_err_fn(exoid, __func__, errmsg, 2);
104 }
105 }
106 /* could also check vectors. Leave this up to the application */
107
108 /* put the variables into the file */
109 if (nc_put_var_text(exoid, vartags, tags) != NC_NOERR) {
110 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed writing frame data in file id %d", exoid);
111 ex_err_fn(exoid, __func__, errmsg, status);
112 EX_FUNC_LEAVE(EX_FATAL);
113 }
114
115 if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
116 status = nc_put_var_longlong(exoid, varids, cf_ids);
117 }
118 else {
119 status = nc_put_var_int(exoid, varids, cf_ids);
120 }
121
122 if (status != NC_NOERR) {
123 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed writing frame data in file id %d", exoid);
124 ex_err_fn(exoid, __func__, errmsg, status);
125 EX_FUNC_LEAVE(EX_FATAL);
126 }
127
128 if (exi_comp_ws(exoid) == 4) {
129 status = nc_put_var_float(exoid, varcoords, pt_coordinates);
130 }
131 else {
132 status = nc_put_var_double(exoid, varcoords, pt_coordinates);
133 }
134
135 if (status != NC_NOERR) {
136 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed writing frame data in file id %d", exoid);
137 ex_err_fn(exoid, __func__, errmsg, status);
138 EX_FUNC_LEAVE(EX_FATAL);
139 }
140 EX_FUNC_LEAVE(EX_NOERR);
141
142 error_ret:
143 exi_leavedef(exoid, __func__);
144 EX_FUNC_LEAVE(EX_FATAL);
145 }