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