示例#1
0
文件: makenode.C 项目: Ingwar/amuse
int main(int argc, char ** argv)
{
    int  n = 1;
    real m = 1.0;

    check_help();

    extern char *poptarg;
    int c;
    const char *param_string = "m:n:";

    while ((c = pgetopt(argc, argv, param_string,
		    "$Revision: 1.9 $", _SRC_)) != -1)
	switch(c) {

	    case 'm': m = atof(poptarg);
		      break;
	    case 'n': n = atoi(poptarg);
		      break;
            case '?': params_to_usage(cerr, argv[0], param_string);
	    	      get_help();
		      exit(1);
	}

    if (m <= 0) err_exit("mknodes: M > 0 required!");
    if (n <= 0) err_exit("mknodes: N > 0 required!");

    node * root = mknode_mass(n, m);

    root->log_history(argc, argv);

    put_node(root);
    rmtree(root);
    return 0;
}
示例#2
0
文件: print_time.C 项目: Ingwar/amuse
main(int argc, char ** argv)
{
    check_help();

    extern char *poptarg;
    extern char *poparr[];
    int c;
    const char *param_string = "";

    while ((c = pgetopt(argc, argv, param_string,
		    "$Revision: 1.5 $", _SRC_)) != -1)
	switch(c) {
            case '?':	params_to_usage(cerr, argv[0], param_string);
	    		get_help();
	    		exit(1);
        }            

    dyn *b;
    real prev_time = -VERY_LARGE_NUMBER;
    cerr.precision(HIGH_PRECISION);

    while (b = get_dyn()) {

	real time = b->get_system_time();

	if (prev_time > -VERY_LARGE_NUMBER) {
	    real dt = time - prev_time;
	    PRC(time); PRL(dt);
	} else
	    PRL(time);
	prev_time = time;

	rmtree(b);
    }
}
示例#3
0
文件: gethist.C 项目: Ingwar/amuse
main(int argc, char ** argv)
{
    check_help();
    pgetopt(argc, argv, "", "$Revision: 1.5 $", _SRC_);

    printf("%s\n", gethist(argc, argv));
}
示例#4
0
/*-----------------------------------------------------------------------------
 *  main  --  driver to create directly a single node
 *-----------------------------------------------------------------------------
 */
main(int argc, char ** argv)
{
    bool  c_flag = FALSE;
    bool  i_flag = FALSE;
    real m = 1;               // default mass: unity
    char  *comment;

    check_help();

    extern char *poptarg;
    int  c;
    const char *param_string = "c:im:";

    while ((c = pgetopt(argc, argv, param_string,
		    "$Revision: 1.7 $", _SRC_)) != -1)
	switch(c) {
	    case 'c': c_flag = TRUE;
		      comment = poptarg;
		      break;
	    case 'i': i_flag = TRUE;
		      break;
	    case 'm': m = atof(poptarg);
		      break;
            case '?': params_to_usage(cerr, argv[0], param_string);
		      get_help();
		      exit(1);
	}            
    
    node * root;

    root = new node();
    root->set_root(root);
    root->set_mass(m);

    if (c_flag == TRUE)
        root->log_comment(comment);
    root->log_history(argc, argv);

    if (i_flag)
        root->set_label(1);

    put_node(root);
    rmtree(root);
}
示例#5
0
文件: energy.C 项目: Ingwar/amuse
main(int argc, char **argv)
{
    dyn *root;
    int  e_flag = 0;
    real eps = 0;

    check_help();

    extern char *poptarg;
    int c;
    const char *param_string = "e:";

    while ((c = pgetopt(argc, argv, param_string,
		    "$Revision: 1.6 $", _SRC_)) != -1)
	switch(c) {
	    case 'e': e_flag = 1;
                      eps = atof(poptarg);
	              break;
            case '?': params_to_usage(cerr, argv[0], param_string);
	              get_help();
                      exit(1);
	}

    // Loop over input until no more data remain.

    while ( (root = get_dyn()) != NULL) {

	real kinetic_energy, potential_energy;
	get_top_level_energies(root, eps*eps, potential_energy, kinetic_energy);

	cout << "Top-level energies (T, U, E):  "
	     << kinetic_energy << "  "
	     << potential_energy << "  "
	     << kinetic_energy + potential_energy 
	     << endl;
    }
}
示例#6
0
main(int argc, char ** argv)
{
    char  *comment;
    bool  c_flag = FALSE;	// if TRUE, a comment given on command line

    real  t_extract;
    bool  t_flag = FALSE;	// if TRUE, a time was specified

    bool  v_flag = FALSE;	// if TRUE, print snap times as read

    int   n = 1;
    bool  n_flag = false;	// if TRUE, a number was specified

    check_help();

    extern char *poptarg;
    int c;
    const char *param_string = "c:n:t:v";

    while ((c = pgetopt(argc, argv, param_string,
		    "$Revision: 1.8 $", _SRC_)) != -1)
	switch(c) {
	    case 'c': c_flag = TRUE;
	    	      comment = poptarg;
		      break;
	    case 't': t_flag = TRUE;
		      t_extract = atof(poptarg);
		      break;
	    case 'n': n_flag = TRUE;
		      n = atoi(poptarg);
		      break;
	    case 'v': v_flag = TRUE;
		      break;
	    case '?': params_to_usage(cerr, argv[0], param_string);
	              get_help();
		      exit(1);
	}            

    if (n < 0) err_exit("n < 0 specified.");
    if (n > 1 && !t_flag) {
	warning("n > 1 but no time specified -- 0 assumed.");
	t_extract = 0;
	t_flag = true;
    }

    node *b = NULL, *bp = NULL;
    int i = 0;

    // Need to ensure that the data are not changed by this function.
    // Currently, get_dyn() ends by calling check_and_correct_node(),
    // which may change pos and vel to force the system to the center
    // of mass frame.  Can fix (1) by suppressing this call in this
    // case, (2) setting a tolerance to avoid forcing if the system is
    // already "close" to the CM frame, or (3) use nodes here, which
    // will never interpret pos or vel and hence will not change them.
    // The only number we really need below is sytsem_time.  Options
    // (1) and (2) are awkward, because this function is a member
    // function and changing its arguments would propagate through the
    // other classes.  However, we could add a static local option to
    // the dyn instance of the function.  Option (3) seems cleanest.
    // To revert, change node to dyn and use b->get_system_time() to
    // determine time.
    //						(Steve, 7/04)

    while (b = get_node()) {

	real time;
	if (find_qmatch(b->get_dyn_story(), "real_system_time"))
	    time = getrq(b->get_dyn_story(), "real_system_time");
	else
	    time = getrq(b->get_dyn_story(), "system_time");

	// real time = b->get_system_time();

	i++;

	if (v_flag) cerr << "Snap time #" << i << " = " << time << endl;

	if (t_flag && time >= t_extract) {

	    if (n > 0) {

		if (c_flag == TRUE)
		    b->log_comment(comment);

		b->log_history(argc, argv);
		put_node(b);
	    }

	    if (--n <= 0) exit(0);
	}

	if (bp) rmtree(bp);
	bp = b;
    }

    if (n > 0 && !t_flag) {
	bp->log_history(argc, argv);
	put_node(bp);
    }

}
示例#7
0
main(int argc, char ** argv)
{
    bool renumber = true;
    check_help();

    extern char *poptarg;
    extern char *poparr[];
    int c;
    const char *param_string = "n";

    // Parse the argument list:

    while ((c = pgetopt(argc, argv, param_string,
		    "$Revision: 1.8 $", _SRC_)) != -1) {
	switch (c) {
	    case 'n':	renumber = false;
			break;

	    default:
	    case '?':	params_to_usage(cerr, argv[0], param_string);
			get_help();
			return false;
	}
    }

    dyn *b, *root = new dyn;
    if (!root) err_exit("merge_snaps: can't create root node.");
    int count = 0;
    root->log_history(argc, argv);

    while (b = get_dyn()) {

	b->offset_com();		// add root pos/vel to daughters

	// Attach top-level nodes of b to root.

	dyn *last = root->get_oldest_daughter();
	while (last && last->get_younger_sister())
	    last = last->get_younger_sister();

	for_all_daughters(dyn, b, bb) {

	    // First node is a special case.

	    if (!last)
		root->set_oldest_daughter(bb);
	    else
		last->set_younger_sister(bb);

	    bb->set_elder_sister(last);
	    bb->set_parent(root);
	    last = bb;
	}

	// Merge the root log stories, with a prefix indicating which
	// initial snapshot this was.  This code is not completely general,
	// but should be sufficient for simple (typical) stories.

	story *sr = root->get_log_story();
	story *s = b->get_log_story();
	for (story * d = s->get_first_daughter_node(); d != NULL;
	     d = d->get_next_story_node())
	    if (!d->get_chapter_flag()) {
		char tmp[1024];
		sprintf(tmp, "  +%4.4d:  ", count);
		strncat(tmp, d->get_text(), 1013);
		tmp[1023] = '\0';
		add_story_line(sr, tmp);
	    }

	count++;
	delete b;
    }

    // Recompute the total mass and force the center of mass to 0.
    // Better renumber too, unless specifically suppressed..

    real mass = 0;
    int index = 0;
    for_all_daughters(dyn, root, bb) {
	mass += bb->get_mass();
	if (renumber) bb->set_index(++index);
    }
示例#8
0
int main(int argc, char ** argv)
{
    real lower = 1.0, upper = 1.0;
    real emax = 1;
    int function_select = 3;
    int option = 1;
    int random_seed = 0;
    char seedlog[64];

    check_help();

    extern char *poptarg;
    int c;
    const char *param_string = "f:l:s:o:u:e:";

    while ((c = pgetopt(argc, argv, param_string,
		    "$Revision: 1.9 $", _SRC_)) != -1)
	switch(c) {

	    case 'f': function_select = atoi(poptarg);
		      break;
	    case 'l': lower = atof(poptarg);
		      break;
	    case 'o': option= atoi(poptarg);
		      break;
	    case 'e': emax = atof(poptarg);
		      break;
	    case 's': random_seed = atoi(poptarg);
		      break;
	    case 'u': upper = atof(poptarg);
		      break;
            case '?': params_to_usage(cerr, argv[0], param_string);
	    	      get_help();
		      exit(1);
	}

    if (lower <= 0 || upper <= 0 || lower > upper)
	err_exit("makebinary: Illegal limits");

    dyn* b;
    b = get_dyn();

    b->log_history(argc, argv);

    int actual_seed = srandinter(random_seed);

    sprintf(seedlog, "       random number generator seed = %d",
	    actual_seed);
    b->log_comment(seedlog);

    // Look in the dyn story to see if a total system energy is known.
    // If it is, scale lower and upper accordingly.

    // Thus, in case function_select = 3, if the energy is known,
    // lower and upper are specified in "kT" units.  If the energy
    // is not known, lower and upper are absolute limits on the
    // binary kinetic energy.

    const char* energy_string = "initial_total_energy";

    if (function_select == 1) {
	if (b->get_starbase()->get_stellar_evolution_scaling()) {
	    real scale = sqrt(b->get_starbase()->conv_m_star_to_dyn(1)
			      * b->get_starbase()->conv_r_star_to_dyn(1));
	    lower *= scale;
	    upper *= scale;
	}
	else
	    cerr << "makebinary: Using unscaled angular-momentum limits.\n";
    }
    else if (function_select == 2) {
	if (b->get_starbase()->conv_r_star_to_dyn(1)>0) {
	    lower = b->get_starbase()->conv_r_star_to_dyn(lower);
	    upper = b->get_starbase()->conv_r_star_to_dyn(upper);
	}
	else
	    cerr << "makebinary: Using unscaled semi-major axis limits.\n";
    }
    else if (function_select == 3) {
	if (find_qmatch(b->get_log_story(), energy_string))
	    scale_limits(lower, upper, option,
			 b->n_daughters(), b->get_mass(),
			 getrq(b->get_log_story(), energy_string));
	else
	    cerr << "makebinary: Using unscaled energy limits.\n";
    }

    makebinary(b, lower, upper, function_select, option, emax);

    put_dyn(b);
    rmtree(b);
    return 0;
}
示例#9
0
int parse_opts(Opts * const opts, PuzzleContext * context,
               int argc, char **argv) {
    int opt;
    extern char *poptarg;
    extern int poptind;

    opts->fix_for_texts = 1;
    opts->exit = 0;
    opts->similarity_threshold = PUZZLE_CVEC_SIMILARITY_THRESHOLD;
    while ((opt = pgetopt(argc, argv, "b:cC:eE:hH:l:n:p:tW:")) != -1) {
        switch (opt) {
        case 'b':
            puzzle_set_contrast_barrier_for_cropping(context, atof(poptarg));
            break;
        case 'c':
            puzzle_set_autocrop(context, 0);
            break;            
        case 'C':
            puzzle_set_max_cropping_ratio(context, atof(poptarg));
            break;
        case 'e':
            opts->exit = 1;
            break;
        case 'E':
            opts->similarity_threshold = atof(poptarg);
            break;
        case 'h':
            usage();
            /* NOTREACHED */
        case 'H':
            puzzle_set_max_height(context, strtoul(poptarg, NULL, 10));
            break;
        case 'l':
            puzzle_set_lambdas(context, strtoul(poptarg, NULL, 10));
            break;
        case 'n':
            puzzle_set_noise_cutoff(context, atof(poptarg));
            break;
        case 'p':
            puzzle_set_p_ratio(context, atof(poptarg));
            break;
        case 't':
            opts->fix_for_texts = 0;
            break;
        case 'W':
            puzzle_set_max_width(context, strtoul(poptarg, NULL, 10));
            break;
        default:
            usage();
            /* NOTREACHED */            
        }
    }
    argc -= poptind;
    argv += poptind;
    if (argc != 2) {
        usage();
    }
    opts->file1 = *argv++;
    opts->file2 = *argv;
    
    return 0;
}