Actual source code: xmlviewer.c
petsc-3.7.1 2016-05-15
Report Typos and Errors

      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 xmlviewer.h

     13: #if defined(PETSC_USE_LOG)

     15: static int XMLSectionDepth            = 0;

     19: PetscErrorCode PetscViewerXMLStartSection(PetscViewer viewer, const char *name, const char *desc)
     20: {

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

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

     43:   PetscObjectGetComm((PetscObject)viewer,&comm);
     44:   PetscViewerASCIIPrintf(viewer, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
     45:   PetscStrreplace(comm,"<?xml-stylesheet type=\"text/xsl\" href=\"${PETSC_DIR}/share/petsc/xml/performance_xml2html.xsl\"?>",PerfScript,sizeof(PerfScript));
     46:   PetscViewerASCIIPrintf(viewer, "%s\n",PerfScript);
     47:   XMLSectionDepth = 0;
     48:   PetscViewerXMLStartSection(viewer, "root", NULL);
     49:   return(0);
     50: }

     52: /* Initialize a viewer to XML, and initialize the XMLDepth static parameter */
     55: PetscErrorCode PetscViewerFinalASCII_XML(PetscViewer viewer)
     56: {

     60:   PetscViewerXMLEndSection(viewer, "root");
     61:   return(0);
     62: }

     66: PetscErrorCode PetscViewerXMLEndSection(PetscViewer viewer, const char *name)
     67: {

     71:   XMLSectionDepth -= 2;
     72:   if (XMLSectionDepth<0) XMLSectionDepth = 0;
     73:   PetscViewerASCIIPrintf(viewer, "%*s</%s>\n", XMLSectionDepth, "", name);
     74:   return(0);
     75: }

     79: PetscErrorCode PetscViewerXMLPutString(PetscViewer viewer, const char *name, const char *desc, const char *value)
     80: {

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

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

     99:   if (!desc) {
    100:     PetscViewerASCIIPrintf(viewer, "%*s<%s>%d</%s>\n", XMLSectionDepth, "", name, value, name);
    101:   } else {
    102:     PetscViewerASCIIPrintf(viewer, "%*s<%s desc=\"%s\">%d</%s>\n", XMLSectionDepth, "", name, desc, value, name);
    103:   }
    104:   return(0);
    105: }

    109: PetscErrorCode PetscViewerXMLPutDouble(PetscViewer viewer, const char *name, const char *desc, PetscLogDouble value, const char *format)
    110: {
    112:   char           buffer[1024];

    115:   if (!desc) {
    116:     PetscSNPrintf(buffer,sizeof(buffer), "%*s<%s>%s</%s>\n", XMLSectionDepth, "", name, format, name);
    117:   } else {
    118:     PetscSNPrintf(buffer,sizeof(buffer), "%*s<%s desc=\"%s\">%s</%s>\n", XMLSectionDepth, "", name, desc, format, name);
    119:   }
    120:   PetscViewerASCIIPrintf(viewer, buffer, value);
    121:   return(0);
    122: }

    124: #endif