示例#1
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);
}
示例#2
0
文件: gsp.c 项目: jasminegrosso/zeno
int main(int argc, string argv[])
{
    stream istr, ostr;
    gsprof *gsp;
    int np, i;
    real r0, lgrs, r;

    initparam(argv, defv);
    istr = stropen(getparam("in"), "r");
    get_history(istr);
    gsp = get_gsprof(istr);
    if (! strnull(getparam("out"))) {
	ostr = stropen(getparam("out"), "w");
	put_history(ostr);
	put_gsprof(ostr, gsp);
	strclose(ostr);
    }
    np = getiparam("npoint");
    r0 = 1.0 / getdparam("r0inv");
    lgrs = getdparam("lgrstep");
    printf("%12s%12s%12s%12s%12s%12s\n",
	   "radius", "log rho", "drho/dr", "mass", "mtot-mass", "radius(m)");
    for (i = 0; i < np; i++) {
	r = r0 * rpow(2.0, lgrs * i);
	printf("%12.5f%12.7f%12.3e%12.8f%12.8f%12.5f\n", r,
	       rlog10(rho_gsp(gsp, r)), drho_gsp(gsp, r),
	       mass_gsp(gsp, r), gsp->mtot - mass_gsp(gsp, r),
	       r_mass_gsp(gsp, mass_gsp(gsp, r)));
    }
    free_gsprof(gsp);
    return (0);
}
示例#3
0
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);
}
示例#4
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);
}
示例#5
0
int main(int argc, string argv[])
{
  string *mdtab, *names, *exprs, prog;
  int nexp = 0, i, j;

  initparam(argv, defv);
  mdtab = getmapdefs();				// get list of mapping vars
  for (i = 0; mdtab[i] != NULL; i += 2)
    if (getparamstat(mdtab[i]) & ARGPARAM)	// if var has assigned value
      nexp++;
  eprintf("[%s: %scounted %d variable assignments]\n", getprog(),
	  nexp > 0 ? "" : "warning: ", nexp);
  names = (string *) allocate(sizeof(string *) * (nexp + 1));
  exprs = (string *) allocate(sizeof(string *) * (nexp + 1));
  for (i = j = 0; mdtab[i] != NULL; i += 2)
    if (getparamstat(mdtab[i]) & ARGPARAM) {	// if var has assigned value
      exprs[j] = getparam(mdtab[i]);		// list value given as expr
      names[j] = mdtab[i+1];			// and name of access macro
      j++;
    }
  exprs[j] = names[j] = NULL;
  prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char)));
  buildmap(prog, names, exprs, NULL,
	   strnull(getparam("t")) ? NULL : getparam("t"),
	   Precision, NDIM, TRUE);
  execmap(prog);
  if (unlink(prog) != 0)
    error("%s: can't unlink %s\n", getargv0(), prog);
  return (0);
}
示例#6
0
int main(int argc, string argv[])
{
  real rrange[2], rmax;
  int np;
  double lgrs;
  gsprof *gsp;
  stream ostr;

  initparam(argv, defv);
  setrange(rrange, getparam("rrange"));
  np = getiparam("npoint");
  rmax = pow(2.0, floor(log2(32.0 / getdparam("alpha"))));
  if (rmax < rrange[1] && getbparam("smartrange")) {
    lgrs = log2(rrange[1] / rrange[0]) / (np - 1);
    np = 1 + log2(rmax / rrange[0]) / lgrs;
    eprintf("[%s: warning: npoint = %d -> %d  rrange[1] = %f -> %f]\n",
	    getprog(), getiparam("npoint"), np, rrange[1], rmax);
    rrange[1] = rmax;
  }
  gsp = gsp_expd(getdparam("mtot"), getdparam("alpha"), getdparam("zdisk"),
		 np, rrange[0], rrange[1]);
  ostr = stropen(getparam("out"), "w");
  put_history(ostr);
  gsp_write(ostr, gsp);
  fflush(NULL);
  return 0;
}
示例#7
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);
}
示例#8
0
int main(int argc, string argv[])
{
  stream istr, ostr;
  string times, *vecs, *produce, iotags[MaxBodyFields];
  bool expand;
  snapshot snap = { NULL, 0, 0.0 };

  initparam(argv, defv);
  istr = stropen(getparam("in"), "r");
  get_history(istr);
  ostr = stropen(getparam("out"), "w");
  put_history(ostr);
  times = getparam("times");
  vecs = burststring(getparam("vectors"), ", ");
  expand = streq(getparam("produce"), "*");
  if (! expand) {
    produce = burststring(getparam("produce"), ", ");
    layout_body(produce, Precision, NDIM);
  }
  while (get_snapshot_timed(istr, snap, iotags, expand, times)) {
    eprintf("[%s: rotating time %f]\n", getprog(), snap.time);
    snaprotate(&snap, iotags, vecs, getparam("order"), getbparam("invert"),
	       getdparam("thetax"), getdparam("thetay"), getdparam("thetaz"));
    put_snapshot(ostr, snap, iotags);
    skip_history(istr);
  }
  strclose(ostr);
  return (0);
}
示例#9
0
int main(int argc, string *argv)
{
  initparam(argv, defv);
  printf("program %s:\n", getprog());
  printf("  input = \"%s\" [%o]\n", getparam("input"),
	 getparamstat("input"));
  printf("  output = \"%s\" [%o]\n", getparam("output"),
	 getparamstat("output"));
  printf("  answer = %d [%o]\n", getiparam("answer"),
	 getparamstat("answer"));
  printf("  value = %g [%o]\n", getdparam("value"),
	 getparamstat("value"));
  printf("  flag = %s [%o]\n", getbparam("flag") ? "TRUE" : "FALSE",
	 getparamstat("flag"));
  printf("  foobar = \"%s\" [%o]\n", getparam("foobar"),
	 getparamstat("foobar"));
  printf("  VERSION = \"%s\" [%o]\n", getversion(),
	 getparamstat("VERSION"));
  if (getbparam("flag")) {
    printf("getparamstat(\"junk\") = %o\n", getparamstat("junk"));
    printf("calling getparam(\"junk\")\n");
    (void) getparam("junk");
  }
  return (0);
}
示例#10
0
int main(int argc, string argv[])
{
  string *datafields, *bodyfields, times, ifmt, rfmt;
  stream istr;
  bodyptr btab = NULL;
  int nbody;
  real tnow;
  string intags[MaxBodyFields];

  initparam(argv, defv);
  istr = stropen(getparam("in"), "r");
  get_history(istr);
  datafields = burststring(getparam("fields"), ", ");
  if (set_member(datafields, TimeTag))
    bodyfields = set_diff(datafields, set_cons(TimeTag, NULL));
  else
    bodyfields = datafields;
  layout_body(bodyfields, Precision, NDIM);
  times = getparam("times");
  ifmt = getparam("ifmt");
  rfmt = getparam("rfmt");
  print_header(datafields, getparam("hfmt"), getparam("keyhead"),
	       burststring(getparam("auxhead"), ", "));
  while (get_snap_t(istr, &btab, &nbody, &tnow, intags, FALSE, times)) {
    if (! set_subset(intags, bodyfields))
      error("%s: one or more required fields not found\n", getargv0());
    print_data(btab, nbody, tnow, datafields, ifmt, rfmt);
    skip_history(istr);
  }
  return (0);
}
示例#11
0
int main(int argc, string argv[])
{
  stream outstr;
  int nmodel;
  real tzero = 0.0;

  initparam(argv, defv);
  layout_body(bodyfields, Precision, NDIM);
  nbody = getiparam("nbody");
  nmodel = getiparam("nmodel");
  if (nbody < 1 || nmodel < 1)
    error("%s: absurd value for nbody or nmodel\n", getprog());
  btab = (bodyptr) allocate(nbody * SizeofBody);
  init_random(getiparam("seed"));
  outstr = stropen(getparam("out"), "w");
  put_history(outstr);
  while (--nmodel >= 0) {
    plummodel(getdparam("mfrac"));
    if (getbparam("besort"))
      qsort(btab, nbody, SizeofBody, berank);
    if (getbparam("zerocm"))
      snapcenter(btab, nbody, MassField.offset);
    put_snap(outstr, &btab, &nbody, &tzero, bodyfields);
    fflush(outstr);
  }
  return (0);
}
示例#12
0
int main(int argc, string argv[])
{
    stream istr;
    gsprof *tgsp, *mgsp;
    real beta_a, *sig2, rrange[2], lgrs, r;
    int np, i;

    initparam(argv, defv);
    istr = stropen(getparam("gsp"), "r");
    get_history(istr);
    tgsp = get_gsprof(istr);
    strclose(istr);
    if (! strnull(getparam("grav"))) {
        istr = stropen(getparam("grav"), "r");
        get_history(istr);
        mgsp = get_gsprof(istr);
        strclose(istr);
    } else
        mgsp = tgsp;
    beta_a = getdparam("beta_a");
    sig2 = calc_sig2_gsp(tgsp, mgsp, beta_a);
    np = getiparam("npoint");
    setrange(rrange, getparam("rrange"));
    lgrs = rlog2(rrange[1] / rrange[0]) / (np - 1);
    printf("%12s  %12s\n", "radius", "sig_r^2");
    for (i = 0; i < np; i++) {
        r = rrange[0] * rpow(2.0, lgrs * i);
        printf("%12.5f  %12.7f\n",
               r, sig2_gsp(tgsp, mgsp, beta_a, sig2, r));
    }
    return (0);
}
示例#13
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);
}
示例#14
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);
}
示例#15
0
int main (int argc, string argv[])
#endif
{
#ifndef SIM_SOCLIB
   long c;

   while ((c = getopt(argc, argv, "h")) != -1) {
     switch(c) {
      case 'h':
	Help();
	exit(-1);
	break;
      default:
	fprintf(stderr, "Only valid option is \"-h\".\n");
	exit(-1);
	break;
     }
   }
#endif

   Global = NULL;
   initparam(defv);
   startrun();
   initoutput();
   tab_init();

   Global->tracktime = 0;
   Global->partitiontime = 0;
   Global->treebuildtime = 0;
   Global->forcecalctime = 0;
   Global->current_id = 0;

   CLOCK(Global->computestart);

   printf("COMPUTESTART  = %12lu\n",Global->computestart);

   CREATE(SlaveStart, NPROC);

   WAIT_FOR_END(NPROC);

   CLOCK(Global->computeend);

   printf("COMPUTEEND    = %12lu\n",Global->computeend);
   printf("COMPUTETIME   = %12lu\n",Global->computeend - Global->computestart);
   printf("TRACKTIME     = %12lu\n",Global->tracktime);
   printf("PARTITIONTIME = %12lu\t%5.2f\n",Global->partitiontime,
	  ((float)Global->partitiontime)/Global->tracktime);
   printf("TREEBUILDTIME = %12lu\t%5.2f\n",Global->treebuildtime,
	  ((float)Global->treebuildtime)/Global->tracktime);
   printf("FORCECALCTIME = %12lu\t%5.2f\n",Global->forcecalctime,
	  ((float)Global->forcecalctime)/Global->tracktime);
   printf("RESTTIME      = %12lu\t%5.2f\n",
	  Global->tracktime - Global->partitiontime -
	  Global->treebuildtime - Global->forcecalctime,
	  ((float)(Global->tracktime-Global->partitiontime-
		   Global->treebuildtime-Global->forcecalctime))/
	  Global->tracktime);
   MAIN_END;
}
示例#16
0
void main(int argc, string argv[])
{
  initparam(argv, defv);
  if (within(getdparam("val"), getparam("range"), getdparam("fuzz")))
    printf("within returns TRUE\n");
  else
    printf("within returns FALSE\n");
}
示例#17
0
int main(int argc,char *argv[])
{
    if(argv[argc] != NULL) warning("Old-style (short) argv[] in main()");
    initparam(argv,defv);		/* start  */
    nemo_main();			/* call program */
    finiparam();			/* end */
    exit(0);                            /* return normal status to shell */
    return 0;				/* fool a strict compiler */
}
示例#18
0
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");
}
示例#19
0
int main(int argc, string argv[])
{
    initparam(argv, defv);
    readgsp();
    init_random(getiparam("seed"));
    layout_body(bodyfields, Precision, NDIM);
    gspmodel();
    writemodel();
    return (0);
}
示例#20
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);
}
示例#21
0
int main(int argc, string argv[])
{
  initparam(argv, defv);
  layout_body(bodyfields, Precision, NDIM);
  readsphr(getparam("in"));
  sphrprof();
  testdisk();
  if (! strnull(getparam("out")))
    writegal(getparam("out"));
  return (0);
}
示例#22
0
int main(int argc, string argv[])
{
    initparam(argv, defv);
    readgsp();
    init_random(getiparam("seed"));
    layout_body(bodyfields, Precision, NDIM);
    gspsphere();
    if (getbparam("zerocm"))
        snapcenter(btab, nbody, MassField.offset);
    writemodel();
    return (0);
}
示例#23
0
void main(int argc, string argv[])
{
  string type, name;

  initparam(argv, defv);
  type = getparam("type");
  name = getparam("name");
  printf("type_length(\"%s\") = %d\n", type, type_length(type));
  printf("type_name(\"%s\") = %s\n", type, type_name(type));
  printf("type_base(\"%s\") = %s\n", type, type_base(type));
  printf("type_fmt(\"%s\", TRUE) = %s\n", type, type_fmt(type, TRUE));
  printf("type_fmt(\"%s\", FALSE) = %s\n", type, type_fmt(type, FALSE));
  printf("name_type(\"%s\") = %s\n", name, name_type(name));
}
示例#24
0
文件: tsf.c 项目: jasminegrosso/zeno
int main(int argc, string argv[])
{
    string tag;

    initparam(argv, defv);
    instr = stropen(getparam("in"), "r");
    maxprec = getbparam("maxprec");
    maxline = getiparam("maxline");
    indent = getiparam("indent");
    margin = getiparam("margin");
    while ((tag = next_item_tag(instr)) != NULL) {
        print_item(tag);
	free(tag);
    }
    return (0);
}
示例#25
0
int main(int argc, string argv[])
{
    real rrange[2];
    gsprof *gsp;
    stream ostr;

    initparam(argv, defv);
    setrange(rrange, getparam("rrange"));
    gsp = plumgsp(getdparam("mtot"), getdparam("a"),
		  getiparam("npoint"), rrange[0], rrange[1]);
    ostr = stropen(getparam("out"), "w");
    put_history(ostr);
    put_gsprof(ostr, gsp);
    strclose(ostr);
    return (0);
}
示例#26
0
int main(int argc, string argv[])
{
  real mass_scale;

  initparam(argv, defv);
  nmax = getiparam("nmax");
  radius_tab = (double *) allocate(nmax * sizeof(double));
  density_tab = (double *) allocate(nmax * sizeof(double));
  mass_tab = (double *) allocate(nmax * sizeof(double));
  read_table(getparam("in"), getbparam("smooth"));
  integ_mass(getbparam("smooth"));
  fit_params();
  mass_scale = (strnull(getparam("mtot")) ? 1 : getdparam("mtot") / mtot);
  if (!strnull(getparam("out")))
    write_gsp(getparam("out"), mass_scale);
  return (0);
}
示例#27
0
int main(int argc, string argv[])
{
  initparam(argv, defv);			// initialize param access
  headline = defv[0] + 1;			// use default headline
  startrun();					// get params & input data
  startoutput();				// activate output code
  if (nstep == 0) {				// if data just initialized
    treeforce();				// calculate initial forces
    output();					// generate initial output
  }
  if (dtime != 0.0)				// if time steps requested
    while (tstop - tnow > 0.01 * dtime) {	// while not past tstop
      stepsystem();				// advance step by step
      output();					// output results each time
    }
  return (0);					// end with proper status
}
示例#28
0
int main(int argc, string argv[]) {
  initparam(argv, defv);			// initialize param access
  headline = defv[0] + 1;			// use default headline
  startrun();					// get params & input data
  startoutput();				// activate output code
  if (nstep == 0) {				// if data just initialized
    treeforce_initial_0 = wtime();
    treeforce();				// calculate initial forces
    treeforce_initial_1 = wtime();
    output();					// generate initial output
  }
  if (dtime != 0.0)				// if time steps requested
    // TODO: make this work in timesteps?
    treeforce_0 = wtime();
    while (nstep <= timesteps) { // while not past tstop
      stepsystem();       // advance step by step
      output();         // output results each time
    }
    // while (tstop - tnow > 0.01 * dtime) {	// while not past tstop
    //   stepsystem();				// advance step by step
    //   output();					// output results each time
    // }
    treeforce_1 = wtime();
  finaloutput();
  bodyptr p;
  bodyptr q;
  float phi = 0.0f;
  for (p = bodytab; p < bodytab+nbody; p++) {// loop over all bodies
    for (q = bodytab; q < bodytab+nbody; q++) {// loop over all bodies
    //  printf("Pos(p) = (%.8f,%.8f,%.8f)\n",  Pos(p)[0], Pos(p)[1], Pos(p)[2]);
    //  printf("Pos(q) = (%.8f,%.8f,%.8f)\n",  Pos(q)[0], Pos(q)[1], Pos(q)[2]);
      float rx = Pos(q)[0] - Pos(p)[0];
      float ry = Pos(q)[1] - Pos(p)[1];
      float rz = Pos(q)[2] - Pos(p)[2];
      float r2 = rx*rx + ry*ry + rz*rz + eps;
      float r2inv = 1.0 / sqrt(r2);
      float r6inv = r2inv * r2inv * r2inv;
      float mass = Mass(q);
      phi += mass * r6inv;
    }
  }
  printf(" Answer = %f\n", phi);
  return (0);					// end with proper status
}
示例#29
0
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);
}
示例#30
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);
}