📄 cle.c
字号:
/*---------------------------------------------------------------------- File : cle.c Contents: probabilistic and fuzzy cluster evaluation Author : Christian Borgelt History : 17.05.2003 file created 18.05.2003 setting of noise parameter (option -y) added 09.06.2003 coverage of data added 16.08.2003 slight changes in error message output 25.02.2004 source files mcle.c and cle.c combined 28.01.2006 conditional compilation simplified----------------------------------------------------------------------*/#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <math.h>#include <time.h>#include <assert.h>#ifdef MATVERSION#ifndef MAT_READ#define MAT_READ#endif#else /* #ifdef MATVERSION */#ifndef AS_RDWR#define AS_RDWR#endif#ifndef AS_PARSE#define AS_PARSE#endif#include "io.h"#endif /* #ifdef MATVERSION */#ifndef CLS_PARSE#define CLS_PARSE#endif#ifndef CLS_EXTFN#define CLS_EXTFN#endif#include "cluster.h"/*---------------------------------------------------------------------- Preprocessor Definitions----------------------------------------------------------------------*/#define PRGNAME "cle"#define DESCRIPTION "probabilistic and fuzzy cluster evaluation"#define VERSION "version 1.11 (2006.01.28) " \ "(c) 2003-2006 Christian Borgelt"/* --- error codes --- */#define OK 0 /* no error */#define E_NONE 0 /* no error */#define E_NOMEM (-1) /* not enough memory */#define E_FOPEN (-2) /* file open failed */#define E_FREAD (-3) /* file read failed */#define E_FWRITE (-4) /* file write failed */#define E_OPTION (-5) /* unknown option */#define E_OPTARG (-6) /* missing option argument */#define E_ARGCNT (-7) /* wrong number of arguments */#define E_STDIN (-8) /* double assignment of stdin */#define E_PARSE (-9) /* parse errors on input file */#define E_PATCNT (-10) /* no pattern found */#define E_PATSIZE (-11) /* illegal pattern size */#define E_MSEXP (-12) /* illegal membership exponent */#define E_UNKNOWN (-18) /* unknown error *//*---------------------------------------------------------------------- Constants----------------------------------------------------------------------*/static const char *errmsgs[] = { /* error messages */ /* E_NONE 0 */ "no error\n", /* E_NOMEM -1 */ "not enough memory\n", /* E_FOPEN -2 */ "cannot open file %s\n", /* E_FREAD -3 */ "read error on file %s\n", /* E_FWRITE -4 */ "write error on file %s\n", /* E_OPTION -5 */ "unknown option -%c\n", /* E_OPTARG -6 */ "missing option argument\n", /* E_ARGCNT -7 */ "wrong number of arguments\n", /* E_STDIN -8 */ "double assignment of standard input\n", /* E_PARSE -9 */ "parse error(s) on file %s\n", /* E_PATCNT -10 */ "no pattern in file %s\n", /* E_PATSIZE -11 */ "illegal pattern size %d\n", /* E_MSEXP -12 */ "illegal membership exponent %g\n", /* -13 to -15 */ NULL, NULL, NULL, /* E_VALUE -16 */ "file %s, record %d: " "illegal value %s in field %d\n", /* E_FLDCNT -17 */ "file %s, record %d: " "%s%d field(s) instead of %d\n", /* E_UNKNOWN -18 */ "unknown error\n",};/*---------------------------------------------------------------------- Global Variables----------------------------------------------------------------------*/const char *prgname = NULL; /* program name for error messages */static SCAN *scan = NULL; /* scanner for cluster set desc. */static CLSET *clset = NULL; /* cluster set */static FILE *in = NULL; /* input file */#ifdef MATVERSIONstatic TFSCAN *tfscan = NULL; /* table file scanner */#elsestatic ATTSET *attset = NULL; /* attribute set */#endif/*---------------------------------------------------------------------- Main Functions----------------------------------------------------------------------*/static void error (int code, ...){ /* --- print error message */ va_list args; /* list of variable arguments */ const char *msg; /* error message */ assert(prgname); /* check the program name */ if (code < E_UNKNOWN) code = E_UNKNOWN; if (code < 0) { /* if to report an error, */ msg = errmsgs[-code]; /* get the error message */ if (!msg) msg = errmsgs[-E_UNKNOWN]; fprintf(stderr, "\n%s: ", prgname); va_start(args, code); /* get variable arguments */ vfprintf(stderr, msg, args);/* print the error message */ va_end(args); /* end argument evaluation */ } #ifndef NDEBUG /* clean up memory */ if (clset) cls_delete(clset);/* and close files */ #ifdef MATVERSION if (tfscan) tfs_delete(tfscan); #else if (attset) as_delete(attset); #endif if (scan) sc_delete(scan); if (in && (in != stdin)) fclose(in); #endif exit(code); /* abort the program */} /* error() *//*--------------------------------------------------------------------*/int main (int argc, char *argv[]){ /* --- main function */ int i, k = 0; /* loop variables, counters */ char *s; /* to traverse options */ char **optarg = NULL; /* option argument */ char *fn_cls = NULL; /* name of cluster set file */ #ifndef MATVERSION char *fn_hdr = NULL; /* name of table header file */ #endif char *fn_in = NULL; /* name of table file */ char *blanks = NULL; /* blanks */ char *fldseps = NULL; /* field separators */ char *recseps = NULL; /* record separators */ double msexp = 2; /* membership degree exponent */ double radius = 1; /* radius for (avg.) part. density */ #ifdef MATVERSION int patcnt = 0; /* number of test patterns */ double *pat; /* to traverse the patterns */ #else int flags = 0, f; /* table file read flags */ int tplcnt = 0; /* number of tuples */ double tplwgt = 0.0, w; /* weight of tuples */ #endif int attcnt; /* number of values in a pattern */ int clscnt; /* number of clusters */ TFSERR *err; /* error information */ prgname = argv[0]; /* get program name for error msgs. */ /* --- print startup/usage message --- */ if (argc > 1) { /* if arguments are given */ fprintf(stderr, "%s - %s\n", argv[0], DESCRIPTION); fprintf(stderr, VERSION); } /* print a startup message */ else { /* if no argument is given */ #ifdef MATVERSION printf("usage: %s [options] clsfile patfile\n", argv[0]); #else printf("usage: %s [options] clsfile " "[-d|-h hdrfile] tabfile\n", argv[0]); #endif printf("%s\n", DESCRIPTION); printf("%s\n", VERSION); printf("-x# membership degree exponent " "(default: %g)\n", msexp); printf("-p# radius for (average) partition density "
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -