FrontISTR 5.2.0
Large-scale structural analysis program with finit element method
Loading...
Searching...
No Matches
hecmw_couple_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
11#include "hecmw_malloc.h"
12#include "hecmw_lib_fc.h"
13#include "hecmw_msgno.h"
14#include "hecmw_struct.h"
15#include "hecmw_couple_define.h"
17
18static struct hecmw_couple_value *couple_value;
19
20/*------------------------------------------------------------------------------------------------*/
21/*
22 * SetFunc
23 */
24
25static int set_n(void *src) {
26 couple_value->n = *((int *)src);
27 return 0;
28}
29
30static int set_item_type(void *src) {
31 couple_value->item_type = *((int *)src);
32 return 0;
33}
34
35static int set_n_dof(void *src) {
36 couple_value->n_dof = *((int *)src);
37 return 0;
38}
39
40static int set_item(void *src) {
41 int size;
42
43 if (couple_value->n <= 0) return 0;
44
45 if (couple_value->item_type == HECMW_COUPLE_NODE_GROUP) {
46 size = sizeof(*couple_value->item) * couple_value->n;
47 } else if (couple_value->item_type == HECMW_COUPLE_ELEMENT_GROUP) {
48 size = sizeof(*couple_value->item) * couple_value->n;
49 } else if (couple_value->item_type == HECMW_COUPLE_SURFACE_GROUP) {
50 size = sizeof(*couple_value->item) * couple_value->n * 2;
51 } else {
52 return 0;
53 }
54 couple_value->item = HECMW_malloc(size);
55 if (couple_value->item == NULL) {
56 HECMW_set_error(errno, "");
57 return -1;
58 }
59 memcpy(couple_value->item, src, size);
60 return 0;
61}
62
63static int set_value(void *src) {
64 int size;
65
66 if (couple_value->n <= 0 || couple_value->n_dof <= 0) return 0;
67
68 size = sizeof(*couple_value->value) * couple_value->n * couple_value->n_dof;
69 couple_value->value = HECMW_malloc(size);
70 if (couple_value->value == NULL) {
71 HECMW_set_error(errno, "");
72 return -1;
73 }
74 memcpy(couple_value->value, src, size);
75 return 0;
76}
77
78/*------------------------------------------------------------------------------------------------*/
79/*
80 * SetFunc table
81 */
82
83typedef int (*SetFunc)(void *);
84
85static struct func_table {
86 char *struct_name;
87 char *var_name;
88 SetFunc set_func;
89} functions[] = {
90 /* { Struct_name, Variable name, memcpy function } */
91 {"hecmw_couple_value", "n", set_n},
92 {"hecmw_couple_value", "item_type", set_item_type},
93 {"hecmw_couple_value", "n_dof", set_n_dof},
94 {"hecmw_couple_value", "item", set_item},
95 {"hecmw_couple_value", "value", set_value},
96};
97
98static const int NFUNC = sizeof(functions) / sizeof(functions[0]);
99
100static SetFunc get_set_func(char *struct_name, char *var_name) {
101 int i;
102
103 for (i = 0; i < NFUNC; i++) {
104 if (strcmp(functions[i].struct_name, struct_name) == 0 &&
105 strcmp(functions[i].var_name, var_name) == 0) {
106 return functions[i].set_func;
107 }
108 }
109 return NULL;
110}
111
112/*------------------------------------------------------------------------------------------------*/
113
115 struct hecmw_couple_value *_couple_value) {
116 couple_value = _couple_value;
117 return 0;
118}
119
121 couple_value = NULL;
122 return 0;
123}
124
125/*------------------------------------------------------------------------------------------------*/
126
127extern void hecmw_cpl_copy_f2c_set_if(char *struct_name, char *var_name,
128 void *src, int *err, int slen, int vlen) {
129 SetFunc func;
130 char sname[HECMW_NAME_LEN + 1];
131 char vname[HECMW_NAME_LEN + 1];
132
133 *err = 1;
134
135 if (couple_value == NULL) {
138 "hecmw_cpl_copy_f2c_set_if(): 'couple_value' has not initialized yet");
139 return;
140 }
141 if (struct_name == NULL) {
143 "hecmw_cpl_copy_f2c_set_if(): 'struct_name' is NULL");
144 return;
145 }
146 if (var_name == NULL) {
148 "hecmw_cpl_copy_f2c_set_if(): 'var_name' is NULL");
149 return;
150 }
151
152 if (HECMW_strcpy_f2c_r(struct_name, slen, sname, sizeof(sname)) == NULL)
153 return;
154 if (HECMW_strcpy_f2c_r(var_name, vlen, vname, sizeof(vname)) == NULL) return;
155
156 if ((func = get_set_func(sname, vname)) == NULL) {
158 "hecmw_cpl_copy_f2c_set_if(): SetFunc not found");
159 return;
160 }
161
162 if ((*func)(src)) return;
163
164 *err = 0;
165}
166
167extern void hecmw_cpl_copy_f2c_set_if_(char *struct_name, char *var_name,
168 void *src, int *err, int slen,
169 int vlen) {
170 hecmw_cpl_copy_f2c_set_if(struct_name, var_name, src, err, slen, vlen);
171}
172
173extern void hecmw_cpl_copy_f2c_set_if__(char *struct_name, char *var_name,
174 void *src, int *err, int slen,
175 int vlen) {
176 hecmw_cpl_copy_f2c_set_if(struct_name, var_name, src, err, slen, vlen);
177}
178
179extern void HECMW_CPL_COPY_F2C_SET_IF(char *struct_name, char *var_name,
180 void *src, int *err, int slen, int vlen) {
181 hecmw_cpl_copy_f2c_set_if(struct_name, var_name, src, err, slen, vlen);
182}
#define HECMW_NAME_LEN
Definition: hecmw_config.h:70
void hecmw_cpl_copy_f2c_set_if_(char *struct_name, char *var_name, void *src, int *err, int slen, int vlen)
int HECMW_couple_copy_f2c_init(struct hecmw_couple_value *_couple_value)
int HECMW_couple_copy_f2c_finalize(void)
void HECMW_CPL_COPY_F2C_SET_IF(char *struct_name, char *var_name, void *src, int *err, int slen, int vlen)
void hecmw_cpl_copy_f2c_set_if__(char *struct_name, char *var_name, void *src, int *err, int slen, int vlen)
void hecmw_cpl_copy_f2c_set_if(char *struct_name, char *var_name, void *src, int *err, int slen, int vlen)
int(* SetFunc)(void *)
#define HECMW_COUPLE_ELEMENT_GROUP
#define HECMW_COUPLE_NODE_GROUP
#define HECMWCPL_E_INVALID_NULL_PTR
#define HECMWCPL_E_INVALID_ARG
#define HECMW_COUPLE_SURFACE_GROUP
int HECMW_set_error(int errorno, const char *fmt,...)
Definition: hecmw_error.c:37
#define NULL
char * HECMW_strcpy_f2c_r(const char *fstr, int flen, char *buf, int bufsize)
Definition: hecmw_lib_fc.c:45
#define HECMW_malloc(size)
Definition: hecmw_malloc.h:20