Ejemplo n.º 1
0
/*=============================================================================
 *                                   MAIN
 *=============================================================================*/
int read_snapshot(char *infile_name, int format, float **out_x, float **out_y, float **out_z, long *out_Np, float *out_mp, float *out_L, float *out_omega_0){
  char    gadget_file[MAXSTRING];
  int     no_gadget_files, i_gadget_file;
  FILE   *icfile;

  
  FORMAT       = format;
  
  #ifdef _KPC
  	GADGET_LUNIT = 1000.;
  #else
	GADGET_LUNIT=1.;
  #endif

  GADGET_MUNIT = 1.0e10;

  #ifdef _SWAPBYTES
  	SWAPBYTES    = 1;
  #else
	SWAPBYTES    =0;
  #endif


  #ifdef _LONGGADGET
  	LGADGET      = 1;
  #else
	LGADGET =0;
  #endif

  #ifdef _DOUBLEGADGET
  	DGADGET      = 1;
  #else
	DGADGET      = 0;
  #endif
  
  /*==================================
   * are there multiple GADGET files?
   *==================================*/
  if((icfile = fopen(infile_name,"rb")) == NULL)
   {
    /* maybe there are multiple GADGET files ... count them! */
    no_gadget_files = 0;
    i_gadget_file   = 0;
    sprintf(gadget_file,"%s.%d",infile_name,i_gadget_file);
    while((icfile = fopen(gadget_file,"rb")) != NULL)
     {
      fclose(icfile);
      no_gadget_files++;
      i_gadget_file++;
      sprintf(gadget_file,"%s.%d",infile_name,i_gadget_file);
     }

    if(no_gadget_files > 1)
     {
      fprintf(stderr,"\nreading GADGET data from %d files:\n",no_gadget_files);
      gadget.no_gadget_files  = no_gadget_files;
      
      /* allocate temporary storage for no. of particles arrays */
      gadget.np[0]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
      gadget.np[1]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
      gadget.np[2]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
      gadget.np[3]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
      gadget.np[4]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
      gadget.np[5]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
            
      /* read multi-GADGET files one by one */
      for(i_gadget_file=0; i_gadget_file<no_gadget_files; i_gadget_file++)
       {
        sprintf(gadget_file,"%s.%d",infile_name,i_gadget_file);
        fprintf(stderr,"\n===================================================================\n");
        fprintf(stderr,"=> reading %s\n\n",gadget_file);
        icfile = fopen(gadget_file,"rb");
        
        /* tell read_gadget() which file we are using at the moment */
        gadget.i_gadget_file = i_gadget_file;
        
        /* read files... */
        read_gadget(icfile,out_x,out_y,out_z);
        fclose(icfile);
       } 
      
      /* free temporary storage again */
      free(gadget.np[0]);
      free(gadget.np[1]);
      free(gadget.np[2]);
      free(gadget.np[3]);
      free(gadget.np[4]);
      free(gadget.np[5]);
     }
    else
     {
      /* there are no multi-GADGET files */
      fprintf(stderr,"\n\ninput: could not open file  %s\n",infile_name);
      fprintf(stderr,"Remember: if using multiple files, do not include the dot at the end of the filename.\n");
      exit(0);
     }
   }
  /*===============================
   * there is only one GADGET file
   *===============================*/
  else
   {
    gadget.no_gadget_files  = 1;
    gadget.i_gadget_file    = 0;
    
    /* allocate temporary storage for no. of particles arrays */
    gadget.np[0]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    gadget.np[1]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    gadget.np[2]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    gadget.np[3]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    gadget.np[4]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    gadget.np[5]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    
    read_gadget(icfile,out_x,out_y,out_z);
    fclose(icfile);
    
    /* remove temporary storage again */
    free(gadget.np[0]);
    free(gadget.np[1]);
    free(gadget.np[2]);
    free(gadget.np[3]);
    free(gadget.np[4]);
    free(gadget.np[5]);
   }
  
  
  /* check the range of the IDs of "halo" particles */
  #ifdef _DEBUG
  fprintf(stderr,"\nquick ID check:\n");
  fprintf(stderr,"   IDmin = %ld\n",IDmin);
  fprintf(stderr,"   IDmax = %ld\n",IDmax);
  fprintf(stderr,"   IDmax-IDmin = %ld  vs.  nall[1] = %d\n\n",IDmax-IDmin,gadget.header.nall[1]);
  #endif 
  

	*out_mp  = GADGET_MUNIT*gadget.header.massarr[1];
	*out_Np  = gadget.nall; 
	*out_L   = gadget.header.BoxSize;


	return 0;
  

  
}
Ejemplo n.º 2
0
/*=============================================================================
 *                                   MAIN
 *=============================================================================*/
int read_snapshot(char *infile_name, float lunit, float munit, int format, int swapbytes, int lgadget, int dgadget, float **out_x, float **out_y, float **out_z, long *out_Np, float *out_mp, float *out_L){
  char    gadget_file[MAXSTRING];
  int     no_gadget_files, i_gadget_file;
  FILE   *icfile;
  int     ipart;
  char outname[MAXSTRING];

  
  

  GADGET_LUNIT = (double) lunit;
  GADGET_MUNIT = (double) munit;
  FORMAT       = format;
  SWAPBYTES    = swapbytes;
  LGADGET      = lgadget;
  DGADGET      = dgadget;
  
  fprintf(stderr,"=====================================================\n");
  fprintf(stderr," read_gadget:\n\n");
  fprintf(stderr,"    infile = %s\n",infile_name);
  fprintf(stderr,"    lunit  = %g\n",GADGET_LUNIT);
  fprintf(stderr,"    munit  = %g\n",GADGET_MUNIT);
  fprintf(stderr,"    format = %d\n",FORMAT);
  fprintf(stderr,"    swap   = %d\n",SWAPBYTES);
  fprintf(stderr,"=====================================================\n");
  
  /*==================================
   * are there multiple GADGET files?
   *==================================*/
  if((icfile = fopen(infile_name,"rb")) == NULL)
   {
    /* maybe there are multiple GADGET files ... count them! */
    no_gadget_files = 0;
    i_gadget_file   = 0;
    sprintf(gadget_file,"%s.%d",infile_name,i_gadget_file);
    while((icfile = fopen(gadget_file,"rb")) != NULL)
     {
      fclose(icfile);
      no_gadget_files++;
      i_gadget_file++;
      sprintf(gadget_file,"%s.%d",infile_name,i_gadget_file);
     }

    if(no_gadget_files > 1)
     {
      fprintf(stderr,"\nreading GADGET data from %d files:\n",no_gadget_files);
      gadget.no_gadget_files  = no_gadget_files;
      
      /* allocate temporary storage for no. of particles arrays */
      gadget.np[0]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
      gadget.np[1]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
      gadget.np[2]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
      gadget.np[3]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
      gadget.np[4]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
      gadget.np[5]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
            
      /* read multi-GADGET files one by one */
      for(i_gadget_file=0; i_gadget_file<no_gadget_files; i_gadget_file++)
       {
        sprintf(gadget_file,"%s.%d",infile_name,i_gadget_file);
        fprintf(stderr,"\n===================================================================\n");
        fprintf(stderr,"=> reading %s\n\n",gadget_file);
        icfile = fopen(gadget_file,"rb");
        
        /* tell read_gadget() which file we are using at the moment */
        gadget.i_gadget_file = i_gadget_file;
        
        /* read files... */
        read_gadget(icfile);
        fclose(icfile);
       } 
      
      /* free temporary storage again */
      free(gadget.np[0]);
      free(gadget.np[1]);
      free(gadget.np[2]);
      free(gadget.np[3]);
      free(gadget.np[4]);
      free(gadget.np[5]);
     }
    else
     {
      /* there are no multi-GADGET files */
      fprintf(stderr,"\n\ninput: could not open file with IC's  %s\n",infile_name);
      exit(0);
     }
   }
  /*===============================
   * there is only one GADGET file
   *===============================*/
  else
   {
    gadget.no_gadget_files  = 1;
    gadget.i_gadget_file    = 0;
    
    /* allocate temporary storage for no. of particles arrays */
    gadget.np[0]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    gadget.np[1]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    gadget.np[2]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    gadget.np[3]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    gadget.np[4]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    gadget.np[5]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    
    read_gadget(icfile);
    fclose(icfile);
    
    /* remove temporary storage again */
    free(gadget.np[0]);
    free(gadget.np[1]);
    free(gadget.np[2]);
    free(gadget.np[3]);
    free(gadget.np[4]);
    free(gadget.np[5]);
   }
  
  
  /* check the range of the IDs of "halo" particles */
  fprintf(stderr,"\nquick ID check:\n");
  fprintf(stderr,"   IDmin = %ld\n",IDmin);
  fprintf(stderr,"   IDmax = %ld\n",IDmax);
  fprintf(stderr,"   IDmax-IDmin = %ld  vs.  nall[1] = %d\n\n",IDmax-IDmin,gadget.header.nall[1]);
  //exit(0);
  

	*out_mp  = GADGET_MUNIT*gadget.header.massarr[1];
	*out_Np  = gadget.nall; 
	*out_L   = gadget.header.BoxSize;
	(*out_x) = (float *) calloc(*out_Np,sizeof(float)); 
	(*out_y) = (float *) calloc(*out_Np,sizeof(float)); 
	(*out_z) = (float *) calloc(*out_Np,sizeof(float)); 

	long i;
	for (i=0; i<gadget.nall; i++){
		(*out_x)[i]=Part[i].Pos[X];
		(*out_y)[i]=Part[i].Pos[Y];
		(*out_z)[i]=Part[i].Pos[Z];
	}


	return 0;
  

  
}
Ejemplo n.º 3
0
/*=============================================================================
 *                                   MAIN
 *=============================================================================*/
int read_snapshot(char *infile_name, int format, float lunit, float munit, int swp, int glong, int gdouble, float **out_x, float **out_y, float **out_z, long *out_Np, float *out_mp, float *out_L, float *out_omega_0){
  char    gadget_file[MAXSTRING];
  int     no_gadget_files, i_gadget_file;
  FILE   *icfile;

  
  FORMAT       = format;
  GADGET_LUNIT = lunit;
  GADGET_MUNIT = munit;
  SWAPBYTES    = swp;
  LGADGET      = glong;
  DGADGET      = gdouble;

  
  /*==================================
   * are there multiple GADGET files?
   *==================================*/
  if((icfile = fopen(infile_name,"rb")) == NULL)
   {
    /* maybe there are multiple GADGET files ... count them! */
    no_gadget_files = 0;
    i_gadget_file   = 0;
    sprintf(gadget_file,"%s.%d",infile_name,i_gadget_file);
    while((icfile = fopen(gadget_file,"rb")) != NULL)
     {
      fclose(icfile);
      no_gadget_files++;
      i_gadget_file++;
      sprintf(gadget_file,"%s.%d",infile_name,i_gadget_file);
     }

    if(no_gadget_files > 1)
     {
      fprintf(stderr,"\n\treading GADGET data from %d files:\n",no_gadget_files);
      gadget.no_gadget_files  = no_gadget_files;
      
      /* allocate temporary storage for no. of particles arrays */
      gadget.np[0]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
      gadget.np[1]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
      gadget.np[2]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
      gadget.np[3]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
      gadget.np[4]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
      gadget.np[5]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
            
      /* read multi-GADGET files one by one */
      //#pragma omp parallel for private(i_gadget_file,icfile,gadget_file) shared(no_gadget_files,gadget,infile_name,stderr,out_x,out_y,out_z) default(none)
      for(i_gadget_file=0; i_gadget_file<no_gadget_files; i_gadget_file++)
       {
        sprintf(gadget_file,"%s.%d",infile_name,i_gadget_file);
        fprintf(stderr,"\n\t===================================================================\n");
        fprintf(stderr,"\t=> reading %s\n\n",gadget_file);
        icfile = fopen(gadget_file,"rb");
        
        /* tell read_gadget() which file we are using at the moment */
        gadget.i_gadget_file = i_gadget_file;
        
        /* read files... */
        read_gadget(icfile,out_x,out_y,out_z);
        fclose(icfile);
       } 
      
      /* free temporary storage again */
      free(gadget.np[0]);
      free(gadget.np[1]);
      free(gadget.np[2]);
      free(gadget.np[3]);
      free(gadget.np[4]);
      free(gadget.np[5]);
     }
    else
     {
      /* there are no multi-GADGET files */
      fprintf(stderr,"\n\ninput: could not open file  %s\n",infile_name);
      fprintf(stderr,"Remember: if using multiple files, do not include the dot at the end of the filename.\n");
      exit(0);
     }
   }
  /*===============================
   * there is only one GADGET file
   *===============================*/
  else
   {
    gadget.no_gadget_files  = 1;
    gadget.i_gadget_file    = 0;
    
    /* allocate temporary storage for no. of particles arrays */
    gadget.np[0]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    gadget.np[1]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    gadget.np[2]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    gadget.np[3]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    gadget.np[4]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    gadget.np[5]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    
    read_gadget(icfile,out_x,out_y,out_z);
    fclose(icfile);
    
    /* remove temporary storage again */
    free(gadget.np[0]);
    free(gadget.np[1]);
    free(gadget.np[2]);
    free(gadget.np[3]);
    free(gadget.np[4]);
    free(gadget.np[5]);
   }
  
  
 
	*out_mp  = GADGET_MUNIT*gadget.header.massarr[1];
	*out_Np  = gadget.nall; 
	*out_L   = gadget.header.BoxSize;


	return 0;
  

  
}
Ejemplo n.º 4
0
int read_positions_file(char *fname, float ***p, int ThisTask) {
  int i,np = 0;
  float rmin[3],rmax[3],rmin_tot,rmax_tot;

  /* Read position file based on file format on process 0 */
  printf("Thread %03d: -----------------------------\n",ThisTask);
  printf("Thread %03d: Reading in position file...\n",ThisTask);
  if (All.PositionFileFormat == 0) {
    np = read_unfbi77(fname,p,All.DecimateInputBy,ThisTask);
  } else if (All.PositionFileFormat == 1) {
    np = read_gadget(fname,p,All.DecimateInputBy,All.ParticleType,ThisTask);
  } else if (All.PositionFileFormat == 2) {
    np = read_bgtreebi(fname,p,All.DecimateInputBy,All.BgTreebiNskip,ThisTask);
  } else if (All.PositionFileFormat == 3) {
    np = read_bgc2(fname,p,All.DecimateInputBy,All.Bgc2HaloId,ThisTask);
  } else if (All.PositionFileFormat == 4) {
    np = read_tipsy(fname,p,All.DecimateInputBy,All.ParticleType,ThisTask);
  } else {
    printf("Thread %03d: Invalid PositionFileFormat = %d.\n",ThisTask,All.PositionFileFormat);
    np = -2;
  }
  if (np > 0) {
    printf("Thread %03d: %d particles read from file\n",ThisTask,np);
    /* for (i=0; i<3; i++) { */
    /*   printf("Thread %03d: test1 %d %+4.2f %+4.2f %+4.2f\n",ThisTask,i,(*p)[i][0],(*p)[i][1],(*p)[i][2]); */
    /*   printf("Thread %03d: test2 %d %+4.2f %+4.2f %+4.2f\n",ThisTask,i,*(*((*p)+i)+0),*(*((*p)+i)+1),*(*((*p)+i)+2)); */
    /*   printf("\n"); */
    /* } */
    printf("Thread %03d: -----------------------------\n\n",ThisTask);
    fflush(stdout);
    
    /* Get minimum & maximum */
    printf("Thread %03d: -----------------------------\n",ThisTask);
    printf("Thread %03d: Scaling positions to unit box...\n",ThisTask);
    DL { rmin[d] = BF; rmax[d] = -BF; }
    for (i=0; i<np; i++) {
      DL {
	if ((*p)[i][d] < rmin[d]) rmin[d] = (*p)[i][d];
	if ((*p)[i][d] > rmax[d]) rmax[d] = (*p)[i][d];
      }
    }
    printf("Thread %03d: Raw positions:\n",ThisTask);
    printf("Thread %03d:     xmin=%+4.2f ymin=%+4.2f zmin=%+4.2f\n",
	   ThisTask,rmin[0],rmin[1],rmin[2]);
    printf("Thread %03d:     xmax=%+4.2f ymax=%+4.2f zmax=%+4.2f\n",
	   ThisTask,rmax[0],rmax[1],rmax[2]);

    /* Squish in some direction */
    if ((All.SquishY != 1) || (All.SquishZ != 1)) {
      DL { rmin[d] = BF; rmax[d] = -BF; }
      for (i=0; i<np; i++) {
	printf("SquishY: %f\n",All.SquishY);
	printf("SquishZ: %f\n",All.SquishZ);
	(*p)[i][1] *= All.SquishY;
	(*p)[i][2] *= All.SquishZ;
	DL {
	  (*p)[i][d] *= pow(All.SquishY*All.SquishZ,-1./3.);
	  if ((*p)[i][d] < rmin[d]) rmin[d] = (*p)[i][d];
	  if ((*p)[i][d] > rmax[d]) rmax[d] = (*p)[i][d];
	}
      }
      printf("Thread %03d: Squished positions:\n",ThisTask);
      printf("Thread %03d:     xmin=%+4.2f ymin=%+4.2f zmin=%+4.2f\n",
	     ThisTask,rmin[0],rmin[1],rmin[2]);
      printf("Thread %03d:     xmax=%+4.2f ymax=%+4.2f zmax=%+4.2f\n",
	     ThisTask,rmax[0],rmax[1],rmax[2]);
    }
Ejemplo n.º 5
0
/*=============================================================================
 *                                   MAIN
 *=============================================================================*/
int read_snapshot(char *infile_name, int format, float lunit, float munit, int swp, int glong, int gdouble, int NCells, float **out_x, float **out_y, float **out_z, float **out_vx, float **out_vy, float **out_vz,long *out_Np, float *out_mp, float *out_L, float *out_omega_0,long **ListOfPart,long *NPartPerCell){
  char    gadget_file[MAXSTRING];
  int     no_gadget_files, i_gadget_file;
  long  ipart=0,ii,i,j,k,lin_ijk;
  FILE   *icfile;
  long   *PartPerFile;
  double invL;
  long *count;
  time_t t0,t1;
  float diff;

  float **file_x, **file_y, **file_z, **file_vx,**file_vy,**file_vz; 

  FORMAT       = format;
  GADGET_LUNIT = lunit;
  GADGET_MUNIT = munit;
  SWAPBYTES    = swp;
  LGADGET      = glong;
  DGADGET      = gdouble;

  
  /*==================================
   * are there multiple GADGET files?
   *==================================*/
  if((icfile = fopen(infile_name,"rb")) == NULL)
   {
    /* maybe there are multiple GADGET files ... count them! */
    no_gadget_files = 0;
    i_gadget_file   = 0;
    sprintf(gadget_file,"%s.%d",infile_name,i_gadget_file);
    while((icfile = fopen(gadget_file,"rb")) != NULL)
     {
      fclose(icfile);
      no_gadget_files++;
      i_gadget_file++;
      sprintf(gadget_file,"%s.%d",infile_name,i_gadget_file);
     }
	t0=time(NULL);

    if(no_gadget_files > 1)
     {
      fprintf(stderr,"\n\treading GADGET data from %d files:\n",no_gadget_files);
      gadget.no_gadget_files  = no_gadget_files;
      if(!((PartPerFile)=(long *) calloc(no_gadget_files, sizeof(long))))
      {
        fprintf(stderr,"\nfailed to allocate memory for GADGET data\n");
        exit(1);
      }
      if(!((file_x)=(float **) calloc(no_gadget_files, sizeof(float *))))
      {
        fprintf(stderr,"\nfailed to allocate memory for GADGET data\n");
        exit(1);
      }
      if(!((file_y)=(float **) calloc(no_gadget_files, sizeof(float *))))
      {
        fprintf(stderr,"\nfailed to allocate memory for GADGET data\n");
        exit(1);
      }
      if(!((file_z)=(float **) calloc(no_gadget_files, sizeof(float *))))
      {
        fprintf(stderr,"\nfailed to allocate memory for GADGET data\n");
        exit(1);
      }
      if(!((file_vx)=(float **) calloc(no_gadget_files, sizeof(float *))))
      {
        fprintf(stderr,"\nfailed to allocate memory for GADGET data\n");
        exit(1);
      }
      if(!((file_vy)=(float **) calloc(no_gadget_files, sizeof(float *))))
      {
        fprintf(stderr,"\nfailed to allocate memory for GADGET data\n");
        exit(1);
      }
      if(!((file_vz)=(float **) calloc(no_gadget_files, sizeof(float *))))
      {
        fprintf(stderr,"\nfailed to allocate memory for GADGET data\n");
        exit(1);
      }
      
      /* allocate temporary storage for no. of particles arrays */
      gadget.np[0]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
      gadget.np[1]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
      gadget.np[2]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
      gadget.np[3]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
      gadget.np[4]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
      gadget.np[5]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
   

    
      /* read multi-GADGET files one by one */


      #ifndef NO_READ_PARALLEL
      #pragma omp parallel for private(i_gadget_file,icfile,gadget_file) shared(no_gadget_files,gadget,infile_name,stderr,file_x,file_y,file_z,file_vx,file_vy,file_vz,PartPerFile) default(none)
      #endif
      for(i_gadget_file=0; i_gadget_file<no_gadget_files; i_gadget_file++)
       {
        sprintf(gadget_file,"%s.%d",infile_name,i_gadget_file);
        fprintf(stderr,"\n\t===================================================================\n");
        fprintf(stderr,"\t=> reading %s\n\n",gadget_file);
        icfile = fopen(gadget_file,"rb");
        
        /* tell read_gadget() which file we are using at the moment */
        gadget.i_gadget_file = i_gadget_file;
        
        /* read files... */
        PartPerFile[i_gadget_file] = read_gadget(icfile,&file_x,&file_y,&file_z,&file_vx,&file_vy,&file_vz,i_gadget_file);
        fclose(icfile);
        fprintf(stderr,"\tDone with %s\n\n",gadget_file);
       } 
      
      /* free temporary storage again */
      free(gadget.np[0]);
      free(gadget.np[1]);
      free(gadget.np[2]);
      free(gadget.np[3]);
      free(gadget.np[4]);
      free(gadget.np[5]);
        fprintf(stderr,"\tEnd of parallel reading\n");
     }
    else
     {
      /* there are no multi-GADGET files */
      fprintf(stderr,"\n\ninput: could not open file  %s\n",infile_name);
      fprintf(stderr,"Remember: if using multiple files, do not include the dot at the end of the filename.\n");
      exit(0);
     }
   }
  /*===============================
   * there is only one GADGET file
   *===============================*/
  else
   {
    gadget.no_gadget_files  = 1;
    no_gadget_files  = 1;
    i_gadget_file    = 0;
      if(!((PartPerFile)=(long *) calloc(no_gadget_files, sizeof(long))))
      {
        fprintf(stderr,"\nfailed to allocate memory for GADGET data\n");
        exit(1);
      }
      if(!((file_x)=(float **) calloc(no_gadget_files, sizeof(float *))))
      {
        fprintf(stderr,"\nfailed to allocate memory for GADGET data\n");
        exit(1);
      }
      if(!((file_y)=(float **) calloc(no_gadget_files, sizeof(float *))))
      {
        fprintf(stderr,"\nfailed to allocate memory for GADGET data\n");
        exit(1);
      }
      if(!((file_z)=(float **) calloc(no_gadget_files, sizeof(float *))))
      {
        fprintf(stderr,"\nfailed to allocate memory for GADGET data\n");
        exit(1);
      }
      if(!((file_vx)=(float **) calloc(no_gadget_files, sizeof(float *))))
      {
        fprintf(stderr,"\nfailed to allocate memory for GADGET data\n");
        exit(1);
      }
      if(!((file_vy)=(float **) calloc(no_gadget_files, sizeof(float *))))
      {
        fprintf(stderr,"\nfailed to allocate memory for GADGET data\n");
        exit(1);
      }
      if(!((file_vz)=(float **) calloc(no_gadget_files, sizeof(float *))))
      {
        fprintf(stderr,"\nfailed to allocate memory for GADGET data\n");
        exit(1);
      }
    
    /* allocate temporary storage for no. of particles arrays */
    gadget.np[0]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    gadget.np[1]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    gadget.np[2]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    gadget.np[3]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    gadget.np[4]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));
    gadget.np[5]     = (long *) calloc(gadget.no_gadget_files, sizeof(long *));

    PartPerFile[i_gadget_file] = read_gadget(icfile,&file_x,&file_y,&file_z,&file_vx,&file_vy,&file_vz,0);
    fclose(icfile);
    
    /* remove temporary storage again */
    free(gadget.np[0]);
    free(gadget.np[1]);
    free(gadget.np[2]);
    free(gadget.np[3]);
    free(gadget.np[4]);
    free(gadget.np[5]);
   }
	t1=time(NULL);
        diff = difftime(t1,t0);
        fprintf(stderr,"\tTime in actual reading: %f\n",diff);

	//Distribute Particles
       /* ListOfPart = (long **) calloc(NCells*NCells*NCells,sizeof(long *));
        if( ListOfPart == NULL) {
                fprintf(stderr,"\tplace_halos(): could not allocate %d array for NPartPerCell[]\nABORTING",NCells*NCells*NCells);
                exit(-1);
        }
        (NPartPerCell) = (long *) calloc(NCells*NCells*NCells,sizeof(long));
        if( NPartPerCell == NULL) {
                fprintf(stderr,"\tplace_halos(): could not allocate %d array for NPartPerCell[]\nABORTING",NCells*NCells*NCells);
                exit(-1);
        }*/
	count = (long *) calloc(NCells*NCells*NCells,sizeof(long));
        if( count == NULL) {
                fprintf(stderr,"\tplace_halos(): could not allocate %d array for NPartPerCell[]\nABORTING",NCells*NCells*NCells);
                exit(-1);
        }
        fprintf(stderr,"\t Counters allocated \n\n");
	ipart=0;
	invL = 1.0/gadget.header.BoxSize;
	//Counting Particles in cells
      	for(i_gadget_file=0; i_gadget_file<no_gadget_files; i_gadget_file++)
        for (ii=0;ii<PartPerFile[i_gadget_file];ii++) {

                if (file_x[i_gadget_file][ii]==gadget.header.BoxSize)
                        file_x[i_gadget_file][ii]=0.;
                if (file_y[i_gadget_file][ii]==gadget.header.BoxSize)
                        file_y[i_gadget_file][ii]=0.;
                if (file_z[i_gadget_file][ii]==gadget.header.BoxSize)
                        file_z[i_gadget_file][ii]=0.;
                i = (long) (invL * file_x[i_gadget_file][ii]*NCells);
                j = (long) (invL * file_y[i_gadget_file][ii]*NCells);
                k = (long) (invL * file_z[i_gadget_file][ii]*NCells);
                if (i<0 || i>=NCells || j<0 || j>=NCells || k<0 || k>=NCells){
                        fprintf(stderr,"\tERROR: Particle %ld at [%f,%f,%f] seems to be out of the right box interval [0.,%f)",ipart,file_x[i_gadget_file][ii],file_y[i_gadget_file][ii],file_z[i_gadget_file][ii],gadget.header.BoxSize);
                }

                lin_ijk = k+j*NCells+i*NCells*NCells;
                (NPartPerCell)[lin_ijk]++;
		ipart++;
        }
        fprintf(stderr,"\t Particles Counted \n\n");

	//Alloccing memory for particle
        for (i=0;i<NCells;i++){
        for (j=0;j<NCells;j++){
        for (k=0;k<NCells;k++){
                lin_ijk = k+j*NCells+i*NCells*NCells;
		//fprintf(stderr,"lin_ijk=%d\n",lin_ijk);
                (ListOfPart)[lin_ijk] = (long *) calloc((NPartPerCell)[lin_ijk],sizeof(long));
        }
        }
        }
        fprintf(stderr,"\t Grid allocated \n\n");
	(*out_x) = (float *) calloc(ipart,sizeof(double));
	(*out_y) = (float *) calloc(ipart,sizeof(double));
	(*out_z) = (float *) calloc(ipart,sizeof(double));
	(*out_vx) = (float *) calloc(ipart,sizeof(double));
	(*out_vy) = (float *) calloc(ipart,sizeof(double));
	(*out_vz) = (float *) calloc(ipart,sizeof(double));
        fprintf(stderr,"\t vector allocated \n\n");
	ipart=0;
	//Distributing Particles
        //#pragma omp parallel for private(i_gadget_file,ipart,i,k,j,lin_ijk,ii) shared(PartPerFile,invL,NCells,ListOfPart,count,out_x,out_z,out_y,out_vx,out_vz,out_vy,file_x,file_y,file_z,file_vx,file_vy,file_vz,stderr,gadget,no_gadget_files) default(none)
      	for(i_gadget_file=0; i_gadget_file<no_gadget_files; i_gadget_file++)
        for (ii=0;ii<PartPerFile[i_gadget_file];ii++) {
                i = (long) (invL * file_x[i_gadget_file][ii]*NCells);
                j = (long) (invL * file_y[i_gadget_file][ii]*NCells);
                k = (long) (invL * file_z[i_gadget_file][ii]*NCells);
                if (i<0 || i>=NCells || j<0 || j>=NCells || k<0 || k>=NCells){
                        fprintf(stderr,"\tERROR: Particle %ld at [%f,%f,%f] seems to be out of the right box interval [0.,%f)",ipart,file_x[i_gadget_file][ii],file_y[i_gadget_file][ii],file_z[i_gadget_file][ii],gadget.header.BoxSize);
                }
		(*out_x)[ipart] = file_x[i_gadget_file][ii];
		(*out_y)[ipart] = file_y[i_gadget_file][ii];
		(*out_z)[ipart] = file_z[i_gadget_file][ii];
		(*out_vx)[ipart] = file_vx[i_gadget_file][ii];
		(*out_vy)[ipart] = file_vy[i_gadget_file][ii];
		(*out_vz)[ipart] = file_vz[i_gadget_file][ii];
                lin_ijk = k+j*NCells+i*NCells*NCells;
                (ListOfPart)[lin_ijk][count[lin_ijk]] = ipart;
                count[lin_ijk]++;
		ipart++;
        }

        fprintf(stderr,"\t Particles Distributed \n\n");
  
 
	*out_mp  = GADGET_MUNIT*gadget.header.massarr[1];
	*out_Np  = gadget.nall; 
	*out_L   = gadget.header.BoxSize;


        fprintf(stderr,"N[0]=%ld, N[1]=%ld, N[2]=%ld, \n",NPartPerCell[0],NPartPerCell[1],NPartPerCell[2]); 


	return 0;
  

  
}
Ejemplo n.º 6
0
int main(int argc, char **argv) {

    if (argc == 2)
        myreadini(argv[1]);
    else {
        std::cout << "Usage:\n " << argv[0] << " param.xml" << std::endl;
        exit(0);
    }
    // Read and check command line parameters.
    //	cimg_usage("Compute a HOP over the particles with given Est and Rho files");
    //	const char *file_ascii = cimg_option("-ascii_file",(char*)0,"Input in Ascii format");
    //	const char *file_gadget2;
    //	if( SMALL_TEST)
    //		file_gadget2= cimg_option("-gadget2_file","C:\\arm2arm\\DATA\\MODEL7\\MODELS\\MODEL7\\RUNG2\\SNAPS\\test_0450","Input in Gadget-2 format");
    //	else
    //		file_gadget2= cimg_option("-gadget2_file","C:\\arm2arm\\DATA\\MODEL7\\MODELS\\MODEL7\\RUNG2\\SNAPS\\snap_gal_sfr_0450","Input in Gadget-2 format");
    //	const char *file_base  = cimg_option("-base4files","C:/arm2arm/DATA/MODEL7/MST_GRAPH/","Base for input and output");
    //	const char *HOP_file  = cimg_option("-hopfile","hop_0450","HOP algorithm output,eg: groups and their IDs.");
    /*	const bool visu     = cimg_option("-visu",true,"Visualization mode");
            const int shape  = cimg_option("-s",1,"shape [0,6]");
            const int profile  = cimg_option("-p",0,"profile [0,7]");
     */
    ////////////////////////////////////////////////////////////////////
    int iMcount = pset.get_ModelCount();
    if (iMcount == 0) {
        std::cout << "No Models defined in the " << argv[1] << std::endl;
        exit(0);
    }
    int imodel = 0;
    int isnap = 0;
    string hopfile = pset.get_HOPfile(isnap, imodel);

    read_gadget(pset.get_SNAPfile(isnap, imodel));
    ///

    ////////////////////////////////////////////////
    /// Smooth Est with 64 Ngb
       GetEst est_me;
       //est_me.makeMSTreeForPaper() ;
    est_me.Run_SPHEst();
     exit(0);
    //SmoothSph();
    /////////////////////// GET setAB This is the HOP stuff based on Enbid Density  one can test also for RHO by SPH//////////////////////////////////////
    //exit(0);
    MyFloat alpha = 0.05;
    CHOP *hop = new CHOP(alpha, MIN_NGRP);

    int seeds = hop->get_seeds();
    cout << "We got " << seeds << " seeds out of " << All.NumPart << endl;


    hop->write_catalogues(hopfile);

    ///////////////////////////////////////////////////////////////
    // Here we need to cut and store the catalogues
    ///////////////////////////////////////////////////////


    ////////////////////////////////
    return EXIT_SUCCESS;
}