00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef SUNDANCE_OUT_H
00032 #define SUNDANCE_OUT_H
00033
00034 #include "SundanceDefs.hpp"
00035 #include "Teuchos_TestForException.hpp"
00036 #include "SundanceObjectWithVerbosity.hpp"
00037 #include "Teuchos_RefCountPtr.hpp"
00038 #include "Teuchos_FancyOStream.hpp"
00039 #include "Teuchos_MPIComm.hpp"
00040
00041 namespace Teuchos
00042 {
00043 template <class T> class Array;
00044 }
00045 namespace Sundance
00046 {
00047 class Tabs;
00048 using namespace Teuchos;
00049
00050
00051
00052
00053 class Out
00054 {
00055 public:
00056
00057 static void println(const std::string& str)
00058 {
00059 if (hasLogFile()) *logFile() << str << std::endl;
00060 if (!suppressStdout()) os() << str << std::endl;
00061 }
00062
00063 static void setLogFile(const std::string& filename)
00064 {
00065 logFile() = rcp(new std::ofstream(filename.c_str()));
00066 hasLogFile() = true;
00067 }
00068
00069 static FancyOStream& os()
00070 {
00071 static RCP<std::ostream> os = rcp(&std::cout, false);
00072 static RCP<FancyOStream> rtn = fancyOStream(os);
00073 static bool first = true;
00074 if (first)
00075 {
00076 rtn->setShowProcRank(true);
00077 first = false;
00078 }
00079 return *rtn;
00080 }
00081
00082 static FancyOStream& root()
00083 {
00084 static bool isRoot = MPIComm::world().getRank()==0;
00085 static RCP<FancyOStream> blackHole
00086 = rcp(new FancyOStream(rcp(new oblackholestream())));
00087
00088 if (isRoot)
00089 {
00090 return os();
00091 }
00092 else
00093 {
00094 return *blackHole;
00095 }
00096 }
00097
00098 static bool& suppressStdout() {static bool rtn=false; return rtn;}
00099
00100 private:
00101 static bool& hasLogFile() {static bool rtn=false; return rtn;}
00102 static RCP<std::ostream>& logFile() {static RCP<std::ostream> rtn; return rtn;}
00103
00104 };
00105
00106
00107
00108 void writeTable(std::ostream& os, const Tabs& tab,
00109 const Array<double>& a, int cols);
00110
00111 void writeTable(std::ostream& os, const Tabs& tab,
00112 const Array<int>& a, int cols);
00113
00114 }
00115
00116 #define SUNDANCE_OUT(test, msg) \
00117 { \
00118 if (test) \
00119 { \
00120 TeuchosOStringStream omsg; \
00121 omsg << msg; \
00122 Out::println(omsg.str()); \
00123 } \
00124 }
00125
00126
00127 #define SUNDANCE_VERB_EXTREME(msg) SUNDANCE_MSG4(this->verb(), msg)
00128 #define SUNDANCE_VERB_HIGH(msg) SUNDANCE_MSG3(this->verb(), msg)
00129 #define SUNDANCE_VERB_MEDIUM(msg) SUNDANCE_MSG2(this->verb(), msg)
00130 #define SUNDANCE_VERB_LOW(msg) SUNDANCE_MSG1(this->verb(), msg)
00131
00132 #define SUNDANCE_HEADER_LINE "\n------------------------------------------------------------------\n"
00133
00134 #define SUNDANCE_MSG(context, level, msg) SUNDANCE_OUT(this->verbLevel(context) >= level, msg)
00135
00136 #define SUNDANCE_LEVEL1(context, msg) SUNDANCE_MSG(context, 1, msg)
00137
00138 #define SUNDANCE_LEVEL2(context, msg) SUNDANCE_MSG(context, 2, msg)
00139
00140 #define SUNDANCE_LEVEL3(context, msg) SUNDANCE_MSG(context, 3, msg)
00141
00142 #define SUNDANCE_LEVEL4(context, msg) SUNDANCE_MSG(context, 4, msg)
00143
00144 #define SUNDANCE_LEVEL5(context, msg) SUNDANCE_MSG(context, 5, msg)
00145
00146
00147 #define SUNDANCE_MSG1(level, msg) SUNDANCE_OUT(level >= 1, msg)
00148
00149 #define SUNDANCE_MSG2(level, msg) SUNDANCE_OUT(level >= 2, msg)
00150
00151 #define SUNDANCE_MSG3(level, msg) SUNDANCE_OUT(level >= 3, msg)
00152
00153 #define SUNDANCE_MSG4(level, msg) SUNDANCE_OUT(level >= 4, msg)
00154
00155 #define SUNDANCE_MSG5(level, msg) SUNDANCE_OUT(level >= 5, msg)
00156
00157 #define SUNDANCE_BANNER1(level, tab, msg) \
00158 SUNDANCE_MSG1(level, tab \
00159 << "===================================================================");\
00160 SUNDANCE_MSG1(level, tab << std::endl << tab \
00161 << " " << msg); \
00162 SUNDANCE_MSG1(level, tab << std::endl << tab\
00163 << "===================================================================");
00164
00165
00166 #define SUNDANCE_BANNER2(level, tab, msg) \
00167 SUNDANCE_MSG2(level, tab \
00168 << "-------------------------------------------------------------------");\
00169 SUNDANCE_MSG2(level, tab << msg); \
00170 SUNDANCE_MSG2(level, tab\
00171 << "-------------------------------------------------------------------");
00172
00173
00174
00175 #define SUNDANCE_BANNER3(level, tab, msg) \
00176 SUNDANCE_MSG3(level, tab \
00177 << "-------------------------------------------------------------------");\
00178 SUNDANCE_MSG3(level, tab << std::endl << tab \
00179 << msg); \
00180 SUNDANCE_MSG3(level, tab << std::endl << tab\
00181 << "-------------------------------------------------------------------");
00182
00183 #endif