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