xref: /petsc/src/sys/objects/aoptions.c (revision d8d19677bbccf95218448bee62e6b87f4513e133)
17d0a6c19SBarry Smith 
253acd3b1SBarry Smith /*
33fc1eb6aSBarry Smith    Implements the higher-level options database querying methods. These are self-documenting and can attach at runtime to
43fc1eb6aSBarry Smith    GUI code to display the options and get values from the users.
553acd3b1SBarry Smith 
653acd3b1SBarry Smith */
753acd3b1SBarry Smith 
8af0996ceSBarry Smith #include <petsc/private/petscimpl.h>        /*I  "petscsys.h"   I*/
9665c2dedSJed Brown #include <petscviewer.h>
1053acd3b1SBarry Smith 
112aa6d131SJed Brown #define ManSection(str) ((str) ? (str) : "None")
122aa6d131SJed Brown 
1353acd3b1SBarry Smith /*
1453acd3b1SBarry Smith     Keep a linked list of options that have been posted and we are waiting for
153fc1eb6aSBarry Smith    user selection. See the manual page for PetscOptionsBegin()
1653acd3b1SBarry Smith 
1753acd3b1SBarry Smith     Eventually we'll attach this beast to a MPI_Comm
1853acd3b1SBarry Smith */
19e55864a3SBarry Smith 
2053acd3b1SBarry Smith /*
2153acd3b1SBarry Smith     Handles setting up the data structure in a call to PetscOptionsBegin()
2253acd3b1SBarry Smith */
234416b707SBarry Smith PetscErrorCode PetscOptionsBegin_Private(PetscOptionItems *PetscOptionsObject,MPI_Comm comm,const char prefix[],const char title[],const char mansec[])
2453acd3b1SBarry Smith {
2553acd3b1SBarry Smith   PetscErrorCode ierr;
2653acd3b1SBarry Smith 
2753acd3b1SBarry Smith   PetscFunctionBegin;
28064a246eSJacob Faibussowitsch   if (prefix) PetscValidCharPointer(prefix,3);
29064a246eSJacob Faibussowitsch   PetscValidCharPointer(title,4);
30064a246eSJacob Faibussowitsch   if (mansec) PetscValidCharPointer(mansec,5);
310eb63584SBarry Smith   if (!PetscOptionsObject->alreadyprinted) {
329de0f6ecSBarry Smith     if (!PetscOptionsHelpPrintedSingleton) {
339de0f6ecSBarry Smith       ierr = PetscOptionsHelpPrintedCreate(&PetscOptionsHelpPrintedSingleton);CHKERRQ(ierr);
349de0f6ecSBarry Smith     }
359de0f6ecSBarry Smith     ierr = PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrintedSingleton,prefix,title,&PetscOptionsObject->alreadyprinted);CHKERRQ(ierr);
360eb63584SBarry Smith   }
3702c9f0b5SLisandro Dalcin   PetscOptionsObject->next          = NULL;
38e55864a3SBarry Smith   PetscOptionsObject->comm          = comm;
39e55864a3SBarry Smith   PetscOptionsObject->changedmethod = PETSC_FALSE;
40a297a907SKarl Rupp 
41e55864a3SBarry Smith   ierr = PetscStrallocpy(prefix,&PetscOptionsObject->prefix);CHKERRQ(ierr);
42e55864a3SBarry Smith   ierr = PetscStrallocpy(title,&PetscOptionsObject->title);CHKERRQ(ierr);
4353acd3b1SBarry Smith 
442d747510SLisandro Dalcin   ierr = PetscOptionsHasHelp(PetscOptionsObject->options,&PetscOptionsObject->printhelp);CHKERRQ(ierr);
45e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1) {
46e55864a3SBarry Smith     if (!PetscOptionsObject->alreadyprinted) {
47c0bb3764SVaclav Hapla       ierr = (*PetscHelpPrintf)(comm,"----------------------------------------\n%s:\n",title);CHKERRQ(ierr);
4853acd3b1SBarry Smith     }
4961b37b28SSatish Balay   }
5053acd3b1SBarry Smith   PetscFunctionReturn(0);
5153acd3b1SBarry Smith }
5253acd3b1SBarry Smith 
533194b578SJed Brown /*
543194b578SJed Brown     Handles setting up the data structure in a call to PetscObjectOptionsBegin()
553194b578SJed Brown */
564416b707SBarry Smith PetscErrorCode PetscObjectOptionsBegin_Private(PetscOptionItems *PetscOptionsObject,PetscObject obj)
573194b578SJed Brown {
583194b578SJed Brown   PetscErrorCode ierr;
593194b578SJed Brown   char           title[256];
603194b578SJed Brown   PetscBool      flg;
613194b578SJed Brown 
623194b578SJed Brown   PetscFunctionBegin;
63064a246eSJacob Faibussowitsch   PetscValidHeader(obj,2);
64e55864a3SBarry Smith   PetscOptionsObject->object         = obj;
65e55864a3SBarry Smith   PetscOptionsObject->alreadyprinted = obj->optionsprinted;
66a297a907SKarl Rupp 
673194b578SJed Brown   ierr = PetscStrcmp(obj->description,obj->class_name,&flg);CHKERRQ(ierr);
683194b578SJed Brown   if (flg) {
698caf3d72SBarry Smith     ierr = PetscSNPrintf(title,sizeof(title),"%s options",obj->class_name);CHKERRQ(ierr);
703194b578SJed Brown   } else {
718caf3d72SBarry Smith     ierr = PetscSNPrintf(title,sizeof(title),"%s (%s) options",obj->description,obj->class_name);CHKERRQ(ierr);
723194b578SJed Brown   }
73e55864a3SBarry Smith   ierr = PetscOptionsBegin_Private(PetscOptionsObject,obj->comm,obj->prefix,title,obj->mansec);CHKERRQ(ierr);
743194b578SJed Brown   PetscFunctionReturn(0);
753194b578SJed Brown }
763194b578SJed Brown 
7753acd3b1SBarry Smith /*
7853acd3b1SBarry Smith      Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd()
7953acd3b1SBarry Smith */
804416b707SBarry Smith static int PetscOptionItemCreate_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscOptionType t,PetscOptionItem *amsopt)
8153acd3b1SBarry Smith {
8253acd3b1SBarry Smith   int             ierr;
834416b707SBarry Smith   PetscOptionItem next;
843be6e4c3SJed Brown   PetscBool       valid;
8553acd3b1SBarry Smith 
8653acd3b1SBarry Smith   PetscFunctionBegin;
873be6e4c3SJed Brown   ierr = PetscOptionsValidKey(opt,&valid);CHKERRQ(ierr);
883be6e4c3SJed Brown   if (!valid) SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_ARG_INCOMP,"The option '%s' is not a valid key",opt);
893be6e4c3SJed Brown 
90b00a9115SJed Brown   ierr            = PetscNew(amsopt);CHKERRQ(ierr);
9102c9f0b5SLisandro Dalcin   (*amsopt)->next = NULL;
9253acd3b1SBarry Smith   (*amsopt)->set  = PETSC_FALSE;
936356e834SBarry Smith   (*amsopt)->type = t;
9402c9f0b5SLisandro Dalcin   (*amsopt)->data = NULL;
9561b37b28SSatish Balay 
9653acd3b1SBarry Smith   ierr = PetscStrallocpy(text,&(*amsopt)->text);CHKERRQ(ierr);
9753acd3b1SBarry Smith   ierr = PetscStrallocpy(opt,&(*amsopt)->option);CHKERRQ(ierr);
986356e834SBarry Smith   ierr = PetscStrallocpy(man,&(*amsopt)->man);CHKERRQ(ierr);
9953acd3b1SBarry Smith 
100e55864a3SBarry Smith   if (!PetscOptionsObject->next) PetscOptionsObject->next = *amsopt;
101a297a907SKarl Rupp   else {
102e55864a3SBarry Smith     next = PetscOptionsObject->next;
10353acd3b1SBarry Smith     while (next->next) next = next->next;
10453acd3b1SBarry Smith     next->next = *amsopt;
10553acd3b1SBarry Smith   }
10653acd3b1SBarry Smith   PetscFunctionReturn(0);
10753acd3b1SBarry Smith }
10853acd3b1SBarry Smith 
109aee2cecaSBarry Smith /*
1103fc1eb6aSBarry Smith     PetscScanString -  Gets user input via stdin from process and broadcasts to all processes
1113fc1eb6aSBarry Smith 
112d083f849SBarry Smith     Collective
1133fc1eb6aSBarry Smith 
1143fc1eb6aSBarry Smith    Input Parameters:
1153fc1eb6aSBarry Smith +     commm - communicator for the broadcast, must be PETSC_COMM_WORLD
1163fc1eb6aSBarry Smith .     n - length of the string, must be the same on all processes
1173fc1eb6aSBarry Smith -     str - location to store input
118aee2cecaSBarry Smith 
119aee2cecaSBarry Smith     Bugs:
120aee2cecaSBarry Smith .   Assumes process 0 of the given communicator has access to stdin
121aee2cecaSBarry Smith 
122aee2cecaSBarry Smith */
1233fc1eb6aSBarry Smith static PetscErrorCode PetscScanString(MPI_Comm comm,size_t n,char str[])
124aee2cecaSBarry Smith {
125330cf3c9SBarry Smith   size_t         i;
126aee2cecaSBarry Smith   char           c;
1273fc1eb6aSBarry Smith   PetscMPIInt    rank,nm;
128aee2cecaSBarry Smith   PetscErrorCode ierr;
129aee2cecaSBarry Smith 
130aee2cecaSBarry Smith   PetscFunctionBegin;
131ffc4695bSBarry Smith   ierr = MPI_Comm_rank(comm,&rank);CHKERRMPI(ierr);
132aee2cecaSBarry Smith   if (!rank) {
133aee2cecaSBarry Smith     c = (char) getchar();
134aee2cecaSBarry Smith     i = 0;
135aee2cecaSBarry Smith     while (c != '\n' && i < n-1) {
136aee2cecaSBarry Smith       str[i++] = c;
137aee2cecaSBarry Smith       c = (char)getchar();
138aee2cecaSBarry Smith     }
139aee2cecaSBarry Smith     str[i] = 0;
140aee2cecaSBarry Smith   }
1414dc2109aSBarry Smith   ierr = PetscMPIIntCast(n,&nm);CHKERRQ(ierr);
142ffc4695bSBarry Smith   ierr = MPI_Bcast(str,nm,MPI_CHAR,0,comm);CHKERRMPI(ierr);
143aee2cecaSBarry Smith   PetscFunctionReturn(0);
144aee2cecaSBarry Smith }
145aee2cecaSBarry Smith 
1465b02f95dSBarry Smith /*
1475b02f95dSBarry Smith     This is needed because certain strings may be freed by SAWs, hence we cannot use PetscStrallocpy()
1485b02f95dSBarry Smith */
1495b02f95dSBarry Smith static PetscErrorCode  PetscStrdup(const char s[],char *t[])
1505b02f95dSBarry Smith {
1515b02f95dSBarry Smith   PetscErrorCode ierr;
1525b02f95dSBarry Smith   size_t         len;
15302c9f0b5SLisandro Dalcin   char           *tmp = NULL;
1545b02f95dSBarry Smith 
1555b02f95dSBarry Smith   PetscFunctionBegin;
1565b02f95dSBarry Smith   if (s) {
1575b02f95dSBarry Smith     ierr = PetscStrlen(s,&len);CHKERRQ(ierr);
158f416af30SBarry Smith     tmp = (char*) malloc((len+1)*sizeof(char));
1595b02f95dSBarry Smith     if (!tmp) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_MEM,"No memory to duplicate string");
1605b02f95dSBarry Smith     ierr = PetscStrcpy(tmp,s);CHKERRQ(ierr);
1615b02f95dSBarry Smith   }
1625b02f95dSBarry Smith   *t = tmp;
1635b02f95dSBarry Smith   PetscFunctionReturn(0);
1645b02f95dSBarry Smith }
1655b02f95dSBarry Smith 
166aee2cecaSBarry Smith /*
1673cc1e11dSBarry Smith     PetscOptionsGetFromTextInput - Presents all the PETSc Options processed by the program so the user may change them at runtime
168aee2cecaSBarry Smith 
16995452b02SPatrick Sanan     Notes:
17095452b02SPatrick Sanan     this isn't really practical, it is just to demonstrate the principle
171aee2cecaSBarry Smith 
1727781c08eSBarry Smith     A carriage return indicates no change from the default; but this like -ksp_monitor <stdout>  the default is actually not stdout the default
1737781c08eSBarry Smith     is to do nothing so to get it to use stdout you need to type stdout. This is kind of bug?
1747781c08eSBarry Smith 
175aee2cecaSBarry Smith     Bugs:
1767781c08eSBarry Smith +    All processes must traverse through the exact same set of option queries due to the call to PetscScanString()
1773cc1e11dSBarry Smith .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
178aee2cecaSBarry Smith -    Only works for PetscInt == int, PetscReal == double etc
179aee2cecaSBarry Smith 
18095452b02SPatrick Sanan     Developer Notes:
18195452b02SPatrick Sanan     Normally the GUI that presents the options the user and retrieves the values would be running in a different
1823cc1e11dSBarry Smith      address space and communicating with the PETSc program
1833cc1e11dSBarry Smith 
184aee2cecaSBarry Smith */
1854416b707SBarry Smith PetscErrorCode PetscOptionsGetFromTextInput(PetscOptionItems *PetscOptionsObject)
1866356e834SBarry Smith {
1876356e834SBarry Smith   PetscErrorCode  ierr;
1884416b707SBarry Smith   PetscOptionItem next = PetscOptionsObject->next;
1896356e834SBarry Smith   char            str[512];
1907781c08eSBarry Smith   PetscBool       bid;
191a4404d99SBarry Smith   PetscReal       ir,*valr;
192330cf3c9SBarry Smith   PetscInt        *vald;
193330cf3c9SBarry Smith   size_t          i;
1946356e834SBarry Smith 
1952a409bb0SBarry Smith   PetscFunctionBegin;
196c0bb3764SVaclav Hapla   ierr = (*PetscPrintf)(PETSC_COMM_WORLD,"%s --------------------\n",PetscOptionsObject->title);CHKERRQ(ierr);
1976356e834SBarry Smith   while (next) {
1986356e834SBarry Smith     switch (next->type) {
1996356e834SBarry Smith     case OPTION_HEAD:
2006356e834SBarry Smith       break;
201e26ddf31SBarry Smith     case OPTION_INT_ARRAY:
202e55864a3SBarry Smith       ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1);CHKERRQ(ierr);
203e26ddf31SBarry Smith       vald = (PetscInt*) next->data;
204e26ddf31SBarry Smith       for (i=0; i<next->arraylength; i++) {
205e26ddf31SBarry Smith         ierr = PetscPrintf(PETSC_COMM_WORLD,"%d",vald[i]);CHKERRQ(ierr);
206e26ddf31SBarry Smith         if (i < next->arraylength-1) {
207e26ddf31SBarry Smith           ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr);
208e26ddf31SBarry Smith         }
209e26ddf31SBarry Smith       }
210e26ddf31SBarry Smith       ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s) ",next->text,next->man);CHKERRQ(ierr);
211e26ddf31SBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
212e26ddf31SBarry Smith       if (str[0]) {
213e26ddf31SBarry Smith         PetscToken token;
214e26ddf31SBarry Smith         PetscInt   n=0,nmax = next->arraylength,*dvalue = (PetscInt*)next->data,start,end;
215e26ddf31SBarry Smith         size_t     len;
216e26ddf31SBarry Smith         char       *value;
217ace3abfcSBarry Smith         PetscBool  foundrange;
218e26ddf31SBarry Smith 
219e26ddf31SBarry Smith         next->set = PETSC_TRUE;
220e26ddf31SBarry Smith         value     = str;
221e26ddf31SBarry Smith         ierr      = PetscTokenCreate(value,',',&token);CHKERRQ(ierr);
222e26ddf31SBarry Smith         ierr      = PetscTokenFind(token,&value);CHKERRQ(ierr);
223e26ddf31SBarry Smith         while (n < nmax) {
224e26ddf31SBarry Smith           if (!value) break;
225e26ddf31SBarry Smith 
226e26ddf31SBarry Smith           /* look for form  d-D where d and D are integers */
227e26ddf31SBarry Smith           foundrange = PETSC_FALSE;
228e26ddf31SBarry Smith           ierr       = PetscStrlen(value,&len);CHKERRQ(ierr);
229e26ddf31SBarry Smith           if (value[0] == '-') i=2;
230e26ddf31SBarry Smith           else i=1;
231330cf3c9SBarry Smith           for (;i<len; i++) {
232e26ddf31SBarry Smith             if (value[i] == '-') {
233e32f2f54SBarry Smith               if (i == len-1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry %s\n",n,value);
234e26ddf31SBarry Smith               value[i] = 0;
235cfbddea1SSatish Balay               ierr     = PetscOptionsStringToInt(value,&start);CHKERRQ(ierr);
236cfbddea1SSatish Balay               ierr     = PetscOptionsStringToInt(value+i+1,&end);CHKERRQ(ierr);
237e32f2f54SBarry 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);
238e32f2f54SBarry 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);
239e26ddf31SBarry Smith               for (; start<end; start++) {
240e26ddf31SBarry Smith                 *dvalue = start; dvalue++;n++;
241e26ddf31SBarry Smith               }
242e26ddf31SBarry Smith               foundrange = PETSC_TRUE;
243e26ddf31SBarry Smith               break;
244e26ddf31SBarry Smith             }
245e26ddf31SBarry Smith           }
246e26ddf31SBarry Smith           if (!foundrange) {
247cfbddea1SSatish Balay             ierr = PetscOptionsStringToInt(value,dvalue);CHKERRQ(ierr);
248e26ddf31SBarry Smith             dvalue++;
249e26ddf31SBarry Smith             n++;
250e26ddf31SBarry Smith           }
251e26ddf31SBarry Smith           ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
252e26ddf31SBarry Smith         }
2538c74ee41SBarry Smith         ierr = PetscTokenDestroy(&token);CHKERRQ(ierr);
254e26ddf31SBarry Smith       }
255e26ddf31SBarry Smith       break;
256e26ddf31SBarry Smith     case OPTION_REAL_ARRAY:
257e55864a3SBarry Smith       ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1);CHKERRQ(ierr);
258e26ddf31SBarry Smith       valr = (PetscReal*) next->data;
259e26ddf31SBarry Smith       for (i=0; i<next->arraylength; i++) {
260e26ddf31SBarry Smith         ierr = PetscPrintf(PETSC_COMM_WORLD,"%g",valr[i]);CHKERRQ(ierr);
261e26ddf31SBarry Smith         if (i < next->arraylength-1) {
262e26ddf31SBarry Smith           ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr);
263e26ddf31SBarry Smith         }
264e26ddf31SBarry Smith       }
265e26ddf31SBarry Smith       ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s) ",next->text,next->man);CHKERRQ(ierr);
266e26ddf31SBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
267e26ddf31SBarry Smith       if (str[0]) {
268e26ddf31SBarry Smith         PetscToken token;
269e26ddf31SBarry Smith         PetscInt   n = 0,nmax = next->arraylength;
270e26ddf31SBarry Smith         PetscReal  *dvalue = (PetscReal*)next->data;
271e26ddf31SBarry Smith         char       *value;
272e26ddf31SBarry Smith 
273e26ddf31SBarry Smith         next->set = PETSC_TRUE;
274e26ddf31SBarry Smith         value     = str;
275e26ddf31SBarry Smith         ierr      = PetscTokenCreate(value,',',&token);CHKERRQ(ierr);
276e26ddf31SBarry Smith         ierr      = PetscTokenFind(token,&value);CHKERRQ(ierr);
277e26ddf31SBarry Smith         while (n < nmax) {
278e26ddf31SBarry Smith           if (!value) break;
279cfbddea1SSatish Balay           ierr = PetscOptionsStringToReal(value,dvalue);CHKERRQ(ierr);
280e26ddf31SBarry Smith           dvalue++;
281e26ddf31SBarry Smith           n++;
282e26ddf31SBarry Smith           ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
283e26ddf31SBarry Smith         }
2848c74ee41SBarry Smith         ierr = PetscTokenDestroy(&token);CHKERRQ(ierr);
285e26ddf31SBarry Smith       }
286e26ddf31SBarry Smith       break;
2876356e834SBarry Smith     case OPTION_INT:
288e55864a3SBarry 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);
2893fc1eb6aSBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
2903fc1eb6aSBarry Smith       if (str[0]) {
291d25d7f95SJed Brown #if defined(PETSC_SIZEOF_LONG_LONG)
292d25d7f95SJed Brown         long long lid;
293d25d7f95SJed Brown         sscanf(str,"%lld",&lid);
2941a1499c8SBarry 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);
295c272547aSJed Brown #else
296d25d7f95SJed Brown         long  lid;
297d25d7f95SJed Brown         sscanf(str,"%ld",&lid);
2981a1499c8SBarry 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);
299c272547aSJed Brown #endif
300a297a907SKarl Rupp 
301d25d7f95SJed Brown         next->set = PETSC_TRUE;
302d25d7f95SJed Brown         *((PetscInt*)next->data) = (PetscInt)lid;
303aee2cecaSBarry Smith       }
304aee2cecaSBarry Smith       break;
305aee2cecaSBarry Smith     case OPTION_REAL:
306e55864a3SBarry 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);
3073fc1eb6aSBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
3083fc1eb6aSBarry Smith       if (str[0]) {
309ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE)
310a4404d99SBarry Smith         sscanf(str,"%e",&ir);
311570b7f6dSBarry Smith #elif defined(PETSC_USE_REAL___FP16)
312570b7f6dSBarry Smith         float irtemp;
313570b7f6dSBarry Smith         sscanf(str,"%e",&irtemp);
314570b7f6dSBarry Smith         ir = irtemp;
315ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE)
316aee2cecaSBarry Smith         sscanf(str,"%le",&ir);
317ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128)
318d9822059SBarry Smith         ir = strtoflt128(str,0);
319d9822059SBarry Smith #else
320513dbe71SLisandro Dalcin         SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Unknown scalar type");
321a4404d99SBarry Smith #endif
322aee2cecaSBarry Smith         next->set                 = PETSC_TRUE;
323aee2cecaSBarry Smith         *((PetscReal*)next->data) = ir;
324aee2cecaSBarry Smith       }
325aee2cecaSBarry Smith       break;
3267781c08eSBarry Smith     case OPTION_BOOL:
32783355fc5SBarry 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);
3287781c08eSBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
3297781c08eSBarry Smith       if (str[0]) {
3307781c08eSBarry Smith         ierr = PetscOptionsStringToBool(str,&bid);CHKERRQ(ierr);
3317781c08eSBarry Smith         next->set = PETSC_TRUE;
3327781c08eSBarry Smith         *((PetscBool*)next->data) = bid;
3337781c08eSBarry Smith       }
3347781c08eSBarry Smith       break;
335aee2cecaSBarry Smith     case OPTION_STRING:
336e55864a3SBarry 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);
3373fc1eb6aSBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
3383fc1eb6aSBarry Smith       if (str[0]) {
339aee2cecaSBarry Smith         next->set = PETSC_TRUE;
34064facd6cSBarry Smith         /* must use system malloc since SAWs may free this */
3415b02f95dSBarry Smith         ierr = PetscStrdup(str,(char**)&next->data);CHKERRQ(ierr);
3426356e834SBarry Smith       }
3436356e834SBarry Smith       break;
344a264d7a6SBarry Smith     case OPTION_FLIST:
34544ef3d73SBarry 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);
3463cc1e11dSBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
3473cc1e11dSBarry Smith       if (str[0]) {
348e55864a3SBarry Smith         PetscOptionsObject->changedmethod = PETSC_TRUE;
3493cc1e11dSBarry Smith         next->set = PETSC_TRUE;
35064facd6cSBarry Smith         /* must use system malloc since SAWs may free this */
3515b02f95dSBarry Smith         ierr = PetscStrdup(str,(char**)&next->data);CHKERRQ(ierr);
3523cc1e11dSBarry Smith       }
3533cc1e11dSBarry Smith       break;
354b432afdaSMatthew Knepley     default:
355b432afdaSMatthew Knepley       break;
3566356e834SBarry Smith     }
3576356e834SBarry Smith     next = next->next;
3586356e834SBarry Smith   }
3596356e834SBarry Smith   PetscFunctionReturn(0);
3606356e834SBarry Smith }
3616356e834SBarry Smith 
362e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
363e04113cfSBarry Smith #include <petscviewersaws.h>
364d5649816SBarry Smith 
365d5649816SBarry Smith static int count = 0;
366d5649816SBarry Smith 
367e04113cfSBarry Smith PetscErrorCode PetscOptionsSAWsDestroy(void)
368d5649816SBarry Smith {
3692657e9d9SBarry Smith   PetscFunctionBegin;
370d5649816SBarry Smith   PetscFunctionReturn(0);
371d5649816SBarry Smith }
372d5649816SBarry Smith 
3739c1e0ce8SBarry Smith static const char *OptionsHeader = "<head>\n"
374a8d69d7bSBarry Smith                                    "<script type=\"text/javascript\" src=\"https://www.mcs.anl.gov/research/projects/saws/js/jquery-1.9.1.js\"></script>\n"
375a8d69d7bSBarry Smith                                    "<script type=\"text/javascript\" src=\"https://www.mcs.anl.gov/research/projects/saws/js/SAWs.js\"></script>\n"
376d1fc0251SBarry Smith                                    "<script type=\"text/javascript\" src=\"js/PETSc.js\"></script>\n"
37764bbc9efSBarry Smith                                    "<script>\n"
37864bbc9efSBarry Smith                                       "jQuery(document).ready(function() {\n"
37964bbc9efSBarry Smith                                          "PETSc.getAndDisplayDirectory(null,\"#variablesInfo\")\n"
38064bbc9efSBarry Smith                                       "})\n"
38164bbc9efSBarry Smith                                   "</script>\n"
38264bbc9efSBarry Smith                                   "</head>\n";
3831423471aSBarry Smith 
3841423471aSBarry Smith /*  Determines the size and style of the scroll region where PETSc options selectable from users are displayed */
3851423471aSBarry Smith static const char *OptionsBodyBottom = "<div id=\"variablesInfo\" style=\"background-color:lightblue;height:auto;max-height:500px;overflow:scroll;\"></div>\n<br>\n</body>";
38664bbc9efSBarry Smith 
387b3506946SBarry Smith /*
3887781c08eSBarry Smith     PetscOptionsSAWsInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the SAWs
389b3506946SBarry Smith 
390b3506946SBarry Smith     Bugs:
391b3506946SBarry Smith +    All processes must traverse through the exact same set of option queries do to the call to PetscScanString()
392b3506946SBarry Smith .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
393b3506946SBarry Smith -    Only works for PetscInt == int, PetscReal == double etc
394b3506946SBarry Smith 
395b3506946SBarry Smith */
3964416b707SBarry Smith PetscErrorCode PetscOptionsSAWsInput(PetscOptionItems *PetscOptionsObject)
397b3506946SBarry Smith {
398b3506946SBarry Smith   PetscErrorCode  ierr;
3994416b707SBarry Smith   PetscOptionItem next     = PetscOptionsObject->next;
400d5649816SBarry Smith   static int      mancount = 0;
401b3506946SBarry Smith   char            options[16];
4027aab2a10SBarry Smith   PetscBool       changedmethod = PETSC_FALSE;
403a23eb982SSurtai Han   PetscBool       stopasking    = PETSC_FALSE;
40488a9752cSBarry Smith   char            manname[16],textname[16];
4052657e9d9SBarry Smith   char            dir[1024];
406b3506946SBarry Smith 
4072a409bb0SBarry Smith   PetscFunctionBegin;
408b3506946SBarry Smith   /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */
409b3506946SBarry Smith   sprintf(options,"Options_%d",count++);
410a297a907SKarl Rupp 
4117325c4a4SBarry Smith   PetscOptionsObject->pprefix = PetscOptionsObject->prefix; /* SAWs will change this, so cannot pass prefix directly */
4121bc75a8dSBarry Smith 
413d50831c4SBarry Smith   ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s","_title");CHKERRQ(ierr);
41483355fc5SBarry Smith   PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject->title,1,SAWs_READ,SAWs_STRING));
4157781c08eSBarry Smith   ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s","prefix");CHKERRQ(ierr);
41683355fc5SBarry Smith   PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject->pprefix,1,SAWs_READ,SAWs_STRING));
4172657e9d9SBarry Smith   PetscStackCallSAWs(SAWs_Register,("/PETSc/Options/ChangedMethod",&changedmethod,1,SAWs_WRITE,SAWs_BOOLEAN));
418a23eb982SSurtai Han   PetscStackCallSAWs(SAWs_Register,("/PETSc/Options/StopAsking",&stopasking,1,SAWs_WRITE,SAWs_BOOLEAN));
419b3506946SBarry Smith 
420b3506946SBarry Smith   while (next) {
421d50831c4SBarry Smith     sprintf(manname,"_man_%d",mancount);
4222657e9d9SBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",manname);CHKERRQ(ierr);
4237781c08eSBarry Smith     PetscStackCallSAWs(SAWs_Register,(dir,&next->man,1,SAWs_READ,SAWs_STRING));
424d50831c4SBarry Smith     sprintf(textname,"_text_%d",mancount++);
4257781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",textname);CHKERRQ(ierr);
4267781c08eSBarry Smith     PetscStackCallSAWs(SAWs_Register,(dir,&next->text,1,SAWs_READ,SAWs_STRING));
4279f32e415SBarry Smith 
428b3506946SBarry Smith     switch (next->type) {
429b3506946SBarry Smith     case OPTION_HEAD:
430b3506946SBarry Smith       break;
431b3506946SBarry Smith     case OPTION_INT_ARRAY:
4327781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4332657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_INT));
434b3506946SBarry Smith       break;
435b3506946SBarry Smith     case OPTION_REAL_ARRAY:
4367781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4372657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_DOUBLE));
438b3506946SBarry Smith       break;
439b3506946SBarry Smith     case OPTION_INT:
4407781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4412657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_INT));
442b3506946SBarry Smith       break;
443b3506946SBarry Smith     case OPTION_REAL:
4447781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4452657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_DOUBLE));
446b3506946SBarry Smith       break;
4477781c08eSBarry Smith     case OPTION_BOOL:
4487781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4492657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_BOOLEAN));
4501ae3d29cSBarry Smith       break;
4517781c08eSBarry Smith     case OPTION_BOOL_ARRAY:
4527781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4532657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_BOOLEAN));
45471f08665SBarry Smith       break;
455b3506946SBarry Smith     case OPTION_STRING:
4567781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4577781c08eSBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING));
4581ae3d29cSBarry Smith       break;
4591ae3d29cSBarry Smith     case OPTION_STRING_ARRAY:
4607781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4612657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_STRING));
462b3506946SBarry Smith       break;
463a264d7a6SBarry Smith     case OPTION_FLIST:
464a264d7a6SBarry Smith       {
465a264d7a6SBarry Smith       PetscInt ntext;
4667781c08eSBarry Smith       ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4677781c08eSBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING));
468a264d7a6SBarry Smith       ierr = PetscFunctionListGet(next->flist,(const char***)&next->edata,&ntext);CHKERRQ(ierr);
469a264d7a6SBarry Smith       PetscStackCallSAWs(SAWs_Set_Legal_Variable_Values,(dir,ntext,next->edata));
470a264d7a6SBarry Smith       }
471a264d7a6SBarry Smith       break;
4721ae3d29cSBarry Smith     case OPTION_ELIST:
473a264d7a6SBarry Smith       {
474a264d7a6SBarry Smith       PetscInt ntext = next->nlist;
4757781c08eSBarry Smith       ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4767781c08eSBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING));
477ead66b60SBarry Smith       ierr = PetscMalloc1((ntext+1),(char***)&next->edata);CHKERRQ(ierr);
4781ae3d29cSBarry Smith       ierr = PetscMemcpy(next->edata,next->list,ntext*sizeof(char*));CHKERRQ(ierr);
479a264d7a6SBarry Smith       PetscStackCallSAWs(SAWs_Set_Legal_Variable_Values,(dir,ntext,next->edata));
480a264d7a6SBarry Smith       }
481a264d7a6SBarry Smith       break;
482b3506946SBarry Smith     default:
483b3506946SBarry Smith       break;
484b3506946SBarry Smith     }
485b3506946SBarry Smith     next = next->next;
486b3506946SBarry Smith   }
487b3506946SBarry Smith 
488b3506946SBarry Smith   /* wait until accessor has unlocked the memory */
48964bbc9efSBarry Smith   PetscStackCallSAWs(SAWs_Push_Header,("index.html",OptionsHeader));
49064bbc9efSBarry Smith   PetscStackCallSAWs(SAWs_Push_Body,("index.html",2,OptionsBodyBottom));
4917aab2a10SBarry Smith   ierr = PetscSAWsBlock();CHKERRQ(ierr);
49264bbc9efSBarry Smith   PetscStackCallSAWs(SAWs_Pop_Header,("index.html"));
49364bbc9efSBarry Smith   PetscStackCallSAWs(SAWs_Pop_Body,("index.html",2));
494b3506946SBarry Smith 
49588a9752cSBarry Smith   /* determine if any values have been set in GUI */
49683355fc5SBarry Smith   next = PetscOptionsObject->next;
49788a9752cSBarry Smith   while (next) {
49888a9752cSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
499f7b25cf6SBarry Smith     PetscStackCallSAWs(SAWs_Selected,(dir,(int*)&next->set));
50088a9752cSBarry Smith     next = next->next;
50188a9752cSBarry Smith   }
50288a9752cSBarry Smith 
503b3506946SBarry Smith   /* reset counter to -2; this updates the screen with the new options for the selected method */
504f7b25cf6SBarry Smith   if (changedmethod) PetscOptionsObject->count = -2;
505b3506946SBarry Smith 
506a23eb982SSurtai Han   if (stopasking) {
507a23eb982SSurtai Han     PetscOptionsPublish      = PETSC_FALSE;
50812655325SBarry Smith     PetscOptionsObject->count = 0;//do not ask for same thing again
509a23eb982SSurtai Han   }
510a23eb982SSurtai Han 
5119a492a5cSBarry Smith   PetscStackCallSAWs(SAWs_Delete,("/PETSc/Options"));
512b3506946SBarry Smith   PetscFunctionReturn(0);
513b3506946SBarry Smith }
514b3506946SBarry Smith #endif
515b3506946SBarry Smith 
5164416b707SBarry Smith PetscErrorCode PetscOptionsEnd_Private(PetscOptionItems *PetscOptionsObject)
51753acd3b1SBarry Smith {
51853acd3b1SBarry Smith   PetscErrorCode  ierr;
5194416b707SBarry Smith   PetscOptionItem last;
5206356e834SBarry Smith   char            option[256],value[1024],tmp[32];
521330cf3c9SBarry Smith   size_t          j;
52253acd3b1SBarry Smith 
52353acd3b1SBarry Smith   PetscFunctionBegin;
52483355fc5SBarry Smith   if (PetscOptionsObject->next) {
52583355fc5SBarry Smith     if (!PetscOptionsObject->count) {
526a264d7a6SBarry Smith #if defined(PETSC_HAVE_SAWS)
527f7b25cf6SBarry Smith       ierr = PetscOptionsSAWsInput(PetscOptionsObject);CHKERRQ(ierr);
528b3506946SBarry Smith #else
529e55864a3SBarry Smith       ierr = PetscOptionsGetFromTextInput(PetscOptionsObject);CHKERRQ(ierr);
530b3506946SBarry Smith #endif
531aee2cecaSBarry Smith     }
532aee2cecaSBarry Smith   }
5336356e834SBarry Smith 
534e55864a3SBarry Smith   ierr = PetscFree(PetscOptionsObject->title);CHKERRQ(ierr);
5356356e834SBarry Smith 
536e26ddf31SBarry Smith   /* reset counter to -2; this updates the screen with the new options for the selected method */
537e55864a3SBarry Smith   if (PetscOptionsObject->changedmethod) PetscOptionsObject->count = -2;
5387a72a596SBarry Smith   /* reset alreadyprinted flag */
539e55864a3SBarry Smith   PetscOptionsObject->alreadyprinted = PETSC_FALSE;
540e55864a3SBarry Smith   if (PetscOptionsObject->object) PetscOptionsObject->object->optionsprinted = PETSC_TRUE;
541e55864a3SBarry Smith   PetscOptionsObject->object = NULL;
54253acd3b1SBarry Smith 
543e55864a3SBarry Smith   while (PetscOptionsObject->next) {
544e55864a3SBarry Smith     if (PetscOptionsObject->next->set) {
545e55864a3SBarry Smith       if (PetscOptionsObject->prefix) {
54653acd3b1SBarry Smith         ierr = PetscStrcpy(option,"-");CHKERRQ(ierr);
547e55864a3SBarry Smith         ierr = PetscStrcat(option,PetscOptionsObject->prefix);CHKERRQ(ierr);
548e55864a3SBarry Smith         ierr = PetscStrcat(option,PetscOptionsObject->next->option+1);CHKERRQ(ierr);
5496356e834SBarry Smith       } else {
550e55864a3SBarry Smith         ierr = PetscStrcpy(option,PetscOptionsObject->next->option);CHKERRQ(ierr);
5516356e834SBarry Smith       }
5526356e834SBarry Smith 
553e55864a3SBarry Smith       switch (PetscOptionsObject->next->type) {
5546356e834SBarry Smith       case OPTION_HEAD:
5556356e834SBarry Smith         break;
5566356e834SBarry Smith       case OPTION_INT_ARRAY:
557e55864a3SBarry Smith         sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject->next->data)[0]);
558e55864a3SBarry Smith         for (j=1; j<PetscOptionsObject->next->arraylength; j++) {
559e55864a3SBarry Smith           sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject->next->data)[j]);
5606356e834SBarry Smith           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
5616356e834SBarry Smith           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
5626356e834SBarry Smith         }
5636356e834SBarry Smith         break;
5646356e834SBarry Smith       case OPTION_INT:
565e55864a3SBarry Smith         sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject->next->data);
5666356e834SBarry Smith         break;
5676356e834SBarry Smith       case OPTION_REAL:
568e55864a3SBarry Smith         sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject->next->data);
5696356e834SBarry Smith         break;
5706356e834SBarry Smith       case OPTION_REAL_ARRAY:
571e55864a3SBarry Smith         sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject->next->data)[0]);
572e55864a3SBarry Smith         for (j=1; j<PetscOptionsObject->next->arraylength; j++) {
573e55864a3SBarry Smith           sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject->next->data)[j]);
5746356e834SBarry Smith           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
5756356e834SBarry Smith           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
5766356e834SBarry Smith         }
5776356e834SBarry Smith         break;
578050cccc3SHong Zhang       case OPTION_SCALAR_ARRAY:
57995f3a755SJose E. Roman         sprintf(value,"%g+%gi",(double)PetscRealPart(((PetscScalar*)PetscOptionsObject->next->data)[0]),(double)PetscImaginaryPart(((PetscScalar*)PetscOptionsObject->next->data)[0]));
580050cccc3SHong Zhang         for (j=1; j<PetscOptionsObject->next->arraylength; j++) {
58195f3a755SJose E. Roman           sprintf(tmp,"%g+%gi",(double)PetscRealPart(((PetscScalar*)PetscOptionsObject->next->data)[j]),(double)PetscImaginaryPart(((PetscScalar*)PetscOptionsObject->next->data)[j]));
582050cccc3SHong Zhang           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
583050cccc3SHong Zhang           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
584050cccc3SHong Zhang         }
585050cccc3SHong Zhang         break;
5867781c08eSBarry Smith       case OPTION_BOOL:
587e55864a3SBarry Smith         sprintf(value,"%d",*(int*)PetscOptionsObject->next->data);
5886356e834SBarry Smith         break;
5897781c08eSBarry Smith       case OPTION_BOOL_ARRAY:
590e55864a3SBarry Smith         sprintf(value,"%d",(int)((PetscBool*)PetscOptionsObject->next->data)[0]);
591e55864a3SBarry Smith         for (j=1; j<PetscOptionsObject->next->arraylength; j++) {
592e55864a3SBarry Smith           sprintf(tmp,"%d",(int)((PetscBool*)PetscOptionsObject->next->data)[j]);
5931ae3d29cSBarry Smith           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
5941ae3d29cSBarry Smith           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
5951ae3d29cSBarry Smith         }
5961ae3d29cSBarry Smith         break;
597a264d7a6SBarry Smith       case OPTION_FLIST:
5986991f827SBarry Smith         ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr);
5996991f827SBarry Smith         break;
6001ae3d29cSBarry Smith       case OPTION_ELIST:
601e55864a3SBarry Smith         ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr);
6026356e834SBarry Smith         break;
6031ae3d29cSBarry Smith       case OPTION_STRING:
604e55864a3SBarry Smith         ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr);
605d51da6bfSBarry Smith         break;
6061ae3d29cSBarry Smith       case OPTION_STRING_ARRAY:
607e55864a3SBarry Smith         sprintf(value,"%s",((char**)PetscOptionsObject->next->data)[0]);
608e55864a3SBarry Smith         for (j=1; j<PetscOptionsObject->next->arraylength; j++) {
609e55864a3SBarry Smith           sprintf(tmp,"%s",((char**)PetscOptionsObject->next->data)[j]);
6101ae3d29cSBarry Smith           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
6111ae3d29cSBarry Smith           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
6121ae3d29cSBarry Smith         }
6136356e834SBarry Smith         break;
6146356e834SBarry Smith       }
615c5929fdfSBarry Smith       ierr = PetscOptionsSetValue(PetscOptionsObject->options,option,value);CHKERRQ(ierr);
6166356e834SBarry Smith     }
6176991f827SBarry Smith     if (PetscOptionsObject->next->type == OPTION_ELIST) {
6186991f827SBarry Smith       ierr = PetscStrNArrayDestroy(PetscOptionsObject->next->nlist,(char ***)&PetscOptionsObject->next->list);CHKERRQ(ierr);
6196991f827SBarry Smith     }
620e55864a3SBarry Smith     ierr   = PetscFree(PetscOptionsObject->next->text);CHKERRQ(ierr);
621e55864a3SBarry Smith     ierr   = PetscFree(PetscOptionsObject->next->option);CHKERRQ(ierr);
622e55864a3SBarry Smith     ierr   = PetscFree(PetscOptionsObject->next->man);CHKERRQ(ierr);
623e55864a3SBarry Smith     ierr   = PetscFree(PetscOptionsObject->next->edata);CHKERRQ(ierr);
624c979a496SBarry Smith 
62583355fc5SBarry Smith     if ((PetscOptionsObject->next->type == OPTION_STRING) || (PetscOptionsObject->next->type == OPTION_FLIST) || (PetscOptionsObject->next->type == OPTION_ELIST)) {
62683355fc5SBarry Smith       free(PetscOptionsObject->next->data);
627c979a496SBarry Smith     } else {
62883355fc5SBarry Smith       ierr   = PetscFree(PetscOptionsObject->next->data);CHKERRQ(ierr);
629c979a496SBarry Smith     }
6307781c08eSBarry Smith 
63183355fc5SBarry Smith     last                    = PetscOptionsObject->next;
63283355fc5SBarry Smith     PetscOptionsObject->next = PetscOptionsObject->next->next;
6336356e834SBarry Smith     ierr                    = PetscFree(last);CHKERRQ(ierr);
6346356e834SBarry Smith   }
635f59f755dSBarry Smith   ierr = PetscFree(PetscOptionsObject->prefix);CHKERRQ(ierr);
63602c9f0b5SLisandro Dalcin   PetscOptionsObject->next = NULL;
63753acd3b1SBarry Smith   PetscFunctionReturn(0);
63853acd3b1SBarry Smith }
63953acd3b1SBarry Smith 
64088aa4217SBarry Smith /*MC
64153acd3b1SBarry Smith    PetscOptionsEnum - Gets the enum value for a particular option in the database.
64253acd3b1SBarry Smith 
6433f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
64453acd3b1SBarry Smith 
64588aa4217SBarry Smith    Synopsis:
64688aa4217SBarry Smith    #include "petscsys.h"
6473a89f35bSSatish Balay    PetscErrorCode  PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum currentvalue,PetscEnum *value,PetscBool  *set)
64888aa4217SBarry Smith 
64953acd3b1SBarry Smith    Input Parameters:
65053acd3b1SBarry Smith +  opt - option name
65153acd3b1SBarry Smith .  text - short string that describes the option
65253acd3b1SBarry Smith .  man - manual page with additional information on option
65353acd3b1SBarry Smith .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
6540fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
6550fdccdaeSBarry Smith $                 PetscOptionsEnum(..., obj->value,&object->value,...) or
6560fdccdaeSBarry Smith $                 value = defaultvalue
6570fdccdaeSBarry Smith $                 PetscOptionsEnum(..., value,&value,&flg);
6580fdccdaeSBarry Smith $                 if (flg) {
65953acd3b1SBarry Smith 
660*d8d19677SJose E. Roman    Output Parameters:
66153acd3b1SBarry Smith +  value - the  value to return
662b32e0204SMatthew G Knepley -  set - PETSC_TRUE if found, else PETSC_FALSE
66353acd3b1SBarry Smith 
66453acd3b1SBarry Smith    Level: beginner
66553acd3b1SBarry Smith 
66695452b02SPatrick Sanan    Notes:
66795452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
66853acd3b1SBarry Smith 
66953acd3b1SBarry Smith           list is usually something like PCASMTypes or some other predefined list of enum names
67053acd3b1SBarry Smith 
6712efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
6722efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
6732efd9cb1SBarry Smith 
674989712b9SBarry Smith           The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
675989712b9SBarry Smith 
67653acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
677536f90c4SPierre Jolivet           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(),
678acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
67953acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
68053acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
681acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
682a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
68388aa4217SBarry Smith M*/
68488aa4217SBarry Smith 
6854416b707SBarry 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)
68653acd3b1SBarry Smith {
68753acd3b1SBarry Smith   PetscErrorCode ierr;
68853acd3b1SBarry Smith   PetscInt       ntext = 0;
689aa5bb8c0SSatish Balay   PetscInt       tval;
690ace3abfcSBarry Smith   PetscBool      tflg;
69153acd3b1SBarry Smith 
69253acd3b1SBarry Smith   PetscFunctionBegin;
69353acd3b1SBarry Smith   while (list[ntext++]) {
694e32f2f54SBarry Smith     if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries");
69553acd3b1SBarry Smith   }
696e32f2f54SBarry Smith   if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix");
69753acd3b1SBarry Smith   ntext -= 3;
698e55864a3SBarry Smith   ierr   = PetscOptionsEList_Private(PetscOptionsObject,opt,text,man,list,ntext,list[currentvalue],&tval,&tflg);CHKERRQ(ierr);
699aa5bb8c0SSatish Balay   /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */
700aa5bb8c0SSatish Balay   if (tflg) *value = (PetscEnum)tval;
701aa5bb8c0SSatish Balay   if (set)  *set   = tflg;
70253acd3b1SBarry Smith   PetscFunctionReturn(0);
70353acd3b1SBarry Smith }
70453acd3b1SBarry Smith 
70588aa4217SBarry Smith /*MC
706d3e47460SLisandro Dalcin    PetscOptionsEnumArray - Gets an array of enum values for a particular
707d3e47460SLisandro Dalcin    option in the database.
708d3e47460SLisandro Dalcin 
709d3e47460SLisandro Dalcin    Logically Collective on the communicator passed in PetscOptionsBegin()
710d3e47460SLisandro Dalcin 
71188aa4217SBarry Smith    Synopsis:
71288aa4217SBarry Smith    #include "petscsys.h"
7133a89f35bSSatish Balay    PetscErrorCode  PetscOptionsEnumArray(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum value[],PetscInt *n,PetscBool  *set)
71488aa4217SBarry Smith 
715d3e47460SLisandro Dalcin    Input Parameters:
716d3e47460SLisandro Dalcin +  opt - the option one is seeking
717d3e47460SLisandro Dalcin .  text - short string describing option
718d3e47460SLisandro Dalcin .  man - manual page for option
71922d58ec6SMatthew G. Knepley .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
720d3e47460SLisandro Dalcin -  n - maximum number of values
721d3e47460SLisandro Dalcin 
722*d8d19677SJose E. Roman    Output Parameters:
723d3e47460SLisandro Dalcin +  value - location to copy values
724d3e47460SLisandro Dalcin .  n - actual number of values found
725d3e47460SLisandro Dalcin -  set - PETSC_TRUE if found, else PETSC_FALSE
726d3e47460SLisandro Dalcin 
727d3e47460SLisandro Dalcin    Level: beginner
728d3e47460SLisandro Dalcin 
729d3e47460SLisandro Dalcin    Notes:
730d3e47460SLisandro Dalcin    The array must be passed as a comma separated list.
731d3e47460SLisandro Dalcin 
732d3e47460SLisandro Dalcin    There must be no intervening spaces between the values.
733d3e47460SLisandro Dalcin 
734d3e47460SLisandro Dalcin    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
735d3e47460SLisandro Dalcin 
736d3e47460SLisandro Dalcin .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
737536f90c4SPierre Jolivet           PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(),
738d3e47460SLisandro Dalcin           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
739d3e47460SLisandro Dalcin           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
740d3e47460SLisandro Dalcin           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
741d3e47460SLisandro Dalcin           PetscOptionsFList(), PetscOptionsEList(), PetscOptionsRealArray()
74288aa4217SBarry Smith M*/
74388aa4217SBarry Smith 
7444416b707SBarry 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)
745d3e47460SLisandro Dalcin {
746d3e47460SLisandro Dalcin   PetscInt        i,nlist = 0;
7474416b707SBarry Smith   PetscOptionItem amsopt;
748d3e47460SLisandro Dalcin   PetscErrorCode  ierr;
749d3e47460SLisandro Dalcin 
750d3e47460SLisandro Dalcin   PetscFunctionBegin;
751d3e47460SLisandro 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");
752d3e47460SLisandro Dalcin   if (nlist < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix");
753d3e47460SLisandro Dalcin   nlist -= 3; /* drop enum name, prefix, and null termination */
754d3e47460SLisandro Dalcin   if (0 && !PetscOptionsObject->count) { /* XXX Requires additional support */
755d3e47460SLisandro Dalcin     PetscEnum *vals;
7564416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT_ARRAY/*XXX OPTION_ENUM_ARRAY*/,&amsopt);CHKERRQ(ierr);
757d3e47460SLisandro Dalcin     ierr = PetscStrNArrayallocpy(nlist,list,(char***)&amsopt->list);CHKERRQ(ierr);
758d3e47460SLisandro Dalcin     amsopt->nlist = nlist;
759d3e47460SLisandro Dalcin     ierr = PetscMalloc1(*n,(PetscEnum**)&amsopt->data);CHKERRQ(ierr);
760d3e47460SLisandro Dalcin     amsopt->arraylength = *n;
761d3e47460SLisandro Dalcin     vals = (PetscEnum*)amsopt->data;
762d3e47460SLisandro Dalcin     for (i=0; i<*n; i++) vals[i] = value[i];
763d3e47460SLisandro Dalcin   }
764c5929fdfSBarry Smith   ierr = PetscOptionsGetEnumArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,list,value,n,set);CHKERRQ(ierr);
765d3e47460SLisandro Dalcin   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
766d3e47460SLisandro Dalcin     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%s",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,list[value[0]]);CHKERRQ(ierr);
767d3e47460SLisandro Dalcin     for (i=1; i<*n; i++) {ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%s",list[value[i]]);CHKERRQ(ierr);}
768d3e47460SLisandro Dalcin     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (choose from)",text);CHKERRQ(ierr);
769d3e47460SLisandro Dalcin     for (i=0; i<nlist; i++) {ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s",list[i]);CHKERRQ(ierr);}
770d3e47460SLisandro Dalcin     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," (%s)\n",ManSection(man));CHKERRQ(ierr);
771d3e47460SLisandro Dalcin   }
772d3e47460SLisandro Dalcin   PetscFunctionReturn(0);
773d3e47460SLisandro Dalcin }
774d3e47460SLisandro Dalcin 
77588aa4217SBarry Smith /*MC
7765a856986SBarry Smith    PetscOptionsBoundedInt - Gets an integer value greater than or equal a given bound for a particular option in the database.
7775a856986SBarry Smith 
7785a856986SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
7795a856986SBarry Smith 
78088aa4217SBarry Smith    Synopsis:
78188aa4217SBarry Smith    #include "petscsys.h"
7823a89f35bSSatish Balay    PetscErrorCode  PetscOptionsBoundInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt bound)
78388aa4217SBarry Smith 
7845a856986SBarry Smith    Input Parameters:
7855a856986SBarry Smith +  opt - option name
7865a856986SBarry Smith .  text - short string that describes the option
7875a856986SBarry Smith .  man - manual page with additional information on option
7885a856986SBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
78988aa4217SBarry Smith $                 PetscOptionsInt(..., obj->value,&obj->value,...) or
7905a856986SBarry Smith $                 value = defaultvalue
7915a856986SBarry Smith $                 PetscOptionsInt(..., value,&value,&flg);
7925a856986SBarry Smith $                 if (flg) {
79388aa4217SBarry Smith -  bound - the requested value should be greater than or equal this bound or an error is generated
7945a856986SBarry Smith 
795*d8d19677SJose E. Roman    Output Parameters:
7965a856986SBarry Smith +  value - the integer value to return
7975a856986SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
7985a856986SBarry Smith 
7995a856986SBarry Smith    Notes:
8005a856986SBarry Smith     If the user does not supply the option at all value is NOT changed. Thus
8015a856986SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
8025a856986SBarry Smith 
8035a856986SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
8045a856986SBarry Smith 
8055a856986SBarry Smith     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
8065a856986SBarry Smith 
8075a856986SBarry Smith    Level: beginner
8085a856986SBarry Smith 
8095a856986SBarry Smith .seealso: PetscOptionsInt(), PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
810536f90c4SPierre Jolivet           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), PetscOptionsRangeInt()
8115a856986SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
8125a856986SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
8135a856986SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
8145a856986SBarry Smith           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
8155a856986SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
81688aa4217SBarry Smith M*/
8175a856986SBarry Smith 
81888aa4217SBarry Smith /*MC
8195a856986SBarry Smith    PetscOptionsRangeInt - Gets an integer value within a range of values for a particular option in the database.
8205a856986SBarry Smith 
8215a856986SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
8225a856986SBarry Smith 
82388aa4217SBarry Smith    Synopsis:
82488aa4217SBarry Smith    #include "petscsys.h"
8253a89f35bSSatish Balay PetscErrorCode  PetscOptionsRangeInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt lb,PetscInt ub)
82688aa4217SBarry Smith 
8275a856986SBarry Smith    Input Parameters:
8285a856986SBarry Smith +  opt - option name
8295a856986SBarry Smith .  text - short string that describes the option
8305a856986SBarry Smith .  man - manual page with additional information on option
8315a856986SBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
83288aa4217SBarry Smith $                 PetscOptionsInt(..., obj->value,&obj->value,...) or
8335a856986SBarry Smith $                 value = defaultvalue
8345a856986SBarry Smith $                 PetscOptionsInt(..., value,&value,&flg);
8355a856986SBarry Smith $                 if (flg) {
83688aa4217SBarry Smith .  lb - the lower bound, provided value must be greater than or equal to this value or an error is generated
83788aa4217SBarry Smith -  ub - the upper bound, provided value must be less than or equal to this value or an error is generated
8385a856986SBarry Smith 
839*d8d19677SJose E. Roman    Output Parameters:
8405a856986SBarry Smith +  value - the integer value to return
8415a856986SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
8425a856986SBarry Smith 
8435a856986SBarry Smith    Notes:
8445a856986SBarry Smith     If the user does not supply the option at all value is NOT changed. Thus
8455a856986SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
8465a856986SBarry Smith 
8475a856986SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
8485a856986SBarry Smith 
8495a856986SBarry Smith     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
8505a856986SBarry Smith 
8515a856986SBarry Smith    Level: beginner
8525a856986SBarry Smith 
8535a856986SBarry Smith .seealso: PetscOptionsInt(), PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
854536f90c4SPierre Jolivet           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), PetscOptionsBoundedInt()
8555a856986SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
8565a856986SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
8575a856986SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
8585a856986SBarry Smith           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
8595a856986SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
86088aa4217SBarry Smith M*/
8615a856986SBarry Smith 
86288aa4217SBarry Smith /*MC
86353acd3b1SBarry Smith    PetscOptionsInt - Gets the integer value for a particular option in the database.
86453acd3b1SBarry Smith 
8653f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
86653acd3b1SBarry Smith 
86788aa4217SBarry Smith    Synopsis:
86888aa4217SBarry Smith    #include "petscsys.h"
8693a89f35bSSatish Balay PetscErrorCode  PetscOptionsInt(const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg))
87088aa4217SBarry Smith 
87153acd3b1SBarry Smith    Input Parameters:
87253acd3b1SBarry Smith +  opt - option name
87353acd3b1SBarry Smith .  text - short string that describes the option
87453acd3b1SBarry Smith .  man - manual page with additional information on option
8750fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
87688aa4217SBarry Smith $                 PetscOptionsInt(..., obj->value,&obj->value,...) or
8770fdccdaeSBarry Smith $                 value = defaultvalue
8780fdccdaeSBarry Smith $                 PetscOptionsInt(..., value,&value,&flg);
8790fdccdaeSBarry Smith $                 if (flg) {
88053acd3b1SBarry Smith 
881*d8d19677SJose E. Roman    Output Parameters:
88253acd3b1SBarry Smith +  value - the integer value to return
88353acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
88453acd3b1SBarry Smith 
88595452b02SPatrick Sanan    Notes:
88695452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
8872efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
8882efd9cb1SBarry Smith 
889989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
890989712b9SBarry Smith 
89195452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
89253acd3b1SBarry Smith 
8935a856986SBarry Smith    Level: beginner
8945a856986SBarry Smith 
8955a856986SBarry Smith .seealso: PetscOptionsBoundedInt(), PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
896536f90c4SPierre Jolivet           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(), PetscOptionsRangeInt()
897acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
89853acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
89953acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
900acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
901a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
90288aa4217SBarry Smith M*/
90388aa4217SBarry Smith 
9045a856986SBarry 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)
90553acd3b1SBarry Smith {
90653acd3b1SBarry Smith   PetscErrorCode  ierr;
9074416b707SBarry Smith   PetscOptionItem amsopt;
90812655325SBarry Smith   PetscBool       wasset;
90953acd3b1SBarry Smith 
91053acd3b1SBarry Smith   PetscFunctionBegin;
9115a856986SBarry Smith   if (currentvalue < lb) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Current value %D less than allowed bound %D",currentvalue,lb);
912c5910190SPierre Jolivet   if (currentvalue > ub) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Current value %D greater than allowed bound %D",currentvalue,ub);
913e55864a3SBarry Smith      if (!PetscOptionsObject->count) {
9144416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr);
9156356e834SBarry Smith     ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
91612655325SBarry Smith     *(PetscInt*)amsopt->data = currentvalue;
9173e211508SBarry Smith 
918c5929fdfSBarry Smith     ierr = PetscOptionsGetInt(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,&currentvalue,&wasset);CHKERRQ(ierr);
9193e211508SBarry Smith     if (wasset) {
92012655325SBarry Smith       *(PetscInt*)amsopt->data = currentvalue;
9213e211508SBarry Smith     }
922af6d86caSBarry Smith   }
92344ef3d73SBarry Smith   ierr = PetscOptionsGetInt(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,&wasset);CHKERRQ(ierr);
9245a856986SBarry Smith   if (wasset && *value < lb) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Newly set value %D less than allowed bound %D",*value,lb);
9255a856986SBarry Smith   if (wasset && *value > ub) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Newly set value %D greater than allowed bound %D",*value,ub);
92644ef3d73SBarry Smith   if (set) *set = wasset;
927e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
9280e4c290aSBarry 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);
92953acd3b1SBarry Smith   }
93053acd3b1SBarry Smith   PetscFunctionReturn(0);
93153acd3b1SBarry Smith }
93253acd3b1SBarry Smith 
93388aa4217SBarry Smith /*MC
93453acd3b1SBarry Smith    PetscOptionsString - Gets the string value for a particular option in the database.
93553acd3b1SBarry Smith 
9363f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
93753acd3b1SBarry Smith 
93888aa4217SBarry Smith    Synopsis:
93988aa4217SBarry Smith    #include "petscsys.h"
9403a89f35bSSatish Balay    PetscErrorCode  PetscOptionsString(const char opt[],const char text[],const char man[],const char currentvalue[],char value[],size_t len,PetscBool  *set)
94188aa4217SBarry Smith 
94253acd3b1SBarry Smith    Input Parameters:
94353acd3b1SBarry Smith +  opt - option name
94453acd3b1SBarry Smith .  text - short string that describes the option
94553acd3b1SBarry Smith .  man - manual page with additional information on option
9460fdccdaeSBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. This is not used to set value
947bcbf2dc5SJed Brown -  len - length of the result string including null terminator
94853acd3b1SBarry Smith 
949*d8d19677SJose E. Roman    Output Parameters:
95053acd3b1SBarry Smith +  value - the value to return
95153acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
95253acd3b1SBarry Smith 
95353acd3b1SBarry Smith    Level: beginner
95453acd3b1SBarry Smith 
95595452b02SPatrick Sanan    Notes:
95695452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
95753acd3b1SBarry Smith 
9587fccdfe4SBarry 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).
9597fccdfe4SBarry Smith 
9602efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
9612efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
9622efd9cb1SBarry Smith 
963989712b9SBarry Smith           The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
964989712b9SBarry Smith 
96589a13869SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
966536f90c4SPierre Jolivet           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(),
967acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsReal(), PetscOptionsBool(),
96853acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
96953acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
970acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
971a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
97288aa4217SBarry Smith M*/
97388aa4217SBarry Smith 
9744416b707SBarry 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)
97553acd3b1SBarry Smith {
97653acd3b1SBarry Smith   PetscErrorCode  ierr;
9774416b707SBarry Smith   PetscOptionItem amsopt;
97844ef3d73SBarry Smith   PetscBool       lset;
97953acd3b1SBarry Smith 
98053acd3b1SBarry Smith   PetscFunctionBegin;
9811a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
9824416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
98364facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
9840fdccdaeSBarry Smith     ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr);
985af6d86caSBarry Smith   }
98644ef3d73SBarry Smith   ierr = PetscOptionsGetString(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,len,&lset);CHKERRQ(ierr);
98744ef3d73SBarry Smith   if (set) *set = lset;
988e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
9890e4c290aSBarry 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);
99053acd3b1SBarry Smith   }
99153acd3b1SBarry Smith   PetscFunctionReturn(0);
99253acd3b1SBarry Smith }
99353acd3b1SBarry Smith 
99488aa4217SBarry Smith /*MC
99553acd3b1SBarry Smith    PetscOptionsReal - Gets the PetscReal value for a particular option in the database.
99653acd3b1SBarry Smith 
9973f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
99853acd3b1SBarry Smith 
99988aa4217SBarry Smith    Synopsis:
100088aa4217SBarry Smith    #include "petscsys.h"
10013a89f35bSSatish Balay    PetscErrorCode  PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal currentvalue,PetscReal *value,PetscBool  *set)
100288aa4217SBarry Smith 
100353acd3b1SBarry Smith    Input Parameters:
100453acd3b1SBarry Smith +  opt - option name
100553acd3b1SBarry Smith .  text - short string that describes the option
100653acd3b1SBarry Smith .  man - manual page with additional information on option
10070fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
100888aa4217SBarry Smith $                 PetscOptionsReal(..., obj->value,&obj->value,...) or
10090fdccdaeSBarry Smith $                 value = defaultvalue
10100fdccdaeSBarry Smith $                 PetscOptionsReal(..., value,&value,&flg);
10110fdccdaeSBarry Smith $                 if (flg) {
101253acd3b1SBarry Smith 
1013*d8d19677SJose E. Roman    Output Parameters:
101453acd3b1SBarry Smith +  value - the value to return
101553acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
101653acd3b1SBarry Smith 
101795452b02SPatrick Sanan    Notes:
101895452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
10192efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
10202efd9cb1SBarry Smith 
1021989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
1022989712b9SBarry Smith 
102395452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
102453acd3b1SBarry Smith 
10255a856986SBarry Smith    Level: beginner
10265a856986SBarry Smith 
102789a13869SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1028536f90c4SPierre Jolivet           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(),
1029acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
103053acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
103153acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1032acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1033a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
103488aa4217SBarry Smith M*/
103588aa4217SBarry Smith 
10364416b707SBarry Smith PetscErrorCode  PetscOptionsReal_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscReal currentvalue,PetscReal *value,PetscBool  *set)
103753acd3b1SBarry Smith {
103853acd3b1SBarry Smith   PetscErrorCode  ierr;
10394416b707SBarry Smith   PetscOptionItem amsopt;
104044ef3d73SBarry Smith   PetscBool       lset;
104153acd3b1SBarry Smith 
104253acd3b1SBarry Smith   PetscFunctionBegin;
1043e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
10444416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr);
1045538aa990SBarry Smith     ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
1046a297a907SKarl Rupp 
10470fdccdaeSBarry Smith     *(PetscReal*)amsopt->data = currentvalue;
1048538aa990SBarry Smith   }
104944ef3d73SBarry Smith   ierr = PetscOptionsGetReal(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,&lset);CHKERRQ(ierr);
105044ef3d73SBarry Smith   if (set) *set = lset;
10511a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
10520e4c290aSBarry 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);
105353acd3b1SBarry Smith   }
105453acd3b1SBarry Smith   PetscFunctionReturn(0);
105553acd3b1SBarry Smith }
105653acd3b1SBarry Smith 
105788aa4217SBarry Smith /*MC
105853acd3b1SBarry Smith    PetscOptionsScalar - Gets the scalar value for a particular option in the database.
105953acd3b1SBarry Smith 
10603f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
106153acd3b1SBarry Smith 
106288aa4217SBarry Smith    Synopsis:
106388aa4217SBarry Smith    #include "petscsys.h"
10643a89f35bSSatish Balay    PetscErrorCode PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar currentvalue,PetscScalar *value,PetscBool  *set)
106588aa4217SBarry Smith 
106653acd3b1SBarry Smith    Input Parameters:
106753acd3b1SBarry Smith +  opt - option name
106853acd3b1SBarry Smith .  text - short string that describes the option
106953acd3b1SBarry Smith .  man - manual page with additional information on option
10700fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
107188aa4217SBarry Smith $                 PetscOptionsScalar(..., obj->value,&obj->value,...) or
10720fdccdaeSBarry Smith $                 value = defaultvalue
10730fdccdaeSBarry Smith $                 PetscOptionsScalar(..., value,&value,&flg);
10740fdccdaeSBarry Smith $                 if (flg) {
10750fdccdaeSBarry Smith 
1076*d8d19677SJose E. Roman    Output Parameters:
107753acd3b1SBarry Smith +  value - the value to return
107853acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
107953acd3b1SBarry Smith 
108095452b02SPatrick Sanan    Notes:
108195452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
10822efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
10832efd9cb1SBarry Smith 
1084989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
1085989712b9SBarry Smith 
108695452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
108753acd3b1SBarry Smith 
10885a856986SBarry Smith    Level: beginner
10895a856986SBarry Smith 
109089a13869SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1091536f90c4SPierre Jolivet           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(),
1092acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
109353acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
109453acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1095acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1096a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
109788aa4217SBarry Smith M*/
109888aa4217SBarry Smith 
10994416b707SBarry Smith PetscErrorCode  PetscOptionsScalar_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscScalar currentvalue,PetscScalar *value,PetscBool  *set)
110053acd3b1SBarry Smith {
110153acd3b1SBarry Smith   PetscErrorCode ierr;
110253acd3b1SBarry Smith 
110353acd3b1SBarry Smith   PetscFunctionBegin;
110453acd3b1SBarry Smith #if !defined(PETSC_USE_COMPLEX)
11050fdccdaeSBarry Smith   ierr = PetscOptionsReal(opt,text,man,currentvalue,value,set);CHKERRQ(ierr);
110653acd3b1SBarry Smith #else
1107c5929fdfSBarry Smith   ierr = PetscOptionsGetScalar(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,set);CHKERRQ(ierr);
110853acd3b1SBarry Smith #endif
110953acd3b1SBarry Smith   PetscFunctionReturn(0);
111053acd3b1SBarry Smith }
111153acd3b1SBarry Smith 
111288aa4217SBarry Smith /*MC
111390d69ab7SBarry 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
111490d69ab7SBarry Smith                       its value is set to false.
111553acd3b1SBarry Smith 
11163f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
111753acd3b1SBarry Smith 
111888aa4217SBarry Smith    Synopsis:
111988aa4217SBarry Smith    #include "petscsys.h"
11203a89f35bSSatish Balay    PetscErrorCode PetscOptionsName(const char opt[],const char text[],const char man[],PetscBool  *flg)
112188aa4217SBarry Smith 
112253acd3b1SBarry Smith    Input Parameters:
112353acd3b1SBarry Smith +  opt - option name
112453acd3b1SBarry Smith .  text - short string that describes the option
112553acd3b1SBarry Smith -  man - manual page with additional information on option
112653acd3b1SBarry Smith 
112753acd3b1SBarry Smith    Output Parameter:
112853acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
112953acd3b1SBarry Smith 
113053acd3b1SBarry Smith    Level: beginner
113153acd3b1SBarry Smith 
113295452b02SPatrick Sanan    Notes:
113395452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
113453acd3b1SBarry Smith 
113589a13869SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1136536f90c4SPierre Jolivet           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(),
1137acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
113853acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
113953acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1140acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1141a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
114288aa4217SBarry Smith M*/
114388aa4217SBarry Smith 
11444416b707SBarry Smith PetscErrorCode  PetscOptionsName_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool  *flg)
114553acd3b1SBarry Smith {
114653acd3b1SBarry Smith   PetscErrorCode  ierr;
11474416b707SBarry Smith   PetscOptionItem amsopt;
114853acd3b1SBarry Smith 
114953acd3b1SBarry Smith   PetscFunctionBegin;
1150e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
11514416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1152ace3abfcSBarry Smith     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1153a297a907SKarl Rupp 
1154ace3abfcSBarry Smith     *(PetscBool*)amsopt->data = PETSC_FALSE;
11551ae3d29cSBarry Smith   }
1156c5929fdfSBarry Smith   ierr = PetscOptionsHasName(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg);CHKERRQ(ierr);
1157e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1158e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
115953acd3b1SBarry Smith   }
116053acd3b1SBarry Smith   PetscFunctionReturn(0);
116153acd3b1SBarry Smith }
116253acd3b1SBarry Smith 
116388aa4217SBarry Smith /*MC
1164a264d7a6SBarry Smith      PetscOptionsFList - Puts a list of option values that a single one may be selected from
116553acd3b1SBarry Smith 
11663f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
116753acd3b1SBarry Smith 
116888aa4217SBarry Smith    Synopsis:
116988aa4217SBarry Smith    #include "petscsys.h"
11703a89f35bSSatish Balay    PetscErrorCode  PetscOptionsFList(const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char currentvalue[],char value[],size_t len,PetscBool  *set)
117188aa4217SBarry Smith 
117253acd3b1SBarry Smith    Input Parameters:
117353acd3b1SBarry Smith +  opt - option name
117453acd3b1SBarry Smith .  text - short string that describes the option
117553acd3b1SBarry Smith .  man - manual page with additional information on option
117653acd3b1SBarry Smith .  list - the possible choices
11770fdccdaeSBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with
11780fdccdaeSBarry Smith $                 PetscOptionsFlist(..., obj->value,value,len,&flg);
11790fdccdaeSBarry Smith $                 if (flg) {
11803cc1e11dSBarry Smith -  len - the length of the character array value
118153acd3b1SBarry Smith 
1182*d8d19677SJose E. Roman    Output Parameters:
118353acd3b1SBarry Smith +  value - the value to return
118453acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
118553acd3b1SBarry Smith 
118653acd3b1SBarry Smith    Level: intermediate
118753acd3b1SBarry Smith 
118895452b02SPatrick Sanan    Notes:
118995452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
119053acd3b1SBarry Smith 
11912efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
11922efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
11932efd9cb1SBarry Smith 
1194989712b9SBarry Smith           The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
1195989712b9SBarry Smith 
119653acd3b1SBarry Smith    See PetscOptionsEList() for when the choices are given in a string array
119753acd3b1SBarry Smith 
119853acd3b1SBarry Smith    To get a listing of all currently specified options,
119988c29154SBarry Smith     see PetscOptionsView() or PetscOptionsGetAll()
120053acd3b1SBarry Smith 
1201eabe10d7SBarry Smith    Developer Note: This cannot check for invalid selection because of things like MATAIJ that are not included in the list
1202eabe10d7SBarry Smith 
120389a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1204acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
120553acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
120653acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1207acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1208a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList(), PetscOptionsEnum()
120988aa4217SBarry Smith M*/
121088aa4217SBarry Smith 
12114416b707SBarry 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)
121253acd3b1SBarry Smith {
121353acd3b1SBarry Smith   PetscErrorCode  ierr;
12144416b707SBarry Smith   PetscOptionItem amsopt;
121544ef3d73SBarry Smith   PetscBool       lset;
121653acd3b1SBarry Smith 
121753acd3b1SBarry Smith   PetscFunctionBegin;
12181a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
12194416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,ltext,man,OPTION_FLIST,&amsopt);CHKERRQ(ierr);
122064facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
12210fdccdaeSBarry Smith     ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr);
12223cc1e11dSBarry Smith     amsopt->flist = list;
12233cc1e11dSBarry Smith   }
122444ef3d73SBarry Smith   ierr = PetscOptionsGetString(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,len,&lset);CHKERRQ(ierr);
122544ef3d73SBarry Smith   if (set) *set = lset;
12261a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1227c3b366b1Sprj-     ierr = PetscFunctionListPrintTypes(PetscOptionsObject->comm,stdout,PetscOptionsObject->prefix,opt,ltext,man,list,currentvalue,lset && value ? value : currentvalue);CHKERRQ(ierr);
122853acd3b1SBarry Smith   }
122953acd3b1SBarry Smith   PetscFunctionReturn(0);
123053acd3b1SBarry Smith }
123153acd3b1SBarry Smith 
123288aa4217SBarry Smith /*MC
123353acd3b1SBarry Smith      PetscOptionsEList - Puts a list of option values that a single one may be selected from
123453acd3b1SBarry Smith 
12353f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
123653acd3b1SBarry Smith 
123788aa4217SBarry Smith    Synopsis:
123888aa4217SBarry Smith    #include "petscsys.h"
12393a89f35bSSatish 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)
124088aa4217SBarry Smith 
124153acd3b1SBarry Smith    Input Parameters:
124253acd3b1SBarry Smith +  opt - option name
124353acd3b1SBarry Smith .  ltext - short string that describes the option
124453acd3b1SBarry Smith .  man - manual page with additional information on option
1245a264d7a6SBarry Smith .  list - the possible choices (one of these must be selected, anything else is invalid)
124653acd3b1SBarry Smith .  ntext - number of choices
12470fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with
12480fdccdaeSBarry Smith $                 PetscOptionsElist(..., obj->value,&value,&flg);
12490fdccdaeSBarry Smith $                 if (flg) {
12500fdccdaeSBarry Smith 
1251*d8d19677SJose E. Roman    Output Parameters:
125253acd3b1SBarry Smith +  value - the index of the value to return
125353acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
125453acd3b1SBarry Smith 
125553acd3b1SBarry Smith    Level: intermediate
125653acd3b1SBarry Smith 
125795452b02SPatrick Sanan    Notes:
125895452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
125953acd3b1SBarry Smith 
12602efd9cb1SBarry Smith          If the user does not supply the option at all value is NOT changed. Thus
12612efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
12622efd9cb1SBarry Smith 
1263a264d7a6SBarry Smith    See PetscOptionsFList() for when the choices are given in a PetscFunctionList()
126453acd3b1SBarry Smith 
126589a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1266acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
126753acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
126853acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1269acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1270a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEnum()
127188aa4217SBarry Smith M*/
127288aa4217SBarry Smith 
12734416b707SBarry 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)
127453acd3b1SBarry Smith {
127553acd3b1SBarry Smith   PetscErrorCode  ierr;
127653acd3b1SBarry Smith   PetscInt        i;
12774416b707SBarry Smith   PetscOptionItem amsopt;
127844ef3d73SBarry Smith   PetscBool       lset;
127953acd3b1SBarry Smith 
128053acd3b1SBarry Smith   PetscFunctionBegin;
12811a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
12824416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,ltext,man,OPTION_ELIST,&amsopt);CHKERRQ(ierr);
128364facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
12840fdccdaeSBarry Smith     ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr);
12856991f827SBarry Smith     ierr = PetscStrNArrayallocpy(ntext,list,(char***)&amsopt->list);CHKERRQ(ierr);
12861ae3d29cSBarry Smith     amsopt->nlist = ntext;
12871ae3d29cSBarry Smith   }
128844ef3d73SBarry Smith   ierr = PetscOptionsGetEList(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,list,ntext,value,&lset);CHKERRQ(ierr);
128944ef3d73SBarry Smith   if (set) *set = lset;
12901a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
12910e4c290aSBarry 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);
129253acd3b1SBarry Smith     for (i=0; i<ntext; i++) {
1293e55864a3SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s",list[i]);CHKERRQ(ierr);
129453acd3b1SBarry Smith     }
1295e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," (%s)\n",ManSection(man));CHKERRQ(ierr);
129653acd3b1SBarry Smith   }
129753acd3b1SBarry Smith   PetscFunctionReturn(0);
129853acd3b1SBarry Smith }
129953acd3b1SBarry Smith 
130088aa4217SBarry Smith /*MC
1301acfcf0e5SJed Brown      PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for
1302d5649816SBarry Smith        which at most a single value can be true.
130353acd3b1SBarry Smith 
13043f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
130553acd3b1SBarry Smith 
130688aa4217SBarry Smith    Synopsis:
130788aa4217SBarry Smith    #include "petscsys.h"
13083a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroupBegin(const char opt[],const char text[],const char man[],PetscBool  *flg)
130988aa4217SBarry Smith 
131053acd3b1SBarry Smith    Input Parameters:
131153acd3b1SBarry Smith +  opt - option name
131253acd3b1SBarry Smith .  text - short string that describes the option
131353acd3b1SBarry Smith -  man - manual page with additional information on option
131453acd3b1SBarry Smith 
131553acd3b1SBarry Smith    Output Parameter:
131653acd3b1SBarry Smith .  flg - whether that option was set or not
131753acd3b1SBarry Smith 
131853acd3b1SBarry Smith    Level: intermediate
131953acd3b1SBarry Smith 
132095452b02SPatrick Sanan    Notes:
132195452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
132253acd3b1SBarry Smith 
1323acfcf0e5SJed Brown    Must be followed by 0 or more PetscOptionsBoolGroup()s and PetscOptionsBoolGroupEnd()
132453acd3b1SBarry Smith 
132589a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1326acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
132753acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
132853acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1329acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1330a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
133188aa4217SBarry Smith M*/
133288aa4217SBarry Smith 
13334416b707SBarry Smith PetscErrorCode  PetscOptionsBoolGroupBegin_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool  *flg)
133453acd3b1SBarry Smith {
133553acd3b1SBarry Smith   PetscErrorCode  ierr;
13364416b707SBarry Smith   PetscOptionItem amsopt;
133753acd3b1SBarry Smith 
133853acd3b1SBarry Smith   PetscFunctionBegin;
1339e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
13404416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1341ace3abfcSBarry Smith     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1342a297a907SKarl Rupp 
1343ace3abfcSBarry Smith     *(PetscBool*)amsopt->data = PETSC_FALSE;
13441ae3d29cSBarry Smith   }
134568b16fdaSBarry Smith   *flg = PETSC_FALSE;
1346c5929fdfSBarry Smith   ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr);
1347e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1348e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  Pick at most one of -------------\n");CHKERRQ(ierr);
1349e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"    -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
135053acd3b1SBarry Smith   }
135153acd3b1SBarry Smith   PetscFunctionReturn(0);
135253acd3b1SBarry Smith }
135353acd3b1SBarry Smith 
135488aa4217SBarry Smith /*MC
1355acfcf0e5SJed Brown      PetscOptionsBoolGroup - One in a series of logical queries on the options database for
1356d5649816SBarry Smith        which at most a single value can be true.
135753acd3b1SBarry Smith 
13583f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
135953acd3b1SBarry Smith 
136088aa4217SBarry Smith    Synopsis:
136188aa4217SBarry Smith    #include "petscsys.h"
13623a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroup(const char opt[],const char text[],const char man[],PetscBool  *flg)
136388aa4217SBarry Smith 
136453acd3b1SBarry Smith    Input Parameters:
136553acd3b1SBarry Smith +  opt - option name
136653acd3b1SBarry Smith .  text - short string that describes the option
136753acd3b1SBarry Smith -  man - manual page with additional information on option
136853acd3b1SBarry Smith 
136953acd3b1SBarry Smith    Output Parameter:
137053acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
137153acd3b1SBarry Smith 
137253acd3b1SBarry Smith    Level: intermediate
137353acd3b1SBarry Smith 
137495452b02SPatrick Sanan    Notes:
137595452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
137653acd3b1SBarry Smith 
1377acfcf0e5SJed Brown    Must follow a PetscOptionsBoolGroupBegin() and preceded a PetscOptionsBoolGroupEnd()
137853acd3b1SBarry Smith 
137989a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1380acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
138153acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
138253acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1383acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1384a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
138588aa4217SBarry Smith M*/
138688aa4217SBarry Smith 
13874416b707SBarry Smith PetscErrorCode  PetscOptionsBoolGroup_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool  *flg)
138853acd3b1SBarry Smith {
138953acd3b1SBarry Smith   PetscErrorCode  ierr;
13904416b707SBarry Smith   PetscOptionItem amsopt;
139153acd3b1SBarry Smith 
139253acd3b1SBarry Smith   PetscFunctionBegin;
1393e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
13944416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1395ace3abfcSBarry Smith     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1396a297a907SKarl Rupp 
1397ace3abfcSBarry Smith     *(PetscBool*)amsopt->data = PETSC_FALSE;
13981ae3d29cSBarry Smith   }
139917326d04SJed Brown   *flg = PETSC_FALSE;
1400c5929fdfSBarry Smith   ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr);
1401e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1402e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"    -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
140353acd3b1SBarry Smith   }
140453acd3b1SBarry Smith   PetscFunctionReturn(0);
140553acd3b1SBarry Smith }
140653acd3b1SBarry Smith 
140788aa4217SBarry Smith /*MC
1408acfcf0e5SJed Brown      PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for
1409d5649816SBarry Smith        which at most a single value can be true.
141053acd3b1SBarry Smith 
14113f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
141253acd3b1SBarry Smith 
141388aa4217SBarry Smith    Synopsis:
141488aa4217SBarry Smith    #include "petscsys.h"
14153a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroupEnd(const char opt[],const char text[],const char man[],PetscBool  *flg)
141688aa4217SBarry Smith 
141753acd3b1SBarry Smith    Input Parameters:
141853acd3b1SBarry Smith +  opt - option name
141953acd3b1SBarry Smith .  text - short string that describes the option
142053acd3b1SBarry Smith -  man - manual page with additional information on option
142153acd3b1SBarry Smith 
142253acd3b1SBarry Smith    Output Parameter:
142353acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
142453acd3b1SBarry Smith 
142553acd3b1SBarry Smith    Level: intermediate
142653acd3b1SBarry Smith 
142795452b02SPatrick Sanan    Notes:
142895452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
142953acd3b1SBarry Smith 
1430acfcf0e5SJed Brown    Must follow a PetscOptionsBoolGroupBegin()
143153acd3b1SBarry Smith 
143289a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1433acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
143453acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
143553acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1436acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1437a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
143888aa4217SBarry Smith M*/
143988aa4217SBarry Smith 
14404416b707SBarry Smith PetscErrorCode  PetscOptionsBoolGroupEnd_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool  *flg)
144153acd3b1SBarry Smith {
144253acd3b1SBarry Smith   PetscErrorCode  ierr;
14434416b707SBarry Smith   PetscOptionItem amsopt;
144453acd3b1SBarry Smith 
144553acd3b1SBarry Smith   PetscFunctionBegin;
1446e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
14474416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1448ace3abfcSBarry Smith     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1449a297a907SKarl Rupp 
1450ace3abfcSBarry Smith     *(PetscBool*)amsopt->data = PETSC_FALSE;
14511ae3d29cSBarry Smith   }
145217326d04SJed Brown   *flg = PETSC_FALSE;
1453c5929fdfSBarry Smith   ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr);
1454e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1455e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"    -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
145653acd3b1SBarry Smith   }
145753acd3b1SBarry Smith   PetscFunctionReturn(0);
145853acd3b1SBarry Smith }
145953acd3b1SBarry Smith 
146088aa4217SBarry Smith /*MC
1461acfcf0e5SJed Brown    PetscOptionsBool - Determines if a particular option is in the database with a true or false
146253acd3b1SBarry Smith 
14633f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
146453acd3b1SBarry Smith 
146588aa4217SBarry Smith    Synopsis:
146688aa4217SBarry Smith    #include "petscsys.h"
14673a89f35bSSatish Balay    PetscErrorCode PetscOptionsBool(const char opt[],const char text[],const char man[],PetscBool currentvalue,PetscBool  *flg,PetscBool  *set)
146888aa4217SBarry Smith 
146953acd3b1SBarry Smith    Input Parameters:
147053acd3b1SBarry Smith +  opt - option name
147153acd3b1SBarry Smith .  text - short string that describes the option
1472868c398cSBarry Smith .  man - manual page with additional information on option
147394ae4db5SBarry Smith -  currentvalue - the current value
147453acd3b1SBarry Smith 
1475*d8d19677SJose E. Roman    Output Parameters:
1476a2b725a8SWilliam Gropp +  flg - PETSC_TRUE or PETSC_FALSE
1477a2b725a8SWilliam Gropp -  set - PETSC_TRUE if found, else PETSC_FALSE
147853acd3b1SBarry Smith 
14792efd9cb1SBarry Smith    Notes:
14802efd9cb1SBarry Smith        TRUE, true, YES, yes, nostring, and 1 all translate to PETSC_TRUE
14812efd9cb1SBarry Smith        FALSE, false, NO, no, and 0 all translate to PETSC_FALSE
14822efd9cb1SBarry Smith 
14832efd9cb1SBarry 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
14842efd9cb1SBarry Smith      is equivalent to -requested_bool true
14852efd9cb1SBarry Smith 
14862efd9cb1SBarry Smith        If the user does not supply the option at all flg is NOT changed. Thus
14872efd9cb1SBarry Smith      you should ALWAYS initialize the flg if you access it without first checking if the set flag is true.
14882efd9cb1SBarry Smith 
148995452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
149053acd3b1SBarry Smith 
14915a856986SBarry Smith    Level: beginner
14925a856986SBarry Smith 
149389a13869SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1494536f90c4SPierre Jolivet           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetBool(),
1495536f90c4SPierre Jolivet           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(),
149653acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
149753acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1498acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1499a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
150088aa4217SBarry Smith M*/
150188aa4217SBarry Smith 
15024416b707SBarry Smith PetscErrorCode  PetscOptionsBool_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool currentvalue,PetscBool  *flg,PetscBool  *set)
150353acd3b1SBarry Smith {
150453acd3b1SBarry Smith   PetscErrorCode  ierr;
1505ace3abfcSBarry Smith   PetscBool       iset;
15064416b707SBarry Smith   PetscOptionItem amsopt;
150753acd3b1SBarry Smith 
150853acd3b1SBarry Smith   PetscFunctionBegin;
1509e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
15104416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1511ace3abfcSBarry Smith     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1512a297a907SKarl Rupp 
151394ae4db5SBarry Smith     *(PetscBool*)amsopt->data = currentvalue;
1514af6d86caSBarry Smith   }
1515c5929fdfSBarry Smith   ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,&iset);CHKERRQ(ierr);
151653acd3b1SBarry Smith   if (set) *set = iset;
15171a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
151844ef3d73SBarry Smith     const char *v = PetscBools[currentvalue], *vn = PetscBools[iset && flg ? *flg : currentvalue];
151944ef3d73SBarry 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);
152053acd3b1SBarry Smith   }
152153acd3b1SBarry Smith   PetscFunctionReturn(0);
152253acd3b1SBarry Smith }
152353acd3b1SBarry Smith 
152488aa4217SBarry Smith /*MC
152553acd3b1SBarry Smith    PetscOptionsRealArray - Gets an array of double values for a particular
152653acd3b1SBarry Smith    option in the database. The values must be separated with commas with
152753acd3b1SBarry Smith    no intervening spaces.
152853acd3b1SBarry Smith 
15293f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
153053acd3b1SBarry Smith 
153188aa4217SBarry Smith    Synopsis:
153288aa4217SBarry Smith    #include "petscsys.h"
15333a89f35bSSatish Balay    PetscErrorCode PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool  *set)
153488aa4217SBarry Smith 
153553acd3b1SBarry Smith    Input Parameters:
153653acd3b1SBarry Smith +  opt - the option one is seeking
153753acd3b1SBarry Smith .  text - short string describing option
153853acd3b1SBarry Smith .  man - manual page for option
153953acd3b1SBarry Smith -  nmax - maximum number of values
154053acd3b1SBarry Smith 
1541*d8d19677SJose E. Roman    Output Parameters:
154253acd3b1SBarry Smith +  value - location to copy values
154353acd3b1SBarry Smith .  nmax - actual number of values found
154453acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
154553acd3b1SBarry Smith 
154653acd3b1SBarry Smith    Level: beginner
154753acd3b1SBarry Smith 
154853acd3b1SBarry Smith    Notes:
154953acd3b1SBarry Smith    The user should pass in an array of doubles
155053acd3b1SBarry Smith 
155153acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
155253acd3b1SBarry Smith 
155389a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1554acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
155553acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
155653acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1557acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1558a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
155988aa4217SBarry Smith M*/
156088aa4217SBarry Smith 
15614416b707SBarry Smith PetscErrorCode PetscOptionsRealArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool  *set)
156253acd3b1SBarry Smith {
156353acd3b1SBarry Smith   PetscErrorCode  ierr;
156453acd3b1SBarry Smith   PetscInt        i;
15654416b707SBarry Smith   PetscOptionItem amsopt;
156653acd3b1SBarry Smith 
156753acd3b1SBarry Smith   PetscFunctionBegin;
1568e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1569e26ddf31SBarry Smith     PetscReal *vals;
1570e26ddf31SBarry Smith 
15714416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr);
1572e55864a3SBarry Smith     ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
1573e26ddf31SBarry Smith     vals = (PetscReal*)amsopt->data;
1574e26ddf31SBarry Smith     for (i=0; i<*n; i++) vals[i] = value[i];
1575e26ddf31SBarry Smith     amsopt->arraylength = *n;
1576e26ddf31SBarry Smith   }
1577c5929fdfSBarry Smith   ierr = PetscOptionsGetRealArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr);
1578e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1579a519f713SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%g",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,(double)value[0]);CHKERRQ(ierr);
158053acd3b1SBarry Smith     for (i=1; i<*n; i++) {
1581e55864a3SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%g",(double)value[i]);CHKERRQ(ierr);
158253acd3b1SBarry Smith     }
1583e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
158453acd3b1SBarry Smith   }
158553acd3b1SBarry Smith   PetscFunctionReturn(0);
158653acd3b1SBarry Smith }
158753acd3b1SBarry Smith 
158888aa4217SBarry Smith /*MC
1589050cccc3SHong Zhang    PetscOptionsScalarArray - Gets an array of Scalar values for a particular
1590050cccc3SHong Zhang    option in the database. The values must be separated with commas with
1591050cccc3SHong Zhang    no intervening spaces.
1592050cccc3SHong Zhang 
1593050cccc3SHong Zhang    Logically Collective on the communicator passed in PetscOptionsBegin()
1594050cccc3SHong Zhang 
159588aa4217SBarry Smith    Synopsis:
159688aa4217SBarry Smith    #include "petscsys.h"
15973a89f35bSSatish Balay    PetscErrorCode PetscOptionsScalarArray(const char opt[],const char text[],const char man[],PetscScalar value[],PetscInt *n,PetscBool  *set)
159888aa4217SBarry Smith 
1599050cccc3SHong Zhang    Input Parameters:
1600050cccc3SHong Zhang +  opt - the option one is seeking
1601050cccc3SHong Zhang .  text - short string describing option
1602050cccc3SHong Zhang .  man - manual page for option
1603050cccc3SHong Zhang -  nmax - maximum number of values
1604050cccc3SHong Zhang 
1605*d8d19677SJose E. Roman    Output Parameters:
1606050cccc3SHong Zhang +  value - location to copy values
1607050cccc3SHong Zhang .  nmax - actual number of values found
1608050cccc3SHong Zhang -  set - PETSC_TRUE if found, else PETSC_FALSE
1609050cccc3SHong Zhang 
1610050cccc3SHong Zhang    Level: beginner
1611050cccc3SHong Zhang 
1612050cccc3SHong Zhang    Notes:
1613050cccc3SHong Zhang    The user should pass in an array of doubles
1614050cccc3SHong Zhang 
1615050cccc3SHong Zhang    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1616050cccc3SHong Zhang 
161789a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1618050cccc3SHong Zhang           PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1619050cccc3SHong Zhang           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1620050cccc3SHong Zhang           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1621050cccc3SHong Zhang           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1622050cccc3SHong Zhang           PetscOptionsFList(), PetscOptionsEList()
162388aa4217SBarry Smith M*/
162488aa4217SBarry Smith 
16254416b707SBarry Smith PetscErrorCode PetscOptionsScalarArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscScalar value[],PetscInt *n,PetscBool  *set)
1626050cccc3SHong Zhang {
1627050cccc3SHong Zhang   PetscErrorCode  ierr;
1628050cccc3SHong Zhang   PetscInt        i;
16294416b707SBarry Smith   PetscOptionItem amsopt;
1630050cccc3SHong Zhang 
1631050cccc3SHong Zhang   PetscFunctionBegin;
1632050cccc3SHong Zhang   if (!PetscOptionsObject->count) {
1633050cccc3SHong Zhang     PetscScalar *vals;
1634050cccc3SHong Zhang 
16354416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_SCALAR_ARRAY,&amsopt);CHKERRQ(ierr);
1636050cccc3SHong Zhang     ierr = PetscMalloc((*n)*sizeof(PetscScalar),&amsopt->data);CHKERRQ(ierr);
1637050cccc3SHong Zhang     vals = (PetscScalar*)amsopt->data;
1638050cccc3SHong Zhang     for (i=0; i<*n; i++) vals[i] = value[i];
1639050cccc3SHong Zhang     amsopt->arraylength = *n;
1640050cccc3SHong Zhang   }
1641c5929fdfSBarry Smith   ierr = PetscOptionsGetScalarArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr);
1642050cccc3SHong Zhang   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
164395f3a755SJose 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);
1644050cccc3SHong Zhang     for (i=1; i<*n; i++) {
164595f3a755SJose E. Roman       ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%g+%gi",(double)PetscRealPart(value[i]),(double)PetscImaginaryPart(value[i]));CHKERRQ(ierr);
1646050cccc3SHong Zhang     }
1647050cccc3SHong Zhang     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1648050cccc3SHong Zhang   }
1649050cccc3SHong Zhang   PetscFunctionReturn(0);
1650050cccc3SHong Zhang }
165153acd3b1SBarry Smith 
165288aa4217SBarry Smith /*MC
165353acd3b1SBarry Smith    PetscOptionsIntArray - Gets an array of integers for a particular
1654b32a342fSShri Abhyankar    option in the database.
165553acd3b1SBarry Smith 
16563f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
165753acd3b1SBarry Smith 
165888aa4217SBarry Smith    Synopsis:
165988aa4217SBarry Smith    #include "petscsys.h"
16603a89f35bSSatish Balay    PetscErrorCode PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool  *set)
166188aa4217SBarry Smith 
166253acd3b1SBarry Smith    Input Parameters:
166353acd3b1SBarry Smith +  opt - the option one is seeking
166453acd3b1SBarry Smith .  text - short string describing option
166553acd3b1SBarry Smith .  man - manual page for option
1666f8a50e2bSBarry Smith -  n - maximum number of values
166753acd3b1SBarry Smith 
1668*d8d19677SJose E. Roman    Output Parameters:
166953acd3b1SBarry Smith +  value - location to copy values
1670f8a50e2bSBarry Smith .  n - actual number of values found
167153acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
167253acd3b1SBarry Smith 
167353acd3b1SBarry Smith    Level: beginner
167453acd3b1SBarry Smith 
167553acd3b1SBarry Smith    Notes:
1676b32a342fSShri Abhyankar    The array can be passed as
1677bebe2cf6SSatish Balay    a comma separated list:                                 0,1,2,3,4,5,6,7
16780fd488f5SShri Abhyankar    a range (start-end+1):                                  0-8
16790fd488f5SShri Abhyankar    a range with given increment (start-end+1:inc):         0-7:2
1680bebe2cf6SSatish Balay    a combination of values and ranges separated by commas: 0,1-8,8-15:2
1681b32a342fSShri Abhyankar 
1682b32a342fSShri Abhyankar    There must be no intervening spaces between the values.
168353acd3b1SBarry Smith 
168453acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
168553acd3b1SBarry Smith 
168689a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1687acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
168853acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
168953acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1690acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1691a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList(), PetscOptionsRealArray()
169288aa4217SBarry Smith M*/
169388aa4217SBarry Smith 
16944416b707SBarry Smith PetscErrorCode  PetscOptionsIntArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool  *set)
169553acd3b1SBarry Smith {
169653acd3b1SBarry Smith   PetscErrorCode ierr;
169753acd3b1SBarry Smith   PetscInt        i;
16984416b707SBarry Smith   PetscOptionItem amsopt;
169953acd3b1SBarry Smith 
170053acd3b1SBarry Smith   PetscFunctionBegin;
1701e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1702e26ddf31SBarry Smith     PetscInt *vals;
1703e26ddf31SBarry Smith 
17044416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr);
1705854ce69bSBarry Smith     ierr = PetscMalloc1(*n,(PetscInt**)&amsopt->data);CHKERRQ(ierr);
1706e26ddf31SBarry Smith     vals = (PetscInt*)amsopt->data;
1707e26ddf31SBarry Smith     for (i=0; i<*n; i++) vals[i] = value[i];
1708e26ddf31SBarry Smith     amsopt->arraylength = *n;
1709e26ddf31SBarry Smith   }
1710c5929fdfSBarry Smith   ierr = PetscOptionsGetIntArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr);
1711e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1712e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%d",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,value[0]);CHKERRQ(ierr);
171353acd3b1SBarry Smith     for (i=1; i<*n; i++) {
1714e55864a3SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%d",value[i]);CHKERRQ(ierr);
171553acd3b1SBarry Smith     }
1716e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
171753acd3b1SBarry Smith   }
171853acd3b1SBarry Smith   PetscFunctionReturn(0);
171953acd3b1SBarry Smith }
172053acd3b1SBarry Smith 
172188aa4217SBarry Smith /*MC
172253acd3b1SBarry Smith    PetscOptionsStringArray - Gets an array of string values for a particular
172353acd3b1SBarry Smith    option in the database. The values must be separated with commas with
172453acd3b1SBarry Smith    no intervening spaces.
172553acd3b1SBarry Smith 
17263f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
172753acd3b1SBarry Smith 
172888aa4217SBarry Smith    Synopsis:
172988aa4217SBarry Smith    #include "petscsys.h"
17303a89f35bSSatish Balay    PetscErrorCode PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool  *set)
173188aa4217SBarry Smith 
173253acd3b1SBarry Smith    Input Parameters:
173353acd3b1SBarry Smith +  opt - the option one is seeking
173453acd3b1SBarry Smith .  text - short string describing option
173553acd3b1SBarry Smith .  man - manual page for option
173653acd3b1SBarry Smith -  nmax - maximum number of strings
173753acd3b1SBarry Smith 
1738*d8d19677SJose E. Roman    Output Parameters:
173953acd3b1SBarry Smith +  value - location to copy strings
174053acd3b1SBarry Smith .  nmax - actual number of strings found
174153acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
174253acd3b1SBarry Smith 
174353acd3b1SBarry Smith    Level: beginner
174453acd3b1SBarry Smith 
174553acd3b1SBarry Smith    Notes:
174653acd3b1SBarry Smith    The user should pass in an array of pointers to char, to hold all the
174753acd3b1SBarry Smith    strings returned by this function.
174853acd3b1SBarry Smith 
174953acd3b1SBarry Smith    The user is responsible for deallocating the strings that are
175053acd3b1SBarry Smith    returned. The Fortran interface for this routine is not supported.
175153acd3b1SBarry Smith 
175253acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
175353acd3b1SBarry Smith 
175489a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1755acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
175653acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
175753acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1758acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1759a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
176088aa4217SBarry Smith M*/
176188aa4217SBarry Smith 
17624416b707SBarry Smith PetscErrorCode  PetscOptionsStringArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool  *set)
176353acd3b1SBarry Smith {
176453acd3b1SBarry Smith   PetscErrorCode  ierr;
17654416b707SBarry Smith   PetscOptionItem amsopt;
176653acd3b1SBarry Smith 
176753acd3b1SBarry Smith   PetscFunctionBegin;
1768e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
17694416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING_ARRAY,&amsopt);CHKERRQ(ierr);
1770854ce69bSBarry Smith     ierr = PetscMalloc1(*nmax,(char**)&amsopt->data);CHKERRQ(ierr);
1771a297a907SKarl Rupp 
17721ae3d29cSBarry Smith     amsopt->arraylength = *nmax;
17731ae3d29cSBarry Smith   }
1774c5929fdfSBarry Smith   ierr = PetscOptionsGetStringArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,nmax,set);CHKERRQ(ierr);
1775e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1776e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
177753acd3b1SBarry Smith   }
177853acd3b1SBarry Smith   PetscFunctionReturn(0);
177953acd3b1SBarry Smith }
178053acd3b1SBarry Smith 
178188aa4217SBarry Smith /*MC
1782acfcf0e5SJed Brown    PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular
1783e2446a98SMatthew Knepley    option in the database. The values must be separated with commas with
1784e2446a98SMatthew Knepley    no intervening spaces.
1785e2446a98SMatthew Knepley 
17863f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
1787e2446a98SMatthew Knepley 
178888aa4217SBarry Smith    Synopsis:
178988aa4217SBarry Smith    #include "petscsys.h"
17903a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolArray(const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set)
179188aa4217SBarry Smith 
1792e2446a98SMatthew Knepley    Input Parameters:
1793e2446a98SMatthew Knepley +  opt - the option one is seeking
1794e2446a98SMatthew Knepley .  text - short string describing option
1795e2446a98SMatthew Knepley .  man - manual page for option
1796e2446a98SMatthew Knepley -  nmax - maximum number of values
1797e2446a98SMatthew Knepley 
1798*d8d19677SJose E. Roman    Output Parameters:
1799e2446a98SMatthew Knepley +  value - location to copy values
1800e2446a98SMatthew Knepley .  nmax - actual number of values found
1801e2446a98SMatthew Knepley -  set - PETSC_TRUE if found, else PETSC_FALSE
1802e2446a98SMatthew Knepley 
1803e2446a98SMatthew Knepley    Level: beginner
1804e2446a98SMatthew Knepley 
1805e2446a98SMatthew Knepley    Notes:
1806e2446a98SMatthew Knepley    The user should pass in an array of doubles
1807e2446a98SMatthew Knepley 
1808e2446a98SMatthew Knepley    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1809e2446a98SMatthew Knepley 
181089a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1811acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1812e2446a98SMatthew Knepley           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1813e2446a98SMatthew Knepley           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1814acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1815a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
181688aa4217SBarry Smith M*/
181788aa4217SBarry Smith 
18184416b707SBarry Smith PetscErrorCode  PetscOptionsBoolArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set)
1819e2446a98SMatthew Knepley {
1820e2446a98SMatthew Knepley   PetscErrorCode   ierr;
1821e2446a98SMatthew Knepley   PetscInt         i;
18224416b707SBarry Smith   PetscOptionItem  amsopt;
1823e2446a98SMatthew Knepley 
1824e2446a98SMatthew Knepley   PetscFunctionBegin;
1825e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1826ace3abfcSBarry Smith     PetscBool *vals;
18271ae3d29cSBarry Smith 
18284416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL_ARRAY,&amsopt);CHKERRQ(ierr);
18291a1499c8SBarry Smith     ierr = PetscMalloc1(*n,(PetscBool**)&amsopt->data);CHKERRQ(ierr);
1830ace3abfcSBarry Smith     vals = (PetscBool*)amsopt->data;
18311ae3d29cSBarry Smith     for (i=0; i<*n; i++) vals[i] = value[i];
18321ae3d29cSBarry Smith     amsopt->arraylength = *n;
18331ae3d29cSBarry Smith   }
1834c5929fdfSBarry Smith   ierr = PetscOptionsGetBoolArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr);
1835e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1836e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%d",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,value[0]);CHKERRQ(ierr);
1837e2446a98SMatthew Knepley     for (i=1; i<*n; i++) {
1838e55864a3SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%d",value[i]);CHKERRQ(ierr);
1839e2446a98SMatthew Knepley     }
1840e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1841e2446a98SMatthew Knepley   }
1842e2446a98SMatthew Knepley   PetscFunctionReturn(0);
1843e2446a98SMatthew Knepley }
1844e2446a98SMatthew Knepley 
184588aa4217SBarry Smith /*MC
1846d1da0b69SBarry Smith    PetscOptionsViewer - Gets a viewer appropriate for the type indicated by the user
18478cc676e6SMatthew G Knepley 
18488cc676e6SMatthew G Knepley    Logically Collective on the communicator passed in PetscOptionsBegin()
18498cc676e6SMatthew G Knepley 
185088aa4217SBarry Smith    Synopsis:
185188aa4217SBarry Smith    #include "petscsys.h"
18523a89f35bSSatish Balay    PetscErrorCode PetscOptionsViewer(const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool  *set)
185388aa4217SBarry Smith 
18548cc676e6SMatthew G Knepley    Input Parameters:
18558cc676e6SMatthew G Knepley +  opt - option name
18568cc676e6SMatthew G Knepley .  text - short string that describes the option
18578cc676e6SMatthew G Knepley -  man - manual page with additional information on option
18588cc676e6SMatthew G Knepley 
1859*d8d19677SJose E. Roman    Output Parameters:
18608cc676e6SMatthew G Knepley +  viewer - the viewer
18618cc676e6SMatthew G Knepley -  set - PETSC_TRUE if found, else PETSC_FALSE
18628cc676e6SMatthew G Knepley 
18638cc676e6SMatthew G Knepley    Level: beginner
18648cc676e6SMatthew G Knepley 
186595452b02SPatrick Sanan    Notes:
186695452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
18678cc676e6SMatthew G Knepley 
18685a7113b9SPatrick Sanan    See PetscOptionsGetViewer() for the format of the supplied viewer and its options
18698cc676e6SMatthew G Knepley 
187089a13869SBarry Smith .seealso: PetscOptionsGetViewer(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
18718cc676e6SMatthew G Knepley           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
18728cc676e6SMatthew G Knepley           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
18738cc676e6SMatthew G Knepley           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
18748cc676e6SMatthew G Knepley           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
18758cc676e6SMatthew G Knepley           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1876a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
187788aa4217SBarry Smith M*/
187888aa4217SBarry Smith 
18794416b707SBarry Smith PetscErrorCode  PetscOptionsViewer_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool  *set)
18808cc676e6SMatthew G Knepley {
18818cc676e6SMatthew G Knepley   PetscErrorCode  ierr;
18824416b707SBarry Smith   PetscOptionItem amsopt;
18838cc676e6SMatthew G Knepley 
18848cc676e6SMatthew G Knepley   PetscFunctionBegin;
18851a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
18864416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
188764facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
18885b02f95dSBarry Smith     ierr = PetscStrdup("",(char**)&amsopt->data);CHKERRQ(ierr);
18898cc676e6SMatthew G Knepley   }
189016413a6aSBarry Smith   ierr = PetscOptionsGetViewer(PetscOptionsObject->comm,PetscOptionsObject->options,PetscOptionsObject->prefix,opt,viewer,format,set);CHKERRQ(ierr);
1891e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1892e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%s>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,"",text,ManSection(man));CHKERRQ(ierr);
18938cc676e6SMatthew G Knepley   }
18948cc676e6SMatthew G Knepley   PetscFunctionReturn(0);
18958cc676e6SMatthew G Knepley }
18968cc676e6SMatthew G Knepley 
189753acd3b1SBarry Smith /*@C
1898b52f573bSBarry Smith      PetscOptionsHead - Puts a heading before listing any more published options. Used, for example,
189953acd3b1SBarry Smith             in KSPSetFromOptions_GMRES().
190053acd3b1SBarry Smith 
19013f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
190253acd3b1SBarry Smith 
190353acd3b1SBarry Smith    Input Parameter:
190453acd3b1SBarry Smith .   head - the heading text
190553acd3b1SBarry Smith 
190653acd3b1SBarry Smith    Level: intermediate
190753acd3b1SBarry Smith 
190895452b02SPatrick Sanan    Notes:
19093a89f35bSSatish Balay     Must be between a PetscOptionsBegin() and a PetscOptionsEnd(), and PetscOptionsObject created in PetscOptionsBegin() should be the first argument
191053acd3b1SBarry Smith 
1911b52f573bSBarry Smith           Can be followed by a call to PetscOptionsTail() in the same function.
191253acd3b1SBarry Smith 
191389a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1914acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
191553acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
191653acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1917acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1918a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
191953acd3b1SBarry Smith @*/
19204416b707SBarry Smith PetscErrorCode  PetscOptionsHead(PetscOptionItems *PetscOptionsObject,const char head[])
192153acd3b1SBarry Smith {
192253acd3b1SBarry Smith   PetscErrorCode ierr;
192353acd3b1SBarry Smith 
192453acd3b1SBarry Smith   PetscFunctionBegin;
1925e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1926e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  %s\n",head);CHKERRQ(ierr);
192753acd3b1SBarry Smith   }
192853acd3b1SBarry Smith   PetscFunctionReturn(0);
192953acd3b1SBarry Smith }
193053acd3b1SBarry Smith 
1931