Skip to content

Commit

Permalink
Merge branch 'develop' into as_aecpack
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardhartnett authored Sep 22, 2024
2 parents dc1c83a + 4fd42a5 commit 95d07a7
Show file tree
Hide file tree
Showing 110 changed files with 3,456 additions and 3,302 deletions.
21 changes: 21 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
Language: Cpp
AlignAfterOpenBracket: Align
AlwaysBreakAfterDefinitionReturnType: true
BraceWrapping:
AfterControlStatement: true
AfterFunction: true
AfterStruct: true
AfterUnion: true
BeforeElse: true
IndentBraces: false
BreakBeforeBraces: Custom
BreakStringLiterals: false
ColumnLimit: 0
IndentWidth: 4
ReflowComments: false
TabWidth: 4
UseCRLF: false
UseTab: Never
...

2 changes: 1 addition & 1 deletion src/CodeFlag.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,7 @@ Code table 4.2 - Parameter number by product discipline and parameter category,"
Code table 4.2 - Parameter number by product discipline and parameter category,"Product discipline 10 - Oceanographic products, parameter category 2: ice",23,,Sea ice fraction tendency due to parameterization,,,s-1,Operational
Code table 4.2 - Parameter number by product discipline and parameter category,"Product discipline 10 - Oceanographic products, parameter category 2: ice",24,,x-component of ice drift,,,m s-1,Operational
Code table 4.2 - Parameter number by product discipline and parameter category,"Product discipline 10 - Oceanographic products, parameter category 2: ice",25,,y-component of ice drift,,,m s-1,Operational
Code table 4.2 - Parameter number by product discipline and parameter category,"Product discipline 10 - Oceanographic products, parameter category 2: ice",26,,Sea ice salinity,,,g kg-1,operational
Code table 4.2 - Parameter number by product discipline and parameter category,"Product discipline 10 - Oceanographic products, parameter category 2: ice",26,,Sea ice salinity,,,g kg-1,operational
Code table 4.2 - Parameter number by product discipline and parameter category,"Product discipline 10 - Oceanographic products, parameter category 2: ice",27,,Freezing/melting potential,,,W m-2,Operational
Code table 4.2 - Parameter number by product discipline and parameter category,"Product discipline 10 - Oceanographic products, parameter category 2: ice",28,,Melt onset date,(see Note 2),144,Numeric,Operational
Code table 4.2 - Parameter number by product discipline and parameter category,"Product discipline 10 - Oceanographic products, parameter category 2: ice",29,,Freeze onset date,(see Note 3),145,Numeric,Operational
Expand Down
4 changes: 2 additions & 2 deletions src/Template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2236,7 +2236,7 @@ Product definition template 4.87 - quantile forecasts at a horizontal level or i
Product definition template 4.87 - quantile forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval,29,Type of second fixed surface,(see Code table 4.5),,4.5,,Operational
Product definition template 4.87 - quantile forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval,30,Scale factor of second fixed surface,,,,,Operational
Product definition template 4.87 - quantile forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval,31-34,Scaled value of second fixed surface,,,,,Operational
Product definition template 4.87 - quantile forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval,35-36, Total number of quantiles q,,,,,Operational
Product definition template 4.87 - quantile forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval,35-36, Total number of quantiles q,,,,,Operational
Product definition template 4.87 - quantile forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval,37-38, Quantile value (between 0 and q),,,,,Operational
Product definition template 4.87 - quantile forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval,39-40,Year of end of overall time interval,,,,,Operational
Product definition template 4.87 - quantile forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval,41,Month of end of overall time interval,,,,,Operational
Expand Down Expand Up @@ -2322,7 +2322,7 @@ Product definition template 4.90 - post-processed quantile forecasts at a horizo
Product definition template 4.90 - post-processed quantile forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval,34,Type of second fixed surface,(see Code table 4.5),,4.5,,Operational
Product definition template 4.90 - post-processed quantile forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval,35,Scale factor of second fixed surface,,,,,Operational
Product definition template 4.90 - post-processed quantile forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval,36-39,Scaled value of second fixed surface,,,,,Operational
Product definition template 4.90 - post-processed quantile forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval,40-41, Total number of quantiles (q),,,,,Operational
Product definition template 4.90 - post-processed quantile forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval,40-41, Total number of quantiles (q),,,,,Operational
Product definition template 4.90 - post-processed quantile forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval,42-43, Quantile value (between 0 and q),,,,,Operational
Product definition template 4.90 - post-processed quantile forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval,44-45,Year of end of overall time interval,,,,,Operational
Product definition template 4.90 - post-processed quantile forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval,46,Month of end of overall time interval,,,,,Operational
Expand Down
23 changes: 12 additions & 11 deletions src/aecpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
* for CCSDS parameters.
*/

#include "grib2_int.h"
#include <libaec.h>
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
#include <libaec.h>
#include "grib2_int.h"

/**
* Pack a float or double array into a AEC/CCSDS code stream.
Expand Down Expand Up @@ -140,13 +140,13 @@ aecpack_int(void *fld, int fld_is_double, g2int width, g2int height, g2int *idrs
if (fld_is_double)
{
rmind = (float)imin;
for(j = 0; j < ndpts; j++)
for (j = 0; j < ndpts; j++)
ifld[j] = (g2int)rint(dfld[j] * dscale) - imin;
}
else
{
rmin = (float)imin;
for(j = 0; j < ndpts; j++)
for (j = 0; j < ndpts; j++)
ifld[j] = (g2int)rint(ffld[j] * dscale) - imin;
}
}
Expand Down Expand Up @@ -184,12 +184,12 @@ aecpack_int(void *fld, int fld_is_double, g2int width, g2int height, g2int *idrs
/* Define AEC compression options */
if (idrstmpl[3] <= 0)
{
nbits = pow(2, ceil(log(nbits)/log(2))); // Round to nearest base 2 int
nbits = pow(2, ceil(log(nbits) / log(2))); // Round to nearest base 2 int
}
else
{
nbits = idrstmpl[3];
nbits = pow(2, ceil(log(nbits)/log(2))); // Round to nearest base 2 int
nbits = pow(2, ceil(log(nbits) / log(2))); // Round to nearest base 2 int
}
nbits = nbits < 8 ? 8 : nbits;

Expand Down Expand Up @@ -222,13 +222,14 @@ aecpack_int(void *fld, int fld_is_double, g2int width, g2int height, g2int *idrs
* calculate the length of the packed data in bytes. */
nbytes = (nbits + 7) / 8;
ctemp = calloc(ndpts, nbytes);
ctemplen = ndpts*nbytes;
sbits(ctemp, ifld, 0, nbytes*8, 0, ndpts);
ctemplen = ndpts * nbytes;
sbits(ctemp, ifld, 0, nbytes * 8, 0, ndpts);

*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);
if (verbose)
printf("aecpack: ERROR Packing AEC = %d\n", ret);
nbits = 0;
*lcpack = 0;
ret = G2C_EAEC;
Expand All @@ -245,7 +246,7 @@ aecpack_int(void *fld, int fld_is_double, g2int width, g2int height, g2int *idrs
/* Fill in values for template 5.42. */
if (fld_is_double)
rmin = (float)rmind;
mkieee(&rmin, idrstmpl, 1); /* ensure reference value is IEEE format. */
mkieee(&rmin, idrstmpl, 1); /* ensure reference value is IEEE format. */
idrstmpl[3] = nbits;
idrstmpl[5] = ccsds_flags;
idrstmpl[6] = ccsds_block_size;
Expand Down
26 changes: 13 additions & 13 deletions src/aecunpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* stream
* @author Eric Engle @date 2023-10-16
*/
#include "grib2_int.h"
#include <stdio.h>
#include <stdlib.h>
#include "grib2_int.h"

/**
* Unpack AEC compressed data into an
Expand Down Expand Up @@ -41,10 +41,10 @@
*/
static int
aecunpack_int(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts,
void *fld, int fld_is_double, int verbose)
void *fld, int fld_is_double, int verbose)
{
g2int *ifld;
g2int j, ctemplen = 0 , nbits;
g2int j, ctemplen = 0, nbits;
g2int ccsds_flags, ccsds_block_size, ccsds_rsi;
//g2int ifld1 = 0;
int ret = 0;
Expand Down Expand Up @@ -78,11 +78,11 @@ aecunpack_int(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts,

/* Determine the number of bytes needed for each value, then allocate the
* buffer for the decoded AEC stream. */
nbytes = (nbits + 7)/8;
nbytes = (nbits + 7) / 8;
if (nbytes == 3)
nbytes = 4;
ctemplen = nbytes * ndpts;
if ((ctemp = (unsigned char *) malloc(ctemplen)) == NULL)
if ((ctemp = (unsigned char *)malloc(ctemplen)) == NULL)
{
if (verbose)
fprintf(stderr, "Allocation error.\n");
Expand All @@ -96,7 +96,7 @@ aecunpack_int(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts,

/* IMPORTANT: The decoded AEC stream is byte-aligned (not bit), so when extracting the data
* values from the buffer via gbits, we need to pass the byte size in bits, not nbits. */
gbits(ctemp, ifld, 0, nbytes*8, 0, ndpts);
gbits(ctemp, ifld, 0, nbytes * 8, 0, ndpts);

/* Zero out all higher-order bits, preserving nbits. NOTE: This might be unecessary. */
//for (j = 0; j < ndpts; j++)
Expand All @@ -109,7 +109,7 @@ aecunpack_int(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts,
if (fld_is_double)
{
for (j = 0; j < ndpts; j++)
dfld[j] = (((float)ifld[j] * bscale) + ref) * dscale;
dfld[j] = (((float)ifld[j] * bscale) + ref) * dscale;
}
else
{
Expand Down Expand Up @@ -162,7 +162,7 @@ aecunpack(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts,
float *fld)
{
int ret;

LOG((2, "g2c_aecunpack len %lld ndpts %lld", len, ndpts));

ret = aecunpack_int(cpack, len, idrstmpl, ndpts, fld, 0, 1);
Expand Down Expand Up @@ -199,10 +199,10 @@ g2c_aecunpackf(unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts,
int i;

LOG((2, "g2c_aecunpackf len %d ndpts %lld", len, ndpts));

for (i = 0; i < G2C_AEC_DRS_TEMPLATE_LEN; i++)
idrstmpl8[i] = idrstmpl[i];

return aecunpack_int(cpack, len8, idrstmpl8, ndpts8, fld, 0, 0);
}

Expand Down Expand Up @@ -235,11 +235,11 @@ g2c_aecunpackd(unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts,
g2int idrstmpl8[G2C_AEC_DRS_TEMPLATE_LEN];
g2int len8 = len, ndpts8 = ndpts;
int i;

LOG((2, "g2c_aecunpackd len %lld ndpts %lld", len, ndpts));

for (i = 0; i < G2C_AEC_DRS_TEMPLATE_LEN; i++)
idrstmpl8[i] = idrstmpl[i];

return aecunpack_int(cpack, len8, idrstmpl8, ndpts8, fld, 1, 0);
}
7 changes: 3 additions & 4 deletions src/cmplxpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/**
* Pack up a data field using a complex packing
* algorithm.
* algorithm.
*
* This function supports GRIB2
* complex packing templates with or without spatial differences
Expand Down Expand Up @@ -37,14 +37,13 @@ void
cmplxpack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl,
unsigned char *cpack, g2int *lcpack)
{
if (idrstmpl[6] == 0) /* No internal missing values */
if (idrstmpl[6] == 0) /* No internal missing values */
compack(fld, ndpts, idrsnum, idrstmpl, cpack, lcpack);
else if (idrstmpl[6] == 1 || idrstmpl[6] == 2)
else if (idrstmpl[6] == 1 || idrstmpl[6] == 2)
misspack(fld, ndpts, idrsnum, idrstmpl, cpack, lcpack);
else
{
printf("cmplxpack: Don:t recognize Missing value option.");
*lcpack = -1;
}

}
Loading

0 comments on commit 95d07a7

Please sign in to comment.