Skip to content

Commit

Permalink
fixing aecpack bug and adding test
Browse files Browse the repository at this point in the history
  • Loading branch information
AlysonStahl-NOAA committed Sep 20, 2024
1 parent 3109202 commit dc1c83a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/aecpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,15 @@ aecpack_int(void *fld, int fld_is_double, g2int width, g2int height, g2int *idrs
ctemplen = ndpts*nbytes;
sbits(ctemp, ifld, 0, nbytes*8, 0, ndpts);

ret = enc_aec(ctemp, ctemplen, nbits, ccsds_flags, ccsds_block_size, ccsds_rsi, cpack, lcpack);
if (ret < 0)
*lcpack = enc_aec(ctemp, ctemplen, nbits, ccsds_flags, ccsds_block_size, ccsds_rsi, cpack, lcpack);
if (*lcpack < 0)
{
if (verbose) printf("aecpack: ERROR Packing AEC = %d\n",ret);
nbits = 0;
*lcpack = 0;
ret = G2C_EAEC;
}

*lcpack = ret;
free(ctemp);
}
else
Expand Down
29 changes: 29 additions & 0 deletions tests/tst_aec.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,35 @@ main()
}
}
printf("ok!\n");
printf("Testing g2c_aecpackd()/g2c_aecunpackd() calls with data...");
{
size_t height = 2, width = 2;
size_t ndpts = DATA_LEN, len = PACKED_LEN;
double fld[DATA_LEN] = {1.0, 2.0, 3.0, 4.0};
double fld_in[DATA_LEN];
unsigned char cpack[PACKED_LEN];
size_t lcpack;
g2int idrstmpl[8] = {0, 1, 1, 0, 0, 0, 16, 128};
int i, ret;

idrstmpl[5] = CCSDS_FLAGS;

/* Pack the data. */
g2c_aecpackd(fld, width, height, (int *)idrstmpl, cpack, &lcpack);

/* Unpack the data. */
ret = g2c_aecunpackd(cpack, len, (int *)idrstmpl, ndpts, fld_in);
if (ret < 0)
return G2C_ERROR;

for (i = 0; i < DATA_LEN; i++)
{
/* printf("%g %g\n", fld[i], fld_in[i]); */
if (fld[i] != fld_in[i])
return G2C_ERROR;
}
}
printf("ok!\n");
printf("SUCCESS!\n");
return 0;
}

0 comments on commit dc1c83a

Please sign in to comment.