xref: /petsc/src/sys/objects/aoptions.c (revision 475446a1e3a0611cf474352f86b06184959b6260)
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 = PetscStrallocpy(str,(char**)&next->data);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 = PetscStrallocpy(str,(char**)&next->data);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   PetscFunctionBegin;
334   PetscFunctionReturn(0);
335 }
336 
337 #undef __FUNCT__
338 #define __FUNCT__ "PetscOptionsAMSInput"
339 /*
340     PetscOptionsAMSInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the AMS
341 
342     Bugs:
343 +    All processes must traverse through the exact same set of option queries do to the call to PetscScanString()
344 .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
345 -    Only works for PetscInt == int, PetscReal == double etc
346 
347 
348 */
349 PetscErrorCode PetscOptionsSAWsInput()
350 {
351   PetscErrorCode ierr;
352   PetscOptions   next     = PetscOptionsObject.next;
353   static int     mancount = 0;
354   char           options[16];
355   PetscBool      changedmethod = PETSC_FALSE;
356   char           manname[16];
357   char           dir[1024];
358 
359   /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */
360   sprintf(options,"Options_%d",count++);
361 
362   PetscOptionsObject.pprefix = PetscOptionsObject.prefix; /* SAWs will change this, so cannot pass prefix directly */
363 
364   ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",PetscOptionsObject.title);CHKERRQ(ierr);
365   PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject.pprefix,1,SAWs_READ,SAWs_STRING));
366   PetscStackCallSAWs(SAWs_Register,("/PETSc/Options/ChangedMethod",&changedmethod,1,SAWs_WRITE,SAWs_BOOLEAN));
367 
368   while (next) {
369     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
370     PetscStackCallSAWs(SAWs_Register,(dir,&next->set,1,SAWs_WRITE,SAWs_INT));
371     ierr =  PetscMalloc(sizeof(char*),&next->pman);CHKERRQ(ierr);
372 
373     *(char**)next->pman = next->man;
374     sprintf(manname,"man_%d",mancount++);
375     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",manname);CHKERRQ(ierr);
376     PetscStackCallSAWs(SAWs_Register,(dir,next->pman,1,SAWs_READ,SAWs_STRING));
377 
378     switch (next->type) {
379     case OPTION_HEAD:
380       break;
381     case OPTION_INT_ARRAY:
382     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->text);CHKERRQ(ierr);
383       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_INT));
384       break;
385     case OPTION_REAL_ARRAY:
386     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->text);CHKERRQ(ierr);
387       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_DOUBLE));
388       break;
389     case OPTION_INT:
390     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->text);CHKERRQ(ierr);
391       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_INT));
392       break;
393     case OPTION_REAL:
394     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->text);CHKERRQ(ierr);
395       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_DOUBLE));
396       break;
397     case OPTION_LOGICAL:
398     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->text);CHKERRQ(ierr);
399       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_BOOLEAN));
400       break;
401     case OPTION_LOGICAL_ARRAY:
402     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->text);CHKERRQ(ierr);
403       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_BOOLEAN));
404       break;
405     case OPTION_STRING:
406     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->text);CHKERRQ(ierr);
407       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_STRING));
408       break;
409     case OPTION_STRING_ARRAY:
410     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->text);CHKERRQ(ierr);
411       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_STRING));
412       break;
413     case OPTION_LIST:
414       {PetscInt ntext;
415       char      ldefault[128];
416       ierr = PetscStrcpy(ldefault,"DEFAULT:");CHKERRQ(ierr);
417       ierr = PetscStrcat(ldefault,next->text);CHKERRQ(ierr);
418       ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",ldefault);CHKERRQ(ierr);
419       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_STRING));
420       ierr = PetscFunctionListGet(next->flist,(const char***)&next->edata,&ntext);CHKERRQ(ierr);
421       ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->text);CHKERRQ(ierr);
422       PetscStackCallSAWs(SAWs_Register,(dir,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       ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",ldefault);CHKERRQ(ierr);
430       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_STRING));
431       ierr = PetscMalloc((ntext+1)*sizeof(char**),&next->edata);CHKERRQ(ierr);
432       ierr = PetscMemcpy(next->edata,next->list,ntext*sizeof(char*));CHKERRQ(ierr);
433       ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->text);CHKERRQ(ierr);
434       PetscStackCallSAWs(SAWs_Register,(dir,next->edata,ntext,SAWs_WRITE,SAWs_STRING));
435       break;}
436     default:
437       break;
438     }
439     next = next->next;
440   }
441 
442   /* wait until accessor has unlocked the memory */
443   PetscStackCallSAWs(SAWs_Lock,());
444 
445   /* reset counter to -2; this updates the screen with the new options for the selected method */
446   if (changedmethod) PetscOptionsPublishCount = -2;
447 
448   PetscStackCallSAWs(SAWs_Unlock,());
449   PetscStackCallSAWs(SAWs_Delete,("/PETSc/Options"));
450   PetscFunctionReturn(0);
451 }
452 #endif
453 
454 #undef __FUNCT__
455 #define __FUNCT__ "PetscOptionsEnd_Private"
456 PetscErrorCode PetscOptionsEnd_Private(void)
457 {
458   PetscErrorCode ierr;
459   PetscOptions   last;
460   char           option[256],value[1024],tmp[32];
461   size_t         j;
462 
463   PetscFunctionBegin;
464   if (PetscOptionsObject.next) {
465     if (!PetscOptionsPublishCount) {
466 #if defined(PETSC_HAVE_SAWS) && defined(foo)
467       ierr = PetscOptionsSAWsInput();CHKERRQ(ierr);
468 #else
469       ierr = PetscOptionsGetFromTextInput();CHKERRQ(ierr);
470 #endif
471     }
472   }
473 
474   ierr = PetscFree(PetscOptionsObject.title);CHKERRQ(ierr);
475   ierr = PetscFree(PetscOptionsObject.prefix);CHKERRQ(ierr);
476 
477   /* reset counter to -2; this updates the screen with the new options for the selected method */
478   if (PetscOptionsObject.changedmethod) PetscOptionsPublishCount = -2;
479   /* reset alreadyprinted flag */
480   PetscOptionsObject.alreadyprinted = PETSC_FALSE;
481   if (PetscOptionsObject.object) PetscOptionsObject.object->optionsprinted = PETSC_TRUE;
482   PetscOptionsObject.object = NULL;
483 
484   while (PetscOptionsObject.next) {
485     if (PetscOptionsObject.next->set) {
486       if (PetscOptionsObject.prefix) {
487         ierr = PetscStrcpy(option,"-");CHKERRQ(ierr);
488         ierr = PetscStrcat(option,PetscOptionsObject.prefix);CHKERRQ(ierr);
489         ierr = PetscStrcat(option,PetscOptionsObject.next->option+1);CHKERRQ(ierr);
490       } else {
491         ierr = PetscStrcpy(option,PetscOptionsObject.next->option);CHKERRQ(ierr);
492       }
493 
494       switch (PetscOptionsObject.next->type) {
495       case OPTION_HEAD:
496         break;
497       case OPTION_INT_ARRAY:
498         sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[0]);
499         for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
500           sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[j]);
501           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
502           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
503         }
504         break;
505       case OPTION_INT:
506         sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject.next->data);
507         break;
508       case OPTION_REAL:
509         sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject.next->data);
510         break;
511       case OPTION_REAL_ARRAY:
512         sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[0]);
513         for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
514           sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[j]);
515           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
516           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
517         }
518         break;
519       case OPTION_LOGICAL:
520         sprintf(value,"%d",*(int*)PetscOptionsObject.next->data);
521         break;
522       case OPTION_LOGICAL_ARRAY:
523         sprintf(value,"%d",(int)((PetscBool*)PetscOptionsObject.next->data)[0]);
524         for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
525           sprintf(tmp,"%d",(int)((PetscBool*)PetscOptionsObject.next->data)[j]);
526           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
527           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
528         }
529         break;
530       case OPTION_LIST:
531       case OPTION_ELIST:
532         ierr = PetscStrcpy(value,*(char**)PetscOptionsObject.next->data);CHKERRQ(ierr);
533         break;
534       case OPTION_STRING:
535         ierr = PetscStrcpy(value,(char*)PetscOptionsObject.next->data);CHKERRQ(ierr);
536       case OPTION_STRING_ARRAY:
537         sprintf(value,"%s",((char**)PetscOptionsObject.next->data)[0]);
538         for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
539           sprintf(tmp,"%s",((char**)PetscOptionsObject.next->data)[j]);
540           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
541           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
542         }
543         break;
544       }
545       ierr = PetscOptionsSetValue(option,value);CHKERRQ(ierr);
546     }
547     ierr   = PetscFree(PetscOptionsObject.next->text);CHKERRQ(ierr);
548     ierr   = PetscFree(PetscOptionsObject.next->option);CHKERRQ(ierr);
549     ierr   = PetscFree(PetscOptionsObject.next->man);CHKERRQ(ierr);
550     ierr   = PetscFree(PetscOptionsObject.next->data);CHKERRQ(ierr);
551     ierr   = PetscFree(PetscOptionsObject.next->edata);CHKERRQ(ierr);
552 
553     last                    = PetscOptionsObject.next;
554     PetscOptionsObject.next = PetscOptionsObject.next->next;
555     ierr                    = PetscFree(last);CHKERRQ(ierr);
556   }
557   PetscOptionsObject.next = 0;
558   PetscFunctionReturn(0);
559 }
560 
561 #undef __FUNCT__
562 #define __FUNCT__ "PetscOptionsEnum"
563 /*@C
564    PetscOptionsEnum - Gets the enum value for a particular option in the database.
565 
566    Logically Collective on the communicator passed in PetscOptionsBegin()
567 
568    Input Parameters:
569 +  opt - option name
570 .  text - short string that describes the option
571 .  man - manual page with additional information on option
572 .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
573 -  defaultv - the default (current) value
574 
575    Output Parameter:
576 +  value - the  value to return
577 -  set - PETSC_TRUE if found, else PETSC_FALSE
578 
579    Level: beginner
580 
581    Concepts: options database
582 
583    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
584 
585           list is usually something like PCASMTypes or some other predefined list of enum names
586 
587 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
588           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
589           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
590           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
591           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
592           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
593           PetscOptionsList(), PetscOptionsEList()
594 @*/
595 PetscErrorCode  PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum defaultv,PetscEnum *value,PetscBool  *set)
596 {
597   PetscErrorCode ierr;
598   PetscInt       ntext = 0;
599   PetscInt       tval;
600   PetscBool      tflg;
601 
602   PetscFunctionBegin;
603   while (list[ntext++]) {
604     if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries");
605   }
606   if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix");
607   ntext -= 3;
608   ierr   = PetscOptionsEList(opt,text,man,list,ntext,list[defaultv],&tval,&tflg);CHKERRQ(ierr);
609   /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */
610   if (tflg) *value = (PetscEnum)tval;
611   if (set)  *set   = tflg;
612   PetscFunctionReturn(0);
613 }
614 
615 /* -------------------------------------------------------------------------------------------------------------*/
616 #undef __FUNCT__
617 #define __FUNCT__ "PetscOptionsInt"
618 /*@C
619    PetscOptionsInt - Gets the integer value for a particular option in the database.
620 
621    Logically Collective on the communicator passed in PetscOptionsBegin()
622 
623    Input Parameters:
624 +  opt - option name
625 .  text - short string that describes the option
626 .  man - manual page with additional information on option
627 -  defaultv - the default (current) value
628 
629    Output Parameter:
630 +  value - the integer value to return
631 -  flg - PETSC_TRUE if found, else PETSC_FALSE
632 
633    Level: beginner
634 
635    Concepts: options database^has int
636 
637    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
638 
639 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
640           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
641           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
642           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
643           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
644           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
645           PetscOptionsList(), PetscOptionsEList()
646 @*/
647 PetscErrorCode  PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt defaultv,PetscInt *value,PetscBool  *set)
648 {
649   PetscErrorCode ierr;
650   PetscOptions   amsopt;
651 
652   PetscFunctionBegin;
653   if (!PetscOptionsPublishCount) {
654     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr);
655     ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
656 
657     *(PetscInt*)amsopt->data = defaultv;
658   }
659   ierr = PetscOptionsGetInt(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
660   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
661     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr);
662   }
663   PetscFunctionReturn(0);
664 }
665 
666 #undef __FUNCT__
667 #define __FUNCT__ "PetscOptionsString"
668 /*@C
669    PetscOptionsString - Gets the string value for a particular option in the database.
670 
671    Logically Collective on the communicator passed in PetscOptionsBegin()
672 
673    Input Parameters:
674 +  opt - option name
675 .  text - short string that describes the option
676 .  man - manual page with additional information on option
677 .  defaultv - the default (current) value
678 -  len - length of the result string including null terminator
679 
680    Output Parameter:
681 +  value - the value to return
682 -  flg - PETSC_TRUE if found, else PETSC_FALSE
683 
684    Level: beginner
685 
686    Concepts: options database^has int
687 
688    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
689 
690    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).
691 
692 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
693           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
694           PetscOptionsInt(), PetscOptionsReal(), PetscOptionsBool(),
695           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
696           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
697           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
698           PetscOptionsList(), PetscOptionsEList()
699 @*/
700 PetscErrorCode  PetscOptionsString(const char opt[],const char text[],const char man[],const char defaultv[],char value[],size_t len,PetscBool  *set)
701 {
702   PetscErrorCode ierr;
703   PetscOptions   amsopt;
704 
705   PetscFunctionBegin;
706   if (!PetscOptionsPublishCount) {
707     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
708     ierr = PetscStrallocpy(defaultv,(char**)&amsopt->data);CHKERRQ(ierr);
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 = PetscStrallocpy(defaultv,(char**)&amsopt->data);CHKERRQ(ierr);
906     amsopt->flist = list;
907   }
908   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
909   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
910     ierr = PetscFunctionListPrintTypes(PetscOptionsObject.comm,stdout,PetscOptionsObject.prefix,opt,ltext,man,list,defaultv);CHKERRQ(ierr);CHKERRQ(ierr);
911   }
912   PetscFunctionReturn(0);
913 }
914 
915 #undef __FUNCT__
916 #define __FUNCT__ "PetscOptionsEList"
917 /*@C
918      PetscOptionsEList - Puts a list of option values that a single one may be selected from
919 
920    Logically Collective on the communicator passed in PetscOptionsBegin()
921 
922    Input Parameters:
923 +  opt - option name
924 .  ltext - short string that describes the option
925 .  man - manual page with additional information on option
926 .  list - the possible choices
927 .  ntext - number of choices
928 -  defaultv - the default (current) value
929 
930    Output Parameter:
931 +  value - the index of the value to return
932 -  set - PETSC_TRUE if found, else PETSC_FALSE
933 
934    Level: intermediate
935 
936    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
937 
938    See PetscOptionsList() for when the choices are given in a PetscFunctionList()
939 
940    Concepts: options database^list
941 
942 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
943            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
944           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
945           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
946           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
947           PetscOptionsList(), PetscOptionsEnum()
948 @*/
949 PetscErrorCode  PetscOptionsEList(const char opt[],const char ltext[],const char man[],const char *const *list,PetscInt ntext,const char defaultv[],PetscInt *value,PetscBool  *set)
950 {
951   PetscErrorCode ierr;
952   PetscInt       i;
953   PetscOptions   amsopt;
954 
955   PetscFunctionBegin;
956   if (!PetscOptionsPublishCount) {
957     ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_ELIST,&amsopt);CHKERRQ(ierr);
958     ierr = PetscStrallocpy(defaultv,(char**)&amsopt->data);CHKERRQ(ierr);
959     amsopt->list  = list;
960     amsopt->nlist = ntext;
961   }
962   ierr = PetscOptionsGetEList(PetscOptionsObject.prefix,opt,list,ntext,value,set);CHKERRQ(ierr);
963   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
964     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s> (choose one of)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv);CHKERRQ(ierr);
965     for (i=0; i<ntext; i++) {
966       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s",list[i]);CHKERRQ(ierr);
967     }
968     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," (%s)\n",ManSection(man));CHKERRQ(ierr);
969   }
970   PetscFunctionReturn(0);
971 }
972 
973 #undef __FUNCT__
974 #define __FUNCT__ "PetscOptionsBoolGroupBegin"
975 /*@C
976      PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for
977        which at most a single value can be true.
978 
979    Logically Collective on the communicator passed in PetscOptionsBegin()
980 
981    Input Parameters:
982 +  opt - option name
983 .  text - short string that describes the option
984 -  man - manual page with additional information on option
985 
986    Output Parameter:
987 .  flg - whether that option was set or not
988 
989    Level: intermediate
990 
991    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
992 
993    Must be followed by 0 or more PetscOptionsBoolGroup()s and PetscOptionsBoolGroupEnd()
994 
995     Concepts: options database^logical group
996 
997 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
998            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
999           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1000           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1001           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1002           PetscOptionsList(), PetscOptionsEList()
1003 @*/
1004 PetscErrorCode  PetscOptionsBoolGroupBegin(const char opt[],const char text[],const char man[],PetscBool  *flg)
1005 {
1006   PetscErrorCode ierr;
1007   PetscOptions   amsopt;
1008 
1009   PetscFunctionBegin;
1010   if (!PetscOptionsPublishCount) {
1011     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
1012     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1013 
1014     *(PetscBool*)amsopt->data = PETSC_FALSE;
1015   }
1016   *flg = PETSC_FALSE;
1017   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,NULL);CHKERRQ(ierr);
1018   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1019     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  Pick at most one of -------------\n");CHKERRQ(ierr);
1020     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
1021   }
1022   PetscFunctionReturn(0);
1023 }
1024 
1025 #undef __FUNCT__
1026 #define __FUNCT__ "PetscOptionsBoolGroup"
1027 /*@C
1028      PetscOptionsBoolGroup - One in a series of logical queries on the options database for
1029        which at most a single value can be true.
1030 
1031    Logically Collective on the communicator passed in PetscOptionsBegin()
1032 
1033    Input Parameters:
1034 +  opt - option name
1035 .  text - short string that describes the option
1036 -  man - manual page with additional information on option
1037 
1038    Output Parameter:
1039 .  flg - PETSC_TRUE if found, else PETSC_FALSE
1040 
1041    Level: intermediate
1042 
1043    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1044 
1045    Must follow a PetscOptionsBoolGroupBegin() and preceded a PetscOptionsBoolGroupEnd()
1046 
1047     Concepts: options database^logical group
1048 
1049 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1050            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1051           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1052           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1053           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1054           PetscOptionsList(), PetscOptionsEList()
1055 @*/
1056 PetscErrorCode  PetscOptionsBoolGroup(const char opt[],const char text[],const char man[],PetscBool  *flg)
1057 {
1058   PetscErrorCode ierr;
1059   PetscOptions   amsopt;
1060 
1061   PetscFunctionBegin;
1062   if (!PetscOptionsPublishCount) {
1063     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
1064     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1065 
1066     *(PetscBool*)amsopt->data = PETSC_FALSE;
1067   }
1068   *flg = PETSC_FALSE;
1069   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,NULL);CHKERRQ(ierr);
1070   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1071     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
1072   }
1073   PetscFunctionReturn(0);
1074 }
1075 
1076 #undef __FUNCT__
1077 #define __FUNCT__ "PetscOptionsBoolGroupEnd"
1078 /*@C
1079      PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for
1080        which at most a single value can be true.
1081 
1082    Logically Collective on the communicator passed in PetscOptionsBegin()
1083 
1084    Input Parameters:
1085 +  opt - option name
1086 .  text - short string that describes the option
1087 -  man - manual page with additional information on option
1088 
1089    Output Parameter:
1090 .  flg - PETSC_TRUE if found, else PETSC_FALSE
1091 
1092    Level: intermediate
1093 
1094    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1095 
1096    Must follow a PetscOptionsBoolGroupBegin()
1097 
1098     Concepts: options database^logical group
1099 
1100 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1101            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1102           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1103           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1104           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1105           PetscOptionsList(), PetscOptionsEList()
1106 @*/
1107 PetscErrorCode  PetscOptionsBoolGroupEnd(const char opt[],const char text[],const char man[],PetscBool  *flg)
1108 {
1109   PetscErrorCode ierr;
1110   PetscOptions   amsopt;
1111 
1112   PetscFunctionBegin;
1113   if (!PetscOptionsPublishCount) {
1114     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
1115     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1116 
1117     *(PetscBool*)amsopt->data = PETSC_FALSE;
1118   }
1119   *flg = PETSC_FALSE;
1120   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,NULL);CHKERRQ(ierr);
1121   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1122     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
1123   }
1124   PetscFunctionReturn(0);
1125 }
1126 
1127 #undef __FUNCT__
1128 #define __FUNCT__ "PetscOptionsBool"
1129 /*@C
1130    PetscOptionsBool - Determines if a particular option is in the database with a true or false
1131 
1132    Logically Collective on the communicator passed in PetscOptionsBegin()
1133 
1134    Input Parameters:
1135 +  opt - option name
1136 .  text - short string that describes the option
1137 -  man - manual page with additional information on option
1138 
1139    Output Parameter:
1140 .  flg - PETSC_TRUE or PETSC_FALSE
1141 .  set - PETSC_TRUE if found, else PETSC_FALSE
1142 
1143    Level: beginner
1144 
1145    Concepts: options database^logical
1146 
1147    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1148 
1149 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1150           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
1151           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
1152           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1153           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1154           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1155           PetscOptionsList(), PetscOptionsEList()
1156 @*/
1157 PetscErrorCode  PetscOptionsBool(const char opt[],const char text[],const char man[],PetscBool deflt,PetscBool  *flg,PetscBool  *set)
1158 {
1159   PetscErrorCode ierr;
1160   PetscBool      iset;
1161   PetscOptions   amsopt;
1162 
1163   PetscFunctionBegin;
1164   if (!PetscOptionsPublishCount) {
1165     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
1166     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1167 
1168     *(PetscBool*)amsopt->data = deflt;
1169   }
1170   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,&iset);CHKERRQ(ierr);
1171   if (!iset) {
1172     if (flg) *flg = deflt;
1173   }
1174   if (set) *set = iset;
1175   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1176     const char *v = PetscBools[deflt];
1177     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: <%s> %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,v,text,ManSection(man));CHKERRQ(ierr);
1178   }
1179   PetscFunctionReturn(0);
1180 }
1181 
1182 #undef __FUNCT__
1183 #define __FUNCT__ "PetscOptionsRealArray"
1184 /*@C
1185    PetscOptionsRealArray - Gets an array of double values for a particular
1186    option in the database. The values must be separated with commas with
1187    no intervening spaces.
1188 
1189    Logically Collective on the communicator passed in PetscOptionsBegin()
1190 
1191    Input Parameters:
1192 +  opt - the option one is seeking
1193 .  text - short string describing option
1194 .  man - manual page for option
1195 -  nmax - maximum number of values
1196 
1197    Output Parameter:
1198 +  value - location to copy values
1199 .  nmax - actual number of values found
1200 -  set - PETSC_TRUE if found, else PETSC_FALSE
1201 
1202    Level: beginner
1203 
1204    Notes:
1205    The user should pass in an array of doubles
1206 
1207    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1208 
1209    Concepts: options database^array of strings
1210 
1211 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1212            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1213           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1214           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1215           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1216           PetscOptionsList(), PetscOptionsEList()
1217 @*/
1218 PetscErrorCode  PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool  *set)
1219 {
1220   PetscErrorCode ierr;
1221   PetscInt       i;
1222   PetscOptions   amsopt;
1223 
1224   PetscFunctionBegin;
1225   if (!PetscOptionsPublishCount) {
1226     PetscReal *vals;
1227 
1228     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr);
1229     ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
1230     vals = (PetscReal*)amsopt->data;
1231     for (i=0; i<*n; i++) vals[i] = value[i];
1232     amsopt->arraylength = *n;
1233   }
1234   ierr = PetscOptionsGetRealArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1235   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1236     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%G",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
1237     for (i=1; i<*n; i++) {
1238       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%G",value[i]);CHKERRQ(ierr);
1239     }
1240     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1241   }
1242   PetscFunctionReturn(0);
1243 }
1244 
1245 
1246 #undef __FUNCT__
1247 #define __FUNCT__ "PetscOptionsIntArray"
1248 /*@C
1249    PetscOptionsIntArray - Gets an array of integers for a particular
1250    option in the database.
1251 
1252    Logically Collective on the communicator passed in PetscOptionsBegin()
1253 
1254    Input Parameters:
1255 +  opt - the option one is seeking
1256 .  text - short string describing option
1257 .  man - manual page for option
1258 -  n - maximum number of values
1259 
1260    Output Parameter:
1261 +  value - location to copy values
1262 .  n - actual number of values found
1263 -  set - PETSC_TRUE if found, else PETSC_FALSE
1264 
1265    Level: beginner
1266 
1267    Notes:
1268    The array can be passed as
1269    a comma seperated list:                                 0,1,2,3,4,5,6,7
1270    a range (start-end+1):                                  0-8
1271    a range with given increment (start-end+1:inc):         0-7:2
1272    a combination of values and ranges seperated by commas: 0,1-8,8-15:2
1273 
1274    There must be no intervening spaces between the values.
1275 
1276    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1277 
1278    Concepts: options database^array of ints
1279 
1280 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1281            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1282           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1283           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1284           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1285           PetscOptionsList(), PetscOptionsEList(), PetscOptionsRealArray()
1286 @*/
1287 PetscErrorCode  PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool  *set)
1288 {
1289   PetscErrorCode ierr;
1290   PetscInt       i;
1291   PetscOptions   amsopt;
1292 
1293   PetscFunctionBegin;
1294   if (!PetscOptionsPublishCount) {
1295     PetscInt *vals;
1296 
1297     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr);
1298     ierr = PetscMalloc((*n)*sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
1299     vals = (PetscInt*)amsopt->data;
1300     for (i=0; i<*n; i++) vals[i] = value[i];
1301     amsopt->arraylength = *n;
1302   }
1303   ierr = PetscOptionsGetIntArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1304   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1305     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,value[0]);CHKERRQ(ierr);
1306     for (i=1; i<*n; i++) {
1307       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr);
1308     }
1309     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1310   }
1311   PetscFunctionReturn(0);
1312 }
1313 
1314 #undef __FUNCT__
1315 #define __FUNCT__ "PetscOptionsStringArray"
1316 /*@C
1317    PetscOptionsStringArray - Gets an array of string values for a particular
1318    option in the database. The values must be separated with commas with
1319    no intervening spaces.
1320 
1321    Logically Collective on the communicator passed in PetscOptionsBegin()
1322 
1323    Input Parameters:
1324 +  opt - the option one is seeking
1325 .  text - short string describing option
1326 .  man - manual page for option
1327 -  nmax - maximum number of strings
1328 
1329    Output Parameter:
1330 +  value - location to copy strings
1331 .  nmax - actual number of strings found
1332 -  set - PETSC_TRUE if found, else PETSC_FALSE
1333 
1334    Level: beginner
1335 
1336    Notes:
1337    The user should pass in an array of pointers to char, to hold all the
1338    strings returned by this function.
1339 
1340    The user is responsible for deallocating the strings that are
1341    returned. The Fortran interface for this routine is not supported.
1342 
1343    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1344 
1345    Concepts: options database^array of strings
1346 
1347 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1348            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1349           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1350           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1351           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1352           PetscOptionsList(), PetscOptionsEList()
1353 @*/
1354 PetscErrorCode  PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool  *set)
1355 {
1356   PetscErrorCode ierr;
1357   PetscOptions   amsopt;
1358 
1359   PetscFunctionBegin;
1360   if (!PetscOptionsPublishCount) {
1361     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING_ARRAY,&amsopt);CHKERRQ(ierr);
1362     ierr = PetscMalloc((*nmax)*sizeof(char*),&amsopt->data);CHKERRQ(ierr);
1363 
1364     amsopt->arraylength = *nmax;
1365   }
1366   ierr = PetscOptionsGetStringArray(PetscOptionsObject.prefix,opt,value,nmax,set);CHKERRQ(ierr);
1367   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1368     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
1369   }
1370   PetscFunctionReturn(0);
1371 }
1372 
1373 #undef __FUNCT__
1374 #define __FUNCT__ "PetscOptionsBoolArray"
1375 /*@C
1376    PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular
1377    option in the database. The values must be separated with commas with
1378    no intervening spaces.
1379 
1380    Logically Collective on the communicator passed in PetscOptionsBegin()
1381 
1382    Input Parameters:
1383 +  opt - the option one is seeking
1384 .  text - short string describing option
1385 .  man - manual page for option
1386 -  nmax - maximum number of values
1387 
1388    Output Parameter:
1389 +  value - location to copy values
1390 .  nmax - actual number of values found
1391 -  set - PETSC_TRUE if found, else PETSC_FALSE
1392 
1393    Level: beginner
1394 
1395    Notes:
1396    The user should pass in an array of doubles
1397 
1398    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1399 
1400    Concepts: options database^array of strings
1401 
1402 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1403            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1404           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1405           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1406           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1407           PetscOptionsList(), PetscOptionsEList()
1408 @*/
1409 PetscErrorCode  PetscOptionsBoolArray(const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set)
1410 {
1411   PetscErrorCode ierr;
1412   PetscInt       i;
1413   PetscOptions   amsopt;
1414 
1415   PetscFunctionBegin;
1416   if (!PetscOptionsPublishCount) {
1417     PetscBool *vals;
1418 
1419     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL_ARRAY,&amsopt);CHKERRQ(ierr);
1420     ierr = PetscMalloc((*n)*sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1421     vals = (PetscBool*)amsopt->data;
1422     for (i=0; i<*n; i++) vals[i] = value[i];
1423     amsopt->arraylength = *n;
1424   }
1425   ierr = PetscOptionsGetBoolArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1426   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1427     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,value[0]);CHKERRQ(ierr);
1428     for (i=1; i<*n; i++) {
1429       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr);
1430     }
1431     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1432   }
1433   PetscFunctionReturn(0);
1434 }
1435 
1436 #undef __FUNCT__
1437 #define __FUNCT__ "PetscOptionsViewer"
1438 /*@C
1439    PetscOptionsInt - Gets a viewer appropriate for the type indicated by the user
1440 
1441    Logically Collective on the communicator passed in PetscOptionsBegin()
1442 
1443    Input Parameters:
1444 +  opt - option name
1445 .  text - short string that describes the option
1446 -  man - manual page with additional information on option
1447 
1448    Output Parameter:
1449 +  viewer - the viewer
1450 -  set - PETSC_TRUE if found, else PETSC_FALSE
1451 
1452    Level: beginner
1453 
1454    Concepts: options database^has int
1455 
1456    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1457 If no value is provided ascii:stdout is used
1458 $       ascii[:[filename][:format]]   defaults to stdout - format can be one of info, info_detailed, or matlab, for example ascii::info prints just the info
1459 $                                     about the object to standard out
1460 $       binary[:filename]   defaults to binaryoutput
1461 $       draw
1462 $       socket[:port]    defaults to the standard output port
1463 
1464    Use PetscRestoreViewerDestroy() after using the viewer, otherwise a memory leak will occur
1465 
1466 .seealso: PetscOptionsGetViewer(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1467           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
1468           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
1469           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1470           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1471           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1472           PetscOptionsList(), PetscOptionsEList()
1473 @*/
1474 PetscErrorCode  PetscOptionsViewer(const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool  *set)
1475 {
1476   PetscErrorCode ierr;
1477   PetscOptions   amsopt;
1478 
1479   PetscFunctionBegin;
1480   if (!PetscOptionsPublishCount) {
1481     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
1482     ierr = PetscStrallocpy("",(char**)&amsopt->data);CHKERRQ(ierr);
1483   }
1484   ierr = PetscOptionsGetViewer(PetscOptionsObject.comm,PetscOptionsObject.prefix,opt,viewer,format,set);CHKERRQ(ierr);
1485   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1486     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,"",text,ManSection(man));CHKERRQ(ierr);
1487   }
1488   PetscFunctionReturn(0);
1489 }
1490 
1491 
1492 #undef __FUNCT__
1493 #define __FUNCT__ "PetscOptionsHead"
1494 /*@C
1495      PetscOptionsHead - Puts a heading before listing any more published options. Used, for example,
1496             in KSPSetFromOptions_GMRES().
1497 
1498    Logically Collective on the communicator passed in PetscOptionsBegin()
1499 
1500    Input Parameter:
1501 .   head - the heading text
1502 
1503 
1504    Level: intermediate
1505 
1506    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1507 
1508           Can be followed by a call to PetscOptionsTail() in the same function.
1509 
1510    Concepts: options database^subheading
1511 
1512 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1513            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1514           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1515           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1516           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1517           PetscOptionsList(), PetscOptionsEList()
1518 @*/
1519 PetscErrorCode  PetscOptionsHead(const char head[])
1520 {
1521   PetscErrorCode ierr;
1522 
1523   PetscFunctionBegin;
1524   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1525     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  %s\n",head);CHKERRQ(ierr);
1526   }
1527   PetscFunctionReturn(0);
1528 }
1529 
1530 
1531 
1532 
1533 
1534 
1535