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