Exemple #1
0
Fichier : nan.c Projet : EQ4/SPTK
void nan_tmp(FILE * fp)
{
   long count = 0;
#ifdef DOUBLE
   double x;
#else
   float x;
#endif                          /* DOUBLE */

   while (freadx(&x, sizeof(x), 1, fp)) {
#ifdef WIN32
      if (!_finite(x))
         fprintf(stdout, "[No. %ld] is Infinity\n", count);
      if (_isnan(x))
         fprintf(stdout, "[No. %ld] is NaN\n", count);
#else
      if (isinf(x))
         fprintf(stdout, "[No. %ld] is Infinity\n", count);
      if (isnan(x))
         fprintf(stdout, "[No. %ld] is NaN\n", count);
#endif
      ++count;
   }

   return;
}
Exemple #2
0
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);
}
Exemple #3
0
/* get the hit list */
HLIST get_hlist(int index)
{
    int n, *buf, i;
    HLIST hlist;
    double idf = 0;
    uchar tmp[BUFSIZE];
    hlist.n = 0;

    if (-1 == fseek(Index, get_index_pointer(IndexIndex, index), 0))
	return hlist; /* error */

    fgets(tmp, BUFSIZE, Index); /* read and dispose */

    freadx(&n, sizeof(int), 1, Index);

    if (TfIdf) {
        idf = log((double)AllDocumentN / (n/2)) / log(2);
        if (Debug)
            fprintf(stderr, "idf: %f (N:%d, n:%d)\n", idf, AllDocumentN, n/2);
    }

    if (n >= IGNORE_HIT * 2) {  
        /* '* 2' means NMZ.i contains a file-ID and a score. */
        hlist.n = TOO_MUCH_HIT;
    } else {
        buf = (int *) malloc(n * sizeof(int));
	if (buf == NULL) {
	     error("hlist");
        }
	malloc_hlist(&hlist, n / 2);
	freadx(buf, sizeof(int), n, Index);
	for (i = 0; i < n; i += 2) {
	    hlist.fid[i / 2] = *(buf + i);
	    hlist.scr[i / 2] = *(buf + i + 1);
            if (TfIdf) {
                hlist.scr[i / 2] = (int)(hlist.scr[i / 2] * idf) + 1;
            }
	}
	free(buf);
        hlist.n = n / 2;
        hlist = do_date_processing(hlist);
    } 
    return hlist;
}
Exemple #4
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;
}
Exemple #5
0
void conv(FILE * fp, size_t iosize)
{
   long adrs, n;
   int i;
   char ibuf[BUFSIZE], obuf[BUFSIZE];
   int ffseek(FILE * fp, long off);

   if (ffseek(fp, adrs = start + iosize * sno))
      return;

   for (n = sno; (adrs <= _end) && (n <= eno); adrs += iosize, ++n) {
      freadx(ibuf, iosize, 1, fp);
      if (feof(fp))
         break;
      for (i = 0; i < (int) iosize; ++i)
         obuf[i] = ibuf[iosize - 1 - i];
      fwritex(obuf, iosize, 1, stdout);
   }

   return;
}
Exemple #6
0
/* get date info from NMZ.t and do the missing number processing */
HLIST do_date_processing(HLIST hlist)
{
    FILE *date_index;
    int i;

    date_index = fopen(DATEINDEX, "rb");
    if (date_index == NULL) {
        if (Debug) {
            fprintf(stderr, "%s: cannot open file.\n", DATEINDEX);
        }
        set_date_zero_all(hlist);
        return hlist; /* error */
    }

    for (i = 0; i < hlist.n ; i++) {
        if (-1 == fseek(date_index, hlist.fid[i] * sizeof(hlist.date[i]), 0)) {
            set_date_zero_all(hlist);
            return hlist; /* error */
        }
        freadx(&hlist.date[i], sizeof(hlist.date[i]), 1, date_index);

        if (hlist.date[i] == -1) {  
            /* the missing number, this document has been deleted */
            int j;

            for (j = i + 1; j < hlist.n; j++) { /* shift */
                copy_hlist(hlist, j - 1, hlist, j);
            }
            hlist.n--;
            i--;
        }
    }

    fclose(date_index);
    return hlist;
}
Exemple #7
0
int main(int argc, char **argv)
{
   int l = LENG, *cbsize, *index, stage = 0, ss = 0, num, i;
   FILE *fp = stdin, *fpcb;
   double *x, *cb = NULL, *p;
   char **cbfile;

   cbsize = (int *) calloc(argc / 2, sizeof(*cbsize));
   index = (int *) calloc(argc / 2, sizeof(*index));
   cbfile = (char **) calloc(argc / 2, sizeof(**cbfile));

   p = 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[stage] = atoi(*++argv);
            cbfile[stage++] = *++argv;
            argc -= 2;
            break;
         case 'h':
            usage(0);
         default:
            fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1));
            usage(1);
         }
      } else
         fp = getfp(*argv, "rb");

   for (i = 0, num = 0; i < stage; i++)
      num += cbsize[i];
   cb = dgetmem(num * l);
   p = cb;

   for (i = 0; i < stage; i++) {
      fpcb = getfp(cbfile[i], "rb");
      if (freadf(p, sizeof(*p), cbsize[i] * l, fpcb) != cbsize[i] * l) {
         fprintf(stderr, "%s : Codebook size error of %d stage!\n", cmnd, ss);
         return (1);
      }
      p += cbsize[i] * l;
   }

   x = dgetmem(l);

   while (freadx(index, sizeof(*index), stage, fp) == stage) {
      imsvq(index, cb, l, cbsize, stage, x);
      fwritef(x, sizeof(*x), l, stdout);
   }

   return (0);
}
Exemple #8
0
int main(int argc, char **argv)
{
   FILE *fp2 = NULL, *fp1 = stdin;
   int start = START, leng1 = LENG1, leng2 = LENG2, i, j, flag = 1;
   size_t size = sizeof(float);
   Boolean write = WRITE;
   char *y, c, *s;
   long double x;

   if ((cmnd = strrchr(argv[0], '/')) == NULL)
      cmnd = argv[0];
   else
      cmnd++;
   while (--argc)
      if (*(s = *++argv) == '-') {
         c = *++s;
         switch (c) {
         case 's':
            start = atoi(*++argv);
            --argc;
            break;
         case 'l':
            leng1 = atoi(*++argv);
            --argc;
            break;
         case 'n':
            leng1 = atoi(*++argv) + 1;
            --argc;
            break;
         case 'L':
            leng2 = atoi(*++argv);
            --argc;
            break;
         case 'N':
            leng2 = atoi(*++argv) + 1;
            --argc;
            break;
         case 'o':
            write = 1 - write;
            break;
         case 'h':
            usage(0);
         default:
            fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1));
            usage(1);
         }
      } else if (*s == '+') {
         c = *++s;
         switch (c) {
         case 'c':
            size = sizeof(char);
            break;
         case 's':
            size = sizeof(short);
            break;
         case 'i':
            if (*(s + 1) == '3') {
               size = 3;
               (*argv)++;
            } else {
               size = sizeof(int);
            }
            break;
         case 'l':
            if (*(s + 1) == 'e') {
               size = sizeof(long long);
               (*argv)++;
            } else {
               size = sizeof(long);
            }
            break;
         case 'C':
            size = sizeof(unsigned char);
            break;
         case 'S':
            size = sizeof(unsigned short);
            break;
         case 'I':
            if (*(s + 1) == '3') {
               size = 3;
               (*argv)++;
            } else {
               size = sizeof(unsigned int);
            }
            break;
         case 'L':
            if (*(s + 1) == 'E') {
               size = sizeof(unsigned long long);
               (*argv)++;
            } else {
               size = sizeof(unsigned long);
            }
            break;
         case 'f':
            size = sizeof(float);
            break;
         case 'd':
            if (*(s + 1) == 'e') {
               size = sizeof(long double);
               (*argv)++;
            } else {
               size = sizeof(double);
            }
            break;
         default:
            fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1));
            usage(1);
         }
      } else if (fp2 == NULL)
         fp2 = getfp(*argv, "rb");
      else
         fp1 = getfp(*argv, "rb");

   if (fp2 == NULL) {
      fprintf(stderr, "%s : Inserted data must be specified !\n", cmnd);
      usage(1);
   }

   y = (char *) dgetmem(leng2 * size);

   for (;;) {
      for (j = start, i = leng1; j-- && i--;) {
         if (freadx(&x, size, 1, fp1) != 1)
            break;
         fwritex(&x, size, 1, stdout);
      }
      for (j = leng2; j--;)
         if (write) {
            if (freadx(&x, size, 1, fp1) != 1)
               break;
            i--;
         }
      if (freadx(y, size, leng2, fp2) != leng2)
         if (!flag)
            break;

      fwritex(y, size, leng2, stdout);
      flag = 0;
      for (; i-- > 0;) {
         if (freadx(&x, size, 1, fp1) != 1)
            break;
         fwritex(&x, size, 1, stdout);
      }
   }

   if ((fgetc(fp1) == EOF) && (fgetc(fp2) == EOF)) {
      if (feof(fp1) && feof(fp2))
         return (0);
   }
   return (1);
}
Exemple #9
0
/* freadf : read double type data */
int freadf(double *ptr, const size_t size, const int nitems, FILE * fp)
{
   return (freadx(ptr, size, nitems, fp));
}