xref: /petsc/src/sys/tests/ex49.c (revision 2e3d3ef9bcea2ec3187269b59709989dccbaffee)
1 
2 static char help[] = "Demonstrates PetscDataTypeFromString().\n\n";
3 
4 #include <petscsys.h>
5 int main(int argc,char **argv)
6 {
7   PetscDataType  dtype;
8   PetscBool      found;
9 
10   /*
11     Every PETSc routine should begin with the PetscInitialize() routine.
12     argc, argv - These command line arguments are taken to extract the options
13                  supplied to PETSc and options supplied to MPI.
14     help       - When PETSc executable is invoked with the option -help,
15                  it prints the various options that can be applied at
16                  runtime.  The user can use the "help" variable place
17                  additional help messages in this printout.
18   */
19   PetscCall(PetscInitialize(&argc,&argv,(char*)0,help));
20 
21   PetscCall(PetscDataTypeFromString("Scalar",&dtype,&found));
22   PetscCheck(found,PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Did not find scalar datatype");
23   PetscCheckFalse(dtype != PETSC_SCALAR,PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Found wrong datatype for scalar");
24 
25   PetscCall(PetscDataTypeFromString("INT",&dtype,&found));
26   PetscCheck(found,PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Did not find int datatype");
27   PetscCheckFalse(dtype != PETSC_INT,PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Found wrong datatype for int");
28 
29   PetscCall(PetscDataTypeFromString("real",&dtype,&found));
30   PetscCheck(found,PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Did not find real datatype");
31   PetscCheckFalse(dtype != PETSC_REAL,PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Found wrong datatype for real");
32 
33   PetscCall(PetscDataTypeFromString("abogusdatatype",&dtype,&found));
34   PetscCheck(!found,PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Found a bogus datatype");
35 
36   PetscCall(PetscFinalize());
37   return 0;
38 }
39 
40 /*TEST
41 
42    test:
43 
44 TEST*/
45