/*--------------------------------------------------------------------------
 * database.h - definitions/declarations for Sample and Database classes
 *
 *       (C) Jurgen Doornik 1994-2000
 *
 *--------------------------------------------------------------------------*/

#ifndef DATABASE_INCLUDED
#define DATABASE_INCLUDED

class Sample
{
    decl m_iFreq;                               // data frequency
    decl m_iYear1, m_iPeriod1;// year,period of first observation
    decl m_iYear2, m_iPeriod2; // year,period of last observation
    GetFrequency();         			        // data frequency
    GetYear1();                      // year of first observation
    GetPeriod1();                  // period of first observation
    GetYear2();                       // year of last observation
    GetPeriod2();                   // period of last observation
    GetSize();                // number of observations in sample
    GetIndex(const iYear,const iPeriod);   // index of time point
    ObsYear(obs);              // finds year of observation index
    ObsPeriod(obs);          // finds period of observation index
};

class Database : Sample
{
    decl m_mData;                                  // data matrix
    decl m_asNames;                             // variable names
    decl m_mVarsel;                         // variable selection
    decl m_mLagsel;                         // corresponding lags
    decl m_mSelgroup;                // group number of selection
    decl m_iT1sel, m_iT2sel;                   // selected sample
    decl m_dMisVal;                              // missing value

	Database();                                    // constructor

	Append(const mNew,         // append a matrix to the database
        const asNew, ...);	     // last argument is optional iT1
    Create(const iFreq, const iYear1,        // create a database
        const iPeriod1, const iYear2, const iPeriod2);
    Deterministic(const fCseason);      // create Constant, Trend
                              // and Seasonals (possibly centred)
    GetAll();                       // returns the whole database
    GetAllNames();              // returns all the variable names
	GetSample();                     // text with database sample
    GetVar(const sName);              // gets variable(s) by name
	GetVarByIndex(const iVar);       // gets variable(s) by index
	GetVarNameByIndex(const iVar);	     // gets name(s) by index
    GetVarIndex(const sName); // gets the database index of a var
	Grow(const cTadd); // grows sample size by cTadd observations
    Info();                           // prints database contents
    Load(const file);      				         // load data set
    LoadIn7(const file);                // load PcGive 7 data set
    LoadXls(const file);           // load Excel spreadsheet file
    LoadWks(const file);           // load Lotus spreadsheet file
    LoadFmtVar(const file);    // load ASCII formated by variable
    LoadObs(const file,         // load ASCII file by observation
        const cVar, const cObs, const iYear1,
        const iPeriod1, const iFreq, const fOffendMis);
    LoadVar(const file,            // load ASCII file by variable
        const cVar, const cObs, const iYear1,
        const iPeriod1, const iFreq, const fOffendMis);
    LoadDht(const file, const iYear1,
        const iPeriod1, const iFreq);          // Gauss data file
    LoadDta(const file, const iYear1,
        const iPeriod1, const iFreq);          // Stata data file
    Remove(const sName);   // remove a variable from the database
                           //  also removes the current selection
	RemoveObsIf(const vRemove);
    Rename(const sNewName, const sOldName);  // rename a variable
    Renew(const mNew,     // renew the observations of a variable
        const asNew, ...);	     // last argument is optional iT1
	RenewBlock(const mNew, const iVarIndex);// renews a var block
    SaveIn7(const file);                // save PcGive 7 data set
    SaveWks(const file);           // save Excel spreadsheet file
    SaveXls(const file);           // save Lotus spreadsheet file
    SaveFmtVar(const file);    // save ASCII formated by variable
    SaveObs(const file);        // save ASCII file by observation
    SaveVar(const file);           // save ASCII file by variable

	// variable selection specific code
    DeSelect();                       // remove current selection
	DeSelectByIndex(const iSel);     // remove var from selection
	DeSelectByName(const sVar, const iGroup, const iLag);
    FindSelection(const sVar,    // find a variable name with lag
        const iLag);             //              in the selection
	ForceSelSample(const iYear1, const iPeriod1,
		const iYear2, const iPeriod2);//forces a selection sample
    GetGroup(const iGroup);       // get a group selection matrix
    GetGroupLag(const iGroup,// get group with specific lag range
        const iLag1, const iLag2);
	GetGroupLagNames(const iGroup,
		const iLag1, const iLag2, const aasNames);
	GetGroupNames(const iGroup,   // get the var names of a group
		const aasNames);
    GetMaxSelLag();                 // returns maximum lag length
    GetMaxGroupLag(const iGroup); // gets max lag length in group
    GetSelEnd();           // index of last selection observation
	GetSelInfo();				 // get array with selection info
    GetSelSample();                  // text with selected sample
    GetSelStart();        // index of first selection observation
	Select(const iGroup,    // select variables from the database
        const aSel);
	SelectByIndex(const iGroup, const iVar,
		const iLag0, const iLag1);
	SetSelInfo(const asInfo);	 // set array with selection info
    SetSelSample(const iYear1, const iPeriod1, // select a sample
         const iYear2, const iPeriod2);
	// obsolescent:
    GetMaxLag();                              // use GetMaxSelLag
	SetSample(const iYear1,const iPeriod1,    // use SetSelSample
         const iYear2, const iPeriod2);
};

#endif /* DATABASE_INCLUDED */
