xref: /petsc/src/sys/objects/aoptions.c (revision 83355fc50ac5a4cffed6ae96491f391d3620b406)
17d0a6c19SBarry Smith 
253acd3b1SBarry Smith /*
33fc1eb6aSBarry Smith    Implements the higher-level options database querying methods. These are self-documenting and can attach at runtime to
43fc1eb6aSBarry Smith    GUI code to display the options and get values from the users.
553acd3b1SBarry Smith 
653acd3b1SBarry Smith */
753acd3b1SBarry Smith 
8afcb2eb5SJed Brown #include <petsc-private/petscimpl.h>        /*I  "petscsys.h"   I*/
9665c2dedSJed Brown #include <petscviewer.h>
1053acd3b1SBarry Smith 
112aa6d131SJed Brown #define ManSection(str) ((str) ? (str) : "None")
122aa6d131SJed Brown 
1353acd3b1SBarry Smith /*
1453acd3b1SBarry Smith     Keep a linked list of options that have been posted and we are waiting for
153fc1eb6aSBarry Smith    user selection. See the manual page for PetscOptionsBegin()
1653acd3b1SBarry Smith 
1753acd3b1SBarry Smith     Eventually we'll attach this beast to a MPI_Comm
1853acd3b1SBarry Smith */
19e55864a3SBarry Smith 
2053acd3b1SBarry Smith 
2153acd3b1SBarry Smith #undef __FUNCT__
2253acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsBegin_Private"
2353acd3b1SBarry Smith /*
2453acd3b1SBarry Smith     Handles setting up the data structure in a call to PetscOptionsBegin()
2553acd3b1SBarry Smith */
26e55864a3SBarry Smith PetscErrorCode PetscOptionsBegin_Private(PetscOptionsObjectType *PetscOptionsObject,MPI_Comm comm,const char prefix[],const char title[],const char mansec[])
2753acd3b1SBarry Smith {
2853acd3b1SBarry Smith   PetscErrorCode ierr;
2953acd3b1SBarry Smith 
3053acd3b1SBarry Smith   PetscFunctionBegin;
31e55864a3SBarry Smith   PetscOptionsObject->next          = 0;
32e55864a3SBarry Smith   PetscOptionsObject->comm          = comm;
33e55864a3SBarry Smith   PetscOptionsObject->changedmethod = PETSC_FALSE;
34a297a907SKarl Rupp 
35e55864a3SBarry Smith   ierr = PetscStrallocpy(prefix,&PetscOptionsObject->prefix);CHKERRQ(ierr);
36e55864a3SBarry Smith   ierr = PetscStrallocpy(title,&PetscOptionsObject->title);CHKERRQ(ierr);
3753acd3b1SBarry Smith 
38e55864a3SBarry Smith   ierr = PetscOptionsHasName(NULL,"-help",&PetscOptionsObject->printhelp);CHKERRQ(ierr);
39e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1) {
40e55864a3SBarry Smith     if (!PetscOptionsObject->alreadyprinted) {
4153acd3b1SBarry Smith       ierr = (*PetscHelpPrintf)(comm,"%s -------------------------------------------------\n",title);CHKERRQ(ierr);
4253acd3b1SBarry Smith     }
4361b37b28SSatish Balay   }
4453acd3b1SBarry Smith   PetscFunctionReturn(0);
4553acd3b1SBarry Smith }
4653acd3b1SBarry Smith 
473194b578SJed Brown #undef __FUNCT__
483194b578SJed Brown #define __FUNCT__ "PetscObjectOptionsBegin_Private"
493194b578SJed Brown /*
503194b578SJed Brown     Handles setting up the data structure in a call to PetscObjectOptionsBegin()
513194b578SJed Brown */
52e55864a3SBarry Smith PetscErrorCode PetscObjectOptionsBegin_Private(PetscOptionsObjectType *PetscOptionsObject,PetscObject obj)
533194b578SJed Brown {
543194b578SJed Brown   PetscErrorCode ierr;
553194b578SJed Brown   char           title[256];
563194b578SJed Brown   PetscBool      flg;
573194b578SJed Brown 
583194b578SJed Brown   PetscFunctionBegin;
593194b578SJed Brown   PetscValidHeader(obj,1);
60e55864a3SBarry Smith   PetscOptionsObject->object         = obj;
61e55864a3SBarry Smith   PetscOptionsObject->alreadyprinted = obj->optionsprinted;
62a297a907SKarl Rupp 
633194b578SJed Brown   ierr = PetscStrcmp(obj->description,obj->class_name,&flg);CHKERRQ(ierr);
643194b578SJed Brown   if (flg) {
658caf3d72SBarry Smith     ierr = PetscSNPrintf(title,sizeof(title),"%s options",obj->class_name);CHKERRQ(ierr);
663194b578SJed Brown   } else {
678caf3d72SBarry Smith     ierr = PetscSNPrintf(title,sizeof(title),"%s (%s) options",obj->description,obj->class_name);CHKERRQ(ierr);
683194b578SJed Brown   }
69e55864a3SBarry Smith   ierr = PetscOptionsBegin_Private(PetscOptionsObject,obj->comm,obj->prefix,title,obj->mansec);CHKERRQ(ierr);
703194b578SJed Brown   PetscFunctionReturn(0);
713194b578SJed Brown }
723194b578SJed Brown 
7353acd3b1SBarry Smith /*
7453acd3b1SBarry Smith      Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd()
7553acd3b1SBarry Smith */
7653acd3b1SBarry Smith #undef __FUNCT__
7753acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsCreate_Private"
78e55864a3SBarry Smith static int PetscOptionsCreate_Private(PetscOptionsObjectType *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscOptionType t,PetscOptions *amsopt)
7953acd3b1SBarry Smith {
8053acd3b1SBarry Smith   int          ierr;
8153acd3b1SBarry Smith   PetscOptions next;
823be6e4c3SJed Brown   PetscBool    valid;
8353acd3b1SBarry Smith 
8453acd3b1SBarry Smith   PetscFunctionBegin;
853be6e4c3SJed Brown   ierr = PetscOptionsValidKey(opt,&valid);CHKERRQ(ierr);
863be6e4c3SJed Brown   if (!valid) SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_ARG_INCOMP,"The option '%s' is not a valid key",opt);
873be6e4c3SJed Brown 
88b00a9115SJed Brown   ierr            = PetscNew(amsopt);CHKERRQ(ierr);
8953acd3b1SBarry Smith   (*amsopt)->next = 0;
9053acd3b1SBarry Smith   (*amsopt)->set  = PETSC_FALSE;
916356e834SBarry Smith   (*amsopt)->type = t;
9253acd3b1SBarry Smith   (*amsopt)->data = 0;
9361b37b28SSatish Balay 
9453acd3b1SBarry Smith   ierr = PetscStrallocpy(text,&(*amsopt)->text);CHKERRQ(ierr);
9553acd3b1SBarry Smith   ierr = PetscStrallocpy(opt,&(*amsopt)->option);CHKERRQ(ierr);
966356e834SBarry Smith   ierr = PetscStrallocpy(man,&(*amsopt)->man);CHKERRQ(ierr);
9753acd3b1SBarry Smith 
98e55864a3SBarry Smith   if (!PetscOptionsObject->next) PetscOptionsObject->next = *amsopt;
99a297a907SKarl Rupp   else {
100e55864a3SBarry Smith     next = PetscOptionsObject->next;
10153acd3b1SBarry Smith     while (next->next) next = next->next;
10253acd3b1SBarry Smith     next->next = *amsopt;
10353acd3b1SBarry Smith   }
10453acd3b1SBarry Smith   PetscFunctionReturn(0);
10553acd3b1SBarry Smith }
10653acd3b1SBarry Smith 
10753acd3b1SBarry Smith #undef __FUNCT__
108aee2cecaSBarry Smith #define __FUNCT__ "PetscScanString"
109aee2cecaSBarry Smith /*
1103fc1eb6aSBarry Smith     PetscScanString -  Gets user input via stdin from process and broadcasts to all processes
1113fc1eb6aSBarry Smith 
1123fc1eb6aSBarry Smith     Collective on MPI_Comm
1133fc1eb6aSBarry Smith 
1143fc1eb6aSBarry Smith    Input Parameters:
1153fc1eb6aSBarry Smith +     commm - communicator for the broadcast, must be PETSC_COMM_WORLD
1163fc1eb6aSBarry Smith .     n - length of the string, must be the same on all processes
1173fc1eb6aSBarry Smith -     str - location to store input
118aee2cecaSBarry Smith 
119aee2cecaSBarry Smith     Bugs:
120aee2cecaSBarry Smith .   Assumes process 0 of the given communicator has access to stdin
121aee2cecaSBarry Smith 
122aee2cecaSBarry Smith */
1233fc1eb6aSBarry Smith static PetscErrorCode PetscScanString(MPI_Comm comm,size_t n,char str[])
124aee2cecaSBarry Smith {
125330cf3c9SBarry Smith   size_t         i;
126aee2cecaSBarry Smith   char           c;
1273fc1eb6aSBarry Smith   PetscMPIInt    rank,nm;
128aee2cecaSBarry Smith   PetscErrorCode ierr;
129aee2cecaSBarry Smith 
130aee2cecaSBarry Smith   PetscFunctionBegin;
131aee2cecaSBarry Smith   ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
132aee2cecaSBarry Smith   if (!rank) {
133aee2cecaSBarry Smith     c = (char) getchar();
134aee2cecaSBarry Smith     i = 0;
135aee2cecaSBarry Smith     while (c != '\n' && i < n-1) {
136aee2cecaSBarry Smith       str[i++] = c;
137aee2cecaSBarry Smith       c = (char)getchar();
138aee2cecaSBarry Smith     }
139aee2cecaSBarry Smith     str[i] = 0;
140aee2cecaSBarry Smith   }
1414dc2109aSBarry Smith   ierr = PetscMPIIntCast(n,&nm);CHKERRQ(ierr);
1423fc1eb6aSBarry Smith   ierr = MPI_Bcast(str,nm,MPI_CHAR,0,comm);CHKERRQ(ierr);
143aee2cecaSBarry Smith   PetscFunctionReturn(0);
144aee2cecaSBarry Smith }
145aee2cecaSBarry Smith 
146aca04275SShao-Ching Huang #undef __FUNCT__
147aca04275SShao-Ching Huang #define __FUNCT__ "PetscStrdup"
1485b02f95dSBarry Smith /*
1495b02f95dSBarry Smith     This is needed because certain strings may be freed by SAWs, hence we cannot use PetscStrallocpy()
1505b02f95dSBarry Smith */
1515b02f95dSBarry Smith static PetscErrorCode  PetscStrdup(const char s[],char *t[])
1525b02f95dSBarry Smith {
1535b02f95dSBarry Smith   PetscErrorCode ierr;
1545b02f95dSBarry Smith   size_t         len;
1555b02f95dSBarry Smith   char           *tmp = 0;
1565b02f95dSBarry Smith 
1575b02f95dSBarry Smith   PetscFunctionBegin;
1585b02f95dSBarry Smith   if (s) {
1595b02f95dSBarry Smith     ierr = PetscStrlen(s,&len);CHKERRQ(ierr);
160ee48884fSBarry Smith     tmp = (char*) malloc((len+1)*sizeof(char*));
1615b02f95dSBarry Smith     if (!tmp) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_MEM,"No memory to duplicate string");
1625b02f95dSBarry Smith     ierr = PetscStrcpy(tmp,s);CHKERRQ(ierr);
1635b02f95dSBarry Smith   }
1645b02f95dSBarry Smith   *t = tmp;
1655b02f95dSBarry Smith   PetscFunctionReturn(0);
1665b02f95dSBarry Smith }
1675b02f95dSBarry Smith 
1685b02f95dSBarry Smith 
169aee2cecaSBarry Smith #undef __FUNCT__
170aee2cecaSBarry Smith #define __FUNCT__ "PetscOptionsGetFromTextInput"
171aee2cecaSBarry Smith /*
1723cc1e11dSBarry Smith     PetscOptionsGetFromTextInput - Presents all the PETSc Options processed by the program so the user may change them at runtime
173aee2cecaSBarry Smith 
174aee2cecaSBarry Smith     Notes: this isn't really practical, it is just to demonstrate the principle
175aee2cecaSBarry Smith 
1767781c08eSBarry Smith     A carriage return indicates no change from the default; but this like -ksp_monitor <stdout>  the default is actually not stdout the default
1777781c08eSBarry Smith     is to do nothing so to get it to use stdout you need to type stdout. This is kind of bug?
1787781c08eSBarry Smith 
179aee2cecaSBarry Smith     Bugs:
1807781c08eSBarry Smith +    All processes must traverse through the exact same set of option queries due to the call to PetscScanString()
1813cc1e11dSBarry Smith .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
182aee2cecaSBarry Smith -    Only works for PetscInt == int, PetscReal == double etc
183aee2cecaSBarry Smith 
1843cc1e11dSBarry Smith     Developer Notes: Normally the GUI that presents the options the user and retrieves the values would be running in a different
1853cc1e11dSBarry Smith      address space and communicating with the PETSc program
1863cc1e11dSBarry Smith 
187aee2cecaSBarry Smith */
188e55864a3SBarry Smith PetscErrorCode PetscOptionsGetFromTextInput(PetscOptionsObjectType *PetscOptionsObject)
1896356e834SBarry Smith {
1906356e834SBarry Smith   PetscErrorCode ierr;
191e55864a3SBarry Smith   PetscOptions   next = PetscOptionsObject->next;
1926356e834SBarry Smith   char           str[512];
1937781c08eSBarry Smith   PetscBool      bid;
194a4404d99SBarry Smith   PetscReal      ir,*valr;
195330cf3c9SBarry Smith   PetscInt       *vald;
196330cf3c9SBarry Smith   size_t         i;
1976356e834SBarry Smith 
198e55864a3SBarry Smith   ierr = (*PetscPrintf)(PETSC_COMM_WORLD,"%s -------------------------------------------------\n",PetscOptionsObject->title);CHKERRQ(ierr);
1996356e834SBarry Smith   while (next) {
2006356e834SBarry Smith     switch (next->type) {
2016356e834SBarry Smith     case OPTION_HEAD:
2026356e834SBarry Smith       break;
203e26ddf31SBarry Smith     case OPTION_INT_ARRAY:
204e55864a3SBarry Smith       ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1);CHKERRQ(ierr);
205e26ddf31SBarry Smith       vald = (PetscInt*) next->data;
206e26ddf31SBarry Smith       for (i=0; i<next->arraylength; i++) {
207e26ddf31SBarry Smith         ierr = PetscPrintf(PETSC_COMM_WORLD,"%d",vald[i]);CHKERRQ(ierr);
208e26ddf31SBarry Smith         if (i < next->arraylength-1) {
209e26ddf31SBarry Smith           ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr);
210e26ddf31SBarry Smith         }
211e26ddf31SBarry Smith       }
212e26ddf31SBarry Smith       ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s) ",next->text,next->man);CHKERRQ(ierr);
213e26ddf31SBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
214e26ddf31SBarry Smith       if (str[0]) {
215e26ddf31SBarry Smith         PetscToken token;
216e26ddf31SBarry Smith         PetscInt   n=0,nmax = next->arraylength,*dvalue = (PetscInt*)next->data,start,end;
217e26ddf31SBarry Smith         size_t     len;
218e26ddf31SBarry Smith         char       *value;
219ace3abfcSBarry Smith         PetscBool  foundrange;
220e26ddf31SBarry Smith 
221e26ddf31SBarry Smith         next->set = PETSC_TRUE;
222e26ddf31SBarry Smith         value     = str;
223e26ddf31SBarry Smith         ierr      = PetscTokenCreate(value,',',&token);CHKERRQ(ierr);
224e26ddf31SBarry Smith         ierr      = PetscTokenFind(token,&value);CHKERRQ(ierr);
225e26ddf31SBarry Smith         while (n < nmax) {
226e26ddf31SBarry Smith           if (!value) break;
227e26ddf31SBarry Smith 
228e26ddf31SBarry Smith           /* look for form  d-D where d and D are integers */
229e26ddf31SBarry Smith           foundrange = PETSC_FALSE;
230e26ddf31SBarry Smith           ierr       = PetscStrlen(value,&len);CHKERRQ(ierr);
231e26ddf31SBarry Smith           if (value[0] == '-') i=2;
232e26ddf31SBarry Smith           else i=1;
233330cf3c9SBarry Smith           for (;i<len; i++) {
234e26ddf31SBarry Smith             if (value[i] == '-') {
235e32f2f54SBarry Smith               if (i == len-1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry %s\n",n,value);
236e26ddf31SBarry Smith               value[i] = 0;
237cfbddea1SSatish Balay               ierr     = PetscOptionsStringToInt(value,&start);CHKERRQ(ierr);
238cfbddea1SSatish Balay               ierr     = PetscOptionsStringToInt(value+i+1,&end);CHKERRQ(ierr);
239e32f2f54SBarry Smith               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);
240e32f2f54SBarry Smith               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);
241e26ddf31SBarry Smith               for (; start<end; start++) {
242e26ddf31SBarry Smith                 *dvalue = start; dvalue++;n++;
243e26ddf31SBarry Smith               }
244e26ddf31SBarry Smith               foundrange = PETSC_TRUE;
245e26ddf31SBarry Smith               break;
246e26ddf31SBarry Smith             }
247e26ddf31SBarry Smith           }
248e26ddf31SBarry Smith           if (!foundrange) {
249cfbddea1SSatish Balay             ierr = PetscOptionsStringToInt(value,dvalue);CHKERRQ(ierr);
250e26ddf31SBarry Smith             dvalue++;
251e26ddf31SBarry Smith             n++;
252e26ddf31SBarry Smith           }
253e26ddf31SBarry Smith           ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
254e26ddf31SBarry Smith         }
2558c74ee41SBarry Smith         ierr = PetscTokenDestroy(&token);CHKERRQ(ierr);
256e26ddf31SBarry Smith       }
257e26ddf31SBarry Smith       break;
258e26ddf31SBarry Smith     case OPTION_REAL_ARRAY:
259e55864a3SBarry Smith       ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1);CHKERRQ(ierr);
260e26ddf31SBarry Smith       valr = (PetscReal*) next->data;
261e26ddf31SBarry Smith       for (i=0; i<next->arraylength; i++) {
262e26ddf31SBarry Smith         ierr = PetscPrintf(PETSC_COMM_WORLD,"%g",valr[i]);CHKERRQ(ierr);
263e26ddf31SBarry Smith         if (i < next->arraylength-1) {
264e26ddf31SBarry Smith           ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr);
265e26ddf31SBarry Smith         }
266e26ddf31SBarry Smith       }
267e26ddf31SBarry Smith       ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s) ",next->text,next->man);CHKERRQ(ierr);
268e26ddf31SBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
269e26ddf31SBarry Smith       if (str[0]) {
270e26ddf31SBarry Smith         PetscToken token;
271e26ddf31SBarry Smith         PetscInt   n = 0,nmax = next->arraylength;
272e26ddf31SBarry Smith         PetscReal  *dvalue = (PetscReal*)next->data;
273e26ddf31SBarry Smith         char       *value;
274e26ddf31SBarry Smith 
275e26ddf31SBarry Smith         next->set = PETSC_TRUE;
276e26ddf31SBarry Smith         value     = str;
277e26ddf31SBarry Smith         ierr      = PetscTokenCreate(value,',',&token);CHKERRQ(ierr);
278e26ddf31SBarry Smith         ierr      = PetscTokenFind(token,&value);CHKERRQ(ierr);
279e26ddf31SBarry Smith         while (n < nmax) {
280e26ddf31SBarry Smith           if (!value) break;
281cfbddea1SSatish Balay           ierr = PetscOptionsStringToReal(value,dvalue);CHKERRQ(ierr);
282e26ddf31SBarry Smith           dvalue++;
283e26ddf31SBarry Smith           n++;
284e26ddf31SBarry Smith           ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
285e26ddf31SBarry Smith         }
2868c74ee41SBarry Smith         ierr = PetscTokenDestroy(&token);CHKERRQ(ierr);
287e26ddf31SBarry Smith       }
288e26ddf31SBarry Smith       break;
2896356e834SBarry Smith     case OPTION_INT:
290e55864a3SBarry Smith       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);
2913fc1eb6aSBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
2923fc1eb6aSBarry Smith       if (str[0]) {
293d25d7f95SJed Brown #if defined(PETSC_SIZEOF_LONG_LONG)
294d25d7f95SJed Brown         long long lid;
295d25d7f95SJed Brown         sscanf(str,"%lld",&lid);
296d25d7f95SJed Brown         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);
297c272547aSJed Brown #else
298d25d7f95SJed Brown         long  lid;
299d25d7f95SJed Brown         sscanf(str,"%ld",&lid);
300d25d7f95SJed Brown         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);
301c272547aSJed Brown #endif
302a297a907SKarl Rupp 
303d25d7f95SJed Brown         next->set = PETSC_TRUE;
304d25d7f95SJed Brown         *((PetscInt*)next->data) = (PetscInt)lid;
305aee2cecaSBarry Smith       }
306aee2cecaSBarry Smith       break;
307aee2cecaSBarry Smith     case OPTION_REAL:
308e55864a3SBarry Smith       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);
3093fc1eb6aSBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
3103fc1eb6aSBarry Smith       if (str[0]) {
311ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE)
312a4404d99SBarry Smith         sscanf(str,"%e",&ir);
313ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE)
314aee2cecaSBarry Smith         sscanf(str,"%le",&ir);
315ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128)
316d9822059SBarry Smith         ir = strtoflt128(str,0);
317d9822059SBarry Smith #else
318513dbe71SLisandro Dalcin         SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Unknown scalar type");
319a4404d99SBarry Smith #endif
320aee2cecaSBarry Smith         next->set                 = PETSC_TRUE;
321aee2cecaSBarry Smith         *((PetscReal*)next->data) = ir;
322aee2cecaSBarry Smith       }
323aee2cecaSBarry Smith       break;
3247781c08eSBarry Smith     case OPTION_BOOL:
325*83355fc5SBarry Smith       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);
3267781c08eSBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
3277781c08eSBarry Smith       if (str[0]) {
3287781c08eSBarry Smith         ierr = PetscOptionsStringToBool(str,&bid);CHKERRQ(ierr);
3297781c08eSBarry Smith         next->set = PETSC_TRUE;
3307781c08eSBarry Smith         *((PetscBool*)next->data) = bid;
3317781c08eSBarry Smith       }
3327781c08eSBarry Smith       break;
333aee2cecaSBarry Smith     case OPTION_STRING:
334e55864a3SBarry Smith       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);
3353fc1eb6aSBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
3363fc1eb6aSBarry Smith       if (str[0]) {
337aee2cecaSBarry Smith         next->set = PETSC_TRUE;
33864facd6cSBarry Smith         /* must use system malloc since SAWs may free this */
3395b02f95dSBarry Smith         ierr = PetscStrdup(str,(char**)&next->data);CHKERRQ(ierr);
3406356e834SBarry Smith       }
3416356e834SBarry Smith       break;
342a264d7a6SBarry Smith     case OPTION_FLIST:
343e55864a3SBarry Smith       ierr = PetscFunctionListPrintTypes(PETSC_COMM_WORLD,stdout,PetscOptionsObject->prefix,next->option,next->text,next->man,next->flist,(char*)next->data);CHKERRQ(ierr);
3443cc1e11dSBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
3453cc1e11dSBarry Smith       if (str[0]) {
346e55864a3SBarry Smith         PetscOptionsObject->changedmethod = PETSC_TRUE;
3473cc1e11dSBarry Smith         next->set = PETSC_TRUE;
34864facd6cSBarry Smith         /* must use system malloc since SAWs may free this */
3495b02f95dSBarry Smith         ierr = PetscStrdup(str,(char**)&next->data);CHKERRQ(ierr);
3503cc1e11dSBarry Smith       }
3513cc1e11dSBarry Smith       break;
352b432afdaSMatthew Knepley     default:
353b432afdaSMatthew Knepley       break;
3546356e834SBarry Smith     }
3556356e834SBarry Smith     next = next->next;
3566356e834SBarry Smith   }
3576356e834SBarry Smith   PetscFunctionReturn(0);
3586356e834SBarry Smith }
3596356e834SBarry Smith 
360e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
361e04113cfSBarry Smith #include <petscviewersaws.h>
362d5649816SBarry Smith 
363d5649816SBarry Smith static int count = 0;
364d5649816SBarry Smith 
365b3506946SBarry Smith #undef __FUNCT__
366e04113cfSBarry Smith #define __FUNCT__ "PetscOptionsSAWsDestroy"
367e04113cfSBarry Smith PetscErrorCode PetscOptionsSAWsDestroy(void)
368d5649816SBarry Smith {
3692657e9d9SBarry Smith   PetscFunctionBegin;
370d5649816SBarry Smith   PetscFunctionReturn(0);
371d5649816SBarry Smith }
372d5649816SBarry Smith 
373d5649816SBarry Smith #undef __FUNCT__
3747781c08eSBarry Smith #define __FUNCT__ "PetscOptionsSAWsInput"
375b3506946SBarry Smith /*
3767781c08eSBarry Smith     PetscOptionsSAWsInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the SAWs
377b3506946SBarry Smith 
378b3506946SBarry Smith     Bugs:
379b3506946SBarry Smith +    All processes must traverse through the exact same set of option queries do to the call to PetscScanString()
380b3506946SBarry Smith .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
381b3506946SBarry Smith -    Only works for PetscInt == int, PetscReal == double etc
382b3506946SBarry Smith 
383b3506946SBarry Smith 
384b3506946SBarry Smith */
385e55864a3SBarry Smith PetscErrorCode PetscOptionsAMSInput(PetscOptionsObjectType *PetscOptionsObject)
386b3506946SBarry Smith {
387b3506946SBarry Smith   PetscErrorCode ierr;
388e55864a3SBarry Smith   PetscOptions   next     = PetscOptionsObject->next;
389d5649816SBarry Smith   static int     mancount = 0;
390b3506946SBarry Smith   char           options[16];
3917aab2a10SBarry Smith   PetscBool      changedmethod = PETSC_FALSE;
39288a9752cSBarry Smith   char           manname[16],textname[16];
3932657e9d9SBarry Smith   char           dir[1024];
394b3506946SBarry Smith 
395b3506946SBarry Smith   /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */
396b3506946SBarry Smith   sprintf(options,"Options_%d",count++);
397a297a907SKarl Rupp 
398e55864a3SBarry Smith   PetscOptionsObject->pprefix = PetscOptionsObject->prefix; /* AMS will change this, so cannot pass prefix directly */
3991bc75a8dSBarry Smith 
400d50831c4SBarry Smith   ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s","_title");CHKERRQ(ierr);
401*83355fc5SBarry Smith   PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject->title,1,SAWs_READ,SAWs_STRING));
4027781c08eSBarry Smith   ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s","prefix");CHKERRQ(ierr);
403*83355fc5SBarry Smith   PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject->pprefix,1,SAWs_READ,SAWs_STRING));
4042657e9d9SBarry Smith   PetscStackCallSAWs(SAWs_Register,("/PETSc/Options/ChangedMethod",&changedmethod,1,SAWs_WRITE,SAWs_BOOLEAN));
405b3506946SBarry Smith 
406b3506946SBarry Smith   while (next) {
407d50831c4SBarry Smith     sprintf(manname,"_man_%d",mancount);
4082657e9d9SBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",manname);CHKERRQ(ierr);
4097781c08eSBarry Smith     PetscStackCallSAWs(SAWs_Register,(dir,&next->man,1,SAWs_READ,SAWs_STRING));
410d50831c4SBarry Smith     sprintf(textname,"_text_%d",mancount++);
4117781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",textname);CHKERRQ(ierr);
4127781c08eSBarry Smith     PetscStackCallSAWs(SAWs_Register,(dir,&next->text,1,SAWs_READ,SAWs_STRING));
4139f32e415SBarry Smith 
414b3506946SBarry Smith     switch (next->type) {
415b3506946SBarry Smith     case OPTION_HEAD:
416b3506946SBarry Smith       break;
417b3506946SBarry Smith     case OPTION_INT_ARRAY:
4187781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4192657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_INT));
420b3506946SBarry Smith       break;
421b3506946SBarry Smith     case OPTION_REAL_ARRAY:
4227781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4232657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_DOUBLE));
424b3506946SBarry Smith       break;
425b3506946SBarry Smith     case OPTION_INT:
4267781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4272657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_INT));
428b3506946SBarry Smith       break;
429b3506946SBarry Smith     case OPTION_REAL:
4307781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4312657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_DOUBLE));
432b3506946SBarry Smith       break;
4337781c08eSBarry Smith     case OPTION_BOOL:
4347781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4352657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_BOOLEAN));
4361ae3d29cSBarry Smith       break;
4377781c08eSBarry Smith     case OPTION_BOOL_ARRAY:
4387781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4392657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_BOOLEAN));
44071f08665SBarry Smith       break;
441b3506946SBarry Smith     case OPTION_STRING:
4427781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4437781c08eSBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING));
4441ae3d29cSBarry Smith       break;
4451ae3d29cSBarry Smith     case OPTION_STRING_ARRAY:
4467781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4472657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_STRING));
448b3506946SBarry Smith       break;
449a264d7a6SBarry Smith     case OPTION_FLIST:
450a264d7a6SBarry Smith       {
451a264d7a6SBarry Smith       PetscInt ntext;
4527781c08eSBarry Smith       ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4537781c08eSBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING));
454a264d7a6SBarry Smith       ierr = PetscFunctionListGet(next->flist,(const char***)&next->edata,&ntext);CHKERRQ(ierr);
455a264d7a6SBarry Smith       PetscStackCallSAWs(SAWs_Set_Legal_Variable_Values,(dir,ntext,next->edata));
456a264d7a6SBarry Smith       }
457a264d7a6SBarry Smith       break;
4581ae3d29cSBarry Smith     case OPTION_ELIST:
459a264d7a6SBarry Smith       {
460a264d7a6SBarry Smith       PetscInt ntext = next->nlist;
4617781c08eSBarry Smith       ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4627781c08eSBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING));
463315e5ce4SBarry Smith       ierr = PetscMalloc((ntext+1)*sizeof(char),&next->edata);CHKERRQ(ierr);
4641ae3d29cSBarry Smith       ierr = PetscMemcpy(next->edata,next->list,ntext*sizeof(char*));CHKERRQ(ierr);
465a264d7a6SBarry Smith       PetscStackCallSAWs(SAWs_Set_Legal_Variable_Values,(dir,ntext,next->edata));
466a264d7a6SBarry Smith       }
467a264d7a6SBarry Smith       break;
468b3506946SBarry Smith     default:
469b3506946SBarry Smith       break;
470b3506946SBarry Smith     }
471b3506946SBarry Smith     next = next->next;
472b3506946SBarry Smith   }
473b3506946SBarry Smith 
474b3506946SBarry Smith   /* wait until accessor has unlocked the memory */
4757aab2a10SBarry Smith   ierr = PetscSAWsBlock();CHKERRQ(ierr);
476b3506946SBarry Smith 
47788a9752cSBarry Smith   /* determine if any values have been set in GUI */
478*83355fc5SBarry Smith   next = PetscOptionsObject->next;
47988a9752cSBarry Smith   while (next) {
48088a9752cSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
48188a9752cSBarry Smith     PetscStackCallSAWs(SAWs_Selected,(dir,&next->set));
48288a9752cSBarry Smith     next = next->next;
48388a9752cSBarry Smith   }
48488a9752cSBarry Smith 
485b3506946SBarry Smith   /* reset counter to -2; this updates the screen with the new options for the selected method */
486b3506946SBarry Smith   if (changedmethod) PetscOptionsPublishCount = -2;
487b3506946SBarry Smith 
4889a492a5cSBarry Smith   PetscStackCallSAWs(SAWs_Delete,("/PETSc/Options"));
489b3506946SBarry Smith   PetscFunctionReturn(0);
490b3506946SBarry Smith }
491b3506946SBarry Smith #endif
492b3506946SBarry Smith 
4936356e834SBarry Smith #undef __FUNCT__
49453acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsEnd_Private"
495e55864a3SBarry Smith PetscErrorCode PetscOptionsEnd_Private(PetscOptionsObjectType *PetscOptionsObject)
49653acd3b1SBarry Smith {
49753acd3b1SBarry Smith   PetscErrorCode ierr;
4986356e834SBarry Smith   PetscOptions   last;
4996356e834SBarry Smith   char           option[256],value[1024],tmp[32];
500330cf3c9SBarry Smith   size_t         j;
50153acd3b1SBarry Smith 
50253acd3b1SBarry Smith   PetscFunctionBegin;
503*83355fc5SBarry Smith   if (PetscOptionsObject->next) {
504*83355fc5SBarry Smith     if (!PetscOptionsObject->count) {
505a264d7a6SBarry Smith #if defined(PETSC_HAVE_SAWS)
506475446a1SBarry Smith       ierr = PetscOptionsSAWsInput();CHKERRQ(ierr);
507b3506946SBarry Smith #else
508e55864a3SBarry Smith       ierr = PetscOptionsGetFromTextInput(PetscOptionsObject);CHKERRQ(ierr);
509b3506946SBarry Smith #endif
510aee2cecaSBarry Smith     }
511aee2cecaSBarry Smith   }
5126356e834SBarry Smith 
513e55864a3SBarry Smith   ierr = PetscFree(PetscOptionsObject->title);CHKERRQ(ierr);
514e55864a3SBarry Smith   ierr = PetscFree(PetscOptionsObject->prefix);CHKERRQ(ierr);
5156356e834SBarry Smith 
5166356e834SBarry Smith   /* reset counter to -2; this updates the screen with the new options for the selected method */
517e55864a3SBarry Smith   if (PetscOptionsObject->changedmethod) PetscOptionsObject->count = -2;
51861b37b28SSatish Balay   /* reset alreadyprinted flag */
519e55864a3SBarry Smith   PetscOptionsObject->alreadyprinted = PETSC_FALSE;
520e55864a3SBarry Smith   if (PetscOptionsObject->object) PetscOptionsObject->object->optionsprinted = PETSC_TRUE;
521e55864a3SBarry Smith   PetscOptionsObject->object = NULL;
5226356e834SBarry Smith 
523e55864a3SBarry Smith   while (PetscOptionsObject->next) {
524e55864a3SBarry Smith     if (PetscOptionsObject->next->set) {
525e55864a3SBarry Smith       if (PetscOptionsObject->prefix) {
5266356e834SBarry Smith         ierr = PetscStrcpy(option,"-");CHKERRQ(ierr);
527e55864a3SBarry Smith         ierr = PetscStrcat(option,PetscOptionsObject->prefix);CHKERRQ(ierr);
528e55864a3SBarry Smith         ierr = PetscStrcat(option,PetscOptionsObject->next->option+1);CHKERRQ(ierr);
5296356e834SBarry Smith       } else {
530e55864a3SBarry Smith         ierr = PetscStrcpy(option,PetscOptionsObject->next->option);CHKERRQ(ierr);
5316356e834SBarry Smith       }
5326356e834SBarry Smith 
533e55864a3SBarry Smith       switch (PetscOptionsObject->next->type) {
5346356e834SBarry Smith       case OPTION_HEAD:
5356356e834SBarry Smith         break;
536e26ddf31SBarry Smith       case OPTION_INT_ARRAY:
537e55864a3SBarry Smith         sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject->next->data)[0]);
538e55864a3SBarry Smith         for (j=1; j<PetscOptionsObject->next->arraylength; j++) {
539e55864a3SBarry Smith           sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject->next->data)[j]);
540e26ddf31SBarry Smith           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
541e26ddf31SBarry Smith           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
542e26ddf31SBarry Smith         }
543e26ddf31SBarry Smith         break;
5446356e834SBarry Smith       case OPTION_INT:
545e55864a3SBarry Smith         sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject->next->data);
5466356e834SBarry Smith         break;
5476356e834SBarry Smith       case OPTION_REAL:
548e55864a3SBarry Smith         sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject->next->data);
5496356e834SBarry Smith         break;
5506356e834SBarry Smith       case OPTION_REAL_ARRAY:
551e55864a3SBarry Smith         sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject->next->data)[0]);
552e55864a3SBarry Smith         for (j=1; j<PetscOptionsObject->next->arraylength; j++) {
553e55864a3SBarry Smith           sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject->next->data)[j]);
5546356e834SBarry Smith           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
5556356e834SBarry Smith           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
5566356e834SBarry Smith         }
5576356e834SBarry Smith         break;
5587781c08eSBarry Smith       case OPTION_BOOL:
559e55864a3SBarry Smith         sprintf(value,"%d",*(int*)PetscOptionsObject->next->data);
5606356e834SBarry Smith         break;
5617781c08eSBarry Smith       case OPTION_BOOL_ARRAY:
562e55864a3SBarry Smith         sprintf(value,"%d",(int)((PetscBool*)PetscOptionsObject->next->data)[0]);
563e55864a3SBarry Smith         for (j=1; j<PetscOptionsObject->next->arraylength; j++) {
564e55864a3SBarry Smith           sprintf(tmp,"%d",(int)((PetscBool*)PetscOptionsObject->next->data)[j]);
5651ae3d29cSBarry Smith           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
5661ae3d29cSBarry Smith           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
5671ae3d29cSBarry Smith         }
5681ae3d29cSBarry Smith         break;
569a264d7a6SBarry Smith       case OPTION_FLIST:
5701ae3d29cSBarry Smith       case OPTION_ELIST:
571e55864a3SBarry Smith         ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr);
5726356e834SBarry Smith         break;
5731ae3d29cSBarry Smith       case OPTION_STRING:
574e55864a3SBarry Smith         ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr);
5751ae3d29cSBarry Smith       case OPTION_STRING_ARRAY:
576e55864a3SBarry Smith         sprintf(value,"%s",((char**)PetscOptionsObject->next->data)[0]);
577e55864a3SBarry Smith         for (j=1; j<PetscOptionsObject->next->arraylength; j++) {
578e55864a3SBarry Smith           sprintf(tmp,"%s",((char**)PetscOptionsObject->next->data)[j]);
5791ae3d29cSBarry Smith           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
5801ae3d29cSBarry Smith           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
5811ae3d29cSBarry Smith         }
5826356e834SBarry Smith         break;
5836356e834SBarry Smith       }
5846356e834SBarry Smith       ierr = PetscOptionsSetValue(option,value);CHKERRQ(ierr);
5856356e834SBarry Smith     }
586e55864a3SBarry Smith     ierr   = PetscFree(PetscOptionsObject->next->text);CHKERRQ(ierr);
587e55864a3SBarry Smith     ierr   = PetscFree(PetscOptionsObject->next->option);CHKERRQ(ierr);
588e55864a3SBarry Smith     ierr   = PetscFree(PetscOptionsObject->next->man);CHKERRQ(ierr);
589e55864a3SBarry Smith     ierr   = PetscFree(PetscOptionsObject->next->edata);CHKERRQ(ierr);
590c979a496SBarry Smith 
591*83355fc5SBarry Smith     if ((PetscOptionsObject->next->type == OPTION_STRING) || (PetscOptionsObject->next->type == OPTION_FLIST) || (PetscOptionsObject->next->type == OPTION_ELIST)){
592*83355fc5SBarry Smith       free(PetscOptionsObject->next->data);
593c979a496SBarry Smith     } else {
594*83355fc5SBarry Smith       ierr   = PetscFree(PetscOptionsObject->next->data);CHKERRQ(ierr);
595c979a496SBarry Smith     }
5967781c08eSBarry Smith 
597*83355fc5SBarry Smith     last                    = PetscOptionsObject->next;
598*83355fc5SBarry Smith     PetscOptionsObject->next = PetscOptionsObject->next->next;
5996356e834SBarry Smith     ierr                    = PetscFree(last);CHKERRQ(ierr);
6006356e834SBarry Smith   }
601e55864a3SBarry Smith   PetscOptionsObject->next = 0;
60253acd3b1SBarry Smith   PetscFunctionReturn(0);
60353acd3b1SBarry Smith }
60453acd3b1SBarry Smith 
60553acd3b1SBarry Smith #undef __FUNCT__
606e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsEnum_Private"
60753acd3b1SBarry Smith /*@C
60853acd3b1SBarry Smith    PetscOptionsEnum - Gets the enum value for a particular option in the database.
60953acd3b1SBarry Smith 
6103f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
61153acd3b1SBarry Smith 
61253acd3b1SBarry Smith    Input Parameters:
61353acd3b1SBarry Smith +  opt - option name
61453acd3b1SBarry Smith .  text - short string that describes the option
61553acd3b1SBarry Smith .  man - manual page with additional information on option
61653acd3b1SBarry Smith .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
6170fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
6180fdccdaeSBarry Smith $                 PetscOptionsEnum(..., obj->value,&object->value,...) or
6190fdccdaeSBarry Smith $                 value = defaultvalue
6200fdccdaeSBarry Smith $                 PetscOptionsEnum(..., value,&value,&flg);
6210fdccdaeSBarry Smith $                 if (flg) {
62253acd3b1SBarry Smith 
62353acd3b1SBarry Smith    Output Parameter:
62453acd3b1SBarry Smith +  value - the  value to return
625b32e0204SMatthew G Knepley -  set - PETSC_TRUE if found, else PETSC_FALSE
62653acd3b1SBarry Smith 
62753acd3b1SBarry Smith    Level: beginner
62853acd3b1SBarry Smith 
62953acd3b1SBarry Smith    Concepts: options database
63053acd3b1SBarry Smith 
63153acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
63253acd3b1SBarry Smith 
63353acd3b1SBarry Smith           list is usually something like PCASMTypes or some other predefined list of enum names
63453acd3b1SBarry Smith 
63553acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
636acfcf0e5SJed Brown           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
637acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
63853acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
63953acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
640acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
641a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
64253acd3b1SBarry Smith @*/
643e55864a3SBarry Smith PetscErrorCode  PetscOptionsEnum_Private(PetscOptionsObjectType *PetscOptionsObject,const char opt[],const char text[],const char man[],const char *const *list,PetscEnum defaultv,PetscEnum *value,PetscBool  *set)
64453acd3b1SBarry Smith {
64553acd3b1SBarry Smith   PetscErrorCode ierr;
64653acd3b1SBarry Smith   PetscInt       ntext = 0;
647aa5bb8c0SSatish Balay   PetscInt       tval;
648ace3abfcSBarry Smith   PetscBool      tflg;
64953acd3b1SBarry Smith 
65053acd3b1SBarry Smith   PetscFunctionBegin;
65153acd3b1SBarry Smith   while (list[ntext++]) {
652e32f2f54SBarry Smith     if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries");
65353acd3b1SBarry Smith   }
654e32f2f54SBarry Smith   if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix");
65553acd3b1SBarry Smith   ntext -= 3;
656e55864a3SBarry Smith   ierr   = PetscOptionsEList_Private(PetscOptionsObject,opt,text,man,list,ntext,list[currentvalue],&tval,&tflg);CHKERRQ(ierr);
657aa5bb8c0SSatish Balay   /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */
658aa5bb8c0SSatish Balay   if (tflg) *value = (PetscEnum)tval;
659aa5bb8c0SSatish Balay   if (set)  *set   = tflg;
66053acd3b1SBarry Smith   PetscFunctionReturn(0);
66153acd3b1SBarry Smith }
66253acd3b1SBarry Smith 
66353acd3b1SBarry Smith /* -------------------------------------------------------------------------------------------------------------*/
66453acd3b1SBarry Smith #undef __FUNCT__
665e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsInt_Private"
66653acd3b1SBarry Smith /*@C
66753acd3b1SBarry Smith    PetscOptionsInt - Gets the integer value for a particular option in the database.
66853acd3b1SBarry Smith 
6693f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
67053acd3b1SBarry Smith 
67153acd3b1SBarry Smith    Input Parameters:
67253acd3b1SBarry Smith +  opt - option name
67353acd3b1SBarry Smith .  text - short string that describes the option
67453acd3b1SBarry Smith .  man - manual page with additional information on option
6750fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
6760fdccdaeSBarry Smith $                 PetscOptionsInt(..., obj->value,&object->value,...) or
6770fdccdaeSBarry Smith $                 value = defaultvalue
6780fdccdaeSBarry Smith $                 PetscOptionsInt(..., value,&value,&flg);
6790fdccdaeSBarry Smith $                 if (flg) {
68053acd3b1SBarry Smith 
68153acd3b1SBarry Smith    Output Parameter:
68253acd3b1SBarry Smith +  value - the integer value to return
68353acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
68453acd3b1SBarry Smith 
68553acd3b1SBarry Smith    Level: beginner
68653acd3b1SBarry Smith 
68753acd3b1SBarry Smith    Concepts: options database^has int
68853acd3b1SBarry Smith 
68953acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
69053acd3b1SBarry Smith 
69153acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
692acfcf0e5SJed Brown           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
693acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
69453acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
69553acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
696acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
697a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
69853acd3b1SBarry Smith @*/
699e55864a3SBarry Smith PetscErrorCode  PetscOptionsInt_Private(PetscOptionsObjectType *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscInt defaultv,PetscInt *value,PetscBool  *set)
70053acd3b1SBarry Smith {
70153acd3b1SBarry Smith   PetscErrorCode ierr;
7026356e834SBarry Smith   PetscOptions   amsopt;
70353acd3b1SBarry Smith 
70453acd3b1SBarry Smith   PetscFunctionBegin;
705e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
706e55864a3SBarry Smith     ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr);
7076356e834SBarry Smith     ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
708a297a907SKarl Rupp 
7090fdccdaeSBarry Smith     *(PetscInt*)amsopt->data = currentvalue;
710af6d86caSBarry Smith   }
711e55864a3SBarry Smith   ierr = PetscOptionsGetInt(PetscOptionsObject->prefix,opt,value,set);CHKERRQ(ierr);
712e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
713e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%d>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr);
71453acd3b1SBarry Smith   }
71553acd3b1SBarry Smith   PetscFunctionReturn(0);
71653acd3b1SBarry Smith }
71753acd3b1SBarry Smith 
71853acd3b1SBarry Smith #undef __FUNCT__
719e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsString_Private"
72053acd3b1SBarry Smith /*@C
72153acd3b1SBarry Smith    PetscOptionsString - Gets the string value for a particular option in the database.
72253acd3b1SBarry Smith 
7233f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
72453acd3b1SBarry Smith 
72553acd3b1SBarry Smith    Input Parameters:
72653acd3b1SBarry Smith +  opt - option name
72753acd3b1SBarry Smith .  text - short string that describes the option
72853acd3b1SBarry Smith .  man - manual page with additional information on option
7290fdccdaeSBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. This is not used to set value
730bcbf2dc5SJed Brown -  len - length of the result string including null terminator
73153acd3b1SBarry Smith 
73253acd3b1SBarry Smith    Output Parameter:
73353acd3b1SBarry Smith +  value - the value to return
73453acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
73553acd3b1SBarry Smith 
73653acd3b1SBarry Smith    Level: beginner
73753acd3b1SBarry Smith 
73853acd3b1SBarry Smith    Concepts: options database^has int
73953acd3b1SBarry Smith 
74053acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
74153acd3b1SBarry Smith 
7427fccdfe4SBarry Smith    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).
7437fccdfe4SBarry Smith 
74453acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
745acfcf0e5SJed Brown           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
746acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsReal(), PetscOptionsBool(),
74753acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
74853acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
749acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
750a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
75153acd3b1SBarry Smith @*/
752e55864a3SBarry Smith PetscErrorCode  PetscOptionsString_Private(PetscOptionsObjectType *PetscOptionsObject,const char opt[],const char text[],const char man[],const char defaultv[],char value[],size_t len,PetscBool  *set)
75353acd3b1SBarry Smith {
75453acd3b1SBarry Smith   PetscErrorCode ierr;
755aee2cecaSBarry Smith   PetscOptions   amsopt;
75653acd3b1SBarry Smith 
75753acd3b1SBarry Smith   PetscFunctionBegin;
758b3506946SBarry Smith   if (!PetscOptionsPublishCount) {
759aee2cecaSBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
76064facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
7610fdccdaeSBarry Smith     ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr);
762af6d86caSBarry Smith   }
763e55864a3SBarry Smith   ierr = PetscOptionsGetString(PetscOptionsObject->prefix,opt,value,len,set);CHKERRQ(ierr);
764e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
765e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%s>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr);
76653acd3b1SBarry Smith   }
76753acd3b1SBarry Smith   PetscFunctionReturn(0);
76853acd3b1SBarry Smith }
76953acd3b1SBarry Smith 
77053acd3b1SBarry Smith #undef __FUNCT__
771e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsReal_Private"
77253acd3b1SBarry Smith /*@C
77353acd3b1SBarry Smith    PetscOptionsReal - Gets the PetscReal value for a particular option in the database.
77453acd3b1SBarry Smith 
7753f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
77653acd3b1SBarry Smith 
77753acd3b1SBarry Smith    Input Parameters:
77853acd3b1SBarry Smith +  opt - option name
77953acd3b1SBarry Smith .  text - short string that describes the option
78053acd3b1SBarry Smith .  man - manual page with additional information on option
7810fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
7820fdccdaeSBarry Smith $                 PetscOptionsReal(..., obj->value,&object->value,...) or
7830fdccdaeSBarry Smith $                 value = defaultvalue
7840fdccdaeSBarry Smith $                 PetscOptionsReal(..., value,&value,&flg);
7850fdccdaeSBarry Smith $                 if (flg) {
78653acd3b1SBarry Smith 
78753acd3b1SBarry Smith    Output Parameter:
78853acd3b1SBarry Smith +  value - the value to return
78953acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
79053acd3b1SBarry Smith 
79153acd3b1SBarry Smith    Level: beginner
79253acd3b1SBarry Smith 
79353acd3b1SBarry Smith    Concepts: options database^has int
79453acd3b1SBarry Smith 
79553acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
79653acd3b1SBarry Smith 
79753acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
798acfcf0e5SJed Brown           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
799acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
80053acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
80153acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
802acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
803a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
80453acd3b1SBarry Smith @*/
805e55864a3SBarry Smith PetscErrorCode  PetscOptionsReal_Private(PetscOptionsObjectType *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscReal defaultv,PetscReal *value,PetscBool  *set)
80653acd3b1SBarry Smith {
80753acd3b1SBarry Smith   PetscErrorCode ierr;
808538aa990SBarry Smith   PetscOptions   amsopt;
80953acd3b1SBarry Smith 
81053acd3b1SBarry Smith   PetscFunctionBegin;
811e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
812e55864a3SBarry Smith     ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr);
813538aa990SBarry Smith     ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
814a297a907SKarl Rupp 
8150fdccdaeSBarry Smith     *(PetscReal*)amsopt->data = currentvalue;
816538aa990SBarry Smith   }
81753acd3b1SBarry Smith   ierr = PetscOptionsGetReal(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
81861b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
8190fdccdaeSBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%g>: %s (%s)\n",PetscOptionsObject.prefix ? PetscOptionsObject.prefix : "",opt+1,(double)currentvalue,text,ManSection(man));CHKERRQ(ierr);
82053acd3b1SBarry Smith   }
82153acd3b1SBarry Smith   PetscFunctionReturn(0);
82253acd3b1SBarry Smith }
82353acd3b1SBarry Smith 
82453acd3b1SBarry Smith #undef __FUNCT__
825e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsScalar_Private"
82653acd3b1SBarry Smith /*@C
82753acd3b1SBarry Smith    PetscOptionsScalar - Gets the scalar value for a particular option in the database.
82853acd3b1SBarry Smith 
8293f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
83053acd3b1SBarry Smith 
83153acd3b1SBarry Smith    Input Parameters:
83253acd3b1SBarry Smith +  opt - option name
83353acd3b1SBarry Smith .  text - short string that describes the option
83453acd3b1SBarry Smith .  man - manual page with additional information on option
8350fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
8360fdccdaeSBarry Smith $                 PetscOptionsScalar(..., obj->value,&object->value,...) or
8370fdccdaeSBarry Smith $                 value = defaultvalue
8380fdccdaeSBarry Smith $                 PetscOptionsScalar(..., value,&value,&flg);
8390fdccdaeSBarry Smith $                 if (flg) {
8400fdccdaeSBarry Smith 
84153acd3b1SBarry Smith 
84253acd3b1SBarry Smith    Output Parameter:
84353acd3b1SBarry Smith +  value - the value to return
84453acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
84553acd3b1SBarry Smith 
84653acd3b1SBarry Smith    Level: beginner
84753acd3b1SBarry Smith 
84853acd3b1SBarry Smith    Concepts: options database^has int
84953acd3b1SBarry Smith 
85053acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
85153acd3b1SBarry Smith 
85253acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
853acfcf0e5SJed Brown           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
854acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
85553acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
85653acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
857acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
858a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
85953acd3b1SBarry Smith @*/
860e55864a3SBarry Smith PetscErrorCode  PetscOptionsScalar_Private(PetscOptionsObjectType *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscScalar defaultv,PetscScalar *value,PetscBool  *set)
86153acd3b1SBarry Smith {
86253acd3b1SBarry Smith   PetscErrorCode ierr;
86353acd3b1SBarry Smith 
86453acd3b1SBarry Smith   PetscFunctionBegin;
86553acd3b1SBarry Smith #if !defined(PETSC_USE_COMPLEX)
8660fdccdaeSBarry Smith   ierr = PetscOptionsReal(opt,text,man,currentvalue,value,set);CHKERRQ(ierr);
86753acd3b1SBarry Smith #else
868e55864a3SBarry Smith   ierr = PetscOptionsGetScalar(PetscOptionsObject->prefix,opt,value,set);CHKERRQ(ierr);
86953acd3b1SBarry Smith #endif
87053acd3b1SBarry Smith   PetscFunctionReturn(0);
87153acd3b1SBarry Smith }
87253acd3b1SBarry Smith 
87353acd3b1SBarry Smith #undef __FUNCT__
874e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsName_Private"
87553acd3b1SBarry Smith /*@C
87690d69ab7SBarry Smith    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
87790d69ab7SBarry Smith                       its value is set to false.
87853acd3b1SBarry Smith 
8793f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
88053acd3b1SBarry Smith 
88153acd3b1SBarry Smith    Input Parameters:
88253acd3b1SBarry Smith +  opt - option name
88353acd3b1SBarry Smith .  text - short string that describes the option
88453acd3b1SBarry Smith -  man - manual page with additional information on option
88553acd3b1SBarry Smith 
88653acd3b1SBarry Smith    Output Parameter:
88753acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
88853acd3b1SBarry Smith 
88953acd3b1SBarry Smith    Level: beginner
89053acd3b1SBarry Smith 
89153acd3b1SBarry Smith    Concepts: options database^has int
89253acd3b1SBarry Smith 
89353acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
89453acd3b1SBarry Smith 
89553acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
896acfcf0e5SJed Brown           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
897acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
89853acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
89953acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
900acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
901a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
90253acd3b1SBarry Smith @*/
903e55864a3SBarry Smith PetscErrorCode  PetscOptionsName_Private(PetscOptionsObjectType *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool  *flg)
90453acd3b1SBarry Smith {
90553acd3b1SBarry Smith   PetscErrorCode ierr;
9061ae3d29cSBarry Smith   PetscOptions   amsopt;
90753acd3b1SBarry Smith 
90853acd3b1SBarry Smith   PetscFunctionBegin;
909e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
910e55864a3SBarry Smith     ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
911ace3abfcSBarry Smith     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
912a297a907SKarl Rupp 
913ace3abfcSBarry Smith     *(PetscBool*)amsopt->data = PETSC_FALSE;
9141ae3d29cSBarry Smith   }
915e55864a3SBarry Smith   ierr = PetscOptionsHasName(PetscOptionsObject->prefix,opt,flg);CHKERRQ(ierr);
916e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
917e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
91853acd3b1SBarry Smith   }
91953acd3b1SBarry Smith   PetscFunctionReturn(0);
92053acd3b1SBarry Smith }
92153acd3b1SBarry Smith 
92253acd3b1SBarry Smith #undef __FUNCT__
923e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsFList_Private"
92453acd3b1SBarry Smith /*@C
925a264d7a6SBarry Smith      PetscOptionsFList - Puts a list of option values that a single one may be selected from
92653acd3b1SBarry Smith 
9273f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
92853acd3b1SBarry Smith 
92953acd3b1SBarry Smith    Input Parameters:
93053acd3b1SBarry Smith +  opt - option name
93153acd3b1SBarry Smith .  text - short string that describes the option
93253acd3b1SBarry Smith .  man - manual page with additional information on option
93353acd3b1SBarry Smith .  list - the possible choices
9340fdccdaeSBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with
9350fdccdaeSBarry Smith $                 PetscOptionsFlist(..., obj->value,value,len,&flg);
9360fdccdaeSBarry Smith $                 if (flg) {
9373cc1e11dSBarry Smith -  len - the length of the character array value
93853acd3b1SBarry Smith 
93953acd3b1SBarry Smith    Output Parameter:
94053acd3b1SBarry Smith +  value - the value to return
94153acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
94253acd3b1SBarry Smith 
94353acd3b1SBarry Smith    Level: intermediate
94453acd3b1SBarry Smith 
94553acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
94653acd3b1SBarry Smith 
94753acd3b1SBarry Smith    See PetscOptionsEList() for when the choices are given in a string array
94853acd3b1SBarry Smith 
94953acd3b1SBarry Smith    To get a listing of all currently specified options,
95088c29154SBarry Smith     see PetscOptionsView() or PetscOptionsGetAll()
95153acd3b1SBarry Smith 
952eabe10d7SBarry Smith    Developer Note: This cannot check for invalid selection because of things like MATAIJ that are not included in the list
953eabe10d7SBarry Smith 
95453acd3b1SBarry Smith    Concepts: options database^list
95553acd3b1SBarry Smith 
95653acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
957acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
95853acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
95953acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
960acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
961a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList(), PetscOptionsEnum()
96253acd3b1SBarry Smith @*/
963*83355fc5SBarry Smith 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)
96453acd3b1SBarry Smith {
96553acd3b1SBarry Smith   PetscErrorCode ierr;
9663cc1e11dSBarry Smith   PetscOptions   amsopt;
96753acd3b1SBarry Smith 
96853acd3b1SBarry Smith   PetscFunctionBegin;
969b3506946SBarry Smith   if (!PetscOptionsPublishCount) {
970a264d7a6SBarry Smith     ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_FLIST,&amsopt);CHKERRQ(ierr);
97164facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
9720fdccdaeSBarry Smith     ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr);
9733cc1e11dSBarry Smith     amsopt->flist = list;
9743cc1e11dSBarry Smith   }
97553acd3b1SBarry Smith   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
97661b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
9770fdccdaeSBarry Smith     ierr = PetscFunctionListPrintTypes(PetscOptionsObject.comm,stdout,PetscOptionsObject.prefix,opt,ltext,man,list,currentvalue);CHKERRQ(ierr);CHKERRQ(ierr);
97853acd3b1SBarry Smith   }
97953acd3b1SBarry Smith   PetscFunctionReturn(0);
98053acd3b1SBarry Smith }
98153acd3b1SBarry Smith 
98253acd3b1SBarry Smith #undef __FUNCT__
983e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsEList_Private"
98453acd3b1SBarry Smith /*@C
98553acd3b1SBarry Smith      PetscOptionsEList - Puts a list of option values that a single one may be selected from
98653acd3b1SBarry Smith 
9873f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
98853acd3b1SBarry Smith 
98953acd3b1SBarry Smith    Input Parameters:
99053acd3b1SBarry Smith +  opt - option name
99153acd3b1SBarry Smith .  ltext - short string that describes the option
99253acd3b1SBarry Smith .  man - manual page with additional information on option
993a264d7a6SBarry Smith .  list - the possible choices (one of these must be selected, anything else is invalid)
99453acd3b1SBarry Smith .  ntext - number of choices
9950fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with
9960fdccdaeSBarry Smith $                 PetscOptionsElist(..., obj->value,&value,&flg);
9970fdccdaeSBarry Smith $                 if (flg) {
9980fdccdaeSBarry Smith 
99953acd3b1SBarry Smith 
100053acd3b1SBarry Smith    Output Parameter:
100153acd3b1SBarry Smith +  value - the index of the value to return
100253acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
100353acd3b1SBarry Smith 
100453acd3b1SBarry Smith    Level: intermediate
100553acd3b1SBarry Smith 
100653acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
100753acd3b1SBarry Smith 
1008a264d7a6SBarry Smith    See PetscOptionsFList() for when the choices are given in a PetscFunctionList()
100953acd3b1SBarry Smith 
101053acd3b1SBarry Smith    Concepts: options database^list
101153acd3b1SBarry Smith 
101253acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1013acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
101453acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
101553acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1016acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1017a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEnum()
101853acd3b1SBarry Smith @*/
1019e55864a3SBarry Smith 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)
102053acd3b1SBarry Smith {
102153acd3b1SBarry Smith   PetscErrorCode ierr;
102253acd3b1SBarry Smith   PetscInt       i;
10231ae3d29cSBarry Smith   PetscOptions   amsopt;
102453acd3b1SBarry Smith 
102553acd3b1SBarry Smith   PetscFunctionBegin;
10261ae3d29cSBarry Smith   if (!PetscOptionsPublishCount) {
1027d5649816SBarry Smith     ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_ELIST,&amsopt);CHKERRQ(ierr);
102864facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
10290fdccdaeSBarry Smith     ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr);
10301ae3d29cSBarry Smith     amsopt->list  = list;
10311ae3d29cSBarry Smith     amsopt->nlist = ntext;
10321ae3d29cSBarry Smith   }
103353acd3b1SBarry Smith   ierr = PetscOptionsGetEList(PetscOptionsObject.prefix,opt,list,ntext,value,set);CHKERRQ(ierr);
103461b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
10350fdccdaeSBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s> (choose one of)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,currentvalue);CHKERRQ(ierr);
103653acd3b1SBarry Smith     for (i=0; i<ntext; i++) {
1037e55864a3SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s",list[i]);CHKERRQ(ierr);
103853acd3b1SBarry Smith     }
1039e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," (%s)\n",ManSection(man));CHKERRQ(ierr);
104053acd3b1SBarry Smith   }
104153acd3b1SBarry Smith   PetscFunctionReturn(0);
104253acd3b1SBarry Smith }
104353acd3b1SBarry Smith 
104453acd3b1SBarry Smith #undef __FUNCT__
1045e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsBoolGroupBegin_Private"
104653acd3b1SBarry Smith /*@C
1047acfcf0e5SJed Brown      PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for
1048d5649816SBarry Smith        which at most a single value can be true.
104953acd3b1SBarry Smith 
10503f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
105153acd3b1SBarry Smith 
105253acd3b1SBarry Smith    Input Parameters:
105353acd3b1SBarry Smith +  opt - option name
105453acd3b1SBarry Smith .  text - short string that describes the option
105553acd3b1SBarry Smith -  man - manual page with additional information on option
105653acd3b1SBarry Smith 
105753acd3b1SBarry Smith    Output Parameter:
105853acd3b1SBarry Smith .  flg - whether that option was set or not
105953acd3b1SBarry Smith 
106053acd3b1SBarry Smith    Level: intermediate
106153acd3b1SBarry Smith 
106253acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
106353acd3b1SBarry Smith 
1064acfcf0e5SJed Brown    Must be followed by 0 or more PetscOptionsBoolGroup()s and PetscOptionsBoolGroupEnd()
106553acd3b1SBarry Smith 
106653acd3b1SBarry Smith     Concepts: options database^logical group
106753acd3b1SBarry Smith 
106853acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1069acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
107053acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
107153acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1072acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1073a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
107453acd3b1SBarry Smith @*/
1075e55864a3SBarry Smith PetscErrorCode  PetscOptionsBoolGroupBegin_Private(PetscOptionsObjectType *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool  *flg)
107653acd3b1SBarry Smith {
107753acd3b1SBarry Smith   PetscErrorCode ierr;
10781ae3d29cSBarry Smith   PetscOptions   amsopt;
107953acd3b1SBarry Smith 
108053acd3b1SBarry Smith   PetscFunctionBegin;
1081e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1082*83355fc5SBarry Smith     ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1083ace3abfcSBarry Smith     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1084a297a907SKarl Rupp 
1085ace3abfcSBarry Smith     *(PetscBool*)amsopt->data = PETSC_FALSE;
10861ae3d29cSBarry Smith   }
108768b16fdaSBarry Smith   *flg = PETSC_FALSE;
1088e55864a3SBarry Smith   ierr = PetscOptionsGetBool(PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr);
1089e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1090e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  Pick at most one of -------------\n");CHKERRQ(ierr);
1091e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"    -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
109253acd3b1SBarry Smith   }
109353acd3b1SBarry Smith   PetscFunctionReturn(0);
109453acd3b1SBarry Smith }
109553acd3b1SBarry Smith 
109653acd3b1SBarry Smith #undef __FUNCT__
1097e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsBoolGroup_Private"
109853acd3b1SBarry Smith /*@C
1099acfcf0e5SJed Brown      PetscOptionsBoolGroup - One in a series of logical queries on the options database for
1100d5649816SBarry Smith        which at most a single value can be true.
110153acd3b1SBarry Smith 
11023f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
110353acd3b1SBarry Smith 
110453acd3b1SBarry Smith    Input Parameters:
110553acd3b1SBarry Smith +  opt - option name
110653acd3b1SBarry Smith .  text - short string that describes the option
110753acd3b1SBarry Smith -  man - manual page with additional information on option
110853acd3b1SBarry Smith 
110953acd3b1SBarry Smith    Output Parameter:
111053acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
111153acd3b1SBarry Smith 
111253acd3b1SBarry Smith    Level: intermediate
111353acd3b1SBarry Smith 
111453acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
111553acd3b1SBarry Smith 
1116acfcf0e5SJed Brown    Must follow a PetscOptionsBoolGroupBegin() and preceded a PetscOptionsBoolGroupEnd()
111753acd3b1SBarry Smith 
111853acd3b1SBarry Smith     Concepts: options database^logical group
111953acd3b1SBarry Smith 
112053acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1121acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
112253acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
112353acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1124acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1125a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
112653acd3b1SBarry Smith @*/
1127e55864a3SBarry Smith PetscErrorCode  PetscOptionsBoolGroup_Private(PetscOptionsObjectType *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool  *flg)
112853acd3b1SBarry Smith {
112953acd3b1SBarry Smith   PetscErrorCode ierr;
11301ae3d29cSBarry Smith   PetscOptions   amsopt;
113153acd3b1SBarry Smith 
113253acd3b1SBarry Smith   PetscFunctionBegin;
1133e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1134*83355fc5SBarry Smith     ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1135ace3abfcSBarry Smith     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1136a297a907SKarl Rupp 
1137ace3abfcSBarry Smith     *(PetscBool*)amsopt->data = PETSC_FALSE;
11381ae3d29cSBarry Smith   }
113917326d04SJed Brown   *flg = PETSC_FALSE;
1140e55864a3SBarry Smith   ierr = PetscOptionsGetBool(PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr);
1141e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1142e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"    -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
114353acd3b1SBarry Smith   }
114453acd3b1SBarry Smith   PetscFunctionReturn(0);
114553acd3b1SBarry Smith }
114653acd3b1SBarry Smith 
114753acd3b1SBarry Smith #undef __FUNCT__
1148e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsBoolGroupEnd_Private"
114953acd3b1SBarry Smith /*@C
1150acfcf0e5SJed Brown      PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for
1151d5649816SBarry Smith        which at most a single value can be true.
115253acd3b1SBarry Smith 
11533f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
115453acd3b1SBarry Smith 
115553acd3b1SBarry Smith    Input Parameters:
115653acd3b1SBarry Smith +  opt - option name
115753acd3b1SBarry Smith .  text - short string that describes the option
115853acd3b1SBarry Smith -  man - manual page with additional information on option
115953acd3b1SBarry Smith 
116053acd3b1SBarry Smith    Output Parameter:
116153acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
116253acd3b1SBarry Smith 
116353acd3b1SBarry Smith    Level: intermediate
116453acd3b1SBarry Smith 
116553acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
116653acd3b1SBarry Smith 
1167acfcf0e5SJed Brown    Must follow a PetscOptionsBoolGroupBegin()
116853acd3b1SBarry Smith 
116953acd3b1SBarry Smith     Concepts: options database^logical group
117053acd3b1SBarry Smith 
117153acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1172acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
117353acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
117453acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1175acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1176a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
117753acd3b1SBarry Smith @*/
1178e55864a3SBarry Smith PetscErrorCode  PetscOptionsBoolGroupEnd_Private(PetscOptionsObjectType *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool  *flg)
117953acd3b1SBarry Smith {
118053acd3b1SBarry Smith   PetscErrorCode ierr;
11811ae3d29cSBarry Smith   PetscOptions   amsopt;
118253acd3b1SBarry Smith 
118353acd3b1SBarry Smith   PetscFunctionBegin;
1184e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1185*83355fc5SBarry Smith     ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1186ace3abfcSBarry Smith     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1187a297a907SKarl Rupp 
1188ace3abfcSBarry Smith     *(PetscBool*)amsopt->data = PETSC_FALSE;
11891ae3d29cSBarry Smith   }
119017326d04SJed Brown   *flg = PETSC_FALSE;
1191e55864a3SBarry Smith   ierr = PetscOptionsGetBool(PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr);
1192e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1193e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"    -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
119453acd3b1SBarry Smith   }
119553acd3b1SBarry Smith   PetscFunctionReturn(0);
119653acd3b1SBarry Smith }
119753acd3b1SBarry Smith 
119853acd3b1SBarry Smith #undef __FUNCT__
1199e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsBool_Private"
120053acd3b1SBarry Smith /*@C
1201acfcf0e5SJed Brown    PetscOptionsBool - Determines if a particular option is in the database with a true or false
120253acd3b1SBarry Smith 
12033f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
120453acd3b1SBarry Smith 
120553acd3b1SBarry Smith    Input Parameters:
120653acd3b1SBarry Smith +  opt - option name
120753acd3b1SBarry Smith .  text - short string that describes the option
1208868c398cSBarry Smith .  man - manual page with additional information on option
120994ae4db5SBarry Smith -  currentvalue - the current value
121053acd3b1SBarry Smith 
121153acd3b1SBarry Smith    Output Parameter:
121253acd3b1SBarry Smith .  flg - PETSC_TRUE or PETSC_FALSE
121353acd3b1SBarry Smith .  set - PETSC_TRUE if found, else PETSC_FALSE
121453acd3b1SBarry Smith 
121553acd3b1SBarry Smith    Level: beginner
121653acd3b1SBarry Smith 
121753acd3b1SBarry Smith    Concepts: options database^logical
121853acd3b1SBarry Smith 
121953acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
122053acd3b1SBarry Smith 
122153acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1222acfcf0e5SJed Brown           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
1223acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
122453acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
122553acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1226acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1227a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
122853acd3b1SBarry Smith @*/
1229e55864a3SBarry Smith PetscErrorCode  PetscOptionsBool_Private(PetscOptionsObjectType *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool deflt,PetscBool  *flg,PetscBool  *set)
123053acd3b1SBarry Smith {
123153acd3b1SBarry Smith   PetscErrorCode ierr;
1232ace3abfcSBarry Smith   PetscBool      iset;
1233aee2cecaSBarry Smith   PetscOptions   amsopt;
123453acd3b1SBarry Smith 
123553acd3b1SBarry Smith   PetscFunctionBegin;
1236e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1237e55864a3SBarry Smith     ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1238ace3abfcSBarry Smith     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1239a297a907SKarl Rupp 
124094ae4db5SBarry Smith     *(PetscBool*)amsopt->data = currentvalue;
1241af6d86caSBarry Smith   }
1242acfcf0e5SJed Brown   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,&iset);CHKERRQ(ierr);
124353acd3b1SBarry Smith   if (set) *set = iset;
124461b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
124594ae4db5SBarry Smith     const char *v = PetscBools[currentvalue];
12462aa6d131SJed Brown     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: <%s> %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,v,text,ManSection(man));CHKERRQ(ierr);
124753acd3b1SBarry Smith   }
124853acd3b1SBarry Smith   PetscFunctionReturn(0);
124953acd3b1SBarry Smith }
125053acd3b1SBarry Smith 
125153acd3b1SBarry Smith #undef __FUNCT__
1252e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsRealArray_Private"
125353acd3b1SBarry Smith /*@C
125453acd3b1SBarry Smith    PetscOptionsRealArray - Gets an array of double values for a particular
125553acd3b1SBarry Smith    option in the database. The values must be separated with commas with
125653acd3b1SBarry Smith    no intervening spaces.
125753acd3b1SBarry Smith 
12583f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
125953acd3b1SBarry Smith 
126053acd3b1SBarry Smith    Input Parameters:
126153acd3b1SBarry Smith +  opt - the option one is seeking
126253acd3b1SBarry Smith .  text - short string describing option
126353acd3b1SBarry Smith .  man - manual page for option
126453acd3b1SBarry Smith -  nmax - maximum number of values
126553acd3b1SBarry Smith 
126653acd3b1SBarry Smith    Output Parameter:
126753acd3b1SBarry Smith +  value - location to copy values
126853acd3b1SBarry Smith .  nmax - actual number of values found
126953acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
127053acd3b1SBarry Smith 
127153acd3b1SBarry Smith    Level: beginner
127253acd3b1SBarry Smith 
127353acd3b1SBarry Smith    Notes:
127453acd3b1SBarry Smith    The user should pass in an array of doubles
127553acd3b1SBarry Smith 
127653acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
127753acd3b1SBarry Smith 
127853acd3b1SBarry Smith    Concepts: options database^array of strings
127953acd3b1SBarry Smith 
128053acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1281acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
128253acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
128353acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1284acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1285a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
128653acd3b1SBarry Smith @*/
1287e55864a3SBarry Smith PetscErrorCode  PetscOptionsRealArray_Private(PetscOptionsObjectType *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool  *set)
128853acd3b1SBarry Smith {
128953acd3b1SBarry Smith   PetscErrorCode ierr;
129053acd3b1SBarry Smith   PetscInt       i;
1291e26ddf31SBarry Smith   PetscOptions   amsopt;
129253acd3b1SBarry Smith 
129353acd3b1SBarry Smith   PetscFunctionBegin;
1294e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1295e26ddf31SBarry Smith     PetscReal *vals;
1296e26ddf31SBarry Smith 
1297e55864a3SBarry Smith     ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr);
1298e55864a3SBarry Smith     ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
1299e26ddf31SBarry Smith     vals = (PetscReal*)amsopt->data;
1300e26ddf31SBarry Smith     for (i=0; i<*n; i++) vals[i] = value[i];
1301e26ddf31SBarry Smith     amsopt->arraylength = *n;
1302e26ddf31SBarry Smith   }
1303e55864a3SBarry Smith   ierr = PetscOptionsGetRealArray(PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr);
1304e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1305e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%G",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,value[0]);CHKERRQ(ierr);
130653acd3b1SBarry Smith     for (i=1; i<*n; i++) {
1307e55864a3SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%g",(double)value[i]);CHKERRQ(ierr);
130853acd3b1SBarry Smith     }
1309e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
131053acd3b1SBarry Smith   }
131153acd3b1SBarry Smith   PetscFunctionReturn(0);
131253acd3b1SBarry Smith }
131353acd3b1SBarry Smith 
131453acd3b1SBarry Smith 
131553acd3b1SBarry Smith #undef __FUNCT__
1316e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsIntArray_Private"
131753acd3b1SBarry Smith /*@C
131853acd3b1SBarry Smith    PetscOptionsIntArray - Gets an array of integers for a particular
1319b32a342fSShri Abhyankar    option in the database.
132053acd3b1SBarry Smith 
13213f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
132253acd3b1SBarry Smith 
132353acd3b1SBarry Smith    Input Parameters:
132453acd3b1SBarry Smith +  opt - the option one is seeking
132553acd3b1SBarry Smith .  text - short string describing option
132653acd3b1SBarry Smith .  man - manual page for option
1327f8a50e2bSBarry Smith -  n - maximum number of values
132853acd3b1SBarry Smith 
132953acd3b1SBarry Smith    Output Parameter:
133053acd3b1SBarry Smith +  value - location to copy values
1331f8a50e2bSBarry Smith .  n - actual number of values found
133253acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
133353acd3b1SBarry Smith 
133453acd3b1SBarry Smith    Level: beginner
133553acd3b1SBarry Smith 
133653acd3b1SBarry Smith    Notes:
1337b32a342fSShri Abhyankar    The array can be passed as
1338b32a342fSShri Abhyankar    a comma seperated list:                                 0,1,2,3,4,5,6,7
13390fd488f5SShri Abhyankar    a range (start-end+1):                                  0-8
13400fd488f5SShri Abhyankar    a range with given increment (start-end+1:inc):         0-7:2
13410fd488f5SShri Abhyankar    a combination of values and ranges seperated by commas: 0,1-8,8-15:2
1342b32a342fSShri Abhyankar 
1343b32a342fSShri Abhyankar    There must be no intervening spaces between the values.
134453acd3b1SBarry Smith 
134553acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
134653acd3b1SBarry Smith 
1347b32a342fSShri Abhyankar    Concepts: options database^array of ints
134853acd3b1SBarry Smith 
134953acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1350acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
135153acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
135253acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1353acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1354a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList(), PetscOptionsRealArray()
135553acd3b1SBarry Smith @*/
1356e55864a3SBarry Smith PetscErrorCode  PetscOptionsIntArray_Private(PetscOptionsObjectType *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool  *set)
135753acd3b1SBarry Smith {
135853acd3b1SBarry Smith   PetscErrorCode ierr;
135953acd3b1SBarry Smith   PetscInt       i;
1360e26ddf31SBarry Smith   PetscOptions   amsopt;
136153acd3b1SBarry Smith 
136253acd3b1SBarry Smith   PetscFunctionBegin;
1363e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1364e26ddf31SBarry Smith     PetscInt *vals;
1365e26ddf31SBarry Smith 
1366e55864a3SBarry Smith     ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr);
1367854ce69bSBarry Smith     ierr = PetscMalloc1(*n,(PetscInt**)&amsopt->data);CHKERRQ(ierr);
1368e26ddf31SBarry Smith     vals = (PetscInt*)amsopt->data;
1369e26ddf31SBarry Smith     for (i=0; i<*n; i++) vals[i] = value[i];
1370e26ddf31SBarry Smith     amsopt->arraylength = *n;
1371e26ddf31SBarry Smith   }
1372e55864a3SBarry Smith   ierr = PetscOptionsGetIntArray(PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr);
1373e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1374e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%d",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,value[0]);CHKERRQ(ierr);
137553acd3b1SBarry Smith     for (i=1; i<*n; i++) {
1376e55864a3SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%d",value[i]);CHKERRQ(ierr);
137753acd3b1SBarry Smith     }
1378e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
137953acd3b1SBarry Smith   }
138053acd3b1SBarry Smith   PetscFunctionReturn(0);
138153acd3b1SBarry Smith }
138253acd3b1SBarry Smith 
138353acd3b1SBarry Smith #undef __FUNCT__
1384e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsStringArray_Private"
138553acd3b1SBarry Smith /*@C
138653acd3b1SBarry Smith    PetscOptionsStringArray - Gets an array of string values for a particular
138753acd3b1SBarry Smith    option in the database. The values must be separated with commas with
138853acd3b1SBarry Smith    no intervening spaces.
138953acd3b1SBarry Smith 
13903f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
139153acd3b1SBarry Smith 
139253acd3b1SBarry Smith    Input Parameters:
139353acd3b1SBarry Smith +  opt - the option one is seeking
139453acd3b1SBarry Smith .  text - short string describing option
139553acd3b1SBarry Smith .  man - manual page for option
139653acd3b1SBarry Smith -  nmax - maximum number of strings
139753acd3b1SBarry Smith 
139853acd3b1SBarry Smith    Output Parameter:
139953acd3b1SBarry Smith +  value - location to copy strings
140053acd3b1SBarry Smith .  nmax - actual number of strings found
140153acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
140253acd3b1SBarry Smith 
140353acd3b1SBarry Smith    Level: beginner
140453acd3b1SBarry Smith 
140553acd3b1SBarry Smith    Notes:
140653acd3b1SBarry Smith    The user should pass in an array of pointers to char, to hold all the
140753acd3b1SBarry Smith    strings returned by this function.
140853acd3b1SBarry Smith 
140953acd3b1SBarry Smith    The user is responsible for deallocating the strings that are
141053acd3b1SBarry Smith    returned. The Fortran interface for this routine is not supported.
141153acd3b1SBarry Smith 
141253acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
141353acd3b1SBarry Smith 
141453acd3b1SBarry Smith    Concepts: options database^array of strings
141553acd3b1SBarry Smith 
141653acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1417acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
141853acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
141953acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1420acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1421a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
142253acd3b1SBarry Smith @*/
1423e55864a3SBarry Smith PetscErrorCode  PetscOptionsStringArray_Private(PetscOptionsObjectType *PetscOptionsObject,const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool  *set)
142453acd3b1SBarry Smith {
142553acd3b1SBarry Smith   PetscErrorCode ierr;
14261ae3d29cSBarry Smith   PetscOptions   amsopt;
142753acd3b1SBarry Smith 
142853acd3b1SBarry Smith   PetscFunctionBegin;
1429e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1430e55864a3SBarry Smith     ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING_ARRAY,&amsopt);CHKERRQ(ierr);
1431854ce69bSBarry Smith     ierr = PetscMalloc1(*nmax,(char**)&amsopt->data);CHKERRQ(ierr);
1432a297a907SKarl Rupp 
14331ae3d29cSBarry Smith     amsopt->arraylength = *nmax;
14341ae3d29cSBarry Smith   }
1435e55864a3SBarry Smith   ierr = PetscOptionsGetStringArray(PetscOptionsObject->prefix,opt,value,nmax,set);CHKERRQ(ierr);
1436e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1437e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
143853acd3b1SBarry Smith   }
143953acd3b1SBarry Smith   PetscFunctionReturn(0);
144053acd3b1SBarry Smith }
144153acd3b1SBarry Smith 
1442e2446a98SMatthew Knepley #undef __FUNCT__
1443e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsBoolArray_Private"
1444e2446a98SMatthew Knepley /*@C
1445acfcf0e5SJed Brown    PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular
1446e2446a98SMatthew Knepley    option in the database. The values must be separated with commas with
1447e2446a98SMatthew Knepley    no intervening spaces.
1448e2446a98SMatthew Knepley 
14493f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
1450e2446a98SMatthew Knepley 
1451e2446a98SMatthew Knepley    Input Parameters:
1452e2446a98SMatthew Knepley +  opt - the option one is seeking
1453e2446a98SMatthew Knepley .  text - short string describing option
1454e2446a98SMatthew Knepley .  man - manual page for option
1455e2446a98SMatthew Knepley -  nmax - maximum number of values
1456e2446a98SMatthew Knepley 
1457e2446a98SMatthew Knepley    Output Parameter:
1458e2446a98SMatthew Knepley +  value - location to copy values
1459e2446a98SMatthew Knepley .  nmax - actual number of values found
1460e2446a98SMatthew Knepley -  set - PETSC_TRUE if found, else PETSC_FALSE
1461e2446a98SMatthew Knepley 
1462e2446a98SMatthew Knepley    Level: beginner
1463e2446a98SMatthew Knepley 
1464e2446a98SMatthew Knepley    Notes:
1465e2446a98SMatthew Knepley    The user should pass in an array of doubles
1466e2446a98SMatthew Knepley 
1467e2446a98SMatthew Knepley    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1468e2446a98SMatthew Knepley 
1469e2446a98SMatthew Knepley    Concepts: options database^array of strings
1470e2446a98SMatthew Knepley 
1471e2446a98SMatthew Knepley .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1472acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1473e2446a98SMatthew Knepley           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1474e2446a98SMatthew Knepley           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1475acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1476a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
1477e2446a98SMatthew Knepley @*/
1478e55864a3SBarry Smith PetscErrorCode  PetscOptionsBoolArray_Private(PetscOptionsObjectType *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set)
1479e2446a98SMatthew Knepley {
1480e2446a98SMatthew Knepley   PetscErrorCode ierr;
1481e2446a98SMatthew Knepley   PetscInt       i;
14821ae3d29cSBarry Smith   PetscOptions   amsopt;
1483e2446a98SMatthew Knepley 
1484e2446a98SMatthew Knepley   PetscFunctionBegin;
1485e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1486ace3abfcSBarry Smith     PetscBool *vals;
14871ae3d29cSBarry Smith 
1488*83355fc5SBarry Smith     ierr = PetscOptionsCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL_ARRAY,&amsopt);CHKERRQ(ierr);
1489*83355fc5SBarry Smith     ierr = PetscMalloc1(*,(PetscBool*)&amsopt->data);CHKERRQ(ierr);
1490ace3abfcSBarry Smith     vals = (PetscBool*)amsopt->data;
14911ae3d29cSBarry Smith     for (i=0; i<*n; i++) vals[i] = value[i];
14921ae3d29cSBarry Smith     amsopt->arraylength = *n;
14931ae3d29cSBarry Smith   }
1494e55864a3SBarry Smith   ierr = PetscOptionsGetBoolArray(PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr);
1495e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1496e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%d",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,value[0]);CHKERRQ(ierr);
1497e2446a98SMatthew Knepley     for (i=1; i<*n; i++) {
1498e55864a3SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%d",value[i]);CHKERRQ(ierr);
1499e2446a98SMatthew Knepley     }
1500e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1501e2446a98SMatthew Knepley   }
1502e2446a98SMatthew Knepley   PetscFunctionReturn(0);
1503e2446a98SMatthew Knepley }
1504e2446a98SMatthew Knepley 
15058cc676e6SMatthew G Knepley #undef __FUNCT__
1506e55864a3SBarry Smith #define __FUNCT__ "PetscOptionsViewer_Private"
15078cc676e6SMatthew G Knepley /*@C
1508d1da0b69SBarry Smith    PetscOptionsViewer - Gets a viewer appropriate for the type indicated by the user
15098cc676e6SMatthew G Knepley 
15108cc676e6SMatthew G Knepley    Logically Collective on the communicator passed in PetscOptionsBegin()
15118cc676e6SMatthew G Knepley 
15128cc676e6SMatthew G Knepley    Input Parameters:
15138cc676e6SMatthew G Knepley +  opt - option name
15148cc676e6SMatthew G Knepley .  text - short string that describes the option
15158cc676e6SMatthew G Knepley -  man - manual page with additional information on option
15168cc676e6SMatthew G Knepley 
15178cc676e6SMatthew G Knepley    Output Parameter:
15188cc676e6SMatthew G Knepley +  viewer - the viewer
15198cc676e6SMatthew G Knepley -  set - PETSC_TRUE if found, else PETSC_FALSE
15208cc676e6SMatthew G Knepley 
15218cc676e6SMatthew G Knepley    Level: beginner
15228cc676e6SMatthew G Knepley 
15238cc676e6SMatthew G Knepley    Concepts: options database^has int
15248cc676e6SMatthew G Knepley 
15258cc676e6SMatthew G Knepley    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
15268cc676e6SMatthew G Knepley 
15275a7113b9SPatrick Sanan    See PetscOptionsGetViewer() for the format of the supplied viewer and its options
15288cc676e6SMatthew G Knepley 
15298cc676e6SMatthew G Knepley .seealso: PetscOptionsGetViewer(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
15308cc676e6SMatthew G Knepley           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
15318cc676e6SMatthew G Knepley           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
15328cc676e6SMatthew G Knepley           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
15338cc676e6SMatthew G Knepley           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
15348cc676e6SMatthew G Knepley           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1535a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
15368cc676e6SMatthew G Knepley @*/
1537e55864a3SBarry Smith PetscErrorCode  PetscOptionsViewer_Private(PetscOptionsObjectType *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool  *set)
15388cc676e6SMatthew G Knepley {
15398cc676e6SMatthew G Knepley   PetscErrorCode ierr;
15408cc676e6SMatthew G Knepley   PetscOptions   amsopt;
15418cc676e6SMatthew G Knepley 
15428cc676e6SMatthew G Knepley   PetscFunctionBegin;
15438cc676e6SMatthew G Knepley   if (!PetscOptionsPublishCount) {
15448cc676e6SMatthew G Knepley     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
154564facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
15465b02f95dSBarry Smith     ierr = PetscStrdup("",(char**)&amsopt->data);CHKERRQ(ierr);
15478cc676e6SMatthew G Knepley   }
1548e55864a3SBarry Smith   ierr = PetscOptionsGetViewer(PetscOptionsObject->comm,PetscOptionsObject->prefix,opt,viewer,format,set);CHKERRQ(ierr);
1549e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1550e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%s>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,"",text,ManSection(man));CHKERRQ(ierr);
15518cc676e6SMatthew G Knepley   }
15528cc676e6SMatthew G Knepley   PetscFunctionReturn(0);
15538cc676e6SMatthew G Knepley }
15548cc676e6SMatthew G Knepley 
155553acd3b1SBarry Smith 
155653acd3b1SBarry Smith #undef __FUNCT__
155753acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsHead"
155853acd3b1SBarry Smith /*@C
1559b52f573bSBarry Smith      PetscOptionsHead - Puts a heading before listing any more published options. Used, for example,
156053acd3b1SBarry Smith             in KSPSetFromOptions_GMRES().
156153acd3b1SBarry Smith 
15623f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
156353acd3b1SBarry Smith 
156453acd3b1SBarry Smith    Input Parameter:
156553acd3b1SBarry Smith .   head - the heading text
156653acd3b1SBarry Smith 
156753acd3b1SBarry Smith 
156853acd3b1SBarry Smith    Level: intermediate
156953acd3b1SBarry Smith 
157053acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
157153acd3b1SBarry Smith 
1572b52f573bSBarry Smith           Can be followed by a call to PetscOptionsTail() in the same function.
157353acd3b1SBarry Smith 
157453acd3b1SBarry Smith    Concepts: options database^subheading
157553acd3b1SBarry Smith 
157653acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1577acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
157853acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
157953acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1580acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1581a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
158253acd3b1SBarry Smith @*/
1583e55864a3SBarry Smith PetscErrorCode  PetscOptionsHead(PetscOptionsObjectType *PetscOptionsObject,const char head[])
158453acd3b1SBarry Smith {
158553acd3b1SBarry Smith   PetscErrorCode ierr;
158653acd3b1SBarry Smith 
158753acd3b1SBarry Smith   PetscFunctionBegin;
1588e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1589e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  %s\n",head);CHKERRQ(ierr);
159053acd3b1SBarry Smith   }
159153acd3b1SBarry Smith   PetscFunctionReturn(0);
159253acd3b1SBarry Smith }
159353acd3b1SBarry Smith 
159453acd3b1SBarry Smith 
159553acd3b1SBarry Smith 
159653acd3b1SBarry Smith 
159753acd3b1SBarry Smith 
159853acd3b1SBarry Smith 
1599