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