Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

_dyn_io.C

Go to the documentation of this file.
00001 
00002        //=======================================================//    _\|/_
00003       //  __  _____           ___                    ___       //      /|\ ~
00004      //  /      |      ^     |   \  |         ^     |   \     //          _\|/_
00005     //   \__    |     / \    |___/  |        / \    |___/    //            /|\ ~
00006    //       \   |    /___\   |  \   |       /___\   |   \   // _\|/_
00007   //     ___/   |   /     \  |   \  |____  /     \  |___/  //   /|\ ~
00008  //                                                       //            _\|/_
00009 //=======================================================//              /|\ ~
00010 
00017 
00018 #include "_dyn_.h"
00019 #include "util_io.h"
00020 
00021 #ifndef TOOLBOX
00022 
00023 // Initialize any static _dyn_ data here...
00024 //
00025 // ...
00026 
00027 static bool read_xreal = false;
00028 
00029 void _dyn_::print_static(ostream& s)            // default = cerr
00030 {
00031     dyn::print_static(s);
00032 }
00033 
00034 void _dyn_::null_pointers()
00035 {
00036     // Clear all pointers (don't touch what they point to)
00037     // -- for use in cleaning up temporary nodes...  Careful!!
00038 
00039     slow = NULL;
00040     sp =NULL;
00041 
00042     dyn::null_pointers();
00043 }
00044 
00045 istream & _dyn_::scan_dyn_story(istream & s)
00046 {
00047     char input_line[MAX_INPUT_LINE_LENGTH];
00048     real last_real = false;
00049 
00050     while (get_line(s, input_line), strcmp(END_DYNAMICS, input_line)) {
00051 
00052         char keyword[MAX_INPUT_LINE_LENGTH];
00053         const char *val = getequals(input_line, keyword);
00054 
00055         // See xreal notes in dyn_io.C...
00056 
00057         if (!strcmp("real_system_time", keyword)) {
00058 
00059             read_xreal = true;
00060             last_real = true;
00061 
00062         } else if (!strcmp("system_time", keyword)) {
00063 
00064             // Check input format before reading.
00065 
00066             if (!last_real) read_xreal = false;
00067 
00068             if (read_xreal) {
00069                 cerr << "_dyn_::scan_dyn_story: reading xreal time data"
00070                      << endl;
00071 
00072                 set_system_time(get_xreal_from_input_line(input_line));
00073                 cerr << "system_time = " << system_time << " ";
00074             } else {
00075                 cerr << "_dyn_::scan_dyn_story: reading real time data"
00076                      << endl;
00077                 real_system_time = system_time = strtod(val, NULL);
00078                 cerr << "system_time = " << system_time << " ";
00079             }
00080 
00081         } else {
00082 
00083             last_real = false;
00084 
00085             if (!strcmp("t", keyword)) {
00086 
00087                 if (read_xreal)
00088                     time = get_xreal_from_input_line(input_line);
00089                 else {
00090                     time = strtod(val, NULL);
00091                 }
00092 
00093             } else if (!strcmp("dt", keyword))
00094                 timestep = strtod(val, NULL);
00095             else if (!strcmp("m", keyword))
00096                 mass = strtod(val, NULL);
00097             else if (!strcmp("r", keyword))
00098                 set_vector_from_input_line(pos, input_line);
00099             else if (!strcmp("v", keyword))
00100                 set_vector_from_input_line(vel, input_line);
00101             else if (!strcmp("a", keyword))
00102                 set_vector_from_input_line(acc, input_line);
00103             else if (!strcmp("pot", keyword))
00104                 pot = strtod(val, NULL);
00105             else if (!strcmp("R_eff", keyword))
00106                 radius = strtod(val, NULL);
00107             else
00108                 add_story_line(dyn_story, input_line);
00109         }
00110     }
00111 
00112     return s;
00113 }
00114 
00115 local void print_local_time(xreal time,
00116                             xreal system_time,
00117                             ostream & s,
00118                             bool print_xreal,
00119                             int short_output)
00120 {
00121     // Always print high-precision real system_time for t in the
00122     // short_output case.  (In general, the output precision is
00123     // controlled with the STARLAB_PRECISION environment variable.)
00124 
00125     if (short_output) {
00126 
00127         adjust_starlab_precision(HIGH_PRECISION);
00128         put_real_number(s, "  t  =  ", (real)system_time);
00129         if (short_output) adjust_starlab_precision(-1);
00130 
00131     } else {
00132 
00133         if (print_xreal)
00134             put_real_number(s, "  t  =  ", time);       // OK for real or xreal
00135         else
00136             put_real_number(s, "  t  =  ", (real)time);
00137 
00138     }
00139 }
00140 
00141 ostream & _dyn_::print_dyn_story(ostream & s,
00142                                  bool print_xreal,      // default = true
00143                                  int short_output)      // default = 0
00144 {
00145     // Modifications by Steve (5/01) to streamline output.
00146 
00147     // Ordinarily we want to print time before dyn stuff, but it is
00148     // necessary to print system time first for the root node...
00149 
00150     if (parent) print_local_time(time, system_time,
00151                                  s, print_xreal, short_output);
00152 
00153     // Awkward (dyn output prints pos), but...
00154 
00155     vector tmp_pos, tmp_vel;
00156     if (short_output > 1) {
00157         tmp_pos = pos;
00158         tmp_vel = vel;
00159         pos = pred_pos;
00160         vel = pred_vel;
00161     }
00162 
00163     // Use dyn::print_dyn_story() to print dyn stuff...
00164 
00165     dyn::print_dyn_story(s, print_xreal, short_output);
00166 
00167     if (short_output > 1) {
00168         pos = tmp_pos;
00169         vel = tmp_vel;
00170     }
00171 
00172     if (!parent) print_local_time(time, system_time,
00173                                   s, print_xreal, short_output);
00174 
00175     if (!short_output) {
00176         put_real_vector(s, "  a  =  ", acc);
00177         put_real_number(s, "  pot  =  ", pot);
00178         put_real_number(s, "  dt =  ", timestep);
00179         put_real_number(s, "  R_eff  =  ", radius);
00180     }
00181 
00182     return s;
00183 }
00184 
00185 #else
00186 
00187 main(int argc, char** argv)
00188 {
00189     _dyn_  * b;
00190     check_help();
00191 
00192     while (b = get__dyn_(cin)) {
00193         cout << "TESTING put__dyn_:" << endl;
00194         put_node(cout, *b);
00195         cout << "TESTING pp2()   :" << endl;
00196         pp2(b);
00197         delete b;
00198     }
00199     cerr << "Normal exit" << endl;
00200 }
00201 
00202 #endif

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