ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fmm_disp.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
11 #include "fvar.hpp"
12 
13 #if defined(_WIN32)
14  #include <windows.h>
15 #endif
16 #include <admodel.h>
17 
18 #if defined(__TURBOC__)
19  #pragma hdrstop
20  #include <conio.h>
21 #endif
22 
23 #ifdef __ZTC__
24  #include <disp.h>
25 
26  // preprocessor defines and function definitions that emulate Borland
27  // text screen managment functions using the Zortech disp_ package
28  // note the order of includes is important - this stuff should come
29  // after stdio.h, disp.h and anything that might also include these
30 
35  void gotoxy(int x, int y)
36  {
37  disp_move(y-1, x-1);
38  }
39 
44  struct text_info
45  {
46  unsigned char winleft, wintop;
47  unsigned char winright, winbottom;
48  //unsigned char attribute, normattr;
49  unsigned char currmode;
50  unsigned char screenheight;
51  unsigned char screenwidth;
52  unsigned char curx, cury;
53  };
54 
59  void gettextinfo(struct text_info *r)
60  {
61  r->winleft = 1;
62  r->wintop = 1;
63  r->winright = disp_numcols;
64  r->winbottom = disp_numrows-1;
65  //attribute , normattr;
66  r->currmode = disp_mode;;
67  r->screenheight = disp_numrows;
68  r->screenwidth = disp_numcols;
69  r->curx = disp_cursorcol+1;
70  r->cury = disp_cursorrow+1;
71  }
72 
73 #endif
74 
75 #if !defined(_MSC_VER)
76  void gotoxy(int x, int y) { ; }
77 
82  struct text_info
83  {
84  unsigned char winleft, wintop;
85  unsigned char winright, winbottom;
86  //unsigned char attribute, normattr;
87  unsigned char currmode;
88  unsigned char screenheight;
89  unsigned char screenwidth;
90  unsigned char curx, cury;
91  };
92 
93  void gettextinfo(struct text_info *r) {;}
94 #endif
95 
96 #include <string.h>
97 
102 void fmmdisp(const dvector& x, const dvector& g,
103  const int& nvar, int scroll_flag,int noprintx)
104 {
105  if (!noprintx)
106  {
107  //static int colnum[3] = {1, 28, 55}; /* position in line for each column */
108 
109  char format[20];
110  char format1[20];
111  char format2[20];
112  char format3[20];
113  #if defined(__ZTC__)
114  // Zortech uses 3 digits to print exponent in e format
115  strcpy(format,"%3d%9.5lf %12.4le");
116  strcpy(format1,"%3d%9.4lf %12.4le");
117  strcpy(format2,"%3d%9.3lf %12.4le");
118  strcpy(format3,"%3d%9.2lf %12.4le");
119  /* 12345678901234567 */
120  #elif defined(_WIN32)
121  strcpy(format,"%3d%9.5lf %12.4le");
122  strcpy(format1,"%3d%9.4lf %12.4le");
123  strcpy(format2,"%3d%9.3lf %12.4le");
124  strcpy(format3,"%3d%9.2lf %12.4le");
125  /* 12345678901234567 */
126  #else
127  strcpy(format,"%3d%9.5lf %12.5le");
128  strcpy(format1,"%3d%9.4lf %12.5le");
129  strcpy(format2,"%3d%9.3lf %12.5le");
130  strcpy(format3,"%3d%9.2lf %12.5le");
131  /* 12345678901234567 */
132  #endif
133 
134  char colhead[30];
135  char colhead2[30];
136  strcpy(colhead, "Var Value Gradient ");
137  strcpy(colhead2,"Var Value Gradient");
138  //ad_printf("%26s|%26s|%23s\n",colhead,colhead,colhead2);
139  std::ostream& output_stream = get_output_stream();
140  output_stream << colhead << "|"
141  << colhead << "|"
142  << colhead2 << endl;
143 
144  // number of columns to display
145  const int cols = 3;
146  // number of lines to display
147  int imax = nvar / cols;
148  // number of lines in current window
149  const int wmax = 22;
150  // number of heading lines
151  const int headings = 3;
152  if (nvar % cols > 0) imax++;
153  if ( (scroll_flag == 0) && (imax > wmax-headings) )
154  imax = wmax - headings - 1;
155 
156  //int rownum = headings; /* row number to print */
157 
158  for (int i=1; i<=imax; i++)
159  {
160  for (int j=0; j<cols; j++)
161  {
162  int ij = cols*(i-1)+(j+1);
163  if (ij <= nvar)
164  {
165  if (fabs(x[ij])<100)
166  {
167  //ad_printf(format, ij, x[ij], g[ij]);
168  output_stream << setw(3) << ij << ' ' << setw(8) << setprecision(5) << std::fixed << x[ij] << setw(13) << setprecision(5) << std::scientific << g[ij];
169  }
170  else if (fabs(x[ij])<1000)
171  {
172  //ad_printf(format1, ij, x[ij], g[ij]);
173  output_stream << setw(3) << ij << ' ' << setw(8) << setprecision(4) << std::fixed << x[ij] << setw(13) << setprecision(5) << std::scientific << g[ij];
174  }
175  else if (fabs(x[ij])<10000)
176  {
177  //ad_printf(format2, ij, x[ij], g[ij]);
178  output_stream << setw(3) << ij << ' ' << setw(8) << setprecision(3) << std::fixed << x[ij] << setw(13) << setprecision(5) << std::scientific << g[ij];
179  }
180  else
181  {
182  //ad_printf(format3, ij, x[ij], g[ij]);
183  output_stream << setw(3) << ij << ' ' << setw(8) << setprecision(2) << std::fixed << x[ij] << setw(13) << setprecision(5) << std::scientific << g[ij];
184  }
185  if (j<cols-1)
186  {
187  output_stream << " |";
188  }
189  }
190  } // j loop
191  if (i<=imax) output_stream << endl;
192  } // i loop
193  //fflush(stdout);
194  }
195 }
196 
201 void fmmdisp(const double *x, const double *g,
202  const int& nvar, int scroll_flag,int noprintx)
203 {
204  if (!noprintx)
205  {
206  int headings = 3; /* number of heading lines */
207  int cols = 3; /* number of columns to display */
208 
209  //static int colnum[3] = {1, 28, 55}; /* position in line for each column */
210  int i, j, ij;
211  int imax; /* number of lines to display */
212  int wmax; /* number of lines in current window */
213 
214  char colhead[30];
215 
216  char format[30];
217  char format1[30];
218  char format2[30];
219  char format3[30];
220  #if defined(__ZTC__)
221  // Zortech uses 3 digits to print exponent in e format
222  strcpy(format,"%3d%9.5lf ");
223  strcpy(format1,"%3d%9.4lf ");
224  strcpy(format2,"%3d%9.3lf ");
225  strcpy(format3,"%3d%9.2lf ");
226  /* 12345678901234567 */
227  #elif defined(_MSC_VER)
228  strcpy(format,"%3d%8.4lf ");
229  strcpy(format1,"%3d%8.3lf ");
230  strcpy(format2,"%3d%8.2lf ");
231  strcpy(format3,"%3d%8.1lf ");
232  /* 12345678901234567 */
233  #else
234  strcpy(format,"%3d%9.5lf ");
235  strcpy(format1,"%3d%9.4lf ");
236  strcpy(format2,"%3d%9.3lf ");
237  strcpy(format3,"%3d%9.2lf ");
238  /* 12345678901234567 */
239  #endif
240 
241 
242  wmax = 22;
243  strcpy(colhead,"Var Value ");
244  //ad_printf("%26s|%26s|%26s\n",colhead,colhead,colhead);
245  std::ostream& output_stream = get_output_stream();
246  output_stream << colhead << "| "
247  << colhead << "| "
248  << colhead << endl;
249  imax = nvar / cols;
250  if (nvar % cols > 0) imax++;
251  if ( (scroll_flag == 0) && (imax > wmax-headings) )
252  imax = wmax - headings - 1;
253 
254  //int rownum = headings; /* row number to print */
255 
256  for (i=1; i<=imax; i++)
257  {
258  for (j=0; j<cols; j++)
259  {
260  ij = cols*(i-1)+(j+1);
261  if (ij <= nvar)
262  {
263  if (fabs(x[ij])<100)
264  {
265  //ad_printf(format, ij, x[ij]);
266  output_stream << setw(3) << ij << " " << x[ij];
267  }
268  else if (fabs(x[ij])<1000)
269  {
270  //ad_printf(format1, ij, x[ij]);
271  output_stream << setw(3) << ij << " " << x[ij];
272  }
273  else if (fabs(x[ij])<10000)
274  {
275  //ad_printf(format2, ij, x[ij]);
276  output_stream << setw(3) << ij << " " << x[ij];
277  }
278  else
279  {
280  //ad_printf(format3, ij, x[ij]);
281  output_stream << setw(3) << ij << " " << x[ij];
282  }
283  if (j<cols-1)
284  {
285  //ad_printf(" |");
286  output_stream << " |";
287  }
288  }
289  } // j loop
290  if (i<=imax) output_stream << endl;
291  } // i loop
292  //fflush(stdout);
293  }
294 }
295 
296 //void fmmdisp(const dvector& x, const dvector& g,
297 // const int& nvar, int scroll_flag)
298 //{
299 // int headings = 3; /* number of heading lines */
300 // int cols = 3; /* number of columns to display */
301 //
302 // int rownum; /* row number to print */
303 // static int colnum[3] = {1, 28, 55}; /* position in line for each column */
304 // int i, j, ij;
305 // int imax; /* number of lines to display */
306 // int wmax; /* number of lines in current window */
307 //
308 //
309 // char colhead[30];
310 //
311 // char format[20];
312 // #ifdef __ZTC__
313 // // Zortech uses 3 digits to print exponent in e format
314 // strcpy(format,"%3d%9.5lf %12.4le");
315 // /* 12345678901234567 */
316 // #else
317 // strcpy(format,"%3d%9.5lf %12.5le");
318 // /* 12345678901234567 */
319 // #endif
320 //
321 //#if defined(__NDPX__) || defined(__SUN__) || defined(__GNU__)
322 // || defined(_Windows)
323 // wmax = 22;
324 //#if defined(__SUN__) || defined(__GNU__) || defined(_WINDOWS)
325 // strcpy(colhead,"Var Value Gradient ");
326 // if (ad_printf) (*ad_printf)("%26s|%26s|%26s\n",colhead,colhead,colhead);
327 //#else
328 // strcpy(colhead,"Var Value Gradient");
329 // if (ad_printf)
330 // (*ad_printf)("%23s |%23s |%23s\n",colhead,colhead,colhead);
331 //#endif
332 // imax = nvar / cols;
333 // // cout << "imax = " << imax << endl;
334 // if (nvar % cols > 0) imax++;
335 // if ( (scroll_flag == 0) && (imax > wmax-headings) )
336 // imax = wmax - headings - 1;
337 // // cout << "imax = " << imax << endl;
338 //#else
339 // struct text_info ti; /* size etc of text screen */
340 // gettextinfo(&ti);
341 // gotoxy(1,ti.cury);
342 // strcpy(colhead,"Var Value Gradient ");
343 // if (ad_printf) (*ad_printf)("%26s|%26s|%26s\n",colhead,colhead,colhead);
344 // wmax = ti.winbottom - ti.wintop + 1;
345 // gettextinfo(&ti);
346 // headings = ti.cury - 2;
347 //
348 // imax = nvar / cols;
349 // if (nvar % cols > 0) imax++;
350 // if ( (scroll_flag == 0) && (imax > wmax-headings) )
351 // imax = wmax - headings - 1;
352 //#endif
353 //
354 //
355 // rownum = headings;
356 //
357 // for (i=1; i<=imax; i++)
358 // {
359 //#if !defined(__NDPX__) && !defined(__SUN__) && !defined(__GNU__)
360 // && !defined(_Windows)
361 // rownum++;
362 // if (rownum > ti.winbottom)
363 // {
364 // gotoxy(1, ti.winbottom);
365 // if (ad_printf) (*ad_printf)("\n");
366 // rownum = ti.winbottom;
367 // }
368 //#endif
369 //
370 // for (j=0; j<cols; j++)
371 // {
372 // ij = cols*(i-1)+(j+1);
373 // if (ij <= nvar)
374 // {
375 //#if !defined(__NDPX__) && !defined(__SUN__) && !defined(__SUN__)
376 // gotoxy(colnum[j], rownum);
377 //#endif
378 // if (ad_printf) (*ad_printf)(format, ij, x[ij], g[ij]);
379 // if (j<cols-1)
380 // {
381 // if (ad_printf) (*ad_printf)(" |");
382 // }
383 // }
384 // } // j loop
385 //#if defined(__NDPX__) || defined(__SUN__) || defined(__GNU__)
386 // if (ad_printf) (*ad_printf)("\n");
387 //#endif
388 // } // i loop
389 //
390 // if (scroll_flag)
391 //#if defined(__NDPX__) || defined(__SUN__) || defined(__GNU__)
392 // || defined(_Windows)
393 // if (ad_printf) (*ad_printf)("\n");
394 //#else
395 // if (ad_printf) (*ad_printf)("\n\n");
396 // gettextinfo(&ti);
397 // gotoxy(1,ti.cury);
398 //#endif
399 //}
400 //
unsigned char curx
Definition: fmm_disp.cpp:90
void fmmdisp(const dvector &x, const dvector &g, const int &nvar, int scroll_flag, int noprintx)
Description not yet available.
Definition: fmm_disp.cpp:102
unsigned char wintop
Definition: fmm_disp.cpp:84
Description not yet available.
Definition: fmm_disp.cpp:82
#define x
Vector of double precision numbers.
Definition: dvector.h:50
unsigned char screenwidth
Definition: fmm_disp.cpp:89
df1_two_variable fabs(const df1_two_variable &x)
Definition: df12fun.cpp:891
unsigned char screenheight
Definition: fmm_disp.cpp:88
prnstream & endl(prnstream &)
void gotoxy(int x, int y)
Definition: fmm_disp.cpp:76
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
unsigned char currmode
Definition: fmm_disp.cpp:87
Description not yet available.
unsigned char winbottom
Definition: fmm_disp.cpp:85
unsigned char winleft
Definition: fmm_disp.cpp:84
std::ostream & get_output_stream()
Definition: adglobl.cpp:45
unsigned char cury
Definition: fmm_disp.cpp:90
void gettextinfo(struct text_info *r)
Definition: fmm_disp.cpp:93
unsigned char winright
Definition: fmm_disp.cpp:85