1a4963045SJacob Faibussowitsch #pragma once
25c6c1daeSBarry Smith
3af0996ceSBarry Smith #include <petsc/private/viewerimpl.h> /*I "petscsys.h" I*/
45c6c1daeSBarry Smith
55c6c1daeSBarry Smith typedef struct _n_PetscViewerVTKObjectLink *PetscViewerVTKObjectLink;
65c6c1daeSBarry Smith struct _n_PetscViewerVTKObjectLink {
75c6c1daeSBarry Smith PetscViewerVTKFieldType ft;
85c6c1daeSBarry Smith PetscObject vec;
95c6c1daeSBarry Smith PetscViewerVTKObjectLink next;
10e630c359SToby Isaac PetscInt field;
115c6c1daeSBarry Smith };
125c6c1daeSBarry Smith
135c6c1daeSBarry Smith typedef struct {
145c6c1daeSBarry Smith char *filename;
155c6c1daeSBarry Smith PetscFileMode btype;
165c6c1daeSBarry Smith PetscObject dm;
175c6c1daeSBarry Smith PetscViewerVTKObjectLink link;
1818e2ec27SBarry Smith PetscErrorCode (*write)(PetscObject, PetscViewer);
195c6c1daeSBarry Smith } PetscViewer_VTK;
205c6c1daeSBarry Smith
21*6497c311SBarry Smith PETSC_EXTERN PetscErrorCode PetscViewerVTKFWrite(PetscViewer, FILE *, const void *, PetscCount, MPI_Datatype);
225c6c1daeSBarry Smith
235c6c1daeSBarry Smith #if defined(PETSC_HAVE_STDINT_H) /* The VTK format requires a 32-bit integer */
245c6c1daeSBarry Smith typedef int32_t PetscVTKInt;
257de69702SBarry Smith #else /* Hope int is 32-bits */
265c6c1daeSBarry Smith typedef int PetscVTKInt;
275c6c1daeSBarry Smith #endif
285c6c1daeSBarry Smith typedef unsigned char PetscVTKType;
295c6c1daeSBarry Smith
305c6c1daeSBarry Smith #define PETSC_VTK_INT_MAX 2147483647
315c6c1daeSBarry Smith #define PETSC_VTK_INT_MIN -2147483647
32*6497c311SBarry Smith
33*6497c311SBarry Smith /*@C
34*6497c311SBarry Smith PetscVTKIntCast - casts to a `PetscVTKInt` (which may be 32-bits in size), generates an
35*6497c311SBarry Smith error if the `PetscVTKInt` is not large enough to hold the number.
36*6497c311SBarry Smith
37*6497c311SBarry Smith Not Collective; No Fortran Support
38*6497c311SBarry Smith
39*6497c311SBarry Smith Input Parameter:
40*6497c311SBarry Smith . a - the value to cast
41*6497c311SBarry Smith
42*6497c311SBarry Smith Output Parameter:
43*6497c311SBarry Smith . b - the resulting `PetscVTKInt` value
44*6497c311SBarry Smith
45*6497c311SBarry Smith Level: advanced
46*6497c311SBarry Smith
47*6497c311SBarry Smith .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntCast()`
48*6497c311SBarry Smith @*/
PetscVTKIntCast(PetscCount a,PetscVTKInt * b)49*6497c311SBarry Smith static inline PetscErrorCode PetscVTKIntCast(PetscCount a, PetscVTKInt *b)
50*6497c311SBarry Smith {
51*6497c311SBarry Smith PetscFunctionBegin;
52*6497c311SBarry Smith *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */
53*6497c311SBarry Smith PetscCheck(a <= PETSC_VTK_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscCount_FMT " is too big for VTK integer. Maximum supported value is %d", a, PETSC_MPI_INT_MAX);
54*6497c311SBarry Smith *b = (PetscVTKInt)a;
55*6497c311SBarry Smith PetscFunctionReturn(PETSC_SUCCESS);
56*6497c311SBarry Smith }
575c6c1daeSBarry Smith
582fb742c9SToby Isaac /* the only problem we've encountered so far is spaces not being acceptable for paraview field names */
PetscViewerVTKSanitizeName_Internal(char name[],size_t maxlen)59d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscViewerVTKSanitizeName_Internal(char name[], size_t maxlen)
60d71ae5a4SJacob Faibussowitsch {
612fb742c9SToby Isaac size_t c;
622fb742c9SToby Isaac
632fb742c9SToby Isaac PetscFunctionBegin;
642fb742c9SToby Isaac for (c = 0; c < maxlen; c++) {
652fb742c9SToby Isaac char a = name[c];
662fb742c9SToby Isaac if (a == '\0') break;
672fb742c9SToby Isaac if (a == ' ') name[c] = '_';
682fb742c9SToby Isaac }
693ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
702fb742c9SToby Isaac }
71