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