xref: /petsc/src/sys/objects/aoptions.c (revision 426f447e91c47e482e5f1c1f47e35587cd53719d)
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=\"height:550px;overflow:scroll;\"></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     PetscBool wasset;
720 
721     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr);
722     ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
723     *(PetscInt*)amsopt->data = defaultv;
724 
725     ierr = PetscOptionsGetInt(PetscOptionsObject.prefix,opt,&defaultv,&wasset);CHKERRQ(ierr);
726     if (wasset) {
727       *(PetscInt*)amsopt->data = defaultv;
728     }
729   }
730   ierr = PetscOptionsGetInt(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
731   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
732     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr);
733   }
734   PetscFunctionReturn(0);
735 }
736 
737 #undef __FUNCT__
738 #define __FUNCT__ "PetscOptionsString"
739 /*@C
740    PetscOptionsString - Gets the string value for a particular option in the database.
741 
742    Logically Collective on the communicator passed in PetscOptionsBegin()
743 
744    Input Parameters:
745 +  opt - option name
746 .  text - short string that describes the option
747 .  man - manual page with additional information on option
748 .  defaultv - the default (current) value, if the user does not provide a value this is returned in value
749 -  len - length of the result string including null terminator
750 
751    Output Parameter:
752 +  value - the value to return
753 -  flg - PETSC_TRUE if found, else PETSC_FALSE
754 
755    Level: beginner
756 
757    Concepts: options database^has int
758 
759    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
760 
761    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).
762 
763 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
764           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
765           PetscOptionsInt(), PetscOptionsReal(), PetscOptionsBool(),
766           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
767           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
768           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
769           PetscOptionsFList(), PetscOptionsEList()
770 @*/
771 PetscErrorCode  PetscOptionsString(const char opt[],const char text[],const char man[],const char defaultv[],char value[],size_t len,PetscBool  *set)
772 {
773   PetscErrorCode ierr;
774   PetscOptions   amsopt;
775 
776   PetscFunctionBegin;
777   if (!PetscOptionsPublishCount) {
778     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
779     /* must use system malloc since SAWs may free this */
780     ierr = PetscStrdup(defaultv ? defaultv : "",(char**)&amsopt->data);CHKERRQ(ierr);
781   }
782   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
783   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
784     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr);
785   }
786   PetscFunctionReturn(0);
787 }
788 
789 #undef __FUNCT__
790 #define __FUNCT__ "PetscOptionsReal"
791 /*@C
792    PetscOptionsReal - Gets the PetscReal value for a particular option in the database.
793 
794    Logically Collective on the communicator passed in PetscOptionsBegin()
795 
796    Input Parameters:
797 +  opt - option name
798 .  text - short string that describes the option
799 .  man - manual page with additional information on option
800 -  defaultv - the default (current) value, if the user does not provide a value this is returned in value
801 
802    Output Parameter:
803 +  value - the value to return
804 -  flg - PETSC_TRUE if found, else PETSC_FALSE
805 
806    Level: beginner
807 
808    Concepts: options database^has int
809 
810    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
811 
812 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
813           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
814           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
815           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
816           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
817           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
818           PetscOptionsFList(), PetscOptionsEList()
819 @*/
820 PetscErrorCode  PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal defaultv,PetscReal *value,PetscBool  *set)
821 {
822   PetscErrorCode ierr;
823   PetscOptions   amsopt;
824 
825   PetscFunctionBegin;
826   if (!PetscOptionsPublishCount) {
827     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr);
828     ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
829 
830     *(PetscReal*)amsopt->data = defaultv;
831   }
832   ierr = PetscOptionsGetReal(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
833   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
834     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%g>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,(double)defaultv,text,ManSection(man));CHKERRQ(ierr);
835   }
836   PetscFunctionReturn(0);
837 }
838 
839 #undef __FUNCT__
840 #define __FUNCT__ "PetscOptionsScalar"
841 /*@C
842    PetscOptionsScalar - Gets the scalar value for a particular option in the database.
843 
844    Logically Collective on the communicator passed in PetscOptionsBegin()
845 
846    Input Parameters:
847 +  opt - option name
848 .  text - short string that describes the option
849 .  man - manual page with additional information on option
850 -  defaultv - the default (current) value, if the user does not provide a value this is returned in value
851 
852    Output Parameter:
853 +  value - the value to return
854 -  flg - PETSC_TRUE if found, else PETSC_FALSE
855 
856    Level: beginner
857 
858    Concepts: options database^has int
859 
860    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
861 
862 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
863           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
864           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
865           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
866           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
867           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
868           PetscOptionsFList(), PetscOptionsEList()
869 @*/
870 PetscErrorCode  PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar defaultv,PetscScalar *value,PetscBool  *set)
871 {
872   PetscErrorCode ierr;
873 
874   PetscFunctionBegin;
875 #if !defined(PETSC_USE_COMPLEX)
876   ierr = PetscOptionsReal(opt,text,man,defaultv,value,set);CHKERRQ(ierr);
877 #else
878   ierr = PetscOptionsGetScalar(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
879 #endif
880   PetscFunctionReturn(0);
881 }
882 
883 #undef __FUNCT__
884 #define __FUNCT__ "PetscOptionsName"
885 /*@C
886    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
887                       its value is set to false.
888 
889    Logically Collective on the communicator passed in PetscOptionsBegin()
890 
891    Input Parameters:
892 +  opt - option name
893 .  text - short string that describes the option
894 -  man - manual page with additional information on option
895 
896    Output Parameter:
897 .  flg - PETSC_TRUE if found, else PETSC_FALSE
898 
899    Level: beginner
900 
901    Concepts: options database^has int
902 
903    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
904 
905 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
906           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
907           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
908           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
909           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
910           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
911           PetscOptionsFList(), PetscOptionsEList()
912 @*/
913 PetscErrorCode  PetscOptionsName(const char opt[],const char text[],const char man[],PetscBool  *flg)
914 {
915   PetscErrorCode ierr;
916   PetscOptions   amsopt;
917 
918   PetscFunctionBegin;
919   if (!PetscOptionsPublishCount) {
920     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
921     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
922 
923     *(PetscBool*)amsopt->data = PETSC_FALSE;
924   }
925   ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr);
926   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
927     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
928   }
929   PetscFunctionReturn(0);
930 }
931 
932 #undef __FUNCT__
933 #define __FUNCT__ "PetscOptionsFList"
934 /*@C
935      PetscOptionsFList - Puts a list of option values that a single one may be selected from
936 
937    Logically Collective on the communicator passed in PetscOptionsBegin()
938 
939    Input Parameters:
940 +  opt - option name
941 .  text - short string that describes the option
942 .  man - manual page with additional information on option
943 .  list - the possible choices
944 .  defaultv - the default (current) value, if the user does not provide a value this is returned in value
945 -  len - the length of the character array value
946 
947    Output Parameter:
948 +  value - the value to return
949 -  set - PETSC_TRUE if found, else PETSC_FALSE
950 
951    Level: intermediate
952 
953    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
954 
955    See PetscOptionsEList() for when the choices are given in a string array
956 
957    To get a listing of all currently specified options,
958     see PetscOptionsView() or PetscOptionsGetAll()
959 
960    Developer Note: This cannot check for invalid selection because of things like MATAIJ that are not included in the list
961 
962    Concepts: options database^list
963 
964 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
965            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
966           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
967           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
968           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
969           PetscOptionsFList(), PetscOptionsEList(), PetscOptionsEnum()
970 @*/
971 PetscErrorCode  PetscOptionsFList(const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char defaultv[],char value[],size_t len,PetscBool  *set)
972 {
973   PetscErrorCode ierr;
974   PetscOptions   amsopt;
975 
976   PetscFunctionBegin;
977   if (!PetscOptionsPublishCount) {
978     ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_FLIST,&amsopt);CHKERRQ(ierr);
979     /* must use system malloc since SAWs may free this */
980     ierr = PetscStrdup(defaultv ? defaultv : "",(char**)&amsopt->data);CHKERRQ(ierr);
981     amsopt->flist = list;
982   }
983   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
984   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
985     ierr = PetscFunctionListPrintTypes(PetscOptionsObject.comm,stdout,PetscOptionsObject.prefix,opt,ltext,man,list,defaultv);CHKERRQ(ierr);CHKERRQ(ierr);
986   }
987   PetscFunctionReturn(0);
988 }
989 
990 #undef __FUNCT__
991 #define __FUNCT__ "PetscOptionsEList"
992 /*@C
993      PetscOptionsEList - Puts a list of option values that a single one may be selected from
994 
995    Logically Collective on the communicator passed in PetscOptionsBegin()
996 
997    Input Parameters:
998 +  opt - option name
999 .  ltext - short string that describes the option
1000 .  man - manual page with additional information on option
1001 .  list - the possible choices (one of these must be selected, anything else is invalid)
1002 .  ntext - number of choices
1003 -  defaultv - the default (current) value, if the user does not provide a value the index of defaultv is returned
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 defaultv[],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(defaultv ? defaultv : "",(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,defaultv);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