示例#1
0
文件: icqprx.c 项目: tadu/climm
void do_exchange (int fd_cli, int fd_srv, int port, int single)
{
    char from_cli_buf[1024*1024];
    char to_cli_buf[1024*1024];
    int from_cli_index = 0, from_cli_reported = 0;
    int to_cli_index = 0, to_cli_reported = 0;
    int ret;

    while (1)
    {
        ret = read_all_data (fd_cli, from_cli_buf, &from_cli_index, &from_cli_reported, 1024*1024, 0);
        if (!ret)
            printf ("No more data from client.\n");
        if (ret > 0)
        {
            printf ("EOF %d from client.\n", ret);
            while (send_packet (fd_srv, from_cli_buf, &from_cli_index, &from_cli_reported, port, 1))
                ;
            close (fd_cli);
            close (fd_srv);
            return;
        }
        
        if (single)
            send_packet (fd_srv, from_cli_buf, &from_cli_index, &from_cli_reported, port, 1);
        else
            while (send_packet (fd_srv, from_cli_buf, &from_cli_index, &from_cli_reported, port, 1))
                ;
        ret = read_all_data (fd_srv, to_cli_buf, &to_cli_index, &to_cli_reported, 1024*1024, 1);
        if (!ret)
            printf ("No more data from server.\n");
        if (ret > 0)
        {
            printf ("EOF %d from server.\n", ret);
            while (send_packet (fd_cli, to_cli_buf, &to_cli_index, &to_cli_reported, port, 0))
                ;
            close (fd_cli);
            close (fd_srv);
            return;
        }
        send_packet (fd_cli, to_cli_buf, &to_cli_index, &to_cli_reported, port, 0);
    }
}
示例#2
0
文件: main.c 项目: Mikushi/NNet
int
main (int argc, const char* argv[])
{
    err_t err;

    printf ("Loading images and labels...\n");
    data_t data;
    err = read_all_data (&data, images_file, labels_file);
    EXIT_MAIN_ON_ERR(err);

    printf ("Setting up network...\n");
    network_t network;
    uint32_t layers = sizeof(nodes) / sizeof(nodes[0]);

    printf ("Node structure: ");
    for (uint32_t i = 0; i < layers - 1; ++i) {
        printf ("%i x ", nodes[i]);
    }
    printf ("%i.\n", nodes[layers - 1]);

    network.nodes.size = layers;
    network.nodes.data = nodes;
    network.epochs = EPOCHS;
    network.mini_batch_size = MINI_BATCH_SIZE;
    network.eta = ETA;

    err = network_allocate (&network);
    EXIT_MAIN_ON_ERR(err);

    printf ("Initialising network...\n");
    network_random_init (&network, RANDOM_VARIANCE);

    // Split off a chunk of data for testing
    data_t test_data;
    partition_data(&data, &test_data, VALIDATION_DATA_CHUNK_SIZE);

    printf ("Stochastic gradient descent...\n");
    network_sgd (&network, &data, &test_data);

    network_free (&network);
    images_free (&data.images);
    labels_free (&data.labels);

    return EXIT_SUCCESS;
}
int main(int argc, char *argv[])
{
	char arg_string[2000];
	int nsub,n_new_sub,real_nsub;
	float *score,p;
	int max_cc[2],s,n_non_mendelian;
	non_mendelian *non_mendelians;
	char *non_mendelian_report;
	par_info pi;
	sa_par_info spi;
	subject **sub,**new_sub,**real_sub;
	pi.use_cc=1;
	printf("%s v%s\n",PROGRAM,SAVERSION);
	printf("MAX_LOCI=%d\nMAX_SUB=%d\n",MAX_LOCI,MAX_SUB);

	assert(sub=(subject **)calloc(MAX_SUB,sizeof(subject*)));
	for (s=0;s<MAX_SUB;++s)
		assert(sub[s]=(subject *)calloc(1,sizeof(subject)));
	assert(score=(float *)calloc(MAX_SUB,sizeof(float)));
	max_cc[0]=max_cc[1]=0;
	read_all_args(argv,argc, &pi, &spi);
	// make_arg_string(arg_string,argc,argv);
	// parse_arg_string(arg_string,&pi,&spi,&pspi);
	process_options(&pi,&spi);
	if (spi.df[FILTERFILE].fp)
		initExclusions(spi.df[FILTERFILE].fp);
	read_all_data(&pi,&spi,sub,&nsub,names,comments,func_weight);
if (spi.use_trios)
{
	if (atoi(comments[0])>22 || toupper(comments[0][0]) == 'X' || toupper(comments[0][0]) == 'Y' ||
		toupper(comments[0][0]) == 'C'&&toupper(comments[0][1]) == 'H'&&toupper(comments[0][2]) == 'R' && (atoi(comments[0] + 3) > 22 || toupper(comments[0][3]) == 'X' || toupper(comments[0][3]) == 'Y'))
	{
		error("Cannot at present use trios for genes on X or Y chromosome", "");
		return 1;
	}
}

if (spi.use_trios)
	{
		assert(new_sub=(subject **)calloc(nsub,sizeof(subject*)));
		for (s=0;s<nsub;++s)
			assert(new_sub[s]=(subject *)calloc(1,sizeof(subject)));
		assert(non_mendelians=(non_mendelian *)calloc(MAX_SUB,sizeof(non_mendelian)));
		if ((n_new_sub=sort_trios(sub,nsub,&pi,new_sub,non_mendelians,&n_non_mendelian,long_line))==0)
			exit(1);
		real_sub=sub;
		sub=new_sub;
		real_nsub=nsub;
		nsub=n_new_sub;
		assert(non_mendelian_report=(char*)malloc(strlen(long_line)+1));
		strcpy(non_mendelian_report,long_line);
	}
	fprintf(spi.df[OUTFILE].fp,"pscoreassoc output\n"
"Locus                   controls     frequency        cases          frequency   frequency allele  weight\n"
"                     AA  :   AB  :  BB                  AA  :   AB  :  BB                     \n");
get_freqs(sub,nsub,&pi,&spi,cc_freq,cc_count,cc_genocount);
applyExclusions(&pi);
set_weights(spi.df[OUTFILE].fp,weight,missing_score,rarer,sub,nsub,&pi,&spi,func_weight,cc_freq,cc_count,max_cc,names,comments);
get_scores(score,weight,missing_score,rarer,sub,nsub,&pi,&spi);
p=do_score_onetailed_ttest(spi.df[OUTFILE].fp,score,sub,nsub,&pi,&spi,cc_freq,cc_count,max_cc,weight,missing_score,rarer);
if (spi.df[SCOREFILE].fp)
	write_scores(spi.df[SCOREFILE].fp,sub,nsub,score);
if (spi.do_recessive_test)
{
if (atoi(comments[0]+3)>22 || toupper(comments[0][4])=='X' || toupper(comments[0][4])=='Y')
// simple trick for now to avoid X and Y genes
	fprintf(spi.df[OUTFILE].fp,"\nCannot do recessive test for genes on X or Y chromosome.\n");
else if (spi.use_haplotypes)
	do_recessive_HWE_test_with_haplotypes(spi.df[OUTFILE].fp,score,sub,nsub,&pi,&spi,cc_freq,cc_count,max_cc,weight,missing_score,rarer,names);
else 
	do_recessive_HWE_test(spi.df[OUTFILE].fp,score,sub,nsub,&pi,&spi,cc_freq,cc_count,max_cc,weight,missing_score,rarer,names);
}

stateExclusions(spi.df[OUTFILE].fp);
printf("\nProgram run completed OK\n");
return 0;

}
示例#4
0
int main(int argc, char *argv[]) {
#else
int gstat_main(int argc, char *argv[]) {
#endif

	DATA      **data = NULL, *valdata = NULL;

/*
 * initialise some global variables:
 */
	atexit(close_gstat_log_file);
	init_userio(1);
	init_global_variables();
	argv0 = argv[0];
/*
 * register command line arguments on command_line:
 */
	command_line = store_argv(argc, argv);
	parse_gstatrc();
/*
 * INPUT: command line options;
 */
	parse_options(argc, argv); /* exits on -e options */

/*
 * start with program heading:
 */
	printlog("%s: %s version %s\n", GSTAT_NAME, GSTAT_OS, VERSION);
	printlog("%s\n", GSTAT_CR);
	gstat_start();

/*
 * INPUT: Parse command files: 
 */
	if (optind == argc) { /* there's no command file name left */
		if (get_method() != UIF) { /* -i or -m command line option */
			/* no arguments */
			printlog("Updates, manuals and source code: %s\n", 
				GSTAT_HOME);
			printlog("%s\n", USAGE);
			ErrMsg(ER_NOCMD, "");
		} else {
			start_ui();
			exit(0);
		}
	} else { /* we have a command file to be read */
		for ( ; optind < argc; optind++) {
			command_file_name = argv[optind];
			parse_file(command_file_name);
			if (logfile_name != NULL)
				set_gstat_log_file(efopen(logfile_name, "w"));
/* 
 * get global variables locally: 
 */
			data = 			get_gstat_data();
			valdata = 		get_dataval();
			set_seed(gl_seed);

/* 
 * check variable settings and next
 * INPUT: read data values from file: 
 */
			read_all_data(data, valdata, get_n_vars());
			if (get_method() == NSP) /* Still no answer to this: choose default */
				set_method(get_default_method());
			set_mode();
			check_global_variables();
			setup_meschach_error_handler();
			if (DEBUG_DUMP)
				dump_all();
			if (get_method() != NSP)
				printlog("[%s]\n", method_string(get_method()));
			if (check_only)
				set_method(NSP);

/*
 * start calculations && OUTPUT routines:
 */
			switch (get_method()) {
				case UIF:
					start_ui();
					break;
				case NSP:
					break;
				case COV: 
				case SEM:
					do_variogram(get_n_vars(), get_method());
					break;
        		case POLY:
            		setup_poly_method();
            		/*FALLTHROUGH*/
				default: 
					if (gl_xvalid) /* validation/cross validation */
						cross_valid(data);
					else
						predict_all(data); /* or prediction: */
					break;
			} /* switch get_method() */
			remove_all(); /* free all data etc. */
			init_global_variables(); /* re-init for next round */
		}
	}

	if (DEBUG_DUMP)
		atexit(print_file_record);

	if (get_method() != UIF)
		elapsed();
/* 
 * file closing & data freeing time:
 */
	if (plotfile != NULL)
		efclose(plotfile);

	exit(0);
} /* end of main() */
示例#5
0
int periodic_task_1(void)
{
    //static int previous_calibration_status = CALIBRATION_NOT_RUNNING;
    //int current_calibration_status; // Used to detect lowering edge
    static int previous_datalogger_status = DATALOGGER_NOT_RUNNING;
    int current_datalogger_status; // Used to detect rising edge
    char user =0;
   /* int buff_i=0; //i of buffer
    int i, j, k, equal=0;
    short int buff[3][3][3]; //{acc,gyr,mag}{x,y,z}{i=1,2,3}
*/

    // Main communication/control thread

    //Acquire
    total++;
    if( read_all_data(imu_param.i2c_dev, spi_param.spi_dev, &imu_data, &eff_data, &mra_data, &enc_data) != SUCCESS)
      failure++;
        
    // Calibrate and Estimate
    calibrate_all(&imu_data);
    //calibration_calibrate_all(&pwm_read_data, &scp1000_data, &battery_data, &gps_data, &imu_data, &pitot_data, &sonar_data, &calibration_local_coordinate_system_data, &calibration_altimeter_data, &calibration_local_fields_data, &gps_measure, &imu_measure, &magnetometer_measure);
    //estimation_update_state_estimate(&estimation_data, &gps_measure, &imu_measure, &magnetometer_measure, &sonar_measure, &calibration_local_fields_data, task_1_period_us/(double)1e6);

    // Control
    mra_data.v_ctl=1275+(uint8_t)(800*cosf(t_task_1_global*1000));
    //control_main_task(t_task_1_global, &pwm_write_data, &pwm_read_data, &control_data, &estimation_data);

    // Actuate
    actuate(spi_param.spi_dev, &mra_data);
    //protocol_send_actuation_data(&pwm_write_data);

    // Log
    /*user=getch();
    switch(user){
      case 'e': 
	exit_program();
	break;
      case 'a':
	acquire=1;
	break;
      case 's':
	acquire=0;
	break;
      default:
	break;
    }*/
    current_datalogger_status = datalogger_status();
    if( (current_datalogger_status == DATALOGGER_RUNNING))
    {
        if(previous_datalogger_status == DATALOGGER_NOT_RUNNING) // Rising edge
        {
            datalogger_set_Ts(task_1_period_us/1e6);
            reset_timer();
        }
        datalogger_update(t_task_1_global, T_task_1_exec_global, T_task_2_exec_global, t0, &imu_data, &eff_data, &mra_data /*&imu_measure, &magnetometer_measure, &estimation_data, &control_data*/);
  //printf("\n    %d\t|",i);
 /* printw("%d\t|",eff_data.F.x);
    printw("\t%d\t%d\t%d\t|",imu_data.acc.x,imu_data.acc.y,imu_data.acc.z);
    printw("\t%d\t%d\t%d\t|",imu_data.mag.x,imu_data.mag.y,imu_data.mag.z);
    printw("\t%d\t%d\t%d\t%d",imu_data.gyr.x,imu_data.gyr.y,imu_data.gyr.z, imu_data.temp);
    printw("\t%d\t%d",eff_data.new_data,imu_data.new_data);
    printw("\t%d\t%d",mra_data.Out_0, mra_data.Read_0);
    printw("\n");
    refresh();*/
    }
    previous_datalogger_status = current_datalogger_status;

/*    current_calibration_status = calibration_get_status();
    if(current_calibration_status == CALIBRATION_RUNNING)
    {
        calibration_imu_add_sample_bias_estimate(&imu_data);
        calibration_altimeter_add_sample_initial_pressure(&scp1000_data, &calibration_altimeter_data);
    }
    else // Calibration not running
    {
        if(previous_calibration_status == CALIBRATION_RUNNING) // Lowering edge
        {
            calibration_imu_finish_bias_estimate(&imu_data);
            calibration_altimeter_finish_initial_pressure_estimate(&calibration_altimeter_data);
        }
    }
    previous_calibration_status = current_calibration_status;
*/
    return SUCCESS;
}
int main(int argc, char *argv[])
{
	char arg_string[2000];
	int nsub,n_new_sub,real_nsub,nVarTypes;
	float **varScore,p;
	int s,n_non_mendelian;
	non_mendelian *non_mendelians;
	char *non_mendelian_report;
	par_info pi;
	sa_par_info spi;
	subject **sub,**new_sub,**real_sub;
	pi.use_cc=1;
	printf("%s v%s\n",PROGRAM,GVSVERSION);
	printf("MAX_LOCI=%d\nMAX_SUB=%d\n",MAX_LOCI,MAX_SUB);

	assert(sub=(subject **)calloc(MAX_SUB,sizeof(subject*)));
	for (s=0;s<MAX_SUB;++s)
		assert(sub[s]=(subject *)calloc(1,sizeof(subject)));
	max_cc[0]=max_cc[1]=0;
	read_all_args(argv,argc, &pi, &spi);
	// make_arg_string(arg_string,argc,argv);
	// parse_arg_string(arg_string,&pi,&spi,&pspi);
	process_options(&pi,&spi);
	if (spi.df[FILTERFILE].fp)
		initExclusions(spi.df[FILTERFILE].fp);
	read_all_data(&pi,&spi,sub,&nsub,names,comments,func_weight);
if (spi.use_trios)
{
	if (atoi(comments[0])>22 || toupper(comments[0][0]) == 'X' || toupper(comments[0][0]) == 'Y' ||
		toupper(comments[0][0]) == 'C'&&toupper(comments[0][1]) == 'H'&&toupper(comments[0][2]) == 'R' && (atoi(comments[0] + 3) > 22 || toupper(comments[0][3]) == 'X' || toupper(comments[0][3]) == 'Y'))
	{
		error("Cannot at present use trios for genes on X or Y chromosome", "");
		return 1;
	}
}

if (spi.use_trios)
	{
		assert(new_sub=(subject **)calloc(nsub,sizeof(subject*)));
		for (s=0;s<nsub;++s)
			assert(new_sub[s]=(subject *)calloc(1,sizeof(subject)));
		assert(non_mendelians=(non_mendelian *)calloc(MAX_SUB,sizeof(non_mendelian)));
		if ((n_new_sub=sort_trios(sub,nsub,&pi,&spi,new_sub,non_mendelians,&n_non_mendelian,long_line))==0)
			exit(1);
		real_sub=sub;
		sub=new_sub;
		real_nsub=nsub;
		nsub=n_new_sub;
		assert(non_mendelian_report=(char*)malloc(strlen(long_line)+1));
		strcpy(non_mendelian_report,long_line);
	}
else
	non_mendelian_report=0;
	// not used, compiler error otherwise
get_freqs(sub,nsub,&pi,&spi,cc_freq,cc_count,cc_genocount);
applyExclusions(&pi);
spi.use_func_weights=0; // this is a trick to prevent the rarity weight being multiplied by the functional weight
set_weights(0,weight,missing_score,rarer,sub,nsub,&pi,&spi,func_weight,cc_freq,cc_count,max_cc,names,comments);
nVarTypes=readFlagTable(varFlagTable,&spi);
assert(varScore=(float **)malloc(nsub*sizeof(float*)));
for (s=0;s<nsub;++s)
	assert(varScore[s]=(float*)malloc(nVarTypes*sizeof(float)));

// allocate a table to hold the subject scores for each variant type, then output fill it and it
getVarScores(varFlagTable,nVarTypes,varScore,weight,func_weight,missing_score,rarer,sub,nsub,&pi,&spi);
// beware, func_weight is indexed differently
// weight[l]*=func_weight[pi->loci_to_use[l]];
// weight and missing score are only calcuated for loci to be used
writeVarScores(spi.df[SCOREFILE].fp,sub,nsub,nVarTypes,varScore);
fclose(spi.df[SCOREFILE].fp);
spi.df[SCOREFILE].fp=0;

fprintf(spi.df[OUTFILE].fp,"geneVarAssoc output\n");
fprintf(spi.df[OUTFILE].fp,"Used %d valid variants\n",pi.n_loci_to_use);
stateExclusions(spi.df[OUTFILE].fp);
fclose(spi.df[OUTFILE].fp);
spi.df[OUTFILE].fp=0; //  because otherwise the destructor will try to fclose it
printf("\nProgram run completed OK\n");
return 0;

}