Ejemplo n.º 1
0
int main()
{

double i;
double rho_crit_0 = 2.7754e11;
double mass=3e14;
FILE *fp1;
fp1 = fopen("NFW", "w");
	if ( fp1 == NULL )	{	
		printf("Cann't open  file\n");
		return 1;
}
for(i=0;i<r200(mass);i++)
{
//printf("%le\n",r200(3e15));
printf("%le \t%le\n",log10(i/r200(mass)),log10(NFW(i,mass)/rho_crit_0));
fprintf(fp1,"%le \t%le\n",(i/r200(mass)),(NFW(i,mass)/rho_crit_0));
} 
fclose(fp1);
return 0;
}
Ejemplo n.º 2
0
int main()
{
    poc();
    try {
        TestSection("SVector");
        TestSubsection("Matrix");
        {
            SMatrix<5> matrix;
            matrix[1][2][1][0][1] = 123;
            matrix[2][1][0][1][4] = 777;

            TEST("matrix_1", matrix[1][2][1][0][1].GetInt(), 123);
            TEST("matrix_2", matrix[2][1][0][1][4].GetInt(), 777);
        }
        TestSubsection("Matrix_has_you");
        {
            SVector m;
            SVector m0;
            SVector m1;
            SVector m00;
            SVector m01;
            SVector m10;
            SVector m11;

            m10[1] = SReference(25);

            m0[0] = m00;
            m0[1] = m01;
            m1[0] = m10;
            m1[1] = m11;

            m[0]  = m0;
            m[1]  = m1;

            SMatrixRef<3> matr(m);

            TEST("matrix_has_you", matr[1][0][1].GetInt(), 25);
        }
        TestSubsection("resize");
        {
            SVector v;
            v[7] = 5;
            TEST("resize_1", v->Size(), 8);
            v[12] = 5;
            TEST("resize_2", v->Size(), 13);
            v[13] = 5;
            TEST("resize_3", v->Size(), 14);
        }
#if INTELIB_DEBUG_COUNTERS == 1
        TestSubsection("leaks");
        {
            int before = SExpression::object_counter;
            {
                SVector v;
                v[7] = 5;
                SVectorRef vr(v);
                SVectorRef vr2;
                vr2 = vr;
                SVectorRef vr3(vr2);
                for(int i=0; i<200; i++) vr3[vr3->Size()] = SReference(i);
            }
            TEST("no_leaks", SExpression::object_counter, before);
        }
#endif
        TestSubsection("TextRepresentation");
        {
            SVector v;
            for(int i=0; i<5; i++) v[i]=i;
            TEST("text_rep", v->TextRepresentation().c_str(),
                 "#~(0 1 2 3 4)");

        }
        TestSubsection("Range Copying");
        {
            SVector v;
            for(int i=0; i<15; i++) v[i]=i;

            SVectorRange r(v,5,3);
            TEST("range_copy", r.Copy()->TextRepresentation().c_str(),
                 "#~(5 6 7)");
            TESTB("copy_keeps_positive_resizeability",
                 r.Copy()->IsResizeable());

            SVector vn(5);
            for(int i=0; i<5; i++) vn[i]=i*100;
            SVectorRange rn(vn,1,2);
            TESTB("copy_keeps_negative_resizeability",
                 !rn.Copy()->IsResizeable());
            TESTB("copy_positive_resizeability",
                 rn.Copy(true)->IsResizeable());
            TESTB("copy_negative_resizeability",
                 !rn.Copy(false)->IsResizeable());

            SVectorRange r200(v,5,200);
            TEST("range_size_limited", r200.Copy()->Size(), 10);

        }
        TestSubsection("Range Erasing");
        {
            SVector v;
            for(int i=0; i<15; i++) v[i]=i;
            SVectorRange r(v,3,10);
            r.Erase();
            TEST("range_erase", v->TextRepresentation().c_str(),
                 "#~(0 1 2 13 14)");
            TEST("range_erase_size", v->Size(), 5);
            TEST("range_erase_range_len", r.Copy()->Size(), 0);

        }
        TestSubsection("Range Replacing");
        {
            SVector v, w;
            for(int i=0; i<15; i++) v[i]=i;
            for(int i=0; i<5; i++) w[i]=i*100;

            SVectorRange r(v,3,10);
            r.Replace(w);
            TEST("range_replace_less", v->TextRepresentation().c_str(),
                 "#~(0 1 2 0 100 200 300 400 13 14)");
            TEST("range_replace_less_size", v->Size(), 10);
            TEST("range_replace_less_range_len", r.Copy()->Size(), 5);
        }
        {
            SVector v, w;
            for(int i=0; i<10; i++) v[i]=i;
            for(int i=0; i<5; i++) w[i]=i*100;

            SVectorRange r(w,1,2);
            r.Replace(v);
            TEST("range_replace_more", w->TextRepresentation().c_str(),
                 "#~(0 0 1 2 3 4 5 6 7 8 9 300 400)");
            TEST("range_replace_more_size", w->Size(), 13);
            TEST("range_replace_more_range_len", r.Copy()->Size(), 10);
        }
        TestScore();
    }
    catch(const IntelibX &ex) {
        printf("Caught IntelibX: %s\n%s\n",
            ex.Description(),
            ex.Parameter().GetPtr() ?
                ex.Parameter()->TextRepresentation().c_str() : "");
    }
    catch(...) {
        printf("Something strange caught\n");
    }
    poc();
    return 0;
}
Ejemplo n.º 3
0
Archivo: nfw.c Proyecto: lgo33/GadTools
int main (int argc, char *argv[])
{
  FILE *fp;
  char infile[256];
  int i,j,k, usepart;
  struct gadpart *part;
  gadpart_dist *wpart;
  struct header head;
  fltarr cm={0,0,0};
  double rv=0, sfl=0;
  int calccenter=1;
  
  i=1;
  usepart=USE;
  if (1==argc) usage();
  while (i<argc)
    {
      if (!strcmp(argv[i],"-i"))
	{
	  i++;
	  strcpy(infile,argv[i]);
	  i++;
	}
      else if (!strcmp(argv[i],"-cm")) {
	cm[0]=atof(argv[++i]);
	cm[1]=atof(argv[++i]);
	cm[2]=atof(argv[++i]);
	i++;
      }
      else if (!strcmp(argv[i],"-nocenter")) {
	calccenter=0;
	i++;
      }
      else if (!strcmp(argv[i],"-rv")) {
	rv=atof(argv[++i]);
	i++;
      }
      else if (!strcmp(argv[i],"-soft")) {
	sfl=atof(argv[++i]);
	i++;
      }
      else if (!strcmp(argv[i],"-use")) {
	i++;
	if (!strcmp(argv[i],"all")) usepart=63;
	else usepart=atoi(argv[i]);
	i++;
      } 
      else if (*argv[i]!='-')
	{
	  strcpy(infile,argv[i]);
	  i++;
	} else {
	usage();
      }
    }

  unsigned int numpart_all;
  if (!(numpart_all=readgadget_part(infile, &head, &part))) 
    {
      extern int libgaderr;
      printf("error reading file %s\nError Code %d\n",infile, libgaderr);
      exit(1);
    }

  unsigned int numpart=0;
  for (i=0; i<6; i++)
    {
      if (usepart&(1<<i)) {numpart+=head.npart[i];}
    }
  wpart=(struct gadpart_dist*) malloc (numpart*sizeof(struct gadpart_dist));
  j=0;
  for (i=0; i<numpart_all;i++)
    {
	if ((1<<(part[i].type))&usepart)
	{
	  cpygadpart(&(wpart[j].part),&(part[i]));
	  wpart[j].dist=distance(wpart[j].part.pos, cm);
	  //	  printf("%f  | ", wpart[j].dist);
	  j++;
	}
    }
  qsort(wpart, j, sizeof(gadpart_dist), cmp_dist);
  //  pcenter(wpart, j, rv, cm);

  /*********************************************************************

      Program code goes here

  *********************************************************************/

  double par[2]={0.005,20};
  double c;
  double mvir=0;
  double rcs;
  int vcnt;
  if (calccenter)
    {
      const double maxdist =2000.0;
      pcenter(wpart, numpart, maxdist, cm, 2);
    }
  if (rv==0) rv= r200(wpart, j, 200, head, &vcnt, &mvir);
  c = nfwfit(par, wpart, j, rv ,sfl, &rcs);
  printf("center %f %f %f\n", cm[0], cm[1], cm[2]);
  printf("Rvir %g | Vcnt %d | Mvir %g\n", rv, vcnt, mvir);
  printf("rs %g dc %g\n", par[1], par[0]);
  printf("reduced chi^2 %f\n", rcs);
  printf("c %f\n", c);
  return 0;
}