---
name: "aecpack.c"
section: "3"
platform: "linux"
package: "libg2c-dev"
version: "2.1.0-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/aecpack.c"
---

# aecpack.c(3)

Pack array of float/double using AEC/CCSDS compression.

## NAME

aecpack.c - Pack array of float/double using AEC/CCSDS compression.

## SYNOPSIS

`#include 'grib2_int.h'`\
 `#include <libaec.h>`\
 `#include <math.h>`\
 `#include <stdint.h>`\
 `#include <stdlib.h>`\

### Functions

void **aecpack** (float \*fld, **g2int** width, **g2int** height, **g2int** \*idrstmpl, unsigned char \*cpack, **g2int** \*lcpack)\
 This function packs up a float array into a AEC code stream.  static int **aecpack\_int** (void \*fld, int fld\_is\_double, **g2int** width, **g2int** height, **g2int** \*idrstmpl, unsigned char \*cpack, **g2int** \*lcpack, int verbose)\
 Pack a float or double array into a AEC/CCSDS code stream.  int **g2c\_aecpackd** (double \*fld, size\_t width, size\_t height, int \*idrstmpl, unsigned char \*cpack, size\_t \*lcpack)\
 This function packs up a double array into a AEC code stream.  int **g2c\_aecpackf** (float \*fld, size\_t width, size\_t height, int \*idrstmpl, unsigned char \*cpack, size\_t \*lcpack)\
 This function packs up a float array into a AEC code stream.

## Detailed Description

Pack array of float/double using AEC/CCSDS compression.

**Author**

Eric Engle

**Date**

2023-09-10

### Program History Log

Date   Programmer   Comments    2023-09-10   Engle   Initial; Adapted from **aecpack.c**.    2023-10-16   Engle   Added include libaec to set default values   for CCSDS parameters.

Definition in file **aecpack.c**.

## Function Documentation

### void aecpack (float \* fld, g2int width, g2int height, g2int \* idrstmpl, unsigned char \* cpack, g2int \* lcpack)

This function packs up a float array into a AEC code stream. After the data are scaled, and the reference value is subtracted out, the data are passed to the AEC encoder.

This function also fills in GRIB2 Data Representation Template 5.42 with the appropriate values.

**Parameters**

*fld* Pointer to the float data values to pack. \
 *width* The number of points in the x direction. \
 *height* The number of points in the y direction. \
 *idrstmpl* Contains the array of values for Data Representation Template `Table 5.42`.

- •

  0 Reference value - ignored on input, set by aecpack routine.

- •

  1 Binary Scale Factor - used on input, unchanged by aecpack routine.

- •

  2 Decimal Scale Factor - used on input, unchanged by aecpack routine.

- •

  3 number of bits for each data value - ignored on input

- •

  4 Original field type - currently ignored on input Data values assumed to be reals. Set to 0 on output.

- •

  5 CCSDS compression options mask.

- •

  6 Block size.

- •

  7 Reference sample interval. May be modified in this function.

*cpack* A pointer that will get the packed data field. Must be allocated before this function is called. Pass the allocated size in the lcpack parameter. \
 *lcpack* Pointer that gets the length of packed field in cpack. This must be set by the calling function to the size available in cpack.

**Author**

Eric Engle (adapted from jpcpack)

Definition at line **297** of file **aecpack.c**.

References **aecpack\_int()**.

Referenced by **g2\_addfield()**.

### static int aecpack\_int (void \* fld, int fld\_is\_double, g2int width, g2int height, g2int \* idrstmpl, unsigned char \* cpack, g2int \* lcpack, int verbose)` [static]`

Pack a float or double array into a AEC/CCSDS code stream.

**Parameters**

*fld* Pointer to the float or double data values to pack. \
 *fld\_is\_double* If non-zero, then fld points to array of doubles, otherwise an array of floats. \
 *width* The number of points in the x direction. \
 *height* The number of points in the y direction. \
 *idrstmpl* Contains the array of values for Data Representation Template `Table 5.42`. May be modified in this function. \
 *cpack* A pointer that will get the packed data field. Must be allocated before this function is called. Pass the allocated size in the lcpack parameter. \
 *lcpack* Pointer that gets the length of packed field in cpack. This must also be set by the calling function to the size available in cpack. \
 *verbose* If non-zero, error messages will be printed in case of error. Otherwise, error codes will be return but no error messages printed. Calls to the original g2c API may cause error messages to be printed in case of error. For the new g2c\_ API, no error messages will be printed - instead an error code will be returned. Call **g2c\_strerror()** to get the error message for any error code.

**Returns**

- •

  **G2C\_NOERROR** No error.

- •

  **G2C\_EAEC** Error encoding/decoding AEC data.

**Author**

Eric Engle

Definition at line **52** of file **aecpack.c**.

References **ALOG2**, **enc\_aec()**, **G2C\_EAEC**, **G2C\_NOERROR**, **int\_power()**, **LOG**, **mkieee()**, and **sbits()**.

Referenced by **aecpack()**, **g2c\_aecpackd()**, and **g2c\_aecpackf()**.

### int g2c\_aecpackd (double \* fld, size\_t width, size\_t height, int \* idrstmpl, unsigned char \* cpack, size\_t \* lcpack)

This function packs up a double array into a AEC code stream. After the data are scaled, and the reference value is subtracted out, the data are passed to the AEC encoder.

This function also fills in GRIB2 Data Representation Template 5.42 with the appropriate values.

This function is the V2 API version of **aecpack()** for floats.

**Parameters**

*fld* Pointer to the float data values to pack. \
 *width* The number of points in the x direction. \
 *height* The number of points in the y direction. \
 *idrstmpl* Contains the array of values for Data Representation Template `Table 5.42`.

- •

  0 Reference value - ignored on input, set by aecpack routine.

- •

  1 Binary Scale Factor - used on input, unchanged by aecpack routine.

- •

  2 Decimal Scale Factor - used on input, unchanged by aecpack routine.

- •

  3 number of bits for each data value - ignored on input

- •

  4 Original field type - currently ignored on input Data values assumed to be reals. Set to 0 on output.

- •

  5 CCSDS compression options mask.

- •

  6 Block size.

- •

  7 Reference sample interval. May be modified in this function.

*cpack* A pointer that will get the packed data field. Must be allocated before this function is called. Pass the allocated size in the lcpack parameter. \
 *lcpack* Pointer that gets the length of packed field in cpack. This must be set by the calling function to the size available in cpack.

**Returns**

- •

  **G2C\_NOERROR** No error.

- •

  **G2C\_EAEC** Error encoding/decoding AEC data.

**Author**

Eric Engle (adapted from jpcpack)

Definition at line **410** of file **aecpack.c**.

References **aecpack\_int()**, and **G2C\_AEC\_DRS\_TEMPLATE\_LEN**.

### int g2c\_aecpackf (float \* fld, size\_t width, size\_t height, int \* idrstmpl, unsigned char \* cpack, size\_t \* lcpack)

This function packs up a float array into a AEC code stream. After the data are scaled, and the reference value is subtracted out, the data are passed to the AEC encoder.

This function also fills in GRIB2 Data Representation Template 5.42 with the appropriate values.

This function is the V2 API version of **aecpack()** for floats.

**Parameters**

*fld* Pointer to the float data values to pack. \
 *width* The number of points in the x direction. \
 *height* The number of points in the y direction. \
 *idrstmpl* Contains the array of values for Data Representation Template `Table 5.42`.

- •

  0 Reference value - ignored on input, set by aecpack routine.

- •

  1 Binary Scale Factor - used on input, unchanged by aecpack routine.

- •

  2 Decimal Scale Factor - used on input, unchanged by aecpack routine.

- •

  3 number of bits for each data value - ignored on input

- •

  4 Original field type - currently ignored on input Data values assumed to be reals. Set to 0 on output.

- •

  5 CCSDS compression options mask.

- •

  6 Block size.

- •

  7 Reference sample interval. May be modified in this function.

*cpack* A pointer that will get the packed data field. Must be allocated before this function is called. Pass the allocated size in the lcpack parameter. \
 *lcpack* Pointer that gets the length of packed field in cpack. This must be set by the calling function to the size available in cpack.

**Returns**

- •

  **G2C\_NOERROR** No error.

- •

  **G2C\_EAEC** Error encoding/decoding AEC data.

**Author**

Eric Engle (adapted from jpcpack)

Definition at line **346** of file **aecpack.c**.

References **aecpack\_int()**, and **G2C\_AEC\_DRS\_TEMPLATE\_LEN**.

## Author

Generated automatically by Doxygen for NCEPLIBS-g2c from the source code.
