Actual source code: ex49.c


  2: static char help[] = "Demonstrates PetscDataTypeFromString().\n\n";

  4: #include <petscsys.h>
  5: int main(int argc, char **argv)
  6: {
  7:   PetscDataType dtype;
  8:   PetscBool     found;

 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:   PetscFunctionBeginUser;
 20:   PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));

 22:   PetscCall(PetscDataTypeFromString("Scalar", &dtype, &found));
 23:   PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Did not find scalar datatype");
 24:   PetscCheck(dtype == PETSC_SCALAR, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Found wrong datatype for scalar");

 26:   PetscCall(PetscDataTypeFromString("INT", &dtype, &found));
 27:   PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Did not find int datatype");
 28:   PetscCheck(dtype == PETSC_INT, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Found wrong datatype for int");

 30:   PetscCall(PetscDataTypeFromString("real", &dtype, &found));
 31:   PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Did not find real datatype");
 32:   PetscCheck(dtype == PETSC_REAL, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Found wrong datatype for real");

 34:   PetscCall(PetscDataTypeFromString("abogusdatatype", &dtype, &found));
 35:   PetscCheck(!found, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Found a bogus datatype");

 37:   PetscCall(PetscFinalize());
 38:   return 0;
 39: }

 41: /*TEST

 43:    test:

 45: TEST*/