Esempio n. 1
0
void star_cluster::print(ostream& s = cerr) {

  PRC(relative_mass);PRC(get_total_mass());PRL(nstar);
  PRC(relative_age);PRC(next_update_age);PRC(relative_mass);
  PRC(black_hole_mass);PRC(trlx_initial);
  PRC(rvir);PRC(nstar);PRC(x_imf);PRL(minimum_mass);

}
Esempio n. 2
0
local int add_background_stars_to_ccd(real** ccd, wavelength band,
				      real beta_PSF,
				      real arcsec_per_pixel, real fwhm,
				      bool verbose) {

  real luminosity = 0;
  real xpos, ypos;
  real ccd_size = XCCD_MAX*YCCD_MAX * pow(arcsec_per_pixel/3600., 2);
  PRL(ccd_size);

  real a = -5.86697E+00;
  real b = 9.95179E-01;
  real c = -3.74649E-02;
  real d = 6.47974E-04;
  real e = -4.38781E-06;

  int n_added=0;
  int ns_mag;
  real Mv;
  for(int imag=4; imag<31; imag++) {
    Mv = imag;
    ns_mag = (int)(ccd_size * 2.5
           * pow(10., a + b*Mv + c*pow(Mv, 2) + d*pow(Mv, 3) + e*pow(Mv, 4)));

    PRC(Mv);PRC(ns_mag);
    
    for(int i=0; i<ns_mag; i++) {
      Mv = randinter((real)imag, (real)imag+1);
      if(band!=2) {
	Mv += randinter(-0.2, 1.5);
      }
      luminosity = pow(10, (4.76-Mv)/2.5);
      xpos = randinter(0., XCCD_MAX*arcsec_per_pixel);
      ypos = randinter(0., YCCD_MAX*arcsec_per_pixel);
      if (verbose) {
	cerr << "Background star # " << n_added+1
	     << " pos (x, y): " 
	     << xpos << " " << ypos << " pixels"; 
	cerr << "         magnitudes (M): " << Mv << endl;
      }

      if(add_star_to_ccd(ccd, luminosity, xpos, ypos, beta_PSF, 
			 arcsec_per_pixel, fwhm)) 
	n_added++;
    }
  }
  return n_added;
} 
Esempio n. 3
0
main(int argc, char ** argv)
{
    check_help();

    extern char *poptarg;
    extern char *poparr[];
    int c;
    const char *param_string = "";

    while ((c = pgetopt(argc, argv, param_string,
		    "$Revision: 1.5 $", _SRC_)) != -1)
	switch(c) {
            case '?':	params_to_usage(cerr, argv[0], param_string);
	    		get_help();
	    		exit(1);
        }            

    dyn *b;
    real prev_time = -VERY_LARGE_NUMBER;
    cerr.precision(HIGH_PRECISION);

    while (b = get_dyn()) {

	real time = b->get_system_time();

	if (prev_time > -VERY_LARGE_NUMBER) {
	    real dt = time - prev_time;
	    PRC(time); PRL(dt);
	} else
	    PRL(time);
	prev_time = time;

	rmtree(b);
    }
}
Esempio n. 4
0
void
printhand(const int *hand)
{
	int book, i, j;

	for (book = i = 0; i < RANKS; i++)
		if (hand[i] < CARDS)
			for (j = hand[i]; --j >= 0;) 
				PRC(i);
		else
			++book;
	if (book) {
		(void)printf(" + Book%s of", book > 1 ? "s" : "");
		for (i = 0; i < RANKS; i++)
			if (hand[i] == CARDS)
				PRC(i);
	}
	(void)putchar('\n');
}
Esempio n. 5
0
void main()  {
	double x = 0.0,y;
	char *p;

	y = log10(x);
	p = strerror (errno);
	PRC(errno);
	PR(p);
   printf ("%lf\n",y);
	getch();
}
Esempio n. 6
0
void new_camera_position(vec &v_new,
			 vec v_old,
			 real theta_rotation,
			 real phi_rotation,
			 int nsteps,
			 int nsnap) {

  
  real theta = nsnap*theta_rotation/nsteps;
  real phi   = nsnap*phi_rotation/nsteps;

  PRC(nsnap);PRC(theta);PRL(phi);
  real r = abs(v_old);
  v_new[0] = r * sin(theta);
  v_new[1] = r * sin(theta) * cos(phi);
  v_new[2] = r * cos(theta);

  cerr << "vector = " << v_new << endl;

}
Esempio n. 7
0
int
countbooks(const int *hand)
{
	int i, count;

	for (count = i = 0; i < RANKS; i++)
		if (hand[i] == CARDS) {
			++count;
			PRC(i);
		}
	if (!count)
		(void)printf(" none");
	(void)putchar('\n');
	return(count);
}
Esempio n. 8
0
local bool read_binary_params(ifstream& in, real &m_prim, 
			      real &m_sec, real &sma, real &ecc, real &z) {

    m_prim = 1000;
    m_sec = 1000;
    sma = 0;
    ecc = 0;
    z = 1;
    while (m_prim>100.0 || m_sec>100.0 || ecc<0 || ecc>1 || z < 0.0001 || z > 0.03){   
      if(in.eof())
        return false;
    
      // reading from input file
    //  int id, tpp, tps; 
    //  real time, Rlp, Rls;
    
      in >> sma >> ecc >> m_prim >> m_sec >> z;
      //  in >>id >> time >> sma >> ecc 
      //     >> tpp >> m_prim >> Rlp >> tps >> m_sec >> Rls;
    }
    
    PRC(m_prim);PRC(m_sec);PRC(sma);PRC(ecc);PRL(z);
  return true;
}
Esempio n. 9
0
local void  addstoa(dyn * b, int m_flag)
{
    real time;
    int ndim;
    int n;
    int n_stoa;


    n = 0;
    for_all_daughters(dyn, b, bi) n++;

    PRL(n);
    cin >> n_stoa;
    cin >> ndim;
    cin >>  time;
    PRC(n_stoa); PRC(ndim); PRL(time);
    if (n != n_stoa){
	err_exit("n and n_stoa must be equal");
    }
    for_all_daughters(dyn, b, bi) {
	real mass;
	cin >> mass;
	if(m_flag)bi->set_mass(mass);
    }
Esempio n. 10
0
void compute_max_cod(dyn *b, vec& pos, vec& vel)
{
    // First see if the data are already known.

    if (find_qmatch(b->get_dyn_story(), "density_center_type"))
	if (streq(getsq(b->get_dyn_story(), "density_center_type"), "max")) {
	    if (twiddles(getrq(b->get_dyn_story(), "density_center_time"),
			 b->get_system_time(), TTOL)) {
		pos = getvq(b->get_dyn_story(), "density_center_pos");
		vel = getvq(b->get_dyn_story(), "density_center_vel");
		return;
	    }
	}

    real max_density = 0;

    pos = 0;
    vel = 0;

//  for_all_leaves(dyn, b, d)
    for_all_daughters(dyn, b, d) {

	real dens_time = getrq(d->get_dyn_story(), "density_time");

	if (!twiddles(dens_time, b->get_system_time(), TTOL) && print_msg) {
	    warning("compute_max_cod: using out-of-date densities.");
	    PRC(d->format_label()), PRL(dens_time);
	    if (++msg_count > MAX_MSG_COUNT) print_msg = false;
	}

	real this_density = getrq(d->get_dyn_story(), "density");

	if (this_density > 0) {
	    if (max_density < this_density) {
		max_density = this_density;
		pos = d->get_pos();
		vel = d->get_vel();
	    }
	} else if (this_density <= -VERY_LARGE_NUMBER) {
	    if (print_msg) {
		warning("compute_max_cod: density not set.");
		PRL(d->format_label());
	    }
	    if (++msg_count > MAX_MSG_COUNT) print_msg = false;
	}
    }
Esempio n. 11
0
local void add_bad_column(real **ccd, int n_bc, bool verbose) {

  // reset input seed.
  int input_seed = 11111111;
  int actual_seed = srandinter(input_seed);
  if (verbose) {
    cerr << "Add " << n_bc << " bad columns: ";
    PRC(input_seed);PRL(actual_seed);
  }

  for(int iy = 0; iy<n_bc; iy++) {

    int iyy = int(randinter(0., YCCD_MAX));
    if (verbose)
      cerr << "Bad column at: " << iyy << endl;

    for(int ix = 0; ix<XCCD_MAX; ix++) 
      ccd[ix][iyy] = 0;
  }

}
Esempio n. 12
0
local void mk_ccd(dyn* b, vec dc_pos, int project, wavelength band,
		  real distance, real reddening,
		  real upper_Llimit,
		  real xoffset, real yoffset,
		  real electrons_to_ADU, real beta_PSF,
		  real arcsec_per_pixel, real fwhm,
		  char* filename, bool add_background_stars,
		  bool add_standard_star, int input_seed,
		  bool add_cosmics, int nbad_column,
		  bool verbose) {

  PRL(band);

  real maximum_electrons = electrons_to_ADU*SATURATION_LIMIT-1;

  real half_xccd = 0.5*XCCD_MAX*arcsec_per_pixel;
  real half_yccd = 0.5*YCCD_MAX*arcsec_per_pixel;

  real **ccd = mkarray(XCCD_MAX, YCCD_MAX);
  cerr << "CCD allocated"<<endl;
  for(int ix = 0; ix<XCCD_MAX; ix++) 
    for(int iy = 0; iy<YCCD_MAX; iy++)  
      ccd[ix][iy] = 0;

  PRL(distance);

  real distance_modulus = 5 * log10(distance/10.);
  PRC(distance_modulus);
  PRL(distance);

//  magnitude_limit -= distance_modulus;
//  real magnitude_limit = t_obs/10. - distance_modulus;

//  real luminosity_limit = pow(10, (4.76-magnitude_limit)/5.5); // in V
//  PRC(magnitude_limit);
//  PRL(luminosity_limit);
  
  real pos_to_parsec = b->get_starbase()->conv_r_dyn_to_star(1)
                     * cnsts.parameters(Rsun)/cnsts.parameters(parsec);
  real pos_to_arcsec = b->get_starbase()->conv_r_dyn_to_star(1)
                     * 3600 * cnsts.parameters(Rsun)
                     / (distance*cnsts.parameters(parsec));
  

  PRC(pos_to_parsec);PRL(pos_to_arcsec);

  real xpos, ypos, zpos;
  real M_max = VERY_LARGE_NUMBER;
  real local_Mmm=0, magn;
  real luminosity, L_max = 0;
  real xmax=0, ymax=0;
  vec r;
  if (b->get_oldest_daughter()) {

    vec r_com  = b->get_pos() - dc_pos;

    for_all_leaves(dyn, b, bb) {

//      cerr << " new star: ";
//      cerr << bb->get_index()<<endl;

      r = bb->get_pos()-bb->get_parent()->get_pos();
//      PRL(r);

      switch(project) {
        case -3: xpos =  r[0];
		 ypos =  r[1];
		 zpos = -r[2];
		 break;
	case -2: xpos = -r[0];
		 ypos =  r[2];
		 zpos = -r[1];
		 break;
	case -1: xpos = -r[1];
		 ypos =  r[2];
		 zpos = -r[0];
		 break;
	case 1: xpos = r[1];
		ypos = r[2];
		zpos = r[0];
		break;
	case 2: xpos = r[0];
		ypos = r[2];
		zpos = r[1];
		break;
        case 3: xpos = r[0];
		ypos = r[1];
		zpos = r[2];
		break;
      }
      xpos = xpos * pos_to_arcsec + half_xccd - xoffset;
      ypos = ypos * pos_to_arcsec + half_yccd - yoffset;
      zpos *= pos_to_parsec;
//      PRC(zpos);
      if(distance+zpos>0) {
	real local_distance_modulus = 5 * log10((distance+zpos)/10.);
//      PRL(local_distance_modulus);

	luminosity = get_luminosity(bb, band, local_distance_modulus,
				    maximum_electrons/upper_Llimit);

//	PRL(luminosity);
	if(L_max<luminosity) {
	  L_max = luminosity;
	  M_max = 4.76 - 2.5*log10(luminosity) - local_distance_modulus;
	  local_Mmm = local_distance_modulus;
	  xmax = xpos;    //ascsec
	  ymax = ypos;
	}

	if (luminosity<=0) {
	  luminosity = 0;
	  //	  cerr << "Stellar luminosity = " << luminosity << endl;
	  //	  cerr << "        star Not added to ccd"<<endl;
	}
	else {
	  if (verbose) {
	    real nx = xpos/arcsec_per_pixel;
	    real ny = ypos/arcsec_per_pixel;
	    if (nx>=-10 && nx<=XCCD_MAX && 
		ny>=-10 && ny<=YCCD_MAX+10) {
	      cerr << "Cluster star #" << bb->get_index() 
		   << " pos (x, y): " 
	           << nx << " " << ny << " pixels" << endl; 
	      cerr << "             magnitudes (M, m): "  
		   << 4.76 - 2.5*log10(luminosity)  - local_distance_modulus
 	           << " " << 4.76 - 2.5*log10(luminosity) <<endl;
	    }
	  }
	  add_star_to_ccd(ccd, luminosity, xpos, ypos, beta_PSF, 
			  arcsec_per_pixel, fwhm);
	}
      }
    }
Esempio n. 13
0
local real get_luminosity(dyn* bi, wavelength band,
			  real distance_modulus,
			  real luminosity_norm) {

  real Lu, Lb, Lv, Lr, Li;
  Lu= Lb= Lv= Lr= Li = VERY_LARGE_NUMBER;
  stellar_type stype = NAS;
  get_ubvri_star(bi, stype, Lu, Lb, Lv, Lr, Li);

  //	Lu= Lb= Lv= Lr= Li = VERY_LARGE_NUMBER;
  //	get_Lubvri_star(bi, stype, Lu, Lb, Lv, Lr, Li);
  // PRC(Lu);PRC(Lb);PRC(Lv);PRC(Lr);PRL(Li);
  //cerr << type_string(stype) << endl;

  real magn;
  real Msun;
  real air_mass = 0;
  switch(band) {
    case X: magn = Lu;
	    Msun = 5.61;
	    switch(stype) {
	      //	    case Carbon_Dwarf:
	      //	    case Helium_Dwarf:
	    case Oxygen_Dwarf:
	    case Xray_Pulsar:
	    case Radio_Pulsar:
	    case Neutron_Star:
	    case Black_Hole:
	      magn = Lu - 10;
	      Msun = 5.61;
	      PRC(magn);
		break;
	    default: 
	      magn = VERY_LARGE_NUMBER; // cut out all stars.
	    }

	    break;
    case U: magn = Lu;
	    Msun = 5.61;
	    break;
    case B: magn = Lb + 0.11*(Lb-Lv) - 0.05 + 0 * air_mass;
	    Msun = 5.48;
	    break;
    case F: magn = Lv + 0.05*(Lb-Lv) - 0.02 + 0 * air_mass; 
	    Msun = 4.83;
	    break;
    case R: magn = Lr;
	    break;
    case J: magn = Li;
	    break;
    default:  cerr << "No Default value for magnitude"<<endl;
  }

  real Mbol = 4.76;
  real luminosity = pow(10, 0.4*(Mbol-magn - distance_modulus));
  //cerr << "Magnitude = " << magn << " ";PRL(luminosity);

  real dL = gauss()*sqrt(luminosity*luminosity_norm);
  luminosity += dL/luminosity_norm;
  //  PRC(luminosity);PRL(dL);

  return luminosity;
}
Esempio n. 14
0
void refine_cluster_mass2(dyn *b,		// root node
			  int verbose)		// default = 0
{
    // Self-consistently determine the total mass within the outermost
    // closed zero-velocity surface under the specified external field(s).
    // Use a point-mass approximation for the cluster potential and iterate
    // until the actual mass within the surface agrees with the mass used
    // to generate the surface.
    //
    // This code is most likely to be called from refine_cluster_mass().

    // Quit if internal forces are to be neglected.

    if (b->get_ignore_internal()) return;

    // Do nothing if all we want is to set the dyn story and the current
    // values are up to date.

    if (verbose == 0
	&& twiddles(getrq(b->get_dyn_story(), "bound_center_time"),
		    b->get_system_time(), TTOL))
	return;

    unsigned int ext = b->get_external_field();
    if (!ext || b->get_tidal_field()) return;

    // Method assumes that the external field can be characterized as
    // depending on distance from a single point -- i.e. that it has a
    // single center -- and that it is independent of velocity.  OK to
    // have multiple external fields (e.g. central mass + power law),
    // so long as they have a common center.

    int bits_set = bitcount(ext);
    vec external_center = 0;

    if (bits_set != 1) {

	if (bits_set < 1)
	    
	    return;

	else {

	    // We have multiple external fields.  Check for common center.

	    cerr << "  refine_cluster_mass2: "; PRC(ext); PRL(bits_set);

	    int bit = 0, cbit = -1;
	    for (unsigned int i = ext; i != 0; i >>= 1, bit++) {
		if (i & 01) {
		    if (cbit < 0) {
			cbit = bit;
			external_center = b->get_external_center(cbit);
		    } else {
			if (!twiddles(square(b->get_external_center(bit)
					      - external_center),
				      0)) {
			    cerr << "  refine_cluster_mass2: center " << bit
				 << " inconsistent with center " << cbit
			         << endl;
			    return;
			}
		    }
		}
	    }
	    cerr << "  common center = " << external_center << endl;
	}

    } else