xref: /petsc/src/sys/objects/aoptions.c (revision bcbf2dc56252e54b6497528bb28e6efa46bc1a66)
153acd3b1SBarry Smith #define PETSC_DLL
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 
8d382aafbSBarry Smith #include "petscsys.h"        /*I  "petscsys.h"   I*/
953acd3b1SBarry Smith #if defined(PETSC_HAVE_STDLIB_H)
1053acd3b1SBarry Smith #include <stdlib.h>
1153acd3b1SBarry Smith #endif
1253acd3b1SBarry Smith 
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 */
19f8d0b74dSMatthew Knepley PetscOptionsObjectType PetscOptionsObject;
2053acd3b1SBarry Smith PetscInt               PetscOptionsPublishCount = 0;
2153acd3b1SBarry Smith 
2253acd3b1SBarry Smith #undef __FUNCT__
2353acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsBegin_Private"
2453acd3b1SBarry Smith /*
2553acd3b1SBarry Smith     Handles setting up the data structure in a call to PetscOptionsBegin()
2653acd3b1SBarry Smith */
2753acd3b1SBarry Smith PetscErrorCode PetscOptionsBegin_Private(MPI_Comm comm,const char prefix[],const char title[],const char mansec[])
2853acd3b1SBarry Smith {
2953acd3b1SBarry Smith   PetscErrorCode ierr;
3053acd3b1SBarry Smith 
3153acd3b1SBarry Smith   PetscFunctionBegin;
3253acd3b1SBarry Smith   PetscOptionsObject.next          = 0;
3353acd3b1SBarry Smith   PetscOptionsObject.comm          = comm;
346356e834SBarry Smith   PetscOptionsObject.changedmethod = PETSC_FALSE;
35f8d0b74dSMatthew Knepley   if (PetscOptionsObject.prefix) {
36503cfb0cSBarry Smith     ierr = PetscFree(PetscOptionsObject.prefix);CHKERRQ(ierr); PetscOptionsObject.prefix = 0;
37f8d0b74dSMatthew Knepley   }
3853acd3b1SBarry Smith   ierr = PetscStrallocpy(prefix,&PetscOptionsObject.prefix);CHKERRQ(ierr);
39f8d0b74dSMatthew Knepley   if (PetscOptionsObject.title) {
40503cfb0cSBarry Smith     ierr = PetscFree(PetscOptionsObject.title);CHKERRQ(ierr); PetscOptionsObject.title  = 0;
41f8d0b74dSMatthew Knepley   }
4253acd3b1SBarry Smith   ierr = PetscStrallocpy(title,&PetscOptionsObject.title);CHKERRQ(ierr);
4353acd3b1SBarry Smith 
4453acd3b1SBarry Smith   ierr = PetscOptionsHasName(PETSC_NULL,"-help",&PetscOptionsObject.printhelp);CHKERRQ(ierr);
4553acd3b1SBarry Smith   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
4661b37b28SSatish Balay     if (!PetscOptionsObject.alreadyprinted) {
4753acd3b1SBarry Smith       ierr = (*PetscHelpPrintf)(comm,"%s -------------------------------------------------\n",title);CHKERRQ(ierr);
4853acd3b1SBarry Smith     }
4961b37b28SSatish Balay   }
5053acd3b1SBarry Smith   PetscFunctionReturn(0);
5153acd3b1SBarry Smith }
5253acd3b1SBarry Smith 
5353acd3b1SBarry Smith /*
5453acd3b1SBarry Smith      Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd()
5553acd3b1SBarry Smith */
5653acd3b1SBarry Smith #undef __FUNCT__
5753acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsCreate_Private"
58e3ed6ec8SBarry Smith static int PetscOptionsCreate_Private(const char opt[],const char text[],const char man[],PetscOptionType t,PetscOptions *amsopt)
5953acd3b1SBarry Smith {
6053acd3b1SBarry Smith   int          ierr;
6153acd3b1SBarry Smith   PetscOptions next;
6253acd3b1SBarry Smith 
6353acd3b1SBarry Smith   PetscFunctionBegin;
64e3ed6ec8SBarry Smith   ierr             = PetscNew(struct _p_PetscOptions,amsopt);CHKERRQ(ierr);
6553acd3b1SBarry Smith   (*amsopt)->next  = 0;
6653acd3b1SBarry Smith   (*amsopt)->set   = PETSC_FALSE;
676356e834SBarry Smith   (*amsopt)->type  = t;
6853acd3b1SBarry Smith   (*amsopt)->data  = 0;
6961b37b28SSatish Balay 
7053acd3b1SBarry Smith   ierr             = PetscStrallocpy(text,&(*amsopt)->text);CHKERRQ(ierr);
7153acd3b1SBarry Smith   ierr             = PetscStrallocpy(opt,&(*amsopt)->option);CHKERRQ(ierr);
726356e834SBarry Smith   ierr             = PetscStrallocpy(man,&(*amsopt)->man);CHKERRQ(ierr);
7353acd3b1SBarry Smith 
7453acd3b1SBarry Smith   if (!PetscOptionsObject.next) {
7553acd3b1SBarry Smith     PetscOptionsObject.next = *amsopt;
7653acd3b1SBarry Smith   } else {
7753acd3b1SBarry Smith     next = PetscOptionsObject.next;
7853acd3b1SBarry Smith     while (next->next) next = next->next;
7953acd3b1SBarry Smith     next->next = *amsopt;
8053acd3b1SBarry Smith   }
8153acd3b1SBarry Smith   PetscFunctionReturn(0);
8253acd3b1SBarry Smith }
8353acd3b1SBarry Smith 
8453acd3b1SBarry Smith #undef __FUNCT__
85aee2cecaSBarry Smith #define __FUNCT__ "PetscScanString"
86aee2cecaSBarry Smith /*
873fc1eb6aSBarry Smith     PetscScanString -  Gets user input via stdin from process and broadcasts to all processes
883fc1eb6aSBarry Smith 
893fc1eb6aSBarry Smith     Collective on MPI_Comm
903fc1eb6aSBarry Smith 
913fc1eb6aSBarry Smith    Input Parameters:
923fc1eb6aSBarry Smith +     commm - communicator for the broadcast, must be PETSC_COMM_WORLD
933fc1eb6aSBarry Smith .     n - length of the string, must be the same on all processes
943fc1eb6aSBarry Smith -     str - location to store input
95aee2cecaSBarry Smith 
96aee2cecaSBarry Smith     Bugs:
97aee2cecaSBarry Smith .   Assumes process 0 of the given communicator has access to stdin
98aee2cecaSBarry Smith 
99aee2cecaSBarry Smith */
1003fc1eb6aSBarry Smith static PetscErrorCode PetscScanString(MPI_Comm comm,size_t n,char str[])
101aee2cecaSBarry Smith {
102330cf3c9SBarry Smith   size_t         i;
103aee2cecaSBarry Smith   char           c;
1043fc1eb6aSBarry Smith   PetscMPIInt    rank,nm;
105aee2cecaSBarry Smith   PetscErrorCode ierr;
106aee2cecaSBarry Smith 
107aee2cecaSBarry Smith   PetscFunctionBegin;
108aee2cecaSBarry Smith   ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
109aee2cecaSBarry Smith   if (!rank) {
110aee2cecaSBarry Smith     c = (char) getchar();
111aee2cecaSBarry Smith     i = 0;
112aee2cecaSBarry Smith     while ( c != '\n' && i < n-1) {
113aee2cecaSBarry Smith       str[i++] = c;
114aee2cecaSBarry Smith       c = (char) getchar();
115aee2cecaSBarry Smith     }
116aee2cecaSBarry Smith     str[i] = 0;
117aee2cecaSBarry Smith   }
1183fc1eb6aSBarry Smith   nm   = PetscMPIIntCast(n);
1193fc1eb6aSBarry Smith   ierr = MPI_Bcast(str,nm,MPI_CHAR,0,comm);CHKERRQ(ierr);
120aee2cecaSBarry Smith   PetscFunctionReturn(0);
121aee2cecaSBarry Smith }
122aee2cecaSBarry Smith 
123aee2cecaSBarry Smith #undef __FUNCT__
124aee2cecaSBarry Smith #define __FUNCT__ "PetscOptionsGetFromTextInput"
125aee2cecaSBarry Smith /*
1263cc1e11dSBarry Smith     PetscOptionsGetFromTextInput - Presents all the PETSc Options processed by the program so the user may change them at runtime
127aee2cecaSBarry Smith 
128aee2cecaSBarry Smith     Notes: this isn't really practical, it is just to demonstrate the principle
129aee2cecaSBarry Smith 
130aee2cecaSBarry Smith     Bugs:
131aee2cecaSBarry Smith +    All processes must traverse through the exact same set of option queries do to the call to PetscScanString()
1323cc1e11dSBarry Smith .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
133aee2cecaSBarry Smith -    Only works for PetscInt == int, PetscReal == double etc
134aee2cecaSBarry Smith 
1353cc1e11dSBarry Smith     Developer Notes: Normally the GUI that presents the options the user and retrieves the values would be running in a different
1363cc1e11dSBarry Smith      address space and communicating with the PETSc program
1373cc1e11dSBarry Smith 
138aee2cecaSBarry Smith */
139aee2cecaSBarry Smith PetscErrorCode PetscOptionsGetFromTextInput()
1406356e834SBarry Smith {
1416356e834SBarry Smith   PetscErrorCode ierr;
1426356e834SBarry Smith   PetscOptions   next = PetscOptionsObject.next;
1436356e834SBarry Smith   char           str[512];
144a4404d99SBarry Smith   PetscInt       id;
145a4404d99SBarry Smith   PetscReal      ir,*valr;
146330cf3c9SBarry Smith   PetscInt       *vald;
147330cf3c9SBarry Smith   size_t         i;
1486356e834SBarry Smith 
149e26ddf31SBarry Smith   ierr = (*PetscPrintf)(PETSC_COMM_WORLD,"%s -------------------------------------------------\n",PetscOptionsObject.title);CHKERRQ(ierr);
1506356e834SBarry Smith   while (next) {
1516356e834SBarry Smith     switch (next->type) {
1526356e834SBarry Smith       case OPTION_HEAD:
1536356e834SBarry Smith         break;
154e26ddf31SBarry Smith       case OPTION_INT_ARRAY:
155e26ddf31SBarry Smith         ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1);CHKERRQ(ierr);
156e26ddf31SBarry Smith         vald = (PetscInt*) next->data;
157e26ddf31SBarry Smith         for (i=0; i<next->arraylength; i++) {
158e26ddf31SBarry Smith           ierr = PetscPrintf(PETSC_COMM_WORLD,"%d",vald[i]);CHKERRQ(ierr);
159e26ddf31SBarry Smith           if (i < next->arraylength-1) {
160e26ddf31SBarry Smith             ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr);
161e26ddf31SBarry Smith           }
162e26ddf31SBarry Smith         }
163e26ddf31SBarry Smith         ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s)",next->text,next->man);CHKERRQ(ierr);
164e26ddf31SBarry Smith         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
165e26ddf31SBarry Smith         if (str[0]) {
166e26ddf31SBarry Smith           PetscToken token;
167e26ddf31SBarry Smith           PetscInt   n=0,nmax = next->arraylength,*dvalue = (PetscInt*)next->data,start,end;
168e26ddf31SBarry Smith           size_t     len;
169e26ddf31SBarry Smith           char*      value;
170e26ddf31SBarry Smith           PetscTruth foundrange;
171e26ddf31SBarry Smith 
172e26ddf31SBarry Smith           next->set = PETSC_TRUE;
173e26ddf31SBarry Smith           value = str;
174e26ddf31SBarry Smith 	  ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr);
175e26ddf31SBarry Smith 	  ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
176e26ddf31SBarry Smith 	  while (n < nmax) {
177e26ddf31SBarry Smith 	    if (!value) break;
178e26ddf31SBarry Smith 
179e26ddf31SBarry Smith 	    /* look for form  d-D where d and D are integers */
180e26ddf31SBarry Smith 	    foundrange = PETSC_FALSE;
181e26ddf31SBarry Smith 	    ierr      = PetscStrlen(value,&len);CHKERRQ(ierr);
182e26ddf31SBarry Smith 	    if (value[0] == '-') i=2;
183e26ddf31SBarry Smith 	    else i=1;
184330cf3c9SBarry Smith 	    for (;i<len; i++) {
185e26ddf31SBarry Smith 	      if (value[i] == '-') {
186e32f2f54SBarry Smith 		if (i == len-1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry %s\n",n,value);
187e26ddf31SBarry Smith 		value[i] = 0;
188e26ddf31SBarry Smith 		ierr     = PetscOptionsAtoi(value,&start);CHKERRQ(ierr);
189e26ddf31SBarry Smith 		ierr     = PetscOptionsAtoi(value+i+1,&end);CHKERRQ(ierr);
190e32f2f54SBarry 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);
191e32f2f54SBarry 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);
192e26ddf31SBarry Smith 		for (;start<end; start++) {
193e26ddf31SBarry Smith 		  *dvalue = start; dvalue++;n++;
194e26ddf31SBarry Smith 		}
195e26ddf31SBarry Smith 		foundrange = PETSC_TRUE;
196e26ddf31SBarry Smith 		break;
197e26ddf31SBarry Smith 	      }
198e26ddf31SBarry Smith 	    }
199e26ddf31SBarry Smith 	    if (!foundrange) {
200e26ddf31SBarry Smith 	      ierr      = PetscOptionsAtoi(value,dvalue);CHKERRQ(ierr);
201e26ddf31SBarry Smith 	      dvalue++;
202e26ddf31SBarry Smith 	      n++;
203e26ddf31SBarry Smith 	    }
204e26ddf31SBarry Smith 	    ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
205e26ddf31SBarry Smith 	  }
206e26ddf31SBarry Smith 	  ierr = PetscTokenDestroy(token);CHKERRQ(ierr);
207e26ddf31SBarry Smith         }
208e26ddf31SBarry Smith         break;
209e26ddf31SBarry Smith       case OPTION_REAL_ARRAY:
210e26ddf31SBarry Smith         ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1);CHKERRQ(ierr);
211e26ddf31SBarry Smith         valr = (PetscReal*) next->data;
212e26ddf31SBarry Smith         for (i=0; i<next->arraylength; i++) {
213e26ddf31SBarry Smith           ierr = PetscPrintf(PETSC_COMM_WORLD,"%g",valr[i]);CHKERRQ(ierr);
214e26ddf31SBarry Smith           if (i < next->arraylength-1) {
215e26ddf31SBarry Smith             ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr);
216e26ddf31SBarry Smith           }
217e26ddf31SBarry Smith         }
218e26ddf31SBarry Smith         ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s)",next->text,next->man);CHKERRQ(ierr);
219e26ddf31SBarry Smith         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
220e26ddf31SBarry Smith         if (str[0]) {
221e26ddf31SBarry Smith           PetscToken token;
222e26ddf31SBarry Smith           PetscInt   n=0,nmax = next->arraylength;
223e26ddf31SBarry Smith           PetscReal   *dvalue = (PetscReal*)next->data;
224e26ddf31SBarry Smith           char*      value;
225e26ddf31SBarry Smith 
226e26ddf31SBarry Smith           next->set = PETSC_TRUE;
227e26ddf31SBarry Smith           value = str;
228e26ddf31SBarry Smith 	  ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr);
229e26ddf31SBarry Smith 	  ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
230e26ddf31SBarry Smith 	  while (n < nmax) {
231e26ddf31SBarry Smith 	    if (!value) break;
232e26ddf31SBarry Smith             ierr      = PetscOptionsAtod(value,dvalue);CHKERRQ(ierr);
233e26ddf31SBarry Smith 	    dvalue++;
234e26ddf31SBarry Smith 	    n++;
235e26ddf31SBarry Smith 	    ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
236e26ddf31SBarry Smith 	  }
237e26ddf31SBarry Smith 	  ierr = PetscTokenDestroy(token);CHKERRQ(ierr);
238e26ddf31SBarry Smith         }
239e26ddf31SBarry Smith         break;
2406356e834SBarry Smith       case OPTION_INT:
241e26ddf31SBarry 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);
2423fc1eb6aSBarry Smith         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
2433fc1eb6aSBarry Smith         if (str[0]) {
244c272547aSJed Brown #if defined(PETSC_USE_64BIT_INDICES)
245c272547aSJed Brown           sscanf(str,"%lld",&id);
246c272547aSJed Brown #else
247aee2cecaSBarry Smith           sscanf(str,"%d",&id);
248c272547aSJed Brown #endif
249aee2cecaSBarry Smith           next->set = PETSC_TRUE;
250aee2cecaSBarry Smith           *((PetscInt*)next->data) = id;
251aee2cecaSBarry Smith         }
252aee2cecaSBarry Smith         break;
253aee2cecaSBarry Smith       case OPTION_REAL:
254e26ddf31SBarry 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);
2553fc1eb6aSBarry Smith         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
2563fc1eb6aSBarry Smith         if (str[0]) {
257a4404d99SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE)
258a4404d99SBarry Smith           sscanf(str,"%e",&ir);
259a4404d99SBarry Smith #else
260aee2cecaSBarry Smith           sscanf(str,"%le",&ir);
261a4404d99SBarry Smith #endif
262aee2cecaSBarry Smith           next->set = PETSC_TRUE;
263aee2cecaSBarry Smith           *((PetscReal*)next->data) = ir;
264aee2cecaSBarry Smith         }
265aee2cecaSBarry Smith         break;
266aee2cecaSBarry Smith       case OPTION_LOGICAL:
267aee2cecaSBarry Smith       case OPTION_STRING:
268e26ddf31SBarry 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);
2693fc1eb6aSBarry Smith         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
2703fc1eb6aSBarry Smith         if (str[0]) {
271aee2cecaSBarry Smith           next->set = PETSC_TRUE;
272330cf3c9SBarry Smith           ierr = PetscStrcpy((char*)next->data,str);CHKERRQ(ierr);
2736356e834SBarry Smith         }
2746356e834SBarry Smith         break;
2753cc1e11dSBarry Smith       case OPTION_LIST:
2763cc1e11dSBarry Smith         ierr = PetscFListPrintTypes(PETSC_COMM_WORLD,stdout,PetscOptionsObject.prefix,next->option,next->text,next->man,next->flist,(char*)next->data);CHKERRQ(ierr);
2773cc1e11dSBarry Smith         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
2783cc1e11dSBarry Smith         if (str[0]) {
2793cc1e11dSBarry Smith 	  PetscOptionsObject.changedmethod = PETSC_TRUE;
2803cc1e11dSBarry Smith           next->set = PETSC_TRUE;
281330cf3c9SBarry Smith           ierr = PetscStrcpy((char*)next->data,str);CHKERRQ(ierr);
2823cc1e11dSBarry Smith         }
2833cc1e11dSBarry Smith         break;
284b432afdaSMatthew Knepley     default:
285b432afdaSMatthew Knepley       break;
2866356e834SBarry Smith     }
2876356e834SBarry Smith     next = next->next;
2886356e834SBarry Smith   }
2896356e834SBarry Smith   PetscFunctionReturn(0);
2906356e834SBarry Smith }
2916356e834SBarry Smith 
292b3506946SBarry Smith #if defined(PETSC_HAVE_AMS)
2931ae3d29cSBarry Smith #define CHKERRAMS(err)  if (err) {char *msg; AMS_Explain_error((err), &(msg)); SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"AMS Error: %s",msg);}
2941ae3d29cSBarry Smith #define CHKERRAMSFieldName(err,fn)  if (err) {char *msg; AMS_Explain_error((err), &(msg)); SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Fieldname %s, AMS Error: %s",fn,msg);}
295d5649816SBarry Smith 
296d5649816SBarry Smith static int  count = 0;
297d5649816SBarry Smith 
298b3506946SBarry Smith #undef __FUNCT__
299d5649816SBarry Smith #define __FUNCT__ "PetscOptionsAMSDestroy"
300d5649816SBarry Smith PetscErrorCode PetscOptionsAMSDestroy(void)
301d5649816SBarry Smith {
302d5649816SBarry Smith   PetscErrorCode ierr;
303d5649816SBarry Smith   AMS_Comm       acomm = -1;
304d5649816SBarry Smith   AMS_Memory     amem = -1;
305d5649816SBarry Smith   char           options[16];
306d5649816SBarry Smith   const char     *string = "Exit";
307d5649816SBarry Smith 
308d5649816SBarry Smith   /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */
309d5649816SBarry Smith   ierr = PetscViewerAMSGetAMSComm(PETSC_VIEWER_AMS_(PETSC_COMM_WORLD),&acomm);CHKERRQ(ierr);
310d5649816SBarry Smith   sprintf(options,"Options_%d",count++);
311d5649816SBarry Smith   ierr = AMS_Memory_create(acomm,options,&amem);CHKERRAMS(ierr);
312d5649816SBarry Smith   ierr = AMS_Memory_add_field(amem,"Exit",&string,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,"Exit");
313d5649816SBarry Smith 
314d5649816SBarry Smith   ierr = AMS_Memory_take_access(amem);CHKERRAMS(ierr);
315d5649816SBarry Smith   ierr = AMS_Memory_publish(amem);CHKERRAMS(ierr);
316d5649816SBarry Smith   ierr = AMS_Memory_grant_access(amem);CHKERRAMS(ierr);
317d5649816SBarry Smith   /* wait until accessor has unlocked the memory */
318d5649816SBarry Smith   ierr = AMS_Memory_lock(amem,0);CHKERRAMS(ierr);
319d5649816SBarry Smith   ierr = AMS_Memory_take_access(amem);CHKERRAMS(ierr);
320d5649816SBarry Smith   ierr = AMS_Memory_grant_access(amem);CHKERRAMS(ierr);
321d5649816SBarry Smith   ierr = AMS_Memory_destroy(amem);CHKERRAMS(ierr);
322d5649816SBarry Smith   PetscFunctionReturn(0);
323d5649816SBarry Smith }
324d5649816SBarry Smith 
325d5649816SBarry Smith #undef __FUNCT__
326d5649816SBarry Smith #define __FUNCT__ "PetscOptionsAMSInput"
327b3506946SBarry Smith /*
328d5649816SBarry Smith     PetscOptionsAMSInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the AMS
329b3506946SBarry Smith 
330b3506946SBarry Smith     Bugs:
331b3506946SBarry Smith +    All processes must traverse through the exact same set of option queries do to the call to PetscScanString()
332b3506946SBarry Smith .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
333b3506946SBarry Smith -    Only works for PetscInt == int, PetscReal == double etc
334b3506946SBarry Smith 
335b3506946SBarry Smith 
336b3506946SBarry Smith */
337d5649816SBarry Smith PetscErrorCode PetscOptionsAMSInput()
338b3506946SBarry Smith {
339b3506946SBarry Smith   PetscErrorCode ierr;
340b3506946SBarry Smith   PetscOptions   next = PetscOptionsObject.next;
341d5649816SBarry Smith   static int     mancount = 0;
342b3506946SBarry Smith   char           options[16];
343b3506946SBarry Smith   AMS_Comm       acomm = -1;
344b3506946SBarry Smith   AMS_Memory     amem = -1;
345b3506946SBarry Smith   PetscTruth     changedmethod = PETSC_FALSE;
3469f32e415SBarry Smith   char           manname[16];
347b3506946SBarry Smith 
348b3506946SBarry Smith   /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */
349b3506946SBarry Smith   ierr = PetscViewerAMSGetAMSComm(PETSC_VIEWER_AMS_(PETSC_COMM_WORLD),&acomm);CHKERRQ(ierr);
350b3506946SBarry Smith   sprintf(options,"Options_%d",count++);
3511ae3d29cSBarry Smith   ierr = AMS_Memory_create(acomm,options,&amem);CHKERRAMS(ierr);
3521ae3d29cSBarry Smith   ierr = AMS_Memory_take_access(amem);CHKERRAMS(ierr);
3531bc75a8dSBarry Smith   PetscOptionsObject.pprefix = PetscOptionsObject.prefix; /* AMS will change this, so cannot pass prefix directly */
3541bc75a8dSBarry Smith 
3551ae3d29cSBarry Smith   ierr = AMS_Memory_add_field(amem,PetscOptionsObject.title,&PetscOptionsObject.pprefix,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,PetscOptionsObject.title);
3561ae3d29cSBarry Smith   //  ierr = AMS_Memory_add_field(amem,"mansec",&PetscOptionsObject.pprefix,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMS(ierr);
3571ae3d29cSBarry Smith   ierr = AMS_Memory_add_field(amem,"ChangedMethod",&changedmethod,1,AMS_BOOLEAN,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,"ChangedMethod");
358b3506946SBarry Smith 
359b3506946SBarry Smith   while (next) {
3601ae3d29cSBarry Smith     ierr = AMS_Memory_add_field(amem,next->option,&next->set,1,AMS_INT,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->option);
3611bc75a8dSBarry Smith     ierr =  PetscMalloc(sizeof(char*),&next->pman);CHKERRQ(ierr);
3621bc75a8dSBarry Smith     *(char **)next->pman = next->man;
3639f32e415SBarry Smith     sprintf(manname,"man_%d",mancount++);
3641ae3d29cSBarry Smith     ierr = AMS_Memory_add_field(amem,manname,next->pman,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,manname);
3659f32e415SBarry Smith 
366b3506946SBarry Smith     switch (next->type) {
367b3506946SBarry Smith       case OPTION_HEAD:
368b3506946SBarry Smith         break;
369b3506946SBarry Smith       case OPTION_INT_ARRAY:
3701ae3d29cSBarry Smith         ierr = AMS_Memory_add_field(amem,next->text,next->data,next->arraylength,AMS_INT,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
371b3506946SBarry Smith         break;
372b3506946SBarry Smith       case OPTION_REAL_ARRAY:
3731ae3d29cSBarry Smith         ierr = AMS_Memory_add_field(amem,next->text,next->data,next->arraylength,AMS_DOUBLE,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
374b3506946SBarry Smith         break;
375b3506946SBarry Smith       case OPTION_INT:
3761ae3d29cSBarry Smith 	ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_INT,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
377b3506946SBarry Smith         break;
378b3506946SBarry Smith       case OPTION_REAL:
3791ae3d29cSBarry Smith 	ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_DOUBLE,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
380b3506946SBarry Smith         break;
381b3506946SBarry Smith       case OPTION_LOGICAL:
3821ae3d29cSBarry Smith 	ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_BOOLEAN,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
3831ae3d29cSBarry Smith         break;
3841ae3d29cSBarry Smith       case OPTION_LOGICAL_ARRAY:
3851ae3d29cSBarry Smith 	ierr = AMS_Memory_add_field(amem,next->text,next->data,next->arraylength,AMS_BOOLEAN,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
38671f08665SBarry Smith         break;
387b3506946SBarry Smith       case OPTION_STRING:
3881ae3d29cSBarry Smith 	ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
3891ae3d29cSBarry Smith         break;
3901ae3d29cSBarry Smith       case OPTION_STRING_ARRAY:
3911ae3d29cSBarry Smith 	ierr = AMS_Memory_add_field(amem,next->text,next->data,next->arraylength,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
392b3506946SBarry Smith         break;
393b3506946SBarry Smith       case OPTION_LIST:
39471f08665SBarry Smith         {PetscInt  ntext;
39571f08665SBarry Smith         char       ldefault[128];
39671f08665SBarry Smith 	ierr = PetscStrcpy(ldefault,"DEFAULT:");CHKERRQ(ierr);
39771f08665SBarry Smith 	ierr = PetscStrcat(ldefault,next->text);CHKERRQ(ierr);
3981ae3d29cSBarry Smith 	ierr = AMS_Memory_add_field(amem,ldefault,next->data,1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,ldefault);
39971f08665SBarry Smith 	ierr = PetscFListGet(next->flist,(char***)&next->edata,&ntext);CHKERRQ(ierr);
400d5649816SBarry Smith 	ierr = AMS_Memory_add_field(amem,next->text,next->edata,ntext-1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
4011ae3d29cSBarry Smith         break;}
4021ae3d29cSBarry Smith       case OPTION_ELIST:
403d5649816SBarry Smith         {PetscInt  ntext = next->nlist;
4041ae3d29cSBarry Smith         char       ldefault[128];
4051ae3d29cSBarry Smith 	ierr = PetscStrcpy(ldefault,"DEFAULT:");CHKERRQ(ierr);
4061ae3d29cSBarry Smith 	ierr = PetscStrcat(ldefault,next->text);CHKERRQ(ierr);
4071ae3d29cSBarry Smith 	ierr = AMS_Memory_add_field(amem,ldefault,next->data,1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,ldefault);
4081ae3d29cSBarry Smith 	ierr = PetscMalloc((ntext+1)*sizeof(char**),&next->edata);CHKERRQ(ierr);
4091ae3d29cSBarry Smith         ierr = PetscMemcpy(next->edata,next->list,ntext*sizeof(char*));CHKERRQ(ierr);
4101ae3d29cSBarry Smith 	ierr = AMS_Memory_add_field(amem,next->text,next->edata,ntext,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
41171f08665SBarry Smith         break;}
412b3506946SBarry Smith     default:
413b3506946SBarry Smith       break;
414b3506946SBarry Smith     }
415b3506946SBarry Smith     next = next->next;
416b3506946SBarry Smith   }
417b3506946SBarry Smith 
4181ae3d29cSBarry Smith   ierr = AMS_Memory_publish(amem);CHKERRAMS(ierr);
4191ae3d29cSBarry Smith   ierr = AMS_Memory_grant_access(amem);CHKERRAMS(ierr);
420b3506946SBarry Smith   /* wait until accessor has unlocked the memory */
4211ae3d29cSBarry Smith   ierr = AMS_Memory_lock(amem,0);CHKERRAMS(ierr);
4221ae3d29cSBarry Smith   ierr = AMS_Memory_take_access(amem);CHKERRAMS(ierr);
423b3506946SBarry Smith 
424b3506946SBarry Smith   /* reset counter to -2; this updates the screen with the new options for the selected method */
425b3506946SBarry Smith   if (changedmethod) PetscOptionsPublishCount = -2;
426b3506946SBarry Smith 
4271ae3d29cSBarry Smith   ierr = AMS_Memory_grant_access(amem);CHKERRAMS(ierr);
4281ae3d29cSBarry Smith   ierr = AMS_Memory_destroy(amem);CHKERRAMS(ierr);
429b3506946SBarry Smith   PetscFunctionReturn(0);
430b3506946SBarry Smith }
431b3506946SBarry Smith #endif
432b3506946SBarry Smith 
4336356e834SBarry Smith #undef __FUNCT__
43453acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsEnd_Private"
43553acd3b1SBarry Smith PetscErrorCode PetscOptionsEnd_Private(void)
43653acd3b1SBarry Smith {
43753acd3b1SBarry Smith   PetscErrorCode ierr;
4386356e834SBarry Smith   PetscOptions   last;
4396356e834SBarry Smith   char           option[256],value[1024],tmp[32];
440330cf3c9SBarry Smith   size_t         j;
44153acd3b1SBarry Smith 
44253acd3b1SBarry Smith   PetscFunctionBegin;
4436356e834SBarry Smith 
4441bc75a8dSBarry Smith   CHKMEMQ;
445aee2cecaSBarry Smith   if (PetscOptionsObject.next) {
446b3506946SBarry Smith     if (!PetscOptionsPublishCount) {
447b3506946SBarry Smith #if defined(PETSC_HAVE_AMS)
448d5649816SBarry Smith       ierr = PetscOptionsAMSInput();CHKERRQ(ierr);
449b3506946SBarry Smith #else
45071f08665SBarry Smith       ierr = PetscOptionsGetFromTextInput();CHKERRQ(ierr);
451b3506946SBarry Smith #endif
452aee2cecaSBarry Smith     }
453aee2cecaSBarry Smith   }
4546356e834SBarry Smith 
455503cfb0cSBarry Smith   ierr = PetscFree(PetscOptionsObject.title);CHKERRQ(ierr); PetscOptionsObject.title  = 0;
456503cfb0cSBarry Smith   ierr = PetscFree(PetscOptionsObject.prefix);CHKERRQ(ierr); PetscOptionsObject.prefix = 0;
4576356e834SBarry Smith 
4586356e834SBarry Smith   /* reset counter to -2; this updates the screen with the new options for the selected method */
4596356e834SBarry Smith   if (PetscOptionsObject.changedmethod) PetscOptionsPublishCount = -2;
46061b37b28SSatish Balay   /* reset alreadyprinted flag */
46161b37b28SSatish Balay   PetscOptionsObject.alreadyprinted = PETSC_FALSE;
4626356e834SBarry Smith 
4636356e834SBarry Smith   while (PetscOptionsObject.next) {
4646356e834SBarry Smith     if (PetscOptionsObject.next->set) {
4656356e834SBarry Smith       if (PetscOptionsObject.prefix) {
4666356e834SBarry Smith         ierr = PetscStrcpy(option,"-");CHKERRQ(ierr);
4676356e834SBarry Smith         ierr = PetscStrcat(option,PetscOptionsObject.prefix);CHKERRQ(ierr);
4686356e834SBarry Smith         ierr = PetscStrcat(option,PetscOptionsObject.next->option+1);CHKERRQ(ierr);
4696356e834SBarry Smith       } else {
4706356e834SBarry Smith         ierr = PetscStrcpy(option,PetscOptionsObject.next->option);CHKERRQ(ierr);
4716356e834SBarry Smith       }
4726356e834SBarry Smith 
4736356e834SBarry Smith       switch (PetscOptionsObject.next->type) {
4746356e834SBarry Smith         case OPTION_HEAD:
4756356e834SBarry Smith           break;
476e26ddf31SBarry Smith         case OPTION_INT_ARRAY:
477e26ddf31SBarry Smith           sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[0]);
478e26ddf31SBarry Smith           for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
479e26ddf31SBarry Smith             sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[j]);
480e26ddf31SBarry Smith             ierr = PetscStrcat(value,",");CHKERRQ(ierr);
481e26ddf31SBarry Smith             ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
482e26ddf31SBarry Smith           }
483e26ddf31SBarry Smith           break;
4846356e834SBarry Smith         case OPTION_INT:
4857a72a596SBarry Smith           sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject.next->data);
4866356e834SBarry Smith           break;
4876356e834SBarry Smith         case OPTION_REAL:
4887a72a596SBarry Smith           sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject.next->data);
4896356e834SBarry Smith           break;
4906356e834SBarry Smith         case OPTION_REAL_ARRAY:
4917a72a596SBarry Smith           sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[0]);
4926356e834SBarry Smith           for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
4937a72a596SBarry Smith             sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[j]);
4946356e834SBarry Smith             ierr = PetscStrcat(value,",");CHKERRQ(ierr);
4956356e834SBarry Smith             ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
4966356e834SBarry Smith           }
4976356e834SBarry Smith           break;
4986356e834SBarry Smith         case OPTION_LOGICAL:
49971f08665SBarry Smith           sprintf(value,"%d",*(int*)PetscOptionsObject.next->data);
5006356e834SBarry Smith           break;
5011ae3d29cSBarry Smith       case OPTION_LOGICAL_ARRAY:
5021ae3d29cSBarry Smith           sprintf(value,"%d",(int)((PetscTruth*)PetscOptionsObject.next->data)[0]);
5031ae3d29cSBarry Smith           for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
5041ae3d29cSBarry Smith             sprintf(tmp,"%d",(int)((PetscTruth*)PetscOptionsObject.next->data)[j]);
5051ae3d29cSBarry Smith             ierr = PetscStrcat(value,",");CHKERRQ(ierr);
5061ae3d29cSBarry Smith             ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
5071ae3d29cSBarry Smith           }
5081ae3d29cSBarry Smith           break;
5096356e834SBarry Smith         case OPTION_LIST:
5101ae3d29cSBarry Smith         case OPTION_ELIST:
51171f08665SBarry Smith           ierr = PetscStrcpy(value,*(char**)PetscOptionsObject.next->data);CHKERRQ(ierr);
5126356e834SBarry Smith           break;
5131ae3d29cSBarry Smith         case OPTION_STRING:
51471f08665SBarry Smith           ierr = PetscStrcpy(value,*(char**)PetscOptionsObject.next->data);CHKERRQ(ierr);
5151ae3d29cSBarry Smith         case OPTION_STRING_ARRAY:
5161ae3d29cSBarry Smith           sprintf(value,"%s",((char**)PetscOptionsObject.next->data)[0]);
5171ae3d29cSBarry Smith           for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
5181ae3d29cSBarry Smith             sprintf(tmp,"%s",((char**)PetscOptionsObject.next->data)[j]);
5191ae3d29cSBarry Smith             ierr = PetscStrcat(value,",");CHKERRQ(ierr);
5201ae3d29cSBarry Smith             ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
5211ae3d29cSBarry Smith           }
5226356e834SBarry Smith           break;
5236356e834SBarry Smith       }
5246356e834SBarry Smith       ierr = PetscOptionsSetValue(option,value);CHKERRQ(ierr);
5256356e834SBarry Smith     }
526503cfb0cSBarry Smith     ierr   = PetscFree(PetscOptionsObject.next->text);CHKERRQ(ierr);
527503cfb0cSBarry Smith     ierr   = PetscFree(PetscOptionsObject.next->option);CHKERRQ(ierr);
5286356e834SBarry Smith     ierr   = PetscFree(PetscOptionsObject.next->man);CHKERRQ(ierr);
52905b42c5fSBarry Smith     ierr   = PetscFree(PetscOptionsObject.next->data);CHKERRQ(ierr);
53071f08665SBarry Smith     ierr   = PetscFree(PetscOptionsObject.next->edata);CHKERRQ(ierr);
5316356e834SBarry Smith     last                    = PetscOptionsObject.next;
5326356e834SBarry Smith     PetscOptionsObject.next = PetscOptionsObject.next->next;
5336356e834SBarry Smith     ierr                    = PetscFree(last);CHKERRQ(ierr);
5341bc75a8dSBarry Smith     CHKMEMQ;
5356356e834SBarry Smith   }
5361bc75a8dSBarry Smith   CHKMEMQ;
5376356e834SBarry Smith   PetscOptionsObject.next = 0;
53853acd3b1SBarry Smith   PetscFunctionReturn(0);
53953acd3b1SBarry Smith }
54053acd3b1SBarry Smith 
54153acd3b1SBarry Smith #undef __FUNCT__
54253acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsEnum"
54353acd3b1SBarry Smith /*@C
54453acd3b1SBarry Smith    PetscOptionsEnum - Gets the enum value for a particular option in the database.
54553acd3b1SBarry Smith 
5463f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
54753acd3b1SBarry Smith 
54853acd3b1SBarry Smith    Input Parameters:
54953acd3b1SBarry Smith +  opt - option name
55053acd3b1SBarry Smith .  text - short string that describes the option
55153acd3b1SBarry Smith .  man - manual page with additional information on option
55253acd3b1SBarry Smith .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
55353acd3b1SBarry Smith -  defaultv - the default (current) value
55453acd3b1SBarry Smith 
55553acd3b1SBarry Smith    Output Parameter:
55653acd3b1SBarry Smith +  value - the  value to return
55753acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
55853acd3b1SBarry Smith 
55953acd3b1SBarry Smith    Level: beginner
56053acd3b1SBarry Smith 
56153acd3b1SBarry Smith    Concepts: options database
56253acd3b1SBarry Smith 
56353acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
56453acd3b1SBarry Smith 
56553acd3b1SBarry Smith           list is usually something like PCASMTypes or some other predefined list of enum names
56653acd3b1SBarry Smith 
56753acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
56853acd3b1SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
56953acd3b1SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
57053acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
57153acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
57253acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
57353acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
57453acd3b1SBarry Smith @*/
5752ae9f97cSJed Brown PetscErrorCode PETSC_DLLEXPORT PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const*list,PetscEnum defaultv,PetscEnum *value,PetscTruth *set)
57653acd3b1SBarry Smith {
57753acd3b1SBarry Smith   PetscErrorCode ierr;
57853acd3b1SBarry Smith   PetscInt       ntext = 0;
579aa5bb8c0SSatish Balay   PetscInt       tval;
580aa5bb8c0SSatish Balay   PetscTruth     tflg;
58153acd3b1SBarry Smith 
58253acd3b1SBarry Smith   PetscFunctionBegin;
58353acd3b1SBarry Smith   while (list[ntext++]) {
584e32f2f54SBarry Smith     if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries");
58553acd3b1SBarry Smith   }
586e32f2f54SBarry Smith   if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix");
58753acd3b1SBarry Smith   ntext -= 3;
588aa5bb8c0SSatish Balay   ierr = PetscOptionsEList(opt,text,man,list,ntext,list[defaultv],&tval,&tflg);CHKERRQ(ierr);
589aa5bb8c0SSatish Balay   /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */
590aa5bb8c0SSatish Balay   if (tflg) *value = (PetscEnum)tval;
591aa5bb8c0SSatish Balay   if (set)  *set   = tflg;
59253acd3b1SBarry Smith   PetscFunctionReturn(0);
59353acd3b1SBarry Smith }
59453acd3b1SBarry Smith 
59553acd3b1SBarry Smith /* -------------------------------------------------------------------------------------------------------------*/
59653acd3b1SBarry Smith #undef __FUNCT__
59753acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsInt"
59853acd3b1SBarry Smith /*@C
59953acd3b1SBarry Smith    PetscOptionsInt - Gets the integer value for a particular option in the database.
60053acd3b1SBarry Smith 
6013f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
60253acd3b1SBarry Smith 
60353acd3b1SBarry Smith    Input Parameters:
60453acd3b1SBarry Smith +  opt - option name
60553acd3b1SBarry Smith .  text - short string that describes the option
60653acd3b1SBarry Smith .  man - manual page with additional information on option
60753acd3b1SBarry Smith -  defaultv - the default (current) value
60853acd3b1SBarry Smith 
60953acd3b1SBarry Smith    Output Parameter:
61053acd3b1SBarry Smith +  value - the integer value to return
61153acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
61253acd3b1SBarry Smith 
61353acd3b1SBarry Smith    Level: beginner
61453acd3b1SBarry Smith 
61553acd3b1SBarry Smith    Concepts: options database^has int
61653acd3b1SBarry Smith 
61753acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
61853acd3b1SBarry Smith 
61953acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
62053acd3b1SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
62153acd3b1SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
62253acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
62353acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
62453acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
62553acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
62653acd3b1SBarry Smith @*/
62753acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt defaultv,PetscInt *value,PetscTruth *set)
62853acd3b1SBarry Smith {
62953acd3b1SBarry Smith   PetscErrorCode ierr;
6306356e834SBarry Smith   PetscOptions   amsopt;
63153acd3b1SBarry Smith 
63253acd3b1SBarry Smith   PetscFunctionBegin;
633b3506946SBarry Smith   if (!PetscOptionsPublishCount) {
6346356e834SBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr);
6356356e834SBarry Smith     ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
6366356e834SBarry Smith     *(PetscInt*)amsopt->data = defaultv;
637af6d86caSBarry Smith   }
63853acd3b1SBarry Smith   ierr = PetscOptionsGetInt(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
63961b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
64053acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr);
64153acd3b1SBarry Smith   }
64253acd3b1SBarry Smith   PetscFunctionReturn(0);
64353acd3b1SBarry Smith }
64453acd3b1SBarry Smith 
64553acd3b1SBarry Smith #undef __FUNCT__
64653acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsString"
64753acd3b1SBarry Smith /*@C
64853acd3b1SBarry Smith    PetscOptionsString - Gets the string value for a particular option in the database.
64953acd3b1SBarry Smith 
6503f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
65153acd3b1SBarry Smith 
65253acd3b1SBarry Smith    Input Parameters:
65353acd3b1SBarry Smith +  opt - option name
65453acd3b1SBarry Smith .  text - short string that describes the option
65553acd3b1SBarry Smith .  man - manual page with additional information on option
656*bcbf2dc5SJed Brown .  defaultv - the default (current) value
657*bcbf2dc5SJed Brown -  len - length of the result string including null terminator
65853acd3b1SBarry Smith 
65953acd3b1SBarry Smith    Output Parameter:
66053acd3b1SBarry Smith +  value - the value to return
66153acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
66253acd3b1SBarry Smith 
66353acd3b1SBarry Smith    Level: beginner
66453acd3b1SBarry Smith 
66553acd3b1SBarry Smith    Concepts: options database^has int
66653acd3b1SBarry Smith 
66753acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
66853acd3b1SBarry Smith 
66953acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
67053acd3b1SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
67171f08665SBarry Smith           PetscOptionsInt(), PetscOptionsReal(), PetscOptionsTruth(),
67253acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
67353acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
67453acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
67553acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
67653acd3b1SBarry Smith @*/
67753acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsString(const char opt[],const char text[],const char man[],const char defaultv[],char value[],size_t len,PetscTruth *set)
67853acd3b1SBarry Smith {
67953acd3b1SBarry Smith   PetscErrorCode ierr;
680aee2cecaSBarry Smith   PetscOptions   amsopt;
68153acd3b1SBarry Smith 
68253acd3b1SBarry Smith   PetscFunctionBegin;
683b3506946SBarry Smith   if (!PetscOptionsPublishCount) {
684aee2cecaSBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
68571f08665SBarry Smith     ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr);
68671f08665SBarry Smith     *(const char**)amsopt->data = defaultv;
687af6d86caSBarry Smith   }
68853acd3b1SBarry Smith   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
68961b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
69053acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr);
69153acd3b1SBarry Smith   }
69253acd3b1SBarry Smith   PetscFunctionReturn(0);
69353acd3b1SBarry Smith }
69453acd3b1SBarry Smith 
69553acd3b1SBarry Smith #undef __FUNCT__
69653acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsReal"
69753acd3b1SBarry Smith /*@C
69853acd3b1SBarry Smith    PetscOptionsReal - Gets the PetscReal value for a particular option in the database.
69953acd3b1SBarry Smith 
7003f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
70153acd3b1SBarry Smith 
70253acd3b1SBarry Smith    Input Parameters:
70353acd3b1SBarry Smith +  opt - option name
70453acd3b1SBarry Smith .  text - short string that describes the option
70553acd3b1SBarry Smith .  man - manual page with additional information on option
70653acd3b1SBarry Smith -  defaultv - the default (current) value
70753acd3b1SBarry Smith 
70853acd3b1SBarry Smith    Output Parameter:
70953acd3b1SBarry Smith +  value - the value to return
71053acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
71153acd3b1SBarry Smith 
71253acd3b1SBarry Smith    Level: beginner
71353acd3b1SBarry Smith 
71453acd3b1SBarry Smith    Concepts: options database^has int
71553acd3b1SBarry Smith 
71653acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
71753acd3b1SBarry Smith 
71853acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
71953acd3b1SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
72053acd3b1SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
72153acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
72253acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
72353acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
72453acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
72553acd3b1SBarry Smith @*/
72653acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal defaultv,PetscReal *value,PetscTruth *set)
72753acd3b1SBarry Smith {
72853acd3b1SBarry Smith   PetscErrorCode ierr;
729538aa990SBarry Smith   PetscOptions   amsopt;
73053acd3b1SBarry Smith 
73153acd3b1SBarry Smith   PetscFunctionBegin;
732b3506946SBarry Smith   if (!PetscOptionsPublishCount) {
733538aa990SBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr);
734538aa990SBarry Smith     ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
735538aa990SBarry Smith     *(PetscReal*)amsopt->data = defaultv;
736538aa990SBarry Smith   }
73753acd3b1SBarry Smith   ierr = PetscOptionsGetReal(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
73861b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
739a83599f4SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%G>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr);
74053acd3b1SBarry Smith   }
74153acd3b1SBarry Smith   PetscFunctionReturn(0);
74253acd3b1SBarry Smith }
74353acd3b1SBarry Smith 
74453acd3b1SBarry Smith #undef __FUNCT__
74553acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsScalar"
74653acd3b1SBarry Smith /*@C
74753acd3b1SBarry Smith    PetscOptionsScalar - Gets the scalar value for a particular option in the database.
74853acd3b1SBarry Smith 
7493f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
75053acd3b1SBarry Smith 
75153acd3b1SBarry Smith    Input Parameters:
75253acd3b1SBarry Smith +  opt - option name
75353acd3b1SBarry Smith .  text - short string that describes the option
75453acd3b1SBarry Smith .  man - manual page with additional information on option
75553acd3b1SBarry Smith -  defaultv - the default (current) value
75653acd3b1SBarry Smith 
75753acd3b1SBarry Smith    Output Parameter:
75853acd3b1SBarry Smith +  value - the value to return
75953acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
76053acd3b1SBarry Smith 
76153acd3b1SBarry Smith    Level: beginner
76253acd3b1SBarry Smith 
76353acd3b1SBarry Smith    Concepts: options database^has int
76453acd3b1SBarry Smith 
76553acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
76653acd3b1SBarry Smith 
76753acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
76853acd3b1SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
76953acd3b1SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
77053acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
77153acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
77253acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
77353acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
77453acd3b1SBarry Smith @*/
77553acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar defaultv,PetscScalar *value,PetscTruth *set)
77653acd3b1SBarry Smith {
77753acd3b1SBarry Smith   PetscErrorCode ierr;
77853acd3b1SBarry Smith 
77953acd3b1SBarry Smith   PetscFunctionBegin;
78053acd3b1SBarry Smith #if !defined(PETSC_USE_COMPLEX)
78153acd3b1SBarry Smith   ierr = PetscOptionsReal(opt,text,man,defaultv,value,set);CHKERRQ(ierr);
78253acd3b1SBarry Smith #else
78353acd3b1SBarry Smith   ierr = PetscOptionsGetScalar(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
78453acd3b1SBarry Smith #endif
78553acd3b1SBarry Smith   PetscFunctionReturn(0);
78653acd3b1SBarry Smith }
78753acd3b1SBarry Smith 
78853acd3b1SBarry Smith #undef __FUNCT__
78953acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsName"
79053acd3b1SBarry Smith /*@C
79190d69ab7SBarry 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
79290d69ab7SBarry Smith                       its value is set to false.
79353acd3b1SBarry Smith 
7943f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
79553acd3b1SBarry Smith 
79653acd3b1SBarry Smith    Input Parameters:
79753acd3b1SBarry Smith +  opt - option name
79853acd3b1SBarry Smith .  text - short string that describes the option
79953acd3b1SBarry Smith -  man - manual page with additional information on option
80053acd3b1SBarry Smith 
80153acd3b1SBarry Smith    Output Parameter:
80253acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
80353acd3b1SBarry Smith 
80453acd3b1SBarry Smith    Level: beginner
80553acd3b1SBarry Smith 
80653acd3b1SBarry Smith    Concepts: options database^has int
80753acd3b1SBarry Smith 
80853acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
80953acd3b1SBarry Smith 
81053acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
81153acd3b1SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
81253acd3b1SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
81353acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
81453acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
81553acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
81653acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
81753acd3b1SBarry Smith @*/
81853acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsName(const char opt[],const char text[],const char man[],PetscTruth *flg)
81953acd3b1SBarry Smith {
82053acd3b1SBarry Smith   PetscErrorCode ierr;
8211ae3d29cSBarry Smith   PetscOptions   amsopt;
82253acd3b1SBarry Smith 
82353acd3b1SBarry Smith   PetscFunctionBegin;
8241ae3d29cSBarry Smith   if (!PetscOptionsPublishCount) {
8251ae3d29cSBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
8261ae3d29cSBarry Smith     ierr = PetscMalloc(sizeof(PetscTruth),&amsopt->data);CHKERRQ(ierr);
8271ae3d29cSBarry Smith     *(PetscTruth*)amsopt->data = PETSC_FALSE;
8281ae3d29cSBarry Smith   }
82953acd3b1SBarry Smith   ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr);
83061b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
83153acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
83253acd3b1SBarry Smith   }
83353acd3b1SBarry Smith   PetscFunctionReturn(0);
83453acd3b1SBarry Smith }
83553acd3b1SBarry Smith 
83653acd3b1SBarry Smith #undef __FUNCT__
83753acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsList"
83853acd3b1SBarry Smith /*@C
83953acd3b1SBarry Smith      PetscOptionsList - Puts a list of option values that a single one may be selected from
84053acd3b1SBarry Smith 
8413f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
84253acd3b1SBarry Smith 
84353acd3b1SBarry Smith    Input Parameters:
84453acd3b1SBarry Smith +  opt - option name
84553acd3b1SBarry Smith .  text - short string that describes the option
84653acd3b1SBarry Smith .  man - manual page with additional information on option
84753acd3b1SBarry Smith .  list - the possible choices
8483cc1e11dSBarry Smith .  defaultv - the default (current) value
8493cc1e11dSBarry Smith -  len - the length of the character array value
85053acd3b1SBarry Smith 
85153acd3b1SBarry Smith    Output Parameter:
85253acd3b1SBarry Smith +  value - the value to return
85353acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
85453acd3b1SBarry Smith 
85553acd3b1SBarry Smith    Level: intermediate
85653acd3b1SBarry Smith 
85753acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
85853acd3b1SBarry Smith 
85953acd3b1SBarry Smith    See PetscOptionsEList() for when the choices are given in a string array
86053acd3b1SBarry Smith 
86153acd3b1SBarry Smith    To get a listing of all currently specified options,
86253acd3b1SBarry Smith     see PetscOptionsPrint() or PetscOptionsGetAll()
86353acd3b1SBarry Smith 
86453acd3b1SBarry Smith    Concepts: options database^list
86553acd3b1SBarry Smith 
86653acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
86753acd3b1SBarry Smith            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
86853acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
86953acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
87053acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
87153acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
87253acd3b1SBarry Smith @*/
8733cc1e11dSBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsList(const char opt[],const char ltext[],const char man[],PetscFList list,const char defaultv[],char value[],size_t len,PetscTruth *set)
87453acd3b1SBarry Smith {
87553acd3b1SBarry Smith   PetscErrorCode ierr;
8763cc1e11dSBarry Smith   PetscOptions   amsopt;
87753acd3b1SBarry Smith 
87853acd3b1SBarry Smith   PetscFunctionBegin;
879b3506946SBarry Smith   if (!PetscOptionsPublishCount) {
8803cc1e11dSBarry Smith     ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_LIST,&amsopt);CHKERRQ(ierr);
88171f08665SBarry Smith     ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr);
88271f08665SBarry Smith     *(const char**)amsopt->data = defaultv;
8833cc1e11dSBarry Smith     amsopt->flist = list;
8843cc1e11dSBarry Smith   }
88553acd3b1SBarry Smith   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
88661b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
8873cc1e11dSBarry Smith     ierr = PetscFListPrintTypes(PetscOptionsObject.comm,stdout,PetscOptionsObject.prefix,opt,ltext,man,list,defaultv);CHKERRQ(ierr);CHKERRQ(ierr);
88853acd3b1SBarry Smith   }
88953acd3b1SBarry Smith   PetscFunctionReturn(0);
89053acd3b1SBarry Smith }
89153acd3b1SBarry Smith 
89253acd3b1SBarry Smith #undef __FUNCT__
89353acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsEList"
89453acd3b1SBarry Smith /*@C
89553acd3b1SBarry Smith      PetscOptionsEList - Puts a list of option values that a single one may be selected from
89653acd3b1SBarry Smith 
8973f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
89853acd3b1SBarry Smith 
89953acd3b1SBarry Smith    Input Parameters:
90053acd3b1SBarry Smith +  opt - option name
90153acd3b1SBarry Smith .  ltext - short string that describes the option
90253acd3b1SBarry Smith .  man - manual page with additional information on option
90353acd3b1SBarry Smith .  list - the possible choices
90453acd3b1SBarry Smith .  ntext - number of choices
90553acd3b1SBarry Smith -  defaultv - the default (current) value
90653acd3b1SBarry Smith 
90753acd3b1SBarry Smith    Output Parameter:
90853acd3b1SBarry Smith +  value - the index of the value to return
90953acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
91053acd3b1SBarry Smith 
91153acd3b1SBarry Smith    Level: intermediate
91253acd3b1SBarry Smith 
91353acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
91453acd3b1SBarry Smith 
91553acd3b1SBarry Smith    See PetscOptionsList() for when the choices are given in a PetscFList()
91653acd3b1SBarry Smith 
91753acd3b1SBarry Smith    Concepts: options database^list
91853acd3b1SBarry Smith 
91953acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
92053acd3b1SBarry Smith            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
92153acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
92253acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
92353acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
92453acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
92553acd3b1SBarry Smith @*/
9262ae9f97cSJed Brown PetscErrorCode PETSC_DLLEXPORT PetscOptionsEList(const char opt[],const char ltext[],const char man[],const char *const*list,PetscInt ntext,const char defaultv[],PetscInt *value,PetscTruth *set)
92753acd3b1SBarry Smith {
92853acd3b1SBarry Smith   PetscErrorCode ierr;
92953acd3b1SBarry Smith   PetscInt       i;
9301ae3d29cSBarry Smith   PetscOptions   amsopt;
93153acd3b1SBarry Smith 
93253acd3b1SBarry Smith   PetscFunctionBegin;
9331ae3d29cSBarry Smith   if (!PetscOptionsPublishCount) {
934d5649816SBarry Smith     ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_ELIST,&amsopt);CHKERRQ(ierr);
9351ae3d29cSBarry Smith     ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr);
9361ae3d29cSBarry Smith     *(const char**)amsopt->data = defaultv;
9371ae3d29cSBarry Smith     amsopt->list  = list;
9381ae3d29cSBarry Smith     amsopt->nlist = ntext;
9391ae3d29cSBarry Smith   }
94053acd3b1SBarry Smith   ierr = PetscOptionsGetEList(PetscOptionsObject.prefix,opt,list,ntext,value,set);CHKERRQ(ierr);
94161b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
94253acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s> (choose one of)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv);CHKERRQ(ierr);
94353acd3b1SBarry Smith     for (i=0; i<ntext; i++){
94453acd3b1SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s",list[i]);CHKERRQ(ierr);
94553acd3b1SBarry Smith     }
94653acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"\n");CHKERRQ(ierr);
94753acd3b1SBarry Smith   }
94853acd3b1SBarry Smith   PetscFunctionReturn(0);
94953acd3b1SBarry Smith }
95053acd3b1SBarry Smith 
95153acd3b1SBarry Smith #undef __FUNCT__
95253acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsTruthGroupBegin"
95353acd3b1SBarry Smith /*@C
95453acd3b1SBarry Smith      PetscOptionsTruthGroupBegin - First in a series of logical queries on the options database for
955d5649816SBarry Smith        which at most a single value can be true.
95653acd3b1SBarry Smith 
9573f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
95853acd3b1SBarry Smith 
95953acd3b1SBarry Smith    Input Parameters:
96053acd3b1SBarry Smith +  opt - option name
96153acd3b1SBarry Smith .  text - short string that describes the option
96253acd3b1SBarry Smith -  man - manual page with additional information on option
96353acd3b1SBarry Smith 
96453acd3b1SBarry Smith    Output Parameter:
96553acd3b1SBarry Smith .  flg - whether that option was set or not
96653acd3b1SBarry Smith 
96753acd3b1SBarry Smith    Level: intermediate
96853acd3b1SBarry Smith 
96953acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
97053acd3b1SBarry Smith 
97153acd3b1SBarry Smith    Must be followed by 0 or more PetscOptionsTruthGroup()s and PetscOptionsTruthGroupEnd()
97253acd3b1SBarry Smith 
97353acd3b1SBarry Smith     Concepts: options database^logical group
97453acd3b1SBarry Smith 
97553acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
97653acd3b1SBarry Smith            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
97753acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
97853acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
97953acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
98053acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
98153acd3b1SBarry Smith @*/
98253acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroupBegin(const char opt[],const char text[],const char man[],PetscTruth *flg)
98353acd3b1SBarry Smith {
98453acd3b1SBarry Smith   PetscErrorCode ierr;
9851ae3d29cSBarry Smith   PetscOptions   amsopt;
98653acd3b1SBarry Smith 
98753acd3b1SBarry Smith   PetscFunctionBegin;
9881ae3d29cSBarry Smith   if (!PetscOptionsPublishCount) {
9891ae3d29cSBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
9901ae3d29cSBarry Smith     ierr = PetscMalloc(sizeof(PetscTruth),&amsopt->data);CHKERRQ(ierr);
991d5649816SBarry Smith     *(PetscTruth*)amsopt->data = PETSC_FALSE;
9921ae3d29cSBarry Smith   }
99368b16fdaSBarry Smith   *flg = PETSC_FALSE;
99417326d04SJed Brown   ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr);
99561b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
99653acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  Pick at most one of -------------\n");CHKERRQ(ierr);
99753acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
99853acd3b1SBarry Smith   }
99953acd3b1SBarry Smith   PetscFunctionReturn(0);
100053acd3b1SBarry Smith }
100153acd3b1SBarry Smith 
100253acd3b1SBarry Smith #undef __FUNCT__
100353acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsTruthGroup"
100453acd3b1SBarry Smith /*@C
100553acd3b1SBarry Smith      PetscOptionsTruthGroup - One in a series of logical queries on the options database for
1006d5649816SBarry Smith        which at most a single value can be true.
100753acd3b1SBarry Smith 
10083f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
100953acd3b1SBarry Smith 
101053acd3b1SBarry Smith    Input Parameters:
101153acd3b1SBarry Smith +  opt - option name
101253acd3b1SBarry Smith .  text - short string that describes the option
101353acd3b1SBarry Smith -  man - manual page with additional information on option
101453acd3b1SBarry Smith 
101553acd3b1SBarry Smith    Output Parameter:
101653acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
101753acd3b1SBarry Smith 
101853acd3b1SBarry Smith    Level: intermediate
101953acd3b1SBarry Smith 
102053acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
102153acd3b1SBarry Smith 
102253acd3b1SBarry Smith    Must follow a PetscOptionsTruthGroupBegin() and preceded a PetscOptionsTruthGroupEnd()
102353acd3b1SBarry Smith 
102453acd3b1SBarry Smith     Concepts: options database^logical group
102553acd3b1SBarry Smith 
102653acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
102753acd3b1SBarry Smith            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
102853acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
102953acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
103053acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
103153acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
103253acd3b1SBarry Smith @*/
103353acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroup(const char opt[],const char text[],const char man[],PetscTruth *flg)
103453acd3b1SBarry Smith {
103553acd3b1SBarry Smith   PetscErrorCode ierr;
10361ae3d29cSBarry Smith   PetscOptions   amsopt;
103753acd3b1SBarry Smith 
103853acd3b1SBarry Smith   PetscFunctionBegin;
10391ae3d29cSBarry Smith   if (!PetscOptionsPublishCount) {
10401ae3d29cSBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
10411ae3d29cSBarry Smith     ierr = PetscMalloc(sizeof(PetscTruth),&amsopt->data);CHKERRQ(ierr);
10421ae3d29cSBarry Smith     *(PetscTruth*)amsopt->data = PETSC_FALSE;
10431ae3d29cSBarry Smith   }
104417326d04SJed Brown   *flg = PETSC_FALSE;
104517326d04SJed Brown   ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr);
104661b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
104753acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
104853acd3b1SBarry Smith   }
104953acd3b1SBarry Smith   PetscFunctionReturn(0);
105053acd3b1SBarry Smith }
105153acd3b1SBarry Smith 
105253acd3b1SBarry Smith #undef __FUNCT__
105353acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsTruthGroupEnd"
105453acd3b1SBarry Smith /*@C
105553acd3b1SBarry Smith      PetscOptionsTruthGroupEnd - Last in a series of logical queries on the options database for
1056d5649816SBarry Smith        which at most a single value can be true.
105753acd3b1SBarry Smith 
10583f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
105953acd3b1SBarry Smith 
106053acd3b1SBarry Smith    Input Parameters:
106153acd3b1SBarry Smith +  opt - option name
106253acd3b1SBarry Smith .  text - short string that describes the option
106353acd3b1SBarry Smith -  man - manual page with additional information on option
106453acd3b1SBarry Smith 
106553acd3b1SBarry Smith    Output Parameter:
106653acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
106753acd3b1SBarry Smith 
106853acd3b1SBarry Smith    Level: intermediate
106953acd3b1SBarry Smith 
107053acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
107153acd3b1SBarry Smith 
107253acd3b1SBarry Smith    Must follow a PetscOptionsTruthGroupBegin()
107353acd3b1SBarry Smith 
107453acd3b1SBarry Smith     Concepts: options database^logical group
107553acd3b1SBarry Smith 
107653acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
107753acd3b1SBarry Smith            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
107853acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
107953acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
108053acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
108153acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
108253acd3b1SBarry Smith @*/
108353acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroupEnd(const char opt[],const char text[],const char man[],PetscTruth *flg)
108453acd3b1SBarry Smith {
108553acd3b1SBarry Smith   PetscErrorCode ierr;
10861ae3d29cSBarry Smith   PetscOptions   amsopt;
108753acd3b1SBarry Smith 
108853acd3b1SBarry Smith   PetscFunctionBegin;
10891ae3d29cSBarry Smith   if (!PetscOptionsPublishCount) {
10901ae3d29cSBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
10911ae3d29cSBarry Smith     ierr = PetscMalloc(sizeof(PetscTruth),&amsopt->data);CHKERRQ(ierr);
10921ae3d29cSBarry Smith     *(PetscTruth*)amsopt->data = PETSC_FALSE;
10931ae3d29cSBarry Smith   }
109417326d04SJed Brown   *flg = PETSC_FALSE;
109517326d04SJed Brown   ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr);
109661b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
109753acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
109853acd3b1SBarry Smith   }
109953acd3b1SBarry Smith   PetscFunctionReturn(0);
110053acd3b1SBarry Smith }
110153acd3b1SBarry Smith 
110253acd3b1SBarry Smith #undef __FUNCT__
110353acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsTruth"
110453acd3b1SBarry Smith /*@C
110553acd3b1SBarry Smith    PetscOptionsTruth - Determines if a particular option is in the database with a true or false
110653acd3b1SBarry Smith 
11073f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
110853acd3b1SBarry Smith 
110953acd3b1SBarry Smith    Input Parameters:
111053acd3b1SBarry Smith +  opt - option name
111153acd3b1SBarry Smith .  text - short string that describes the option
111253acd3b1SBarry Smith -  man - manual page with additional information on option
111353acd3b1SBarry Smith 
111453acd3b1SBarry Smith    Output Parameter:
111553acd3b1SBarry Smith .  flg - PETSC_TRUE or PETSC_FALSE
111653acd3b1SBarry Smith .  set - PETSC_TRUE if found, else PETSC_FALSE
111753acd3b1SBarry Smith 
111853acd3b1SBarry Smith    Level: beginner
111953acd3b1SBarry Smith 
112053acd3b1SBarry Smith    Concepts: options database^logical
112153acd3b1SBarry Smith 
112253acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
112353acd3b1SBarry Smith 
112453acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
112553acd3b1SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
112653acd3b1SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
112753acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
112853acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
112953acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
113053acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
113153acd3b1SBarry Smith @*/
113253acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruth(const char opt[],const char text[],const char man[],PetscTruth deflt,PetscTruth *flg,PetscTruth *set)
113353acd3b1SBarry Smith {
113453acd3b1SBarry Smith   PetscErrorCode ierr;
113553acd3b1SBarry Smith   PetscTruth     iset;
1136aee2cecaSBarry Smith   PetscOptions   amsopt;
113753acd3b1SBarry Smith 
113853acd3b1SBarry Smith   PetscFunctionBegin;
1139b3506946SBarry Smith   if (!PetscOptionsPublishCount) {
1140aee2cecaSBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
114171f08665SBarry Smith     ierr = PetscMalloc(sizeof(PetscTruth),&amsopt->data);CHKERRQ(ierr);
114271f08665SBarry Smith     *(PetscTruth*)amsopt->data = deflt;
1143af6d86caSBarry Smith   }
114453acd3b1SBarry Smith   ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,&iset);CHKERRQ(ierr);
114553acd3b1SBarry Smith   if (!iset) {
114653acd3b1SBarry Smith     if (flg) *flg = deflt;
114753acd3b1SBarry Smith   }
114853acd3b1SBarry Smith   if (set) *set = iset;
114961b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
115053acd3b1SBarry Smith     const char *v = PetscTruths[deflt];
115153acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: <%s> %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,v,text,man);CHKERRQ(ierr);
115253acd3b1SBarry Smith   }
115353acd3b1SBarry Smith   PetscFunctionReturn(0);
115453acd3b1SBarry Smith }
115553acd3b1SBarry Smith 
115653acd3b1SBarry Smith #undef __FUNCT__
115753acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsRealArray"
115853acd3b1SBarry Smith /*@C
115953acd3b1SBarry Smith    PetscOptionsRealArray - Gets an array of double values for a particular
116053acd3b1SBarry Smith    option in the database. The values must be separated with commas with
116153acd3b1SBarry Smith    no intervening spaces.
116253acd3b1SBarry Smith 
11633f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
116453acd3b1SBarry Smith 
116553acd3b1SBarry Smith    Input Parameters:
116653acd3b1SBarry Smith +  opt - the option one is seeking
116753acd3b1SBarry Smith .  text - short string describing option
116853acd3b1SBarry Smith .  man - manual page for option
116953acd3b1SBarry Smith -  nmax - maximum number of values
117053acd3b1SBarry Smith 
117153acd3b1SBarry Smith    Output Parameter:
117253acd3b1SBarry Smith +  value - location to copy values
117353acd3b1SBarry Smith .  nmax - actual number of values found
117453acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
117553acd3b1SBarry Smith 
117653acd3b1SBarry Smith    Level: beginner
117753acd3b1SBarry Smith 
117853acd3b1SBarry Smith    Notes:
117953acd3b1SBarry Smith    The user should pass in an array of doubles
118053acd3b1SBarry Smith 
118153acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
118253acd3b1SBarry Smith 
118353acd3b1SBarry Smith    Concepts: options database^array of strings
118453acd3b1SBarry Smith 
118553acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
118653acd3b1SBarry Smith            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
118753acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
118853acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
118953acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
119053acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
119153acd3b1SBarry Smith @*/
119253acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscTruth *set)
119353acd3b1SBarry Smith {
119453acd3b1SBarry Smith   PetscErrorCode ierr;
119553acd3b1SBarry Smith   PetscInt       i;
1196e26ddf31SBarry Smith   PetscOptions   amsopt;
119753acd3b1SBarry Smith 
119853acd3b1SBarry Smith   PetscFunctionBegin;
1199b3506946SBarry Smith   if (!PetscOptionsPublishCount) {
1200e26ddf31SBarry Smith     PetscReal *vals;
1201e26ddf31SBarry Smith 
1202e26ddf31SBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr);
1203e26ddf31SBarry Smith     ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
1204e26ddf31SBarry Smith     vals = (PetscReal*)amsopt->data;
1205e26ddf31SBarry Smith     for (i=0; i<*n; i++) vals[i] = value[i];
1206e26ddf31SBarry Smith     amsopt->arraylength = *n;
1207e26ddf31SBarry Smith   }
120853acd3b1SBarry Smith   ierr = PetscOptionsGetRealArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
120961b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1210a83599f4SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%G",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
121153acd3b1SBarry Smith     for (i=1; i<*n; i++) {
1212a83599f4SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%G",value[i]);CHKERRQ(ierr);
121353acd3b1SBarry Smith     }
121453acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr);
121553acd3b1SBarry Smith   }
121653acd3b1SBarry Smith   PetscFunctionReturn(0);
121753acd3b1SBarry Smith }
121853acd3b1SBarry Smith 
121953acd3b1SBarry Smith 
122053acd3b1SBarry Smith #undef __FUNCT__
122153acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsIntArray"
122253acd3b1SBarry Smith /*@C
122353acd3b1SBarry Smith    PetscOptionsIntArray - Gets an array of integers for a particular
122453acd3b1SBarry Smith    option in the database. The values must be separated with commas with
122553acd3b1SBarry Smith    no intervening spaces.
122653acd3b1SBarry Smith 
12273f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
122853acd3b1SBarry Smith 
122953acd3b1SBarry Smith    Input Parameters:
123053acd3b1SBarry Smith +  opt - the option one is seeking
123153acd3b1SBarry Smith .  text - short string describing option
123253acd3b1SBarry Smith .  man - manual page for option
1233f8a50e2bSBarry Smith -  n - maximum number of values
123453acd3b1SBarry Smith 
123553acd3b1SBarry Smith    Output Parameter:
123653acd3b1SBarry Smith +  value - location to copy values
1237f8a50e2bSBarry Smith .  n - actual number of values found
123853acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
123953acd3b1SBarry Smith 
124053acd3b1SBarry Smith    Level: beginner
124153acd3b1SBarry Smith 
124253acd3b1SBarry Smith    Notes:
124353acd3b1SBarry Smith    The user should pass in an array of integers
124453acd3b1SBarry Smith 
124553acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
124653acd3b1SBarry Smith 
124753acd3b1SBarry Smith    Concepts: options database^array of strings
124853acd3b1SBarry Smith 
124953acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
125053acd3b1SBarry Smith            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
125153acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
125253acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
125353acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
125453acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList(), PetscOptionsRealArray()
125553acd3b1SBarry Smith @*/
125653acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscTruth *set)
125753acd3b1SBarry Smith {
125853acd3b1SBarry Smith   PetscErrorCode ierr;
125953acd3b1SBarry Smith   PetscInt       i;
1260e26ddf31SBarry Smith   PetscOptions   amsopt;
126153acd3b1SBarry Smith 
126253acd3b1SBarry Smith   PetscFunctionBegin;
1263b3506946SBarry Smith   if (!PetscOptionsPublishCount) {
1264e26ddf31SBarry Smith     PetscInt *vals;
1265e26ddf31SBarry Smith 
1266e26ddf31SBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr);
1267e26ddf31SBarry Smith     ierr = PetscMalloc((*n)*sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
1268e26ddf31SBarry Smith     vals = (PetscInt*)amsopt->data;
1269e26ddf31SBarry Smith     for (i=0; i<*n; i++) vals[i] = value[i];
1270e26ddf31SBarry Smith     amsopt->arraylength = *n;
1271e26ddf31SBarry Smith   }
127253acd3b1SBarry Smith   ierr = PetscOptionsGetIntArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
127361b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
127453acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
127553acd3b1SBarry Smith     for (i=1; i<*n; i++) {
127653acd3b1SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr);
127753acd3b1SBarry Smith     }
127853acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr);
127953acd3b1SBarry Smith   }
128053acd3b1SBarry Smith   PetscFunctionReturn(0);
128153acd3b1SBarry Smith }
128253acd3b1SBarry Smith 
128353acd3b1SBarry Smith #undef __FUNCT__
128453acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsStringArray"
128553acd3b1SBarry Smith /*@C
128653acd3b1SBarry Smith    PetscOptionsStringArray - Gets an array of string values for a particular
128753acd3b1SBarry Smith    option in the database. The values must be separated with commas with
128853acd3b1SBarry Smith    no intervening spaces.
128953acd3b1SBarry Smith 
12903f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
129153acd3b1SBarry Smith 
129253acd3b1SBarry Smith    Input Parameters:
129353acd3b1SBarry Smith +  opt - the option one is seeking
129453acd3b1SBarry Smith .  text - short string describing option
129553acd3b1SBarry Smith .  man - manual page for option
129653acd3b1SBarry Smith -  nmax - maximum number of strings
129753acd3b1SBarry Smith 
129853acd3b1SBarry Smith    Output Parameter:
129953acd3b1SBarry Smith +  value - location to copy strings
130053acd3b1SBarry Smith .  nmax - actual number of strings found
130153acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
130253acd3b1SBarry Smith 
130353acd3b1SBarry Smith    Level: beginner
130453acd3b1SBarry Smith 
130553acd3b1SBarry Smith    Notes:
130653acd3b1SBarry Smith    The user should pass in an array of pointers to char, to hold all the
130753acd3b1SBarry Smith    strings returned by this function.
130853acd3b1SBarry Smith 
130953acd3b1SBarry Smith    The user is responsible for deallocating the strings that are
131053acd3b1SBarry Smith    returned. The Fortran interface for this routine is not supported.
131153acd3b1SBarry Smith 
131253acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
131353acd3b1SBarry Smith 
131453acd3b1SBarry Smith    Concepts: options database^array of strings
131553acd3b1SBarry Smith 
131653acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
131753acd3b1SBarry Smith            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
131853acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
131953acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
132053acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
132153acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
132253acd3b1SBarry Smith @*/
132353acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscTruth *set)
132453acd3b1SBarry Smith {
132553acd3b1SBarry Smith   PetscErrorCode ierr;
13261ae3d29cSBarry Smith   PetscOptions   amsopt;
132753acd3b1SBarry Smith 
132853acd3b1SBarry Smith   PetscFunctionBegin;
13291ae3d29cSBarry Smith   if (!PetscOptionsPublishCount) {
13301ae3d29cSBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING_ARRAY,&amsopt);CHKERRQ(ierr);
13311ae3d29cSBarry Smith     ierr = PetscMalloc((*nmax)*sizeof(char*),&amsopt->data);CHKERRQ(ierr);
13321ae3d29cSBarry Smith     amsopt->arraylength = *nmax;
13331ae3d29cSBarry Smith   }
133453acd3b1SBarry Smith   ierr = PetscOptionsGetStringArray(PetscOptionsObject.prefix,opt,value,nmax,set);CHKERRQ(ierr);
133561b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
133653acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
133753acd3b1SBarry Smith   }
133853acd3b1SBarry Smith   PetscFunctionReturn(0);
133953acd3b1SBarry Smith }
134053acd3b1SBarry Smith 
1341e2446a98SMatthew Knepley #undef __FUNCT__
1342e2446a98SMatthew Knepley #define __FUNCT__ "PetscOptionsTruthArray"
1343e2446a98SMatthew Knepley /*@C
1344e2446a98SMatthew Knepley    PetscOptionsTruthArray - Gets an array of logical values (true or false) for a particular
1345e2446a98SMatthew Knepley    option in the database. The values must be separated with commas with
1346e2446a98SMatthew Knepley    no intervening spaces.
1347e2446a98SMatthew Knepley 
13483f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
1349e2446a98SMatthew Knepley 
1350e2446a98SMatthew Knepley    Input Parameters:
1351e2446a98SMatthew Knepley +  opt - the option one is seeking
1352e2446a98SMatthew Knepley .  text - short string describing option
1353e2446a98SMatthew Knepley .  man - manual page for option
1354e2446a98SMatthew Knepley -  nmax - maximum number of values
1355e2446a98SMatthew Knepley 
1356e2446a98SMatthew Knepley    Output Parameter:
1357e2446a98SMatthew Knepley +  value - location to copy values
1358e2446a98SMatthew Knepley .  nmax - actual number of values found
1359e2446a98SMatthew Knepley -  set - PETSC_TRUE if found, else PETSC_FALSE
1360e2446a98SMatthew Knepley 
1361e2446a98SMatthew Knepley    Level: beginner
1362e2446a98SMatthew Knepley 
1363e2446a98SMatthew Knepley    Notes:
1364e2446a98SMatthew Knepley    The user should pass in an array of doubles
1365e2446a98SMatthew Knepley 
1366e2446a98SMatthew Knepley    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1367e2446a98SMatthew Knepley 
1368e2446a98SMatthew Knepley    Concepts: options database^array of strings
1369e2446a98SMatthew Knepley 
1370e2446a98SMatthew Knepley .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1371e2446a98SMatthew Knepley            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
1372e2446a98SMatthew Knepley           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1373e2446a98SMatthew Knepley           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1374e2446a98SMatthew Knepley           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
1375e2446a98SMatthew Knepley           PetscOptionsList(), PetscOptionsEList()
1376e2446a98SMatthew Knepley @*/
1377e2446a98SMatthew Knepley PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthArray(const char opt[],const char text[],const char man[],PetscTruth value[],PetscInt *n,PetscTruth *set)
1378e2446a98SMatthew Knepley {
1379e2446a98SMatthew Knepley   PetscErrorCode ierr;
1380e2446a98SMatthew Knepley   PetscInt       i;
13811ae3d29cSBarry Smith   PetscOptions   amsopt;
1382e2446a98SMatthew Knepley 
1383e2446a98SMatthew Knepley   PetscFunctionBegin;
13841ae3d29cSBarry Smith   if (!PetscOptionsPublishCount) {
13851ae3d29cSBarry Smith     PetscTruth *vals;
13861ae3d29cSBarry Smith 
13871ae3d29cSBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL_ARRAY,&amsopt);CHKERRQ(ierr);
13881ae3d29cSBarry Smith     ierr = PetscMalloc((*n)*sizeof(PetscTruth),&amsopt->data);CHKERRQ(ierr);
13891ae3d29cSBarry Smith     vals = (PetscTruth*)amsopt->data;
13901ae3d29cSBarry Smith     for (i=0; i<*n; i++) vals[i] = value[i];
13911ae3d29cSBarry Smith     amsopt->arraylength = *n;
13921ae3d29cSBarry Smith   }
1393e2446a98SMatthew Knepley   ierr = PetscOptionsGetTruthArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1394e2446a98SMatthew Knepley   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1395e2446a98SMatthew Knepley     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
1396e2446a98SMatthew Knepley     for (i=1; i<*n; i++) {
1397e2446a98SMatthew Knepley       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr);
1398e2446a98SMatthew Knepley     }
1399e2446a98SMatthew Knepley     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr);
1400e2446a98SMatthew Knepley   }
1401e2446a98SMatthew Knepley   PetscFunctionReturn(0);
1402e2446a98SMatthew Knepley }
1403e2446a98SMatthew Knepley 
140453acd3b1SBarry Smith 
140553acd3b1SBarry Smith #undef __FUNCT__
140653acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsHead"
140753acd3b1SBarry Smith /*@C
1408b52f573bSBarry Smith      PetscOptionsHead - Puts a heading before listing any more published options. Used, for example,
140953acd3b1SBarry Smith             in KSPSetFromOptions_GMRES().
141053acd3b1SBarry Smith 
14113f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
141253acd3b1SBarry Smith 
141353acd3b1SBarry Smith    Input Parameter:
141453acd3b1SBarry Smith .   head - the heading text
141553acd3b1SBarry Smith 
141653acd3b1SBarry Smith 
141753acd3b1SBarry Smith    Level: intermediate
141853acd3b1SBarry Smith 
141953acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
142053acd3b1SBarry Smith 
1421b52f573bSBarry Smith           Can be followed by a call to PetscOptionsTail() in the same function.
142253acd3b1SBarry Smith 
142353acd3b1SBarry Smith    Concepts: options database^subheading
142453acd3b1SBarry Smith 
142553acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
142653acd3b1SBarry Smith            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
142753acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
142853acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
142953acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
143053acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
143153acd3b1SBarry Smith @*/
143253acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsHead(const char head[])
143353acd3b1SBarry Smith {
143453acd3b1SBarry Smith   PetscErrorCode ierr;
143553acd3b1SBarry Smith 
143653acd3b1SBarry Smith   PetscFunctionBegin;
143761b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
143853acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  %s\n",head);CHKERRQ(ierr);
143953acd3b1SBarry Smith   }
144053acd3b1SBarry Smith   PetscFunctionReturn(0);
144153acd3b1SBarry Smith }
144253acd3b1SBarry Smith 
144353acd3b1SBarry Smith 
144453acd3b1SBarry Smith 
144553acd3b1SBarry Smith 
144653acd3b1SBarry Smith 
144753acd3b1SBarry Smith 
1448