int main(int argc, char **argv) { int l = LENG, cbsize = CBSIZE, index; FILE *fp = stdin, *fpcb = NULL; double *x, *cb; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv + 1)) { case 'l': l = atoi(*++argv); --argc; break; case 'n': l = atoi(*++argv) + 1; --argc; break; case 's': cbsize = atoi(*++argv); --argc; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else if (fpcb == NULL) fpcb = getfp(*argv, "rb"); else fp = getfp(*argv, "rb"); fseek(fpcb, 0, 2); #ifdef DOUBLE cbsize = ftell(fpcb) / sizeof(double) / l; #else cbsize = ftell(fpcb) / sizeof(float) / l; #endif /* DOUBLE */ rewind(fpcb); x = dgetmem(l + cbsize * l); cb = x + l; if (freadf(cb, sizeof(*cb), cbsize * l, fpcb) != cbsize * l) { fprintf(stderr, "%s : Codebook size error!\n", cmnd); return (1); } while (freadx(&index, sizeof(index), 1, fp) == 1) { ivq(index, cb, l, x); fwritef(x, sizeof(*x), l, stdout); } return (0); }
int main(int argc, char *argv[]) { FILE *fp; char *s, *infile = NULL, c; void nan_tmp(FILE *); if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) { if (*(s = *++argv) == '-') { c = *++s; switch (c) { case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, c); usage(1); break; } } else infile = s; } if (infile) fp = getfp(infile, "rb"); else fp = stdin; nan_tmp(fp); return (0); }
int main(int argc, char **argv) { int m = ORDER, l = FLNG, flag, t = 0; FILE *fp = stdin; double *x, *a, f = MINDET; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv + 1)) { case 'm': m = atoi(*++argv); --argc; break; case 'l': l = atoi(*++argv); --argc; break; case 'f': f = atof(*++argv); --argc; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else fp = getfp(*argv, "rb"); x = dgetmem(l + m + 1); a = x + l; while (freadf(x, sizeof(*x), l, fp) == l) { flag = lpc(x, l, a, m, f); switch (flag) { case -1: fprintf(stderr, "%s : The coefficient matrix of the normal equation is singular at %dth frame!\n", cmnd, t); exit(1); break; case -2: fprintf(stderr, "%s : Extracted LPC coefficients become unstable at %dth frame!\n", cmnd, t); break; } fwritef(a, sizeof(*a), m + 1, stdout); t++; } return (0); }
int main(int argc, char **argv) { int m = ORDER, stable, i; FILE *fp = stdin; double *k, *a, g = GAMMA; Boolean flags = STABLE; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv + 1)) { case 'm': m = atoi(*++argv); --argc; break; case 'g': g = atof(*++argv); --argc; break; case 'c': g = atoi(*++argv); --argc; if (g < 1) fprintf(stderr, "%s : value of c must be c>=1!\n", cmnd); g = -1.0 / g; break; case 's': flags = 1 - flags; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else fp = getfp(*argv, "rb"); a = dgetmem(m + m + 2); k = a + m + 1; while (freadf(a, sizeof(*a), m + 1, fp) == m + 1) { if (g != 1.0) for (i = 1; i <= m; i++) a[i] *= g; stable = lpc2par(a, k, m); if (flags) fwritex(&stable, sizeof(stable), 1, stdout); else fwritef(k, sizeof(*k), m + 1, stdout); } return (0); }
int main(int argc, char **argv) { int l = LENG, index = INDEX, size = SIZE, i; FILE *fp = stdin, *fpi = NULL; double *x; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv + 1)) { case 'l': l = atoi(*++argv); --argc; break; case 'i': index = atoi(*++argv); --argc; break; case 's': size = atoi(*++argv); --argc; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else if (fpi == NULL) fpi = getfp(*argv, "rb"); else fp = getfp(*argv, "rb"); x = dgetmem(l); while (freadf(x, sizeof(*x), l, fp) == l && freadx(&i, sizeof(i), 1, fpi) == 1) if (i == index) fwritef(x, sizeof(*x), l, stdout); return 0; }
int main(int argc, char **argv) { int i, j = 0, period = PERIOD, start = START, fleng = LENG; FILE *fp = stdin; double *x; Boolean padinput = PADINPUT; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv + 1)) { case 'p': period = atoi(*++argv); --argc; break; case 's': start = atoi(*++argv); --argc; break; case 'l': fleng = atoi(*++argv); --argc; break; case 'd': padinput = 1 - padinput; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else fp = getfp(*argv, "rb"); x = dgetmem(period * fleng); fwritef(x, sizeof(*x), start * fleng, stdout); while (freadf(x, sizeof(*x), fleng, fp) == fleng) { if (padinput) { for (i = fleng; i < period * fleng; i++) { if (j >= fleng) j = 0; x[i] = x[j]; j++; } } fwritef(x, sizeof(*x), period * fleng, stdout); } return (0); }
int main(int argc, char **argv) { int period = PERIOD, start = START, fleng = LENG, i; FILE *fp = stdin; double *x; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv + 1)) { case 'p': period = atoi(*++argv); --argc; break; case 's': start = atoi(*++argv); --argc; break; case 'l': fleng = atoi(*++argv); --argc; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else fp = getfp(*argv, "rb"); x = dgetmem(fleng); for (i = 0; i < start; i++) if (freadf(x, sizeof(*x), fleng, fp) != fleng) return (1); i = period; while (freadf(x, sizeof(*x), fleng, fp) == fleng) { if (i == period) fwritef(x, sizeof(*x), fleng, stdout); i--; if (i == 0) i = period; } return 0; }
int main(int argc, char *argv[]) { FILE *fp = stdin; double *x, *s; int leng = LENG, nv = -1, k, lp; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv + 1)) { case 'l': leng = atoi(*++argv); --argc; break; case 'n': leng = atoi(*++argv) + 1; --argc; break; case 't': nv = atoi(*++argv); --argc; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else fp = getfp(*argv, "rb"); s = dgetmem(leng + leng); x = s + leng; while (!feof(fp)) { for (k = 0; k < leng; ++k) s[k] = 0.0; for (lp = nv; lp;) { if (freadf(x, sizeof(*x), leng, fp) != leng) break; for (k = 0; k < leng; ++k) s[k] += x[k]; if (nv != -1) --lp; } if (lp == 0 || nv == -1) fwritef(s, sizeof(*s), leng, stdout); } return (0); }
int main(int argc, char **argv) { int start = START, leng = 16384, i; FILE *fp = stdin; double *x; Boolean keep = KEEP; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv + 1)) { case 's': start = atoi(*++argv); --argc; break; case 'f': keep = 1 - keep; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else fp = getfp(*argv, "rb"); if (start > leng) { fprintf(stderr, "%s : Start point %d should be %d or less!\n", cmnd, start, leng); exit(1); } x = dgetmem(leng); while ((i = freadf(x + start, sizeof(*x), leng - start, fp)) == leng - start) { fwritef(x, sizeof(*x), leng - start, stdout); movem(x + leng - start, x, sizeof(*x), start); } if (keep) fwritef(x, sizeof(*x), i, stdout); else fwritef(x, sizeof(*x), i + start, stdout); exit(0); }
void main(int argc, char **argv) { int m1 = ORDERC1, m2 = ORDERC2; FILE *fp = stdin; double *c1, *c2, a1 = ALPHA1, a2 = ALPHA2, a, atof(); if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv+1)) { case 'm': m1 = atoi(*++argv); --argc; break; case 'M': m2 = atoi(*++argv); --argc; break; case 'a': a1 = atof(*++argv); --argc; break; case 'A': a2 = atof(*++argv); --argc; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c' !\n", cmnd, *(*argv+1)); usage(1); } } else fp = getfp(*argv, "r"); c1 = dgetmem(m1+m2+2); c2 = c1 + m1 + 1; a = (a2 - a1) / (1 - a1*a2); while (freadf(c1, sizeof(*c1), m1+1, fp) == m1+1){ freqt(c1, m1, c2, m2, a); fwritef(c2, sizeof(*c2), m2+1, stdout); } exit(0); }
int main(int argc, char *argv[]) { FILE *fp = stdin; int size; double ymin = YMIN, ymax = YMAX; double *x, *y; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { argc--; switch (*(*argv + 1)) { case 'y': if ((*(*argv + 2)) == 'm') { switch (*(*argv + 3)) { case 'i': ymin = atof(*++argv); ymax = FLT_MAX; break; case 'a': ymax = atof(*++argv); ymin = FLT_MIN; break; } } else { ymin = atof(*++argv); argc--; ymax = atof(*++argv); } break; case 'h': default: usage(1); } } else fp = getfp(*argv, "rb"); x = dgetmem(2 * 256); y = x + 256; while ((size = freadf(x, sizeof(*x), 256, fp)) != 0) { clip(x, size, ymin, ymax, y); fwritef(y, sizeof(*y), size, stdout); } return 0; }
void firinit(void) { FILE *fp; fp = getfp(coef, "rt"); flengdn = freada(hdn, RBSIZE + 1, fp); fclose(fp); if (--flengdn < 0) { fprintf(stderr, "%s : Cannot read filter coefficients!\n", cmnd); exit(1); } if (start) { start = flengdn / (2 * d_rate); } }
int main(int argc, char **argv) { double g = GAMMA, *c; int m = ORDER; FILE *fp = stdin; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv + 1)) { case 'g': g = atof(*++argv); --argc; break; case 'c': g = atoi(*++argv); --argc; if (g < 1) fprintf(stderr, "%s : value of c must be c>=1!\n", cmnd); g = -1.0 / g; break; case 'm': m = atoi(*++argv); --argc; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else fp = getfp(*argv, "rb"); c = dgetmem(m + 1); while (freadf(c, sizeof(*c), m + 1, fp) == m + 1) { ignorm(c, c, m, g); fwritef(c, sizeof(*c), m + 1, stdout); } return (0); }
int main(int argc, char **argv) { double x, y, max = MAXVALUE, mu = MU, atof(); Boolean decoder = DECODER; FILE *fp = stdin; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv + 1)) { case 'v': max = atof(*++argv); --argc; break; case 'u': mu = atof(*++argv); --argc; break; case 'c': decoder = FA; break; case 'd': decoder = TR; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else fp = getfp(*argv, "rb"); if (!decoder) while (freadf(&x, sizeof(x), 1, fp) == 1) { y = ulaw_c(x, max, mu); fwritef(&y, sizeof(y), 1, stdout); } else while (freadf(&x, sizeof(x), 1, fp) == 1) { y = ulaw_d(x, max, mu); fwritef(&y, sizeof(y), 1, stdout); } return (0); }
int close(int fd) { int error; struct file *fp; if (getfp(fd, &fp)) return (EBADF); error = (*fp->f_ops->fo_close)(fp); if (error) { errno = error; return -1; } else { ffree(fp); return 0; } }
int main(int argc, char **argv) { FILE *fp = stdin; char *s, *infile = NULL, c; double *x, *r; int l = LENG, np = ORDER; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) { if (*(s = *++argv) == '-') { c = *++s; if (*++s == '\0') { s = *++argv; --argc; } switch (c) { case 'm': np = atoi(s); break; case 'l': l = atoi(s); break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, c); usage(1); break; } } else infile = s; } if (infile) fp = getfp(infile, "rb"); x = dgetmem(l + np + 1); r = x + l; while (freadf(x, sizeof(*x), l, fp) == l) { acorr(x, l, r, np); fwritef(r, sizeof(*r), np + 1, stdout); } return (0); }
int main(int argc, char **argv) { int l = LENG, num = 0; FILE *fp = stdin; double *x, xx, ave = 0.0; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv + 1)) { case 'l': l = atoi(*++argv); --argc; break; case 'n': l = atoi(*++argv) + 1; --argc; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else fp = getfp(*argv, "rb"); if (l > 0) { x = dgetmem(l); while (freadf(x, sizeof(*x), l, fp) == l) { ave = average(x, l); fwritef(&ave, sizeof(ave), 1, stdout); } } else { while (freadf(&xx, sizeof(xx), 1, fp) == 1) { ave += xx; num++; } ave /= num; fwritef(&ave, sizeof(ave), 1, stdout); } return (0); }
int main(int argc, char **argv) { int linenum = 0; int stdinmode = 0; char buf[512]; FILE *fp; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) { if (**++argv == '-') { switch (*(*argv + 1)) { case 'n': linenum = 1; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else { stdinmode = -1; fp = getfp(*argv, "rt"); while (fgets(buf, 512, fp) != 0) { if (linenum > 0) fprintf(stderr, "%6d ", linenum++); fputs(buf, stderr); } } } if (stdinmode == 0) { while (fgets(buf, 512, stdin) != 0) { if (linenum > 0) fprintf(stderr, "%6d ", linenum++); fputs(buf, stderr); } } return 0; }
int main(int argc, char **argv) { int m = ORDERC, n = ORDERR, l = FLENG; FILE *fp = stdin; double *c, *r; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv + 1)) { case 'm': m = atoi(*++argv); --argc; break; case 'M': n = atoi(*++argv); --argc; break; case 'l': l = atoi(*++argv); --argc; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else fp = getfp(*argv, "rb"); c = dgetmem(m + n + 2); r = c + m + 1; while (freadf(c, sizeof(*c), m + 1, fp) == m + 1) { c2acr(c, m, r, n, l); fwritef(r, sizeof(*r), n + 1, stdout); } return (0); }
int main(int argc, char **argv) { int m = ORDER, m1; FILE *fp = stdin; double a = ALPHA, *x; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv + 1)) { case 'a': a = atof(*++argv); --argc; break; case 'm': m = atoi(*++argv); --argc; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else fp = getfp(*argv, "rb"); m1 = m + 1; x = dgetmem(m1); while (freadf(x, sizeof(*x), m1, fp) == m1) { mc2b(x, x, m, a); fwritef(x, sizeof(*x), m1, stdout); } return (0); }
int main(int argc, char **argv) { int m = ORDER; FILE *fp = stdin; double *r, *csm; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv + 1)) { case 'm': m = atoi(*++argv); --argc; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else fp = getfp(*argv, "rb"); if (m % 2 == 0) { fprintf(stderr, "%s : Order of autocorrelation must be odd!\n", cmnd); return 1; } r = dgetmem(m + 1 + m + 1); csm = r + m + 1; while (freadf(r, sizeof(*r), m + 1, fp) == m + 1) { acr2csm(r, csm, m); fwritef(csm, sizeof(*csm), m + 1, stdout); } return 0; }
int main(int argc, char **argv) { int m = ORDER, flag; FILE *fp = stdin; double *r, *a, f = MINDET; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv + 1)) { case 'm': m = atoi(*++argv); --argc; break; case 'f': f = atof(*++argv); --argc; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else fp = getfp(*argv, "rb"); a = dgetmem(m + m + 2); r = a + m + 1; while (freadf(r, sizeof(*r), m + 1, fp) == m + 1) { flag = levdur(r, a, m, f); fwritef(a, sizeof(*a), m + 1, stdout); } return (0); }
void main(int argc, char **argv) { int m = ORDER, i; FILE *fp = stdin; double *x, k; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv+1)) { case 'm': m = atoi(*++argv); --argc; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c' !\n", cmnd, *(*argv+1)); usage(1); } } else fp = getfp(*argv, "r"); x = dgetmem(m+1); while(freadf(x, sizeof(*x), m+1, fp) == m+1){ norm0(x, x, m); fwritef(x, sizeof(*x), m+1, stdout); } exit(0); }
int main(int argc, char **argv) { int m = DEF_M; FILE *fp = stdin; double *csm, *r; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv + 1)) { case 'm': m = atoi(*++argv); --argc; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else fp = getfp(*argv, "rb"); csm = dgetmem(2 * m + 2 * m); r = csm + 2 * m; while (freadf(csm, sizeof(*csm), 2 * m, fp) == 2 * m) { csm2acr(csm, r, m); fwritef(r, sizeof(*r), 2 * m, stdout); } return 0; }
int main(int argc, char **argv) { int m = ORDER; FILE *fp = stdin; double *k, *a; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv + 1)) { case 'm': m = atoi(*++argv); --argc; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else fp = getfp(*argv, "rb"); a = dgetmem(m + m + 2); k = a + m + 1; while (freadf(k, sizeof(*k), m + 1, fp) == m + 1) { par2lpc(k, a, m); fwritef(a, sizeof(*a), m + 1, stdout); } return 0; }
int main(int argc, char *argv[]) { FILE *fp = stdin, *fp_eigen = NULL; int i, j, k, n = PRICOMP_ORDER, leng = LENG, total = -1; BOOL out_evecFlg = FALSE, out_evalFlg = FALSE; double sum; double *buf = NULL; double *mean = NULL, **var = NULL; double eps = EPS; int itemax = ITEMAX; double **e_vec = NULL, *e_val = NULL; /* eigenvector and eigenvalue */ double *cont_rate = NULL; /* contribution rate */ double jacobi_conv; float_list *top, *cur, *prev, *tmpf, *tmpff; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if ((**++argv) == '-') { switch (*(*argv + 1)) { case 'l': leng = atoi(*++argv); --argc; break; case 'n': n = atoi(*++argv); --argc; break; case 'e': eps = atof(*++argv); --argc; break; case 'i': itemax = atoi(*++argv); --argc; break; case 'v': out_evecFlg = TRUE; break; case 'V': out_evalFlg = TRUE; fp_eigen = getfp(*++argv, "wb"); --argc; break; case 'h': usage(EXIT_SUCCESS); default: fprintf(stderr, "%s : Invalid option '%s'!\n", cmnd, *argv); usage(EXIT_FAILURE); } } else fp = getfp(*argv, "rb"); if (n > leng) { fprintf(stderr, "\n %s (Error) output number of pricipal component" " must be less than length of vector.\n", cmnd); usage(EXIT_FAILURE); } /* -- Count number of input vectors and read -- */ buf = dgetmem(leng); top = prev = (float_list *) malloc(sizeof(float_list)); top->f = fgetmem(leng); total = 0; prev->next = NULL; while (freadf(buf, sizeof(*buf), leng, fp) == leng) { cur = (float_list *) malloc(sizeof(float_list)); cur->f = fgetmem(leng); for (i = 0; i < leng; i++) { cur->f[i] = (float) buf[i]; } total++; prev->next = cur; cur->next = NULL; prev = cur; } free(buf); buf = dgetmem(total * leng); for (i = 0, tmpf = top->next; tmpf != NULL; i++, tmpf = tmpff) { for (j = 0; j < leng; j++) { buf[i * leng + j] = tmpf->f[j]; } tmpff = tmpf->next; free(tmpf->f); free(tmpf); } free(top); /* PCA */ /* allocate memory for mean vectors and covariance matrix */ mean = dgetmem(leng); var = malloc_matrix(leng); /* calculate mean vector */ for (i = 0; i < leng; i++) { for (j = 0, sum = 0.0; j < total; j++) sum += buf[i + j * leng]; mean[i] = sum / total; } /* calculate cov. mat. */ for (i = 0; i < leng; i++) { for (j = 0; j < leng; j++) { sum = 0.0; for (k = 0; k < total; k++) sum += (buf[i + k * leng] - mean[i]) * (buf[j + k * leng] - mean[j]); var[i][j] = sum / total; } } /* allocate memory for eigenvector and eigenvalue */ e_vec = malloc_matrix(leng); e_val = dgetmem(leng); /* calculate eig.vec. and eig.val. with jacobi method */ if ((jacobi_conv = jacobi(var, leng, eps, e_val, e_vec, itemax)) == -1) { fprintf(stderr, "Error : matrix is not symmetric.\n"); exit(EXIT_FAILURE); } else if (jacobi_conv == -2) { fprintf(stderr, "Error : loop in jacobi method reached %d times.\n", itemax); exit(EXIT_FAILURE); } /* allocate memory for contribution rate of each eigenvalue */ cont_rate = dgetmem(leng); /* calculate contribution rate of each eigenvalue */ for (j = 0; j < leng; j++) { sum = 0.0; for (i = 0; i < leng; i++) sum += e_val[i]; cont_rate[j] = e_val[j] / sum; } /* end of PCA */ /* output mean vector and eigen vectors */ if (out_evecFlg == TRUE) { fwritef(mean, sizeof(*mean), leng, stdout); for (i = 0; i < n; i++) fwritef(e_vec[i], sizeof(*(e_vec[i])), leng, stdout); } /* output eigen values and contribution ratio */ if (out_evalFlg == TRUE) { for (i = 0; i < n; i++) { fwritef(e_val + i, sizeof(*e_val), 1, fp_eigen); fwritef(cont_rate + i, sizeof(*cont_rate), 1, fp_eigen); } fclose(fp_eigen); } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { FILE *fp; char *s, *infile = NULL, c; int size = SIZE, size2, k, nd = -1, out = ' '; double *x, *y; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) { if (*(s = *++argv) == '-') { c = *++s; switch (c) { case 'l': size = atoi(*++argv); argc--; break; case 'm': nd = atoi(*++argv) + 1; argc--; break; case 'i': case 'p': case 'r': c -= ('a' - 'A'); case 'A': case 'I': case 'P': case 'R': out = c; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, c); usage(1); } } else infile = s; } if (nd == -1) nd = size; if (nd > size) { fprintf(stderr, "%s : Order of sequence %d should be less than the FFT size %d!\n", cmnd, nd, size); return (1); } fp = stdin; if (infile) { fp = getfp(infile, "rb"); } x = dgetmem(size2 = size + size); y = x + size; while (!feof(fp)) { fillz(x, size2, sizeof(double)); if (freadf(x, sizeof(*x), nd, fp) == 0) break; if (freadf(y, sizeof(*y), nd, fp) == 0) break; fft(x, y, size); if (out == 'P') for (k = 0; k < size; k++) x[k] = x[k] * x[k] + y[k] * y[k]; else if (out == 'A') for (k = 0; k < size; k++) x[k] = sqrt(x[k] * x[k] + y[k] * y[k]); if (out != 'I') fwritef(x, sizeof(*x), size, stdout); if (out == ' ' || out == 'I') fwritef(y, sizeof(*y), size, stdout); } if (infile) { fclose(fp); } return (0); }
int main(int argc, char **argv) { int m = ORDER, pd = PADEORDER, fftlen = FFTLENGTH, stable_condition = STABLE1, frame = 0, c = 0; double *mcep, a = ALPHA, r = PADE4_THRESH1, R = 0.0; FILE *fp = stdin; if ((cmnd = strrchr(argv[0], '/')) == NULL) { cmnd = argv[0]; } else { cmnd++; } while (--argc) { if (**++argv == '-') { switch (*(*argv + 1)) { case 'm': m = atoi(*++argv); --argc; break; case 'a': a = atof(*++argv); --argc; break; case 'P': pd = atoi(*++argv); --argc; break; case 'l': fftlen = atoi(*++argv); --argc; break; case 'c': c = atoi(*++argv); if ((c != 0 && c != 1 && c != 2 && c != 3 && c != 4) || isdigit(**argv) == 0) { fprintf(stderr, "%s : '-c' option must be specified with 0, 1, 2, 3 or 4.\n", cmnd); usage(1); } --argc; break; case 'r': stable_condition = atoi(*++argv); if (stable_condition != STABLE1 && stable_condition != STABLE2) { fprintf(stderr, "%s : '-r' option must be specified with %d or %d.\n", cmnd, STABLE1, STABLE2); usage(1); } --argc; break; case 'R': R = atof(*++argv); if (isdigit(**argv) == 0) { fprintf(stderr, "%s : '-R' option must be specified by real number !\n", cmnd); usage(1); } --argc; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else { fp = getfp(*argv, "rb"); } } switch (pd) { case 4: if (stable_condition == STABLE1) r = PADE4_THRESH1; else r = PADE4_THRESH2; break; case 5: if (stable_condition == STABLE1) r = PADE5_THRESH1; else r = PADE5_THRESH2; break; default: fprintf(stderr, "%s : Order of Pade approximation should be 4 or 5!\n", cmnd); usage(1); } if (R != 0.0) r = R; mcep = dgetmem(m + 1); /* check stability of MLSA filter and output */ while (freadf(mcep, sizeof(*mcep), m + 1, fp) == m + 1) { mlsacheck(mcep, m, fftlen, frame, a, r, c); frame++; } return (0); }
void check_BDOS_hook(z80info *z80) { int i; char name[32]; char name2[32]; FILE *fp; char *s, *t; const char *mode; if (trace_bdos) { printf("\r\nbdos %d %s (AF=%04x BC=%04x DE=%04x HL =%04x SP=%04x STACK=", C, bdos_decode(C), AF, BC, DE, HL, SP); for (i = 0; i < 8; ++i) printf(" %4x", z80->mem[SP + 2*i] + 256 * z80->mem[SP + 2*i + 1]); printf(")\r\n"); } switch (C) { case 0: /* System Reset */ warmboot(z80); return; #if 0 for (i = 0; i < 0x1600; ++i) z80->mem[i+BIOS-0x1600] = cpmsys[i]; BC = 0; PC = BIOS-0x1600+3; SP = 0x80; #endif break; case 1: /* Console Input */ HL = kget(0); B = H; A = L; if (A < ' ') { switch(A) { case '\r': case '\n': case '\t': vt52(A); break; default: vt52('^'); vt52((A & 0xff)+'@'); if (A == 3) { /* ctrl-C pressed */ /* PC = BIOS+3; check_BIOS_hook(); */ warmboot(z80); return; } } } else { vt52(A); } break; case 2: /* Console Output */ vt52(0x7F & E); HL = 0; B = H; A = L; break; case 6: /* direct I/O */ switch (E) { case 0xff: if (!constat()) { HL = 0; B = H; A = L; F = 0; break; } case 0xfd: HL = kget(0); B = H; A = L; F = 0; break; case 0xfe: HL = constat() ? 0xff : 0; B = H; A = L; F = 0; break; default: vt52(0x7F & E); HL = 0; B = H; A = L; } break; case 9: /* Print String */ s = (char *)(z80->mem + DE); while (*s != '$') vt52(0x7F & *s++); HL = 0; B = H; A = L; break; case 10: /* Read Command Line */ s = rdcmdline(z80, *(unsigned char *)(t = (char *)(z80->mem + DE)), 1); if (PC == BIOS+3) { /* ctrl-C pressed */ /* check_BIOS_hook(); */ /* execute WBOOT */ warmboot(z80); return; } ++t; for (i = 0; i <= *(unsigned char *)s; ++i) t[i] = s[i]; HL = 0; B = H; A = L; break; case 12: /* Return Version Number */ HL = 0x22; /* Emulate CP/M 2.2 */ B = H; A = L; F = 0; break; case 26: /* Set DMA Address */ z80->dma = DE; HL = 0; B = H; A = L; break; case 32: /* Get/Set User Code */ if (E == 0xff) { /* Get Code */ HL = usercode; B = H; A = L; } else { usercode = E; HL = 0; /* Or does it get usercode? */ B = H; A = L; } break; /* dunno if these are correct */ case 11: /* Console Status */ HL = (constat() ? 0xff : 0x00); B = H; A = L; F = 0; break; case 13: /* reset disk system */ /* storedfps = 0; */ /* WS crashes then */ if (dp) closedir(dp); dp = NULL; z80->dma = 0x80; HL = 0; B = H; A = L; /* select only A:, all r/w */ break; case 14: /* select disk */ HL = 0; B = H; A = L; break; case 15: /* open file */ mode = "r+b"; fileio: FCB_to_filename(z80->mem+DE, name); /* Try lowercase */ if (!(fp = fopen(name, mode))) { FCB_to_ufilename(z80->mem+DE, name); /* Try all uppercase instead */ if (!(fp = fopen(name, mode))) { FCB_to_filename(z80->mem+DE, name); if (*mode == 'r') { char ss[50]; sprintf(ss, "%s/%s", CPMLIBDIR, name); fp = fopen(ss, mode); if (!fp) fp = fopen(ss, "rb"); } if (!fp) { /* still no success */ HL = 0xFF; B = H; A = L; F = 0; break; } } } /* success */ /* memset(z80->mem + DE + 12, 0, 33-12); */ /* User has to set EX, S2, and CR: don't change these- some set them to non-zero */ z80->mem[DE + FCB_S1] = 0; /* memset(z80->mem + DE + 16, 0, 16); */ /* Clear D0-Dn */ /* Should we clear R0 - R2? Nope: then we overlap the following area. */ /* memset(z80->mem + DE + 33, 0, 3); */ /* We need to set high bit of S2: means file is open? */ z80->mem[DE + FCB_S2] |= 0x80; z80->mem[DE + FCB_RC] = 0; /* rc field of FCB */ if (fixrc(z80, fp)) { /* Not a real file? */ HL = 0xFF; B = H; A = L; F = 0; fclose(fp); break; } HL = 0; B = H; A = L; F = 0; /* where to store fp? */ storefp(z80, fp, DE); /* printf("opening file %s\n", name); */ break; case 16: /* close file */ z80->mem[DE + FCB_S2] &= 0x7F; /* Clear high bit: indicates closed */ fp = getfp(z80, DE); delfp(z80, DE); fclose(fp); HL = 0; B = H; A = L; /* printf("close file\n"); */ break; case 17: /* search for first */ if (dp) closedir(dp); if (!(dp = opendir("."))) { fprintf(stderr, "opendir fails\n"); resetterm(); exit(1); } sfn = DE; /* fall through */ case 18: /* search for next */ if (!dp) goto retbad; { struct dirent *de; unsigned char *p; const char *sr; nocpmname: if (!(de = readdir(dp))) { closedir(dp); dp = NULL; retbad: HL = 0xff; B = H; A = L; F = 0; break; } /* printf("\r\nlooking at %s\r\n", de->d_name); */ /* compare data */ memset(p = z80->mem+z80->dma, 0, 128); /* dmaaddr instead of DIRBUF!! */ if (*de->d_name == '.') goto nocpmname; if (strchr(sr = de->d_name, '.')) { if (strlen(de->d_name) > 12) /* POSIX: namlen */ goto nocpmname; } else if (strlen(de->d_name) > 8) goto nocpmname; /* seems OK */ for (i = 0; i < 8; ++i) if (*sr != '.' && *sr) { *++p = toupper(*(unsigned char *)sr); sr++; } else *++p = ' '; /* skip dot */ while (*sr && *sr != '.') ++sr; while (*sr == '.') ++sr; for (i = 0; i < 3; ++i) if (*sr != '.' && *sr) { *++p = toupper(*(unsigned char *)sr); sr++; } else *++p = ' '; /* OK, fcb block is filled */ /* match name */ p -= 11; sr = (char *)(z80->mem + sfn); for (i = 1; i <= 12; ++i) if (sr[i] != '?' && sr[i] != p[i]) goto nocpmname; /* yup, it matches */ HL = 0x00; /* always at pos 0 */ B = H; A = L; F = 0; p[32] = p[64] = p[96] = 0xe5; } break; case 19: /* delete file (no wildcards yet) */ FCB_to_filename(z80->mem + DE, name); unlink(name); HL = 0; B = H; A = L; break; case 20: /* read sequential */ fp = getfp(z80, DE); readseq: if (!fseek(fp, SEQ_ADDRESS, SEEK_SET) && ((i = fread(z80->mem+z80->dma, 1, 128, fp)) > 0)) { long ofst = ftell(fp) + 127; if (i != 128) memset(z80->mem+z80->dma+i, 0x1a, 128-i); z80->mem[DE + FCB_CR] = SEQ_CR(ofst); z80->mem[DE + FCB_EX] = SEQ_EX(ofst); z80->mem[DE + FCB_S2] = (0x80 | SEQ_S2(ofst)); fixrc(z80, fp); HL = 0x00; B = H; A = L; } else { HL = 0x1; /* ff => pip error */ B = H; A = L; } break; case 21: /* write sequential */ fp = getfp(z80, DE); writeseq: if (!fseek(fp, SEQ_ADDRESS, SEEK_SET) && fwrite(z80->mem+z80->dma, 1, 128, fp) == 128) { long ofst = ftell(fp); z80->mem[DE + FCB_CR] = SEQ_CR(ofst); z80->mem[DE + FCB_EX] = SEQ_EX(ofst); z80->mem[DE + FCB_S2] = (0x80 | SEQ_S2(ofst)); fixrc(z80, fp); HL = 0x00; B = H; A = L; } else { HL = 0xff; B = H; A = L; } break; case 22: /* make file */ mode = "w+b"; goto fileio; case 23: /* rename file */ FCB_to_filename(z80->mem + DE, name); FCB_to_filename(z80->mem + DE + 16, name2); /* printf("rename %s %s called\n", name, name2); */ rename(name, name2); HL = 0; B = H; A = L; break; case 24: /* return login vector */ HL = 1; /* only A: online */ B = H; A = L; F = 0; break; case 25: /* return current disk */ HL = 0; /* only A: */ B = H; A = L; F = 0; break; case 29: /* return r/o vector */ HL = 0; /* none r/o */ B = H; A = L; F = 0; break; case 31: /* get disk parameters */ HL = DPB0; /* only A: */ B = H; A = L; break; case 33: /* read random record */ { long ofst; fp = getfp(z80, DE); /* printf("data is %02x %02x %02x\n", z80->mem[z80->regde+33], z80->mem[z80->regde+34], z80->mem[z80->regde+35]); */ ofst = ADDRESS; z80->mem[DE + FCB_CR] = SEQ_CR(ofst); z80->mem[DE + FCB_EX] = SEQ_EX(ofst); z80->mem[DE + FCB_S2] = (0x80 | SEQ_S2(ofst)); goto readseq; } case 34: /* write random record */ { long ofst; fp = getfp(z80, DE); /* printf("data is %02x %02x %02x\n", z80->mem[z80->regde+33], z80->mem[z80->regde+34], z80->mem[z80->regde+35]); */ ofst = ADDRESS; z80->mem[DE + FCB_CR] = SEQ_CR(ofst); z80->mem[DE + FCB_EX] = SEQ_EX(ofst); z80->mem[DE + FCB_S2] = (0x80 | SEQ_S2(ofst)); goto writeseq; } case 35: /* compute file size */ fp = getfp(z80, DE); fseek(fp, 0L, SEEK_END); /* fall through */ case 36: /* set random record */ fp = getfp(z80, DE); { long ofst = ftell(fp) + 127; long pos = (ofst >> 7); HL = 0x00; /* dunno, if necessary */ B = H; A = L; z80->mem[DE + FCB_R0] = pos & 0xff; z80->mem[DE + FCB_R1] = pos >> 8; z80->mem[DE + FCB_R2] = pos >> 16; z80->mem[DE + FCB_CR] = SEQ_CR(ofst); z80->mem[DE + FCB_EX] = SEQ_EX(ofst); z80->mem[DE + FCB_S2] = (0x80 | SEQ_S2(ofst)); fixrc(z80, fp); } break; case 41: for (s = (char *)(z80->mem + DE); *s; ++s) *s = tolower(*(unsigned char *)s); HL = (restricted_mode || chdir((char *)(z80->mem + DE))) ? 0xff : 0x00; B = H; A = L; break; default: printf("\n\nUnrecognized BDOS-Function:\n"); printf("AF=%04x BC=%04x DE=%04x HL=%04x SP=%04x\nStack =", AF, BC, DE, HL, SP); for (i = 0; i < 8; ++i) printf(" %4x", z80->mem[SP + 2*i] + 256 * z80->mem[SP + 2*i + 1]); printf("\r\n"); resetterm(); exit(1); } z80->mem[PC = DIRBUF-1] = 0xc9; /* Return instruction */ return; }
void main(int argc, char **argv) { int l = LENG, cbsize = CBSIZE, index; Boolean qflag = QFLAG; FILE *fp = stdin, *fpcb = NULL; double *x, *qx, *cb; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-'){ switch (*(*argv+1)) { case 'l': l = atoi(*++argv); --argc; break; case 'n': l = atoi(*++argv)+1; --argc; break; case 's': cbsize = atoi(*++argv); --argc; break; case 'q': qflag = 1 - qflag; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c' !\n", cmnd, *(*argv+1)); usage(1); } } else if (fpcb == NULL) fpcb = getfp(*argv, "r"); else fp = getfp(*argv, "r"); fseek(fpcb,0,2); #ifdef DOUBLE cbsize = ftell(fpcb)/sizeof(double)/l; #else cbsize = ftell(fpcb)/sizeof(float)/l; #endif rewind(fpcb); x = dgetmem(l+l+cbsize*l); qx = x + l; cb = qx + l; if(freadf(cb, sizeof(*cb), cbsize*l, fpcb) != cbsize*l){ fprintf(stderr,"%s : Codebook size error !\n",cmnd); exit(1); } if(! qflag) while (freadf(x, sizeof(*x), l, fp) == l){ index = vq(x, cb, l, cbsize); fwrite(&index, sizeof(index), 1, stdout); } else while (freadf(x, sizeof(*x), l, fp) == l){ index = vq(x, cb, l, cbsize); ivq(index, cb, l, qx); fwritef(qx, sizeof(*qx), l, stdout); } exit(0); }