示例#1
0
writesnap(int n)
{
    int cs = CSCode(Cartesian, NDIM, 2);
    static bool first = TRUE;

    if (n==0) return;

    if (first) {
        if (! streq(headline, ""))
            set_headline(headline);
        outstr = stropen(getparam("out"), "w");
        put_history(outstr);
	first = FALSE;
    }

    put_set(outstr, SnapShotTag);
     put_set(outstr, ParametersTag);
      put_data(outstr, NobjTag, IntType, &n, 0);
     put_tes(outstr, ParametersTag);
     put_set(outstr, ParticlesTag);
      put_data(outstr, CoordSystemTag, IntType, &cs, 0);
      put_data(outstr, MassTag, RealType, pmass, n, 0);
      put_data(outstr, PhaseSpaceTag, RealType, pphase[0][0], n, 2, NDIM, 0);
     put_tes(outstr, ParticlesTag);
    put_tes(outstr, SnapShotTag);
    ntot += n;
}
示例#2
0
set_t 
put_set(set_t s, int id)
{
  set_head_t *sh = get_set_head(s);
  int cap = sh->capacity;
  int sz = sh->size;
  int tsz = sh->table_size;

  int *ht = s + cap;
  int *bt = ht + tsz;

  int index;

  if (sz == cap) {
    set_t ns = alloc_set_inner(sh->properties, sz * 2);

    int i;

    if (sh->properties & SP_MAP) {
      ptr_t *mt = (ptr_t *) (bt + tsz);

      for (i=0; i<sz; i++) associate_set(ns, s[i], mt[i]);
    }
    else 
      for (i=0; i<sz; i++) put_set(ns, s[i]);

    set_header_set(ns, sh->header);

    free_set(s);    

    return put_set(ns, id);
  }

  index = probe(ht, bt, cap, tsz, id);
  
  if (index < 0) {
    pretty_print_set(stderr, s);
    fprintf(stderr, "id: %i\n", id);
  }
  assert (index >= 0);

  if (ht[index] == id && bt[index] >= 0) return s;

  s[sz] = id;
  ht[index] = id;
  bt[index] = sz;

  sh->size ++;

  return s;
}
示例#3
0
void writeview(void)
{
    static stream viewstr = NULL;
    real aspect, tempmat[4][4];
    int i, j, k;

    if (viewstr == NULL) {
        viewstr = stropen(getparam("viewfile"), "w");
	put_history(viewstr);
    }
    aspect = ((float) wscreen) / ((float) hscreen);
    for (i = 0; i < 4; i++)
        for (j = 0; j < 4; j++) {
	    tempmat[i][j] = 0.0;
	    for (k = 0; k < 4; k++)
	        tempmat[i][j] += viewmat[i][k] * projmat[k][j];
        }
    put_set(viewstr, "SnapView");
    put_data(viewstr, "Time", RealType, &tnow, 0);
    put_data(viewstr, "Aspect", RealType, &aspect, 0);
    put_data(viewstr, "ViewMatrix", FloatType, tempmat, 4, 4, 0);
    put_data(viewstr, "MouseValues", FloatType, mouseval, NVALUES, 2, 0);
    put_tes(viewstr, "SnapView");
    fflush(viewstr);
}
示例#4
0
文件: image.c 项目: jobovy/nemo
int write_image (stream outstr, imageptr iptr)
{
  put_history(outstr);
  put_set (outstr,ImageTag);
    put_set (outstr,ParametersTag);
      put_data (outstr,NxTag,  IntType,  &(Nx(iptr)),   0);
      put_data (outstr,NyTag,  IntType,  &(Ny(iptr)),   0);
      put_data (outstr,NzTag,  IntType,  &(Nz(iptr)),   0);
      put_data (outstr,XminTag,RealType, &(Xmin(iptr)), 0);
      put_data (outstr,YminTag,RealType, &(Ymin(iptr)), 0);
      put_data (outstr,ZminTag,RealType, &(Zmin(iptr)), 0);
      put_data (outstr,DxTag,  RealType, &(Dx(iptr)),   0);
      put_data (outstr,DyTag,  RealType, &(Dy(iptr)),   0);
      put_data (outstr,DzTag,  RealType, &(Dz(iptr)),   0);
      put_data (outstr,XrefTag,RealType, &(Xref(iptr)), 0);
      put_data (outstr,YrefTag,RealType, &(Yref(iptr)), 0);
      put_data (outstr,ZrefTag,RealType, &(Zref(iptr)), 0);
      put_data (outstr,MapMinTag, RealType, &(MapMin(iptr)), 0);
      put_data (outstr,MapMaxTag, RealType, &(MapMax(iptr)), 0);
      put_data (outstr,BeamTypeTag, IntType, &(BeamType(iptr)), 0);
      put_data (outstr,BeamxTag, RealType, &(Beamx(iptr)), 0);
      put_data (outstr,BeamyTag, RealType, &(Beamy(iptr)), 0);
      put_data (outstr,BeamzTag, RealType, &(Beamz(iptr)), 0);
      if (Namex(iptr))
         put_string (outstr,NamexTag,Namex(iptr));
      if (Namey(iptr))
         put_string (outstr,NameyTag,Namey(iptr));
      if (Namez(iptr))
         put_string (outstr,NamezTag,Namez(iptr));
      if (Unit(iptr))
         put_string (outstr,UnitTag,Unit(iptr));
      put_data (outstr,TimeTag,  RealType, &(Time(iptr)), 0);
      put_string(outstr,StorageTag,matdef[idef]);
      put_data (outstr,AxisTag,  IntType, &(Axis(iptr)), 0);
    put_tes (outstr, ParametersTag);
         
    put_set (outstr,MapTag);
    if (Nz(iptr)==1)
      put_data (outstr,MapValuesTag,RealType,
		Frame(iptr),Nx(iptr),Ny(iptr),0);
    else
      put_data (outstr,MapValuesTag,RealType,
		Frame(iptr),Nx(iptr),Ny(iptr),Nz(iptr),0);
    put_tes (outstr, MapTag);
  put_tes (outstr, ImageTag);
  return 1;
}
示例#5
0
void write_snapshot(void)
{
    real *mbuf, *mp, *pspbuf, *pspp;
    bodyptr bp;
    int cs = CSCode(Cartesian, NDIM, 2);
    string options = getparam("options");

    mbuf = mp = (real *) allocate(ntest * sizeof(real));
    pspbuf = pspp = (real *) allocate(ntest * 2 * NDIM * sizeof(real));
    for (bp = testdata; bp < testdata+ntest; bp++) {
	*mp++ = Mass(bp);
	SETV(pspp, Pos(bp));
	pspp += NDIM;
	SETV(pspp, Vel(bp));
	pspp += NDIM;
    }
    put_set(outstr, SnapShotTag);
    put_set(outstr, ParametersTag);
    put_data(outstr, NobjTag, IntType, &ntest, 0);
    put_data(outstr, TimeTag, RealType, &tsnap, 0);
    put_data(outstr, "tol", RealType, &tol, 0);
    put_data(outstr, "eps", RealType, &eps, 0);
    put_tes(outstr, ParametersTag);
    put_set(outstr, ParticlesTag);
    put_data(outstr, CoordSystemTag, IntType, &cs, 0);
    if (scanopt(options, "mass"))
	put_data(outstr, MassTag, RealType, mbuf, ntest, 0);
    if (scanopt(options, "phase"))
	put_data(outstr, PhaseSpaceTag, RealType, pspbuf, ntest, 2, NDIM, 0);
    put_data(outstr, PotentialTag, RealType, phidata, ntest, 0);
    put_data(outstr, AccelerationTag, RealType, accdata, ntest, NDIM, 0);
    put_tes(outstr, ParticlesTag);
    put_set(outstr, DiagnosticsTag);
    put_data(outstr, "n2btot", IntType, &n2btot, 0);
    put_data(outstr, "nbctot", IntType, &nbctot, 0);
    put_data(outstr, "cputree", RealType, &cputree, 0);
    put_data(outstr, "cpufcal", RealType, &cpufcal, 0);
    put_tes(outstr, DiagnosticsTag);
    put_tes(outstr, SnapShotTag);
    free(mbuf);
    free(pspbuf);
}
示例#6
0
文件: draw.c 项目: zevlg/eukleides
void hatch_polygon(void)
{
     _set* s;

    check_hatch(POPn);
    s = POP(_set);
    if (s == NULL) return;
    fprintf(output_file, "\\pspolygon");
    put_local();
    put_set(s);
}
示例#7
0
文件: draw.c 项目: zevlg/eukleides
void fill_polygon(void)
{
    _set* s;

    s = POP(_set);
    if (s == NULL) return;
    check_color();
    fprintf(output_file, "\\pspolygon*");
    put_local();
    put_set(s);
}
示例#8
0
文件: draw.c 项目: zevlg/eukleides
void draw_polygon(void)
{
    _set* s;

    s = POP(_set);
    if (s == NULL) return;
    check_path_settings();
    fprintf(output_file, "\\pspolygon");
    put_local();
    put_set(s);
}
示例#9
0
文件: gsp.c 项目: jasminegrosso/zeno
void put_gsprof(stream ostr, gsprof *gsp)
{
    put_set(ostr, "GeneralSphericalProfile");
    put_data(ostr, "Npoint", IntType, &gsp->npoint, 0);
    put_data(ostr, "Radius", RealType, gsp->radius, gsp->npoint, 0);
    put_data(ostr, "Density", RealType, gsp->density, gsp->npoint, 0);
    put_data(ostr, "Mass", RealType, gsp->mass, gsp->npoint, 0);
    put_data(ostr, "Alpha", RealType, &gsp->alpha, 0);
    put_data(ostr, "Beta", RealType, &gsp->beta, 0);
    put_data(ostr, "Mtot", RealType, &gsp->mtot, 0);
    put_tes(ostr, "GeneralSphericalProfile");
}
示例#10
0
文件: draw.c 项目: zevlg/eukleides
void draw_path(void)
{
    _set* s;

    s = POP(_set);
    if (s == NULL || s->next == NULL) return;
    check_path_settings();
    check_arrowsize();
    fprintf(output_file, "\\psline");
    put_local();
    put_arrows();
    put_set(s);
}
示例#11
0
local void my_put_snap_diagnostics(stream outstr, int *ofptr)
{
    real cput;

    cput = cputime();
    put_set(outstr, DiagnosticsTag);
    put_data(outstr, EnergyTag, RealType, etot, 3, 0);
    put_data(outstr, KETensorTag, RealType, keten, NDIM, NDIM, 0);
    put_data(outstr, PETensorTag, RealType, peten, NDIM, NDIM, 0);
    put_data(outstr, AMTensorTag, RealType, amten, NDIM, NDIM, 0);
    put_data(outstr, CMPhaseSpaceTag, RealType, cmphase, 2, NDIM, 0);
    put_data(outstr, "cputime", RealType, &cput, 0);
    put_tes(outstr, DiagnosticsTag);
}
示例#12
0
set_t 
associate_set(set_t s, int id, ptr_t obj)
{
  set_head_t *sh = get_set_head(s);
  
  int cap = sh->capacity;
  int tsz = sh->table_size;

  int *ht = s + cap;
  int *bt = ht + tsz;

  ptr_t *mt = (ptr_t *) (bt + tsz);
  
  int index = probe(ht, bt, cap, tsz, id);
  
  assert (sh->properties & SP_MAP);
  
  if (index == EMPTY || bt[index] < 0) {
    s = put_set(s, id);
    
    sh = get_set_head(s);
    
    cap = sh->capacity;
    tsz = sh->table_size;
    
    ht = s + cap;
    bt = ht + tsz;
    
    mt = (ptr_t *) (bt + tsz);
    
    index = probe(ht, bt, cap, tsz, id);
    
    if (index == EMPTY) {
      pretty_print_set(stderr, s);
      fprintf(stderr, "id: %i\n", id);
    }
    assert (index != EMPTY);
  }

  mt[bt[index]] = obj;

  return s;
}
示例#13
0
local void put_quadfield(stream quadstr)
{
    put_set(quadstr, "QuadField");
    put_data(quadstr, TimeTag, RealType, &tnow, 0);
    put_data(quadstr, "nqtab", IntType, &qfld.nqtab, 0);
    put_data(quadstr, "radtab", RealType, qfld.radtab, qfld.nqtab, 0);
    put_data(quadstr, "Q00tab", RealType, qfld.Q00tab, qfld.nqtab, 0);
    put_data(quadstr, "P00tab", RealType, qfld.P00tab, qfld.nqtab, 0);
    put_data(quadstr, "Q10tab", RealType, qfld.Q10tab, qfld.nqtab, 0);
    put_data(quadstr, "P10tab", RealType, qfld.P10tab, qfld.nqtab, 0);
    put_data(quadstr, "Q11tab", RealType, qfld.Q11tab, NDIM, qfld.nqtab, 0);
    put_data(quadstr, "P11tab", RealType, qfld.P11tab, NDIM, qfld.nqtab, 0);
    put_data(quadstr, "Q22tab", RealType, qfld.Q22tab,
	     NDIM, NDIM, qfld.nqtab, 0);
    put_data(quadstr, "P22tab", RealType, qfld.P22tab,
	     NDIM, NDIM, qfld.nqtab, 0);
    put_data(quadstr, "eps1", RealType, &eps1, 0);
    put_data(quadstr, "eps2", RealType, &eps2, 0);
    put_tes(quadstr, "QuadField");
    fflush(quadstr);
}
示例#14
0
文件: xyio.c 项目: jobovy/nemo
image *xyopen(int *handle, string name, string status, int naxis, int *axes)
{
    int i, access;
    string read_matdef;
    image *iptr;
    stream str;

    if(naxis>MAXNAXIS) 
        error("naxis=%d not supported: MAXNAXIS=%d",naxis, MAXNAXIS);

    if (first) xy_init();

    str = stropen(name,status);                       /* open file */
    switch (*status) {
        case 'r':               /* "r", "old" */
        case 'o':
            access = GET;
            break;
        case 'w':               /* "w", "new" */
        case 'n':
            access = PUT;
            break;
        default:
            error("xyopen: Unsupported mode %s",status);
    }
    iptr = (imageptr )allocate(sizeof(image));  /* new image */

    if(access == GET){
      get_history(str);
      get_set (str,ImageTag);
        get_set (str,ParametersTag);
          get_data (str,NxTag,IntType, &(Nx(iptr)), 0);
          get_data (str,NyTag,IntType, &(Ny(iptr)), 0);
          get_data (str,NzTag,IntType, &(Nz(iptr)), 0);
          get_data_coerced (str,XminTag,RealType, &(Xmin(iptr)), 0);
          get_data_coerced (str,YminTag,RealType, &(Ymin(iptr)), 0);
          get_data_coerced (str,ZminTag,RealType, &(Zmin(iptr)), 0);
          get_data_coerced (str,DxTag,RealType, &(Dx(iptr)), 0);
          get_data_coerced (str,DyTag,RealType, &(Dy(iptr)), 0);
          get_data_coerced (str,DzTag,RealType, &(Dz(iptr)), 0);
	  get_data_coerced (str,MapMinTag, RealType, &(MapMin(iptr)), 0);
	  get_data_coerced (str,MapMaxTag, RealType, &(MapMax(iptr)), 0);
	  get_data (str,BeamTypeTag, IntType, &(BeamType(iptr)), 0);
	  get_data_coerced (str,BeamxTag, RealType, &(Beamx(iptr)), 0);
	  get_data_coerced (str,BeamyTag, RealType, &(Beamy(iptr)), 0);
	  get_data_coerced (str,BeamzTag, RealType, &(Beamz(iptr)), 0);
          if (get_tag_ok(str,NamexTag))             /* X-axis name */
            Namex(iptr) = get_string(str,NamexTag);
          else
            Namex(iptr) = NULL;
          if (get_tag_ok(str,NameyTag))             /* Y-axis name */
            Namey(iptr) = get_string(str,NameyTag);
          else
            Namey(iptr) = NULL;
          if (get_tag_ok(str,NamezTag))             /* Z-axis name */
            Namez(iptr) = get_string(str,NamezTag);
          else
            Namez(iptr) = NULL;
          if (get_tag_ok(str,UnitTag))             /* units  */
            Unit(iptr) = get_string(str,UnitTag);
          else
            Unit(iptr) = NULL;
          read_matdef = get_string(str,StorageTag);
	  if (!streq(read_matdef,matdef[idef]))
             dprintf(0,"read_image: StorageTag = %s, compiled with %s\n",
		        read_matdef, matdef[idef]);
        get_tes(str,ParametersTag);
        get_set(str,MapTag);
        if(Nz(iptr)<=1)
            get_data_set(str,MapValuesTag,RealType,Nx(iptr),Ny(iptr),0);
        else
            get_data_set(str,MapValuesTag,RealType,Nx(iptr),Ny(iptr),Nz(iptr),0);
        for (i=0; i<naxis; i++) axes[i] = 1;
        axes[0] = Nx(iptr); axes[1] = Ny(iptr); axes[2] = Nz(iptr);
    } else { /* PUT */
      Nx(iptr) = Ny(iptr) = Nz(iptr) = 1;
      if (naxis>0) Nx(iptr)  = axes[0];
      if (naxis>1) Ny(iptr)  = axes[1];
      if (naxis>2) Nz(iptr)  = axes[2];

      put_history(str);
      put_set (str,ImageTag);
        put_set (str,ParametersTag);
          put_data (str,NxTag,  IntType,  &(Nx(iptr)),   0);
          put_data (str,NyTag,  IntType,  &(Ny(iptr)),   0);
          put_data (str,NzTag,  IntType,  &(Nz(iptr)),   0);
          put_data (str,XminTag,RealType, &(Xmin(iptr)), 0);
          put_data (str,YminTag,RealType, &(Ymin(iptr)), 0);
          put_data (str,ZminTag,RealType, &(Zmin(iptr)), 0);
          put_data (str,DxTag,  RealType, &(Dx(iptr)),   0);
          put_data (str,DyTag,  RealType, &(Dy(iptr)),   0);
          put_data (str,DzTag,  RealType, &(Dz(iptr)),   0);
          put_data (str,MapMinTag, RealType, &(MapMin(iptr)), 0);
          put_data (str,MapMaxTag, RealType, &(MapMax(iptr)), 0);
          put_data (str,BeamTypeTag, IntType, &(BeamType(iptr)), 0);
          put_data (str,BeamxTag, RealType, &(Beamx(iptr)), 0);
          put_data (str,BeamyTag, RealType, &(Beamy(iptr)), 0);
          put_data (str,BeamzTag, RealType, &(Beamz(iptr)), 0);
          if (Namex(iptr))
            put_string (str,NamexTag,Namex(iptr));
          if (Namey(iptr))
            put_string (str,NameyTag,Namey(iptr));
          if (Namez(iptr))
            put_string (str,NamezTag,Namez(iptr));
      	  if (Unit(iptr))
            put_string (str,UnitTag,Unit(iptr));
          put_string(str,StorageTag,matdef[idef]);
        put_tes(str, ParametersTag);
        put_set(str, MapTag);
        if(Nz(iptr)<=1)
          put_data_set(str,MapValuesTag,RealType,Nx(iptr),Ny(iptr),0);
        else
          put_data_set(str,MapValuesTag,RealType,Nx(iptr),Ny(iptr),Nz(iptr),0);
    }

    *handle = -1;
    for(i=0; i<MAXOPEN; i++) {        /* look for a new table entry */
      if(images[i].str == NULL) *handle = i;
    }
    if(*handle < 0) 
        error("xyopen: No more free slots; too many open images");
    for (i=0; i<MAXNAXIS; i++)
        images[*handle].axes[i] = 1;

    images[*handle].str     = str;
    images[*handle].iptr    = iptr;
    images[*handle].offset  = 0;
    images[*handle].access  = access;
    images[*handle].naxis   = (Nz(iptr)<=1 ? 2 : 3);
    images[*handle].axes[0] = Nx(iptr);
    images[*handle].axes[1] = Ny(iptr);
    images[*handle].axes[2] = Nz(iptr);

    return iptr;
}
///identifies edges which are not surrounded by triangles - locations where the surface
///is non manifold.
///This turns the edges variable non-null.
//
//NOTE: THIS FUNCTION IS CURRENTLY BROKEN
//
//
void SurfaceObject::identifyNonManifoldEdges(void)
{
	int i = 0;
	int j = 0;
	
	///create a set of sets to hold non-manifold edges
	set_t nonManifold = alloc_set(SP_MAP);
		
	///Create a set of sets to remember which triangles associate with which vertex.  Allocate that here.
	set_t verticesMappingToTris = alloc_set(SP_MAP);
	for(i = 0; i<numPoints; i++){
		set_t tris = alloc_set(0);
		verticesMappingToTris = associate_set(verticesMappingToTris, i, tris);
	}

	///associate each vertex with a list of triangles it is part of.
	///we do this by interating through all triangles
	set_t tris;
	for(i = 0; i<numTriangles; i++){
		tris = (set_t) mapsto_set(verticesMappingToTris, triangles[3*i+0]);
		tris = put_set(tris, i);
		verticesMappingToTris = associate_set(verticesMappingToTris, triangles[3*i+0], tris);

		tris = (set_t) mapsto_set(verticesMappingToTris, triangles[3*i+1]);
		tris = put_set(tris, i);
		verticesMappingToTris = associate_set(verticesMappingToTris, triangles[3*i+1], tris);
		
		tris = (set_t) mapsto_set(verticesMappingToTris, triangles[3*i+2]);
		tris = put_set(tris, i);
		verticesMappingToTris = associate_set(verticesMappingToTris, triangles[3*i+2], tris);
	}

	int min = 100000;
	int max = 0;
	int counter = 0;
	for(i = 0; i<size_set(verticesMappingToTris); i++){
		tris = (set_t) mapsto_set(verticesMappingToTris, verticesMappingToTris[i]);
		if(min > size_set(tris)){ 
			min = size_set(tris); 
			if(size_set(tris) == 0){
				counter++;
			}
		}
		if(max < size_set(tris)){ max = size_set(tris); }
	}

	printf("MAXIMUM NUMBER OF TRIANLGES ASSOCIATED WITH A point: %i\n", max);
	printf("MINIMUM NUMBER OF TRIANLGES ASSOCIATED WITH A point: %i  (total 0: %i)\n", min, counter);


	set_t set1;
	set_t set2;
	set_t tempSet;
	int numCommon;
	int * tri = new int[3];
	///iterate through all triangles, 
	for(i = 0; i<numTriangles; i++){
		tri[0] = triangles[3*i+0];
		tri[1] = triangles[3*i+1];
		tri[2] = triangles[3*i+2];

		///for each edge on the triangle, verify that exactly two 
		///distinct triangles are part of that edge.  otherwise it is
		///a non-manifold edge.
		for(j = 0; j<3; j++){
			//set the two vertices of the edge we are working on
			int t1 = tri[(j+0)%3];
			int t2 = tri[(j+1)%3];
			//identify the set of triangles adjacent to each endpoint
			set1 = (set_t) mapsto_set(verticesMappingToTris, t1);
			set2 = (set_t) mapsto_set(verticesMappingToTris, t2);
			///find out how many triangles are common between these endpoints
			numCommon = countNumCommon(set1, set2);

			//if numCommon == 1, then this is an edge of a nonmanifold surface.  Store it.
			if(numCommon == 1){
				if(!contains_set(nonManifold, t1)){ tempSet = alloc_set(0); }
				else{ tempSet = (set_t) mapsto_set(nonManifold, t1); }
				tempSet = put_set(tempSet, t2);
				nonManifold = associate_set(nonManifold, t1, tempSet);

				if(!contains_set(nonManifold, t2)){ tempSet = alloc_set(0); }
				else{ tempSet = (set_t) mapsto_set(nonManifold, t2); }
				tempSet = put_set(tempSet, t1);
				nonManifold = associate_set(nonManifold, t2, tempSet);
//				printf("Edge: %i %i\n", t1, t2);
			}

			//if numCommon is zero, then there is a serious issue with triangle topology.  Report it.
			if(numCommon == 0){
				printf("ERROR: Two vertices of the same triangle (vertex %i and %i in triangle %i) \n", t1, t2, i);
				printf("ERROR: are not members of at least one triangle, according to our data!!\n");
			}

			//if numCommon is greater than two, there is impossible surface occuring.  Report it.
			if(numCommon > 2){
				printf("ERROR: Vertices %i and %i appear to be adjacent to an edge which is part of \n", t1, t2);
				printf("ERROR: more than two triangles, creating a non-manifold surface! error!\n");
			}
			
			///if numCommon is equal to two, that is fine.  Report nothing.
		}

		///The end of this loop creates a list of non-manifold edges at the border of the surface, if it exists.
	}
	
	edges = nonManifold;
	
	delete[](tri);
	//free the data structure
	for(i = 0; i<numPoints; i++){ tris = (set_t) mapsto_set(verticesMappingToTris, i); free_set(tris); }
	free_set(verticesMappingToTris);
	
}