testing/icgen/random_verschillende_resoluties_N-GenIC/gadget3_64/read_ic.c
int find_files(char *fname)
{
  FILE *fd;
  char buf[200], buf1[200];
  int dummy;

  sprintf(buf, "%s.%d", fname, 0);
  sprintf(buf1, "%s", fname);

  if(All.ICFormat == 3)
    {
      sprintf(buf, "%s.%d.hdf5", fname, 0);
      sprintf(buf1, "%s.hdf5", fname);
    }

#ifndef  HAVE_HDF5
  if(All.ICFormat == 3)
    {
      if(ThisTask == 0)
	printf("Code wasn't compiled with HDF5 support enabled!\n");
      endrun(0);
    }
#endif

  header.num_files = 0;

  if(ThisTask == 0)
    {
      if((fd = fopen(buf, "r")))
	{
	  if(All.ICFormat == 1 || All.ICFormat == 2)
	    {
	      if(All.ICFormat == 2)
		{
		  my_fread(&dummy, sizeof(dummy), 1, fd);
#ifdef AUTO_SWAP_ENDIAN_READIC
		  swap_file = dummy;
#endif
		  my_fread(&dummy, sizeof(dummy), 1, fd);
		  my_fread(&dummy, sizeof(dummy), 1, fd);
		  my_fread(&dummy, sizeof(dummy), 1, fd);
		}

	      my_fread(&dummy, sizeof(dummy), 1, fd);
#ifdef AUTO_SWAP_ENDIAN_READIC
	      if(All.SnapFormat == 1)
		{
		  if(dummy == 256)
		    swap_file = 8;
		  else
		    swap_file = dummy;
		}
#endif
	      my_fread(&header, sizeof(header), 1, fd);
#ifdef AUTO_SWAP_ENDIAN_READIC
	      swap_header();
#endif
	      my_fread(&dummy, sizeof(dummy), 1, fd);
	    }
	  fclose(fd);

#ifdef HAVE_HDF5
	  if(All.ICFormat == 3)
	    read_header_attributes_in_hdf5(buf);
#endif
	}
    }

#ifdef AUTO_SWAP_ENDIAN_READIC
  MPI_Bcast(&swap_file, sizeof(int), MPI_INT, 0, MPI_COMM_WORLD);
#endif
  MPI_Bcast(&header, sizeof(header), MPI_BYTE, 0, MPI_COMM_WORLD);

  if(header.num_files > 0)
    return header.num_files;

  if(ThisTask == 0)
    {
      if((fd = fopen(buf1, "r")))
	{
	  if(All.ICFormat == 1 || All.ICFormat == 2)
	    {
	      if(All.ICFormat == 2)
		{
		  my_fread(&dummy, sizeof(dummy), 1, fd);
#ifdef AUTO_SWAP_ENDIAN_READIC
		  swap_file = dummy;
#endif
		  my_fread(&dummy, sizeof(dummy), 1, fd);
		  my_fread(&dummy, sizeof(dummy), 1, fd);
		  my_fread(&dummy, sizeof(dummy), 1, fd);
		}

	      my_fread(&dummy, sizeof(dummy), 1, fd);
#ifdef AUTO_SWAP_ENDIAN_READIC
	      if(All.SnapFormat == 1)
		{
		  if(dummy == 256)
		    swap_file = 8;
		  else
		    swap_file = dummy;
		}
#endif
	      my_fread(&header, sizeof(header), 1, fd);
#ifdef AUTO_SWAP_ENDIAN_READIC
	      swap_header();
#endif
	      my_fread(&dummy, sizeof(dummy), 1, fd);
	    }
	  fclose(fd);

#ifdef HAVE_HDF5
	  if(All.ICFormat == 3)
	    read_header_attributes_in_hdf5(buf1);
#endif

	  header.num_files = 1;
	}
    }

#ifdef AUTO_SWAP_ENDIAN_READIC
  MPI_Bcast(&swap_file, sizeof(int), MPI_INT, 0, MPI_COMM_WORLD);
#endif
  MPI_Bcast(&header, sizeof(header), MPI_BYTE, 0, MPI_COMM_WORLD);

  if(header.num_files > 0)
    return header.num_files;

  if(ThisTask == 0)
    {
      printf("\nCan't find initial conditions file.");
      printf("neither as '%s'\nnor as '%s'\n", buf, buf1);
      fflush(stdout);
    }

  endrun(0);
  return 0;
}
/*! This function determines on how many files a given snapshot is distributed.
 */
This function determines on how many files a given snapshot is distributed.
This function determines on how many files a given snapshot is distributed .
int find_files(char *fname)
{
  FILE *fd;
  char buf[200], buf1[200];
  int dummy;
  sprintf(buf, "%s.%d", fname, 0);
  sprintf(buf1, "%s", fname);
  if(All.ICFormat == 3)
    {
      sprintf(buf, "%s.%d.hdf5", fname, 0);
      sprintf(buf1, "%s.hdf5", fname);
    }
#ifndef  HAVE_HDF5
  if(All.ICFormat == 3)
    {
      if(ThisTask == 0)
	printf("Code wasn't compiled with HDF5 support enabled!\n");
      endrun(0);
    }
#endif
  header.num_files = 0;
  if(ThisTask == 0)
    {
      if((fd = fopen(buf, "r")))
	{
	  if(All.ICFormat == 1 || All.ICFormat == 2)
	    {
	      if(All.ICFormat == 2)
		{
		  my_fread(&dummy, sizeof(dummy), 1, fd);
#ifdef AUTO_SWAP_ENDIAN_READIC
		  swap_file = dummy;
#endif
		  my_fread(&dummy, sizeof(dummy), 1, fd);
		  my_fread(&dummy, sizeof(dummy), 1, fd);
		  my_fread(&dummy, sizeof(dummy), 1, fd);
		}
	      my_fread(&dummy, sizeof(dummy), 1, fd);
#ifdef AUTO_SWAP_ENDIAN_READIC
	      if(All.SnapFormat == 1)
		{
		  if(dummy == 256)
		    swap_file = 8;
		  else
		    swap_file = dummy;
		}
#endif
	      my_fread(&header, sizeof(header), 1, fd);
#ifdef AUTO_SWAP_ENDIAN_READIC
	      swap_header();
#endif
	      my_fread(&dummy, sizeof(dummy), 1, fd);
	    }
	  fclose(fd);
#ifdef HAVE_HDF5
	  if(All.ICFormat == 3)
	    read_header_attributes_in_hdf5(buf);
#endif
	}
    }
#ifdef AUTO_SWAP_ENDIAN_READIC
  MPI_Bcast(&swap_file, sizeof(int), MPI_INT, 0, MPI_COMM_WORLD);
#endif
  MPI_Bcast(&header, sizeof(header), MPI_BYTE, 0, MPI_COMM_WORLD);
  if(header.num_files > 0)
    return header.num_files;
  if(ThisTask == 0)
    {
      if((fd = fopen(buf1, "r")))
	{
	  if(All.ICFormat == 1 || All.ICFormat == 2)
	    {
	      if(All.ICFormat == 2)
		{
		  my_fread(&dummy, sizeof(dummy), 1, fd);
#ifdef AUTO_SWAP_ENDIAN_READIC
		  swap_file = dummy;
#endif
		  my_fread(&dummy, sizeof(dummy), 1, fd);
		  my_fread(&dummy, sizeof(dummy), 1, fd);
		  my_fread(&dummy, sizeof(dummy), 1, fd);
		}
	      my_fread(&dummy, sizeof(dummy), 1, fd);
#ifdef AUTO_SWAP_ENDIAN_READIC
	      if(All.SnapFormat == 1)
		{
		  if(dummy == 256)
		    swap_file = 8;
		  else
		    swap_file = dummy;
		}
#endif
	      my_fread(&header, sizeof(header), 1, fd);
#ifdef AUTO_SWAP_ENDIAN_READIC
	      swap_header();
#endif
	      my_fread(&dummy, sizeof(dummy), 1, fd);
	    }
	  fclose(fd);
#ifdef HAVE_HDF5
	  if(All.ICFormat == 3)
	    read_header_attributes_in_hdf5(buf1);
#endif
	  header.num_files = 1;
	}
    }
#ifdef AUTO_SWAP_ENDIAN_READIC
  MPI_Bcast(&swap_file, sizeof(int), MPI_INT, 0, MPI_COMM_WORLD);
#endif
  MPI_Bcast(&header, sizeof(header), MPI_BYTE, 0, MPI_COMM_WORLD);
  if(header.num_files > 0)
    return header.num_files;
  if(ThisTask == 0)
    {
      printf("\nCan't find initial conditions file.");
      printf("neither as '%s'\nnor as '%s'\n", buf, buf1);
      fflush(stdout);
    }
  endrun(0);
  return 0;
}
int find_files ( char * fname ) { FILE * fd ; char buf [ 200 ] , buf1 [ 200 ] ; int dummy ; sprintf ( buf , " " , fname , 0 ) ; sprintf ( buf1 , " " , fname ) ; if ( All . ICFormat == 3 ) { sprintf ( buf , " " , fname , 0 ) ; sprintf ( buf1 , " " , fname ) ; } #ifndef HAVE_HDF5 if ( All . ICFormat == 3 ) { if ( ThisTask == 0 ) printf ( " \n " ) ; endrun ( 0 ) ; } #endif header . num_files = 0 ; if ( ThisTask == 0 ) { if ( ( fd = fopen ( buf , " " ) ) ) { if ( All . ICFormat == 1 || All . ICFormat == 2 ) { if ( All . ICFormat == 2 ) { my_fread ( & dummy , sizeof ( dummy ) , 1 , fd ) ; #ifdef AUTO_SWAP_ENDIAN_READIC swap_file = dummy ; #endif my_fread ( & dummy , sizeof ( dummy ) , 1 , fd ) ; my_fread ( & dummy , sizeof ( dummy ) , 1 , fd ) ; my_fread ( & dummy , sizeof ( dummy ) , 1 , fd ) ; } my_fread ( & dummy , sizeof ( dummy ) , 1 , fd ) ; #ifdef AUTO_SWAP_ENDIAN_READIC if ( All . SnapFormat == 1 ) { if ( dummy == 256 ) swap_file = 8 ; else swap_file = dummy ; } #endif my_fread ( & header , sizeof ( header ) , 1 , fd ) ; #ifdef AUTO_SWAP_ENDIAN_READIC swap_header ( ) ; #endif my_fread ( & dummy , sizeof ( dummy ) , 1 , fd ) ; } fclose ( fd ) ; #ifdef HAVE_HDF5 if ( All . ICFormat == 3 ) read_header_attributes_in_hdf5 ( buf ) ; #endif } } #ifdef AUTO_SWAP_ENDIAN_READIC MPI_Bcast ( & swap_file , sizeof ( int ) , MPI_INT , 0 , MPI_COMM_WORLD ) ; #endif MPI_Bcast ( & header , sizeof ( header ) , MPI_BYTE , 0 , MPI_COMM_WORLD ) ; if ( header . num_files > 0 ) return header . num_files ; if ( ThisTask == 0 ) { if ( ( fd = fopen ( buf1 , " " ) ) ) { if ( All . ICFormat == 1 || All . ICFormat == 2 ) { if ( All . ICFormat == 2 ) { my_fread ( & dummy , sizeof ( dummy ) , 1 , fd ) ; #ifdef AUTO_SWAP_ENDIAN_READIC swap_file = dummy ; #endif my_fread ( & dummy , sizeof ( dummy ) , 1 , fd ) ; my_fread ( & dummy , sizeof ( dummy ) , 1 , fd ) ; my_fread ( & dummy , sizeof ( dummy ) , 1 , fd ) ; } my_fread ( & dummy , sizeof ( dummy ) , 1 , fd ) ; #ifdef AUTO_SWAP_ENDIAN_READIC if ( All . SnapFormat == 1 ) { if ( dummy == 256 ) swap_file = 8 ; else swap_file = dummy ; } #endif my_fread ( & header , sizeof ( header ) , 1 , fd ) ; #ifdef AUTO_SWAP_ENDIAN_READIC swap_header ( ) ; #endif my_fread ( & dummy , sizeof ( dummy ) , 1 , fd ) ; } fclose ( fd ) ; #ifdef HAVE_HDF5 if ( All . ICFormat == 3 ) read_header_attributes_in_hdf5 ( buf1 ) ; #endif header . num_files = 1 ; } } #ifdef AUTO_SWAP_ENDIAN_READIC MPI_Bcast ( & swap_file , sizeof ( int ) , MPI_INT , 0 , MPI_COMM_WORLD ) ; #endif MPI_Bcast ( & header , sizeof ( header ) , MPI_BYTE , 0 , MPI_COMM_WORLD ) ; if ( header . num_files > 0 ) return header . num_files ; if ( ThisTask == 0 ) { printf ( " \n " ) ; printf ( " \n \n " , buf , buf1 ) ; fflush ( stdout ) ; } endrun ( 0 ) ; return 0 ; }
This function determines on how many files a given snapshot is distributed.
This function determines on how many files a given snapshot is distributed .