MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
femgen.c
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/utils/femgen.c,v 1.7 2017/01/12 15:10:27 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 
32 #include "mbconfig.h"
33 
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <unistd.h>
38 
39 #include "ac/f2c.h"
40 
41 extern int __FC_DECL__(femgen)(char outname[73], int32_t *iimd, int32_t *iimv, int32_t *idxm);
42 
43 static void
44 usage(FILE *outf, int rc)
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 }
57 
58 int
59 main(int argc, char *argv[])
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 }
148 
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
int main(int argc, char *argv[])
Definition: femgen.c:59