19 #define _USE_MATH_DEFINES // for M_PI
30 #define QUOTED_TOKENSIZE "79"
31 #define MAXSAMPLESIZE 65535
45 static float *ReadNFloats(
TFile *fp, uint16_t N,
float Buffer[]) {
46 const int kMaxLineSize = 1024;
47 char line[kMaxLineSize];
48 if (fp->
FGets(line, kMaxLineSize) ==
nullptr) {
49 tprintf(
"Hit EOF in ReadNFloats!\n");
52 bool needs_free =
false;
54 if (Buffer ==
nullptr) {
55 Buffer = static_cast<float *>(
Emalloc(N *
sizeof(
float)));
59 std::stringstream stream(line);
61 stream.imbue(std::locale::classic());
62 for (uint16_t i = 0; i < N; i++) {
66 tprintf(
"Read of %u floats failed!\n", N);
67 if (needs_free)
Efree(Buffer);
82 static void WriteNFloats(FILE * File, uint16_t N,
float Array[]) {
83 for (
int i = 0; i < N; i++)
84 fprintf(File,
" %9.6f", Array[i]);
95 static void WriteProtoStyle(FILE *File,
PROTOSTYLE ProtoStyle) {
98 fprintf (File,
"spherical");
101 fprintf (File,
"elliptical");
104 fprintf (File,
"mixed");
107 fprintf (File,
"automatic");
123 const int kMaxLineSize = 100;
124 char line[kMaxLineSize];
144 for (
int i = 0; i < N; i++) {
146 char line[kMaxLineSize];
148 std::istringstream stream(line);
150 stream.imbue(std::locale::classic());
152 stream >> linear_token;
154 stream >> essential_token;
155 stream >> ParamDesc[i].
Min;
156 stream >> ParamDesc[i].
Max;
158 ParamDesc[i].
Circular = (linear_token[0] ==
'c');
159 ParamDesc[i].
NonEssential = (essential_token[0] !=
'e');
160 ParamDesc[i].
Range = ParamDesc[i].
Max - ParamDesc[i].
Min;
162 ParamDesc[i].
MidRange = (ParamDesc[i].
Max + ParamDesc[i].
Min) / 2;
183 char line[kMaxLineSize];
184 if (fp->
FGets(line, kMaxLineSize) ==
nullptr ||
186 sig_token, shape_token, &SampleCount) != 3) {
187 tprintf(
"Invalid prototype: %s\n", line);
194 switch (shape_token[0]) {
205 tprintf(
"Invalid prototype style specification:%s\n", shape_token);
212 Proto->
Mean = ReadNFloats(fp, N,
nullptr);
215 switch (Proto->
Style) {
231 for (i = 0; i < N; i++) {
242 tprintf(
"Invalid prototype style\n");
258 for (i = 0; i < N; i++) {
259 if (ParamDesc[i].Circular)
260 fprintf (File,
"circular ");
262 fprintf (File,
"linear ");
264 if (ParamDesc[i].NonEssential)
265 fprintf (File,
"non-essential ");
267 fprintf (File,
"essential ");
269 fprintf (File,
"%10.6f %10.6f\n", ParamDesc[i].Min, ParamDesc[i].Max);
284 fprintf (File,
"significant ");
286 fprintf (File,
"insignificant ");
287 WriteProtoStyle (File, static_cast<PROTOSTYLE>(Proto->
Style));
289 WriteNFloats (File, N, Proto->
Mean);
290 fprintf (File,
"\t");
292 switch (Proto->
Style) {
300 for (i = 0; i < N; i++)
303 fprintf (File,
" %9s",
"normal");
306 fprintf (File,
" %9s",
"uniform");
309 fprintf (File,
" %9s",
"random");
314 fprintf (File,
"\n\t");