int main(int argc, char *argv[]) { dispstr(0,"Welcome to the HMM program!\n"); #ifndef __STDC_IEC_559__ printf("WARNING: ISO/IEC 60559 not respected!\n"); #endif parse(argc, argv); dispstr(0,"Loading file...\n"); delays_mt input = getinput(); dispstr(0,"Sorting inputs...\n"); mysort(&input); //this offsets the timestamps to zero, and finds the min and max value of the delays. delay_mt ymin = input.delay[0]; delay_mt ymax = ymin; delay_mt current; time_mt tmin = input.time[0]; for(long long i = 0; i<input.length; i++) { input.time[i] = input.time[i] - tmin; current = input.delay[i]; if(current < ymin) ymin = current; if(current > ymax) ymax = current; } //now, we offset the delays to zero for(long long i = 0;i<input.length;i++) { //MINDELAY is an epsilon in order not to bug the algo input.delay[i] = input.delay[i] - ymin + MINDELAY; } struct params p; dispstr(0,"Initializing Markov parameters...\n"); initparams(&p, ymax); input.length = input.length/300; dispstr(0,"Training model...\n"); train(&p, &input, ymax); dispstr(0,"Writing results...\n"); write_results(&p); freeparams(&p); dispstr(0,"Done.\n"); return EXIT_SUCCESS; }
int load_parameters(const char * filename) { FILE *f = fopen(filename,"r"); if(f==NULL) return 0; char buf[1024]; char *ptr, *word; const char *err; int line = 1, mode = 0; char *oldlocal = setlocale (LC_NUMERIC, "C"); if(ps) freeparams(); p_parsed.name = 0; fgets(buf,1024, f); while(!feof(f)) { ptr = buf; word = nextword(ptr); if(word[0]!= '#') { switch (mode) { case 0: //Begin if(strcmp(word, "Begin") == 0) { word = nextword(ptr); if(strcmp(word, "Effect") == 0) { mode = 1; word = nextword(ptr); p_parsed.name = 0; if(strcmp(word, "inherits") == 0) { word = nextword(ptr); for(int i=0;i<nump;i++) { if(strcmp(ps[i].name, word)==0) { p_parsed = ps[i]; p_parsed.name = visual_strdup(p_parsed.name); break; } } } } else { err= "unknown Begin"; goto error; } } case 1: if(strcmp(word, "End") == 0) { word = nextword(ptr); if(strcmp(word, "Effect") == 0) { if(p_parsed.name==0) { err = "no name for this effect"; goto error; } mode = 0; if(nump++==0) ps = (parameters *) malloc(nump* sizeof(parameters)); else ps = (parameters *) realloc(ps,nump* sizeof(parameters)); ps[nump-1] = p_parsed; } } else { char *var, *egal, *val; int i; var = word; egal = nextword(ptr); val = nextword(ptr); for(i=0;i<numpp;i++) { if(strcmp(var, pp[i].pname)==0) { switch (pp[i].type) { case PARAM_INT: sscanf(val, "%d", (int *)pp[i].where); break; case PARAM_FLOAT: float val2 ; val2 = atof(val); *((float *)pp[i].where) = val2; break; case PARAM_CHAR: sscanf(val, "%c", (char *)pp[i].where); break; case PARAM_STR: if(*(char **)pp[i].where) free(*(char **)pp[i].where); *(char **)pp[i].where = visual_strdup(val); break; } break; } } if(i==numpp && *egal == '=') { err= "unknown parameter"; goto error; } } } } fgets(buf,1024, f);line++; } if(mode == 1) { err = " missing End Effect"; goto error; } setlocale (LC_NUMERIC, oldlocal); fclose(f); newconfig = 1; allocParts(); changep(); return 1; error: setlocale (LC_NUMERIC, oldlocal); fclose(f); return 0; }