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