MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
femgen.c File Reference
#include "mbconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "ac/f2c.h"
Include dependency graph for femgen.c:

Go to the source code of this file.

Functions

int femgen (char outname[73], int32_t *iimd, int32_t *iimv, int32_t *idxm)
 
static void usage (FILE *outf, int rc)
 
int main (int argc, char *argv[])
 

Function Documentation

int femgen ( char  outname[73],
int32_t *  iimd,
int32_t *  iimv,
int32_t *  idxm 
)

Referenced by main().

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

Definition at line 59 of file femgen.c.

References femgen(), getopt(), optarg, optind, and usage().

60 {
61  char outname[73] = { ' ' };
62 
63  int32_t iimd = 1, iimv = 1, idxm = 0;
64 
65  for (;;) {
66  int opt = getopt(argc, argv, "dhm:o:");
67  if (opt == -1) {
68  break;
69  }
70 
71  switch (opt) {
72  case 'd':
73  iimd = 0;
74  iimv = 0;
75  break;
76 
77  case '?':
78  case 'h':
79  usage(stdout, EXIT_SUCCESS);
80 
81  case 'm':
82  if (optarg[1] != '\0') {
83  usage(stderr, EXIT_FAILURE);
84  }
85 
86  switch (optarg[0]) {
87  case 'c':
88  idxm = -1;
89  break;
90 
91  case 'x':
92  idxm = 1;
93  break;
94 
95  case 'y':
96  idxm = 2;
97  break;
98 
99  case 'z':
100  idxm = 3;
101  break;
102 
103  default:
104  fprintf(stderr, "femgen: unhandled parameter '%c' for option '-m'\n", optarg[0]);
105  usage(stderr, EXIT_FAILURE);
106  }
107  break;
108 
109  case 'o': {
110  size_t len = strlen(optarg);
111  if (len >= sizeof(outname)) {
112  fprintf(stderr, "femgen: output file name '%s' too long; trim to 72 bytes or less\n", optarg);
113  exit(EXIT_FAILURE);
114  }
115 
116  strncpy(outname, optarg, len + 1);
117  } break;
118 
119  default:
120  fprintf(stderr, "femgen: unhandled option '%c'\n", opt);
121  usage(stderr, EXIT_FAILURE);
122  }
123  }
124 
125  if (optind < argc) {
126  if (outname[0] != ' ') {
127  fprintf(stderr, "femgen: output file name already set using '-o' option\n");
128  exit(EXIT_FAILURE);
129 
130  } else {
131  size_t len = strlen(argv[optind]);
132  if (len >= sizeof(outname)) {
133  fprintf(stderr, "femgen: output file name '%s' too long; trim to 72 bytes or less\n", argv[optind]);
134  exit(EXIT_FAILURE);
135  }
136 
137  strncpy(outname, argv[optind], len + 1);
138  optind++;
139  }
140  }
141 
142  if (optind < argc) {
143  fprintf(stderr, "femgen: extra args ignored\n");
144  }
145 
146  return __FC_DECL__(femgen)(outname, &iimd, &iimv, &idxm);
147 }
int optind
Definition: getopt.c:72
int femgen(char outname[73], int32_t *iimd, int32_t *iimv, int32_t *idxm)
static void usage(FILE *outf, int rc)
Definition: femgen.c:44
int getopt(int argc, char *const argv[], const char *opts)
Definition: getopt.c:93
char * optarg
Definition: getopt.c:74

Here is the call graph for this function:

static void usage ( FILE *  outf,
int  rc 
)
static

Definition at line 44 of file femgen.c.

Referenced by main().

45 {
46  fprintf(outf,
47 "usage: femgen [-hd] [-m {cxyz}] [[-o] <outfile>]\n"
48 "\t-d\t\tno initial modal displacements/velocities\n"
49 "\t-h\t\tthis message\n"
50 "\t-m <idx>\tindex of \"mass\" component to be used\n"
51 "\t\t\t('x', 'y', 'z'; 'c' to check consistency)\n"
52 "\t-o <outfile>\toutput file name (up to 72 characters long)\n"
53  );
54  exit(rc);
55 
56 }