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