Skip to content

Commit ed45656

Browse files
committed
clusttool: Remove unused code and some global functions
* WriteProtoList is unused. Remove it. * ReadNFloats, WriteNFloats and WriteProtoStyle are only used locally, so make them local. Signed-off-by: Stefan Weil <[email protected]>
1 parent 41f50b1 commit ed45656

File tree

2 files changed

+83
-128
lines changed

2 files changed

+83
-128
lines changed

src/classify/clusttool.cpp

+83-118
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/******************************************************************************
2-
** Filename: clustertool.c
2+
** Filename: clusttool.cpp
33
** Purpose: Misc. tools for use with the clustering routines
44
** Author: Dan Johnson
55
**
@@ -17,9 +17,8 @@
1717

1818
//--------------------------Include Files----------------------------------
1919
#include "clusttool.h"
20-
#include "emalloc.h"
21-
#include <cstdio>
2220
#include <cmath>
21+
#include "emalloc.h"
2322

2423
using tesseract::TFile;
2524

@@ -28,6 +27,87 @@ using tesseract::TFile;
2827
#define QUOTED_TOKENSIZE "79"
2928
#define MAXSAMPLESIZE 65535 ///< max num of dimensions in feature space
3029

30+
/**
31+
* This routine reads N floats from the specified text file
32+
* and places them into Buffer. If Buffer is nullptr, a buffer
33+
* is created and passed back to the caller. If EOF is
34+
* encountered before any floats can be read, nullptr is
35+
* returned.
36+
* @param fp open text file to read floats from
37+
* @param N number of floats to read
38+
* @param Buffer pointer to buffer to place floats into
39+
* @return Pointer to buffer holding floats or nullptr if EOF
40+
* @note Globals: None
41+
*/
42+
static float *ReadNFloats(TFile *fp, uint16_t N, float Buffer[]) {
43+
const int kMaxLineSize = 1024;
44+
char line[kMaxLineSize];
45+
if (fp->FGets(line, kMaxLineSize) == nullptr) {
46+
tprintf("Hit EOF in ReadNFloats!\n");
47+
return nullptr;
48+
}
49+
bool needs_free = false;
50+
51+
if (Buffer == nullptr) {
52+
Buffer = static_cast<float *>(Emalloc(N * sizeof(float)));
53+
needs_free = true;
54+
}
55+
56+
char *startptr = line;
57+
for (int i = 0; i < N; i++) {
58+
char *endptr;
59+
Buffer[i] = strtof(startptr, &endptr);
60+
if (endptr == startptr) {
61+
tprintf("Read of %d floats failed!\n", N);
62+
if (needs_free) Efree(Buffer);
63+
return nullptr;
64+
}
65+
startptr = endptr;
66+
}
67+
return Buffer;
68+
}
69+
70+
/**
71+
* This routine writes a text representation of N floats from
72+
* an array to a file. All of the floats are placed on one line.
73+
* @param File open text file to write N floats to
74+
* @param N number of floats to write
75+
* @param Array array of floats to write
76+
* @return None
77+
* @note Globals: None
78+
*/
79+
static void WriteNFloats(FILE * File, uint16_t N, float Array[]) {
80+
for (int i = 0; i < N; i++)
81+
fprintf(File, " %9.6f", Array[i]);
82+
fprintf(File, "\n");
83+
}
84+
85+
/**
86+
* This routine writes to the specified text file a word
87+
* which represents the ProtoStyle. It does not append
88+
* a carriage return to the end.
89+
* @param File open text file to write prototype style to
90+
* @param ProtoStyle prototype style to write
91+
* @return None
92+
* @note Globals: None
93+
*/
94+
static void WriteProtoStyle(FILE *File, PROTOSTYLE ProtoStyle) {
95+
switch (ProtoStyle) {
96+
case spherical:
97+
fprintf (File, "spherical");
98+
break;
99+
case elliptical:
100+
fprintf (File, "elliptical");
101+
break;
102+
case mixed:
103+
fprintf (File, "mixed");
104+
break;
105+
case automatic:
106+
fprintf (File, "automatic");
107+
break;
108+
}
109+
}
110+
31111
/**
32112
* This routine reads a single integer from the specified
33113
* file and checks to ensure that it is between 0 and
@@ -159,46 +239,6 @@ PROTOTYPE *ReadPrototype(TFile *fp, uint16_t N) {
159239
return Proto;
160240
}
161241

162-
/**
163-
* This routine reads N floats from the specified text file
164-
* and places them into Buffer. If Buffer is nullptr, a buffer
165-
* is created and passed back to the caller. If EOF is
166-
* encountered before any floats can be read, nullptr is
167-
* returned.
168-
* @param fp open text file to read floats from
169-
* @param N number of floats to read
170-
* @param Buffer pointer to buffer to place floats into
171-
* @return Pointer to buffer holding floats or nullptr if EOF
172-
* @note Globals: None
173-
*/
174-
float *ReadNFloats(TFile *fp, uint16_t N, float Buffer[]) {
175-
const int kMaxLineSize = 1024;
176-
char line[kMaxLineSize];
177-
if (fp->FGets(line, kMaxLineSize) == nullptr) {
178-
tprintf("Hit EOF in ReadNFloats!\n");
179-
return nullptr;
180-
}
181-
bool needs_free = false;
182-
183-
if (Buffer == nullptr) {
184-
Buffer = static_cast<float *>(Emalloc(N * sizeof(float)));
185-
needs_free = true;
186-
}
187-
188-
char *startptr = line;
189-
for (int i = 0; i < N; i++) {
190-
char *endptr;
191-
Buffer[i] = strtof(startptr, &endptr);
192-
if (endptr == startptr) {
193-
tprintf("Read of %d floats failed!\n", N);
194-
if (needs_free) Efree(Buffer);
195-
return nullptr;
196-
}
197-
startptr = endptr;
198-
}
199-
return Buffer;
200-
}
201-
202242
/**
203243
* This routine writes an array of dimension descriptors to
204244
* the specified text file.
@@ -273,78 +313,3 @@ void WritePrototype(FILE *File, uint16_t N, PROTOTYPE *Proto) {
273313
WriteNFloats (File, N, Proto->Variance.Elliptical);
274314
}
275315
}
276-
277-
/**
278-
* This routine writes a text representation of N floats from
279-
* an array to a file. All of the floats are placed on one line.
280-
* @param File open text file to write N floats to
281-
* @param N number of floats to write
282-
* @param Array array of floats to write
283-
* @return None
284-
* @note Globals: None
285-
*/
286-
void WriteNFloats(FILE * File, uint16_t N, float Array[]) {
287-
for (int i = 0; i < N; i++)
288-
fprintf(File, " %9.6f", Array[i]);
289-
fprintf(File, "\n");
290-
}
291-
292-
/**
293-
* This routine writes to the specified text file a word
294-
* which represents the ProtoStyle. It does not append
295-
* a carriage return to the end.
296-
* @param File open text file to write prototype style to
297-
* @param ProtoStyle prototype style to write
298-
* @return None
299-
* @note Globals: None
300-
*/
301-
void WriteProtoStyle(FILE *File, PROTOSTYLE ProtoStyle) {
302-
switch (ProtoStyle) {
303-
case spherical:
304-
fprintf (File, "spherical");
305-
break;
306-
case elliptical:
307-
fprintf (File, "elliptical");
308-
break;
309-
case mixed:
310-
fprintf (File, "mixed");
311-
break;
312-
case automatic:
313-
fprintf (File, "automatic");
314-
break;
315-
}
316-
}
317-
318-
/**
319-
* This routine writes a textual description of each prototype
320-
* in the prototype list to the specified file. It also
321-
* writes a file header which includes the number of dimensions
322-
* in feature space and the descriptions for each dimension.
323-
* @param File open text file to write prototypes to
324-
* @param N number of dimensions in feature space
325-
* @param ParamDesc descriptions for each dimension
326-
* @param ProtoList list of prototypes to be written
327-
* @param WriteSigProtos true to write out significant prototypes
328-
* @param WriteInsigProtos true to write out insignificants
329-
* @note Globals: None
330-
* @return None
331-
*/
332-
333-
void WriteProtoList(FILE* File, uint16_t N, PARAM_DESC* ParamDesc,
334-
LIST ProtoList, bool WriteSigProtos,
335-
bool WriteInsigProtos) {
336-
PROTOTYPE *Proto;
337-
338-
/* write file header */
339-
fprintf(File,"%0d\n",N);
340-
WriteParamDesc(File,N,ParamDesc);
341-
342-
/* write prototypes */
343-
iterate(ProtoList)
344-
{
345-
Proto = reinterpret_cast<PROTOTYPE *>first_node (ProtoList);
346-
if ((Proto->Significant && WriteSigProtos) ||
347-
(!Proto->Significant && WriteInsigProtos))
348-
WritePrototype(File, N, Proto);
349-
}
350-
}

src/classify/clusttool.h

-10
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,8 @@ PARAM_DESC *ReadParamDesc(tesseract::TFile *fp, uint16_t N);
3232

3333
PROTOTYPE *ReadPrototype(tesseract::TFile *fp, uint16_t N);
3434

35-
float *ReadNFloats(tesseract::TFile *fp, uint16_t N, float Buffer[]);
36-
3735
void WriteParamDesc(FILE *File, uint16_t N, const PARAM_DESC ParamDesc[]);
3836

3937
void WritePrototype(FILE *File, uint16_t N, PROTOTYPE *Proto);
4038

41-
void WriteNFloats (FILE * File, uint16_t N, float Array[]);
42-
43-
void WriteProtoStyle(FILE *File, PROTOSTYLE ProtoStyle);
44-
45-
void WriteProtoList(FILE* File, uint16_t N, PARAM_DESC* ParamDesc,
46-
LIST ProtoList, bool WriteSigProtos,
47-
bool WriteInsigProtos);
48-
4939
#endif // TESSERACT_CLASSIFY_CLUSTTOOL_H_

0 commit comments

Comments
 (0)