real claussen( real x ) { static int nclpi6 = 0, nclpi2 = 0, ncl5pi6 = 0; /* * right half (Pi <= x < 2 Pi) */ int rh = 0; real f; if( !nclpi6 ){ nclpi6 = inits( clpi6, sizeof clpi6 / sizeof *clpi6, mach[2] / 10 ); nclpi2 = inits( clpi2, sizeof clpi2 / sizeof *clpi2, mach[2] / 10 ); ncl5pi6 = inits( cl5pi6, sizeof cl5pi6 / sizeof *cl5pi6, mach[2] / 10 ); } /* * get to canonical interval */ if( ( x = fmod( x, 2 * M_PI ) ) < 0 ){ x += ( real )( 2 * M_PI ); } if( x > ( real )M_PI ){ rh = 1; x = ( real )( 2 * M_PI ) - x; } if( x == 0 ){ f = x; }else if( x <= ( real )( M_PI / 3 ) ){ f = csevl( x * ( real )( 6 / M_PI ) - 1, clpi6, nclpi6 ) * x - x * log( x ); }else if( x <= ( real )( 2 * M_PI / 3 ) ){ f = csevl( x * ( real )( 3 / M_PI ) - 1, clpi2, nclpi2 ) * x - x * log( x ); }else{ /* x <= Pi */ f = ( ( real )M_LN2 - csevl( 5 - x * ( real )( 6 / M_PI ), cl5pi6, ncl5pi6 ) ) * ( ( real )M_PI - x ); } return rh ? -f : f; }
int main() { inits(&empty, 1); inits(&mpMale, 3); inits(&mpFemale, 3); ls_init(&lsMale); ls_init(&lsFemale); int i; pthread_t _man[5]; pthread_t _woman[6]; for (i=0;i<5;i++) { pthread_create(&_man[i], 0, man, 0); } for (i=0;i<6;i++) { pthread_create(&_woman[i], 0, woman, 0); } pthread_exit(0); return 0; }
int main(void) { inits(); sei(); while(1) { seven_seg(counter); if (counter == 100) counter = 0; if (counter == 255) counter = 99; } }
int main(void) { /* Initialize module */ inits(); for(;;) { fm_horn_handler(); fm_wipers_handler(); fm_fans_handler(); _delay_ms(16); // the longer the wait the slower the wiper will go asm("sleep"); } return 0; }
int main() { int n; inits(); while(1) { scanf("%d", &n); if (!n) break; printf("%d\n", grids[n]); } return 0; }
int Caldist::init(Build_m &b_m,Build_s &b_s) { int i,j; initm(b_m); inits(b_s); maxr=0.0; for(i=0;i<vdw_n;i++) if(maxr<vdw_r[i]) maxr=vdw_r[i]; goodn=new int[b_s.resnum]; good=new int*[b_s.resnum]; for(i=0;i<b_s.resnum;i++) good[i]=new int[b_s.rtmn[i]]; }
void iterativetraverse(tree t){ node *temp; stack st; inits(&st); temp = t; if(!temp) return; while(1){ for(; temp; temp = temp->left) push(&st, temp); temp = pop(&st); if(!temp) break; printf("%d\t",temp->n); temp = temp->right; } }
int main(void) { // char i; // Serielle initialisieren inits(); init_ser(); // CR und LF auf das Terminal ausgeben putc (0xd); putc (0xa); // ein Zeichen von der seriellen abholen // i=getc(); putc('a'); // String ausgeben puts("Hallo! \n"); // intOutput(0x80000); intOutput(0x80000000); // diese zahl max mit 20 stellen (- zeichen zählt als stelle), falls mehr benötigt, muss im quellcode die größe von "carray" entsprechend geändert werden return 0; }
/* Main ----------------------------------------------------------------------*/ int main(void){ inits( ); //while(1){;;} while(1){ // Runs in 1000Hz. if(runRegulator){ runRegulator = false; regulator( ); } // Reset if line is lost. /* if(stopTimer >= 3000){ stopTimer = 0; isFindingLine = false; runState = false; drive_total_stop( ); }*/ // Runs when all ADC are read, to calculate speed. if(adcDMA){ adcDMA = false; spokesCounter( ); } // Runs when data has been received. if(handleUsart){ handleUsart = false; usartHandler( ); } // Runs when data has been requested. if(usartRequested){ usartRequested = false; sendUART( ); } } }
// build a single element for the OffsetInfo[] of ClassInfo static LLConstant* build_offti_entry(ClassDeclaration* cd, VarDeclaration* vd) { std::vector<LLConstant*> inits(2); // size_t offset; // assert(vd->ir.irField); // grab the offset from llvm and the formal class type size_t offset = gDataLayout->getStructLayout(isaStruct(cd->type->ir.type->get()))->getElementOffset(vd->ir.irField->index); // offset nested struct/union fields offset += vd->ir.irField->unionOffset; // assert that it matches DMD Logger::println("offsets: %lu vs %u", offset, vd->offset); assert(offset == vd->offset); inits[0] = DtoConstSize_t(offset); // TypeInfo ti; inits[1] = DtoTypeInfoOf(vd->type, true); // done return llvm::ConstantStruct::get(inits); }
CMAParams::CMAParams(eoParser& parser, unsigned dimensionality) { string section = "CMA parameters"; n = parser.createParam(dimensionality, "dimensionality", "Dimensionality (N) of the problem", 'N', section, dimensionality == 0).value(); maxgen = parser.createParam( 1000, "max-gen", "Maximum number of generations that the system will run (needed for damping)", 'M', section).value(); if (n == 0) { return; } defaults(n, maxgen); /* handle lambda */ lambda = parser.createParam( lambda, "lambda", "Number of offspring", 'l', section).value(); if (lambda < 2) { lambda = 4+(int)(3*log((double) n)); cerr << "Too small lambda specified, setting it to " << lambda << endl; } /* handle mu */ mu = parser.createParam( mu, "mu", "Population size", 'm', section).value(); if (mu >= lambda) { mu = lambda/2; cerr << "Mu set larger/equal to lambda, setting it to " << mu << endl; } /* handle selection weights */ int weight_type = parser.createParam( 0, "weighting", "Weighting scheme (for 'selection'): 0 = logarithmic, 1 = equal, 2 = linear", 'w', section).value(); switch (weight_type) { case 1: { for (unsigned i = 0; i < weights.size(); ++i) { weights[i] = mu - i; } } case 2: { weights = 1.; } default : { for (unsigned i = 0; i < weights.size(); ++i) { weights[i] = log(mu+1.)-log(i+1.); } } } /* Normalize weights and set mu_eff */ double sumw = weights.sum(); mueff = sumw * sumw / (weights * weights).sum(); weights /= sumw; /* most of the rest depends on mu_eff, so needs to be set again */ /* set the others using Nikolaus logic. If you want to tweak, you can parameterize over these defaults */ mucov = mueff; ccumsig = (mueff + 2.) / (n + mueff + 3.); ccumcov = 4. / (n + 4); double t1 = 2. / ((n+1.4142)*(n+1.4142)); double t2 = (2.*mucov-1.) / ((n+2.)*(n+2.)+mucov); t2 = (t2 > 1) ? 1 : t2; t2 = (1./mucov) * t1 + (1.-1./mucov) * t2; ccov = t2; damp = 1 + std::max(0.3,(1.-(double)n/(double)maxgen)) * (1+2*std::max(0.,sqrt((mueff-1.)/(n+1.))-1)) /* limit sigma increase */ / ccumsig; vector<double> mins(1,0.0); mins = parser.createParam( mins, "min-stdev", "Array of minimum stdevs, last one will apply for all remaining axes", 0, section).value(); if (mins.size() > n) mins.resize(n); if (mins.size()) { minStdevs = mins.back(); for (unsigned i = 0; i < mins.size(); ++i) { minStdevs[i] = mins[i]; } } vector<double> inits(1,0.3); inits = parser.createParam( inits, "init-stdev", "Array of initial stdevs, last one will apply for all remaining axes", 0, section).value(); if (inits.size() > n) inits.resize(n); if (inits.size()) { initialStdevs = inits.back(); for (unsigned i = 0; i < inits.size(); ++i) { initialStdevs[i] = inits[i]; } } }
int main(int argc, char *argv[]) { char c; FILE *inputf; int skiptoend, opencount, closecount, i, usech; long *loopstarts, *loopsts = calloc(LOOP_DEPTH, sizeof(long)); STACK_TYPE *stack, *stackstart = calloc(MAX, sizeof(STACK_TYPE)); if (argc == 2) { i = 1; } else if (argc == 3 && !strcmp(argv[1], "-c")) { usech = 1; i = 2; } else if (argc == 3 && !strcmp(argv[1], "-n")) { usech = 0; i = 2; } else { fprintf(stderr, "Invalid command\nThe valid command format is ./brainfuck [-c | -n] <filename>\n"); exit(1); } inputf = fopen(argv[i], "r"); if (!inputf) { fprintf(stderr, "Cannot open file %s\n", argv[i]); exit(1); } // give error if no memory if (!stackstart || !loopsts) { fprintf(stderr, "Memory allocation error\n"); exit(1); } inits(stackstart); initl(loopsts); stack = stackstart; loopstarts = loopsts; skiptoend = opencount = closecount = 0; // go through each character while ((c = fgetc(inputf)) != EOF) { // skip to first ] that isn't enclosed by an [ if (skiptoend) { if (c == '[') opencount++; if (c == ']') closecount++; if (c != ']' || (opencount - closecount)) continue; } switch (c) { case '+': ++*stack; break; case '-': --*stack; break; case '>': if (stack < stackstart + MAX - 1) // keep stack position within range ++stack; break; case '<': if (stack > stackstart) // keep stack position within range --stack; break; case ',': if (usech) *stack = getchar(); else scanf("%lld", stack); break; case '.': if (usech) putchar((char) *stack); else printf("%lld\n", (unsigned long long) *stack); break; case '[': if (!*stack) { skiptoend = opencount = 1; closecount = 0; } else if (!inloop(CURRENTPOS - 1)) { // check if I've already come here ++loopstarts; // inc(loopstart, 0); *loopstarts = CURRENTPOS - 1; // loopstart is located at the [ } break; case ']': if (!skiptoend) { // if the loop is continuing jumpto(*loopstarts); // go back to the [ } else { *loopstarts = 0; --loopstarts; // continue after the ] skiptoend = opencount = closecount = 0; } break; } } if (usech) putchar('\n'); fclose(inputf); free(loopsts); free(stackstart); // free(stack); }
int main(int argc ,char *argv[]) { inits(); close(sock_fd); return 0; }
int main(int argc,char *argv[]) { // decode arguments args(argc,argv); inits(); if(run_type==6) to_year=2010; // Read in Data // cout<< "Reading Data\n"; read_data(); // Set initial Params // cout<< "Initiallizing...\n"; init_state(); init_t(); calc_state(); if(fixed_d != 0) //run traf_mat once and only once (for faster prototyping) { calc_traf(); /* _vbc_vec<float> Uj(1,n_lakes); for(int j=1;j<=n_lakes;j++) { Uj(j) = 0; for(int i=1;i<=n_sources;i++) { Uj(j) += sources(i).Gij(j) * sources(i).Oi; } cout << Uj(j) << "\t" << 1-exp(- pow(0.001 * Uj(j), 1 ) ) << "\n"; } */ calc_traf_mat(); calc_pp(); } ofstream ll_("output/ll_test.dat"); if(FALSE) { calc_traf(); calc_traf_mat(); calc_pp(); //!! int tmp_t; for(int lake=1;lake<=n_lakes;lake++) { if(lakes(lake).invaded == 0 && lakes(lake).last_abs == 0 ) { for(int t=from_year;t<=to_year+2;t++) { // sample_t(); tmp_t=t_vec(lake); t_vec(lake)=t; calc_state(); calc_pp(); cout << lake << "\t" << t <<endl; ll_ << lake << "\t" << t <<"\t"<<l_hood()<<endl; } t_vec(lake)=tmp_t; } } } if(FALSE) // likelihood profile of d and e //if init_t is random, MLE d=e=0 (no effect of distance or size: CHECK) { d_par=-1; e_par=0; for(int i=0;i<=60;i++) { d_par=d_par+0.1; e_par=0; for(int j=0;j<=10;j++) { e_par=e_par + 0.1; calc_traf(); calc_traf_mat(); calc_pp(); ll_ << d_par << "\t" << e_par << "\t" << l_hood()<< endl; cout << d_par <<"\t"<< e_par << "\t" << l_hood()<< endl; } } } if(FALSE) //likelihood profile of alpha { chem_pars(1)=0; for(int i=0;i<=1000;i++) { chem_pars(1)+=0.0001; ll_ << chem_pars(1) << "\t" << l_hood()<< endl; } } //Just sim under the true alpha to see the t_vec distribution // to compare with sim_dat.R if(FALSE) { for(int lake_index=1;lake_index<=n_lakes;lake_index++) { lakes(lake_index).discovered=0; lakes(lake_index).last_abs=0; } for(int i=1;i<=1000;i++) { sim_spread(); write_t(); } } /// SEEDS /// //i d e c B_o NAUT KKUT MGUT //8394 1.06513 0.531416 0.000125572 -13.713 0.00405104 -0.00475339 0.0038181 // CAUT PPUT1 SIO3UR DOC COLTR ALKTI ALKT //0.00403173 0.0571088 1.28896 -0.31447 -0.00654376 0.0621327 -0.000480646 // PH COND25 SECCHI.DEPTH NA //0.00852002 0.00335544 0.0995729 -380.192 //0.407766 1.44137 0.417034 -10.8476 0.708086 -0.0150081 -0.404532 -0.512538 0.689779 0.43177-0.584563 -0.224491 0.786624 1.0269 0.868935 -0.0982729 0.37267 chem_pars(1)=-10; chem_pars(2)=0.7; chem_pars(3)=-0.01; //-2:1 MLE ~0 chem_pars(4)=-0.38; //-1.5:1.5 MLE ~0 chem_pars(5)=-0.5; //-0.4:0.2 MLE ~0 chem_pars(6)=0.68; //0:0.1 MLE 0.05 *** chem_pars(7)=0.43; //-0.4:0.2 MLE ~1.3 **** chem_pars(8)=-0.58; //-0.7:0.1 MLE ~-0.31 **** chem_pars(9)=-0.22; //-0.4:0.2 MLE ~-0.01 ** chem_pars(10)=0.78; //-0.1:0.1 MLE ~0.06 * chem_pars(11)=1.02; //-0.16:0.1 MLE ~0 chem_pars(12)=0.85; //-0.2:0.2 MLE ~0 chem_pars(13)=-0.09; //-0.04:0.01 MLE ~0 chem_pars(14)=0.37; //-0.3:0.3 MLE ~0.1 int test_ch=14; d_par=1.54; //float bb = l_hood(); if(ll) { float tmplhood; for(int i=1;i<=20;i++) { cerr << i << "\n"; //chem_pars(test_ch)=chem_pars(test_ch)+0.0013; d_par=d_par+0.05; calc_traf(); cerr << "A" << "\n"; calc_traf_mat(); cerr << "B" << "\n"; sim_spread(); cerr << "C" << "\n"; //write_t(); tmplhood = l_hood(); cerr << "D" << "\n"; ll_ << chem_pars(test_ch) << "\t" << tmplhood << "\n"; cout << d_par << "\t" << tmplhood << "\n"; } } ll_.close(); cout << "# sampled\t" << n_sampled << "\n"; if(run_type==1) { // FIT ON TRAF_PARS & SPREAD PARS ONLY (NO ENV) // // need a likelihood function wrapper to call l_hood() multiple times and average the result // to smooth out stochastic surface. // BOOTSTRAP RESAMPLING OF DATA (SAMPLED LAKES) TO GENERATE CI // float garbage=l_hood(); int n_reps = 1000; ofstream par_file; int n_pars; //13 env + intercept + d,c,gamma _vbc_vec<float> params1; _vbc_vec<float> dat1; _vbc_vec<float> MLE_params; if(!env) { if(sim) par_file.open("sims/gb_output/pred_pars.tab"); else par_file.open("output/pred_pars.tab"); n_pars=4; // d,c,gamma,alpha params1.redim(1,n_pars); dat1.redim(1,n_pars); MLE_params.redim(1,n_pars); params1(1)=1.27; params1(2)=1.48; params1(3)=0.0000489; params1(4)=0.00105; }else{ if(sim) par_file.open("sims/gb_output/pred_parsENV.tab"); else par_file.open("output/pred_parsENV.tab"); n_pars=18; //13 env + intercept + d,e,c,gamma params1.redim(1,n_pars); dat1.redim(1,n_pars); MLE_params.redim(1,n_pars); params1(1)=1.79; params1(2)=2; params1(3)=0.69; params1(4)=0.0000489; /// SEEDS /// params1(5)=-6.2; params1(6)=0.014; params1(7)=-0.08; //-2:1 MLE ~0 params1(8)=0.15; //-1.5:1.5 MLE ~0 params1(9)=0.21; //-0.4:0.2 MLE ~0 params1(10)=0.03; //0:0.1 MLE 0.05 *** params1(11)=-0.13; //-0.4:0.2 MLE ~1.3 **** params1(12)=-0.43; //-0.7:0.1 MLE ~-0.31 **** params1(13)=-0.007; //-0.4:0.2 MLE ~-0.01 ** params1(14)=0.056; //-0.1:0.1 MLE ~0.06 * params1(15)=0.0087; //-0.16:0.1 MLE ~0 params1(16)=0.081; //-0.2:0.2 MLE ~0 params1(17)=-0.015; //-0.04:0.01 MLE ~0 params1(18)=0.013; //-0.3:0.3 MLE ~0.1 } _vbc_vec<int> tmp_index_sampled; tmp_index_sampled = sampled_index; if(boot) { ofstream boot_file; if(sim) boot_file.open("sims/gb_output/boot_lakes.tab"); else boot_file.open("output/boot_lakes.tab"); for(int i=1;i<=n_reps;i++) { //Bootstrap resample // sampled_index = sample_w_replace(tmp_index_sampled); for(int j=1;j<=n_sampled;j++) boot_file << sampled_index(j) << "\t"; boot_file << "\n"; boot_file.flush(); // --- // simplex::clsSimplex<float> gertzen_rep; //gertzen_rep.set_param_small(1e-3); gertzen_rep.start(&dat1,¶ms1, &MLE_l_hood,n_pars, 1e-2); gertzen_rep.getParams(&MLE_params); cout << "\n\nMLE "<< i << " of " << n_reps << "\n\n"; for(int p=1;p<=n_pars;p++) par_file << MLE_params(p) <<"\t"; par_file << "\n"; par_file.flush(); } boot_file.close(); }else{ simplex::clsSimplex<float> gertzen_rep; //gertzen_rep.set_param_small(1e-3); gertzen_rep.start(&dat1,¶ms1, &MLE_l_hood,n_pars, 1e-2); gertzen_rep.getParams(&MLE_params); cout << "\n\nMLE\n"; for(int p=1;p<=n_pars;p++) par_file << MLE_params(p) <<"\t"; par_file << "\n"; par_file.flush(); // Print out distribution of alpha values at MLE ofstream alphas_file; alphas_file.open("output/alphas.tab",std::fstream::app); for(int i=1;i<=n_lakes;i++) { alphas_file << calc_alpha(i) << "\n"; } alphas_file.close(); } par_file.close(); } if(run_type==2) { //MCMC lib string mcmc_file("output/lib.mcmc"); if(env) { _vbc_vec<float> params(1,4+n_chem_var); _vbc_vec<float> prop_width(1,4+n_chem_var,1,4+n_chem_var); prop_width(1)=0.05; prop_width(2)=0.05; prop_width(3)=0.05; params(1)=0.4; params(2)=1.4; params(3)=0.42; for(int i=1;i<=n_chem_var+1;i++) { prop_width(i+3)=0.0001; params(i+3)=chem_pars(i); } prop_width(4)=0.1; _vbc_vec<float> prop_sigma; prop_sigma = diag(prop_width); // Print out prop_sigma for(int i=1;i<=n_chem_var+4;i++) { for(int j=1;j<=n_chem_var+4;j++) cout << prop_sigma(i,j) << " | "; cout << "\n"; } mcmcMD::run_mcmc(params, prop_sigma, &likelihood_wrapperMCMC_MD, &prior_MD, &restrict_MCMC_MD, 50000, 50, 1, mcmc_file.c_str(), true, true, true, 500, 4); }else { /// No env. _vbc_vec<float> params(1,4); _vbc_vec<float> prop_width(1,4,1,4); prop_width(1)=0.05; prop_width(2)=0.05; prop_width(3)=0.000001; prop_width(4)=0.00001; params(1)=1.27; params(2)=1.48; params(3)=0.0000489; params(4)=0.00105; _vbc_vec<float> prop_sigma; prop_sigma = diag(prop_width); // Print out prop_sigma for(int i=1;i<=4;i++) { for(int j=1;j<=4;j++) cout << prop_sigma(i,j) << " | "; cout << "\n"; } mcmcMD::run_mcmc(params, prop_sigma, &likelihood_wrapperMCMC_MD, &prior_MD, &restrict_MCMC_MD, 500000, 1, 1, mcmc_file.c_str(), true, true, true, 500, 5); } /* mcmcMD::run_mcmc(pms, props, &like, &prior, &restrictions, 500000, 1, 100, file_name.c_str(), TRUE, TRUE, 1000); */ } /// Sim from posterior /// if(run_type==3) sim_spread_posterior(); /// Traf tests //// if(run_type==4) { ofstream traf_ll_file("output/traf_ll.dat"); d_par=1.54; e_par=2; c_par=0.8; calc_traf(); calc_traf_mat(); calc_pp(); sim_spread(); cout << l_hood() <<"\n"; /* for(int i=1;i<=70;i++) { e_par=e_par+0.05; cout << e_par << "\t"; calc_traf(); calc_traf_mat(); calc_pp(); sim_spread(); traf_ll_file << e_par << "\t" << l_hood() << "\n"; cout << l_hood() <<"\t"; sim_spread(); traf_ll_file << e_par << "\t" << l_hood() << "\n"; cout << l_hood() <<"\t"; sim_spread(); traf_ll_file << e_par << "\t" << l_hood() << "\n"; cout << l_hood() <<"\n"; traf_ll_file << e_par << "\t" << l_hood() << "\n"; } for(int i=1;i<=10;i++) { e_par=e_par+0.2; c_par=0.8; calc_traf(); calc_traf_mat(); calc_pp(); for(int j = 1;j<=10;j++) { c_par=c_par+0.2; glb_alpha=0; //from MLE for(int k=1;k<=500;k++) { glb_alpha=glb_alpha+0.00001; sim_spread(); sim_spread(); sim_spread(); cout << e_par << "\t" << c_par << "\t" << glb_alpha << "\t" << l_hood() << "\n"; traf_ll_file << e_par << "\t" << c_par << "\t" << glb_alpha << "\t" << l_hood() << "\n"; } } } */ traf_ll_file.close(); calc_pp(); write_pp(); write_inv_stat(); } /// Holdout sets for internal AUC //// if(run_type==5) { int n_pars=4; _vbc_vec<float>params1(1,n_pars); // Read parameters values from file // ifstream pred_pars; if(sim) pred_pars.open("sims/gb_output/pred_pars.tab"); else pred_pars.open("output/pred_pars.tab"); for(int j=1;j<=n_pars;j++) pred_pars >> params1(j); pred_pars.close(); // -- // d_par=params1(1); e_par = 1; c_par=params1(2); gamma_par=params1(3); glb_alpha=params1(4); calc_traf(); calc_traf_mat(); //write_traf_mat(); //Sub-sample a holdout set from sampled lakes (pre-2010) int n_sub_sampled = 100,choose_from=0; _vbc_vec<int> index_2006_big(1,n_lakes); for(int i = 1; i<=n_lakes;i++) { if( (lakes(i).last_abs==2006 || lakes(i).discovered == 2006) ) { choose_from += 1; index_2006_big(choose_from)=i; } } _vbc_vec<int> index_2006(1,choose_from); for(int i = 1; i<=choose_from;i++) index_2006(i)=index_2006_big(i); ofstream prop_holdout_file; prop_holdout_file.open("output/holdout_sim_props.csv"); ofstream holdout_inv_file("output/holdout2006_data_status.csv"); _vbc_vec<int> holdout_inv_status(1,n_sub_sampled); _vbc_vec<int> indicies_holdout(1,n_sub_sampled); _vbc_vec<int> tmp_discovered(1,n_sub_sampled); _vbc_vec<int> tmp_last_abs(1,n_sub_sampled); cout << "Total 2006 lakes to choose from " << choose_from << "\n"; for(int rep=1;rep<=50;rep++) { indicies_holdout = sample_wo_replace(index_2006,n_sub_sampled); //Record the year_discovered of holdoutset for(int i = 1; i<=n_sub_sampled;i++) { if(lakes(indicies_holdout(i)).discovered == 2006) holdout_inv_status(i) = 1; else holdout_inv_status(i) = 0; //write year discovered if(i == n_sub_sampled) holdout_inv_file << holdout_inv_status(i) << "\n"; else holdout_inv_file << holdout_inv_status(i) << ","; //save last_abs and discoved tmp_discovered(i) = lakes(indicies_holdout(i)).discovered; tmp_last_abs(i) = lakes(indicies_holdout(i)).last_abs; //remove year discovered lakes(indicies_holdout(i)).discovered = 0; lakes(indicies_holdout(i)).last_abs = 0; } //SIM SPREAD _vbc_vec<float> prop_holdout_invaded(1,n_sub_sampled); for(int i=1;i<=n_sub_sampled;i++) prop_holdout_invaded(i) = 0; int n_sims=1000; for(int s=1; s<= n_sims; s++) { sim_spread(); for(int i=1;i<=n_sub_sampled;i++) { if(t_vec(indicies_holdout(i)) <= 2006) prop_holdout_invaded(i) += 1; } } //write prop inv for(int i=1;i<=n_sub_sampled;i++) { prop_holdout_invaded(i) = prop_holdout_invaded(i)/n_sims; if(i < n_sub_sampled) prop_holdout_file << prop_holdout_invaded(i) << ","; else prop_holdout_file << prop_holdout_invaded(i) << "\n"; //reset last_abs and discoved lakes(indicies_holdout(i)).discovered = tmp_discovered(i); lakes(indicies_holdout(i)).last_abs = tmp_last_abs(i); } } holdout_inv_file.close(); prop_holdout_file.close(); }
int main() { inits(); Shader text_shader("text.vs", "text.frag"); Shader ourShader("coordinate_systems.vs", "coordinate_systems.frag"); Shader bar_shader("bar.vs", "bar.frag"); inittext(text_shader); initbar(bar_shader); // Set up our vertex data (and buffer(s)) and attribute pointers msg(sizeof(vertices_indexed)); msg(sizeof(indices)); msg(sizeof(vertices)); #ifdef use_indexed makeglgeom_indexed(VBO_indexed, VAO_indexed, EBO_indexed, vertices_indexed, indices, sizeof(vertices_indexed), sizeof(indices)); #else makeglgeom(VBO, VAO, vertices, sizeof(vertices)); #endif // Load and create a texture makegltext(texture1, "resources/textures/container.jpg"); makegltext(texture2, "resources/textures/awesomeface.png"); GLint modelLoc = glGetUniformLocation(ourShader.Program, "model"); GLint viewLoc = glGetUniformLocation(ourShader.Program, "view"); GLint projLoc = glGetUniformLocation(ourShader.Program, "projection"); // Game loop while (!glfwWindowShouldClose(window)) { // Set frame time GLfloat currentFrame = glfwGetTime(); deltaTime = currentFrame - lastFrame; lastFrame = currentFrame; #ifdef RAWMOUSE acc += updatemouse(); #endif //vec2 diff = mouse - acc; //log //mousepos += acc; lag = lag_coeff*acc; //lag = lag_coeff*vec2(log(abs(acc.x)), log(abs(acc.y))); //if (acc.x < 0)lag.x *= -1.0f; //if (acc.y < 0)lag.y *= -1.0f; if (abs(lag.x) < 1e-4) lag.x = 0; if (abs(lag.y) < 1e-4) lag.y = 0; acc -= lag; camera.ProcessMouseMovement(lag.x, lag.y); show2(mouse); show2(lag); show2(acc); //show2(string(int(0.1f*length(acc)), '=')); //show2(string(int(10.f*length(lag)), '=')); // Check and call events ####################################### glfwPollEvents(); Do_Movement(); // Clear the colorbuffer glClearColor(0.2f, 0.2f, 0.2f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // texts ####################### int line = 0; for (auto&a : texts) { RenderText(text_shader, a.first + " " + a.second, 25.0f, (line + 1)*25.0f, 0.3f, glm::vec3(1, 1, 1)); ++line; } //RenderText(text_shader, "(C) LearnOpenGL.com", 540.0f, 570.0f, 0.5f, glm::vec3(0.3, 0.7f, 0.9f)); drawbar(bar_shader); // Draw our first triangle ####################### ourShader.Use(); // Bind Textures using texture units ####################### glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture1); glUniform1i(glGetUniformLocation(ourShader.Program, "ourTexture1"), 0); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, texture2); glUniform1i(glGetUniformLocation(ourShader.Program, "ourTexture2"), 1); // Create camera transformation ####################### glm::mat4 view; view = camera.GetViewMatrix(); glm::mat4 projection; projection = glm::perspective(glm::radians(camera.Zoom), (float)screenWidth / (float)screenHeight, 0.1f, 1000.0f); // Get the uniform locations // Pass the matrices to the shader glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view)); glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(projection)); #ifdef use_indexed glBindVertexArray(VAO_indexed); #else glBindVertexArray(VAO); #endif for (GLuint i = 0; i < 10; i++) { // Calculate the model matrix for each object and pass it to shader before drawing glm::mat4 model; model = glm::translate(model, cubePositions[i]); GLfloat angle = 20.0f * i; model = glm::rotate(model, angle, glm::vec3(1.0f, 0.3f, 0.5f)); glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model)); #ifdef use_indexed glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0); #else glDrawArrays(GL_TRIANGLES, 0, 36); #endif } glBindVertexArray(0); // Swap the buffers glfwSwapBuffers(window); } // Properly de-allocate all resources once they've outlived their purpose glDeleteVertexArrays(1, &VAO); glDeleteBuffers(1, &VBO); glfwTerminate(); ManyMouse_Quit(); return 0; }
Particle::Particle(char *l) { parser(l); behavior(); inits(); }
int main() { inits(); solve(0, 0, 0, 0, 0, 0, 0, -1); return 0; }
int main(void) { pump_stop(); int test1 = 0; int test = 50; // Serielle initialisieren inits(); init_ser(); puts("Herzlich willkommen zur Ausschankstation. Bitte Folgen Sie den Anweisungen.\n"); while(1){ pump_stop(); //falls die Pumpe noch läuft int fehlertoleranz = 7; int voll = 50; // Welche Menge soll abgefüllt werden puts("Bitte stellen Sie zur Kalibrierung den Becher auf und drücken Sie SW1 \n"); init_messung(); while(piobaseB->PIO_PDSR & KEY1){} //polling (KEY1) int becher = 0; becher = MasseMitGenauigkeit(); //Bechergewicht messen puts("Der Becher hat folgende Masse in Gramm: "); intOutput(becher); puts("\n"); puts("Drücken Sie SW2 um den Becher zu befüllen. \n"); while(piobaseB->PIO_PDSR & KEY2){} //polling (KEY2) if (MasseMitGenauigkeit() < becher+fehlertoleranz && MasseMitGenauigkeit() > becher -fehlertoleranz){ // pump_init(); pump_start(); int alteMasse = becher; int neueMasse = becher; int testMasse = becher; int ausgabe = 1; while ((neueMasse - becher) < voll){ // Solange Masse minus Bechergewicht kleiner als die gewünschte Menge ist, Schleife ausführen test1++; if(test1%test==0){ if(testMasse>=neueMasse){ pump_stop(); puts("keine Gewichtszunahme !! \n"); break; } testMasse = neueMasse; } alteMasse = neueMasse; neueMasse = MasseMitGenauigkeit(); if((neueMasse-becher) >= ausgabe){ puts(" im Becher sind "); intOutput(neueMasse-becher); puts(" Gramm \n"); ausgabe = neueMasse-becher+1; } if (neueMasse < 1 || (alteMasse+6) < neueMasse || (alteMasse-6) > neueMasse){ // Falls Becher weg genommen wird oder Gewichtsveränderung zu groß ist pump_stop(); puts("Fehler: Gewichtsveränderung zu groß \n"); break; } } pump_stop(); puts("Vorgang abgeschlossen \n\n"); } else{ pump_stop(); puts("Fehler: Gewichtsveränderung an Becher zu groß \n"); } } return 0; }
int main() { inits(); DHT22 * dhtS = new DHT22(18, "Sisämittari(DIG)"); DHT22 * dht2S = new DHT22(17, "Ulkomittari(DIG)"); BMP180 * bmp = new BMP180(0x77, "Painemittari(DIG)"); char *code = NULL; short prog = 1; clock_t timer1 = clock(); clock_t timer2 = clock(); for(tempSensIT it = tempSensors.begin(); it != tempSensors.end(); ++it) { it->second->update(); } //while(lirc_nextcode(&code) != 0) { while(1) { if(float(clock())/CLOCKS_PER_SEC - float(timer1)/CLOCKS_PER_SEC >= 0.012) { // Turn on DHT22's digitalWrite(20, HIGH); usleep(1000); for(tempSensIT it = tempSensors.begin(); it != tempSensors.end(); ++it) { it->second->update(); } digitalWrite(20, LOW); timer1 = clock(); } if(float(clock())/CLOCKS_PER_SEC - float(timer2)/CLOCKS_PER_SEC >= 0.25) { #ifdef HCDEBUG logfile << "MySQL connection: " << (mysql_ping(sqlcon) == 0 ? "Up" : "Down") << endl; #endif for(tempSensIT it = tempSensors.begin(); it != tempSensors.end(); ++it) { it->second->saveCurTemp(); } for(humSensIT it = humSens.begin(); it != humSens.end(); ++it) { it->second->saveCurHumi(); } for(pressSensIT it = pressSens.begin(); it != pressSens.end(); ++it) { it->second->saveCurPress(); } timer2 = clock(); } switch(prog) { case 0: { lcdClear(lcdHandle); break; } case 1: { lcdPrint1("Temperatures("+string(1, (unsigned char)(int)223)+"C)"); stringstream ss; for(tempSensIT it = tempSensors.begin(); it != tempSensors.end(); ++it) { ss << (int)it->second->getTemp() << " "; } lcdPrint2(ss.str()); break; } case 2: { lcdPrint1("Humidities(%)"); stringstream ss; for(humSensIT it = humSens.begin(); it != humSens.end(); ++it) { ss << (int)it->second->getHumi() << " "; } lcdPrint2(ss.str()); break; } case 3: { lcdPrint1("Pressures(hPa)"); stringstream ss; for(pressSensIT it = pressSens.begin(); it != pressSens.end(); ++it) { ss << (int)it->second->getPress() << " "; } lcdPrint2(ss.str()); break; } } if(code != NULL) { if(parseKey(code) == "KEY_SUSPEND") { if(shutdown()) { break; } } if(parseKey(code) == "KEY_MODE") { calibrateAnalogTempSensors(); } if(parseKey(code) == "KEY_0") { prog = 0; } if(parseKey(code) == "KEY_1") { prog = 1; } if(parseKey(code) == "KEY_2") { prog = 2; } free(code); } } delete diS; delete diS2; delete dhtS; delete dht2S; delete bmp; deinits(); return EXIT_SUCCESS; }
int getConst(double * constante, int * sh ){ int flag=0,mas=0,menos=0,pto=0,num=0; char aux[50]; int lenght=0; inits(aux,lenght); // inciando cadena while(flag==0){ gets(aux); //obteniendo cadena lenght= strlen(aux); int x=0; while(aux[x]!='\0'){ if((aux[x]-'0'>=0 &&aux[x]-'0'<=9)||aux[x]=='-'||aux[x]=='.'||aux[x]=='+'){ flag=1; if(aux[x]=='.') pto++; if(aux[x]=='-') menos++; if(aux[x]=='+') mas++; if((aux[x]-'0'>=0 &&aux[x]-'0'<=9)) num++; if((aux[x]=='-'||aux[x]=='+')&&(num>0)) menos=2; if((aux[x]=='-'||aux[x]=='+')&&(pto>0)) menos=2; } else{ flag=0; x= lenght-1; } x++; } if(flag==1){ *constante=atof(aux); if(pto>1||menos>1||mas>1) printf("Eso no es un número pero pienso que puedo tratar con %f \n\n",*constante); } else{ printf("Es en serio?, intenta de nuevo... Ingrese el valor requerido:\n"); *sh=1; } } return flag; }
Thunder::Thunder(char *l) { parser(l); behavior(); inits(); }