Changeset 308

Show
Ignore:
Timestamp:
04/09/09 09:13:35 (15 years ago)
Author:
dedecius
Message:

libDS.h & libDS.cpp - made 'pseudo'virtual object FileDS, which is a parent of ItppFileDS (the original FileDS) and CsvFileDS (for parsing data from CSV files).

Location:
bdm/stat
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • bdm/stat/libDS.cpp

    r278 r308  
    11 
    22#include "libDS.h" 
    3  
    43using namespace bdm; 
    54 
     
    5453} 
    5554 
     55CsvFileDS::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 
    5677//! Auxiliary function building full history of rv0 
    5778RV fullrgr ( const RV &drv0, const RV &urv0, const RV &rrv0 ) { 
     
    6586        return T; 
    6687} 
     88 
  • bdm/stat/libDS.h

    r283 r308  
    5050}; 
    5151 
    52 /*! Read Data Matrix from an IT file 
     52/*! Pseudovirtual class for reading data from files 
    5353 
    5454*/ 
     
    5656 
    5757public: 
    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 ignored 
    64         } 
    6558        void getdata ( vec &dt ) { 
    6659                it_assert_debug ( dt.length() ==Data.rows(),"" ); 
     
    7669        int ndat(){return Data.cols();} 
    7770}; 
     71 
     72/*!  
     73* \brief Read Data Matrix from an IT file 
     74 
     75The 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*/ 
     78class ItppFileDS: public FileDS { 
     79 
     80public: 
     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 
     92The constructor creates \c Data matrix from the records in a CSV file \c fname. The orientation can be of two types: 
     931. \c BY_COL which is default - the data are stored in columns; one column per time \f$t\f$, one row per data item. 
     942. \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*/ 
     97class CsvFileDS: public FileDS { 
     98 
     99public: 
     100        //! Constructor - create DS from a CSV file. 
     101        CsvFileDS ( const string& fname, const string& orientation = "BY_COL" ); 
     102}; 
     103 
     104 
    78105 
    79106/*!