2007-03-08 04:03:40 +08:00
|
|
|
/******************************************************************************
|
|
|
|
** Filename: clustertool.c
|
|
|
|
** Purpose: Misc. tools for use with the clustering routines
|
|
|
|
** Author: Dan Johnson
|
|
|
|
** History: 6/6/89, DSJ, Created.
|
|
|
|
**
|
|
|
|
** (c) Copyright Hewlett-Packard Company, 1988.
|
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
|
|
|
** limitations under the License.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
//--------------------------Include Files----------------------------------
|
|
|
|
#include "clusttool.h"
|
|
|
|
#include "const.h"
|
|
|
|
#include "danerror.h"
|
|
|
|
#include "emalloc.h"
|
|
|
|
#include "scanutils.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
//---------------Global Data Definitions and Declarations--------------------
|
2014-09-13 04:41:19 +08:00
|
|
|
#define TOKENSIZE 80 //< max size of tokens read from an input file
|
|
|
|
#define MAXSAMPLESIZE 65535 //< max num of dimensions in feature space
|
|
|
|
//#define MAXBLOCKSIZE 65535 //< max num of samples in a character (block size)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This routine reads a single integer from the specified
|
|
|
|
* file and checks to ensure that it is between 0 and
|
|
|
|
* MAXSAMPLESIZE.
|
|
|
|
* @param File open text file to read sample size from
|
|
|
|
* @return Sample size
|
|
|
|
* @note Globals: None
|
|
|
|
* @note Exceptions: ILLEGALSAMPLESIZE illegal format or range
|
|
|
|
* @note History: 6/6/89, DSJ, Created.
|
|
|
|
*/
|
2008-04-22 08:23:04 +08:00
|
|
|
uinT16 ReadSampleSize(FILE *File) {
|
2007-03-08 04:03:40 +08:00
|
|
|
int SampleSize;
|
|
|
|
|
2014-04-24 07:12:53 +08:00
|
|
|
if ((tfscanf(File, "%d", &SampleSize) != 1) ||
|
2007-03-08 04:03:40 +08:00
|
|
|
(SampleSize < 0) || (SampleSize > MAXSAMPLESIZE))
|
|
|
|
DoError (ILLEGALSAMPLESIZE, "Illegal sample size");
|
|
|
|
return (SampleSize);
|
2014-09-13 04:41:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This routine reads textual descriptions of sets of parameters
|
|
|
|
* which describe the characteristics of feature dimensions.
|
|
|
|
*
|
|
|
|
* Exceptions:
|
|
|
|
* - ILLEGALCIRCULARSPEC
|
|
|
|
* - ILLEGALESSENTIALSPEC
|
|
|
|
* - ILLEGALMINMAXSPEC
|
|
|
|
* @param File open text file to read N parameter descriptions from
|
|
|
|
* @param N number of parameter descriptions to read
|
|
|
|
* @return Pointer to an array of parameter descriptors.
|
|
|
|
* @note Globals: None
|
|
|
|
* @note History: 6/6/89, DSJ, Created.
|
|
|
|
*/
|
2008-04-22 08:23:04 +08:00
|
|
|
PARAM_DESC *ReadParamDesc(FILE *File, uinT16 N) {
|
2007-03-08 04:03:40 +08:00
|
|
|
int i;
|
|
|
|
PARAM_DESC *ParamDesc;
|
|
|
|
char Token[TOKENSIZE];
|
2007-05-16 09:30:20 +08:00
|
|
|
|
2007-03-08 04:03:40 +08:00
|
|
|
ParamDesc = (PARAM_DESC *) Emalloc (N * sizeof (PARAM_DESC));
|
|
|
|
for (i = 0; i < N; i++) {
|
2014-04-24 07:12:53 +08:00
|
|
|
if (tfscanf(File, "%s", Token) != 1)
|
2007-03-08 04:03:40 +08:00
|
|
|
DoError (ILLEGALCIRCULARSPEC,
|
|
|
|
"Illegal circular/linear specification");
|
|
|
|
if (Token[0] == 'c')
|
|
|
|
ParamDesc[i].Circular = TRUE;
|
|
|
|
else
|
|
|
|
ParamDesc[i].Circular = FALSE;
|
|
|
|
|
2014-04-24 07:12:53 +08:00
|
|
|
if (tfscanf(File, "%s", Token) != 1)
|
2007-03-08 04:03:40 +08:00
|
|
|
DoError (ILLEGALESSENTIALSPEC,
|
|
|
|
"Illegal essential/non-essential spec");
|
|
|
|
if (Token[0] == 'e')
|
|
|
|
ParamDesc[i].NonEssential = FALSE;
|
|
|
|
else
|
|
|
|
ParamDesc[i].NonEssential = TRUE;
|
2014-04-29 07:10:48 +08:00
|
|
|
if (tfscanf(File, "%f%f", &(ParamDesc[i].Min), &(ParamDesc[i].Max)) != 2)
|
2007-03-08 04:03:40 +08:00
|
|
|
DoError (ILLEGALMINMAXSPEC, "Illegal min or max specification");
|
|
|
|
ParamDesc[i].Range = ParamDesc[i].Max - ParamDesc[i].Min;
|
|
|
|
ParamDesc[i].HalfRange = ParamDesc[i].Range / 2;
|
|
|
|
ParamDesc[i].MidRange = (ParamDesc[i].Max + ParamDesc[i].Min) / 2;
|
|
|
|
}
|
|
|
|
return (ParamDesc);
|
2014-09-13 04:41:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This routine reads a textual description of a prototype from
|
|
|
|
* the specified file.
|
|
|
|
*
|
|
|
|
* Exceptions:
|
|
|
|
* - ILLEGALSIGNIFICANCESPEC
|
|
|
|
* - ILLEGALSAMPLECOUNT
|
|
|
|
* - ILLEGALMEANSPEC
|
|
|
|
* - ILLEGALVARIANCESPEC
|
|
|
|
* - ILLEGALDISTRIBUTION
|
|
|
|
* @param File open text file to read prototype from
|
|
|
|
* @param N number of dimensions used in prototype
|
|
|
|
* @return List of prototypes
|
|
|
|
* @note Globals: None
|
|
|
|
* @note History: 6/6/89, DSJ, Created.
|
|
|
|
*/
|
2008-04-22 08:23:04 +08:00
|
|
|
PROTOTYPE *ReadPrototype(FILE *File, uinT16 N) {
|
2007-03-08 04:03:40 +08:00
|
|
|
char Token[TOKENSIZE];
|
|
|
|
int Status;
|
|
|
|
PROTOTYPE *Proto;
|
|
|
|
int SampleCount;
|
|
|
|
int i;
|
|
|
|
|
2014-04-24 07:12:53 +08:00
|
|
|
if ((Status = tfscanf(File, "%s", Token)) == 1) {
|
2007-03-08 04:03:40 +08:00
|
|
|
Proto = (PROTOTYPE *) Emalloc (sizeof (PROTOTYPE));
|
|
|
|
Proto->Cluster = NULL;
|
|
|
|
if (Token[0] == 's')
|
|
|
|
Proto->Significant = TRUE;
|
|
|
|
else
|
|
|
|
Proto->Significant = FALSE;
|
|
|
|
|
|
|
|
Proto->Style = ReadProtoStyle (File);
|
|
|
|
|
2014-04-24 07:12:53 +08:00
|
|
|
if ((tfscanf(File, "%d", &SampleCount) != 1) || (SampleCount < 0))
|
2007-03-08 04:03:40 +08:00
|
|
|
DoError (ILLEGALSAMPLECOUNT, "Illegal sample count");
|
|
|
|
Proto->NumSamples = SampleCount;
|
|
|
|
|
|
|
|
Proto->Mean = ReadNFloats (File, N, NULL);
|
|
|
|
if (Proto->Mean == NULL)
|
|
|
|
DoError (ILLEGALMEANSPEC, "Illegal prototype mean");
|
|
|
|
|
|
|
|
switch (Proto->Style) {
|
|
|
|
case spherical:
|
|
|
|
if (ReadNFloats (File, 1, &(Proto->Variance.Spherical)) == NULL)
|
|
|
|
DoError (ILLEGALVARIANCESPEC, "Illegal prototype variance");
|
|
|
|
Proto->Magnitude.Spherical =
|
|
|
|
1.0 / sqrt ((double) (2.0 * PI * Proto->Variance.Spherical));
|
|
|
|
Proto->TotalMagnitude =
|
2007-05-16 09:30:20 +08:00
|
|
|
pow (Proto->Magnitude.Spherical, (float) N);
|
2007-03-08 04:03:40 +08:00
|
|
|
Proto->LogMagnitude = log ((double) Proto->TotalMagnitude);
|
|
|
|
Proto->Weight.Spherical = 1.0 / Proto->Variance.Spherical;
|
|
|
|
Proto->Distrib = NULL;
|
|
|
|
break;
|
|
|
|
case elliptical:
|
|
|
|
Proto->Variance.Elliptical = ReadNFloats (File, N, NULL);
|
|
|
|
if (Proto->Variance.Elliptical == NULL)
|
|
|
|
DoError (ILLEGALVARIANCESPEC, "Illegal prototype variance");
|
|
|
|
Proto->Magnitude.Elliptical =
|
|
|
|
(FLOAT32 *) Emalloc (N * sizeof (FLOAT32));
|
|
|
|
Proto->Weight.Elliptical =
|
|
|
|
(FLOAT32 *) Emalloc (N * sizeof (FLOAT32));
|
|
|
|
Proto->TotalMagnitude = 1.0;
|
|
|
|
for (i = 0; i < N; i++) {
|
|
|
|
Proto->Magnitude.Elliptical[i] =
|
|
|
|
1.0 /
|
|
|
|
sqrt ((double) (2.0 * PI * Proto->Variance.Elliptical[i]));
|
|
|
|
Proto->Weight.Elliptical[i] =
|
|
|
|
1.0 / Proto->Variance.Elliptical[i];
|
|
|
|
Proto->TotalMagnitude *= Proto->Magnitude.Elliptical[i];
|
|
|
|
}
|
|
|
|
Proto->LogMagnitude = log ((double) Proto->TotalMagnitude);
|
|
|
|
Proto->Distrib = NULL;
|
|
|
|
break;
|
|
|
|
case mixed:
|
|
|
|
Proto->Distrib =
|
|
|
|
(DISTRIBUTION *) Emalloc (N * sizeof (DISTRIBUTION));
|
|
|
|
for (i = 0; i < N; i++) {
|
2014-04-24 07:12:53 +08:00
|
|
|
if (tfscanf(File, "%s", Token) != 1)
|
2007-03-08 04:03:40 +08:00
|
|
|
DoError (ILLEGALDISTRIBUTION,
|
|
|
|
"Illegal prototype distribution");
|
|
|
|
switch (Token[0]) {
|
|
|
|
case 'n':
|
|
|
|
Proto->Distrib[i] = normal;
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
Proto->Distrib[i] = uniform;
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
Proto->Distrib[i] = D_random;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DoError (ILLEGALDISTRIBUTION,
|
|
|
|
"Illegal prototype distribution");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Proto->Variance.Elliptical = ReadNFloats (File, N, NULL);
|
|
|
|
if (Proto->Variance.Elliptical == NULL)
|
|
|
|
DoError (ILLEGALVARIANCESPEC, "Illegal prototype variance");
|
|
|
|
Proto->Magnitude.Elliptical =
|
|
|
|
(FLOAT32 *) Emalloc (N * sizeof (FLOAT32));
|
|
|
|
Proto->Weight.Elliptical =
|
|
|
|
(FLOAT32 *) Emalloc (N * sizeof (FLOAT32));
|
|
|
|
Proto->TotalMagnitude = 1.0;
|
|
|
|
for (i = 0; i < N; i++) {
|
|
|
|
switch (Proto->Distrib[i]) {
|
|
|
|
case normal:
|
|
|
|
Proto->Magnitude.Elliptical[i] = 1.0 /
|
|
|
|
sqrt ((double)
|
|
|
|
(2.0 * PI * Proto->Variance.Elliptical[i]));
|
|
|
|
Proto->Weight.Elliptical[i] =
|
|
|
|
1.0 / Proto->Variance.Elliptical[i];
|
|
|
|
break;
|
|
|
|
case uniform:
|
|
|
|
case D_random:
|
|
|
|
Proto->Magnitude.Elliptical[i] = 1.0 /
|
|
|
|
(2.0 * Proto->Variance.Elliptical[i]);
|
|
|
|
break;
|
2012-02-02 10:57:42 +08:00
|
|
|
case DISTRIBUTION_COUNT:
|
|
|
|
ASSERT_HOST(!"Distribution count not allowed!");
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
Proto->TotalMagnitude *= Proto->Magnitude.Elliptical[i];
|
|
|
|
}
|
|
|
|
Proto->LogMagnitude = log ((double) Proto->TotalMagnitude);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (Proto);
|
|
|
|
}
|
|
|
|
else if (Status == EOF)
|
|
|
|
return (NULL);
|
|
|
|
else {
|
|
|
|
DoError (ILLEGALSIGNIFICANCESPEC, "Illegal significance specification");
|
|
|
|
return (NULL);
|
|
|
|
}
|
2014-09-13 04:41:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This routine reads an single token from the specified
|
|
|
|
* text file and interprets it as a prototype specification.
|
|
|
|
* @param File open text file to read prototype style from
|
|
|
|
* @return Prototype style read from text file
|
|
|
|
* @note Globals: None
|
|
|
|
* @note Exceptions: ILLEGALSTYLESPEC illegal prototype style specification
|
|
|
|
* @note History: 6/8/89, DSJ, Created.
|
|
|
|
*/
|
2007-05-16 09:30:20 +08:00
|
|
|
PROTOSTYLE ReadProtoStyle(FILE *File) {
|
2007-03-08 04:03:40 +08:00
|
|
|
char Token[TOKENSIZE];
|
|
|
|
PROTOSTYLE Style;
|
|
|
|
|
2014-04-24 07:12:53 +08:00
|
|
|
if (tfscanf(File, "%s", Token) != 1)
|
2007-03-08 04:03:40 +08:00
|
|
|
DoError (ILLEGALSTYLESPEC, "Illegal prototype style specification");
|
|
|
|
switch (Token[0]) {
|
|
|
|
case 's':
|
|
|
|
Style = spherical;
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
Style = elliptical;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
Style = mixed;
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
Style = automatic;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Style = elliptical;
|
|
|
|
DoError (ILLEGALSTYLESPEC, "Illegal prototype style specification");
|
|
|
|
}
|
|
|
|
return (Style);
|
2014-09-13 04:41:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
* @param File open text file to read floats from
|
|
|
|
* @param N number of floats to read
|
|
|
|
* @param Buffer pointer to buffer to place floats into
|
|
|
|
* @return Pointer to buffer holding floats or NULL if EOF
|
|
|
|
* @note Globals: None
|
|
|
|
* @note Exceptions: ILLEGALFLOAT
|
|
|
|
* @note History: 6/6/89, DSJ, Created.
|
|
|
|
*/
|
2014-02-05 07:36:24 +08:00
|
|
|
FLOAT32* ReadNFloats(FILE * File, uinT16 N, FLOAT32 Buffer[]) {
|
2015-11-25 00:45:00 +08:00
|
|
|
bool needs_free = false;
|
2007-03-08 04:03:40 +08:00
|
|
|
int i;
|
|
|
|
int NumFloatsRead;
|
|
|
|
|
2015-11-25 00:45:00 +08:00
|
|
|
if (Buffer == NULL) {
|
2014-02-05 07:36:24 +08:00
|
|
|
Buffer = reinterpret_cast<FLOAT32*>(Emalloc(N * sizeof(FLOAT32)));
|
2015-11-25 00:45:00 +08:00
|
|
|
needs_free = true;
|
|
|
|
}
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
for (i = 0; i < N; i++) {
|
2014-04-24 07:12:53 +08:00
|
|
|
NumFloatsRead = tfscanf(File, "%f", &(Buffer[i]));
|
2007-03-08 04:03:40 +08:00
|
|
|
if (NumFloatsRead != 1) {
|
2014-02-05 07:36:24 +08:00
|
|
|
if ((NumFloatsRead == EOF) && (i == 0)) {
|
2015-11-25 00:45:00 +08:00
|
|
|
if (needs_free) {
|
|
|
|
Efree(Buffer);
|
|
|
|
}
|
2014-02-05 07:36:24 +08:00
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
DoError(ILLEGALFLOAT, "Illegal float specification");
|
|
|
|
}
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
}
|
2014-02-05 07:36:24 +08:00
|
|
|
return Buffer;
|
2014-09-13 04:41:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This routine writes an array of dimension descriptors to
|
|
|
|
* the specified text file.
|
|
|
|
* @param File open text file to write param descriptors to
|
|
|
|
* @param N number of param descriptors to write
|
|
|
|
* @param ParamDesc array of param descriptors to write
|
|
|
|
* @return None
|
|
|
|
* @note Globals: None
|
|
|
|
* @note Exceptions: None
|
|
|
|
* @note History: 6/6/89, DSJ, Created.
|
|
|
|
*/
|
2007-03-08 04:03:40 +08:00
|
|
|
void
|
2008-04-22 08:23:04 +08:00
|
|
|
WriteParamDesc (FILE * File, uinT16 N, PARAM_DESC ParamDesc[]) {
|
2007-03-08 04:03:40 +08:00
|
|
|
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);
|
|
|
|
}
|
2014-09-13 04:41:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This routine writes a textual description of a prototype
|
|
|
|
* to the specified text file.
|
|
|
|
* @param File open text file to write prototype to
|
|
|
|
* @param N number of dimensions in feature space
|
|
|
|
* @param Proto prototype to write out
|
|
|
|
* @return None
|
|
|
|
* @note Globals: None
|
|
|
|
* @note Exceptions: None
|
|
|
|
* @note History: 6/12/89, DSJ, Created.
|
|
|
|
*/
|
2008-04-22 08:23:04 +08:00
|
|
|
void WritePrototype(FILE *File, uinT16 N, PROTOTYPE *Proto) {
|
2007-03-08 04:03:40 +08:00
|
|
|
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;
|
2012-02-02 10:57:42 +08:00
|
|
|
case DISTRIBUTION_COUNT:
|
|
|
|
ASSERT_HOST(!"Distribution count not allowed!");
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
fprintf (File, "\n\t");
|
|
|
|
WriteNFloats (File, N, Proto->Variance.Elliptical);
|
|
|
|
}
|
2014-09-13 04:41:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This routine writes a text representation of N floats from
|
|
|
|
* an array to a file. All of the floats are placed on one line.
|
|
|
|
* @param File open text file to write N floats to
|
|
|
|
* @param N number of floats to write
|
|
|
|
* @param Array array of floats to write
|
|
|
|
* @return None
|
|
|
|
* @note Globals: None
|
|
|
|
* @note Exceptions: None
|
|
|
|
* @note History: 6/6/89, DSJ, Created.
|
|
|
|
*/
|
2012-02-02 10:57:42 +08:00
|
|
|
void WriteNFloats(FILE * File, uinT16 N, FLOAT32 Array[]) {
|
|
|
|
for (int i = 0; i < N; i++)
|
|
|
|
fprintf(File, " %9.6f", Array[i]);
|
|
|
|
fprintf(File, "\n");
|
2014-09-13 04:41:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This routine writes to the specified text file a word
|
|
|
|
* which represents the ProtoStyle. It does not append
|
|
|
|
* a carriage return to the end.
|
|
|
|
* @param File open text file to write prototype style to
|
|
|
|
* @param ProtoStyle prototype style to write
|
|
|
|
* @return None
|
|
|
|
* @note Globals: None
|
|
|
|
* @note Exceptions: None
|
|
|
|
* @note History: 6/8/89, DSJ, Created.
|
|
|
|
*/
|
2007-05-16 09:30:20 +08:00
|
|
|
void WriteProtoStyle(FILE *File, PROTOSTYLE ProtoStyle) {
|
2007-03-08 04:03:40 +08:00
|
|
|
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;
|
|
|
|
}
|
2014-09-13 04:41:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
* @param File open text file to write prototypes to
|
|
|
|
* @param N number of dimensions in feature space
|
|
|
|
* @param ParamDesc descriptions for each dimension
|
|
|
|
* @param ProtoList list of prototypes to be written
|
|
|
|
* @param WriteSigProtos TRUE to write out significant prototypes
|
|
|
|
* @param WriteInsigProtos TRUE to write out insignificants
|
|
|
|
* @note Globals: None
|
|
|
|
* @return None
|
|
|
|
* @note Exceptions: None
|
|
|
|
* @note History: 6/12/89, DSJ, Created.
|
|
|
|
*/
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
void WriteProtoList(
|
|
|
|
FILE *File,
|
2008-04-22 08:23:04 +08:00
|
|
|
uinT16 N,
|
2007-03-08 04:03:40 +08:00
|
|
|
PARAM_DESC ParamDesc[],
|
|
|
|
LIST ProtoList,
|
|
|
|
BOOL8 WriteSigProtos,
|
|
|
|
BOOL8 WriteInsigProtos)
|
|
|
|
{
|
|
|
|
PROTOTYPE *Proto;
|
2007-05-16 09:30:20 +08:00
|
|
|
|
2007-03-08 04:03:40 +08:00
|
|
|
/* write file header */
|
|
|
|
fprintf(File,"%0d\n",N);
|
|
|
|
WriteParamDesc(File,N,ParamDesc);
|
|
|
|
|
|
|
|
/* write prototypes */
|
|
|
|
iterate(ProtoList)
|
|
|
|
{
|
2007-05-16 09:30:20 +08:00
|
|
|
Proto = (PROTOTYPE *) first_node ( ProtoList );
|
2007-03-08 04:03:40 +08:00
|
|
|
if (( Proto->Significant && WriteSigProtos ) ||
|
|
|
|
( ! Proto->Significant && WriteInsigProtos ) )
|
|
|
|
WritePrototype( File, N, Proto );
|
|
|
|
}
|
2014-09-13 04:41:19 +08:00
|
|
|
}
|