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