Ejemplo n.º 1
0
int print_header(FILE *fp, char *hname)
{
  int c;
  struct file_info *fi;
  FILE *header_file;

  if (hname)
    {
      if ((fi = open_file(hname, "r")) == NULL)
	{
	  fprintf(stderr, "umat: can't read PS header file %s\n", hname);
	  return 1;
	}
      header_file = fi2fp(fi);
      while ((c = fgetc(header_file)) != EOF)
	fputc(c, fp);
      close_file(fi);
    }
  else
    print_lines(fp, psheader);

  return 0;
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
  FILE *cf1, *cf2;
  struct file_info *cfi1 = NULL, *cfi2 = NULL;
  int i1,i2,c1,c2,cnt,i;
  double testv, tmp;
  int error = 1;

  if (argc != 3) {
    fprintf(stderr, usage);
    exit(1);
  }
  if ((cfi1 = open_file(argv[1],"r")) == NULL) {
    fprintf(stderr, "\nCannot open %s\n",argv[1]);
    goto cleanup;
  }
  cf1 = fi2fp(cfi1);

  if ( (cfi2 = open_file(argv[2],"r")) == NULL) {
    fprintf(stderr, "\nCannot open %s\n",argv[2]);
    goto cleanup;
  }
  cf2 = fi2fp(cfi2);
  
  for (;;) {
    i1 = fscanf(cf1,"%d", &c1);
    i2 = fscanf(cf2,"%d", &c2);

    if (i1 != i2) {
      fprintf(stderr, "\nERROR: Unequal numbers of classifications in files.\n");
      goto cleanup;
    }
    if (i1 != 1) break;

    if ( (c1!=0 && c1!=1) || (c2!=0 && c2!=1)) {
      fprintf(stderr, "\nFiles contain other than 0's and 1's.\n");
      goto cleanup;
    }

    c1 = 1 - c1;
    c2 = 1 - c2;
    tbl[c1][c2]++;
  }
  
  cnt = tbl[0][1] + tbl[1][0];
  if (cnt) {
    fprintf(stderr, "\nStatistics of the results of the two classifiers:");
    fprintf(stderr, "\n             1st correct,  1st errors");
    fprintf(stderr, "\n2nd correct:      %6d       %6d",   tbl[0][0],tbl[1][0]);
    fprintf(stderr, "\n2nd errors:       %6d       %6d\n", tbl[0][1],tbl[1][1]);
    tmp = tbl[0][1] - tbl[1][0];
    testv = tmp*tmp;
    testv /= cnt;
    fprintf(stderr, "\nTest statistics (%.3f)", testv);
    
    for (i=3; i>=0; i--) if (testv > chi_sq[i]) break;
    
    if (i>=0) {
      fprintf(stderr, " is significant at risk level %.3f\n", alpha[i]);
      fprintf(stderr, "The classifiers are significantly different!\n");
    } else {
      fprintf(stderr, " is not significant!\n");
      fprintf(stderr, "The classifiers are not significantly different!\n");
    }
    
  }
  else
    fprintf(stderr, "\nRecognition result files are equal!\n");

  error = 0;
 cleanup:

  if (cfi1)
    close_file(cfi1);
  if (cfi2)
    close_file(cfi2);

  return(error);
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
  char *in_name, *out_name, *s;
  struct umatrix *umat;
  struct eps_info einfo;
  int average = 0;
  int median = 0;
  FILE *out_fp;
  struct file_info *out_fi;

  global_options(argc, argv);
  if (extract_parameter(argc, argv, "-help", OPTION2))
    {
      printhelp();
      exit(0);
    }
  
  in_name = NULL;
  out_name = NULL;

  /* default page size is A4 */
  set_paper(get_paper_by_id(PAPER_A4));

  /* parse args */
  
  if (extract_parameter(argc, argv, "-border", OPTION2))
    doborder = 1;

  if (extract_parameter(argc, argv, "-portrait", OPTION2))
    orientation = PORTRAIT;

  if (extract_parameter(argc, argv, "-landscape", OPTION2))
    orientation = LANDSCAPE;

  if (extract_parameter(argc, argv, "-ps", OPTION2))
    mode = OUTPUT_PS;

  if (extract_parameter(argc, argv, "-eps", OPTION2))
    mode = OUTPUT_EPS;

  white_treshold = oatof(extract_parameter(argc, argv, "-W", OPTION), 1.0);

  black_treshold = oatof(extract_parameter(argc, argv, "-B", OPTION), 0.0);

  out_name = extract_parameter(argc, argv, "-o", OPTION);
  if (mode == 0)
    mode = guess_mode(out_name);

  if ((s = extract_parameter(argc, argv, "-font", OPTION)))
    fontname = s;

  fontsize = oatof(extract_parameter(argc, argv, "-fontsize", OPTION), -1.0);
  
  title = extract_parameter(argc, argv, "-title", OPTION);
  
  if (extract_parameter(argc, argv, "-notitle", OPTION2))
    notitle = 1;

  if ((s = extract_parameter(argc, argv, "-paper", OPTION)))
    {
      struct paper_info *p = get_paper_by_name(s);
      if (p == NULL)
	{
	  fprintf(stderr, "Unknown paper type: %s\n", s);
	  exit(1);
	}
      set_paper(p);
    }

  if (extract_parameter(argc, argv, "-average", OPTION2))
    average = 1;

  if (extract_parameter(argc, argv, "-median", OPTION2))
    median = 1;

  if (extract_parameter(argc, argv, "-onlylabs", OPTION2))
    drawblocks = 0;

  if (extract_parameter(argc, argv, "-nolabs", OPTION2))
    drawlabels = 0;

  in_name = extract_parameter(argc, argv, IN_CODE_FILE, ALWAYS);

  if ((s = getenv("UMAT_HEADERFILE")))
    headerfile = s;

  if ((s = extract_parameter(argc, argv, "-headerfile", OPTION)))
    headerfile = s;

  label_not_needed(1);

  if ((umat = read_map(in_name, 0, 0)) == NULL)
    {
      fprintf(stderr, "Can't load file\n");
      exit(1);
    }

  calc_umatrix(umat, 0, 0);

  if (average)
    average_umatrix(umat);

  if (median)
    median_umatrix(umat);

  if (mode == 0)
    mode = OUTPUT_EPS;
    
  if (orientation == BEST)
    orientation =  (umat->mxdim >= umat->mydim) ? LANDSCAPE : PORTRAIT;

  if ((out_fi = open_file(out_name, "w")) == NULL)
    {
      fprintf(stderr, "can't open output file\n");
      free_umat(umat);
      exit(1);
    }
  out_fp = fi2fp(out_fi);

  einfo.umat = umat;
  einfo.title = title ? title : in_name;
      
  image_size(&einfo, 0);
      
  if (mode == OUTPUT_EPS)
    print_eps(out_fp, &einfo);
  else
    print_page(out_fp, &einfo);

  free_umat(umat);
  umat = NULL;

  if (out_fi)
    close_file(out_fi);

  return 0;
}
Ejemplo n.º 4
0
int save_snapshot(struct teach_params *teach, long iter)
{
  struct entries *codes = teach->codes;
  struct snapshot_info *shot = teach->snapshot;
  struct data_entry *entry;
  eptr p;
  char filename[1024]; /* hope this is enough */
  struct file_info *fi = NULL;
  int retcode = 0;
  int bg = shot->flags & SNAPFLAG_BACKGROUND;
  int ko = shot->flags & SNAPFLAG_KEEPOPEN;

  shot->counter++;
  if (ko)
    if ((fi = shot->fi) == NULL)
      {
	if ((shot->fi = open_file(shot->filename, "w")) == NULL)
	  return 1;
	
	fi = shot->fi;
      }
    else
      fi = shot->fi;

#ifndef NO_BACKGROUND_SNAP
  if (bg)
    {
      if (shot->pid > 0)
	{
	  int statptr;
	  if (!(shot->flags & SNAPFLAG_NOWAIT))
	    {
	      /* fprintf(stderr, "Snap: waiting for pid %d\n", (int)shot->pid); */
	      /* wait for previous child before forking a new one */
	      waitpid(shot->pid, &statptr, 0);
	      shot->pid = -1;
	    }
	}

      if ((shot->pid = fork()) < 0)
	{
	  perror("save_snapshot(background):");
	  return 1;
	}
      if (shot->pid == 0)
	{
	  /* fprintf(stderr, "saving snapshot\n"); */
	}
      else
	{
	  /* fprintf(stderr, "forked pid %d\n", (int)shot->pid); */
	  return 0;
	}
    }
#endif /* NO_BACKGROUND_SNAP */

  if (fi == NULL)
    {
      /* make filename */
      sprintf(filename, shot->filename, iter);
      if ((fi = open_file(filename, "w")) == NULL)
	return 1;
    }

  if (ko)
    fprintf(fi2fp(fi), "#start %d\n", shot->counter);

  if (write_header(fi, codes))
    {
      fprintf(stderr, "save_snapshot: Error writing headers\n");
      close_file(shot->fi);
      shot->fi = NULL;
      return 1;
    }

  /* open file for writing */

  ifverbose(3)
    fprintf(stderr, "saving snapshot: file '%s', type '%s'\n", filename, 
	    get_str_by_id(snapshot_list, shot->type));

  fprintf(fi2fp(fi), "#SNAPSHOT FILE\n#iterations: %ld/%ld\n",
	  iter, teach->length);

  for (entry = rewind_entries(codes, &p); entry != NULL; entry = next_entry(&p))
    {
      if (write_entry(fi, codes, entry))
	{
	  fprintf(stderr, "save_entries: Error writing entry, aborting\n");
	  retcode = 1;
	  break;
	}
    }

  if (ko)
    {
      fprintf(fi2fp(fi), "#end\n");
      fflush(fi2fp(fi));
    }
  else
    close_file(fi);
  
#ifndef NO_BACKGROUND_SNAP
  if (bg)
    exit(retcode);
  else
#endif
    return(retcode);
}