xref: /petsc/src/sys/objects/aoptions.c (revision 37bef68685c1f05064f72c911cffeeaba9b107d9)
1 
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-private/petscimpl.h>        /*I  "petscsys.h"   I*/
9 #include <petscviewer.h>
10 
11 #define ManSection(str) ((str) ? (str) : "None")
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 
36   ierr = PetscFree(PetscOptionsObject.prefix);CHKERRQ(ierr);
37   ierr = PetscStrallocpy(prefix,&PetscOptionsObject.prefix);CHKERRQ(ierr);
38   ierr = PetscFree(PetscOptionsObject.title);CHKERRQ(ierr);
39   ierr = PetscStrallocpy(title,&PetscOptionsObject.title);CHKERRQ(ierr);
40 
41   ierr = PetscOptionsHasName(NULL,"-help",&PetscOptionsObject.printhelp);CHKERRQ(ierr);
42   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
43     if (!PetscOptionsObject.alreadyprinted) {
44       ierr = (*PetscHelpPrintf)(comm,"%s -------------------------------------------------\n",title);CHKERRQ(ierr);
45     }
46   }
47   PetscFunctionReturn(0);
48 }
49 
50 #undef __FUNCT__
51 #define __FUNCT__ "PetscObjectOptionsBegin_Private"
52 /*
53     Handles setting up the data structure in a call to PetscObjectOptionsBegin()
54 */
55 PetscErrorCode PetscObjectOptionsBegin_Private(PetscObject obj)
56 {
57   PetscErrorCode ierr;
58   char           title[256];
59   PetscBool      flg;
60 
61   PetscFunctionBegin;
62   PetscValidHeader(obj,1);
63   PetscOptionsObject.object         = obj;
64   PetscOptionsObject.alreadyprinted = obj->optionsprinted;
65 
66   ierr = PetscStrcmp(obj->description,obj->class_name,&flg);CHKERRQ(ierr);
67   if (flg) {
68     ierr = PetscSNPrintf(title,sizeof(title),"%s options",obj->class_name);CHKERRQ(ierr);
69   } else {
70     ierr = PetscSNPrintf(title,sizeof(title),"%s (%s) options",obj->description,obj->class_name);CHKERRQ(ierr);
71   }
72   ierr = PetscOptionsBegin_Private(obj->comm,obj->prefix,title,obj->mansec);CHKERRQ(ierr);
73   PetscFunctionReturn(0);
74 }
75 
76 /*
77      Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd()
78 */
79 #undef __FUNCT__
80 #define __FUNCT__ "PetscOptionsCreate_Private"
81 static int PetscOptionsCreate_Private(const char opt[],const char text[],const char man[],PetscOptionType t,PetscOptions *amsopt)
82 {
83   int          ierr;
84   PetscOptions next;
85   PetscBool    valid;
86 
87   PetscFunctionBegin;
88   ierr = PetscOptionsValidKey(opt,&valid);CHKERRQ(ierr);
89   if (!valid) SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_ARG_INCOMP,"The option '%s' is not a valid key",opt);
90 
91   ierr            = PetscNew(struct _n_PetscOptions,amsopt);CHKERRQ(ierr);
92   (*amsopt)->next = 0;
93   (*amsopt)->set  = PETSC_FALSE;
94   (*amsopt)->type = t;
95   (*amsopt)->data = 0;
96 
97   ierr = PetscStrallocpy(text,&(*amsopt)->text);CHKERRQ(ierr);
98   ierr = PetscStrallocpy(opt,&(*amsopt)->option);CHKERRQ(ierr);
99   ierr = PetscStrallocpy(man,&(*amsopt)->man);CHKERRQ(ierr);
100 
101   if (!PetscOptionsObject.next) PetscOptionsObject.next = *amsopt;
102   else {
103     next = PetscOptionsObject.next;
104     while (next->next) next = next->next;
105     next->next = *amsopt;
106   }
107   PetscFunctionReturn(0);
108 }
109 
110 #undef __FUNCT__
111 #define __FUNCT__ "PetscScanString"
112 /*
113     PetscScanString -  Gets user input via stdin from process and broadcasts to all processes
114 
115     Collective on MPI_Comm
116 
117    Input Parameters:
118 +     commm - communicator for the broadcast, must be PETSC_COMM_WORLD
119 .     n - length of the string, must be the same on all processes
120 -     str - location to store input
121 
122     Bugs:
123 .   Assumes process 0 of the given communicator has access to stdin
124 
125 */
126 static PetscErrorCode PetscScanString(MPI_Comm comm,size_t n,char str[])
127 {
128   size_t         i;
129   char           c;
130   PetscMPIInt    rank,nm;
131   PetscErrorCode ierr;
132 
133   PetscFunctionBegin;
134   ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
135   if (!rank) {
136     c = (char) getchar();
137     i = 0;
138     while (c != '\n' && i < n-1) {
139       str[i++] = c;
140       c = (char)getchar();
141     }
142     str[i] = 0;
143   }
144   ierr = PetscMPIIntCast(n,&nm);CHKERRQ(ierr);
145   ierr = MPI_Bcast(str,nm,MPI_CHAR,0,comm);CHKERRQ(ierr);
146   PetscFunctionReturn(0);
147 }
148 
149 #undef __FUNCT__
150 #define __FUNCT__ "PetscOptionsGetFromTextInput"
151 /*
152     PetscOptionsGetFromTextInput - Presents all the PETSc Options processed by the program so the user may change them at runtime
153 
154     Notes: this isn't really practical, it is just to demonstrate the principle
155 
156     Bugs:
157 +    All processes must traverse through the exact same set of option queries do to the call to PetscScanString()
158 .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
159 -    Only works for PetscInt == int, PetscReal == double etc
160 
161     Developer Notes: Normally the GUI that presents the options the user and retrieves the values would be running in a different
162      address space and communicating with the PETSc program
163 
164 */
165 PetscErrorCode PetscOptionsGetFromTextInput()
166 {
167   PetscErrorCode ierr;
168   PetscOptions   next = PetscOptionsObject.next;
169   char           str[512];
170   PetscInt       id;
171   PetscReal      ir,*valr;
172   PetscInt       *vald;
173   size_t         i;
174 
175   ierr = (*PetscPrintf)(PETSC_COMM_WORLD,"%s -------------------------------------------------\n",PetscOptionsObject.title);CHKERRQ(ierr);
176   while (next) {
177     switch (next->type) {
178     case OPTION_HEAD:
179       break;
180     case OPTION_INT_ARRAY:
181       ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",next->option+1);CHKERRQ(ierr);
182       vald = (PetscInt*) next->data;
183       for (i=0; i<next->arraylength; i++) {
184         ierr = PetscPrintf(PETSC_COMM_WORLD,"%d",vald[i]);CHKERRQ(ierr);
185         if (i < next->arraylength-1) {
186           ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr);
187         }
188       }
189       ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s)",next->text,next->man);CHKERRQ(ierr);
190       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
191       if (str[0]) {
192         PetscToken token;
193         PetscInt   n=0,nmax = next->arraylength,*dvalue = (PetscInt*)next->data,start,end;
194         size_t     len;
195         char       *value;
196         PetscBool  foundrange;
197 
198         next->set = PETSC_TRUE;
199         value     = str;
200         ierr      = PetscTokenCreate(value,',',&token);CHKERRQ(ierr);
201         ierr      = PetscTokenFind(token,&value);CHKERRQ(ierr);
202         while (n < nmax) {
203           if (!value) break;
204 
205           /* look for form  d-D where d and D are integers */
206           foundrange = PETSC_FALSE;
207           ierr       = PetscStrlen(value,&len);CHKERRQ(ierr);
208           if (value[0] == '-') i=2;
209           else i=1;
210           for (;i<len; i++) {
211             if (value[i] == '-') {
212               if (i == len-1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry %s\n",n,value);
213               value[i] = 0;
214               ierr     = PetscOptionsStringToInt(value,&start);CHKERRQ(ierr);
215               ierr     = PetscOptionsStringToInt(value+i+1,&end);CHKERRQ(ierr);
216               if (end <= start) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry, %s-%s cannot have decreasing list",n,value,value+i+1);
217               if (n + end - start - 1 >= nmax) SETERRQ4(PETSC_COMM_SELF,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);
218               for (; start<end; start++) {
219                 *dvalue = start; dvalue++;n++;
220               }
221               foundrange = PETSC_TRUE;
222               break;
223             }
224           }
225           if (!foundrange) {
226             ierr = PetscOptionsStringToInt(value,dvalue);CHKERRQ(ierr);
227             dvalue++;
228             n++;
229           }
230           ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
231         }
232         ierr = PetscTokenDestroy(&token);CHKERRQ(ierr);
233       }
234       break;
235     case OPTION_REAL_ARRAY:
236       ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",next->option+1);CHKERRQ(ierr);
237       valr = (PetscReal*) next->data;
238       for (i=0; i<next->arraylength; i++) {
239         ierr = PetscPrintf(PETSC_COMM_WORLD,"%g",valr[i]);CHKERRQ(ierr);
240         if (i < next->arraylength-1) {
241           ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr);
242         }
243       }
244       ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s)",next->text,next->man);CHKERRQ(ierr);
245       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
246       if (str[0]) {
247         PetscToken token;
248         PetscInt   n = 0,nmax = next->arraylength;
249         PetscReal  *dvalue = (PetscReal*)next->data;
250         char       *value;
251 
252         next->set = PETSC_TRUE;
253         value     = str;
254         ierr      = PetscTokenCreate(value,',',&token);CHKERRQ(ierr);
255         ierr      = PetscTokenFind(token,&value);CHKERRQ(ierr);
256         while (n < nmax) {
257           if (!value) break;
258           ierr = PetscOptionsStringToReal(value,dvalue);CHKERRQ(ierr);
259           dvalue++;
260           n++;
261           ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
262         }
263         ierr = PetscTokenDestroy(&token);CHKERRQ(ierr);
264       }
265       break;
266     case OPTION_INT:
267       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);
268       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
269       if (str[0]) {
270 #if defined(PETSC_USE_64BIT_INDICES)
271         sscanf(str,"%lld",&id);
272 #else
273         sscanf(str,"%d",&id);
274 #endif
275         next->set = PETSC_TRUE;
276 
277         *((PetscInt*)next->data) = id;
278       }
279       break;
280     case OPTION_REAL:
281       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);
282       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
283       if (str[0]) {
284 #if defined(PETSC_USE_REAL_SINGLE)
285         sscanf(str,"%e",&ir);
286 #elif defined(PETSC_USE_REAL_DOUBLE)
287         sscanf(str,"%le",&ir);
288 #elif defined(PETSC_USE_REAL___FLOAT128)
289         ir = strtoflt128(str,0);
290 #else
291         SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Unknown scalar type");
292 #endif
293         next->set                 = PETSC_TRUE;
294         *((PetscReal*)next->data) = ir;
295       }
296       break;
297     case OPTION_LOGICAL:
298     case OPTION_STRING:
299       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);
300       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
301       if (str[0]) {
302         next->set = PETSC_TRUE;
303 
304         ierr = PetscStrcpy((char*)next->data,str);CHKERRQ(ierr);
305       }
306       break;
307     case OPTION_LIST:
308       ierr = PetscFunctionListPrintTypes(PETSC_COMM_WORLD,stdout,PetscOptionsObject.prefix,next->option,next->text,next->man,next->flist,(char*)next->data);CHKERRQ(ierr);
309       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
310       if (str[0]) {
311         PetscOptionsObject.changedmethod = PETSC_TRUE;
312         next->set = PETSC_TRUE;
313         ierr = PetscStrcpy((char*)next->data,str);CHKERRQ(ierr);
314       }
315       break;
316     default:
317       break;
318     }
319     next = next->next;
320   }
321   PetscFunctionReturn(0);
322 }
323 
324 #if defined(PETSC_HAVE_SAWS)
325 #include <petscviewersaws.h>
326 
327 static int count = 0;
328 
329 #undef __FUNCT__
330 #define __FUNCT__ "PetscOptionsSAWsDestroy"
331 PetscErrorCode PetscOptionsSAWsDestroy(void)
332 {
333   SAWs_Directory amem  = NULL;
334   char           options[16];
335   const char     *string = "Exit";
336 
337   /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */
338   sprintf(options,"Options_%d",count++);
339   PetscStackCallSAWs(SAWs_Add_Directory,(PETSC_SAWs_ROOT_DIRECTORY,options,&amem));
340   PetscStackCallSAWs(SAWs_Add_Variable,(amem,"Exit",&string,1,SAWs_READ,SAWs_STRING));
341 
342   PetscStackCallSAWs(SAWs_Lock_Directory,(amem));
343   PetscStackCallSAWs(SAWs_Unlock_Directory,(amem));
344   /* wait until accessor has unlocked the memory */
345   PetscStackCallSAWs(SAWs_Destroy_Directory,(&amem));
346   PetscFunctionReturn(0);
347 }
348 
349 #undef __FUNCT__
350 #define __FUNCT__ "PetscOptionsAMSInput"
351 /*
352     PetscOptionsAMSInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the AMS
353 
354     Bugs:
355 +    All processes must traverse through the exact same set of option queries do to the call to PetscScanString()
356 .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
357 -    Only works for PetscInt == int, PetscReal == double etc
358 
359 
360 */
361 PetscErrorCode PetscOptionsAMSInput()
362 {
363   PetscErrorCode ierr;
364   PetscOptions   next     = PetscOptionsObject.next;
365   static int     mancount = 0;
366   char           options[16];
367   SAWs_Directory amem = NULL;
368   PetscBool      changedmethod = PETSC_FALSE;
369   char           manname[16];
370 
371   /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */
372   sprintf(options,"Options_%d",count++);
373   PetscStackCallSAWs(SAWs_Add_Directory,(PETSC_SAWs_ROOT_DIRECTORY,options,&amem));
374 
375   PetscOptionsObject.pprefix = PetscOptionsObject.prefix; /* SAWs will change this, so cannot pass prefix directly */
376 
377   PetscStackCallSAWs(SAWs_Add_Variable,(amem,PetscOptionsObject.title,&PetscOptionsObject.pprefix,1,SAWs_READ,SAWs_STRING));
378   PetscStackCallSAWs(SAWs_Add_Variable,(amem,"ChangedMethod",&changedmethod,1,SAWs_WRITE,SAWs_BOOLEAN));
379 
380   while (next) {
381     PetscStackCallSAWs(SAWs_Add_Variable,(amem,next->option,&next->set,1,SAWs_WRITE,SAWs_INT));
382     ierr =  PetscMalloc(sizeof(char*),&next->pman);CHKERRQ(ierr);
383 
384     *(char**)next->pman = next->man;
385     sprintf(manname,"man_%d",mancount++);
386     PetscStackCallSAWs(SAWs_Add_Variable,(amem,manname,next->pman,1,SAWs_READ,SAWs_STRING));
387 
388     switch (next->type) {
389     case OPTION_HEAD:
390       break;
391     case OPTION_INT_ARRAY:
392       PetscStackCallSAWs(SAWs_Add_Variable,(amem,next->text,next->data,next->arraylength,SAWs_WRITE,SAWs_INT));
393       break;
394     case OPTION_REAL_ARRAY:
395       PetscStackCallSAWs(SAWs_Add_Variable,(amem,next->text,next->data,next->arraylength,SAWs_WRITE,SAWs_DOUBLE));
396       break;
397     case OPTION_INT:
398       PetscStackCallSAWs(SAWs_Add_Variable,(amem,next->text,next->data,1,SAWs_WRITE,SAWs_INT));
399       break;
400     case OPTION_REAL:
401       PetscStackCallSAWs(SAWs_Add_Variable,(amem,next->text,next->data,1,SAWs_WRITE,SAWs_DOUBLE));
402       break;
403     case OPTION_LOGICAL:
404       PetscStackCallSAWs(SAWs_Add_Variable,(amem,next->text,next->data,1,SAWs_WRITE,SAWs_BOOLEAN));
405       break;
406     case OPTION_LOGICAL_ARRAY:
407       PetscStackCallSAWs(SAWs_Add_Variable,(amem,next->text,next->data,next->arraylength,SAWs_WRITE,SAWs_BOOLEAN));
408       break;
409     case OPTION_STRING:
410       PetscStackCallSAWs(SAWs_Add_Variable,(amem,next->text,next->data,1,SAWs_WRITE,SAWs_STRING));
411       break;
412     case OPTION_STRING_ARRAY:
413       PetscStackCallSAWs(SAWs_Add_Variable,(amem,next->text,next->data,next->arraylength,SAWs_WRITE,SAWs_STRING));
414       break;
415     case OPTION_LIST:
416       {PetscInt ntext;
417       char      ldefault[128];
418       ierr = PetscStrcpy(ldefault,"DEFAULT:");CHKERRQ(ierr);
419       ierr = PetscStrcat(ldefault,next->text);CHKERRQ(ierr);
420       PetscStackCallSAWs(SAWs_Add_Variable,(amem,ldefault,next->data,1,SAWs_WRITE,SAWs_STRING));
421       ierr = PetscFunctionListGet(next->flist,(const char***)&next->edata,&ntext);CHKERRQ(ierr);
422       PetscStackCallSAWs(SAWs_Add_Variable,(amem,next->text,next->edata,ntext-1,SAWs_WRITE,SAWs_STRING));
423       break;}
424     case OPTION_ELIST:
425       {PetscInt ntext = next->nlist;
426       char      ldefault[128];
427       ierr = PetscStrcpy(ldefault,"DEFAULT:");CHKERRQ(ierr);
428       ierr = PetscStrcat(ldefault,next->text);CHKERRQ(ierr);
429       PetscStackCallSAWs(SAWs_Add_Variable,(amem,ldefault,next->data,1,SAWs_WRITE,SAWs_STRING));
430       ierr = PetscMalloc((ntext+1)*sizeof(char**),&next->edata);CHKERRQ(ierr);
431       ierr = PetscMemcpy(next->edata,next->list,ntext*sizeof(char*));CHKERRQ(ierr);
432       PetscStackCallSAWs(SAWs_Add_Variable,(amem,next->text,next->edata,ntext,SAWs_WRITE,SAWs_STRING));
433       break;}
434     default:
435       break;
436     }
437     next = next->next;
438   }
439 
440   /* wait until accessor has unlocked the memory */
441   PetscStackCallSAWs(SAWs_Lock_Directory,(amem));
442 
443   /* reset counter to -2; this updates the screen with the new options for the selected method */
444   if (changedmethod) PetscOptionsPublishCount = -2;
445 
446   PetscStackCallSAWs(SAWs_Unlock_Directory,(amem));
447   PetscStackCallSAWs(SAWs_Destroy_Directory,(&amem));
448   PetscFunctionReturn(0);
449 }
450 #endif
451 
452 #undef __FUNCT__
453 #define __FUNCT__ "PetscOptionsEnd_Private"
454 PetscErrorCode PetscOptionsEnd_Private(void)
455 {
456   PetscErrorCode ierr;
457   PetscOptions   last;
458   char           option[256],value[1024],tmp[32];
459   size_t         j;
460 
461   PetscFunctionBegin;
462   if (PetscOptionsObject.next) {
463     if (!PetscOptionsPublishCount) {
464 #if defined(PETSC_HAVE_SAWS)
465       ierr = PetscOptionsAMSInput();CHKERRQ(ierr);
466 #else
467       ierr = PetscOptionsGetFromTextInput();CHKERRQ(ierr);
468 #endif
469     }
470   }
471 
472   ierr = PetscFree(PetscOptionsObject.title);CHKERRQ(ierr);
473   ierr = PetscFree(PetscOptionsObject.prefix);CHKERRQ(ierr);
474 
475   /* reset counter to -2; this updates the screen with the new options for the selected method */
476   if (PetscOptionsObject.changedmethod) PetscOptionsPublishCount = -2;
477   /* reset alreadyprinted flag */
478   PetscOptionsObject.alreadyprinted = PETSC_FALSE;
479   if (PetscOptionsObject.object) PetscOptionsObject.object->optionsprinted = PETSC_TRUE;
480   PetscOptionsObject.object = NULL;
481 
482   while (PetscOptionsObject.next) {
483     if (PetscOptionsObject.next->set) {
484       if (PetscOptionsObject.prefix) {
485         ierr = PetscStrcpy(option,"-");CHKERRQ(ierr);
486         ierr = PetscStrcat(option,PetscOptionsObject.prefix);CHKERRQ(ierr);
487         ierr = PetscStrcat(option,PetscOptionsObject.next->option+1);CHKERRQ(ierr);
488       } else {
489         ierr = PetscStrcpy(option,PetscOptionsObject.next->option);CHKERRQ(ierr);
490       }
491 
492       switch (PetscOptionsObject.next->type) {
493       case OPTION_HEAD:
494         break;
495       case OPTION_INT_ARRAY:
496         sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[0]);
497         for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
498           sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[j]);
499           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
500           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
501         }
502         break;
503       case OPTION_INT:
504         sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject.next->data);
505         break;
506       case OPTION_REAL:
507         sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject.next->data);
508         break;
509       case OPTION_REAL_ARRAY:
510         sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[0]);
511         for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
512           sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[j]);
513           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
514           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
515         }
516         break;
517       case OPTION_LOGICAL:
518         sprintf(value,"%d",*(int*)PetscOptionsObject.next->data);
519         break;
520       case OPTION_LOGICAL_ARRAY:
521         sprintf(value,"%d",(int)((PetscBool*)PetscOptionsObject.next->data)[0]);
522         for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
523           sprintf(tmp,"%d",(int)((PetscBool*)PetscOptionsObject.next->data)[j]);
524           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
525           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
526         }
527         break;
528       case OPTION_LIST:
529       case OPTION_ELIST:
530         ierr = PetscStrcpy(value,*(char**)PetscOptionsObject.next->data);CHKERRQ(ierr);
531         break;
532       case OPTION_STRING:
533         ierr = PetscStrcpy(value,*(char**)PetscOptionsObject.next->data);CHKERRQ(ierr);
534       case OPTION_STRING_ARRAY:
535         sprintf(value,"%s",((char**)PetscOptionsObject.next->data)[0]);
536         for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
537           sprintf(tmp,"%s",((char**)PetscOptionsObject.next->data)[j]);
538           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
539           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
540         }
541         break;
542       }
543       ierr = PetscOptionsSetValue(option,value);CHKERRQ(ierr);
544     }
545     ierr   = PetscFree(PetscOptionsObject.next->text);CHKERRQ(ierr);
546     ierr   = PetscFree(PetscOptionsObject.next->option);CHKERRQ(ierr);
547     ierr   = PetscFree(PetscOptionsObject.next->man);CHKERRQ(ierr);
548     ierr   = PetscFree(PetscOptionsObject.next->data);CHKERRQ(ierr);
549     ierr   = PetscFree(PetscOptionsObject.next->edata);CHKERRQ(ierr);
550 
551     last                    = PetscOptionsObject.next;
552     PetscOptionsObject.next = PetscOptionsObject.next->next;
553     ierr                    = PetscFree(last);CHKERRQ(ierr);
554   }
555   PetscOptionsObject.next = 0;
556   PetscFunctionReturn(0);
557 }
558 
559 #undef __FUNCT__
560 #define __FUNCT__ "PetscOptionsEnum"
561 /*@C
562    PetscOptionsEnum - Gets the enum value for a particular option in the database.
563 
564    Logically Collective on the communicator passed in PetscOptionsBegin()
565 
566    Input Parameters:
567 +  opt - option name
568 .  text - short string that describes the option
569 .  man - manual page with additional information on option
570 .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
571 -  defaultv - the default (current) value
572 
573    Output Parameter:
574 +  value - the  value to return
575 -  set - PETSC_TRUE if found, else PETSC_FALSE
576 
577    Level: beginner
578 
579    Concepts: options database
580 
581    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
582 
583           list is usually something like PCASMTypes or some other predefined list of enum names
584 
585 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
586           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
587           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
588           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
589           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
590           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
591           PetscOptionsList(), PetscOptionsEList()
592 @*/
593 PetscErrorCode  PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum defaultv,PetscEnum *value,PetscBool  *set)
594 {
595   PetscErrorCode ierr;
596   PetscInt       ntext = 0;
597   PetscInt       tval;
598   PetscBool      tflg;
599 
600   PetscFunctionBegin;
601   while (list[ntext++]) {
602     if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries");
603   }
604   if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix");
605   ntext -= 3;
606   ierr   = PetscOptionsEList(opt,text,man,list,ntext,list[defaultv],&tval,&tflg);CHKERRQ(ierr);
607   /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */
608   if (tflg) *value = (PetscEnum)tval;
609   if (set)  *set   = tflg;
610   PetscFunctionReturn(0);
611 }
612 
613 /* -------------------------------------------------------------------------------------------------------------*/
614 #undef __FUNCT__
615 #define __FUNCT__ "PetscOptionsInt"
616 /*@C
617    PetscOptionsInt - Gets the integer value for a particular option in the database.
618 
619    Logically Collective on the communicator passed in PetscOptionsBegin()
620 
621    Input Parameters:
622 +  opt - option name
623 .  text - short string that describes the option
624 .  man - manual page with additional information on option
625 -  defaultv - the default (current) value
626 
627    Output Parameter:
628 +  value - the integer value to return
629 -  flg - PETSC_TRUE if found, else PETSC_FALSE
630 
631    Level: beginner
632 
633    Concepts: options database^has int
634 
635    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
636 
637 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
638           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
639           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
640           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
641           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
642           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
643           PetscOptionsList(), PetscOptionsEList()
644 @*/
645 PetscErrorCode  PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt defaultv,PetscInt *value,PetscBool  *set)
646 {
647   PetscErrorCode ierr;
648   PetscOptions   amsopt;
649 
650   PetscFunctionBegin;
651   if (!PetscOptionsPublishCount) {
652     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr);
653     ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
654 
655     *(PetscInt*)amsopt->data = defaultv;
656   }
657   ierr = PetscOptionsGetInt(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
658   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
659     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr);
660   }
661   PetscFunctionReturn(0);
662 }
663 
664 #undef __FUNCT__
665 #define __FUNCT__ "PetscOptionsString"
666 /*@C
667    PetscOptionsString - Gets the string value for a particular option in the database.
668 
669    Logically 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 .  defaultv - the default (current) value
676 -  len - length of the result string including null terminator
677 
678    Output Parameter:
679 +  value - the value to return
680 -  flg - PETSC_TRUE if found, else PETSC_FALSE
681 
682    Level: beginner
683 
684    Concepts: options database^has int
685 
686    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
687 
688    Even if the user provided no string (for example -optionname -someotheroption) the flag is set to PETSC_TRUE (and the string is fulled with nulls).
689 
690 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
691           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
692           PetscOptionsInt(), PetscOptionsReal(), PetscOptionsBool(),
693           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
694           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
695           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
696           PetscOptionsList(), PetscOptionsEList()
697 @*/
698 PetscErrorCode  PetscOptionsString(const char opt[],const char text[],const char man[],const char defaultv[],char value[],size_t len,PetscBool  *set)
699 {
700   PetscErrorCode ierr;
701   PetscOptions   amsopt;
702 
703   PetscFunctionBegin;
704   if (!PetscOptionsPublishCount) {
705     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
706     ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr);
707 
708     *(const char**)amsopt->data = defaultv;
709   }
710   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
711   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
712     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr);
713   }
714   PetscFunctionReturn(0);
715 }
716 
717 #undef __FUNCT__
718 #define __FUNCT__ "PetscOptionsReal"
719 /*@C
720    PetscOptionsReal - Gets the PetscReal value for a particular option in the database.
721 
722    Logically Collective on the communicator passed in PetscOptionsBegin()
723 
724    Input Parameters:
725 +  opt - option name
726 .  text - short string that describes the option
727 .  man - manual page with additional information on option
728 -  defaultv - the default (current) value
729 
730    Output Parameter:
731 +  value - the value to return
732 -  flg - PETSC_TRUE if found, else PETSC_FALSE
733 
734    Level: beginner
735 
736    Concepts: options database^has int
737 
738    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
739 
740 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
741           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
742           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
743           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
744           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
745           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
746           PetscOptionsList(), PetscOptionsEList()
747 @*/
748 PetscErrorCode  PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal defaultv,PetscReal *value,PetscBool  *set)
749 {
750   PetscErrorCode ierr;
751   PetscOptions   amsopt;
752 
753   PetscFunctionBegin;
754   if (!PetscOptionsPublishCount) {
755     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr);
756     ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
757 
758     *(PetscReal*)amsopt->data = defaultv;
759   }
760   ierr = PetscOptionsGetReal(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
761   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
762     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%G>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr);
763   }
764   PetscFunctionReturn(0);
765 }
766 
767 #undef __FUNCT__
768 #define __FUNCT__ "PetscOptionsScalar"
769 /*@C
770    PetscOptionsScalar - Gets the scalar value for a particular option in the database.
771 
772    Logically Collective on the communicator passed in PetscOptionsBegin()
773 
774    Input Parameters:
775 +  opt - option name
776 .  text - short string that describes the option
777 .  man - manual page with additional information on option
778 -  defaultv - the default (current) value
779 
780    Output Parameter:
781 +  value - the value to return
782 -  flg - PETSC_TRUE if found, else PETSC_FALSE
783 
784    Level: beginner
785 
786    Concepts: options database^has int
787 
788    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
789 
790 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
791           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
792           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
793           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
794           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
795           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
796           PetscOptionsList(), PetscOptionsEList()
797 @*/
798 PetscErrorCode  PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar defaultv,PetscScalar *value,PetscBool  *set)
799 {
800   PetscErrorCode ierr;
801 
802   PetscFunctionBegin;
803 #if !defined(PETSC_USE_COMPLEX)
804   ierr = PetscOptionsReal(opt,text,man,defaultv,value,set);CHKERRQ(ierr);
805 #else
806   ierr = PetscOptionsGetScalar(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
807 #endif
808   PetscFunctionReturn(0);
809 }
810 
811 #undef __FUNCT__
812 #define __FUNCT__ "PetscOptionsName"
813 /*@C
814    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
815                       its value is set to false.
816 
817    Logically Collective on the communicator passed in PetscOptionsBegin()
818 
819    Input Parameters:
820 +  opt - option name
821 .  text - short string that describes the option
822 -  man - manual page with additional information on option
823 
824    Output Parameter:
825 .  flg - PETSC_TRUE if found, else PETSC_FALSE
826 
827    Level: beginner
828 
829    Concepts: options database^has int
830 
831    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
832 
833 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
834           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
835           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
836           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
837           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
838           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
839           PetscOptionsList(), PetscOptionsEList()
840 @*/
841 PetscErrorCode  PetscOptionsName(const char opt[],const char text[],const char man[],PetscBool  *flg)
842 {
843   PetscErrorCode ierr;
844   PetscOptions   amsopt;
845 
846   PetscFunctionBegin;
847   if (!PetscOptionsPublishCount) {
848     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
849     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
850 
851     *(PetscBool*)amsopt->data = PETSC_FALSE;
852   }
853   ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);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,ManSection(man));CHKERRQ(ierr);
856   }
857   PetscFunctionReturn(0);
858 }
859 
860 #undef __FUNCT__
861 #define __FUNCT__ "PetscOptionsList"
862 /*@C
863      PetscOptionsList - Puts a list of option values that a single one may be selected from
864 
865    Logically Collective on the communicator passed in PetscOptionsBegin()
866 
867    Input Parameters:
868 +  opt - option name
869 .  text - short string that describes the option
870 .  man - manual page with additional information on option
871 .  list - the possible choices
872 .  defaultv - the default (current) value
873 -  len - the length of the character array value
874 
875    Output Parameter:
876 +  value - the value to return
877 -  set - PETSC_TRUE if found, else PETSC_FALSE
878 
879    Level: intermediate
880 
881    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
882 
883    See PetscOptionsEList() for when the choices are given in a string array
884 
885    To get a listing of all currently specified options,
886     see PetscOptionsView() or PetscOptionsGetAll()
887 
888    Concepts: options database^list
889 
890 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
891            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
892           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
893           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
894           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
895           PetscOptionsList(), PetscOptionsEList(), PetscOptionsEnum()
896 @*/
897 PetscErrorCode  PetscOptionsList(const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char defaultv[],char value[],size_t len,PetscBool  *set)
898 {
899   PetscErrorCode ierr;
900   PetscOptions   amsopt;
901 
902   PetscFunctionBegin;
903   if (!PetscOptionsPublishCount) {
904     ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_LIST,&amsopt);CHKERRQ(ierr);
905     ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr);
906 
907     *(const char**)amsopt->data = defaultv;
908 
909     amsopt->flist = list;
910   }
911   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
912   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
913     ierr = PetscFunctionListPrintTypes(PetscOptionsObject.comm,stdout,PetscOptionsObject.prefix,opt,ltext,man,list,defaultv);CHKERRQ(ierr);CHKERRQ(ierr);
914   }
915   PetscFunctionReturn(0);
916 }
917 
918 #undef __FUNCT__
919 #define __FUNCT__ "PetscOptionsEList"
920 /*@C
921      PetscOptionsEList - Puts a list of option values that a single one may be selected from
922 
923    Logically Collective on the communicator passed in PetscOptionsBegin()
924 
925    Input Parameters:
926 +  opt - option name
927 .  ltext - short string that describes the option
928 .  man - manual page with additional information on option
929 .  list - the possible choices
930 .  ntext - number of choices
931 -  defaultv - the default (current) value
932 
933    Output Parameter:
934 +  value - the index of the value to return
935 -  set - PETSC_TRUE if found, else PETSC_FALSE
936 
937    Level: intermediate
938 
939    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
940 
941    See PetscOptionsList() for when the choices are given in a PetscFunctionList()
942 
943    Concepts: options database^list
944 
945 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
946            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
947           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
948           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
949           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
950           PetscOptionsList(), PetscOptionsEnum()
951 @*/
952 PetscErrorCode  PetscOptionsEList(const char opt[],const char ltext[],const char man[],const char *const *list,PetscInt ntext,const char defaultv[],PetscInt *value,PetscBool  *set)
953 {
954   PetscErrorCode ierr;
955   PetscInt       i;
956   PetscOptions   amsopt;
957 
958   PetscFunctionBegin;
959   if (!PetscOptionsPublishCount) {
960     ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_ELIST,&amsopt);CHKERRQ(ierr);
961     ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr);
962 
963     *(const char**)amsopt->data = defaultv;
964 
965     amsopt->list  = list;
966     amsopt->nlist = ntext;
967   }
968   ierr = PetscOptionsGetEList(PetscOptionsObject.prefix,opt,list,ntext,value,set);CHKERRQ(ierr);
969   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
970     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s> (choose one of)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv);CHKERRQ(ierr);
971     for (i=0; i<ntext; i++) {
972       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s",list[i]);CHKERRQ(ierr);
973     }
974     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," (%s)\n",ManSection(man));CHKERRQ(ierr);
975   }
976   PetscFunctionReturn(0);
977 }
978 
979 #undef __FUNCT__
980 #define __FUNCT__ "PetscOptionsBoolGroupBegin"
981 /*@C
982      PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for
983        which at most a single value can be true.
984 
985    Logically Collective on the communicator passed in PetscOptionsBegin()
986 
987    Input Parameters:
988 +  opt - option name
989 .  text - short string that describes the option
990 -  man - manual page with additional information on option
991 
992    Output Parameter:
993 .  flg - whether that option was set or not
994 
995    Level: intermediate
996 
997    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
998 
999    Must be followed by 0 or more PetscOptionsBoolGroup()s and PetscOptionsBoolGroupEnd()
1000 
1001     Concepts: options database^logical group
1002 
1003 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1004            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1005           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1006           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1007           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1008           PetscOptionsList(), PetscOptionsEList()
1009 @*/
1010 PetscErrorCode  PetscOptionsBoolGroupBegin(const char opt[],const char text[],const char man[],PetscBool  *flg)
1011 {
1012   PetscErrorCode ierr;
1013   PetscOptions   amsopt;
1014 
1015   PetscFunctionBegin;
1016   if (!PetscOptionsPublishCount) {
1017     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
1018     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1019 
1020     *(PetscBool*)amsopt->data = PETSC_FALSE;
1021   }
1022   *flg = PETSC_FALSE;
1023   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,NULL);CHKERRQ(ierr);
1024   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1025     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  Pick at most one of -------------\n");CHKERRQ(ierr);
1026     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
1027   }
1028   PetscFunctionReturn(0);
1029 }
1030 
1031 #undef __FUNCT__
1032 #define __FUNCT__ "PetscOptionsBoolGroup"
1033 /*@C
1034      PetscOptionsBoolGroup - One in a series of logical queries on the options database for
1035        which at most a single value can be true.
1036 
1037    Logically Collective on the communicator passed in PetscOptionsBegin()
1038 
1039    Input Parameters:
1040 +  opt - option name
1041 .  text - short string that describes the option
1042 -  man - manual page with additional information on option
1043 
1044    Output Parameter:
1045 .  flg - PETSC_TRUE if found, else PETSC_FALSE
1046 
1047    Level: intermediate
1048 
1049    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1050 
1051    Must follow a PetscOptionsBoolGroupBegin() and preceded a PetscOptionsBoolGroupEnd()
1052 
1053     Concepts: options database^logical group
1054 
1055 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1056            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1057           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1058           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1059           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1060           PetscOptionsList(), PetscOptionsEList()
1061 @*/
1062 PetscErrorCode  PetscOptionsBoolGroup(const char opt[],const char text[],const char man[],PetscBool  *flg)
1063 {
1064   PetscErrorCode ierr;
1065   PetscOptions   amsopt;
1066 
1067   PetscFunctionBegin;
1068   if (!PetscOptionsPublishCount) {
1069     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
1070     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1071 
1072     *(PetscBool*)amsopt->data = PETSC_FALSE;
1073   }
1074   *flg = PETSC_FALSE;
1075   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,NULL);CHKERRQ(ierr);
1076   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1077     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
1078   }
1079   PetscFunctionReturn(0);
1080 }
1081 
1082 #undef __FUNCT__
1083 #define __FUNCT__ "PetscOptionsBoolGroupEnd"
1084 /*@C
1085      PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for
1086        which at most a single value can be true.
1087 
1088    Logically Collective on the communicator passed in PetscOptionsBegin()
1089 
1090    Input Parameters:
1091 +  opt - option name
1092 .  text - short string that describes the option
1093 -  man - manual page with additional information on option
1094 
1095    Output Parameter:
1096 .  flg - PETSC_TRUE if found, else PETSC_FALSE
1097 
1098    Level: intermediate
1099 
1100    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1101 
1102    Must follow a PetscOptionsBoolGroupBegin()
1103 
1104     Concepts: options database^logical group
1105 
1106 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1107            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1108           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1109           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1110           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1111           PetscOptionsList(), PetscOptionsEList()
1112 @*/
1113 PetscErrorCode  PetscOptionsBoolGroupEnd(const char opt[],const char text[],const char man[],PetscBool  *flg)
1114 {
1115   PetscErrorCode ierr;
1116   PetscOptions   amsopt;
1117 
1118   PetscFunctionBegin;
1119   if (!PetscOptionsPublishCount) {
1120     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
1121     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1122 
1123     *(PetscBool*)amsopt->data = PETSC_FALSE;
1124   }
1125   *flg = PETSC_FALSE;
1126   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,NULL);CHKERRQ(ierr);
1127   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1128     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
1129   }
1130   PetscFunctionReturn(0);
1131 }
1132 
1133 #undef __FUNCT__
1134 #define __FUNCT__ "PetscOptionsBool"
1135 /*@C
1136    PetscOptionsBool - Determines if a particular option is in the database with a true or false
1137 
1138    Logically Collective on the communicator passed in PetscOptionsBegin()
1139 
1140    Input Parameters:
1141 +  opt - option name
1142 .  text - short string that describes the option
1143 -  man - manual page with additional information on option
1144 
1145    Output Parameter:
1146 .  flg - PETSC_TRUE or PETSC_FALSE
1147 .  set - PETSC_TRUE if found, else PETSC_FALSE
1148 
1149    Level: beginner
1150 
1151    Concepts: options database^logical
1152 
1153    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1154 
1155 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1156           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
1157           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
1158           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1159           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1160           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1161           PetscOptionsList(), PetscOptionsEList()
1162 @*/
1163 PetscErrorCode  PetscOptionsBool(const char opt[],const char text[],const char man[],PetscBool deflt,PetscBool  *flg,PetscBool  *set)
1164 {
1165   PetscErrorCode ierr;
1166   PetscBool      iset;
1167   PetscOptions   amsopt;
1168 
1169   PetscFunctionBegin;
1170   if (!PetscOptionsPublishCount) {
1171     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
1172     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1173 
1174     *(PetscBool*)amsopt->data = deflt;
1175   }
1176   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,&iset);CHKERRQ(ierr);
1177   if (!iset) {
1178     if (flg) *flg = deflt;
1179   }
1180   if (set) *set = iset;
1181   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1182     const char *v = PetscBools[deflt];
1183     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: <%s> %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,v,text,ManSection(man));CHKERRQ(ierr);
1184   }
1185   PetscFunctionReturn(0);
1186 }
1187 
1188 #undef __FUNCT__
1189 #define __FUNCT__ "PetscOptionsRealArray"
1190 /*@C
1191    PetscOptionsRealArray - Gets an array of double values for a particular
1192    option in the database. The values must be separated with commas with
1193    no intervening spaces.
1194 
1195    Logically Collective on the communicator passed in PetscOptionsBegin()
1196 
1197    Input Parameters:
1198 +  opt - the option one is seeking
1199 .  text - short string describing option
1200 .  man - manual page for option
1201 -  nmax - maximum number of values
1202 
1203    Output Parameter:
1204 +  value - location to copy values
1205 .  nmax - actual number of values found
1206 -  set - PETSC_TRUE if found, else PETSC_FALSE
1207 
1208    Level: beginner
1209 
1210    Notes:
1211    The user should pass in an array of doubles
1212 
1213    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1214 
1215    Concepts: options database^array of strings
1216 
1217 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1218            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1219           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1220           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1221           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1222           PetscOptionsList(), PetscOptionsEList()
1223 @*/
1224 PetscErrorCode  PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool  *set)
1225 {
1226   PetscErrorCode ierr;
1227   PetscInt       i;
1228   PetscOptions   amsopt;
1229 
1230   PetscFunctionBegin;
1231   if (!PetscOptionsPublishCount) {
1232     PetscReal *vals;
1233 
1234     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr);
1235     ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
1236     vals = (PetscReal*)amsopt->data;
1237     for (i=0; i<*n; i++) vals[i] = value[i];
1238     amsopt->arraylength = *n;
1239   }
1240   ierr = PetscOptionsGetRealArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1241   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1242     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%G",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
1243     for (i=1; i<*n; i++) {
1244       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%G",value[i]);CHKERRQ(ierr);
1245     }
1246     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1247   }
1248   PetscFunctionReturn(0);
1249 }
1250 
1251 
1252 #undef __FUNCT__
1253 #define __FUNCT__ "PetscOptionsIntArray"
1254 /*@C
1255    PetscOptionsIntArray - Gets an array of integers for a particular
1256    option in the database.
1257 
1258    Logically Collective on the communicator passed in PetscOptionsBegin()
1259 
1260    Input Parameters:
1261 +  opt - the option one is seeking
1262 .  text - short string describing option
1263 .  man - manual page for option
1264 -  n - maximum number of values
1265 
1266    Output Parameter:
1267 +  value - location to copy values
1268 .  n - actual number of values found
1269 -  set - PETSC_TRUE if found, else PETSC_FALSE
1270 
1271    Level: beginner
1272 
1273    Notes:
1274    The array can be passed as
1275    a comma seperated list:                                 0,1,2,3,4,5,6,7
1276    a range (start-end+1):                                  0-8
1277    a range with given increment (start-end+1:inc):         0-7:2
1278    a combination of values and ranges seperated by commas: 0,1-8,8-15:2
1279 
1280    There must be no intervening spaces between the values.
1281 
1282    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1283 
1284    Concepts: options database^array of ints
1285 
1286 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1287            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1288           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1289           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1290           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1291           PetscOptionsList(), PetscOptionsEList(), PetscOptionsRealArray()
1292 @*/
1293 PetscErrorCode  PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool  *set)
1294 {
1295   PetscErrorCode ierr;
1296   PetscInt       i;
1297   PetscOptions   amsopt;
1298 
1299   PetscFunctionBegin;
1300   if (!PetscOptionsPublishCount) {
1301     PetscInt *vals;
1302 
1303     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr);
1304     ierr = PetscMalloc((*n)*sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
1305     vals = (PetscInt*)amsopt->data;
1306     for (i=0; i<*n; i++) vals[i] = value[i];
1307     amsopt->arraylength = *n;
1308   }
1309   ierr = PetscOptionsGetIntArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1310   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1311     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,value[0]);CHKERRQ(ierr);
1312     for (i=1; i<*n; i++) {
1313       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr);
1314     }
1315     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1316   }
1317   PetscFunctionReturn(0);
1318 }
1319 
1320 #undef __FUNCT__
1321 #define __FUNCT__ "PetscOptionsStringArray"
1322 /*@C
1323    PetscOptionsStringArray - Gets an array of string values for a particular
1324    option in the database. The values must be separated with commas with
1325    no intervening spaces.
1326 
1327    Logically Collective on the communicator passed in PetscOptionsBegin()
1328 
1329    Input Parameters:
1330 +  opt - the option one is seeking
1331 .  text - short string describing option
1332 .  man - manual page for option
1333 -  nmax - maximum number of strings
1334 
1335    Output Parameter:
1336 +  value - location to copy strings
1337 .  nmax - actual number of strings found
1338 -  set - PETSC_TRUE if found, else PETSC_FALSE
1339 
1340    Level: beginner
1341 
1342    Notes:
1343    The user should pass in an array of pointers to char, to hold all the
1344    strings returned by this function.
1345 
1346    The user is responsible for deallocating the strings that are
1347    returned. The Fortran interface for this routine is not supported.
1348 
1349    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1350 
1351    Concepts: options database^array of strings
1352 
1353 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1354            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1355           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1356           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1357           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1358           PetscOptionsList(), PetscOptionsEList()
1359 @*/
1360 PetscErrorCode  PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool  *set)
1361 {
1362   PetscErrorCode ierr;
1363   PetscOptions   amsopt;
1364 
1365   PetscFunctionBegin;
1366   if (!PetscOptionsPublishCount) {
1367     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING_ARRAY,&amsopt);CHKERRQ(ierr);
1368     ierr = PetscMalloc((*nmax)*sizeof(char*),&amsopt->data);CHKERRQ(ierr);
1369 
1370     amsopt->arraylength = *nmax;
1371   }
1372   ierr = PetscOptionsGetStringArray(PetscOptionsObject.prefix,opt,value,nmax,set);CHKERRQ(ierr);
1373   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1374     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
1375   }
1376   PetscFunctionReturn(0);
1377 }
1378 
1379 #undef __FUNCT__
1380 #define __FUNCT__ "PetscOptionsBoolArray"
1381 /*@C
1382    PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular
1383    option in the database. The values must be separated with commas with
1384    no intervening spaces.
1385 
1386    Logically Collective on the communicator passed in PetscOptionsBegin()
1387 
1388    Input Parameters:
1389 +  opt - the option one is seeking
1390 .  text - short string describing option
1391 .  man - manual page for option
1392 -  nmax - maximum number of values
1393 
1394    Output Parameter:
1395 +  value - location to copy values
1396 .  nmax - actual number of values found
1397 -  set - PETSC_TRUE if found, else PETSC_FALSE
1398 
1399    Level: beginner
1400 
1401    Notes:
1402    The user should pass in an array of doubles
1403 
1404    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1405 
1406    Concepts: options database^array of strings
1407 
1408 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1409            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1410           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1411           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1412           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1413           PetscOptionsList(), PetscOptionsEList()
1414 @*/
1415 PetscErrorCode  PetscOptionsBoolArray(const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set)
1416 {
1417   PetscErrorCode ierr;
1418   PetscInt       i;
1419   PetscOptions   amsopt;
1420 
1421   PetscFunctionBegin;
1422   if (!PetscOptionsPublishCount) {
1423     PetscBool *vals;
1424 
1425     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL_ARRAY,&amsopt);CHKERRQ(ierr);
1426     ierr = PetscMalloc((*n)*sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1427     vals = (PetscBool*)amsopt->data;
1428     for (i=0; i<*n; i++) vals[i] = value[i];
1429     amsopt->arraylength = *n;
1430   }
1431   ierr = PetscOptionsGetBoolArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1432   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1433     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,value[0]);CHKERRQ(ierr);
1434     for (i=1; i<*n; i++) {
1435       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr);
1436     }
1437     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1438   }
1439   PetscFunctionReturn(0);
1440 }
1441 
1442 #undef __FUNCT__
1443 #define __FUNCT__ "PetscOptionsViewer"
1444 /*@C
1445    PetscOptionsInt - Gets a viewer appropriate for the type indicated by the user
1446 
1447    Logically Collective on the communicator passed in PetscOptionsBegin()
1448 
1449    Input Parameters:
1450 +  opt - option name
1451 .  text - short string that describes the option
1452 -  man - manual page with additional information on option
1453 
1454    Output Parameter:
1455 +  viewer - the viewer
1456 -  set - PETSC_TRUE if found, else PETSC_FALSE
1457 
1458    Level: beginner
1459 
1460    Concepts: options database^has int
1461 
1462    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1463 If no value is provided ascii:stdout is used
1464 $       ascii[:[filename][:format]]   defaults to stdout - format can be one of info, info_detailed, or matlab, for example ascii::info prints just the info
1465 $                                     about the object to standard out
1466 $       binary[:filename]   defaults to binaryoutput
1467 $       draw
1468 $       socket[:port]    defaults to the standard output port
1469 
1470    Use PetscRestoreViewerDestroy() after using the viewer, otherwise a memory leak will occur
1471 
1472 .seealso: PetscOptionsGetViewer(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1473           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
1474           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
1475           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1476           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1477           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1478           PetscOptionsList(), PetscOptionsEList()
1479 @*/
1480 PetscErrorCode  PetscOptionsViewer(const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool  *set)
1481 {
1482   PetscErrorCode ierr;
1483   PetscOptions   amsopt;
1484 
1485   PetscFunctionBegin;
1486   if (!PetscOptionsPublishCount) {
1487     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
1488     ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
1489 
1490     *(const char**)amsopt->data = "";
1491   }
1492   ierr = PetscOptionsGetViewer(PetscOptionsObject.comm,PetscOptionsObject.prefix,opt,viewer,format,set);CHKERRQ(ierr);
1493   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1494     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,"",text,ManSection(man));CHKERRQ(ierr);
1495   }
1496   PetscFunctionReturn(0);
1497 }
1498 
1499 
1500 #undef __FUNCT__
1501 #define __FUNCT__ "PetscOptionsHead"
1502 /*@C
1503      PetscOptionsHead - Puts a heading before listing any more published options. Used, for example,
1504             in KSPSetFromOptions_GMRES().
1505 
1506    Logically Collective on the communicator passed in PetscOptionsBegin()
1507 
1508    Input Parameter:
1509 .   head - the heading text
1510 
1511 
1512    Level: intermediate
1513 
1514    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1515 
1516           Can be followed by a call to PetscOptionsTail() in the same function.
1517 
1518    Concepts: options database^subheading
1519 
1520 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1521            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1522           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1523           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1524           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1525           PetscOptionsList(), PetscOptionsEList()
1526 @*/
1527 PetscErrorCode  PetscOptionsHead(const char head[])
1528 {
1529   PetscErrorCode ierr;
1530 
1531   PetscFunctionBegin;
1532   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1533     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  %s\n",head);CHKERRQ(ierr);
1534   }
1535   PetscFunctionReturn(0);
1536 }
1537 
1538 
1539 
1540 
1541 
1542 
1543