|
From: Herton R. K. <he...@us...> - 2005-06-24 03:41:57
|
Update of /cvsroot/kimageprocess/kimageprocess/res2pgm In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4158 Modified Files: lex.yy.c res.l res2pgm.c Added Files: Makefile.am Log Message: - Finished res2pgm, fixed bugs. Index: lex.yy.c =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/res2pgm/lex.yy.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- lex.yy.c 23 Jun 2005 23:27:16 -0000 1.1 +++ lex.yy.c 24 Jun 2005 03:41:47 -0000 1.2 @@ -1,85 +1,32 @@ - -#line 3 "lex.yy.c" - -#define YY_INT_ALIGNED short int - /* A lexical scanner generated by flex */ +/* Scanner skeleton version: + * $Header$ + */ + [...2190 lines suppressed...] + { + free( ptr ); + } +#if YY_MAIN +int main() + { + yylex(); + return 0; + } +#endif +#line 121 "res.l" void yyerror(char *s) { fprintf(stderr, " %s at line: %d, column: %d.\n", s, row, col); @@ -1902,4 +1737,3 @@ /* * vim:noet */ - Index: res.l =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/res2pgm/res.l,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- res.l 23 Jun 2005 23:27:16 -0000 1.1 +++ res.l 24 Jun 2005 03:41:47 -0000 1.2 @@ -2,15 +2,17 @@ #include <stdio.h> #include <math.h> -#define DEBUG 0 -#define INTNUMBER 1 -#define FLOATNUMBER 2 -#define RESHEADER 3 -#define RESDATE 4 -#define NUMPAT 5 -#define NUMIN 6 -#define NUMOUT 7 -#define END 8 +#define DEBUG 0 +#define INTNUMBER 1 +#define FLOATNUMBER 2 +#define RESHEADER 3 +#define RESDATE 4 +#define NUMPAT 5 +#define NUMIN 6 +#define NUMOUT 7 +#define STARTPATTERN 8 +#define ENDPATTERN 9 +#define END 10 int row=1, col=1; --- NEW FILE: Makefile.am --- ## Makefile.am for testclass SUBDIRS = . # this is the program that gets installed. it's name is used for all # of the other Makefile.am variables bin_PROGRAMS = res2pgm # set the include path for X, qt and KDE INCLUDES = $(all_includes) \ -I$(srcdir)/../res2pgm # the library search path. res2pgm_LDFLAGS = $(all_libraries) # the libraries to link against. res2pgm_LDADD = -lfl -lm # which sources should be compiled for testclass res2pgm_SOURCES = res2pgm.c Index: res2pgm.c =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/res2pgm/res2pgm.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- res2pgm.c 23 Jun 2005 23:27:16 -0000 1.1 +++ res2pgm.c 24 Jun 2005 03:41:47 -0000 1.2 @@ -14,7 +14,7 @@ float **resultValues; int numInputUnits; int numOutputUnits; - int numPatterns; + int numResults; int startPattern; int endPattern; } res; @@ -69,11 +69,10 @@ resLoadFail(PARSER_ERROR, fileName); resInf->numInputUnits = -1; resInf->numOutputUnits = -1; - resInf->numPatterns = -1; + resInf->numResults = -1; resInf->startPattern = -1; resInf->endPattern = -1; - resInf->inputValues = NULL; - resInf->outputValues = NULL; + resInf->resultValues = NULL; tok = yylex(); while (tok != END) { @@ -83,7 +82,7 @@ tok = yylex(); if (tok != INTNUMBER) resLoadFail(PARSER_ERROR, fileName); - resInf->numPatterns = atoi(yytext); + resInf->numResults = atoi(yytext); break; case NUMIN: tok = yylex(); @@ -111,29 +110,31 @@ break; case FLOATNUMBER: case INTNUMBER: - if (resInf->numPatterns <= 0 || curPat == resInf->numPatterns) + if (resInf->numResults <= 0 || curRes == resInf->numResults) resLoadFail(CHECK_ERROR, fileName); if (resInf->resultValues == NULL && resInf->numOutputUnits > 0) { - tempp = malloc(sizeof(float) * resInf->numPatterns * resInf->numOutputUnits); + tempp = malloc(sizeof(float) * resInf->numResults * resInf->numOutputUnits); if (tempp == NULL) fatal(errno); - resInf->resultValues = malloc(sizeof(float *) * resInf->numPatterns); + resInf->resultValues = malloc(sizeof(float *) * resInf->numResults); if (resInf->resultValues == NULL) fatal(errno); - for (i = 0; i < resInf->numPatterns; i++) + for (i = 0; i < resInf->numResults; i++) resInf->resultValues[i] = tempp + (i * resInf->numOutputUnits); } - i = 0; + resInf->resultValues[curRes][0] = atof(yytext); + i = 1; while (i < resInf->numOutputUnits) { tok = yylex(); - if (tok != FLOATNUMBER && tok != INTNUMBER) + if (tok != FLOATNUMBER && tok != INTNUMBER) { resLoadFail(CHECK_ERROR, fileName); - resInf->resultValues[curPat][i] = atof(yytext); + } + resInf->resultValues[curRes][i] = atof(yytext); ++i; } - curPat++; + curRes++; break; default: resLoadFail(PARSER_ERROR, fileName); @@ -142,6 +143,20 @@ } } +static int get_class(float *values, int n) { + int max; + if (n <= 0) + return 0; + --n; + max = values[n]; + while (n >= 0) { + if (max < values[n]) + max = values[n]; + --n; + } + return max; +} + int main(int argc, char **argv) { int c; @@ -159,7 +174,7 @@ FILE *pr_file, *pp_file; res resData; int cols = -1, rows = -1; - int npat, t; + int npat, t, j; char p_buf[BUF_LEN]; if (argc == 1) @@ -211,66 +226,29 @@ if (fprintf(pp_file, "P5\n%d %d\n%d\n", cols, rows, resData.numOutputUnits) < 0) fatal(errno); npat = 0; - while (npat < resData.numPatterns) { - t = (npat + NUM_BUF) > resData.numPatterns ? resData.numPatters - npat : NUM_BUF; - while (npat < t) { - - ++npat; + while (npat < resData.numResults) { + t = (npat + 1 + BUF_LEN) >= resData.numResults ? resData.numResults - npat - 1 : BUF_LEN - 1; + j = t + 1; + while (t >= 0) { + p_buf[t] = get_class(resData.resultValues[npat+t], resData.numOutputUnits); + --t; } - ++npat; - } - for (npat = 0; npat < resData.numPatterns; npat++) - { - if (fprintf(pr_file, "#%d.1\n", npat + 1) < 0) + if (fwrite(p_buf, j, 1, pp_file) != 1) fatal(errno); - result = fann_run(tfann, c_patData.inputValues[npat]); - for (c = 0; c < t_patData.numOutputUnits; c++) - { - if (fprintf(pr_file, "%.5f ", result[c]) < 0) - fatal(errno); - } - fseek(pr_file, -1, SEEK_CUR); /* remove extra space */ - fprintf(pr_file, "\n"); - } - fann_destroy(tfann); - if (t_patData.inputValues != NULL) - { - /* free only first element because is a contiguous allocated memory - space (see loadNetwork) */ - if (t_patData.inputValues[0] != NULL) - free(t_patData.inputValues[0]); - free(t_patData.inputValues); - } - if (t_patData.outputValues != NULL) - { - /* free only first element because is a contiguous allocated memory - space (see loadNetwork) */ - if (t_patData.outputValues[0] != NULL) - free(t_patData.outputValues[0]); - free(t_patData.outputValues); - } - if (c_patData.inputValues != NULL) - { - /* free only first element because is a contiguous allocated memory - space (see loadNetwork) */ - if (c_patData.inputValues[0] != NULL) - free(c_patData.inputValues[0]); - free(c_patData.inputValues); + npat += j; } - if (c_patData.outputValues != NULL) + if (resData.resultValues != NULL) { /* free only first element because is a contiguous allocated memory - space (see loadNetwork) */ - if (c_patData.outputValues[0] != NULL) - free(c_patData.outputValues[0]); - free(c_patData.outputValues); + space (see loadResults) */ + if (resData.resultValues[0] != NULL) + free(resData.resultValues[0]); + free(resData.resultValues); } - if (fclose(pt_file) != 0) - fatal(errno); - if (fclose(pc_file) != 0) - fatal(errno); if (fclose(pr_file) != 0) fatal(errno); + if (fclose(pp_file) != 0) + fatal(errno); return 0; } |