📄 clusttool.cpp
字号:
case 'm': Style = mixed; break; case 'a': Style = automatic; break; default: Style = elliptical; DoError (ILLEGALSTYLESPEC, "Illegal prototype style specification"); } return (Style);} // ReadProtoStyle/** ReadNFloats *************************************************************Parameters: File open text file to read floats from N number of floats to read Buffer pointer to buffer to place floats intoGlobals: NoneOperation: This routine reads N floats from the specified text file and places them into Buffer. If Buffer is NULL, a buffer is created and passed back to the caller. If EOF is encountered before any floats can be read, NULL is returned.Return: Pointer to buffer holding floats or NULL if EOFExceptions: ILLEGALFLOATHistory: 6/6/89, DSJ, Created.******************************************************************************/FLOAT32 *ReadNFloats (FILE * File, UINT16 N, FLOAT32 Buffer[]) { int i; int NumFloatsRead; if (Buffer == NULL) Buffer = (FLOAT32 *) Emalloc (N * sizeof (FLOAT32)); for (i = 0; i < N; i++) { NumFloatsRead = fscanf (File, "%f", &(Buffer[i])); if (NumFloatsRead != 1) { if ((NumFloatsRead == EOF) && (i == 0)) return (NULL); else DoError (ILLEGALFLOAT, "Illegal float specification"); } } return (Buffer);} // ReadNFloats/** WriteParamDesc ************************************************************Parameters: File open text file to write param descriptors to N number of param descriptors to write ParamDesc array of param descriptors to writeGlobals: NoneOperation: This routine writes an array of dimension descriptors to the specified text file.Return: NoneExceptions: NoneHistory: 6/6/89, DSJ, Created.******************************************************************************/voidWriteParamDesc (FILE * File, UINT16 N, PARAM_DESC ParamDesc[]) { int i; for (i = 0; i < N; i++) { if (ParamDesc[i].Circular) fprintf (File, "circular "); else fprintf (File, "linear "); if (ParamDesc[i].NonEssential) fprintf (File, "non-essential "); else fprintf (File, "essential "); fprintf (File, "%10.6f %10.6f\n", ParamDesc[i].Min, ParamDesc[i].Max); }} // WriteParamDesc/** WritePrototype ************************************************************Parameters: File open text file to write prototype to N number of dimensions in feature space Proto prototype to write outGlobals: NoneOperation: This routine writes a textual description of a prototype to the specified text file.Return: NoneExceptions: NoneHistory: 6/12/89, DSJ, Created.*******************************************************************************/void WritePrototype(FILE *File, UINT16 N, PROTOTYPE *Proto) { int i; if (Proto->Significant) fprintf (File, "significant "); else fprintf (File, "insignificant "); WriteProtoStyle (File, (PROTOSTYLE) Proto->Style); fprintf (File, "%6d\n\t", Proto->NumSamples); WriteNFloats (File, N, Proto->Mean); fprintf (File, "\t"); switch (Proto->Style) { case spherical: WriteNFloats (File, 1, &(Proto->Variance.Spherical)); break; case elliptical: WriteNFloats (File, N, Proto->Variance.Elliptical); break; case mixed: for (i = 0; i < N; i++) switch (Proto->Distrib[i]) { case normal: fprintf (File, " %9s", "normal"); break; case uniform: fprintf (File, " %9s", "uniform"); break; case D_random: fprintf (File, " %9s", "random"); break; } fprintf (File, "\n\t"); WriteNFloats (File, N, Proto->Variance.Elliptical); }} // WritePrototype/** WriteNFloats ***********************************************************Parameters: File open text file to write N floats to N number of floats to write Array array of floats to writeGlobals: NoneOperation: This routine writes a text representation of N floats from an array to a file. All of the floats are placed on one line.Return: NoneExceptions: NoneHistory: 6/6/89, DSJ, Created.****************************************************************************/voidWriteNFloats (FILE * File, UINT16 N, FLOAT32 Array[]) { int i; for (i = 0; i < N; i++) fprintf (File, " %9.6f", Array[i]); fprintf (File, "\n");} // WriteNFloats/** WriteProtoSyle **********************************************************Parameters: File open text file to write prototype style to ProtoStyle prototype style to writeGlobals: NoneOperation: This routine writes to the specified text file a word which represents the ProtoStyle. It does not append a carriage return to the end.Return: NoneExceptions: NoneHistory: 6/8/89, DSJ, Created.****************************************************************************/void WriteProtoStyle(FILE *File, PROTOSTYLE ProtoStyle) { switch (ProtoStyle) { case spherical: fprintf (File, "spherical"); break; case elliptical: fprintf (File, "elliptical"); break; case mixed: fprintf (File, "mixed"); break; case automatic: fprintf (File, "automatic"); break; }} // WriteProtoStyle/*---------------------------------------------------------------------------*/void WriteProtoList( FILE *File, UINT16 N, PARAM_DESC ParamDesc[], LIST ProtoList, BOOL8 WriteSigProtos, BOOL8 WriteInsigProtos) /*** Parameters:** File open text file to write prototypes to** N number of dimensions in feature space** ParamDesc descriptions for each dimension** ProtoList list of prototypes to be written** WriteSigProtos TRUE to write out significant prototypes** WriteInsigProtos TRUE to write out insignificants** Globals:** None** Operation:** This routine writes a textual description of each prototype** in the prototype list to the specified file. It also** writes a file header which includes the number of dimensions** in feature space and the descriptions for each dimension.** Return:** None** Exceptions:** None** History:** 6/12/89, DSJ, Created.*/{ PROTOTYPE *Proto; /* write file header */ fprintf(File,"%0d\n",N); WriteParamDesc(File,N,ParamDesc); /* write prototypes */ iterate(ProtoList) { Proto = (PROTOTYPE *) first ( ProtoList ); if (( Proto->Significant && WriteSigProtos ) || ( ! Proto->Significant && WriteInsigProtos ) ) WritePrototype( File, N, Proto ); }} /* WriteProtoList *//** UniformRandomNumber ********************************************************Parameters: MMin lower range of uniform distribution MMax upper range of uniform distributionGlobals: NoneOperation: This routine computes a random number which comes from a uniform distribution over the range from MMin to MMax.Return: Uniform random numberExceptions: NoneHistory: 6/6/89, DSJ, Created.*******************************************************************************/FLOAT32 UniformRandomNumber(FLOAT32 MMin, FLOAT32 MMax) { double fake_drand48(); FLOAT32 RandomNumber; RandomNumber = fake_drand48 (); return (MMin + (RandomNumber * (MMax - MMin)));} // UniformRandomNumber/** drand48 *************************************************************Cheap replacement for drand48 which is not available on the PC.**********************************************************************/double fake_drand48() { return rand () / (RAND_MAX + 1.0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -