ADMB Documentation  11.1.2192
 All Classes Files Functions Variables Typedefs Friends Defines
fmm_disp.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: fmm_disp.cpp 1919 2014-04-22 22:02:01Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include "fvar.hpp"
00012 
00013 #if defined(_WIN32)
00014   #include <windows.h>
00015 #endif
00016 #include <admodel.h>
00017 
00018 #if defined(__TURBOC__)
00019   #pragma hdrstop
00020   #include <conio.h>
00021 #endif
00022 
00023 #ifdef __ZTC__
00024   #include <disp.h>
00025 
00026   // preprocessor defines and function definitions that emulate Borland
00027   // text screen managment functions using the Zortech disp_ package
00028   // note the order of includes is important - this stuff should come
00029   // after stdio.h, disp.h and anything that might also include these
00030 
00031 //  #define if (ad_printf) (*ad_printf) disp_if (ad_printf) (*ad_printf)
00032 
00037   void gotoxy(int x, int y)
00038   {
00039     disp_move(y-1, x-1);
00040   }
00041 
00046   struct text_info
00047   {
00048     unsigned char  winleft,   wintop;
00049     unsigned char  winright,  winbottom;
00050   //unsigned char  attribute, normattr;
00051     unsigned char  currmode;
00052     unsigned char  screenheight;
00053     unsigned char  screenwidth;
00054     unsigned char  curx, cury;
00055   };
00056 
00061   void gettextinfo(struct text_info *r)
00062   {
00063      r->winleft = 1;
00064      r->wintop = 1;
00065      r->winright = disp_numcols;
00066      r->winbottom = disp_numrows-1;
00067      //attribute , normattr;
00068      r->currmode = disp_mode;;
00069      r->screenheight = disp_numrows;
00070      r->screenwidth = disp_numcols;
00071      r->curx = disp_cursorcol+1;
00072      r->cury = disp_cursorrow+1;
00073   }
00074 
00075 #endif
00076 
00077 #if !defined(_MSC_VER)
00078   void gotoxy(int x, int y) { ; }
00079 
00084   struct text_info
00085   {
00086     unsigned char  winleft,   wintop;
00087     unsigned char  winright,  winbottom;
00088   //unsigned char  attribute, normattr;
00089     unsigned char  currmode;
00090     unsigned char  screenheight;
00091     unsigned char  screenwidth;
00092     unsigned char  curx, cury;
00093   };
00094 
00095   void gettextinfo(struct text_info *r) {;}
00096 #endif
00097 
00098 #include <string.h>
00099 
00104 void fmmdisp(const dvector& x, const dvector& g,
00105              const int& nvar, int scroll_flag,int noprintx)
00106 {
00107   if (!noprintx)
00108   {
00109     int      headings = 3;     /* number of heading lines */
00110     int      cols = 3;     /* number of columns to display  */
00111 
00112     //static int colnum[3] = {1, 28, 55}; /* position in line for each column */
00113     int      i, j, ij;
00114     int      imax;         /* number of lines to display */
00115     int      wmax;         /* number of lines in current window */
00116 
00117     char     colhead[30];
00118 
00119     char format[20];
00120     char format1[20];
00121     char format2[20];
00122     char format3[20];
00123     #if defined(__ZTC__)
00124       // Zortech uses 3 digits to print exponent in e format
00125       strcpy(format,"%3d%9.5lf %12.4le");
00126       strcpy(format1,"%3d%9.4lf %12.4le");
00127       strcpy(format2,"%3d%9.3lf %12.4le");
00128       strcpy(format3,"%3d%9.2lf %12.4le");
00129                  /*  12345678901234567 */
00130     #elif defined(_MSC_VER)
00131       strcpy(format,"%3d%8.4lf %12.4le");
00132       strcpy(format1,"%3d%8.3lf %12.4le");
00133       strcpy(format2,"%3d%8.2lf %12.4le");
00134       strcpy(format3,"%3d%8.1lf %12.4le");
00135               /*  12345678901234567 */
00136     #else
00137       strcpy(format,"%3d%9.5lf %12.5le");
00138       strcpy(format1,"%3d%9.4lf %12.5le");
00139       strcpy(format2,"%3d%9.3lf %12.5le");
00140       strcpy(format3,"%3d%9.2lf %12.5le");
00141               /*  12345678901234567 */
00142     #endif
00143 
00144     wmax = 22;
00145     strcpy(colhead,"Var   Value    Gradient   ");
00146     if (ad_printf) (*ad_printf)("%26s|%26s|%26s\n",colhead,colhead,colhead);
00147     imax = nvar / cols;
00148     if (nvar % cols > 0) imax++;
00149     if ( (scroll_flag == 0) && (imax > wmax-headings) )
00150       imax = wmax - headings - 1;
00151 
00152     //int rownum = headings;       /* row number to print */
00153 
00154     for (i=1; i<=imax; i++)
00155     {
00156       for (j=0; j<cols; j++)
00157       {
00158         ij = cols*(i-1)+(j+1);
00159         if (ij <= nvar)
00160         {
00161           if (fabs(x[ij])<100)
00162           {
00163             if (ad_printf) (*ad_printf)(format, ij, x[ij], g[ij]);
00164           }
00165           else if (fabs(x[ij])<1000)
00166           {
00167             if (ad_printf) (*ad_printf)(format1, ij, x[ij], g[ij]);
00168           }
00169           else if (fabs(x[ij])<10000)
00170           {
00171             if (ad_printf) (*ad_printf)(format2, ij, x[ij], g[ij]);
00172           }
00173           else
00174           {
00175             if (ad_printf) (*ad_printf)(format3, ij, x[ij], g[ij]);
00176           }
00177           if (j<cols-1)
00178           {
00179             if (ad_printf) (*ad_printf)(" |");
00180           }
00181         }
00182       } // j loop
00183       if (i<=imax) if (ad_printf) (*ad_printf)("\n");
00184     }  // i loop
00185     if (ad_printf) fflush(stdout);
00186   }
00187 }
00188 
00193 void fmmdisp(const double *x, const double *g,
00194              const int& nvar, int scroll_flag,int noprintx)
00195 {
00196   if (!noprintx)
00197   {
00198     int      headings = 3;     /* number of heading lines */
00199     int      cols = 3;     /* number of columns to display  */
00200 
00201     //static int colnum[3] = {1, 28, 55}; /* position in line for each column */
00202     int      i, j, ij;
00203     int      imax;         /* number of lines to display */
00204     int      wmax;         /* number of lines in current window */
00205 
00206     char     colhead[30];
00207 
00208     char format[30];
00209     char format1[30];
00210     char format2[30];
00211     char format3[30];
00212     #if defined(__ZTC__)
00213       // Zortech uses 3 digits to print exponent in e format
00214       strcpy(format,"%3d%9.5lf             ");
00215       strcpy(format1,"%3d%9.4lf            ");
00216       strcpy(format2,"%3d%9.3lf            ");
00217       strcpy(format3,"%3d%9.2lf            ");
00218                  /*  12345678901234567 */
00219     #elif defined(_MSC_VER)
00220       strcpy(format,"%3d%8.4lf             ");
00221       strcpy(format1,"%3d%8.3lf            ");
00222       strcpy(format2,"%3d%8.2lf            ");
00223       strcpy(format3,"%3d%8.1lf            ");
00224               /*  12345678901234567 */
00225     #else
00226       strcpy(format,"%3d%9.5lf             ");
00227       strcpy(format1,"%3d%9.4lf            ");
00228       strcpy(format2,"%3d%9.3lf            ");
00229       strcpy(format3,"%3d%9.2lf            ");
00230               /*  12345678901234567 */
00231     #endif
00232 
00233     wmax = 22;
00234     strcpy(colhead,"Var   Value               ");
00235     if (ad_printf) (*ad_printf)("%26s|%26s|%26s\n",colhead,colhead,colhead);
00236     imax = nvar / cols;
00237     if (nvar % cols > 0) imax++;
00238     if ( (scroll_flag == 0) && (imax > wmax-headings) )
00239       imax = wmax - headings - 1;
00240 
00241     //int rownum = headings;       /* row number to print */
00242 
00243     for (i=1; i<=imax; i++)
00244     {
00245       for (j=0; j<cols; j++)
00246       {
00247         ij = cols*(i-1)+(j+1);
00248         if (ij <= nvar)
00249         {
00250           if (fabs(x[ij])<100)
00251           {
00252             if (ad_printf) (*ad_printf)(format, ij, x[ij]);
00253           }
00254           else if (fabs(x[ij])<1000)
00255           {
00256             if (ad_printf) (*ad_printf)(format1, ij, x[ij]);
00257           }
00258           else if (fabs(x[ij])<10000)
00259           {
00260             if (ad_printf) (*ad_printf)(format2, ij, x[ij]);
00261           }
00262           else
00263           {
00264             if (ad_printf) (*ad_printf)(format3, ij, x[ij]);
00265           }
00266           if (j<cols-1)
00267           {
00268             if (ad_printf) (*ad_printf)(" |");
00269           }
00270         }
00271       } // j loop
00272       if (i<=imax) if (ad_printf) (*ad_printf)("\n");
00273     }  // i loop
00274     if (ad_printf) fflush(stdout);
00275   }
00276 }
00277 
00278 //void fmmdisp(const dvector& x, const dvector& g,
00279 //             const int& nvar, int scroll_flag)
00280 //{
00281 //  int      headings = 3;     /* number of heading lines */
00282 //  int      cols = 3;     /* number of columns to display  */
00283 //
00284 //  int      rownum;       /* row number to print */
00285 //  static int colnum[3] = {1, 28, 55}; /* position in line for each column */
00286 //  int      i, j, ij;
00287 //  int      imax;         /* number of lines to display */
00288 //  int      wmax;         /* number of lines in current window */
00289 //
00290 //
00291 //  char     colhead[30];
00292 //
00293 //  char format[20];
00294 //  #ifdef __ZTC__
00295 //    // Zortech uses 3 digits to print exponent in e format
00296 //    strcpy(format,"%3d%9.5lf %12.4le");
00297 //               /*  12345678901234567 */
00298 //  #else
00299 //    strcpy(format,"%3d%9.5lf %12.5le");
00300 //            /*  12345678901234567 */
00301 //  #endif
00302 //
00303 //#if defined(__NDPX__) || defined(__SUN__) || defined(__GNU__)
00304 // || defined(_Windows)
00305 //  wmax = 22;
00306 //#if  defined(__SUN__) || defined(__GNU__) || defined(_WINDOWS)
00307 //  strcpy(colhead,"Var   Value    Gradient   ");
00308 //  if (ad_printf) (*ad_printf)("%26s|%26s|%26s\n",colhead,colhead,colhead);
00309 //#else
00310 //  strcpy(colhead,"Var   Value    Gradient");
00311 //  if (ad_printf)
00312 //    (*ad_printf)("%23s   |%23s   |%23s\n",colhead,colhead,colhead);
00313 //#endif
00314 //  imax = nvar / cols;
00315 //  // cout << "imax = " << imax << endl;
00316 //  if (nvar % cols > 0) imax++;
00317 //  if ( (scroll_flag == 0) && (imax > wmax-headings) )
00318 //    imax = wmax - headings - 1;
00319 //  // cout << "imax = " << imax << endl;
00320 //#else
00321 //  struct text_info ti;   /* size etc of text screen */
00322 //  gettextinfo(&ti);
00323 //  gotoxy(1,ti.cury);
00324 //  strcpy(colhead,"Var   Value    Gradient   ");
00325 //  if (ad_printf) (*ad_printf)("%26s|%26s|%26s\n",colhead,colhead,colhead);
00326 //  wmax = ti.winbottom - ti.wintop + 1;
00327 //  gettextinfo(&ti);
00328 //  headings = ti.cury - 2;
00329 //
00330 //  imax = nvar / cols;
00331 //  if (nvar % cols > 0) imax++;
00332 //  if ( (scroll_flag == 0) && (imax > wmax-headings) )
00333 //    imax = wmax - headings - 1;
00334 //#endif
00335 //
00336 //
00337 //  rownum = headings;
00338 //
00339 //  for (i=1; i<=imax; i++)
00340 //  {
00341 //#if !defined(__NDPX__) && !defined(__SUN__) && !defined(__GNU__)
00342 // && !defined(_Windows)
00343 //    rownum++;
00344 //    if (rownum > ti.winbottom)
00345 //    {
00346 //      gotoxy(1, ti.winbottom);
00347 //      if (ad_printf) (*ad_printf)("\n");
00348 //      rownum = ti.winbottom;
00349 //    }
00350 //#endif
00351 //
00352 //    for (j=0; j<cols; j++)
00353 //    {
00354 //      ij = cols*(i-1)+(j+1);
00355 //      if (ij <= nvar)
00356 //      {
00357 //#if !defined(__NDPX__) && !defined(__SUN__)  && !defined(__SUN__)
00358 //        gotoxy(colnum[j], rownum);
00359 //#endif
00360 //        if (ad_printf) (*ad_printf)(format, ij, x[ij], g[ij]);
00361 //        if (j<cols-1)
00362 //        {
00363 //          if (ad_printf) (*ad_printf)(" |");
00364 //        }
00365 //      }
00366 //    } // j loop
00367 //#if defined(__NDPX__) || defined(__SUN__)  || defined(__GNU__)
00368 //    if (ad_printf) (*ad_printf)("\n");
00369 //#endif
00370 //  }  // i loop
00371 //
00372 //  if  (scroll_flag)
00373 //#if defined(__NDPX__) || defined(__SUN__)  || defined(__GNU__)
00374 //  || defined(_Windows)
00375 //    if (ad_printf) (*ad_printf)("\n");
00376 //#else
00377 //    if (ad_printf) (*ad_printf)("\n\n");
00378 //  gettextinfo(&ti);
00379 //  gotoxy(1,ti.cury);
00380 //#endif
00381 //}
00382 //