xref: /petsc/src/sys/tests/ex49.c (revision 08401ef684002a709c6d3db98a0c9f54a8bcf1ec)
1c4762a1bSJed Brown 
2c4762a1bSJed Brown static char help[] = "Demonstrates PetscDataTypeFromString().\n\n";
3c4762a1bSJed Brown 
4c4762a1bSJed Brown /*T
5c4762a1bSJed Brown    Concepts: introduction to PETSc;
6c4762a1bSJed Brown    Concepts: printing^in parallel
7c4762a1bSJed Brown    Processors: n
8c4762a1bSJed Brown T*/
9c4762a1bSJed Brown 
10c4762a1bSJed Brown #include <petscsys.h>
11c4762a1bSJed Brown int main(int argc,char **argv)
12c4762a1bSJed Brown {
13c4762a1bSJed Brown   PetscDataType  dtype;
14c4762a1bSJed Brown   PetscBool      found;
15c4762a1bSJed Brown 
16c4762a1bSJed Brown   /*
17c4762a1bSJed Brown     Every PETSc routine should begin with the PetscInitialize() routine.
18c4762a1bSJed Brown     argc, argv - These command line arguments are taken to extract the options
19c4762a1bSJed Brown                  supplied to PETSc and options supplied to MPI.
20c4762a1bSJed Brown     help       - When PETSc executable is invoked with the option -help,
21c4762a1bSJed Brown                  it prints the various options that can be applied at
22c4762a1bSJed Brown                  runtime.  The user can use the "help" variable place
23c4762a1bSJed Brown                  additional help messages in this printout.
24c4762a1bSJed Brown   */
259566063dSJacob Faibussowitsch   PetscCall(PetscInitialize(&argc,&argv,(char*)0,help));
26c4762a1bSJed Brown 
279566063dSJacob Faibussowitsch   PetscCall(PetscDataTypeFromString("Scalar",&dtype,&found));
2828b400f6SJacob Faibussowitsch   PetscCheck(found,PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Did not find scalar datatype");
29*08401ef6SPierre Jolivet   PetscCheck(dtype == PETSC_SCALAR,PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Found wrong datatype for scalar");
30c4762a1bSJed Brown 
319566063dSJacob Faibussowitsch   PetscCall(PetscDataTypeFromString("INT",&dtype,&found));
3228b400f6SJacob Faibussowitsch   PetscCheck(found,PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Did not find int datatype");
33*08401ef6SPierre Jolivet   PetscCheck(dtype == PETSC_INT,PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Found wrong datatype for int");
34c4762a1bSJed Brown 
359566063dSJacob Faibussowitsch   PetscCall(PetscDataTypeFromString("real",&dtype,&found));
3628b400f6SJacob Faibussowitsch   PetscCheck(found,PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Did not find real datatype");
37*08401ef6SPierre Jolivet   PetscCheck(dtype == PETSC_REAL,PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Found wrong datatype for real");
38c4762a1bSJed Brown 
399566063dSJacob Faibussowitsch   PetscCall(PetscDataTypeFromString("abogusdatatype",&dtype,&found));
4028b400f6SJacob Faibussowitsch   PetscCheck(!found,PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Found a bogus datatype");
41c4762a1bSJed Brown 
429566063dSJacob Faibussowitsch   PetscCall(PetscFinalize());
43b122ec5aSJacob Faibussowitsch   return 0;
44c4762a1bSJed Brown }
45c4762a1bSJed Brown 
46c4762a1bSJed Brown /*TEST
47c4762a1bSJed Brown 
48c4762a1bSJed Brown    test:
49c4762a1bSJed Brown 
50c4762a1bSJed Brown TEST*/
51