Exemplo n.º 1
0
int read_snapshot(
		   bodyptr *btab_ptr,	     /* gets particle array */
		   int *nobj_ptr,	     /* gets number of bodies */
		   stream instr              /* stream to read from */
		   )
{
  int nobj, cs, i;
  real *mbuf, *mp, *pbuf, *pp;
  bodyptr bp;

  for(;;) {                        /* loop until done or proper snapshot */
    if (!get_tag_ok(instr,SnapShotTag))
        return 0;
    get_set(instr, SnapShotTag);
    if (!get_tag_ok(instr,ParametersTag)) {
    	get_tes(instr,SnapShotTag);
        continue;
    }
    get_set(instr, ParametersTag);
    get_data(instr, NobjTag, IntType, &nobj, 0);
    if (nobj < 1)
	error("read_snapshot: %s = %d  is absurd", NobjTag, nobj);
    if (get_tag_ok(instr,TimeTag))
        get_data(instr,TimeTag, RealType, &tsnap, 0);
    else {
        dprintf(0,"No time tag: time=0.0 assumed\n");
        tsnap = 0.0;
    }
    get_tes(instr, ParametersTag);
    if (!get_tag_ok(instr,ParticlesTag)) {
    	get_tes(instr,SnapShotTag);
        continue;
    }
    get_set(instr, ParticlesTag);
    get_data(instr, CoordSystemTag, IntType, &cs, 0);
    if (cs != CSCode(Cartesian, NDIM, 2))
	error("read_snapshot: cannot handle %s = %d", CoordSystemTag, cs);
    mbuf = mp = (real *) allocate(nobj * sizeof(real));
    pbuf = pp = (real *) allocate(nobj * 2 * NDIM * sizeof(real));
    get_data(instr, MassTag, RealType, mbuf, nobj, 0);
    get_data(instr, PhaseSpaceTag, RealType, pbuf, nobj, 2, NDIM, 0);
    get_tes(instr, ParticlesTag);
    get_tes(instr, SnapShotTag);
    *btab_ptr = bp = (bodyptr) allocate(nobj * sizeof(body));
    for (i = 0; i < nobj; i++) {
	Type(bp) = BODY;
	Mass(bp) = *mp++;
	SETV(Pos(bp), pp);
	pp += NDIM;
	SETV(Vel(bp), pp);
	pp += NDIM;
	bp++;
    }
    free(mbuf);
    free(pbuf);
    *nobj_ptr = nobj;
    return 1;
  }
}
Exemplo n.º 2
0
int main(int argc, string argv[])
{
  string prog, itags[MaxBodyFields];
  stream xstr, ostr;
  int nold = -1;

  initparam(argv, defv);
  exprs[0] = getparam("group");
  prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char)));
  buildmap(prog, names, exprs, types, NULL, Precision, NDIM, TRUE);
  xstr = execmap(prog);
  if (get_tag_ok(xstr, "History"))
    skip_item(xstr);
  get_history(xstr);
  ostr = stropen(getparam("out"), "w");
  put_history(ostr);
  new_field(&GroupField, IntType, "Group");
  new_field(&GroupField + 1, NULL, NULL);
  layout_body(btags, Precision, NDIM);
  while (get_snap(xstr, &bodytab, &nbody, &tbody, itags, FALSE)) {
    snaptrak();
    put_snap(ostr, &traktab, &ntrak, &tbody, otags);
    if (ntrak != nold)
      eprintf("[%s: wrote %d groups at t = %f]\n",
	      getprog(), ntrak, tbody);
    nold = ntrak;
  }
  strclose(ostr);
  if (unlink(prog) != 0)
    error("%s: can't unlink %s\n", getprog(), prog);
  return (0);
}
Exemplo n.º 3
0
void nemo_main(void) /* this replaces main(argc,argv)        <--- required */
{
    stream instr, outstr;
    string times = getparam("times");
    real   tsnap;
    Body  *btab = NULL, *bp;
    int    i, nbody, bits;
    bool   first = TRUE;

    instr = stropen(getparam("in"), "r");
    outstr = stropen(getparam("out"), "w");

    for (;;) {    /* infinite loop, broken only when ran out of snapshots */
    	get_history(instr);                    /* read history */
        if (!get_tag_ok(instr, SnapShotTag)) break; /* check if done */
        get_snap(instr, &btab, &nbody, &tsnap, &bits);  /* get next */
        
        /* Operate on the snapshot here : */
        for (bp=btab, i=0; i<nbody; bp++, i++) {
            /* all the work goes here */
        }
        if (first) {
            put_history(outstr);
            first = FALSE;
        }
        put_snap(outstr, &btab, &nbody, &tsnap, &bits);     /* output */
    }
    strclose(instr);
    if (first) {
    	warning("No snapshots processed");
  	strdelete(outstr,TRUE);
    } else
        strclose(outstr);
}
Exemplo n.º 4
0
int main(int argc, string argv[])
{
  string prog, itags[MaxBodyFields], otags[MaxBodyFields];
  stream xstr, ostr;
  bodyptr btab = NULL;
  int nbody;
  real tnow;

  initparam(argv, defv);
  exprs[0] = getparam("weight");
  prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char)));
  buildmap(prog, names, exprs, types, NULL, Precision, NDIM, TRUE);
  xstr = execmap(prog);
  if (get_tag_ok(xstr, "History"))
    skip_item(xstr);
  get_history(xstr);
  ostr = stropen(getparam("out"), "w");
  put_history(ostr);
  new_field(&WeightField, RealType, "Weight");
  new_field(&WeightField + 1, NULL, NULL);
  while (get_snap(xstr, &btab, &nbody, &tnow, itags, TRUE)) {
    snaprect(btab, nbody);
    del_tag(otags, itags, "Weight");
    put_snap(ostr, &btab, &nbody, &tnow, otags);
  }
  strclose(ostr);
  if (unlink(prog) != 0)
    error("%s: can't unlink %s\n", getargv0(), prog);
  return (0);
}
Exemplo n.º 5
0
void nemo_main()
{
    stream instr, outstr;
    string times, ctypei, ctypeo;
    real   tsnap;
    int i, nbody, bits, mode;
    Body *btab = NULL, *bp;
    proc transform, trans2;

    times = getparam("times");
    ctypei = getparam("ctypei");
    ctypeo = getparam("ctypeo");
    if (streq(ctypei,"cart") && streq(ctypeo,"sph"))
        transform = cartesian_spherical;
    else if (streq(ctypei,"sph") && streq(ctypeo,"cart"))
        transform = spherical_cartesian;
    else if (streq(ctypei,"cart") && streq(ctypeo,"cyl"))
        transform = cartesian_cylindrical;
    else if (streq(ctypei,"cyl") && streq(ctypeo,"cart"))
        transform = cylindrical_cartesian;
    else
        error("Unimplemented ctype i/o : %s -> %s",ctypei,ctypeo);
    dprintf(0,"converting from %s to %s\n",ctypei,ctypeo);
    
    instr = stropen(getparam("in"), "r");   
    outstr = stropen(getparam("out"), "w");

    get_history(instr);
    put_history(outstr);		
    for (;;) {
    	get_history(instr);		/* skip over stuff we can forget */
        if (!get_tag_ok(instr, SnapShotTag))
		break;			/* done with work in loop */
        get_snap(instr, &btab, &nbody, &tsnap, &bits);
        if ((bits & MassBit) == 0 && (bits & PhaseSpaceBit) == 0) {
	    continue;       /* just skip it's probably a diagnostics */
        }

        if ((bits & TimeBit) == 0)
	    tsnap = 0.0;
        else if (!streq(times,"all") && !within(tsnap, times, TIMEFUZZ))
            continue;
        dprintf (1,"Transforming snapshot at time= %f bits=0x%x\n",tsnap,bits);
#if 0
        Qmass  = MassBit & bits;       
        Qphase = PhaseSpaceBit & bits;
        Qacc   = AccelerationBit & bits;
        Qaux   = AuxBit & bits;
        Qkey   = KeyBit & bits;
#endif

        for (bp = btab; bp < btab+nbody; bp++) {
            (transform)(Pos(bp),Vel(bp),Acc(bp));
        }
        put_snap(outstr, &btab, &nbody, &tsnap, &bits);
    }
}
Exemplo n.º 6
0
nemo_main()
{
  stream instr;
  real   tsnap, x, y, v, d;
  int    i, nbody, bits, iy, ny, nout;
  Body *btab = NULL, *bp;
  Grid g;
  real yrange[MAXY], sumd[MAXY], sumvd[MAXY], sumxd[MAXY];
  bool Qmass = getbparam("mass");
  
  instr = stropen(getparam("in"), "r");           /* open input file */
  ny = nemoinpr(getparam("y"),yrange,MAXY);
  if (ny<2) error("yrange syntax error or not enuf slices");
#if 0  
  inia_grid(&g, ny, yrange);
#else
  inil_grid(&g, ny-1, yrange[0], yrange[ny-1]);
#endif

  get_history(instr);			    /* accumulate data history */
  for(;;) {				 	 /* loop for all times */
    get_history(instr);                         /* for paranoidici */
    if (!get_tag_ok(instr, SnapShotTag))          /* check if done */
      break;
    get_snap(instr, &btab, &nbody, &tsnap, &bits);      /* get one */
    if ((bits & PhaseSpaceBit) == 0)
      continue;     /* if no positions -  skip */
    
    for (i=0; i<ny; i++)
      sumd[i] = sumxd[i] = sumvd[i] = 0.0;

    for (bp = btab; bp < btab+nbody; bp++) {    /* loop all bodies */
      y = Pos(bp)[1];
      iy = index_grid(&g, y);
      if (iy < 0) continue;
      d = Qmass ? Mass(bp) : Dens(bp);
      x = Pos(bp)[0];
      v = Vel(bp)[1];
      sumd[iy]  += d;
      sumvd[iy] += v*d;
      sumxd[iy] += x*d;
    }
    break; /* for now just first snapshot */
  }
  nout = 0;
  for (i=0; i<ny-1; i++) {
    if (sumd[i] > 0.0) {
      nout++;
      printf("%g %g %g %g\n",value_grid(&g, (real)i+0.5), 
	     sumxd[i]/sumd[i], sumvd[i]/sumd[i], sumd[i]);
    }
  }
  if (nout==0)
    warning("No densities found in slices %s",getparam("y"));
} /* nemo_main() */
Exemplo n.º 7
0
int main(int argc, string argv[])
{
  string prog, coords, itags[MaxBodyFields], otags[MaxBodyFields];
  stream xstr, ostr;
  bodyptr btab = NULL, bp;
  int nbody;
  real tnow;
  vector cmpos, cmvel, cmacc;

  initparam(argv, defv);
  exprs[0] = getparam("weight");
  prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char)));
  buildmap(prog, names, exprs, types, NULL, Precision, NDIM, TRUE);
  xstr = execmap(prog);
  if (get_tag_ok(xstr, "History"))
    skip_item(xstr);
  get_history(xstr);
  ostr = stropen(getparam("out"), "w");
  put_history(ostr);
  coords = getparam("coords");
  new_field(&WeightField, RealType, "Weight");
  new_field(&WeightField + 1, NULL, NULL);
  while (get_snap(xstr, &btab, &nbody, &tnow, itags, TRUE, NULL)) {
    if (scanopt(coords, PosTag) && set_member(itags, PosTag)) {
      snapcmpos(cmpos, btab, nbody, WeightField.offset);
      for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
	SUBV(Pos(bp), Pos(bp), cmpos);
      }
      eprintf("[%s: centroid position: %f,%f,%f]\n", getprog(),
	      cmpos[0], cmpos[1], cmpos[2]);
    }
    if (scanopt(coords, VelTag) && set_member(itags, VelTag)) {
      snapcmvel(cmvel, btab, nbody, WeightField.offset);
      for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
	SUBV(Vel(bp), Vel(bp), cmvel);
      }
      eprintf("[%s: centroid velocity: %f,%f,%f]\n", getprog(),
	      cmvel[0], cmvel[1], cmvel[2]);
    }
    if (scanopt(coords, AccTag) && set_member(itags, AccTag)) {
      snapcmacc(cmacc, btab, nbody, WeightField.offset);
      for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
	SUBV(Acc(bp), Acc(bp), cmacc);
      }
      eprintf("[%s: cen. acceleration: %f,%f,%f]\n", getprog(),
	      cmacc[0], cmacc[1], cmacc[2]);
    }
    del_tag(otags, itags, "Weight");
    put_snap(ostr, &btab, &nbody, &tnow, otags);
  }
  strclose(ostr);
  if (unlink(prog) != 0)
    error("%s: can't unlink %s\n", getprog(), prog);
  return (0);
}
Exemplo n.º 8
0
int get_history(stream instr)
{
    for(;;) {                   		/* loop reading input data  */
	if (get_tag_ok(instr, HeadlineTag)) {
	    headline = get_string(instr, HeadlineTag);
	    dprintf(5, "get_history: headline = %s\n", headline);
	} else if (get_tag_ok(instr, HistoryTag)) {
	    if (nhist > MAXHIST) {
		warning("get_history: no more history saved; MAXHIST=%d",
                        MAXHIST);
		return MAXHIST;
	    }
	    histbuf[nhist] = get_string(instr, HistoryTag);
	    dprintf(5, "get_history: histbuf[%d] = %s\n",
		    nhist, histbuf[nhist]);
	    freeup[nhist] = FALSE;
	    nhist++;
	} else
            break;                          /* done with reading loop */
    }
    return nhist;
}
Exemplo n.º 9
0
int get_number(string name, real *x)
{
    stream str;
    real *buf;
    int  n;

    str = stropen(name,"r");
    get_history(str);

    if (!get_tag_ok(str,"n"))
        error("%s: missing \"n\", Not a valid TESTIO input file",name);
    get_data(str,"n",IntType,&n,0);
    buf = (real *) allocate(n*sizeof(real));

    if (!get_tag_ok(str,"x"))
        error("%s: missing \"x\", Not a valid TESTIO input file",name);
    get_data(str,"x",RealType,buf,n,0);
    strclose(str);

    *x = *buf;
    dprintf(1,"Read number %f from file %s\n",*x,name);
    free( (char *) buf);
    return n;
}
Exemplo n.º 10
0
nemo_main()
{
    stream instr;
    real   inv_rscale, e_pot, e_kin, tsnap;
    string times;
    Body *btab = NULL, *bp;
    int i, nbody, bits, nrscale, nvscale;
    real   tmporb, tmpran, e_orb, e_ran;

    times = getparam("times");
    instr = stropen(getparam("in"), "r");

    get_history(instr);
    for (;;) {
        if (!get_tag_ok(instr, SnapShotTag))
                break;                  /* done with work in loop */
        get_snap(instr, &btab, &nbody, &tsnap, &bits);
        if ((bits & MassBit) == 0 && (bits & PhaseSpaceBit) == 0) {
            continue;       /* just skip */
        }

        if ((bits & TimeBit) == 0)
                tsnap = 0.0;
        else if (!streq(times,"all") && !within(tsnap, times, TIMEFUZZ))
                continue;               /* now skip this snapshot */
        dprintf (1,"Snapshot time=%f\n",tsnap);
        if ((bits & PotentialBit)) {
            e_pot = e_kin = e_orb = 0.0;
            for (bp = btab; bp < btab+nbody; bp++) {
                e_pot += Mass(bp) * Phi(bp);
                split_e (Mass(bp), Pos(bp), Vel(bp), &tmporb, &tmpran);
                e_kin += tmporb + tmpran;
                e_orb += tmporb;
            }
        } else
            error("snapstab: Potentials required\n");
        e_kin *= 0.5;   /* proper factor 0.5  */
        e_pot *= 0.5;   /* double count */
        e_orb *= 0.5;
        if (e_pot > 0.0)
            error("positive total potential energy???");
        if (e_kin < 0.0)
            error("negative total kinetic energy???");

        printf("t= %g E=T+U:  %g %g %g   2T+U= %g t_OP= %g\n",
            tsnap,e_pot+e_kin,e_kin,e_pot,2*e_kin+e_pot,e_orb/ABS(e_pot));
    }
}
Exemplo n.º 11
0
void nemo_main(void)
{
    stream instr, outstr;
    real   tsnap;
    string times;
    Body *btab = NULL, *bp;
    float mass, pos[NDIM], vel[NDIM], t;
    int j, nbody, bits;

            
    instr = stropen(getparam("in"), "r");	/* open input file */
    outstr = stropen(getparam("out"), "w");	/* open output file */
    times = getparam("times");

    get_history(instr);                 /* read history */
    for(;;) {                /* repeating until first or all times are read */
	get_history(instr);
        if (!get_tag_ok(instr, SnapShotTag))
            break;                                  /* done with work */
        get_snap(instr, &btab, &nbody, &tsnap, &bits);
        if (!streq(times,"all") && !within(tsnap,times,0.0001))
            continue;                   /* skip work on this snapshot */
        if ( (bits & PhaseSpaceBit) == 0)
            continue;                   /* skip work, only diagnostics here */

        dprintf(0,"Converting time=%f to RV format",tsnap);
        
	fwrite(&nbody,sizeof(int),1,outstr);
        for (bp = btab; bp < btab+nbody; bp++) {
	    mass = Mass(bp);
            fwrite(&mass,sizeof(float),1,outstr);
        }
        t = tsnap;
        fwrite(&t,sizeof(float),1,outstr);
        for (bp = btab; bp < btab+nbody; bp++) {
	    for(j = 0; j < NDIM; j++) {
		pos[j] = Pos(bp)[j];
		vel[j] = Vel(bp)[j];
	    }
	    fwrite(pos,sizeof(float),NDIM,outstr);
	    fwrite(vel,sizeof(float),NDIM,outstr);
        }
    }
    strclose(instr);
    strclose(outstr);
}
Exemplo n.º 12
0
nemo_main()
{
    stream instr, outstr;
    real   tsnap, mscale;
    Body  *btab = NULL, *bp;
    int i, j, n, nbody, nbodymass, bits, bitsmass, seed;
    rproc  bfunc, btrtrans();

    instr = stropen(getparam("in"), "r");
    outstr = hasvalue("out") ? stropen(getparam("out"),"w") : NULL;

    n = getiparam("iter");

    get_history(instr);
    if (!get_tag_ok(instr, SnapShotTag)) 
      error("not a snapshot");
    get_snap(instr, &btab, &nbody, &tsnap, &bits);

    if (getbparam("bodytrans")) {
      dprintf(0,"bodytrans scaling, iter=%d\n",n);
      bfunc = btrtrans(getparam("mass"));     /* use bodytrans expression */

      for (j=0; j<n; j++)
	for (bp=btab, i=0; i<nbody; bp++,i++)
	  Mass(bp) = bfunc(bp, tsnap, i);
    } else {
      dprintf(0,"simple inline scaling, iter=%d\n",n);
      mscale = getdparam("mass");
      for (j=0; j<n; j++)
	for (bp=btab, i=0; i<nbody; bp++,i++)
	  Mass(bp) = mscale*Mass(bp);
    }

    strclose(instr);
    if (outstr) { 
      put_history(outstr);
      put_snap(outstr, &btab, &nbody, &tsnap, &bits);
      strclose(outstr);
    }
}
Exemplo n.º 13
0
gsprof *get_gsprof(stream istr)
{
    string gsptag = "GeneralSphericalProfile";
    gsprof *gsp;

    if (get_tag_ok(istr, "FiniteSphericalProfile"))	/* old-style file?  */
	gsptag = "FiniteSphericalProfile";		/* use old tag      */
    gsp = (gsprof *) allocate(sizeof(gsprof));
    get_set(istr, gsptag);
    get_data(istr, "Npoint", IntType, &gsp->npoint, 0);
    gsp->radius = (real *) allocate(gsp->npoint * sizeof(real));
    gsp->density = (real *) allocate(gsp->npoint * sizeof(real));
    gsp->mass = (real *) allocate(gsp->npoint * sizeof(real));
    get_data(istr, "Radius", RealType, gsp->radius, gsp->npoint, 0);
    get_data(istr, "Density", RealType, gsp->density, gsp->npoint, 0);
    get_data(istr, "Mass", RealType, gsp->mass, gsp->npoint, 0);
    get_data(istr, "Alpha", RealType, &gsp->alpha, 0);
    get_data(istr, "Beta", RealType, &gsp->beta, 0);
    get_data(istr, "Mtot", RealType, &gsp->mtot, 0);
    get_tes(istr, gsptag);
    return (gsp);
}
Exemplo n.º 14
0
nemo_main()
{
    stream instr, tabstr;
    real   tsnap, ekin, etot, dr, r, rv, v, vr, vt, aux;
    real   varmin[MAXOPT], varmax[MAXOPT];
    real   var0[MAXOPT], var1[MAXOPT], var2[MAXOPT];
    Moment var[MAXOPT];
    string headline=NULL, options, times, mnmxmode;
    Body *btab = NULL, *bp, *bq;
    bool   Qmin, Qmax, Qmean, Qsig, Qtime, scanopt();
    int i, n, nbody, bits, nsep, isep, nopt, ParticlesBit;
    char fmt[20],*pfmt;
    string *burststring(), *opt;
    rproc btrtrans(), fopt[MAXOPT], faux;

    ParticlesBit = (MassBit | PhaseSpaceBit | PotentialBit | AccelerationBit |
            AuxBit | KeyBit);
    instr = stropen(getparam("in"), "r");	/* open input file */
    mnmxmode= getparam("mode");

    opt = burststring(getparam("var"),", ");
    nopt = 0;					/* count options */
    while (opt[nopt]) {				/* scan through options */
        fopt[nopt] = btrtrans(opt[nopt]);
        nopt++;
        if (nopt==MAXOPT) {
            dprintf(0,"\n\nMaximum number of var's = %d exhausted\n",MAXOPT);
            break;
        }
    }
    dprintf(0,"var: \n");
    for (i=0; i<nopt; i++)
        dprintf(0,"%s ",opt[i]);
    dprintf(0,"\n");
    dprintf(0,"mode: %s\n",mnmxmode);

    Qmin = scanopt(mnmxmode,"min");
    Qmax = scanopt(mnmxmode,"max");
    Qmean = scanopt(mnmxmode,"mean");
    Qsig = scanopt(mnmxmode,"sigma");
    Qtime = scanopt(mnmxmode,"time");
    if (!Qmin && !Qmax && !Qmean && !Qsig && !Qtime) 
        error("No mode selected");
#if 0
    pfmt = getparam("tab");
    if (pfmt!=NULL && *pfmt!=NULL) {
	dprintf(0,"Saving table in %s\n",pfmt);
        tabstr = stropen(pfmt,"w");
    } else
#endif
        tabstr = stdout;

    times = getparam("times");
    pfmt = getparam("format");
    strcpy (fmt,pfmt);
    if (strchr(fmt,' ')==NULL && strchr(fmt,',')==NULL)
        strcat (fmt," ");       /* append blank if user did not specify sep */

    get_history(instr);                 /* read history */

    for(;;) {                /* repeating until first or all times are read */
	get_history(instr);
        if (!get_tag_ok(instr, SnapShotTag))
            break;                                  /* done with work */
        get_snap(instr, &btab, &nbody, &tsnap, &bits);
        if (!streq(times,"all") && !within(tsnap,times,0.0001))
            continue;                   /* skip work on this snapshot */
        if ( (bits & ParticlesBit) == 0)
            continue;                   /* skip work, only diagnostics here */

            for (bp = btab, i=0; bp < btab+nbody; bp++, i++) {
                for (n=0; n<nopt; n++) {
                    aux = fopt[n](bp,tsnap,i);
                    if (i==0) ini_moment(&var[n],2,0);
                    accum_moment(&var[n], aux, 1.0);
                }
            }
            if (Qtime)
                fprintf(tabstr,fmt,tsnap);
            if (Qmin) {
                for (n=0; n<nopt; n++)
                    fprintf(tabstr,fmt,min_moment(&var[n]));
            }
            if (Qmax) {
                for (n=0; n<nopt; n++)
                    fprintf(tabstr,fmt,max_moment(&var[n]));
            }
            if (Qmean) {
                for (n=0; n<nopt; n++)
                    fprintf(tabstr,fmt,mean_moment(&var[n]));
            }
            if (Qsig) {
                for (n=0; n<nopt; n++)
                    fprintf(tabstr,fmt,sigma_moment(&var[n]));
            }
            fprintf(tabstr,"\n");
    
    }
    strclose(instr);
}
Exemplo n.º 15
0
int nemo_main()
{
    int i, n, nbody, bits, ndata, count, ngrid[3];
    real scale, dt, dtout, dtlog, tstop, tsnap, mass;
    string exefile = getparam("exe");
    string rundir = getparam("outdir");
    string fmt = getparam("format");
    stream datstr, instr, outstr;
    char dname[256];
    char command[256];
    char fmt6[256];
    float *gdata, *gd;
    Body *bp, *btab = NULL;

    if (hasvalue("header"))
      unfsize(getiparam("header"));

    n = nemoinpi(getparam("grid"),ngrid,3);
    if (n>0 && n<=3) {
        for (i=n; i<3; i++)
            ngrid[i] = ngrid[i-1];
    } else
        error("%d Syntax error: %s (need 1,2 or 3 integers)",
                n,getparam("grid"));
    scale = getdparam("scale");
    dt = getdparam("dt");
    dtout = getdparam("dtout");
    dtlog = getdparam("dtlog");
    tstop = getdparam("tstop");
    sprintf(fmt6,"%s %s %s %s %s %s\n",fmt,fmt,fmt,fmt,fmt,fmt);

    make_rundir(rundir);


    /* prepare the parameter file for galaxy */

    sprintf(dname,"%s/%s",rundir,"galaxy.dat");
    datstr = stropen(dname,"w");    
    fprintf(datstr,"%d %d %d\n",ngrid[0],ngrid[1],ngrid[2]);
    fprintf(datstr,"%g\n",scale);
    fprintf(datstr,"%g\n",dt);
    fprintf(datstr,"%g\n",dtout);
    fprintf(datstr,"%g\n",dtlog);
    fprintf(datstr,"%g\n",tstop);
    strclose(datstr);

    /* read snapshot and output it in something galaxy understands */

    instr = stropen(getparam("in"),"r");
    get_history(instr);
    if (!get_tag_ok(instr, SnapShotTag)) error("no snapshot");
    get_snap(instr, &btab, &nbody, &tsnap, &bits);
    strclose(instr);

    if ( (bits & PhaseSpaceBit) == 0) error("no phasespace");
    for (bp=btab;bp<btab+nbody; bp++)
      mass += Mass(bp);
    
    sprintf(dname,"%s/%s",rundir,"galaxy.ini");
    datstr = stropen(dname,"w");
    fprintf(datstr,"%g %g %d\n",tsnap,mass,nbody);
    for (bp=btab;bp<btab+nbody; bp++)
      fprintf(datstr,fmt6,
	      Pos(bp)[0],Pos(bp)[1],Pos(bp)[2],
	      Vel(bp)[0],Vel(bp)[1],Vel(bp)[2]);
    strclose(datstr);

    /* run the fortran program */

    goto_rundir(rundir);
    if (run_program(exefile))
      error("Problem executing %s",exefile);

    /* Output data from native galaxy (.res) format to snapshot */
    
    sprintf(dname,"%s","galaxy.res");
    instr = stropen(dname,"r");

    sprintf(dname,"%s","galaxy.snap");
    outstr = stropen(dname,"w");
    put_history(outstr);

    ndata = 7*sizeof(float)*nbody;
    gdata = (float *) allocate(ndata);

    bits = (TimeBit | PhaseSpaceBit | PotentialBit);
    while (1) {
      count = unfread(instr,gdata,ndata);
      if (count <= 0) break;
      printf("Time=%g\n",gdata[0]);
      tsnap = gdata[0];
      count = unfread(instr,gdata,ndata);
      if (count <= 0) error("Problem reading posvelphi from galaxy.res");
      for (bp=btab, gd=gdata;bp<btab+nbody; bp++) {
	Pos(bp)[0] = *gd++;
	Pos(bp)[1] = *gd++;
	Pos(bp)[2] = *gd++;
	Vel(bp)[0] = *gd++;
	Vel(bp)[1] = *gd++;
	Vel(bp)[2] = *gd++;
	Phi(bp)    = *gd++;
      }
      put_snap(outstr, &btab, &nbody, &tsnap, &bits);
    }
}
Exemplo n.º 16
0
void nemo_main()
{
    stream instr, outstr;
    real   mscale, pscale, xscale, tsnap, escale, dscale;
    vector rscale, vscale, ascale;
    string times;
    int i, nbody, bits, nrscale, nvscale, nascale, kscale;
    Body *btab = NULL, *bp;
    bool Qmass, Qphase, Qacc, Qpot, Qkey, Qaux, Qeps, Qdens;

    nrscale = nemoinpr(getparam("rscale"),rscale,NDIM);     /* RSCALE */
    if (nrscale==1) 
    	for (i=1; i<NDIM; i++)
    	   rscale[i] = rscale[0];
    else if (nrscale!=NDIM)
    	error("keyword rscale needs either 1 or %d numbers", NDIM);
    			

    nvscale = nemoinpr(getparam("vscale"),vscale,NDIM);     /* VSCALE */
    if (nvscale==1)
    	for (i=1; i<NDIM; i++)
    	   vscale[i] = vscale[0];
    else if (nvscale!=NDIM)
    	error("keyword vscale needs either 1 or %d numbers", NDIM);    

    nascale = nemoinpr(getparam("ascale"),ascale,NDIM);     /* ASCALE */
    if (nascale==1)
    	for (i=1; i<NDIM; i++)
    	   ascale[i] = ascale[0];
    else if (nascale!=NDIM)
    	error("keyword ascale needs either 1 or %d numbers", NDIM);    

    mscale = getdparam("mscale");
    pscale = getdparam("pscale");
    xscale = getdparam("xscale");
    dscale = getdparam("dscale");
    escale = getdparam("escale");
    kscale = getiparam("kscale");
    times = getparam("times");

    instr = stropen(getparam("in"), "r");   /* open files */
    outstr = stropen(getparam("out"), "w");

    get_history(instr);
    put_history(outstr);		
    for (;;) {
    	get_history(instr);		/* skip over stuff we can forget */
        if (!get_tag_ok(instr, SnapShotTag))
		break;			/* done with work in loop */
        get_snap(instr, &btab, &nbody, &tsnap, &bits);
        if ((bits & MassBit) == 0 && (bits & PhaseSpaceBit) == 0) {
	    continue;       /* just skip it's probably a diagnostics */
        }

        if ((bits & TimeBit) == 0)
	    tsnap = 0.0;
        else if (!streq(times,"all") && !within(tsnap, times, TIMEFUZZ))
            continue;
        dprintf (1,"Scaling snapshot at time= %f bits=0x%x\n",tsnap,bits);

        Qmass  = MassBit & bits        && !uscalar(mscale);
        Qphase = PhaseSpaceBit & bits  &&(!uvector(rscale) || !uvector(vscale));
        Qacc   = AccelerationBit & bits&& !uvector(ascale);
        Qpot   = PotentialBit & bits   && !uscalar(pscale);
        Qaux   = AuxBit & bits         && !uscalar(xscale);
        Qkey   = KeyBit & bits         && (kscale!=1);
        Qdens  = DensBit & bits        && !uscalar(dscale);
        Qeps   = EpsBit & bits         && !uscalar(escale);

        dprintf(1,"Scaling: ");
        if (Qmass)  dprintf(1," mass");
        if (Qphase) dprintf(1," phase");
        if (Qacc)   dprintf(1," acc");
        if (Qpot)   dprintf(1," pot");
        if (Qaux)   dprintf(1," aux");
        if (Qkey)   dprintf(1," key");
        if (Qdens)  dprintf(1," dens");
        if (Qeps)   dprintf(1," eps");
        dprintf(1,"\n");

        if (Qmass || Qphase || Qacc || Qpot || Qaux || Qkey || Qdens || Qeps) {
            for (bp = btab; bp < btab+nbody; bp++) {
                if(Qmass) Mass(bp) *= mscale;
                if(Qphase) {
                    SMULVV(Pos(bp),rscale);
                    SMULVV(Vel(bp),vscale);
	        }
                if(Qpot) Phi(bp) *= pscale;
                if(Qacc) {
                    SMULVV(Acc(bp),ascale);
                }
                if(Qaux) Aux(bp) *= xscale;
                if(Qkey) Key(bp) *= kscale;
		if(Qdens) Dens(bp) *= dscale;
		if(Qeps) Eps(bp) *= escale;
            }
        } else {
            warning("No scaling applied to snapshot");
	}

        put_snap(outstr, &btab, &nbody, &tsnap, &bits);
    }
}
Exemplo n.º 17
0
bool scansnap(void)
{
    bool success;
    int i;
    real *pptr, *xptr;
    

    success = FALSE;
    while (! success) {
	get_history(instr);
	if (! get_tag_ok(instr, SnapShotTag))
	    return (FALSE);
	get_set(instr, SnapShotTag);
	get_set(instr, ParametersTag);
	if (get_tag_ok(instr, TimeTag)) {
	    if (timeptr == NULL)
		timeptr = (real *) allocate(sizeof(real));
	    get_data_coerced(instr, TimeTag, RealType, timeptr, 0);
	}
	if (get_tag_ok(instr, NobjTag))
	    get_data(instr, NobjTag, IntType, &nbody, 0);
	get_tes(instr, ParametersTag);
	if (get_tag_ok(instr, ParticlesTag) &&
	      (timeptr == NULL || streq(times, "all") ||
	         within(*timeptr, times, TIMEFUZZ))) {
	    get_set(instr, ParticlesTag);
	    if (get_tag_ok(instr, MassTag)) {
		if (massptr == NULL)
		    massptr = (real *) allocate(sizeof(real) * nbody);
		get_data_coerced(instr, MassTag, RealType, massptr,
				 nbody, 0);
	    }
	    if (get_tag_ok(instr, PhaseSpaceTag)) {
		if (phaseptr == NULL)
		    phaseptr = (real *) allocate(sizeof(real) * 2*NDIM * nbody);
		get_data_coerced(instr, PhaseSpaceTag, RealType, phaseptr,
				 nbody, 2, NDIM, 0);
		success = TRUE;
	    } else if (get_tag_ok(instr, PosTag)) {
	        real *ptmp = (real *) allocate(sizeof(real)*nbody*NDIM);
		if (phaseptr == NULL)
		    phaseptr = (real *) allocate(sizeof(real) * 2*NDIM * nbody);
		get_data_coerced(instr, PosTag, RealType, ptmp, nbody, NDIM, 0);

		for (i=0, pptr=phaseptr, xptr=ptmp; i<nbody; i++) {
		  *pptr++ = *xptr++;
		  *pptr++ = *xptr++;
		  if (NDIM==3) *pptr++ = *xptr++;
		  pptr += NDIM;
		}
		get_data_coerced(instr, VelTag, RealType, ptmp, nbody, NDIM, 0);
		for (i=0, pptr=phaseptr+NDIM, xptr=ptmp; i<nbody; i++) {
		  *pptr++ = *xptr++;
		  *pptr++ = *xptr++;
		  if (NDIM==3) *pptr++ = *xptr++;
		  pptr += NDIM;
		}
		free(ptmp);
		success = TRUE;
	    }
	    if (get_tag_ok(instr, PotentialTag)) {
		if (phiptr == NULL)
		    phiptr = (real *) allocate(sizeof(real) * nbody);
		get_data_coerced(instr, PotentialTag, RealType, phiptr,
				 nbody, 0);
	    }
	    if (get_tag_ok(instr, AccelerationTag)) {
		if (accptr == NULL)
		    accptr = (real *) allocate(sizeof(real) * NDIM * nbody);
		get_data_coerced(instr, AccelerationTag, RealType, accptr,
				 nbody, NDIM, 0);
	    }
	    if (get_tag_ok(instr, AuxTag)) {
		if (auxptr == NULL)
		    auxptr = (real *) allocate(sizeof(real) * nbody);
		get_data_coerced(instr, AuxTag, RealType, auxptr,
				 nbody, 0);
	    }
	    get_tes(instr, ParticlesTag);
	    xpnt = (float *) allocate(sizeof(float)*nbody);
	    ypnt = (float *) allocate(sizeof(float)*nbody);
	    zpnt = (float *) allocate(sizeof(float)*nbody);
	}
	get_tes(instr, SnapShotTag);
    }
    return TRUE;
}
Exemplo n.º 18
0
void nemo_main()
{
    stream instr, outstr;
    real   tsnap, dr, aux, t0, dt;
    string times;
    Body *btab = NULL, *bp, *bq;
    int i, j, k, n, nbody, bits, nopt, ParticlesBit, ntime;
    char fmt[20],*pfmt;
    string *burststring(), *opt;
    rproc btrtrans(), fopt[MAXOPT];
    imageptr iptr = NULL; 
    bool Qfirst = getbparam("first");

    ParticlesBit = (MassBit | PhaseSpaceBit | PotentialBit | AccelerationBit |
            AuxBit | KeyBit | DensBit | EpsBit);
    instr = stropen(getparam("in"), "r");	
    outstr = stropen(getparam("out"), "w");

    opt = burststring(getparam("options"),", ");
    nopt = 0;					/* count options */
    while (opt[nopt]) {				/* scan through options */
        fopt[nopt] = btrtrans(opt[nopt]);
        nopt++;
        if (nopt==MAXOPT) {
            dprintf(0,"\n\nMaximum number of options = %d exhausted\n",MAXOPT);
            break;
        }
    }
    times = getparam("times");
    ntime = (hasvalue("ntime") ? getiparam("ntime") : 1);
    
    for(;;) {                /* repeating until first or all times are read */
	get_history(instr);
        if (!get_tag_ok(instr, SnapShotTag))
            break;                                  /* done with work */
        get_snap(instr, &btab, &nbody, &tsnap, &bits);
        if (!streq(times,"all") && !within(tsnap,times,0.0001))
            continue;                   /* skip work on this snapshot */
        if ( (bits & ParticlesBit) == 0)
            continue;                   /* skip work, only diagnostics here */
	dprintf(1,"Time=%g\n",tsnap);
	if (iptr == NULL) {
	  create_cube(&iptr,nbody,nopt,ntime);
	  k=0;
	  t0 = tsnap;
	  if (k==0) dt = 0.0;
	} 
	if (k==1) dt=tsnap-t0;    /* should be good for the whole snapshot */
	for (j=0; j<nopt; j++) {
	  for (bp = btab, i=0; bp < btab+nbody; bp++, i++) {
	    CubeValue(iptr,i,j,k) = fopt[j](bp,tsnap,i);
	  }
	}
	k++;

	if (k==ntime)  { /* cube is full */
	  fixheader(iptr,getparam("options"),t0,dt);
	  write_image(outstr,iptr);
	  free_image(iptr);
	  iptr = NULL;
	  k = 0;
	  if (Qfirst) break;
	}
    }
    if (!Qfirst && k) {
      warning("k=%d something not written yet, possible trailing garbage written",k);
      fixheader(iptr,getparam("options"),t0,dt);
      write_image(outstr,iptr);
    }
    strclose(instr);
    strclose(outstr);
}
Exemplo n.º 19
0
Arquivo: image.c Projeto: jobovy/nemo
int read_image (stream instr, imageptr *iptr)
{
    string read_matdef;
    int nx=0, ny=0, nz=0;
    size_t  nxyz;

    get_history(instr);         /* accumulate history */

    if (!get_tag_ok (instr,ImageTag))
        return 0;			/* not an image available */
        
    if (*iptr==NULL) {		/* allocate image if neccessary */
    	*iptr = (imageptr ) allocate(sizeof(image));
	dprintf (DLEV,"Allocated image @ %d ",*iptr);
    } else {
        nx = Nx(*iptr);
        ny = Ny(*iptr);
        nz = Nz(*iptr);
    	dprintf (DLEV,"Image %dx%dx%d already allocated @ %d\n",
		 nx,ny,nz,*iptr);
    }
    	
    get_set (instr,ImageTag);
        get_set (instr,ParametersTag);
            get_data (instr,NxTag,IntType, &(Nx(*iptr)), 0);
            get_data (instr,NyTag,IntType, &(Ny(*iptr)), 0);
            get_data (instr,NzTag,IntType, &(Nz(*iptr)), 0);
	    if ((nx>0 || ny>0 || nz>0) &&
		(nx != Nx(*iptr) || ny != Ny(*iptr) || nz != Nz(*iptr)))
	      error("Cannot read different sized images in old pointer yet");
	    if (get_tag_ok(instr,AxisTag))
	      get_data (instr,AxisTag,IntType, &(Axis(*iptr)), 0);
	    else
	      Axis(*iptr) = 0;
	    if (Axis(*iptr) == 1) {
	      get_data_coerced (instr,XrefTag,RealType, &(Xref(*iptr)), 0);
	      get_data_coerced (instr,YrefTag,RealType, &(Yref(*iptr)), 0);
	      get_data_coerced (instr,ZrefTag,RealType, &(Zref(*iptr)), 0);
	    } else {
	      Xref(*iptr) = 0.0;
	      Yref(*iptr) = 0.0;
	      Zref(*iptr) = 0.0;
	    }

            get_data_coerced (instr,XminTag,RealType, &(Xmin(*iptr)), 0);
            get_data_coerced (instr,YminTag,RealType, &(Ymin(*iptr)), 0);
            get_data_coerced (instr,ZminTag,RealType, &(Zmin(*iptr)), 0);
            get_data_coerced (instr,DxTag,RealType, &(Dx(*iptr)), 0);
            get_data_coerced (instr,DyTag,RealType, &(Dy(*iptr)), 0);
            get_data_coerced (instr,DzTag,RealType, &(Dz(*iptr)), 0);
	    get_data_coerced (instr,MapMinTag, RealType, &(MapMin(*iptr)), 0);
	    get_data_coerced (instr,MapMaxTag, RealType, &(MapMax(*iptr)), 0);
	    get_data (instr,BeamTypeTag, IntType, &(BeamType(*iptr)), 0);
	    get_data_coerced (instr,BeamxTag, RealType, &(Beamx(*iptr)), 0);
	    get_data_coerced (instr,BeamyTag, RealType, &(Beamy(*iptr)), 0);
	    get_data_coerced (instr,BeamzTag, RealType, &(Beamz(*iptr)), 0);
            if (get_tag_ok(instr,NamexTag))             /* X-axis name */
                Namex(*iptr) = get_string(instr,NamexTag);
            else
                Namex(*iptr) = NULL;
            if (get_tag_ok(instr,NameyTag))             /* Y-axis name */
                Namey(*iptr) = get_string(instr,NameyTag);
            else
                Namey(*iptr) = NULL;
            if (get_tag_ok(instr,NamezTag))             /* Z-axis name */
                Namez(*iptr) = get_string(instr,NamezTag);
            else
                Namez(*iptr) = NULL;
            if (get_tag_ok(instr,UnitTag))             /* units  */
                Unit(*iptr) = get_string(instr,UnitTag);
            else
                Unit(*iptr) = NULL;
            if (get_tag_ok(instr,TimeTag))             /* time  */
   	    	get_data_coerced (instr,TimeTag, RealType, &(Time(*iptr)), 0);
   	    else
   	    	Time(*iptr) = 0.0;
            read_matdef = get_string(instr,StorageTag);
	    if (!streq(read_matdef,matdef[idef]))
                dprintf(0,"read_image: StorageTag = %s, compiled with %s\n",
		        read_matdef, matdef[idef]);
         get_tes (instr,ParametersTag);

         get_set (instr,MapTag);
            if (Frame(*iptr)==NULL) {        /* check if allocated */
	        nxyz = Nx(*iptr)*Ny(*iptr)*Nz(*iptr);
                Frame(*iptr) = (real *) allocate(nxyz * sizeof(real));
                dprintf (DLEV,"Frame allocated @ %d ",Frame(*iptr));
            } else
                dprintf (DLEV,"Frame already allocated @ %d\n",Frame(*iptr));
	    if (Nz(*iptr)==1)
                get_data_coerced (instr,MapValuesTag,RealType, Frame(*iptr), 
                                Nx(*iptr), Ny(*iptr), 0);
            else
                get_data_coerced (instr,MapValuesTag,RealType, Frame(*iptr),
                                Nx(*iptr), Ny(*iptr), Nz(*iptr), 0);
         get_tes (instr,MapTag);
      get_tes (instr,ImageTag);

      set_iarray(*iptr);

      dprintf (DLEV,"Frame size %d * %d \n",Nx(*iptr), Ny(*iptr));
      
      return 1;		/* succes return code  */
}
Exemplo n.º 20
0
void nemo_main(void)
{
    stream instr, outstr;
    real   tsnap;
    string times, precision, keep;
    Body   *btab = NULL, *bpi, *bpo;
    int    i, nbody, nout, nreject, bitsi, bitso, vis, visnow, vismax;
    bool   Qall;
    iproc_body sfunc;

    times = getparam("times");
    sfunc = btitrans(getparam("select"));
    instr = stropen(getparam("in"), "r");
    outstr = stropen(getparam("out"), "w");
    precision = getparam("precision");	/* unused */
    if (!streq(precision,"double")) {
        warning("Precision \"%s\" not supported yet, use csf convert=d2f/f2d",
            precision);
    }
    keep = getparam("keep");
    bitso = 0;
    if (scanopt(keep,"all")) {
        Qall = TRUE;
    } else {
        Qall = FALSE;
        if (scanopt(keep,"mass"))
            bitso |= MassBit;
        if (scanopt(keep,"phase"))
            bitso |= PhaseSpaceBit;
        if (scanopt(keep,"phi"))
            bitso |= PotentialBit;
        if (scanopt(keep,"acc"))
            bitso |= AccelerationBit;
        if (scanopt(keep,"aux"))
            bitso |= AuxBit;
        if (scanopt(keep,"key"))
            bitso |= KeyBit;
        if (scanopt(keep,"time"))
            bitso |= TimeBit;
    }


    get_history(instr);
    put_history(outstr);		
    for (;;) {
    	get_history(instr);		/* skip over stuff we can forget */
        if (!get_tag_ok(instr, SnapShotTag))
		break;			/* done with work in loop */
        get_snap(instr, &btab, &nbody, &tsnap, &bitsi);
        if ((bitsi & MassBit) == 0 && (bitsi & PhaseSpaceBit) == 0) {
	    continue;       /* just skip */
        }
        				/* do some initial output */
        if ((bitsi & TimeBit) == 0) {	/* if not time flag */
        	tsnap = 0.0;		/* set time to zero */
		bitsi |= TimeBit;
		warning("time reset to 0");
        } else if (!streq(times,"all") && !within(tsnap, times, TIMEFUZZ))
        	continue;		/* now skip this snapshot */
        if (bitsi & KeyBit)
            dprintf(0,"Warning: Keyfield reinitialized\n");
        for (bpi = btab; bpi < btab+nbody; bpi++)
            Key(bpi) = 0;                    /* set to false */
        visnow = vismax = nreject = 0;
        do {				/* loop through all particles */
            visnow++;
            for (bpi = btab, i=0; i<nbody; bpi++,i++) {
                vis = (*sfunc)(bpi, tsnap, i);
		dprintf(2,"sfunc [%d] = %d\n",i,vis);
                vismax = MAX(vismax,vis);
                if (vis==visnow)
                    Key(bpi) = 1;
            }
        } while (visnow < vismax);          /* do all layers */
        nreject = 0;
        for (bpi = btab, bpo = btab, i=0; i<nbody; bpi++,i++) {
            if (!Key(bpi)) { 
               nreject++;       /* count number of stars rejected */
               continue;
            }
            if (nreject)        /* only copy while out of sync */
                bcopy (bpi, bpo, sizeof(Body));
            Key(bpo) = i;       /* counting from zero */
            bpo++;
            
        }
        nout = nbody - nreject;
        if (nout) {
            if (Qall) {             /* if all old things selected */
                if (nreject)        /* and some stars were rejected */
                    bitsi |= KeyBit;    /* then explicitly add Key field */
            } else
                bitsi = bitso;      
            put_snap(outstr, &btab, &nout, &tsnap, &bitsi);
            dprintf (1,"Snapshot time=%f copied %d particles\n",
				tsnap,nout);
        } else
           dprintf(0,"No particles to copy at tsnap=%f\n",tsnap);
    }
}
Exemplo n.º 21
0
void nemo_main()
{
    stream instr, tabstr = stdout;
    real   tsnap, dr, aux;
    string times;
    Body *btab = NULL, *bp, *bq;
    bool   Qhead, Qfirst = TRUE;
    int i, n, nbody, bits, nsep, isep, nopt, ParticlesBit;
    char fmt[20],*pfmt;
    string *opt;
    rproc_body fopt[MAXOPT];

#if defined(SINGLEPREC)
    warning("SINGLEPREC mode: data will not be in full precision");
#endif

    ParticlesBit = (MassBit | PhaseSpaceBit | PotentialBit | AccelerationBit |
            AuxBit | KeyBit | DensBit | EpsBit);
    instr = stropen(getparam("in"), "r");	/* open input file */
    Qhead = getbparam("header");

    opt = burststring(getparam("options"),", ");
    nopt = 0;					/* count options */
    while (opt[nopt]) {				/* scan through options */
        fopt[nopt] = btrtrans(opt[nopt]);
        nopt++;
        if (nopt==MAXOPT) {
            dprintf(0,"\n\nMaximum number of options = %d exhausted\n",MAXOPT);
            break;
        }
    }
    if (Qhead) {
	fprintf(tabstr,"# ");
	for (i=0; i<nopt; i++)
	  fprintf(tabstr,"%s ",opt[i]);
	fprintf(tabstr,"\n");
    }

    times = getparam("times");
    pfmt = getparam("format");
    strcpy (fmt,pfmt);
    if (strchr(fmt,' ')==NULL && strchr(fmt,',')==NULL)
        strcat (fmt," ");       /* append blank if user did not specify sep */

    get_history(instr);                 /* read history */
    for(;;) {                /* repeating until first or all times are read */
	get_history(instr);
        if (!get_tag_ok(instr, SnapShotTag))
            break;                                  /* done with work */
#if 0
        get_snap(instr, &btab, &nbody, &tsnap, &bits);
        if (!streq(times,"all") && !within(tsnap,times,0.0001))
            continue;                   /* skip work on this snapshot */
#else
        get_snap_by_t(instr, &btab, &nbody, &tsnap, &bits, times);	
#endif
        if ( (bits & ParticlesBit) == 0)
            continue;                   /* skip work, only diagnostics here */

	if (Qfirst)                     /* add blank line between snapshots */
	  Qfirst = FALSE;
	else
	  fprintf(tabstr," \n");
	fprintf(tabstr,"%d\n",nbody);
	fprintf(tabstr,fmt,tsnap);
	fprintf(tabstr,"\n");
	for (bp = btab, i=0; bp < btab+nbody; bp++, i++) {
	  for (n=0; n<nopt; n++) {
	    aux = fopt[n](bp,tsnap,i);
	    fprintf(tabstr,fmt,aux);
	  }
	  fprintf(tabstr,"\n");
	}
    }
    strclose(instr);
}
Exemplo n.º 22
0
Arquivo: xyio.c Projeto: 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;
}