Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

lagradplot.C

Go to the documentation of this file.
00001 
00012 
00013 //.............................................................................
00014 //    version 1:  May 1989   Piet Hut               email: piet@iassns.bitnet
00015 //                           Institute for Advanced Study, Princeton, NJ, USA
00016 //    version 2:  Dec 1992   Piet Hut  --  adopted to the new C++-based starlab
00017 //    version 3:  Dec 2000   Piet Hut  --  added 1%, 2%, 5% radii
00018 //.............................................................................
00019 //  non-local function: 
00020 //    plot_mass_radii
00021 //.............................................................................
00022 //     ....
00023 //  ....
00024 //.............................................................................
00025 //  see also: pnode.c
00026 //.............................................................................
00027 
00028 #include "dyn.h"
00029 
00030 #ifdef TOOLBOX
00031 
00032 #define  MAX_NUMBER_OF_COLUMNS   79
00033 #define  PMR_LENGTH_PER_COLUMN   0.1
00034 #define  PMRP_LENGTH_PER_COLUMN  0.05
00035 
00036 typedef  struct
00037     {
00038     real  radius;
00039     real  mass;
00040     } rm_pair, *rm_pair_ptr;
00041 
00042 //-----------------------------------------------------------------------------
00043 //  compare_radii  --  compare the radii of two particles
00044 //-----------------------------------------------------------------------------
00045 
00046 local int compare_radii(const void * pi, const void * pj)
00047     {
00048     if (((rm_pair_ptr) pi)->radius > ((rm_pair_ptr) pj)->radius)
00049         return(1);
00050     else if (((rm_pair_ptr)pi)->radius < ((rm_pair_ptr)pj)->radius)
00051         return(-1);
00052     else
00053         return(0);
00054     }
00055 
00056 //-----------------------------------------------------------------------------
00057 //  plot_mass_radii  --  Get the massradii for all particles.
00058 //-----------------------------------------------------------------------------
00059 
00060 void  plot_mass_radii(dyn * b)
00061     {
00062     int  i;
00063     int  n;
00064     real  cumulative_mass;
00065     real  half_mass;
00066     real  first_quartile_mass;
00067     real  third_quartile_mass;
00068     bool  within_first_quartile = TRUE;
00069     bool  within_half_mass = TRUE;
00070     bool  within_third_quartile = TRUE;
00071     story *st;
00072     rm_pair_ptr  rm_table;
00073     
00074 //  quick fix to determine  n  for a flat tree:
00075 
00076     dyn * bi;
00077     for (n = 0, bi = b->get_oldest_daughter(); bi != NULL;
00078          bi = bi->get_younger_sister())
00079         n++;    
00080 
00081     rm_table = new rm_pair[n];
00082     if (rm_table == NULL)
00083         {
00084         cerr << "plot_mass_radii: not enough memory left for the rm_table[]\n";
00085         exit(1);
00086         }
00087 
00088     for (i = 0, bi=b->get_oldest_daughter(); bi != NULL;
00089          i++, bi=bi->get_younger_sister())
00090         {
00091         (rm_table + i)->radius = abs(bi->get_pos());
00092         (rm_table + i)->mass = bi->get_mass();
00093         }       
00094 
00095     qsort((void *)rm_table, (size_t)n, sizeof(rm_pair), compare_radii);
00096 
00097     half_mass = 0.5 * b->get_mass();
00098     first_quartile_mass = 0.25 * b->get_mass();
00099     third_quartile_mass = 0.75 * b->get_mass();
00100 
00101     st = b->get_log_story();
00102 
00103     cumulative_mass = 0.0;
00104     i = 0;
00105 
00106     while (cumulative_mass < first_quartile_mass)
00107         cumulative_mass += (rm_table + i++)->mass;
00108 
00109     first_quartile_mass = (rm_table + i-1)->radius;
00110 
00111     while (cumulative_mass < half_mass)
00112         cumulative_mass += (rm_table + i++)->mass;
00113 
00114     half_mass = (rm_table + i-1)->radius;
00115 
00116     while (cumulative_mass < third_quartile_mass)
00117         cumulative_mass += (rm_table + i++)->mass;
00118 
00119     third_quartile_mass = (rm_table + i-1)->radius;
00120 
00121     for (i= 0; i < MAX_NUMBER_OF_COLUMNS; i++)
00122         {
00123         if (within_first_quartile)
00124             {
00125             if (PMR_LENGTH_PER_COLUMN * i < first_quartile_mass)
00126                 printf(" ");
00127             else
00128                 {
00129                 printf("*");
00130                 within_first_quartile = FALSE;
00131                 }
00132             }
00133         else if (within_half_mass)
00134             {
00135             if (PMR_LENGTH_PER_COLUMN * i < half_mass)
00136                 printf(" ");
00137             else
00138                 {
00139                 printf("*");
00140                 within_half_mass = FALSE;
00141                 }
00142             }
00143         else if (within_third_quartile)
00144             {
00145             if (PMR_LENGTH_PER_COLUMN * i < third_quartile_mass)
00146                 printf(" ");
00147             else
00148                 {
00149                 printf("*");
00150                 within_third_quartile = FALSE;
00151                 }
00152             }
00153         }
00154     printf("\n");
00155     }
00156 
00157 //-----------------------------------------------------------------------------
00158 //  plot_mass_radii_in_percentages  --  Get the massradii for all particles.
00159 //
00160 //  Dec. 2000: I added an option for wider output, which triggers the use 
00161 //             of these extra symbols:  '  for the 1% mass radius
00162 //                                      "  for the 2% mass radius
00163 //                                      :  for the 5% mass radius
00164 //             These symbols only appear if they don't collide with the
00165 //             older |,X,@ symbols.  It's a bit of a kluge, but it works.
00166 //             Piet
00167 //-----------------------------------------------------------------------------
00168 
00169 void  plot_mass_radii_in_percentages(dyn * b, int width_factor)
00170     {
00171     int  i, k;
00172     int  n;
00173     real  cumulative_mass;
00174     real  mass_percent[9];
00175     bool  within_mass_percent[9];
00176     real  mass_percent_1, mass_percent_2, mass_percent_5;
00177     bool  within_mass_percent_1, within_mass_percent_2, within_mass_percent_5;
00178     real  length_per_column;
00179     real  max_number_of_columns;
00180     rm_pair_ptr  rm_table;
00181     dyn * bi;
00182     
00183     length_per_column = PMRP_LENGTH_PER_COLUMN / width_factor;
00184     max_number_of_columns = MAX_NUMBER_OF_COLUMNS;
00185     if (width_factor > 1) max_number_of_columns *= 2;
00186 
00187 //  quick fix to determine  n  for a flat tree:
00188 
00189     for (n = 0, bi = b->get_oldest_daughter(); bi != NULL;
00190          bi = bi->get_younger_sister())
00191         n++;    
00192 
00193     for (i = 0; i < 9; i++)
00194         within_mass_percent[i] = TRUE;
00195 
00196     within_mass_percent_1 = within_mass_percent_2 = within_mass_percent_5=TRUE;
00197 
00198     rm_table = new rm_pair[n];
00199     if (rm_table == NULL)
00200         {
00201         cerr << "plot_mass_radii_in_percentages: "
00202              << "not enough memory left for the rm_table[]\n";
00203         exit(1);
00204         }
00205 
00206     for (i = 0, bi=b->get_oldest_daughter(); bi != NULL;
00207          i++, bi=bi->get_younger_sister())
00208         {
00209         (rm_table + i)->radius = abs(bi->get_pos());
00210         (rm_table + i)->mass = bi->get_mass();
00211         }       
00212 
00213     qsort((void *)rm_table, (size_t)n, sizeof(rm_pair), compare_radii);
00214 
00215     mass_percent_1 = 0.01*b->get_mass();
00216     mass_percent_2 = 0.02*b->get_mass();
00217     mass_percent_5 = 0.05*b->get_mass();
00218 
00219     for (i = 0; i < 9; i++)
00220         mass_percent[i] = ((1 + i) / 10.0) * b->get_mass();
00221 
00222     i = 0;
00223     cumulative_mass = 0;
00224     while (cumulative_mass < mass_percent_1)
00225             cumulative_mass += (rm_table + i++)->mass;
00226     mass_percent_1 = (rm_table + i-1)->radius;
00227 
00228     i = 0;
00229     cumulative_mass = 0;
00230     while (cumulative_mass < mass_percent_2)
00231             cumulative_mass += (rm_table + i++)->mass;
00232     mass_percent_2 = (rm_table + i-1)->radius;
00233 
00234     i = 0;
00235     cumulative_mass = 0;
00236     while (cumulative_mass < mass_percent_5)
00237             cumulative_mass += (rm_table + i++)->mass;
00238     mass_percent_5 = (rm_table + i-1)->radius;
00239 
00240     for (i = k = 0, cumulative_mass = 0; k < 9; k++)
00241         {
00242         while (cumulative_mass < mass_percent[k])
00243             cumulative_mass += (rm_table + i++)->mass;
00244         mass_percent[k] = (rm_table + i-1)->radius;
00245         }
00246 
00247     for (i= 0; i < max_number_of_columns; i++)
00248         {
00249         if (within_mass_percent_1)
00250             {
00251             if (length_per_column * i < mass_percent_1)
00252                 printf(" ");
00253             else
00254                 {
00255                 within_mass_percent_1 = FALSE;
00256                 if (length_per_column * i < mass_percent_2)
00257                     {
00258                     if (width_factor > 1) printf("`"); else printf(" ");
00259                     }
00260                 else if (length_per_column * i < mass_percent_5)
00261                     {
00262                     if (width_factor > 1) printf("\""); else printf(" ");
00263                     within_mass_percent_2 = FALSE;
00264                     }
00265                 else if (length_per_column * i < mass_percent[0])
00266                     {
00267                     if (width_factor > 1) printf(":"); else printf(" ");
00268                     within_mass_percent_2 = FALSE;
00269                     within_mass_percent_5 = FALSE;
00270                     }
00271                 else if (length_per_column * i < mass_percent[1])
00272                     {
00273                     printf("|");
00274                     within_mass_percent_2 = FALSE;
00275                     within_mass_percent_5 = FALSE;
00276                     within_mass_percent[0] = FALSE;
00277                     }
00278                 else if (length_per_column * i < mass_percent[2])
00279                     {
00280                     printf("X");
00281                     within_mass_percent_2 = FALSE;
00282                     within_mass_percent_5 = FALSE;
00283                     within_mass_percent[0] = FALSE;
00284                     within_mass_percent[1] = FALSE;
00285                     }
00286                 else
00287                     {
00288                     printf("@");
00289                     within_mass_percent_2 = FALSE;
00290                     within_mass_percent_5 = FALSE;
00291                     within_mass_percent[0] = FALSE;
00292                     within_mass_percent[1] = FALSE;
00293                     within_mass_percent[2] = FALSE;
00294                     }
00295                 }
00296             }
00297         else if (within_mass_percent_2)
00298             {
00299             if (length_per_column * i < mass_percent_2)
00300                 printf(" ");
00301             else
00302                 {
00303                 within_mass_percent_2 = FALSE;
00304                 if (length_per_column * i < mass_percent_5)
00305                     {
00306                     if (width_factor > 1) printf("\""); else printf(" ");
00307                     }
00308                 else if (length_per_column * i < mass_percent[0])
00309                     {
00310                     if (width_factor > 1) printf(":"); else printf(" ");
00311                     within_mass_percent_5 = FALSE;
00312                     }
00313                 else if (length_per_column * i < mass_percent[1])
00314                     {
00315                     printf("|");
00316                     within_mass_percent_5 = FALSE;
00317                     within_mass_percent[0] = FALSE;
00318                     }
00319                 else if (length_per_column * i < mass_percent[2])
00320                     {
00321                     printf("X");
00322                     within_mass_percent_5 = FALSE;
00323                     within_mass_percent[0] = FALSE;
00324                     within_mass_percent[1] = FALSE;
00325                     }
00326                 else
00327                     {
00328                     printf("@");
00329                     within_mass_percent_5 = FALSE;
00330                     within_mass_percent[0] = FALSE;
00331                     within_mass_percent[1] = FALSE;
00332                     within_mass_percent[2] = FALSE;
00333                     }
00334                 }
00335             }
00336         else if (within_mass_percent_5)
00337             {
00338             if (length_per_column * i < mass_percent_5)
00339                 printf(" ");
00340             else
00341                 {
00342                 within_mass_percent_5 = FALSE;
00343                 if (length_per_column * i < mass_percent[0])
00344                     {
00345                     if (width_factor > 1) printf(":"); else printf(" ");
00346                     }
00347                 else if (length_per_column * i < mass_percent[1])
00348                     {
00349                     printf("|");
00350                     within_mass_percent[0] = FALSE;
00351                     }
00352                 else if (length_per_column * i < mass_percent[2])
00353                     {
00354                     printf("X");
00355                     within_mass_percent[0] = FALSE;
00356                     within_mass_percent[1] = FALSE;
00357                     }
00358                 else
00359                     {
00360                     printf("@");
00361                     within_mass_percent[0] = FALSE;
00362                     within_mass_percent[1] = FALSE;
00363                     within_mass_percent[2] = FALSE;
00364                     }
00365                 }
00366             }
00367         else if (within_mass_percent[0])
00368             {
00369             if (length_per_column * i < mass_percent[0])
00370                 printf(" ");
00371             else
00372                 {
00373                 within_mass_percent[0] = FALSE;
00374                 if (length_per_column * i < mass_percent[1])
00375                     {
00376                     printf("|");
00377                     }
00378                 else if (length_per_column * i < mass_percent[2])
00379                     {
00380                     printf("X");
00381                     within_mass_percent[1] = FALSE;
00382                     }
00383                 else
00384                     {
00385                     printf("@");
00386                     within_mass_percent[1] = FALSE;
00387                     within_mass_percent[2] = FALSE;
00388                     }
00389                 }
00390             }
00391         else if (within_mass_percent[1])
00392             {
00393             if (length_per_column * i < mass_percent[1])
00394                 printf(" ");
00395             else
00396                 {
00397                 within_mass_percent[1] = FALSE;
00398                 if (length_per_column * i < mass_percent[2])
00399                     {
00400                     printf("|");
00401                     }
00402                 else if (length_per_column * i < mass_percent[3])
00403                     {
00404                     printf("X");
00405                     within_mass_percent[2] = FALSE;
00406                     }
00407                 else
00408                     {
00409                     printf("@");
00410                     within_mass_percent[2] = FALSE;
00411                     within_mass_percent[3] = FALSE;
00412                     }
00413                 }
00414             }
00415         else if (within_mass_percent[2])
00416             {
00417             if (length_per_column * i < mass_percent[2])
00418                 printf(" ");
00419             else
00420                 {
00421                 within_mass_percent[2] = FALSE;
00422                 if (length_per_column * i < mass_percent[3])
00423                     {
00424                     printf("|");
00425                     }
00426                 else if (length_per_column * i < mass_percent[4])
00427                     {
00428                     printf("X");
00429                     within_mass_percent[3] = FALSE;
00430                     }
00431                 else
00432                     {
00433                     printf("@");
00434                     within_mass_percent[3] = FALSE;
00435                     within_mass_percent[4] = FALSE;
00436                     }
00437                 }
00438             }
00439         else if (within_mass_percent[3])
00440             {
00441             if (length_per_column * i < mass_percent[3])
00442                 printf(" ");
00443             else
00444                 {
00445                 within_mass_percent[3] = FALSE;
00446                 if (length_per_column * i < mass_percent[4])
00447                     {
00448                     printf("|");
00449                     }
00450                 else if (length_per_column * i < mass_percent[5])
00451                     {
00452                     printf("X");
00453                     within_mass_percent[4] = FALSE;
00454                     }
00455                 else
00456                     {
00457                     printf("@");
00458                     within_mass_percent[4] = FALSE;
00459                     within_mass_percent[5] = FALSE;
00460                     }
00461                 }
00462             }
00463         else if (within_mass_percent[4])
00464             {
00465             if (length_per_column * i < mass_percent[4])
00466                 printf(" ");
00467             else
00468                 {
00469                 within_mass_percent[4] = FALSE;
00470                 if (length_per_column * i < mass_percent[5])
00471                     {
00472                     printf("|");
00473                     }
00474                 else if (length_per_column * i < mass_percent[6])
00475                     {
00476                     printf("X");
00477                     within_mass_percent[5] = FALSE;
00478                     }
00479                 else
00480                     {
00481                     printf("@");
00482                     within_mass_percent[5] = FALSE;
00483                     within_mass_percent[6] = FALSE;
00484                     }
00485                 }
00486             }
00487         else if (within_mass_percent[5])
00488             {
00489             if (length_per_column * i < mass_percent[5])
00490                 printf(" ");
00491             else
00492                 {
00493                 within_mass_percent[5] = FALSE;
00494                 if (length_per_column * i < mass_percent[6])
00495                     {
00496                     printf("|");
00497                     }
00498                 else if (length_per_column * i < mass_percent[7])
00499                     {
00500                     printf("X");
00501                     within_mass_percent[6] = FALSE;
00502                     }
00503                 else
00504                     {
00505                     printf("@");
00506                     within_mass_percent[6] = FALSE;
00507                     within_mass_percent[7] = FALSE;
00508                     }
00509                 }
00510             }
00511         else if (within_mass_percent[6])
00512             {
00513             if (length_per_column * i < mass_percent[6])
00514                 printf(" ");
00515             else
00516                 {
00517                 within_mass_percent[6] = FALSE;
00518                 if (length_per_column * i < mass_percent[7])
00519                     {
00520                     printf("|");
00521                     }
00522                 else if (length_per_column * i < mass_percent[8])
00523                     {
00524                     printf("X");
00525                     within_mass_percent[7] = FALSE;
00526                     }
00527                 else
00528                     {
00529                     printf("@");
00530                     within_mass_percent[7] = FALSE;
00531                     within_mass_percent[8] = FALSE;
00532                     }
00533                 }
00534             }
00535         else if (within_mass_percent[7])
00536             {
00537             if (length_per_column * i < mass_percent[7])
00538                 printf(" ");
00539             else
00540                 {
00541                 within_mass_percent[7] = FALSE;
00542                 if (length_per_column * i < mass_percent[8])
00543                     {
00544                     printf("|");
00545                     }
00546                 else
00547                     {
00548                     printf("X");
00549                     within_mass_percent[8] = FALSE;
00550                     }
00551                 }
00552             }
00553         else if (within_mass_percent[8])
00554             {
00555             if (length_per_column * i < mass_percent[8])
00556                 printf(" ");
00557             else
00558                 {
00559                 within_mass_percent[8] = FALSE;
00560                 printf("|");
00561                 }
00562             }
00563         }
00564     printf("\n");
00565     }
00566 
00567 //-----------------------------------------------------------------------------
00568 //  main  --  driver to use  plot_mass_radii() as a tool
00569 //-----------------------------------------------------------------------------
00570 
00571 main(int argc, char ** argv)
00572 {
00573     char  *comment;
00574     bool  c_flag = FALSE;      /* if TRUE: a comment given on command line   */
00575     bool  t_flag = FALSE;      /* if TRUE: percentiles rather than quartiles */
00576     bool  d_flag = FALSE;      /* if TRUE: double width output, with even    */
00577                                /*          more percentiles                  */
00578     bool  q_flag = FALSE;      /* if TRUE: quadruple width output            */
00579 
00580     check_help();
00581 
00582     extern char *poptarg;
00583     int c;
00584     char* param_string = "c:tdq";
00585 
00586     while ((c = pgetopt(argc, argv, param_string)) != -1)
00587         switch(c)
00588             {
00589             case 'c': c_flag = TRUE;
00590                       comment = poptarg;
00591                       break;
00592             case 'd': d_flag = TRUE;
00593                       break;
00594             case 'q': q_flag = TRUE;
00595                       break;
00596             case 't': t_flag = TRUE;
00597                       break;
00598             case '?': params_to_usage(cerr, argv[0], param_string);
00599                       get_help();
00600                       exit(1);
00601             }            
00602 
00603     dyn *b;
00604     while (b = get_dyn(cin))
00605         {
00606         if (q_flag)
00607             plot_mass_radii_in_percentages(b,4);
00608         else if (d_flag)
00609             plot_mass_radii_in_percentages(b,2);
00610         else if (t_flag)
00611             plot_mass_radii_in_percentages(b,1);
00612         else
00613             plot_mass_radii(b);
00614 
00615         delete b;
00616         }
00617     }
00618 
00619 #endif
00620 
00621 // endof: lagradplot.C

Generated at Sun Feb 24 09:57:07 2002 for STARLAB by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001