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