xref: /petsc/src/sys/objects/aoptions.c (revision 289f3aa11b3ac459c99a6895ea3b9e0a0e6ded3a)
1 #define PETSC_DLL
2 /*
3    Implements the higher-level options database querying methods. These are self-documenting and can attach at runtime to
4    GUI code to display the options and get values from the users.
5 
6 */
7 
8 #include "petsc.h"        /*I  "petsc.h"   I*/
9 #include "petscsys.h"
10 #if defined(PETSC_HAVE_STDLIB_H)
11 #include <stdlib.h>
12 #endif
13 
14 /*
15     Keep a linked list of options that have been posted and we are waiting for
16    user selection. See the manual page for PetscOptionsBegin()
17 
18     Eventually we'll attach this beast to a MPI_Comm
19 */
20 PetscOptionsObjectType PetscOptionsObject;
21 PetscInt               PetscOptionsPublishCount = 0;
22 
23 #undef __FUNCT__
24 #define __FUNCT__ "PetscOptionsBegin_Private"
25 /*
26     Handles setting up the data structure in a call to PetscOptionsBegin()
27 */
28 PetscErrorCode PetscOptionsBegin_Private(MPI_Comm comm,const char prefix[],const char title[],const char mansec[])
29 {
30   PetscErrorCode ierr;
31 
32   PetscFunctionBegin;
33   PetscOptionsObject.next          = 0;
34   PetscOptionsObject.comm          = comm;
35   PetscOptionsObject.changedmethod = PETSC_FALSE;
36   if (PetscOptionsObject.prefix) {
37     ierr = PetscStrfree(PetscOptionsObject.prefix);CHKERRQ(ierr); PetscOptionsObject.prefix = 0;
38   }
39   ierr = PetscStrallocpy(prefix,&PetscOptionsObject.prefix);CHKERRQ(ierr);
40   if (PetscOptionsObject.title) {
41     ierr = PetscStrfree(PetscOptionsObject.title);CHKERRQ(ierr); PetscOptionsObject.title  = 0;
42   }
43   ierr = PetscStrallocpy(title,&PetscOptionsObject.title);CHKERRQ(ierr);
44 
45   ierr = PetscOptionsHasName(PETSC_NULL,"-help",&PetscOptionsObject.printhelp);CHKERRQ(ierr);
46   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
47     if (!PetscOptionsObject.alreadyprinted) {
48       ierr = (*PetscHelpPrintf)(comm,"%s -------------------------------------------------\n",title);CHKERRQ(ierr);
49     }
50   }
51   PetscFunctionReturn(0);
52 }
53 
54 /*
55      Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd()
56 */
57 #undef __FUNCT__
58 #define __FUNCT__ "PetscOptionsCreate_Private"
59 static int PetscOptionsCreate_Private(const char opt[],const char text[],const char man[],PetscOptionType t,PetscOptions *amsopt)
60 {
61   int          ierr;
62   PetscOptions next;
63 
64   PetscFunctionBegin;
65   ierr             = PetscNew(struct _p_PetscOptions,amsopt);CHKERRQ(ierr);
66   (*amsopt)->next  = 0;
67   (*amsopt)->set   = PETSC_FALSE;
68   (*amsopt)->type  = t;
69   (*amsopt)->data  = 0;
70 
71   ierr             = PetscStrallocpy(text,&(*amsopt)->text);CHKERRQ(ierr);
72   ierr             = PetscStrallocpy(opt,&(*amsopt)->option);CHKERRQ(ierr);
73   ierr             = PetscStrallocpy(man,&(*amsopt)->man);CHKERRQ(ierr);
74 
75   if (!PetscOptionsObject.next) {
76     PetscOptionsObject.next = *amsopt;
77   } else {
78     next = PetscOptionsObject.next;
79     while (next->next) next = next->next;
80     next->next = *amsopt;
81   }
82   PetscFunctionReturn(0);
83 }
84 
85 #undef __FUNCT__
86 #define __FUNCT__ "PetscScanString"
87 /*
88     PetscScanString -  Gets user input via stdin from process and broadcasts to all processes
89 
90     Collective on MPI_Comm
91 
92    Input Parameters:
93 +     commm - communicator for the broadcast, must be PETSC_COMM_WORLD
94 .     n - length of the string, must be the same on all processes
95 -     str - location to store input
96 
97     Bugs:
98 .   Assumes process 0 of the given communicator has access to stdin
99 
100 */
101 static PetscErrorCode PetscScanString(MPI_Comm comm,size_t n,char str[])
102 {
103   size_t         i;
104   char           c;
105   PetscMPIInt    rank,nm;
106   PetscErrorCode ierr;
107 
108   PetscFunctionBegin;
109   ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
110   if (!rank) {
111     c = (char) getchar();
112     i = 0;
113     while ( c != '\n' && i < n-1) {
114       str[i++] = c;
115       c = (char) getchar();
116     }
117     str[i] = 0;
118   }
119   nm   = PetscMPIIntCast(n);
120   ierr = MPI_Bcast(str,nm,MPI_CHAR,0,comm);CHKERRQ(ierr);
121   PetscFunctionReturn(0);
122 }
123 
124 #undef __FUNCT__
125 #define __FUNCT__ "PetscOptionsGetFromTextInput"
126 /*
127     PetscOptionsGetFromTextInput - Presents all the PETSc Options processed by the program so the user may change them at runtime
128 
129     Notes: this isn't really practical, it is just to demonstrate the principle
130 
131     Bugs:
132 +    All processes must traverse through the exact same set of option queries do to the call to PetscScanString()
133 .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
134 -    Only works for PetscInt == int, PetscReal == double etc
135 
136     Developer Notes: Normally the GUI that presents the options the user and retrieves the values would be running in a different
137      address space and communicating with the PETSc program
138 
139 */
140 PetscErrorCode PetscOptionsGetFromTextInput()
141 {
142   PetscErrorCode ierr;
143   PetscOptions   next = PetscOptionsObject.next;
144   char           str[512];
145   PetscInt       id;
146   PetscReal      ir,*valr;
147   PetscInt       *vald;
148   size_t         i;
149 
150   ierr = (*PetscPrintf)(PETSC_COMM_WORLD,"%s -------------------------------------------------\n",PetscOptionsObject.title);CHKERRQ(ierr);
151   while (next) {
152     switch (next->type) {
153       case OPTION_HEAD:
154         break;
155       case OPTION_INT_ARRAY:
156         ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1);CHKERRQ(ierr);
157         vald = (PetscInt*) next->data;
158         for (i=0; i<next->arraylength; i++) {
159           ierr = PetscPrintf(PETSC_COMM_WORLD,"%d",vald[i]);CHKERRQ(ierr);
160           if (i < next->arraylength-1) {
161             ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr);
162           }
163         }
164         ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s)",next->text,next->man);CHKERRQ(ierr);
165         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
166         if (str[0]) {
167           PetscToken token;
168           PetscInt   n=0,nmax = next->arraylength,*dvalue = (PetscInt*)next->data,start,end;
169           size_t     len;
170           char*      value;
171           PetscTruth foundrange;
172 
173           next->set = PETSC_TRUE;
174           value = str;
175 	  ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr);
176 	  ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
177 	  while (n < nmax) {
178 	    if (!value) break;
179 
180 	    /* look for form  d-D where d and D are integers */
181 	    foundrange = PETSC_FALSE;
182 	    ierr      = PetscStrlen(value,&len);CHKERRQ(ierr);
183 	    if (value[0] == '-') i=2;
184 	    else i=1;
185 	    for (;i<len; i++) {
186 	      if (value[i] == '-') {
187 		if (i == len-1) SETERRQ2(PETSC_ERR_USER,"Error in %D-th array entry %s\n",n,value);
188 		value[i] = 0;
189 		ierr     = PetscOptionsAtoi(value,&start);CHKERRQ(ierr);
190 		ierr     = PetscOptionsAtoi(value+i+1,&end);CHKERRQ(ierr);
191 		if (end <= start) SETERRQ3(PETSC_ERR_USER,"Error in %D-th array entry, %s-%s cannot have decreasing list",n,value,value+i+1);
192 		if (n + end - start - 1 >= nmax) SETERRQ4(PETSC_ERR_USER,"Error in %D-th array entry, not enough space in left in array (%D) to contain entire range from %D to %D",n,nmax-n,start,end);
193 		for (;start<end; start++) {
194 		  *dvalue = start; dvalue++;n++;
195 		}
196 		foundrange = PETSC_TRUE;
197 		break;
198 	      }
199 	    }
200 	    if (!foundrange) {
201 	      ierr      = PetscOptionsAtoi(value,dvalue);CHKERRQ(ierr);
202 	      dvalue++;
203 	      n++;
204 	    }
205 	    ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
206 	  }
207 	  ierr = PetscTokenDestroy(token);CHKERRQ(ierr);
208         }
209         break;
210       case OPTION_REAL_ARRAY:
211         ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1);CHKERRQ(ierr);
212         valr = (PetscReal*) next->data;
213         for (i=0; i<next->arraylength; i++) {
214           ierr = PetscPrintf(PETSC_COMM_WORLD,"%g",valr[i]);CHKERRQ(ierr);
215           if (i < next->arraylength-1) {
216             ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr);
217           }
218         }
219         ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s)",next->text,next->man);CHKERRQ(ierr);
220         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
221         if (str[0]) {
222           PetscToken token;
223           PetscInt   n=0,nmax = next->arraylength;
224           PetscReal   *dvalue = (PetscReal*)next->data;
225           char*      value;
226 
227           next->set = PETSC_TRUE;
228           value = str;
229 	  ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr);
230 	  ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
231 	  while (n < nmax) {
232 	    if (!value) break;
233             ierr      = PetscOptionsAtod(value,dvalue);CHKERRQ(ierr);
234 	    dvalue++;
235 	    n++;
236 	    ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
237 	  }
238 	  ierr = PetscTokenDestroy(token);CHKERRQ(ierr);
239         }
240         break;
241       case OPTION_INT:
242         ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <%d>: %s (%s)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1,*(int*)next->data,next->text,next->man);CHKERRQ(ierr);
243         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
244         if (str[0]) {
245           sscanf(str,"%d",&id);
246           next->set = PETSC_TRUE;
247           *((PetscInt*)next->data) = id;
248         }
249         break;
250       case OPTION_REAL:
251         ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <%g>: %s (%s)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1,*(double*)next->data,next->text,next->man);CHKERRQ(ierr);
252         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
253         if (str[0]) {
254 #if defined(PETSC_USE_SCALAR_SINGLE)
255           sscanf(str,"%e",&ir);
256 #else
257           sscanf(str,"%le",&ir);
258 #endif
259           next->set = PETSC_TRUE;
260           *((PetscReal*)next->data) = ir;
261         }
262         break;
263       case OPTION_LOGICAL:
264       case OPTION_STRING:
265         ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <%s>: %s (%s)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1,(char*)next->data,next->text,next->man);CHKERRQ(ierr);
266         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
267         if (str[0]) {
268           next->set = PETSC_TRUE;
269           ierr = PetscStrcpy((char*)next->data,str);CHKERRQ(ierr);
270         }
271         break;
272       case OPTION_LIST:
273         ierr = PetscFListPrintTypes(PETSC_COMM_WORLD,stdout,PetscOptionsObject.prefix,next->option,next->text,next->man,next->flist,(char*)next->data);CHKERRQ(ierr);
274         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
275         if (str[0]) {
276 	  PetscOptionsObject.changedmethod = PETSC_TRUE;
277           next->set = PETSC_TRUE;
278           ierr = PetscStrcpy((char*)next->data,str);CHKERRQ(ierr);
279         }
280         break;
281     default:
282       break;
283     }
284     next = next->next;
285   }
286   PetscFunctionReturn(0);
287 }
288 
289 #undef __FUNCT__
290 #define __FUNCT__ "PetscOptionsEnd_Private"
291 PetscErrorCode PetscOptionsEnd_Private(void)
292 {
293   PetscErrorCode ierr;
294   PetscOptions   last;
295   char           option[256],value[1024],tmp[32];
296   size_t         j;
297 
298   PetscFunctionBegin;
299 
300   if (PetscOptionsObject.next) {
301     if (PetscOptionsPublishCount == 0) {
302       ierr = PetscOptionsGetFromTextInput();
303     }
304   }
305 
306   ierr = PetscStrfree(PetscOptionsObject.title);CHKERRQ(ierr); PetscOptionsObject.title  = 0;
307   ierr = PetscStrfree(PetscOptionsObject.prefix);CHKERRQ(ierr); PetscOptionsObject.prefix = 0;
308 
309   /* reset counter to -2; this updates the screen with the new options for the selected method */
310   if (PetscOptionsObject.changedmethod) PetscOptionsPublishCount = -2;
311   /* reset alreadyprinted flag */
312   PetscOptionsObject.alreadyprinted = PETSC_FALSE;
313 
314   while (PetscOptionsObject.next) {
315     if (PetscOptionsObject.next->set) {
316       if (PetscOptionsObject.prefix) {
317         ierr = PetscStrcpy(option,"-");CHKERRQ(ierr);
318         ierr = PetscStrcat(option,PetscOptionsObject.prefix);CHKERRQ(ierr);
319         ierr = PetscStrcat(option,PetscOptionsObject.next->option+1);CHKERRQ(ierr);
320       } else {
321         ierr = PetscStrcpy(option,PetscOptionsObject.next->option);CHKERRQ(ierr);
322       }
323 
324       switch (PetscOptionsObject.next->type) {
325         case OPTION_HEAD:
326           break;
327         case OPTION_INT_ARRAY:
328           sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[0]);
329           for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
330             sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[j]);
331             ierr = PetscStrcat(value,",");CHKERRQ(ierr);
332             ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
333           }
334           break;
335         case OPTION_INT:
336           sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject.next->data);
337           break;
338         case OPTION_REAL:
339           sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject.next->data);
340           break;
341         case OPTION_REAL_ARRAY:
342           sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[0]);
343           for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
344             sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[j]);
345             ierr = PetscStrcat(value,",");CHKERRQ(ierr);
346             ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
347           }
348           break;
349         case OPTION_LOGICAL:
350           ierr = PetscStrcpy(value,(char*)PetscOptionsObject.next->data);CHKERRQ(ierr);
351           break;
352         case OPTION_LIST:
353           ierr = PetscStrcpy(value,(char*)PetscOptionsObject.next->data);CHKERRQ(ierr);
354           break;
355         case OPTION_STRING: /* also handles string arrays */
356           ierr = PetscStrcpy(value,(char*)PetscOptionsObject.next->data);CHKERRQ(ierr);
357           break;
358       }
359       ierr = PetscOptionsSetValue(option,value);CHKERRQ(ierr);
360     }
361     ierr   = PetscStrfree(PetscOptionsObject.next->text);CHKERRQ(ierr);
362     ierr   = PetscStrfree(PetscOptionsObject.next->option);CHKERRQ(ierr);
363     ierr   = PetscFree(PetscOptionsObject.next->man);CHKERRQ(ierr);
364     ierr   = PetscFree(PetscOptionsObject.next->data);CHKERRQ(ierr);
365     last                    = PetscOptionsObject.next;
366     PetscOptionsObject.next = PetscOptionsObject.next->next;
367     ierr                    = PetscFree(last);CHKERRQ(ierr);
368   }
369   PetscOptionsObject.next = 0;
370   PetscFunctionReturn(0);
371 }
372 
373 #undef __FUNCT__
374 #define __FUNCT__ "PetscOptionsEnum"
375 /*@C
376    PetscOptionsEnum - Gets the enum value for a particular option in the database.
377 
378    Collective on the communicator passed in PetscOptionsBegin()
379 
380    Input Parameters:
381 +  opt - option name
382 .  text - short string that describes the option
383 .  man - manual page with additional information on option
384 .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
385 -  defaultv - the default (current) value
386 
387    Output Parameter:
388 +  value - the  value to return
389 -  flg - PETSC_TRUE if found, else PETSC_FALSE
390 
391    Level: beginner
392 
393    Concepts: options database
394 
395    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
396 
397           list is usually something like PCASMTypes or some other predefined list of enum names
398 
399 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
400           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
401           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
402           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
403           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
404           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
405           PetscOptionsList(), PetscOptionsEList()
406 @*/
407 PetscErrorCode PETSC_DLLEXPORT PetscOptionsEnum(const char opt[],const char text[],const char man[],const char **list,PetscEnum defaultv,PetscEnum *value,PetscTruth *set)
408 {
409   PetscErrorCode ierr;
410   PetscInt       ntext = 0;
411   PetscInt       tval;
412   PetscTruth     tflg;
413 
414   PetscFunctionBegin;
415   while (list[ntext++]) {
416     if (ntext > 50) SETERRQ(PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries");
417   }
418   if (ntext < 3) SETERRQ(PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix");
419   ntext -= 3;
420   ierr = PetscOptionsEList(opt,text,man,list,ntext,list[defaultv],&tval,&tflg);CHKERRQ(ierr);
421   /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */
422   if (tflg) *value = (PetscEnum)tval;
423   if (set)  *set   = tflg;
424   PetscFunctionReturn(0);
425 }
426 
427 /* -------------------------------------------------------------------------------------------------------------*/
428 #undef __FUNCT__
429 #define __FUNCT__ "PetscOptionsInt"
430 /*@C
431    PetscOptionsInt - Gets the integer value for a particular option in the database.
432 
433    Collective on the communicator passed in PetscOptionsBegin()
434 
435    Input Parameters:
436 +  opt - option name
437 .  text - short string that describes the option
438 .  man - manual page with additional information on option
439 -  defaultv - the default (current) value
440 
441    Output Parameter:
442 +  value - the integer value to return
443 -  flg - PETSC_TRUE if found, else PETSC_FALSE
444 
445    Level: beginner
446 
447    Concepts: options database^has int
448 
449    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
450 
451 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
452           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
453           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
454           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
455           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
456           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
457           PetscOptionsList(), PetscOptionsEList()
458 @*/
459 PetscErrorCode PETSC_DLLEXPORT PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt defaultv,PetscInt *value,PetscTruth *set)
460 {
461   PetscErrorCode ierr;
462   PetscOptions   amsopt;
463 
464   PetscFunctionBegin;
465   if (PetscOptionsPublishCount == 0) {
466     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr);
467     ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
468     *(PetscInt*)amsopt->data = defaultv;
469   }
470   ierr = PetscOptionsGetInt(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
471   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
472     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr);
473   }
474   PetscFunctionReturn(0);
475 }
476 
477 #undef __FUNCT__
478 #define __FUNCT__ "PetscOptionsString"
479 /*@C
480    PetscOptionsString - Gets the string value for a particular option in the database.
481 
482    Collective on the communicator passed in PetscOptionsBegin()
483 
484    Input Parameters:
485 +  opt - option name
486 .  text - short string that describes the option
487 .  man - manual page with additional information on option
488 -  defaultv - the default (current) value
489 
490    Output Parameter:
491 +  value - the value to return
492 -  flg - PETSC_TRUE if found, else PETSC_FALSE
493 
494    Level: beginner
495 
496    Concepts: options database^has int
497 
498    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
499 
500 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
501           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
502           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
503           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
504           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
505           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
506           PetscOptionsList(), PetscOptionsEList()
507 @*/
508 PetscErrorCode PETSC_DLLEXPORT PetscOptionsString(const char opt[],const char text[],const char man[],const char defaultv[],char value[],size_t len,PetscTruth *set)
509 {
510   PetscErrorCode ierr;
511   PetscOptions   amsopt;
512 
513   PetscFunctionBegin;
514   if (PetscOptionsPublishCount == 0) {
515     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
516     ierr = PetscMalloc(len*sizeof(char),&amsopt->data);CHKERRQ(ierr);
517     ierr = PetscStrcpy((char*)amsopt->data,defaultv);CHKERRQ(ierr);
518   }
519   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
520   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
521     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr);
522   }
523   PetscFunctionReturn(0);
524 }
525 
526 #undef __FUNCT__
527 #define __FUNCT__ "PetscOptionsReal"
528 /*@C
529    PetscOptionsReal - Gets the PetscReal value for a particular option in the database.
530 
531    Collective on the communicator passed in PetscOptionsBegin()
532 
533    Input Parameters:
534 +  opt - option name
535 .  text - short string that describes the option
536 .  man - manual page with additional information on option
537 -  defaultv - the default (current) value
538 
539    Output Parameter:
540 +  value - the value to return
541 -  flg - PETSC_TRUE if found, else PETSC_FALSE
542 
543    Level: beginner
544 
545    Concepts: options database^has int
546 
547    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
548 
549 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
550           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
551           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
552           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
553           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
554           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
555           PetscOptionsList(), PetscOptionsEList()
556 @*/
557 PetscErrorCode PETSC_DLLEXPORT PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal defaultv,PetscReal *value,PetscTruth *set)
558 {
559   PetscErrorCode ierr;
560   PetscOptions   amsopt;
561 
562   PetscFunctionBegin;
563   if (PetscOptionsPublishCount == 0) {
564     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr);
565     ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
566     *(PetscReal*)amsopt->data = defaultv;
567   }
568   ierr = PetscOptionsGetReal(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
569   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
570     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%G>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr);
571   }
572   PetscFunctionReturn(0);
573 }
574 
575 #undef __FUNCT__
576 #define __FUNCT__ "PetscOptionsScalar"
577 /*@C
578    PetscOptionsScalar - Gets the scalar value for a particular option in the database.
579 
580    Collective on the communicator passed in PetscOptionsBegin()
581 
582    Input Parameters:
583 +  opt - option name
584 .  text - short string that describes the option
585 .  man - manual page with additional information on option
586 -  defaultv - the default (current) value
587 
588    Output Parameter:
589 +  value - the value to return
590 -  flg - PETSC_TRUE if found, else PETSC_FALSE
591 
592    Level: beginner
593 
594    Concepts: options database^has int
595 
596    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
597 
598 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
599           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
600           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
601           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
602           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
603           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
604           PetscOptionsList(), PetscOptionsEList()
605 @*/
606 PetscErrorCode PETSC_DLLEXPORT PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar defaultv,PetscScalar *value,PetscTruth *set)
607 {
608   PetscErrorCode ierr;
609 
610   PetscFunctionBegin;
611 #if !defined(PETSC_USE_COMPLEX)
612   ierr = PetscOptionsReal(opt,text,man,defaultv,value,set);CHKERRQ(ierr);
613 #else
614   ierr = PetscOptionsGetScalar(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
615 #endif
616   PetscFunctionReturn(0);
617 }
618 
619 #undef __FUNCT__
620 #define __FUNCT__ "PetscOptionsName"
621 /*@C
622    PetscOptionsName - Determines if a particular option has been set in the database. This returns true whether the option is a number, string or boolean, even
623                       its value is set to false.
624 
625    Collective on the communicator passed in PetscOptionsBegin()
626 
627    Input Parameters:
628 +  opt - option name
629 .  text - short string that describes the option
630 -  man - manual page with additional information on option
631 
632    Output Parameter:
633 .  flg - PETSC_TRUE if found, else PETSC_FALSE
634 
635    Level: beginner
636 
637    Concepts: options database^has int
638 
639    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
640 
641 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
642           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
643           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
644           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
645           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
646           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
647           PetscOptionsList(), PetscOptionsEList()
648 @*/
649 PetscErrorCode PETSC_DLLEXPORT PetscOptionsName(const char opt[],const char text[],const char man[],PetscTruth *flg)
650 {
651   PetscErrorCode ierr;
652 
653   PetscFunctionBegin;
654   ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr);
655   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
656     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
657   }
658   PetscFunctionReturn(0);
659 }
660 
661 #undef __FUNCT__
662 #define __FUNCT__ "PetscOptionsList"
663 /*@C
664      PetscOptionsList - Puts a list of option values that a single one may be selected from
665 
666    Collective on the communicator passed in PetscOptionsBegin()
667 
668    Input Parameters:
669 +  opt - option name
670 .  text - short string that describes the option
671 .  man - manual page with additional information on option
672 .  list - the possible choices
673 .  defaultv - the default (current) value
674 -  len - the length of the character array value
675 
676    Output Parameter:
677 +  value - the value to return
678 -  set - PETSC_TRUE if found, else PETSC_FALSE
679 
680    Level: intermediate
681 
682    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
683 
684    See PetscOptionsEList() for when the choices are given in a string array
685 
686    To get a listing of all currently specified options,
687     see PetscOptionsPrint() or PetscOptionsGetAll()
688 
689    Concepts: options database^list
690 
691 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
692            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
693           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
694           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
695           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
696           PetscOptionsList(), PetscOptionsEList()
697 @*/
698 PetscErrorCode PETSC_DLLEXPORT PetscOptionsList(const char opt[],const char ltext[],const char man[],PetscFList list,const char defaultv[],char value[],size_t len,PetscTruth *set)
699 {
700   PetscErrorCode ierr;
701   PetscOptions   amsopt;
702 
703   PetscFunctionBegin;
704   if (PetscOptionsPublishCount == 0) {
705     ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_LIST,&amsopt);CHKERRQ(ierr);
706     ierr = PetscMalloc(1024*sizeof(char),&amsopt->data);CHKERRQ(ierr);
707     ierr = PetscStrcpy((char*)amsopt->data,defaultv);CHKERRQ(ierr);
708     amsopt->flist = list;
709   }
710   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
711   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
712     ierr = PetscFListPrintTypes(PetscOptionsObject.comm,stdout,PetscOptionsObject.prefix,opt,ltext,man,list,defaultv);CHKERRQ(ierr);CHKERRQ(ierr);
713   }
714   PetscFunctionReturn(0);
715 }
716 
717 #undef __FUNCT__
718 #define __FUNCT__ "PetscOptionsEList"
719 /*@C
720      PetscOptionsEList - Puts a list of option values that a single one may be selected from
721 
722    Collective on the communicator passed in PetscOptionsBegin()
723 
724    Input Parameters:
725 +  opt - option name
726 .  ltext - short string that describes the option
727 .  man - manual page with additional information on option
728 .  list - the possible choices
729 .  ntext - number of choices
730 -  defaultv - the default (current) value
731 
732    Output Parameter:
733 +  value - the index of the value to return
734 -  set - PETSC_TRUE if found, else PETSC_FALSE
735 
736    Level: intermediate
737 
738    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
739 
740    See PetscOptionsList() for when the choices are given in a PetscFList()
741 
742    Concepts: options database^list
743 
744 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
745            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
746           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
747           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
748           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
749           PetscOptionsList(), PetscOptionsEList()
750 @*/
751 PetscErrorCode PETSC_DLLEXPORT PetscOptionsEList(const char opt[],const char ltext[],const char man[],const char **list,PetscInt ntext,const char defaultv[],PetscInt *value,PetscTruth *set)
752 {
753   PetscErrorCode ierr;
754   PetscInt       i;
755 
756   PetscFunctionBegin;
757   ierr = PetscOptionsGetEList(PetscOptionsObject.prefix,opt,list,ntext,value,set);CHKERRQ(ierr);
758   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
759     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s> (choose one of)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv);CHKERRQ(ierr);
760     for (i=0; i<ntext; i++){
761       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s",list[i]);CHKERRQ(ierr);
762     }
763     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"\n");CHKERRQ(ierr);
764   }
765   PetscFunctionReturn(0);
766 }
767 
768 #undef __FUNCT__
769 #define __FUNCT__ "PetscOptionsTruthGroupBegin"
770 /*@C
771      PetscOptionsTruthGroupBegin - First in a series of logical queries on the options database for
772        which only a single value can be true.
773 
774    Collective on the communicator passed in PetscOptionsBegin()
775 
776    Input Parameters:
777 +  opt - option name
778 .  text - short string that describes the option
779 -  man - manual page with additional information on option
780 
781    Output Parameter:
782 .  flg - whether that option was set or not
783 
784    Level: intermediate
785 
786    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
787 
788    Must be followed by 0 or more PetscOptionsTruthGroup()s and PetscOptionsTruthGroupEnd()
789 
790     Concepts: options database^logical group
791 
792 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
793            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
794           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
795           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
796           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
797           PetscOptionsList(), PetscOptionsEList()
798 @*/
799 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroupBegin(const char opt[],const char text[],const char man[],PetscTruth *flg)
800 {
801   PetscErrorCode ierr;
802 
803   PetscFunctionBegin;
804   *flg = PETSC_FALSE;
805   ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr);
806   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
807     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  Pick at most one of -------------\n");CHKERRQ(ierr);
808     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
809   }
810   PetscFunctionReturn(0);
811 }
812 
813 #undef __FUNCT__
814 #define __FUNCT__ "PetscOptionsTruthGroup"
815 /*@C
816      PetscOptionsTruthGroup - One in a series of logical queries on the options database for
817        which only a single value can be true.
818 
819    Collective on the communicator passed in PetscOptionsBegin()
820 
821    Input Parameters:
822 +  opt - option name
823 .  text - short string that describes the option
824 -  man - manual page with additional information on option
825 
826    Output Parameter:
827 .  flg - PETSC_TRUE if found, else PETSC_FALSE
828 
829    Level: intermediate
830 
831    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
832 
833    Must follow a PetscOptionsTruthGroupBegin() and preceded a PetscOptionsTruthGroupEnd()
834 
835     Concepts: options database^logical group
836 
837 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
838            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
839           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
840           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
841           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
842           PetscOptionsList(), PetscOptionsEList()
843 @*/
844 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroup(const char opt[],const char text[],const char man[],PetscTruth *flg)
845 {
846   PetscErrorCode ierr;
847 
848   PetscFunctionBegin;
849   *flg = PETSC_FALSE;
850   ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr);
851   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
852     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
853   }
854   PetscFunctionReturn(0);
855 }
856 
857 #undef __FUNCT__
858 #define __FUNCT__ "PetscOptionsTruthGroupEnd"
859 /*@C
860      PetscOptionsTruthGroupEnd - Last in a series of logical queries on the options database for
861        which only a single value can be true.
862 
863    Collective on the communicator passed in PetscOptionsBegin()
864 
865    Input Parameters:
866 +  opt - option name
867 .  text - short string that describes the option
868 -  man - manual page with additional information on option
869 
870    Output Parameter:
871 .  flg - PETSC_TRUE if found, else PETSC_FALSE
872 
873    Level: intermediate
874 
875    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
876 
877    Must follow a PetscOptionsTruthGroupBegin()
878 
879     Concepts: options database^logical group
880 
881 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
882            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
883           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
884           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
885           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
886           PetscOptionsList(), PetscOptionsEList()
887 @*/
888 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroupEnd(const char opt[],const char text[],const char man[],PetscTruth *flg)
889 {
890   PetscErrorCode ierr;
891 
892   PetscFunctionBegin;
893   *flg = PETSC_FALSE;
894   ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr);
895   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
896     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
897   }
898   PetscFunctionReturn(0);
899 }
900 
901 #undef __FUNCT__
902 #define __FUNCT__ "PetscOptionsTruth"
903 /*@C
904    PetscOptionsTruth - Determines if a particular option is in the database with a true or false
905 
906    Collective on the communicator passed in PetscOptionsBegin()
907 
908    Input Parameters:
909 +  opt - option name
910 .  text - short string that describes the option
911 -  man - manual page with additional information on option
912 
913    Output Parameter:
914 .  flg - PETSC_TRUE or PETSC_FALSE
915 .  set - PETSC_TRUE if found, else PETSC_FALSE
916 
917    Level: beginner
918 
919    Concepts: options database^logical
920 
921    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
922 
923 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
924           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
925           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
926           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
927           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
928           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
929           PetscOptionsList(), PetscOptionsEList()
930 @*/
931 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruth(const char opt[],const char text[],const char man[],PetscTruth deflt,PetscTruth *flg,PetscTruth *set)
932 {
933   PetscErrorCode ierr;
934   PetscTruth     iset;
935   PetscOptions   amsopt;
936 
937   PetscFunctionBegin;
938   if (PetscOptionsPublishCount == 0) {
939     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
940     ierr = PetscMalloc(16*sizeof(char),&amsopt->data);CHKERRQ(ierr);
941     ierr = PetscStrcpy((char*)amsopt->data,deflt ? "true" : "false");CHKERRQ(ierr);
942   }
943   ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,&iset);CHKERRQ(ierr);
944   if (!iset) {
945     if (flg) *flg = deflt;
946   }
947   if (set) *set = iset;
948   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
949     const char *v = PetscTruths[deflt];
950     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: <%s> %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,v,text,man);CHKERRQ(ierr);
951   }
952   PetscFunctionReturn(0);
953 }
954 
955 #undef __FUNCT__
956 #define __FUNCT__ "PetscOptionsRealArray"
957 /*@C
958    PetscOptionsRealArray - Gets an array of double values for a particular
959    option in the database. The values must be separated with commas with
960    no intervening spaces.
961 
962    Collective on the communicator passed in PetscOptionsBegin()
963 
964    Input Parameters:
965 +  opt - the option one is seeking
966 .  text - short string describing option
967 .  man - manual page for option
968 -  nmax - maximum number of values
969 
970    Output Parameter:
971 +  value - location to copy values
972 .  nmax - actual number of values found
973 -  set - PETSC_TRUE if found, else PETSC_FALSE
974 
975    Level: beginner
976 
977    Notes:
978    The user should pass in an array of doubles
979 
980    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
981 
982    Concepts: options database^array of strings
983 
984 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
985            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
986           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
987           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
988           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
989           PetscOptionsList(), PetscOptionsEList()
990 @*/
991 PetscErrorCode PETSC_DLLEXPORT PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscTruth *set)
992 {
993   PetscErrorCode ierr;
994   PetscInt       i;
995   PetscOptions   amsopt;
996 
997   PetscFunctionBegin;
998   if (PetscOptionsPublishCount == 0) {
999     PetscReal *vals;
1000 
1001     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr);
1002     ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
1003     vals = (PetscReal*)amsopt->data;
1004     for (i=0; i<*n; i++) vals[i] = value[i];
1005     amsopt->arraylength = *n;
1006   }
1007   ierr = PetscOptionsGetRealArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1008   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1009     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%G",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
1010     for (i=1; i<*n; i++) {
1011       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%G",value[i]);CHKERRQ(ierr);
1012     }
1013     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr);
1014   }
1015   PetscFunctionReturn(0);
1016 }
1017 
1018 
1019 #undef __FUNCT__
1020 #define __FUNCT__ "PetscOptionsIntArray"
1021 /*@C
1022    PetscOptionsIntArray - Gets an array of integers for a particular
1023    option in the database. The values must be separated with commas with
1024    no intervening spaces.
1025 
1026    Collective on the communicator passed in PetscOptionsBegin()
1027 
1028    Input Parameters:
1029 +  opt - the option one is seeking
1030 .  text - short string describing option
1031 .  man - manual page for option
1032 -  n - maximum number of values
1033 
1034    Output Parameter:
1035 +  value - location to copy values
1036 .  n - actual number of values found
1037 -  set - PETSC_TRUE if found, else PETSC_FALSE
1038 
1039    Level: beginner
1040 
1041    Notes:
1042    The user should pass in an array of integers
1043 
1044    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1045 
1046    Concepts: options database^array of strings
1047 
1048 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1049            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
1050           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1051           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1052           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
1053           PetscOptionsList(), PetscOptionsEList(), PetscOptionsRealArray()
1054 @*/
1055 PetscErrorCode PETSC_DLLEXPORT PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscTruth *set)
1056 {
1057   PetscErrorCode ierr;
1058   PetscInt       i;
1059   PetscOptions   amsopt;
1060 
1061   PetscFunctionBegin;
1062   if (PetscOptionsPublishCount == 0) {
1063     PetscInt *vals;
1064 
1065     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr);
1066     ierr = PetscMalloc((*n)*sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
1067     vals = (PetscInt*)amsopt->data;
1068     for (i=0; i<*n; i++) vals[i] = value[i];
1069     amsopt->arraylength = *n;
1070   }
1071   ierr = PetscOptionsGetIntArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1072   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1073     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
1074     for (i=1; i<*n; i++) {
1075       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr);
1076     }
1077     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr);
1078   }
1079   PetscFunctionReturn(0);
1080 }
1081 
1082 #undef __FUNCT__
1083 #define __FUNCT__ "PetscOptionsStringArray"
1084 /*@C
1085    PetscOptionsStringArray - Gets an array of string values for a particular
1086    option in the database. The values must be separated with commas with
1087    no intervening spaces.
1088 
1089    Collective on the communicator passed in PetscOptionsBegin()
1090 
1091    Input Parameters:
1092 +  opt - the option one is seeking
1093 .  text - short string describing option
1094 .  man - manual page for option
1095 -  nmax - maximum number of strings
1096 
1097    Output Parameter:
1098 +  value - location to copy strings
1099 .  nmax - actual number of strings found
1100 -  set - PETSC_TRUE if found, else PETSC_FALSE
1101 
1102    Level: beginner
1103 
1104    Notes:
1105    The user should pass in an array of pointers to char, to hold all the
1106    strings returned by this function.
1107 
1108    The user is responsible for deallocating the strings that are
1109    returned. The Fortran interface for this routine is not supported.
1110 
1111    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1112 
1113    Concepts: options database^array of strings
1114 
1115 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1116            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
1117           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1118           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1119           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
1120           PetscOptionsList(), PetscOptionsEList()
1121 @*/
1122 PetscErrorCode PETSC_DLLEXPORT PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscTruth *set)
1123 {
1124   PetscErrorCode ierr;
1125 
1126   PetscFunctionBegin;
1127   ierr = PetscOptionsGetStringArray(PetscOptionsObject.prefix,opt,value,nmax,set);CHKERRQ(ierr);
1128   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1129     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
1130   }
1131   PetscFunctionReturn(0);
1132 }
1133 
1134 #undef __FUNCT__
1135 #define __FUNCT__ "PetscOptionsTruthArray"
1136 /*@C
1137    PetscOptionsTruthArray - Gets an array of logical values (true or false) for a particular
1138    option in the database. The values must be separated with commas with
1139    no intervening spaces.
1140 
1141    Collective on the communicator passed in PetscOptionsBegin()
1142 
1143    Input Parameters:
1144 +  opt - the option one is seeking
1145 .  text - short string describing option
1146 .  man - manual page for option
1147 -  nmax - maximum number of values
1148 
1149    Output Parameter:
1150 +  value - location to copy values
1151 .  nmax - actual number of values found
1152 -  set - PETSC_TRUE if found, else PETSC_FALSE
1153 
1154    Level: beginner
1155 
1156    Notes:
1157    The user should pass in an array of doubles
1158 
1159    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1160 
1161    Concepts: options database^array of strings
1162 
1163 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1164            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
1165           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1166           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1167           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
1168           PetscOptionsList(), PetscOptionsEList()
1169 @*/
1170 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthArray(const char opt[],const char text[],const char man[],PetscTruth value[],PetscInt *n,PetscTruth *set)
1171 {
1172   PetscErrorCode ierr;
1173   PetscInt       i;
1174 
1175   PetscFunctionBegin;
1176   ierr = PetscOptionsGetTruthArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1177   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1178     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
1179     for (i=1; i<*n; i++) {
1180       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr);
1181     }
1182     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr);
1183   }
1184   PetscFunctionReturn(0);
1185 }
1186 
1187 
1188 #undef __FUNCT__
1189 #define __FUNCT__ "PetscOptionsHead"
1190 /*@C
1191      PetscOptionsHead - Puts a heading before listing any more published options. Used, for example,
1192             in KSPSetFromOptions_GMRES().
1193 
1194    Collective on the communicator passed in PetscOptionsBegin()
1195 
1196    Input Parameter:
1197 .   head - the heading text
1198 
1199 
1200    Level: intermediate
1201 
1202    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1203 
1204           Can be followed by a call to PetscOptionsTail() in the same function.
1205 
1206    Concepts: options database^subheading
1207 
1208 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1209            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
1210           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1211           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1212           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
1213           PetscOptionsList(), PetscOptionsEList()
1214 @*/
1215 PetscErrorCode PETSC_DLLEXPORT PetscOptionsHead(const char head[])
1216 {
1217   PetscErrorCode ierr;
1218 
1219   PetscFunctionBegin;
1220   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1221     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  %s\n",head);CHKERRQ(ierr);
1222   }
1223   PetscFunctionReturn(0);
1224 }
1225 
1226 
1227 
1228 
1229 
1230 
1231