xref: /petsc/src/sys/classes/viewer/interface/viewa.c (revision 2e61fd769e96e8a8a9db2df18bbb201572eea519)
15c6c1daeSBarry Smith 
25c6c1daeSBarry Smith #include <petsc-private/viewerimpl.h>  /*I "petscsys.h" I*/
35c6c1daeSBarry Smith 
45c6c1daeSBarry Smith const char *const PetscViewerFormats[] = {
55c6c1daeSBarry Smith   "DEFAULT",
65c6c1daeSBarry Smith   "ASCII_MATLAB",
75c6c1daeSBarry Smith   "ASCII_MATHEMATICA",
85c6c1daeSBarry Smith   "ASCII_IMPL",
95c6c1daeSBarry Smith   "ASCII_INFO",
105c6c1daeSBarry Smith   "ASCII_INFO_DETAIL",
115c6c1daeSBarry Smith   "ASCII_COMMON",
125c6c1daeSBarry Smith   "ASCII_SYMMODU",
135c6c1daeSBarry Smith   "ASCII_INDEX",
145c6c1daeSBarry Smith   "ASCII_DENSE",
155c6c1daeSBarry Smith   "ASCII_MATRIXMARKET",
165c6c1daeSBarry Smith   "ASCII_VTK",
175c6c1daeSBarry Smith   "ASCII_VTK_CELL",
185c6c1daeSBarry Smith   "ASCII_VTK_COORDS",
195c6c1daeSBarry Smith   "ASCII_PCICE",
205c6c1daeSBarry Smith   "ASCII_PYTHON",
215c6c1daeSBarry Smith   "ASCII_FACTOR_INFO",
22*2e61fd76SBarry Smith   "ASCII_LATEX",
235c6c1daeSBarry Smith   "DRAW_BASIC",
245c6c1daeSBarry Smith   "DRAW_LG",
255c6c1daeSBarry Smith   "DRAW_CONTOUR",
265c6c1daeSBarry Smith   "DRAW_PORTS",
275c6c1daeSBarry Smith   "VTK_VTS",
28*2e61fd76SBarry Smith   "VTK_VTU",
295c6c1daeSBarry Smith   "NATIVE",
30*2e61fd76SBarry Smith   "NOFORMAT",
31*2e61fd76SBarry Smith   "PetscViewerFormat",
32*2e61fd76SBarry Smith   "PETSC_VIEWER_",
33*2e61fd76SBarry Smith   0
345c6c1daeSBarry Smith };
355c6c1daeSBarry Smith 
365c6c1daeSBarry Smith #undef __FUNCT__
375c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerSetFormat"
385c6c1daeSBarry Smith /*@C
395c6c1daeSBarry Smith    PetscViewerSetFormat - Sets the format for PetscViewers.
405c6c1daeSBarry Smith 
415c6c1daeSBarry Smith    Logically Collective on PetscViewer
425c6c1daeSBarry Smith 
435c6c1daeSBarry Smith    Input Parameters:
445c6c1daeSBarry Smith +  viewer - the PetscViewer
455c6c1daeSBarry Smith -  format - the format
465c6c1daeSBarry Smith 
475c6c1daeSBarry Smith    Level: intermediate
485c6c1daeSBarry Smith 
495c6c1daeSBarry Smith    Notes:
505c6c1daeSBarry Smith    Available formats include
515c6c1daeSBarry Smith +    PETSC_VIEWER_DEFAULT - default format
525c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_MATLAB - MATLAB format
535c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_DENSE - print matrix as dense
545c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_IMPL - implementation-specific format
555c6c1daeSBarry Smith       (which is in many cases the same as the default)
565c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_INFO - basic information about object
575c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_INFO_DETAIL - more detailed info
585c6c1daeSBarry Smith        about object
595c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_COMMON - identical output format for
605c6c1daeSBarry Smith        all objects of a particular type
615c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_INDEX - (for vectors) prints the vector
625c6c1daeSBarry Smith        element number next to each vector entry
635c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_SYMMODU - print parallel vectors without
645c6c1daeSBarry Smith        indicating the processor ranges
655c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_VTK - outputs the object to a VTK file
665c6c1daeSBarry Smith .    PETSC_VIEWER_NATIVE - store the object to the binary
675c6c1daeSBarry Smith        file in its native format (for example, dense
685c6c1daeSBarry Smith        matrices are stored as dense), DMDA vectors are dumped directly to the
695c6c1daeSBarry Smith        file instead of being first put in the natural ordering
705c6c1daeSBarry Smith .    PETSC_VIEWER_DRAW_BASIC - views the vector with a simple 1d plot
715c6c1daeSBarry Smith .    PETSC_VIEWER_DRAW_LG - views the vector with a line graph
725c6c1daeSBarry Smith -    PETSC_VIEWER_DRAW_CONTOUR - views the vector with a contour plot
735c6c1daeSBarry Smith 
745c6c1daeSBarry Smith    These formats are most often used for viewing matrices and vectors.
755c6c1daeSBarry Smith 
765c6c1daeSBarry Smith    If a format (for example PETSC_VIEWER_DRAW_CONTOUR) was applied to a viewer
775c6c1daeSBarry Smith   where it didn't apply (PETSC_VIEWER_STDOUT_WORLD) it cause the default behavior
785c6c1daeSBarry Smith   for that viewer to be used.
795c6c1daeSBarry Smith 
805c6c1daeSBarry Smith    Concepts: PetscViewer^setting format
815c6c1daeSBarry Smith 
825c6c1daeSBarry Smith .seealso: PetscViewerASCIIOpen(), PetscViewerBinaryOpen(), MatView(), VecView(), PetscViewerType,
835c6c1daeSBarry Smith           PetscViewerPushFormat(), PetscViewerPopFormat(), PetscViewerDrawOpen(),PetscViewerSocketOpen()
845c6c1daeSBarry Smith @*/
855c6c1daeSBarry Smith PetscErrorCode  PetscViewerSetFormat(PetscViewer viewer,PetscViewerFormat format)
865c6c1daeSBarry Smith {
875c6c1daeSBarry Smith   PetscFunctionBegin;
885c6c1daeSBarry Smith   if (!viewer) viewer = PETSC_VIEWER_STDOUT_SELF;
895c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
905c6c1daeSBarry Smith   PetscValidLogicalCollectiveEnum(viewer,format,2);
915c6c1daeSBarry Smith   viewer->format     = format;
925c6c1daeSBarry Smith   PetscFunctionReturn(0);
935c6c1daeSBarry Smith }
945c6c1daeSBarry Smith 
955c6c1daeSBarry Smith #undef __FUNCT__
965c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerPushFormat"
975c6c1daeSBarry Smith /*@C
985c6c1daeSBarry Smith    PetscViewerPushFormat - Sets the format for file PetscViewers.
995c6c1daeSBarry Smith 
1005c6c1daeSBarry Smith    Logically Collective on PetscViewer
1015c6c1daeSBarry Smith 
1025c6c1daeSBarry Smith    Input Parameters:
1035c6c1daeSBarry Smith +  viewer - the PetscViewer
1045c6c1daeSBarry Smith -  format - the format
1055c6c1daeSBarry Smith 
1065c6c1daeSBarry Smith    Level: intermediate
1075c6c1daeSBarry Smith 
1085c6c1daeSBarry Smith    Notes:
1095c6c1daeSBarry Smith    Available formats include
1105c6c1daeSBarry Smith +    PETSC_VIEWER_DEFAULT - default format
1115c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_MATLAB - MATLAB format
1125c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_IMPL - implementation-specific format
1135c6c1daeSBarry Smith       (which is in many cases the same as the default)
1145c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_INFO - basic information about object
1155c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_INFO_DETAIL - more detailed info
1165c6c1daeSBarry Smith        about object
1175c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_COMMON - identical output format for
1185c6c1daeSBarry Smith        all objects of a particular type
1195c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_INDEX - (for vectors) prints the vector
1205c6c1daeSBarry Smith        element number next to each vector entry
1215c6c1daeSBarry Smith .    PETSC_VIEWER_NATIVE - store the object to the binary
1225c6c1daeSBarry Smith        file in its native format (for example, dense
1235c6c1daeSBarry Smith        matrices are stored as dense), for DMDA vectors displays vectors in DMDA ordering, not natural
1245c6c1daeSBarry Smith .    PETSC_VIEWER_DRAW_BASIC - views the vector with a simple 1d plot
1255c6c1daeSBarry Smith .    PETSC_VIEWER_DRAW_LG - views the vector with a line graph
1265c6c1daeSBarry Smith -    PETSC_VIEWER_DRAW_CONTOUR - views the vector with a contour plot
1275c6c1daeSBarry Smith 
1285c6c1daeSBarry Smith    These formats are most often used for viewing matrices and vectors.
1295c6c1daeSBarry Smith    Currently, the object name is used only in the MATLAB format.
1305c6c1daeSBarry Smith 
1315c6c1daeSBarry Smith    Concepts: PetscViewer^setting format
1325c6c1daeSBarry Smith 
1335c6c1daeSBarry Smith .seealso: PetscViewerASCIIOpen(), PetscViewerBinaryOpen(), MatView(), VecView(),
1345c6c1daeSBarry Smith           PetscViewerSetFormat(), PetscViewerPopFormat()
1355c6c1daeSBarry Smith @*/
1365c6c1daeSBarry Smith PetscErrorCode  PetscViewerPushFormat(PetscViewer viewer,PetscViewerFormat format)
1375c6c1daeSBarry Smith {
1385c6c1daeSBarry Smith   PetscFunctionBegin;
1395c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
1405c6c1daeSBarry Smith   PetscValidLogicalCollectiveEnum(viewer,format,2);
1415c6c1daeSBarry Smith   if (viewer->iformat > 9) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Too many pushes");
1425c6c1daeSBarry Smith 
1435c6c1daeSBarry Smith   viewer->formats[viewer->iformat++]  = viewer->format;
1445c6c1daeSBarry Smith   viewer->format                      = format;
1455c6c1daeSBarry Smith 
1465c6c1daeSBarry Smith   PetscFunctionReturn(0);
1475c6c1daeSBarry Smith }
1485c6c1daeSBarry Smith 
1495c6c1daeSBarry Smith #undef __FUNCT__
1505c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerPopFormat"
1515c6c1daeSBarry Smith /*@C
1525c6c1daeSBarry Smith    PetscViewerPopFormat - Resets the format for file PetscViewers.
1535c6c1daeSBarry Smith 
1545c6c1daeSBarry Smith    Logically Collective on PetscViewer
1555c6c1daeSBarry Smith 
1565c6c1daeSBarry Smith    Input Parameters:
1575c6c1daeSBarry Smith .  viewer - the PetscViewer
1585c6c1daeSBarry Smith 
1595c6c1daeSBarry Smith    Level: intermediate
1605c6c1daeSBarry Smith 
1615c6c1daeSBarry Smith    Concepts: PetscViewer^setting format
1625c6c1daeSBarry Smith 
1635c6c1daeSBarry Smith .seealso: PetscViewerASCIIOpen(), PetscViewerBinaryOpen(), MatView(), VecView(),
1645c6c1daeSBarry Smith           PetscViewerSetFormat(), PetscViewerPushFormat()
1655c6c1daeSBarry Smith @*/
1665c6c1daeSBarry Smith PetscErrorCode  PetscViewerPopFormat(PetscViewer viewer)
1675c6c1daeSBarry Smith {
1685c6c1daeSBarry Smith   PetscFunctionBegin;
1695c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
1705c6c1daeSBarry Smith   if (viewer->iformat <= 0) PetscFunctionReturn(0);
1715c6c1daeSBarry Smith 
1725c6c1daeSBarry Smith   viewer->format = viewer->formats[--viewer->iformat];
1735c6c1daeSBarry Smith   PetscFunctionReturn(0);
1745c6c1daeSBarry Smith }
1755c6c1daeSBarry Smith 
1765c6c1daeSBarry Smith #undef __FUNCT__
1775c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerGetFormat"
1785c6c1daeSBarry Smith PetscErrorCode  PetscViewerGetFormat(PetscViewer viewer,PetscViewerFormat *format)
1795c6c1daeSBarry Smith {
1805c6c1daeSBarry Smith   PetscFunctionBegin;
1815c6c1daeSBarry Smith   *format =  viewer->format;
1825c6c1daeSBarry Smith   PetscFunctionReturn(0);
1835c6c1daeSBarry Smith }
1845c6c1daeSBarry Smith 
1855c6c1daeSBarry Smith 
1865c6c1daeSBarry Smith 
187