00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "dyn.h"
00024
00025 #ifdef TOOLBOX
00026
00027 #define HBINS 56 // number of horizontal bins
00028 #define VBINS 28 // number of vertical bins
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 void starplot(dyn * b, int k, real lmax, int nlines)
00040 {
00041 int n;
00042 int kx, ky;
00043 register int i, j;
00044 real lvmax;
00045 char screen[VBINS][HBINS];
00046 dyn *bi;
00047 char *str;
00048 char plot_symbol = 'o';
00049
00050 switch (k)
00051 {
00052 case 1:
00053 kx = 2; ky = 1; break;
00054 case 2:
00055 kx = 0; ky = 2; break;
00056 case 3:
00057 kx = 1; ky = 0; break;
00058 default:
00059 cerr << "starplot: k = " << k
00060 << " illegal value; choose from {1, 2, 3}\n";
00061 exit(0);
00062 }
00063
00064
00065
00066 real temp, true_max = 0;
00067 for (n = 0, bi = b->get_oldest_daughter(); bi != NULL;
00068 bi = bi->get_younger_sister()) {
00069 n++;
00070
00071 temp = bi->get_pos()[kx];
00072 if (temp < 0) temp = -temp;
00073 if (temp > true_max) true_max = temp;
00074 temp = bi->get_pos()[ky];
00075 if (temp < 0) temp = -temp;
00076 if (temp > true_max) true_max = temp;
00077 }
00078 if (lmax <= 0) {
00079 temp = 1.0/128;
00080 while (temp < true_max) temp *= 2;
00081 lmax = temp;
00082 }
00083
00084 if (nlines > VBINS)
00085 nlines = VBINS;
00086
00087 for (i = 0; i < nlines; i++)
00088 for (j = 0; j < HBINS; j++)
00089 screen[i][j] = ' ';
00090
00091 lvmax = lmax * ((real)nlines / (real)VBINS);
00092
00093 for (bi=b->get_oldest_daughter(); bi != NULL; bi=bi->get_younger_sister())
00094 {
00095 str = &plot_symbol;
00096
00097 i = (int)(nlines *
00098 (lvmax + bi->get_pos()[kx]) / (2.0*lvmax));
00099 j = (int)(HBINS *
00100 (lmax + bi->get_pos()[ky]) / (2.0*lmax));
00101
00102 if ( i >=0 && i < nlines && j >=0 && j < HBINS)
00103 {
00104 if (screen[i][j] == ' ')
00105 screen[i][j] = *str;
00106 else if (screen[i][j] == *str || screen[i][j] == (*str + 'A'-'a'))
00107 screen[i][j] = *str + 'A'-'a';
00108 else
00109 screen[i][j] = '*';
00110 }
00111 }
00112
00113 putchar(' ');
00114 putchar(' ');
00115 putchar('+');
00116 for (j = 0; j < HBINS; j++)
00117 putchar('-');
00118 putchar('+');
00119 putchar('\n');
00120
00121 putchar('^');
00122 putchar(' ');
00123 putchar('|');
00124 for (j = 0; j < HBINS; j++)
00125 putchar(screen[nlines - 1][j]);
00126 putchar('|');
00127
00128 printf(" N = %d", n);
00129
00130 printf("\n");
00131
00132 putchar('|');
00133 putchar(' ');
00134 putchar('|');
00135 for (j = 0; j < HBINS; j++)
00136 putchar(screen[nlines - 2][j]);
00137 putchar('|');
00138 putchar('\n');
00139
00140 putchar('|');
00141 putchar(' ');
00142 putchar('|');
00143 for (j = 0; j < HBINS; j++)
00144 putchar(screen[nlines - 3][j]);
00145 putchar('|');
00146
00147 printf(" max = %.2f", lmax);
00148 printf("\n");
00149
00150 switch (k)
00151 {
00152 case 1: putchar('z'); break;
00153 case 2: putchar('x'); break;
00154 case 3: putchar('y'); break;
00155 }
00156 putchar(' ');
00157 putchar('|');
00158 for (j = 0; j < HBINS; j++)
00159 putchar(screen[nlines - 4][j]);
00160 putchar('|');
00161 putchar('\n');
00162
00163 for (i = nlines - 5; i >= 0; i--)
00164 {
00165 putchar(' ');
00166 putchar(' ');
00167 putchar('|');
00168 for (j = 0; j < HBINS; j++)
00169 putchar(screen[i][j]);
00170 putchar('|');
00171 putchar('\n');
00172 }
00173
00174 putchar(' ');
00175 putchar(' ');
00176 putchar('+');
00177 for (j = 0; j < HBINS; j++)
00178 putchar('-');
00179 putchar('+');
00180 putchar('\n');
00181
00182 for (j = 0; j < HBINS - 3; j++)
00183 putchar(' ');
00184 switch (k)
00185 {
00186 case 1: putchar('y'); break;
00187 case 2: putchar('z'); break;
00188 case 3: putchar('x'); break;
00189 }
00190 printf(" --->\n");
00191 }
00192
00193 #define BIG_NUMBER 100
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 main(int argc, char ** argv)
00208 {
00209 int k;
00210 int nlines;
00211 real lmax;
00212 dyn *b;
00213 bool a_flag = FALSE;
00214 bool c_flag = FALSE;
00215 bool l_flag = FALSE;
00216 bool n_flag = FALSE;
00217
00218 check_help();
00219
00220 extern char *poptarg;
00221 int c;
00222 char* param_string = "a:cl:n:";
00223
00224 while ((c = pgetopt(argc, argv, param_string)) != -1)
00225 switch(c)
00226 {
00227 case 'a': a_flag = TRUE;
00228 k = atoi(poptarg);
00229 break;
00230 case 'c': c_flag = TRUE;
00231 break;
00232 case 'l': l_flag = TRUE;
00233 lmax = atof(poptarg);
00234 break;
00235 case 'n': n_flag = TRUE;
00236 nlines = atoi(poptarg);
00237 break;
00238 case '?': params_to_usage(cerr, argv[0], param_string);
00239 get_help();
00240 exit(1);
00241 }
00242
00243 if (a_flag == FALSE)
00244 k = 3;
00245
00246 if (l_flag == FALSE)
00247 lmax = 0;
00248 else
00249 if (lmax < 0)
00250 cerr << "starplot: a maximum length of " << lmax
00251 << " < 0 not allowed\n";
00252
00253 if (c_flag) cout << "\33[H\33[J\33[H";
00254
00255 if (n_flag == FALSE)
00256 nlines = BIG_NUMBER;
00257
00258 while (b = get_dyn(cin))
00259 {
00260 if (c_flag) cout << "\33[H";
00261 starplot(b, k, lmax, nlines);
00262
00263 dyn* bi = b->get_oldest_daughter();
00264 while (bi)
00265 {
00266 dyn * tmp = bi->get_younger_sister();
00267 delete bi;
00268 bi = tmp;
00269 }
00270 delete b;
00271 }
00272 }
00273
00274 #endif
00275
00276
00277