FrontISTR 5.2.0
Large-scale structural analysis program with finit element method
Loading...
Searching...
No Matches
hecmw_result_copy_f2c.c
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright (c) 2019 FrontISTR Commons
3 * This software is released under the MIT License, see LICENSE.txt
4 *****************************************************************************/
5
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9#include <errno.h>
10#include "hecmw_config.h"
11#include "hecmw_result.h"
12#include "hecmw_util.h"
13
14static struct hecmwST_result_data *result;
15static int nnode, nelem;
16
17/*-----------------------------------------------------------------------------
18 * SetFunc
19 */
20
21static int set_ng_component(void *src) {
22 result->ng_component = *((int *)src);
23 return 0;
24}
25
26static int set_nn_component(void *src) {
27 result->nn_component = *((int *)src);
28 return 0;
29}
30
31static int set_ne_component(void *src) {
32 result->ne_component = *((int *)src);
33 return 0;
34}
35
36static int set_ng_dof(void *src) {
37 int size;
38
39 if (result->ng_component <= 0) return 0;
40 size = sizeof(*result->ng_dof) * result->ng_component;
41 result->ng_dof = HECMW_malloc(size);
42 if (result->ng_dof == NULL) {
43 HECMW_set_error(errno, "");
44 return -1;
45 }
46 memcpy(result->ng_dof, src, size);
47 return 0;
48}
49
50static int set_nn_dof(void *src) {
51 int size;
52
53 if (result->nn_component <= 0) return 0;
54 size = sizeof(*result->nn_dof) * result->nn_component;
55 result->nn_dof = HECMW_malloc(size);
56 if (result->nn_dof == NULL) {
57 HECMW_set_error(errno, "");
58 return -1;
59 }
60 memcpy(result->nn_dof, src, size);
61 return 0;
62}
63
64static int set_ne_dof(void *src) {
65 int size;
66
67 if (result->ne_component <= 0) return 0;
68 size = sizeof(*result->ne_dof) * result->ne_component;
69 result->ne_dof = HECMW_malloc(size);
70 if (result->ne_dof == NULL) {
71 HECMW_set_error(errno, "");
72 return -1;
73 }
74 memcpy(result->ne_dof, src, size);
75 return 0;
76}
77
78static int set_global_label(void *src) {
79 int i;
80
81 if (result->ng_component <= 0) return 0;
82
83 result->global_label =
84 HECMW_malloc(sizeof(*result->global_label) * result->ng_component);
85 if (result->global_label == NULL) {
86 HECMW_set_error(errno, "");
87 return -1;
88 }
89 for (i = 0; i < result->ng_component; i++) {
90 char *src_point = (char *)src + HECMW_NAME_LEN * i;
91 result->global_label[i] = HECMW_strcpy_f2c(src_point, HECMW_NAME_LEN);
92 }
93
94 return 0;
95}
96
97static int set_node_label(void *src) {
98 int i;
99
100 if (result->nn_component <= 0) return 0;
101
102 result->node_label =
103 HECMW_malloc(sizeof(*result->node_label) * result->nn_component);
104 if (result->node_label == NULL) {
105 HECMW_set_error(errno, "");
106 return -1;
107 }
108 for (i = 0; i < result->nn_component; i++) {
109 char *src_point = (char *)src + HECMW_NAME_LEN * i;
110 result->node_label[i] = HECMW_strcpy_f2c(src_point, HECMW_NAME_LEN);
111 }
112
113 return 0;
114}
115
116static int set_elem_label(void *src) {
117 int i;
118
119 if (result->ne_component <= 0) return 0;
120
121 result->elem_label =
122 HECMW_malloc(sizeof(*result->elem_label) * result->ne_component);
123 if (result->elem_label == NULL) {
124 HECMW_set_error(errno, "");
125 return -1;
126 }
127 for (i = 0; i < result->ne_component; i++) {
128 char *src_point = (char *)src + HECMW_NAME_LEN * i;
129 result->elem_label[i] = HECMW_strcpy_f2c(src_point, HECMW_NAME_LEN);
130 }
131
132 return 0;
133}
134
135static int set_global_val_item(void *src) {
136 int i, size;
137 int n = 0;
138
139 if (result->ng_component <= 0) return 0;
140 for (i = 0; i < result->ng_component; i++) {
141 n += result->ng_dof[i];
142 }
143 size = sizeof(*result->global_val_item) * n;
144 result->global_val_item = HECMW_malloc(size);
145 if (result->global_val_item == NULL) {
146 HECMW_set_error(errno, "");
147 return -1;
148 }
149 memcpy(result->global_val_item, src, size);
150 return 0;
151}
152
153static int set_node_val_item(void *src) {
154 int i, size;
155 int n = 0;
156
157 if (result->nn_component <= 0) return 0;
158 for (i = 0; i < result->nn_component; i++) {
159 n += result->nn_dof[i];
160 }
161 size = sizeof(*result->node_val_item) * n * nnode;
162 result->node_val_item = HECMW_malloc(size);
163 if (result->node_val_item == NULL) {
164 HECMW_set_error(errno, "");
165 return -1;
166 }
167 memcpy(result->node_val_item, src, size);
168 return 0;
169}
170
171static int set_elem_val_item(void *src) {
172 int i, size;
173 int n = 0;
174
175 if (result->ne_component <= 0) return 0;
176 for (i = 0; i < result->ne_component; i++) {
177 n += result->ne_dof[i];
178 }
179 size = sizeof(*result->elem_val_item) * n * nelem;
180 result->elem_val_item = HECMW_malloc(size);
181 if (result->elem_val_item == NULL) {
182 HECMW_set_error(errno, "");
183 return -1;
184 }
185 memcpy(result->elem_val_item, src, size);
186 return 0;
187}
188
189/*-----------------------------------------------------------------------------
190 * SetFunc table
191 */
192
193typedef int (*SetFunc)(void *);
194
195static struct func_table {
196 char *struct_name;
197 char *var_name;
198 SetFunc set_func;
199} functions[] = {
200 /* { Struct name, Variable name, memcpy function } */
201 {"hecmwST_result_data", "ng_component", set_ng_component},
202 {"hecmwST_result_data", "nn_component", set_nn_component},
203 {"hecmwST_result_data", "ne_component", set_ne_component},
204 {"hecmwST_result_data", "ng_dof", set_ng_dof},
205 {"hecmwST_result_data", "nn_dof", set_nn_dof},
206 {"hecmwST_result_data", "ne_dof", set_ne_dof},
207 {"hecmwST_result_data", "global_label", set_global_label},
208 {"hecmwST_result_data", "node_label", set_node_label},
209 {"hecmwST_result_data", "elem_label", set_elem_label},
210 {"hecmwST_result_data", "global_val_item", set_global_val_item},
211 {"hecmwST_result_data", "node_val_item", set_node_val_item},
212 {"hecmwST_result_data", "elem_val_item", set_elem_val_item},
213};
214
215static const int NFUNC = sizeof(functions) / sizeof(functions[0]);
216
217static SetFunc get_set_func(char *struct_name, char *var_name) {
218 int i;
219
220 for (i = 0; i < NFUNC; i++) {
221 if (strcmp(functions[i].struct_name, struct_name) == 0 &&
222 strcmp(functions[i].var_name, var_name) == 0) {
223 return functions[i].set_func;
224 }
225 }
226 return NULL;
227}
228
229/*----------------------------------------------------------------------------*/
230
232 int n_node, int n_elem) {
233 result = result_data;
234 nnode = n_node;
235 nelem = n_elem;
236 return 0;
237}
238
240 result = NULL;
241 return 0;
242}
243
244/*----------------------------------------------------------------------------*/
245
246void hecmw_result_copy_f2c_set_if(char *struct_name, char *var_name, void *src,
247 int *err, int slen, int vlen) {
248 SetFunc func;
249 char sname[HECMW_NAME_LEN + 1];
250 char vname[HECMW_NAME_LEN + 1];
251
252 *err = 1;
253
254 if (result == NULL) {
257 "hecmw_result_copy_f2c_set_if(): 'result' has not initialized yet");
258 return;
259 }
260 if (struct_name == NULL) {
262 "hecmw_result_copy_f2c_set_if(): 'sname' is NULL");
263 return;
264 }
265 if (var_name == NULL) {
267 "hecmw_result_copy_f2c_set_if(): 'vname' is NULL");
268 return;
269 }
270
271 if (HECMW_strcpy_f2c_r(struct_name, slen, sname, sizeof(sname)) == NULL) {
272 return;
273 }
274
275 if (HECMW_strcpy_f2c_r(var_name, vlen, vname, sizeof(vname)) == NULL) {
276 return;
277 }
278
279 func = get_set_func(sname, vname);
280 if (func == NULL) {
282 "hecmw_result_copy_f2c_set_if(): SetFunc not found");
283 return;
284 }
285
286 if ((*func)(src)) {
287 return;
288 }
289
290 *err = 0;
291}
292
293void hecmw_result_copy_f2c_set_if_(char *struct_name, char *var_name, void *src,
294 int *err, int slen, int vlen) {
295 hecmw_result_copy_f2c_set_if(struct_name, var_name, src, err, slen, vlen);
296}
297
298extern void hecmw_result_copy_f2c_set_if__(char *struct_name, char *var_name,
299 void *src, int *err, int slen,
300 int vlen) {
301 hecmw_result_copy_f2c_set_if(struct_name, var_name, src, err, slen, vlen);
302}
303
304extern void HECMW_RESULT_COPY_F2C_SET_IF(char *struct_name, char *var_name,
305 void *src, int *err, int slen,
306 int vlen) {
307 hecmw_result_copy_f2c_set_if(struct_name, var_name, src, err, slen, vlen);
308}
309
310/*----------------------------------------------------------------------------*/
311
313 *err = 1;
314 result = HECMW_calloc(1, sizeof(*result));
315 if (result == NULL) {
316 HECMW_set_error(errno, "");
317 return;
318 }
319
320 nnode = HECMW_result_get_nnode();
321 nelem = HECMW_result_get_nelem();
322 *err = 0;
323}
324
327}
328
331}
332
335}
336
337/*----------------------------------------------------------------------------*/
338
340 HECMW_result_free(result);
341
342 *err = 0;
343}
344
347}
348
351}
352
355}
356
357/*----------------------------------------------------------------------------*/
358
359void hecmw_result_write_st_by_name_if(char *name_ID, int *err, int len) {
360 char name_ID_str[HECMW_NAME_LEN + 1];
361 char head[HECMW_HEADER_LEN + 1];
362 char comment[HECMW_MSG_LEN + 1];
363
364 *err = 1;
365
366 if (HECMW_strcpy_f2c_r(name_ID, len, name_ID_str, sizeof(name_ID_str)) ==
367 NULL)
368 return;
369
372 if (HECMW_result_write_ST_by_name(name_ID_str, result, nnode, nelem, head, comment))
373 return;
374
375 *err = 0;
376}
377
378void hecmw_result_write_st_by_name_if_(char *name_ID, int *err, int len) {
379 hecmw_result_write_st_by_name_if(name_ID, err, len);
380}
381
382void hecmw_result_write_st_by_name_if__(char *name_ID, int *err, int len) {
383 hecmw_result_write_st_by_name_if(name_ID, err, len);
384}
385
386void HECMW_RESULT_WRITE_ST_BY_NAME_IF(char *name_ID, int *err, int len) {
387 hecmw_result_write_st_by_name_if(name_ID, err, len);
388}
#define HECMW_MSG_LEN
Definition: hecmw_config.h:74
#define HECMW_HEADER_LEN
Definition: hecmw_config.h:68
#define HECMW_NAME_LEN
Definition: hecmw_config.h:70
int(* SetFunc)(void *)
int HECMW_set_error(int errorno, const char *fmt,...)
Definition: hecmw_error.c:37
#define NULL
char * HECMW_strcpy_f2c(const char *fstr, int flen)
Definition: hecmw_lib_fc.c:11
char * HECMW_strcpy_f2c_r(const char *fstr, int flen, char *buf, int bufsize)
Definition: hecmw_lib_fc.c:45
#define HECMW_calloc(nmemb, size)
Definition: hecmw_malloc.h:21
#define HECMW_malloc(size)
Definition: hecmw_malloc.h:20
#define HECMW_ALL_E0101
Definition: hecmw_msgno.h:12
#define HECMW_ALL_E0102
Definition: hecmw_msgno.h:13
char * HECMW_result_get_header(char *buff)
Definition: hecmw_result.c:207
int HECMW_result_get_nnode(void)
Definition: hecmw_result.c:203
int HECMW_result_get_nelem(void)
Definition: hecmw_result.c:205
char * HECMW_result_get_comment(char *buff)
Definition: hecmw_result.c:212
void HECMW_result_free(struct hecmwST_result_data *result)
Definition: hecmw_result.c:25
int HECMW_result_write_ST_by_name(char *name_ID, struct hecmwST_result_data *result, int n_node, int n_elem, char *header, char *comment)
Definition: hecmw_result.c:98
void hecmw_result_write_st_init_if__(int *err)
void hecmw_result_write_st_by_name_if(char *name_ID, int *err, int len)
void hecmw_result_copy_f2c_set_if(char *struct_name, char *var_name, void *src, int *err, int slen, int vlen)
void HECMW_RESULT_WRITE_ST_FINALIZE_IF(int *err)
void HECMW_RESULT_WRITE_ST_BY_NAME_IF(char *name_ID, int *err, int len)
void hecmw_result_write_st_finalize_if__(int *err)
void hecmw_result_write_st_finalize_if_(int *err)
void hecmw_result_write_st_by_name_if_(char *name_ID, int *err, int len)
void hecmw_result_copy_f2c_set_if__(char *struct_name, char *var_name, void *src, int *err, int slen, int vlen)
void HECMW_RESULT_COPY_F2C_SET_IF(char *struct_name, char *var_name, void *src, int *err, int slen, int vlen)
void HECMW_RESULT_WRITE_ST_INIT_IF(int *err)
void hecmw_result_write_st_by_name_if__(char *name_ID, int *err, int len)
int HECMW_result_copy_f2c_init(struct hecmwST_result_data *result_data, int n_node, int n_elem)
void hecmw_result_write_st_init_if(int *err)
void hecmw_result_copy_f2c_set_if_(char *struct_name, char *var_name, void *src, int *err, int slen, int vlen)
void hecmw_result_write_st_finalize_if(int *err)
void hecmw_result_write_st_init_if_(int *err)
int(* SetFunc)(void *)
int HECMW_result_copy_f2c_finalize(void)
char head[HECMW_HEADER_LEN+1]
double * elem_val_item
Definition: hecmw_result.h:23
double * global_val_item
Definition: hecmw_result.h:21
double * node_val_item
Definition: hecmw_result.h:22