void sphreport(stream ostr, smxptr sm, string options) { bodyptr *bptr = sm->kd->bptr; int i, nupd, nlev[MAXLEV+1], *rprof = sm->rprof; real rbsum, rbmin, rbmax, flev[MAXLEV+1], flev4, xi[NRPROF-1]; nupd = 0; for (i = 0; i <= MAXLEV; i++) nlev[i] = 0; rbsum = 0.0; for (i = 0; i < sm->kd->ngas; i++) { if (Update(bptr[i])) { nupd++; nlev[NewLevel(bptr[i])]++; rbsum += Smooth(bptr[i]); rbmin = (nupd == 1 ? Smooth(bptr[i]) : MIN(rbmin, Smooth(bptr[i]))); rbmax = (nupd == 1 ? Smooth(bptr[i]) : MAX(rbmin, Smooth(bptr[i]))); } } flev4 = 0.0; for (i = 0; i <= MAXLEV; i++) { flev[i] = 100.0 * ((real) nlev[i]) / ((real) nupd); if (i >= 4) flev4 += flev[i]; } fprintf(ostr, "\n%9s %9s %9s %9s %29s %9s\n", "log hmin", "log havg", "log hmax", "freqavg", "timestep level distribution", "CPUsph"); fprintf(ostr, "%9.4f %9.4f %9.4f %9.2f %5.1f %5.1f %5.1f %5.1f %5.1f %9.3f\n", rlog10(rbmin), rlog10(rbsum / nupd), rlog10(rbmax), sm->freqsum / nupd, flev[0], flev[1], flev[2], flev[3], flev4, cputime() - sm->cpustart); if (scanopt(options, "corrfunc")) { for (i = 0; i <= NRPROF - 2; i++) xi[i] = -1 + rpow(8.0, i/2.0) * (rprof[i] - rprof[i+1]) / ((1 - rsqrt(0.125)) * rprof[0]); fprintf(ostr, "\n "); for (i = NRPROF - 2; i >= 0; i--) fprintf(ostr, " xi%d", i); fprintf(ostr, "\n "); for (i = NRPROF - 2; i >= 0; i--) fprintf(ostr, "%6.2f", xi[i]); fprintf(ostr, "\n"); } if (scanopt(options, "levelhist")) { fprintf(ostr, "\n "); for (i = 0; i <= MAXLEV; i++) if (nlev[i] != 0) fprintf(ostr, i<10 ? " lev%d" : " lev%d", i); fprintf(ostr, "\n "); for (i = 0; i <= MAXLEV; i++) if (nlev[i] != 0) fprintf(ostr, "%6d", nlev[i]); fprintf(ostr, "\n"); } fflush(ostr); }
void mksymname(char *name, char *options) { char *cp=name; int upper=0, lower=0, underend=0; if (name==0 || *name==0) return; if (options==0 || *options == 0) { #if FORTRANIZE_LOWERCASE dprintf(0,"ftoc: using FORTRANIZE_LOWERCASE\n"); lower=1; #elif FORTRANIZE_UPPERCASE dprintf(0,"ftoc: using FORTRANIZE_UPPERCASE\n"); upper=1; #elif FORTRANIZE_LOWERCASE_UNDERSCORE dprintf(0,"ftoc: using FORTRANIZE_LOWERCASE_UNDERSCORE\n"); lower=1; underend=1; #elif FORTRANIZE_UPPERCASE_UNDERSCORE dprintf(0,"ftoc: using FORTRANIZE_UPPERCASE_UNDERSCORE\n"); upper=1; underend=1; #endif } else { dprintf(0,"%d %d %d\n",lower,upper,underend); if (scanopt(options,"lower")) lower=1; dprintf(0,"%d %d %d\n",lower,upper,underend); if (scanopt(options,"upper")) upper=1; dprintf(0,"%d %d %d\n",lower,upper,underend); if (scanopt(options,"under")) underend=1; dprintf(0,"%d %d %d\n",lower,upper,underend); } if (upper) { /* convert to upper case */ while (*cp) { if (islower(*cp)) *cp = toupper(*cp); cp++; } } if (lower) { /* convert to lower case */ while (*cp) { if (isupper(*cp)) *cp = tolower(*cp); cp++; } } if (underend) { /* append underscore */ while (*cp) cp++; *cp++ = '_'; *cp = '\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); }
output() { int nttot, nbavg, ncavg, k, bits; diagnostics(); /* compute std diagnostics */ nttot = n2bcalc + nbccalc; nbavg = (int) ((real) n2bcalc / (real) nfcalc); ncavg = (int) ((real) nbccalc / (real) nfcalc); printf("\n %10s%10s%10s%10s%10s%10s%10s\n", "tnow", "T+U", "T/U", "nttot", "nbavg", "ncavg", "cputime"); printf(" %10.3f%10.4f%10.4f%10d%10d%10d%10.2f\n\n", tnow, etot[0], etot[1]/etot[2], nttot, nbavg, ncavg, cputime()); printf("\t %10s", "cm pos"); for (k = 0; k < NDIM; k++) printf("%10.4f", cmphase[0][k]); printf("\n\t %10s", "cm vel"); for (k = 0; k < NDIM; k++) printf("%10.4f", cmphase[1][k]); printf("\n"); bits = 0; /* collect output bit flags */ if (minor_freqout > 0.0 && (minor_tout - 0.01/freq) <= tnow) { minor_tout += 1.0 / minor_freqout; bits |= TimeBit; } if (freqout > 0.0 && (tout - 0.01/freq) <= tnow) { tout += 1.0 / freqout; bits |= TimeBit | PhaseSpaceBit; if (scanopt(options, "mass") || firstmass) { bits |= MassBit; firstmass = FALSE; } if (scanopt(options, "phi")) bits |= PotentialBit; if (scanopt(options, "acc")) bits |= AccelerationBit; } if (bits != 0 && outstr != NULL) { /* output ready and able? */ put_snap(outstr, &bodytab, &nbody, &tnow, &bits); if (bits & PhaseSpaceBit) printf("\n\tparticle data written\n"); } if (*savefile) /* state file specified? */ savestate(savefile); /* save system data */ }
void main(int argc, string argv[]) { string opt, key; initparam(argv, defv); opt = getparam("opt"); key = getparam("key"); printf("scanopt(\"%s\", \"%s\") returns %s\n", opt, key, scanopt(opt, key) ? "true" : "false"); }
void write_snapshot(void) { real *mbuf, *mp, *pspbuf, *pspp; bodyptr bp; int cs = CSCode(Cartesian, NDIM, 2); string options = getparam("options"); mbuf = mp = (real *) allocate(ntest * sizeof(real)); pspbuf = pspp = (real *) allocate(ntest * 2 * NDIM * sizeof(real)); for (bp = testdata; bp < testdata+ntest; bp++) { *mp++ = Mass(bp); SETV(pspp, Pos(bp)); pspp += NDIM; SETV(pspp, Vel(bp)); pspp += NDIM; } put_set(outstr, SnapShotTag); put_set(outstr, ParametersTag); put_data(outstr, NobjTag, IntType, &ntest, 0); put_data(outstr, TimeTag, RealType, &tsnap, 0); put_data(outstr, "tol", RealType, &tol, 0); put_data(outstr, "eps", RealType, &eps, 0); put_tes(outstr, ParametersTag); put_set(outstr, ParticlesTag); put_data(outstr, CoordSystemTag, IntType, &cs, 0); if (scanopt(options, "mass")) put_data(outstr, MassTag, RealType, mbuf, ntest, 0); if (scanopt(options, "phase")) put_data(outstr, PhaseSpaceTag, RealType, pspbuf, ntest, 2, NDIM, 0); put_data(outstr, PotentialTag, RealType, phidata, ntest, 0); put_data(outstr, AccelerationTag, RealType, accdata, ntest, NDIM, 0); put_tes(outstr, ParticlesTag); put_set(outstr, DiagnosticsTag); put_data(outstr, "n2btot", IntType, &n2btot, 0); put_data(outstr, "nbctot", IntType, &nbctot, 0); put_data(outstr, "cputree", RealType, &cputree, 0); put_data(outstr, "cpufcal", RealType, &cpufcal, 0); put_tes(outstr, DiagnosticsTag); put_tes(outstr, SnapShotTag); free(mbuf); free(pspbuf); }
void output() { int k, bits; diagnostics(); printf("\n %12s%12s%12s%12s\n", "tnow", "T+U", "T/U", "cputime"); printf(" %12.3f%12.6f%12.4f%12.2f\n\n", tnow, etot[0], etot[1]/etot[2], cputime()); printf("\t %10s", "cm pos"); for (k = 0; k < NDIM; k++) printf("%10.4f", cmphase[0][k]); printf("\n\t %10s", "cm vel"); for (k = 0; k < NDIM; k++) printf("%10.4f", cmphase[1][k]); printf("\n"); bits = 0; if (minor_freqout > 0.0 && (minor_tout - 0.01/freq) <= tnow) { minor_tout += 1.0 / minor_freqout; bits |= TimeBit; } if (freqout > 0.0 && (tout - 0.01/freq) <= tnow) { tout += 1.0 / freqout; bits |= TimeBit | PhaseSpaceBit; if (firstmass || scanopt(options, "mass")) bits |= MassBit; firstmass = FALSE; if (scanopt(options, "phi")) bits |= PotentialBit; if (scanopt(options, "acc")) bits |= AccelerationBit; } if (bits != 0 && outstr != NULL) { put_snap(outstr, &bodytab, &nbody, &tnow, &bits); if (bits & PhaseSpaceBit) printf("\n\tparticle data written\n"); } if ((bits & PhaseSpaceBit) != 0 && quadstr != NULL) put_quadfield(quadstr); if (*savefile) /* state file specified? */ savestate(savefile); /* save system data */ }
void hackgrav(bodyptr p, bool intree) { pskip = p; /* exclude p from f.c. */ SETV(pos0, PosB(p)); /* set field point */ phi0 = 0.0; /* init total potential */ CLRV(acc0); /* and total acceleration */ n2bterm = nbcterm = 0; /* count body & cell terms */ skipself = FALSE; /* watch for tree-incest */ treescan((nodeptr) &root->cellnode); /* scan tree from root */ if (intree && ! skipself) { /* did tree-incest occur? */ if (! scanopt(options, "allow-incest")) /* treat as catastrophic? */ error("hackgrav: tree-incest detected\n"); if (! treeincest) /* for the first time? */ eprintf("\n[hackgrav: tree-incest detected]\n"); treeincest = TRUE; /* don't repeat warning */ } Phi(p) = phi0; /* store total potential */ SETV(Acc(p), acc0); /* and acceleration */ }
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 }
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 */ }
local void oldrun(void) { restorestate(getparam("restore")); // read in old state file if (getparamstat("eps") & ARGPARAM) // was eps given new value? eps = getdparam("eps"); // use command line value if (getparamstat("nstatic") & ARGPARAM) // likewise for others... nstatic = getiparam("nstatic"); #if !defined(QUICKSCAN) if (getparamstat("theta") & ARGPARAM) theta = getdparam("theta"); #endif if (getparamstat("usequad") & ARGPARAM) usequad = getbparam("usequad"); if (getparamstat("options") & ARGPARAM) options = getparam("options"); if (getparamstat("outputs") & ARGPARAM) outputs = getparam("outputs"); if (getparamstat("tstop") & ARGPARAM) tstop = getdparam("tstop"); if (getparamstat("dtout") & ARGPARAM) dtout = getdparam("dtout"); if (scanopt(options, "new-tout")) // if output time reset tout = tnow + dtout; // then offset from now }
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 */ }
startrun() { string restfile, contfile; bool scanopt(); proc get_potential(); infile = getparam("in"); /* set I/O file names */ outfile = getparam("out"); restfile = getparam("restart"); contfile = getparam("continue"); savefile = getparam("save"); options = getparam("options"); /* set control options */ debug = getbparam("hdebug"); if (debug) dprintf(0,"hdebug is turned on"); nrigid = getiparam("nrigid"); if (*contfile) /* resume interrupted run */ restorestate(contfile); else if (*restfile) { /* resume w/ new parameters */ restorestate(restfile); /* NOTE: someday, I will have a way to tell which, if any, of these * * parameters are actually input from the command line, and only * * change them. ANY NON-DEFAULT ARGS MUST BE SPECIFIED AT RESTART. */ eps = getdparam("eps"); /* get modified params */ tol = getdparam("tol"); options = getparam("options"); /* restorestate overwrite */ fcells = getdparam("fcells"); tstop = getdparam("tstop"); freqout = getdparam("freqout"); minor_freqout = getdparam("minor_freqout"); if (scanopt(options, "new_tout")) { /* reset output times? */ tout = tnow + 1 / freqout; /* offset from present */ minor_tout = tnow + 1 / minor_freqout; } } else { /* start new calculation */ if (*infile) /* was data file given? */ inputdata(infile); /* read inital data */ else { /* make initial conds? */ nbody = getiparam("nbody"); /* get nbody parameter */ if (nbody < 1) /* is value absurd? */ error("startrun: absurd nbody\n"); init_xrandom(getparam("seed")); /* set random generator */ testdata(getbparam("cencon")); /* make test model */ } freq = getdparam("freq"); /* get various parameters */ eps = getdparam("eps"); tol = getdparam("tol"); fcells = getdparam("fcells"); tstop = getdparam("tstop"); freqout = getdparam("freqout"); minor_freqout = getdparam("minor_freqout"); nstep = 0; /* start counting steps */ minor_tout = tout = tnow; /* schedule first output */ SETVS(rmin, -2.0); /* init box scaling */ rsize = -2.0 * rmin[0]; } contfile = getparam("potname"); if (*contfile) { extpot = get_potential(contfile, getparam("potpars"),getparam("potfile")); } }
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); }
nemo_main() { setparams(); read_data(); if (scanopt(method,"line")) { do_line(); } else if (scanopt(method,"ellipse")) { do_ellipse(); } else if (scanopt(method,"imageshift")) { do_imageshift(); } else if (scanopt(method,"plane")) { do_plane(); } else if (scanopt(method,"gauss1d")) { do_gauss1d(); } else if (scanopt(method,"gauss2d")) { do_gauss2d(); } else if (scanopt(method,"poly")) { do_poly(); } else if (scanopt(method,"area")) { do_area(); } else if (scanopt(method,"peak")) { do_peak(); } else if (scanopt(method,"zero")) { do_zero(); } else if (scanopt(method,"fourier")) { do_fourier(); } else error("fit=%s invalid; try [line,ellipse,imageshift,plane,gauss1d,gauss2d,poly,area,peak,zero,fourier]", getparam("fit")); if (outstr) strclose(outstr); }
void output(void) { real teff; int n; string outtags[MaxBodyFields]; char namebuf[256]; struct stat buf; stream outstr; string streamtags[] = { MassTag, PosTag, VelTag, PhiTag, AccTag, NULL }; diagnostics(); // compute std diagnostics if (logstr != NULL) { //fprintf(logstr, "\n %8s%8s%8s%8s%8s%8s%8s%8s\n", //"time", "|T+U|", "T", "-U", "-T/U", "|Vcom|", "|Jtot|", "CPUtot"); //fprintf(logstr, " %8.3f%8.4f%8.4f%8.4f%8.5f%8.5f%8.4f%8.2f\n", // tnow, ABS(etot[0]), etot[1], -etot[2], -etot[1]/etot[2], // absv(cmvel), absv(amvec), cputime()); } teff = tnow + dtime/8; // anticipate slightly... if (! strnull(outfile) && teff >= tout) { // time for data output? n = 0; if (scanopt(outputs, PosTag)) // if listed in outputs outtags[n++] = PosTag; // include tag in list if (scanopt(outputs, VelTag)) outtags[n++] = VelTag; if (scanopt(outputs, MassTag) || (nstep == 0)) outtags[n++] = MassTag; if (scanopt(outputs, PhiTag)) outtags[n++] = PhiTag; // select potential data if (scanopt(outputs, AccTag)) outtags[n++] = AccTag; // select acceleration data outtags[n] = NULL; sprintf(namebuf, outfile, nstep); // make up output file name if (stat(namebuf, &buf) != 0) { // no output file exists? outstr = stropen(namebuf, "w"); // create & open for output put_history(outstr); // write out hiatory data } else // else file already exists outstr = stropen(namebuf, "a"); // reopen and append output put_snap(outstr, &bodytab, &nbody, &tnow, outtags); strclose(outstr); // close up output file if (logstr != NULL) fprintf(logstr, "\n\tdata output to file %s at time %f\n", namebuf, tnow); tout += dtout; // schedule next output } if (! strnull(strfile)) { if (! streq(strfile, "-")) { sprintf(namebuf, strfile, nstep); if (stat(namebuf, &buf) != 0) { outstr = stropen(namebuf, "w"); put_history(outstr); } else outstr = stropen(namebuf, "a"); } else outstr = stdout; put_snap(outstr, &bodytab, &nbody, &tnow, streamtags); fflush(outstr); if (! streq(strfile, "-")) strclose(outstr); } if (! strnull(savefile)) // was state file given? savestate(savefile); // save data for restart forcehead = FALSE; // insure headers print fflush(NULL); // empty all output buffers }
int main(int argc, string argv[]) { glutInit(&argc, argv); initparam(argv, defv); instr = stropen(getparam("in"), "r"); refscale = getdparam("refscale"); if (! strnull(getparam("colordata"))) { /* color data wanted? */ if (getbparam("dopcolor")) error("%s: colordata precludes dopcolor\n", getargv0()); if (! scanopt(PhiTag "," SmoothTag "," RhoTag "," EntFuncTag "," UinternTag "," UdotIntTag "," UdotRadTag "," UdotVisTag "," TauTag "," BirthTag "," DeathTag "," AuxTag, getparam("colordata"))) error("%s: %s unknown\n", getargv0(), getparam("colordata")); bodytags[1] = getparam("colordata"); /* replace key w/ field... */ butbind[2] = COLORMAP; } else if (getbparam("dopcolor")) { dopcolor = TRUE; bodytags[1] = VelTag; /* replace key w/ velocity */ butbind[2] = COLORMAP; } if (! strnull(getparam("vectordata"))) { if (! scanopt(VelTag "," AccTag "," AuxVecTag, getparam("vectordata"))) error("%s: %s unknown\n", getargv0(), getparam("vectordata")); if (! (streq(getparam("vectordata"), VelTag) && dopcolor)) bodytags[2] = getparam("vectordata"); butbind[2] = VSCALE; } maxfast = getiparam("maxfast"); if (sscanf(getparam("defcolors"), "%x,%x", &pcolor, &bcolor) != 2) error("%s: can't scan defcolor parameter\n", getargv0()); if (sscanf(getparam("viewsize"), "%ix%i", &wscreen, &hscreen) != 2) error("%s: can't scan viewsize parameter\n", getargv0()); layout_body(bodytags, Precision, NDIM); if (! strnull(getparam("colordata"))) { scalaroff = streq(bodytags[1], PhiTag) ? PhiField.offset : streq(bodytags[1], SmoothTag) ? SmoothField.offset : streq(bodytags[1], RhoTag) ? RhoField.offset : streq(bodytags[1], EntFuncTag) ? EntFuncField.offset : streq(bodytags[1], UinternTag) ? UinternField.offset : streq(bodytags[1], UdotIntTag) ? UdotIntField.offset : streq(bodytags[1], UdotRadTag) ? UdotRadField.offset : streq(bodytags[1], UdotVisTag) ? UdotVisField.offset : streq(bodytags[1], TauTag) ? TauField.offset : streq(bodytags[1], BirthTag) ? BirthField.offset : streq(bodytags[1], DeathTag) ? DeathField.offset : streq(bodytags[1], AuxTag) ? AuxField.offset : -1; assert(scalaroff != -1); } if (! strnull(getparam("vectordata"))) { vectoroff = streq(getparam("vectordata"), VelTag) ? VelField.offset : streq(getparam("vectordata"), AccTag) ? AccField.offset : streq(getparam("vectordata"), AuxVecTag) ? AuxVecField.offset : -1; assert(vectoroff != -1); } if (! getdata()) error("%s: no data in input file\n", getargv0()); initgraphics(argv[0]); glutMainLoop(); return (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); } }
void flexinit (int argc, char **argv) { int i, sawcmpflag, rv, optind; char *arg; scanopt_t sopt; printstats = syntaxerror = trace = spprdflt = false; lex_compat = posix_compat = C_plus_plus = backing_up_report = ddebug = fulltbl = false; fullspd = long_align = nowarn = yymore_used = continued_action = false; do_yylineno = yytext_is_array = in_rule = reject = do_stdinit = false; yymore_really_used = reject_really_used = unspecified; interactive = csize = unspecified; do_yywrap = gen_line_dirs = usemecs = useecs = true; reentrant = bison_bridge_lval = bison_bridge_lloc = false; performance_report = 0; did_outfilename = 0; prefix = "yy"; yyclass = 0; use_read = use_stdout = false; tablesext = tablesverify = false; gentables = true; tablesfilename = tablesname = NULL; sawcmpflag = false; /* Initialize dynamic array for holding the rule actions. */ action_size = 2048; /* default size of action array in bytes */ action_array = allocate_character_array (action_size); defs1_offset = prolog_offset = action_offset = action_index = 0; action_array[0] = '\0'; /* Initialize any buffers. */ buf_init (&userdef_buf, sizeof (char)); /* one long string */ buf_init (&defs_buf, sizeof (char *)); /* list of strings */ buf_init (&yydmap_buf, sizeof (char)); /* one long string */ buf_init (&top_buf, sizeof (char)); /* one long string */ { const char * m4defs_init_str[] = {"m4_changequote\n", "m4_changequote([[, ]])\n"}; buf_init (&m4defs_buf, sizeof (char *)); buf_append (&m4defs_buf, &m4defs_init_str, 2); } sf_init (); /* initialize regex lib */ flex_init_regex(); /* Enable C++ if program name ends with '+'. */ program_name = basename (argv[0]); if (program_name != NULL && program_name[strlen (program_name) - 1] == '+') C_plus_plus = true; /* read flags */ sopt = scanopt_init (flexopts, argc, argv, 0); if (!sopt) { /* This will only happen when flexopts array is altered. */ fprintf (stderr, _("Internal error. flexopts are malformed.\n")); FLEX_EXIT (1); } while ((rv = scanopt (sopt, &arg, &optind)) != 0) { if (rv < 0) { /* Scanopt has already printed an option-specific error message. */ fprintf (stderr, _ ("Try `%s --help' for more information.\n"), program_name); FLEX_EXIT (1); } switch ((enum flexopt_flag_t) rv) { case OPT_CPLUSPLUS: C_plus_plus = true; break; case OPT_BATCH: interactive = false; break; case OPT_BACKUP: backing_up_report = true; break; case OPT_DONOTHING: break; case OPT_COMPRESSION: if (!sawcmpflag) { useecs = false; usemecs = false; fulltbl = false; sawcmpflag = true; } for (i = 0; arg && arg[i] != '\0'; i++) switch (arg[i]) { case 'a': long_align = true; break; case 'e': useecs = true; break; case 'F': fullspd = true; break; case 'f': fulltbl = true; break; case 'm': usemecs = true; break; case 'r': use_read = true; break; default: lerr (_ ("unknown -C option '%c'"), arg[i]); break; } break; case OPT_DEBUG: ddebug = true; break; case OPT_NO_DEBUG: ddebug = false; break; case OPT_FULL: useecs = usemecs = false; use_read = fulltbl = true; break; case OPT_FAST: useecs = usemecs = false; use_read = fullspd = true; break; case OPT_HELP: usage (); FLEX_EXIT (0); case OPT_INTERACTIVE: interactive = true; break; case OPT_CASE_INSENSITIVE: sf_set_case_ins(true); break; case OPT_LEX_COMPAT: lex_compat = true; break; case OPT_POSIX_COMPAT: posix_compat = true; break; case OPT_PREPROC_LEVEL: preproc_level = (int) strtol(arg,NULL,0); break; case OPT_MAIN: buf_strdefine (&userdef_buf, "YY_MAIN", "1"); do_yywrap = false; break; case OPT_NO_MAIN: buf_strdefine (&userdef_buf, "YY_MAIN", "0"); break; case OPT_NO_LINE: gen_line_dirs = false; break; case OPT_OUTFILE: outfilename = arg; did_outfilename = 1; break; case OPT_PREFIX: prefix = arg; break; case OPT_PERF_REPORT: ++performance_report; break; case OPT_BISON_BRIDGE: bison_bridge_lval = true; break; case OPT_BISON_BRIDGE_LOCATIONS: bison_bridge_lval = bison_bridge_lloc = true; break; case OPT_REENTRANT: reentrant = true; break; case OPT_NO_REENTRANT: reentrant = false; break; case OPT_SKEL: skelname = arg; break; case OPT_DEFAULT: spprdflt = false; break; case OPT_NO_DEFAULT: spprdflt = true; break; case OPT_STDOUT: use_stdout = true; break; case OPT_NO_UNISTD_H: //buf_strdefine (&userdef_buf, "YY_NO_UNISTD_H", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_UNISTD_H",0); break; case OPT_TABLES_FILE: tablesext = true; tablesfilename = arg; break; case OPT_TABLES_VERIFY: tablesverify = true; break; case OPT_TRACE: trace = true; break; case OPT_VERBOSE: printstats = true; break; case OPT_VERSION: printf (_("%s %s\n"), program_name, flex_version); FLEX_EXIT (0); case OPT_WARN: nowarn = false; break; case OPT_NO_WARN: nowarn = true; break; case OPT_7BIT: csize = 128; break; case OPT_8BIT: csize = CSIZE; break; case OPT_ALIGN: long_align = true; break; case OPT_NO_ALIGN: long_align = false; break; case OPT_ALWAYS_INTERACTIVE: buf_m4_define (&m4defs_buf, "M4_YY_ALWAYS_INTERACTIVE", 0); break; case OPT_NEVER_INTERACTIVE: buf_m4_define( &m4defs_buf, "M4_YY_NEVER_INTERACTIVE", 0); break; case OPT_ARRAY: yytext_is_array = true; break; case OPT_POINTER: yytext_is_array = false; break; case OPT_ECS: useecs = true; break; case OPT_NO_ECS: useecs = false; break; case OPT_HEADER_FILE: headerfilename = arg; break; case OPT_META_ECS: usemecs = true; break; case OPT_NO_META_ECS: usemecs = false; break; case OPT_PREPROCDEFINE: { /* arg is "symbol" or "symbol=definition". */ char *def; for (def = arg; *def != '\0' && *def != '='; ++def) ; buf_strappend (&userdef_buf, "#define "); if (*def == '\0') { buf_strappend (&userdef_buf, arg); buf_strappend (&userdef_buf, " 1\n"); } else { buf_strnappend (&userdef_buf, arg, (int) (def - arg)); buf_strappend (&userdef_buf, " "); buf_strappend (&userdef_buf, def + 1); buf_strappend (&userdef_buf, "\n"); } } break; case OPT_READ: use_read = true; break; case OPT_STACK: //buf_strdefine (&userdef_buf, "YY_STACK_USED", "1"); buf_m4_define( &m4defs_buf, "M4_YY_STACK_USED",0); break; case OPT_STDINIT: do_stdinit = true; break; case OPT_NO_STDINIT: do_stdinit = false; break; case OPT_YYCLASS: yyclass = arg; break; case OPT_YYLINENO: do_yylineno = true; break; case OPT_NO_YYLINENO: do_yylineno = false; break; case OPT_YYWRAP: do_yywrap = true; break; case OPT_NO_YYWRAP: do_yywrap = false; break; case OPT_YYMORE: yymore_really_used = true; break; case OPT_NO_YYMORE: yymore_really_used = false; break; case OPT_REJECT: reject_really_used = true; break; case OPT_NO_REJECT: reject_really_used = false; break; case OPT_NO_YY_PUSH_STATE: //buf_strdefine (&userdef_buf, "YY_NO_PUSH_STATE", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_PUSH_STATE",0); break; case OPT_NO_YY_POP_STATE: //buf_strdefine (&userdef_buf, "YY_NO_POP_STATE", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_POP_STATE",0); break; case OPT_NO_YY_TOP_STATE: //buf_strdefine (&userdef_buf, "YY_NO_TOP_STATE", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_TOP_STATE",0); break; case OPT_NO_UNPUT: //buf_strdefine (&userdef_buf, "YY_NO_UNPUT", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_UNPUT",0); break; case OPT_NO_YY_SCAN_BUFFER: //buf_strdefine (&userdef_buf, "YY_NO_SCAN_BUFFER", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_BUFFER",0); break; case OPT_NO_YY_SCAN_BYTES: //buf_strdefine (&userdef_buf, "YY_NO_SCAN_BYTES", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_BYTES",0); break; case OPT_NO_YY_SCAN_STRING: //buf_strdefine (&userdef_buf, "YY_NO_SCAN_STRING", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_STRING",0); break; case OPT_NO_YYGET_EXTRA: //buf_strdefine (&userdef_buf, "YY_NO_GET_EXTRA", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_EXTRA",0); break; case OPT_NO_YYSET_EXTRA: //buf_strdefine (&userdef_buf, "YY_NO_SET_EXTRA", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_EXTRA",0); break; case OPT_NO_YYGET_LENG: //buf_strdefine (&userdef_buf, "YY_NO_GET_LENG", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LENG",0); break; case OPT_NO_YYGET_TEXT: //buf_strdefine (&userdef_buf, "YY_NO_GET_TEXT", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_TEXT",0); break; case OPT_NO_YYGET_LINENO: //buf_strdefine (&userdef_buf, "YY_NO_GET_LINENO", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LINENO",0); break; case OPT_NO_YYSET_LINENO: //buf_strdefine (&userdef_buf, "YY_NO_SET_LINENO", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LINENO",0); break; case OPT_NO_YYGET_IN: //buf_strdefine (&userdef_buf, "YY_NO_GET_IN", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_IN",0); break; case OPT_NO_YYSET_IN: //buf_strdefine (&userdef_buf, "YY_NO_SET_IN", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_IN",0); break; case OPT_NO_YYGET_OUT: //buf_strdefine (&userdef_buf, "YY_NO_GET_OUT", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_OUT",0); break; case OPT_NO_YYSET_OUT: //buf_strdefine (&userdef_buf, "YY_NO_SET_OUT", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_OUT",0); break; case OPT_NO_YYGET_LVAL: //buf_strdefine (&userdef_buf, "YY_NO_GET_LVAL", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LVAL",0); break; case OPT_NO_YYSET_LVAL: //buf_strdefine (&userdef_buf, "YY_NO_SET_LVAL", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LVAL",0); break; case OPT_NO_YYGET_LLOC: //buf_strdefine (&userdef_buf, "YY_NO_GET_LLOC", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LLOC",0); break; case OPT_NO_YYSET_LLOC: //buf_strdefine (&userdef_buf, "YY_NO_SET_LLOC", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LLOC",0); break; case OPT_HEX: trace_hex = 1; break; case OPT_NO_SECT3_ESCAPE: no_section3_escape = true; break; } /* switch */ } /* while scanopt() */ scanopt_destroy (sopt); num_input_files = argc - optind; input_files = argv + optind; set_input_file (num_input_files > 0 ? input_files[0] : NULL); lastccl = lastsc = lastdfa = lastnfa = 0; num_rules = num_eof_rules = default_rule = 0; numas = numsnpairs = tmpuses = 0; numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst = 0; numuniq = numdup = hshsave = eofseen = datapos = dataline = 0; num_backing_up = onesp = numprots = 0; variable_trailing_context_rules = bol_needed = false; linenum = sectnum = 1; firstprot = NIL; /* Used in mkprot() so that the first proto goes in slot 1 * of the proto queue. */ lastprot = 1; set_up_initial_allocations (); }