about summary refs log tree commit diff
path: root/sourcecodes/k-best/src/score_nets.c
blob: 44ab3a276fb48fc2ffd47f67d03d6ea9236155dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "cfg.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "files.h"
#include "varpar.h"

score_t score_net(char* netfile, char* dirprefix, int nof_vars, FILE** fins){
  score_t score = 0.0;

  int v;
  varset_t varset;
  FILE* netf = strcmp(netfile,"-") ? fopen(netfile, "r") : stdin;
  for(v=0; 1 == fscanf(netf, "%u", &varset); ++v){
    score_t vscore;
    fseek(fins[v], varset2parset(v, varset)*sizeof(score_t), SEEK_SET);
    fread(&vscore, sizeof(score_t), 1, fins[v]);
    rewind(fins[v]);
    score += vscore;
  }
  fclose(netf);
  return score;
}

void score_nets(char* netfiles, char* dirprefix){
  char netfile[1024];
  FILE* netfs = strcmp(netfiles,"-") ? fopen(netfiles, "r") : stdin;
  int nof_vars = 0;
  FILE** fins = NULL; 
  while(EOF != fscanf(netfs, "%s", netfile)){
    if (0 == nof_vars){
      nof_vars = nof_lines(netfile);
      fins = open_files(nof_vars, dirprefix,"","r");
    }
    printf("%.3f\n", score_net(netfile, dirprefix, nof_vars, fins));
  }
  free_files(nof_vars,fins);
  fclose(netfs);
}

int main(int argc, char* argv[])
{

  if (argc!=3) {
    fprintf(stderr, "Usage: score_nets netfiles dirname\n");
    return 1;
  }

  score_nets(argv[1], argv[2]);

  return 0;
}