00001
00013 #ifndef LGR_H
00014 #define LGR_H
00015
00016 #include "bdmbase.h"
00017 #include "user_info.h"
00018
00019 namespace bdm{
00020 using std::string;
00021
00028 class memlog : public logger {
00029
00030 protected:
00032 int maxlen;
00034 int ind;
00036 Array<mat> vectors;
00038 string itfilename;
00039 public:
00041 memlog ( int maxlen0, string itf="" ) : maxlen ( maxlen0 ),ind ( 0 ),vectors ( 0 ),itfilename(itf) {}
00042
00043 memlog(): ind ( 0 ),vectors ( 0 ) {}
00044
00046 void init() {
00047 int i; int n =entries.length();
00048 vectors.set_size ( n );
00049 for ( i=0;i<n;i++ ) {vectors(i).set_size (maxlen,entries(i)._dsize() );}
00050 }
00051 void step() {if ( ind<maxlen ) ind++; else it_error ( "memlog::ind is too high;" );}
00052 void logit ( int id, const vec &v ) {
00053 it_assert_debug(id<vectors.length(),"Logger was not initialized, run init().");
00054 if(id>=0){ vectors ( id ).set_row ( ind,v );}
00055 }
00056 void logit ( int id, const double &d ) {
00057 it_assert_debug(id<vectors.length(),"Logger was not initialized, run init().");
00058 it_assert_debug(vectors(id).cols()==1,"Vector expected");
00059 if(id>=0){ vectors ( id ) ( ind )=d;}
00060 }
00062 void itsave(const char* fname);
00064 void finalize() {if (itfilename.length()>0) itsave(itfilename.c_str());};
00065
00066
00079 void from_setting( const Setting &set );
00080
00081
00082 };
00083
00084 UIREGISTER(memlog);
00085
00093 class dirfilelog : public memlog {
00094
00095 protected:
00097 string dirname;
00099 Array<string> scalarnames;
00100 public:
00104 dirfilelog ( string dirname0, int maxlen0 ) : memlog ( maxlen0 ), dirname ( dirname0 ), scalarnames ( 0 ) {}
00105
00106 dirfilelog() {}
00107
00109 void init();
00110 void step();
00111 void finalize();
00115 void write_buffers ( int Len );
00116
00117
00127 void from_setting( const Setting &set );
00128
00129
00130 };
00131
00132 UIREGISTER(dirfilelog);
00133
00134 };
00135 #endif // LGR_H