Exemplo n.º 1
0
/****************************************************************************
 * main
 *
 * @param argc argument count
 * @param argv argument list
 * @return int return code
 ***************************************************************************/
int
main(int argc, char *argv[])
{
    config_t    config;
    char        config_file[NAME_MAX+1];
    bool        fflag = false;  /* option: config-file */
    
    int         opt;            /* argument for getopt() as a single integer */
    
    /* program without arguments */
    if (argc == 1) {
        usage(argc, argv, NULL);
    }
    
    
    /* first character ':' of getopt()'s optstring sets opterr=0 and
       returns ':' to indicate a missing option argument
       or '?' to indicate a unrecognised option */
    while ((opt = getopt(argc, argv, ":l:df:")) != -1) {
        switch (opt) {
                
            /* option: config-file */
            case 'f':
                strcpy(config_file, optarg);
                fflag = true;
                break;
                
            /* missing option argument */
            case ':':
                usage(argc, argv, OPT_REQUIRED);
                break;
                
            /* unrecognised option */
            case '?':
                usage(argc, argv, OPT_UNRECOGNISED);
                break;
                
            default:
                usage(argc, argv, NULL);
        }
    }
    
    log_init();
    
    /* option: config-file */
    if (!fflag) {
        strcpy(config_file, CONFIG_FILE_NAME);
    }
    
    LOG_PRINTLN(LOG_SIM, LOG_INFO, ("Using config-file \"%s\"", config_file));
    if (!config_file_parse(config_file, &config)) {
        printf("Error in parsing the file!\n");
        exit(EXIT_FAILURE);
    }
    
    do_simulation(&config);
    fprintf(stderr, "Exit!\n");
    
    return 0;
}
Exemplo n.º 2
0
double
compute_error_func (const gsl_vector *proposed_vars, void *params_raw)
{
	struct experiment_params *params = params_raw;
	double dist_err, secs_err, err;
	char filename[1000];
	double proposed_speed, proposed_angle;

	proposed_speed = gsl_vector_get (proposed_vars, 0);
	proposed_angle = gsl_vector_get (proposed_vars, 1);

	if (vflag) {
		sprintf (filename, "sim%04.1f-%04.1f.dat",
			 proposed_speed, RTOD (proposed_angle));
		if ((outf = fopen (filename, "w")) == NULL) {
			fprintf (stderr, "can't create %s\n", filename);
			exit (1);
		}
		printf ("%s\n", filename);
	}

	do_simulation (proposed_vars, params);

	if (vflag) {
		fclose (outf);
	}

	dist_err = params->sim_dist - params->observed_dist;
	secs_err = params->sim_secs - params->observed_secs;

	err = dist_err * dist_err + 100 * secs_err * secs_err;

	if (vflag) {
		printf ("%10.6f %10.6f %10.6f %10.6f %10.6f %10.6f\n",
			params->sim_secs,
			gsl_vector_get (proposed_vars, 0),
			RTOD (gsl_vector_get (proposed_vars, 1)),
			dist_err, secs_err, err);
	}

	return (err);
}