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