SALSA Analysis Modules
reporting.c
Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include <stdio.h>
00003 #include <string.h>
00004 #include "petsc.h"
00005 #include "anamod.h"
00006 #if !defined(HAVE_NMD)
00007 #error This file can not be compiled without nmd
00008 #endif
00009 #include "nmd.h"
00010 
00011 #undef __FUNCT__
00012 #define __FUNCT__ "ReportAnamodContent"
00013 /*! Generate a delimited string of all module names and corresponding values.
00014 
00015   - if the rval parameter is null, no value string is generated
00016   - separator is a single character
00017 */
00018 static PetscErrorCode ReportAnamodContent
00019 (NMD_metadata nmd,char **rkey,char **rval,int separator)
00020 {
00021   char *key,*val; size_t lkey,lval;
00022   int ncat,icat,nmod,imod;
00023   const char **categories,**modules; AnalysisDataType *types;
00024   PetscBool begun=PETSC_FALSE,trace_arrays; PetscErrorCode ierr;
00025   PetscFunctionBegin;
00026 
00027   ierr = GetCategories(&ncat,&categories); CHKERRQ(ierr);
00028   ierr = AnaModTraceArrays(&trace_arrays); CHKERRQ(ierr);
00029 
00030   lkey = 0; lval = 0;
00031   for (icat=0; icat<ncat; icat++) {
00032     ierr = CategoryGetModules
00033       (categories[icat],&modules,&types,PETSC_NULL,&nmod); CHKERRQ(ierr);
00034     for (imod=0; imod<nmod; imod++) {
00035       PetscBool f,isarray;
00036       AnalysisDataType type=types[imod];
00037 
00038       lkey += strlen(categories[icat])+strlen(modules[imod])+20;
00039 
00040       if (rval) {
00041         ierr = NMDIsArrayType(type,(NMDTruth*)&isarray); CHKERRQ(ierr);
00042         if (isarray) {
00043           if (trace_arrays) {
00044             int len;
00045             ierr = NMDGetArrayValue
00046               (nmd,categories[icat],modules[imod],
00047                NULL,NULL,&len,(NMDTruth*)&f); CHKERRQ(ierr);
00048             if (f) lval += len*20;
00049           } else
00050             lval += 4*20;
00051         } else
00052           lval += 20;
00053       }
00054     }
00055   }
00056   ierr = PetscMalloc(lkey*sizeof(char),&key); CHKERRQ(ierr);
00057   ierr = PetscMemzero(key,lkey*sizeof(char)); CHKERRQ(ierr);
00058   if (rval) {
00059     ierr = PetscMalloc(lval*sizeof(char),&val); CHKERRQ(ierr);
00060     ierr = PetscMemzero(val,lval*sizeof(char)); CHKERRQ(ierr);
00061   }
00062 
00063   for (icat=0; icat<ncat; icat++) {
00064     ierr = CategoryGetModules
00065       (categories[icat],&modules,&types,PETSC_NULL,&nmod); CHKERRQ(ierr);
00066     for (imod=0; imod<nmod; imod++) {
00067       PetscBool f=PETSC_FALSE;
00068       AnalysisDataType type=types[imod];
00069 
00070       ierr = PetscStrlen(key,&lkey); CHKERRQ(ierr);
00071       if (rval) {ierr = PetscStrlen(val,&lval); CHKERRQ(ierr);}
00072 
00073       if (begun) {
00074         sprintf(key+lkey++,"%c", separator);
00075         if (rval) sprintf(val+lval++,"%c", separator);
00076       } else begun=PETSC_TRUE;
00077 
00078       sprintf(key+lkey,"%s:%s",categories[icat],modules[imod]);
00079 
00080       ierr = PetscStrlen(key,&lkey); CHKERRQ(ierr);
00081       sprintf(key+lkey,":%s",typenames[types[imod]]);
00082 
00083       if (rval) {
00084         AnalysisItem v; char *stringed; int vlen=0; PetscBool isarray;
00085         ierr = NMDIsArrayType(type,(NMDTruth*)&isarray); CHKERRQ(ierr);
00086         if (isarray) {
00087           ierr = NMDGetArrayValue
00088             (nmd,categories[icat],modules[imod],
00089              &type,(void*)&v,&vlen,(NMDTruth*)&f); CHKERRQ(ierr);
00090         } else {
00091           ierr = NMDGetValue
00092             (nmd,categories[icat],modules[imod],
00093              NULL,(void*)&v,(NMDTruth*)&f); CHKERRQ(ierr);
00094         }
00095         if (f && (!isarray || trace_arrays) ) {
00096           ierr = QuantityAsString
00097             (&v,types[imod],&stringed); CHKERRQ(ierr);
00098         } else stringed = "";
00099         sprintf(val+lval,"%s",stringed);
00100       }
00101       CHKMEMQ;
00102     }
00103   }
00104   *rkey = key; 
00105   if (rval) *rval = val;
00106 
00107   PetscFunctionReturn(0);
00108 }
00109 
00110 #undef __FUNCT__
00111 #define __FUNCT__ "TabReportModules"
00112 /*! Generate a string with \c separator delimiter listing
00113   all currently declared modules in the AnaMod system.
00114   The user needs to PetscFree() the string after use.
00115 */
00116 PetscErrorCode TabReportModules(char **rkey,int separator)
00117 {
00118   PetscErrorCode ierr;
00119   PetscFunctionBegin;
00120   ierr = ReportAnamodContent
00121     (PETSC_NULL,rkey,PETSC_NULL,separator); CHKERRQ(ierr);
00122   PetscFunctionReturn(0);
00123 }
00124 
00125 #undef __FUNCT__
00126 #define __FUNCT__ "TabReportValues"
00127 /*! Generate strings with \c separator delimiter listing
00128   all currently declared modules in the AnaMod system and their values.
00129   The user needs to PetscFree() the strings after use.
00130 */
00131 PetscErrorCode TabReportValues(NMD_metadata nmd,char **rkey,char **rval,int separator)
00132 {
00133   PetscErrorCode ierr;
00134   PetscFunctionBegin;
00135 #if defined(HAVE_NMD)
00136   printf("\n\n>>>> Please use NMD value reporting<<<<\n\n\n");
00137 #endif
00138   ierr = ReportAnamodContent
00139     (nmd,rkey,rval,separator); CHKERRQ(ierr);
00140   PetscFunctionReturn(0);
00141 }