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