aboutsummaryrefslogtreecommitdiff
path: root/src/cohpsk_put_test_bits.c
diff options
context:
space:
mode:
authordrowe67 <[email protected]>2023-07-20 08:59:48 +0930
committerGitHub <[email protected]>2023-07-20 08:59:48 +0930
commit06d4c11e699b0351765f10398abb4f663a984f36 (patch)
tree33e22af0814c5b6c3d676f096ae8c2ac8a3ed9f0 /src/cohpsk_put_test_bits.c
parent6588e77f38bdebd7adffe091b22e7760d95d0ccb (diff)
parent4d6c143c0abec15e1d6ed1fd95d36f80e6cb7df8 (diff)
Merge pull request #3 from drowe67/dr-cleanup21.2.0
Cleanup Part 2
Diffstat (limited to 'src/cohpsk_put_test_bits.c')
-rw-r--r--src/cohpsk_put_test_bits.c141
1 files changed, 70 insertions, 71 deletions
diff --git a/src/cohpsk_put_test_bits.c b/src/cohpsk_put_test_bits.c
index 69811a0..de41da2 100644
--- a/src/cohpsk_put_test_bits.c
+++ b/src/cohpsk_put_test_bits.c
@@ -10,7 +10,6 @@
\*---------------------------------------------------------------------------*/
-
/*
Copyright (C) 2015 David Rowe
@@ -29,85 +28,85 @@
*/
#include <assert.h>
+#include <errno.h>
+#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <math.h>
-#include <errno.h>
#include "codec2_cohpsk.h"
#include "octave.h"
#define LOG_FRAMES 100
-int main(int argc, char *argv[])
-{
- FILE *fin, *foct;
- char rx_bits[COHPSK_BITS_PER_FRAME];
- int state, i, nbits, bit_errors, nerrors;
- short error_pattern[COHPSK_BITS_PER_FRAME];
- int error_positions_hist[COHPSK_BITS_PER_FRAME], logframes;
- int nerr_log[LOG_FRAMES];
- struct COHPSK *coh;
-
- for(i=0; i<COHPSK_BITS_PER_FRAME; i++)
- error_positions_hist[i] = 0;
-
- if (argc < 2) {
- fprintf(stderr, "usage: %s InputOneCharPerBitFile [OctaveLogFile]\n", argv[0]);
- exit(1);
- }
-
- if (strcmp(argv[1], "-") == 0) fin = stdin;
- else if ( (fin = fopen(argv[1],"rb")) == NULL ) {
- fprintf(stderr, "Error opening input file: %s: %s.\n",
- argv[1], strerror(errno));
- exit(1);
- }
-
- coh = cohpsk_create();
-
- foct = NULL;
- logframes = 0;
- if (argc == 3) {
- if ( (foct = fopen(argv[2],"wt")) == NULL ) {
- fprintf(stderr, "Error opening output Octave file: %s: %s.\n",
- argv[2], strerror(errno));
- exit(1);
- }
- }
-
- for(i=0; i<COHPSK_BITS_PER_FRAME; i++)
- error_positions_hist[i] = 0;
-
- state = 0; nbits = 0; nerrors = 0;
- while (fread(rx_bits, sizeof(char), COHPSK_BITS_PER_FRAME, fin) == COHPSK_BITS_PER_FRAME) {
-
- cohpsk_put_test_bits(coh, &state, error_pattern, &bit_errors, rx_bits, 0);
- if (state == 1) {
- for(i=0; i<COHPSK_BITS_PER_FRAME; i++)
- error_positions_hist[i] += error_pattern[i];
- if (logframes < LOG_FRAMES)
- nerr_log[logframes++] = bit_errors;
- nerrors += bit_errors;
- nbits += COHPSK_BITS_PER_FRAME;
- }
+int main(int argc, char *argv[]) {
+ FILE *fin, *foct;
+ char rx_bits[COHPSK_BITS_PER_FRAME];
+ int state, i, nbits, bit_errors, nerrors;
+ short error_pattern[COHPSK_BITS_PER_FRAME];
+ int error_positions_hist[COHPSK_BITS_PER_FRAME], logframes;
+ int nerr_log[LOG_FRAMES];
+ struct COHPSK *coh;
+
+ for (i = 0; i < COHPSK_BITS_PER_FRAME; i++) error_positions_hist[i] = 0;
+
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s InputOneCharPerBitFile [OctaveLogFile]\n",
+ argv[0]);
+ exit(1);
+ }
+
+ if (strcmp(argv[1], "-") == 0)
+ fin = stdin;
+ else if ((fin = fopen(argv[1], "rb")) == NULL) {
+ fprintf(stderr, "Error opening input file: %s: %s.\n", argv[1],
+ strerror(errno));
+ exit(1);
+ }
+
+ coh = cohpsk_create();
+
+ foct = NULL;
+ logframes = 0;
+ if (argc == 3) {
+ if ((foct = fopen(argv[2], "wt")) == NULL) {
+ fprintf(stderr, "Error opening output Octave file: %s: %s.\n", argv[2],
+ strerror(errno));
+ exit(1);
}
-
- if (foct != NULL) {
- octave_save_int(foct, "nerr_log_c", nerr_log, 1, logframes);
- octave_save_int(foct, "error_positions_hist_c", error_positions_hist, 1, COHPSK_BITS_PER_FRAME);
- fclose(foct);
+ }
+
+ for (i = 0; i < COHPSK_BITS_PER_FRAME; i++) error_positions_hist[i] = 0;
+
+ state = 0;
+ nbits = 0;
+ nerrors = 0;
+ while (fread(rx_bits, sizeof(char), COHPSK_BITS_PER_FRAME, fin) ==
+ COHPSK_BITS_PER_FRAME) {
+ cohpsk_put_test_bits(coh, &state, error_pattern, &bit_errors, rx_bits, 0);
+ if (state == 1) {
+ for (i = 0; i < COHPSK_BITS_PER_FRAME; i++)
+ error_positions_hist[i] += error_pattern[i];
+ if (logframes < LOG_FRAMES) nerr_log[logframes++] = bit_errors;
+ nerrors += bit_errors;
+ nbits += COHPSK_BITS_PER_FRAME;
}
-
- fclose(fin);
- float ber = (float)nerrors/nbits;
- fprintf(stderr, "BER: %4.3f Nbits: %d Nerrors: %d\n", ber, nbits, nerrors);
-
- /* return code for Ctest - 0 for pass, 1 for fail, based on 2% BER */
- if (nbits && (ber < 0.02))
- return 0;
- else
- return 1;
+ }
+
+ if (foct != NULL) {
+ octave_save_int(foct, "nerr_log_c", nerr_log, 1, logframes);
+ octave_save_int(foct, "error_positions_hist_c", error_positions_hist, 1,
+ COHPSK_BITS_PER_FRAME);
+ fclose(foct);
+ }
+
+ fclose(fin);
+ float ber = (float)nerrors / nbits;
+ fprintf(stderr, "BER: %4.3f Nbits: %d Nerrors: %d\n", ber, nbits, nerrors);
+
+ /* return code for Ctest - 0 for pass, 1 for fail, based on 2% BER */
+ if (nbits && (ber < 0.02))
+ return 0;
+ else
+ return 1;
}
-