Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

hrd_util.C

Go to the documentation of this file.
00001 
00002 //#include <strstream.h>
00003 #include "sdyn3.h"
00004 #include "xhrdplot.h"
00005 #include "single_star.h"
00006 
00007 // Open windows for plotting and instructions, set up color schemes, etc.
00008 static float linespacing;    // Set in xstarplot.  Too many references
00009 
00010 
00011 void initialize_hrd_graphics(float r_factor,         // (input) scale factor
00012                          bool b_flag,                // (input) color scheme
00013                          unsigned long& hrd_win,     // ID of plot window
00014                          unsigned long& hrd_instr,   // ID of status window
00015                          unsigned long& hrd_colwin,  // ID of color window
00016                          unsigned long* c_index,     // color by index 
00017                          unsigned long* c_energy,    // color by energy
00018                          int& win_size,              // width of plot window
00019                          int& hrd_xorigin, int& hrd_yorigin) // origin for dialog box
00020 {
00021     // This is a kludge to try to get the font size right...
00022     // Note that the same font is used everywhere.
00023 
00024     // The layout works best for 0.6 < r_factor < 1.3.
00025 
00026     if (r_factor >= 1.0) {
00027         set_default_font("9x15");
00028         linespacing = 1.2;
00029     } else if (r_factor >= 0.8) {
00030         set_default_font("7x13");
00031         if (r_factor >= 0.9)
00032             linespacing = 1.15;
00033         else
00034             linespacing = 1.1;
00035     } else if (r_factor >= 0.65) {
00036         set_default_font("6x12");
00037         if (r_factor >= 0.725)
00038             linespacing = 1.05;
00039         else
00040             linespacing = 1.0;
00041     } else if (r_factor >= 0.5) {
00042         set_default_font("6x10");
00043         if (r_factor >= 0.575)
00044             linespacing = 1.05;
00045         else
00046             linespacing = 1.0;
00047     } else if (r_factor >= 0.4) {
00048         set_default_font("6x9");
00049         linespacing = 1.0;
00050     } else {
00051         set_default_font("5x8");
00052         linespacing = 1.0;
00053     }
00054 
00055     // The twm title bar is ~27-30 pixels (*independent* of scaling),
00056     // but the bar doesn't count in the location of the window!
00057     // Mac windows need more space (frame at bottom too).
00058     // Assume that scale factors of 0.75 or less mean we are
00059     // using a Mac or PC display.  Also, for r_factor > 1.1, move
00060     // the  "colwin" box up and over.
00061 
00062     // Main window:
00063 
00064     int title = 27;
00065     int bottom = 0;
00066     if (r_factor <= 0.75) {
00067         title = 20;
00068         bottom = 20;
00069     }
00070 
00071     int xsize = _R_(400);
00072     int ysize = _R_(400);
00073     hrd_xorigin = xsize + 6;
00074     hrd_yorigin = 0;
00075     hrd_win = lux_openwin(hrd_xorigin, hrd_yorigin, xsize, ysize);
00076     lux_set_window_name(hrd_win, "Hertzsprung-Russel");
00077 
00078     win_size = xsize;
00079 
00080     // Status window:
00081 
00082     if (r_factor <= 1)
00083         hrd_yorigin += ysize + title + bottom;
00084     else
00085         hrd_yorigin += ysize + 2*title + bottom;
00086 
00087     // (Extra factor of 2 seems to improve layout...)
00088 
00089     ysize = _R_(260);
00090     if (r_factor <= 0.6) {
00091         xsize = (int) (xsize * 1.25);
00092         ysize = (int) (ysize * 1.1);
00093     }
00094     hrd_instr = lux_openwin(hrd_xorigin, hrd_yorigin, xsize, ysize);
00095     lux_set_window_name(hrd_instr, "Status & Commands");
00096 
00097     // Color window:
00098 
00099     if (r_factor <= 1.1 && r_factor > 0.75) {
00100         hrd_yorigin += ysize + title + bottom;
00101     } else {
00102         int edge = 3;
00103         if (r_factor <= 0.6) xsize = (int) (xsize / 1.25);
00104         hrd_xorigin += xsize + edge;
00105         hrd_yorigin = 0;
00106     }
00107     if (r_factor <= 0.6) {
00108         xsize = (int) (xsize * 1.25);
00109         ysize = (int) (ysize * 1.1);
00110     }
00111     if (r_factor <= 0.6) ysize =  (int) (ysize * 1.1);
00112     hrd_colwin = lux_openwin(hrd_xorigin, hrd_yorigin, xsize, ysize);
00113     lux_set_window_name(hrd_colwin, "Color coding");
00114 
00115     init_colors(hrd_win, c_energy, c_index, b_flag);
00116 
00117     lux_set_noupdate(hrd_win);
00118     lux_set_bgcolor(hrd_win,c_energy[background_color]);
00119     lux_set_window_bgcolor(hrd_win,c_energy[background_color]);
00120     lux_set_color(hrd_win,c_energy[default_color]);
00121 
00122     lux_set_noupdate(hrd_colwin);
00123     lux_set_bgcolor(hrd_colwin,c_energy[background_color]);
00124     lux_set_window_bgcolor(hrd_colwin,c_energy[background_color]);
00125     lux_set_color(hrd_colwin,c_energy[default_color]);
00126 
00127     lux_set_noupdate(hrd_instr);
00128     lux_set_bgcolor(hrd_instr,c_energy[background_color]);
00129     lux_set_window_bgcolor(hrd_instr,c_energy[background_color]);
00130     lux_set_color(hrd_instr,c_energy[default_color]);
00131 
00132     lux_setup_region(hrd_win, 1.0, 1.0, 8.0, 8.0);
00133 
00134     // Set up origin of dialog box.
00135 
00136     if (r_factor <= 1.1 && r_factor > 0.75) {
00137         int edge = 3;
00138         hrd_xorigin += xsize + edge;
00139         hrd_yorigin = 0;
00140     } else
00141         hrd_yorigin += ysize + title + bottom;
00142 }
00143 
00144 void set_hrd_limits(float& xmin, float& xmax,
00145                     float& ymin, float& ymax)
00146 {
00147     xmin = -1.0;
00148     xmax = 7.0;
00149     ymin = -1;
00150     ymax = 7;
00151 //    xmin = -3.0;
00152 //    xmax = 10.0;
00153 //    ymin = -5;
00154 //    ymax = 8;
00155 }
00156 
00157 void derive_stellar_type(dyn* bj, dyn* bi, char& c)
00158 {
00159     c = default_color;
00160     real rmin = VERY_LARGE_NUMBER;
00161     dynptr bmin = bi;
00162 
00163     stellar_type type = NAS;
00164     real t_cur, t_rel, m_rel, m_env, m_core, T_eff, L_eff, p_rot, b_fld;
00165     t_cur=t_rel=m_rel=m_env=m_core=T_eff=L_eff=p_rot=b_fld=0;
00166     story *s = bi->get_starbase()->get_star_story();
00167     extract_story_chapter(type, t_cur, t_rel,
00168                           m_rel, m_env, m_core,
00169                           T_eff, L_eff, p_rot, b_fld, *s);
00170 //cerr<<"star: "<<type<<" " <<t_rel<<" " <<m_rel<<" " <<m_env<<" "
00171 //<<m_core<<" "<<T_eff<< " "<< L_eff<<endl;
00172     switch(summarize_stellar_type(type)) {
00173        case ZAMS          : c = bound_binary;
00174                             break;
00175        case Early_Giant   : c = unbound_binary;
00176                             break;
00177        case Late_Giant    : c = unbound_single;
00178                             break;
00179        case Helium_Remnant: c = default_color;
00180                             break;
00181        case Inert_Remnant : c = bound_single;
00182                             break;
00183        default            : c = default_color;
00184        break;
00185     }
00186 }
00187 
00188 void show_hrd_color_scheme(unsigned long co, unsigned long *c_e, unsigned long *c_i,
00189                        float r, char ce, bool b_flag, int u)
00190 {
00191     lux_clear_window(co);
00192 
00193     if (ce==1) {
00194         show_instructions(co, r, "Color by stellar type:\n",0,u);
00195         lux_set_color(co, c_e[bound_binary]);
00196         show_instructions(co, r, "  Green  = main sequence star\n",3,u);
00197         lux_set_color(co, c_e[unbound_binary]);
00198         show_instructions(co, r, "  Gold   = sub giant\n",5,u);
00199         lux_set_color(co, c_e[unbound_single]);
00200         show_instructions(co, r, "  Red    = red giant\n",4,u);
00201         lux_set_color(co, c_e[default_color]);
00202         if (b_flag)
00203             show_instructions(co, r,
00204                               "  White  = white dwarf of helium star\n",2,u);
00205         else
00206             show_instructions(co, r,
00207                               "  Black  = white dwarf of helium star\n",2,u);
00208         lux_set_color(co, c_e[bound_single]);
00209         show_instructions(co, r,
00210                               "  Blue   = neutron star or black hole\n",1,u);
00211         lux_set_color(co, c_e[default_color]);
00212 
00213     } else if(ce==2) {
00214         show_instructions(co, r, "Color by energy:\n",0,u);
00215         lux_set_color(co, c_e[default_color]);
00216         if (b_flag) 
00217             show_instructions(co, r,
00218                               "  White  = default (bound to cluster)\n",1,u);
00219         else 
00220             show_instructions(co, r,
00221                               "  Black  = default (bound to cluster)\n",1,u);
00222         lux_set_color(co, c_e[bound_single]);
00223         show_instructions(co, r, "  Blue   = bound to nearest neighbor\n",2,u);
00224         lux_set_color(co, c_e[bound_binary]);
00225         show_instructions(co, r, "  Green  = bound binary\n",3,u);
00226         lux_set_color(co, c_e[unbound_single]);
00227         show_instructions(co, r, "  Red    = unbound single star\n",4,u);
00228         lux_set_color(co, c_e[unbound_binary]);
00229         show_instructions(co, r, "  Gold   = unbound binary\n",5,u);
00230         lux_set_color(co, c_e[default_color]);
00231      }
00232      else {
00233 
00234         show_instructions(co, r, "Color by index:\n",0,u);
00235         lux_set_color(co, c_i[1]);
00236 
00237         if (b_flag) {
00238             format_and_show_instructions(co, r, c_i,  1, 0, "white", 1, u);
00239             format_and_show_instructions(co, r, c_i,  2, 1, RV_COLOR2, 1, u);
00240             format_and_show_instructions(co, r, c_i,  3, 2, RV_COLOR3, 1, u);
00241             format_and_show_instructions(co, r, c_i,  4, 0, RV_COLOR4, 2, u);
00242             format_and_show_instructions(co, r, c_i,  5, 1, RV_COLOR5, 2, u);
00243             format_and_show_instructions(co, r, c_i,  6, 2, RV_COLOR6, 2, u);
00244             format_and_show_instructions(co, r, c_i,  7, 0, RV_COLOR7, 3, u);
00245             format_and_show_instructions(co, r, c_i,  8, 1, RV_COLOR8, 3, u);
00246             format_and_show_instructions(co, r, c_i,  9, 2, RV_COLOR9, 3, u);
00247             format_and_show_instructions(co, r, c_i, 10, 0, RV_COLORa, 4, u);
00248             format_and_show_instructions(co, r, c_i, 11, 1, RV_COLORb, 4, u);
00249             format_and_show_instructions(co, r, c_i, 12, 2, RV_COLORc, 4, u);
00250             format_and_show_instructions(co, r, c_i, 13, 0, RV_COLORd, 5, u);
00251             format_and_show_instructions(co, r, c_i, 14, 1, RV_COLORe, 5, u);
00252             format_and_show_instructions(co, r, c_i, 15, 2, RV_COLORf, 5, u);
00253             format_and_show_instructions(co, r, c_i, 16, 0, RV_COLORg, 6, u);
00254         } else {
00255             format_and_show_instructions(co, r, c_i,  1, 0, "black", 1, u);
00256             format_and_show_instructions(co, r, c_i,  2, 1, NV_COLOR2, 1, u);
00257             format_and_show_instructions(co, r, c_i,  3, 2, NV_COLOR3, 1, u);
00258             format_and_show_instructions(co, r, c_i,  4, 0, NV_COLOR4, 2, u);
00259             format_and_show_instructions(co, r, c_i,  5, 1, NV_COLOR5, 2, u);
00260             format_and_show_instructions(co, r, c_i,  6, 2, NV_COLOR6, 2, u);
00261             format_and_show_instructions(co, r, c_i,  7, 0, NV_COLOR7, 3, u);
00262             format_and_show_instructions(co, r, c_i,  8, 1, NV_COLOR8, 3, u);
00263             format_and_show_instructions(co, r, c_i,  9, 2, NV_COLOR9, 3, u);
00264             format_and_show_instructions(co, r, c_i, 10, 0, NV_COLORa, 4, u);
00265             format_and_show_instructions(co, r, c_i, 11, 1, NV_COLORb, 4, u);
00266             format_and_show_instructions(co, r, c_i, 12, 2, NV_COLORc, 4, u);
00267             format_and_show_instructions(co, r, c_i, 13, 0, NV_COLORd, 5, u);
00268             format_and_show_instructions(co, r, c_i, 14, 1, NV_COLORe, 5, u);
00269             format_and_show_instructions(co, r, c_i, 15, 2, NV_COLORf, 5, u);
00270             format_and_show_instructions(co, r, c_i, 16, 0, NV_COLORg, 6, u);
00271         } 
00272     lux_set_color(co, c_i[default_color]);
00273     }
00274 }
00275 
00276 void show_hrd_information(unsigned long instr,float r,int d, int u, dyn* b) {
00277 
00278 //              Methos for plotting HRD.
00279       real total_mass=0;
00280       real t_cur, t_rel, m_rel, m_env, m_core, T_eff, L_eff, p_rot, b_fld;
00281       t_cur=t_rel=m_rel=m_env=m_core=T_eff=L_eff=p_rot=b_fld=0;
00282       stellar_type type=NAS;
00283       story *st = NULL;
00284       int su[6] = {0, 0, 0, 0, 0, 0};
00285       real mu[6] = {0, 0, 0, 0, 0, 0};
00286       for_all_leaves(dyn, b, bi) {
00287          st = bi->get_starbase()->get_star_story();
00288          extract_story_chapter(type, t_cur, t_rel, m_rel, m_env, m_core, 
00289                                T_eff, L_eff, p_rot, b_fld, *st);
00290          total_mass += m_env+m_core;
00291          if (type<= Main_Sequence) {
00292             su[0]++;
00293             mu[0] += (m_env + m_core);
00294          }
00295          else 
00296          if (type<= Sub_Giant) {
00297            su[1]++; 
00298            mu[1] += (m_env + m_core);
00299          }
00300          else 
00301          if (type<= Super_Giant) {
00302            su[2]++; 
00303            mu[2] += (m_env + m_core);
00304          }
00305          else 
00306          if (type== Helium_Star || type== White_Dwarf) {
00307            su[3]++; 
00308            mu[3] += (m_env + m_core);
00309          }
00310          else 
00311          if (type== Neutron_Star || type== Black_Hole) {
00312            su[4]++; 
00313            mu[4] += (m_env + m_core);
00314          }
00315          else {
00316            su[5]++; 
00317            mu[5] += (m_env + m_core);
00318          }
00319       // extract binary information should go here.
00320       // compute_energies(b, bi, c);
00321       }
00322 
00323       mu[0] /= total_mass;
00324       mu[1] /= total_mass;
00325       mu[2] /= total_mass;
00326       mu[3] /= total_mass;
00327       mu[4] /= total_mass;
00328       mu[5] /= total_mass;
00329 
00330       char *centence = new char[500];
00331       sprintf(centence,  
00332 "Hertzsprung-Russel Diagram information
00333   total mass       : %6.1f Mo\n\
00334   Stellar contents : N       mass fr.\n\
00335    Main sequence   : %5d   %5.3f\n\
00336    Early giant     : %5d   %5.3f\n\
00337    Late type giant : %5d   %5.3f\n\
00338    Helium rich star: %5d   %5.3f\n\
00339    inert remnant   : %5d   %5.3f\n\
00340    other           : %5d   %5.3f\n\n\
00341    Binary information should go here:\n\
00342 ",total_mass, su[0], mu[0], su[1], mu[1], su[2], mu[2], su[3], mu[3],
00343               su[4], mu[4], su[5], mu[5]); 
00344 
00345     show_instructions(instr, r, centence, u);
00346     delete centence;
00347 }
00348 
00349 
00350 

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