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