xref: /petsc/src/sys/objects/aoptions.c (revision 6eeb591da1cd8f41f90e44e952934481bcc4b9a2)
153acd3b1SBarry Smith /*
23fc1eb6aSBarry Smith    Implements the higher-level options database querying methods. These are self-documenting and can attach at runtime to
33fc1eb6aSBarry Smith    GUI code to display the options and get values from the users.
453acd3b1SBarry Smith 
553acd3b1SBarry Smith */
653acd3b1SBarry Smith 
7af0996ceSBarry Smith #include <petsc/private/petscimpl.h>        /*I  "petscsys.h"   I*/
8665c2dedSJed Brown #include <petscviewer.h>
953acd3b1SBarry Smith 
102aa6d131SJed Brown #define ManSection(str) ((str) ? (str) : "None")
112aa6d131SJed Brown 
1253acd3b1SBarry Smith /*
1353acd3b1SBarry Smith     Keep a linked list of options that have been posted and we are waiting for
143fc1eb6aSBarry Smith    user selection. See the manual page for PetscOptionsBegin()
1553acd3b1SBarry Smith 
1653acd3b1SBarry Smith     Eventually we'll attach this beast to a MPI_Comm
1753acd3b1SBarry Smith */
18e55864a3SBarry Smith 
1953acd3b1SBarry Smith /*
2053acd3b1SBarry Smith     Handles setting up the data structure in a call to PetscOptionsBegin()
2153acd3b1SBarry Smith */
224416b707SBarry Smith PetscErrorCode PetscOptionsBegin_Private(PetscOptionItems *PetscOptionsObject,MPI_Comm comm,const char prefix[],const char title[],const char mansec[])
2353acd3b1SBarry Smith {
2453acd3b1SBarry Smith   PetscErrorCode ierr;
2553acd3b1SBarry Smith 
2653acd3b1SBarry Smith   PetscFunctionBegin;
27064a246eSJacob Faibussowitsch   if (prefix) PetscValidCharPointer(prefix,3);
28064a246eSJacob Faibussowitsch   PetscValidCharPointer(title,4);
29064a246eSJacob Faibussowitsch   if (mansec) PetscValidCharPointer(mansec,5);
300eb63584SBarry Smith   if (!PetscOptionsObject->alreadyprinted) {
319de0f6ecSBarry Smith     if (!PetscOptionsHelpPrintedSingleton) {
329de0f6ecSBarry Smith       ierr = PetscOptionsHelpPrintedCreate(&PetscOptionsHelpPrintedSingleton);CHKERRQ(ierr);
339de0f6ecSBarry Smith     }
349de0f6ecSBarry Smith     ierr = PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrintedSingleton,prefix,title,&PetscOptionsObject->alreadyprinted);CHKERRQ(ierr);
350eb63584SBarry Smith   }
3602c9f0b5SLisandro Dalcin   PetscOptionsObject->next          = NULL;
37e55864a3SBarry Smith   PetscOptionsObject->comm          = comm;
38e55864a3SBarry Smith   PetscOptionsObject->changedmethod = PETSC_FALSE;
39a297a907SKarl Rupp 
40e55864a3SBarry Smith   ierr = PetscStrallocpy(prefix,&PetscOptionsObject->prefix);CHKERRQ(ierr);
41e55864a3SBarry Smith   ierr = PetscStrallocpy(title,&PetscOptionsObject->title);CHKERRQ(ierr);
4253acd3b1SBarry Smith 
432d747510SLisandro Dalcin   ierr = PetscOptionsHasHelp(PetscOptionsObject->options,&PetscOptionsObject->printhelp);CHKERRQ(ierr);
44e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1) {
45e55864a3SBarry Smith     if (!PetscOptionsObject->alreadyprinted) {
46c0bb3764SVaclav Hapla       ierr = (*PetscHelpPrintf)(comm,"----------------------------------------\n%s:\n",title);CHKERRQ(ierr);
4753acd3b1SBarry Smith     }
4861b37b28SSatish Balay   }
4953acd3b1SBarry Smith   PetscFunctionReturn(0);
5053acd3b1SBarry Smith }
5153acd3b1SBarry Smith 
523194b578SJed Brown /*
533194b578SJed Brown     Handles setting up the data structure in a call to PetscObjectOptionsBegin()
543194b578SJed Brown */
554416b707SBarry Smith PetscErrorCode PetscObjectOptionsBegin_Private(PetscOptionItems *PetscOptionsObject,PetscObject obj)
563194b578SJed Brown {
573194b578SJed Brown   PetscErrorCode ierr;
583194b578SJed Brown   char           title[256];
593194b578SJed Brown   PetscBool      flg;
603194b578SJed Brown 
613194b578SJed Brown   PetscFunctionBegin;
62064a246eSJacob Faibussowitsch   PetscValidHeader(obj,2);
63e55864a3SBarry Smith   PetscOptionsObject->object         = obj;
64e55864a3SBarry Smith   PetscOptionsObject->alreadyprinted = obj->optionsprinted;
65a297a907SKarl Rupp 
663194b578SJed Brown   ierr = PetscStrcmp(obj->description,obj->class_name,&flg);CHKERRQ(ierr);
673194b578SJed Brown   if (flg) {
688caf3d72SBarry Smith     ierr = PetscSNPrintf(title,sizeof(title),"%s options",obj->class_name);CHKERRQ(ierr);
693194b578SJed Brown   } else {
708caf3d72SBarry Smith     ierr = PetscSNPrintf(title,sizeof(title),"%s (%s) options",obj->description,obj->class_name);CHKERRQ(ierr);
713194b578SJed Brown   }
72e55864a3SBarry Smith   ierr = PetscOptionsBegin_Private(PetscOptionsObject,obj->comm,obj->prefix,title,obj->mansec);CHKERRQ(ierr);
733194b578SJed Brown   PetscFunctionReturn(0);
743194b578SJed Brown }
753194b578SJed Brown 
7653acd3b1SBarry Smith /*
7753acd3b1SBarry Smith      Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd()
7853acd3b1SBarry Smith */
794416b707SBarry Smith static int PetscOptionItemCreate_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscOptionType t,PetscOptionItem *amsopt)
8053acd3b1SBarry Smith {
8153acd3b1SBarry Smith   int             ierr;
824416b707SBarry Smith   PetscOptionItem next;
833be6e4c3SJed Brown   PetscBool       valid;
8453acd3b1SBarry Smith 
8553acd3b1SBarry Smith   PetscFunctionBegin;
863be6e4c3SJed Brown   ierr = PetscOptionsValidKey(opt,&valid);CHKERRQ(ierr);
873be6e4c3SJed Brown   if (!valid) SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_ARG_INCOMP,"The option '%s' is not a valid key",opt);
883be6e4c3SJed Brown 
89b00a9115SJed Brown   ierr            = PetscNew(amsopt);CHKERRQ(ierr);
9002c9f0b5SLisandro Dalcin   (*amsopt)->next = NULL;
9153acd3b1SBarry Smith   (*amsopt)->set  = PETSC_FALSE;
926356e834SBarry Smith   (*amsopt)->type = t;
9302c9f0b5SLisandro Dalcin   (*amsopt)->data = NULL;
9461b37b28SSatish Balay 
9553acd3b1SBarry Smith   ierr = PetscStrallocpy(text,&(*amsopt)->text);CHKERRQ(ierr);
9653acd3b1SBarry Smith   ierr = PetscStrallocpy(opt,&(*amsopt)->option);CHKERRQ(ierr);
976356e834SBarry Smith   ierr = PetscStrallocpy(man,&(*amsopt)->man);CHKERRQ(ierr);
9853acd3b1SBarry Smith 
99e55864a3SBarry Smith   if (!PetscOptionsObject->next) PetscOptionsObject->next = *amsopt;
100a297a907SKarl Rupp   else {
101e55864a3SBarry Smith     next = PetscOptionsObject->next;
10253acd3b1SBarry Smith     while (next->next) next = next->next;
10353acd3b1SBarry Smith     next->next = *amsopt;
10453acd3b1SBarry Smith   }
10553acd3b1SBarry Smith   PetscFunctionReturn(0);
10653acd3b1SBarry Smith }
10753acd3b1SBarry Smith 
108aee2cecaSBarry Smith /*
1093fc1eb6aSBarry Smith     PetscScanString -  Gets user input via stdin from process and broadcasts to all processes
1103fc1eb6aSBarry Smith 
111d083f849SBarry Smith     Collective
1123fc1eb6aSBarry Smith 
1133fc1eb6aSBarry Smith    Input Parameters:
1143fc1eb6aSBarry Smith +     commm - communicator for the broadcast, must be PETSC_COMM_WORLD
1153fc1eb6aSBarry Smith .     n - length of the string, must be the same on all processes
1163fc1eb6aSBarry Smith -     str - location to store input
117aee2cecaSBarry Smith 
118aee2cecaSBarry Smith     Bugs:
119aee2cecaSBarry Smith .   Assumes process 0 of the given communicator has access to stdin
120aee2cecaSBarry Smith 
121aee2cecaSBarry Smith */
1223fc1eb6aSBarry Smith static PetscErrorCode PetscScanString(MPI_Comm comm,size_t n,char str[])
123aee2cecaSBarry Smith {
124330cf3c9SBarry Smith   size_t         i;
125aee2cecaSBarry Smith   char           c;
1263fc1eb6aSBarry Smith   PetscMPIInt    rank,nm;
127aee2cecaSBarry Smith   PetscErrorCode ierr;
128aee2cecaSBarry Smith 
129aee2cecaSBarry Smith   PetscFunctionBegin;
130ffc4695bSBarry Smith   ierr = MPI_Comm_rank(comm,&rank);CHKERRMPI(ierr);
131dd400576SPatrick Sanan   if (rank == 0) {
132aee2cecaSBarry Smith     c = (char) getchar();
133aee2cecaSBarry Smith     i = 0;
134aee2cecaSBarry Smith     while (c != '\n' && i < n-1) {
135aee2cecaSBarry Smith       str[i++] = c;
136aee2cecaSBarry Smith       c = (char)getchar();
137aee2cecaSBarry Smith     }
138aee2cecaSBarry Smith     str[i] = 0;
139aee2cecaSBarry Smith   }
1404dc2109aSBarry Smith   ierr = PetscMPIIntCast(n,&nm);CHKERRQ(ierr);
141ffc4695bSBarry Smith   ierr = MPI_Bcast(str,nm,MPI_CHAR,0,comm);CHKERRMPI(ierr);
142aee2cecaSBarry Smith   PetscFunctionReturn(0);
143aee2cecaSBarry Smith }
144aee2cecaSBarry Smith 
1455b02f95dSBarry Smith /*
1465b02f95dSBarry Smith     This is needed because certain strings may be freed by SAWs, hence we cannot use PetscStrallocpy()
1475b02f95dSBarry Smith */
1485b02f95dSBarry Smith static PetscErrorCode  PetscStrdup(const char s[],char *t[])
1495b02f95dSBarry Smith {
1505b02f95dSBarry Smith   PetscErrorCode ierr;
1515b02f95dSBarry Smith   size_t         len;
15202c9f0b5SLisandro Dalcin   char           *tmp = NULL;
1535b02f95dSBarry Smith 
1545b02f95dSBarry Smith   PetscFunctionBegin;
1555b02f95dSBarry Smith   if (s) {
1565b02f95dSBarry Smith     ierr = PetscStrlen(s,&len);CHKERRQ(ierr);
157f416af30SBarry Smith     tmp = (char*) malloc((len+1)*sizeof(char));
1585b02f95dSBarry Smith     if (!tmp) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_MEM,"No memory to duplicate string");
1595b02f95dSBarry Smith     ierr = PetscStrcpy(tmp,s);CHKERRQ(ierr);
1605b02f95dSBarry Smith   }
1615b02f95dSBarry Smith   *t = tmp;
1625b02f95dSBarry Smith   PetscFunctionReturn(0);
1635b02f95dSBarry Smith }
1645b02f95dSBarry Smith 
165aee2cecaSBarry Smith /*
1663cc1e11dSBarry Smith     PetscOptionsGetFromTextInput - Presents all the PETSc Options processed by the program so the user may change them at runtime
167aee2cecaSBarry Smith 
16895452b02SPatrick Sanan     Notes:
16995452b02SPatrick Sanan     this isn't really practical, it is just to demonstrate the principle
170aee2cecaSBarry Smith 
1717781c08eSBarry Smith     A carriage return indicates no change from the default; but this like -ksp_monitor <stdout>  the default is actually not stdout the default
1727781c08eSBarry Smith     is to do nothing so to get it to use stdout you need to type stdout. This is kind of bug?
1737781c08eSBarry Smith 
174aee2cecaSBarry Smith     Bugs:
1757781c08eSBarry Smith +    All processes must traverse through the exact same set of option queries due to the call to PetscScanString()
1763cc1e11dSBarry Smith .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
177aee2cecaSBarry Smith -    Only works for PetscInt == int, PetscReal == double etc
178aee2cecaSBarry Smith 
17995452b02SPatrick Sanan     Developer Notes:
18095452b02SPatrick Sanan     Normally the GUI that presents the options the user and retrieves the values would be running in a different
1813cc1e11dSBarry Smith      address space and communicating with the PETSc program
1823cc1e11dSBarry Smith 
183aee2cecaSBarry Smith */
1844416b707SBarry Smith PetscErrorCode PetscOptionsGetFromTextInput(PetscOptionItems *PetscOptionsObject)
1856356e834SBarry Smith {
1866356e834SBarry Smith   PetscErrorCode  ierr;
1874416b707SBarry Smith   PetscOptionItem next = PetscOptionsObject->next;
1886356e834SBarry Smith   char            str[512];
1897781c08eSBarry Smith   PetscBool       bid;
190a4404d99SBarry Smith   PetscReal       ir,*valr;
191330cf3c9SBarry Smith   PetscInt        *vald;
192330cf3c9SBarry Smith   size_t          i;
1936356e834SBarry Smith 
1942a409bb0SBarry Smith   PetscFunctionBegin;
195c0bb3764SVaclav Hapla   ierr = (*PetscPrintf)(PETSC_COMM_WORLD,"%s --------------------\n",PetscOptionsObject->title);CHKERRQ(ierr);
1966356e834SBarry Smith   while (next) {
1976356e834SBarry Smith     switch (next->type) {
1986356e834SBarry Smith     case OPTION_HEAD:
1996356e834SBarry Smith       break;
200e26ddf31SBarry Smith     case OPTION_INT_ARRAY:
201e55864a3SBarry Smith       ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1);CHKERRQ(ierr);
202e26ddf31SBarry Smith       vald = (PetscInt*) next->data;
203e26ddf31SBarry Smith       for (i=0; i<next->arraylength; i++) {
204e26ddf31SBarry Smith         ierr = PetscPrintf(PETSC_COMM_WORLD,"%d",vald[i]);CHKERRQ(ierr);
205e26ddf31SBarry Smith         if (i < next->arraylength-1) {
206e26ddf31SBarry Smith           ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr);
207e26ddf31SBarry Smith         }
208e26ddf31SBarry Smith       }
209e26ddf31SBarry Smith       ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s) ",next->text,next->man);CHKERRQ(ierr);
210e26ddf31SBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
211e26ddf31SBarry Smith       if (str[0]) {
212e26ddf31SBarry Smith         PetscToken token;
213e26ddf31SBarry Smith         PetscInt   n=0,nmax = next->arraylength,*dvalue = (PetscInt*)next->data,start,end;
214e26ddf31SBarry Smith         size_t     len;
215e26ddf31SBarry Smith         char       *value;
216ace3abfcSBarry Smith         PetscBool  foundrange;
217e26ddf31SBarry Smith 
218e26ddf31SBarry Smith         next->set = PETSC_TRUE;
219e26ddf31SBarry Smith         value     = str;
220e26ddf31SBarry Smith         ierr      = PetscTokenCreate(value,',',&token);CHKERRQ(ierr);
221e26ddf31SBarry Smith         ierr      = PetscTokenFind(token,&value);CHKERRQ(ierr);
222e26ddf31SBarry Smith         while (n < nmax) {
223e26ddf31SBarry Smith           if (!value) break;
224e26ddf31SBarry Smith 
225e26ddf31SBarry Smith           /* look for form  d-D where d and D are integers */
226e26ddf31SBarry Smith           foundrange = PETSC_FALSE;
227e26ddf31SBarry Smith           ierr       = PetscStrlen(value,&len);CHKERRQ(ierr);
228e26ddf31SBarry Smith           if (value[0] == '-') i=2;
229e26ddf31SBarry Smith           else i=1;
230330cf3c9SBarry Smith           for (;i<len; i++) {
231e26ddf31SBarry Smith             if (value[i] == '-') {
232e32f2f54SBarry Smith               if (i == len-1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry %s\n",n,value);
233e26ddf31SBarry Smith               value[i] = 0;
234cfbddea1SSatish Balay               ierr     = PetscOptionsStringToInt(value,&start);CHKERRQ(ierr);
235cfbddea1SSatish Balay               ierr     = PetscOptionsStringToInt(value+i+1,&end);CHKERRQ(ierr);
236e32f2f54SBarry 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);
237e32f2f54SBarry 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);
238e26ddf31SBarry Smith               for (; start<end; start++) {
239e26ddf31SBarry Smith                 *dvalue = start; dvalue++;n++;
240e26ddf31SBarry Smith               }
241e26ddf31SBarry Smith               foundrange = PETSC_TRUE;
242e26ddf31SBarry Smith               break;
243e26ddf31SBarry Smith             }
244e26ddf31SBarry Smith           }
245e26ddf31SBarry Smith           if (!foundrange) {
246cfbddea1SSatish Balay             ierr = PetscOptionsStringToInt(value,dvalue);CHKERRQ(ierr);
247e26ddf31SBarry Smith             dvalue++;
248e26ddf31SBarry Smith             n++;
249e26ddf31SBarry Smith           }
250e26ddf31SBarry Smith           ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
251e26ddf31SBarry Smith         }
2528c74ee41SBarry Smith         ierr = PetscTokenDestroy(&token);CHKERRQ(ierr);
253e26ddf31SBarry Smith       }
254e26ddf31SBarry Smith       break;
255e26ddf31SBarry Smith     case OPTION_REAL_ARRAY:
256e55864a3SBarry Smith       ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1);CHKERRQ(ierr);
257e26ddf31SBarry Smith       valr = (PetscReal*) next->data;
258e26ddf31SBarry Smith       for (i=0; i<next->arraylength; i++) {
259e26ddf31SBarry Smith         ierr = PetscPrintf(PETSC_COMM_WORLD,"%g",valr[i]);CHKERRQ(ierr);
260e26ddf31SBarry Smith         if (i < next->arraylength-1) {
261e26ddf31SBarry Smith           ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr);
262e26ddf31SBarry Smith         }
263e26ddf31SBarry Smith       }
264e26ddf31SBarry Smith       ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s) ",next->text,next->man);CHKERRQ(ierr);
265e26ddf31SBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
266e26ddf31SBarry Smith       if (str[0]) {
267e26ddf31SBarry Smith         PetscToken token;
268e26ddf31SBarry Smith         PetscInt   n = 0,nmax = next->arraylength;
269e26ddf31SBarry Smith         PetscReal  *dvalue = (PetscReal*)next->data;
270e26ddf31SBarry Smith         char       *value;
271e26ddf31SBarry Smith 
272e26ddf31SBarry Smith         next->set = PETSC_TRUE;
273e26ddf31SBarry Smith         value     = str;
274e26ddf31SBarry Smith         ierr      = PetscTokenCreate(value,',',&token);CHKERRQ(ierr);
275e26ddf31SBarry Smith         ierr      = PetscTokenFind(token,&value);CHKERRQ(ierr);
276e26ddf31SBarry Smith         while (n < nmax) {
277e26ddf31SBarry Smith           if (!value) break;
278cfbddea1SSatish Balay           ierr = PetscOptionsStringToReal(value,dvalue);CHKERRQ(ierr);
279e26ddf31SBarry Smith           dvalue++;
280e26ddf31SBarry Smith           n++;
281e26ddf31SBarry Smith           ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
282e26ddf31SBarry Smith         }
2838c74ee41SBarry Smith         ierr = PetscTokenDestroy(&token);CHKERRQ(ierr);
284e26ddf31SBarry Smith       }
285e26ddf31SBarry Smith       break;
2866356e834SBarry Smith     case OPTION_INT:
287e55864a3SBarry 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);
2883fc1eb6aSBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
2893fc1eb6aSBarry Smith       if (str[0]) {
290d25d7f95SJed Brown #if defined(PETSC_SIZEOF_LONG_LONG)
291d25d7f95SJed Brown         long long lid;
292d25d7f95SJed Brown         sscanf(str,"%lld",&lid);
2931a1499c8SBarry Smith         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);
294c272547aSJed Brown #else
295d25d7f95SJed Brown         long  lid;
296d25d7f95SJed Brown         sscanf(str,"%ld",&lid);
2971a1499c8SBarry Smith         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);
298c272547aSJed Brown #endif
299a297a907SKarl Rupp 
300d25d7f95SJed Brown         next->set = PETSC_TRUE;
301d25d7f95SJed Brown         *((PetscInt*)next->data) = (PetscInt)lid;
302aee2cecaSBarry Smith       }
303aee2cecaSBarry Smith       break;
304aee2cecaSBarry Smith     case OPTION_REAL:
305e55864a3SBarry 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);
3063fc1eb6aSBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
3073fc1eb6aSBarry Smith       if (str[0]) {
308ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE)
309a4404d99SBarry Smith         sscanf(str,"%e",&ir);
310570b7f6dSBarry Smith #elif defined(PETSC_USE_REAL___FP16)
311570b7f6dSBarry Smith         float irtemp;
312570b7f6dSBarry Smith         sscanf(str,"%e",&irtemp);
313570b7f6dSBarry Smith         ir = irtemp;
314ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE)
315aee2cecaSBarry Smith         sscanf(str,"%le",&ir);
316ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128)
317d9822059SBarry Smith         ir = strtoflt128(str,0);
318d9822059SBarry Smith #else
319513dbe71SLisandro Dalcin         SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Unknown scalar type");
320a4404d99SBarry Smith #endif
321aee2cecaSBarry Smith         next->set                 = PETSC_TRUE;
322aee2cecaSBarry Smith         *((PetscReal*)next->data) = ir;
323aee2cecaSBarry Smith       }
324aee2cecaSBarry Smith       break;
3257781c08eSBarry Smith     case OPTION_BOOL:
32683355fc5SBarry 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);
3277781c08eSBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
3287781c08eSBarry Smith       if (str[0]) {
3297781c08eSBarry Smith         ierr = PetscOptionsStringToBool(str,&bid);CHKERRQ(ierr);
3307781c08eSBarry Smith         next->set = PETSC_TRUE;
3317781c08eSBarry Smith         *((PetscBool*)next->data) = bid;
3327781c08eSBarry Smith       }
3337781c08eSBarry Smith       break;
334aee2cecaSBarry Smith     case OPTION_STRING:
335e55864a3SBarry 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);
3363fc1eb6aSBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
3373fc1eb6aSBarry Smith       if (str[0]) {
338aee2cecaSBarry Smith         next->set = PETSC_TRUE;
33964facd6cSBarry Smith         /* must use system malloc since SAWs may free this */
3405b02f95dSBarry Smith         ierr = PetscStrdup(str,(char**)&next->data);CHKERRQ(ierr);
3416356e834SBarry Smith       }
3426356e834SBarry Smith       break;
343a264d7a6SBarry Smith     case OPTION_FLIST:
34444ef3d73SBarry Smith       ierr = PetscFunctionListPrintTypes(PETSC_COMM_WORLD,stdout,PetscOptionsObject->prefix,next->option,next->text,next->man,next->flist,(char*)next->data,(char*)next->data);CHKERRQ(ierr);
3453cc1e11dSBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
3463cc1e11dSBarry Smith       if (str[0]) {
347e55864a3SBarry Smith         PetscOptionsObject->changedmethod = PETSC_TRUE;
3483cc1e11dSBarry Smith         next->set = PETSC_TRUE;
34964facd6cSBarry Smith         /* must use system malloc since SAWs may free this */
3505b02f95dSBarry Smith         ierr = PetscStrdup(str,(char**)&next->data);CHKERRQ(ierr);
3513cc1e11dSBarry Smith       }
3523cc1e11dSBarry Smith       break;
353b432afdaSMatthew Knepley     default:
354b432afdaSMatthew Knepley       break;
3556356e834SBarry Smith     }
3566356e834SBarry Smith     next = next->next;
3576356e834SBarry Smith   }
3586356e834SBarry Smith   PetscFunctionReturn(0);
3596356e834SBarry Smith }
3606356e834SBarry Smith 
361e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
362e04113cfSBarry Smith #include <petscviewersaws.h>
363d5649816SBarry Smith 
364d5649816SBarry Smith static int count = 0;
365d5649816SBarry Smith 
366e04113cfSBarry Smith PetscErrorCode PetscOptionsSAWsDestroy(void)
367d5649816SBarry Smith {
3682657e9d9SBarry Smith   PetscFunctionBegin;
369d5649816SBarry Smith   PetscFunctionReturn(0);
370d5649816SBarry Smith }
371d5649816SBarry Smith 
3729c1e0ce8SBarry Smith static const char *OptionsHeader = "<head>\n"
373a8d69d7bSBarry Smith                                    "<script type=\"text/javascript\" src=\"https://www.mcs.anl.gov/research/projects/saws/js/jquery-1.9.1.js\"></script>\n"
374a8d69d7bSBarry Smith                                    "<script type=\"text/javascript\" src=\"https://www.mcs.anl.gov/research/projects/saws/js/SAWs.js\"></script>\n"
375d1fc0251SBarry Smith                                    "<script type=\"text/javascript\" src=\"js/PETSc.js\"></script>\n"
37664bbc9efSBarry Smith                                    "<script>\n"
37764bbc9efSBarry Smith                                       "jQuery(document).ready(function() {\n"
37864bbc9efSBarry Smith                                          "PETSc.getAndDisplayDirectory(null,\"#variablesInfo\")\n"
37964bbc9efSBarry Smith                                       "})\n"
38064bbc9efSBarry Smith                                   "</script>\n"
38164bbc9efSBarry Smith                                   "</head>\n";
3821423471aSBarry Smith 
3831423471aSBarry Smith /*  Determines the size and style of the scroll region where PETSc options selectable from users are displayed */
3841423471aSBarry Smith static const char *OptionsBodyBottom = "<div id=\"variablesInfo\" style=\"background-color:lightblue;height:auto;max-height:500px;overflow:scroll;\"></div>\n<br>\n</body>";
38564bbc9efSBarry Smith 
386b3506946SBarry Smith /*
3877781c08eSBarry Smith     PetscOptionsSAWsInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the SAWs
388b3506946SBarry Smith 
389b3506946SBarry Smith     Bugs:
390b3506946SBarry Smith +    All processes must traverse through the exact same set of option queries do to the call to PetscScanString()
391b3506946SBarry Smith .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
392b3506946SBarry Smith -    Only works for PetscInt == int, PetscReal == double etc
393b3506946SBarry Smith 
394b3506946SBarry Smith */
3954416b707SBarry Smith PetscErrorCode PetscOptionsSAWsInput(PetscOptionItems *PetscOptionsObject)
396b3506946SBarry Smith {
397b3506946SBarry Smith   PetscErrorCode  ierr;
3984416b707SBarry Smith   PetscOptionItem next     = PetscOptionsObject->next;
399d5649816SBarry Smith   static int      mancount = 0;
400b3506946SBarry Smith   char            options[16];
4017aab2a10SBarry Smith   PetscBool       changedmethod = PETSC_FALSE;
402a23eb982SSurtai Han   PetscBool       stopasking    = PETSC_FALSE;
40388a9752cSBarry Smith   char            manname[16],textname[16];
4042657e9d9SBarry Smith   char            dir[1024];
405b3506946SBarry Smith 
4062a409bb0SBarry Smith   PetscFunctionBegin;
407b3506946SBarry Smith   /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */
408b3506946SBarry Smith   sprintf(options,"Options_%d",count++);
409a297a907SKarl Rupp 
4107325c4a4SBarry Smith   PetscOptionsObject->pprefix = PetscOptionsObject->prefix; /* SAWs will change this, so cannot pass prefix directly */
4111bc75a8dSBarry Smith 
412d50831c4SBarry Smith   ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s","_title");CHKERRQ(ierr);
41383355fc5SBarry Smith   PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject->title,1,SAWs_READ,SAWs_STRING));
4147781c08eSBarry Smith   ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s","prefix");CHKERRQ(ierr);
41583355fc5SBarry Smith   PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject->pprefix,1,SAWs_READ,SAWs_STRING));
4162657e9d9SBarry Smith   PetscStackCallSAWs(SAWs_Register,("/PETSc/Options/ChangedMethod",&changedmethod,1,SAWs_WRITE,SAWs_BOOLEAN));
417a23eb982SSurtai Han   PetscStackCallSAWs(SAWs_Register,("/PETSc/Options/StopAsking",&stopasking,1,SAWs_WRITE,SAWs_BOOLEAN));
418b3506946SBarry Smith 
419b3506946SBarry Smith   while (next) {
420d50831c4SBarry Smith     sprintf(manname,"_man_%d",mancount);
4212657e9d9SBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",manname);CHKERRQ(ierr);
4227781c08eSBarry Smith     PetscStackCallSAWs(SAWs_Register,(dir,&next->man,1,SAWs_READ,SAWs_STRING));
423d50831c4SBarry Smith     sprintf(textname,"_text_%d",mancount++);
4247781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",textname);CHKERRQ(ierr);
4257781c08eSBarry Smith     PetscStackCallSAWs(SAWs_Register,(dir,&next->text,1,SAWs_READ,SAWs_STRING));
4269f32e415SBarry Smith 
427b3506946SBarry Smith     switch (next->type) {
428b3506946SBarry Smith     case OPTION_HEAD:
429b3506946SBarry Smith       break;
430b3506946SBarry Smith     case OPTION_INT_ARRAY:
4317781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4322657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_INT));
433b3506946SBarry Smith       break;
434b3506946SBarry Smith     case OPTION_REAL_ARRAY:
4357781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4362657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_DOUBLE));
437b3506946SBarry Smith       break;
438b3506946SBarry Smith     case OPTION_INT:
4397781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4402657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_INT));
441b3506946SBarry Smith       break;
442b3506946SBarry Smith     case OPTION_REAL:
4437781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4442657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_DOUBLE));
445b3506946SBarry Smith       break;
4467781c08eSBarry Smith     case OPTION_BOOL:
4477781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4482657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_BOOLEAN));
4491ae3d29cSBarry Smith       break;
4507781c08eSBarry Smith     case OPTION_BOOL_ARRAY:
4517781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4522657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_BOOLEAN));
45371f08665SBarry Smith       break;
454b3506946SBarry Smith     case OPTION_STRING:
4557781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4567781c08eSBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING));
4571ae3d29cSBarry Smith       break;
4581ae3d29cSBarry Smith     case OPTION_STRING_ARRAY:
4597781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4602657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_STRING));
461b3506946SBarry Smith       break;
462a264d7a6SBarry Smith     case OPTION_FLIST:
463a264d7a6SBarry Smith       {
464a264d7a6SBarry Smith       PetscInt ntext;
4657781c08eSBarry Smith       ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4667781c08eSBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING));
467a264d7a6SBarry Smith       ierr = PetscFunctionListGet(next->flist,(const char***)&next->edata,&ntext);CHKERRQ(ierr);
468a264d7a6SBarry Smith       PetscStackCallSAWs(SAWs_Set_Legal_Variable_Values,(dir,ntext,next->edata));
469a264d7a6SBarry Smith       }
470a264d7a6SBarry Smith       break;
4711ae3d29cSBarry Smith     case OPTION_ELIST:
472a264d7a6SBarry Smith       {
473a264d7a6SBarry Smith       PetscInt ntext = next->nlist;
4747781c08eSBarry Smith       ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4757781c08eSBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING));
476ead66b60SBarry Smith       ierr = PetscMalloc1((ntext+1),(char***)&next->edata);CHKERRQ(ierr);
4771ae3d29cSBarry Smith       ierr = PetscMemcpy(next->edata,next->list,ntext*sizeof(char*));CHKERRQ(ierr);
478a264d7a6SBarry Smith       PetscStackCallSAWs(SAWs_Set_Legal_Variable_Values,(dir,ntext,next->edata));
479a264d7a6SBarry Smith       }
480a264d7a6SBarry Smith       break;
481b3506946SBarry Smith     default:
482b3506946SBarry Smith       break;
483b3506946SBarry Smith     }
484b3506946SBarry Smith     next = next->next;
485b3506946SBarry Smith   }
486b3506946SBarry Smith 
487b3506946SBarry Smith   /* wait until accessor has unlocked the memory */
48864bbc9efSBarry Smith   PetscStackCallSAWs(SAWs_Push_Header,("index.html",OptionsHeader));
48964bbc9efSBarry Smith   PetscStackCallSAWs(SAWs_Push_Body,("index.html",2,OptionsBodyBottom));
4907aab2a10SBarry Smith   ierr = PetscSAWsBlock();CHKERRQ(ierr);
49164bbc9efSBarry Smith   PetscStackCallSAWs(SAWs_Pop_Header,("index.html"));
49264bbc9efSBarry Smith   PetscStackCallSAWs(SAWs_Pop_Body,("index.html",2));
493b3506946SBarry Smith 
49488a9752cSBarry Smith   /* determine if any values have been set in GUI */
49583355fc5SBarry Smith   next = PetscOptionsObject->next;
49688a9752cSBarry Smith   while (next) {
49788a9752cSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
498f7b25cf6SBarry Smith     PetscStackCallSAWs(SAWs_Selected,(dir,(int*)&next->set));
49988a9752cSBarry Smith     next = next->next;
50088a9752cSBarry Smith   }
50188a9752cSBarry Smith 
502b3506946SBarry Smith   /* reset counter to -2; this updates the screen with the new options for the selected method */
503f7b25cf6SBarry Smith   if (changedmethod) PetscOptionsObject->count = -2;
504b3506946SBarry Smith 
505a23eb982SSurtai Han   if (stopasking) {
506a23eb982SSurtai Han     PetscOptionsPublish      = PETSC_FALSE;
50712655325SBarry Smith     PetscOptionsObject->count = 0;//do not ask for same thing again
508a23eb982SSurtai Han   }
509a23eb982SSurtai Han 
5109a492a5cSBarry Smith   PetscStackCallSAWs(SAWs_Delete,("/PETSc/Options"));
511b3506946SBarry Smith   PetscFunctionReturn(0);
512b3506946SBarry Smith }
513b3506946SBarry Smith #endif
514b3506946SBarry Smith 
5154416b707SBarry Smith PetscErrorCode PetscOptionsEnd_Private(PetscOptionItems *PetscOptionsObject)
51653acd3b1SBarry Smith {
51753acd3b1SBarry Smith   PetscErrorCode  ierr;
5184416b707SBarry Smith   PetscOptionItem last;
5196356e834SBarry Smith   char            option[256],value[1024],tmp[32];
520330cf3c9SBarry Smith   size_t          j;
52153acd3b1SBarry Smith 
52253acd3b1SBarry Smith   PetscFunctionBegin;
52383355fc5SBarry Smith   if (PetscOptionsObject->next) {
52483355fc5SBarry Smith     if (!PetscOptionsObject->count) {
525a264d7a6SBarry Smith #if defined(PETSC_HAVE_SAWS)
526f7b25cf6SBarry Smith       ierr = PetscOptionsSAWsInput(PetscOptionsObject);CHKERRQ(ierr);
527b3506946SBarry Smith #else
528e55864a3SBarry Smith       ierr = PetscOptionsGetFromTextInput(PetscOptionsObject);CHKERRQ(ierr);
529b3506946SBarry Smith #endif
530aee2cecaSBarry Smith     }
531aee2cecaSBarry Smith   }
5326356e834SBarry Smith 
533e55864a3SBarry Smith   ierr = PetscFree(PetscOptionsObject->title);CHKERRQ(ierr);
5346356e834SBarry Smith 
535e26ddf31SBarry Smith   /* reset counter to -2; this updates the screen with the new options for the selected method */
536e55864a3SBarry Smith   if (PetscOptionsObject->changedmethod) PetscOptionsObject->count = -2;
5377a72a596SBarry Smith   /* reset alreadyprinted flag */
538e55864a3SBarry Smith   PetscOptionsObject->alreadyprinted = PETSC_FALSE;
539e55864a3SBarry Smith   if (PetscOptionsObject->object) PetscOptionsObject->object->optionsprinted = PETSC_TRUE;
540e55864a3SBarry Smith   PetscOptionsObject->object = NULL;
54153acd3b1SBarry Smith 
542e55864a3SBarry Smith   while (PetscOptionsObject->next) {
543e55864a3SBarry Smith     if (PetscOptionsObject->next->set) {
544e55864a3SBarry Smith       if (PetscOptionsObject->prefix) {
54553acd3b1SBarry Smith         ierr = PetscStrcpy(option,"-");CHKERRQ(ierr);
546e55864a3SBarry Smith         ierr = PetscStrcat(option,PetscOptionsObject->prefix);CHKERRQ(ierr);
547e55864a3SBarry Smith         ierr = PetscStrcat(option,PetscOptionsObject->next->option+1);CHKERRQ(ierr);
5486356e834SBarry Smith       } else {
549e55864a3SBarry Smith         ierr = PetscStrcpy(option,PetscOptionsObject->next->option);CHKERRQ(ierr);
5506356e834SBarry Smith       }
5516356e834SBarry Smith 
552e55864a3SBarry Smith       switch (PetscOptionsObject->next->type) {
5536356e834SBarry Smith       case OPTION_HEAD:
5546356e834SBarry Smith         break;
5556356e834SBarry Smith       case OPTION_INT_ARRAY:
556e55864a3SBarry Smith         sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject->next->data)[0]);
557e55864a3SBarry Smith         for (j=1; j<PetscOptionsObject->next->arraylength; j++) {
558e55864a3SBarry Smith           sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject->next->data)[j]);
5596356e834SBarry Smith           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
5606356e834SBarry Smith           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
5616356e834SBarry Smith         }
5626356e834SBarry Smith         break;
5636356e834SBarry Smith       case OPTION_INT:
564e55864a3SBarry Smith         sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject->next->data);
5656356e834SBarry Smith         break;
5666356e834SBarry Smith       case OPTION_REAL:
567e55864a3SBarry Smith         sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject->next->data);
5686356e834SBarry Smith         break;
5696356e834SBarry Smith       case OPTION_REAL_ARRAY:
570e55864a3SBarry Smith         sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject->next->data)[0]);
571e55864a3SBarry Smith         for (j=1; j<PetscOptionsObject->next->arraylength; j++) {
572e55864a3SBarry Smith           sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject->next->data)[j]);
5736356e834SBarry Smith           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
5746356e834SBarry Smith           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
5756356e834SBarry Smith         }
5766356e834SBarry Smith         break;
577050cccc3SHong Zhang       case OPTION_SCALAR_ARRAY:
57895f3a755SJose E. Roman         sprintf(value,"%g+%gi",(double)PetscRealPart(((PetscScalar*)PetscOptionsObject->next->data)[0]),(double)PetscImaginaryPart(((PetscScalar*)PetscOptionsObject->next->data)[0]));
579050cccc3SHong Zhang         for (j=1; j<PetscOptionsObject->next->arraylength; j++) {
58095f3a755SJose E. Roman           sprintf(tmp,"%g+%gi",(double)PetscRealPart(((PetscScalar*)PetscOptionsObject->next->data)[j]),(double)PetscImaginaryPart(((PetscScalar*)PetscOptionsObject->next->data)[j]));
581050cccc3SHong Zhang           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
582050cccc3SHong Zhang           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
583050cccc3SHong Zhang         }
584050cccc3SHong Zhang         break;
5857781c08eSBarry Smith       case OPTION_BOOL:
586e55864a3SBarry Smith         sprintf(value,"%d",*(int*)PetscOptionsObject->next->data);
5876356e834SBarry Smith         break;
5887781c08eSBarry Smith       case OPTION_BOOL_ARRAY:
589e55864a3SBarry Smith         sprintf(value,"%d",(int)((PetscBool*)PetscOptionsObject->next->data)[0]);
590e55864a3SBarry Smith         for (j=1; j<PetscOptionsObject->next->arraylength; j++) {
591e55864a3SBarry Smith           sprintf(tmp,"%d",(int)((PetscBool*)PetscOptionsObject->next->data)[j]);
5921ae3d29cSBarry Smith           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
5931ae3d29cSBarry Smith           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
5941ae3d29cSBarry Smith         }
5951ae3d29cSBarry Smith         break;
596a264d7a6SBarry Smith       case OPTION_FLIST:
5976991f827SBarry Smith         ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr);
5986991f827SBarry Smith         break;
5991ae3d29cSBarry Smith       case OPTION_ELIST:
600e55864a3SBarry Smith         ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr);
6016356e834SBarry Smith         break;
6021ae3d29cSBarry Smith       case OPTION_STRING:
603e55864a3SBarry Smith         ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr);
604d51da6bfSBarry Smith         break;
6051ae3d29cSBarry Smith       case OPTION_STRING_ARRAY:
606e55864a3SBarry Smith         sprintf(value,"%s",((char**)PetscOptionsObject->next->data)[0]);
607e55864a3SBarry Smith         for (j=1; j<PetscOptionsObject->next->arraylength; j++) {
608e55864a3SBarry Smith           sprintf(tmp,"%s",((char**)PetscOptionsObject->next->data)[j]);
6091ae3d29cSBarry Smith           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
6101ae3d29cSBarry Smith           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
6111ae3d29cSBarry Smith         }
6126356e834SBarry Smith         break;
6136356e834SBarry Smith       }
614c5929fdfSBarry Smith       ierr = PetscOptionsSetValue(PetscOptionsObject->options,option,value);CHKERRQ(ierr);
6156356e834SBarry Smith     }
6166991f827SBarry Smith     if (PetscOptionsObject->next->type == OPTION_ELIST) {
6176991f827SBarry Smith       ierr = PetscStrNArrayDestroy(PetscOptionsObject->next->nlist,(char ***)&PetscOptionsObject->next->list);CHKERRQ(ierr);
6186991f827SBarry Smith     }
619e55864a3SBarry Smith     ierr   = PetscFree(PetscOptionsObject->next->text);CHKERRQ(ierr);
620e55864a3SBarry Smith     ierr   = PetscFree(PetscOptionsObject->next->option);CHKERRQ(ierr);
621e55864a3SBarry Smith     ierr   = PetscFree(PetscOptionsObject->next->man);CHKERRQ(ierr);
622e55864a3SBarry Smith     ierr   = PetscFree(PetscOptionsObject->next->edata);CHKERRQ(ierr);
623c979a496SBarry Smith 
62483355fc5SBarry Smith     if ((PetscOptionsObject->next->type == OPTION_STRING) || (PetscOptionsObject->next->type == OPTION_FLIST) || (PetscOptionsObject->next->type == OPTION_ELIST)) {
62583355fc5SBarry Smith       free(PetscOptionsObject->next->data);
626c979a496SBarry Smith     } else {
62783355fc5SBarry Smith       ierr   = PetscFree(PetscOptionsObject->next->data);CHKERRQ(ierr);
628c979a496SBarry Smith     }
6297781c08eSBarry Smith 
63083355fc5SBarry Smith     last                    = PetscOptionsObject->next;
63183355fc5SBarry Smith     PetscOptionsObject->next = PetscOptionsObject->next->next;
6326356e834SBarry Smith     ierr                    = PetscFree(last);CHKERRQ(ierr);
6336356e834SBarry Smith   }
634f59f755dSBarry Smith   ierr = PetscFree(PetscOptionsObject->prefix);CHKERRQ(ierr);
63502c9f0b5SLisandro Dalcin   PetscOptionsObject->next = NULL;
63653acd3b1SBarry Smith   PetscFunctionReturn(0);
63753acd3b1SBarry Smith }
63853acd3b1SBarry Smith 
63988aa4217SBarry Smith /*MC
64053acd3b1SBarry Smith    PetscOptionsEnum - Gets the enum value for a particular option in the database.
64153acd3b1SBarry Smith 
6423f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
64353acd3b1SBarry Smith 
64488aa4217SBarry Smith    Synopsis:
64588aa4217SBarry Smith    #include "petscsys.h"
6463a89f35bSSatish Balay    PetscErrorCode  PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum currentvalue,PetscEnum *value,PetscBool  *set)
64788aa4217SBarry Smith 
64853acd3b1SBarry Smith    Input Parameters:
64953acd3b1SBarry Smith +  opt - option name
65053acd3b1SBarry Smith .  text - short string that describes the option
65153acd3b1SBarry Smith .  man - manual page with additional information on option
65253acd3b1SBarry Smith .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
6530fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
6540fdccdaeSBarry Smith $                 PetscOptionsEnum(..., obj->value,&object->value,...) or
6550fdccdaeSBarry Smith $                 value = defaultvalue
6560fdccdaeSBarry Smith $                 PetscOptionsEnum(..., value,&value,&flg);
6570fdccdaeSBarry Smith $                 if (flg) {
65853acd3b1SBarry Smith 
659d8d19677SJose E. Roman    Output Parameters:
66053acd3b1SBarry Smith +  value - the  value to return
661b32e0204SMatthew G Knepley -  set - PETSC_TRUE if found, else PETSC_FALSE
66253acd3b1SBarry Smith 
66353acd3b1SBarry Smith    Level: beginner
66453acd3b1SBarry Smith 
66595452b02SPatrick Sanan    Notes:
66695452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
66753acd3b1SBarry Smith 
66853acd3b1SBarry Smith           list is usually something like PCASMTypes or some other predefined list of enum names
66953acd3b1SBarry Smith 
6702efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
6712efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
6722efd9cb1SBarry Smith 
673989712b9SBarry Smith           The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
674989712b9SBarry Smith 
67553acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
676536f90c4SPierre Jolivet           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(),
677acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
67853acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
67953acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
680acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
681a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
68288aa4217SBarry Smith M*/
68388aa4217SBarry Smith 
6844416b707SBarry Smith PetscErrorCode  PetscOptionsEnum_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],const char *const *list,PetscEnum currentvalue,PetscEnum *value,PetscBool  *set)
68553acd3b1SBarry Smith {
68653acd3b1SBarry Smith   PetscErrorCode ierr;
68753acd3b1SBarry Smith   PetscInt       ntext = 0;
688aa5bb8c0SSatish Balay   PetscInt       tval;
689ace3abfcSBarry Smith   PetscBool      tflg;
69053acd3b1SBarry Smith 
69153acd3b1SBarry Smith   PetscFunctionBegin;
69253acd3b1SBarry Smith   while (list[ntext++]) {
693e32f2f54SBarry Smith     if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries");
69453acd3b1SBarry Smith   }
695e32f2f54SBarry Smith   if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix");
69653acd3b1SBarry Smith   ntext -= 3;
697e55864a3SBarry Smith   ierr   = PetscOptionsEList_Private(PetscOptionsObject,opt,text,man,list,ntext,list[currentvalue],&tval,&tflg);CHKERRQ(ierr);
698aa5bb8c0SSatish Balay   /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */
699aa5bb8c0SSatish Balay   if (tflg) *value = (PetscEnum)tval;
700aa5bb8c0SSatish Balay   if (set)  *set   = tflg;
70153acd3b1SBarry Smith   PetscFunctionReturn(0);
70253acd3b1SBarry Smith }
70353acd3b1SBarry Smith 
70488aa4217SBarry Smith /*MC
705d3e47460SLisandro Dalcin    PetscOptionsEnumArray - Gets an array of enum values for a particular
706d3e47460SLisandro Dalcin    option in the database.
707d3e47460SLisandro Dalcin 
708d3e47460SLisandro Dalcin    Logically Collective on the communicator passed in PetscOptionsBegin()
709d3e47460SLisandro Dalcin 
71088aa4217SBarry Smith    Synopsis:
71188aa4217SBarry Smith    #include "petscsys.h"
7123a89f35bSSatish Balay    PetscErrorCode  PetscOptionsEnumArray(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum value[],PetscInt *n,PetscBool  *set)
71388aa4217SBarry Smith 
714d3e47460SLisandro Dalcin    Input Parameters:
715d3e47460SLisandro Dalcin +  opt - the option one is seeking
716d3e47460SLisandro Dalcin .  text - short string describing option
717d3e47460SLisandro Dalcin .  man - manual page for option
71822d58ec6SMatthew G. Knepley .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
719d3e47460SLisandro Dalcin -  n - maximum number of values
720d3e47460SLisandro Dalcin 
721d8d19677SJose E. Roman    Output Parameters:
722d3e47460SLisandro Dalcin +  value - location to copy values
723d3e47460SLisandro Dalcin .  n - actual number of values found
724d3e47460SLisandro Dalcin -  set - PETSC_TRUE if found, else PETSC_FALSE
725d3e47460SLisandro Dalcin 
726d3e47460SLisandro Dalcin    Level: beginner
727d3e47460SLisandro Dalcin 
728d3e47460SLisandro Dalcin    Notes:
729d3e47460SLisandro Dalcin    The array must be passed as a comma separated list.
730d3e47460SLisandro Dalcin 
731d3e47460SLisandro Dalcin    There must be no intervening spaces between the values.
732d3e47460SLisandro Dalcin 
733d3e47460SLisandro Dalcin    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
734d3e47460SLisandro Dalcin 
735d3e47460SLisandro Dalcin .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
736536f90c4SPierre Jolivet           PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(),
737d3e47460SLisandro Dalcin           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
738d3e47460SLisandro Dalcin           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
739d3e47460SLisandro Dalcin           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
740d3e47460SLisandro Dalcin           PetscOptionsFList(), PetscOptionsEList(), PetscOptionsRealArray()
74188aa4217SBarry Smith M*/
74288aa4217SBarry Smith 
7434416b707SBarry Smith PetscErrorCode  PetscOptionsEnumArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],const char *const *list,PetscEnum value[],PetscInt *n,PetscBool  *set)
744d3e47460SLisandro Dalcin {
745d3e47460SLisandro Dalcin   PetscInt        i,nlist = 0;
7464416b707SBarry Smith   PetscOptionItem amsopt;
747d3e47460SLisandro Dalcin   PetscErrorCode  ierr;
748d3e47460SLisandro Dalcin 
749d3e47460SLisandro Dalcin   PetscFunctionBegin;
750d3e47460SLisandro Dalcin   while (list[nlist++]) if (nlist > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries");
751d3e47460SLisandro Dalcin   if (nlist < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix");
752d3e47460SLisandro Dalcin   nlist -= 3; /* drop enum name, prefix, and null termination */
753d3e47460SLisandro Dalcin   if (0 && !PetscOptionsObject->count) { /* XXX Requires additional support */
754d3e47460SLisandro Dalcin     PetscEnum *vals;
7554416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT_ARRAY/*XXX OPTION_ENUM_ARRAY*/,&amsopt);CHKERRQ(ierr);
756d3e47460SLisandro Dalcin     ierr = PetscStrNArrayallocpy(nlist,list,(char***)&amsopt->list);CHKERRQ(ierr);
757d3e47460SLisandro Dalcin     amsopt->nlist = nlist;
758d3e47460SLisandro Dalcin     ierr = PetscMalloc1(*n,(PetscEnum**)&amsopt->data);CHKERRQ(ierr);
759d3e47460SLisandro Dalcin     amsopt->arraylength = *n;
760d3e47460SLisandro Dalcin     vals = (PetscEnum*)amsopt->data;
761d3e47460SLisandro Dalcin     for (i=0; i<*n; i++) vals[i] = value[i];
762d3e47460SLisandro Dalcin   }
763c5929fdfSBarry Smith   ierr = PetscOptionsGetEnumArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,list,value,n,set);CHKERRQ(ierr);
764d3e47460SLisandro Dalcin   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
765d3e47460SLisandro Dalcin     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%s",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,list[value[0]]);CHKERRQ(ierr);
766d3e47460SLisandro Dalcin     for (i=1; i<*n; i++) {ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%s",list[value[i]]);CHKERRQ(ierr);}
767d3e47460SLisandro Dalcin     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (choose from)",text);CHKERRQ(ierr);
768d3e47460SLisandro Dalcin     for (i=0; i<nlist; i++) {ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s",list[i]);CHKERRQ(ierr);}
769d3e47460SLisandro Dalcin     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," (%s)\n",ManSection(man));CHKERRQ(ierr);
770d3e47460SLisandro Dalcin   }
771d3e47460SLisandro Dalcin   PetscFunctionReturn(0);
772d3e47460SLisandro Dalcin }
773d3e47460SLisandro Dalcin 
77488aa4217SBarry Smith /*MC
7755a856986SBarry Smith    PetscOptionsBoundedInt - Gets an integer value greater than or equal a given bound for a particular option in the database.
7765a856986SBarry Smith 
7775a856986SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
7785a856986SBarry Smith 
77988aa4217SBarry Smith    Synopsis:
78088aa4217SBarry Smith    #include "petscsys.h"
7813a89f35bSSatish Balay    PetscErrorCode  PetscOptionsBoundInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt bound)
78288aa4217SBarry Smith 
7835a856986SBarry Smith    Input Parameters:
7845a856986SBarry Smith +  opt - option name
7855a856986SBarry Smith .  text - short string that describes the option
7865a856986SBarry Smith .  man - manual page with additional information on option
7875a856986SBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
78888aa4217SBarry Smith $                 PetscOptionsInt(..., obj->value,&obj->value,...) or
7895a856986SBarry Smith $                 value = defaultvalue
7905a856986SBarry Smith $                 PetscOptionsInt(..., value,&value,&flg);
7915a856986SBarry Smith $                 if (flg) {
79288aa4217SBarry Smith -  bound - the requested value should be greater than or equal this bound or an error is generated
7935a856986SBarry Smith 
794d8d19677SJose E. Roman    Output Parameters:
7955a856986SBarry Smith +  value - the integer value to return
7965a856986SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
7975a856986SBarry Smith 
7985a856986SBarry Smith    Notes:
7995a856986SBarry Smith     If the user does not supply the option at all value is NOT changed. Thus
8005a856986SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
8015a856986SBarry Smith 
8025a856986SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
8035a856986SBarry Smith 
8045a856986SBarry Smith     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
8055a856986SBarry Smith 
8065a856986SBarry Smith    Level: beginner
8075a856986SBarry Smith 
8085a856986SBarry Smith .seealso: PetscOptionsInt(), PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
809536f90c4SPierre Jolivet           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), PetscOptionsRangeInt()
8105a856986SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
8115a856986SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
8125a856986SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
8135a856986SBarry Smith           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
8145a856986SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
81588aa4217SBarry Smith M*/
8165a856986SBarry Smith 
81788aa4217SBarry Smith /*MC
8185a856986SBarry Smith    PetscOptionsRangeInt - Gets an integer value within a range of values for a particular option in the database.
8195a856986SBarry Smith 
8205a856986SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
8215a856986SBarry Smith 
82288aa4217SBarry Smith    Synopsis:
82388aa4217SBarry Smith    #include "petscsys.h"
8243a89f35bSSatish Balay PetscErrorCode  PetscOptionsRangeInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt lb,PetscInt ub)
82588aa4217SBarry Smith 
8265a856986SBarry Smith    Input Parameters:
8275a856986SBarry Smith +  opt - option name
8285a856986SBarry Smith .  text - short string that describes the option
8295a856986SBarry Smith .  man - manual page with additional information on option
8305a856986SBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
83188aa4217SBarry Smith $                 PetscOptionsInt(..., obj->value,&obj->value,...) or
8325a856986SBarry Smith $                 value = defaultvalue
8335a856986SBarry Smith $                 PetscOptionsInt(..., value,&value,&flg);
8345a856986SBarry Smith $                 if (flg) {
83588aa4217SBarry Smith .  lb - the lower bound, provided value must be greater than or equal to this value or an error is generated
83688aa4217SBarry Smith -  ub - the upper bound, provided value must be less than or equal to this value or an error is generated
8375a856986SBarry Smith 
838d8d19677SJose E. Roman    Output Parameters:
8395a856986SBarry Smith +  value - the integer value to return
8405a856986SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
8415a856986SBarry Smith 
8425a856986SBarry Smith    Notes:
8435a856986SBarry Smith     If the user does not supply the option at all value is NOT changed. Thus
8445a856986SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
8455a856986SBarry Smith 
8465a856986SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
8475a856986SBarry Smith 
8485a856986SBarry Smith     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
8495a856986SBarry Smith 
8505a856986SBarry Smith    Level: beginner
8515a856986SBarry Smith 
8525a856986SBarry Smith .seealso: PetscOptionsInt(), PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
853536f90c4SPierre Jolivet           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), PetscOptionsBoundedInt()
8545a856986SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
8555a856986SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
8565a856986SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
8575a856986SBarry Smith           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
8585a856986SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
85988aa4217SBarry Smith M*/
8605a856986SBarry Smith 
86188aa4217SBarry Smith /*MC
86253acd3b1SBarry Smith    PetscOptionsInt - Gets the integer value for a particular option in the database.
86353acd3b1SBarry Smith 
8643f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
86553acd3b1SBarry Smith 
86688aa4217SBarry Smith    Synopsis:
86788aa4217SBarry Smith    #include "petscsys.h"
868*6eeb591dSVaclav Hapla PetscErrorCode  PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg))
86988aa4217SBarry Smith 
87053acd3b1SBarry Smith    Input Parameters:
87153acd3b1SBarry Smith +  opt - option name
87253acd3b1SBarry Smith .  text - short string that describes the option
87353acd3b1SBarry Smith .  man - manual page with additional information on option
8740fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
87588aa4217SBarry Smith $                 PetscOptionsInt(..., obj->value,&obj->value,...) or
8760fdccdaeSBarry Smith $                 value = defaultvalue
8770fdccdaeSBarry Smith $                 PetscOptionsInt(..., value,&value,&flg);
8780fdccdaeSBarry Smith $                 if (flg) {
87953acd3b1SBarry Smith 
880d8d19677SJose E. Roman    Output Parameters:
88153acd3b1SBarry Smith +  value - the integer value to return
88253acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
88353acd3b1SBarry Smith 
88495452b02SPatrick Sanan    Notes:
88595452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
8862efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
8872efd9cb1SBarry Smith 
888989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
889989712b9SBarry Smith 
89095452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
89153acd3b1SBarry Smith 
8925a856986SBarry Smith    Level: beginner
8935a856986SBarry Smith 
8945a856986SBarry Smith .seealso: PetscOptionsBoundedInt(), PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
895536f90c4SPierre Jolivet           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), PetscOptionsRangeInt()
896acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
89753acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
89853acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
899acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
900a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
90188aa4217SBarry Smith M*/
90288aa4217SBarry Smith 
9035a856986SBarry Smith PetscErrorCode  PetscOptionsInt_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool  *set,PetscInt lb,PetscInt ub)
90453acd3b1SBarry Smith {
90553acd3b1SBarry Smith   PetscErrorCode  ierr;
9064416b707SBarry Smith   PetscOptionItem amsopt;
90712655325SBarry Smith   PetscBool       wasset;
90853acd3b1SBarry Smith 
90953acd3b1SBarry Smith   PetscFunctionBegin;
9105a856986SBarry Smith   if (currentvalue < lb) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Current value %D less than allowed bound %D",currentvalue,lb);
911c5910190SPierre Jolivet   if (currentvalue > ub) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Current value %D greater than allowed bound %D",currentvalue,ub);
912e55864a3SBarry Smith      if (!PetscOptionsObject->count) {
9134416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr);
9146356e834SBarry Smith     ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
91512655325SBarry Smith     *(PetscInt*)amsopt->data = currentvalue;
9163e211508SBarry Smith 
917c5929fdfSBarry Smith     ierr = PetscOptionsGetInt(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,&currentvalue,&wasset);CHKERRQ(ierr);
9183e211508SBarry Smith     if (wasset) {
91912655325SBarry Smith       *(PetscInt*)amsopt->data = currentvalue;
9203e211508SBarry Smith     }
921af6d86caSBarry Smith   }
92244ef3d73SBarry Smith   ierr = PetscOptionsGetInt(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,&wasset);CHKERRQ(ierr);
9235a856986SBarry Smith   if (wasset && *value < lb) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Newly set value %D less than allowed bound %D",*value,lb);
9245a856986SBarry Smith   if (wasset && *value > ub) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Newly set value %D greater than allowed bound %D",*value,ub);
92544ef3d73SBarry Smith   if (set) *set = wasset;
926e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
9270e4c290aSBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <now %D : formerly %D>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,wasset && value ? *value : currentvalue,currentvalue,text,ManSection(man));CHKERRQ(ierr);
92853acd3b1SBarry Smith   }
92953acd3b1SBarry Smith   PetscFunctionReturn(0);
93053acd3b1SBarry Smith }
93153acd3b1SBarry Smith 
93288aa4217SBarry Smith /*MC
93353acd3b1SBarry Smith    PetscOptionsString - Gets the string value for a particular option in the database.
93453acd3b1SBarry Smith 
9353f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
93653acd3b1SBarry Smith 
93788aa4217SBarry Smith    Synopsis:
93888aa4217SBarry Smith    #include "petscsys.h"
9393a89f35bSSatish Balay    PetscErrorCode  PetscOptionsString(const char opt[],const char text[],const char man[],const char currentvalue[],char value[],size_t len,PetscBool  *set)
94088aa4217SBarry Smith 
94153acd3b1SBarry Smith    Input Parameters:
94253acd3b1SBarry Smith +  opt - option name
94353acd3b1SBarry Smith .  text - short string that describes the option
94453acd3b1SBarry Smith .  man - manual page with additional information on option
9450fdccdaeSBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. This is not used to set value
946bcbf2dc5SJed Brown -  len - length of the result string including null terminator
94753acd3b1SBarry Smith 
948d8d19677SJose E. Roman    Output Parameters:
94953acd3b1SBarry Smith +  value - the value to return
95053acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
95153acd3b1SBarry Smith 
95253acd3b1SBarry Smith    Level: beginner
95353acd3b1SBarry Smith 
95495452b02SPatrick Sanan    Notes:
95595452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
95653acd3b1SBarry Smith 
9577fccdfe4SBarry 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).
9587fccdfe4SBarry Smith 
9592efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
9602efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
9612efd9cb1SBarry Smith 
962989712b9SBarry Smith           The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
963989712b9SBarry Smith 
96489a13869SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
965536f90c4SPierre Jolivet           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(),
966acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsReal(), PetscOptionsBool(),
96753acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
96853acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
969acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
970a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
97188aa4217SBarry Smith M*/
97288aa4217SBarry Smith 
9734416b707SBarry Smith PetscErrorCode  PetscOptionsString_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],const char currentvalue[],char value[],size_t len,PetscBool  *set)
97453acd3b1SBarry Smith {
97553acd3b1SBarry Smith   PetscErrorCode  ierr;
9764416b707SBarry Smith   PetscOptionItem amsopt;
97744ef3d73SBarry Smith   PetscBool       lset;
97853acd3b1SBarry Smith 
97953acd3b1SBarry Smith   PetscFunctionBegin;
9801a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
9814416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
98264facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
9830fdccdaeSBarry Smith     ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr);
984af6d86caSBarry Smith   }
98544ef3d73SBarry Smith   ierr = PetscOptionsGetString(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,len,&lset);CHKERRQ(ierr);
98644ef3d73SBarry Smith   if (set) *set = lset;
987e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
9880e4c290aSBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <now %s : formerly %s>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,lset && value ? value : currentvalue,currentvalue,text,ManSection(man));CHKERRQ(ierr);
98953acd3b1SBarry Smith   }
99053acd3b1SBarry Smith   PetscFunctionReturn(0);
99153acd3b1SBarry Smith }
99253acd3b1SBarry Smith 
99388aa4217SBarry Smith /*MC
99453acd3b1SBarry Smith    PetscOptionsReal - Gets the PetscReal value for a particular option in the database.
99553acd3b1SBarry Smith 
9963f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
99753acd3b1SBarry Smith 
99888aa4217SBarry Smith    Synopsis:
99988aa4217SBarry Smith    #include "petscsys.h"
10003a89f35bSSatish Balay    PetscErrorCode  PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal currentvalue,PetscReal *value,PetscBool  *set)
100188aa4217SBarry Smith 
100253acd3b1SBarry Smith    Input Parameters:
100353acd3b1SBarry Smith +  opt - option name
100453acd3b1SBarry Smith .  text - short string that describes the option
100553acd3b1SBarry Smith .  man - manual page with additional information on option
10060fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
100788aa4217SBarry Smith $                 PetscOptionsReal(..., obj->value,&obj->value,...) or
10080fdccdaeSBarry Smith $                 value = defaultvalue
10090fdccdaeSBarry Smith $                 PetscOptionsReal(..., value,&value,&flg);
10100fdccdaeSBarry Smith $                 if (flg) {
101153acd3b1SBarry Smith 
1012d8d19677SJose E. Roman    Output Parameters:
101353acd3b1SBarry Smith +  value - the value to return
101453acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
101553acd3b1SBarry Smith 
101695452b02SPatrick Sanan    Notes:
101795452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
10182efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
10192efd9cb1SBarry Smith 
1020989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
1021989712b9SBarry Smith 
102295452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
102353acd3b1SBarry Smith 
10245a856986SBarry Smith    Level: beginner
10255a856986SBarry Smith 
102689a13869SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1027536f90c4SPierre Jolivet           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(),
1028acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
102953acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
103053acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1031acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1032a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
103388aa4217SBarry Smith M*/
103488aa4217SBarry Smith 
10354416b707SBarry Smith PetscErrorCode  PetscOptionsReal_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscReal currentvalue,PetscReal *value,PetscBool  *set)
103653acd3b1SBarry Smith {
103753acd3b1SBarry Smith   PetscErrorCode  ierr;
10384416b707SBarry Smith   PetscOptionItem amsopt;
103944ef3d73SBarry Smith   PetscBool       lset;
104053acd3b1SBarry Smith 
104153acd3b1SBarry Smith   PetscFunctionBegin;
1042e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
10434416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr);
1044538aa990SBarry Smith     ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
1045a297a907SKarl Rupp 
10460fdccdaeSBarry Smith     *(PetscReal*)amsopt->data = currentvalue;
1047538aa990SBarry Smith   }
104844ef3d73SBarry Smith   ierr = PetscOptionsGetReal(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,&lset);CHKERRQ(ierr);
104944ef3d73SBarry Smith   if (set) *set = lset;
10501a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
10510e4c290aSBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%g : %g>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,lset && value ? (double)*value : (double) currentvalue,(double)currentvalue,text,ManSection(man));CHKERRQ(ierr);
105253acd3b1SBarry Smith   }
105353acd3b1SBarry Smith   PetscFunctionReturn(0);
105453acd3b1SBarry Smith }
105553acd3b1SBarry Smith 
105688aa4217SBarry Smith /*MC
105753acd3b1SBarry Smith    PetscOptionsScalar - Gets the scalar value for a particular option in the database.
105853acd3b1SBarry Smith 
10593f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
106053acd3b1SBarry Smith 
106188aa4217SBarry Smith    Synopsis:
106288aa4217SBarry Smith    #include "petscsys.h"
10633a89f35bSSatish Balay    PetscErrorCode PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar currentvalue,PetscScalar *value,PetscBool  *set)
106488aa4217SBarry Smith 
106553acd3b1SBarry Smith    Input Parameters:
106653acd3b1SBarry Smith +  opt - option name
106753acd3b1SBarry Smith .  text - short string that describes the option
106853acd3b1SBarry Smith .  man - manual page with additional information on option
10690fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
107088aa4217SBarry Smith $                 PetscOptionsScalar(..., obj->value,&obj->value,...) or
10710fdccdaeSBarry Smith $                 value = defaultvalue
10720fdccdaeSBarry Smith $                 PetscOptionsScalar(..., value,&value,&flg);
10730fdccdaeSBarry Smith $                 if (flg) {
10740fdccdaeSBarry Smith 
1075d8d19677SJose E. Roman    Output Parameters:
107653acd3b1SBarry Smith +  value - the value to return
107753acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
107853acd3b1SBarry Smith 
107995452b02SPatrick Sanan    Notes:
108095452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
10812efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
10822efd9cb1SBarry Smith 
1083989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
1084989712b9SBarry Smith 
108595452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
108653acd3b1SBarry Smith 
10875a856986SBarry Smith    Level: beginner
10885a856986SBarry Smith 
108989a13869SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1090536f90c4SPierre Jolivet           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(),
1091acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
109253acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
109353acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1094acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1095a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
109688aa4217SBarry Smith M*/
109788aa4217SBarry Smith 
10984416b707SBarry Smith PetscErrorCode  PetscOptionsScalar_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscScalar currentvalue,PetscScalar *value,PetscBool  *set)
109953acd3b1SBarry Smith {
110053acd3b1SBarry Smith   PetscErrorCode ierr;
110153acd3b1SBarry Smith 
110253acd3b1SBarry Smith   PetscFunctionBegin;
110353acd3b1SBarry Smith #if !defined(PETSC_USE_COMPLEX)
11040fdccdaeSBarry Smith   ierr = PetscOptionsReal(opt,text,man,currentvalue,value,set);CHKERRQ(ierr);
110553acd3b1SBarry Smith #else
1106c5929fdfSBarry Smith   ierr = PetscOptionsGetScalar(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,set);CHKERRQ(ierr);
110753acd3b1SBarry Smith #endif
110853acd3b1SBarry Smith   PetscFunctionReturn(0);
110953acd3b1SBarry Smith }
111053acd3b1SBarry Smith 
111188aa4217SBarry Smith /*MC
111290d69ab7SBarry 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
111390d69ab7SBarry Smith                       its value is set to false.
111453acd3b1SBarry Smith 
11153f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
111653acd3b1SBarry Smith 
111788aa4217SBarry Smith    Synopsis:
111888aa4217SBarry Smith    #include "petscsys.h"
11193a89f35bSSatish Balay    PetscErrorCode PetscOptionsName(const char opt[],const char text[],const char man[],PetscBool  *flg)
112088aa4217SBarry Smith 
112153acd3b1SBarry Smith    Input Parameters:
112253acd3b1SBarry Smith +  opt - option name
112353acd3b1SBarry Smith .  text - short string that describes the option
112453acd3b1SBarry Smith -  man - manual page with additional information on option
112553acd3b1SBarry Smith 
112653acd3b1SBarry Smith    Output Parameter:
112753acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
112853acd3b1SBarry Smith 
112953acd3b1SBarry Smith    Level: beginner
113053acd3b1SBarry Smith 
113195452b02SPatrick Sanan    Notes:
113295452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
113353acd3b1SBarry Smith 
113489a13869SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1135536f90c4SPierre Jolivet           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(),
1136acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
113753acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
113853acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1139acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1140a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
114188aa4217SBarry Smith M*/
114288aa4217SBarry Smith 
11434416b707SBarry Smith PetscErrorCode  PetscOptionsName_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool  *flg)
114453acd3b1SBarry Smith {
114553acd3b1SBarry Smith   PetscErrorCode  ierr;
11464416b707SBarry Smith   PetscOptionItem amsopt;
114753acd3b1SBarry Smith 
114853acd3b1SBarry Smith   PetscFunctionBegin;
1149e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
11504416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1151ace3abfcSBarry Smith     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1152a297a907SKarl Rupp 
1153ace3abfcSBarry Smith     *(PetscBool*)amsopt->data = PETSC_FALSE;
11541ae3d29cSBarry Smith   }
1155c5929fdfSBarry Smith   ierr = PetscOptionsHasName(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg);CHKERRQ(ierr);
1156e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1157e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
115853acd3b1SBarry Smith   }
115953acd3b1SBarry Smith   PetscFunctionReturn(0);
116053acd3b1SBarry Smith }
116153acd3b1SBarry Smith 
116288aa4217SBarry Smith /*MC
1163a264d7a6SBarry Smith      PetscOptionsFList - Puts a list of option values that a single one may be selected from
116453acd3b1SBarry Smith 
11653f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
116653acd3b1SBarry Smith 
116788aa4217SBarry Smith    Synopsis:
116888aa4217SBarry Smith    #include "petscsys.h"
11693a89f35bSSatish Balay    PetscErrorCode  PetscOptionsFList(const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char currentvalue[],char value[],size_t len,PetscBool  *set)
117088aa4217SBarry Smith 
117153acd3b1SBarry Smith    Input Parameters:
117253acd3b1SBarry Smith +  opt - option name
117353acd3b1SBarry Smith .  text - short string that describes the option
117453acd3b1SBarry Smith .  man - manual page with additional information on option
117553acd3b1SBarry Smith .  list - the possible choices
11760fdccdaeSBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with
11770fdccdaeSBarry Smith $                 PetscOptionsFlist(..., obj->value,value,len,&flg);
11780fdccdaeSBarry Smith $                 if (flg) {
11793cc1e11dSBarry Smith -  len - the length of the character array value
118053acd3b1SBarry Smith 
1181d8d19677SJose E. Roman    Output Parameters:
118253acd3b1SBarry Smith +  value - the value to return
118353acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
118453acd3b1SBarry Smith 
118553acd3b1SBarry Smith    Level: intermediate
118653acd3b1SBarry Smith 
118795452b02SPatrick Sanan    Notes:
118895452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
118953acd3b1SBarry Smith 
11902efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
11912efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
11922efd9cb1SBarry Smith 
1193989712b9SBarry Smith           The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
1194989712b9SBarry Smith 
119553acd3b1SBarry Smith    See PetscOptionsEList() for when the choices are given in a string array
119653acd3b1SBarry Smith 
119753acd3b1SBarry Smith    To get a listing of all currently specified options,
119888c29154SBarry Smith     see PetscOptionsView() or PetscOptionsGetAll()
119953acd3b1SBarry Smith 
1200eabe10d7SBarry Smith    Developer Note: This cannot check for invalid selection because of things like MATAIJ that are not included in the list
1201eabe10d7SBarry Smith 
120289a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1203acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
120453acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
120553acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1206acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1207a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList(), PetscOptionsEnum()
120888aa4217SBarry Smith M*/
120988aa4217SBarry Smith 
12104416b707SBarry Smith PetscErrorCode  PetscOptionsFList_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char currentvalue[],char value[],size_t len,PetscBool  *set)
121153acd3b1SBarry Smith {
121253acd3b1SBarry Smith   PetscErrorCode  ierr;
12134416b707SBarry Smith   PetscOptionItem amsopt;
121444ef3d73SBarry Smith   PetscBool       lset;
121553acd3b1SBarry Smith 
121653acd3b1SBarry Smith   PetscFunctionBegin;
12171a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
12184416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,ltext,man,OPTION_FLIST,&amsopt);CHKERRQ(ierr);
121964facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
12200fdccdaeSBarry Smith     ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr);
12213cc1e11dSBarry Smith     amsopt->flist = list;
12223cc1e11dSBarry Smith   }
122344ef3d73SBarry Smith   ierr = PetscOptionsGetString(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,len,&lset);CHKERRQ(ierr);
122444ef3d73SBarry Smith   if (set) *set = lset;
12251a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1226c3b366b1Sprj-     ierr = PetscFunctionListPrintTypes(PetscOptionsObject->comm,stdout,PetscOptionsObject->prefix,opt,ltext,man,list,currentvalue,lset && value ? value : currentvalue);CHKERRQ(ierr);
122753acd3b1SBarry Smith   }
122853acd3b1SBarry Smith   PetscFunctionReturn(0);
122953acd3b1SBarry Smith }
123053acd3b1SBarry Smith 
123188aa4217SBarry Smith /*MC
123253acd3b1SBarry Smith      PetscOptionsEList - Puts a list of option values that a single one may be selected from
123353acd3b1SBarry Smith 
12343f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
123553acd3b1SBarry Smith 
123688aa4217SBarry Smith    Synopsis:
123788aa4217SBarry Smith    #include "petscsys.h"
12383a89f35bSSatish Balay    PetscErrorCode  PetscOptionsEList(const char opt[],const char ltext[],const char man[],const char *const *list,PetscInt ntext,const char currentvalue[],PetscInt *value,PetscBool  *set)
123988aa4217SBarry Smith 
124053acd3b1SBarry Smith    Input Parameters:
124153acd3b1SBarry Smith +  opt - option name
124253acd3b1SBarry Smith .  ltext - short string that describes the option
124353acd3b1SBarry Smith .  man - manual page with additional information on option
1244a264d7a6SBarry Smith .  list - the possible choices (one of these must be selected, anything else is invalid)
124553acd3b1SBarry Smith .  ntext - number of choices
12460fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with
12470fdccdaeSBarry Smith $                 PetscOptionsElist(..., obj->value,&value,&flg);
12480fdccdaeSBarry Smith $                 if (flg) {
12490fdccdaeSBarry Smith 
1250d8d19677SJose E. Roman    Output Parameters:
125153acd3b1SBarry Smith +  value - the index of the value to return
125253acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
125353acd3b1SBarry Smith 
125453acd3b1SBarry Smith    Level: intermediate
125553acd3b1SBarry Smith 
125695452b02SPatrick Sanan    Notes:
125795452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
125853acd3b1SBarry Smith 
12592efd9cb1SBarry Smith          If the user does not supply the option at all value is NOT changed. Thus
12602efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
12612efd9cb1SBarry Smith 
1262a264d7a6SBarry Smith    See PetscOptionsFList() for when the choices are given in a PetscFunctionList()
126353acd3b1SBarry Smith 
126489a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1265acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
126653acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
126753acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1268acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1269a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEnum()
127088aa4217SBarry Smith M*/
127188aa4217SBarry Smith 
12724416b707SBarry Smith PetscErrorCode  PetscOptionsEList_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char ltext[],const char man[],const char *const *list,PetscInt ntext,const char currentvalue[],PetscInt *value,PetscBool  *set)
127353acd3b1SBarry Smith {
127453acd3b1SBarry Smith   PetscErrorCode  ierr;
127553acd3b1SBarry Smith   PetscInt        i;
12764416b707SBarry Smith   PetscOptionItem amsopt;
127744ef3d73SBarry Smith   PetscBool       lset;
127853acd3b1SBarry Smith 
127953acd3b1SBarry Smith   PetscFunctionBegin;
12801a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
12814416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,ltext,man,OPTION_ELIST,&amsopt);CHKERRQ(ierr);
128264facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
12830fdccdaeSBarry Smith     ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr);
12846991f827SBarry Smith     ierr = PetscStrNArrayallocpy(ntext,list,(char***)&amsopt->list);CHKERRQ(ierr);
12851ae3d29cSBarry Smith     amsopt->nlist = ntext;
12861ae3d29cSBarry Smith   }
128744ef3d73SBarry Smith   ierr = PetscOptionsGetEList(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,list,ntext,value,&lset);CHKERRQ(ierr);
128844ef3d73SBarry Smith   if (set) *set = lset;
12891a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
12900e4c290aSBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <now %s : formerly %s> %s (choose one of)",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,lset && value ? list[*value] : currentvalue,currentvalue,ltext);CHKERRQ(ierr);
129153acd3b1SBarry Smith     for (i=0; i<ntext; i++) {
1292e55864a3SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s",list[i]);CHKERRQ(ierr);
129353acd3b1SBarry Smith     }
1294e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," (%s)\n",ManSection(man));CHKERRQ(ierr);
129553acd3b1SBarry Smith   }
129653acd3b1SBarry Smith   PetscFunctionReturn(0);
129753acd3b1SBarry Smith }
129853acd3b1SBarry Smith 
129988aa4217SBarry Smith /*MC
1300acfcf0e5SJed Brown      PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for
1301d5649816SBarry Smith        which at most a single value can be true.
130253acd3b1SBarry Smith 
13033f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
130453acd3b1SBarry Smith 
130588aa4217SBarry Smith    Synopsis:
130688aa4217SBarry Smith    #include "petscsys.h"
13073a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroupBegin(const char opt[],const char text[],const char man[],PetscBool  *flg)
130888aa4217SBarry Smith 
130953acd3b1SBarry Smith    Input Parameters:
131053acd3b1SBarry Smith +  opt - option name
131153acd3b1SBarry Smith .  text - short string that describes the option
131253acd3b1SBarry Smith -  man - manual page with additional information on option
131353acd3b1SBarry Smith 
131453acd3b1SBarry Smith    Output Parameter:
131553acd3b1SBarry Smith .  flg - whether that option was set or not
131653acd3b1SBarry Smith 
131753acd3b1SBarry Smith    Level: intermediate
131853acd3b1SBarry Smith 
131995452b02SPatrick Sanan    Notes:
132095452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
132153acd3b1SBarry Smith 
1322acfcf0e5SJed Brown    Must be followed by 0 or more PetscOptionsBoolGroup()s and PetscOptionsBoolGroupEnd()
132353acd3b1SBarry Smith 
132489a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1325acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
132653acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
132753acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1328acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1329a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
133088aa4217SBarry Smith M*/
133188aa4217SBarry Smith 
13324416b707SBarry Smith PetscErrorCode  PetscOptionsBoolGroupBegin_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool  *flg)
133353acd3b1SBarry Smith {
133453acd3b1SBarry Smith   PetscErrorCode  ierr;
13354416b707SBarry Smith   PetscOptionItem amsopt;
133653acd3b1SBarry Smith 
133753acd3b1SBarry Smith   PetscFunctionBegin;
1338e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
13394416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1340ace3abfcSBarry Smith     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1341a297a907SKarl Rupp 
1342ace3abfcSBarry Smith     *(PetscBool*)amsopt->data = PETSC_FALSE;
13431ae3d29cSBarry Smith   }
134468b16fdaSBarry Smith   *flg = PETSC_FALSE;
1345c5929fdfSBarry Smith   ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr);
1346e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1347e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  Pick at most one of -------------\n");CHKERRQ(ierr);
1348e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"    -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
134953acd3b1SBarry Smith   }
135053acd3b1SBarry Smith   PetscFunctionReturn(0);
135153acd3b1SBarry Smith }
135253acd3b1SBarry Smith 
135388aa4217SBarry Smith /*MC
1354acfcf0e5SJed Brown      PetscOptionsBoolGroup - One in a series of logical queries on the options database for
1355d5649816SBarry Smith        which at most a single value can be true.
135653acd3b1SBarry Smith 
13573f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
135853acd3b1SBarry Smith 
135988aa4217SBarry Smith    Synopsis:
136088aa4217SBarry Smith    #include "petscsys.h"
13613a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroup(const char opt[],const char text[],const char man[],PetscBool  *flg)
136288aa4217SBarry Smith 
136353acd3b1SBarry Smith    Input Parameters:
136453acd3b1SBarry Smith +  opt - option name
136553acd3b1SBarry Smith .  text - short string that describes the option
136653acd3b1SBarry Smith -  man - manual page with additional information on option
136753acd3b1SBarry Smith 
136853acd3b1SBarry Smith    Output Parameter:
136953acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
137053acd3b1SBarry Smith 
137153acd3b1SBarry Smith    Level: intermediate
137253acd3b1SBarry Smith 
137395452b02SPatrick Sanan    Notes:
137495452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
137553acd3b1SBarry Smith 
1376acfcf0e5SJed Brown    Must follow a PetscOptionsBoolGroupBegin() and preceded a PetscOptionsBoolGroupEnd()
137753acd3b1SBarry Smith 
137889a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1379acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
138053acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
138153acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1382acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1383a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
138488aa4217SBarry Smith M*/
138588aa4217SBarry Smith 
13864416b707SBarry Smith PetscErrorCode  PetscOptionsBoolGroup_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool  *flg)
138753acd3b1SBarry Smith {
138853acd3b1SBarry Smith   PetscErrorCode  ierr;
13894416b707SBarry Smith   PetscOptionItem amsopt;
139053acd3b1SBarry Smith 
139153acd3b1SBarry Smith   PetscFunctionBegin;
1392e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
13934416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1394ace3abfcSBarry Smith     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1395a297a907SKarl Rupp 
1396ace3abfcSBarry Smith     *(PetscBool*)amsopt->data = PETSC_FALSE;
13971ae3d29cSBarry Smith   }
139817326d04SJed Brown   *flg = PETSC_FALSE;
1399c5929fdfSBarry Smith   ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr);
1400e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1401e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"    -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
140253acd3b1SBarry Smith   }
140353acd3b1SBarry Smith   PetscFunctionReturn(0);
140453acd3b1SBarry Smith }
140553acd3b1SBarry Smith 
140688aa4217SBarry Smith /*MC
1407acfcf0e5SJed Brown      PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for
1408d5649816SBarry Smith        which at most a single value can be true.
140953acd3b1SBarry Smith 
14103f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
141153acd3b1SBarry Smith 
141288aa4217SBarry Smith    Synopsis:
141388aa4217SBarry Smith    #include "petscsys.h"
14143a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroupEnd(const char opt[],const char text[],const char man[],PetscBool  *flg)
141588aa4217SBarry Smith 
141653acd3b1SBarry Smith    Input Parameters:
141753acd3b1SBarry Smith +  opt - option name
141853acd3b1SBarry Smith .  text - short string that describes the option
141953acd3b1SBarry Smith -  man - manual page with additional information on option
142053acd3b1SBarry Smith 
142153acd3b1SBarry Smith    Output Parameter:
142253acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
142353acd3b1SBarry Smith 
142453acd3b1SBarry Smith    Level: intermediate
142553acd3b1SBarry Smith 
142695452b02SPatrick Sanan    Notes:
142795452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
142853acd3b1SBarry Smith 
1429acfcf0e5SJed Brown    Must follow a PetscOptionsBoolGroupBegin()
143053acd3b1SBarry Smith 
143189a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1432acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
143353acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
143453acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1435acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1436a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
143788aa4217SBarry Smith M*/
143888aa4217SBarry Smith 
14394416b707SBarry Smith PetscErrorCode  PetscOptionsBoolGroupEnd_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool  *flg)
144053acd3b1SBarry Smith {
144153acd3b1SBarry Smith   PetscErrorCode  ierr;
14424416b707SBarry Smith   PetscOptionItem amsopt;
144353acd3b1SBarry Smith 
144453acd3b1SBarry Smith   PetscFunctionBegin;
1445e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
14464416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1447ace3abfcSBarry Smith     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1448a297a907SKarl Rupp 
1449ace3abfcSBarry Smith     *(PetscBool*)amsopt->data = PETSC_FALSE;
14501ae3d29cSBarry Smith   }
145117326d04SJed Brown   *flg = PETSC_FALSE;
1452c5929fdfSBarry Smith   ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr);
1453e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1454e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"    -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
145553acd3b1SBarry Smith   }
145653acd3b1SBarry Smith   PetscFunctionReturn(0);
145753acd3b1SBarry Smith }
145853acd3b1SBarry Smith 
145988aa4217SBarry Smith /*MC
1460acfcf0e5SJed Brown    PetscOptionsBool - Determines if a particular option is in the database with a true or false
146153acd3b1SBarry Smith 
14623f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
146353acd3b1SBarry Smith 
146488aa4217SBarry Smith    Synopsis:
146588aa4217SBarry Smith    #include "petscsys.h"
14663a89f35bSSatish Balay    PetscErrorCode PetscOptionsBool(const char opt[],const char text[],const char man[],PetscBool currentvalue,PetscBool  *flg,PetscBool  *set)
146788aa4217SBarry Smith 
146853acd3b1SBarry Smith    Input Parameters:
146953acd3b1SBarry Smith +  opt - option name
147053acd3b1SBarry Smith .  text - short string that describes the option
1471868c398cSBarry Smith .  man - manual page with additional information on option
147294ae4db5SBarry Smith -  currentvalue - the current value
147353acd3b1SBarry Smith 
1474d8d19677SJose E. Roman    Output Parameters:
1475a2b725a8SWilliam Gropp +  flg - PETSC_TRUE or PETSC_FALSE
1476a2b725a8SWilliam Gropp -  set - PETSC_TRUE if found, else PETSC_FALSE
147753acd3b1SBarry Smith 
14782efd9cb1SBarry Smith    Notes:
14792efd9cb1SBarry Smith        TRUE, true, YES, yes, nostring, and 1 all translate to PETSC_TRUE
14802efd9cb1SBarry Smith        FALSE, false, NO, no, and 0 all translate to PETSC_FALSE
14812efd9cb1SBarry Smith 
14822efd9cb1SBarry Smith       If the option is given, but no value is provided, then flg and set are both given the value PETSC_TRUE. That is -requested_bool
14832efd9cb1SBarry Smith      is equivalent to -requested_bool true
14842efd9cb1SBarry Smith 
14852efd9cb1SBarry Smith        If the user does not supply the option at all flg is NOT changed. Thus
14862efd9cb1SBarry Smith      you should ALWAYS initialize the flg if you access it without first checking if the set flag is true.
14872efd9cb1SBarry Smith 
148895452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
148953acd3b1SBarry Smith 
14905a856986SBarry Smith    Level: beginner
14915a856986SBarry Smith 
149289a13869SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1493536f90c4SPierre Jolivet           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(),
1494536f90c4SPierre Jolivet           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(),
149553acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
149653acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1497acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1498a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
149988aa4217SBarry Smith M*/
150088aa4217SBarry Smith 
15014416b707SBarry Smith PetscErrorCode  PetscOptionsBool_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool currentvalue,PetscBool  *flg,PetscBool  *set)
150253acd3b1SBarry Smith {
150353acd3b1SBarry Smith   PetscErrorCode  ierr;
1504ace3abfcSBarry Smith   PetscBool       iset;
15054416b707SBarry Smith   PetscOptionItem amsopt;
150653acd3b1SBarry Smith 
150753acd3b1SBarry Smith   PetscFunctionBegin;
1508e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
15094416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1510ace3abfcSBarry Smith     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1511a297a907SKarl Rupp 
151294ae4db5SBarry Smith     *(PetscBool*)amsopt->data = currentvalue;
1513af6d86caSBarry Smith   }
1514c5929fdfSBarry Smith   ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,&iset);CHKERRQ(ierr);
151553acd3b1SBarry Smith   if (set) *set = iset;
15161a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
151744ef3d73SBarry Smith     const char *v = PetscBools[currentvalue], *vn = PetscBools[iset && flg ? *flg : currentvalue];
151844ef3d73SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s: <%s : %s> %s (%s)\n",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,v,vn,text,ManSection(man));CHKERRQ(ierr);
151953acd3b1SBarry Smith   }
152053acd3b1SBarry Smith   PetscFunctionReturn(0);
152153acd3b1SBarry Smith }
152253acd3b1SBarry Smith 
152388aa4217SBarry Smith /*MC
152453acd3b1SBarry Smith    PetscOptionsRealArray - Gets an array of double values for a particular
152553acd3b1SBarry Smith    option in the database. The values must be separated with commas with
152653acd3b1SBarry Smith    no intervening spaces.
152753acd3b1SBarry Smith 
15283f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
152953acd3b1SBarry Smith 
153088aa4217SBarry Smith    Synopsis:
153188aa4217SBarry Smith    #include "petscsys.h"
15323a89f35bSSatish Balay    PetscErrorCode PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool  *set)
153388aa4217SBarry Smith 
153453acd3b1SBarry Smith    Input Parameters:
153553acd3b1SBarry Smith +  opt - the option one is seeking
153653acd3b1SBarry Smith .  text - short string describing option
153753acd3b1SBarry Smith .  man - manual page for option
153853acd3b1SBarry Smith -  nmax - maximum number of values
153953acd3b1SBarry Smith 
1540d8d19677SJose E. Roman    Output Parameters:
154153acd3b1SBarry Smith +  value - location to copy values
154253acd3b1SBarry Smith .  nmax - actual number of values found
154353acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
154453acd3b1SBarry Smith 
154553acd3b1SBarry Smith    Level: beginner
154653acd3b1SBarry Smith 
154753acd3b1SBarry Smith    Notes:
154853acd3b1SBarry Smith    The user should pass in an array of doubles
154953acd3b1SBarry Smith 
155053acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
155153acd3b1SBarry Smith 
155289a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1553acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
155453acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
155553acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1556acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1557a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
155888aa4217SBarry Smith M*/
155988aa4217SBarry Smith 
15604416b707SBarry Smith PetscErrorCode PetscOptionsRealArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool  *set)
156153acd3b1SBarry Smith {
156253acd3b1SBarry Smith   PetscErrorCode  ierr;
156353acd3b1SBarry Smith   PetscInt        i;
15644416b707SBarry Smith   PetscOptionItem amsopt;
156553acd3b1SBarry Smith 
156653acd3b1SBarry Smith   PetscFunctionBegin;
1567e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1568e26ddf31SBarry Smith     PetscReal *vals;
1569e26ddf31SBarry Smith 
15704416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr);
1571e55864a3SBarry Smith     ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
1572e26ddf31SBarry Smith     vals = (PetscReal*)amsopt->data;
1573e26ddf31SBarry Smith     for (i=0; i<*n; i++) vals[i] = value[i];
1574e26ddf31SBarry Smith     amsopt->arraylength = *n;
1575e26ddf31SBarry Smith   }
1576c5929fdfSBarry Smith   ierr = PetscOptionsGetRealArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr);
1577e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1578a519f713SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%g",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,(double)value[0]);CHKERRQ(ierr);
157953acd3b1SBarry Smith     for (i=1; i<*n; i++) {
1580e55864a3SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%g",(double)value[i]);CHKERRQ(ierr);
158153acd3b1SBarry Smith     }
1582e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
158353acd3b1SBarry Smith   }
158453acd3b1SBarry Smith   PetscFunctionReturn(0);
158553acd3b1SBarry Smith }
158653acd3b1SBarry Smith 
158788aa4217SBarry Smith /*MC
1588050cccc3SHong Zhang    PetscOptionsScalarArray - Gets an array of Scalar values for a particular
1589050cccc3SHong Zhang    option in the database. The values must be separated with commas with
1590050cccc3SHong Zhang    no intervening spaces.
1591050cccc3SHong Zhang 
1592050cccc3SHong Zhang    Logically Collective on the communicator passed in PetscOptionsBegin()
1593050cccc3SHong Zhang 
159488aa4217SBarry Smith    Synopsis:
159588aa4217SBarry Smith    #include "petscsys.h"
15963a89f35bSSatish Balay    PetscErrorCode PetscOptionsScalarArray(const char opt[],const char text[],const char man[],PetscScalar value[],PetscInt *n,PetscBool  *set)
159788aa4217SBarry Smith 
1598050cccc3SHong Zhang    Input Parameters:
1599050cccc3SHong Zhang +  opt - the option one is seeking
1600050cccc3SHong Zhang .  text - short string describing option
1601050cccc3SHong Zhang .  man - manual page for option
1602050cccc3SHong Zhang -  nmax - maximum number of values
1603050cccc3SHong Zhang 
1604d8d19677SJose E. Roman    Output Parameters:
1605050cccc3SHong Zhang +  value - location to copy values
1606050cccc3SHong Zhang .  nmax - actual number of values found
1607050cccc3SHong Zhang -  set - PETSC_TRUE if found, else PETSC_FALSE
1608050cccc3SHong Zhang 
1609050cccc3SHong Zhang    Level: beginner
1610050cccc3SHong Zhang 
1611050cccc3SHong Zhang    Notes:
1612050cccc3SHong Zhang    The user should pass in an array of doubles
1613050cccc3SHong Zhang 
1614050cccc3SHong Zhang    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1615050cccc3SHong Zhang 
161689a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1617050cccc3SHong Zhang           PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1618050cccc3SHong Zhang           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1619050cccc3SHong Zhang           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1620050cccc3SHong Zhang           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1621050cccc3SHong Zhang           PetscOptionsFList(), PetscOptionsEList()
162288aa4217SBarry Smith M*/
162388aa4217SBarry Smith 
16244416b707SBarry Smith PetscErrorCode PetscOptionsScalarArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscScalar value[],PetscInt *n,PetscBool  *set)
1625050cccc3SHong Zhang {
1626050cccc3SHong Zhang   PetscErrorCode  ierr;
1627050cccc3SHong Zhang   PetscInt        i;
16284416b707SBarry Smith   PetscOptionItem amsopt;
1629050cccc3SHong Zhang 
1630050cccc3SHong Zhang   PetscFunctionBegin;
1631050cccc3SHong Zhang   if (!PetscOptionsObject->count) {
1632050cccc3SHong Zhang     PetscScalar *vals;
1633050cccc3SHong Zhang 
16344416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_SCALAR_ARRAY,&amsopt);CHKERRQ(ierr);
1635050cccc3SHong Zhang     ierr = PetscMalloc((*n)*sizeof(PetscScalar),&amsopt->data);CHKERRQ(ierr);
1636050cccc3SHong Zhang     vals = (PetscScalar*)amsopt->data;
1637050cccc3SHong Zhang     for (i=0; i<*n; i++) vals[i] = value[i];
1638050cccc3SHong Zhang     amsopt->arraylength = *n;
1639050cccc3SHong Zhang   }
1640c5929fdfSBarry Smith   ierr = PetscOptionsGetScalarArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr);
1641050cccc3SHong Zhang   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
164295f3a755SJose E. Roman     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%g+%gi",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,(double)PetscRealPart(value[0]),(double)PetscImaginaryPart(value[0]));CHKERRQ(ierr);
1643050cccc3SHong Zhang     for (i=1; i<*n; i++) {
164495f3a755SJose E. Roman       ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%g+%gi",(double)PetscRealPart(value[i]),(double)PetscImaginaryPart(value[i]));CHKERRQ(ierr);
1645050cccc3SHong Zhang     }
1646050cccc3SHong Zhang     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1647050cccc3SHong Zhang   }
1648050cccc3SHong Zhang   PetscFunctionReturn(0);
1649050cccc3SHong Zhang }
165053acd3b1SBarry Smith 
165188aa4217SBarry Smith /*MC
165253acd3b1SBarry Smith    PetscOptionsIntArray - Gets an array of integers for a particular
1653b32a342fSShri Abhyankar    option in the database.
165453acd3b1SBarry Smith 
16553f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
165653acd3b1SBarry Smith 
165788aa4217SBarry Smith    Synopsis:
165888aa4217SBarry Smith    #include "petscsys.h"
16593a89f35bSSatish Balay    PetscErrorCode PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool  *set)
166088aa4217SBarry Smith 
166153acd3b1SBarry Smith    Input Parameters:
166253acd3b1SBarry Smith +  opt - the option one is seeking
166353acd3b1SBarry Smith .  text - short string describing option
166453acd3b1SBarry Smith .  man - manual page for option
1665f8a50e2bSBarry Smith -  n - maximum number of values
166653acd3b1SBarry Smith 
1667d8d19677SJose E. Roman    Output Parameters:
166853acd3b1SBarry Smith +  value - location to copy values
1669f8a50e2bSBarry Smith .  n - actual number of values found
167053acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
167153acd3b1SBarry Smith 
167253acd3b1SBarry Smith    Level: beginner
167353acd3b1SBarry Smith 
167453acd3b1SBarry Smith    Notes:
1675b32a342fSShri Abhyankar    The array can be passed as
1676bebe2cf6SSatish Balay    a comma separated list:                                 0,1,2,3,4,5,6,7
16770fd488f5SShri Abhyankar    a range (start-end+1):                                  0-8
16780fd488f5SShri Abhyankar    a range with given increment (start-end+1:inc):         0-7:2
1679bebe2cf6SSatish Balay    a combination of values and ranges separated by commas: 0,1-8,8-15:2
1680b32a342fSShri Abhyankar 
1681b32a342fSShri Abhyankar    There must be no intervening spaces between the values.
168253acd3b1SBarry Smith 
168353acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
168453acd3b1SBarry Smith 
168589a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1686acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
168753acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
168853acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1689acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1690a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList(), PetscOptionsRealArray()
169188aa4217SBarry Smith M*/
169288aa4217SBarry Smith 
16934416b707SBarry Smith PetscErrorCode  PetscOptionsIntArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool  *set)
169453acd3b1SBarry Smith {
169553acd3b1SBarry Smith   PetscErrorCode ierr;
169653acd3b1SBarry Smith   PetscInt        i;
16974416b707SBarry Smith   PetscOptionItem amsopt;
169853acd3b1SBarry Smith 
169953acd3b1SBarry Smith   PetscFunctionBegin;
1700e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1701e26ddf31SBarry Smith     PetscInt *vals;
1702e26ddf31SBarry Smith 
17034416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr);
1704854ce69bSBarry Smith     ierr = PetscMalloc1(*n,(PetscInt**)&amsopt->data);CHKERRQ(ierr);
1705e26ddf31SBarry Smith     vals = (PetscInt*)amsopt->data;
1706e26ddf31SBarry Smith     for (i=0; i<*n; i++) vals[i] = value[i];
1707e26ddf31SBarry Smith     amsopt->arraylength = *n;
1708e26ddf31SBarry Smith   }
1709c5929fdfSBarry Smith   ierr = PetscOptionsGetIntArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr);
1710e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1711e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%d",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,value[0]);CHKERRQ(ierr);
171253acd3b1SBarry Smith     for (i=1; i<*n; i++) {
1713e55864a3SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%d",value[i]);CHKERRQ(ierr);
171453acd3b1SBarry Smith     }
1715e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
171653acd3b1SBarry Smith   }
171753acd3b1SBarry Smith   PetscFunctionReturn(0);
171853acd3b1SBarry Smith }
171953acd3b1SBarry Smith 
172088aa4217SBarry Smith /*MC
172153acd3b1SBarry Smith    PetscOptionsStringArray - Gets an array of string values for a particular
172253acd3b1SBarry Smith    option in the database. The values must be separated with commas with
172353acd3b1SBarry Smith    no intervening spaces.
172453acd3b1SBarry Smith 
17253f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
172653acd3b1SBarry Smith 
172788aa4217SBarry Smith    Synopsis:
172888aa4217SBarry Smith    #include "petscsys.h"
17293a89f35bSSatish Balay    PetscErrorCode PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool  *set)
173088aa4217SBarry Smith 
173153acd3b1SBarry Smith    Input Parameters:
173253acd3b1SBarry Smith +  opt - the option one is seeking
173353acd3b1SBarry Smith .  text - short string describing option
173453acd3b1SBarry Smith .  man - manual page for option
173553acd3b1SBarry Smith -  nmax - maximum number of strings
173653acd3b1SBarry Smith 
1737d8d19677SJose E. Roman    Output Parameters:
173853acd3b1SBarry Smith +  value - location to copy strings
173953acd3b1SBarry Smith .  nmax - actual number of strings found
174053acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
174153acd3b1SBarry Smith 
174253acd3b1SBarry Smith    Level: beginner
174353acd3b1SBarry Smith 
174453acd3b1SBarry Smith    Notes:
174553acd3b1SBarry Smith    The user should pass in an array of pointers to char, to hold all the
174653acd3b1SBarry Smith    strings returned by this function.
174753acd3b1SBarry Smith 
174853acd3b1SBarry Smith    The user is responsible for deallocating the strings that are
174953acd3b1SBarry Smith    returned. The Fortran interface for this routine is not supported.
175053acd3b1SBarry Smith 
175153acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
175253acd3b1SBarry Smith 
175389a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1754acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
175553acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
175653acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1757acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1758a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
175988aa4217SBarry Smith M*/
176088aa4217SBarry Smith 
17614416b707SBarry Smith PetscErrorCode  PetscOptionsStringArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool  *set)
176253acd3b1SBarry Smith {
176353acd3b1SBarry Smith   PetscErrorCode  ierr;
17644416b707SBarry Smith   PetscOptionItem amsopt;
176553acd3b1SBarry Smith 
176653acd3b1SBarry Smith   PetscFunctionBegin;
1767e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
17684416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING_ARRAY,&amsopt);CHKERRQ(ierr);
1769854ce69bSBarry Smith     ierr = PetscMalloc1(*nmax,(char**)&amsopt->data);CHKERRQ(ierr);
1770a297a907SKarl Rupp 
17711ae3d29cSBarry Smith     amsopt->arraylength = *nmax;
17721ae3d29cSBarry Smith   }
1773c5929fdfSBarry Smith   ierr = PetscOptionsGetStringArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,nmax,set);CHKERRQ(ierr);
1774e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1775e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
177653acd3b1SBarry Smith   }
177753acd3b1SBarry Smith   PetscFunctionReturn(0);
177853acd3b1SBarry Smith }
177953acd3b1SBarry Smith 
178088aa4217SBarry Smith /*MC
1781acfcf0e5SJed Brown    PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular
1782e2446a98SMatthew Knepley    option in the database. The values must be separated with commas with
1783e2446a98SMatthew Knepley    no intervening spaces.
1784e2446a98SMatthew Knepley 
17853f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
1786e2446a98SMatthew Knepley 
178788aa4217SBarry Smith    Synopsis:
178888aa4217SBarry Smith    #include "petscsys.h"
17893a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolArray(const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set)
179088aa4217SBarry Smith 
1791e2446a98SMatthew Knepley    Input Parameters:
1792e2446a98SMatthew Knepley +  opt - the option one is seeking
1793e2446a98SMatthew Knepley .  text - short string describing option
1794e2446a98SMatthew Knepley .  man - manual page for option
1795e2446a98SMatthew Knepley -  nmax - maximum number of values
1796e2446a98SMatthew Knepley 
1797d8d19677SJose E. Roman    Output Parameters:
1798e2446a98SMatthew Knepley +  value - location to copy values
1799e2446a98SMatthew Knepley .  nmax - actual number of values found
1800e2446a98SMatthew Knepley -  set - PETSC_TRUE if found, else PETSC_FALSE
1801e2446a98SMatthew Knepley 
1802e2446a98SMatthew Knepley    Level: beginner
1803e2446a98SMatthew Knepley 
1804e2446a98SMatthew Knepley    Notes:
1805e2446a98SMatthew Knepley    The user should pass in an array of doubles
1806e2446a98SMatthew Knepley 
1807e2446a98SMatthew Knepley    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1808e2446a98SMatthew Knepley 
180989a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1810acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1811e2446a98SMatthew Knepley           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1812e2446a98SMatthew Knepley           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1813acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1814a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
181588aa4217SBarry Smith M*/
181688aa4217SBarry Smith 
18174416b707SBarry Smith PetscErrorCode  PetscOptionsBoolArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set)
1818e2446a98SMatthew Knepley {
1819e2446a98SMatthew Knepley   PetscErrorCode   ierr;
1820e2446a98SMatthew Knepley   PetscInt         i;
18214416b707SBarry Smith   PetscOptionItem  amsopt;
1822e2446a98SMatthew Knepley 
1823e2446a98SMatthew Knepley   PetscFunctionBegin;
1824e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1825ace3abfcSBarry Smith     PetscBool *vals;
18261ae3d29cSBarry Smith 
18274416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL_ARRAY,&amsopt);CHKERRQ(ierr);
18281a1499c8SBarry Smith     ierr = PetscMalloc1(*n,(PetscBool**)&amsopt->data);CHKERRQ(ierr);
1829ace3abfcSBarry Smith     vals = (PetscBool*)amsopt->data;
18301ae3d29cSBarry Smith     for (i=0; i<*n; i++) vals[i] = value[i];
18311ae3d29cSBarry Smith     amsopt->arraylength = *n;
18321ae3d29cSBarry Smith   }
1833c5929fdfSBarry Smith   ierr = PetscOptionsGetBoolArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr);
1834e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1835e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%d",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,value[0]);CHKERRQ(ierr);
1836e2446a98SMatthew Knepley     for (i=1; i<*n; i++) {
1837e55864a3SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%d",value[i]);CHKERRQ(ierr);
1838e2446a98SMatthew Knepley     }
1839e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1840e2446a98SMatthew Knepley   }
1841e2446a98SMatthew Knepley   PetscFunctionReturn(0);
1842e2446a98SMatthew Knepley }
1843e2446a98SMatthew Knepley 
184488aa4217SBarry Smith /*MC
1845d1da0b69SBarry Smith    PetscOptionsViewer - Gets a viewer appropriate for the type indicated by the user
18468cc676e6SMatthew G Knepley 
18478cc676e6SMatthew G Knepley    Logically Collective on the communicator passed in PetscOptionsBegin()
18488cc676e6SMatthew G Knepley 
184988aa4217SBarry Smith    Synopsis:
185088aa4217SBarry Smith    #include "petscsys.h"
18513a89f35bSSatish Balay    PetscErrorCode PetscOptionsViewer(const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool  *set)
185288aa4217SBarry Smith 
18538cc676e6SMatthew G Knepley    Input Parameters:
18548cc676e6SMatthew G Knepley +  opt - option name
18558cc676e6SMatthew G Knepley .  text - short string that describes the option
18568cc676e6SMatthew G Knepley -  man - manual page with additional information on option
18578cc676e6SMatthew G Knepley 
1858d8d19677SJose E. Roman    Output Parameters:
18598cc676e6SMatthew G Knepley +  viewer - the viewer
18608cc676e6SMatthew G Knepley -  set - PETSC_TRUE if found, else PETSC_FALSE
18618cc676e6SMatthew G Knepley 
18628cc676e6SMatthew G Knepley    Level: beginner
18638cc676e6SMatthew G Knepley 
186495452b02SPatrick Sanan    Notes:
186595452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
18668cc676e6SMatthew G Knepley 
18675a7113b9SPatrick Sanan    See PetscOptionsGetViewer() for the format of the supplied viewer and its options
18688cc676e6SMatthew G Knepley 
186989a13869SBarry Smith .seealso: PetscOptionsGetViewer(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
18708cc676e6SMatthew G Knepley           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
18718cc676e6SMatthew G Knepley           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
18728cc676e6SMatthew G Knepley           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
18738cc676e6SMatthew G Knepley           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
18748cc676e6SMatthew G Knepley           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1875a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
187688aa4217SBarry Smith M*/
187788aa4217SBarry Smith 
18784416b707SBarry Smith PetscErrorCode  PetscOptionsViewer_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool  *set)
18798cc676e6SMatthew G Knepley {
18808cc676e6SMatthew G Knepley   PetscErrorCode  ierr;
18814416b707SBarry Smith   PetscOptionItem amsopt;
18828cc676e6SMatthew G Knepley 
18838cc676e6SMatthew G Knepley   PetscFunctionBegin;
18841a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
18854416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
188664facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
18875b02f95dSBarry Smith     ierr = PetscStrdup("",(char**)&amsopt->data);CHKERRQ(ierr);
18888cc676e6SMatthew G Knepley   }
188916413a6aSBarry Smith   ierr = PetscOptionsGetViewer(PetscOptionsObject->comm,PetscOptionsObject->options,PetscOptionsObject->prefix,opt,viewer,format,set);CHKERRQ(ierr);
1890e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1891e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%s>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,"",text,ManSection(man));CHKERRQ(ierr);
18928cc676e6SMatthew G Knepley   }
18938cc676e6SMatthew G Knepley   PetscFunctionReturn(0);
18948cc676e6SMatthew G Knepley }
18958cc676e6SMatthew G Knepley 
189653acd3b1SBarry Smith /*@C
1897b52f573bSBarry Smith      PetscOptionsHead - Puts a heading before listing any more published options. Used, for example,
189853acd3b1SBarry Smith             in KSPSetFromOptions_GMRES().
189953acd3b1SBarry Smith 
19003f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
190153acd3b1SBarry Smith 
190253acd3b1SBarry Smith    Input Parameter:
190353acd3b1SBarry Smith .   head - the heading text
190453acd3b1SBarry Smith 
190553acd3b1SBarry Smith    Level: intermediate
190653acd3b1SBarry Smith 
190795452b02SPatrick Sanan    Notes:
19083a89f35bSSatish Balay     Must be between a PetscOptionsBegin() and a PetscOptionsEnd(), and PetscOptionsObject created in PetscOptionsBegin() should be the first argument
190953acd3b1SBarry Smith 
1910b52f573bSBarry Smith           Can be followed by a call to PetscOptionsTail() in the same function.
191153acd3b1SBarry Smith 
191289a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1913acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
191453acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
191553acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1916acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1917a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
191853acd3b1SBarry Smith @*/
19194416b707SBarry Smith PetscErrorCode  PetscOptionsHead(PetscOptionItems *PetscOptionsObject,const char head[])
192053acd3b1SBarry Smith {
192153acd3b1SBarry Smith   PetscErrorCode ierr;
192253acd3b1SBarry Smith 
192353acd3b1SBarry Smith   PetscFunctionBegin;
1924e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1925e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  %s\n",head);CHKERRQ(ierr);
192653acd3b1SBarry Smith   }
192753acd3b1SBarry Smith   PetscFunctionReturn(0);
192853acd3b1SBarry Smith }
192953acd3b1SBarry Smith 
1930