Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

extract_star_story.C

Go to the documentation of this file.
00001 
00002        //=======================================================//    _\|/_
00003       //  __  _____           ___                    ___       //      /|\ ~
00004      //  /      |      ^     |   \  |         ^     |   \     //          _\|/_
00005     //   \__    |     / \    |___/  |        / \    |___/    //            /|\ ~
00006    //       \   |    /___\   |  \   |       /___\   |   \   // _\|/_
00007   //     ___/   |   /     \  |   \  |____  /     \  |___/  //   /|\ ~
00008  //                                                       //            _\|/_
00009 //=======================================================//              /|\ ~
00010 
00011 /*
00012  *  addstar.C: creates a star part for each body
00013  *.............................................................................
00014  *    version 1.0:  Apr 1993   Piet Hut, Steve McMillan, Jun Makino
00015  *.............................................................................
00016  *  This file includes the following non-local functions:
00017  *    addstar - creates a star part for each node
00018  *.............................................................................
00019  */
00020 #include "main_sequence.h"
00021 #include "util_io.h"
00022 
00023 #ifndef TOOLBOX
00024 
00025 void dump_line_text(ostream& str, story& s)
00026     {
00027 #ifndef BAD_GNU_IO
00028     str << s.get_text() << "\n";
00029 #else
00030     fprintf(stdout, "%s\n", s.get_text());
00031 #endif
00032     }
00033 
00034 void extract_line_text(char* type, real& t_cur,  real& t_rel,
00035                        real& m_rel, real& m_env,
00036                        real& m_core, real& co_core,
00037                        real& t_eff, real& l_eff,
00038                        real& p_rot, real& b_fld,
00039                        story& s)
00040     {
00041 
00042         char keyword[MAX_INPUT_LINE_LENGTH];
00043         char should_be_equal_sign[MAX_INPUT_LINE_LENGTH];
00044         char line [MAX_INPUT_LINE_LENGTH];
00045         strcpy(line, s.get_text());
00046         sscanf(line,"%s%s",keyword,should_be_equal_sign);
00047         if(strcmp("=",should_be_equal_sign)){
00048             cerr << "Expected '=', but got '"<< should_be_equal_sign <<"'\n";
00049             exit(1);
00050         }
00051 
00052         real number;
00053         if(0){   // trick to keep the if() statement, for the else below
00054         }else if(!strcmp("Type",keyword)){
00055             char str_tpe[MAX_INPUT_LINE_LENGTH];
00056             sscanf(line,"%*s%*s%s",type);
00057         }else if(!strcmp("T_cur",keyword)){
00058             sscanf(line,"%*s%*s%lf",&t_cur);
00059         }else if(!strcmp("T_rel",keyword)){
00060             sscanf(line,"%*s%*s%lf",&t_rel);
00061         }else if(!strcmp("M_rel",keyword)){
00062             sscanf(line,"%*s%*s%lf",&m_rel);
00063         }else if(!strcmp("M_env",keyword)){
00064             sscanf(line,"%*s%*s%lf",&m_env);
00065         }else if(!strcmp("M_core",keyword)){
00066             sscanf(line,"%*s%*s%lf",&m_core);
00067         }else if(!strcmp("M_COcore",keyword)){
00068             sscanf(line,"%*s%*s%lf",&m_core);
00069         }else if(!strcmp("T_eff",keyword)){
00070             sscanf(line,"%*s%*s%lf",&t_eff);
00071         }else if(!strcmp("L_eff",keyword)){
00072             sscanf(line,"%*s%*s%lf",&l_eff);
00073         }else if(!strcmp("P_rot",keyword)){       // Experimental extra
00074             sscanf(line,"%*s%*s%lf",&p_rot);     // information for
00075         }else if(!strcmp("B_fld",keyword)){       // Only for neutron stars
00076             sscanf(line,"%*s%*s%lf",&b_fld);
00077         }
00078 
00079     }
00080 
00081 void extract_story_chapter(char* type, real& t_cur, real& t_rel,
00082                            real& m_rel, real& m_env, real& m_core,
00083                            real& co_core,
00084                            real& t_eff, real& l_eff,
00085                            real& p_rot, real& b_fld,
00086                            story& s) {
00087 
00088 
00089     if (!s.get_chapter_flag())
00090         {
00091         cerr << "extract_story_chapter: not a story\n";
00092         exit(1);
00093         }
00094 
00095 
00096     t_rel=-1;
00097 
00098     for (story * d = s.get_first_daughter_node(); d != NULL;
00099                                                   d = d->get_next_story_node())
00100       {
00101         
00102         
00103         if (d->get_chapter_flag())
00104           extract_story_chapter(type, t_cur, t_rel,
00105                                 m_rel, m_env, m_core, co_core,
00106                                 t_eff, l_eff,
00107                                 p_rot, b_fld, *d);
00108         else
00109           extract_line_text(type, t_cur, t_rel,
00110                             m_rel, m_env, m_core, co_core,
00111                             t_eff, l_eff,
00112                             p_rot, b_fld, *d);
00113       }
00114 
00115     if (t_rel<=0)
00116       t_rel = t_cur;
00117 }
00118 
00119 /*-----------------------------------------------------------------------------
00120  *  addstar  -- for all particles, add a star part using "new star()".
00121  *-----------------------------------------------------------------------------
00122  */
00123 void  addstar(node * b, real t_rel, stellar_type type,
00124                         real mf=1, real rf=1, real tf=1) {
00125       node * bi;
00126 
00127       if (b->get_oldest_daughter() != NULL)
00128          for (bi=b->get_oldest_daughter(); bi != NULL;
00129                                            bi=bi->get_younger_sister())
00130             addstar(bi, t_rel, type, mf, rf, tf);
00131       else {
00132          int id = b->get_index();
00133          real t_cur=0, t_rel=0, m_rel=1, m_env=0, m_core=0.01, co_core=0;
00134          real t_eff=0, l_eff=0;
00135          real p_rot=0, b_fld=0;
00136          real m_tot;
00137          char type_string[MAX_INPUT_LINE_LENGTH];
00138          starbase * old_starbase = b->get_starbase();
00139          story * s = old_starbase->get_star_story();
00140 
00141          extract_story_chapter(type_string, t_cur, t_rel,
00142                                m_rel, m_env, m_core, co_core,
00143                                t_eff, l_eff,
00144                                p_rot, b_fld, *s);
00145          m_tot = m_env+m_core;
00146          stellar_type local_type = extract_stellar_type_string(type_string);
00147 
00148          if (local_type!=NAS) {         // is the star properly defined.
00149             type = local_type;
00150             single_star* new_star = new_single_star(type, id, t_cur, t_rel,
00151                          m_rel, m_tot, m_core, co_core, p_rot, b_fld,  b);
00152 
00153          }
00154          else {         // No star story present, at least no proper
00155                         // definition for a single star.
00156             real t_cur=0,t_rel=0, r_eff=0, m_rel=1, m_core=0.01;
00157             real m_tot, p_rot=0, b_fld=0;
00158             starbase * old_starbase = b->get_starbase();
00159             id = b->get_index();
00160             m_rel = m_tot = b->get_mass()/mf;
00161 
00162             // Treat by dynamics pre-requested black holes
00163             if(getiq(b->get_log_story(), "black_hole")==1) {
00164               single_star* new_star = new_single_star(Black_Hole, id,
00165                                                       t_cur, t_rel,
00166                                                       m_rel, m_tot, m_tot,
00167                                                       m_tot,
00168                                                       p_rot, b_fld, b);
00169             }
00170             else {
00171               single_star* new_star = new_single_star(type, id,
00172                                                     t_cur, t_rel,
00173                                                     m_rel, m_tot, m_core,
00174                                                     co_core,
00175                                                     p_rot, b_fld, b);
00176 
00177 //            single_star* new_star = new_single_star(type, id, t_cur, t_rel,
00178 //                         m_rel, m_tot, m_core, co_core, p_rot, b_fld, b);
00179 
00180           }
00181         }
00182      }
00183   }
00184 
00185 #  define  FALSE  0
00186 #  define  TRUE   1
00187 
00188 #else
00189 
00190 /*-----------------------------------------------------------------------------
00191  *  main  --
00192  *-----------------------------------------------------------------------------
00193  */
00194 main(int argc, char ** argv)
00195     {
00196     int  c;
00197     bool  t_flag = FALSE;
00198     bool  M_flag = FALSE;
00199     bool  R_flag = FALSE;
00200     bool  T_flag = FALSE;
00201     bool  s_flag = FALSE;
00202     bool  c_flag = FALSE;
00203     real  mf = 1;
00204     real  rf = 1;
00205     real  tf = 1;
00206     real  t_rel = 0;
00207     stellar_type type = Main_Sequence;
00208 
00209     char  *comment;
00210     extern char *poptarg;
00211     int  pgetopt(int, char **, char *);
00212 
00213     while ((c = pgetopt(argc, argv, "M:R:T:t:s:c:")) != -1)
00214         switch(c)
00215             {
00216             case 'M': M_flag = TRUE;
00217                       mf = atof(poptarg);
00218                       break;
00219             case 'R': R_flag = TRUE;
00220                       rf = atof(poptarg);
00221                       break;
00222             case 'T': T_flag = TRUE;
00223                       tf = atof(poptarg);
00224                       break;
00225             case 't': T_flag = TRUE;
00226                       t_rel = atof(poptarg);
00227                       break;
00228             case 's': s_flag = TRUE;
00229                       type = (stellar_type)atoi(poptarg);
00230                       break;
00231             case 'c': c_flag = TRUE;
00232                       comment = poptarg;
00233                       break;
00234             case '?': cerr <<
00235                       "usage: addstar [-t #] [-T #] [-c \"..\"]\n";
00236                       exit(1);
00237             }
00238 
00239     node *b;
00240 
00241     while (b = get_node(cin))
00242         {
00243         if (c_flag == TRUE)
00244             b->log_comment(comment);
00245         b->log_history(argc, argv);
00246 
00247         addstar(b, t_rel, type, mf, rf, tf);
00248 
00249         put_node(cout, *b);     
00250         delete b;
00251         }
00252     }
00253 
00254 #endif

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