xref: /petsc/src/sys/objects/aoptions.c (revision 39d508bb00ddff42cd842b40ab2faf2a7a11a8c1)
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     = PetscOptionsStringToInt(value,&start);CHKERRQ(ierr);
191 		ierr     = PetscOptionsStringToInt(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      = PetscOptionsStringToInt(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      = PetscOptionsStringToReal(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  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  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    Even if the user provided no string (for example -optionname -someotheroption) the flag is set to PETSC_TRUE (and the string is fulled with nulls).
672 
673 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
674           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
675           PetscOptionsInt(), PetscOptionsReal(), PetscOptionsBool(),
676           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
677           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
678           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
679           PetscOptionsList(), PetscOptionsEList()
680 @*/
681 PetscErrorCode  PetscOptionsString(const char opt[],const char text[],const char man[],const char defaultv[],char value[],size_t len,PetscBool  *set)
682 {
683   PetscErrorCode ierr;
684   PetscOptions   amsopt;
685 
686   PetscFunctionBegin;
687   if (!PetscOptionsPublishCount) {
688     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
689     ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr);
690     *(const char**)amsopt->data = defaultv;
691   }
692   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
693   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
694     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr);
695   }
696   PetscFunctionReturn(0);
697 }
698 
699 #undef __FUNCT__
700 #define __FUNCT__ "PetscOptionsReal"
701 /*@C
702    PetscOptionsReal - Gets the PetscReal value for a particular option in the database.
703 
704    Logically Collective on the communicator passed in PetscOptionsBegin()
705 
706    Input Parameters:
707 +  opt - option name
708 .  text - short string that describes the option
709 .  man - manual page with additional information on option
710 -  defaultv - the default (current) value
711 
712    Output Parameter:
713 +  value - the value to return
714 -  flg - PETSC_TRUE if found, else PETSC_FALSE
715 
716    Level: beginner
717 
718    Concepts: options database^has int
719 
720    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
721 
722 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
723           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
724           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
725           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
726           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
727           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
728           PetscOptionsList(), PetscOptionsEList()
729 @*/
730 PetscErrorCode  PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal defaultv,PetscReal *value,PetscBool  *set)
731 {
732   PetscErrorCode ierr;
733   PetscOptions   amsopt;
734 
735   PetscFunctionBegin;
736   if (!PetscOptionsPublishCount) {
737     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr);
738     ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
739     *(PetscReal*)amsopt->data = defaultv;
740   }
741   ierr = PetscOptionsGetReal(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
742   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
743     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%G>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr);
744   }
745   PetscFunctionReturn(0);
746 }
747 
748 #undef __FUNCT__
749 #define __FUNCT__ "PetscOptionsScalar"
750 /*@C
751    PetscOptionsScalar - Gets the scalar value for a particular option in the database.
752 
753    Logically Collective on the communicator passed in PetscOptionsBegin()
754 
755    Input Parameters:
756 +  opt - option name
757 .  text - short string that describes the option
758 .  man - manual page with additional information on option
759 -  defaultv - the default (current) value
760 
761    Output Parameter:
762 +  value - the value to return
763 -  flg - PETSC_TRUE if found, else PETSC_FALSE
764 
765    Level: beginner
766 
767    Concepts: options database^has int
768 
769    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
770 
771 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
772           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
773           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
774           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
775           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
776           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
777           PetscOptionsList(), PetscOptionsEList()
778 @*/
779 PetscErrorCode  PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar defaultv,PetscScalar *value,PetscBool  *set)
780 {
781   PetscErrorCode ierr;
782 
783   PetscFunctionBegin;
784 #if !defined(PETSC_USE_COMPLEX)
785   ierr = PetscOptionsReal(opt,text,man,defaultv,value,set);CHKERRQ(ierr);
786 #else
787   ierr = PetscOptionsGetScalar(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
788 #endif
789   PetscFunctionReturn(0);
790 }
791 
792 #undef __FUNCT__
793 #define __FUNCT__ "PetscOptionsName"
794 /*@C
795    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
796                       its value is set to false.
797 
798    Logically Collective on the communicator passed in PetscOptionsBegin()
799 
800    Input Parameters:
801 +  opt - option name
802 .  text - short string that describes the option
803 -  man - manual page with additional information on option
804 
805    Output Parameter:
806 .  flg - PETSC_TRUE if found, else PETSC_FALSE
807 
808    Level: beginner
809 
810    Concepts: options database^has int
811 
812    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
813 
814 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
815           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
816           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
817           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
818           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
819           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
820           PetscOptionsList(), PetscOptionsEList()
821 @*/
822 PetscErrorCode  PetscOptionsName(const char opt[],const char text[],const char man[],PetscBool  *flg)
823 {
824   PetscErrorCode ierr;
825   PetscOptions   amsopt;
826 
827   PetscFunctionBegin;
828   if (!PetscOptionsPublishCount) {
829     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
830     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
831     *(PetscBool*)amsopt->data = PETSC_FALSE;
832   }
833   ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr);
834   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
835     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,ManSection(man));CHKERRQ(ierr);
836   }
837   PetscFunctionReturn(0);
838 }
839 
840 #undef __FUNCT__
841 #define __FUNCT__ "PetscOptionsList"
842 /*@C
843      PetscOptionsList - Puts a list of option values that a single one may be selected from
844 
845    Logically Collective on the communicator passed in PetscOptionsBegin()
846 
847    Input Parameters:
848 +  opt - option name
849 .  text - short string that describes the option
850 .  man - manual page with additional information on option
851 .  list - the possible choices
852 .  defaultv - the default (current) value
853 -  len - the length of the character array value
854 
855    Output Parameter:
856 +  value - the value to return
857 -  set - PETSC_TRUE if found, else PETSC_FALSE
858 
859    Level: intermediate
860 
861    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
862 
863    See PetscOptionsEList() for when the choices are given in a string array
864 
865    To get a listing of all currently specified options,
866     see PetscOptionsPrint() or PetscOptionsGetAll()
867 
868    Concepts: options database^list
869 
870 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
871            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
872           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
873           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
874           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
875           PetscOptionsList(), PetscOptionsEList()
876 @*/
877 PetscErrorCode  PetscOptionsList(const char opt[],const char ltext[],const char man[],PetscFList list,const char defaultv[],char value[],size_t len,PetscBool  *set)
878 {
879   PetscErrorCode ierr;
880   PetscOptions   amsopt;
881 
882   PetscFunctionBegin;
883   if (!PetscOptionsPublishCount) {
884     ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_LIST,&amsopt);CHKERRQ(ierr);
885     ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr);
886     *(const char**)amsopt->data = defaultv;
887     amsopt->flist = list;
888   }
889   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
890   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
891     ierr = PetscFListPrintTypes(PetscOptionsObject.comm,stdout,PetscOptionsObject.prefix,opt,ltext,man,list,defaultv);CHKERRQ(ierr);CHKERRQ(ierr);
892   }
893   PetscFunctionReturn(0);
894 }
895 
896 #undef __FUNCT__
897 #define __FUNCT__ "PetscOptionsEList"
898 /*@C
899      PetscOptionsEList - Puts a list of option values that a single one may be selected from
900 
901    Logically Collective on the communicator passed in PetscOptionsBegin()
902 
903    Input Parameters:
904 +  opt - option name
905 .  ltext - short string that describes the option
906 .  man - manual page with additional information on option
907 .  list - the possible choices
908 .  ntext - number of choices
909 -  defaultv - the default (current) value
910 
911    Output Parameter:
912 +  value - the index of the value to return
913 -  set - PETSC_TRUE if found, else PETSC_FALSE
914 
915    Level: intermediate
916 
917    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
918 
919    See PetscOptionsList() for when the choices are given in a PetscFList()
920 
921    Concepts: options database^list
922 
923 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
924            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
925           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
926           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
927           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
928           PetscOptionsList(), PetscOptionsEList()
929 @*/
930 PetscErrorCode  PetscOptionsEList(const char opt[],const char ltext[],const char man[],const char *const*list,PetscInt ntext,const char defaultv[],PetscInt *value,PetscBool  *set)
931 {
932   PetscErrorCode ierr;
933   PetscInt       i;
934   PetscOptions   amsopt;
935 
936   PetscFunctionBegin;
937   if (!PetscOptionsPublishCount) {
938     ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_ELIST,&amsopt);CHKERRQ(ierr);
939     ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr);
940     *(const char**)amsopt->data = defaultv;
941     amsopt->list  = list;
942     amsopt->nlist = ntext;
943   }
944   ierr = PetscOptionsGetEList(PetscOptionsObject.prefix,opt,list,ntext,value,set);CHKERRQ(ierr);
945   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
946     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s> (choose one of)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv);CHKERRQ(ierr);
947     for (i=0; i<ntext; i++){
948       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s",list[i]);CHKERRQ(ierr);
949     }
950     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," (%s)\n",ManSection(man));CHKERRQ(ierr);
951   }
952   PetscFunctionReturn(0);
953 }
954 
955 #undef __FUNCT__
956 #define __FUNCT__ "PetscOptionsBoolGroupBegin"
957 /*@C
958      PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for
959        which at most a single value can be true.
960 
961    Logically Collective on the communicator passed in PetscOptionsBegin()
962 
963    Input Parameters:
964 +  opt - option name
965 .  text - short string that describes the option
966 -  man - manual page with additional information on option
967 
968    Output Parameter:
969 .  flg - whether that option was set or not
970 
971    Level: intermediate
972 
973    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
974 
975    Must be followed by 0 or more PetscOptionsBoolGroup()s and PetscOptionsBoolGroupEnd()
976 
977     Concepts: options database^logical group
978 
979 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
980            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
981           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
982           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
983           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
984           PetscOptionsList(), PetscOptionsEList()
985 @*/
986 PetscErrorCode  PetscOptionsBoolGroupBegin(const char opt[],const char text[],const char man[],PetscBool  *flg)
987 {
988   PetscErrorCode ierr;
989   PetscOptions   amsopt;
990 
991   PetscFunctionBegin;
992   if (!PetscOptionsPublishCount) {
993     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
994     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
995     *(PetscBool*)amsopt->data = PETSC_FALSE;
996   }
997   *flg = PETSC_FALSE;
998   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr);
999   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1000     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  Pick at most one of -------------\n");CHKERRQ(ierr);
1001     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,ManSection(man));CHKERRQ(ierr);
1002   }
1003   PetscFunctionReturn(0);
1004 }
1005 
1006 #undef __FUNCT__
1007 #define __FUNCT__ "PetscOptionsBoolGroup"
1008 /*@C
1009      PetscOptionsBoolGroup - One in a series of logical queries on the options database for
1010        which at most a single value can be true.
1011 
1012    Logically Collective on the communicator passed in PetscOptionsBegin()
1013 
1014    Input Parameters:
1015 +  opt - option name
1016 .  text - short string that describes the option
1017 -  man - manual page with additional information on option
1018 
1019    Output Parameter:
1020 .  flg - PETSC_TRUE if found, else PETSC_FALSE
1021 
1022    Level: intermediate
1023 
1024    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1025 
1026    Must follow a PetscOptionsBoolGroupBegin() and preceded a PetscOptionsBoolGroupEnd()
1027 
1028     Concepts: options database^logical group
1029 
1030 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1031            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1032           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1033           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1034           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1035           PetscOptionsList(), PetscOptionsEList()
1036 @*/
1037 PetscErrorCode  PetscOptionsBoolGroup(const char opt[],const char text[],const char man[],PetscBool  *flg)
1038 {
1039   PetscErrorCode ierr;
1040   PetscOptions   amsopt;
1041 
1042   PetscFunctionBegin;
1043   if (!PetscOptionsPublishCount) {
1044     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
1045     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1046     *(PetscBool*)amsopt->data = PETSC_FALSE;
1047   }
1048   *flg = PETSC_FALSE;
1049   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr);
1050   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1051     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,ManSection(man));CHKERRQ(ierr);
1052   }
1053   PetscFunctionReturn(0);
1054 }
1055 
1056 #undef __FUNCT__
1057 #define __FUNCT__ "PetscOptionsBoolGroupEnd"
1058 /*@C
1059      PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for
1060        which at most a single value can be true.
1061 
1062    Logically Collective on the communicator passed in PetscOptionsBegin()
1063 
1064    Input Parameters:
1065 +  opt - option name
1066 .  text - short string that describes the option
1067 -  man - manual page with additional information on option
1068 
1069    Output Parameter:
1070 .  flg - PETSC_TRUE if found, else PETSC_FALSE
1071 
1072    Level: intermediate
1073 
1074    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1075 
1076    Must follow a PetscOptionsBoolGroupBegin()
1077 
1078     Concepts: options database^logical group
1079 
1080 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1081            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1082           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1083           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1084           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1085           PetscOptionsList(), PetscOptionsEList()
1086 @*/
1087 PetscErrorCode  PetscOptionsBoolGroupEnd(const char opt[],const char text[],const char man[],PetscBool  *flg)
1088 {
1089   PetscErrorCode ierr;
1090   PetscOptions   amsopt;
1091 
1092   PetscFunctionBegin;
1093   if (!PetscOptionsPublishCount) {
1094     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
1095     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1096     *(PetscBool*)amsopt->data = PETSC_FALSE;
1097   }
1098   *flg = PETSC_FALSE;
1099   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr);
1100   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1101     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,ManSection(man));CHKERRQ(ierr);
1102   }
1103   PetscFunctionReturn(0);
1104 }
1105 
1106 #undef __FUNCT__
1107 #define __FUNCT__ "PetscOptionsBool"
1108 /*@C
1109    PetscOptionsBool - Determines if a particular option is in the database with a true or false
1110 
1111    Logically Collective on the communicator passed in PetscOptionsBegin()
1112 
1113    Input Parameters:
1114 +  opt - option name
1115 .  text - short string that describes the option
1116 -  man - manual page with additional information on option
1117 
1118    Output Parameter:
1119 .  flg - PETSC_TRUE or PETSC_FALSE
1120 .  set - PETSC_TRUE if found, else PETSC_FALSE
1121 
1122    Level: beginner
1123 
1124    Concepts: options database^logical
1125 
1126    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1127 
1128 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1129           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
1130           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
1131           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1132           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1133           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1134           PetscOptionsList(), PetscOptionsEList()
1135 @*/
1136 PetscErrorCode  PetscOptionsBool(const char opt[],const char text[],const char man[],PetscBool  deflt,PetscBool  *flg,PetscBool  *set)
1137 {
1138   PetscErrorCode ierr;
1139   PetscBool      iset;
1140   PetscOptions   amsopt;
1141 
1142   PetscFunctionBegin;
1143   if (!PetscOptionsPublishCount) {
1144     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
1145     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1146     *(PetscBool*)amsopt->data = deflt;
1147   }
1148   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,&iset);CHKERRQ(ierr);
1149   if (!iset) {
1150     if (flg) *flg = deflt;
1151   }
1152   if (set) *set = iset;
1153   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1154     const char *v = PetscBools[deflt];
1155     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: <%s> %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,v,text,ManSection(man));CHKERRQ(ierr);
1156   }
1157   PetscFunctionReturn(0);
1158 }
1159 
1160 #undef __FUNCT__
1161 #define __FUNCT__ "PetscOptionsRealArray"
1162 /*@C
1163    PetscOptionsRealArray - Gets an array of double values for a particular
1164    option in the database. The values must be separated with commas with
1165    no intervening spaces.
1166 
1167    Logically Collective on the communicator passed in PetscOptionsBegin()
1168 
1169    Input Parameters:
1170 +  opt - the option one is seeking
1171 .  text - short string describing option
1172 .  man - manual page for option
1173 -  nmax - maximum number of values
1174 
1175    Output Parameter:
1176 +  value - location to copy values
1177 .  nmax - actual number of values found
1178 -  set - PETSC_TRUE if found, else PETSC_FALSE
1179 
1180    Level: beginner
1181 
1182    Notes:
1183    The user should pass in an array of doubles
1184 
1185    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1186 
1187    Concepts: options database^array of strings
1188 
1189 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1190            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1191           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1192           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1193           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1194           PetscOptionsList(), PetscOptionsEList()
1195 @*/
1196 PetscErrorCode  PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool  *set)
1197 {
1198   PetscErrorCode ierr;
1199   PetscInt       i;
1200   PetscOptions   amsopt;
1201 
1202   PetscFunctionBegin;
1203   if (!PetscOptionsPublishCount) {
1204     PetscReal *vals;
1205 
1206     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr);
1207     ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
1208     vals = (PetscReal*)amsopt->data;
1209     for (i=0; i<*n; i++) vals[i] = value[i];
1210     amsopt->arraylength = *n;
1211   }
1212   ierr = PetscOptionsGetRealArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1213   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1214     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%G",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
1215     for (i=1; i<*n; i++) {
1216       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%G",value[i]);CHKERRQ(ierr);
1217     }
1218     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1219   }
1220   PetscFunctionReturn(0);
1221 }
1222 
1223 
1224 #undef __FUNCT__
1225 #define __FUNCT__ "PetscOptionsIntArray"
1226 /*@C
1227    PetscOptionsIntArray - Gets an array of integers for a particular
1228    option in the database. The values must be separated with commas with
1229    no intervening spaces.
1230 
1231    Logically Collective on the communicator passed in PetscOptionsBegin()
1232 
1233    Input Parameters:
1234 +  opt - the option one is seeking
1235 .  text - short string describing option
1236 .  man - manual page for option
1237 -  n - maximum number of values
1238 
1239    Output Parameter:
1240 +  value - location to copy values
1241 .  n - actual number of values found
1242 -  set - PETSC_TRUE if found, else PETSC_FALSE
1243 
1244    Level: beginner
1245 
1246    Notes:
1247    The user should pass in an array of integers
1248 
1249    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1250 
1251    Concepts: options database^array of strings
1252 
1253 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1254            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1255           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1256           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1257           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1258           PetscOptionsList(), PetscOptionsEList(), PetscOptionsRealArray()
1259 @*/
1260 PetscErrorCode  PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool  *set)
1261 {
1262   PetscErrorCode ierr;
1263   PetscInt       i;
1264   PetscOptions   amsopt;
1265 
1266   PetscFunctionBegin;
1267   if (!PetscOptionsPublishCount) {
1268     PetscInt *vals;
1269 
1270     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr);
1271     ierr = PetscMalloc((*n)*sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
1272     vals = (PetscInt*)amsopt->data;
1273     for (i=0; i<*n; i++) vals[i] = value[i];
1274     amsopt->arraylength = *n;
1275   }
1276   ierr = PetscOptionsGetIntArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1277   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1278     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
1279     for (i=1; i<*n; i++) {
1280       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr);
1281     }
1282     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1283   }
1284   PetscFunctionReturn(0);
1285 }
1286 
1287 #undef __FUNCT__
1288 #define __FUNCT__ "PetscOptionsStringArray"
1289 /*@C
1290    PetscOptionsStringArray - Gets an array of string values for a particular
1291    option in the database. The values must be separated with commas with
1292    no intervening spaces.
1293 
1294    Logically Collective on the communicator passed in PetscOptionsBegin()
1295 
1296    Input Parameters:
1297 +  opt - the option one is seeking
1298 .  text - short string describing option
1299 .  man - manual page for option
1300 -  nmax - maximum number of strings
1301 
1302    Output Parameter:
1303 +  value - location to copy strings
1304 .  nmax - actual number of strings found
1305 -  set - PETSC_TRUE if found, else PETSC_FALSE
1306 
1307    Level: beginner
1308 
1309    Notes:
1310    The user should pass in an array of pointers to char, to hold all the
1311    strings returned by this function.
1312 
1313    The user is responsible for deallocating the strings that are
1314    returned. The Fortran interface for this routine is not supported.
1315 
1316    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1317 
1318    Concepts: options database^array of strings
1319 
1320 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1321            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1322           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1323           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1324           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1325           PetscOptionsList(), PetscOptionsEList()
1326 @*/
1327 PetscErrorCode  PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool  *set)
1328 {
1329   PetscErrorCode ierr;
1330   PetscOptions   amsopt;
1331 
1332   PetscFunctionBegin;
1333   if (!PetscOptionsPublishCount) {
1334     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING_ARRAY,&amsopt);CHKERRQ(ierr);
1335     ierr = PetscMalloc((*nmax)*sizeof(char*),&amsopt->data);CHKERRQ(ierr);
1336     amsopt->arraylength = *nmax;
1337   }
1338   ierr = PetscOptionsGetStringArray(PetscOptionsObject.prefix,opt,value,nmax,set);CHKERRQ(ierr);
1339   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1340     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,ManSection(man));CHKERRQ(ierr);
1341   }
1342   PetscFunctionReturn(0);
1343 }
1344 
1345 #undef __FUNCT__
1346 #define __FUNCT__ "PetscOptionsBoolArray"
1347 /*@C
1348    PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular
1349    option in the database. The values must be separated with commas with
1350    no intervening spaces.
1351 
1352    Logically Collective on the communicator passed in PetscOptionsBegin()
1353 
1354    Input Parameters:
1355 +  opt - the option one is seeking
1356 .  text - short string describing option
1357 .  man - manual page for option
1358 -  nmax - maximum number of values
1359 
1360    Output Parameter:
1361 +  value - location to copy values
1362 .  nmax - actual number of values found
1363 -  set - PETSC_TRUE if found, else PETSC_FALSE
1364 
1365    Level: beginner
1366 
1367    Notes:
1368    The user should pass in an array of doubles
1369 
1370    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1371 
1372    Concepts: options database^array of strings
1373 
1374 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1375            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1376           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1377           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1378           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1379           PetscOptionsList(), PetscOptionsEList()
1380 @*/
1381 PetscErrorCode  PetscOptionsBoolArray(const char opt[],const char text[],const char man[],PetscBool  value[],PetscInt *n,PetscBool  *set)
1382 {
1383   PetscErrorCode ierr;
1384   PetscInt       i;
1385   PetscOptions   amsopt;
1386 
1387   PetscFunctionBegin;
1388   if (!PetscOptionsPublishCount) {
1389     PetscBool  *vals;
1390 
1391     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL_ARRAY,&amsopt);CHKERRQ(ierr);
1392     ierr = PetscMalloc((*n)*sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1393     vals = (PetscBool*)amsopt->data;
1394     for (i=0; i<*n; i++) vals[i] = value[i];
1395     amsopt->arraylength = *n;
1396   }
1397   ierr = PetscOptionsGetBoolArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1398   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1399     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
1400     for (i=1; i<*n; i++) {
1401       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr);
1402     }
1403     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1404   }
1405   PetscFunctionReturn(0);
1406 }
1407 
1408 
1409 #undef __FUNCT__
1410 #define __FUNCT__ "PetscOptionsHead"
1411 /*@C
1412      PetscOptionsHead - Puts a heading before listing any more published options. Used, for example,
1413             in KSPSetFromOptions_GMRES().
1414 
1415    Logically Collective on the communicator passed in PetscOptionsBegin()
1416 
1417    Input Parameter:
1418 .   head - the heading text
1419 
1420 
1421    Level: intermediate
1422 
1423    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1424 
1425           Can be followed by a call to PetscOptionsTail() in the same function.
1426 
1427    Concepts: options database^subheading
1428 
1429 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1430            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1431           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1432           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1433           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1434           PetscOptionsList(), PetscOptionsEList()
1435 @*/
1436 PetscErrorCode  PetscOptionsHead(const char head[])
1437 {
1438   PetscErrorCode ierr;
1439 
1440   PetscFunctionBegin;
1441   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1442     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  %s\n",head);CHKERRQ(ierr);
1443   }
1444   PetscFunctionReturn(0);
1445 }
1446 
1447 
1448 
1449 
1450 
1451 
1452