Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

get_profile.C

Go to the documentation of this file.
00001 
00002 // profile: print out a cumulative mass profile for a system,
00003 //          relative to the system center of mass.
00004 //.............................................................................
00005 //    version 1:  June 1997, Steve McMillan
00006 //.............................................................................
00007 
00008 #include "dyn.h"
00009 
00010 typedef struct {real radius;
00011                 real mass;} rm;
00012 
00013 int comp(rm *a, rm* b)
00014 {
00015     if (a->radius < b->radius)
00016         return -1;
00017     else if (a->radius > b->radius)
00018         return 1;
00019     else
00020         return 0;
00021 }
00022 
00023 main(int argc, char ** argv)
00024 {
00025     extern char *poptarg;
00026     int c;
00027     char* param_string = "c";
00028 
00029     while ((c = pgetopt(argc, argv, "param_string")) != -1)
00030         switch(c) {
00031 
00032             case 'c': break;
00033             case '?': params_to_usage(cerr, argv[0], param_string);
00034                       exit(1);
00035         }            
00036 
00037     dyn *b;
00038 
00039     while (b = get_dyn(cin)) {
00040 
00041         real msum = 0;
00042         int i = 0, n = 0;
00043 
00044         b->to_com();
00045 
00046         for_all_daughters(dyn, b, bb) n++;
00047 
00048         rm *sys = new rm[n];
00049 
00050         for_all_daughters(dyn, b, bb) {
00051 
00052             sys[i].radius = bb->get_pos()*bb->get_pos();
00053             sys[i].mass = bb->get_mass();
00054             
00055             i++;
00056         }
00057 
00058         qsort(sys, (size_t) n, (size_t) sizeof(rm), comp);
00059 
00060         for (i = 0; i < n; i++) {
00061             msum += sys[i].mass;
00062             cerr << i << " " << sqrt(sys[i].radius) << " " << msum << endl;
00063         }
00064 
00065         rmtree(b);
00066     }
00067 }
00068 

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