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