Пример #1
0
void repository::builder::build(const entry &package) {
  try {
    BUNSAN_LOG_DEBUG << "Starting \"" << package << "\" " << __func__;
    const tempfile build_dir_ = local_system_().tempdir_for_build();
    const boost::filesystem::path build_dir = build_dir_.path();
    const boost::filesystem::path src =
        build_dir / m_config.name.dir.get_source();
    const boost::filesystem::path build =
        build_dir / m_config.name.dir.get_build();
    const boost::filesystem::path installation =
        build_dir / m_config.name.dir.get_installation();
    // create/clean directories
    boost::filesystem::create_directory(src);
    boost::filesystem::create_directory(build);
    boost::filesystem::create_directory(installation);
    // unpack source
    snapshot snapshot_;
    unpack_source(package, src, snapshot_);
    get_builder()->install(build_dir / m_config.name.dir.get_source(),
                           build_dir / m_config.name.dir.get_build(),
                           build_dir / m_config.name.dir.get_installation());
    cache_().pack_build(package,
                        build_dir / m_config.name.dir.get_installation());
    write_snapshot(cache_().build_snapshot_path(package), snapshot_);
  } catch (std::exception &) {
    BOOST_THROW_EXCEPTION(builder_build_error()
                          << builder_build_error::package(package)
                          << enable_nested_current());
  }
}
Пример #2
0
void repository::builder::build_installation(const entry &package) {
  try {
    BUNSAN_LOG_DEBUG << "Starting \"" << package << "\" " << __func__;
    const tempfile build_dir = local_system_().tempdir_for_build();
    boost::filesystem::path install_dir =
        build_dir.path() / m_config.name.dir.get_installation();
    // unpack
    extractor_().extract_build(package, install_dir);
    snapshot snapshot_ = cache_().read_build_snapshot(package);
    const index deps = cache_().read_index(package);
    for (const auto &i : deps.package.self)
      extractor_().extract_source(package, i.source, install_dir / i.path);
    for (const auto &i : deps.package.import.source)
      unpack_source(i.package, install_dir / i.path, snapshot_);
    for (const auto &i : deps.package.import.package) {
      extractor_().extract_installation(i.package, install_dir / i.path);
      merge_maps(snapshot_, cache_().read_installation_snapshot(i.package));
    }
    // save
    cache_().pack_installation(package, install_dir);
    write_snapshot(cache_().installation_snapshot_path(package), snapshot_);
  } catch (std::exception &) {
    BOOST_THROW_EXCEPTION(builder_build_installation_error()
                          << builder_build_installation_error::package(package)
                          << enable_nested_current());
  }
}
Пример #3
0
void out_result(void)
{
    string out;

    if (outstr==NULL) {
        out = getparam("out");
	outstr = stropen(out, "w");
	put_history(outstr);
    }
    write_snapshot();			/* output testdata results */
}
Пример #4
0
int main(int argc, char * argv [])
{
  const int n = argc > 1 ? atoi(argv[1]) : 1000000;
  fprintf(stderr,  " -- writing %d particles -- \n", n);
  assert(n > 16);

  MPI_Init(&argc, &argv);
  int rank, nrank;
  MPI_Comm_rank (MPI_COMM_WORLD, &rank); 
  MPI_Comm_size (MPI_COMM_WORLD, &nrank);

  const MPI_Comm MPI_WORKING_WORLD = MPI_COMM_WORLD;

  std::vector<real4> pos(n), vel(n);
  std::vector<int> IDs(n);

  for (int i = 0; i < n ; i++)
  {
    const float fi = i;
    pos[i] = (real4){     fi,      fi+1.0f,      fi-1.0f,      -fi-1.0f};
    vel[i] = (real4){2.0f*fi, 2.0f*fi+1.0f, 2.0f*fi-1.0f, -2.0f*fi-1.0f};
    IDs[i] = 3*i-2;
  }

  const float time = 0.125;

  std::string fileName; fileName.resize(256);
  MPI_Barrier(MPI_WORKING_WORLD);
  const double t0 = rtc();

#ifndef _SION_
  sprintf(&fileName[0], "%s_%010.4f-%d", "naive_test", time, rank);
  const size_t nbytes = write_snapshot(
      &pos[0], &vel[0], &IDs[0], n, fileName, time,
      rank, nrank, MPI_WORKING_WORLD);
#else
  sprintf(&fileName[0], "%s_%010.4f-%d", "sion_test", time, nrank);
  const size_t nbytes = sion_write_snapshot(
      &pos[0], &vel[0], &IDs[0], n, fileName, time,
      rank, nrank, MPI_WORKING_WORLD);
#endif

  MPI_Barrier(MPI_WORKING_WORLD);
  const double t1 = rtc();

  if (rank == 0)
    fprintf(stderr, " -- writing took %g sec -- BW= %g MB/s\n",
        (t1-t0), nbytes/1e6/(t1-t0));


  MPI_Finalize();
}
Пример #5
0
void repository::builder::build_empty(const entry &package) {
  try {
    BUNSAN_LOG_DEBUG << "Starting \"" << package << "\" " << __func__;
    const tempfile build_dir = local_system_().tempdir_for_build();
    // create empty archive
    cache_().pack_build(package, build_dir.path());
    const snapshot snapshot_ = {{package, cache_().read_checksum(package)}};
    write_snapshot(cache_().build_snapshot_path(package), snapshot_);
  } catch (std::exception &) {
    BOOST_THROW_EXCEPTION(builder_build_empty_error()
                          << builder_build_empty_error::package(package)
                          << enable_nested_current());
  }
}
Пример #6
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  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);
}
}
Пример #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 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();
}
Пример #8
0
static void snapshot_save_callback(unsigned int opt) {
	const char *snap_exts[] = { "SN0", "SN1", "SN2", "SN3", "SN4",
		"SN5", "SN6", "SN7", "SN8", "SN9", NULL };
	int selected;
	Menu savemenu[2];
	char filename[13];
	(void)opt;  /* unused */
	if (save_basename == NULL) {
		notify_box("Unable to save snapshot");
		return;
	}
	memset(savemenu, 0, sizeof(savemenu));
	savemenu[0].label = save_basename;
	savemenu[0].num_opts = 10;
	savemenu[0].options = snap_exts;
	selected = show_menu(savemenu, 1, 9, 38, 1);
	if (selected < 0)
		return;
	strcpy(filename, save_basename);
	strcat(filename, ".");
	strcat(filename, snap_exts[selected]);
	write_snapshot(filename);
}
Пример #9
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();
}
Пример #10
0
static int
extract_snap( libspectrum_rzx *rzx, size_t where, const char *filename )
{
  libspectrum_rzx_iterator it;
  libspectrum_snap *snap;
  int e;

  it = get_block( rzx, where );
  if( !it ) {
    fprintf( stderr, "%s: not enough blocks in RZX file\n", progname );
    return 1;
  }

  snap = libspectrum_rzx_iterator_get_snap( it );
  if( !snap ) {
    fprintf( stderr, "%s: not a snapshot block\n", progname );
    return 1;
  }

  e = write_snapshot( snap, filename );
  if( e ) return e;
  
  return 0;
}
Пример #11
0
int
main(int argc, char *argv[])
{
  char         **av, *source_fname, *target_fname, *out_fname, fname[STRLEN] ;
  int          ac, nargs, new_transform = 0, pad ;
  MRI          *mri_target, *mri_source, *mri_orig_source ;
  MRI_REGION   box ;
  struct timeb start ;
  int          msec, minutes, seconds ;
  GCA_MORPH    *gcam ;
  MATRIX       *m_L/*, *m_I*/ ;
  LTA          *lta ;


  /* initialize the morph params */
  memset(&mp, 0, sizeof(GCA_MORPH_PARMS));
  /* for nonlinear morph */
  mp.l_jacobian = 1 ;
  mp.min_sigma = 0.4 ;
  mp.l_distance = 0 ;
  mp.l_log_likelihood = .025 ;
  mp.dt = 0.005 ;
  mp.noneg = True ;
  mp.exp_k = 20 ;
  mp.diag_write_snapshots = 1 ;
  mp.momentum = 0.9 ;
  if (FZERO(mp.l_smoothness))
    mp.l_smoothness = 2 ;
  mp.sigma = 8 ;
  mp.relabel_avgs = -1 ;
  mp.navgs = 256 ;
  mp.levels = 6 ;
  mp.integration_type = GCAM_INTEGRATE_BOTH ;
  mp.nsmall = 1 ;
  mp.reset_avgs = -1 ;
  mp.npasses = 3 ;
  mp.regrid = regrid? True : False ;
  mp.tol = 0.1 ;
  mp.niterations = 1000 ;
	
  TimerStart(&start) ;
  setRandomSeed(-1L) ;
  DiagInit(NULL, NULL, NULL) ;
  ErrorInit(NULL, NULL, NULL) ;

  Progname = argv[0] ;
  ac = argc ;
  av = argv ;
  for ( ; argc > 1 && ISOPTION(*argv[1]) ; argc--, argv++)
    {
      nargs = get_option(argc, argv) ;
      argc -= nargs ;
      argv += nargs ;
    }

  if (argc < 4)
    usage_exit(1) ;

  source_fname = argv[1] ;
  target_fname = argv[2] ;
  out_fname = argv[3] ;
  FileNameOnly(out_fname, fname) ;
  FileNameRemoveExtension(fname, fname) ;
  strcpy(mp.base_name, fname) ;
  mri_source = MRIread(source_fname) ;
  if (!mri_source)
    ErrorExit(ERROR_NOFILE, "%s: could not read source label volume %s",
	      Progname, source_fname) ;

  if (mri_source->type == MRI_INT)
    {
      MRI *mri_tmp = MRIchangeType(mri_source, MRI_FLOAT, 0, 1, 1) ;
      MRIfree(&mri_source); mri_source = mri_tmp ;
    }
  mri_target = MRIread(target_fname) ;
  if (!mri_target)
    ErrorExit(ERROR_NOFILE, "%s: could not read target label volume %s",
	      Progname, target_fname) ;
  if (mri_target->type == MRI_INT)
    {
      MRI *mri_tmp = MRIchangeType(mri_target, MRI_FLOAT, 0, 1, 1) ;
      MRIfree(&mri_target); mri_target = mri_tmp ;
    }
  if (erosions > 0)
    {
      int n ;
      for (n = 0 ; n < erosions ; n++)
	{
	  MRIerodeZero(mri_target, mri_target) ;
	  MRIerodeZero(mri_source, mri_source) ;
	}
    }
  if (scale_values > 0)
    {
      MRIscalarMul(mri_source, mri_source, scale_values) ;
      MRIscalarMul(mri_target, mri_target, scale_values) ;
    }
  if (transform && transform->type == MORPH_3D_TYPE)
    TransformRas2Vox(transform, mri_source,NULL) ;
  if (use_aseg == 0)
    {
      if (match_peak_intensity_ratio)
	MRImatchIntensityRatio(mri_source, mri_target, mri_source, .8, 1.2, 
			       100, 125) ;
      else if (match_mean_intensity)
	MRImatchMeanIntensity(mri_source, mri_target, mri_source) ;
      MRIboundingBox(mri_source, 0, &box) ;
      pad = (int)ceil(PADVOX * 
		      MAX(mri_target->xsize,MAX(mri_target->ysize,mri_target->zsize)) / 
		      MIN(mri_source->xsize,MIN(mri_source->ysize,mri_source->zsize))); 
#if 0
      { MRI *mri_tmp ;
	if (pad < 1)
	  pad = 1 ;
	printf("padding source with %d voxels...\n", pad) ;
	mri_tmp = MRIextractRegionAndPad(mri_source, NULL, &box, pad) ;
	if ((Gdiag & DIAG_WRITE) && DIAG_VERBOSE_ON)
	  MRIwrite(mri_tmp, "t.mgz") ;
	MRIfree(&mri_source) ;
	mri_source = mri_tmp ;
      }
#endif
    }
  mri_orig_source = MRIcopy(mri_source, NULL) ;

  mp.max_grad = 0.3*mri_source->xsize ;

  if (transform == NULL)
    transform = TransformAlloc(LINEAR_VOXEL_TO_VOXEL, NULL) ;

  if (transform->type != MORPH_3D_TYPE)  // initializing m3d from a linear transform
    {
      new_transform = 1 ;
      lta = ((LTA *)(transform->xform)) ;
      if (lta->type != LINEAR_VOX_TO_VOX)
	{
	  printf("converting ras xform to voxel xform\n") ;
	  m_L = MRIrasXformToVoxelXform(mri_source, mri_target, lta->xforms[0].m_L, NULL) ;
	  MatrixFree(&lta->xforms[0].m_L) ;
	  lta->type = LINEAR_VOX_TO_VOX ;
	}
      else
	{
	  printf("using voxel xform\n") ;
	  m_L = lta->xforms[0].m_L ;
	}
#if 0
      if (Gsx >= 0)   // update debugging coords
	{
	  VECTOR *v1, *v2 ;

	  v1 = VectorAlloc(4, MATRIX_REAL) ;
	  Gsx -= (box.x-pad) ;
	  Gsy -= (box.y-pad) ;
	  Gsz -= (box.z-pad) ;
	  V3_X(v1) = Gsx ; V3_Y(v1) = Gsy ; V3_Z(v1) = Gsz ;
	  VECTOR_ELT(v1,4) = 1.0 ;
	  v2 = MatrixMultiply(m_L, v1, NULL) ;
      
	  Gsx = nint(V3_X(v2)) ; Gsy = nint(V3_Y(v2)) ; Gsz = nint(V3_Z(v2)) ;
	  MatrixFree(&v2) ; MatrixFree(&v1) ;
	  printf("mapping by transform (%d, %d, %d) --> (%d, %d, %d) for rgb writing\n",
		 Gx, Gy, Gz, Gsx, Gsy, Gsz) ;
	}
#endif
      if (Gdiag & DIAG_WRITE && DIAG_VERBOSE_ON)
	write_snapshot(mri_target, mri_source, m_L, &mp, 0, 1, "linear_init");

      lta->xforms[0].m_L = m_L ;
      printf("initializing GCAM with vox->vox matrix:\n") ;
      MatrixPrint(stdout, m_L) ;
      gcam = GCAMcreateFromIntensityImage(mri_source, mri_target, transform) ;
#if 0
      gcam->gca = gcaAllocMax(1, 1, 1, 
			      mri_target->width, mri_target->height, 
			      mri_target->depth,
			      0, 0) ;
#endif
      GCAMinitVolGeom(gcam, mri_source, mri_target) ;
      if (use_aseg)
	{
	  if (ribbon_name)
	    {
	      char fname[STRLEN], path[STRLEN], *str, *hemi ;
	      int  h, s, label ;
	      MRI_SURFACE *mris_white, *mris_pial ;
	      MRI         *mri ;

	      for (s = 0 ; s <= 1 ; s++) // source and target
		{
		  if (s == 0)
		    {
		      str = source_surf ;
		      mri = mri_source ;
		      FileNamePath(mri->fname, path) ;
		      strcat(path, "/../surf") ;
		    }
		  else
		    {
		      mri = mri_target ;
		      FileNamePath(mri->fname, path) ;
		      strcat(path, "/../elastic") ;
		      str = target_surf ;
		    }
		  // sorry - these values come from FreeSurferColorLUT.txt
		  MRIreplaceValueRange(mri, mri, 1000, 1034, Left_Cerebral_Cortex) ;
		  MRIreplaceValueRange(mri, mri, 1100, 1180, Left_Cerebral_Cortex) ;
		  MRIreplaceValueRange(mri, mri, 2000, 2034, Right_Cerebral_Cortex) ;
		  MRIreplaceValueRange(mri, mri, 2100, 2180, Right_Cerebral_Cortex) ;
		  for (h = LEFT_HEMISPHERE ; h <= RIGHT_HEMISPHERE ; h++)  
		    {
		      if (h == LEFT_HEMISPHERE)
			{
			  hemi = "lh" ;
			  label = Left_Cerebral_Cortex ;
			}
		      else
			{
			  label = Right_Cerebral_Cortex ;
			  hemi = "rh" ;
			}
		      sprintf(fname, "%s/%s%s.white", path, hemi, str) ;
		      mris_white = MRISread(fname) ;
		      if (mris_white == NULL)
			ErrorExit(ERROR_NOFILE, "%s: could not read surface %s", Progname, fname) ;
		      MRISsaveVertexPositions(mris_white, WHITE_VERTICES) ;
		      sprintf(fname, "%s/%s%s.pial", path, hemi, str) ;
		      mris_pial = MRISread(fname) ;
		      if (mris_pial == NULL)
			ErrorExit(ERROR_NOFILE, "%s: could not read surface %s", Progname, fname) ;
		      MRISsaveVertexPositions(mris_pial, PIAL_VERTICES) ;
		      if (Gdiag & DIAG_WRITE && DIAG_VERBOSE_ON)
			{
			  sprintf(fname, "sb.mgz") ;
			  MRIwrite(mri_source, fname) ; 
			  sprintf(fname, "tb.mgz") ;
			  MRIwrite(mri_target, fname) ;
			}

		      insert_ribbon_into_aseg(mri, mri, mris_white, mris_pial, h) ;
		      if (Gdiag & DIAG_WRITE && DIAG_VERBOSE_ON)
			{
			  sprintf(fname, "sa.mgz") ;
			  MRIwrite(mri_source, fname) ; 
			  sprintf(fname, "ta.mgz") ;
			  MRIwrite(mri_target, fname) ;
			}
		      MRISfree(&mris_white) ; MRISfree(&mris_pial) ;
		    }
		}
	      if (Gdiag & DIAG_WRITE && DIAG_VERBOSE_ON)
		{
		  sprintf(fname, "s.mgz") ;
		  MRIwrite(mri_source, fname) ; 
		  sprintf(fname, "t.mgz") ;
		  MRIwrite(mri_target, fname) ;
		}
	    }
	  GCAMinitLabels(gcam, mri_target) ;
	  GCAMsetVariances(gcam, 1.0) ;
	  mp.mri_dist_map = create_distance_transforms(mri_source, mri_target, NULL, 40.0, gcam) ;
	}
    }
  else  /* use a previously create morph and integrate it some more */
    {
      printf("using previously create gcam...\n") ;
      gcam = (GCA_MORPH *)(transform->xform) ;
      GCAMrasToVox(gcam, mri_source) ;
      if (use_aseg)
	{
	  GCAMinitLabels(gcam, mri_target) ;
	  GCAMsetVariances(gcam, 1.0) ;
	  mp.mri_dist_map = create_distance_transforms(mri_source, mri_target, NULL, 40.0, gcam) ;
	}
      else
	GCAMaddIntensitiesFromImage(gcam, mri_target) ;
    }
  if (gcam->width != mri_source->width ||
      gcam->height != mri_source->height ||
      gcam->depth != mri_source->depth)
    ErrorExit(ERROR_BADPARM, "%s: warning gcam (%d, %d, %d), doesn't match source vol (%d, %d, %d)",
	      Progname, gcam->width, gcam->height, gcam->depth,
	      mri_source->width, mri_source->height, mri_source->depth) ;
	
  mp.mri_diag = mri_source ;
  mp.diag_morph_from_atlas = 0 ;
  mp.diag_write_snapshots = 1 ;
  mp.diag_sample_type = use_aseg ? SAMPLE_NEAREST : SAMPLE_TRILINEAR ;
  mp.diag_volume = use_aseg ? GCAM_LABEL : GCAM_MEANS ;

  if (renormalize)
    GCAMnormalizeIntensities(gcam, mri_target) ;
  if (mp.write_iterations != 0)
    {
      char fname[STRLEN] ;
      MRI  *mri_gca ;
		
      if (getenv("DONT_COMPRESS"))
        sprintf(fname, "%s_target.mgh", mp.base_name) ;
      else
        sprintf(fname, "%s_target.mgz", mp.base_name) ;
      if (mp.diag_morph_from_atlas == 0)
      {
        printf("writing target volume to %s...\n", fname) ;
        MRIwrite(mri_target, fname) ;
        sprintf(fname, "%s_target", mp.base_name) ;
        MRIwriteImageViews(mri_target, fname, IMAGE_SIZE) ;
      }
      else
      {
        if (use_aseg)
          mri_gca = GCAMwriteMRI(gcam, NULL, GCAM_LABEL) ;
        else
        {
          mri_gca = MRIclone(mri_source, NULL) ;
          GCAMbuildMostLikelyVolume(gcam, mri_gca) ;
        }
	  printf("writing target volume to %s...\n", fname) ;
	  MRIwrite(mri_gca, fname) ;
	  sprintf(fname, "%s_target", mp.base_name) ;
	  MRIwriteImageViews(mri_gca, fname, IMAGE_SIZE) ;
	  MRIfree(&mri_gca) ;
	}
    }

  if (nozero)
    {
      printf("disabling zero nodes\n") ;
      GCAMignoreZero(gcam, mri_target) ;
    }
  mp.mri = mri_target ;
  if (mp.regrid == True && new_transform == 0)
    GCAMregrid(gcam, mri_target, PAD, &mp, &mri_source) ;

  mp.write_fname = out_fname ;
  GCAMregister(gcam, mri_source, &mp) ; // atlas is target, morph target into register with it
  if (apply_transform)
    {
      MRI *mri_aligned ;
      char   fname[STRLEN] ;
		
      FileNameRemoveExtension(out_fname, fname) ;
      strcat(fname, ".mgz") ;
      mri_aligned = GCAMmorphToAtlas(mp.mri, gcam, NULL, -1, mp.diag_sample_type) ;
      printf("writing transformed output volume to %s...\n", fname) ;
      MRIwrite(mri_aligned, fname) ;
      MRIfree(&mri_aligned) ;
    }
  printf("writing warp vector field to %s\n", out_fname) ;
  GCAMvoxToRas(gcam) ;
  GCAMwrite(gcam, out_fname) ;
  GCAMrasToVox(gcam, mri_source) ;

  msec = TimerStop(&start) ;
  seconds = nint((float)msec/1000.0f) ;
  minutes = seconds / 60 ;
  seconds = seconds % 60 ;
  printf("registration took %d minutes and %d seconds.\n", 
	 minutes, seconds) ;
  exit(0) ;
  return(0) ;
}
int main(int argc, char** argv) {

  char *infile;
  infile=argv[1];
  char *outfile;
  outfile=argv[2];

  float clumpx, clumpy, clumpz;
  sscanf (argv[3],"%f",&clumpx);
  sscanf (argv[4],"%f",&clumpy);
  sscanf (argv[5],"%f",&clumpz);
    
  if(argc!=6) {
    printf("Usage: ./cutout <infile> <outfile> <x coordinate of clump [Mpc]> <y coordinate> <z coordinate>\n");
    return 0;
  }

  printf("Box centered around x: %g y: %g z: %g [Mpc] \n", clumpx, clumpy, clumpz);

  /* load snapshot file */
  io_header header;
  particle_data * P;
  int nTot;
  nTot = load_snapshot(infile, &header, &P);

 
  /* output information about the simulation */
  printf(">> Output from Header \n");
  printf("Boxsize of Simulation: %g\n", header.BoxSize);
  printf("Number of gas particles: %i\n", header.npart[0]);
  printf("Number of high-res dm particles: %i\n", header.npart[1]);
  printf("Number of low-res dm particles: %i\n", header.npart[5]);
  printf("Number of star particles: %i\n", header.npart[4]);

  /*cutout region around the center */
  float extent=20000;
  clumpx=clumpx*1000; 		// Mpc -> kpc 
  clumpy=clumpy*1000; 		// Mpc -> kpc 
  clumpz=clumpz*1000; 		// Mpc -> kpc 

 
  /* check if the cutout region does not extend over boundaries */ 
  if(header.BoxSize-extent/2.<clumpx || extent/2.>clumpx) {
    printf("Out of bound in x-dimension - chose a more centered clump \n" );
    printf(">> ABORTING \n" );
    return 0;  
  }
  if(header.BoxSize-extent/2.<clumpy || extent/2.>clumpy) {
    printf("Out of bound in y-dimension - chose a more centered clump \n" );
    printf(">> ABORTING \n" );
    return 0;  
  }
  if(header.BoxSize-extent/2.<clumpz || extent/2.>clumpz) {
    printf("Out of bound in z-dimension - chose a more centered clump \n" );
    printf(">> ABORTING \n" );
    return 0;  
  } 

    
  int i;
  /* loop over all particles */
  int counter = 0;
  float center = header.BoxSize/2;
  for (i=0;i<nTot;i++) {
    /* test if particle is within our desired volume */
    if(P[i].Pos[0]<clumpx+extent/2 && P[i].Pos[0]>clumpx-extent/2 &&
       P[i].Pos[1]<clumpy+extent/2 && P[i].Pos[1]>clumpy-extent/2 &&
       P[i].Pos[2]<clumpz+extent/2 && P[i].Pos[2]>clumpz-extent/2) {
      /* shift coordinates */
      P[i].Pos[0]-= clumpx-extent/2;
      P[i].Pos[1]-= clumpy-extent/2;
      P[i].Pos[2]-= clumpz-extent/2;
      P[counter] = P[i];
      
      counter++;
    }

  }
  int counterType [6] = {0,0,0,0,0,0};
  /* get the numbers of the particle types */
  for (i=0;i<counter;i++) {
    if(P[i].Type==0) {
      counterType[0]+=1;
    }
    if(P[i].Type==1) {
      counterType[1]+=1;
    }
    if(P[i].Type==2) {
      counterType[2]+=1;
    }
    if(P[i].Type==3) {
      counterType[3]+=1;
    }
    if(P[i].Type==4) {
      counterType[4]+=1;
    }
    if(P[i].Type==5) {
      counterType[5]+=1;
    }
  }

  header.npart[0]=counterType[0];
  header.npartTotal[0]=counterType[0];
  header.npart[1]=counterType[1];
  header.npartTotal[1]=counterType[1];
  header.npart[4]=counterType[4];
  header.npartTotal[4]=counterType[4];
  header.npart[5]=counterType[5];
  header.npartTotal[5]=counterType[5];
  header.BoxSize = extent;

  /* output information about the simulation */
  printf(">> Output Cutout Box\n");
  printf("Boxsize: %g\n", header.BoxSize);
  printf("Number of gas particles: %i\n", header.npart[0]);
  printf("Number of high-res dm particles: %i\n", header.npart[1]);
  printf("Number of low-res dm particles: %i\n", header.npart[5]);
  printf("Number of star particles: %i\n", header.npart[4]);
  printf("Box centered around x: %g y: %g z: %g \n", clumpx, clumpy, clumpz);


  /* write reduced snapshot file */
  write_snapshot(outfile, &header, P);

  return 0;
}
Пример #13
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  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);
}
}
Пример #14
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  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();
}