FrontISTR  5.7.0
Large-scale structural analysis program with finit element method
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 
14 static struct hecmwST_result_data *Result;
15 static int NNode, NElem;
16 
17 /*-----------------------------------------------------------------------------
18  * SetFunc
19  */
20 
21 static int set_ng_component(void *src) {
22  Result->ng_component = *((int *)src);
23  return 0;
24 }
25 
26 static int set_nn_component(void *src) {
27  Result->nn_component = *((int *)src);
28  return 0;
29 }
30 
31 static int set_ne_component(void *src) {
32  Result->ne_component = *((int *)src);
33  return 0;
34 }
35 
36 static 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 
50 static 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 
64 static 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 
78 static 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 
97 static 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 
116 static 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 
135 static 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 
153 static 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 
171 static 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 
193 typedef int (*SetFunc)(void *);
194 
195 static 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 
215 static const int NFUNC = sizeof(functions) / sizeof(functions[0]);
216 
217 static 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 
246 void 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 
293 void 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 
298 extern 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 
304 extern 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 
341 
342  *err = 0;
343 }
344 
347 }
348 
351 }
352 
355 }
356 
357 /*----------------------------------------------------------------------------*/
358 
359 void 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 
371  HECMW_result_get_comment(comment);
372  if (HECMW_result_write_ST_by_name(name_ID_str, Result, NNode, NElem, head, comment))
373  return;
374 
375  *err = 0;
376 }
377 
378 void 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 
382 void 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 
386 void 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 }
hecmwST_result_data
Definition: hecmw_result.h:11
HECMW_result_get_comment
char * HECMW_result_get_comment(char *buff)
Definition: hecmw_result.c:209
HECMW_result_get_header
char * HECMW_result_get_header(char *buff)
Definition: hecmw_result.c:204
HECMW_malloc
#define HECMW_malloc(size)
Definition: hecmw_malloc.h:20
HECMW_RESULT_WRITE_ST_FINALIZE_IF
void HECMW_RESULT_WRITE_ST_FINALIZE_IF(int *err)
Definition: hecmw_result_copy_f2c.c:353
hecmw_result_write_st_finalize_if
void hecmw_result_write_st_finalize_if(int *err)
Definition: hecmw_result_copy_f2c.c:339
hecmw_result_write_st_by_name_if
void hecmw_result_write_st_by_name_if(char *name_ID, int *err, int len)
Definition: hecmw_result_copy_f2c.c:359
hecmw_result.h
hecmw_result_write_st_finalize_if_
void hecmw_result_write_st_finalize_if_(int *err)
Definition: hecmw_result_copy_f2c.c:345
HECMW_RESULT_WRITE_ST_INIT_IF
void HECMW_RESULT_WRITE_ST_INIT_IF(int *err)
Definition: hecmw_result_copy_f2c.c:333
SetFunc
int(* SetFunc)(void *)
Definition: hecmw_result_copy_f2c.c:193
HECMW_calloc
#define HECMW_calloc(nmemb, size)
Definition: hecmw_malloc.h:21
hecmw_result_write_st_init_if_
void hecmw_result_write_st_init_if_(int *err)
Definition: hecmw_result_copy_f2c.c:325
HECMW_result_write_ST_by_name
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:95
HECMW_result_get_nnode
int HECMW_result_get_nnode(void)
Definition: hecmw_result.c:200
HECMW_NAME_LEN
#define HECMW_NAME_LEN
Definition: hecmw_config.h:70
hecmw_config.h
hecmw_result_write_st_by_name_if__
void hecmw_result_write_st_by_name_if__(char *name_ID, int *err, int len)
Definition: hecmw_result_copy_f2c.c:382
HECMW_RESULT_WRITE_ST_BY_NAME_IF
void HECMW_RESULT_WRITE_ST_BY_NAME_IF(char *name_ID, int *err, int len)
Definition: hecmw_result_copy_f2c.c:386
hecmw_result_write_st_init_if
void hecmw_result_write_st_init_if(int *err)
Definition: hecmw_result_copy_f2c.c:312
hecmw_result_write_st_by_name_if_
void hecmw_result_write_st_by_name_if_(char *name_ID, int *err, int len)
Definition: hecmw_result_copy_f2c.c:378
hecmw_result_write_st_init_if__
void hecmw_result_write_st_init_if__(int *err)
Definition: hecmw_result_copy_f2c.c:329
HECMW_result_copy_f2c_init
int HECMW_result_copy_f2c_init(struct hecmwST_result_data *result_data, int n_node, int n_elem)
Definition: hecmw_result_copy_f2c.c:231
hecmw_result_write_st_finalize_if__
void hecmw_result_write_st_finalize_if__(int *err)
Definition: hecmw_result_copy_f2c.c:349
HECMW_ALL_E0101
#define HECMW_ALL_E0101
Definition: hecmw_msgno.h:8
hecmw_result_copy_f2c_set_if_
void hecmw_result_copy_f2c_set_if_(char *struct_name, char *var_name, void *src, int *err, int slen, int vlen)
Definition: hecmw_result_copy_f2c.c:293
_result_struct
Definition: hecmw_vis_SF_geom.h:170
HECMW_result_get_nelem
int HECMW_result_get_nelem(void)
Definition: hecmw_result.c:202
HECMW_ALL_E0102
#define HECMW_ALL_E0102
Definition: hecmw_msgno.h:9
HECMW_strcpy_f2c
char * HECMW_strcpy_f2c(const char *fstr, int flen)
Definition: hecmw_lib_fc.c:11
hecmw_result_copy_f2c_set_if
void hecmw_result_copy_f2c_set_if(char *struct_name, char *var_name, void *src, int *err, int slen, int vlen)
Definition: hecmw_result_copy_f2c.c:246
HECMW_strcpy_f2c_r
char * HECMW_strcpy_f2c_r(const char *fstr, int flen, char *buf, int bufsize)
Definition: hecmw_lib_fc.c:45
HECMW_result_copy_f2c_finalize
int HECMW_result_copy_f2c_finalize(void)
Definition: hecmw_result_copy_f2c.c:239
Result
struct _result_struct Result
HECMW_result_free
void HECMW_result_free(struct hecmwST_result_data *result)
Definition: hecmw_result.c:21
HECMW_set_error
int HECMW_set_error(int errorno, const char *fmt,...)
Definition: hecmw_error.c:37
hecmw_result_copy_f2c_set_if__
void hecmw_result_copy_f2c_set_if__(char *struct_name, char *var_name, void *src, int *err, int slen, int vlen)
Definition: hecmw_result_copy_f2c.c:298
NULL
#define NULL
Definition: hecmw_io_nastran.c:30
HECMW_RESULT_COPY_F2C_SET_IF
void HECMW_RESULT_COPY_F2C_SET_IF(char *struct_name, char *var_name, void *src, int *err, int slen, int vlen)
Definition: hecmw_result_copy_f2c.c:304
hecmw_util.h
HECMW_MSG_LEN
#define HECMW_MSG_LEN
Definition: hecmw_config.h:74
HECMW_HEADER_LEN
#define HECMW_HEADER_LEN
Definition: hecmw_config.h:68