Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

single_star_io.C

Go to the documentation of this file.
00001 //
00002 // single_star_io.C
00003 //
00004 
00005 //#include "hdyn.h"
00006 #include "single_star.h"
00007 #include "util_io.h"
00008 
00009 istream & single_star::scan_star_story(istream& s)
00010 {
00011     char input_line[MAX_INPUT_LINE_LENGTH];
00012 
00013     cerr << "\n\nUsing single_star_io version of scan_star_story()...\n\n";
00014 
00015     while(get_line(s,input_line), strcmp(END_STAR, input_line)){
00016         char keyword[MAX_INPUT_LINE_LENGTH];
00017         const char *val = getequals(input_line, keyword);
00018 
00019         real number;
00020         if(0){   // trick to keep the if() statement, for the else below
00021         }else if(!strcmp("Type",keyword)){
00022             char str_tpe[MAX_INPUT_LINE_LENGTH];
00023             sscanf(val,"%s",str_tpe);
00024 
00025         }else if(!strcmp("Class",keyword)){
00026             char str_cls[MAX_INPUT_LINE_LENGTH];
00027             sscanf(val,"%s",str_cls);
00028 
00029         }else if(!strcmp("T_cur",keyword)){
00030             set_current_time( strtod(val,NULL) );
00031 
00032         }else if(!strcmp("T_rel",keyword)){
00033             set_relative_age( strtod(val,NULL) );
00034 
00035         }else if(!strcmp("M_rel",keyword)){
00036             set_relative_mass( strtod(val,NULL) );
00037 
00038         }else if(!strcmp("M_env",keyword)){
00039             set_envelope_mass( strtod(val,NULL) );
00040 
00041         }else if(!strcmp("M_core",keyword)){
00042             set_core_mass( strtod(val,NULL) );
00043 
00044         }else if(!strcmp("M_COcore",keyword)){
00045             set_COcore_mass( strtod(val,NULL) );
00046 
00047         }else if(!strcmp("T_eff",keyword)){
00048             number = strtod(val,NULL);
00049             /* XXX ignore value?? */
00050 
00051         }else if(!strcmp("L_eff",keyword)){
00052             set_luminosity( strtod(val,NULL) );
00053 
00054         }else if(!strcmp("P_rot",keyword)){       // Experimental extra 
00055                                                   // information for 
00056           set_rotation_period( strtod(val,NULL) );// radio pulsars.
00057 
00058         } else if(!strcmp("B_fld",keyword)){
00059           set_magnetic_field( strtod(val,NULL) );
00060 
00061         }else{
00062             add_story_line(star_story, input_line);
00063         }
00064     }
00065 
00066     //if(current_time<=0) current_time = relative_age;
00067     return s;
00068 }
00069 
00070 ostream& single_star::print_star_story(ostream& s,
00071                                        int short_output)  // default = 0
00072 {
00073     put_story_header(s, STAR_ID);
00074 
00075     if (short_output) {
00076 
00077         // If we were to handle short output in the Star part of
00078         // the output stream, this is where it should be done.
00079         // However, for now it is simpler to handle all stellar
00080         // quantities in the Dyn output (in hdyn_io).
00081 
00082 #if 0
00083         put_string(s,      "  S  =  ", type_short_string(get_element_type()));
00084         put_real_number(s, "  T  =  ", temperature());
00085         put_real_number(s, "  L  =  ", get_luminosity());
00086 #endif
00087 
00088     } else {
00089 
00090         put_string(s,      "  Type   =  ", type_string(get_element_type()));
00091         if (get_spec_type(Accreting)==Accreting)
00092             put_string(s,  "  Class   =  ",
00093                        type_string(get_spec_type(Accreting)));
00094         put_real_number(s, "  T_cur  =  ", get_current_time());
00095         if (get_current_time()!=get_relative_age())
00096             put_real_number(s, "  T_rel  =  ", get_relative_age());
00097         put_real_number(s, "  M_rel  =  ", get_relative_mass());
00098         put_real_number(s, "  M_env  =  ", get_envelope_mass());
00099         put_real_number(s, "  M_core =  ", get_core_mass());
00100         put_real_number(s, "  T_eff  =  ", temperature());
00101         put_real_number(s, "  L_eff  =  ", get_luminosity());
00102 
00103         // Extra output for stars with CO cores
00104         if (star_with_COcore()) {
00105             put_real_number(s, "  M_COcore  =  ", get_COcore_mass());
00106         }
00107 
00108         // Extra output for radio- and X-ray pulsars.
00109         if (get_element_type()==Xray_Pulsar ||
00110             get_element_type()==Radio_Pulsar ||
00111             get_element_type()==Neutron_Star) {
00112             put_real_number(s, "  P_rot  =  ", get_rotation_period());
00113             put_real_number(s, "  B_fld  =  ", get_magnetic_field());
00114         }
00115 
00116         if (star_story)
00117             put_story_contents(s, *star_story);
00118     }
00119 
00120     put_story_footer(s, STAR_ID);
00121 
00122     return s;
00123 }
00124 
00125 void extract_line_text(stellar_type& type, real& t_cur, real& t_rel, 
00126                        real& m_rel, real& m_env, real& m_core, real& co_core,
00127                        real& t_eff, real& l_eff,
00128                        real& p_rot, real& b_fld,
00129                        story& s)
00130     {
00131 
00132         char line [MAX_INPUT_LINE_LENGTH];
00133         char type_string[MAX_INPUT_LINE_LENGTH];
00134 
00135         strcpy(line, s.get_text());
00136         char keyword[MAX_INPUT_LINE_LENGTH];
00137         const char *val = getequals(line, keyword);
00138 
00139 
00140         real number;
00141         if(0){   // trick to keep the if() statement, for the else below
00142         }else if(!strcmp("Type",keyword)){
00143             char str_tpe[MAX_INPUT_LINE_LENGTH];
00144             sscanf(val,"%s",type_string); 
00145             type = extract_stellar_type_string(type_string);
00146         }else if(!strcmp("T_cur",keyword)){
00147             t_cur = strtod(val,NULL);
00148         }else if(!strcmp("T_rel",keyword)){
00149             t_rel = strtod(val,NULL);
00150         }else if(!strcmp("M_rel",keyword)){
00151             m_rel = strtod(val,NULL);
00152         }else if(!strcmp("M_env",keyword)){
00153             m_env = strtod(val,NULL);
00154         }else if(!strcmp("M_core",keyword)){
00155             m_core = strtod(val,NULL);
00156         }else if(!strcmp("M_COcore",keyword)){
00157             co_core = strtod(val,NULL);
00158         }else if(!strcmp("T_eff",keyword)){
00159             t_eff = strtod(val,NULL);
00160         }else if(!strcmp("L_eff",keyword)){
00161             l_eff = strtod(val,NULL);
00162         }else if(!strcmp("P_rot",keyword)){       // Experimental extra 
00163             p_rot = strtod(val,NULL);             // information for 
00164                                                   // radio pulsars
00165         }else if(!strcmp("B_fld",keyword)){       // Only for neutron stars
00166             b_fld = strtod(val,NULL);
00167         }
00168 
00169     }
00170 
00171 void extract_story_chapter(stellar_type& type, real& t_cur, real& t_rel, 
00172                            real& m_rel, real& m_env, real& m_core, 
00173                            real& co_core,
00174                            real& T_eff, real& L_eff,
00175                            real& p_rot, real& b_fld, story& s)
00176 {
00177     
00178     if (!s.get_chapter_flag())
00179         {
00180         cerr << "extract_story_chapter: not a story\n";
00181         exit(1);
00182         }
00183 
00184     t_rel=-1;
00185       
00186     for (story * d = s.get_first_daughter_node();
00187          d != NULL;
00188          d = d->get_next_story_node()) {
00189 
00190       if (d->get_chapter_flag()) 
00191         extract_story_chapter(type, t_cur, t_rel,
00192                               m_rel, m_env, m_core, co_core,
00193                               T_eff, L_eff, p_rot, b_fld, *d);
00194       else 
00195         extract_line_text(type, t_cur, t_rel,
00196                           m_rel, m_env, m_core, co_core,
00197                           T_eff, L_eff, p_rot, b_fld, *d);
00198     }
00199     
00200     if (t_rel<=0)
00201       t_rel = t_cur;
00202 }
00203 
00204 void single_star::star_transformation_story(stellar_type new_type)
00205 {
00206     char info_line[MAX_STORY_LINE_LENGTH];
00207     stellar_type old_type = get_element_type();
00208     real time = get_current_time();
00209 
00210     sprintf(info_line,
00211             "%s_to_%s_at_time = %6.2f",
00212             type_string(old_type), type_string(new_type), time);
00213 
00214     add_story_line(get_node()->get_log_story(), info_line);
00215 
00216     // cerr output for debugging!
00217 
00218     cerr << endl << get_node()->format_label() << " " << info_line
00219          << " Myr (old mass = " << get_total_mass() << ")" << endl;
00220 
00221     if(is_binary_component()) {
00222         cerr << "binary companion: " 
00223              << type_string(get_companion()->get_element_type()) << endl;
00224         cerr << "parent: " << get_node()->get_parent()->format_label() 
00225              << endl;
00226     }
00227 }
00228 
00229 void single_star::post_supernova_story()
00230 {
00231     char info_line[MAX_STORY_LINE_LENGTH];
00232 
00233     sprintf(info_line, "v_kick = %6.2f, %6.2f, %6.2f",
00234             anomal_velocity[0], anomal_velocity[1], anomal_velocity[2]);
00235 
00236     add_story_line(get_node()->get_log_story(), info_line);
00237 }
00238 
00239 void single_star::first_roche_lobe_contact_story(stellar_type accretor)
00240 {
00241     char info_line[MAX_STORY_LINE_LENGTH];
00242     real time = get_current_time();
00243      
00244     sprintf(info_line,
00245             "%s_%s_%s_RLOF_to_%s_at_time = %6.2f",
00246             type_string(get_element_type()),
00247             type_string(get_spectral_class(temperature())),
00248             type_string(get_luminosity_class(temperature(), luminosity)),
00249             type_string(accretor), time);
00250 
00251     add_story_line(get_node()->get_log_story(), info_line);
00252 
00253 }

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