-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommand2.cpp
More file actions
181 lines (140 loc) · 5.39 KB
/
Command2.cpp
File metadata and controls
181 lines (140 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include <iostream>
#include <fstream>
#include <sstream>
#include <unistd.h>
using namespace std;
void oneDimensionalTransform(int[],stringstream[]); // Will be called if you are performing one dimensional Fourier Transforms
void twoDimensionalTransform(int[],stringstream[]); // Will be called if you are performing two dimensional Fourier Transforms
void fftTransform(int); // This function will perform the majority of the work with preparing the command line.
void instructions(); // Will display instructions about what the program is asking for.
int main()
{
int choice = 0; // Will allow you to choose which transform to perform
while (choice != 4) // This will be the main menu loop
{
cout << "Fast Fourier Transform Assistant" << endl << endl;
cout << "1. One dimensional Fast Fourier transforms." << endl;
cout << "2. Two dimensional Fast Fourier transforms." << endl;
cout << "3. Instructions" << endl;
cout << "4. Quit" << endl;
cout << "Please make a choice (1 - 4): ";
cin >> choice;
switch (choice)
{
case 1: // One dimensional transform
case 2: // Two dimensional transform
{
fftTransform(choice);
break;
}
case 3: // Call up the instructions
{
instructions();
break;
}
case 4: //Quit
{
cout << "Thank you for using this assistant. Have a nice day." << endl;
break;
}
default: //Invalid choice
cout << "That is not a valid option, please make a choice 1 - 3." << endl << endl;
break;
}
}
return 0;
}
void instructions ()
{
cout << "The following is an example of the input format: " << endl << endl
<< "One Dimensional Fourier Transforms: \n"
<< "\t c2c X1 X2 X3 X4 \n"
<< "Where c2c is the FFT_Type, X1 is the number of fft's, \n"
<< "X2 is the number of SPU's to use, X3 is the size of the fft's, \n"
<< "and X4 is the hugepage_flag." << endl << endl;
cout << "Two Dimensional Fourier Transforms: \n"
<< "\t c2c X1 X2 X3 X4 X5 X6 X7 X8 X9 \n"
<< "Where c2c is once again the FFT_Type, and the X1-X9 variables \n"
<< "correspond to other numeric parameters of the transform." << endl << endl;
return;
}
void fftTransform (int choice)
{
string charParameter; // Will hold the character parameter (such as 'c2c')
string command; // This string will contain the command line.
string outputFilePrefix, outFileName; // These will hold the prefix and the output file name.
std::stringstream convert[8]; // Array for converting the integers array into strings for use in the command line.
const char *sendCommand; // Will contain the command line as a sequence of characters in a c-style string.
char exit; // Will allow you to nicely exit the program.
int numericVariables[8]; // Holds the numeric parameters of the FFT.
cout << "Please enter today's date (no /'s or \'s please!): ";
cin >> outputFilePrefix;
cout << "Please enter the type of Fourier Transform to be performed (i.e. c2c): ";
cin >> charParameter;
switch (choice)
{
case 1:
{
oneDimensionalTransform(numericVariables,convert); // Set up the parameters for the one dimensional FFT
command += "./FFT1D_sample " + charParameter + " ";
for (int i = 0; i < 4; i++) // Add numeric parameters to the command line.
command += convert[i].str() + " ";
break;
}
case 2:
{
twoDimensionalTransform(numericVariables,convert); // Set up the parameters for the two dimensional FFT
command += "./FFT2D_sample " + charParameter + " ";
for (int i = 0; i < 8; i++) // Add numeric parameters to the command line.
command += convert[i].str() + " ";
break;
}
}
command += "| tee " + outFileName + ".txt"; // This will cause the output to be put in the file you have specified.
sendCommand = command.c_str(); // Create the character string to be used in the actual system call.
cout << "The send command is equal to " << sendCommand << endl; //Check to make sure the command was assembled correctly.
while (true) // Run the command in a loop until the program is killed manually (going to fix this eventually)
{
system(sendCommand);
sleep(1); //Pause one second between loops.
}
return;
}
void oneDimensionalTransform(int number[], stringstream conv[])
{
for (int i = 0; i < 4; i++) //Loop will get all of the numeric parameters from the user (instead of using a bunch of cout-cin pairs).
{
cout << "Please enter the ";
if (i == 0)
cout << "number of FFT's: ";
else
if (i == 1)
cout << "SPU's to use: ";
else
if (i == 2)
cout << "size of the FFT's: ";
else
if (i == 3)
cout << "hugepage_flag: ";
cin >> number[i];
conv[i] << number[i]; //Convert all of the integer parameters into string streams, convert them to strings and add them to the command variable.
}
return;
}
void twoDimensionalTransform (int number[], stringstream conv[])
{
for (int i = 0; i < 8; i++) //Loop will get all of the numeric parameters from the user (instead of using a bunch of cout-cin pairs).
{
cout << "Please enter the ";
if (i == 0)
cout << "second parameter: ";
else
if (i == 1)
cout << "third parameter: ";
else
cout << (i+1) << "th parameter: "; // Works for up to the eighth parameter.
cin >> number[i];
conv[i] << number[i]; //Convert all of the integer parameters into string streams, convert them to strings and add them to the command variable.
}
return;
}