int main() { freopen("double_encodings.txt", "r", stdin); setbuf(stdout, NULL); int T, tc, i, j, k; scanf("%d", &T); for (tc = 1; tc <= T; tc++) { // input: a_cnt = 0, b_cnt = 0, c_cnt = 0; input_target_words(); //print_target_words(a_cnt, b_cnt, c_cnt); // solve: matched_cnt = 0; no_match = false; ed_idx = -1; /* check matched with B and C*/ check_matched(); //print_target_words(a_cnt, b_cnt, c_cnt); // output: print_outputs(); // clear buf: clear_buf(); } return 0; }
void key_ctrl_p(t_j *j) { t_key key; PS(j->caps.ti); while (true) { print_outputs(j); key = ft_getkey(); if (key.c == EOF || ft_keyequ(key, KEY('d', KEY_CTRL)) || ft_keyequ(key, KEY('c', KEY_CTRL)) || key.c == KEY_ESC) break ; ft_promptkey(&(j->ctrl_p_prompt), key); } PS(j->caps.te); }
void rednoise_bias_wrapper(control *c, timeseries *ts, output_options *o) { /* As mentioned already, spectra of time-series shows a decrease in spectral amplitude with increasing frequency - red-noise. By fitting a first-order autoregressive (AR1) process to the irregularly spaced time-series and transforming this to the frequency domain, the spectra can be tested against the hypothesis that the time-series originates from an AR1 process. See Schulz and Mudelsee (2002). */ int i, k, rprv, rnow; double sum = 0.0, fac90, fac, rho, rhosq, fnyq; /* estimate variance for raw periodgram - needed to correct data */ for (i = 1; i <= ts->nout; i++) { sum += ts->gxx[i]; } ts->var = ts->df * sum; if (c->EQUAL_DIST_DATA == TRUE) { ts->equalrho = calculate_persistence(ts); } else { /* Estimate tau - unless prescribed? */ if (ts->rho < 0.0) { /* Estimate a value for tau */ gettau(c, ts); /* can't have a negative tau */ if (ts->tau < 0.0) { ts->tau = 0.0; fprintf(stderr, "Negative tau returned, tau forced to zero: %f\n", ts->tau); } } else { ts->tau = -(ts->avgdt) / log(ts->rho); } } /* need to feed random numbers with a different seed - one off runs can simply use the clock. However, when running on multiple machines, there is potentially a scenerio where the same seed will be used, hence there is the option to feed the program with a seed on the cmd line. Ideally some bash func that generates a load of NEGATIVE ints. */ if (c->CMD_LINE_SEED == FALSE) { ts->idum = -fabs(rand()); } else { if (ts->seed > 0) { check_errors("Error: You must seed me with a negative int", __LINE__); } else { ts->idum = ts->seed; } } /* if debugging...*/ /*ts->idum = -123456789;*/ /* As the lomb-scargle spectrum cannot be directly corrected (dependent on the sampling intervals), a monte-Carlo ensemble, nsim AR1 time-series are generated. The difference between the average ensemble spectrum from the theoretical specturm is used as the correction. */ /* gneratre AR(1) spectra */ for (i = 1; i <= ts->nsim; i++) { /* set up AR1 junk */ make_AR1(c, ts); /* calculate lomb periodgram for AR1 spectra */ spectrum_wrapper(c, ts, ts->x, ts->red, ts->frq, ts->grr); /* scale and sum red-noise spectra */ sum = 0.0; for (k = 1; k <= ts->nout; k++) { sum += ts->grr[k]; } ts->varx = ts->df * sum; fac = ts->var / ts->varx; for (k = 1; k <= ts->nout; k++) { ts->grrsum[k] += ts->grr[k] * fac; } /* Need to zero grr array */ for (k = 1; k <= ts->nout; k++) { ts->grr[k] = 0.0; } } /* average red-noise spectrum */ sum = 0.0; for (k = 1; k <= ts->nout; k++) { ts->grravg[k] = ts->grrsum[k] / ((double)ts->nsim); sum += ts->grravg[k]; } ts->varx = ts->df * sum; fac = ts->var / ts->varx; for (k = 1; k <= ts->nout; k++) { ts->grravg[k] *= fac; } /* determine lag-1 autocorrelation coeff, which decays exponetially as a func of time */ if (c->EQUAL_DIST_DATA == TRUE) { rho = ts->equalrho; rhosq = rho * rho; } else { rho = exp((-1.0 * ts->avgdt) / ts->tau); rhosq = rho * rho; } /* If we want to test the spectrum against the background white noise spectrum instead then according to Mann and Lees (1996) Eq. 1, then setting rho to zero yields a white-noise process, I guess technically we also need to set rho in the AR1 stuff, but this seems fine as gredth is what we use to form the significance level */ if (c->SIGNIF_TEST == WHITE) { rho = 0.0; } /* set theoretical spectrum (e.g., Mann and Lees, 1996, Eq. 4) make area equal to that of the input time series */ fnyq = ts->frq[ts->nout]; sum = 0.0; for (k = 1; k <= ts->nout; k++) { /* power spectrum of an AR(1) process is given by ... */ ts->gredth[k] = (1.0 - rhosq) / (1.0 - 2.0 * rho * cos(M_PI * ts->frq[k] / fnyq) + rhosq); sum += ts->gredth[k]; } ts->varx = ts->df * sum; fac = ts->var / ts->varx; /* work out degrees of freedom and signif. The degrees of freedom affect the size of the confidence levels. Greater dof = a smoother spectrum, the lower the variance of the estimates and the narrower the confidence intervals and hence levels (Weedon 2003). */ getdof(c, ts); fac90 = getchi2(ts->dof, ts->alpha) / ts->dof; /* determine correction factor */ for (k = 1; k <= ts->nout; k++) { ts->gredth[k] *= fac; ts->corr[k] = ts->grravg[k] / ts->gredth[k]; ts->gxxc[k] = ts->gxx[k] / ts->corr[k]; ts->gredth[k] *= fac90; /* store up area under power spectrum to normalise by */ ts->rel_pow_rescale += ts->gxxc[k]; } if (c->DO_RUNS_TEST == TRUE) { /* Check it is appropriate to use an AR1 model to describe the time-series Using a non-parametric test according to Bendat and Piersol, 1986, Random data, 2nd ed, wiley: New York, pg 95. */ if ((c->WINDOW_TYPE != RECTANGULAR) || (ts->ofac >= 1.5) || (ts->n50 != 1)) { check_errors("You can only apply the runs test using a rectangular window, ofac = 1.0, and segs = 1", __LINE__); } ts->runs_count = 1; rprv = SIGN(1.0, ts->gxxc[1] - ts->gredth[1]); for (k = 1; k <= ts->nout; k++) { rnow = SIGN(1.0, ts->gxxc[k] - ts->gredth[k]); if (rnow != rprv) { ts->runs_count++; } rprv = rnow; } /* note I have added 0.5 at the end to make sure rounding when converting to int is right */ ts->rcrithlo = (int)((pow((-0.79557086 + 1.0088719 * sqrt((double)(ts->nout/2))), 2.0)) + 0.5); ts->rcrithi = (int)((pow(( 0.75751462 + 0.9955133 * sqrt((double)(ts->nout/2))), 2.0)) + 0.5); print_outputs(c, ts, o); } return; }
int main(int argc, char **argv) { /* setup up space to pass stuff around in */ control *c; if ((c = malloc(sizeof(control))) == NULL) { check_errors("Control structure: Not allocated enough memory", __LINE__); } timeseries *ts; if ((ts = malloc(sizeof(timeseries))) == NULL) { check_errors("Timeseries structure: Not allocated enough memory", __LINE__); } meta *m; if ((m = malloc(sizeof(meta))) == NULL) { check_errors("Meta structure: Not allocated enough memory", __LINE__); } output_options *o; if ((o = malloc(sizeof(output_options))) == NULL) { check_errors("Output_options structure: Not allocated enough memory", __LINE__); } /* setup initial junk */ setup_initial_conditions(c, ts, o); /* send sweep along the command line */ clparse(argc, argv, c, ts, o); /* check the input file is on the stdin? */ check_stdin(__LINE__); /* read data in from stdin */ read_input_file(argv, c, ts, o); /* setup space for working arrays and other misc stuff */ allocate_working_environment(c, ts); /* calculate lomb periodgram for raw time-series */ spectrum_wrapper(c, ts, ts->x, ts->y, ts->frq, ts->gxx); /* Calculate red noise bias and correct periodgram - need to generate a seed ONCE */ srand (time(NULL)); rednoise_bias_wrapper(c, ts, o); /* dump out what you need */ print_outputs(c, ts, o); /* tidy up */ free_array_double(ts->gxx); free_array_double(ts->frq); free_array_double(ts->red); free_array_double(ts->grr); free_array_double(ts->grrsum); free_array_double(ts->gredth); free_array_double(ts->corr); free_array_double(ts->gxxc); free_array_double(ts->grravg); free_array_double(ts->x); free_array_double(ts->y); free(c); free(ts); free(m); free(o); return (0); }
int main(int argc, char *argv[]){ FILE *fp; // stimulus file handle char filename[50] = "stim.txt"; // stimulus file name, can be overwritten on cmdline // if filename given on commandline use it otherwise use default filename if (argc == 2) {strcpy(filename, argv[1]);} else {strcpy(filename, "stim.txt");} int opt = 0; // parse the cmdline while ((opt = getopt(argc, argv, "i:p:")) != -1) { switch(opt) { case 'i': strcpy(filename, optarg); break; case 'p': available_pf = (u32) strtol(optarg,NULL,10); validate_pf_number(available_pf); break; case '?': if (optopt == 'i'){ printf("USAGE: -i <filename>\n\n"); return -1; } else if (optopt == 'p') { printf("USAGE: -p <numpages>\n\n"); return -1; } else { printf("Valid switches are:\n"); printf("\t -i <input_filename>\n\t -p <numpages>\n\n"); return -1; break; } } } // open the input file fp = fopen (filename,"r"); if (NULL == fp){ fprintf (stderr, "Failed to open input file. This is fatal!\n"); exit(0); } //call function to allocate memory to PD init_PD(); // loop through input file an feed commands to sim do { get_command(fp); if (strcmp(cmd, "-v") == MATCH) { printf("VMM Simulator Ver 0.1\n"); exit(-1); } else if (strcmp(cmd, "w") == MATCH || strcmp(cmd, "r") == MATCH ) { // update read/wrote/access statistics num_accesses ++; if (strcmp(cmd, "w") == MATCH) {num_writes ++;} else {num_reads ++;} parse_addr(addr); if ( t_flag == 1 ){ printf(" %s 0x%08X\n", cmd, addr); } if (is_PT_present(working_addr.PD_index) == 1) { //check the user page present if(is_UP_present(working_addr.PD_index, working_addr.PT_index) == 1) { total_cycles += 20; //if the address exist, it considers memory access //printf("get here few time\n"); } else //the PT exists but not the user page { if (available_pf == used_pf) // no pf avail then evict one page evict_page(); create_user_page(working_addr.PD_index, working_addr.PT_index,cmd); } } else // new PT and UP need to created { while (available_pf < (used_pf + 2)) // create 2 avail pf evict_page(); create_page_table(working_addr.PD_index, cmd); create_user_page(working_addr.PD_index, working_addr.PT_index, cmd); } } if (d_flag == 1){dump_vmm();} } while (strcmp (cmd, "EOF")); num_physical_frames = 1 + num_PT + num_UP; print_outputs(); }