00001
00010
00011 #include "dyn.h"
00012 #include <ctype.h>
00013
00014 #ifdef TOOLBOX
00015
00016 #define LENGTH_SCALE_FACTOR 0.1
00017 #define LEFT_OFFSET -20
00018 #define TOP_OFFSET -5
00019
00020 main(int argc, char ** argv)
00021 {
00022 char *comment;
00023 bool c_flag = false;
00024
00025 real v_rand = 0;
00026
00027 int input_seed, actual_seed;
00028 bool s_flag = false;
00029
00030 check_help();
00031
00032 extern char *poptarg;
00033 int c;
00034 char* param_string = "c:v:s:";
00035
00036 while ((c = pgetopt(argc, argv, param_string)) != -1)
00037 switch(c) {
00038 case 'c': c_flag = true;
00039 comment = poptarg;
00040 break;
00041 case 's': s_flag = true;
00042 input_seed = atoi(poptarg);
00043 break;
00044 case 'v': v_rand = atof(poptarg);
00045 break;
00046 case '?': params_to_usage(cerr, argv[0], param_string);
00047 get_help();
00048 exit(1);
00049 }
00050
00051 if (!s_flag) input_seed = 0;
00052 actual_seed = srandinter(input_seed);
00053
00054 dyn *b, *by, *bo;
00055 b = new dyn();
00056 bo = new dyn();
00057 b->set_oldest_daughter(bo);
00058 bo->set_parent(b);
00059
00060 int j = TOP_OFFSET;
00061 int i = LEFT_OFFSET;
00062 int indx = 0;
00063 int n = 0;
00064
00065
00066
00067
00068 c = getchar();
00069 while(c != EOF) {
00070 while (c != '\n' && c != EOF) {
00071 if (!isspace(c)) {
00072
00073 n++;
00074 bo->set_pos(vector(j*LENGTH_SCALE_FACTOR,
00075 i*LENGTH_SCALE_FACTOR, 0));
00076 bo->set_vel(v_rand*vector(randinter(-1,1),
00077 randinter(-1,1),
00078 randinter(-1,1)));
00079
00080 bo->set_label(++indx);
00081
00082 by = new dyn();
00083 bo->set_younger_sister(by);
00084 by->set_elder_sister(bo);
00085 bo = by;
00086 }
00087 i++;
00088 c = getchar();
00089 }
00090 j++;
00091 i = LEFT_OFFSET;
00092 if (c != EOF)
00093 c = getchar();
00094 }
00095
00096 bo = bo->get_elder_sister();
00097 delete by;
00098 bo->set_younger_sister(NULL);
00099
00100 for_all_daughters(dyn, b, bb)
00101 bb->set_mass(1.0/n);
00102
00103 if (c_flag == TRUE)
00104 b->log_comment(comment);
00105 b->log_history(argc, argv);
00106
00107 b->to_com();
00108 put_node(cout, *b);
00109 }
00110
00111 #endif
00112
00113