PLUTO
cmd_line_opt.c File Reference

Parse command line options. More...

#include "pluto.h"
Include dependency graph for cmd_line_opt.c:

Go to the source code of this file.

Functions

static void PrintUsage ()
 
void ParseCmdLineArgs (int argc, char *argv[], char *ini_file, Cmd_Line *cmd)
 

Detailed Description

Parse command line options.

Parse command line options at runtime and set values in the Cmd_Line structure.

Authors
A. Mignone (migno.nosp@m.ne@p.nosp@m.h.uni.nosp@m.to.i.nosp@m.t)
Date
July 17, 2013

Definition in file cmd_line_opt.c.

Function Documentation

void ParseCmdLineArgs ( int  argc,
char *  argv[],
char *  ini_file,
Cmd_Line cmd 
)

Parse command line options. Error messages will be output to stdout.

Parameters
[in]argcargument count
[in]argvargument vector
[in]ini_filea pointer to a string containing the name of the initialization file (default: "pluto.ini")
[out]cmdthe command-line structure.

Definition at line 18 of file cmd_line_opt.c.

32 {
33  int i,j;
34 
35 /* -----------------------------------------------
36  Set default values first
37  ----------------------------------------------- */
38 
39  cmd->restart = NO;
40  cmd->h5restart = NO;
41  cmd->maxsteps = 0 ;
42  cmd->write = YES;
43  cmd->makegrid = NO;
44  cmd->jet = -1; /* -- means no direction -- */
45  cmd->show_dec = NO;
46  cmd->xres = -1; /* -- means no grid resizing -- */
47 
48  cmd->nproc[IDIR] = -1; /* means autodecomp will be used */
49  cmd->nproc[JDIR] = -1;
50  cmd->nproc[KDIR] = -1;
51 
52  #ifdef PARALLEL
53  cmd->parallel_dim[IDIR] = YES; /* by default, we parallelize */
54  cmd->parallel_dim[JDIR] = YES; /* all directions */
55  cmd->parallel_dim[KDIR] = YES;
56  #endif
57 
58 /* --------------------------------------------------------------------
59  Parse Command Line Options.
60 
61  Note: Since at this time the output directory is now known and
62  "pluto.log" has not been opened yet, we use printf to issue
63  error messages.
64  -------------------------------------------------------------------- */
65 
66  for (i = 1; i < argc ; i++){
67 
68  if (!strcmp(argv[i],"-dec")) {
69 
70  /* -- start reading integers at i+1 -- */
71 
72  for (g_dir = 0; g_dir < DIMENSIONS; g_dir++){
73 
74  if ((++i) >= argc){
75  if (prank == 0){
76  D_SELECT(printf ("! You must specify -dec n1\n"); ,
77  printf ("! You must specify -dec n1 n2\n"); ,
78  printf ("! You must specify -dec n1 n2 n3\n");)
79  }
80  QUIT_PLUTO(1);
81  }
82  cmd->nproc[g_dir] = atoi(argv[i]);
83  if (cmd->nproc[g_dir] == 0){
84  if (prank == 0) {
85  printf ("! Incorrect number of processor for g_dir = %d \n", g_dir);
86  }
87  QUIT_PLUTO(0);
88  }
89  }
90 
91  }else if (!strcmp(argv[i],"-i")) {
92 
93  sprintf (ini_file,"%s",argv[++i]);
94 
95  } else if (!strcmp(argv[i],"-makegrid")) {
96 
97  cmd->makegrid = YES;
98 
99  }else if (!strcmp(argv[i],"-maxsteps")){
100 
101  if ((++i) >= argc){
102  if (prank == 0) printf ("! You must specify -maxsteps nn\n");
103  QUIT_PLUTO(1);
104  }else{
105  cmd->maxsteps = atoi(argv[i]);
106  if (cmd->maxsteps == 0) {
107  if (prank == 0)
108  printf ("! You must specify -maxsteps nn, with nn > 0 \n");
109  QUIT_PLUTO(0);
110  }
111  }
112 
113  }else if (!strcmp(argv[i],"-no-write")) {
114 
115  cmd->write = NO;
116 
117  }else if (!strcmp(argv[i],"-no-x1par")) {
118 
119  cmd->parallel_dim[IDIR] = NO;
120 
121  }else if (!strcmp(argv[i],"-no-x2par")) {
122 
123  cmd->parallel_dim[JDIR] = NO;
124 
125  }else if (!strcmp(argv[i],"-no-x3par")) {
126 
127  cmd->parallel_dim[KDIR] = NO;
128 
129  } else if (!strcmp(argv[i],"-show-dec")) {
130 
131  cmd->show_dec = YES;
132 
133  } else if (!strcmp(argv[i],"-x1jet")) {
134 
135  cmd->jet = IDIR;
136 
137  } else if (!strcmp(argv[i],"-x2jet")) {
138 
139  cmd->jet = JDIR;
140 
141  } else if (!strcmp(argv[i],"-x3jet")) {
142 
143  cmd->jet = KDIR;
144 
145  }else if (!strcmp(argv[i],"-xres")){
146 
147  if ((++i) >= argc){
148  if (prank == 0) printf ("! You must specify -xres nn\n");
149  QUIT_PLUTO(1);
150  }else{
151  cmd->xres = atoi(argv[i]);
152  if (cmd->xres <= 1) {
153  if (prank == 0) printf ("! You must specify -xres nn, with nn > 1 \n");
154  QUIT_PLUTO(0)
155  }
156  }
157 
158  }else if (!strcmp(argv[i],"-restart") || !strcmp(argv[i],"-h5restart")) {
159 
160  /* ---------------------------------------------
161  default restart is last written file (-1)
162  --------------------------------------------- */
163 
164  if (!strcmp(argv[i], "-restart")) cmd->restart = YES; /* can only take YES/NO values */
165  else cmd->h5restart = YES;
166  cmd->nrestart = -1; /* the file number to restart from */
167 
168  if ((++i) < argc){
169  char *endptr;
170 /* cmd->restart = atoi(argv[i]); */
171  cmd->nrestart = (int)strtol(argv[i], &endptr, 10);
172 
173  /* ----------------------------------------------
174  if a non-numerical character is encountered,
175  cmd->nrestart should reset to -1
176  ---------------------------------------------- */
177 
178  if (endptr == argv[i]){
179  i--;
180  cmd->nrestart = -1;
181  }
182  }
183 
184  }else if (!strcmp(argv[i],"--help")){
185 
186  PrintUsage();
187  QUIT_PLUTO(1);
188 
189  }else{
190  if (prank == 0) printf ("! Unknown option '%s'\n",argv[i]);
191  QUIT_PLUTO(1);
192  }
193  }
194 
195 /* -- disable domain decomposition in the
196  direction specified by -xnjet -- */
197 
198  if (cmd->jet == IDIR) cmd->parallel_dim[IDIR] = NO;
199  else if (cmd->jet == JDIR) cmd->parallel_dim[JDIR] = NO;
200  else if (cmd->jet == KDIR) cmd->parallel_dim[KDIR] = NO;
201 
202 }
int write
Definition: structs.h:16
int parallel_dim[3]
Definition: structs.h:19
int nrestart
Definition: structs.h:14
static void PrintUsage()
Definition: cmd_line_opt.c:204
#define YES
Definition: pluto.h:25
int xres
Definition: structs.h:22
int nproc[3]
Definition: structs.h:20
int h5restart
Definition: structs.h:13
int prank
Processor rank.
Definition: globals.h:33
#define KDIR
Definition: pluto.h:195
#define IDIR
Definition: pluto.h:193
int g_dir
Specifies the current sweep or direction of integration.
Definition: globals.h:86
int show_dec
Definition: structs.h:21
int j
Definition: analysis.c:2
int jet
Definition: structs.h:18
int maxsteps
Definition: structs.h:17
int i
Definition: analysis.c:2
int makegrid
Definition: structs.h:15
#define JDIR
Definition: pluto.h:194
int restart
Definition: structs.h:12
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
#define DIMENSIONS
Definition: definitions_01.h:2
#define NO
Definition: pluto.h:26

Here is the call graph for this function:

Here is the caller graph for this function:

void PrintUsage ( )
static

Definition at line 204 of file cmd_line_opt.c.

209 {
210 
211  if (prank != 0) return;
212 
213  printf ("Usage: pluto [options]\n\n");
214  printf (" or \n\n");
215  printf (" mpirun -np NP ./pluto [options]\n\n");
216  printf ("[options] are:\n\n");
217  printf (" -dec n1 [n2] [n3]\n");
218  printf (" Enable user-defined parallel decomposition mode. The integers\n");
219  printf (" n1, n2 and n3 specify the number of processors along the x1,\n");
220  printf (" x2, and x3 directions. There must be as many integers as the\n");
221  printf (" number of dimensions and their product must equal the total\n");
222  printf (" number of processors used by mpirun or an error will occurr.\n\n");
223 
224  printf (" -i <name>\n");
225  printf (" Use <name> as initialization file instead of pluto.ini.\n\n");
226 
227  printf (" --help\n");
228  printf (" Show this option summary.\n\n");
229 
230  printf (" -h5restart n\n");
231  printf (" Restart computations from the n-th output file in HDF5\n");
232  printf (" double precision format (.dbl.h5).\n\n");
233 
234  printf (" -makegrid\n");
235  printf (" Generate grid only, do not start computations.\n\n");
236 
237  printf (" -maxsteps n\n");
238  printf (" Stop computations after n steps.\n\n");
239 
240  printf (" -no-write\n");
241  printf (" Do not write data to disk.\n\n");
242 
243  printf (" -no-x1par, -no-x2par, -no-x3par\n");
244  printf (" Do not perform parallel domain decomposition along the x1, x2\n");
245  printf (" or x3 direction, respectively.\n\n");
246 
247  printf (" -restart n\n");
248  printf (" Restart computations from the n-th output file in double in\n");
249  printf (" precision format (.dbl).\n\n");
250 
251  printf (" -show-dec\n");
252  printf (" Show domain decomposition when running in parallel mode.\n\n");
253 
254  printf (" -x1jet, -x2jet, -x3jet\n");
255  printf (" Exclude from integration regions of zero pressure gradient\n");
256  printf (" that extends up to the end of the domain in x1, x2 or x3\n");
257  printf (" direction, respectively. This option is specifically\n");
258  printf (" designed for jets propagating along one of the coordinate\n");
259  printf (" axis. In parallel mode, parallel decomposition is not\n");
260  printf (" performed along the selected direction.\n\n");
261 
262  printf (" -xres n1\n");
263  printf (" Set the grid resolution in the x1 direction to n1 zones\n");
264  printf (" by overriding pluto.ini. Cell aspect ratio is preserved by\n");
265  printf (" modifying the grid resolution in the other coordinate\n");
266  printf (" directions accordingly.\n");
267 
268 }
int prank
Processor rank.
Definition: globals.h:33

Here is the caller graph for this function: