00001
00002
00003
00004
00005
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
00027
00028
00029
00030
00031
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
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
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
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
00110
00111 char format[20];
00112 char format1[20];
00113 char format2[20];
00114 char format3[20];
00115 #if defined(__ZTC__)
00116
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
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
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
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
00143 const int cols = 3;
00144
00145 int imax = nvar / cols;
00146
00147 const int wmax = 22;
00148
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
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 }
00185 if (i<=imax) if (ad_printf) (*ad_printf)("\n");
00186 }
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;
00201 int cols = 3;
00202
00203
00204 int i, j, ij;
00205 int imax;
00206 int wmax;
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
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
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
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
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
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 }
00274 if (i<=imax) if (ad_printf) (*ad_printf)("\n");
00275 }
00276 if (ad_printf) fflush(stdout);
00277 }
00278 }
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384