static int FinishPage(RING * gbl, int inlist, int infile, int y) { int shown = FALSE; int foo; off_t length = 0; while (y < LINES - 1) y = typeline(y, FALSE); move(LINES - 1, 0); (void) standout(); PRINTW("---lines %d to %d", TopOfPage(infile, &foo) + 1, infile); if (inlist >= 0) { int oldy, oldx; int save = gbl->AT_opt; getyx(stdscr, oldy, oldx); (void) standend(); gbl->AT_opt = TRUE; shown = reshow(gbl, (unsigned) inlist); gbl->AT_opt = save; gbl->mrkfile = -1; markC(gbl, TRUE); (void) standout(); move(oldy, oldx); } if ((length = MaxP()) != 0) { off_t num = ftell(InFile); PRINTW(": %.1f%%", ((double) num * 100.) / (double) length); } PRINTW("---"); (void) standend(); PRINTW(" "); clrtoeol(); return shown; }
int main() { int n, m, x, y, t; float *p; while (scanf("%d%d%d%d%d", &n, &m, &x, &y, &t) != EOF) { p = new float[n * m]; int i = 0; int size = n * m; while (i < size) { scanf("%f", p + i); i++; } MaxP(p, n, m, x, y, t); delete[] p; } return 0; }
int main(int argc, char *argv[]) { ub4 tots=0; ub4 ts, r, bts, div; ub4 q1 = 24; ub4 q2 = 28; double totSigma=0.0; double totRange=0.0; double sigma,range,mSigma,mRange; // timer time_t a,z; // rounds qi = pow(2,q1); // check the command line if (argc<=1) { usage(); exit(0); } if (argc>=2) q1 = atoi(argv[1]); if (argc>=3) q2 = atoi(argv[2]); if (argc>=4) rng= atoi(argv[3]) % 9; if (argc>=5) strcpy(s,argv[4]); #ifdef TEST #ifdef __TINYC__ puts("Tiny C"); #endif #ifdef __WATCOMC__ puts("Open Watcom C"); #endif #ifdef _MSC_VER puts("Microsoft Visual C"); #endif #ifdef __GNUC__ puts("GNU C"); #endif #endif #if __STDC_VERSION__ >= 199901L puts("C99 supported."); #endif #ifdef MOD printf("MOD: "); #endif #ifdef LIM printf("LIM: "); #endif #ifdef SAM printf("SAM: "); #endif div = q2-q1+1; printf("%d %s trial sets in [2**%d..2**%d]\n",div,RNGs[rng],q1,q2); puts("Trial Range Sigma Time"); puts("------------------------------------------"); for (j=q1; j<=q2; j++) { for (i=0; i<MODU; i++) totals[i]=0; probtot = 0.0; qi = pow(2,j); rSeed(rng,s,rStateSize(rng)*7); time(&a); for (q=0; q<qi; q++) { #ifdef MOD r=rRandom(rng) % MODU; #else #ifdef LIM r=Lim(rng); #endif r=Sam(rng); #endif totals[r]++; } time(&z); ts=(size_t)(z-a); tots+=ts; for (i=0; i<MODU; i++) { // expected probabilities expect[i] = (double)1/MODU; // actual probabilities prob[i]=(double)totals[i]/qi; // probtot holds total of probabilities - it should converge to 1.0 probtot=probtot+prob[i]; // collect value-names & decide output format values[i] = i + 'A'; } sigma = Sigma(0,MODM1); range = prob[MaxP(0,MODM1)]-prob[MinP(0,MODM1)]; totSigma+=sigma; totRange+=range; printf("2**%d %1.7f %1.7f %3d s\n",j,range,sigma,ts); } puts("------------------------------------------"); mSigma = (double)totSigma/div; mRange = (double)totRange/div; printf("Mean: %1.7f %1.7f %4d s\n",mRange,mSigma,tots); #ifdef TEST puts(""); for (i=0; i<MODU; i++) printf("%2c) %1.7f\n",values[i],prob[i]); #endif return 0; }
void dedtype(RING * gbl, char *name, int inlist, int binary, int stripped, int isdir) { int had_eof; int c; int count, /* ...and repeat-count */ y, /* current line-in-screen */ shift = COLS / 4, /* amount of left/right shift */ done = FALSE, shown = FALSE, infile = -1; /* # of lines processed */ OFF_T skip = 0; tabstop = 8; Shift = 0; UsePattern = FALSE; OptBinary = binary; OptStripped = stripped; if (isdir && !OptBinary) { DIR *dp; DirentT *de; char bfr[MAXPATHLEN]; # define INO_FMT "%5lu" if ((InFile = tmpfile()) == 0) { warn(gbl, "tmp-file"); return; } if ((dp = opendir(name)) != 0) { while ((de = readdir(dp)) != NULL) { (void) ded2string(gbl, bfr, (int) NAMLEN(de), de->d_name, FALSE); FPRINTF(InFile, INO_FMT, (unsigned long) de->d_ino); FPRINTF(InFile, " %s\n", bfr); } (void) closedir(dp); rewind(InFile); } else { warn(gbl, "opendir"); FCLOSE(InFile); return; } } else InFile = fopen(name, "r"); in_dedtype = TRUE; /* disable clearing of workspace via A/a cmd */ if (InFile) { int jump = 0; dlog_comment("type \"%s\" (%s %s)\n", name, OptBinary ? "binary" : "text", isdir ? "directory" : "file"); to_work(gbl, FALSE); dyn_init(&my_text, BUFSIZ); dyn_init(&my_over, BUFSIZ); max_lines = -1; MarkLine(&infile); while (!done) { if (jump) { #if defined(HAVE_WSCRL) && defined(HAVE_WSETSCRREG) /* * If we're doing single-line scrolling past * the point we've read in the file, try to * cache pointers so that the scrolling logic * will go more smoothly. */ if (jump > 0 && jump < NumP(1) && infile + NumP(1) >= max_lines) { int line = infile; (void) StartPage(&line, TRUE, &had_eof); } #endif (void) JumpBackwards(&infile, jump); jump = 0; } markC(gbl, TRUE); y = StartPage(&infile, (int) skip, &had_eof); if (skip && !was_interrupted) { if (feof(InFile)) { skip = 0; jump = NumP(1); } else { IgnorePage(infile); skip--; } continue; } if (had_eof) { int blank; infile = TopOfPage(infile, &blank); (void) JumpToLine(infile); y = StartPage(&infile, 0, &had_eof); } shown |= FinishPage(gbl, inlist, infile, y); jump = NumP(1); reset_catcher(); switch (c = dlog_char(gbl, &count, 1)) { case CTL('K'): deddump(gbl); break; case 'w': retouch(gbl, 0); break; case '\t': if (OptBinary) { beep(); } else { tabstop = (count <= 1) ? (tabstop == 8 ? 4 : 8) : count; } break; case 'q': done = TRUE; break; case KEY_HOME: case '^': jump = infile; break; case KEY_END: case '$': infile = max_lines; skip = MaxP(); break; case KEY_PPAGE: case '\b': case 'b': if (AtTop(infile)) { beep(); } else { jump += NumP(count); } break; case KEY_NPAGE: case '\n': case ' ': case 'f': jump = 0; skip = count - 1; break; case '<': case CTL('L'): LeftOrRight(-shift * count); break; case '>': case CTL('R'): LeftOrRight(shift * count); break; case KEY_LEFT: case 'h': LeftOrRight(-count); break; case KEY_DOWN: case 'j': jump = NumP(1) - count; if ((infile - jump) > max_lines) { skip = (-jump + NumP(1) - 1) / NumP(1); jump = 0; } break; case KEY_UP: case 'k': if (AtTop(infile)) { beep(); } else { jump += count; } break; case KEY_RIGHT: case 'l': LeftOrRight(count); break; /* move work-area marker */ case 'A': count = -count; jump -= count; /*FALLTHRU */ case 'a': markset(gbl, (unsigned) (mark_W + count)); break; case '/': case '?': case 'n': case 'N': FindPattern(gbl, &infile, c); break; default: beep(); } } FCLOSE(InFile); if (shown) (void) reshow(gbl, (unsigned) inlist); showMARK(gbl->Xbase); showC(gbl); } else warn(gbl, name); in_dedtype = FALSE; }