Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

readstoa.C

Go to the documentation of this file.
00001 
00010 
00011 //            Jun Makino, Aug 1996
00012 
00013 #include "dyn.h"
00014 
00015 #ifdef TOOLBOX
00016 
00017 local dyn* read_stoa(bool i_flag) {
00018 
00019     dyn *root, *by, *bo;
00020 
00021     // Create root node.
00022 
00023     root = new dyn();
00024     if (i_flag) root->set_label(0);
00025 
00026     int n; scanf("%d", &n); PRL(n);
00027     int ndim; scanf("%d", &ndim); PRL(ndim);
00028     real time; scanf("%lf", &time); PRL(time);
00029     root->set_system_time(time);
00030     
00031     // Create first daughter node.
00032 
00033     bo = new dyn();
00034     root->set_oldest_daughter(bo);
00035     bo->set_parent(root);
00036     if (i_flag) bo->set_label(1);
00037 
00038     // Create other daughter nodes.
00039 
00040     for (int i = 1; i < n; i++) {
00041         by = new dyn();
00042         if (i_flag) by->set_label(i+1);
00043         by->set_parent(root);
00044         bo->set_younger_sister(by);
00045         by->set_elder_sister(bo);
00046         by->set_mass(bo->get_mass());
00047         bo = by;
00048     }
00049 
00050     real total_mass = 0;
00051 
00052     for_all_daughters(dyn, root, b) {
00053         real mass; cin >> mass; 
00054         b->set_mass(mass);
00055         total_mass += mass;
00056     }
00057 
00058     root->set_mass(total_mass);
00059 
00060     for_all_daughters(dyn, root, b) {
00061         vector pos; cin >> pos; 
00062         b->set_pos(pos);
00063     }
00064 
00065     for_all_daughters(dyn, root, b){
00066         vector vel; cin >> vel; 
00067         b->set_vel(vel);
00068     }
00069 
00070     return root;
00071   }
00072 
00073 local void write_stoa() {
00074 
00075   real ndim = 3; // x, y and z
00076 
00077   dyn *b;
00078   b = get_dyn(cin);
00079   
00080   b->flatten_node();
00081   
00082   // for safetly check number of leaves.
00083   int n=0;
00084   for_all_daughters(dyn, b, bi) {
00085     n++;
00086   }
00087   
00088   //start writing NEMO stoa
00089   cout << n << endl;
00090   cout << ndim << endl;
00091   cout << b->get_system_time() << endl;
00092   for_all_daughters(dyn, b, bi) {
00093     cout << bi->get_mass() << endl;
00094   }
00095   
00096   for_all_daughters(dyn, b, bi) {
00097     cout << bi->get_pos() << endl;
00098   }
00099   
00100   for_all_daughters(dyn, b, bi){
00101     cout << bi->get_vel() << endl;
00102   }
00103   
00104 }
00105 
00106 void main(int argc, char ** argv)
00107 {
00108     check_help();
00109 
00110     extern char *poptarg;
00111     int c;
00112     char* param_string = "iw";
00113 
00114     bool i_flag = false;
00115     bool w_flag = false;
00116 
00117     while ((c = pgetopt(argc, argv, param_string)) != -1)
00118         switch(c) {
00119 
00120             case 'i': i_flag = true;
00121                       break;
00122             case 'w': w_flag = true;
00123                       break;
00124             case '?': params_to_usage(cerr, argv[0], param_string);
00125                       exit(1);
00126         }
00127 
00128     dyn *root;
00129 
00130     if(w_flag) {
00131       write_stoa();
00132     }
00133     else {
00134       root = read_stoa(i_flag);
00135       root->log_history(argc, argv);
00136       put_node(cout, *root);
00137     }
00138 
00139 }
00140 
00141 #endif
00142 
00143 /* end of: readstoa.c */

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