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

nlmdl: display.cc

nlmdl is a C++ implementation of the statistical methods in A. Ronald 
Gallant, "Nonlinear Statistical Models," New York: John Wiley and Sons, 
1987, ISBN 0-471-80260-3, using a matrix class realmat that is distributed 
with it.  The header files nlmdl.h and realmat.h describe the use of the 
program and matrix class, respectively.  

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.

---------------------------------------------------------------------------- */
/* display.cc is a piece of status.cc that was split */
/* out to reduce Turbo C++ memory requirements.      */

#include "status.h"

int status::display(display_mode mode)
{

  INTEGER i,j,len;
  char    temp[MAX_STATUS_LINE];
  char*   pad = "     ";


  switch (mode) {

  case START_UP:

    cout << starbox("/Parameter settings//_") << "\n";

    cout<<pad<< switches << "\n";

    sprintf(temp,"%-19s", method);
    cout<<pad<<temp<< "What estimation method?  Code SUR, TSLS, or GMM.\n";

    sprintf(temp,"%-19d", n);
    cout<<pad<<temp<< "Number of observations, t = 1, ..., n.\n";

    sprintf(temp,"%-19d",M);
    cout<<pad<<temp<< "Number of equations, i.e. dimension of e.\n";

    sprintf(temp,"%-19d",K);
    cout<<pad<<temp<<"Number of instruments, i.e. dimension of Z.\n";

    sprintf(temp,"%-19d",p);
    cout<<pad<<temp<<"Number of parameters, i.e. dimension of theta.\n";

    sprintf(temp,"%-19d",itheta);
    cout<<pad<<temp<< "Upper limit on Gauss-Newton iterations.\n";

    sprintf(temp,"%-19d",ivar);
    cout<<pad<<temp<< "Number var iterates, ivar=0 means none.\n";

    sprintf(temp,"%-19s",vartype);
    cout<<pad<<temp<< "Code homoskedastic or heteroskedastic.\n";

    sprintf(temp,"%-19d",MA);
    cout<<pad<<temp<< "Number of moving average terms MA for var estimate.\n";

    sprintf(temp,"%-19s",weights);
    cout<<pad<<temp<< "Code none or Parzen, none when MA>0 is unwise.\n";

    sprintf(temp,"%-19.6e",tol);
    cout<<pad<<temp<< "Convergence tolerance, tol=1.0e-8 is reasonable.\n";

    sprintf(temp,"%-19.6e",eps);
    cout<<pad<<temp<< "Inversion tolerance, eps=1.0e-13 is reasonable\n";

    sprintf(temp,"%-19s",detail);
    cout<<pad<<temp<< "How much output?  Code none, minimal, or full.\n";

    break;

  case VAR_ITERATE:

    if ( rows(var) > 0 && cols(var) > 0 ){
      if ( strcmp(method,"SUR") == 0 || strcmp(method,"TSLS") == 0){
        for (j=1; j<=M; j++){ 
        for (i=1; i<=M; i++){ 
          sprintf(temp,"%25.16e % 20.8f ",var.check(i,j),var(i,j));
          cout<<temp<< " var(" << i << "," << j << ")\n";
        }
        }  
      }
      else{
        len = M*K;
        for (j=1; j<=len; j++){
        for (i=1; i<=len; i++){
          sprintf(temp,"%25.16e % 20.8f ",var.check(i,j),var(i,j));
          cout<<temp<< " var(" << i << "," << j << ")\n";
        }
        }
      }
    }
    else{
      cout << "Error, status::display, var is not initialized.\n";
    }

    break;

   case THETA_ITERATE:

    if ( rows(theta) > 0 && cols(theta) > 0 ){
      for (i=1; i<=p; i++){
        sprintf(temp,"%25.16e % 20.8f ",theta[i],theta[i]);
        cout<<temp<< " theta(" << i << ")\n";
      }
    }
    else{
      cout << "Error, status::display, theta is not initialized.\n";
    }

    sprintf(temp,"%25.16e % 20.8f ",obj,obj);
    cout<<temp<< " obj\n";

    if (strcmp(detail,"full")!=0) break;

    if ( rows(D) > 0 && cols(D) > 0 ){
      for (i=1; i<=p; i++){
        sprintf(temp,"%25.16e % 20.8f ",D[i],D[i]);
        cout<<temp<< " D(" << i << ")\n";
      }
    }
    else{
      cout << "Error, status::display, D is not initialized.\n";
    }
 
    break;

  case TERMINATION:
  
    cout << starbox("/theta//_") << theta << "\n";

    if (strcmp(df,"corrected") == 0)
      cout << starbox("/var/(corrected for degrees of freedom)//_");
    else
      cout << starbox("/var/(no degrees of freedom corrections)//_"); 

    cout << var << "\n";

    sprintf(temp,"/V/(rank = %d)//_",rank);
    cout << starbox(temp) << V << "\n";

    break;

  }

  cout.flush();

  return 0;

}
