Example #1
0
nemo_main()
{
  int n=getiparam("n");
  int iter=getiparam("iter");
  int m=getiparam("m");
  int seed = init_xrandom(getparam("seed"));
  int i,j,k,l;
  real *x, sum;
  real t0,t1,t2;

  init_timers(100);
  stamp_timers(0);

  x = (real *) allocate(n*sizeof(real));

  for (i=0; i<n; i++)         /* init the whole array */
    x[i] = xrandom(0.0,1.0);
  for (i=0; i<m; i++)         /* cache it in again ? */
    x[i] = xrandom(0.0,1.0);

  sum = 0.0;
  t0 = cputime();
  stamp_timers(1);
  if (m==0) {                         /* do it in one sweep, the N^2 algorithm */
    stamp_timers(2);
    for (l=0; l<iter;  l++)
      for (j=0; j<n; j++)
	for (i=0; i<n; i++)
	  sum += FUN(x[i],x[j]);
    stamp_timers(3);
  } else {                            /* N/M times a small M*M patch that may be in cache */
    stamp_timers(2);
    for (l=0; l<iter; l++)
      for (k=0; k<n-m; k++)
	for (j=k; j<k+m; j++)
	  for (i=k; i<k+m; i++)
	    sum += FUN(x[i],x[j]);
    stamp_timers(3);
  }
  stamp_timers(4);
  t1 = cputime();
  if (m)
    printf("%d %d %d sum=%lg Mops=%lg\n",
	 n,iter,m,sum,iter*m*m*n/(t1-t0)/60.0/1e6);
  else
    printf("%d %d %d sum=%lg Mops=%lg\n",
	 n,iter,m,sum,iter*n*n/(t1-t0)/60.0/1e6);
  stamp_timers(5);
  printf("%Ld %Ld %Ld %Ld %Ld\n",
	 diff_timers(0,1),
	 diff_timers(1,2),
	 diff_timers(2,3),
	 diff_timers(3,4),
	 diff_timers(4,5));
}
Example #2
0
void nemo_main()
{
    int seed;

    rmin = -0.5 * getdparam("size");
    rmax = -rmin;
    nbody = getiparam("nbody");
    sigma = getdparam("sigma");
    seed = init_xrandom(getparam("seed"));
    zerocm = getbparam("zerocm");
    mkcube();
    writegalaxy(getparam("out"), getparam("headline"));
    free(btab);
}
Example #3
0
void nemo_main()
{
    stream outstr;
    
    potential = get_potential(getparam("potname"),
                    getparam("potpars"), getparam("potfile"));
    rmin = getdparam("rmin");
    rmax = getdparam("rmax");
    rref = rmax;
    if (hasvalue("rref")) rref = getdparam("rref");
    Qkey = hasvalue("key");
    if (Qkey) key = getiparam("key");
    Qconstant = getbparam("constant");

    ndisk = getiparam("nbody");
    jz_sign = getiparam("sign");
    nmodel = getiparam("nmodel");
    totmass = getdparam("mass");
    offset = getdparam("phase") * PI / 180.0;    
    Qtest = getbparam("test");
    Quniform = getbparam("uniform");
    if (ABS(jz_sign) != 1) error("sign must be +1 or -1");

    Qlinear = hasvalue("k");
    if (Qlinear)
      SPk = getdparam("k");	/* corrected for rot counter clock wise */
    else if (hasvalue("pitch"))
      pitch = getdparam("pitch"); /* corrected for rot counter clock wise */
    else
      error("Either k= (linear) or pitch= (logarithmic) spiral indicator needed");
    
    init_xrandom(getparam("seed"));

    outstr = stropen(getparam("out"), "w");
    put_history(outstr);
    if (hasvalue("headline"))
	set_headline(getparam("headline"));
    setdensity();
    
    while (nmodel--) {
        testdisk(nmodel);
        writegalaxy(outstr);
    }
    strclose(outstr);
    free(disk);
}
Example #4
0
nemo_main()
{
    int seed;

    alpha = getdparam("alpha");
    rcut = getdparam("rcut");
    mdisk = getdparam("mdisk");
    Qtoomre = getdparam("Qtoomre");
    gammas = getdparam("gamma");
    ndisk = getiparam("nbody");
    z0 = getdparam("z0");             /* was called epsi in mkbaredisk */
    cmode = getiparam("mode");
    zmode = getiparam("zmode");
    seed = init_xrandom(getparam("seed"));
    Qtab = getbparam("tab");
    inittables();
    makedisk();
    writesnap(getparam("out"), getparam("headline"));
}
Example #5
0
File: code.c Project: jobovy/nemo
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"));
    }
}
Example #6
0
void
parse_command_line(int argc, char *argv[], int spec)
{
    const char *arg, *aispec;
    char tmpspec[100], tmpargbuf[CLIBUFSIZE], blurb[BLURBSIZE];
    int i, n, numused, total_arg_space, tmpargbuflen = 0;

/* This macro just checks that a required next argument is actually
   there. */

#define REQUIRE_ONE_ARG  \
  if (i + 1 >= argc) {  \
    fprintf(stderr, "Error: `%s' requires an argument, exiting now\n", argv[i]);  \
    had_error = TRUE;  \
    continue;  \
  }  \
  numused = 2;

/* Each of these causes argument parsing to skip over the option if
   it's not the right time to look at it. */

#define GENERAL_OPTION if (spec != general_options) continue;
#define VARIANT_OPTION if (spec != variant_options) continue;
#define PLAYER_OPTION  if (spec != player_options)  continue;

    /* (should peel off any path stuff) */
    program_name = argv[0];

    if (spec == general_options)
      init_options();

    total_arg_space = 0;
    for (i = 0; i < argc; ++i) {
      if (!empty_string(argv[i])) {
        strncpy(tmpargbuf, argv[i], CLIBUFSIZE);
        tmpargbuf[CLIBUFSIZE - 1] = 0;
        tmpargbuflen = strlen(tmpargbuf);
	total_arg_space += tmpargbuflen + 2;
        (argv[i])[tmpargbuflen] = 0; 
      }
    }
    if (args_used == NULL)
      args_used = (char *)xmalloc (total_arg_space);

    for (i = 1; i < argc; ++i) {
	if (argv[i] == NULL || (argv[i])[0] == '\0') {
	    /* Empty or already munched, nothing to do. */
	} else if ((argv[i])[0] == '-') {
	    arg = argv[i];
	    Dprintf("%s\n", arg);
	    numused = 1;
	    if (strcmp(arg, "-c") == 0) {
		REQUIRE_ONE_ARG;
		GENERAL_OPTION;
		checkpoint_interval = atoi(argv[i+1]);
	    } else if (strcmp(arg, "-design") == 0) {
		GENERAL_OPTION;
#ifdef DESIGNERS
		allbedesigners = TRUE;
#else
		fprintf(stderr,
			"No designing available, ignoring option `%s'\n", arg);
#endif /* DESIGNERS */
	    } else if (strncmp(arg, "-D", 2) == 0) {
		GENERAL_OPTION;
#ifdef DEBUGGING
		Debug = TRUE;
		if (strchr(arg+2, '-'))
		  Debug = FALSE;
		if (strchr(arg+2, 'M'))
		  DebugM = TRUE;
		if (strchr(arg+2, 'G'))
		  DebugG = TRUE;
#else
		fprintf(stderr,
			"No debugging available, ignoring option `%s'\n", arg);
#endif /* DEBUGGING */
	    } else if (strncmp(arg, "-e", 2) == 0) {
		REQUIRE_ONE_ARG;
		PLAYER_OPTION;
		n = atoi(argv[i+1]);
		/* A comma indicates that the name of a particular
		   desired AI type follows. */
		if (strlen(arg) > 2) {
		    aispec = arg + 2;
		    if (*aispec != ',') {
			sprintf(tmpspec, "%s%s", default_ai_type, aispec);
			aispec = tmpspec;
		    }
		} else {
		    aispec = default_ai_type;
		}
		while (n-- > 0)
		  add_a_raw_player_spec(aispec);
	    } else if (strcmp(arg, "-f") == 0) {
		REQUIRE_ONE_ARG;
		GENERAL_OPTION;
		add_a_module(NULL, argv[i+1]); 
	    } else if (strcmp(arg, "-g") == 0) {
		REQUIRE_ONE_ARG;
		GENERAL_OPTION;
		add_a_module(copy_string(argv[i+1]), NULL);
	    } else if (strcmp(arg, "-h") == 0) {
		REQUIRE_ONE_ARG;
		PLAYER_OPTION;
		n = atoi(argv[i+1]);
		option_num_to_wait_for += n;
		while (n-- > 0)
		  add_a_raw_player_spec("?@");
	    } else if (strcmp(arg, "-help") == 0) {
		GENERAL_OPTION;
		help_wanted = TRUE;
		/* Will display help info later. */
	    } else if (strcmp(arg, "-host") == 0) {
		REQUIRE_ONE_ARG;
		GENERAL_OPTION;
		option_game_to_host = copy_string(argv[i+1]);
	    } else if (strcmp(arg, "-join") == 0) {
		REQUIRE_ONE_ARG;
		GENERAL_OPTION;
		option_game_to_join = copy_string(argv[i+1]);
	    } else if (strcmp(arg, "-L") == 0) {
		REQUIRE_ONE_ARG;
		GENERAL_OPTION;
		if (strcmp(argv[i+1], "-") == 0)
		  add_library_path(NULL);
		else
		  add_library_path(argv[i+1]);
	    } else if (strcmp(arg, "-M") == 0) {
		REQUIRE_ONE_ARG;
		VARIANT_OPTION;
		parse_world_option(argv[i+1]);
	    } else if (strcmp(arg, "-noai") == 0) {
		PLAYER_OPTION;
		initially_no_ai = TRUE;
	    } else if (strcmp(arg, "-r") == 0) {
		PLAYER_OPTION;
		option_add_default_player = FALSE;
	    } else if (strcmp(arg, "-R") == 0) {
		REQUIRE_ONE_ARG;
		GENERAL_OPTION;
#ifdef DEBUGGING
		init_xrandom(atoi(argv[i+1]));
#else
		fprintf(stderr,
			"No debugging available, ignoring option `%s'\n", arg);
#endif /* DEBUGGING */
	    } else if (strcmp(arg, "-seq") == 0) {
		VARIANT_OPTION;
		push_key_int_binding(&variant_settings, K_SEQUENTIAL, 1);
	    } else if (strcmp(arg, "-sim") == 0) {
		VARIANT_OPTION;
		push_key_int_binding(&variant_settings, K_SEQUENTIAL, 0);
	    } else if (strncmp(arg, "-t", 2) == 0) {
		REQUIRE_ONE_ARG;
		VARIANT_OPTION;
		parse_realtime_option(arg, argv[i+1]);
	    } else if (strncmp(arg, "-v", 2) == 0) {
		VARIANT_OPTION;
		parse_variant(arg + 2);
	    } else if (strcmp(arg, "-V") == 0) {
		VARIANT_OPTION;
		push_key_int_binding(&variant_settings, K_SEE_ALL, 1);
	    } else if (strcmp(arg, "-V0") == 0) {
		VARIANT_OPTION;
		push_key_int_binding(&variant_settings, K_SEE_ALL, 0);
	    } else if (strcmp(arg, "-Vfalse") == 0) {
		VARIANT_OPTION;
		push_key_int_binding(&variant_settings, K_SEE_ALL, 0);
	    } else if (strcmp(arg, "-w") == 0) {
		GENERAL_OPTION;
		warnings_suppressed = TRUE;
	    } else if (strcmp(arg, "-x") == 0) {
		GENERAL_OPTION;
		option_popup_new_game_dialog = TRUE;
	    } else if (strcmp(arg, "--help") == 0) {
		GENERAL_OPTION;
		help_wanted = TRUE;
		/* Will display help info later. */
	    } else if (strcmp(arg, "--version") == 0) {
		GENERAL_OPTION;
		version_wanted = TRUE;
	    } else {
		numused = 0;
		/* Anything unrecognized during the last parse is an error. */
		if (spec >= leftover_options) {
		    fprintf(stderr, "Unrecognized option `%s'\n", arg);
		    had_error = TRUE;
		}
	    }
	    if (numused >= 1) {
		strcat(args_used, " ");
		strcat(args_used, argv[i]);
		argv[i] = NULL;
	    }
	    if (numused >= 2) {
		strcat(args_used, " ");
		strcat(args_used, argv[i+1]);
		argv[i+1] = NULL;
	    }
	    if (numused >= 1)
	      i += (numused - 1);
	} else {
	    if (spec == player_options) {
		if (*(argv[i]) == '+' || *(argv[i]) == '@') {
		    raw_default_player_spec = argv[i];
		} else {
		    add_a_raw_player_spec(argv[i]);
		}
		strcat(args_used, " ");
		strcat(args_used, argv[i]);
		argv[i] = NULL;
	    }
	}
    }
    if (version_wanted) {
	version_info();
    }
    if (had_error || help_wanted || variant_help_wanted) {
	/* If we want to get help about a particular game, have to
           load it first. */
	if (help_wanted || variant_help_wanted)
	  load_all_modules();
	if (had_error || help_wanted)
	  general_usage_info();
	if (had_error || help_wanted)
	  player_usage_info();
	if (help_wanted && mainmodule != NULL) {
	    printf("\nGame info:\n\n");
	    if (!empty_string(mainmodule->title))
	      printf("%s (%s)\n", mainmodule->title, mainmodule->name);
	    else
	      printf("%s\n", mainmodule->name);
	    printf("    \n");
	    if (mainmodule->blurb != lispnil) {
	    	append_blurb_strings(blurb, mainmodule->blurb);
	    	printf("%s", blurb);
	    } else {
	    	printf("(no description)");
	    }
	}
	/* Display variant info here so it comes after basic info
	   about the game module. */
	if (had_error || help_wanted || variant_help_wanted)
	  game_usage_info();
    }
    if (had_error || help_wanted || variant_help_wanted || version_wanted) {
	exit(had_error);
    }
}
Example #7
0
int nemo_main()
{
  int i, j, n, m, nrad, seed, flags[6], nflags, ncenter, bootstrap, nradii;
  real scale, dt, dtout, dtlog, tstop, tsnap, mass;
  real center[2], pa, inc, vsys, rmsism, rcirc, radii[MAXRAD];
  string infile = getparam("in");
  string outfile = getparam("out");
  string parfile = getparam("par");
  stream datstr;
  
  string exefile = getparam("exe");
  char dname[256];
  char command[256];

#if 0
  seed = init_xrandom(getparam("seed"));
#else
  seed = getiparam("seed");
#endif
  
  nflags  = nemoinpi(getparam("flags"),flags,MAXFLAGS);
  ncenter = nemoinpr(getparam("center"),center,2);
  nradii  = nemoinpr(getparam("radii"),radii,MAXRAD);
  j = getiparam("j");


  /* sanity checks before writing out input file */
  if (nflags != MAXFLAGS) error("flags= needs %d values",MAXFLAGS);
  if (ncenter != 2) error("center= needs 2 values");

  if (seed >=0 ) error("seed must be negative for SS07");
  if (strlen(infile)  > 100) warning("infile too long");
  if (strlen(outfile) > 100) warning("outfile too long");
  if (strlen(parfile) > 100) warning("parfile too long");


  sprintf(dname,"%s","velfit.inp");
  datstr = stropen(dname,"w!");    
  fprintf(datstr,"# input file for velfitss07\n");
  fprintf(datstr,"'%s'\n",infile);                 /* invfile */
  fprintf(datstr,"'%s'\n",parfile);                /* outpfile */
  fprintf(datstr,"'%s'\n",outfile);                /* outmfile */
  fprintf(datstr,"%g\n",center[0]);                /* xcen*/
  fprintf(datstr,"%g\n",center[1]);                /* ycen*/
  fprintf(datstr,"%g\n",getrparam("vsys"));        /* vsys */
  fprintf(datstr,"%g\n",getrparam("pa"));          /* pa */
  fprintf(datstr,"%g\n",getrparam("inc"));         /* incl */
  fprintf(datstr,"%g\n",getrparam("rmsism"));      /* eISM */
  for (i=0; i<MAXFLAGS; i++)
    fprintf(datstr,"%s ", flags[i] ? "T" : "F");   /* disk,centre,systemic,radial,bisymm,uncert */
  fprintf(datstr,"\n");
  fprintf(datstr,"%d\n",getiparam("m"));           /* order */
  fprintf(datstr,"%d\n",seed);
  fprintf(datstr,"%d\n",getiparam("bootstrap"));   /* nunc */
  fprintf(datstr,"%g\n",getrparam("j"));           /* junc */
  fprintf(datstr,"%g\n",getrparam("rcirc"));       /* maxr */
  for (i=0; i<nradii; i++)
    fprintf(datstr,"%g\n", radii[i]);              /* sma(i) */
  

  strclose(datstr);

  if (run_program(exefile))
    error("Problem executing %s",exefile);
}
Example #8
0
void nemo_main(void)
{
    char   fmt1[20], fmt2[20], *cp;
    double dms[32];
    double *x;
    int    *ix;
    int    i,nret, nx, seed;
    bool   Qnl, Qint,Qdms;
    stream outstr;

    if (hasvalue("tab"))
        outstr = stropen(getparam("tab"),"w");
    else
        outstr = stdout;                /* is that really ok? */
    cp = getparam("format");            /* get format string to print with */
    if (strchr(cp,'%')==NULL)
      warning("%s badly formed printf-conversion specification ???",cp);
    if (strchr(cp,'d')) {
      dprintf(1,"Using integer math\n");
      Qint = TRUE;
    } else {
      dprintf(1,"Using floating point math\n");
      Qint = FALSE;
    }
    seed = init_xrandom(getparam("seed"));
    dprintf(1,"init_xrandom: seed=%d\n",seed);
    Qdms = getbparam("dms");
    if (Qdms) {
      nret = nemoinpx(getparam("expression"),dms,32);
      if (nret < 0) error("Parsing dms expression");
      for (i=0; i<nret; i++)
	printf("%g\n",dms[i]);
      return;  /* for now */
    }

    strcpy (fmt1,cp);                   /* store it in 'fmt' */
    strcpy (fmt2,cp);                   /* and here */
    cp = getparam("separ");             
    if (hasvalue("separ"))              /* separator between numbers ? */
        strcat(fmt2,getparam("separ"));
    else
        strcat (fmt2," ");              /* else use blank as separator */

    Qnl = getbparam("newline");         /* use newlines also ? */

    if (hasvalue("atof")) {
      printf(fmt1,natof(getparam("atof")));
      printf("\n");
      return;
    }

    if (!hasvalue("expression")) {      /* extra help if nothing given */
    	/* this somewhat unusual exit is because aliens often use this program */
	/* what really should have been done is make "expression=???" default */
        dprintf(0,"Usage: %s <expression>\n",getargv0());
        dprintf(0,"\n<expr> can be of form:  start[:end][:incr][,start::repeat]...\n");
        dprintf(0,"Also try keyword 'help= or help=h'\n");
        stop(0);
    }
    nx = getiparam("nmax");

    if (Qint) {
        ix = (int *) allocate(nx * sizeof(int));
   
        nret = nemoinpi(getparam("expression"),ix,nx);
        if (nret == -23)
            error("Too many items in list, use a bigger nmax=%d",nx);
        else if (nret < 0)
            error("nemoinp (%s) parsing error (%d)",cp,nret);

        for (i=0; i< nret-1; i++) {
            fprintf(outstr,fmt2,ix[i]);
            if (Qnl)
                fprintf(outstr,"\n");
        }
        fprintf (outstr,fmt1,ix[nret-1]);
        if (Qnl)
            fprintf (outstr,"\n");
    } else {
        x = (double *) allocate(nx * sizeof(double));
   
        nret = nemoinpd(getparam("expression"),x,nx);
        if (nret == -23)
            error("Too many items in list, use a bigger nmax=%d",nx);
        else if (nret < 0)
            error("nemoinp (%s) parsing error (%d)",cp,nret);

        for (i=0; i< nret-1; i++) {
            fprintf(outstr,fmt2,x[i]);
            if (Qnl)
                fprintf(outstr,"\n");
        }
        fprintf (outstr,fmt1,x[nret-1]);
        if (Qnl)
            fprintf (outstr,"\n");
    }
    if (!Qnl) fprintf(outstr,"\n");  /* always make sure to add 1 newline */

}
Example #9
0
void nemo_main()
{
	int i, seed, bits;
	real mg, mh, tsnap;
	double vx, vy, vz;
	double fmax, f0, f1, v2, vmax, vmax2;
        bool Qcenter = getbparam("zerocm");
        bool Qphi = getbparam("addphi");
        stream outstr = stropen(getparam("out"),"w");

        mu = getdparam("m");
        a = getdparam("a");
        seed = init_xrandom(getparam("seed"));
        nobj = getiparam("nbody");
	if (nobj%2) 
	    warning("Total number of particles reset to %d\n",2*((nobj+1)/2));
        nobj = ((nobj+1)/2);
        if (hasvalue("headline"))
            set_headline(getparam("headline"));
        put_history(outstr);

	b = a - 1;

	btab = (Body *) allocate(2*nobj*sizeof(Body));

	for(i=0, bp=btab; i<2*nobj; i++, bp++) {
		double eta, radius, cth, sth, phi;
		double psi0;

		eta = (double) xrandom(0.0,1.0);
		radius = rad(eta);
		if( i >= nobj ) {
			if( mu == 0.0 ) break;
			radius *= a;
		}
		if( i<nobj ) {
			galaxy = 1;
		} else {
			galaxy = 0;
		}

		phi = xrandom(0.0,2*M_PI);
		cth = xrandom(-1.0,1.0);
		sth = sqrt(1.0 - cth*cth);
		Pos(bp)[0] = (real) (radius*sth*cos(phi));
		Pos(bp)[1] = (real) (radius*sth*sin(phi));
		Pos(bp)[2] = (real) (radius*cth);

		psi0 = -pot(radius);
                if (Qphi) Phi(bp) = psi0;
		vmax2 = 2.0*psi0;
		vmax = sqrt(vmax2);
		fmax = f(psi0);
		f0 = fmax; f1 = 1.1*fmax;        /* just some initial values */
		while( f1 > f0 ) {

                        /* pick a velocity */
			v2 = 2.0*vmax2;
			while( v2 > vmax2 ) {    /* rejection technique */
				vx = vmax*xrandom(-1.0,1.0);
				vy = vmax*xrandom(-1.0,1.0);
				vz = vmax*xrandom(-1.0,1.0);
				v2 = vx*vx + vy*vy + vz*vz;
			}

			f0 = f((psi0 - 0.5*v2));
			f1 = fmax*xrandom(0.0,1.0);

		}
		Vel(bp)[0] = vx;
		Vel(bp)[1] = vy;
		Vel(bp)[2] = vz;
        } 
	mg = 1.0/nobj;
	mh = mu/nobj;
	for(i=0, bp=btab; i<2*nobj; i++, bp++) {
            if (i<nobj)
                Mass(bp) = mg;
            else
                Mass(bp) = mh;
	}

	if (Qcenter)
	    cofm();

        bits = MassBit | PhaseSpaceBit;
        if (Qphi)  bits |= PotentialBit;
        nobj *= 2;
        tsnap = 0.0;
        put_snap(outstr, &btab, &nobj, &tsnap, &bits);
        strclose(outstr);
}
Example #10
0
void nemo_main ()
{
  string  fnames;
  stream  instr;                      /* input file (optional) */
  stream  outstr;                     /* output file */
  int     size[3],nx, ny, nz;         /* size of scratch map */
  int     ncen;
  string  object;
  string  headline;
  int seed = init_xrandom(getparam("seed"));

  object = getparam("object");
  npar = nemoinpr(getparam("spar"),spar,MAXPAR);
  if (npar < 0) error("Syntax error %s",getparam("spar"));

  Qtotflux = getbparam("totflux");
  factor = getdparam("factor");

  pa = getdparam("pa");
  inc = getdparam("inc");
  sinp = sin(pa*PI/180.0);
  cosp = cos(pa*PI/180.0);
  sini = sin(inc*PI/180.0);
  cosi = cos(inc*PI/180.0);
  dprintf(0,"%s: disk with pa=%g inc=%g\n",object,pa,inc);
  dprintf(1,"pa(%g %g) inc(%g %g)\n",sinp,cosp,sini,cosi);

  ncen = nemoinpr(getparam("center"),center,2);
  if (ncen<0) error("Syntax error %s",getparam("center"));
  if (ncen==1) center[1] = center[0];

  init_xrandom(getparam("seed"));
  nwcs = nemorinpd(getparam("crval"),crval,MAXNAX,0.0,FALSE);
  nwcs = nemorinpd(getparam("cdelt"),cdelt,MAXNAX,1.0,FALSE);
  nwcs = nemorinpd(getparam("crpix"),crpix,MAXNAX,1.0,FALSE);
  if (hasvalue("in")) {
    instr = stropen(getparam("in"),"r");    /* open file */
    read_image (instr, &iptr);
  } else {
    dprintf(0,"Generating a map from scratch\n");
    switch (nemoinpi(getparam("size"),size,3)) {
    case 1:			/*  nx[,nx,1] */
      size[1] = size[0];
      size[2] = 1;
      break;
    case 2:			/*  nx,ny[,1] */
      size[2] = 1;
      break;
    case 3:			/*  nx,ny,nz  */
      break;
    case 0:			/*  [10,10,1] */
      dprintf(0,"Cannot have no size, default 10 assumed\n");
      size[0] = size[1] = 10;
      size[2] = 1;
      break;
    default:			/* --- some error --- */
      error("Syntax error in size keyword\n");
    }
    nx = size[0];
    ny = size[1];
    nz = size[2];
    do_create(nx,ny,nz);
#if 0
    if (nwcs == 0) {    /* last one for crpix */
      warning("going to set the center of the map in new NEMO convention");
      crpix[0] = (nx-1)/2.0;
      crpix[1] = (ny-1)/2.0;
      crpix[2] = (nz-1)/2.0;
    }
#endif

  }
  if (ncen==0) {   /* fix center if it has not been set yet */
    center[0] = (Nx(iptr)-1)/2.0;     /* 0 based center= */
    center[1] = (Ny(iptr)-1)/2.0;
  }
  dprintf(0,"%s: center pixel: %g %g\n",object,center[0],center[1]);
  surface = Dx(iptr)*Dy(iptr);
  surface = ABS(surface);

  if (streq(object,"flat"))
    object_flat(npar,spar);
  else if (streq(object,"exp"))
    object_exp(npar,spar);
  else if (streq(object,"gauss"))
    object_gauss(npar,spar);
  else if (streq(object,"bar"))
    object_bar(npar,spar);
  else if (streq(object,"ferrers"))
    object_ferrers(npar,spar);
  else if (streq(object,"spiral"))
    object_spiral(npar,spar);
  else if (streq(object,"noise"))
    object_noise(npar,spar);
  else if (streq(object,"jet"))
    object_jet(npar,spar);
  else if (streq(object,"j1x"))
    object_j1x(npar,spar);
  else if (streq(object,"isothermal"))
    object_isothermal(npar,spar);
  else if (streq(object,"comet"))
    object_comet(npar,spar);
  else if (streq(object,"shell"))
    object_shell(npar,spar);
  else
    error("Unknown object %g",object);
  
  outstr = stropen (getparam("out"),"w");  /* open output file first ... */
  if (hasvalue("headline"))
    set_headline(getparam("headline"));
  write_image (outstr,iptr);         /* write image to file */
  strclose(outstr);
}