/* Here we load a snapshot file. It can be distributed
 * onto several files (for files>1).
 * The particles are brought back into the order
 * implied by their ID's.
 * A unit conversion routine is called to do unit
 * conversion, and to evaluate the gas temperature.
 */
int main(int argc, char **argv)
{
  char path[200], input_fname[200], output_fname[200], basename[200], basenameout[200];
  int  j, n, type, snapshot_number, output_number,files, Ngas, random, ncount, ncounthalo1, ncount2;
  float x,y,z,x1,y1, z1, delr;
  double delx, dely, delz, boxsize;
  FILE *outfile;

  sprintf(path, "/work/00863/minerva/");
  sprintf(basename, "bin_HR10_map");

output_number = 0;
for(j=0; j<=0; j=j+1)
  {

  snapshot_number=j;
  
  files=1;     

  boxsize = 140.0;

  delx = 512.65800353;  //del's used in making bin_zoom10_cut_??? (bin_zoom10_???)
  dely = 505.21836888;
  delz = 497.39349349;

  sprintf(input_fname, "%s/%s_%03d", path, basename, snapshot_number);
  if(snapshot_number > 999)
    sprintf(input_fname, "%s/%s_%04d", path, basename, snapshot_number);
  if(snapshot_number > 9999)
    sprintf(input_fname, "%s/%s_%05d", path, basename, snapshot_number);
  
  sprintf(basenameout, "ot");
  sprintf(output_fname, "%s/%s_%04d", path, basenameout, output_number);
  if(snapshot_number > 999)
    sprintf(output_fname, "%s/%s_%04d", path, basenameout, output_number);
  if(snapshot_number > 9999)
    sprintf(output_fname, "%s/%s_%05d", path, basenameout, output_number);
  output_number++;

  Ngas = write_snapshot(input_fname, files, output_fname, delx, dely, delz, boxsize);

  unit_conversion();  

  do_what_you_want();
  free(P);
}
}
Example #2
0
/* Here we load a snapshot file. It can be distributed
 * onto several files (for files>1).
 * The particles are brought back into the order
 * implied by their ID's.
 * A unit conversion routine is called to do unit
 * conversion, and to evaluate the gas temperature.
 */
int main(int argc, char **argv)
{
  char path[200], input_fname[200], basename[200];
  int type, snapshot_number, files;


  sprintf(path, "/home/tczhang/desktop/C");
  sprintf(basename, "snapshot");
  snapshot_number = 6;		/* number of snapshot */
  files = 1;			/* number of files per snapshot */


  sprintf(input_fname, "%s/%s_%03d", path, basename, snapshot_number);
  load_snapshot(input_fname, files);


  reordering();			/* call this routine only if your ID's are set properly */

  unit_conversion();		/* optional stuff */

  do_what_you_want();
}
Example #3
0
/* Here we load a snapshot file. It can be distributed
 * onto several files (for files>1).
 * The particles are brought back into the order
 * implied by their ID's.
 * A unit conversion routine is called to do unit
 * conversion, and to evaluate the gas temperature.
 */
int main(int argc, char **argv)
{
  char path[200], input_fname[200], input_fname_dm[200], output_fname[200], basename[200], basenameout[200];
  int  j, n, type, snapshot_number, files, Ngas, random, ncount, ncounthalo1, ncount2;
  float x,y,z,x1,y1, z1, delr;
  double delx, dely, delz, delx_dm, dely_dm, delz_dm, boxsize;
  FILE *outfile;


  sprintf(path, "/work/00863/minerva");
  sprintf(basename, "ds_ic");
  snapshot_number=000;                   /* number of snapshot */
  files=1;     

  boxsize = 100.0;
  delx = 50.339110402;
  dely = 50.122129376;
  delz = 49.486652655;

  delx_dm = 3.4331373996e-06;
  dely_dm = 3.4336503546e-06;
  delz_dm = 3.432893655e-06;
 
  sprintf(input_fname, "%s/%s_%03d", path, basename, snapshot_number);
  sprintf(input_fname_dm, "/work/00863/minerva/minihalo_128");
  sprintf(output_fname, "/work/00863/minerva/ds_ng_000");
  Ngas = write_snapshot(input_fname, input_fname_dm, files, output_fname, delx, dely, delz, delx_dm, dely_dm, delz_dm, boxsize);

  unit_conversion();  

  ncount = 0;
  ncount2 = 0;

  printf("ncount = %d.\n", ncount);
  printf("ncount2 = %d.\n", ncount2);

  do_what_you_want();
}
Example #4
0
/* Here we load a snapshot file. It can be distributed
 * onto several files (for files>1).
 * The particles are brought back into the order
 * implied by their ID's.
 * A unit conversion routine is called to do unit
 * conversion, and to evaluate the gas temperature.
 */
int main(int argc, char **argv)
{
  char path[200], input_fname[200], input_fname_dm[200], output_fname[200], basename[200], basenameout[200];
  int  j, n, type, snapshot_number, files, Ngas, random, ncount, ncounthalo1, ncount2;
  float x,y,z,x1,y1, z1, delr;
  double delx, dely, delz, delx_dm, dely_dm, delz_dm, boxsize, dummy=1.0;
  FILE *outfile;


  sprintf(path, "/nobackupp1/astacy");
  sprintf(basename, "dma");
  snapshot_number=12;                   /* number of snapshot */
  files=1;     

  boxsize = 140.0;
  delx = dely = delz = dummy;

  delx_dm = dely_dm = delz_dm = dummy;
 
  sprintf(input_fname, "%s/%s_%03d", path, basename, snapshot_number);

  sprintf(input_fname_dm, "/nobackupp1/astacy/minihalo_256");  //"nfw" denotes an r^-1 profile!
  sprintf(output_fname, "/nobackupp1/astacy/dma_prof1_000");

  Ngas = write_snapshot(input_fname, input_fname_dm, files, output_fname, delx, dely, delz, delx_dm, dely_dm, delz_dm, boxsize);

  unit_conversion();  

  ncount = 0;
  ncount2 = 0;

  printf("ncount = %d.\n", ncount);
  printf("ncount2 = %d.\n", ncount2);

  do_what_you_want();
}
/* Here we load a snapshot file. It can be distributed
 * onto several files (for files>1).
 * The particles are brought back into the order
 * implied by their ID's.
 * A unit conversion routine is called to do unit
 * conversion, and to evaluate the gas temperature.
 */
int main(int argc, char **argv)
{
  char path[200], input_fname[200], output_fname[200], basename[200], basenameout[200];
  int  j, n, type, snapshot_number, files, Ngas, random, ncount, ncounthalo1, ncount2;
  double x,y,z,x1,y1, z1, delr;
  double nh, nhmax, nhmax2, mass, mmax, mmax2, dis, xmax, xmax2, ymax, ymax2, zmax, zmax2, sl, masstot, temp, tmax, h2, h2max, gam, gammin;
  double sinkposx, sinkposy, sinkposz, disAU, vrad, vrotx, vroty, vrotz, vrot;
  double velx, vely, velz;
  double dum_num;
  FILE *outfile;


  sprintf(path, "/work/utexas/ao/minerva");
  sprintf(basename, "hires_am2");
  sprintf(basenameout, "snaphires_am2_chem");

  for(j=2;j<=2;j++){

  snapshot_number= j;                   /* number of snapshot */
  files=1;                               /* number of files per snapshot */

  sprintf(input_fname, "%s/%s_%03d", path, basename, snapshot_number);
  sprintf(output_fname, "%s/%s_%03d", path, basenameout, snapshot_number);
  Ngas = load_snapshot(input_fname, files);

  /*    reordering();*/ /* call this routine only if your ID's are set properly */

  unit_conversion();  

  outfile=fopen(output_fname, "w");

  ncount = 0;
  ncount2 = 0;

  nhmax = nhmax2 = 0;
  mmax= mmax2 = 0;
  xmax= xmax2 = 0;
  ymax= ymax2 = 0;
  zmax= zmax2 = 0;
  sl = 0;
  tmax=0;
  h2max=0;


  for(n = 1; n <= Ngas; n++)
       {
       if(P[n].Id == 3755078)
          {
          sinkposx = P[n].Pos[0];
          sinkposy = P[n].Pos[1];
          sinkposz = P[n].Pos[2];
          }
       }


  for(n=1;n<=Ngas;n++) { 
    x=P[n].Pos[0];
    y=P[n].Pos[1];
    z=P[n].Pos[2];

    x1=x/(0.7e0*(1.e0 + 18.9e0));
    y1=y/(0.7e0*(1.e0 + 18.9e0));
    z1=z/(0.7e0*(1.e0 + 18.9e0));

          nh = P[n].nh;
          mass=P[n].Mass;
          masstot=masstot+mass;
          h2 = P[n].H2I;

          if(nh > nhmax2 && mass < 3.e-12)
            {
              nhmax2 = nh;
              mmax2=mass;
              xmax2=P[n].Pos[0];
              ymax2=P[n].Pos[1];
              zmax2=P[n].Pos[2];

            }


          if(nh > nhmax)
            {
              nhmax = nh;
              mmax=mass;
              xmax=P[n].Pos[0];
              ymax=P[n].Pos[1];
              zmax=P[n].Pos[2];
              h2max=P[n].H2I;
            }
    }


    random = rand();
    dum_num = 5.0;

         sinkposx=xmax;
         sinkposy=ymax;
         sinkposz=zmax; 
         printf("sinkposx = %g, sinkposy = %g, sinkposz = %g\n", sinkposx, sinkposy, sinkposz);

         printf("nhmax2 = %lg, maxmass2 = %lg, xmax2 = %lg, ymax2 = %lg, zmax2 = %lg\n", nhmax2, mmax2, xmax2, ymax2, zmax2);

         for(n = 1; n <= Ngas; n++)
             {


             dis = pow(((P[n].Pos[0]-sinkposx)*(P[n].Pos[0]-sinkposx) + (P[n].Pos[1]-sinkposy)*(P[n].Pos[1]-sinkposy) + (P[n].Pos[2]-sinkposz)*(P[n].Pos[2]-sinkposz)), 0.5);
             dis=dis*1.e3*Time/(0.7);
             disAU=dis*206264.806;


      if (/*(random*(1.e0/RAND_MAX))< 0.1e0*/ /* P[n].nh > 1.e4 || P[n].sink > 0.5*/ P[n].Id % 100 == 0) {
      //fprintf(outfile,"%15.13g %8d %15.13g %15.13g %15.13g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g\n", P[n].sink, Id[n],x,y,z,P[n].Temp,P[n].nh,P[n].HII,P[n].H2I,P[n].HDI, P[n].gam, P[n].Vel[0],P[n].Vel[1],P[n].Vel[2],P[n].hsm, P[n].Mass);
      fprintf(outfile,"%15.13g %8d %15.13g %15.13g %15.13g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g\n", dum_num, P[n].Id,P[n].Pos[0],P[n].Pos[1],P[n].Pos[2],dum_num,P[n].nh,P[n].HII,P[n].H2I,P[n].HDI, dum_num, disAU, vrad, vrot,dum_num, P[n].Mass);
      ncount = ncount + 1;
       }

    delr = sqrt((226.791-x)*(226.791-x) + (230.096-y)*(230.096-y) + (230.16-z)*(230.16-z))/(0.7e0*19.98);
  }
  printf("ncount = %d.\n", ncount);
  printf("ncount2 = %d.\n", ncount2);

   printf("nhmax= %g\n", nhmax);
   printf("mmax= %g\n", mmax);
   printf("xmax= %g\n", xmax);
   printf("ymax= %g\n", ymax);
   printf("zmax= %g\n", zmax);
   printf("sl = %g\n", sl);
   printf("tmax = %g\n", tmax);
   printf("h2max = %g\n", h2max);


  fclose(outfile);
}

  do_what_you_want();
}
/* Here we load a snapshot file. It can be distributed
 * onto several files (for files>1).
 * The particles are brought back into the order
 * implied by their ID's.
 * A unit conversion routine is called to do unit
 * conversion, and to evaluate the gas temperature.
 */
int main(int argc, char **argv)
{
  char path[200], input_fname[200], output_fname[200], basename[200], basenameout[200];
  int  i, j, jnum, n, type, snapshot_number, files, random, ncount, ncounthalo1, ncount2, idmax;
  double x,y,z,x1,y1, z1, delr, vx, vy, vz, vel, typemax, dismax;
  double nh, nhmax, mass, mmax, dis, xmax, ymax, zmax, sl, masstot, temp, tmax, h2, h2max, gam, gammin;
  double sinkposx, sinkposy, sinkposz, disAU, vrad, vrotx, vroty, vrotz, vrot, mh_mass;
  double xCOM, yCOM, zCOM, vxCOM, vyCOM, vzCOM, disCOM, vCOM, ncount_doub;
  double hubble_param;
  FILE *outfile;

  sprintf(path, "/work/00863/minerva/strom");

  sprintf(basename, "strom");
  sprintf(basenameout, "snapstrom");

  jnum = 800;

  for(j=jnum;j<=jnum;j=j+5){

  snapshot_number= j;                   /* number of snapshot */
  files=1;                               /* number of files per snapshot */

  if(j<=999)
  {
  sprintf(input_fname, "%s/%s_%04d", path, basename, snapshot_number);
  sprintf(output_fname, "%s/%s_%04d", path, basenameout, snapshot_number);
  }

  if(j>999)
  {
    sprintf(input_fname, "%s/%s_%04d", path, basename, snapshot_number);
    sprintf(output_fname, "%s/%s_%04d", path, basenameout, snapshot_number);
  }

  Ngas = load_snapshot(input_fname, files);

  //for NON-comoving integrations
  Time = hubble_param = 1.0;

  /*    reordering();*/ /* call this routine only if your ID's are set properly */

  printf("hi 1, Ngas = %d, NumPart = %d\n", Ngas, NumPart);

  unit_conversion();  

  printf("hi 2\n");

  outfile=fopen(output_fname, "w");

  ncount = 0;
  ncount2 = 0;

  printf("hi 3\n");

  nhmax = 0;
  mmax = mh_mass = 0;
  xmax = ymax = zmax = 0;
  sl = tmax = h2max = gammin=0;
  masstot = dismax = 0;
  typemax = 5;
  xCOM = yCOM = zCOM = vxCOM = vyCOM = vzCOM = ncount_doub = 0.0;

  printf("hi 4\n");

  for(n=0;n<Ngas;n++) { 

          nh = P[n].nh;
          mass=P[n].Mass;
          temp = P[n].Temp;
          h2 = P[n].H2I;
          gam=P[n].gam;

          if(nh > nhmax)
          //if(mass > mmax)
            {
              //printf("Found the sink!\n");
              nhmax = nh;
              mmax=mass;
              xmax=P[n].Pos[0];
              ymax=P[n].Pos[1];
              zmax=P[n].Pos[2];
              sl = P[n].hsm;
              tmax=P[n].Temp;
              h2max=P[n].H2I;
              gammin=P[n].gam;
              typemax = P[n].Type;
              idmax = P[n].Id;
              vx = P[n].Vel[0];
              vy = P[n].Vel[1];
              vz = P[n].Vel[2];
            }
    }

         for(n=0;n<=Ngas;n++)
           {
            nh = P[n].nh;
            if(nh > nhmax/1e8)
            {
            vxCOM = vxCOM + P[n].Vel[0]*P[n].Mass;
            vyCOM = vyCOM + P[n].Vel[1]*P[n].Mass;
            vzCOM = vzCOM + P[n].Vel[2]*P[n].Mass;
            xCOM = xCOM + P[n].Pos[0]*P[n].Mass;
            yCOM = yCOM + P[n].Pos[1]*P[n].Mass;
            zCOM = zCOM + P[n].Pos[2]*P[n].Mass;
            ncount_doub = ncount_doub + P[n].Mass;
            }
            //if(nh > 1.e6)
            //if(nh > 1e3 && nh < 1e5)
              //printf("ID = %d, nh = %lg\n", P[n].Id, P[n].nh);
              //printf("%d\n", P[n].Id);
         }


         vx = vxCOM/ncount_doub;
         vy = vyCOM/ncount_doub;
         vz = vzCOM/ncount_doub;


         sinkposx=xmax;
         sinkposy=ymax;
         sinkposz=zmax;
         printf("sinkposx = %15.11g, sinkposy = %15.11g, sinkposz = %15.11g, nhmax = %15.11g, mmax = %15.11g\n", sinkposx, sinkposy, sinkposz, nhmax, mmax);

         vx = vy = vz = 0;
         sinkposx = sinkposy = sinkposz = header1.BoxSize/2.0; 

         if(nhmax < 1.e1)
           {
           sinkposx=header1.BoxSize/2.0;
           sinkposy=header1.BoxSize/2.0;
           sinkposz=header1.BoxSize/2.0; 
           }
         printf("sinkposx = %15.11g, sinkposy = %15.11g, sinkposz = %15.11g\n", sinkposx, sinkposy, sinkposz);
         printf("vx = %lg, vy = %lg, vz = %lg\n", vx, vy, vz);

         for(n = 0; n < NumPart; n++)
         //for(n = 0; n < Ngas; n++)
             {

             P[n].Vel[0] = P[n].Vel[0] - vx;
             P[n].Vel[1] = P[n].Vel[1] - vy;
             P[n].Vel[2] = P[n].Vel[2] - vz;

             x = P[n].Pos[0];
             y = P[n].Pos[1];
             z = P[n].Pos[2];

             dis = pow(((P[n].Pos[0]-sinkposx)*(P[n].Pos[0]-sinkposx) + (P[n].Pos[1]-sinkposy)*(P[n].Pos[1]-sinkposy) + (P[n].Pos[2]-sinkposz)*(P[n].Pos[2]-sinkposz)), 0.5);
             //dis = pow(((P[n].Pos[0]-xmax)*(P[n].Pos[0]-xmax) + (P[n].Pos[1]-ymax)*(P[n].Pos[1]-ymax) + (P[n].Pos[2]-zmax)*(P[n].Pos[2]-zmax)), 0.5);
             if(dis > dismax)
                dismax = dis;
             dis=dis*1.e3*Time/hubble_param;
             disAU=dis*206264.806;

             vel = P[n].Vel[0]*P[n].Vel[0] + P[n].Vel[1]*P[n].Vel[1] + P[n].Vel[2]*P[n].Vel[2];
             vel = pow(vel,0.5)*pow(Time, 0.5); 

             vrad =  (P[n].Vel[0]*(P[n].Pos[0]-sinkposx) + P[n].Vel[1]*(P[n].Pos[1]-sinkposy) + P[n].Vel[2]*(P[n].Pos[2]-sinkposz))/pow(((P[n].Pos[0]-sinkposx)*(P[n].Pos[0]-sinkposx) + (P[n].Pos[1]-sinkposy)*(P[n].Pos[1]-sinkposy) + (P[n].Pos[2]-sinkposz)*(P[n].Pos[2]-sinkposz)), 0.5);
             vrad = vrad*pow(Time, 0.5); 

             vrotx = (P[n].Pos[1]-sinkposy)*P[n].Vel[2]  - (P[n].Pos[2]-sinkposz)*P[n].Vel[1];
             vroty = (P[n].Pos[2]-sinkposz)*P[n].Vel[0] - (P[n].Pos[0]-sinkposx)*P[n].Vel[2];
             vrotz = (P[n].Pos[0]-sinkposx)*P[n].Vel[1]  -  (P[n].Pos[1]-sinkposy)*P[n].Vel[0];


             vrot = pow(vrotx*vrotx + vroty*vroty + vrotz*vrotz, 0.5); 
             vrot = vrot*pow(Time, 0.5)/pow(((P[n].Pos[0]-sinkposx)*(P[n].Pos[0]-sinkposx) + (P[n].Pos[1]-sinkposy)*(P[n].Pos[1]-sinkposy) + (P[n].Pos[2]-sinkposz)*(P[n].Pos[2]-sinkposz)), 0.5);
;  //convert to km/s

             if(n%10000 == 0)
               printf("ID = %d, nh = %lg, temp = %lg, elec %lg, H2 = %lg HeII = %lg mass = %lg\n", P[n].Id, P[n].nh, P[n].Temp, P[n].HII, P[n].H2I, P[n].HeII, P[n].Mass);

             //f(P[n].nh > 1.e10 && P[n].sink > -4)
             if(disAU <= 1.e2 /*&& P[n].sink < -4*/)
               masstot = masstot + P[n].Mass/1.e-10/hubble_param;

             if(P[n].sink > 0 && P[n].nh > 8.0e13)
               printf("Mass = %g sink = %g ID = %d nh = %lg Dens = %lg Temp = %lg dis = %lg, vel = %lg, vrad = %lg, vrot = %lg\n", P[n].Mass, P[n].sink, P[n].Id, P[n].nh, P[n].Rho, P[n].Temp, disAU, vel, vrad, vrot);


    random = rand();

    if((random*(1.e0/RAND_MAX)< 0.2 && P[n].nh > 3.e-2) /*|| P[n].nh > 2.e1*/ /*&& P[n].sink < 0*/ /* ||  P[n].sink > 0.5*/ || P[n].Id < 3 ) 
    //if(P[n].nh > 1.e4 /*&& random*(1.e0/RAND_MAX)< 0.1e0*/ /*|| P[n].sink > 0.5 || (random*(1.e0/RAND_MAX))< 0.02e0*/) 
    //if(dis < 1.e1)
      {
      fprintf(outfile,"%15.13g %12d %15.13g %15.13g %15.13g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g\n", P[n].sink, P[n].Id,x,y,z,P[n].Temp,P[n].nh,P[n].HII,P[n].H2I,P[n].HDI, P[n].gam, disAU, vrad, vrot,P[n].Vel[0], P[n].Mass);
      //fprintf(outfile,"%15.13g %12d %15.13g %15.13g %15.13g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %15.6g %lg %lg %15.6g %15.6g\n", P[n].sink, Id[n],x,y,z,P[n].Temp,P[n].nh,P[n].HII,P[n].H2I,P[n].HDI, P[n].gam, disAU, P[n].Vel[0]*pow(Time, 0.5), P[n].Vel[2]*pow(Time, 0.5), P[n].hsm, P[n].Mass);
      ncount = ncount + 1;
      }
  }
  printf("ncount = %d.\n", ncount);
  printf("ncount2 = %d.\n", ncount2);

   printf("nhmax= %g\n", nhmax);
   printf("mmax= %g\n", mmax);
   printf("xmax= %15.11g\n", xmax);
   printf("ymax= %15.11g\n", ymax);
   printf("zmax= %15.11g\n", zmax);
   printf("sl = %g\n", sl);
   printf("tmax = %g\n", tmax);
   printf("h2max = %g\n", h2max);
   printf("gammin = %g\n", gammin);
   printf("typemax = %lg\n", typemax);
   printf("idmax = %d\n", idmax);
   printf("sink = %g\n", P[n-1].sink);
   printf("masstot = %g\n", masstot);
   printf("dismax = %g\n", dismax);

  fclose(outfile);
  free(P);
}

  do_what_you_want();
}
Example #7
0
/* Here we load a snapshot file. It can be distributed
 * onto several files (for files>1).
 * The particles are brought back into the order
 * implied by their ID's.
 * A unit conversion routine is called to do unit
 * conversion, and to evaluate the gas temperature.
 */
int main(int argc, char **argv)
{
  char input_fname[200];
  int  type, files, i, ok;
  int  quiteon= 0;
  char *p;

  if(argc<2)
    {
      printf("\n>readsnap <filename> <[option]>\n\n");
      printf("options\n");
      printf("-------\n");
      printf(" -info   prints byte information for all fields present\n");
      printf(" -h      only the header information is printed to the screen\n");
      printf(" -m      prints the mass of a particle when displaying other information\n");
      printf(" -id     prints the ID for each particle.\n");
      printf(" -pot    prints the Potential for every particle.\n");
      printf(" -tm     prints the total mass of each type\n");
      printf(" -gm     prints the gas mass\n");
      printf("\n\n");
      exit(0);
    }

  files=1;                               /* number of files per snapshot */
  ShowHeader=0;
  ShowMass=0;
  ShowId=0;
  ShowPot=0;
  Reorder=0;
  PrintDefault=0;
  SnapFile=0;

  strcpy(input_fname, argv[1]);

  /* problem, what if we give a path rather then just filename 
  if(!strncmp(input_fname, "snapshot", 8))  SnapFile = 1; */
  if(strstr(input_fname,"snapshot")!=0)  SnapFile = 1;

  if(argc==2) PrintDefault = 1;

  for(i=2; i<argc; i++)
  {
	ok = 0;
	if(!(strcmp(argv[i],"-info"))) ok = SnapInfo = 1;
	if(!(strcmp(argv[i],"-h"))) ok = ShowHeader = 1;
	if(!(strcmp(argv[i],"-tm"))) ok = PrintTotalMass =1;
	if(!(strcmp(argv[i],"-gm"))) ok = PrintGasMass = quiteon= 1;
	if(!(strcmp(argv[i],"-m"))) PrintDefault = ShowMass = 1;
	if(!(strcmp(argv[i],"-id"))) PrintDefault = ShowId = 1;
	if(!(strcmp(argv[i],"-pot"))) PrintDefault = ShowPot = 1;

	if((ok==0) && (PrintDefault==0))
	{
		printf("Unknown parameter: %s\n",argv[i]);
		printf("Please use correct parameters.\n");
		exit(0); 
	}
  }


  ok= load_snapshot(input_fname, files, quiteon, ShowHeader);

  if(Reorder) reordering();  /* call this routine only if your ID's are set properly */

  if(!ShowHeader) unit_conversion();  /* optional stuff */

  if(PrintDefault) write_std_to_file();
  if(ShowHeader) write_header();
  if(PrintTotalMass) print_totalmass();
  if(PrintGasMass) print_gasmass();

  return(0);
}
Example #8
0
/* Here we load a snapshot file. It can be distributed
 * onto several files (for files>1).
 * The particles are brought back into the order
 * implied by their ID's.
 * A unit conversion routine is called to do unit
 * conversion, and to evaluate the gas temperature.
 */
int main(int argc, char **argv)
{
  char path[200], input_fname[200], output_fname[200], basename[200], basenameout[200];
  int  i, k=0, j, n, type, snapshot_number, files, Ngas, random, ncount, ncounthalo1, ncount2, halo;
  double x,y,z,x1,y1,z1, delr;
  double nh, nhmax, mass, mmax, dis, disAU, xmax, ymax, zmax, sl, masstot, temp, tmax, h2, h2max, gam, gammin;
  double kB, G;
  double massHIT, diskmass, massin=0.0, massout=0.0;
  double mass_sink1, mass_sink2, mass_sink3, mass_sink4, mass_tot;
  double dis12, dis13, x_com, y_com, z_com, vx_com, vy_com, vz_com, vx1, vy1, vz1, vx2, vy2, vz2, vx3, vy3, vz3, vx4, vy4, vz4;
  double sinkposx1, sinkposy1, sinkposz1, sinkposx2, sinkposy2, sinkposz2, sinkposx3, sinkposy3, sinkposz3, sinkposx4, sinkposy4, sinkposz4;
  double num, numz, tempz, vz, rhoz, amom, amomtot, amomtotx, amomtoty, amomtotz, amomx, amomy, amomz, amomx1, amomx2, amomy1, amomy2, amomz1, amomz2;
  double xfac, vrad, vrot, vrotx, vroty, vrotz, omega, nh_avg, temp_avg, vrad_avg, vrot_avg, omega_avg, num_tot;
  double xtimesm, ytimesm, ztimesm, vxtimesm, vytimesm, vztimesm;
  double xCOM, yCOM, zCOM, vxCOM, vyCOM, vzCOM, jzcent, jnum;
  double m_enc_arr[200], d_arr[200], mass_enc;
  int ID_sink1, ID_sink2, ID_sink3, ID_sink4, sinknum;
  FILE *outfile;
  FILE *outfile2;


  sprintf(path, "/nobackupp1/astacy/hires");
  //sprintf(path, "/nobackupp1/astacy/");
  //sprintf(path, "/nobackupp1/astacy/binHR");

  halo = 0;

    if(halo == 0)
     {
     //sprintf(basename, "hires_test10");
     sprintf(basename, "hires_test10b");
     sprintf(basename, "hires3");
     sprintf(basenameout, "snaphires_test10");
     //jnum = 228;
     jnum = 2;
     }
  if(halo == 1)
     {
     sprintf(basename, "bin_HR1");
     sprintf(basenameout, "snapbin_HR1");
     //jnum = 228;
     jnum = 6;
     }
  if(halo == 2)
     {
     sprintf(basename, "bin_HR2");
     sprintf(basenameout, "snapbin_HR2");
     //jnum = 207;
     jnum = 5;
     }
  if(halo == 3)
     {
     sprintf(basename, "bin_HR3");
     sprintf(basenameout, "snapbin_HR3");
     //jnum = 206;
     jnum = 7;
     }
  if(halo == 4)
     {
     sprintf(basename, "bin_HR4");
     sprintf(basenameout, "snapbin_HR4");
     //jnum = 204;
     jnum = 7;
     }
  if(halo == 5)
     {
     sprintf(basename, "bin_HR5");
     sprintf(basenameout, "snapbin_HR5");
     //jnum = 209;
     jnum = 7;
     }
  if(halo == 6)
     {
     sprintf(basename, "bin_HR6");
     sprintf(basenameout, "snapbin_HR6b");
     //jnum = 224;
     jnum = 7;
     }
  if(halo == 7)
     {
     sprintf(basename, "bin_HR7b");
     sprintf(basenameout, "snapbin_HR7b");
     //jnum = 655;
     jnum = 9;
     //jnum=38;
     }
  if(halo == 8)
     {
     sprintf(basename, "bin_HR8");
     sprintf(basenameout, "snapbin_HR8");
     //jnum = 219;
     jnum = 7;
     }
  if(halo == 9)
     {
     sprintf(basename, "bin_HR9");
     sprintf(basenameout, "snapbin_HR9");
     //jnum = 207;
     jnum = 5;
     }
  if(halo == 10)
     {
     //sprintf(basename, "bin_HR10");
     sprintf(basename, "bin_HR10_alt");
     sprintf(basenameout, "snapbin_HR10");
     //jnum = 241;
     //jnum = 7;
     jnum=8;
     //jnum = 24;
     }


  for(j=2;j<=50;j=j+1){
  //for(j=jnum;j<=jnum;j=j+100){

  snapshot_number= j;                   /* number of snapshot */
  files=1;                               /* number of files per snapshot */

  kB = 1.38e-16;
  G = 6.67e-8;
  diskmass = 0.0;

  sprintf(input_fname, "%s/%s_%03d", path, basename, snapshot_number);
  sprintf(output_fname, "%s_disk.dat",basename);
  Ngas = load_snapshot(input_fname, files);

  ID_sink1 = 4352905;
  ID_sink2 = 4333881;
  sinknum = 0;
          /*    reordering();*/ /* call this routine only if your ID's are set properly */

printf("hello line 187\n");

          unit_conversion();

printf("hello line 191\n");

          nh_avg= vrad_avg = vrot_avg = omega_avg = 0;

printf("hello line 195\n");

          temp_avg=0;
          num_tot=0;
          h2max=0;
          masstot=0;
          mmax=0;
          xtimesm = 0.0;
          ytimesm = 0.0;
          ztimesm = 0.0;
          vxtimesm = 0.0;
          vytimesm = 0.0;
          vztimesm = 0.0;


             for(i = 0; i < Ngas; i++)
                {
                if(Id[i] == ID_sink1)
                  {
                  sinkposx1 = P[i].Pos[0];
                  sinkposy1 = P[i].Pos[1];
                  sinkposz1 = P[i].Pos[2];
                  vx1 = P[i].Vel[0];
                  vy1 = P[i].Vel[1];
                  vz1 = P[i].Vel[2];
                  mass_sink1 = P[i].Mass*1.e10/0.7;
                  printf("Found the sink! mass= %lg, nh = %lg\n", mass_sink1, P[i].nh);
                  }

                 if(P[i].nh > 1e9)
                  {
                  diskmass = diskmass + (P[i].Mass*1.e10/0.7);
                  xtimesm = xtimesm + P[i].Pos[0]*(P[i].Mass*1.e10/0.7);
                  ytimesm = ytimesm + P[i].Pos[1]*(P[i].Mass*1.e10/0.7);
                  ztimesm = ztimesm + P[i].Pos[2]*(P[i].Mass*1.e10/0.7);
                  vxtimesm = vxtimesm + P[i].Vel[0]*(P[i].Mass*1.e10/0.7);
                  vytimesm = vytimesm + P[i].Vel[1]*(P[i].Mass*1.e10/0.7);
                  vztimesm = vztimesm + P[i].Vel[2]*(P[i].Mass*1.e10/0.7);
                  }
                }

             xCOM = xtimesm/diskmass;
             yCOM = ytimesm/diskmass;
             zCOM = ztimesm/diskmass;
             vxCOM = vxtimesm/diskmass;
             vyCOM = vytimesm/diskmass;
             vzCOM = vztimesm/diskmass;
             printf("%15.11g %15.11g %15.11g\n", xCOM, yCOM, zCOM);
             printf("%15.11g %15.11g %15.11g\n", vxCOM, vyCOM, vzCOM);


          //  if(j>=4)
          //  {
            sinkposx1 = xCOM;
            sinkposy1 = yCOM;
            sinkposz1 = zCOM;
            mass_sink1 = diskmass;
            vx1 = vxCOM;
            vy1 = vyCOM;
            vz1 = vzCOM;
         //   }

         diskmass=0.0;
         ncount=0;

        for(n=0; n<200; n++)
               {
               m_enc_arr[n] = 0.0;
               d_arr[n] = (double(n)/199.0)*10000.0;
               printf("d_arr[%d] = %lg\n", n, d_arr[n]);
               }

       for(i = 0; i < Ngas; i++)
               {
                if(P[i].nh > 1.e8)
                  {
                   dis = pow(((P[i].Pos[0]-sinkposx1)*(P[i].Pos[0]-sinkposx1) + (P[i].Pos[1]-sinkposy1)*(P[i].Pos[1]-sinkposy1) + (P[i].Pos[2]-sinkposz1)*(P[i].Pos[2]-sinkposz1)), 0.5);
                   dis=dis*1.e3*Time/(0.7);                   //dis is in pc
                   disAU = dis*206264.8060;
                   for(n=0; n<200; n++)
                     {
                     if(disAU < d_arr[n] /*|| P[i].sink > 0.5*/)
                       m_enc_arr[n] = m_enc_arr[n] + P[i].Mass*1.e10/0.7;
                     }
                    }
                  }

        for(n=0; n<200; n++)
               {
               printf("m_enc_arr[%d] = %lg\n", n, m_enc_arr[n]);
               }


         for(i = 0; i < Ngas; i++)
                {

                 P[i].Vel[0] = P[i].Vel[0] - vx1;
                 P[i].Vel[1] = P[i].Vel[1] - vy1;
                 P[i].Vel[2] = P[i].Vel[2] - vz1;

                 amomx = (P[i].Pos[1]-sinkposy1)*P[i].Vel[2]  - (P[i].Pos[2]-sinkposz1)*P[i].Vel[1];
                 amomy = (P[i].Pos[2]-sinkposz1)*P[i].Vel[0] - (P[i].Pos[0]-sinkposx1)*P[i].Vel[2];
                 amomz = (P[i].Pos[0]-sinkposx1)*P[i].Vel[1]  -  (P[i].Pos[1]-sinkposy1)*P[i].Vel[0];

                 amomx =  amomx*pow(Time, 0.5)*1.e5*3.086e18*1.e3*Time/(0.7);  //convert to cgs units
                 amomy =  amomy*pow(Time, 0.5)*1.e5*3.086e18*1.e3*Time/(0.7);
                 amomz =  amomz*pow(Time, 0.5)*1.e5*3.086e18*1.e3*Time/(0.7);

                 amom = pow(amomx*amomx + amomy*amomy + amomz*amomz, 0.5);

                 dis = pow(((P[i].Pos[0]-sinkposx1)*(P[i].Pos[0]-sinkposx1) + (P[i].Pos[1]-sinkposy1)*(P[i].Pos[1]-sinkposy1) + (P[i].Pos[2]-sinkposz1)*(P[i].Pos[2]-sinkposz1)), 0.5);
                 //dis = pow(((P[i].Pos[0]-sinkposx1)*(P[i].Pos[0]-sinkposx1) + (P[i].Pos[2]-sinkposz1)*(P[i].Pos[2]-sinkposz1)), 0.5);
                 dis=dis*1.e3*Time/(0.7);                   //dis is in pc
                 disAU = dis*206264.8060;
                 dis=dis*3.086e18;   //dis in now in cm                

                 vrad =  (P[n].Vel[0]*(P[n].Pos[0]-sinkposx1) + P[n].Vel[1]*(P[n].Pos[1]-sinkposy1) + P[n].Vel[2]*(P[n].Pos[2]-sinkposz1))/pow(((P[n].Pos[0]-sinkposx1)*(P[n].Pos[0]-sinkposx1) + (P[n].Pos[1]-sinkposy1)*(P[n].Pos[1]-sinkposy1) + (P[n].Pos[2]-sinkposz1)*(P[n].Pos[2]-sinkposz1)), 0.5);
                 vrad = vrad*pow(Time, 0.5);


                 vrotx = (P[n].Pos[1]-sinkposy1)*P[n].Vel[2]  - (P[n].Pos[2]-sinkposz1)*P[n].Vel[1];
                 vroty = (P[n].Pos[2]-sinkposz1)*P[n].Vel[0] - (P[n].Pos[0]-sinkposx1)*P[n].Vel[2];
                 vrotz = (P[n].Pos[0]-sinkposx1)*P[n].Vel[1]  -  (P[n].Pos[1]-sinkposy1)*P[n].Vel[0];

                 vrot = pow(vrotx*vrotx + vroty*vroty + vrotz*vrotz, 0.5);
                 vrot = vrot*pow(Time, 0.5)/pow(((P[n].Pos[0]-sinkposx1)*(P[n].Pos[0]-sinkposx1) + (P[n].Pos[1]-sinkposy1)*(P[n].Pos[1]-sinkposy1) + (P[n].Pos[2]-sinkposz1)*(P[n].Pos[2]-sinkposz1)), 0.5);

                 omega = vrot/(dis/1.e5);  // pi factors CANCEL OUT -- 2 pi r to get circumference CANCELS with the 2 pi radians per circumference

                 if(P[i].nh > 1.e8)
                 {
                   mass_enc = m_enc_arr[0];
                   for(n=0; n<200; n++)
                     {
                     if(disAU > d_arr[n])
                       mass_enc = m_enc_arr[n];
                     }
                 //jzcent = pow(6.67e-8 * mass_sink1 * 1.98892e33*dis, 0.5);
                 jzcent = pow(6.67e-8 * mass_enc * 1.98892e33*dis, 0.5);
                 }

                 //if((fabs(amom - jzcent) <= 0.5*jzcent && P[i].nh > 1.e8) && P[i].sink < 0.5)
                 //if((fabs(amom - jzcent) <= 0.5*jzcent && P[i].nh > 1.e8) || P[i].sink > 0.5)
                 if(P[i].nh > 1.e9 && P[i].H2I > 1.e-3 || P[i].sink > 0.5)
                 //if(P[i].nh > 1.e9 && P[i].H2I > 1.e-3 && P[i].sink < 0.5)
                 //if(P[i].nh > 1.e9 && P[i].H2I <= 1.e-3 &&  P[i].sink < 0.5)
                 //if(amom > jzcent && P[i].nh > 1.e8 && P[i].sink < 0.5)
                  {

                  //diskmass = diskmass + (P[i].Mass*1.e10/0.7);
                  //nh_avg = nh_avg + P[i].nh*(P[i].Mass/1.03395e-12);
                  //temp_avg = temp_avg + P[i].Temp*(P[i].Mass/1.03395e-12);
                  //num_tot = num_tot + (P[i].Mass/1.03395e-12);

                  diskmass = diskmass + (P[i].Mass*1.e10/0.7);
                  //nh_avg = nh_avg + P[i].nh;
                  nh_avg = nh_avg +(1- 2.*P[i].H2I);

                  if(P[i].sink < 0.5)
                   temp_avg = temp_avg + P[i].Temp;
                  
                  //if(P[i].Temp > 6000)
                  //  printf("ID = %d nh = %lg, temp = %lg, elec %lg, H2 = %lg sink = %lg\n", Id[i], P[i].nh, P[i].Temp, P[i].HII, P[i].H2I, P[i].sink);

                  vrad_avg = vrad_avg + fabs(vrad);
                  vrot_avg = vrot_avg + vrot;
                  omega_avg = omega_avg + omega;
                  num_tot = num_tot + 1.0;

                  if(P[i].sink > 0.5)
                   sinknum++;

                    ncount++;
                    //}
                  }
                }
            //fclose(outfile2);  
            printf("temp = %lg, num_tot = %lg, temp_avg = %lg\n", temp_avg, num_tot, temp_avg/num_tot);

             //outfile=fopen("disk_tot_h2_ng9_nr6e_alt", "a");
             //outfile=fopen("disk_nosink_h2_ng9_nr6e_alt", "a");
             //outfile=fopen("disk_hot_ng9_nr6e_alt", "a");
             //outfile=fopen("disk_test", "a");
             outfile=fopen(output_fname, "a");
             fprintf(outfile, "%15.11g %15.11g %15.11g %15.11g %15.11g %15.11g %15.11g %d\n", Time, diskmass, nh_avg/num_tot, temp_avg/num_tot, vrad_avg/num_tot, vrot_avg/num_tot, omega_avg/num_tot, sinknum);
             fclose(outfile);

             outfile=fopen(output_fname2, "a");
             fprintf(outfile, "%15.11g %15.11g \n", Time, fshield);
             fclose(outfile);

  free(P);
}

  do_what_you_want();
}
/* Here we load a snapshot file. It can be distributed
 * onto several files (for files>1).
 * The particles are brought back into the order
 * implied by their ID's.
 * A unit conversion routine is called to do unit
 * conversion, and to evaluate the gas temperature.
 */
int main(int argc, char **argv)
{
  char path[200], input_fname[200], output_fname[200], basename[200], basenameout[200];
  int  j, n, type, snapshot_number, output_number,files, Ngas, random, ncount, ncounthalo1, ncount2;
  float x,y,z,x1,y1, z1, delr;
  double delx, dely, delz, boxsize;
  FILE *outfile;


  sprintf(path, "/work/00863/minerva/");

  //sprintf(basename, "midres_small");
  //sprintf(basename, "midhires/midhires");
  //sprintf(basename, "hires_test10");
  //sprintf(basename, "dmaH101");
  sprintf(basename, "bin_HR10");
  //sprintf(basename, "bin_zoom10_new");
  //sprintf(basename, "bin_zoom10_new_highN");
  //sprintf(basename, "bin_zoom10_new_ref");

  //snapshot_number=300;                   /* number of snapshot */
  //snapshot_number=500;
  //snapshot_number=800;  
  //snapshot_number=910;
  //snapshot_number=2550;
  //snapshot_number=764;
  //snapshot_number=442;

  //sprintf(basename, "midres");
  //snapshot_number=250;                   /* number of snapshot */

output_number = 6;
for(j=6; j<=6; j=j+1)
  {

  snapshot_number=j;
  
  files=1;     

  boxsize = 140.0;

/*
  delx = 70.309788381;  /del's used in making hires_nf (?) (midhires_920)
  dely = 70.290775273;
  delz = 69.663477541;
*/
/*
  delx = 70.285815369;  //del's used in making hires_nf2 (midhires_500)
  dely = 70.267684537;
  delz = 69.645294964;
*/
/*
  delx = 70.285954951;  //del's used in making hires_nf3 (midhires_800)
  dely = 70.267065424;
  delz = 69.645294964;
*/
/*
  delx = 70.285976724;  //del's used in making hires_nf2 (midhires_910)
  dely = 70.266799478;
  delz = 69.644071682;
*/
/*
  delx = 70.286688899;  //del's used in making dma_ (midhires_300)
  dely = 70.271233273;
  delz = 69.65345084;
*/
/*
  delx = 70.285951357;  //del's used in making hires_test10_4202 (hires_test10_4201)
  dely = 70.2668302;
  delz = 69.644059893;
*/
/*
  delx = 70.285964359;  //del's used in making hires_test10b_2550 (hires_test10_2550)
  dely = 70.266825688;
  delz = 69.644095683;
*/
/*
  delx = 70.285900597;  //del's used in making dmaH101_765 (dmaH101_764)
  dely = 70.267312791;
  delz = 69.645754876;
*/
/*
  delx = 512.65800353;  //del's used in making bin_HRE10_442 (bin_HRE10_443)
  dely = 505.21836888;
  delz = 497.39349349;
*/

  delx = 512.65800353;  //del's used in making bin_zoom10_cut_??? (bin_zoom10_???)
  dely = 505.21836888;
  delz = 497.39349349;

  sprintf(input_fname, "%s/%s_%03d", path, basename, snapshot_number);

  if(snapshot_number > 999)
    sprintf(input_fname, "%s/%s_%04d", path, basename, snapshot_number);

  //sprintf(output_fname, "/nobackupp1/astacy/dma_001");
  //sprintf(output_fname, "/nobackupp1/astacy/hires_test10_4202");
  //sprintf(output_fname, "/nobackupp1/astacy/hires_test10b_2550");
  //sprintf(output_fname, "/nobackupp1/astacy/dmaH101_765");
  //sprintf(output_fname, "/nobackupp1/astacy/bin_HRE10_443");
  
  sprintf(basenameout, "bin_HR10_cut");
  sprintf(output_fname, "%s/%s_%03d", path, basenameout, output_number);
  if(snapshot_number > 999)
    sprintf(output_fname, "%s/%s_%04d", path, basenameout, output_number);
  output_number++;

  Ngas = write_snapshot(input_fname, files, output_fname, delx, dely, delz, boxsize);

  unit_conversion();  

  ncount = 0;
  ncount2 = 0;

  printf("ncount = %d.\n", ncount);
  printf("ncount2 = %d.\n", ncount2);

  do_what_you_want();
  free(P);
}
}
Example #10
0
/* Here we load a snapshot file. It can be distributed
 * onto several files (for files>1).
 * The particles are brought back into the order
 * implied by their ID's.
 * A unit conversion routine is called to do unit
 * conversion, and to evaluate the gas temperature.
 */
int main(int argc, char **argv)
{
  char path[200], input_fname[200], output_fname[200], output_fname2[200], basename[200], basenameout[200];
  int  i, k=0, j, n, type, snapshot_number, files, Ngas, random, ncount, ncounthalo1, arrnum=200;
  double x,y,z,x1,y1,z1, delr;
  double nh, nhmax, mass, mmax, dis, dis_sim, disAU, xmax, ymax, zmax, sl, masstot, temp, tmax, h2, h2max, gam, gammin;
  int IDmax;
  double rho_b, rho_DM[arrnum], rho_vir, r_vir, v_vir;
  double kB, G;
  double bind, diskmass, massin=0.0, massout=0.0;
  double vrad, vrot, disAUxy, disAUz, disAUxyz, vx_com, vy_com, vz_com, vx1, vy1, vz1, vx2, vy2, vz2, vx3, vy3, vz3, vx4, vy4, vz4;
  double sinkposx1, sinkposy1, sinkposz1, sinkposx2, sinkposy2, sinkposz2; 
  double sinkposx3, sinkposy3, sinkposz3, sinkposx4, sinkposy4, sinkposz4;
  double num, amom, amom_arr[arrnum], amomtot, amomx_tot, amomy_tot; 
  double amomz_tot, amomx, amomy, amomz, amomx1, amomx2, amomy1, amomy2, amomz1, amomz2;
  double xfac, yfac, zfac, kfloat, nh_avg, num_tot, omega, omega0, nthresh;
  double xtimesm, ytimesm, ztimesm, vxtimesm, vytimesm, vztimesm;
  double xCOM, yCOM, zCOM, vxCOM, vyCOM, vzCOM, jzcent;
  double temp_arr[arrnum], mbe_arr[arrnum], omega_arr[arrnum];
  double m_enc_arr[arrnum], d_arr[arrnum], mass_enc, n_arr[arrnum], n_arr2[arrnum], surf_dens_arr[arrnum];
  double rmin, rmax, nmin, nmax, numdens_arr[arrnum]; 
  double vradx, vrady, vradz, vrotx, vroty, vrotz, vrad_arr[arrnum], vrot_arr[arrnum], dens_arr[arrnum], c_s_arr[arrnum]; 
  double vradx_arr[arrnum], vrady_arr[arrnum], vradz_arr[arrnum], vrotx_arr[arrnum], vroty_arr[arrnum], vrotz_arr[arrnum];
  double velx, vely, velz, velx_arr[arrnum], vely_arr[arrnum], velz_arr[arrnum];
  double mdm_enc_arr[arrnum], turb_arr[arrnum], disx, disy, disz;
  double KE, KE_tot, PE, PE_tot, vel, spin_param, ncount_doub;
  int ID_sink1, ID_sink2, ID_sink3, ID_sink4, sinknumk;
  FILE *outfile, *outfile2;

  sprintf(path, "/work/00863/minerva/bin_zoom");
  //sprintf(basename, "ifront_hiacc");

  //sprintf(path, "/nobackupp1/astacy/binHR");
  //sprintf(basename, "bin_HR1");
  //sprintf(basename, "bin_HR7");
  //sprintf(basename, "bin_HR10");

  //sprintf(path, "/nobackupp1/astacy/bin_zoom");
  //sprintf(basename, "bin_zoom1");
  //sprintf(basename, "bin_zoom2");
  //sprintf(basename, "bin_zoom3");
  //sprintf(basename, "bin_zoom4");
  //sprintf(basename, "bin_zoom5");
  //sprintf(basename, "bin_zoom6");
  //sprintf(basename, "bin_zoom7");
  //sprintf(basename, "bin_zoom9");
  //sprintf(basename, "bin_zoom10");


  //for(j=453;j<=453;j++)
  //for(j=6;j<=6;j++)	
  //for(j=9;j<=9;j++)
  //for(j=1;j<=1;j++)
  //for(j=90;j<=90;j++)
  //for(j=77;j<=77;j++)
  //for(j=86;j<=86;j++)
  //for(j=127;j<=127;j++)
  //for(j=112;j<=112;j++)
  //for(j=139;j<=139;j++)
  //for(j=91;j<=91;j++)
  //for(j=113;j<=113;j++)  
  //for(j=101;j<=101;j++)

/*
  sprintf(path, "/scratch/00863/minerva");
  sprintf(basename, "bin_zoom9_new_ref3");  
  for(j=6800;j<=6800;j=j+20)
*/


  sprintf(path, "/scratch/00863/minerva");
  sprintf(basename, "bin_zoom10_new_ref3");  
  for(j=5600;j<=5600;j=j+20)

  //for(j=40;j<=80;j=j+20)
  {
  
  snapshot_number= j;                   /* number of snapshot */
  files=1;                               /* number of files per snapshot */

  sprintf(input_fname, "%s/%s_%03d", path, basename, snapshot_number);
  //sprintf(input_fname, "%s/%s_%04d", path, basename, snapshot_number);
  Ngas = load_snapshot(input_fname, files);

  sprintf(output_fname, "%s_mini_%03d.dat",basename, snapshot_number);
  if(j > 999) sprintf(output_fname, "%s_mini_%04d.dat",basename, snapshot_number);

          /*    reordering();*/ /* call this routine only if your ID's are set properly */

  rho_b = 2.94e-30; //background density of the universe

  unit_conversion();

  nh_avg=ncount_doub=0;
  num_tot=0;
  h2max=nhmax=mmax=kfloat=0.0;
  xtimesm = ytimesm = ztimesm = 0.0;
  vxtimesm = vytimesm = vztimesm = 0.0;
  vxCOM=vyCOM=vzCOM=xCOM=yCOM=zCOM=0;
  amomx_tot = amomy_tot = amomz_tot = 0;
  amomtot = omega0 = masstot = 0.0;
  
  nthresh = 1.e4;	  	
	
       for(i = 0; i < Ngas; i++)
        {
       if(P[i].nh > nhmax /*&& P[i].sink < 0.5*/)
   	   {
           nhmax = P[i].nh;
           IDmax = P[i].Id;
           xmax = P[i].Pos[0];
           ymax = P[i].Pos[1];
           zmax = P[i].Pos[2];
           mmax = P[i].Mass;
           }
         }
	printf("xmax = %lg ymax = %lg zmax = %lg mmax = %lg nhmax = %lg\n", xmax, ymax, zmax, mmax, nhmax);

        for(n=0;n<=Ngas;n++) 
         {
           nh = P[n].nh;
           dis = pow(((P[n].Pos[0]-xmax)*(P[n].Pos[0]-xmax) + (P[n].Pos[1]-ymax)*(P[n].Pos[1]-ymax) + (P[n].Pos[2]-zmax)*(P[n].Pos[2]-zmax)), 0.5);
           dis=dis*1.e3*Time/(0.7);
           disx = fabs((P[n].Pos[0]-xmax))*1.e3*Time/(0.7);
           disy = fabs((P[n].Pos[1]-ymax))*1.e3*Time/(0.7);
           disz = fabs((P[n].Pos[2]-zmax))*1.e3*Time/(0.7);
           disAU=dis*206264.806;
           if(disx < width && disy < width && disz < width)
            {
            vxCOM = vxCOM + P[n].Vel[0]*P[n].Mass;
            vyCOM = vyCOM + P[n].Vel[1]*P[n].Mass;
            vzCOM = vzCOM + P[n].Vel[2]*P[n].Mass;
            xCOM = xCOM + P[n].Pos[0]*P[n].Mass;
            yCOM = yCOM + P[n].Pos[1]*P[n].Mass;
            zCOM = zCOM + P[n].Pos[2]*P[n].Mass;
            ncount_doub = ncount_doub + P[n].Mass;
            }
        }

         vx1 = vxCOM/ncount_doub;
         vy1 = vyCOM/ncount_doub;
         vz1 = vzCOM/ncount_doub;
         //vx = vy = vz = 0;

	sinkposx1 = xmax;
	sinkposy1 = ymax;
	sinkposz1 = zmax;

        printf("vx1 = %lg, vy1 = %lg, vz1 = %lg, sinkposx1 = %lg, sinkposy1 = %lg, sinkposz1 = %lg\n", vx1, vy1, vz1, sinkposx1, sinkposy1, sinkposz1);

	diskmass=0.0;
	ncount=0;  
	ncount_doub=0.;
	  

	rmin = 100.;
        rmax = 3e8;
        nmin = 1.e-2;
        nmax = 1.e12;

        for(n=0; n<arrnum; n++)
          {
          m_enc_arr[n] = amom_arr[n] = n_arr[n] = n_arr2[n]  = surf_dens_arr[n] = c_s_arr[n] = 0.0;
          temp_arr[n] = mbe_arr[n] = omega_arr[n] = 0.0; 
          vrot_arr[n] = vrotx_arr[n] = vroty_arr[n] = vrotz_arr[n] = 0;
          vrad_arr[n] = vradx_arr[n] = vrady_arr[n] = vradz_arr[n] = 0;
          rho_DM[n] = 0.0;
          //d_arr[n] = (double(n)/199.0)*5.e8;
          //d_arr[n] = pow(5.e8,double(n)/double(arrnum));
          d_arr[n] = rmin * pow(rmax/rmin, double(n)/double(arrnum));
          numdens_arr[n] = nmin * pow(nmax/nmin, double(n)/double(arrnum));
          //printf("d_arr[%d] = %lg\n", n, d_arr[n]);
          }
 
         //for(i = Ngas; i < NumPart; i++)
         for(i = 0; i < NumPart; i++)
               {
	       dis = pow(((P[i].Pos[0]-sinkposx1)*(P[i].Pos[0]-sinkposx1) + (P[i].Pos[1]-sinkposy1)*(P[i].Pos[1]-sinkposy1) + (P[i].Pos[2]-sinkposz1)*(P[i].Pos[2]-sinkposz1)), 0.5);
	       dis=dis*1.e3*Time/(0.7);                   //dis is in pc
	       disAU = dis*206264.8060;
	       if(disAU < 5.e8)
                    {
                    for(n=0; n<arrnum; n++)
                      {
                      if(disAU < d_arr[n] && P[i].Type == 0)
                        m_enc_arr[n] = m_enc_arr[n] + P[i].Mass*1.e10/0.7;
                      if(disAU < d_arr[n] && P[i].Type == 1)
                        mdm_enc_arr[n] = mdm_enc_arr[n] + P[i].Mass*1.e10/0.7;
                      } 
                     }
                  }

          for(n=0; n<arrnum; n++)
               {
               rho_DM[n] = mdm_enc_arr[n]*1.98892e33/((4.0/3.0)*3.14159*pow(d_arr[n]*1.5e13, 3.0));  //DM density in cgs
               printf("mdm_enc_arr[%d] = %lg\n", n, mdm_enc_arr[n]);
               //printf("rho_DM[%d] = %lg\n", n, rho_DM[n]/(rho_b*pow(Time, -3.0)));
               if(rho_DM[n] > 200.0*rho_b*pow(Time, -3.0))
                 {
                 rho_vir = rho_DM[n];
                 r_vir = d_arr[n];
                 }
               }
	  
	
             //rotate(sinkposx1,sinkposy1,sinkposz1, vx1, vy1, vz1);
 
         //for(i = Ngas; i < NumPart; i++)
         for(i = 0; i < Ngas; i++)
                {

                 P[i].Vel[0] = P[i].Vel[0] - vx1;
                 P[i].Vel[1] = P[i].Vel[1] - vy1;
                 P[i].Vel[2] = P[i].Vel[2] - vz1;
          
                 amomx = (P[i].Pos[1]-sinkposy1)*P[i].Vel[2]  - (P[i].Pos[2]-sinkposz1)*P[i].Vel[1];
                 amomy = (P[i].Pos[2]-sinkposz1)*P[i].Vel[0] - (P[i].Pos[0]-sinkposx1)*P[i].Vel[2];
                 amomz = (P[i].Pos[0]-sinkposx1)*P[i].Vel[1]  -  (P[i].Pos[1]-sinkposy1)*P[i].Vel[0];

                 amomx = (P[i].Mass*1.e10*1.98892e33/.7)*amomx*pow(Time, 0.5)*1.e5*3.086e18*1.e3*Time/(0.7);  //convert to cgs units
                 amomy = (P[i].Mass*1.e10*1.98892e33/.7)*amomy*pow(Time, 0.5)*1.e5*3.086e18*1.e3*Time/(0.7);
                 amomz = (P[i].Mass*1.e10*1.98892e33/.7)*amomz*pow(Time, 0.5)*1.e5*3.086e18*1.e3*Time/(0.7);

                 amom = pow(amomx*amomx + amomy*amomy + amomz*amomz, 0.5);  //ang. mom. of particle in cgs

                 vel = pow(P[i].Vel[0]*P[i].Vel[0] + P[i].Vel[1]*P[i].Vel[1] + P[i].Vel[2]*P[i].Vel[2], 0.5);
                 vel = vel*pow(Time, 0.5)*1.e5;  //convert vel to cgs 

                 KE = 0.5*(P[i].Mass*1.e10*1.98892e33/.7)*pow(vel,2.0);   //kinetic energy in cgs

                 velx = P[i].Vel[0]*pow(Time, 0.5);
                 vely = P[i].Vel[1]*pow(Time, 0.5);
                 velz = P[i].Vel[2]*pow(Time, 0.5);

                 dis_sim = pow(((P[i].Pos[0]-sinkposx1)*(P[i].Pos[0]-sinkposx1) + (P[i].Pos[1]-sinkposy1)*(P[i].Pos[1]-sinkposy1) + (P[i].Pos[2]-sinkposz1)*(P[i].Pos[2]-sinkposz1)), 0.5);
                 dis = pow(((P[i].Pos[0]-sinkposx1)*(P[i].Pos[0]-sinkposx1) + (P[i].Pos[1]-sinkposy1)*(P[i].Pos[1]-sinkposy1) + (P[i].Pos[2]-sinkposz1)*(P[i].Pos[2]-sinkposz1)), 0.5); 
                 dis=dis*1.e3*Time/(0.7);                   //dis is in pc
                 disAU = dis*206264.8060;
                 dis=dis*3.086e18;   //dis in now in cm                

                 vrot  = amom/(P[i].Mass*1.e10*1.98892e33/.7)/dis/1e5;
                 vrotx = amomx/(P[i].Mass*1.e10*1.98892e33/.7)/dis/1e5;              
                 vroty = amomy/(P[i].Mass*1.e10*1.98892e33/.7)/dis/1e5;
                 vrotz = amomz/(P[i].Mass*1.e10*1.98892e33/.7)/dis/1e5; //vrot in km/s 
                 omega = (P[i].Mass/1.e-10/.7)*vrot/(disAU*1.5e8); 

             if(P[i].nh > nthresh && disAU > 0)
                   {
                   masstot = masstot + P[i].Mass/1.e-10/.7;
                   omega0 = omega0 + (P[i].Mass/1.e-10/.7)*vrot/(disAU*1.5e8);  //divide vrot by distance in km
                   }

                 disAUxyz = pow((P[i].Pos_new[0])*(P[i].Pos_new[0]) + (P[i].Pos_new[1])*(P[i].Pos_new[1]) + (P[i].Pos_new[2])*(P[i].Pos_new[2]), 0.5);
                 disAUxyz = disAUxyz*1.e3*Time/(0.7)*206264.8060;

                 disAUxy = pow(((P[i].Pos_new[0])*(P[i].Pos_new[0]) + (P[i].Pos_new[1])*(P[i].Pos_new[1])), 0.5);
                 disAUxy = disAUxy*1.e3*Time/(0.7)*206264.8060;
 
                 disAUz = fabs(P[i].Pos_new[2]*1.e3*Time/(0.7)*206264.8060);  

                 vrad =  (P[i].Vel[0]*(P[i].Pos[0]-sinkposx1) + P[i].Vel[1]*(P[i].Pos[1]-sinkposy1) + P[i].Vel[2]*(P[i].Pos[2]-sinkposz1))/dis_sim;
                 vrad = vrad*pow(Time, 0.5);
                 vradx = (P[i].Vel[0]*(P[i].Pos[0]-sinkposx1))/dis_sim*pow(Time, 0.5);
                 vrady = (P[i].Vel[1]*(P[i].Pos[1]-sinkposy1))/dis_sim*pow(Time, 0.5);
                 vradz = (P[i].Vel[2]*(P[i].Pos[2]-sinkposz1))/dis_sim*pow(Time, 0.5); 

                 if(disAU < r_vir /*&& KE + PE < 0.0*/)
                   {
                   KE_tot = KE_tot + KE;
                   PE_tot = PE_tot + PE;
                   amomtot = amomtot + amom;
                   amomx_tot = amomx_tot + amomx;          
                   amomy_tot = amomy_tot + amomy;
                   amomz_tot = amomz_tot + amomz;
                   num_tot = num_tot + P[i].Mass;
		   ncount++;  
                   }

                 if(P[i].nh > 1.e-2)
                   for(n=0; n<arrnum; n++)
                    {
                    if(disAU > d_arr[n] && disAU < d_arr[n+1] && P[i].sink < 0.5)
                      {
                      amom_arr[n] = amom_arr[n] + amom/(P[i].Mass*1.e10*1.98892e33/.7);
                      dens_arr[n] = dens_arr[n] + P[i].nh;
                      c_s_arr[n] = c_s_arr[n] + pow(1.38e-16*P[i].Temp/1.e-24,0.5)/1.e5;
                      temp_arr[n] = temp_arr[n] + P[i].Temp;
                      mbe_arr[n] = mbe_arr[n] + 1050.*pow(P[i].Temp/200.,1.5)*pow(P[i].nh/1.e4,-0.5);

                      velx_arr[k] = velx_arr[k] + velx;
                      vely_arr[k] = vely_arr[k] + vely;
                      velz_arr[k] = velz_arr[k] + velz;
                      vrad_arr[n] = vrad_arr[n] + vrad;
                      //vrot_arr[n] = vrot_arr[n] + vrot;
                      vradx_arr[n] = vradx_arr[n] + vradx;
                      vrady_arr[n] = vrady_arr[n] + vrady;
                      vradz_arr[n] = vradz_arr[n] + vradz;
                      vrotx_arr[n] = vrotx_arr[n] + vrotx;
                      vroty_arr[n] = vroty_arr[n] + vroty;
                      vrotz_arr[n] = vrotz_arr[n] + vrotz;
                      n_arr[n]=n_arr[n] + 1.0;
                      }
                     if(disAU < d_arr[n+1] && disAU > 0)
                       omega_arr[n] = omega_arr[n] + omega;
                     }

                 if(P[i].nh > 1.e-2)
                   for(n=0; n<arrnum; n++) 
                    {   
                    if(disAUxy > d_arr[n] && disAUxy < d_arr[n+1] && disAUz < 10.  && P[i].sink < 0.5)
                    //if(disAUxyz > d_arr[n] && disAUxyz < d_arr[n+1] && P[i].sink < 0.5)
                     {
                     surf_dens_arr[n] = surf_dens_arr[n] + P[i].Mass*1.e10*1.98892e33/.7;
                     n_arr2[n]=n_arr2[n] + 1.0;                     
                     }
                    }
                }

             outfile=fopen(output_fname, "a");
             for(n=0; n<arrnum; n++)
                   {
                   printf("n_arr2 = %lg , c_s = %lg, vrad = %lg, surf_dens = %lg omega = %lg\n", n_arr2[n], c_s_arr[n], vrad_arr[n], surf_dens_arr[n], omega_arr[n]);
                   dens_arr[n] = dens_arr[n]/n_arr[n];

                   velx_arr[n] = velx_arr[n]/n_arr[n];
                   vely_arr[n] = vely_arr[n]/n_arr[n];
                   velz_arr[n] = velz_arr[n]/n_arr[n];
                   vradx_arr[n] = vradx_arr[n]/n_arr[n];
                   vrady_arr[n] = vrady_arr[n]/n_arr[n];
                   vradz_arr[n] = vradz_arr[n]/n_arr[n];
                   vrotx_arr[n] = vrotx_arr[n]/n_arr[n];
                   vroty_arr[n] = vroty_arr[n]/n_arr[n];
                   vrotz_arr[n] = vrotz_arr[n]/n_arr[n];
                   //vrad_arr[n] = pow(vradx_arr[n]*vradx_arr[n] + vrady_arr[n]*vrady_arr[n] + vradz_arr[n]*vradz_arr[n], 0.5)/n_arr[n];
                   vrad_arr[n] = vrad_arr[n]/n_arr[n];
                   vrot_arr[n] = pow(vrotx_arr[n]*vrotx_arr[n] + vroty_arr[n]*vroty_arr[n] + vrotz_arr[n]*vrotz_arr[n], 0.5)/n_arr[n];
                   c_s_arr[n] = c_s_arr[n]/n_arr[n];
                   temp_arr[n] = temp_arr[n]/n_arr[n];
                   mbe_arr[n] = mbe_arr[n]/n_arr[n];
                   surf_dens_arr[n] = surf_dens_arr[n]/3.14159/(pow(1.4958e13*d_arr[n+1],2) - pow(1.4958e13*d_arr[n],2));

	           turb_arr[n] = pow(velx_arr[n] - vradx_arr[n] - vrotx_arr[n],2) + pow(vely_arr[n] - vrady_arr[n] - vroty_arr[n],2) + pow(velz_arr[n] - vradz_arr[n] - vrotz_arr[n],2);
      		   turb_arr[n] = pow(turb_arr[n], 0.5);

      		   vrot_arr[n] = pow(vrotx_arr[n]*vrotx_arr[n] + vroty_arr[n]*vroty_arr[n] + vrotz_arr[n]*vrotz_arr[n], 0.5);
      		   if(n > 0)
        		amom_arr[n] = (m_enc_arr[k] - m_enc_arr[k-1])*vrot_arr[n]*d_arr[n]*1.5e13*1.e5*2.e33;
      		   if(n == 0)
        		amom_arr[n] = m_enc_arr[0]*vrot_arr[0]*d_arr[0]*1.5e13*1.e5*2.e33;


                   fprintf(outfile, "%15.11g %15.11g %15.11g %15.11g %15.11g %15.11g %15.11g %15.11g %15.11g %15.11g %15.11g %15.11g %15.11g\n", d_arr[n], m_enc_arr[n], mdm_enc_arr[n], dens_arr[n], surf_dens_arr[n], c_s_arr[n], temp_arr[n], mbe_arr[n], omega_arr[n]/m_enc_arr[n], vrad_arr[n], vrot_arr[n], turb_arr[n], amom_arr[n]);
                   }
             fclose(outfile);
 
             free(P);
  }

}
/* Here we load a snapshot file. It can be distributed
 * onto several files (for files>1).
 * The particles are brought back into the order
 * implied by their ID's.
 * A unit conversion routine is called to do unit
 * conversion, and to evaluate the gas temperature.
 */
int main(int argc, char **argv)
{
  char path[200], input_fname[200], output_fname[200], basename[200], basenameout[200];
  int  j, n, type, snapshot_number, files, Ngas, random, ncount, ncounthalo1, ncount2;
  float x,y,z,x1,y1, z1, delr;
  double delx, dely, delz, boxsize;
  FILE *outfile;


  sprintf(path, "/nobackupp1/astacy/bin_zoom");
  //sprintf(basename, "midres_small");
  //sprintf(basename, "midhires");
  sprintf(basename, "bin_zoom10");
  //snapshot_number=90;                   /* number of snapshot */
  //snapshot_number=77;
  //snapshot_number=86;
  //snapshot_number=127;
  //snapshot_number=112; 
  //snapshot_number=139;
  //snapshot_number=101;
  //snapshot_number=94;
  //snapshot_number=113;
  snapshot_number=91;
  //snapshot_number=89;           //using bin_zoom10 for dma study
  files=1;     

  boxsize = 140.0;

  //delx = 70.309788381;
  //dely = 70.290775273;
  //delz = 69.663477541;

  //delx = 50.339110402;
  //dely = 50.122129376;
  //delz = 49.486652655;

  //delx = 501.10837429;   //bin_HR1
  //dely = 502.63795002;
  //delz = 500.57881331;

  //delx = 504.74822278;   //bin_HR2
  //dely = 502.54674042;
  //delz = 498.35964366;

  //delx = 497.97549715;   //bin_HR3
  //dely = 478.97623119;
  //delz = 533.38658886;

  //delx = 492.79124064;   //bin_HR4
  //dely = 481.69180059;
  //delz = 488.42188726;

  //delx = 500.7922779;   //bin_HR5
  //dely = 499.63885791;
  //delz = 498.79440875;

  //delx = 491.44365517;   //bin_HR6
  //dely = 524.86976032;
  //delz = 504.56886557;

  //delx = 500.88344323;   //bin_HR7
  //dely = 499.58683015;
  //delz = 504.99209358;

  //delx = 506.01124135;   //bin_HR8
  //dely = 501.56161969;
  //delz = 503.11090611;

  //delx = 496.9606639;   //bin_HR9
  //dely = 497.98016741;
  //delz = 514.16669622;

  delx = 512.66315335;   //bin_HR10
  dely = 505.21955922;
  delz = 497.39292251;

  //delx = 512.70283548;   //bin_HR10 (for dma study)
  //dely = 505.23514735;
  //delz = 497.3872807;

  sprintf(input_fname, "%s/%s_%03d", path, basename, snapshot_number);
  //sprintf(output_fname, "/nobackupp1/astacy/hires_001a");
  //sprintf(output_fname, "/nobackupp1/astacy/bin_HR10_001");
  sprintf(output_fname, "/nobackupp1/astacy/bin_HRL10_001");
  //sprintf(output_fname, "/nobackupp1/astacy/dma2_001");
  Ngas = write_snapshot(input_fname, files, output_fname, delx, dely, delz, boxsize);

  unit_conversion();  

  ncount = 0;
  ncount2 = 0;

  printf("ncount = %d.\n", ncount);
  printf("ncount2 = %d.\n", ncount2);

  do_what_you_want();
}