www.pudn.com > eval-1.2.zip > mos.c



#ifdef _WIN32
#include 
#endif

#ifdef LINUX
#include 
#endif

#include 
#include 
#include 
#include "dir.h"

#define FQ "qual.txt"

static int cmpstr(const void *p1, const void *p2)
{
  return strcmp(*(char **)p1, *(char **)p2);
}

int main(int cn, char *cl[])
{
  FILE *fi, *fo;
  char buf[1024], dir[512];
  char **F=0, **Q=0, *R=0, **ppT, *pT;
  int i, j, k, l, iv, tmp, nF=0, nQ=0, nL=0, nR=0;
  int *L=0, mos[5], *pL;
  double d;

  if (cn < 3) {
    puts("mos   [iv]");
    puts("  dir\t\tdirectory with psnr*.txt files");
    puts("  ref\t\treference psnr file");
    puts("  iv\t\toptional nr. of frames in interval");
    return 0;
  }

  if (!(fi = fopen(cl[2], "r"))) {
    fprintf(stderr, "Coudn't open %s.\n", cl[2]);
    return EXIT_FAILURE;
  }

#ifdef _WIN32
  if (!SetCurrentDirectory(cl[1])) {
    fputs("Couldn't find directory.\n", stderr);
    return EXIT_FAILURE;
  }
  GetCurrentDirectory(sizeof dir, dir);
#endif

#ifdef LINUX
  if (chdir(cl[1]) == -1) {
    fputs("Couldn't find directory.\n", stderr);
    return EXIT_FAILURE;
  }
  getcwd(dir, sizeof dir);
#endif

  while (!feof(fi)) {
    if (!fgets(buf, sizeof buf, fi)) break;
    if ((d = strtod(buf, 0)) == 0) continue;
    if ((pT = realloc(R, ++nR * sizeof *R)) == 0) break;
    R = pT;
    R[nR-1] = d>37 ? 5 : d>31 ? 4 : d>25 ? 3 : d>20 ? 2 : 1;
  }

  fclose(fi);

  if (cn < 4) iv = 25;
  else {
    iv = strtol(cl[3], 0, 10);
    if (iv == 0) iv = 25;
  }

  if ((fo = fopen(FQ, "w")) == 0) {
    fputs("Couldn't open " FQ, stderr);
    return EXIT_FAILURE;
  }

  F = GetFiles(&nF, "psnr*.txt");
  qsort(F, nF, sizeof *F, cmpstr);

  for (j=0; j37 ? 5 : d>31 ? 4 : d>25 ? 3 : d>20 ? 2 : 1;
    }
    L[nQ-1] = nL;

    fclose(fi);
  }

  for (k=0; k