/* ---------------------------------------------------------------------------

Copyright (C) 1990, 1991, 1993, 1994, 2002.

A. Ronald Gallant
Post Office Box 659
Chapel Hill NC 27514-0659 
USA   

Permission to use, copy, modify, and distribute this software and its 
documentation for any purpose and without fee is hereby granted, provided 
that the above copyright notice appears in all copies and that both that 
copyright notice and this permission notice appear in supporting 
documentation.  

This software is provided "as is" without any expressed or implied warranty.

----------------------------------------------------------------------------*/

#include "model.h"

model::model() { }

model::~model() { }


void model::e(INTEGER t)
{
  REAL    a,b,yta,yt,xt;

  INTEGER i=t+2;
  
  yt = (nds[i]/pop[i])/(nds[i-1]/pop[i-1]);
  xt = (1.0+nyse[i])*(dflat[i-1]/dflat[i]);

  a=s.theta[1];
  b=s.theta[2];

  yta = pow(yt,a);

  e_t[1] = b * yta * xt - 1.0;
}

void model::dele(INTEGER t) 
{
  REAL    a,b,yta,yt,xt;

  INTEGER i=t+2;
  
  yt = (nds[i]/pop[i])/(nds[i-1]/pop[i-1]);
  xt = (1.0+nyse[i])*(dflat[i-1]/dflat[i]);

  a=s.theta[1];
  b=s.theta[2];

  yta = pow(yt,a);

  dele_t(1,1) = b * log(yt) * yta * xt;
  dele_t(1,2) = yta*xt;
}


int model::initialize()
{
  INTEGER i;
  double tmp;


  ifstream cdata("hansen.dat");
  if (!cdata) {
    cerr << "Error, model::model, Cannot open hansen.dat.\n";
    exit(1);
  }

  for (i=1; i<=240; i++) {
    cdata >> tmp; nds[i]=(REAL)tmp;
    cdata >> tmp; pop[i]=(REAL)tmp;
    cdata >> tmp; nyse[i]=(REAL)tmp;
    cdata >> tmp; dflat[i]=(REAL)tmp;
  }

  return 1;
}

void model::Z(INTEGER t)
{
  INTEGER i = t+2;
  Z_t[1] = 1.0;
  Z_t[2] = (nds[i-1]/pop[i-1])/(nds[i-2]/pop[i-2]);
  Z_t[3] = (1.0+nyse[i-1])*(dflat[i-2]/dflat[i-1]);
}

int model::terminate() { return 0; }
