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 PetscFunctionBeginUser; 20 PetscCall(PetscInitialize(&argc, &argv, (char *)0, help)); 21 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"); 25 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"); 29 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"); 33 34 PetscCall(PetscDataTypeFromString("abogusdatatype", &dtype, &found)); 35 PetscCheck(!found, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Found a bogus datatype"); 36 37 PetscCall(PetscFinalize()); 38 return 0; 39 } 40 41 /*TEST 42 43 test: 44 45 TEST*/ 46