ADMB Documentation  11.1.2490
 All Classes Files Functions Variables Typedefs Friends Defines
fmm_disp.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: fmm_disp.cpp 2245 2014-08-14 23:54:44Z 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     //static int colnum[3] = {1, 28, 55}; /* position in line for each column */
00110 
00111     char format[20];
00112     char format1[20];
00113     char format2[20];
00114     char format3[20];
00115     #if defined(__ZTC__)
00116       // Zortech uses 3 digits to print exponent in e format
00117       strcpy(format,"%3d%9.5lf %12.4le");
00118       strcpy(format1,"%3d%9.4lf %12.4le");
00119       strcpy(format2,"%3d%9.3lf %12.4le");
00120       strcpy(format3,"%3d%9.2lf %12.4le");
00121                  /*  12345678901234567 */
00122     #elif defined(_WIN32)
00123       strcpy(format,"%3d%9.5lf %12.4le");
00124       strcpy(format1,"%3d%9.4lf %12.4le");
00125       strcpy(format2,"%3d%9.3lf %12.4le");
00126       strcpy(format3,"%3d%9.2lf %12.4le");
00127               /*  12345678901234567 */
00128     #else
00129       strcpy(format,"%3d%9.5lf %12.5le");
00130       strcpy(format1,"%3d%9.4lf %12.5le");
00131       strcpy(format2,"%3d%9.3lf %12.5le");
00132       strcpy(format3,"%3d%9.2lf %12.5le");
00133               /*  12345678901234567 */
00134     #endif
00135 
00136     char colhead[30];
00137     char colhead2[30];
00138     strcpy(colhead,"Var   Value    Gradient   ");
00139     strcpy(colhead2,"Var   Value    Gradient");
00140     if (ad_printf) (*ad_printf)("%26s|%26s|%23s\n",colhead,colhead,colhead2);
00141 
00142     // number of columns to display
00143     const int cols = 3;
00144     // number of lines to display
00145     int imax = nvar / cols;
00146     // number of lines in current window
00147     const int wmax = 22;
00148     // number of heading lines
00149     const int headings = 3;
00150     if (nvar % cols > 0) imax++;
00151     if ( (scroll_flag == 0) && (imax > wmax-headings) )
00152       imax = wmax - headings - 1;
00153 
00154     //int rownum = headings;       /* row number to print */
00155 
00156     for (int i=1; i<=imax; i++)
00157     {
00158       for (int j=0; j<cols; j++)
00159       {
00160         int ij = cols*(i-1)+(j+1);
00161         if (ij <= nvar)
00162         {
00163           if (fabs(x[ij])<100)
00164           {
00165             if (ad_printf) (*ad_printf)(format, ij, x[ij], g[ij]);
00166           }
00167           else if (fabs(x[ij])<1000)
00168           {
00169             if (ad_printf) (*ad_printf)(format1, ij, x[ij], g[ij]);
00170           }
00171           else if (fabs(x[ij])<10000)
00172           {
00173             if (ad_printf) (*ad_printf)(format2, ij, x[ij], g[ij]);
00174           }
00175           else
00176           {
00177             if (ad_printf) (*ad_printf)(format3, ij, x[ij], g[ij]);
00178           }
00179           if (j<cols-1)
00180           {
00181             if (ad_printf) (*ad_printf)(" |");
00182           }
00183         }
00184       } // j loop
00185       if (i<=imax) if (ad_printf) (*ad_printf)("\n");
00186     }  // i loop
00187     if (ad_printf) fflush(stdout);
00188   }
00189 }
00190 
00195 void fmmdisp(const double *x, const double *g,
00196              const int& nvar, int scroll_flag,int noprintx)
00197 {
00198   if (!noprintx)
00199   {
00200     int      headings = 3;     /* number of heading lines */
00201     int      cols = 3;     /* number of columns to display  */
00202 
00203     //static int colnum[3] = {1, 28, 55}; /* position in line for each column */
00204     int      i, j, ij;
00205     int      imax;         /* number of lines to display */
00206     int      wmax;         /* number of lines in current window */
00207 
00208     char     colhead[30];
00209 
00210     char format[30];
00211     char format1[30];
00212     char format2[30];
00213     char format3[30];
00214     #if defined(__ZTC__)
00215       // Zortech uses 3 digits to print exponent in e format
00216       strcpy(format,"%3d%9.5lf             ");
00217       strcpy(format1,"%3d%9.4lf            ");
00218       strcpy(format2,"%3d%9.3lf            ");
00219       strcpy(format3,"%3d%9.2lf            ");
00220                  /*  12345678901234567 */
00221     #elif defined(_MSC_VER)
00222       strcpy(format,"%3d%8.4lf             ");
00223       strcpy(format1,"%3d%8.3lf            ");
00224       strcpy(format2,"%3d%8.2lf            ");
00225       strcpy(format3,"%3d%8.1lf            ");
00226               /*  12345678901234567 */
00227     #else
00228       strcpy(format,"%3d%9.5lf             ");
00229       strcpy(format1,"%3d%9.4lf            ");
00230       strcpy(format2,"%3d%9.3lf            ");
00231       strcpy(format3,"%3d%9.2lf            ");
00232               /*  12345678901234567 */
00233     #endif
00234 
00235     wmax = 22;
00236     strcpy(colhead,"Var   Value               ");
00237     if (ad_printf) (*ad_printf)("%26s|%26s|%26s\n",colhead,colhead,colhead);
00238     imax = nvar / cols;
00239     if (nvar % cols > 0) imax++;
00240     if ( (scroll_flag == 0) && (imax > wmax-headings) )
00241       imax = wmax - headings - 1;
00242 
00243     //int rownum = headings;       /* row number to print */
00244 
00245     for (i=1; i<=imax; i++)
00246     {
00247       for (j=0; j<cols; j++)
00248       {
00249         ij = cols*(i-1)+(j+1);
00250         if (ij <= nvar)
00251         {
00252           if (fabs(x[ij])<100)
00253           {
00254             if (ad_printf) (*ad_printf)(format, ij, x[ij]);
00255           }
00256           else if (fabs(x[ij])<1000)
00257           {
00258             if (ad_printf) (*ad_printf)(format1, ij, x[ij]);
00259           }
00260           else if (fabs(x[ij])<10000)
00261           {
00262             if (ad_printf) (*ad_printf)(format2, ij, x[ij]);
00263           }
00264           else
00265           {
00266             if (ad_printf) (*ad_printf)(format3, ij, x[ij]);
00267           }
00268           if (j<cols-1)
00269           {
00270             if (ad_printf) (*ad_printf)(" |");
00271           }
00272         }
00273       } // j loop
00274       if (i<=imax) if (ad_printf) (*ad_printf)("\n");
00275     }  // i loop
00276     if (ad_printf) fflush(stdout);
00277   }
00278 }
00279 
00280 //void fmmdisp(const dvector& x, const dvector& g,
00281 //             const int& nvar, int scroll_flag)
00282 //{
00283 //  int      headings = 3;     /* number of heading lines */
00284 //  int      cols = 3;     /* number of columns to display  */
00285 //
00286 //  int      rownum;       /* row number to print */
00287 //  static int colnum[3] = {1, 28, 55}; /* position in line for each column */
00288 //  int      i, j, ij;
00289 //  int      imax;         /* number of lines to display */
00290 //  int      wmax;         /* number of lines in current window */
00291 //
00292 //
00293 //  char     colhead[30];
00294 //
00295 //  char format[20];
00296 //  #ifdef __ZTC__
00297 //    // Zortech uses 3 digits to print exponent in e format
00298 //    strcpy(format,"%3d%9.5lf %12.4le");
00299 //               /*  12345678901234567 */
00300 //  #else
00301 //    strcpy(format,"%3d%9.5lf %12.5le");
00302 //            /*  12345678901234567 */
00303 //  #endif
00304 //
00305 //#if defined(__NDPX__) || defined(__SUN__) || defined(__GNU__)
00306 // || defined(_Windows)
00307 //  wmax = 22;
00308 //#if  defined(__SUN__) || defined(__GNU__) || defined(_WINDOWS)
00309 //  strcpy(colhead,"Var   Value    Gradient   ");
00310 //  if (ad_printf) (*ad_printf)("%26s|%26s|%26s\n",colhead,colhead,colhead);
00311 //#else
00312 //  strcpy(colhead,"Var   Value    Gradient");
00313 //  if (ad_printf)
00314 //    (*ad_printf)("%23s   |%23s   |%23s\n",colhead,colhead,colhead);
00315 //#endif
00316 //  imax = nvar / cols;
00317 //  // cout << "imax = " << imax << endl;
00318 //  if (nvar % cols > 0) imax++;
00319 //  if ( (scroll_flag == 0) && (imax > wmax-headings) )
00320 //    imax = wmax - headings - 1;
00321 //  // cout << "imax = " << imax << endl;
00322 //#else
00323 //  struct text_info ti;   /* size etc of text screen */
00324 //  gettextinfo(&ti);
00325 //  gotoxy(1,ti.cury);
00326 //  strcpy(colhead,"Var   Value    Gradient   ");
00327 //  if (ad_printf) (*ad_printf)("%26s|%26s|%26s\n",colhead,colhead,colhead);
00328 //  wmax = ti.winbottom - ti.wintop + 1;
00329 //  gettextinfo(&ti);
00330 //  headings = ti.cury - 2;
00331 //
00332 //  imax = nvar / cols;
00333 //  if (nvar % cols > 0) imax++;
00334 //  if ( (scroll_flag == 0) && (imax > wmax-headings) )
00335 //    imax = wmax - headings - 1;
00336 //#endif
00337 //
00338 //
00339 //  rownum = headings;
00340 //
00341 //  for (i=1; i<=imax; i++)
00342 //  {
00343 //#if !defined(__NDPX__) && !defined(__SUN__) && !defined(__GNU__)
00344 // && !defined(_Windows)
00345 //    rownum++;
00346 //    if (rownum > ti.winbottom)
00347 //    {
00348 //      gotoxy(1, ti.winbottom);
00349 //      if (ad_printf) (*ad_printf)("\n");
00350 //      rownum = ti.winbottom;
00351 //    }
00352 //#endif
00353 //
00354 //    for (j=0; j<cols; j++)
00355 //    {
00356 //      ij = cols*(i-1)+(j+1);
00357 //      if (ij <= nvar)
00358 //      {
00359 //#if !defined(__NDPX__) && !defined(__SUN__)  && !defined(__SUN__)
00360 //        gotoxy(colnum[j], rownum);
00361 //#endif
00362 //        if (ad_printf) (*ad_printf)(format, ij, x[ij], g[ij]);
00363 //        if (j<cols-1)
00364 //        {
00365 //          if (ad_printf) (*ad_printf)(" |");
00366 //        }
00367 //      }
00368 //    } // j loop
00369 //#if defined(__NDPX__) || defined(__SUN__)  || defined(__GNU__)
00370 //    if (ad_printf) (*ad_printf)("\n");
00371 //#endif
00372 //  }  // i loop
00373 //
00374 //  if  (scroll_flag)
00375 //#if defined(__NDPX__) || defined(__SUN__)  || defined(__GNU__)
00376 //  || defined(_Windows)
00377 //    if (ad_printf) (*ad_printf)("\n");
00378 //#else
00379 //    if (ad_printf) (*ad_printf)("\n\n");
00380 //  gettextinfo(&ti);
00381 //  gotoxy(1,ti.cury);
00382 //#endif
00383 //}
00384 //