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