Actual source code: xmlviewer.c

      1: /*************************************************************************************
      2:  *    M A R I T I M E  R E S E A R C H  I N S T I T U T E  N E T H E R L A N D S     *
      3:  *************************************************************************************
      4:  *    authors: Koos Huijssen, Christiaan M. Klaij                                    *
      5:  *************************************************************************************
      6:  *    content: Viewer for writing XML output                                         *
      7:  *************************************************************************************/
      8: #include <petscviewer.h>
      9: #include <petsc/private/logimpl.h>
     10: #include <petsc/private/fortranimpl.h>
     11: #include "../src/sys/logging/xmlviewer.h"

     13: #if defined(PETSC_USE_LOG)

     15: static int XMLSectionDepth            = 0;

     17: PetscErrorCode PetscViewerXMLStartSection(PetscViewer viewer, const char *name, const char *desc)
     18: {

     22:   if (!desc) {
     23:     PetscViewerASCIIPrintf(viewer, "%*s<%s>\n", XMLSectionDepth, "", name);
     24:   } else {
     25:     PetscViewerASCIIPrintf(viewer, "%*s<%s desc=\"%s\">\n", XMLSectionDepth, "", name, desc);
     26:   }
     27:   XMLSectionDepth += 2;
     28:   return(0);
     29: }

     31: /* Initialize a viewer to XML, and initialize the XMLDepth static parameter */
     32: PetscErrorCode PetscViewerInitASCII_XML(PetscViewer viewer)
     33: {
     35:   MPI_Comm       comm;
     36:   char           PerfScript[PETSC_MAX_PATH_LEN+40];

     39:   PetscObjectGetComm((PetscObject)viewer,&comm);
     40:   PetscViewerASCIIPrintf(viewer, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
     41:   PetscStrreplace(comm,"<?xml-stylesheet type=\"text/xsl\" href=\"performance_xml2html.xsl\"?>",PerfScript,sizeof(PerfScript));
     42:   PetscViewerASCIIPrintf(viewer, "%s\n",PerfScript);
     43:   XMLSectionDepth = 0;
     44:   PetscViewerXMLStartSection(viewer, "root", NULL);
     45:   return(0);
     46: }

     48: /* Initialize a viewer to XML, and initialize the XMLDepth static parameter */
     49: PetscErrorCode PetscViewerFinalASCII_XML(PetscViewer viewer)
     50: {

     54:   PetscViewerXMLEndSection(viewer, "root");
     55:   return(0);
     56: }

     58: PetscErrorCode PetscViewerXMLEndSection(PetscViewer viewer, const char *name)
     59: {

     63:   XMLSectionDepth -= 2;
     64:   if (XMLSectionDepth<0) XMLSectionDepth = 0;
     65:   PetscViewerASCIIPrintf(viewer, "%*s</%s>\n", XMLSectionDepth, "", name);
     66:   return(0);
     67: }

     69: PetscErrorCode PetscViewerXMLPutString(PetscViewer viewer, const char *name, const char *desc, const char *value)
     70: {

     74:   if (!desc) {
     75:     PetscViewerASCIIPrintf(viewer, "%*s<%s>%s</%s>\n", XMLSectionDepth, "", name, value, name);
     76:   } else {
     77:     PetscViewerASCIIPrintf(viewer, "%*s<%s desc=\"%s\">%s</%s>\n", XMLSectionDepth, "", name, desc, value, name);
     78:   }
     79:   return(0);
     80: }

     82: PetscErrorCode PetscViewerXMLPutInt(PetscViewer viewer, const char *name, const char *desc, int value)
     83: {

     87:   if (!desc) {
     88:     PetscViewerASCIIPrintf(viewer, "%*s<%s>%d</%s>\n", XMLSectionDepth, "", name, value, name);
     89:   } else {
     90:     PetscViewerASCIIPrintf(viewer, "%*s<%s desc=\"%s\">%d</%s>\n", XMLSectionDepth, "", name, desc, value, name);
     91:   }
     92:   return(0);
     93: }

     95: PetscErrorCode PetscViewerXMLPutDouble(PetscViewer viewer, const char *name, const char *desc, PetscLogDouble value, const char *format)
     96: {
     98:   char           buffer[1024];

    101:   if (!desc) {
    102:     PetscSNPrintf(buffer,sizeof(buffer), "%*s<%s>%s</%s>\n", XMLSectionDepth, "", name, format, name);
    103:   } else {
    104:     PetscSNPrintf(buffer,sizeof(buffer), "%*s<%s desc=\"%s\">%s</%s>\n", XMLSectionDepth, "", name, desc, format, name);
    105:   }
    106:   PetscViewerASCIIPrintf(viewer, buffer, value);
    107:   return(0);
    108: }

    110: #endif