Changeset 308
Legend:
- Unmodified
- Added
- Removed
-
bdm/stat/libDS.cpp
r278 r308 1 1 2 2 #include "libDS.h" 3 4 3 using namespace bdm; 5 4 … … 54 53 } 55 54 55 CsvFileDS::CsvFileDS ( const string& fname, const string& orientation ) :FileDS() { 56 time = 0; 57 58 vec data_line; 59 string line; 60 61 ifstream fs; 62 fs.open(fname.c_str()); 63 if(fs.is_open()) { 64 while ( getline(fs, line) ) { 65 data_line.set(line); 66 Data.append_row(data_line); 67 } 68 } 69 70 if(orientation == "BY_ROW") { 71 transpose(Data, Data); 72 } 73 74 75 } 76 56 77 //! Auxiliary function building full history of rv0 57 78 RV fullrgr ( const RV &drv0, const RV &urv0, const RV &rrv0 ) { … … 65 86 return T; 66 87 } 88 -
bdm/stat/libDS.h
r283 r308 50 50 }; 51 51 52 /*! Read Data Matrix from an IT file52 /*! Pseudovirtual class for reading data from files 53 53 54 54 */ … … 56 56 57 57 public: 58 FileDS ( const string &fname, const string &varname ) :MemDS() {59 it_file it ( fname );60 it << Name ( varname );61 it >> Data;62 time =0;63 //rowid and delays are ignored64 }65 58 void getdata ( vec &dt ) { 66 59 it_assert_debug ( dt.length() ==Data.rows(),"" ); … … 76 69 int ndat(){return Data.cols();} 77 70 }; 71 72 /*! 73 * \brief Read Data Matrix from an IT file 74 75 The constructor creates an internal matrix \c Data from an IT++ file. The file is binary and can be made using the IT++ library or the Matlab/Octave function itsave. NB: the data are stored columnwise, i.e. each column contains the data for time \f$t\f$! 76 77 */ 78 class ItppFileDS: public FileDS { 79 80 public: 81 ItppFileDS ( const string &fname, const string &varname ) :FileDS() { 82 it_file it ( fname ); 83 it << Name ( varname ); 84 it >> Data; 85 time = 0; 86 //rowid and delays are ignored 87 } 88 }; 89 90 /*! 91 * \brief CSV file data storage 92 The constructor creates \c Data matrix from the records in a CSV file \c fname. The orientation can be of two types: 93 1. \c BY_COL which is default - the data are stored in columns; one column per time \f$t\f$, one row per data item. 94 2. \c BY_ROW if the data are stored the classical CSV style. Then each column stores the values for data item, for ex. \f$[y_{t} y_{t-1} ...]\f$, one row for each discrete time instant. 95 96 */ 97 class CsvFileDS: public FileDS { 98 99 public: 100 //! Constructor - create DS from a CSV file. 101 CsvFileDS ( const string& fname, const string& orientation = "BY_COL" ); 102 }; 103 104 78 105 79 106 /*!