int main(int argc, string argv[]) { string prog, itags[MaxBodyFields]; stream xstr; int nprof, nbody, nsamp; real *prof1, *prof2, rrange[2], tnow; bodyptr btab = NULL; initparam(argv, defv); layout_body(fields, Precision, NDIM); prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char))); xstr = execmap(prog); get_history(xstr); nprof = getiparam("nprof"); prof1 = (real *) allocate((2 + nprof) * sizeof(real)); prof2 = (real *) allocate((2 + nprof) * sizeof(real)); setrange(rrange, getparam("rrange")); nsamp = 0; while (get_snap(xstr, &btab, &nbody, &tnow, itags, FALSE)) { setprofile(prof1, prof2, nprof, rrange, btab, nbody); nsamp++; } if (unlink(prog) != 0) error("%s: can't unlink %s\n", getargv0(), prog); if (nsamp == 0) error("%s: no data in input\n", getargv0()); listdensity(prof1, prof2, nprof, rrange, nsamp); return (0); }
int main(int argc, string argv[]) { stream istr, ostr; bodyptr btab = NULL; int nbody; real tnow; string intags[MaxBodyFields]; gsprof *gsp; initparam(argv, defv); layout_body(bodyfields, Precision, NDIM); istr = stropen(getparam("in"), "r"); get_history(istr); if (! get_snap(istr, &btab, &nbody, &tnow, intags, FALSE)) error("%s: snapshot input failed\n", getargv0()); if (! set_member(intags, PosTag)) error("%s: position data missing\n", getargv0()); if (! set_member(intags, MassTag)) error("%s: mass data missing\n", getargv0()); gsp = snapgsp(btab, nbody, getiparam("npoint"), getdparam("alpha"), getdparam("beta")); if (! strnull(getparam("out"))) { ostr = stropen(getparam("out"), "w"); put_history(ostr); put_gsprof(ostr, gsp); strclose(ostr); } return (0); }
int main(int argc, string argv[]) { stream istr, ostr; real eps2, tnow; int nforce, nbody, i; bodyptr btab = NULL; string intags[MaxBodyFields]; initparam(argv, defv); layout_body(bodytags, Precision, NDIM); istr = stropen(getparam("in"), "r"); get_history(istr); ostr = stropen(getparam("out"), "w"); put_history(ostr); eps2 = rsqr(getdparam("eps")); nforce = -1; /* use nforce as flag... */ while (get_snap(istr, &btab, &nbody, &tnow, intags, FALSE)) { if (nforce == -1 && ! set_member(intags, MassTag)) error("%s: Mass data missing from 1st snapshot\n", getargv0()); if (! set_member(intags, PosTag)) error("%s: %s data missing\n", getargv0(), PosTag); if (nforce == -1) nforce = (strnull(getparam("nforce")) ? nbody : MIN(getiparam("nforce"), nbody)); for (i = 0; i < nforce; i++) sum1force(btab, nbody, i, eps2); put_snap(ostr, &btab, &nforce, &tnow, bodytags); } return (0); }
read_snap() { int bits; get_history(instr); get_snap(instr,&btab,&nobj,&tsnap,&bits); }
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); }
nemo_main() { stream instr, quadstr, outstr; Body *btab = NULL, *bp; int nbody, bits; real eps_r, eps_t, tsnap = 0.0; if (!hasvalue("out")) warning("No output supplied (out=)"); quadstr = stropen(getparam("quad"), "r"); get_history(quadstr); instr = stropen(getparam("in"), "r"); get_history(instr); get_quadfield(quadstr, &eps_r, &eps_t); get_snap(instr, &btab, &nbody, &tsnap, &bits); if (bits & PhaseSpaceBit == 0) error("not enuf info: bits = %o", bits); for (bp = btab; bp < btab+nbody; bp++) { CLRV(Acc(bp)); Phi(bp) = 0.0; } quadinter(btab, nbody, eps_r, eps_t); if (hasvalue("out")) { outstr = stropen(getparam("out"), "w"); put_history(outstr); bits = bits | PotentialBit | AccelerationBit; put_snap(outstr, &btab, &nbody, &tsnap, &bits); } }
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); }
int main(int argc, string argv[]) { stream istr, ostr; string itags[MaxBodyFields]; initparam(argv, defv); new_field(&LinkField, IntType, LinkTag); /* use int's worth of space */ new_field(&LinkField + 1, NULL, NULL); layout_body(bodytags, Precision, NDIM); istr = stropen(getparam("in"), "r"); get_history(istr); if (! get_snap(istr, &btab, &nbody, &tnow, itags, TRUE)) error("%s: snapshot input failed\n", getargv0()); if (! set_member(itags, PosTag)) error("%s: %s data missing\n", getargv0(), PosTag); if (getbparam("subkey") && ! set_member(itags, KeyTag)) error("%s: %s data missing\n", getargv0(), KeyTag); findobj(getdparam("bcrit"), getiparam("nmin"), getbparam("subkey")); ostr = stropen(getparam("out"), "w"); put_history(ostr); put_snap(ostr, &btab, &nbody, &tnow, set_union(itags, set_cons(KeyTag, NULL))); strclose(ostr); return (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); }
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); } }
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() */
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); }
void readsphr(string name) { stream instr; real tsnap; string infields[MaxBodyFields]; instr = stropen(name, "r"); get_history(instr); if (! get_snap(instr, &spheroid, &nspheroid, &tsnap, infields, FALSE)) error("readsphr in %s: no data in input file\n", getargv0()); strclose(instr); if (! (set_member(infields, MassTag) && set_member(infields, PosTag))) error("readsphr in %s: required data missing\n", getargv0()); }
int main(int argc, string argv[]) { stream istr, ostr; string itags1[MaxBodyFields], itags2[MaxBodyFields]; string *produce, *otags; bodyptr btab1 = NULL, btab2 = NULL, btab; int nbody1, nbody2, nbody; real tsnap; initparam(argv, defv); if (! streq(getparam("produce"), "*")) { produce = burststring(getparam("produce"), ", "); layout_body(produce, Precision, NDIM); } else produce = NULL; istr = stropen(getparam("in1"), "r"); get_history(istr); if (! get_snap(istr, &btab1, &nbody1, &tsnap, itags1, produce == NULL)) error("%s: no data in 1st input file\n"); istr = stropen(getparam("in2"), "r"); get_history(istr); if (! get_snap(istr, &btab2, &nbody2, &tsnap, itags2, FALSE)) error("%s: no data in 2nd input file\n"); otags = set_inter(itags1, itags2); if (produce != NULL) checktags(otags, produce); eprintf("[%s: nbody = %d + %d]\n", getargv0(), nbody1, nbody2); nbody = nbody1 + nbody2; btab = (bodyptr) allocate(SizeofBody * nbody); snapstack(btab, btab1, nbody1, btab2, nbody2, otags); ostr = stropen(getparam("out"), "w"); put_history(ostr); put_snap(ostr, &btab, &nbody, &tsnap, otags); strclose(ostr); return (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)); } }
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); }
int main(int argc, string argv[]) { stream fstr, istr, ostr; gsprof *gsp; bodyptr btab = NULL, p; int nbody; real tnow, r; string intags[MaxBodyFields]; initparam(argv, defv); layout_body(bodyfields, Precision, NDIM); fstr = stropen(getparam("gsp"), "r"); get_history(fstr); gsp = get_gsprof(fstr); istr = stropen(getparam("in"), "r"); get_history(istr); if (! get_snap(istr, &btab, &nbody, &tnow, intags, TRUE)) error("%s: snapshot input failed\n", getargv0()); if (! set_member(intags, PosTag)) error("%s: position data missing\n", getargv0()); if (streq(getparam("option"), "rho")) for (p = btab; p < NthBody(btab, nbody); p = NextBody(p)) Aux(p) = rho_gsp(gsp, absv(Pos(p))); else if (streq(getparam("option"), "drho")) for (p = btab; p < NthBody(btab, nbody); p = NextBody(p)) Aux(p) = drho_gsp(gsp, absv(Pos(p))); else if (streq(getparam("option"), "mass")) for (p = btab; p < NthBody(btab, nbody); p = NextBody(p)) Aux(p) = mass_gsp(gsp, absv(Pos(p))); else if (streq(getparam("option"), "phi")) for (p = btab; p < NthBody(btab, nbody); p = NextBody(p)) Aux(p) = phi_gsp(gsp, absv(Pos(p))); else error("%s: unknown option %s\n", getargv0(), getparam("option")); if (! strnull(getparam("out"))) { ostr = stropen(getparam("out"), "w"); put_history(ostr); put_snap(ostr, &btab, &nbody, &tnow, set_union(bodyfields, intags)); strclose(ostr); } return (0); }
int main(int argc, string argv[]) { stream istr; string bodytags[] = { PosTag, NULL }, intags[MaxBodyFields]; bodyptr btab = NULL, bp; int nbody, nshell, n; real tnow, vals[3]; matrix tmpm, qmat; vector v1, v2, v3; initparam(argv, defv); istr = stropen(getparam("in"), "r"); get_history(istr); layout_body(bodytags, Precision, NDIM); printf("#%11s %3s %11s %11s %11s\n", "time", "n", "r_rms", "c/a", "b/a"); while (get_snap(istr, &btab, &nbody, &tnow, intags, FALSE)) { if (! set_member(intags, PosTag)) error("%s: %s data missing\n", getargv0(), PosTag); if (nbody % getiparam("nbin") != 0) error("%s: nbin does not divide number of bodies\n", getargv0()); nshell = nbody / getiparam("nbin"); for (n = 0; n < nbody; n += nshell) { CLRM(qmat); for (bp = NthBody(btab, n); bp < NthBody(btab, n + nshell); bp = NextBody(bp)) { OUTVP(tmpm, Pos(bp), Pos(bp)); ADDM(qmat, qmat, tmpm); } eigensolve(v1, v2, v3, vals, qmat); printf(" %11.6f %3d %11.6f %11.6f %11.6f\n", tnow, n / nshell, rsqrt(tracem(qmat) / nshell), rsqrt(vals[2] / vals[0]), rsqrt(vals[1] / vals[0])); if (getbparam("listvec")) { printf("#\t\t\t\t\t\t\t%8.5f %8.5f %8.5f\n", v1[0], v1[1], v1[2]); printf("#\t\t\t\t\t\t\t%8.5f %8.5f %8.5f\n", v2[0], v2[1], v2[2]); printf("#\t\t\t\t\t\t\t%8.5f %8.5f %8.5f\n", v3[0], v3[1], v3[2]); } } } return (0); }
void inputdata(void) { stream instr; string intags[MaxBodyFields]; bodyptr p; bodytab = NULL; // request new input data instr = stropen(infile, "r"); // open input stream get_history(instr); // read file history data if (! get_snap(instr, &bodytab, &nbody, &tnow, intags, FALSE)) error("%s.inputdata: no data in input file\n", getprog()); strclose(instr); // close input stream if (! set_member(intags, MassTag) || ! set_member(intags, PosTag) || ! set_member(intags, VelTag)) error("%s.inputdata: essential data missing\n", getprog()); if (scanopt(options, "reset-time")) // reset starting time? tnow = 0.0; for (p = bodytab; p < bodytab+nbody; p++) // loop over new bodies Type(p) = BODY; // initializing body type }
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); } }
inputdata(string file) { stream instr; int bits; bodyptr p; instr = stropen(file, "r"); /* open input stream */ get_history(instr); /* read file history data */ if (ask_headline() != NULL) /* if headline was present */ headline = ask_headline(); /* set headline for run */ bodytab = NULL; /* request new input data */ get_snap(instr, &bodytab, &nbody, &tnow, &bits); /* invoke generic input */ strclose(instr); /* close input stream */ if ((bits & MassBit) == 0 || (bits & PhaseSpaceBit) == 0) error("inputdata: essential data missing\tbits = %o\n", bits); if ((bits & TimeBit) == 0 || scanopt(options, "reset_time")) /* time missing or reset? */ tnow = 0.0; /* then supply default */ for (p = bodytab; p < bodytab+nbody; p++) /* loop over new bodies */ Type(p) = BODY; /* init body type */ }
void inputdata() { stream instr; int bits; instr = stropen(infile, "r"); /* open input stream */ get_history(instr); #if 0 if (ask_headline() != NULL && streq(headline, "")) headline = ask_headline(); #endif bodytab = NULL; /* prepare input pointer */ nbody = 0; get_snap(instr, &bodytab, &nbody, &tnow, &bits); /* invoke generic input */ strclose(instr); /* close input stream */ if ((bits & MassBit) == 0 || (bits & PhaseSpaceBit) == 0) error("inputdata: essential data missing\tbits = 0x%x", bits); if (nbody > MBODY) error("inputdata: nbody(%d) > MBODY(%d) (recompile)", nbody,MBODY); if (scanopt(options, "reset_time") || (bits & TimeBit) == 0) /* no time specified? */ tnow = 0.0; /* then supply default */ }
bool getdata(void) { static bool firstcall = TRUE; string intags[MaxBodyFields]; bodyptr bp; get_history(instr); if (! get_snap(instr, &btab, &nbody, &tnow, intags, FALSE, getparam("times"))) return (FALSE); if (firstcall && ! set_member(intags, bodytags[0])) error("%s: required %s data missing\n", getargv0(), bodytags[0]); if (firstcall && ! set_member(intags, bodytags[1])) if (streq(bodytags[1], KeyTag)) { eprintf("[%s: using default point color]\n", getargv0()); for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) Key(bp) = pcolor; } else error("%s: required %s data missing\n", getargv0(), bodytags[1]); if (firstcall && bodytags[2] != NULL && ! set_member(intags, bodytags[2])) error("%s: required %s data missing\n", getargv0(), bodytags[2]); firstcall = FALSE; return (TRUE); }
void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { Ref<InputEventMouseMotion> mm = p_ev; if (mm.is_valid() && (mm->get_button_mask() & BUTTON_MASK_MIDDLE || (mm->get_button_mask() & BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) { h_scroll->set_value(h_scroll->get_value() - mm->get_relative().x); v_scroll->set_value(v_scroll->get_value() - mm->get_relative().y); } if (mm.is_valid() && dragging) { just_selected = true; // TODO: Remove local mouse pos hack if/when InputEventMouseMotion is fixed to support floats //drag_accum+=Vector2(mm->get_relative().x,mm->get_relative().y); drag_accum = get_local_mouse_position() - drag_origin; for (int i = get_child_count() - 1; i >= 0; i--) { GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (gn && gn->is_selected()) { Vector2 pos = (gn->get_drag_from() * zoom + drag_accum) / zoom; if (is_using_snap()) { int snap = get_snap(); pos = pos.snapped(Vector2(snap, snap)); } gn->set_offset(pos); } } } if (mm.is_valid() && box_selecting) { box_selecting_to = get_local_mouse_position(); box_selecting_rect = Rect2(MIN(box_selecting_from.x, box_selecting_to.x), MIN(box_selecting_from.y, box_selecting_to.y), ABS(box_selecting_from.x - box_selecting_to.x), ABS(box_selecting_from.y - box_selecting_to.y)); for (int i = get_child_count() - 1; i >= 0; i--) { GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (!gn) continue; Rect2 r = gn->get_rect(); r.size *= zoom; bool in_box = r.intersects(box_selecting_rect); if (in_box) gn->set_selected(box_selection_mode_aditive); else gn->set_selected(previus_selected.find(gn) != NULL); } top_layer->update(); } Ref<InputEventMouseButton> b = p_ev; if (b.is_valid()) { if (b->get_button_index() == BUTTON_RIGHT && b->is_pressed()) { if (box_selecting) { box_selecting = false; for (int i = get_child_count() - 1; i >= 0; i--) { GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (!gn) continue; gn->set_selected(previus_selected.find(gn) != NULL); } top_layer->update(); } else { if (connecting) { connecting = false; top_layer->update(); } else { emit_signal("popup_request", b->get_global_position()); } } } if (b->get_button_index() == BUTTON_LEFT && !b->is_pressed() && dragging) { if (!just_selected && drag_accum == Vector2() && Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { //deselect current node for (int i = get_child_count() - 1; i >= 0; i--) { GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (gn) { Rect2 r = gn->get_rect(); r.size *= zoom; if (r.has_point(get_local_mouse_position())) gn->set_selected(false); } } } if (drag_accum != Vector2()) { emit_signal("_begin_node_move"); for (int i = get_child_count() - 1; i >= 0; i--) { GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (gn && gn->is_selected()) gn->set_drag(false); } emit_signal("_end_node_move"); } dragging = false; top_layer->update(); update(); connections_layer->update(); } if (b->get_button_index() == BUTTON_LEFT && b->is_pressed()) { GraphNode *gn = NULL; for (int i = get_child_count() - 1; i >= 0; i--) { GraphNode *gn_selected = Object::cast_to<GraphNode>(get_child(i)); if (gn_selected) { if (gn_selected->is_resizing()) continue; if (gn_selected->has_point(gn_selected->get_local_mouse_position())) { gn = gn_selected; break; } } } if (gn) { if (_filter_input(b->get_position())) return; dragging = true; drag_accum = Vector2(); drag_origin = get_local_mouse_position(); just_selected = !gn->is_selected(); if (!gn->is_selected() && !Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { for (int i = 0; i < get_child_count(); i++) { GraphNode *o_gn = Object::cast_to<GraphNode>(get_child(i)); if (o_gn) o_gn->set_selected(o_gn == gn); } } gn->set_selected(true); for (int i = 0; i < get_child_count(); i++) { GraphNode *o_gn = Object::cast_to<GraphNode>(get_child(i)); if (!o_gn) continue; if (o_gn->is_selected()) o_gn->set_drag(true); } } else { if (_filter_input(b->get_position())) return; if (Input::get_singleton()->is_key_pressed(KEY_SPACE)) return; box_selecting = true; box_selecting_from = get_local_mouse_position(); if (b->get_control()) { box_selection_mode_aditive = true; previus_selected.clear(); for (int i = get_child_count() - 1; i >= 0; i--) { GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i)); if (!gn2 || !gn2->is_selected()) continue; previus_selected.push_back(gn2); } } else if (b->get_shift()) { box_selection_mode_aditive = false; previus_selected.clear(); for (int i = get_child_count() - 1; i >= 0; i--) { GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i)); if (!gn2 || !gn2->is_selected()) continue; previus_selected.push_back(gn2); } } else { box_selection_mode_aditive = true; previus_selected.clear(); for (int i = get_child_count() - 1; i >= 0; i--) { GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i)); if (!gn2) continue; gn2->set_selected(false); } } } } if (b->get_button_index() == BUTTON_LEFT && !b->is_pressed() && box_selecting) { box_selecting = false; previus_selected.clear(); top_layer->update(); } if (b->get_button_index() == BUTTON_WHEEL_UP && b->is_pressed()) { //too difficult to get right //set_zoom(zoom*ZOOM_SCALE); } if (b->get_button_index() == BUTTON_WHEEL_DOWN && b->is_pressed()) { //too difficult to get right //set_zoom(zoom/ZOOM_SCALE); } if (b->get_button_index() == BUTTON_WHEEL_UP && !Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() * b->get_factor() / 8); } if (b->get_button_index() == BUTTON_WHEEL_DOWN && !Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * b->get_factor() / 8); } if (b->get_button_index() == BUTTON_WHEEL_RIGHT || (b->get_button_index() == BUTTON_WHEEL_DOWN && Input::get_singleton()->is_key_pressed(KEY_SHIFT))) { h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * b->get_factor() / 8); } if (b->get_button_index() == BUTTON_WHEEL_LEFT || (b->get_button_index() == BUTTON_WHEEL_UP && Input::get_singleton()->is_key_pressed(KEY_SHIFT))) { h_scroll->set_value(h_scroll->get_value() - h_scroll->get_page() * b->get_factor() / 8); } } Ref<InputEventKey> k = p_ev; if (k.is_valid() && k->get_scancode() == KEY_D && k->is_pressed() && k->get_command()) { emit_signal("duplicate_nodes_request"); accept_event(); } if (k.is_valid() && k->get_scancode() == KEY_DELETE && k->is_pressed()) { emit_signal("delete_nodes_request"); accept_event(); } Ref<InputEventMagnifyGesture> magnify_gesture = p_ev; if (magnify_gesture.is_valid()) { set_zoom_custom(zoom * magnify_gesture->get_factor(), magnify_gesture->get_position()); } Ref<InputEventPanGesture> pan_gesture = p_ev; if (pan_gesture.is_valid()) { h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * pan_gesture->get_delta().x / 8); v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * pan_gesture->get_delta().y / 8); } }
void GraphEdit::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { port_grab_distance_horizontal = get_constant("port_grab_distance_horizontal"); port_grab_distance_vertical = get_constant("port_grab_distance_vertical"); } if (p_what == NOTIFICATION_READY) { Size2 hmin = h_scroll->get_combined_minimum_size(); Size2 vmin = v_scroll->get_combined_minimum_size(); v_scroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, -vmin.width); v_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0); v_scroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 0); v_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0); h_scroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 0); h_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0); h_scroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, -hmin.height); h_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0); zoom_minus->set_icon(get_icon("minus")); zoom_reset->set_icon(get_icon("reset")); zoom_plus->set_icon(get_icon("more")); snap_button->set_icon(get_icon("snap")); } if (p_what == NOTIFICATION_DRAW) { draw_style_box(get_stylebox("bg"), Rect2(Point2(), get_size())); if (is_using_snap()) { //draw grid int snap = get_snap(); Vector2 offset = get_scroll_ofs() / zoom; Size2 size = get_size() / zoom; Point2i from = (offset / float(snap)).floor(); Point2i len = (size / float(snap)).floor() + Vector2(1, 1); Color grid_minor = get_color("grid_minor"); Color grid_major = get_color("grid_major"); for (int i = from.x; i < from.x + len.x; i++) { Color color; if (ABS(i) % 10 == 0) color = grid_major; else color = grid_minor; float base_ofs = i * snap * zoom - offset.x * zoom; draw_line(Vector2(base_ofs, 0), Vector2(base_ofs, get_size().height), color); } for (int i = from.y; i < from.y + len.y; i++) { Color color; if (ABS(i) % 10 == 0) color = grid_major; else color = grid_minor; float base_ofs = i * snap * zoom - offset.y * zoom; draw_line(Vector2(0, base_ofs), Vector2(get_size().width, base_ofs), color); } } } if (p_what == NOTIFICATION_RESIZED) { _update_scroll(); top_layer->update(); } }
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); }
int main(int argc, string argv[]) { stream istr, ostr, gstr; real tnow, tgrav, eps2, tstop, dtime, tout, Mhqm, ahqm, bhqm, tol; real decrit, epot0, demin, demax, derms, de2avg, enow, denow; int nbody, ngrav; bodyptr btab = NULL, gtab = NULL, bp; string bdtags[MaxBodyFields], grtags[MaxBodyFields], *optags; gsprof *gravgsp = NULL; bool decrit_inc = FALSE; initparam(argv, defv); new_field(&EinitPBF, RealType, EinitTag); // define initial energy field layout_body(bodytags, Precision, NDIM); // layout necessary fields istr = stropen(getparam("in"), "r"); get_history(istr); if (! get_snap(istr, &btab, &nbody, &tnow, bdtags, TRUE)) error("%s: can't read input snapshot\n", getprog()); if (! (set_member(bdtags, PosTag) && set_member(bdtags, VelTag))) error("%s: required data missing from input snapshot\n", getprog()); #if defined(NBDGRAV) gstr = stropen(getparam("grav"), "r"); get_history(gstr); if (! get_snap(gstr, >ab, &ngrav, &tgrav, grtags, FALSE)) error("%s: can't read gravity snapshot\n", getprog()); if (! (set_member(grtags, MassTag) && set_member(grtags, PosTag))) error("%s: required data missing from gravity snapshot\n", getprog()); eps2 = rsqr(getdparam("eps")); #elif defined(GSPGRAV) gstr = stropen(getparam("grav"), "r"); get_history(gstr); gravgsp = get_gsprof(gstr); // read GSP for grav. field #elif defined(HQMGRAV) Mhqm = getdparam("M"); ahqm = getdparam("a"); bhqm = getdparam("b"); tol = getdparam("tol"); #endif ostr = stropen(getparam("out"), "w"); put_history(ostr); tstop = getdparam("tstop"); dtime = getdparam("dtime"); decrit = getdparam("decrit"); optags = burststring(getparam("outputs"), ","); #if defined(NBDGRAV) sumforces(btab, nbody, gtab, ngrav, eps2); // prime the pump... #elif defined(GSPGRAV) gspforces(btab, nbody, gravgsp); #elif defined(HQMGRAV) hqmforces(btab, nbody, Mhqm, ahqm, bhqm, tol); #endif epot0 = 0.0; // use as energy scale for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) { epot0 += Phi(bp) / nbody; // compute avg. potential Einit(bp) = Phi(bp) + dotvp(Vel(bp), Vel(bp)) / 2; } eprintf("[%s: initial average potential = %g]\n", getprog(), epot0); put_snap(ostr, &btab, &nbody, &tnow, optags); fflush(NULL); tout = tnow + getdparam("dtout"); demin = demax = derms = 0.0; // track maximum errors while (tnow < tstop) { // enter main loop for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) { ADDMULVS(Vel(bp), Acc(bp), 0.5 * dtime); // step velocities by dt/2 ADDMULVS(Pos(bp), Vel(bp), dtime); // step positions by dt } tnow = tnow + dtime; // step time to new value #if defined(NBDGRAV) if (! getbparam("frozen")) if (! get_snap(gstr, >ab, &ngrav, &tgrav, grtags, TRUE)) error("%s: can't read gravity snapshot\n", getprog()); sumforces(btab, nbody, gtab, ngrav, eps2); // get new accelerations #elif defined(GSPGRAV) gspforces(btab, nbody, gravgsp); #elif defined(HQMGRAV) hqmforces(btab, nbody, Mhqm, ahqm, bhqm, tol); #endif de2avg = 0.0; for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) { ADDMULVS(Vel(bp), Acc(bp), 0.5 * dtime); // step velocities by dt/2 enow = 0.5 * dotvp(Vel(bp), Vel(bp)) + Phi(bp); denow = (enow - Einit(bp)) / ABS(epot0); // compute rel. energy change demin = MIN(demin, denow); demax = MAX(demax, denow); de2avg += rsqr(denow) / nbody; } derms = MAX(derms, rsqrt(de2avg)); if (demin < -decrit || demax > decrit) { eprintf("[%s: warning: energy error exceeds %.4e at time = %-12.8f\n" " min,max,rms = %.6g,%.6g,%.6g threshold now %.4e]\n", getprog(), decrit, tnow, demin, demax, rsqrt(de2avg), decrit * rsqrt(2.0)); decrit = decrit * rsqrt(2.0); decrit_inc = TRUE; } if (tout <= tnow) { put_snap(ostr, &btab, &nbody, &tnow, optags); tout = tout + getdparam("dtout"); } fflush(NULL); } eprintf(decrit_inc ? "[%s: WARNING: energy error: min,max,rms = %.6g,%.6g,%.6g]\n" : "[%s: energy error: min,max,rms = %.6g,%.6g,%.6g]\n", getprog(), demin, demax, derms); return (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); } }
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); }
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); } }