/* ---------------------------------------------------------------------------- nlmdl: status.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. A. Ronald Gallant P.O. Box 5513 Raleigh NC 27650-5513 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 appear 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. ---------------------------------------------------------------------------- */ /* status is a class used by nlmdl */ #include "status.h" status::status() { switches[0]='\0'; method[0]='\0'; n=0; M=0; K=0; p=0; itheta=0; ivar=0; vartype[0]='\0'; MA=0; weights[0]='\0'; tol=0; eps=0; detail[0]='\0'; rank=0; df[0]='\0'; obj=0; starting=STARTING_FILENAME; ending=ENDING_FILENAME; } status::~status() { } int status::from(char* filename) { #ifdef GNU_GPP_COMPILER #ifdef USE_ATT_STYLE_IO_WITH_GNU filebuf ib; if( ib.open(filename, input) == 0 ){ cerr << "Error, status::from, Cannot open " << filename << "\n"; exit(1); } istream ifrom(&ib); #endif #ifdef USE_GNU_STYLE_IO_WITH_GNU istream ifrom(filename,io_readonly,a_useonly); if ( !ifrom ) { cerr << "Error, status::from, Cannot open " << filename << "\n"; exit(1); } #endif #endif #ifdef TURBO_CPP_COMPILER ifstream ifrom(filename); if ( !ifrom ) { cerr << "Error, status::from, Cannot open " << filename << "\n"; exit(1); } #endif char junk[MAX_STATUS_LINE]; char newline; INTEGER i,len; double x = 0; if (!ifrom.get(switches,MAX_STATUS_LINE,'\n')) { cerr << "Error, status::from, Bad data (switches) in " << filename << "\n"; exit(1); } if (!(ifrom>>method)) return 0; if ( strcmp(method,"SUR") != 0 && strcmp(method,"TSLS") != 0 && strcmp(method,"GMM") != 0 ) { cerr << "Error, status::from, Bad data (method) in " << filename << "\n"; exit(1); } if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) return 0; if (!(ifrom>>n)) return 0; if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) return 0; if (!(ifrom>>M)) return 0; if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) return 0; if (!(ifrom>>K)) return 0; if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) return 0; if (!(ifrom>>p)) return 0; if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) return 0; if (!(ifrom>>itheta)) return 0; if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) return 0; if (!(ifrom>>ivar)) return 0; if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) return 0; if (!(ifrom>>vartype)) return 0; if ( strcmp(vartype,"homoskedastic") != 0 && strcmp(vartype,"heteroskedastic") != 0 ) { cerr << "Error, status::from, Bad data (vartype) in " << filename << "\n"; exit(1); } if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) return 0; if (!(ifrom>>MA)) return 0; if ( MA<0 || MA>=n ) { cerr << "Error, status::from, Bad data (MA) in " << filename << "\n"; exit(1); } if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) return 0; if (!(ifrom>>weights)) return 0; if ( strcmp(weights,"none") != 0 && strcmp(weights,"Parzen") != 0 ) { cerr << "Error, status::from, Bad data (weights) in " << filename << "\n"; exit(1); } if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) return 0; if (!(ifrom>>x)) return 0; else tol = (REAL)x; if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) return 0; if (!(ifrom>>x)) return 0; else eps = (REAL)x; if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) return 0; if (!(ifrom>>detail)) return 0; if ( strcmp(detail,"none") != 0 && strcmp(detail,"minimal") != 0 && strcmp(detail,"full") != 0 ) { cerr << "Error, status::from, Bad data (detail) in " << filename << "\n"; exit(1); } if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) return 0; if (!ifrom.get(newline)) return 0; for (i=1; i<=5; i++) { if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) return 0; if (!ifrom.get(newline)) return 0; } #ifdef GNU_GPP_COMPILER if (!(ifrom>>x)) return 0; if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) { cerr << "Error, status::from, Bad data (theta) in " << filename << "\n"; exit(1); } #endif #ifdef TURBO_CPP_COMPILER float y; //This nonsense is because Turbo can't read a null line into x=0; //a float. Precision is lost. I should find a better way. if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) return 0; if (sscanf(junk, "%e", &x) <= 0) return 0; if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) { cerr << "Error, status::from, Bad data (theta) in " << filename << "\n"; exit(1); } x = (double)y; #endif theta.resize(p,(INTEGER)1,0); theta[1] = (REAL)x; if (p==1) return 0; for (i=2; i<=p; i++) { if(!(ifrom>>x)) { cerr << "Error, status::from, Bad data (theta) in " << filename << "\n"; exit(1); } else { theta[i] = (REAL)x; } if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) { cerr << "Error, status::from, Bad data (theta) in " << filename << "\n"; exit(1); } } if (!ifrom.get(newline)) return 0; #ifdef GNU_GPP_COMPILER if (!(ifrom>>x)) return 0; if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) { cerr << "Error, status::from, Bad data (var) in " << filename << "\n"; exit(1); } #endif #ifdef TURBO_CPP_COMPILER if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) return 0; if (sscanf(junk, "%e", &x) <= 0) return 0; if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) { cerr << "Error, status::from, Bad data (var) in " << filename << "\n"; exit(1); } x = (double)y; #endif if ( strcmp(method,"SUR") == 0 || strcmp(method,"TSLS") == 0) { var.resize(M,M); var[1] = (REAL)x; if (M==1) return 0; for (i=2; i<=M*M; i++) { if(!(ifrom>>x)) { cerr << "Error, status::from, Bad data (var) in " << filename << "\n"; exit(1); } else { var[i] = (REAL)x; } if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) { cerr << "Error, status::from, Bad data (var) in " << filename << "\n"; exit(1); } } } else if ( strcmp(method,"GMM") == 0 ) { len = M*K; var.resize(len,len); var[1] = (REAL)x; if (len==1) return 0; for (i=2; i<=len*len; i++) { if(!(ifrom>>x)) { cerr << "Error, status::from, Bad data (var) in " << filename << "\n"; exit(1); } else { var[i] = (REAL)x; } if (!ifrom.get(junk,MAX_STATUS_LINE,'\n')) { cerr << "Error, status::from, Bad data (var) in " << filename << "\n"; exit(1); } } } else { cerr << "Error, status::from, Bad data (var) in " << filename << "\n"; exit(1); } ifrom.close(); return 0; } int status::to(char* filename) { #ifdef GNU_GPP_COMPILER #ifdef USE_ATT_STYLE_IO_WITH_GNU filebuf ob; if( ob.open(filename, output) == 0 ) { cerr << "Error, status::to, Cannot open " << filename << "\n"; exit(1); } ostream oto(&ob); #endif #ifdef USE_GNU_STYLE_IO_WITH_GNU ostream oto(filename,io_writeonly,a_create); if ( !oto ) { cerr << "Error, status::to, Cannot open " << filename << "\n"; exit(1); } #endif #endif #ifdef TURBO_CPP_COMPILER ofstream oto(filename); if ( !oto ) { cerr << "Error, status::to, Cannot open " << filename << "\n"; exit(1); } #endif INTEGER i,j,len; char temp[MAX_STATUS_LINE]; if (strlen(switches) == 0) { if (!(oto << "\tThis line is passed to class model as a string.\n")) { cerr << "Error, status::to, Error writing to " << filename << "\n"; exit(1); } } else { if (!(oto << switches << "\n")) { cerr << "Error, status::to, Error writing to " << filename << "\n"; exit(1); } } sprintf(temp,"%-19s", method); if (!(oto<0 is unwise.\n")) { cerr << "Error, status::to, Error writing to " << filename << "\n"; exit(1); } sprintf(temp,"%-19.6e",tol); if (!(oto<0 is unwise.\n"; sprintf(temp,"%-19.6e",tol); cout< 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.check2(i,j),var.elem(i,j)); cout< 0 && cols(theta) > 0 ){ for (i=1; i<=p; i++){ sprintf(temp,"%25.16e % 20.8f ",theta[i],theta[i]); cout< 0 && cols(D) > 0 ){ for (i=1; i<=p; i++){ sprintf(temp,"%25.16e % 20.8f ",D[i],D[i]); cout<