#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "structs.h"
#include "read.h"
#include "ini.h"
#include "simu.h"

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

    struct nwdata nwd;
    struct initdata initd;
    struct results res;
    struct tmpdata tmpd;

    FILE *inputfile;
    char inputf[FILENAME_MAX]={0};

    res.c0 = clock();

    if (argc == 1) {
        printf("Enter input file:");
        scanf("%s", inputf);
        inputfile = fopen(inputf, "r");
    }
    else
        inputfile = fopen(argv[1], "r");

    if (inputfile == NULL) {
        printf("File not found\n");
        exit(EXIT_FAILURE);
    }

    srand48( time(NULL) );   /* not ANSI-C */

    read_values( &nwd, inputfile );
    init_nmax( &nwd, &initd );
    init_f( &nwd, &initd );
    res.hits_in_B      = emalloc( nwd.n_classes * sizeof(long) );

    nwd.int_batch = 1000;

    printf("\n%-17s", "Traffic class");
    printf("%20s", "Point estimate of Bk");
    printf("%23s\n", "95% conf int");   
    printf("=================================");
    printf("=================================\n");

    nwd.currentclass = nwd.targetclass-1;
    init_structs( nwd.currentclass, &nwd, &initd, &res );
    simulate(nwd.currentclass, &nwd, &initd, &res, &tmpd ); 

    res.c2 = clock();
    print_info( &nwd, &res );
    free_all( &nwd, &initd, &res );

    return 0;

}

