00001
00014
00015
00016 #include "dyn.h"
00017
00018 #ifndef TOOLBOX
00019 #else
00020
00021 local void mk_mrv(dyn* b, int i_flag, int id,
00022 int m_flag, real mass,
00023 int r_flag, vector pos,
00024 int v_flag, vector vel) {
00025
00026 b->set_index(id);
00027 b->set_mass(mass);
00028 b->set_pos(pos);
00029 b->set_vel(vel);
00030
00031 }
00032
00033 local dyn * initialize_dyn(istream &in, int n, int i_flag,
00034 int m_flag, int r_flag,
00035 int v_flag) {
00036
00037
00038 if(n<=0)
00039 in >> n;
00040
00041 vector r, v;
00042 real m, time;
00043 real m_tot = 0;
00044 int id=0;
00045 dyn *root = mkdyn(n);
00046 for_all_daughters(dyn, root, b) {
00047 if(i_flag < 0 && m_flag < r_flag && r_flag < v_flag) {
00048 id++;
00049 in >> m >> r >> v;
00050 }
00051 else if (i_flag < m_flag && m_flag < r_flag && r_flag < v_flag)
00052 in >> id >> m >> r >> v;
00053 else {
00054 cerr << "order not not yet implemented."<<endl;
00055 PRC(i_flag);PRC(m_flag);PRC(r_flag);PRL(v_flag);
00056 }
00057
00058 mk_mrv(b, i_flag, id,
00059 m_flag, m,
00060 r_flag, r,
00061 v_flag, v);
00062 m_tot += m;
00063 }
00064
00065 root->set_mass(m_tot);
00066 return root;
00067 }
00068
00069 void main(int argc, char ** argv)
00070 {
00071 bool F_flag = false;
00072 int i_flag = -1;
00073 int m_flag = -1;
00074 int r_flag = -1;
00075 int v_flag = -1;
00076 int order = 0;
00077 bool vctr[] = {false, false, false, false};
00078 char *filename;
00079
00080 int n = -1;
00081 check_help();
00082
00083 extern char *poptarg;
00084 int c;
00085 char* param_string = "F:imrvn:";
00086
00087 while ((c = pgetopt(argc, argv, param_string)) != -1)
00088 switch(c) {
00089
00090 case 'F': F_flag = true;
00091 filename = poptarg;
00092 break;
00093 case 'n': n = atoi(poptarg);
00094 break;
00095 case 'i': i_flag = order++;
00096 break;
00097 case 'm': m_flag = order++;
00098 break;
00099 case 'r': r_flag = order++;
00100 vctr[r_flag] = true;
00101 break;
00102 case 'v': v_flag = order++;
00103 vctr[v_flag] = true;
00104 break;
00105 case '?': params_to_usage(cerr, argv[0], param_string);
00106 get_help();
00107 exit(1);
00108 }
00109
00110 cerr << "Selected order: " << endl;
00111 PRC(order);PRC(i_flag);PRC(m_flag);PRC(r_flag);PRL(v_flag);
00112
00113 dyn * root = NULL;
00114 if (F_flag) {
00115 ifstream infile(filename);
00116 if (!infile) cerr << "error: couldn't create file "
00117 << filename <<endl;
00118 cerr << "Reading input from file "<< filename <<endl;
00119
00120 root = initialize_dyn(infile, n, i_flag, m_flag, r_flag, v_flag);
00121 }
00122 else {
00123 root = initialize_dyn(cin, n, i_flag, m_flag, r_flag, v_flag);
00124 }
00125
00126 root->log_history(argc, argv);
00127 put_dyn(cout, *root);
00128 rmtree(root);
00129 }
00130
00131 #endif
00132
00133
00134