|
From: Herton R. K. <he...@us...> - 2005-04-05 06:55:07
|
Update of /cvsroot/kimageprocess/kimageprocess/testclass In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15787/testclass Modified Files: Makefile.am lex.yy.c pat.l testclass.c Log Message: - Fixing more bugs. Index: pat.l =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/testclass/pat.l,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- pat.l 31 Mar 2005 22:09:29 -0000 1.4 +++ pat.l 5 Apr 2005 06:54:56 -0000 1.5 @@ -1,9 +1,8 @@ -%option noyywrap %{ #include <stdio.h> #include <math.h> -#define DEBUG 0 +#define DEBUG 0 #define INTNUMBER 1 #define FLOATNUMBER 2 #define PATHEADER 3 @@ -11,7 +10,12 @@ #define NUMPAT 5 #define NUMIN 6 #define NUMOUT 7 +#define END 8 + int row=1, col=1; + +/* function prototypes */ +void yyerror(char *s); %} INTNUMBER [0-9]+ FLOATNUMBER [0-9]+"."[0-9]* @@ -25,28 +29,28 @@ %% \n ++row; col=1; {INTNUMBER} { - #ifdef DEBUG + #if DEBUG printf("INTNUMBER: %d\n", atoi(yytext)); #endif col += yyleng; return INTNUMBER; } {FLOATNUMBER} { - #ifdef DEBUG + #if DEBUG printf("FLOATNUMBER: %f\n", atof(yytext)); #endif col += yyleng; return FLOATNUMBER; } {PATHEADER} { - #ifdef DEBUG + #if DEBUG printf("PATHEADER\n"); #endif col += yyleng; return PATHEADER; } {PATDATE} { - #ifdef DEBUG + #if DEBUG printf("PATDATE\n"); #endif col = 1; @@ -54,39 +58,45 @@ return PATDATE; } {NUMPAT} { - #ifdef DEBUG + #if DEBUG printf("NUMPAT\n"); #endif col += yyleng; return NUMPAT; } {NUMIN} { - #ifdef DEBUG + #if DEBUG printf("NUMIN\n"); #endif col += yyleng; return NUMIN; } {NUMOUT} { - #ifdef DEBUG + #if DEBUG printf("NUMOUT\n"); #endif col += yyleng; return NUMOUT; } {WHITESPACE}+ { - #ifdef DEBUG + #if DEBUG printf("WHITESPACE\n"); #endif col += yyleng; } {COMMENT} { - #ifdef DEBUG + #if DEBUG printf("COMMENT\n"); #endif col = 1; row++; } +<<EOF>> { + #if DEBUG + printf("END\n"); + #endif + return END; +} . { ++col; } Index: lex.yy.c =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/testclass/lex.yy.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- lex.yy.c 31 Mar 2005 22:09:28 -0000 1.1 +++ lex.yy.c 5 Apr 2005 06:54:56 -0000 1.2 @@ -1,39 +1,84 @@ -/* A lexical scanner generated by flex */ -/* Scanner skeleton version: - * $Header$ - */ +#line 3 "lex.yy.c" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ [...2187 lines suppressed...] +#undef YY_NEW_FILE +#undef YY_FLUSH_BUFFER +#undef yy_set_bol +#undef yy_new_buffer +#undef yy_set_interactive +#undef yytext_ptr +#undef YY_DO_BEFORE_ACTION + +#ifdef YY_DECL_IS_OURS +#undef YY_DECL_IS_OURS +#undef YY_DECL #endif -#line 93 "pat.l" +#line 103 "pat.l" + void yyerror(char *s) { fprintf(stderr, " %s at line: %d, column: %d.\n", s, row, col); } + Index: Makefile.am =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/testclass/Makefile.am,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Makefile.am 1 Apr 2005 05:22:13 -0000 1.3 +++ Makefile.am 5 Apr 2005 06:54:55 -0000 1.4 @@ -12,10 +12,11 @@ # the libraries to link against. testclass_LDADD = $(top_builddir)/testclass/libfann/libfann.a \ - $(top_builddir)/testclass/libfann/libfloatfann.a + $(top_builddir)/testclass/libfann/libfloatfann.a \ + -lfl # which sources should be compiled for testclass testclass_SOURCES = testclass.c # these are the headers for your project -# noinst_HEADERS = +#noinst_HEADERS = Index: testclass.c =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/testclass/testclass.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- testclass.c 4 Apr 2005 23:54:02 -0000 1.11 +++ testclass.c 5 Apr 2005 06:54:56 -0000 1.12 @@ -10,6 +10,14 @@ #define PARSER_ERROR 1 #define CHECK_ERROR 2 +/* function prototypes */ +void usage(char *progname); +void fatal(int err); +void netLoadFail(int code, char *fileName); +void loadNetwork(float **inputValues, float **outputValues, int *numInputUnits, + int *numOutputUnits, int *numPatterns, FILE *patFile, + char *fileName); + void usage(char *progname) { fprintf(stderr, "testclass version %s\n", TESTCLASS_VERSION); @@ -34,7 +42,7 @@ switch(code) { case PARSER_ERROR: - fprintf(stderr, "Error: Invalid pattern file format.\n", fileName); + fprintf(stderr, "Error: Invalid pattern file format.\n"); yyerror(fileName); break; case CHECK_ERROR: @@ -51,7 +59,7 @@ char *fileName) { int tok, curPat = 0, i; - char *tokval; + float *tempp; yyin = patFile; tok = yylex(); if (tok != PATHEADER) @@ -64,8 +72,8 @@ *numPatterns = -1; inputValues = NULL; outputValues = NULL; - tok = yylex(); - while (tok != EOF) + tok = yylex(); + while (tok != END) { switch(tok) { @@ -93,37 +101,25 @@ netLoadFail(CHECK_ERROR, fileName); if (inputValues == NULL) { - inputValues = (float *) malloc(sizeof(float) * *numPatterns); + tempp = malloc(sizeof(float) * *numPatterns * *numInputUnits); + if (tempp == NULL) + fatal(errno); + inputValues = malloc(sizeof(float *) * *numPatterns); if (inputValues == NULL) fatal(errno); for (i = 0; i < *numPatterns; i++) - inputValues[i] = NULL; - if (*numInputUnits > 0) - { - for (i = 0; i < *numPatterns; i++) - { - inputValues[i] = (float *) malloc(sizeof(float) * *numInputUnits); - if (inputValues[i] == NULL) - fatal(errno); - } - } + inputValues[i] = tempp + (i * *numInputUnits); } if (outputValues == NULL) { - outputValues = (float *) malloc(sizeof(float) * *numPatterns); + tempp = malloc(sizeof(float) * *numPatterns * *numOutputUnits); + if (tempp == NULL) + fatal(errno); + outputValues = malloc(sizeof(float *) * *numPatterns); if (outputValues == NULL) fatal(errno); for (i = 0; i < *numPatterns; i++) - outputValues[i] = NULL; - if (*numOutputUnits > 0) - { - for (i = 0; i < *numPatterns; i++) - { - outputValues[i] = (float *) malloc(sizeof(float) * *numOutputUnits); - if (outputValues[i] == NULL) - fatal(errno); - } - } + outputValues[i] = tempp + (i * *numOutputUnits); } inputValues[curPat][0] = atof(yytext); for (i = 1; i < *numInputUnits; i++) @@ -145,13 +141,13 @@ default: netLoadFail(PARSER_ERROR, fileName); } - tok = yylex(); + tok = yylex(); } } int main(int argc, char **argv) { - int c; + int a, b, c; int option_index = 0; static struct option long_options[] = { @@ -206,14 +202,22 @@ pt_file = fopen(t_file, "r"); if (pt_file == NULL) fatal(errno); - loadNetwork(&in_tvalues, &out_tvalues, &in_tnum, &out_tnum, &pat_tnum, - pt_file, t_file); + loadNetwork(in_tvalues, out_tvalues, &in_tnum, &out_tnum, &pat_tnum, + pt_file, t_file); + for (a = 0; a < pat_tnum; a++) + { + for (b = 0; b < in_tnum; b++) + { + printf("%.5f", in_tvalues[a][b]); + } + for (b = 0; b < out_tnum; b++) + { + printf("%.5f", out_tvalues[a][b]); + } + } pc_file = fopen(c_file, "r"); if (pc_file == NULL) fatal(errno); - free(t_file); - free(c_file); - free(r_file); if (fclose(pt_file) != 0) fatal(errno); if (fclose(pc_file) != 0) |