52 signal(signum, SIG_DFL);
59 "usage: testsocket [options]\n"
60 "\t-c [random:]<c>\tnumber of iterations\n"
61 "\t-f {fx,fy,fz,mx,my,mz} reference node force/moment\n"
62 "\t-H <url>\tURL (local://path | inet://host:port)\n"
63 "\t-M <modes>\tmodes number\n"
64 "\t-p {p1,...,pM}\tmodal forces (need -M first)\n"
65 "\t-r\t\tuse reference node data\n"
66 "\t-s <sleeptime>\tsleep time between tries\n"
68 "\t-x\t\tdata_and_next\n");
73 main(
int argc,
char *argv[])
82 unsigned short int port = -1;
90 double fx[6], *
f0 = NULL;
94 int opt =
getopt(argc, argv,
"c:f:H:M:p:rs:vx");
102 if (strncasecmp(
optarg,
"random:",
sizeof(
"random:") -1) == 0) {
104 iters = atoi(&
optarg[
sizeof(
"random:") -1]);
108 printf(
"iterations: %d\n", iters);
111 fprintf(stderr,
"test_modalext_socket: "
112 "invalid iterations %s\n",
123 fprintf(stderr,
"test_modalext_socket: "
124 "-f already provided\n");
131 for (i = 0; i < 6; i++) {
134 f0[i] = strtod(s, &next);
136 fprintf(stderr,
"test_modalext_socket: "
137 "unable to parse f[%d]\n", i);
142 if (next[0] !=
',') {
143 fprintf(stderr,
"test_modalext_socket: "
144 "unable to parse past f[%d]\n", i);
151 if (next[0] !=
'\0') {
152 fprintf(stderr,
"test_modalext_socket: "
153 "extra cruft past f[%d]\n", i);
161 if (strncasecmp(
optarg,
"inet://",
sizeof(
"inet://") - 1) == 0) {
165 host =
optarg +
sizeof(
"inet://") - 1;
166 ptr = strchr(host,
':');
172 l = strtol(ptr, &next, 10);
173 if (next == ptr || next[0] !=
'\0') {
179 port = (
unsigned short)l;
181 }
else if (strncasecmp(
optarg,
"local://",
sizeof(
"local://") - 1) == 0) {
182 path =
optarg +
sizeof(
"local://") - 1;
183 if (path[0] !=
'/') {
197 fprintf(stderr,
"test_modalext_socket: "
198 "-M cannot follow -p\n");
204 fprintf(stderr,
"test_modalext_socket: "
205 "invalid mode number %s\n",
209 modes = (unsigned)imodes;
217 fprintf(stderr,
"test_modalext_socket: "
218 "-p already provided\n");
223 fprintf(stderr,
"test_modalext_socket: "
228 p0 = (
double *)calloc(
sizeof(
double), modes);
230 fprintf(stderr,
"test_modalext_socket: "
231 "malloc for modal force values failed\n");
236 for (i = 0; i < modes; i++) {
239 p0[i] = strtod(s, &next);
241 fprintf(stderr,
"test_modalext_socket: "
242 "unable to parse p[%d]\n", i);
247 if (next[0] !=
',') {
248 fprintf(stderr,
"test_modalext_socket: "
249 "unable to parse past p[%d]\n", i);
256 if (next[0] !=
'\0') {
257 fprintf(stderr,
"test_modalext_socket: "
258 "extra cruft past p[%d]\n", i);
272 fprintf(stderr,
"test_modalext_socket: "
273 "invalid iters %s\n",
317 for (steps = 0; keep_going > 0; steps++) {
322 niters = rand() % iters + 1;
323 printf(
" iterations within this iter: %d\n", niters);
329 for (iter = 0; iter < niters; iter++) {
340 fprintf(stdout,
"x={%+16.8e,%+16.8e,%+16.8e}\n", x[0], x[1], x[2]);
344 fprintf(stdout,
"t={%+16.8e,%+16.8e,%+16.8e};\n", r[0], r[1], r[2]);
349 fprintf(stdout,
"R={{%+16.8e,%+16.8e,%+16.8e};\n", r[0], r[3], r[6]);
350 fprintf(stdout,
" {%+16.8e,%+16.8e,%+16.8e};\n", r[1], r[4], r[7]);
351 fprintf(stdout,
" {%+16.8e,%+16.8e,%+16.8e}};\n", r[2], r[5], r[8]);
356 fprintf(stdout,
"e={%+16.8e,%+16.8e,%+16.8e};\n", r[0], r[1], r[2]);
359 fprintf(stdout,
"v={%+16.8e,%+16.8e,%+16.8e}\n", v[0], v[1], v[2]);
360 fprintf(stdout,
"w={%+16.8e,%+16.8e,%+16.8e}\n", w[0], w[1], w[2]);
364 double *q =
MBC_Q(mbc);
368 for (m = 0; m < modes; m++) {
369 fprintf(stdout,
"mode #%d: %+16.8e %+16.8e\n", m, q[m], qp[m]);
403 double *p =
MBC_P(mbc);
407 for (m = 0; m < modes; m++) {
412 for (m = 0; m < modes; m++) {
413 p[m] = (double)(m + 1);
nodal stuff (partially opaque).
int mbc_modal_destroy(mbc_modal_t *mbc)
Destroy modal data.
int main(int argc, char *argv[])
int mbc_modal_negotiate_request(mbc_modal_t *mbc)
Negotiate modal data.
int mbc_modal_init(mbc_modal_t *mbc, int refnode, unsigned modes)
Initialize modal data.
Connection data structure (partially opaque)
static volatile sig_atomic_t keep_going
int getopt(int argc, char *const argv[], const char *opts)
int mbc_unix_init(mbc_t *mbc, const char *path)
Initialize communication using "unix" socket.
int mbc_inet_init(mbc_t *mbc, const char *host, short unsigned port)
Initialize communication using "inet" socket.
int mbc_modal_get_motion(mbc_modal_t *mbc)
Get modal motion from peer.
#define MBC_R_EULER_123(mbc)
static void sh(int signum)
int mbc_modal_put_forces(mbc_modal_t *mbc, int last)
Put forces to peer.