#include #include #include #include #include #include using namespace std; char *generate_output_filename (char *filename); void copy_file (ifstream &input_file, ofstream &output_file, int file_length); int main() { double BER; char RS, MPE_FEC; char *input_filename = new char[300]; cout << "Enter filename (file must be in the same directory as exe): "; cin >> input_filename; cout << "Enter BER (e.g for a BER of 10^-6 enter 1e-6): "; cin >> BER; cout << "Using RS coding (y/n)?: "; cin >> RS; //cout << "Using MPE-FEC (y/n) (can't use both RS and MPE-FEC at same time)?: "; //cin >> MPE_FEC; MPE_FEC = 'n'; int NUM_RS_CORRECTABLE_BYTES = 5; int RS_CODEWORD_LENGTH = 110; if (MPE_FEC == 'y') { NUM_RS_CORRECTABLE_BYTES = 64; RS_CODEWORD_LENGTH = 255; } char *output_filename = generate_output_filename (input_filename); ifstream input_file(input_filename, ios::binary); if (!input_file) { cerr << "Input file could not be opened" << endl; exit(1); } ofstream output_file(output_filename, ios::binary); if (!output_file) { cerr << "Output file could not be opened" << endl; exit(1); } ofstream data_file("changes made.txt", ios::out); if (!data_file) { cerr << "Data file could not be opened" << endl; exit(1); } input_file.seekg (0, ios::end); int file_length = input_file.tellg(); input_file.seekg (0, ios::beg); cout << "File length = " << file_length << endl; copy_file (input_file, output_file, file_length); int i; int num_errors = (int)(file_length * 8 * BER); unsigned long *byte_number; byte_number = new unsigned long[num_errors]; int number_rs_packets = file_length / RS_CODEWORD_LENGTH; unsigned long *rs_packet; rs_packet = new unsigned long [number_rs_packets]; for (i=0; i> c; return 0; } char *generate_output_filename (char *filename) { int length = strlen(filename); char *output_filename = new char[length+3]; int pos = (int)strchr(filename, '.') - (int)filename; strncpy(output_filename, filename, pos); output_filename[pos] = '\0'; strcat(output_filename, "_01"); strcat(output_filename, strchr(filename, '.')); return output_filename; } void copy_file (ifstream &input_file, ofstream &output_file, int file_length) { int i; const int RW_BUFFER_SIZE = 2048; char *rw_buf = new char[RW_BUFFER_SIZE]; unsigned int num_read_cycles = file_length / RW_BUFFER_SIZE; for (i=0; i