MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
test_strext_edge.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <signal.h>
#include <errno.h>
#include "mbsleep.h"
Include dependency graph for test_strext_edge.c:

Go to the source code of this file.

Enumerations

enum  { RM, MR }
 

Functions

static void sh (int signum)
 
static const char * cmd2str (int cmd)
 
static int check_flag (const char *flag, int sleeptime)
 
static int put_flag (const char *flag, int cmd)
 
static int put_rdata (const char *rdata, double fm[6])
 
static int put_mdata (const char *mdata, int modes, double *fg)
 
static int put_ndata (const char *ndata, int nodes, unsigned *ul, double *fg)
 
static int do_rigid0 (const char *rflag, const char *rdata, double *fm)
 
static int do_modal0 (const char *mflag, const char *mdata, int modes, double **fgp)
 
static int do_nodal0 (const char *nflag, const char *ndata, int nodes, unsigned **ulp, double **fgp)
 
int do_rigid (const char *rflag, const char *rdata, int niters, int *iterp, int cmd, double *fm)
 
int do_modal (const char *mflag, const char *mdata, int niters, int *iterp, int cmd, int modes, double *fg)
 
int do_nodal (const char *nflag, const char *ndata, int niters, int *iterp, int cmd, int nodes, unsigned *ul, double *fg)
 
void usage (void)
 
int main (int argc, char *argv[])
 

Variables

volatile sig_atomic_t keep_going = 1
 
int do_rename
 
int sleeptime = 1
 
mbsleep_t mbt
 
int verbose
 
enum { ... }  order = RM
 

Enumeration Type Documentation

anonymous enum
Enumerator
RM 
MR 

Definition at line 48 of file test_strext_edge.c.

48  {
49  RM,
50  MR
51 } order = RM;
enum @56 order

Function Documentation

static int check_flag ( const char *  flag,
int  sleeptime 
)
static

Definition at line 87 of file test_strext_edge.c.

References buf, c, cmd2str(), mbsleep(), and mbt.

Referenced by do_modal(), do_nodal(), and do_rigid().

88 {
89  int rc;
90 
91  while (1) {
92  char buf[BUFSIZ];
93  FILE *f;
94  char c = ' ';
95 
96  f = fopen(flag, "r");
97  if (f == NULL && errno == ENOENT) {
98  fprintf(stderr, "test_strext_edge: file \"%s\" missing\n", flag);
99  return 1;
100  }
101 
102  if (fgets(buf, sizeof(buf), f) == NULL) {
103  fprintf(stderr, "test_strext_edge: expecting \"UPDATE,N,0,0,1\", got nothing from file \"%s\"\n", flag);
104  fclose(f);
105  return -1;
106  }
107 
108  if (strcmp(buf, "UPDATE,N,0,0,1\n") != 0) {
109  size_t len = strlen(buf);
110  buf[len - 1] = '\0';
111  fprintf(stderr, "test_strext_edge: expecting \"UPDATE,N,0,0,1\", got \"%s\" from file \"%s\"\n", buf, flag);
112  fclose(f);
113  return -1;
114  }
115 
116  if (fgets(buf, sizeof(buf), f) == NULL) {
117  fprintf(stderr, "test_strext_edge: expecting \"FLAG,I,1,1,0\", got nothing from file \"%s\"\n", flag);
118  fclose(f);
119  return -1;
120  }
121  if (strcmp(buf, "FLAG,I,1,1,0\n") != 0) {
122  size_t len = strlen(buf);
123  buf[len - 1] = '\0';
124  fprintf(stderr, "test_strext_edge: expecting \"FLAG,I,1,1,0\", got \"%s\" from file \"%s\"\n", buf, flag);
125  fclose(f);
126  return -1;
127  }
128 
129  rc = fread((void *)&c, 1, 1, f);
130  fclose(f);
131  if (rc == 1) {
132  fprintf(stderr, "test_strext_edge: got %c (%s) from file \"%s\"\n", c, cmd2str(c - '0'), flag);
133 
134  switch (c) {
135  case '0':
136  case '1':
137  case '3':
138  return 0;
139 
140  case '5':
141  return 1;
142 
143  default:
144  break;
145  }
146  }
147 
148  if (sleeptime) {
149  fprintf(stderr, "test_strext_edge: sleeping %d s\n", sleeptime);
150  mbsleep(&mbt);
151  }
152  }
153 
154  return 0;
155 }
long int flag
Definition: mbdyn.h:43
int mbsleep(const mbsleep_t *t)
Definition: mbsleep.c:90
mbsleep_t mbt
static const char * cmd2str(int cmd)
static std::stack< cleanup * > c
Definition: cleanup.cc:59
static doublereal buf[BUFSIZE]
Definition: discctrl.cc:333

Here is the call graph for this function:

static const char* cmd2str ( int  cmd)
static

Definition at line 60 of file test_strext_edge.c.

Referenced by check_flag().

61 {
62  switch (cmd) {
63  case 0:
64  return "EDGE is initializing; MBDyn waits";
65 
66  case 1:
67  return "EDGE is busy; MBDyn waits";
68 
69  case 2:
70  return "EDGE waits (is ready to read kinematics); MBDyn iterates";
71 
72  case 3:
73  return "EDGE is computing; MBDyn waits before reading forces";
74 
75  case 4:
76  return "EDGE converged; MBDyn advances one step";
77 
78  case 5:
79  return "EDGE wants to end simulation";
80 
81  default:
82  return "unknown";
83  }
84 }
int do_modal ( const char *  mflag,
const char *  mdata,
int  niters,
int iterp,
int  cmd,
int  modes,
double *  fg 
)

Definition at line 460 of file test_strext_edge.c.

References buf, check_flag(), put_flag(), and put_mdata().

Referenced by main().

463 {
464  /* modal */
465  if (mflag != NULL) {
466  if (check_flag(mflag, sleeptime)) {
467  *iterp = niters;
468  keep_going = 0;
469  return 0;
470  }
471 
472  if (verbose) {
473  char buf[BUFSIZ];
474  FILE *f;
475 
476  f = fopen(mdata, "r");
477  if (f == NULL) {
478  int save_errno = errno;
479 
480  fprintf(stderr, "unable to open modal data file \"%s\" (%d: %s)\n",
481  mdata, save_errno, strerror(save_errno));
482  exit(EXIT_FAILURE);
483  }
484 
485  while (fgets(buf, sizeof(buf), f) != NULL) {
486  fprintf(stderr, ">> mdata:%s", buf);
487  }
488 
489  fclose(f);
490  }
491 
492  put_mdata(mdata, modes, fg);
493  put_flag(mflag, cmd);
494  }
495 
496  return 0;
497 }
volatile sig_atomic_t keep_going
int verbose
static int put_mdata(const char *mdata, int modes, double *fg)
int sleeptime
static int check_flag(const char *flag, int sleeptime)
static int put_flag(const char *flag, int cmd)
static doublereal buf[BUFSIZE]
Definition: discctrl.cc:333

Here is the call graph for this function:

static int do_modal0 ( const char *  mflag,
const char *  mdata,
int  modes,
double **  fgp 
)
static

Definition at line 343 of file test_strext_edge.c.

References put_flag(), and put_mdata().

Referenced by main().

344 {
345  if (mflag != NULL) {
346  FILE *f = NULL;
347  int i;
348 
349  f = fopen(mflag, "r");
350  if (f == NULL) {
351  int save_errno = errno;
352  if (save_errno == ENOENT) {
353  put_flag(mflag, 0);
354 
355  } else {
356  fprintf(stderr, "unable to open modal flag file \"%s\" (%d: %s)\n",
357  mflag, save_errno, strerror(save_errno));
358  exit(EXIT_FAILURE);
359  }
360 
361  } else {
362  fclose(f);
363  }
364 
365  *fgp = (double *)malloc(sizeof(double)*modes);
366  for (i = 0; i < modes; i++) {
367  (*fgp)[i] = ((double)i)/10.0;
368  }
369 
370  put_mdata(mdata, modes, *fgp);
371  }
372 
373  return 0;
374 }
static int put_mdata(const char *mdata, int modes, double *fg)
static int put_flag(const char *flag, int cmd)

Here is the call graph for this function:

int do_nodal ( const char *  nflag,
const char *  ndata,
int  niters,
int iterp,
int  cmd,
int  nodes,
unsigned *  ul,
double *  fg 
)

Definition at line 500 of file test_strext_edge.c.

References buf, check_flag(), put_flag(), and put_ndata().

Referenced by main().

503 {
504  /* nodal */
505  if (nflag != NULL) {
506  if (check_flag(nflag, sleeptime)) {
507  *iterp = niters;
508  keep_going = 0;
509  return 0;
510  }
511 
512  if (verbose) {
513  char buf[BUFSIZ];
514  FILE *f;
515 
516  f = fopen(ndata, "r");
517  if (f == NULL) {
518  int save_errno = errno;
519 
520  fprintf(stderr, "unable to open nodal data file \"%s\" (%d: %s)\n",
521  ndata, save_errno, strerror(save_errno));
522  exit(EXIT_FAILURE);
523  }
524 
525  while (fgets(buf, sizeof(buf), f) != NULL) {
526  fprintf(stderr, ">> ndata:%s", buf);
527  }
528 
529  fclose(f);
530  }
531 
532  put_ndata(ndata, nodes, ul, fg);
533  put_flag(nflag, cmd);
534  }
535 
536  return 0;
537 }
volatile sig_atomic_t keep_going
int verbose
int sleeptime
static int check_flag(const char *flag, int sleeptime)
static int put_flag(const char *flag, int cmd)
static doublereal buf[BUFSIZE]
Definition: discctrl.cc:333
static int put_ndata(const char *ndata, int nodes, unsigned *ul, double *fg)

Here is the call graph for this function:

static int do_nodal0 ( const char *  nflag,
const char *  ndata,
int  nodes,
unsigned **  ulp,
double **  fgp 
)
static

Definition at line 377 of file test_strext_edge.c.

References nodes, put_flag(), and put_ndata().

Referenced by main().

378 {
379  if (nflag != NULL) {
380  FILE *f = NULL;
381  int i;
382 
383  f = fopen(nflag, "r");
384  if (f == NULL) {
385  int save_errno = errno;
386  if (save_errno == ENOENT) {
387  put_flag(nflag, 0);
388 
389  } else {
390  fprintf(stderr, "unable to open nodal flag file \"%s\" (%d: %s)\n",
391  nflag, save_errno, strerror(save_errno));
392  exit(EXIT_FAILURE);
393  }
394 
395  } else {
396  fclose(f);
397  }
398 
399  if (*ulp == NULL) {
400  *ulp = (unsigned *)malloc(sizeof(unsigned)*nodes);
401  for (i = 0; i < nodes; i++) {
402  (*ulp)[i] = i + 1;
403  }
404  }
405 
406  if (*fgp == NULL) {
407  *fgp = (double *)malloc(3*sizeof(double)*nodes);
408  for (i = 0; i < 3*nodes; i++) {
409  (*fgp)[i] = ((double)i)*1e1;
410  }
411  }
412 
413  put_ndata(ndata, nodes, *ulp, *fgp);
414  }
415 
416  return 0;
417 }
static int put_flag(const char *flag, int cmd)
static int nodes
static int put_ndata(const char *ndata, int nodes, unsigned *ul, double *fg)

Here is the call graph for this function:

int do_rigid ( const char *  rflag,
const char *  rdata,
int  niters,
int iterp,
int  cmd,
double *  fm 
)

Definition at line 420 of file test_strext_edge.c.

References buf, check_flag(), put_flag(), and put_rdata().

Referenced by main().

423 {
424  /* rigid */
425  if (rflag != NULL) {
426  if (check_flag(rflag, sleeptime)) {
427  *iterp = niters;
428  keep_going = 0;
429  return 0;
430  }
431 
432  if (verbose) {
433  char buf[BUFSIZ];
434  FILE *f;
435 
436  f = fopen(rdata, "r");
437  if (f == NULL) {
438  int save_errno = errno;
439 
440  fprintf(stderr, "unable to open rigid data file \"%s\" (%d: %s)\n",
441  rdata, save_errno, strerror(save_errno));
442  exit(EXIT_FAILURE);
443  }
444 
445  while (fgets(buf, sizeof(buf), f) != NULL) {
446  fprintf(stderr, ">> rdata:%s", buf);
447  }
448 
449  fclose(f);
450  }
451 
452  put_rdata(rdata, fm);
453  put_flag(rflag, cmd);
454  }
455 
456  return 0;
457 }
volatile sig_atomic_t keep_going
int verbose
int sleeptime
static int put_rdata(const char *rdata, double fm[6])
static int check_flag(const char *flag, int sleeptime)
static int put_flag(const char *flag, int cmd)
static doublereal buf[BUFSIZE]
Definition: discctrl.cc:333

Here is the call graph for this function:

static int do_rigid0 ( const char *  rflag,
const char *  rdata,
double *  fm 
)
static

Definition at line 310 of file test_strext_edge.c.

References put_flag(), and put_rdata().

Referenced by main().

311 {
312  if (rflag != NULL) {
313  FILE *f = NULL;
314  int i;
315 
316  f = fopen(rflag, "r");
317  if (f == NULL) {
318  int save_errno = errno;
319  if (save_errno == ENOENT) {
320  put_flag(rflag, 0);
321 
322  } else {
323  fprintf(stderr, "unable to open rigid flag file \"%s\" (%d: %s)\n",
324  rflag, save_errno, strerror(save_errno));
325  exit(EXIT_FAILURE);
326  }
327 
328  } else {
329  fclose(f);
330  }
331 
332  for (i = 0; i < 6; i++) {
333  fm[i] = 0.1*(i + 1);
334  }
335 
336  put_rdata(rdata, fm);
337  }
338 
339  return 0;
340 }
static int put_rdata(const char *rdata, double fm[6])
static int put_flag(const char *flag, int cmd)

Here is the call graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 559 of file test_strext_edge.c.

References do_modal(), do_modal0(), do_nodal(), do_nodal0(), do_rigid(), do_rigid0(), getopt(), iters, iters_random, mbsleep_init(), mbt, MR, nodes, optarg, order, put_flag(), RM, sh(), steps, and usage().

560 {
561  char *rflag = NULL;
562  char *rdata = NULL;
563  char *mflag = NULL;
564  char *mdata = NULL;
565  char *nflag = NULL;
566  char *ndata = NULL;
567  int iters = 1;
568  int iters_random = 0;
569  unsigned steps;
570  int modes = 5;
571  int nodes = 0;
572  double fm[6];
573  unsigned *ul = NULL;
574  double *fg = NULL;
575 
576  while (1) {
577  int opt = getopt(argc, argv, "c:m:M:no:r:s:vw:x:X:");
578 
579  if (opt == EOF) {
580  break;
581  }
582 
583  switch (opt) {
584  case 'c':
585  if (strncasecmp(optarg, "random:", sizeof("random:") -1) == 0) {
586  iters_random = 1;
587  iters = atoi(&optarg[sizeof("random:") -1]);
588 
589  } else {
590  iters = atoi(optarg);
591  fprintf(stderr, "iterations: %d\n", iters);
592  }
593  if (iters < 1) {
594  fprintf(stderr, "test_strext_edge: "
595  "invalid sleep time %s\n",
596  optarg);
597  usage();
598  }
599  break;
600 
601  case 'm':
602  if (strncasecmp(optarg, "flag=", sizeof("flag=") - 1) == 0) {
603  mflag = &optarg[sizeof("flag=") - 1];
604 
605  } else if (strncasecmp(optarg, "data=", sizeof("data=") - 1) == 0) {
606  mdata = &optarg[sizeof("data=") - 1];
607 
608  } else {
609  fprintf(stderr, "test_strext_edge: "
610  "unknown modal file \"%s\"\n",
611  optarg);
612  usage();
613  }
614  break;
615 
616  case 'M':
617  modes = atoi(optarg);
618  if (modes <= 0) {
619  fprintf(stderr, "test_strext_edge: "
620  "invalid mode number %s\n",
621  optarg);
622  usage();
623  }
624  break;
625 
626  case 'n':
627 #ifdef HAVE_MKSTEMP
628  do_rename++;
629 #else // ! HAVE_MKSTEMP
630  fprintf(stderr, "test_strext_edge: "
631  "'-n' meaningless\n");
632 #endif // ! HAVE_MKSTEMP
633  break;
634 
635  case 'o':
636  if (strcmp(optarg, "rm") == 0) {
637  order = RM;
638 
639  } else if (strcmp(optarg, "mr") == 0) {
640  order = MR;
641 
642  } else {
643  fprintf(stderr, "test_strext_edge: "
644  "invalid order \"%s\"\n",
645  optarg);
646  usage();
647  }
648  break;
649 
650  case 'r':
651  if (strncasecmp(optarg, "flag=", sizeof("flag=") - 1) == 0) {
652  rflag = &optarg[sizeof("flag=") - 1];
653 
654  } else if (strncasecmp(optarg, "data=", sizeof("data=") - 1) == 0) {
655  rdata = &optarg[sizeof("data=") - 1];
656 
657  } else {
658  fprintf(stderr, "test_strext_edge: "
659  "unknown rigid file \"%s\"\n",
660  optarg);
661  usage();
662  }
663  break;
664 
665  case 's':
666  sleeptime = atoi(optarg);
667  if (sleeptime < 0) {
668  fprintf(stderr, "test_strext_edge: "
669  "invalid iters %s\n",
670  optarg);
671  usage();
672  }
674  break;
675 
676  case 'v':
677  verbose++;
678  break;
679 
680  case 'w':
681  if (nodes == 0) {
682  fprintf(stderr, "test_strext_edge: "
683  "-w needs -W first\n");
684  usage();
685 
686  } else if (fg != NULL) {
687  fprintf(stderr, "test_strext_edge: "
688  "-w already provided\n");
689  usage();
690 
691  } else {
692  char *value = optarg, *next;
693  int i;
694 
695  fg = (double *)malloc(3*sizeof(double)*nodes);
696 
697  fg[0] = strtod(value, &next);
698  if (next == value || next == NULL) {
699  fprintf(stderr, "test_strext_edge: "
700  "unable to parse first value\n");
701  usage();
702  }
703 
704  if (next[0] == ',') {
705  value = next + 1;
706  fg[nodes] = strtod(value, &next);
707  if (next == value || next == NULL || next[0] != ',') {
708  fprintf(stderr, "test_strext_edge: "
709  "unable to parse second value\n");
710  usage();
711  }
712 
713  value = next + 1;
714  fg[2*nodes] = strtod(value, &next);
715  if (next == value || next == NULL) {
716  fprintf(stderr, "test_strext_edge: "
717  "unable to parse third value\n");
718  usage();
719  }
720 
721  if (next[0] == ',') {
722  for (i = 3; i < 3*nodes; i++) {
723  value = next + 1;
724  fg[(i%3)*nodes + i/3] = strtod(value, &next);
725  if (next == value || next == NULL || next[0] != ( i == 3*nodes - 1 ? '\0' : ',' )) {
726  fprintf(stderr, "test_strext_edge: "
727  "unable to parse value #%d\n", i);
728  usage();
729  }
730  }
731 
732  } else {
733  for (i = 1; i < nodes; i++) {
734  fg[i] = fg[0];
735  fg[nodes + i] = fg[nodes];
736  fg[2*nodes + i] = fg[2*nodes];
737  }
738  }
739 
740  } else {
741  for (i = 1; i < 3*nodes; i++) {
742  fg[i] = fg[0];
743  }
744  }
745  }
746 
747  break;
748 
749  case 'x':
750  if (strncasecmp(optarg, "flag=", sizeof("flag=") - 1) == 0) {
751  nflag = &optarg[sizeof("flag=") - 1];
752 
753  } else if (strncasecmp(optarg, "data=", sizeof("data=") - 1) == 0) {
754  ndata = &optarg[sizeof("data=") - 1];
755 
756  } else {
757  fprintf(stderr, "test_strext_edge: "
758  "unknown nodal file \"%s\"\n",
759  optarg);
760  usage();
761  }
762  break;
763 
764  case 'X': {
765  char *p = optarg, *next;
766 
767  nodes = strtol(p, &next, 10);
768  if (nodes <= 0) {
769  fprintf(stderr, "test_strext_edge: "
770  "invalid node number %s\n",
771  optarg);
772  usage();
773  }
774 
775  if (next != NULL && next != p && next[0] == ':') {
776  int i;
777  ul = (unsigned *)malloc(nodes*sizeof(unsigned));
778  for (i = 0; i < nodes; i++) {
779  p = next + 1;
780  ul[i] = strtol(p, &next, 10);
781  if (next == NULL || next == p || (next[0] != ',' && next[0] != '\0')) {
782  fprintf(stderr, "test_strext_edge: "
783  "invalid ID #%d\n", i);
784  usage();
785  }
786  }
787  }
788  } break;
789 
790  default:
791  usage();
792  }
793  }
794 
795  if (mflag == NULL && mdata != NULL) {
796  fprintf(stderr, "test_strext_edge: "
797  "need modal flag file "
798  "along with modal data file \"%s\"\n",
799  mdata);
800  usage();
801  }
802 
803  if (mflag != NULL && mdata == NULL) {
804  fprintf(stderr, "test_strext_edge: "
805  "need modal data file "
806  "along with modal flag file \"%s\"\n",
807  mflag);
808  usage();
809  }
810 
811  if (nflag == NULL && ndata != NULL) {
812  fprintf(stderr, "test_strext_edge: "
813  "need nodal flag file "
814  "along with nodal data file \"%s\"\n",
815  ndata);
816  usage();
817  }
818 
819  if (nflag != NULL && ndata == NULL) {
820  fprintf(stderr, "test_strext_edge: "
821  "need nodal data file "
822  "along with nodal flag file \"%s\"\n",
823  nflag);
824  usage();
825  }
826 
827  if (mflag != NULL && nflag != NULL) {
828  fprintf(stderr, "test_strext_edge: "
829  "nodal and modal incompatible\n");
830  usage();
831  }
832 
833  if (rflag == NULL && rdata != NULL) {
834  fprintf(stderr, "test_strext_edge: "
835  "need rigid flag file "
836  "along with rigid data file \"%s\"\n",
837  rdata);
838  usage();
839  }
840 
841  if (rflag != NULL && rdata == NULL) {
842  fprintf(stderr, "test_strext_edge: "
843  "need rigid data file "
844  "along with rigid flag file \"%s\"\n",
845  rflag);
846  usage();
847  }
848 
849  if (mflag == NULL && nflag == NULL && rflag == NULL) {
850  fprintf(stderr, "test_strext_edge: "
851  "need at least rigid or modal or nodal files\n");
852  usage();
853  }
854 
855  signal(SIGTERM, sh);
856  signal(SIGINT, sh);
857 
858  switch (order) {
859  case RM:
860  do_rigid0(rflag, rdata, fm);
861  if (mflag) do_modal0(mflag, mdata, modes, &fg);
862  if (nflag) do_nodal0(nflag, ndata, nodes, &ul, &fg);
863  break;
864 
865  case MR:
866  if (mflag) do_modal0(mflag, mdata, modes, &fg);
867  if (nflag) do_nodal0(nflag, ndata, nodes, &ul, &fg);
868  do_rigid0(rflag, rdata, fm);
869  break;
870  }
871 
872  for (steps = 0; keep_going > 0; steps++) {
873  int iter;
874  int niters;
875 
876  if (iters_random) {
877  niters = rand() % iters + 1;
878  fprintf(stderr, " iterations within this iter: %d\n", niters);
879 
880  } else {
881  niters = iters;
882  }
883 
884  for (iter = 0; iter < niters; iter++) {
885  int cmd = 2;
886 
887  if (iter == niters - 1) {
888  fprintf(stderr, "*** step %d converged after %d iterations\n", steps, iter);
889  cmd = 4;
890  }
891 
892  switch (order) {
893  case RM:
894  do_rigid(rflag, rdata, niters, &iter, cmd, fm);
895  if (mflag) do_modal(mflag, mdata, niters, &iter, cmd, modes, fg);
896  if (nflag) do_nodal(nflag, ndata, niters, &iter, cmd, nodes, ul, fg);
897  break;
898 
899  case MR:
900  if (mflag) do_modal(mflag, mdata, niters, &iter, cmd, modes, fg);
901  if (nflag) do_nodal(nflag, ndata, niters, &iter, cmd, nodes, ul, fg);
902  do_rigid(rflag, rdata, niters, &iter, cmd, fm);
903  break;
904  }
905 
906  }
907  }
908 
909  if (rflag) put_flag(rflag, 5);
910  if (mflag) put_flag(mflag, 5);
911  if (nflag) put_flag(nflag, 5);
912 
913  return 0;
914 }
void usage(void)
static int iters
enum @56 order
volatile sig_atomic_t keep_going
int verbose
static int iters_random
int sleeptime
mbsleep_t mbt
static void sh(int signum)
static int do_modal0(const char *mflag, const char *mdata, int modes, double **fgp)
int do_nodal(const char *nflag, const char *ndata, int niters, int *iterp, int cmd, int nodes, unsigned *ul, double *fg)
int do_modal(const char *mflag, const char *mdata, int niters, int *iterp, int cmd, int modes, double *fg)
mbsleep_t mbsleep_init(long t)
Definition: mbsleep.c:38
static int do_nodal0(const char *nflag, const char *ndata, int nodes, unsigned **ulp, double **fgp)
static int put_flag(const char *flag, int cmd)
static int nodes
int getopt(int argc, char *const argv[], const char *opts)
Definition: getopt.c:93
static unsigned steps
char * optarg
Definition: getopt.c:74
struct s2s_t * next
Definition: s2s.h:86
static int do_rigid0(const char *rflag, const char *rdata, double *fm)
int do_rigid(const char *rflag, const char *rdata, int niters, int *iterp, int cmd, double *fm)
int do_rename

Here is the call graph for this function:

static int put_flag ( const char *  flag,
int  cmd 
)
static

Definition at line 158 of file test_strext_edge.c.

References mbsleep(), and mbt.

Referenced by do_modal(), do_modal0(), do_nodal(), do_nodal0(), do_rigid(), do_rigid0(), and main().

159 {
160  FILE *f;
161  char ftmpname[] = "mbedgeXXXXXX";
162 
163 #ifdef HAVE_MKSTEMP
164  if (do_rename) {
165  int filedes = mkstemp(ftmpname);
166  f = fdopen(filedes, "w");
167 
168  } else
169 #endif // HAVE_MKSTEMP
170  {
171  f = fopen(flag, "w");
172  }
173 
174  if (f == NULL) {
175  int save_errno = errno;
176  fprintf(stderr, "unable to open flag file \"%s\" for writing (%d: %s)\n",
177  flag, save_errno, strerror(save_errno));
178  exit(EXIT_FAILURE);
179  }
180 
181  fprintf(f, "UPDATE,N,0,0,1\n");
182  fprintf(f, "FLAG,I,1,1,0\n");
183  fprintf(f, "%d", cmd);
184  fclose(f);
185 
186  if (do_rename) {
187 retry:;
188  if (rename(ftmpname, flag) == -1) {
189  switch (errno) {
190  case EBUSY:
191  mbsleep(&mbt);
192  goto retry;
193 
194  default: {
195  int save_errno = errno;
196  fprintf(stderr, "unable to rename flag file \"%s\" (errno=%d: %s)\n",
197  flag, save_errno, strerror(save_errno));
198  exit(EXIT_FAILURE);
199  }
200  }
201  }
202  }
203 
204  return 0;
205 }
long int flag
Definition: mbdyn.h:43
int mbsleep(const mbsleep_t *t)
Definition: mbsleep.c:90
mbsleep_t mbt
int do_rename

Here is the call graph for this function:

static int put_mdata ( const char *  mdata,
int  modes,
double *  fg 
)
static

Definition at line 235 of file test_strext_edge.c.

Referenced by do_modal(), and do_modal0().

236 {
237  FILE *f;
238  int i;
239 
240  f = fopen(mdata, "w");
241  if (f == NULL) {
242  int save_errno = errno;
243 
244  fprintf(stderr, "unable to open modal data file \"%s\" (%d: %s)\n",
245  mdata, save_errno, strerror(save_errno));
246  exit(EXIT_FAILURE);
247  }
248 
249  fprintf(f,
250  "* modal forces\n"
251  "modal_force_flow,R,%d,1,0\n",
252  modes);
253  for (i = 0; i < modes; i++) {
254  fprintf(f, "%e ", fg[i]);
255  }
256  fputc('\n', f);
257  fclose(f);
258 
259  return 0;
260 }
static int put_ndata ( const char *  ndata,
int  nodes,
unsigned *  ul,
double *  fg 
)
static

Definition at line 263 of file test_strext_edge.c.

References nodes.

Referenced by do_nodal(), and do_nodal0().

264 {
265  FILE *f;
266  int i;
267 
268  f = fopen(ndata, "w");
269  if (f == NULL) {
270  int save_errno = errno;
271 
272  fprintf(stderr, "unable to open nodal data file \"%s\" (%d: %s)\n",
273  ndata, save_errno, strerror(save_errno));
274  exit(EXIT_FAILURE);
275  }
276 
277  fprintf(f,
278  "ext_model, N, 0, 0, 2\n"
279  "* nodal forces\n"
280  "grid_idents, IF, 1, %d, 0\n",
281  nodes);
282  for (i = 0; i < nodes; i++) {
283  if (i > 0) fputc(((i%6) == 0) ? '\n' : ' ', f);
284  fprintf(f, "%d", ul[i]);
285  }
286  fputc('\n', f);
287 
288  fprintf(f, "force, RF, 3, %d, 0\n", nodes);
289  for (i = 0; i < nodes; i++) {
290  if (i > 0) fputc(((i%6) == 0) ? '\n' : ' ', f);
291  fprintf(f, "%e", fg[i]);
292  }
293  fputc('\n', f);
294  for (i = 0; i < nodes; i++) {
295  if (i > 0) fputc(((i%6) == 0) ? '\n' : ' ', f);
296  fprintf(f, "%e", fg[nodes + i]);
297  }
298  fputc('\n', f);
299  for (i = 0; i < nodes; i++) {
300  if (i > 0) fputc(((i%6) == 0) ? '\n' : ' ', f);
301  fprintf(f, "%e", fg[2*nodes + i]);
302  }
303  fputc('\n', f);
304  fclose(f);
305 
306  return 0;
307 }
static int nodes
static int put_rdata ( const char *  rdata,
double  fm[6] 
)
static

Definition at line 208 of file test_strext_edge.c.

Referenced by do_rigid(), and do_rigid0().

209 {
210  FILE *f;
211  int i;
212 
213  f = fopen(rdata, "w");
214  if (f == NULL) {
215  int save_errno = errno;
216 
217  fprintf(stderr, "unable to open rigid data file \"%s\" (%d: %s)\n",
218  rdata, save_errno, strerror(save_errno));
219  exit(EXIT_FAILURE);
220  }
221 
222  fprintf(f,
223  "* rigid-body forces and moments\n"
224  "body_forces,R,1,6,0\n");
225  for (i = 0; i < 6; i++) {
226  fprintf(f, "%e ", fm[i]);
227  }
228  fputc('\n', f);
229  fclose(f);
230 
231  return 0;
232 }
static void sh ( int  signum)
static

Definition at line 54 of file test_strext_edge.c.

Referenced by main().

55 {
56  keep_going = 0;
57  signal(signum, SIG_DFL);
58 }
volatile sig_atomic_t keep_going
void usage ( void  )

Definition at line 540 of file test_strext_edge.c.

Referenced by main().

541 {
542  fprintf(stderr,
543  "usage: test_strext_edge [options]\n"
544  "\t-c [random:]<c>\t\tnumber of iterations\n"
545  "\t-m [flag|data]=<file>\tmodal file names (set both)\n"
546  "\t-M <modes>\t\tmodes number\n"
547  "\t-n\t\t\tuse \"rename\" when writing flag files\n"
548  "\t-o {rm|mr}\tprocess rigid,modal (rm) or modal,rigid (mr)\n"
549  "\t-r [flag|data]=<file>\trigid-body file names (set both)\n"
550  "\t-s <sleeptime>\t\tsleep time between tries\n"
551  "\t-v\t\t\tverbose\n"
552  "\t-w f[x,fy,fz[,fx2,fy2,fz2,...]]\n"
553  "\t-x [flag|data]=<file>\tnodal file names (set both)\n"
554  "\t-X <nodes>[:<label>[,<label>]]\t\tnodes number (labels)\n" );
555  exit(EXIT_FAILURE);
556 }

Variable Documentation

int do_rename

Definition at line 44 of file test_strext_edge.c.

volatile sig_atomic_t keep_going = 1

Definition at line 42 of file test_strext_edge.c.

mbsleep_t mbt

Definition at line 46 of file test_strext_edge.c.

Referenced by check_flag(), main(), and put_flag().

enum { ... } order

Referenced by main().

int sleeptime = 1

Definition at line 45 of file test_strext_edge.c.

int verbose

Definition at line 47 of file test_strext_edge.c.