xref: /petsc/src/sys/objects/aoptions.c (revision 536b137f95b6f40d8df0141fed3efeb26b0ec7af)
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 static const char *OptionsHeader = "<head>\n"
377                                    "<script type=\"text/javascript\" src=\"http://www.mcs.anl.gov/research/projects/saws/js/jquery-1.9.1.js\"></script>\n"
378                                    "<script type=\"text/javascript\" src=\"http://www.mcs.anl.gov/research/projects/saws/js/SAWs.js\"></script>\n"
379                                    "<script type=\"text/javascript\" src=\"js/PETSc.js\"></script>\n"
380                                    "<script>\n"
381                                       "jQuery(document).ready(function() {\n"
382                                          "PETSc.getAndDisplayDirectory(null,\"#variablesInfo\")\n"
383                                       "})\n"
384                                   "</script>\n"
385                                   "</head>\n";
386 static const char *OptionsBodyBottom = "<div id=\"variablesInfo\" style=\"float:left\"></div>\n<br>\n</body>";
387 
388 #undef __FUNCT__
389 #define __FUNCT__ "PetscOptionsSAWsInput"
390 /*
391     PetscOptionsSAWsInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the SAWs
392 
393     Bugs:
394 +    All processes must traverse through the exact same set of option queries do to the call to PetscScanString()
395 .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
396 -    Only works for PetscInt == int, PetscReal == double etc
397 
398 
399 */
400 PetscErrorCode PetscOptionsSAWsInput()
401 {
402   PetscErrorCode ierr;
403   PetscOptions   next     = PetscOptionsObject.next;
404   static int     mancount = 0;
405   char           options[16];
406   PetscBool      changedmethod = PETSC_FALSE;
407   char           manname[16],textname[16];
408   char           dir[1024];
409 
410   /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */
411   sprintf(options,"Options_%d",count++);
412 
413   PetscOptionsObject.pprefix = PetscOptionsObject.prefix; /* SAWs will change this, so cannot pass prefix directly */
414 
415   ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s","_title");CHKERRQ(ierr);
416   PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject.title,1,SAWs_READ,SAWs_STRING));
417   ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s","prefix");CHKERRQ(ierr);
418   PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject.pprefix,1,SAWs_READ,SAWs_STRING));
419   PetscStackCallSAWs(SAWs_Register,("/PETSc/Options/ChangedMethod",&changedmethod,1,SAWs_WRITE,SAWs_BOOLEAN));
420 
421   while (next) {
422     sprintf(manname,"_man_%d",mancount);
423     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",manname);CHKERRQ(ierr);
424     PetscStackCallSAWs(SAWs_Register,(dir,&next->man,1,SAWs_READ,SAWs_STRING));
425     sprintf(textname,"_text_%d",mancount++);
426     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",textname);CHKERRQ(ierr);
427     PetscStackCallSAWs(SAWs_Register,(dir,&next->text,1,SAWs_READ,SAWs_STRING));
428 
429     switch (next->type) {
430     case OPTION_HEAD:
431       break;
432     case OPTION_INT_ARRAY:
433     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
434       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_INT));
435       break;
436     case OPTION_REAL_ARRAY:
437     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
438       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_DOUBLE));
439       break;
440     case OPTION_INT:
441     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
442       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_INT));
443       break;
444     case OPTION_REAL:
445     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
446       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_DOUBLE));
447       break;
448     case OPTION_BOOL:
449     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
450       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_BOOLEAN));
451       break;
452     case OPTION_BOOL_ARRAY:
453     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
454       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_BOOLEAN));
455       break;
456     case OPTION_STRING:
457     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
458       PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING));
459       break;
460     case OPTION_STRING_ARRAY:
461     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
462       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_STRING));
463       break;
464     case OPTION_FLIST:
465       {
466       PetscInt ntext;
467       ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
468       PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING));
469       ierr = PetscFunctionListGet(next->flist,(const char***)&next->edata,&ntext);CHKERRQ(ierr);
470       PetscStackCallSAWs(SAWs_Set_Legal_Variable_Values,(dir,ntext,next->edata));
471       }
472       break;
473     case OPTION_ELIST:
474       {
475       PetscInt ntext = next->nlist;
476       ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
477       PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING));
478       ierr = PetscMalloc1((ntext+1),(char***)&next->edata);CHKERRQ(ierr);
479       ierr = PetscMemcpy(next->edata,next->list,ntext*sizeof(char*));CHKERRQ(ierr);
480       PetscStackCallSAWs(SAWs_Set_Legal_Variable_Values,(dir,ntext,next->edata));
481       }
482       break;
483     default:
484       break;
485     }
486     next = next->next;
487   }
488 
489   /* wait until accessor has unlocked the memory */
490   PetscStackCallSAWs(SAWs_Push_Header,("index.html",OptionsHeader));
491   PetscStackCallSAWs(SAWs_Push_Body,("index.html",2,OptionsBodyBottom));
492   ierr = PetscSAWsBlock();CHKERRQ(ierr);
493   PetscStackCallSAWs(SAWs_Pop_Header,("index.html"));
494   PetscStackCallSAWs(SAWs_Pop_Body,("index.html",2));
495 
496   /* determine if any values have been set in GUI */
497   next = PetscOptionsObject.next;
498   while (next) {
499     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
500     PetscStackCallSAWs(SAWs_Selected,(dir,&next->set));
501     next = next->next;
502   }
503 
504   /* reset counter to -2; this updates the screen with the new options for the selected method */
505   if (changedmethod) PetscOptionsPublishCount = -2;
506 
507   PetscStackCallSAWs(SAWs_Delete,("/PETSc/Options"));
508   PetscFunctionReturn(0);
509 }
510 #endif
511 
512 #undef __FUNCT__
513 #define __FUNCT__ "PetscOptionsEnd_Private"
514 PetscErrorCode PetscOptionsEnd_Private(void)
515 {
516   PetscErrorCode ierr;
517   PetscOptions   last;
518   char           option[256],value[1024],tmp[32];
519   size_t         j;
520 
521   PetscFunctionBegin;
522   if (PetscOptionsObject.next) {
523     if (!PetscOptionsPublishCount) {
524 #if defined(PETSC_HAVE_SAWS)
525       ierr = PetscOptionsSAWsInput();CHKERRQ(ierr);
526 #else
527       ierr = PetscOptionsGetFromTextInput();CHKERRQ(ierr);
528 #endif
529     }
530   }
531 
532   ierr = PetscFree(PetscOptionsObject.title);CHKERRQ(ierr);
533   ierr = PetscFree(PetscOptionsObject.prefix);CHKERRQ(ierr);
534 
535   /* reset counter to -2; this updates the screen with the new options for the selected method */
536   if (PetscOptionsObject.changedmethod) PetscOptionsPublishCount = -2;
537   /* reset alreadyprinted flag */
538   PetscOptionsObject.alreadyprinted = PETSC_FALSE;
539   if (PetscOptionsObject.object) PetscOptionsObject.object->optionsprinted = PETSC_TRUE;
540   PetscOptionsObject.object = NULL;
541 
542   while (PetscOptionsObject.next) {
543     if (PetscOptionsObject.next->set) {
544       if (PetscOptionsObject.prefix) {
545         ierr = PetscStrcpy(option,"-");CHKERRQ(ierr);
546         ierr = PetscStrcat(option,PetscOptionsObject.prefix);CHKERRQ(ierr);
547         ierr = PetscStrcat(option,PetscOptionsObject.next->option+1);CHKERRQ(ierr);
548       } else {
549         ierr = PetscStrcpy(option,PetscOptionsObject.next->option);CHKERRQ(ierr);
550       }
551 
552       switch (PetscOptionsObject.next->type) {
553       case OPTION_HEAD:
554         break;
555       case OPTION_INT_ARRAY:
556         sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[0]);
557         for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
558           sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[j]);
559           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
560           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
561         }
562         break;
563       case OPTION_INT:
564         sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject.next->data);
565         break;
566       case OPTION_REAL:
567         sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject.next->data);
568         break;
569       case OPTION_REAL_ARRAY:
570         sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[0]);
571         for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
572           sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[j]);
573           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
574           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
575         }
576         break;
577       case OPTION_BOOL:
578         sprintf(value,"%d",*(int*)PetscOptionsObject.next->data);
579         break;
580       case OPTION_BOOL_ARRAY:
581         sprintf(value,"%d",(int)((PetscBool*)PetscOptionsObject.next->data)[0]);
582         for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
583           sprintf(tmp,"%d",(int)((PetscBool*)PetscOptionsObject.next->data)[j]);
584           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
585           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
586         }
587         break;
588       case OPTION_FLIST:
589       case OPTION_ELIST:
590         ierr = PetscStrcpy(value,(char*)PetscOptionsObject.next->data);CHKERRQ(ierr);
591         break;
592       case OPTION_STRING:
593         ierr = PetscStrcpy(value,(char*)PetscOptionsObject.next->data);CHKERRQ(ierr);
594         break;
595       case OPTION_STRING_ARRAY:
596         sprintf(value,"%s",((char**)PetscOptionsObject.next->data)[0]);
597         for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
598           sprintf(tmp,"%s",((char**)PetscOptionsObject.next->data)[j]);
599           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
600           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
601         }
602         break;
603       }
604       ierr = PetscOptionsSetValue(option,value);CHKERRQ(ierr);
605     }
606     ierr   = PetscFree(PetscOptionsObject.next->text);CHKERRQ(ierr);
607     ierr   = PetscFree(PetscOptionsObject.next->option);CHKERRQ(ierr);
608     ierr   = PetscFree(PetscOptionsObject.next->man);CHKERRQ(ierr);
609     ierr   = PetscFree(PetscOptionsObject.next->edata);CHKERRQ(ierr);
610 
611     if ((PetscOptionsObject.next->type == OPTION_STRING) || (PetscOptionsObject.next->type == OPTION_FLIST) || (PetscOptionsObject.next->type == OPTION_ELIST)){
612       /* must use system free since SAWs may have allocated it */
613       free(PetscOptionsObject.next->data);
614     } else {
615       ierr   = PetscFree(PetscOptionsObject.next->data);CHKERRQ(ierr);
616     }
617 
618     last                    = PetscOptionsObject.next;
619     PetscOptionsObject.next = PetscOptionsObject.next->next;
620     ierr                    = PetscFree(last);CHKERRQ(ierr);
621   }
622   PetscOptionsObject.next = 0;
623   PetscFunctionReturn(0);
624 }
625 
626 #undef __FUNCT__
627 #define __FUNCT__ "PetscOptionsEnum"
628 /*@C
629    PetscOptionsEnum - Gets the enum value for a particular option in the database.
630 
631    Logically Collective on the communicator passed in PetscOptionsBegin()
632 
633    Input Parameters:
634 +  opt - option name
635 .  text - short string that describes the option
636 .  man - manual page with additional information on option
637 .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
638 -  defaultv - the default (current) value
639 
640    Output Parameter:
641 +  value - the  value to return
642 -  set - PETSC_TRUE if found, else PETSC_FALSE
643 
644    Level: beginner
645 
646    Concepts: options database
647 
648    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
649 
650           list is usually something like PCASMTypes or some other predefined list of enum names
651 
652 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
653           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
654           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
655           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
656           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
657           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
658           PetscOptionsFList(), PetscOptionsEList()
659 @*/
660 PetscErrorCode  PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum defaultv,PetscEnum *value,PetscBool  *set)
661 {
662   PetscErrorCode ierr;
663   PetscInt       ntext = 0;
664   PetscInt       tval;
665   PetscBool      tflg;
666 
667   PetscFunctionBegin;
668   while (list[ntext++]) {
669     if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries");
670   }
671   if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix");
672   ntext -= 3;
673   ierr   = PetscOptionsEList(opt,text,man,list,ntext,list[defaultv],&tval,&tflg);CHKERRQ(ierr);
674   /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */
675   if (tflg) *value = (PetscEnum)tval;
676   if (set)  *set   = tflg;
677   PetscFunctionReturn(0);
678 }
679 
680 /* -------------------------------------------------------------------------------------------------------------*/
681 #undef __FUNCT__
682 #define __FUNCT__ "PetscOptionsInt"
683 /*@C
684    PetscOptionsInt - Gets the integer value for a particular option in the database.
685 
686    Logically Collective on the communicator passed in PetscOptionsBegin()
687 
688    Input Parameters:
689 +  opt - option name
690 .  text - short string that describes the option
691 .  man - manual page with additional information on option
692 -  defaultv - the default (current) value, if the user does not provide a value this is returned in value
693 
694    Output Parameter:
695 +  value - the integer value to return
696 -  flg - PETSC_TRUE if found, else PETSC_FALSE
697 
698    Level: beginner
699 
700    Concepts: options database^has int
701 
702    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
703 
704 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
705           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
706           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
707           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
708           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
709           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
710           PetscOptionsFList(), PetscOptionsEList()
711 @*/
712 PetscErrorCode  PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt defaultv,PetscInt *value,PetscBool  *set)
713 {
714   PetscErrorCode ierr;
715   PetscOptions   amsopt;
716 
717   PetscFunctionBegin;
718   if (!PetscOptionsPublishCount) {
719     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr);
720     ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
721 
722     *(PetscInt*)amsopt->data = defaultv;
723   }
724   ierr = PetscOptionsGetInt(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
725   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
726     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr);
727   }
728   PetscFunctionReturn(0);
729 }
730 
731 #undef __FUNCT__
732 #define __FUNCT__ "PetscOptionsString"
733 /*@C
734    PetscOptionsString - Gets the string value for a particular option in the database.
735 
736    Logically Collective on the communicator passed in PetscOptionsBegin()
737 
738    Input Parameters:
739 +  opt - option name
740 .  text - short string that describes the option
741 .  man - manual page with additional information on option
742 .  defaultv - the default (current) value, if the user does not provide a value this is returned in value
743 -  len - length of the result string including null terminator
744 
745    Output Parameter:
746 +  value - the value to return
747 -  flg - PETSC_TRUE if found, else PETSC_FALSE
748 
749    Level: beginner
750 
751    Concepts: options database^has int
752 
753    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
754 
755    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).
756 
757 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
758           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
759           PetscOptionsInt(), PetscOptionsReal(), PetscOptionsBool(),
760           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
761           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
762           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
763           PetscOptionsFList(), PetscOptionsEList()
764 @*/
765 PetscErrorCode  PetscOptionsString(const char opt[],const char text[],const char man[],const char defaultv[],char value[],size_t len,PetscBool  *set)
766 {
767   PetscErrorCode ierr;
768   PetscOptions   amsopt;
769 
770   PetscFunctionBegin;
771   if (!PetscOptionsPublishCount) {
772     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
773     /* must use system malloc since SAWs may free this */
774     ierr = PetscStrdup(defaultv ? defaultv : "",(char**)&amsopt->data);CHKERRQ(ierr);
775   }
776   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
777   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
778     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr);
779   }
780   PetscFunctionReturn(0);
781 }
782 
783 #undef __FUNCT__
784 #define __FUNCT__ "PetscOptionsReal"
785 /*@C
786    PetscOptionsReal - Gets the PetscReal value for a particular option in the database.
787 
788    Logically Collective on the communicator passed in PetscOptionsBegin()
789 
790    Input Parameters:
791 +  opt - option name
792 .  text - short string that describes the option
793 .  man - manual page with additional information on option
794 -  defaultv - the default (current) value, if the user does not provide a value this is returned in value
795 
796    Output Parameter:
797 +  value - the value to return
798 -  flg - PETSC_TRUE if found, else PETSC_FALSE
799 
800    Level: beginner
801 
802    Concepts: options database^has int
803 
804    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
805 
806 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
807           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
808           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
809           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
810           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
811           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
812           PetscOptionsFList(), PetscOptionsEList()
813 @*/
814 PetscErrorCode  PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal defaultv,PetscReal *value,PetscBool  *set)
815 {
816   PetscErrorCode ierr;
817   PetscOptions   amsopt;
818 
819   PetscFunctionBegin;
820   if (!PetscOptionsPublishCount) {
821     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr);
822     ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
823 
824     *(PetscReal*)amsopt->data = defaultv;
825   }
826   ierr = PetscOptionsGetReal(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
827   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
828     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%g>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,(double)defaultv,text,ManSection(man));CHKERRQ(ierr);
829   }
830   PetscFunctionReturn(0);
831 }
832 
833 #undef __FUNCT__
834 #define __FUNCT__ "PetscOptionsScalar"
835 /*@C
836    PetscOptionsScalar - Gets the scalar value for a particular option in the database.
837 
838    Logically Collective on the communicator passed in PetscOptionsBegin()
839 
840    Input Parameters:
841 +  opt - option name
842 .  text - short string that describes the option
843 .  man - manual page with additional information on option
844 -  defaultv - the default (current) value, if the user does not provide a value this is returned in value
845 
846    Output Parameter:
847 +  value - the value to return
848 -  flg - PETSC_TRUE if found, else PETSC_FALSE
849 
850    Level: beginner
851 
852    Concepts: options database^has int
853 
854    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
855 
856 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
857           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
858           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
859           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
860           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
861           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
862           PetscOptionsFList(), PetscOptionsEList()
863 @*/
864 PetscErrorCode  PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar defaultv,PetscScalar *value,PetscBool  *set)
865 {
866   PetscErrorCode ierr;
867 
868   PetscFunctionBegin;
869 #if !defined(PETSC_USE_COMPLEX)
870   ierr = PetscOptionsReal(opt,text,man,defaultv,value,set);CHKERRQ(ierr);
871 #else
872   ierr = PetscOptionsGetScalar(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
873 #endif
874   PetscFunctionReturn(0);
875 }
876 
877 #undef __FUNCT__
878 #define __FUNCT__ "PetscOptionsName"
879 /*@C
880    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
881                       its value is set to false.
882 
883    Logically Collective on the communicator passed in PetscOptionsBegin()
884 
885    Input Parameters:
886 +  opt - option name
887 .  text - short string that describes the option
888 -  man - manual page with additional information on option
889 
890    Output Parameter:
891 .  flg - PETSC_TRUE if found, else PETSC_FALSE
892 
893    Level: beginner
894 
895    Concepts: options database^has int
896 
897    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
898 
899 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
900           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
901           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
902           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
903           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
904           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
905           PetscOptionsFList(), PetscOptionsEList()
906 @*/
907 PetscErrorCode  PetscOptionsName(const char opt[],const char text[],const char man[],PetscBool  *flg)
908 {
909   PetscErrorCode ierr;
910   PetscOptions   amsopt;
911 
912   PetscFunctionBegin;
913   if (!PetscOptionsPublishCount) {
914     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
915     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
916 
917     *(PetscBool*)amsopt->data = PETSC_FALSE;
918   }
919   ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr);
920   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
921     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
922   }
923   PetscFunctionReturn(0);
924 }
925 
926 #undef __FUNCT__
927 #define __FUNCT__ "PetscOptionsFList"
928 /*@C
929      PetscOptionsFList - Puts a list of option values that a single one may be selected from
930 
931    Logically Collective on the communicator passed in PetscOptionsBegin()
932 
933    Input Parameters:
934 +  opt - option name
935 .  text - short string that describes the option
936 .  man - manual page with additional information on option
937 .  list - the possible choices
938 .  defaultv - the default (current) value, if the user does not provide a value this is returned in value
939 -  len - the length of the character array value
940 
941    Output Parameter:
942 +  value - the value to return
943 -  set - PETSC_TRUE if found, else PETSC_FALSE
944 
945    Level: intermediate
946 
947    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
948 
949    See PetscOptionsEList() for when the choices are given in a string array
950 
951    To get a listing of all currently specified options,
952     see PetscOptionsView() or PetscOptionsGetAll()
953 
954    Developer Note: This cannot check for invalid selection because of things like MATAIJ that are not included in the list
955 
956    Concepts: options database^list
957 
958 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
959            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
960           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
961           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
962           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
963           PetscOptionsFList(), PetscOptionsEList(), PetscOptionsEnum()
964 @*/
965 PetscErrorCode  PetscOptionsFList(const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char defaultv[],char value[],size_t len,PetscBool  *set)
966 {
967   PetscErrorCode ierr;
968   PetscOptions   amsopt;
969 
970   PetscFunctionBegin;
971   if (!PetscOptionsPublishCount) {
972     ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_FLIST,&amsopt);CHKERRQ(ierr);
973     /* must use system malloc since SAWs may free this */
974     ierr = PetscStrdup(defaultv ? defaultv : "",(char**)&amsopt->data);CHKERRQ(ierr);
975     amsopt->flist = list;
976   }
977   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
978   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
979     ierr = PetscFunctionListPrintTypes(PetscOptionsObject.comm,stdout,PetscOptionsObject.prefix,opt,ltext,man,list,defaultv);CHKERRQ(ierr);CHKERRQ(ierr);
980   }
981   PetscFunctionReturn(0);
982 }
983 
984 #undef __FUNCT__
985 #define __FUNCT__ "PetscOptionsEList"
986 /*@C
987      PetscOptionsEList - Puts a list of option values that a single one may be selected from
988 
989    Logically Collective on the communicator passed in PetscOptionsBegin()
990 
991    Input Parameters:
992 +  opt - option name
993 .  ltext - short string that describes the option
994 .  man - manual page with additional information on option
995 .  list - the possible choices (one of these must be selected, anything else is invalid)
996 .  ntext - number of choices
997 -  defaultv - the default (current) value, if the user does not provide a value the index of defaultv is returned
998 
999    Output Parameter:
1000 +  value - the index of the value to return
1001 -  set - PETSC_TRUE if found, else PETSC_FALSE
1002 
1003    Level: intermediate
1004 
1005    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1006 
1007    See PetscOptionsFList() for when the choices are given in a PetscFunctionList()
1008 
1009    Concepts: options database^list
1010 
1011 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1012            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1013           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1014           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1015           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1016           PetscOptionsFList(), PetscOptionsEnum()
1017 @*/
1018 PetscErrorCode  PetscOptionsEList(const char opt[],const char ltext[],const char man[],const char *const *list,PetscInt ntext,const char defaultv[],PetscInt *value,PetscBool  *set)
1019 {
1020   PetscErrorCode ierr;
1021   PetscInt       i;
1022   PetscOptions   amsopt;
1023 
1024   PetscFunctionBegin;
1025   if (!PetscOptionsPublishCount) {
1026     ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_ELIST,&amsopt);CHKERRQ(ierr);
1027     /* must use system malloc since SAWs may free this */
1028     ierr = PetscStrdup(defaultv ? defaultv : "",(char**)&amsopt->data);CHKERRQ(ierr);
1029     amsopt->list  = list;
1030     amsopt->nlist = ntext;
1031   }
1032   ierr = PetscOptionsGetEList(PetscOptionsObject.prefix,opt,list,ntext,value,set);CHKERRQ(ierr);
1033   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1034     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s> (choose one of)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv);CHKERRQ(ierr);
1035     for (i=0; i<ntext; i++) {
1036       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s",list[i]);CHKERRQ(ierr);
1037     }
1038     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," (%s)\n",ManSection(man));CHKERRQ(ierr);
1039   }
1040   PetscFunctionReturn(0);
1041 }
1042 
1043 #undef __FUNCT__
1044 #define __FUNCT__ "PetscOptionsBoolGroupBegin"
1045 /*@C
1046      PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for
1047        which at most a single value can be true.
1048 
1049    Logically Collective on the communicator passed in PetscOptionsBegin()
1050 
1051    Input Parameters:
1052 +  opt - option name
1053 .  text - short string that describes the option
1054 -  man - manual page with additional information on option
1055 
1056    Output Parameter:
1057 .  flg - whether that option was set or not
1058 
1059    Level: intermediate
1060 
1061    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1062 
1063    Must be followed by 0 or more PetscOptionsBoolGroup()s and PetscOptionsBoolGroupEnd()
1064 
1065     Concepts: options database^logical group
1066 
1067 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1068            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1069           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1070           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1071           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1072           PetscOptionsFList(), PetscOptionsEList()
1073 @*/
1074 PetscErrorCode  PetscOptionsBoolGroupBegin(const char opt[],const char text[],const char man[],PetscBool  *flg)
1075 {
1076   PetscErrorCode ierr;
1077   PetscOptions   amsopt;
1078 
1079   PetscFunctionBegin;
1080   if (!PetscOptionsPublishCount) {
1081     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1082     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1083 
1084     *(PetscBool*)amsopt->data = PETSC_FALSE;
1085   }
1086   *flg = PETSC_FALSE;
1087   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,NULL);CHKERRQ(ierr);
1088   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1089     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  Pick at most one of -------------\n");CHKERRQ(ierr);
1090     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
1091   }
1092   PetscFunctionReturn(0);
1093 }
1094 
1095 #undef __FUNCT__
1096 #define __FUNCT__ "PetscOptionsBoolGroup"
1097 /*@C
1098      PetscOptionsBoolGroup - One in a series of logical queries on the options database for
1099        which at most a single value can be true.
1100 
1101    Logically Collective on the communicator passed in PetscOptionsBegin()
1102 
1103    Input Parameters:
1104 +  opt - option name
1105 .  text - short string that describes the option
1106 -  man - manual page with additional information on option
1107 
1108    Output Parameter:
1109 .  flg - PETSC_TRUE if found, else PETSC_FALSE
1110 
1111    Level: intermediate
1112 
1113    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1114 
1115    Must follow a PetscOptionsBoolGroupBegin() and preceded a PetscOptionsBoolGroupEnd()
1116 
1117     Concepts: options database^logical group
1118 
1119 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1120            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1121           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1122           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1123           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1124           PetscOptionsFList(), PetscOptionsEList()
1125 @*/
1126 PetscErrorCode  PetscOptionsBoolGroup(const char opt[],const char text[],const char man[],PetscBool  *flg)
1127 {
1128   PetscErrorCode ierr;
1129   PetscOptions   amsopt;
1130 
1131   PetscFunctionBegin;
1132   if (!PetscOptionsPublishCount) {
1133     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1134     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1135 
1136     *(PetscBool*)amsopt->data = PETSC_FALSE;
1137   }
1138   *flg = PETSC_FALSE;
1139   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,NULL);CHKERRQ(ierr);
1140   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1141     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
1142   }
1143   PetscFunctionReturn(0);
1144 }
1145 
1146 #undef __FUNCT__
1147 #define __FUNCT__ "PetscOptionsBoolGroupEnd"
1148 /*@C
1149      PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for
1150        which at most a single value can be true.
1151 
1152    Logically Collective on the communicator passed in PetscOptionsBegin()
1153 
1154    Input Parameters:
1155 +  opt - option name
1156 .  text - short string that describes the option
1157 -  man - manual page with additional information on option
1158 
1159    Output Parameter:
1160 .  flg - PETSC_TRUE if found, else PETSC_FALSE
1161 
1162    Level: intermediate
1163 
1164    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1165 
1166    Must follow a PetscOptionsBoolGroupBegin()
1167 
1168     Concepts: options database^logical group
1169 
1170 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1171            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1172           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1173           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1174           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1175           PetscOptionsFList(), PetscOptionsEList()
1176 @*/
1177 PetscErrorCode  PetscOptionsBoolGroupEnd(const char opt[],const char text[],const char man[],PetscBool  *flg)
1178 {
1179   PetscErrorCode ierr;
1180   PetscOptions   amsopt;
1181 
1182   PetscFunctionBegin;
1183   if (!PetscOptionsPublishCount) {
1184     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1185     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1186 
1187     *(PetscBool*)amsopt->data = PETSC_FALSE;
1188   }
1189   *flg = PETSC_FALSE;
1190   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,NULL);CHKERRQ(ierr);
1191   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1192     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
1193   }
1194   PetscFunctionReturn(0);
1195 }
1196 
1197 #undef __FUNCT__
1198 #define __FUNCT__ "PetscOptionsBool"
1199 /*@C
1200    PetscOptionsBool - Determines if a particular option is in the database with a true or false
1201 
1202    Logically Collective on the communicator passed in PetscOptionsBegin()
1203 
1204    Input Parameters:
1205 +  opt - option name
1206 .  text - short string that describes the option
1207 .  man - manual page with additional information on option
1208 -  deflt - the default value, if the user does not set a value then this value is returned in flg
1209 
1210    Output Parameter:
1211 .  flg - PETSC_TRUE or PETSC_FALSE
1212 .  set - PETSC_TRUE if found, else PETSC_FALSE
1213 
1214    Level: beginner
1215 
1216    Concepts: options database^logical
1217 
1218    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1219 
1220 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1221           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
1222           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
1223           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1224           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1225           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1226           PetscOptionsFList(), PetscOptionsEList()
1227 @*/
1228 PetscErrorCode  PetscOptionsBool(const char opt[],const char text[],const char man[],PetscBool deflt,PetscBool  *flg,PetscBool  *set)
1229 {
1230   PetscErrorCode ierr;
1231   PetscBool      iset;
1232   PetscOptions   amsopt;
1233 
1234   PetscFunctionBegin;
1235   if (!PetscOptionsPublishCount) {
1236     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1237     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1238 
1239     *(PetscBool*)amsopt->data = deflt;
1240   }
1241   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,&iset);CHKERRQ(ierr);
1242   if (!iset) {
1243     if (flg) *flg = deflt;
1244   }
1245   if (set) *set = iset;
1246   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1247     const char *v = PetscBools[deflt];
1248     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: <%s> %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,v,text,ManSection(man));CHKERRQ(ierr);
1249   }
1250   PetscFunctionReturn(0);
1251 }
1252 
1253 #undef __FUNCT__
1254 #define __FUNCT__ "PetscOptionsRealArray"
1255 /*@C
1256    PetscOptionsRealArray - Gets an array of double values for a particular
1257    option in the database. The values must be separated with commas with
1258    no intervening spaces.
1259 
1260    Logically Collective on the communicator passed in PetscOptionsBegin()
1261 
1262    Input Parameters:
1263 +  opt - the option one is seeking
1264 .  text - short string describing option
1265 .  man - manual page for option
1266 -  nmax - maximum number of values
1267 
1268    Output Parameter:
1269 +  value - location to copy values
1270 .  nmax - actual number of values found
1271 -  set - PETSC_TRUE if found, else PETSC_FALSE
1272 
1273    Level: beginner
1274 
1275    Notes:
1276    The user should pass in an array of doubles
1277 
1278    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1279 
1280    Concepts: options database^array of strings
1281 
1282 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1283            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1284           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1285           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1286           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1287           PetscOptionsFList(), PetscOptionsEList()
1288 @*/
1289 PetscErrorCode  PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool  *set)
1290 {
1291   PetscErrorCode ierr;
1292   PetscInt       i;
1293   PetscOptions   amsopt;
1294 
1295   PetscFunctionBegin;
1296   if (!PetscOptionsPublishCount) {
1297     PetscReal *vals;
1298 
1299     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr);
1300     ierr = PetscMalloc1((*n),(PetscReal**)&amsopt->data);CHKERRQ(ierr);
1301     vals = (PetscReal*)amsopt->data;
1302     for (i=0; i<*n; i++) vals[i] = value[i];
1303     amsopt->arraylength = *n;
1304   }
1305   ierr = PetscOptionsGetRealArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1306   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1307     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%g",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,(double)value[0]);CHKERRQ(ierr);
1308     for (i=1; i<*n; i++) {
1309       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%g",(double)value[i]);CHKERRQ(ierr);
1310     }
1311     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1312   }
1313   PetscFunctionReturn(0);
1314 }
1315 
1316 
1317 #undef __FUNCT__
1318 #define __FUNCT__ "PetscOptionsIntArray"
1319 /*@C
1320    PetscOptionsIntArray - Gets an array of integers for a particular
1321    option in the database.
1322 
1323    Logically Collective on the communicator passed in PetscOptionsBegin()
1324 
1325    Input Parameters:
1326 +  opt - the option one is seeking
1327 .  text - short string describing option
1328 .  man - manual page for option
1329 -  n - maximum number of values
1330 
1331    Output Parameter:
1332 +  value - location to copy values
1333 .  n - actual number of values found
1334 -  set - PETSC_TRUE if found, else PETSC_FALSE
1335 
1336    Level: beginner
1337 
1338    Notes:
1339    The array can be passed as
1340    a comma seperated list:                                 0,1,2,3,4,5,6,7
1341    a range (start-end+1):                                  0-8
1342    a range with given increment (start-end+1:inc):         0-7:2
1343    a combination of values and ranges seperated by commas: 0,1-8,8-15:2
1344 
1345    There must be no intervening spaces between the values.
1346 
1347    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1348 
1349    Concepts: options database^array of ints
1350 
1351 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1352            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1353           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1354           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1355           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1356           PetscOptionsFList(), PetscOptionsEList(), PetscOptionsRealArray()
1357 @*/
1358 PetscErrorCode  PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool  *set)
1359 {
1360   PetscErrorCode ierr;
1361   PetscInt       i;
1362   PetscOptions   amsopt;
1363 
1364   PetscFunctionBegin;
1365   if (!PetscOptionsPublishCount) {
1366     PetscInt *vals;
1367 
1368     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr);
1369     ierr = PetscMalloc1((*n),(PetscInt**)&amsopt->data);CHKERRQ(ierr);
1370     vals = (PetscInt*)amsopt->data;
1371     for (i=0; i<*n; i++) vals[i] = value[i];
1372     amsopt->arraylength = *n;
1373   }
1374   ierr = PetscOptionsGetIntArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1375   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1376     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,value[0]);CHKERRQ(ierr);
1377     for (i=1; i<*n; i++) {
1378       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr);
1379     }
1380     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1381   }
1382   PetscFunctionReturn(0);
1383 }
1384 
1385 #undef __FUNCT__
1386 #define __FUNCT__ "PetscOptionsStringArray"
1387 /*@C
1388    PetscOptionsStringArray - Gets an array of string values for a particular
1389    option in the database. The values must be separated with commas with
1390    no intervening spaces.
1391 
1392    Logically Collective on the communicator passed in PetscOptionsBegin()
1393 
1394    Input Parameters:
1395 +  opt - the option one is seeking
1396 .  text - short string describing option
1397 .  man - manual page for option
1398 -  nmax - maximum number of strings
1399 
1400    Output Parameter:
1401 +  value - location to copy strings
1402 .  nmax - actual number of strings found
1403 -  set - PETSC_TRUE if found, else PETSC_FALSE
1404 
1405    Level: beginner
1406 
1407    Notes:
1408    The user should pass in an array of pointers to char, to hold all the
1409    strings returned by this function.
1410 
1411    The user is responsible for deallocating the strings that are
1412    returned. The Fortran interface for this routine is not supported.
1413 
1414    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1415 
1416    Concepts: options database^array of strings
1417 
1418 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1419            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1420           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1421           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1422           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1423           PetscOptionsFList(), PetscOptionsEList()
1424 @*/
1425 PetscErrorCode  PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool  *set)
1426 {
1427   PetscErrorCode ierr;
1428   PetscOptions   amsopt;
1429 
1430   PetscFunctionBegin;
1431   if (!PetscOptionsPublishCount) {
1432     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING_ARRAY,&amsopt);CHKERRQ(ierr);
1433     ierr = PetscMalloc1((*nmax),(char**)&amsopt->data);CHKERRQ(ierr);
1434 
1435     amsopt->arraylength = *nmax;
1436   }
1437   ierr = PetscOptionsGetStringArray(PetscOptionsObject.prefix,opt,value,nmax,set);CHKERRQ(ierr);
1438   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1439     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
1440   }
1441   PetscFunctionReturn(0);
1442 }
1443 
1444 #undef __FUNCT__
1445 #define __FUNCT__ "PetscOptionsBoolArray"
1446 /*@C
1447    PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular
1448    option in the database. The values must be separated with commas with
1449    no intervening spaces.
1450 
1451    Logically Collective on the communicator passed in PetscOptionsBegin()
1452 
1453    Input Parameters:
1454 +  opt - the option one is seeking
1455 .  text - short string describing option
1456 .  man - manual page for option
1457 -  nmax - maximum number of values
1458 
1459    Output Parameter:
1460 +  value - location to copy values
1461 .  nmax - actual number of values found
1462 -  set - PETSC_TRUE if found, else PETSC_FALSE
1463 
1464    Level: beginner
1465 
1466    Notes:
1467    The user should pass in an array of doubles
1468 
1469    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1470 
1471    Concepts: options database^array of strings
1472 
1473 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1474            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1475           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1476           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1477           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1478           PetscOptionsFList(), PetscOptionsEList()
1479 @*/
1480 PetscErrorCode  PetscOptionsBoolArray(const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set)
1481 {
1482   PetscErrorCode ierr;
1483   PetscInt       i;
1484   PetscOptions   amsopt;
1485 
1486   PetscFunctionBegin;
1487   if (!PetscOptionsPublishCount) {
1488     PetscBool *vals;
1489 
1490     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_BOOL_ARRAY,&amsopt);CHKERRQ(ierr);
1491     ierr = PetscMalloc1((*n),(PetscBool**)&amsopt->data);CHKERRQ(ierr);
1492     vals = (PetscBool*)amsopt->data;
1493     for (i=0; i<*n; i++) vals[i] = value[i];
1494     amsopt->arraylength = *n;
1495   }
1496   ierr = PetscOptionsGetBoolArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1497   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1498     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,value[0]);CHKERRQ(ierr);
1499     for (i=1; i<*n; i++) {
1500       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr);
1501     }
1502     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1503   }
1504   PetscFunctionReturn(0);
1505 }
1506 
1507 #undef __FUNCT__
1508 #define __FUNCT__ "PetscOptionsViewer"
1509 /*@C
1510    PetscOptionsViewer - Gets a viewer appropriate for the type indicated by the user
1511 
1512    Logically Collective on the communicator passed in PetscOptionsBegin()
1513 
1514    Input Parameters:
1515 +  opt - option name
1516 .  text - short string that describes the option
1517 -  man - manual page with additional information on option
1518 
1519    Output Parameter:
1520 +  viewer - the viewer
1521 -  set - PETSC_TRUE if found, else PETSC_FALSE
1522 
1523    Level: beginner
1524 
1525    Concepts: options database^has int
1526 
1527    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1528 
1529    See PetscOptionsGetVieweer() for the format of the supplied viewer and its options
1530 
1531 .seealso: PetscOptionsGetViewer(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1532           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
1533           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
1534           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1535           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1536           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1537           PetscOptionsFList(), PetscOptionsEList()
1538 @*/
1539 PetscErrorCode  PetscOptionsViewer(const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool  *set)
1540 {
1541   PetscErrorCode ierr;
1542   PetscOptions   amsopt;
1543 
1544   PetscFunctionBegin;
1545   if (!PetscOptionsPublishCount) {
1546     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
1547     /* must use system malloc since SAWs may free this */
1548     ierr = PetscStrdup("",(char**)&amsopt->data);CHKERRQ(ierr);
1549   }
1550   ierr = PetscOptionsGetViewer(PetscOptionsObject.comm,PetscOptionsObject.prefix,opt,viewer,format,set);CHKERRQ(ierr);
1551   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1552     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,"",text,ManSection(man));CHKERRQ(ierr);
1553   }
1554   PetscFunctionReturn(0);
1555 }
1556 
1557 
1558 #undef __FUNCT__
1559 #define __FUNCT__ "PetscOptionsHead"
1560 /*@C
1561      PetscOptionsHead - Puts a heading before listing any more published options. Used, for example,
1562             in KSPSetFromOptions_GMRES().
1563 
1564    Logically Collective on the communicator passed in PetscOptionsBegin()
1565 
1566    Input Parameter:
1567 .   head - the heading text
1568 
1569 
1570    Level: intermediate
1571 
1572    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1573 
1574           Can be followed by a call to PetscOptionsTail() in the same function.
1575 
1576    Concepts: options database^subheading
1577 
1578 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1579            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1580           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1581           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1582           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1583           PetscOptionsFList(), PetscOptionsEList()
1584 @*/
1585 PetscErrorCode  PetscOptionsHead(const char head[])
1586 {
1587   PetscErrorCode ierr;
1588 
1589   PetscFunctionBegin;
1590   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1591     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  %s\n",head);CHKERRQ(ierr);
1592   }
1593   PetscFunctionReturn(0);
1594 }
1595 
1596 
1597 
1598 
1599 
1600 
1601