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