From 4fd42a5ad6ffa4ba26f6ae0cdc6502efd9680334 Mon Sep 17 00:00:00 2001 From: Dusan Jovic <48258889+DusanJovic-NOAA@users.noreply.github.com> Date: Sun, 22 Sep 2024 03:48:47 -0400 Subject: [PATCH] Add clang format (#513) * Add .clang-format * clang-format all source files in src directory * clang-format all source files in tests directory * Fix cmake placeholder in grib2.h.in --- .clang-format | 21 + src/CodeFlag.txt | 2 +- src/Template.txt | 4 +- src/aecpack.c | 23 +- src/aecunpack.c | 26 +- src/cmplxpack.c | 7 +- src/compack.c | 82 +-- src/comunpack.c | 67 +- src/decenc_aec.c | 46 +- src/decenc_jpeg2000.c | 23 +- src/decenc_openjpeg.c | 150 +++-- src/decenc_png.c | 11 +- src/drstemplates.c | 67 +- src/g2_addfield.c | 74 +-- src/g2_addgrid.c | 28 +- src/g2_addlocal.c | 14 +- src/g2_create.c | 18 +- src/g2_free.c | 2 +- src/g2_getfld.c | 44 +- src/g2_gribend.c | 13 +- src/g2_info.c | 26 +- src/g2_miss.c | 4 +- src/g2_unpack1.c | 6 +- src/g2_unpack2.c | 2 +- src/g2_unpack3.c | 22 +- src/g2_unpack4.c | 17 +- src/g2_unpack5.c | 12 +- src/g2_unpack6.c | 10 +- src/g2_unpack7.c | 31 +- src/g2ccompare.c | 15 +- src/g2ccsv.c | 268 ++++---- src/g2cdegrib2.c | 75 ++- src/g2cfile.c | 33 +- src/g2cindex.c | 285 ++++----- src/g2cinq.c | 11 +- src/g2cio.c | 30 +- src/g2cparams.c | 12 +- src/g2cprod.c | 44 +- src/g2cutil.c | 108 ++-- src/gbits.c | 27 +- src/getdim.c | 31 +- src/getpoly.c | 24 +- src/grib2.h.in | 77 ++- src/grib2_int.h | 150 ++--- src/gridtemplates.c | 150 +++-- src/int_power.c | 2 +- src/jpcpack.c | 186 +++--- src/jpcunpack.c | 62 +- src/misspack.c | 89 +-- src/mkieee.c | 26 +- src/pack_gp.c | 1094 ++++++++++++++++++-------------- src/pdstemplates.c | 273 ++++---- src/pngpack.c | 157 +++-- src/pngunpack.c | 52 +- src/rdieee.c | 26 +- src/reduce.c | 368 ++++++----- src/seekgb.c | 13 +- src/simpack.c | 48 +- src/simunpack.c | 6 +- src/specpack.c | 26 +- src/specunpack.c | 36 +- src/util.c | 17 +- tests/CMakeLists.txt | 14 +- tests/g2c_test_util.c | 7 +- tests/run_degrib2_tests.sh | 4 +- tests/run_extra_index_tests.sh | 2 +- tests/run_ftp_index_tests.sh | 4 +- tests/run_index_tests.sh | 4 +- tests/run_large_index_tests.sh | 4 +- tests/tst_addfield2.c | 43 +- tests/tst_addfield3.c | 55 +- tests/tst_addfield4.c | 55 +- tests/tst_addfield_spec.c | 4 +- tests/tst_aec.c | 48 +- tests/tst_aqm.c | 1 - tests/tst_com.c | 322 +++++----- tests/tst_csv.c | 21 +- tests/tst_decode.c | 35 +- tests/tst_degrib2_fast.c | 2 +- tests/tst_degrib2_ftp_all.c | 74 +-- tests/tst_degrib2_int.c | 40 +- tests/tst_drstemplates.c | 29 +- tests/tst_error.c | 59 +- tests/tst_files.c | 153 +++-- tests/tst_g2_addfield.c | 54 +- tests/tst_g2_addgrid.c | 37 +- tests/tst_g2_addlocal.c | 6 +- tests/tst_g2_create.c | 8 +- tests/tst_g2_testfile.c | 12 +- tests/tst_gbits.c | 72 ++- tests/tst_gdaswave.c | 5 +- tests/tst_get_grid_template.c | 57 +- tests/tst_getdim.c | 21 +- tests/tst_gridtemplates.c | 6 +- tests/tst_index.c | 117 ++-- tests/tst_inq.c | 18 +- tests/tst_jasper_warning.c | 6 +- tests/tst_jpeg.c | 22 +- tests/tst_metacmp.c | 12 +- tests/tst_mrms.c | 4 +- tests/tst_params.c | 21 +- tests/tst_params2.c | 2 - tests/tst_params3.c | 5 +- tests/tst_pdstemplates.c | 151 +++-- tests/tst_png.c | 244 +++---- tests/tst_seekgb.c | 2 +- tests/tst_simpack.c | 174 ++--- tests/tst_spec.c | 2 +- tests/tst_unpack.c | 26 +- tests/tst_xml.c | 21 +- 110 files changed, 3456 insertions(+), 3302 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..21f38487 --- /dev/null +++ b/.clang-format @@ -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 +... + diff --git a/src/CodeFlag.txt b/src/CodeFlag.txt index e4fa6e12..ed54b697 100644 --- a/src/CodeFlag.txt +++ b/src/CodeFlag.txt @@ -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 diff --git a/src/Template.txt b/src/Template.txt index 0cc86a31..9c89fd03 100644 --- a/src/Template.txt +++ b/src/Template.txt @@ -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 @@ -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 diff --git a/src/aecpack.c b/src/aecpack.c index 84cbc624..5d5838e2 100644 --- a/src/aecpack.c +++ b/src/aecpack.c @@ -10,11 +10,11 @@ * for CCSDS parameters. */ +#include "grib2_int.h" +#include +#include #include #include -#include -#include -#include "grib2_int.h" /** * Pack a float or double array into a AEC/CCSDS code stream. @@ -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; } } @@ -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; @@ -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); ret = enc_aec(ctemp, ctemplen, nbits, ccsds_flags, ccsds_block_size, ccsds_rsi, cpack, lcpack); if (ret < 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; } @@ -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; diff --git a/src/aecunpack.c b/src/aecunpack.c index ae8b0509..dc71f1e8 100644 --- a/src/aecunpack.c +++ b/src/aecunpack.c @@ -3,9 +3,9 @@ * stream * @author Eric Engle @date 2023-10-16 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /** * Unpack AEC compressed data into an @@ -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; @@ -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"); @@ -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++) @@ -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 { @@ -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); @@ -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); } @@ -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); } diff --git a/src/cmplxpack.c b/src/cmplxpack.c index c013eaaa..14b41052 100644 --- a/src/cmplxpack.c +++ b/src/cmplxpack.c @@ -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 @@ -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; } - } diff --git a/src/compack.c b/src/compack.c index f43f785c..2d731879 100644 --- a/src/compack.c +++ b/src/compack.c @@ -5,9 +5,9 @@ * @author Stephen Gilbert @date 2002-11-07 */ -#include -#include #include "grib2_int.h" +#include +#include /** * Pack a data field using a complex packing algorithm. @@ -45,17 +45,17 @@ compack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, static g2int zero = 0; g2int *ifld, *gref, *glen, *gwidth; - g2int *jmin, *jmax, *lbit; + g2int *jmin, *jmax, *lbit; g2int i, j, n, imin, imax, left; g2int isd, itemp, ilmax, ngwidthref = 0, nbitsgwidth = 0; g2int nglenref = 0, nglenlast = 0, iofst, ival1, ival2; g2int minsd, nbitsd = 0, maxorig, nbitorig, ngroups; g2int lg, ng, igmax, iwmax, nbitsgref; g2int glength, grpwidth, nbitsglen = 0; - g2int kfildo, minpk, inc, maxgrps, ibit, jbit, kbit, novref, lbitref; + g2int kfildo, minpk, inc, maxgrps, ibit, jbit, kbit, novref, lbitref; g2int missopt, miss1, miss2, ier; float bscale, dscale, rmax, rmin, temp; - static float alog2 = ALOG2; /* ln(2.0) */ + static float alog2 = ALOG2; /* ln(2.0) */ static g2int one = 1; bscale = int_power(2.0, -idrstmpl[1]); @@ -66,8 +66,10 @@ compack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, rmin = fld[0]; for (j = 1; j < ndpts; j++) { - if (fld[j] > rmax) rmax = fld[j]; - if (fld[j] < rmin) rmin = fld[j]; + if (fld[j] > rmax) + rmax = fld[j]; + if (fld[j] < rmin) + rmin = fld[j]; } /* If max and min values are not equal, pack up field. If they are @@ -83,15 +85,15 @@ compack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, /* Scale original data. */ if (idrstmpl[1] == 0) - { /* No binary scaling. */ - imin = (g2int)rint(rmin*dscale); + { /* No binary scaling. */ + imin = (g2int)rint(rmin * dscale); /*imax = (g2int)rint(rmax*dscale); */ rmin = (float)imin; for (j = 0; j < ndpts; j++) ifld[j] = (g2int)rint(fld[j] * dscale) - imin; } else - { /* Use binary scaling factor */ + { /* Use binary scaling factor */ rmin = rmin * dscale; /*rmax = rmax*dscale; */ for (j = 0; j < ndpts; j++) @@ -101,18 +103,18 @@ compack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, /* Calculate Spatial differences, if using DRS Template * 5.3. */ if (idrsnum == 3) - { /* spatial differences */ - if (idrstmpl[16] !=1 && idrstmpl[16] != 2) + { /* spatial differences */ + if (idrstmpl[16] != 1 && idrstmpl[16] != 2) idrstmpl[16] = 1; if (idrstmpl[16] == 1) - { /* first order */ + { /* first order */ ival1 = ifld[0]; - for (j = ndpts-1; j > 0; j--) + for (j = ndpts - 1; j > 0; j--) ifld[j] = ifld[j] - ifld[j - 1]; ifld[0] = 0; } else if (idrstmpl[16] == 2) - { /* second order */ + { /* second order */ ival1 = ifld[0]; ival2 = ifld[1]; for (j = ndpts - 1; j > 1; j--) @@ -146,7 +148,7 @@ compack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, /* Increase number of bits to even multiple of 8 (octet). */ if ((nbitsd % 8) != 0) - nbitsd = nbitsd+(8-(nbitsd%8)); + nbitsd = nbitsd + (8 - (nbitsd % 8)); /* Store extra spatial differencing info into the packed * data section. */ @@ -156,14 +158,14 @@ compack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, if (ival1 >= 0) { sbit(cpack, &ival1, iofst, nbitsd); - iofst = iofst+nbitsd; + iofst = iofst + nbitsd; } else { sbit(cpack, &one, iofst, 1); iofst = iofst + 1; itemp = abs(ival1); - sbit(cpack, &itemp, iofst, nbitsd-1); + sbit(cpack, &itemp, iofst, nbitsd - 1); iofst = iofst + nbitsd - 1; } if (idrstmpl[16] == 2) @@ -183,7 +185,7 @@ compack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, iofst = iofst + nbitsd - 1; } } - + /* pack overall min of spatial differences */ if (minsd >= 0) { @@ -199,7 +201,7 @@ compack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, iofst = iofst + nbitsd - 1; } } - } /* end of spatial diff section */ + } /* end of spatial diff section */ /* Use Dr. Glahn's algorithm for determining grouping. */ kfildo = 6; @@ -210,10 +212,10 @@ compack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, jmax = calloc(maxgrps, sizeof(g2int)); lbit = calloc(maxgrps, sizeof(g2int)); missopt = 0; - pack_gp(&kfildo, ifld, &ndpts, &missopt, &minpk, &inc, &miss1, &miss2, - jmin, jmax, lbit, glen, &maxgrps, &ngroups, &ibit, &jbit, + pack_gp(&kfildo, ifld, &ndpts, &missopt, &minpk, &inc, &miss1, &miss2, + jmin, jmax, lbit, glen, &maxgrps, &ngroups, &ibit, &jbit, &kbit, &novref, &lbitref, &ier); - for (ng = 0; ng #include -#include "grib2_int.h" /** * Unpack a data field that was packed using a complex packing @@ -18,7 +18,7 @@ * * ### Program History Log * Date | Programmer | Comments - * -----|------------|--------- + * -----|------------|--------- * 2002-10-29 | Gilbert | Initial * 2004-12-16 | Gilbert | Added test (from Arthur Taylor/MDL) verifying group widths/lengths * @@ -41,14 +41,14 @@ int comunpack(unsigned char *cpack, g2int lensec, g2int idrsnum, g2int *idrstmpl, g2int ndpts, float *fld) { - g2int nbitsd=0, isign; - g2int j, iofst, ival1, ival2, minsd, itemp, l, k, n, non=0; - g2int *ifld, *ifldmiss=0; + g2int nbitsd = 0, isign; + g2int j, iofst, ival1, ival2, minsd, itemp, l, k, n, non = 0; + g2int *ifld, *ifldmiss = 0; g2int *gref, *gwidth, *glen; g2int itype, ngroups, nbitsgref, nbitsgwidth, nbitsglen; g2int msng1, msng2; float ref, bscale, dscale, rmiss1, rmiss2; - g2int totBit, totLen; + g2int totBit, totLen; LOG((3, "comunpack lensec %ld idrsnum %ld ndpts %ld", lensec, idrsnum, ndpts)); @@ -61,14 +61,14 @@ comunpack(unsigned char *cpack, g2int lensec, g2int idrsnum, nbitsgwidth = idrstmpl[11]; nbitsglen = idrstmpl[15]; if (idrsnum == 3) - nbitsd=idrstmpl[17] * 8; + nbitsd = idrstmpl[17] * 8; /* Constant field */ if (ngroups == 0) { for (j = 0; j < ndpts; j++) fld[j] = ref; - return(0); + return (0); } iofst = 0; @@ -80,7 +80,7 @@ comunpack(unsigned char *cpack, g2int lensec, g2int idrsnum, if (idrstmpl[6] == 1) { if (itype == 0) - rdieee(idrstmpl+7,&rmiss1,1); + rdieee(idrstmpl + 7, &rmiss1, 1); else rmiss1 = (float)idrstmpl[7]; } @@ -88,10 +88,11 @@ comunpack(unsigned char *cpack, g2int lensec, g2int idrsnum, { if (itype == 0) { - rdieee(idrstmpl+7,&rmiss1,1); - rdieee(idrstmpl+8,&rmiss2,1); + rdieee(idrstmpl + 7, &rmiss1, 1); + rdieee(idrstmpl + 8, &rmiss2, 1); } - else { + else + { rmiss1 = (float)idrstmpl[7]; rmiss2 = (float)idrstmpl[8]; } @@ -118,7 +119,8 @@ comunpack(unsigned char *cpack, g2int lensec, g2int idrsnum, if (isign == 1) minsd = -minsd; } - else { + else + { ival1 = 0; ival2 = 0; minsd = 0; @@ -139,16 +141,18 @@ comunpack(unsigned char *cpack, g2int lensec, g2int idrsnum, for (j = 0; j < ngroups; j++) gref[j] = 0; } - + /* Extract Each Group's bit width */ - if (nbitsgwidth != 0) { + if (nbitsgwidth != 0) + { gbits(cpack, gwidth, iofst, nbitsgwidth, 0, ngroups); itemp = nbitsgwidth * ngroups; iofst = iofst + itemp; if (itemp % 8 != 0) iofst = iofst + (8 - (itemp % 8)); } - else { + else + { for (j = 0; j < ngroups; j++) gwidth[j] = 0; } @@ -171,9 +175,9 @@ comunpack(unsigned char *cpack, g2int lensec, g2int idrsnum, for (j = 0; j < ngroups; j++) glen[j] = 0; } - for (j = 0;j -#include -#include #include "grib2_int.h" +#include +#include +#include /** * Decode an AEC code stream specified in the [CCSDS 121.0-B-3 Blue @@ -34,45 +34,47 @@ * * @author Eric Engle @date 2023-10-16 */ -int dec_aec(unsigned char *cpack, g2int len, g2int nbits, g2int flags, - g2int block_size, g2int rsi, unsigned char *cfld, g2int cfldlen) +int +dec_aec(unsigned char *cpack, g2int len, g2int nbits, g2int flags, + g2int block_size, g2int rsi, unsigned char *cfld, g2int cfldlen) { struct aec_stream strm; int ret = 0; /* Define bits per sample */ strm.bits_per_sample = nbits; - LOG((3, "dec_aec: bits_per_sample = %d",strm.bits_per_sample)); + LOG((3, "dec_aec: bits_per_sample = %d", strm.bits_per_sample)); /* Define a block size */ - LOG((3, "dec_aec: block_size = %d",block_size)); + LOG((3, "dec_aec: block_size = %d", block_size)); strm.block_size = block_size; /* Define the reference sample interval */ - LOG((3, "dec_aec: rsi = %d",rsi)); + LOG((3, "dec_aec: rsi = %d", rsi)); strm.rsi = rsi; /* Define the AEC compression flags. */ strm.flags = flags; - LOG((3, "dec_aec: flags = %d",strm.flags)); + LOG((3, "dec_aec: flags = %d", strm.flags)); /* Pointer to input */ strm.next_in = cpack; /* Length of input in bytes */ strm.avail_in = len; - LOG((3, "dec_aec: avail_in = %d",strm.avail_in)); + LOG((3, "dec_aec: avail_in = %d", strm.avail_in)); /* Pointer to output buffer */ strm.next_out = cfld; /* Length of output buffer in bytes */ - strm.avail_out = (size_t) cfldlen; + strm.avail_out = (size_t)cfldlen; /* Decode. */ ret = aec_buffer_decode(&strm); LOG((3, "dec_aec: return from aec_buffer_encode = %d", ret)); - if (ret == AEC_OK) ret = strm.total_out; + if (ret == AEC_OK) + ret = strm.total_out; return ret; } @@ -102,45 +104,47 @@ int dec_aec(unsigned char *cpack, g2int len, g2int nbits, g2int flags, * * @author Eric Engle @date 2023-10-16 */ -int enc_aec(unsigned char *data, g2int ctemplen, g2int nbits, g2int flags, - g2int block_size, g2int rsi, unsigned char *aecbuf, g2int *aecbuflen) +int +enc_aec(unsigned char *data, g2int ctemplen, g2int nbits, g2int flags, + g2int block_size, g2int rsi, unsigned char *aecbuf, g2int *aecbuflen) { struct aec_stream strm; int ret = 0; /* Define bits per sample */ strm.bits_per_sample = nbits; - LOG((3, "enc_aec: bits_per_sample = %d",strm.bits_per_sample)); + LOG((3, "enc_aec: bits_per_sample = %d", strm.bits_per_sample)); /* Define a block size */ - LOG((3, "enc_aec: block_size = %d",block_size)); + LOG((3, "enc_aec: block_size = %d", block_size)); strm.block_size = block_size; /* Define the reference sample interval */ - LOG((3, "enc_aec: rsi = %d",rsi)); + LOG((3, "enc_aec: rsi = %d", rsi)); strm.rsi = rsi; /* Define the AEC compression flags. */ strm.flags = flags; - LOG((3, "enc_aec: flags = %d",strm.flags)); + LOG((3, "enc_aec: flags = %d", strm.flags)); /* Pointer to input */ strm.next_in = data; /* Length of input in bytes */ strm.avail_in = ctemplen; - LOG((3, "enc_aec: avail_in = %d",strm.avail_in)); + LOG((3, "enc_aec: avail_in = %d", strm.avail_in)); /* Pointer to output buffer */ strm.next_out = aecbuf; /* Length of output buffer in bytes */ - strm.avail_out = (size_t) aecbuflen; + strm.avail_out = (size_t)aecbuflen; /* Encode into AEC. */ ret = aec_buffer_encode(&strm); LOG((3, "enc_aec: return from aec_buffer_encode = %d", ret)); - if (ret == AEC_OK) ret = strm.total_out; + if (ret == AEC_OK) + ret = strm.total_out; return ret; } diff --git a/src/decenc_jpeg2000.c b/src/decenc_jpeg2000.c index fa9c6769..6bed2c6b 100644 --- a/src/decenc_jpeg2000.c +++ b/src/decenc_jpeg2000.c @@ -3,11 +3,11 @@ * @author Alyson Stahl @date 2024-14-08 */ +#include "grib2_int.h" +#include "jasper/jasper.h" #include #include #include -#include "grib2_int.h" -#include "jasper/jasper.h" #define MAXOPTSSIZE 1024 /**< Maximum size of options. */ @@ -48,7 +48,7 @@ g2c_enc_jpeg2000(unsigned char *cin, int width, int height, int nbits, { g2int width8 = width, height8 = height, nbits8 = nbits, ltype8 = ltype; g2int ratio8 = ratio, retry8 = retry, jpclen8 = jpclen; - + return enc_jpeg2000(cin, width8, height8, nbits8, ltype8, ratio8, retry8, outjpc, jpclen8); } @@ -64,7 +64,7 @@ g2c_enc_jpeg2000(unsigned char *cin, int width, int height, int nbits, * 2002-12-02 | Gilbert | Initial * 2004-12-16 | Gilbert | Added retry argument allowing increased guard bits. * 2022-04-15 | Hartnett | Converted to use jas_ instead of jpc_ functions. - * + * * @param cin Packed matrix of Grayscale image values to encode. * @param width width of image. * @param height height of image. @@ -103,16 +103,16 @@ enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits, int fmt; LOG((3, "enc_jpeg2000 width %ld height %ld nbits %ld ltype %ld ratio %ld retry %ld jpclen %d", - width, height, nbits, ltype, ratio, retry, jpclen)); + width, height, nbits, ltype, ratio, retry, jpclen)); /* Set lossy compression options, if requested. */ if (ltype != 1) opts[0] = (char)0; else - snprintf(opts,MAXOPTSSIZE,"mode=real\nrate=%f",1.0/(float)ratio); + snprintf(opts, MAXOPTSSIZE, "mode=real\nrate=%f", 1.0 / (float)ratio); - if (retry == 1) /* option to increase number of guard bits */ - strcat(opts,"\nnumgbits=4"); + if (retry == 1) /* option to increase number of guard bits */ + strcat(opts, "\nnumgbits=4"); /* Initialize the JasPer image structure describing the grayscale * image to encode into the JPEG2000 code stream. */ @@ -122,7 +122,7 @@ enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits, image.bry_ = (jas_image_coord_t)height; image.numcmpts_ = 1; image.maxcmpts_ = 1; - image.clrspc_ = JAS_CLRSPC_SGRAY; /* grayscale Image */ + image.clrspc_ = JAS_CLRSPC_SGRAY; /* grayscale Image */ image.cmprof_ = 0; cmpt.tlx_ = 0; @@ -291,9 +291,8 @@ int_dec_jpeg2000(char *injpc, g2int bufsize, void *outfld, int out_is_g2int) jas_image_readcmpt(image, 0, 0, 0, jas_image_width(image), jas_image_height(image), data); - LOG((3, "pcmpt->height_ %d pcmpt->width_ %d", pcmpt->height_, pcmpt->width_)); - + /* Copy data matrix to output integer array. */ k = 0; if (out_is_g2int) @@ -371,7 +370,7 @@ g2c_dec_jpeg2000(char *injpc, size_t bufsize, int *outfld) * components. Only grayscale is expected. * - ::G2_JASPER_INIT Error inializing Jasper library. * - * @author Stephen Gilbert, Ed Hartnett + * @author Stephen Gilbert, Ed Hartnett */ int dec_jpeg2000(char *injpc, g2int bufsize, g2int *outfld) diff --git a/src/decenc_openjpeg.c b/src/decenc_openjpeg.c index d2d1bff6..f5cf6127 100644 --- a/src/decenc_openjpeg.c +++ b/src/decenc_openjpeg.c @@ -33,10 +33,11 @@ * * @author ECMWF programmer */ -static void openjpeg_warning(const char *msg, void *client_data) +static void +openjpeg_warning(const char *msg, void *client_data) { (void)client_data; - fprintf(stderr,"openjpeg: %s",msg); + fprintf(stderr, "openjpeg: %s", msg); } /** @@ -47,10 +48,11 @@ static void openjpeg_warning(const char *msg, void *client_data) * * @author ECMWF programmer */ -static void openjpeg_error(const char *msg, void *client_data) +static void +openjpeg_error(const char *msg, void *client_data) { (void)client_data; - fprintf(stderr,"openjpeg: %s",msg); + fprintf(stderr, "openjpeg: %s", msg); } /** @@ -61,7 +63,8 @@ static void openjpeg_error(const char *msg, void *client_data) * * @author ECMWF programmer */ -static void openjpeg_info(const char *msg, void *client_data) +static void +openjpeg_info(const char *msg, void *client_data) { (void)msg; (void)client_data; @@ -75,9 +78,9 @@ static void openjpeg_info(const char *msg, void *client_data) /* struct need to treat memory as a stream */ typedef struct { - OPJ_UINT8* pData; /* our data */ - OPJ_SIZE_T dataSize; /* how big is our data */ - OPJ_SIZE_T offset; /* where we are currently in our data */ + OPJ_UINT8 *pData; /* our data */ + OPJ_SIZE_T dataSize; /* how big is our data */ + OPJ_SIZE_T offset; /* where we are currently in our data */ } opj_memory_stream; /** @@ -91,14 +94,15 @@ typedef struct * * @author ECMWF programmer */ -static OPJ_SIZE_T opj_memory_stream_read(void *buffer, OPJ_SIZE_T nb_bytes, void * p_user_data) +static OPJ_SIZE_T +opj_memory_stream_read(void *buffer, OPJ_SIZE_T nb_bytes, void *p_user_data) { - opj_memory_stream* mstream = (opj_memory_stream*) p_user_data; /* Our data */ - OPJ_SIZE_T nb_bytes_read = nb_bytes; /* Amount to move to buffer */ + opj_memory_stream *mstream = (opj_memory_stream *)p_user_data; /* Our data */ + OPJ_SIZE_T nb_bytes_read = nb_bytes; /* Amount to move to buffer */ /* Check if the current offset is outside our data buffer */ if (mstream->offset >= mstream->dataSize) - return (OPJ_SIZE_T) -1; + return (OPJ_SIZE_T)-1; /* Check if we are reading more than we have */ if (nb_bytes > (mstream->dataSize - mstream->offset)) @@ -120,10 +124,11 @@ static OPJ_SIZE_T opj_memory_stream_read(void *buffer, OPJ_SIZE_T nb_bytes, void * * @author ECMWF programmer */ -static OPJ_SIZE_T opj_memory_stream_write(void *buffer, OPJ_SIZE_T nb_bytes, void *user_data) +static OPJ_SIZE_T +opj_memory_stream_write(void *buffer, OPJ_SIZE_T nb_bytes, void *user_data) { - opj_memory_stream* mstream = (opj_memory_stream*) user_data; /* our data */ - OPJ_SIZE_T nb_bytes_write = nb_bytes; /* Amount to move to buffer */ + opj_memory_stream *mstream = (opj_memory_stream *)user_data; /* our data */ + OPJ_SIZE_T nb_bytes_write = nb_bytes; /* Amount to move to buffer */ /* Check if the current offset is outside our data buffer */ if (mstream->offset >= mstream->dataSize) @@ -149,14 +154,15 @@ static OPJ_SIZE_T opj_memory_stream_write(void *buffer, OPJ_SIZE_T nb_bytes, voi * * @author ECMWF programmer */ -static OPJ_OFF_T opj_memory_stream_skip(OPJ_OFF_T nb_bytes, void *user_data) +static OPJ_OFF_T +opj_memory_stream_skip(OPJ_OFF_T nb_bytes, void *user_data) { - opj_memory_stream* mstream = (opj_memory_stream*) user_data; + opj_memory_stream *mstream = (opj_memory_stream *)user_data; OPJ_SIZE_T l_nb_bytes; if (nb_bytes < 0) - return -1; /* No skipping backwards */ - l_nb_bytes = (OPJ_SIZE_T) nb_bytes; /* Allowed because it is positive */ + return -1; /* No skipping backwards */ + l_nb_bytes = (OPJ_SIZE_T)nb_bytes; /* Allowed because it is positive */ /* Do not allow jumping past the end */ if (l_nb_bytes > mstream->dataSize - mstream->offset) l_nb_bytes = mstream->dataSize - mstream->offset; @@ -174,15 +180,16 @@ static OPJ_OFF_T opj_memory_stream_skip(OPJ_OFF_T nb_bytes, void *user_data) * * @author ECMWF programmer */ -static OPJ_BOOL opj_memory_stream_seek(OPJ_OFF_T nb_bytes, void * user_data) +static OPJ_BOOL +opj_memory_stream_seek(OPJ_OFF_T nb_bytes, void *user_data) { - opj_memory_stream* mstream = (opj_memory_stream*) user_data; + opj_memory_stream *mstream = (opj_memory_stream *)user_data; if (nb_bytes < 0) return OPJ_FALSE; /* Not before the buffer */ - if (nb_bytes >(OPJ_OFF_T) mstream->dataSize) - return OPJ_FALSE; /* Not after the buffer */ - mstream->offset = (OPJ_SIZE_T) nb_bytes; /* Move to new position */ + if (nb_bytes > (OPJ_OFF_T)mstream->dataSize) + return OPJ_FALSE; /* Not after the buffer */ + mstream->offset = (OPJ_SIZE_T)nb_bytes; /* Move to new position */ return OPJ_TRUE; } @@ -193,7 +200,8 @@ static OPJ_BOOL opj_memory_stream_seek(OPJ_OFF_T nb_bytes, void * user_data) * * @author ECMWF programmer */ -static void opj_memory_stream_do_nothing(void * p_user_data) +static void +opj_memory_stream_do_nothing(void *p_user_data) { OPJ_ARG_NOT_USED(p_user_data); } @@ -208,9 +216,10 @@ static void opj_memory_stream_do_nothing(void * p_user_data) * * @author ECMWF programmer */ -static opj_stream_t* opj_stream_create_default_memory_stream(opj_memory_stream* memoryStream, OPJ_BOOL is_read_stream) +static opj_stream_t * +opj_stream_create_default_memory_stream(opj_memory_stream *memoryStream, OPJ_BOOL is_read_stream) { - opj_stream_t* stream; + opj_stream_t *stream; if (!(stream = opj_stream_default_create(is_read_stream))) return (NULL); @@ -248,7 +257,8 @@ static opj_stream_t* opj_stream_create_default_memory_stream(opj_memory_stream* * * @author Stephen Gilbert, Jovic */ -int dec_jpeg2000(char *injpc,g2int bufsize,g2int *outfld) +int +dec_jpeg2000(char *injpc, g2int bufsize, g2int *outfld) { int iret = 0; OPJ_INT32 mask; @@ -258,7 +268,9 @@ int dec_jpeg2000(char *injpc,g2int bufsize,g2int *outfld) opj_codec_t *codec = NULL; /* set decoding parameters to default values */ - opj_dparameters_t parameters = {0,}; /* decompression parameters */ + opj_dparameters_t parameters = { + 0, + }; /* decompression parameters */ opj_set_default_decoder_parameters(¶meters); parameters.decod_format = 1; /* JP2_FMT */ @@ -268,7 +280,7 @@ int dec_jpeg2000(char *injpc,g2int bufsize,g2int *outfld) /* catch events using our callbacks */ opj_set_info_handler(codec, openjpeg_info, NULL); opj_set_warning_handler(codec, openjpeg_warning, NULL); - opj_set_error_handler(codec, openjpeg_error,NULL); + opj_set_error_handler(codec, openjpeg_error, NULL); /* initialize our memory stream */ opj_memory_stream mstream; @@ -276,48 +288,56 @@ int dec_jpeg2000(char *injpc,g2int bufsize,g2int *outfld) mstream.dataSize = (OPJ_SIZE_T)bufsize; mstream.offset = 0; /* open a byte stream from memory stream */ - stream = opj_stream_create_default_memory_stream( &mstream, OPJ_STREAM_READ); + stream = opj_stream_create_default_memory_stream(&mstream, OPJ_STREAM_READ); /* setup the decoder decoding parameters using user parameters */ - if (!opj_setup_decoder(codec, ¶meters)) { - fprintf(stderr,"openjpeg: failed to setup decoder"); + if (!opj_setup_decoder(codec, ¶meters)) + { + fprintf(stderr, "openjpeg: failed to setup decoder"); iret = -3; goto cleanup; } - if (!opj_read_header(stream, codec, &image)) { - fprintf(stderr,"openjpeg: failed to read the header"); + if (!opj_read_header(stream, codec, &image)) + { + fprintf(stderr, "openjpeg: failed to read the header"); iret = -3; goto cleanup; } - if (!opj_decode(codec, stream, image)) { - fprintf(stderr,"openjpeg: failed to decode"); + if (!opj_decode(codec, stream, image)) + { + fprintf(stderr, "openjpeg: failed to decode"); iret = -3; goto cleanup; } - if ( (image->numcomps != 1) || (image->x1 * image->y1)==0 ) { + if ((image->numcomps != 1) || (image->x1 * image->y1) == 0) + { iret = -3; goto cleanup; } assert(image->comps[0].sgnd == 0); - assert(image->comps[0].prec < sizeof(mask)*8-1); + assert(image->comps[0].prec < sizeof(mask) * 8 - 1); mask = (1 << image->comps[0].prec) - 1; - for(unsigned int i = 0; i < image->comps[0].w * image->comps[0].h ; i++) - outfld[i] = (g2int) (image->comps[0].data[i] & mask); + for (unsigned int i = 0; i < image->comps[0].w * image->comps[0].h; i++) + outfld[i] = (g2int)(image->comps[0].data[i] & mask); - if (!opj_end_decompress(codec, stream)) { - fprintf(stderr,"openjpeg: failed in opj_end_decompress"); + if (!opj_end_decompress(codec, stream)) + { + fprintf(stderr, "openjpeg: failed in opj_end_decompress"); iret = -3; } cleanup: /* close the byte stream */ - if (codec) opj_destroy_codec(codec); - if (stream) opj_stream_destroy(stream); - if (image) opj_image_destroy(image); + if (codec) + opj_destroy_codec(codec); + if (stream) + opj_stream_destroy(stream); + if (image) + opj_image_destroy(image); return iret; } @@ -355,11 +375,12 @@ int dec_jpeg2000(char *injpc,g2int bufsize,g2int *outfld) * * @author Stephen Gilbert, Jovic */ -int enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits, - g2int ltype, g2int ratio, g2int retry, char *outjpc, - g2int jpclen) +int +enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits, + g2int ltype, g2int ratio, g2int retry, char *outjpc, + g2int jpclen) { - (void) retry; + (void)retry; int iret = 0; const int numcomps = 1; @@ -368,14 +389,17 @@ int enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits, opj_stream_t *stream = NULL; /* set encoding parameters to default values */ - opj_cparameters_t parameters = {0,}; /* compression parameters */ + opj_cparameters_t parameters = { + 0, + }; /* compression parameters */ opj_set_default_encoder_parameters(¶meters); - parameters.tcp_numlayers = 1; + parameters.tcp_numlayers = 1; parameters.cp_disto_alloc = 1; - if (ltype == 1) { + if (ltype == 1) + { assert(ratio != 255); - parameters.tcp_rates[0] = 1.0f/(float)ratio; + parameters.tcp_rates[0] = 1.0f / (float)ratio; } /* By default numresolution = 6 (must be between 1 and 32) @@ -389,7 +413,9 @@ int enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits, } /* initialize image component */ - opj_image_cmptparm_t cmptparm = {0,}; + opj_image_cmptparm_t cmptparm = { + 0, + }; cmptparm.prec = (OPJ_UINT32)nbits; cmptparm.bpp = (OPJ_UINT32)nbits; cmptparm.sgnd = 0; @@ -410,7 +436,7 @@ int enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits, image->x1 = (OPJ_UINT32)width; image->y1 = (OPJ_UINT32)height; - assert(cmptparm.prec <= sizeof(image->comps[0].data[0])*8 - 1); /* BR: -1 because I don't know what happens if the sign bit is set */ + assert(cmptparm.prec <= sizeof(image->comps[0].data[0]) * 8 - 1); /* BR: -1 because I don't know what happens if the sign bit is set */ /* Simple packing */ for (int i = 0; i < width * height; i++) @@ -421,12 +447,12 @@ int enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits, opj_set_info_handler(codec, openjpeg_info, NULL); opj_set_warning_handler(codec, openjpeg_warning, NULL); - opj_set_error_handler(codec, openjpeg_error,NULL); + opj_set_error_handler(codec, openjpeg_error, NULL); /* setup the encoder parameters using the current image and user parameters */ if (!opj_setup_encoder(codec, ¶meters, image)) { - fprintf(stderr,"openjpeg: failed to setup encoder"); + fprintf(stderr, "openjpeg: failed to setup encoder"); iret = -3; goto cleanup; } @@ -439,14 +465,14 @@ int enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits, stream = opj_stream_create_default_memory_stream(&mstream, OPJ_STREAM_WRITE); if (!stream) { - fprintf(stderr,"openjpeg: failed create default memory stream"); + fprintf(stderr, "openjpeg: failed create default memory stream"); iret = -3; goto cleanup; } if (!opj_start_compress(codec, image, stream)) { - fprintf(stderr,"openjpeg: failed to setup encoder"); + fprintf(stderr, "openjpeg: failed to setup encoder"); iret = -3; goto cleanup; } @@ -454,14 +480,14 @@ int enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits, /* encode image */ if (!opj_encode(codec, stream)) { - fprintf(stderr,"openjpeg: opj_encode failed"); + fprintf(stderr, "openjpeg: opj_encode failed"); iret = -3; goto cleanup; } if (!opj_end_compress(codec, stream)) { - fprintf(stderr,"openjpeg: opj_end_compress failed"); + fprintf(stderr, "openjpeg: opj_end_compress failed"); iret = -3; goto cleanup; } diff --git a/src/decenc_png.c b/src/decenc_png.c index e34d46d8..d48c68c6 100644 --- a/src/decenc_png.c +++ b/src/decenc_png.c @@ -3,11 +3,11 @@ * @author Alyson Stahl @date 2024-13-08 */ +#include "grib2_int.h" +#include #include #include #include -#include -#include "grib2_int.h" /** * Struct for PNG stream. @@ -15,7 +15,7 @@ struct png_stream { unsigned char *stream_ptr; /**< Location to write PNG stream. */ - g2int stream_len; /**< Number of bytes written. */ + g2int stream_len; /**< Number of bytes written. */ }; typedef struct png_stream png_stream; /**< Typedef for PNG stream. */ @@ -79,7 +79,8 @@ user_write_data(png_structp png_ptr, png_bytep data, png_uint_32 length) * * @author Stephen Gilbert */ -void user_flush_data(png_structp png_ptr) +void +user_flush_data(png_structp png_ptr) { } @@ -131,7 +132,7 @@ dec_png(unsigned char *pngbuf, g2int *width, g2int *height, /* Set Error callback. */ if (setjmp(png_jmpbuf(png_ptr))) { - png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); + png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); return -3; } diff --git a/src/drstemplates.c b/src/drstemplates.c index 4900fb83..4cc7e3b7 100644 --- a/src/drstemplates.c +++ b/src/drstemplates.c @@ -40,9 +40,9 @@ */ struct drstemplate { - g2int template_num; /**< The number of entries in the template. */ - g2int mapdrslen; /**< Length of map of the template. */ - g2int needext; /**< Whether the Template needs to be extended. */ + g2int template_num; /**< The number of entries in the template. */ + g2int mapdrslen; /**< Length of map of the template. */ + g2int needext; /**< Whether the Template needs to be extended. */ g2int mapdrs[G2C_MAX_DRS_TEMPLATE_MAPLEN]; /**< A map of the template. */ }; @@ -51,28 +51,28 @@ struct drstemplate * template. */ static const struct drstemplate templatesdrs[G2C_MAX_DRS_TEMPLATE] = -{ - /** [5.0: Grid point data - Simple + { + /** [5.0: Grid point data - Simple * Packing](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-0.shtml) */ - {0, 5, 0, {4, -2, -2, 1, 1}}, + {0, 5, 0, {4, -2, -2, 1, 1}}, - /** [5.2: Grid point data - Complex + /** [5.2: Grid point data - Complex * Packing](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-2.shtml) */ - {2, 16, 0, {4, -2, -2, 1, 1, 1, 1, 4, 4, 4, 1, 1, 4, 1, 4, 1}}, + {2, 16, 0, {4, -2, -2, 1, 1, 1, 1, 4, 4, 4, 1, 1, 4, 1, 4, 1}}, - /** [5.3: Grid point data - Complex Packing and spatial + /** [5.3: Grid point data - Complex Packing and spatial * differencing](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-3.shtml) */ - {3, 18, 0, {4, -2, -2, 1, 1, 1, 1, 4, 4, 4, 1, 1, 4, 1, 4, 1, 1, 1}}, + {3, 18, 0, {4, -2, -2, 1, 1, 1, 1, 4, 4, 4, 1, 1, 4, 1, 4, 1, 1, 1}}, - /** [5.50: Spectral Data - Simple + /** [5.50: Spectral Data - Simple * Packing](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-50.shtml) */ - {50, 5, 0, {4, -2, -2, 1, 4}}, + {50, 5, 0, {4, -2, -2, 1, 4}}, - /** [5.51: Spherical Harmonics data - Complex + /** [5.51: Spherical Harmonics data - Complex * packing](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-51.shtml) */ - {51, 10, 0, {4, -2, -2, 1, -4, 2, 2, 2, 4, 1}}, + {51, 10, 0, {4, -2, -2, 1, -4, 2, 2, 2, 4, 1}}, - /* 5.1: Matrix values at gridpoint - Simple packing. + /* 5.1: Matrix values at gridpoint - Simple packing. * Comment from Stephen Gilbert in 2021: * * This encoder/decoder was written in the early days of GRIB2 @@ -92,32 +92,32 @@ static const struct drstemplate templatesdrs[G2C_MAX_DRS_TEMPLATE] = * in the future. */ - /* {1, 15, 1, {4, -2, -2, 1, 1, 1, 4, 2, 2, 1, 1, 1, 1, 1, 1}}, */ + /* {1, 15, 1, {4, -2, -2, 1, 1, 1, 4, 2, 2, 1, 1, 1, 1, 1, 1}}, */ - /** [5.40: Grid point data - JPEG2000 + /** [5.40: Grid point data - JPEG2000 * encoding](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-40.shtml) */ - {40, 7, 0, {4, -2, -2, 1, 1, 1, 1}}, + {40, 7, 0, {4, -2, -2, 1, 1, 1, 1}}, - /** [5.41: Grid point data - PNG + /** [5.41: Grid point data - PNG * encoding](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-41.shtml) */ - {41, 5, 0, {4, -2, -2, 1, 1}}, + {41, 5, 0, {4, -2, -2, 1, 1}}, - /** [5.42: Grid point data - CCSDS recommended lossless compress (libaec) + /** [5.42: Grid point data - CCSDS recommended lossless compress (libaec) * encoding](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-42.shtml) */ - {42, 8, 0, {4, -2, -2, 1, 1, 1, 1, 2}}, + {42, 8, 0, {4, -2, -2, 1, 1, 1, 1, 2}}, - /** 5.40000: Grid point data - JPEG2000 encoding + /** 5.40000: Grid point data - JPEG2000 encoding * * This is a local template number, from a time before WMO standardized use of JPEG2000 * with 5.40. This should not be used in new data files. Use 5.40 instead. */ - {40000, 7, 0, {4, -2, -2, 1, 1, 1, 1}}, + {40000, 7, 0, {4, -2, -2, 1, 1, 1, 1}}, - /** 5.40010: Grid point data - PNG encoding + /** 5.40010: Grid point data - PNG encoding * * This is a local template number, from a time before WMO standardized use of PNG * with 5.41. This should not be used in new data files. Use 5.41 instead. */ - {40010, 5, 0, {4, -2, -2, 1, 1}}, -} ; + {40010, 5, 0, {4, -2, -2, 1, 1}}, +}; /** * This function returns the index of specified Data Representation @@ -141,11 +141,11 @@ getdrsindex(g2int number) if (number == templatesdrs[j].template_num) { getdrsindex = j; - return(getdrsindex); + return (getdrsindex); } } - return(getdrsindex); + return (getdrsindex); } /** @@ -181,15 +181,15 @@ getdrstemplate(g2int number) new->map = (g2int *)templatesdrs[index].mapdrs; new->extlen = 0; new->ext = NULL; - return(new); + return (new); } else { printf("getdrstemplate: DRS Template 5.%d not defined.\n", (int)number); - return(NULL); + return (NULL); } - return(NULL); + return (NULL); } /** @@ -220,7 +220,7 @@ extdrstemplate(g2int number, g2int *list) new = getdrstemplate(number); if (!new->needext) - return(new); + return (new); /* This template is commented out (see comment in struct * drstemplate for explanation). */ @@ -284,4 +284,3 @@ g2c_get_drs_template(int drs_template_num, int *maplen, int *map, int *needext) /* If we didn't find a template, return an error. */ return G2C_ENOTEMPLATE; } - diff --git a/src/g2_addfield.c b/src/g2_addfield.c index 6a990bda..ed90ed9e 100644 --- a/src/g2_addfield.c +++ b/src/g2_addfield.c @@ -4,9 +4,9 @@ * @author Stephen Gilbert @date 2002-11-05 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /** * Pack sections 4 through 7 and adds them to a GRIB2 message. @@ -130,7 +130,7 @@ g2_addfield(unsigned char *cgrib, g2int ipdsnum, g2int *ipdstmpl, /* Loop through all current sections of the GRIB message to find * the last section number. */ - len = 16; /* length of Section 0 */ + len = 16; /* length of Section 0 */ for (;;) { /* Get number and length of next section. */ @@ -189,13 +189,13 @@ g2_addfield(unsigned char *cgrib, g2int ipdsnum, g2int *ipdstmpl, } /* Add Section 4 - Product Definition Section. */ - ibeg = lencurr * 8; /* Calculate offset for beginning of section 4 */ - iofst = ibeg + 32; /* leave space for length of section */ - sbit(cgrib, &four, iofst, 8); /* Store section number (4) */ + ibeg = lencurr * 8; /* Calculate offset for beginning of section 4 */ + iofst = ibeg + 32; /* leave space for length of section */ + sbit(cgrib, &four, iofst, 8); /* Store section number (4) */ iofst = iofst + 8; - sbit(cgrib, &numcoord, iofst, 16); /* Store num of coordinate values */ + sbit(cgrib, &numcoord, iofst, 16); /* Store num of coordinate values */ iofst = iofst + 16; - sbit(cgrib, &ipdsnum, iofst, 16); /* Store Prod Def Template num. */ + sbit(cgrib, &ipdsnum, iofst, 16); /* Store Prod Def Template num. */ iofst = iofst + 16; /* Get Product Definition Template. */ @@ -223,7 +223,7 @@ g2_addfield(unsigned char *cgrib, g2int ipdsnum, g2int *ipdstmpl, { sbit(cgrib, &one, iofst, 1); temp = abs(ipdstmpl[i]); - sbit(cgrib, &temp, iofst + 1, nbits-1); + sbit(cgrib, &temp, iofst + 1, nbits - 1); } iofst = iofst + nbits; } @@ -297,16 +297,16 @@ g2_addfield(unsigned char *cgrib, g2int ipdsnum, g2int *ipdstmpl, cpack = malloc(nsize); /* Call packing function based on idrsnum. */ - if (idrsnum == 0) /* Simple Packing */ + if (idrsnum == 0) /* Simple Packing */ simpack(pfld, ndpts, idrstmpl, cpack, &lcpack); - else if (idrsnum == 2 || idrsnum == 3) /* Complex Packing */ + else if (idrsnum == 2 || idrsnum == 3) /* Complex Packing */ cmplxpack(pfld, ndpts, idrsnum, idrstmpl, cpack, &lcpack); - else if (idrsnum == 50) /* Sperical Harmonic Simple Packing */ + else if (idrsnum == 50) /* Sperical Harmonic Simple Packing */ { simpack(pfld + 1, ndpts - 1, idrstmpl, cpack, &lcpack); - mkieee(pfld, idrstmpl + 4, 1); /* ensure RE(0, 0) value is IEEE format */ + mkieee(pfld, idrstmpl + 4, 1); /* ensure RE(0, 0) value is IEEE format */ } - else if (idrsnum == 51) /* Sperical Harmonic Complex Packing */ + else if (idrsnum == 51) /* Sperical Harmonic Complex Packing */ { getpoly(cgrib + lpos3, &JJ, &KK, &MM); if (JJ != 0 && KK != 0 && MM != 0) @@ -319,7 +319,7 @@ g2_addfield(unsigned char *cgrib, g2int ipdsnum, g2int *ipdstmpl, } #if defined USE_JPEG2000 || defined USE_OPENJPEG else if (idrsnum == 40 || idrsnum == 40000) - { /* JPEG2000 encoding */ + { /* JPEG2000 encoding */ if (ibmap == 255) { getdim(cgrib + lpos3, &width, &height, &iscan); @@ -334,7 +334,7 @@ g2_addfield(unsigned char *cgrib, g2int ipdsnum, g2int *ipdstmpl, height = 1; } else if ((iscan & 32) == 32) - { /* Scanning mode: bit 3 */ + { /* Scanning mode: bit 3 */ itemp = width; width = height; height = itemp; @@ -348,10 +348,10 @@ g2_addfield(unsigned char *cgrib, g2int ipdsnum, g2int *ipdstmpl, lcpack = nsize; jpcpack(pfld, width, height, idrstmpl, cpack, &lcpack); } -#endif /* USE_JPEG2000 */ +#endif /* USE_JPEG2000 */ #ifdef USE_PNG else if (idrsnum == 41 || idrsnum == 40010) - { /* PNG encoding */ + { /* PNG encoding */ if (ibmap == 255) { getdim(cgrib + lpos3, &width, &height, &iscan); @@ -366,7 +366,7 @@ g2_addfield(unsigned char *cgrib, g2int ipdsnum, g2int *ipdstmpl, height = 1; } else if ((iscan & 32) == 32) - { /* Scanning mode: bit 3 */ + { /* Scanning mode: bit 3 */ itemp = width; width = height; height = itemp; @@ -379,10 +379,10 @@ g2_addfield(unsigned char *cgrib, g2int ipdsnum, g2int *ipdstmpl, } pngpack(pfld, width, height, idrstmpl, cpack, &lcpack); } -#endif /* USE_PNG */ +#endif /* USE_PNG */ #ifdef USE_AEC else if (idrsnum == 42) - { /* AEC Encoding */ + { /* AEC Encoding */ if (ibmap == 255) { getdim(cgrib + lpos3, &width, &height, &iscan); @@ -397,7 +397,7 @@ g2_addfield(unsigned char *cgrib, g2int ipdsnum, g2int *ipdstmpl, height = 1; } else if ((iscan & 32) == 32) - { /* Scanning mode: bit 3 */ + { /* Scanning mode: bit 3 */ itemp = width; width = height; height = itemp; @@ -408,7 +408,7 @@ g2_addfield(unsigned char *cgrib, g2int ipdsnum, g2int *ipdstmpl, width = ndpts; height = 1; } - //printf("IN G2C, in g2_addfield, using AEC compression...\n"); + //printf("IN G2C, in g2_addfield, using AEC compression...\n"); lcpack = nsize; aecpack(pfld, width, height, idrstmpl, cpack, &lcpack); } @@ -419,7 +419,7 @@ g2_addfield(unsigned char *cgrib, g2int ipdsnum, g2int *ipdstmpl, return G2_ADDFIELD_BAD_DRT; } - /* Free temp space. */ + /* Free temp space. */ if (ibmap == 0 || ibmap == 254) { if (fld != pfld) @@ -436,13 +436,13 @@ g2_addfield(unsigned char *cgrib, g2int ipdsnum, g2int *ipdstmpl, } /* Add Section 5 - Data Representation Section */ - ibeg = iofst; /* Calculate offset for beginning of section 5 */ - iofst = ibeg + 32; /* leave space for length of section */ - sbit(cgrib, &five, iofst, 8); /* Store section number (5) */ + ibeg = iofst; /* Calculate offset for beginning of section 5 */ + iofst = ibeg + 32; /* leave space for length of section */ + sbit(cgrib, &five, iofst, 8); /* Store section number (5) */ iofst = iofst + 8; - sbit(cgrib, &ndpts, iofst, 32); /* Store num of actual data points */ + sbit(cgrib, &ndpts, iofst, 32); /* Store num of actual data points */ iofst = iofst + 32; - sbit(cgrib, &idrsnum, iofst, 16); /* Store Data Repr. Template num. */ + sbit(cgrib, &idrsnum, iofst, 16); /* Store Data Repr. Template num. */ iofst = iofst + 16; /* Pack up each input value in array idrstmpl into the */ @@ -469,17 +469,17 @@ g2_addfield(unsigned char *cgrib, g2int ipdsnum, g2int *ipdstmpl, sbit(cgrib, &lensec5, ibeg, 32); /* Add Section 6 - Bit-Map Section */ - ibeg = iofst; /* Calculate offset for beginning of section 6 */ - iofst = ibeg + 32; /* leave space for length of section */ - sbit(cgrib, &six, iofst, 8); /* Store section number (6) */ + ibeg = iofst; /* Calculate offset for beginning of section 6 */ + iofst = ibeg + 32; /* leave space for length of section */ + sbit(cgrib, &six, iofst, 8); /* Store section number (6) */ iofst = iofst + 8; - sbit(cgrib, &ibmap, iofst, 8); /* Store Bit Map indicator */ + sbit(cgrib, &ibmap, iofst, 8); /* Store Bit Map indicator */ iofst = iofst + 8; /* Store bitmap, if supplied */ if (ibmap == 0) { - sbits(cgrib, bmap, iofst, 1, 0, ngrdpts); /* Store BitMap */ + sbits(cgrib, bmap, iofst, 1, 0, ngrdpts); /* Store BitMap */ iofst = iofst + ngrdpts; } @@ -497,16 +497,16 @@ g2_addfield(unsigned char *cgrib, g2int ipdsnum, g2int *ipdstmpl, left = 8 - (iofst % 8); if (left != 8) { - sbit(cgrib, &zero, iofst, left); /* Pad with zeros to fill Octet */ + sbit(cgrib, &zero, iofst, left); /* Pad with zeros to fill Octet */ iofst = iofst + left; } lensec6 = (iofst - ibeg) / 8; sbit(cgrib, &lensec6, ibeg, 32); /* Add Section 7 - Data Section */ - ibeg = iofst; /* Calculate offset for beginning of section 7 */ - iofst = ibeg + 32; /* leave space for length of section */ - sbit(cgrib, &seven, iofst, 8); /* Store section number (7) */ + ibeg = iofst; /* Calculate offset for beginning of section 7 */ + iofst = ibeg + 32; /* leave space for length of section */ + sbit(cgrib, &seven, iofst, 8); /* Store section number (7) */ iofst = iofst + 8; /* Store Packed Binary Data values, if non-constant field. */ diff --git a/src/g2_addgrid.c b/src/g2_addgrid.c index 70a43265..29ad320b 100644 --- a/src/g2_addgrid.c +++ b/src/g2_addgrid.c @@ -5,14 +5,14 @@ * @author Stephen Gilbeert @date 2002-11-01 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /** * Packs a [Grid Definition Section (Section * 3)](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect3.shtml) - * and adds it to a GRIB2 message. + * and adds it to a GRIB2 message. * * This function is used with routines * g2_create(), g2_addlocal(), g2_addfield(), and g2_gribend() to @@ -84,7 +84,7 @@ g2_addgrid(unsigned char *cgrib, g2int *igds, g2int *igdstmpl, g2int *ideflist, /* Loop through all current sections of the GRIB message to find * the last section number. */ - len = 16; /* length of Section 0 */ + len = 16; /* length of Section 0 */ for (;;) { /* Get section number and length of next section. */ @@ -118,25 +118,25 @@ g2_addgrid(unsigned char *cgrib, g2int *igds, g2int *igdstmpl, g2int *ideflist, } /* Add Section 3 - Grid Definition Section. */ - ibeg = lencurr * 8; /* Calculate offset for beginning of section 3 */ - iofst = ibeg + 32; /* leave space for length of section */ - sbit(cgrib, &three, iofst, 8); /* Store section number (3) */ + ibeg = lencurr * 8; /* Calculate offset for beginning of section 3 */ + iofst = ibeg + 32; /* leave space for length of section */ + sbit(cgrib, &three, iofst, 8); /* Store section number (3) */ iofst = iofst + 8; - sbit(cgrib, igds+0, iofst, 8); /* Store source of Grid def. */ + sbit(cgrib, igds + 0, iofst, 8); /* Store source of Grid def. */ iofst = iofst + 8; - sbit(cgrib, igds+1, iofst, 32); /* Store number of data pts. */ + sbit(cgrib, igds + 1, iofst, 32); /* Store number of data pts. */ iofst = iofst + 32; - sbit(cgrib, igds+2, iofst, 8); /* Store number of extra octets. */ + sbit(cgrib, igds + 2, iofst, 8); /* Store number of extra octets. */ iofst = iofst + 8; - sbit(cgrib, igds+3, iofst, 8); /* Store interp. of extra octets. */ + sbit(cgrib, igds + 3, iofst, 8); /* Store interp. of extra octets. */ iofst = iofst + 8; /* if Octet 6 is not equal to zero, Grid Definition Template may * not be supplied. */ if (igds[0] == 0) - sbit(cgrib, igds+4, iofst, 16); /* Store Grid Def Template num. */ + sbit(cgrib, igds + 4, iofst, 16); /* Store Grid Def Template num. */ else - sbit(cgrib, &miss, iofst, 16); /* Store missing value as Grid Def Template num. */ + sbit(cgrib, &miss, iofst, 16); /* Store missing value as Grid Def Template num. */ iofst = iofst + 16; /* Get Grid Definition Template. */ @@ -162,12 +162,12 @@ g2_addgrid(unsigned char *cgrib, g2int *igds, g2int *igdstmpl, g2int *ideflist, { nbits = abs(mapgrid->map[i]) * 8; if ((mapgrid->map[i] >= 0) || (igdstmpl[i] >= 0)) - sbit(cgrib, igdstmpl+i, iofst, nbits); + sbit(cgrib, igdstmpl + i, iofst, nbits); else { sbit(cgrib, &one, iofst, 1); temp = abs(igdstmpl[i]); - sbit(cgrib, &temp, iofst+1, nbits-1); + sbit(cgrib, &temp, iofst + 1, nbits - 1); } iofst = iofst + nbits; } diff --git a/src/g2_addlocal.c b/src/g2_addlocal.c index 45db756c..76a92935 100644 --- a/src/g2_addlocal.c +++ b/src/g2_addlocal.c @@ -3,13 +3,13 @@ * @author Stephen Gilbeert @date 2002-11-01 */ -#include #include "grib2_int.h" +#include /** * Adds a [Local Use Section (Section * 2)](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect2.shtml) - * to a GRIB2 message. + * to a GRIB2 message. * * This function is used with routines g2_create(), g2_addgrid(), * g2_addfield(), and g2_gribend() to create a complete GRIB2 message. @@ -57,7 +57,7 @@ g2_addlocal(unsigned char *cgrib, unsigned char *csec2, g2int lcsec2) /* Loop through all current sections of the GRIB message to find * the last section number. */ - len = 16; /* length of Section 0 */ + len = 16; /* length of Section 0 */ for (;;) { /* Get section number and length of next section. */ @@ -91,9 +91,9 @@ g2_addlocal(unsigned char *cgrib, unsigned char *csec2, g2int lcsec2) } /* Add Section 2 - Local Use Section. */ - ibeg = lencurr * 8; /* Calculate offset for beginning of section 2 */ - iofst = ibeg + 32; /* leave space for length of section */ - sbit(cgrib, &two, iofst, 8); /* Store section number (2) */ + ibeg = lencurr * 8; /* Calculate offset for beginning of section 2 */ + iofst = ibeg + 32; /* leave space for length of section */ + sbit(cgrib, &two, iofst, 8); /* Store section number (2) */ istart = lencurr + 5; k = 0; for (j = istart; j < istart + lcsec2; j++) @@ -101,7 +101,7 @@ g2_addlocal(unsigned char *cgrib, unsigned char *csec2, g2int lcsec2) /* Calculate length of section 2 and store it in octets 1-4 of * section 2. */ - lensec2 = lcsec2 + 5; /* bytes */ + lensec2 = lcsec2 + 5; /* bytes */ sbit(cgrib, &lensec2, ibeg, 32); /* Update current byte total of message in Section 0. */ diff --git a/src/g2_create.c b/src/g2_create.c index c028d56c..bf84f782 100644 --- a/src/g2_create.c +++ b/src/g2_create.c @@ -4,11 +4,11 @@ * @author Stephen Gilbert @date 2002-10-31 */ -#include #include "grib2_int.h" +#include #define MAPSEC1LEN 13 /**< Length of Map Section 1. */ -#define LENSEC0 16 /**< Length of GRIB Section 0. */ +#define LENSEC0 16 /**< Length of GRIB Section 0. */ /** * Initialize a new GRIB2 message and pack GRIB2 @@ -87,17 +87,17 @@ g2_create(unsigned char *cgrib, g2int *listsec0, g2int *listsec1) /* Pack Section 0 - Indicator Section (except for total length of * GRIB message). */ - cgrib[0] = 0x47; /* 'G' */ - cgrib[1] = 0x52; /* 'R' */ - cgrib[2] = 0x49; /* 'I' */ - cgrib[3] = 0x42; /* 'B' */ - sbit(cgrib, &zero, 32, 16); /* reserved for future use */ + cgrib[0] = 0x47; /* 'G' */ + cgrib[1] = 0x52; /* 'R' */ + cgrib[2] = 0x49; /* 'I' */ + cgrib[3] = 0x42; /* 'B' */ + sbit(cgrib, &zero, 32, 16); /* reserved for future use */ sbit(cgrib, listsec0 + 0, 48, 8); /* Discipline */ sbit(cgrib, listsec0 + 1, 56, 8); /* GRIB edition number */ /* Pack Section 1 - Identification Section. */ - ibeg = LENSEC0 * 8; /* Calculate offset for beginning of section 1. */ - iofst = ibeg + 32; /* Leave space for length of section. */ + ibeg = LENSEC0 * 8; /* Calculate offset for beginning of section 1. */ + iofst = ibeg + 32; /* Leave space for length of section. */ sbit(cgrib, &one, iofst, 8); /* Store section number (1). */ iofst = iofst + 8; diff --git a/src/g2_free.c b/src/g2_free.c index e3b4981b..c56a0dfb 100644 --- a/src/g2_free.c +++ b/src/g2_free.c @@ -4,8 +4,8 @@ * @author Stephen Gilbeert @date 2002-10-28 */ +#include "grib2_int.h" #include -#include "grib2_int.h" /** * Free memory that was allocated for struct ::gribfield. diff --git a/src/g2_getfld.c b/src/g2_getfld.c index e2520a34..5f177617 100644 --- a/src/g2_getfld.c +++ b/src/g2_getfld.c @@ -3,13 +3,13 @@ * applicable), and the unpacked data for a given data field. * @author Stephen Gilbert @date 2002-10-28 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /** * Return all the metadata, template values, bit-map - * (if applicable), and the unpacked data for a data field. + * (if applicable), and the unpacked data for a data field. * * All of the information returned is stored in a ::gribfield * structure, which is defined in file grib2.h. Users of this routine @@ -120,7 +120,7 @@ g2_getfld(unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand, istart = -1; for (j = 0; j < 100; j++) { - if (cgrib[j] == 'G' && cgrib[j + 1] == 'R' &&cgrib[j + 2] == 'I' && + if (cgrib[j] == 'G' && cgrib[j + 1] == 'R' && cgrib[j + 2] == 'I' && cgrib[j + 3] == 'B') { istart = j; @@ -136,12 +136,12 @@ g2_getfld(unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand, /* Unpack Section 0 - Indicator Section. */ iofst = 8 * (istart + 6); - gbit(cgrib, &disc, iofst, 8); /* Discipline */ + gbit(cgrib, &disc, iofst, 8); /* Discipline */ iofst = iofst + 8; - gbit(cgrib, &ver, iofst, 8); /* GRIB edition number */ + gbit(cgrib, &ver, iofst, 8); /* GRIB edition number */ iofst = iofst + 8; iofst = iofst + 32; - gbit(cgrib, &lengrib, iofst, 32); /* Length of GRIB message */ + gbit(cgrib, &lengrib, iofst, 32); /* Length of GRIB message */ iofst = iofst + 32; lensec0 = 16; ipos = istart + lensec0; @@ -178,9 +178,9 @@ g2_getfld(unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand, /* Get length of Section and Section number. */ iofst = ipos * 8; - gbit(cgrib, &lensec, iofst, 32); /* Get Length of Section */ + gbit(cgrib, &lensec, iofst, 32); /* Get Length of Section */ iofst = iofst + 32; - gbit(cgrib, &isecnum, iofst, 8); /* Get Section number */ + gbit(cgrib, &isecnum, iofst, 8); /* Get Section number */ iofst = iofst + 8; /* Check to see if section number is valid. */ @@ -194,7 +194,7 @@ g2_getfld(unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand, /* If found Section 1, decode elements in Identification Section. */ if (isecnum == 1) { - iofst = iofst - 40; /* reset offset to beginning of section */ + iofst = iofst - 40; /* reset offset to beginning of section */ if (g2_unpack1(cgrib, &iofst, &lgfld->idsect, &lgfld->idsectlen)) { g2_free(lgfld); @@ -206,7 +206,7 @@ g2_getfld(unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand, * is the latest one before the requested field. */ if (isecnum == 2) { - iofst = iofst - 40; /* reset offset to beginning of section */ + iofst = iofst - 40; /* reset offset to beginning of section */ if (lgfld->local) free(lgfld->local); if (g2_unpack2(cgrib, &iofst, &lgfld->locallen, &lgfld->local)) @@ -221,7 +221,7 @@ g2_getfld(unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand, * before the requested field. */ if (isecnum == 3) { - iofst = iofst - 40; /* reset offset to beginning of section */ + iofst = iofst - 40; /* reset offset to beginning of section */ if (lgfld->igdtmpl) free(lgfld->igdtmpl); if (lgfld->list_opt) @@ -254,7 +254,7 @@ g2_getfld(unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand, lgfld->ifldnum = ifldnum; lgfld->unpacked = unpack; lgfld->expanded = 0; - iofst = iofst - 40; /* reset offset to beginning of section */ + iofst = iofst - 40; /* reset offset to beginning of section */ if (g2_unpack4(cgrib, &iofst, &lgfld->ipdtnum, &lgfld->ipdtmpl, &lgfld->ipdtlen, &lgfld->coord_list, &lgfld->num_coord)) { @@ -270,7 +270,7 @@ g2_getfld(unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand, * requested. */ if (isecnum == 5 && numfld == ifldnum) { - iofst = iofst - 40; /* reset offset to beginning of section */ + iofst = iofst - 40; /* reset offset to beginning of section */ if (g2_unpack5(cgrib, &iofst, &lgfld->ndpts, &lgfld->idrtnum, &lgfld->idrtmpl, &lgfld->idrtlen)) { @@ -286,9 +286,9 @@ g2_getfld(unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand, if (isecnum == 6) { if (unpack) - { /* unpack bitmap */ - iofst = iofst - 40; /* reset offset to beginning of section */ - bmpsave = lgfld->bmap; /* save pointer to previous bitmap */ + { /* unpack bitmap */ + iofst = iofst - 40; /* reset offset to beginning of section */ + bmpsave = lgfld->bmap; /* save pointer to previous bitmap */ if (g2_unpack6(cgrib, &iofst, lgfld->ngrdpts, &lgfld->ibmap, &lgfld->bmap)) { @@ -297,7 +297,7 @@ g2_getfld(unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand, } have6 = 1; - if (lgfld->ibmap == 254) /* use previously specified bitmap */ + if (lgfld->ibmap == 254) /* use previously specified bitmap */ { if (bmpsave) lgfld->bmap = bmpsave; @@ -307,13 +307,13 @@ g2_getfld(unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand, return G2_GETFLD_NO_BITMAP; } } - else /* get rid of it */ + else /* get rid of it */ if (bmpsave) free(bmpsave); } else - { /* do not unpack bitmap */ - gbit(cgrib, &lgfld->ibmap, iofst, 8); /* Get BitMap Indicator */ + { /* do not unpack bitmap */ + gbit(cgrib, &lgfld->ibmap, iofst, 8); /* Get BitMap Indicator */ have6 = 1; } } @@ -322,7 +322,7 @@ g2_getfld(unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand, * requested. */ if (isecnum == 7 && numfld == ifldnum && unpack) { - iofst = iofst - 40; /* reset offset to beginning of section */ + iofst = iofst - 40; /* reset offset to beginning of section */ if ((jerr = g2_unpack7(cgrib, &iofst, lgfld->igdtnum, lgfld->igdtmpl, lgfld->idrtnum, lgfld->idrtmpl, lgfld->ndpts, &lgfld->fld))) @@ -364,7 +364,7 @@ g2_getfld(unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand, /* Check to see if we read pass the end of the GRIB message * and missed the terminator string '7777'. */ - ipos = ipos + lensec; /* Update beginning of section pointer */ + ipos = ipos + lensec; /* Update beginning of section pointer */ if (ipos > istart + lengrib) { printf("g2_getfld: '7777' not found at end of GRIB message.\n"); diff --git a/src/g2_gribend.c b/src/g2_gribend.c index dd42756a..1308a54e 100644 --- a/src/g2_gribend.c +++ b/src/g2_gribend.c @@ -3,12 +3,12 @@ * been added. * @author Stephen Gilbert @date 2002-10-31 */ -#include #include "grib2_int.h" +#include /** * Finalize a GRIB2 message after all grids and fields - * have been added. + * have been added. * * This function adds the End Section ("7777") to the end of * the GRIB message and calculates the length and stores it in the @@ -36,11 +36,12 @@ * * @author Stephen Gilbert @date 2002-10-31 */ -g2int g2_gribend(unsigned char *cgrib) +g2int +g2_gribend(unsigned char *cgrib) { g2int iofst, lencurr, len, ilen, isecnum; g2int lengrib; - unsigned char seven = 0x37; /* '7' */ + unsigned char seven = 0x37; /* '7' */ int ret; /* Check for GRIB header and terminator. Translate the error codes @@ -55,7 +56,7 @@ g2int g2_gribend(unsigned char *cgrib) /* Loop through all current sections of the GRIB message to find * the last section number. */ - len = 16; /* Length of Section 0. */ + len = 16; /* Length of Section 0. */ for (;;) { /* Get number and length of next section. */ @@ -81,7 +82,7 @@ g2int g2_gribend(unsigned char *cgrib) } /* Can only add End Section (Section 8) after Section 7. */ - if (isecnum != 7 ) + if (isecnum != 7) { printf("g2_gribend: Section 8 can only be added after Section 7.\n"); printf("g2_gribend: Section %ld was the last found in given GRIB message.\n", isecnum); diff --git a/src/g2_info.c b/src/g2_info.c index 79ed5da1..a3e867e4 100644 --- a/src/g2_info.c +++ b/src/g2_info.c @@ -7,14 +7,14 @@ * @author Stephen Gilbeert @date 2002-10-28 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /** * Search through a GRIB2 message and return the * number of gridded fields found in the message and the number (and - * maximum size) of Local Use Sections. + * maximum size) of Local Use Sections. * * Other checks are performed to see if the message is a valid GRIB2 * message. @@ -101,13 +101,13 @@ g2_info(unsigned char *cgrib, g2int *listsec0, g2int *listsec1, /* Unpack Section 0 - Indicator Section. */ iofst = 8 * (istart + 6); - gbit(cgrib, listsec0, iofst, 8); /* Discipline */ + gbit(cgrib, listsec0, iofst, 8); /* Discipline */ iofst = iofst + 8; - gbit(cgrib, &listsec0[1], iofst, 8); /* GRIB edition number */ + gbit(cgrib, &listsec0[1], iofst, 8); /* GRIB edition number */ iofst = iofst + 8; /* iofst = iofst + 32; */ /* gbit(cgrib, &lengrib, iofst, 32); /\* Length of GRIB message *\/ */ - gbit(cgrib, &lengrib, iofst, 64); /* Length of GRIB message */ + gbit(cgrib, &lengrib, iofst, 64); /* Length of GRIB message */ /* iofst = iofst + 32; */ iofst = iofst + 64; listsec0[2] = lengrib; @@ -123,9 +123,9 @@ g2_info(unsigned char *cgrib, g2int *listsec0, g2int *listsec1, } /* Unpack Section 1 - Identification Section */ - gbit(cgrib, &lensec1, iofst, 32); /* Length of Section 1 */ + gbit(cgrib, &lensec1, iofst, 32); /* Length of Section 1 */ iofst = iofst + 32; - gbit(cgrib, &isecnum, iofst, 8); /* Section number (1) */ + gbit(cgrib, &isecnum, iofst, 8); /* Section number (1) */ iofst = iofst + 8; if (isecnum != 1) { @@ -143,7 +143,7 @@ g2_info(unsigned char *cgrib, g2int *listsec0, g2int *listsec1, iofst = iofst + nbits; } ipos = ipos + lensec1; - LOG((3, "unpacked section 1, now at byte %ld", ipos)); + LOG((3, "unpacked section 1, now at byte %ld", ipos)); /* Loop through the remaining sections to see if they are * valid. Also count the number of times Section 2 and Section @@ -153,7 +153,7 @@ g2_info(unsigned char *cgrib, g2int *listsec0, g2int *listsec1, if (cgrib[ipos] == '7' && cgrib[ipos + 1] == '7' && cgrib[ipos + 2] == '7' && cgrib[ipos + 3] == '7') { - LOG((3, "found 7777 at byte %ld", ipos)); + LOG((3, "found 7777 at byte %ld", ipos)); ipos = ipos + 4; if (ipos != (istart + lengrib)) { @@ -164,12 +164,12 @@ g2_info(unsigned char *cgrib, g2int *listsec0, g2int *listsec1, } iofst = ipos * 8; - gbit(cgrib, &lensec, iofst, 32); /* Get Length of Section */ + gbit(cgrib, &lensec, iofst, 32); /* Get Length of Section */ iofst = iofst + 32; - gbit(cgrib, &isecnum, iofst, 8); /* Get Section number */ - LOG((3, "found section number %ld of length %ld", isecnum, lensec)); + gbit(cgrib, &isecnum, iofst, 8); /* Get Section number */ + LOG((3, "found section number %ld of length %ld", isecnum, lensec)); iofst = iofst + 8; - ipos = ipos + lensec; /* Update beginning of section pointer */ + ipos = ipos + lensec; /* Update beginning of section pointer */ if (ipos > (istart + lengrib)) { printf("g2_info: '7777' not found at end of GRIB message.\n"); diff --git a/src/g2_miss.c b/src/g2_miss.c index d668df59..fdddebfa 100644 --- a/src/g2_miss.c +++ b/src/g2_miss.c @@ -27,7 +27,7 @@ g2_miss(gribfield *gfld, float *rmiss, int *nmiss) /* Missing value management currnetly only used in DRT's 5.2 and * 5.3. */ - if (gfld->idrtnum != 2 && gfld->idrtnum != 3) + if (gfld->idrtnum != 2 && gfld->idrtnum != 3) { *nmiss = 0; return; @@ -38,7 +38,7 @@ g2_miss(gribfield *gfld, float *rmiss, int *nmiss) { *nmiss = 1; if (itype == 0) - rdieee(gfld->idrtmpl + 7, rmiss+0, 1); + rdieee(gfld->idrtmpl + 7, rmiss + 0, 1); else rmiss[0] = (float)gfld->idrtmpl[7]; } diff --git a/src/g2_unpack1.c b/src/g2_unpack1.c index 3f7376a8..e39c835f 100644 --- a/src/g2_unpack1.c +++ b/src/g2_unpack1.c @@ -6,9 +6,9 @@ * @author Stephen Gilbert @date 2002-10-29 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /** * Unpacks [Section 1 - Identification @@ -62,9 +62,9 @@ g2_unpack1(unsigned char *cgrib, g2int *iofst, g2int **ids, g2int *idslen) *idslen = 13; - gbit(cgrib, &lensec, *iofst, 32); /* Get Length of Section */ + gbit(cgrib, &lensec, *iofst, 32); /* Get Length of Section */ *iofst = *iofst + 32; - gbit(cgrib, &isecnum, *iofst, 8); /* Get Section Number */ + gbit(cgrib, &isecnum, *iofst, 8); /* Get Section Number */ *iofst = *iofst + 8; if (isecnum != 1) diff --git a/src/g2_unpack2.c b/src/g2_unpack2.c index 25feca12..06240f37 100644 --- a/src/g2_unpack2.c +++ b/src/g2_unpack2.c @@ -3,9 +3,9 @@ * @author Stephen Gilbert @date 2002-10-31 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /** * Unpack [Section 2 (Local Use diff --git a/src/g2_unpack3.c b/src/g2_unpack3.c index beadb781..012e5c62 100644 --- a/src/g2_unpack3.c +++ b/src/g2_unpack3.c @@ -3,9 +3,9 @@ * message. * @author Stephen Gilbert @date 2002-10-31 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /** * Unpack [Section 3 (Grid Definition @@ -71,9 +71,9 @@ g2_unpack3(unsigned char *cgrib, g2int *iofst, g2int **igds, g2int **igdstmpl, *igdstmpl = NULL; *ideflist = NULL; - gbit(cgrib, &lensec, *iofst, 32); /* Get Length of Section */ + gbit(cgrib, &lensec, *iofst, 32); /* Get Length of Section */ *iofst = *iofst + 32; - gbit(cgrib, &isecnum, *iofst, 8); /* Get Section Number */ + gbit(cgrib, &isecnum, *iofst, 8); /* Get Section Number */ *iofst = *iofst + 8; if (isecnum != 3) @@ -86,22 +86,22 @@ g2_unpack3(unsigned char *cgrib, g2int *iofst, g2int **igds, g2int **igdstmpl, ligds = calloc(5, sizeof(g2int)); *igds = ligds; - gbit(cgrib, &ligds[0], *iofst, 8); /* Get source of Grid def. */ + gbit(cgrib, &ligds[0], *iofst, 8); /* Get source of Grid def. */ *iofst = *iofst + 8; - gbit(cgrib, &ligds[1], *iofst, 32); /* Get number of grid pts. */ + gbit(cgrib, &ligds[1], *iofst, 32); /* Get number of grid pts. */ *iofst = *iofst + 32; - gbit(cgrib, &ligds[2], *iofst, 8); /* Get num octets for opt. list */ + gbit(cgrib, &ligds[2], *iofst, 8); /* Get num octets for opt. list */ *iofst = *iofst + 8; - gbit(cgrib, &ligds[3], *iofst, 8); /* Get interpret. for opt. list */ + gbit(cgrib, &ligds[3], *iofst, 8); /* Get interpret. for opt. list */ *iofst = *iofst + 8; - gbit(cgrib, &ligds[4], *iofst, 16); /* Get Grid Def Template num. */ + gbit(cgrib, &ligds[4], *iofst, 16); /* Get Grid Def Template num. */ *iofst = *iofst + 16; if (ligds[4] != 65535) { /* Get Grid Definition Template */ if (!(mapgrid = getgridtemplate(ligds[4]))) - { /* undefined template */ + { /* undefined template */ free(ligds); return G2_UNPACK3_BAD_GDT; } @@ -180,7 +180,7 @@ g2_unpack3(unsigned char *cgrib, g2int *iofst, g2int **igds, g2int **igdstmpl, free(mapgrid); } else - { /* No Grid Definition Template */ + { /* No Grid Definition Template */ *mapgridlen = 0; *igdstmpl = 0; } @@ -210,5 +210,5 @@ g2_unpack3(unsigned char *cgrib, g2int *iofst, g2int **igds, g2int **igdstmpl, *ideflist = NULL; } - return G2_NO_ERROR; /* End of Section 3 processing */ + return G2_NO_ERROR; /* End of Section 3 processing */ } diff --git a/src/g2_unpack4.c b/src/g2_unpack4.c index 705dd6cc..f9efb803 100644 --- a/src/g2_unpack4.c +++ b/src/g2_unpack4.c @@ -3,9 +3,9 @@ * @author Stephen Gilbert @date 2002-10-31 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /** * Unpack [Section 4 (Product Definition @@ -56,9 +56,9 @@ g2_unpack4(unsigned char *cgrib, g2int *iofst, g2int *ipdsnum, g2int **ipdstmpl, *ipdstmpl = NULL; *coordlist = NULL; - gbit(cgrib, &lensec, *iofst, 32); /* Get Length of Section */ + gbit(cgrib, &lensec, *iofst, 32); /* Get Length of Section */ *iofst = *iofst + 32; - gbit(cgrib, &isecnum, *iofst, 8); /* Get Section Number */ + gbit(cgrib, &isecnum, *iofst, 8); /* Get Section Number */ *iofst = *iofst + 8; if (isecnum != 4) @@ -68,9 +68,9 @@ g2_unpack4(unsigned char *cgrib, g2int *iofst, g2int *ipdsnum, g2int **ipdstmpl, return G2_UNPACK_BAD_SEC; } - gbit(cgrib, numcoord, *iofst, 16); /* Get num of coordinate values */ + gbit(cgrib, numcoord, *iofst, 16); /* Get num of coordinate values */ *iofst = *iofst + 16; - gbit(cgrib, ipdsnum, *iofst, 16); /* Get Prod. Def Template num. */ + gbit(cgrib, ipdsnum, *iofst, 16); /* Get Prod. Def Template num. */ *iofst = *iofst + 16; /* Get Product Definition Template */ @@ -108,7 +108,8 @@ g2_unpack4(unsigned char *cgrib, g2int *iofst, g2int *ipdsnum, g2int **ipdstmpl, { gbit(cgrib, &isign, *iofst, 1); gbit(cgrib, lipdstmpl + i, *iofst + 1, nbits - 1); - if (isign == 1) lipdstmpl[i] = -1 * lipdstmpl[i]; + if (isign == 1) + lipdstmpl[i] = -1 * lipdstmpl[i]; } *iofst = *iofst + nbits; } @@ -121,7 +122,7 @@ g2_unpack4(unsigned char *cgrib, g2int *iofst, g2int *ipdsnum, g2int **ipdstmpl, { free(mappds); mappds = extpdstemplate(*ipdsnum, lipdstmpl); - newlen = mappds->maplen+mappds->extlen; + newlen = mappds->maplen + mappds->extlen; lipdstmpl = realloc(lipdstmpl, newlen * sizeof(g2int)); *ipdstmpl = lipdstmpl; /* Unpack the rest of the Product Definition Template */ @@ -136,7 +137,7 @@ g2_unpack4(unsigned char *cgrib, g2int *iofst, g2int *ipdsnum, g2int **ipdstmpl, else { gbit(cgrib, &isign, *iofst, 1); - gbit(cgrib, lipdstmpl + i, *iofst+1, nbits-1); + gbit(cgrib, lipdstmpl + i, *iofst + 1, nbits - 1); if (isign == 1) lipdstmpl[i] = -1 * lipdstmpl[i]; } diff --git a/src/g2_unpack5.c b/src/g2_unpack5.c index 72ffb9f4..2cd3780e 100644 --- a/src/g2_unpack5.c +++ b/src/g2_unpack5.c @@ -3,9 +3,9 @@ * @author Stephen Gilbert @date 2002-10-31 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /** * Unpack Section 5 (Data Representation Section) of a GRIB2 message. @@ -45,11 +45,11 @@ g2_unpack5(unsigned char *cgrib, g2int *iofst, g2int *ndpts, g2int *idrsnum, g2int *lidrstmpl = 0; gtemplate *mapdrs; - *idrstmpl = 0; /* NULL*/ + *idrstmpl = 0; /* NULL*/ - gbit(cgrib, &lensec, *iofst, 32); /* Get Length of Section */ + gbit(cgrib, &lensec, *iofst, 32); /* Get Length of Section */ *iofst = *iofst + 32; - gbit(cgrib, &isecnum, *iofst, 8); /* Get Section Number */ + gbit(cgrib, &isecnum, *iofst, 8); /* Get Section Number */ *iofst = *iofst + 8; if (isecnum != 5) @@ -59,9 +59,9 @@ g2_unpack5(unsigned char *cgrib, g2int *iofst, g2int *ndpts, g2int *idrsnum, return G2_UNPACK_BAD_SEC; } - gbit(cgrib, ndpts, *iofst, 32); /* Get num of data points */ + gbit(cgrib, ndpts, *iofst, 32); /* Get num of data points */ *iofst = *iofst + 32; - gbit(cgrib, idrsnum, *iofst, 16); /* Get Data Rep Template Num. */ + gbit(cgrib, idrsnum, *iofst, 16); /* Get Data Rep Template Num. */ *iofst = *iofst + 16; /* Gen Data Representation Template */ diff --git a/src/g2_unpack6.c b/src/g2_unpack6.c index fbdad7d2..a6358af6 100644 --- a/src/g2_unpack6.c +++ b/src/g2_unpack6.c @@ -2,9 +2,9 @@ * @brief Unpack Section 6 (Bit-Map Section) of a GRIB2 message. * @author Stephen Gilbert @date 2002-10-31 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /** * Unpack Section 6 (Bit-Map Section) of a GRIB2 message. @@ -38,8 +38,8 @@ g2_unpack6(unsigned char *cgrib, g2int *iofst, g2int ngpts, g2int *ibmap, *bmap = NULL; - *iofst = *iofst + 32; /* skip Length of Section */ - gbit(cgrib, &isecnum, *iofst, 8); /* Get Section Number */ + *iofst = *iofst + 32; /* skip Length of Section */ + gbit(cgrib, &isecnum, *iofst, 8); /* Get Section Number */ *iofst = *iofst + 8; if (isecnum != 6) @@ -48,11 +48,11 @@ g2_unpack6(unsigned char *cgrib, g2int *iofst, g2int ngpts, g2int *ibmap, return G2_UNPACK_BAD_SEC; } - gbit(cgrib, ibmap, *iofst, 8); /* Get bit-map indicator */ + gbit(cgrib, ibmap, *iofst, 8); /* Get bit-map indicator */ *iofst = *iofst + 8; if (*ibmap == 0) - { /* Unpack bitmap */ + { /* Unpack bitmap */ if (ngpts > 0) lbmap = calloc(ngpts, sizeof(g2int)); if (!lbmap) diff --git a/src/g2_unpack7.c b/src/g2_unpack7.c index 64642fce..4b28ef30 100644 --- a/src/g2_unpack7.c +++ b/src/g2_unpack7.c @@ -15,9 +15,9 @@ * 2023-10-16 | Engle | Added support for DRT 5.42, AEC compression. * */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /** * Unpacks Section 7 (Data Section) of a GRIB2 message. @@ -46,9 +46,9 @@ * (N=idrsnum). Each element of this integer array contains an entry * (in the order specified) of Data Representation Template 5.N * @param ndpts Number of data points to be unpacked and returned. - * @param v1 If non-zero, then act like the V1 G2C API. This includes: + * @param v1 If non-zero, then act like the V1 G2C API. This includes: * - printing error messages to stderr in the event of error. - * - returning V1 error codes. + * - returning V1 error codes. * @param fld Pointer to a float pointer which gets a pointer to an * array allocated by this function to hold the unpacked data. This * memory must be freed by the caller. @@ -72,10 +72,10 @@ g2c_unpack7_int(unsigned char *cgrib, g2int *iofst, g2int igdsnum, g2int *igdstm float *lfld; assert(cgrib && iofst && idrstmpl && fld); - + LOG((2, "g2c_unpack7_int *iofst %ld igdsnum %ld idrsnum %ld ndpts %ld v1 %d", *iofst, igdsnum, idrsnum, ndpts, v1)); - + /* Get Length of Section */ gbit(cgrib, &lensec, *iofst, 32); *iofst = *iofst + 32; @@ -108,7 +108,7 @@ g2c_unpack7_int(unsigned char *cgrib, g2int *iofst, g2int igdsnum, g2int *igdstm } else if (idrsnum == 2 || idrsnum == 3) { - if (comunpack(cgrib+ipos, lensec, idrsnum, idrstmpl, ndpts, *fld)) + if (comunpack(cgrib + ipos, lensec, idrsnum, idrstmpl, ndpts, *fld)) return G2_UNPACK7_CORRUPT_SEC; } else if (idrsnum == 50) @@ -139,24 +139,25 @@ g2c_unpack7_int(unsigned char *cgrib, g2int *iofst, g2int igdsnum, g2int *igdstm { jpcunpack(cgrib + ipos, lensec - 5, idrstmpl, ndpts, *fld); } -#endif /* USE_JPEG2000 */ +#endif /* USE_JPEG2000 */ #ifdef USE_PNG else if (idrsnum == 41 || idrsnum == 40010) { pngunpack(cgrib + ipos, lensec - 5, idrstmpl, ndpts, *fld); } -#endif /* USE_PNG */ +#endif /* USE_PNG */ #ifdef USE_AEC else if (idrsnum == 42) { aecunpack(cgrib + ipos, lensec - 5, idrstmpl, ndpts, *fld); } -#endif /* USE_AEC */ +#endif /* USE_AEC */ else { if (v1) fprintf(stderr, "g2_unpack7: Data Representation Template 5.%d not yet " - "implemented.\n", (int)idrsnum); + "implemented.\n", + (int)idrsnum); if (lfld) free(lfld); *fld = NULL; @@ -277,18 +278,18 @@ g2c_unpack7(unsigned char *cgrib, int igdsnum, int gds_tmpl_len, long long int * if (!(igdstmpl = malloc(gds_tmpl_len * sizeof(g2int)))) return G2C_ENOMEM; if (!(idrstmpl = malloc(drs_tmpl_len * sizeof(g2int)))) - return G2C_ENOMEM; + return G2C_ENOMEM; /* Copy the templates. */ if (gds_tmpl_len) for (i = 0; i < gds_tmpl_len; i++) igdstmpl[i] = gdstmpl[i]; for (i = 0; i < drs_tmpl_len; i++) - idrstmpl[i] = drstmpl[i]; - + idrstmpl[i] = drstmpl[i]; + /* Call the internal function that does the work. */ ret = g2c_unpack7_int(cgrib, &iofst, igdsnum, igdstmpl, idrsnum, idrstmpl, - ndpts, 0, &fld); + ndpts, 0, &fld); /* Free the g2int versions of the templates. */ if (igdstmpl) @@ -297,5 +298,3 @@ g2c_unpack7(unsigned char *cgrib, int igdsnum, int gds_tmpl_len, long long int * return ret; } - - diff --git a/src/g2ccompare.c b/src/g2ccompare.c index ec97c836..99671f7d 100644 --- a/src/g2ccompare.c +++ b/src/g2ccompare.c @@ -5,8 +5,8 @@ * @author Ed Hartnett @date Dec 28, 2022 */ #include "grib2_int.h" -#include #include +#include /** Global file information. */ extern G2C_FILE_INFO_T g2c_file[G2C_MAX_FILES + 1]; @@ -51,7 +51,7 @@ g2c_compare(int g2cid1, int g2cid2) for (m = 0; m < g2c_file[g2cid1].num_messages; m++) { int fld; - + if (msg1->discipline != msg2->discipline) return G2C_ERROR; if (msg1->center != msg2->center || msg1->subcenter != msg2->subcenter || @@ -64,7 +64,7 @@ g2c_compare(int g2cid1, int g2cid2) if (msg1->num_local != msg2->num_local || msg1->num_fields != msg2->num_fields) return G2C_ERROR; - /* For each field, print info. */ + /* For each field, print info. */ for (fld = 0; fld < msg1->num_fields; fld++) { G2C_SECTION_INFO_T *sec_1, *sec_2; @@ -99,7 +99,7 @@ g2c_compare(int g2cid1, int g2cid2) return G2C_ERROR; for (t = 0; t < sec_1->template_len; t++) if (sec_1->template[t] != sec_2->template[t]) - return G2C_ERROR; + return G2C_ERROR; /* Find the sec3 that applies to this field. */ for (sec3_1 = sec_1; sec3_1; sec3_1 = sec3_1->prev) @@ -124,8 +124,8 @@ g2c_compare(int g2cid1, int g2cid2) return G2C_ERROR; for (t = 0; t < sec3_1->template_len; t++) if (sec3_1->template[t] != sec3_2->template[t]) - return G2C_ERROR; - + return G2C_ERROR; + /* Find the sec5 that applies to this field. */ for (sec5_1 = sec_1; sec5_1; sec5_1 = sec5_1->next) if (sec5_1->sec_num == 5) @@ -146,8 +146,7 @@ g2c_compare(int g2cid1, int g2cid2) return G2C_ERROR; for (t = 0; t < sec5_1->template_len; t++) if (sec5_1->template[t] != sec5_2->template[t]) - return G2C_ERROR; - + return G2C_ERROR; } msg1 = msg1->next; msg2 = msg2->next; diff --git a/src/g2ccsv.c b/src/g2ccsv.c index f4d11bfe..eb28f437 100644 --- a/src/g2ccsv.c +++ b/src/g2ccsv.c @@ -4,13 +4,13 @@ * @author Ed Hartnett @date 8/25/22 */ +#include #include #include #include -#include /** Contains the parsed CSV document. */ -FILE* doc; +FILE *doc; /** Pointer to the list of code tables. */ G2C_CODE_TABLE_T *g2c_table = NULL; @@ -26,12 +26,11 @@ g2c_print_tables() for (t = g2c_table; t; t = t->next) { - G2C_CODE_ENTRY_T *e; - - printf("%s\n", t->title); - for (e = t->entry; e; e = e->next) - printf("code %s desc %s status %s\n", e->code, e->desc, e->status); - + G2C_CODE_ENTRY_T *e; + + printf("%s\n", t->title); + for (e = t->entry; e; e = e->next) + printf("code %s desc %s status %s\n", e->code, e->desc, e->status); } } @@ -47,23 +46,23 @@ g2c_free_tables() /* If g2c_table is NULL, then tables have already been * freed. */ if (!g2c_table) - return; + return; /* Free each table. */ for (t = g2c_table; t; t = the_next) { - G2C_CODE_ENTRY_T *e; - G2C_CODE_ENTRY_T *e_next; - - /* Free each entry in the table. */ - the_next = t->next; - for (e = t->entry; e; e = e_next) - { - e_next = e->next; - free(e); - } - - free(t); + G2C_CODE_ENTRY_T *e; + G2C_CODE_ENTRY_T *e_next; + + /* Free each entry in the table. */ + the_next = t->next; + for (e = t->entry; e; e = e_next) + { + e_next = e->next; + free(e); + } + + free(t); } /* Set to NULL so we all know g2c_table has been freed. */ @@ -88,33 +87,32 @@ g2c_find_desc_str(char *title, char *code, char *desc) int found = 0; /* Check inputs. */ - if (!title || strlen(title) > G2C_MAX_GRIB_TITLE_LEN - || !code || strlen(code) > G2C_MAX_GRIB_CODE_LEN || !desc) - return G2C_EINVAL; - + if (!title || strlen(title) > G2C_MAX_GRIB_TITLE_LEN || !code || strlen(code) > G2C_MAX_GRIB_CODE_LEN || !desc) + return G2C_EINVAL; + /* Find table. */ for (t = g2c_table; !found && t; t = t->next) { - if (!strncmp(title, t->title, strlen(title))) - { - G2C_CODE_ENTRY_T *e = NULL; - - /* Find entry. */ - for (e = t->entry; e; e = e->next) - { - if (!strncmp(code, e->code, strlen(code))) - { - strcpy(desc, e->desc); - found++; - break; - } - } - } + if (!strncmp(title, t->title, strlen(title))) + { + G2C_CODE_ENTRY_T *e = NULL; + + /* Find entry. */ + for (e = t->entry; e; e = e->next) + { + if (!strncmp(code, e->code, strlen(code))) + { + strcpy(desc, e->desc); + found++; + break; + } + } + } } if (!found) - return G2C_ENOTFOUND; - + return G2C_ENOTFOUND; + return G2C_NOERROR; } @@ -152,8 +150,8 @@ g2c_find_table(char *key) G2C_CODE_TABLE_T *g; for (g = g2c_table; g; g = g->next) - if (!strncmp(key, g->title, G2C_MAX_GRIB_TITLE_LEN)) - return g; + if (!strncmp(key, g->title, G2C_MAX_GRIB_TITLE_LEN)) + return g; return NULL; } @@ -173,8 +171,8 @@ g2c_find_entry(char *desc, G2C_CODE_TABLE_T *table) G2C_CODE_ENTRY_T *e; for (e = table->entry; e; e = e->next) - if (!strncmp(desc, e->desc, G2C_MAX_GRIB_DESC_LEN)) - return e; + if (!strncmp(desc, e->desc, G2C_MAX_GRIB_DESC_LEN)) + return e; return NULL; } @@ -201,124 +199,124 @@ g2c_csv_init() /* If g2c_table is not NULL, then tables have already been * initialized. */ if (g2c_table) - return G2C_NOERROR; + return G2C_NOERROR; /* Ingest the CSV document. */ if (!(doc = fopen("CodeFlag.txt", "r"))) - return G2C_ECSV; + return G2C_ECSV; /* Skip header line */ - buf = fgets(line,max_line_size,doc); + buf = fgets(line, max_line_size, doc); - /* Go through the document and save table data. + /* Go through the document and save table data. * Each line is a table of codes. */ - while((buf = fgets(line,max_line_size,doc)) != NULL) - { - i = 0; - while(buf != NULL && i < num_columns) - { - G2C_CODE_TABLE_T *new_table = NULL; - - if (*buf == '\"') - { - tmp = strsep(&buf,"\""); - tmp = strsep(&buf,"\""); - key = strdup((const char*)tmp); - tmp = strsep(&buf,","); - } - else - { - tmp = strsep(&buf,","); - key = strdup((const char*)tmp); - } + while ((buf = fgets(line, max_line_size, doc)) != NULL) + { + i = 0; + while (buf != NULL && i < num_columns) + { + G2C_CODE_TABLE_T *new_table = NULL; - /* Title_en */ - if (i==0) - { - if (strlen(key) > G2C_MAX_GRIB_TITLE_LEN) - return G2C_ENAMETOOLONG; - if (!(my_table = g2c_find_table(key))) + if (*buf == '\"') { - if (!(new_table = calloc(1,sizeof(G2C_CODE_TABLE_T)))) - return G2C_ENOMEM; - strncpy(new_table->title, key,G2C_MAX_GRIB_TITLE_LEN); - my_table = new_table; + tmp = strsep(&buf, "\""); + tmp = strsep(&buf, "\""); + key = strdup((const char *)tmp); + tmp = strsep(&buf, ","); } - } - - if (my_table) + else { - /* CodeFlag */ - if (i==2) - { - G2C_CODE_ENTRY_T *e; + tmp = strsep(&buf, ","); + key = strdup((const char *)tmp); + } - if (!(new_entry = calloc(1,sizeof(G2C_CODE_ENTRY_T)))) - return G2C_ENOMEM; - if (strlen(key) > G2C_MAX_GRIB_CODE_LEN) + /* Title_en */ + if (i == 0) + { + if (strlen(key) > G2C_MAX_GRIB_TITLE_LEN) return G2C_ENAMETOOLONG; - strncpy(new_entry->code,key,G2C_MAX_GRIB_CODE_LEN); - - /* Add entry at end of list. */ - if (my_table->entry) + if (!(my_table = g2c_find_table(key))) { - for (e = my_table->entry; e->next; e = e->next); - e->next = new_entry; + if (!(new_table = calloc(1, sizeof(G2C_CODE_TABLE_T)))) + return G2C_ENOMEM; + strncpy(new_table->title, key, G2C_MAX_GRIB_TITLE_LEN); + my_table = new_table; } - else - my_table->entry = new_entry; - } - /* MeaningParameterDescription */ - if (i==4) - { - if (strlen(key) > G2C_MAX_GRIB_DESC_LEN) - return G2C_ENAMETOOLONG; - if (!new_entry) - return G2C_ECSV; - strncpy(new_entry->desc,key,G2C_MAX_GRIB_LEVEL_DESC_LEN); } - /* Status */ - if (i==8) + + if (my_table) { - if (strlen(key) > G2C_MAX_GRIB_STATUS_LEN) - return G2C_ENAMETOOLONG; - if (!new_entry) - return G2C_ECSV; - strncpy(new_entry->status,key,G2C_MAX_GRIB_STATUS_LEN); - } + /* CodeFlag */ + if (i == 2) + { + G2C_CODE_ENTRY_T *e; + + if (!(new_entry = calloc(1, sizeof(G2C_CODE_ENTRY_T)))) + return G2C_ENOMEM; + if (strlen(key) > G2C_MAX_GRIB_CODE_LEN) + return G2C_ENAMETOOLONG; + strncpy(new_entry->code, key, G2C_MAX_GRIB_CODE_LEN); + + /* Add entry at end of list. */ + if (my_table->entry) + { + for (e = my_table->entry; e->next; e = e->next) + ; + e->next = new_entry; + } + else + my_table->entry = new_entry; + } + /* MeaningParameterDescription */ + if (i == 4) + { + if (strlen(key) > G2C_MAX_GRIB_DESC_LEN) + return G2C_ENAMETOOLONG; + if (!new_entry) + return G2C_ECSV; + strncpy(new_entry->desc, key, G2C_MAX_GRIB_LEVEL_DESC_LEN); + } + /* Status */ + if (i == 8) + { + if (strlen(key) > G2C_MAX_GRIB_STATUS_LEN) + return G2C_ENAMETOOLONG; + if (!new_entry) + return G2C_ECSV; + strncpy(new_entry->status, key, G2C_MAX_GRIB_STATUS_LEN); + } } /* Add this table to our list of GRIB tables. */ if (new_table) { - if (!g2c_table) - g2c_table = new_table; - else - { - G2C_CODE_TABLE_T *g = g2c_table; - - /* Go to end of list and add the table. */ - if (g) - { - for (; g->next; g = g->next) - ; - g->next = new_table; - } + if (!g2c_table) + g2c_table = new_table; else { - g2c_table = new_table; + G2C_CODE_TABLE_T *g = g2c_table; + + /* Go to end of list and add the table. */ + if (g) + { + for (; g->next; g = g->next) + ; + g->next = new_table; + } + else + { + g2c_table = new_table; + } } - } - new_table = NULL; + new_table = NULL; } free(key); - i++; - } - } + i++; + } + } - fclose(doc); + fclose(doc); return G2C_NOERROR; } - diff --git a/src/g2cdegrib2.c b/src/g2cdegrib2.c index 913398fc..e84fc401 100644 --- a/src/g2cdegrib2.c +++ b/src/g2cdegrib2.c @@ -6,8 +6,8 @@ * @author Ed Hartnett @date Sep 17, 2022 */ #include "grib2_int.h" -#include #include +#include /** Global file information. */ extern G2C_FILE_INFO_T g2c_file[G2C_MAX_FILES + 1]; @@ -16,7 +16,7 @@ extern G2C_FILE_INFO_T g2c_file[G2C_MAX_FILES + 1]; extern G2C_CODE_TABLE_T *g2c_table; /** Maximum length of "Type of first fixed surface" string. */ -#define G2C_MAX_TYPE_OF_FIXED_SURFACE_LEN 40 +#define G2C_MAX_TYPE_OF_FIXED_SURFACE_LEN 40 #define G2C_DATE_TIME_LEN 25 /**< Size of the date/time string. */ @@ -72,22 +72,21 @@ g2c_get_datetime(int ipdtn, long long int *ipdtmpl, short year, unsigned char mo 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; /* data ipos2 /7*0, 26, 33, 27, 29, 28, 42, 41, 27*0, 22, 30, 0, 0, 32, & */ /* 35, 43*0, 33, 109*0/ */ int ipos2[200] = { 0, 0, 0, 0, 0, 0, 0, 26, 33, 27, 29, 28, 42, 41, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 30, 0, 0, 32, 35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -97,8 +96,7 @@ g2c_get_datetime(int ipdtn, long long int *ipdtmpl, short year, unsigned char mo 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; /* tabbrev(1:100) = " " */ /* Check inputs. */ @@ -158,9 +156,9 @@ g2c_get_datetime(int ipdtn, long long int *ipdtmpl, short year, unsigned char mo /* Determine second unit of time range. */ if (ipdtn > 0) - iutpos2 = ipos2[ipdtn - 1]; + iutpos2 = ipos2[ipdtn - 1]; else - iutpos2 = 0; + iutpos2 = 0; switch (ipdtmpl[iutpos2]) { case 0: @@ -217,22 +215,22 @@ g2c_get_datetime(int ipdtn, long long int *ipdtmpl, short year, unsigned char mo { is = ipos[ipdtn - 1] - 1; /* Continuous time interval. */ sprintf(endtime, "%4.4d%2.2d%2.2d%2.2d:%2.2d:%2.2d", (int)ipdtmpl[is], (int)ipdtmpl[is + 1], - (int)ipdtmpl[is + 2], (int)ipdtmpl[is + 3], (int)ipdtmpl[is + 4], (int)ipdtmpl[is + 5]); + (int)ipdtmpl[is + 2], (int)ipdtmpl[is + 3], (int)ipdtmpl[is + 4], (int)ipdtmpl[is + 5]); /* write(endtime, fmt = '(i4,3i2.2,":",i2.2,":",i2.2)') (ipdtmpl(j), j = is, is + 5) */ - itemp2 = abs(ipdtmpl[iutpos2]) * iunit2; - itemp2 = itemp + itemp2; - sprintf(tmpval2, "%d", itemp2); + itemp2 = abs(ipdtmpl[iutpos2]) * iunit2; + itemp2 = itemp + itemp2; + sprintf(tmpval2, "%d", itemp2); if (ipdtn == 8 && ipdtmpl[8] < 0) { /* tabbrev = "(" // trim(tmpval) // " -" // trim(tmpval2) // ") valid " // trim(tmpval) // " " // trim(tunit) // " before " // reftime // " to " //endtime */ - sprintf(tabbrev, "(%d -%d) valid %d %s before %s to %s", itemp, itemp2, itemp, tunit, reftime, endtime); + sprintf(tabbrev, "(%d -%d) valid %d %s before %s to %s", itemp, itemp2, itemp, tunit, reftime, endtime); } else if ((ipdtn >= 8 && ipdtn <= 14) || (ipdtn >= 42 && ipdtn <= 47) || - ipdtn == 91) /* Continuous time interval */ + ipdtn == 91) /* Continuous time interval */ { /* write(tmpval2, '(I0)') itemp2 */ /* tabbrev = "(" // trim(tmpval) // " -" // trim(tmpval2) // " hr) valid " // trim(tmpval) // " " // trim(tunit) // " after " // reftime // " to " // endtime */ - sprintf(tabbrev, "(%d -%d hr) valid %d %s after %s to %s", itemp, itemp2, itemp, tunit, reftime, endtime); + sprintf(tabbrev, "(%d -%d hr) valid %d %s after %s to %s", itemp, itemp2, itemp, tunit, reftime, endtime); } } @@ -256,7 +254,7 @@ static int format_level(char *cbuf, int ival, int scale) { char tmpcbuf[37]; - + assert(cbuf); if (!scale) @@ -277,9 +275,8 @@ format_level(char *cbuf, int ival, int scale) char fmt[37]; sprintf(fmt, "%s%d%s", "%.", (int)abs(scale), "f"); sprintf(tmpcbuf, fmt, rval); - strcpy(cbuf, &tmpcbuf[1]); + strcpy(cbuf, &tmpcbuf[1]); } - } return G2C_NOERROR; } @@ -513,8 +510,8 @@ g2c_get_level_desc(int ipdtn, long long int *ipdtmpl, char *level_desc) strcpy(level_desc, " Cloud top lvl"); else if (ipdtmpl[ipos] == 4) strcpy(level_desc, " 0 Deg Isotherm"); - else if (ipdtmpl[ipos] == 5) /* from the surface. */ - strcpy(level_desc, " Level of adiabatic" ); + else if (ipdtmpl[ipos] == 5) /* from the surface. */ + strcpy(level_desc, " Level of adiabatic"); else if (ipdtmpl[ipos] == 6) strcpy(level_desc, " Max wind lvl"); else if (ipdtmpl[ipos] == 7) @@ -579,8 +576,8 @@ g2c_get_level_desc(int ipdtn, long long int *ipdtmpl, char *level_desc) strcpy(level_desc, " Bot. Ocean mix. lyr"); else if (ipdtmpl[ipos] == 238) strcpy(level_desc, " Bot. Ocean iso. lyr"); - else if (ipdtmpl[ipos] == 239) /* isothermal level (S26CY). */ - strcpy(level_desc, " layer ocean sfc 26C" ); + else if (ipdtmpl[ipos] == 239) /* isothermal level (S26CY). */ + strcpy(level_desc, " layer ocean sfc 26C"); else if (ipdtmpl[ipos] == 240) strcpy(level_desc, " Ocean Mixed Layer"); else if (ipdtmpl[ipos] == 241) @@ -605,13 +602,13 @@ g2c_get_level_desc(int ipdtn, long long int *ipdtmpl, char *level_desc) strcpy(level_desc, " Deep conv. cld bl"); else if (ipdtmpl[ipos] == 252) strcpy(level_desc, " Deep conv. cld tl"); - else if (ipdtmpl[ipos] == 253) /* liquid water layer (LBLSW). */ - strcpy(level_desc, " Lowest bot. lvl sup" ); - else if (ipdtmpl[ipos] == 254) /* liquid water layer (HBLSW). */ - strcpy(level_desc, " highest top lvl sup" ); + else if (ipdtmpl[ipos] == 253) /* liquid water layer (LBLSW). */ + strcpy(level_desc, " Lowest bot. lvl sup"); + else if (ipdtmpl[ipos] == 254) /* liquid water layer (HBLSW). */ + strcpy(level_desc, " highest top lvl sup"); else { - sprintf(level_desc, " %4d (Unknown Lvl)", (int)ipdtmpl[ipos]); + sprintf(level_desc, " %4d (Unknown Lvl)", (int)ipdtmpl[ipos]); /* write(level_desc, fmt = '(1x,I4," (Unknown Lvl)")') ipdtmpl[ipos] */ } @@ -688,14 +685,14 @@ g2c_degrib2(int g2cid, const char *fileout) fprintf(f, "\n"); fprintf(f, " FIELD %d\n", fld + 1); - /* Only print section 0 and 1 data for the first field. */ - if (fld == 0) - { - fprintf(f, " SECTION 0: %d 2\n", msg->discipline); - fprintf(f, " SECTION 1: %d %d %d %d %d %d %d %d %d %d %d %d %d\n", msg->center, msg->subcenter, - msg->master_version, msg->local_version, msg->sig_ref_time, msg->year, msg->month, msg->day, - msg->hour, msg->minute, msg->second, msg->status, msg->type); - } + /* Only print section 0 and 1 data for the first field. */ + if (fld == 0) + { + fprintf(f, " SECTION 0: %d 2\n", msg->discipline); + fprintf(f, " SECTION 1: %d %d %d %d %d %d %d %d %d %d %d %d %d\n", msg->center, msg->subcenter, + msg->master_version, msg->local_version, msg->sig_ref_time, msg->year, msg->month, msg->day, + msg->hour, msg->minute, msg->second, msg->status, msg->type); + } /* Find this field (a.k.a. product, a.k.a. section 4). */ for (sec = msg->sec; sec; sec = sec->next) @@ -809,7 +806,7 @@ g2c_degrib2(int g2cid, const char *fileout) if (!(data = malloc(sec5_info->num_data_points * sizeof(float)))) return G2C_ERROR; } - + /* Get the data from message 0, product 0. */ if ((ret = g2c_get_prod(g2cid, msg->msg_num, fld, NULL, data))) return ret; @@ -828,7 +825,7 @@ g2c_degrib2(int g2cid, const char *fileout) if (data[i] < min) min = data[i]; } - avg = total/sec5_info->num_data_points; + avg = total / sec5_info->num_data_points; } fprintf(f, "( PARM= %s ) : MIN=%25.8f AVE=%25.8f MAX=%25.8f\n", abbrev, min, avg, max); diff --git a/src/g2cfile.c b/src/g2cfile.c index 86089561..a08bdc9d 100644 --- a/src/g2cfile.c +++ b/src/g2cfile.c @@ -13,7 +13,7 @@ G2C_FILE_INFO_T g2c_file[G2C_MAX_FILES + 1]; int g2c_next_g2cid = 1; /** Find a minimum. */ -#define MIN(a,b) ((a) < (b) ? (a) : (b)) +#define MIN(a, b) ((a) < (b) ? (a) : (b)) /** Default size of read-buffer. */ #define READ_BUF_SIZE 4092 @@ -30,7 +30,7 @@ MUTEX(m); extern G2C_FILE_INFO_T g2c_file[G2C_MAX_FILES + 1]; /** - * Search a file for the next GRIB2 Message. + * Search a file for the next GRIB2 Message. * * The search is terminated when a GRIB2 message is found, or the end * of the file is reached. @@ -64,8 +64,8 @@ g2c_seekmsg(int g2cid, size_t skip, size_t *offset, size_t *msglen) /* Find the open file struct. */ if (g2c_file[g2cid].g2cid != g2cid) - return G2C_EBADID; - + return G2C_EBADID; + LOG((3, "g2c_seekgb skip %ld", skip)); /* Get memory to read in some of the file. */ @@ -95,8 +95,8 @@ g2c_seekmsg(int g2cid, size_t skip, size_t *offset, size_t *msglen) * an 8-byte big-endian integer starting at positon * 8 in cbuf. */ my_msglen = hton64(*(size_t *)&cbuf[k + 8]); - - LOG((4, "my_msglen %ld", my_msglen)); + + LOG((4, "my_msglen %ld", my_msglen)); /* Read the last 4 bytes of the message. */ if (fseek(g2c_file[g2cid].f, ipos + k + my_msglen - 4, SEEK_SET)) @@ -104,19 +104,19 @@ g2c_seekmsg(int g2cid, size_t skip, size_t *offset, size_t *msglen) free(cbuf); return G2C_EFILE; } - + if ((k4 = fread(&end, 4, 1, g2c_file[g2cid].f)) != 1) { free(cbuf); return G2C_EFILE; } - + /* Look for '7777' at end of grib message. */ if (k4 == 1 && end == 926365495) { /* GRIB message found. */ my_offset = ipos + k; - LOG((4, "found end of message my_offset %ld", my_offset)); + LOG((4, "found end of message my_offset %ld", my_offset)); break; } } @@ -216,8 +216,7 @@ g2c_find_msg2(int g2cid, size_t skip_bytes, size_t max_bytes, size_t *bytes_to_m /* if (i < 10) LOG((3, "buf[%ld] = %2.2x", i, buf[i])); */ #endif /* Find the beginning of a GRIB message. */ - if (buf[i] == 'G' && i < bytes_read - G2C_MAGIC_HEADER_LEN - && buf[i + 1] == 'R' && buf[i + 2] == 'I' && buf[i + 3] == 'B') + if (buf[i] == 'G' && i < bytes_read - G2C_MAGIC_HEADER_LEN && buf[i + 1] == 'R' && buf[i + 2] == 'I' && buf[i + 3] == 'B') { msg_found++; *bytes_to_msg = ftell_pos + i; @@ -232,8 +231,7 @@ g2c_find_msg2(int g2cid, size_t skip_bytes, size_t max_bytes, size_t *bytes_to_m } /* Find the end of a GRIB message. And then we're done. */ - if (msg_found && buf[i] == '7' && i < bytes_read - G2C_MAGIC_HEADER_LEN - && buf[i + 1] == '7' && buf[i + 2] == '7' && buf[i + 3] == '7') + if (msg_found && buf[i] == '7' && i < bytes_read - G2C_MAGIC_HEADER_LEN && buf[i + 1] == '7' && buf[i + 2] == '7' && buf[i + 3] == '7') { msg_found--; *bytes_in_msg = ftell_pos + i - *bytes_to_msg + 4; @@ -394,7 +392,6 @@ find_available_g2cid(int *g2cid) return ret; } - /** * Determine the dimension information from the section 3 metadata. * @@ -439,7 +436,7 @@ determine_dims(G2C_SECTION_INFO_T *sec) d0->value[0] = sec->template[11]; for (d = 1; d < d0->len; d++) d0->value[d] = d0->value[d - 1] - sec->template[16]; - + d1->len = sec->template[7]; strncpy(d1->name, LONGITUDE, G2C_MAX_NAME); if (!(d1->value = malloc(d1->len * sizeof(float)))) @@ -451,7 +448,7 @@ determine_dims(G2C_SECTION_INFO_T *sec) default: break; } - + return G2C_NOERROR; } @@ -466,7 +463,7 @@ determine_dims(G2C_SECTION_INFO_T *sec) * * @param f FILE pointer to open GRIB2 file. * @param rw_flag ::G2C_FILE_WRITE if function should write, - * ::G2C_FILE_READ (0) if it should read. + * ::G2C_FILE_READ (0) if it should read. * @param sec Pointer to the G2C_SECTION_INFO_T struct. * * @return @@ -884,7 +881,7 @@ g2c_rw_section1_metadata(FILE *f, int rw_flag, G2C_MESSAGE_INFO_T *msg) /* Read the section. */ if ((ret = g2c_file_io_uint(f, rw_flag, (unsigned int *)&msg->sec1_len))) return ret; - + if ((ret = g2c_file_io_ubyte(f, rw_flag, &sec_num))) return ret; if (!rw_flag && sec_num != 1) /* When reading sec num must be 1. */ diff --git a/src/g2cindex.c b/src/g2cindex.c index db91f34b..1a3a46f2 100644 --- a/src/g2cindex.c +++ b/src/g2cindex.c @@ -6,9 +6,9 @@ * @author Ed Hartnett @date 10/12/22 */ #include "grib2_int.h" -#include -#include #include +#include +#include /** Global file information. */ extern G2C_FILE_INFO_T g2c_file[G2C_MAX_FILES + 1]; @@ -76,8 +76,7 @@ g2c_start_index_record(FILE *f, int rw_flag, int *reclen, int *msg, int *local, int ret; /* All pointers must be provided. */ - if (!f || !reclen || !msg || !local || !gds || !pds || !drs || !bms || !data - || !msglen || !version || !discipline || !fieldnum) + if (!f || !reclen || !msg || !local || !gds || !pds || !drs || !bms || !data || !msglen || !version || !discipline || !fieldnum) return G2C_EINVAL; LOG((4, "g2c_start_index_record rw_flag %d", rw_flag)); @@ -150,8 +149,8 @@ g2c_start_index_record(FILE *f, int rw_flag, int *reclen, int *msg, int *local, */ int g2c_start_index_record_lf(FILE *f, int rw_flag, int *reclen, size_t *msg, size_t *local, size_t *gds, - size_t *pds, size_t *drs, size_t *bms, size_t *data, size_t *msglen, - unsigned char *version, unsigned char *discipline, short *fieldnum) + size_t *pds, size_t *drs, size_t *bms, size_t *data, size_t *msglen, + unsigned char *version, unsigned char *discipline, short *fieldnum) { /* size_t size_t_be; */ short fieldnum1; /* This is for the 1-based fieldnum in the index file. */ @@ -160,8 +159,7 @@ g2c_start_index_record_lf(FILE *f, int rw_flag, int *reclen, size_t *msg, size_t LOG((4, "g2c_start_index_record_lf rw_flag %d", rw_flag)); /* All pointers must be provided. */ - if (!f || !reclen || !msg || !local || !gds || !pds || !drs || !bms || !data - || !msglen || !version || !discipline || !fieldnum) + if (!f || !reclen || !msg || !local || !gds || !pds || !drs || !bms || !data || !msglen || !version || !discipline || !fieldnum) return G2C_EINVAL; /* When writing, set the fieldnum1 to be a 1-based index, just @@ -223,7 +221,7 @@ g2c_start_index_record_lf(FILE *f, int rw_flag, int *reclen, size_t *msg, size_t * @param version Pointer that gets grib version number (always 1 for this function). * @param pds_val Pointer that gets an arry of 27 bytes of the product definition section (pds). * @param gds_val Pointer that gets an arry of 41 bytes of the gds. - * @param bms_val Pointer that gets an arry of 5 bytes of the bms. + * @param bms_val Pointer that gets an arry of 5 bytes of the bms. * @param bds_val Pointer that gets an arry of 10 bytes, bytes 41-100 of the bds. * @param pds_val2 Pointer that gets an arry of 59 bytes 41-100 of the pds. Ignored if null. * @param pds_val3 Pointer that gets an arry of 11 bytes 29-40 of the pds. Ignored if null. @@ -238,17 +236,17 @@ g2c_start_index_record_lf(FILE *f, int rw_flag, int *reclen, size_t *msg, size_t */ int g2c_start_index1_record(FILE *f, int rw_flag, unsigned int *b2_msg, unsigned int *b2_pds, - unsigned int *b2_gds, unsigned int *b2_bms, unsigned int *b2_bds, - unsigned int *msglen, unsigned char *version, unsigned char *pds_val, - unsigned char *gds_val, unsigned char *bms_val, unsigned char *bds_val, - unsigned char *pds_val2, unsigned char *pds_val3, unsigned char *gds_val2) + unsigned int *b2_gds, unsigned int *b2_bms, unsigned int *b2_bds, + unsigned int *msglen, unsigned char *version, unsigned char *pds_val, + unsigned char *gds_val, unsigned char *bms_val, unsigned char *bds_val, + unsigned char *pds_val2, unsigned char *pds_val3, unsigned char *gds_val2) { - size_t bytes_read; + size_t bytes_read; int ret; /* All pointers must be provided. */ if (!f || !b2_msg || !b2_pds || !b2_gds || !b2_bms || !b2_bds || - !msglen || !version) + !msglen || !version) return G2C_EINVAL; /* Read or write the values at the beginning of each index @@ -273,13 +271,13 @@ g2c_start_index1_record(FILE *f, int rw_flag, unsigned int *b2_msg, unsigned int * length. For more detail see * https://noaa-emc.github.io/NCEPLIBS-grib_util/grbindex/grbindex_8f.html. */ if ((bytes_read = fread(pds_val, 1, G2C_INDEX1_PDS_VAL_LEN, f)) != G2C_INDEX1_PDS_VAL_LEN) - return G2C_EFILE; + return G2C_EFILE; if ((bytes_read = fread(gds_val, 1, G2C_INDEX1_GDS_VAL_LEN, f)) != G2C_INDEX1_GDS_VAL_LEN) - return G2C_EFILE; + return G2C_EFILE; if ((bytes_read = fread(bms_val, 1, G2C_INDEX1_BMS_VAL_LEN, f)) != G2C_INDEX1_BMS_VAL_LEN) - return G2C_EFILE; + return G2C_EFILE; if ((bytes_read = fread(bds_val, 1, G2C_INDEX1_BDS_VAL_LEN, f)) != G2C_INDEX1_BDS_VAL_LEN) - return G2C_EFILE; + return G2C_EFILE; return G2C_NOERROR; } @@ -323,7 +321,7 @@ g2c_get_prod_sections(G2C_MESSAGE_INFO_T *msg, int fieldnum, G2C_SECTION_INFO_T G2C_SECTION_INFO_T *s3, *s4, *s5, *s6, *s7; /* Check inputs. */ - if (!msg || fieldnum < 0 ||!sec3 || !sec4 || !sec5 || !sec6 || !sec7) + if (!msg || fieldnum < 0 || !sec3 || !sec4 || !sec5 || !sec6 || !sec7) return G2C_EINVAL; /* Find the product with matching fieldnum. */ @@ -441,7 +439,7 @@ g2c_write_index(int g2cid, int mode, const char *index_file) char my_path[G2C_INDEX_BASENAME_LEN + 1]; G2C_MESSAGE_INFO_T *msg; int total_index_size = 0; /* Does not include size of header records. */ - int index_version = 1; /* 1 for legacy, 2 if indexed file may be > 2 GB. */ + int index_version = 1; /* 1 for legacy, 2 if indexed file may be > 2 GB. */ int reclen; int ret = G2C_NOERROR; @@ -467,8 +465,8 @@ g2c_write_index(int g2cid, int mode, const char *index_file) /* If LARGE_INDEX_FILE, set index version. */ if (mode & G2C_LARGE_FILE_INDEX) - index_version = 2; - + index_version = 2; + /* Create the index file. */ if (!(f = fopen(index_file, "wb+"))) return G2C_EFILE; @@ -482,10 +480,10 @@ g2c_write_index(int g2cid, int mode, const char *index_file) if (!ret) { /* Create header 1. */ - snprintf(h1, G2C_INDEX_HEADER_LEN + 1, - "!GFHDR! 1 1 162 %4.4u-%2.2u-%2.2u %2.2u:%2.2u:%2.2u %s hfe08 grb2index\n", - (tm.tm_year + 1900), (tm.tm_mon + 1), tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, - "GB2IX1"); + snprintf(h1, G2C_INDEX_HEADER_LEN + 1, + "!GFHDR! 1 1 162 %4.4u-%2.2u-%2.2u %2.2u:%2.2u:%2.2u %s hfe08 grb2index\n", + (tm.tm_year + 1900), (tm.tm_mon + 1), tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, + "GB2IX1"); /* Write header 1. */ if ((items_written = fwrite(h1, G2C_INDEX_HEADER_LEN, 1, f)) != 1) @@ -498,18 +496,18 @@ g2c_write_index(int g2cid, int mode, const char *index_file) for (msg = g2c_file[g2cid].msg; msg; msg = msg->next) { short fieldnum; - + /* Find information for each field in the message. */ for (fieldnum = 0; fieldnum < msg->num_fields; fieldnum++) { G2C_SECTION_INFO_T *sec3, *sec4, *sec5, *sec6, *sec7; - + if ((ret = g2c_get_prod_sections(msg, fieldnum, &sec3, &sec4, &sec5, &sec6, &sec7))) break; - + /* What will be the length of this index record? */ reclen = (index_version == 1 ? G2C_INDEX_FIXED_LEN : G2C_INDEX_FIXED_LEN_2) + - msg->sec1_len + sec3->sec_len + sec4->sec_len + sec5->sec_len + G2C_INDEX_BITMAP_BYTES; + msg->sec1_len + sec3->sec_len + sec4->sec_len + sec5->sec_len + G2C_INDEX_BITMAP_BYTES; total_index_size += reclen; LOG((4, "fieldnum %d reclen %d total_index_size %d", fieldnum, reclen, total_index_size)); } /* next product */ @@ -527,7 +525,7 @@ g2c_write_index(int g2cid, int mode, const char *index_file) sprintf(h2, "IX%dFORM: 162 %6d %6ld %s \n", index_version, total_index_size, g2c_file[g2cid].num_messages, my_path); LOG((5, "header 2: %s", h2)); - + /* Write header 2. */ if ((items_written = fwrite(h2, G2C_INDEX_HEADER_LEN, 1, f)) != 1) ret = G2C_EFILE; @@ -544,7 +542,7 @@ g2c_write_index(int g2cid, int mode, const char *index_file) for (fieldnum = 0; fieldnum < msg->num_fields; fieldnum++) { G2C_SECTION_INFO_T *sec3, *sec4, *sec5, *sec6, *sec7; - int bs3, bs4, bs5, bs6, bs7; /* bytes to each section, as ints. */ + int bs3, bs4, bs5, bs6, bs7; /* bytes to each section, as ints. */ size_t bs3_8, bs4_8, bs5_8, bs6_8, bs7_8; /* bytes to each section, as size_t. */ unsigned char sec_num; int ret; @@ -564,29 +562,28 @@ g2c_write_index(int g2cid, int mode, const char *index_file) bs7_8 = sec7->bytes_to_sec; /* What will be the length of this index record? */ - reclen = (index_version == 1 ? G2C_INDEX_FIXED_LEN : G2C_INDEX_FIXED_LEN_2) - + msg->sec1_len + sec3->sec_len + sec4->sec_len + sec5->sec_len + G2C_INDEX_BITMAP_BYTES; + reclen = (index_version == 1 ? G2C_INDEX_FIXED_LEN : G2C_INDEX_FIXED_LEN_2) + msg->sec1_len + sec3->sec_len + sec4->sec_len + sec5->sec_len + G2C_INDEX_BITMAP_BYTES; LOG((4, "fieldnum %d reclen %d", fieldnum, reclen)); /* Write the beginning of the index record. */ - if (index_version == 2) - { - if ((ret = g2c_start_index_record_lf(f, G2C_FILE_WRITE, &reclen, &msg->bytes_to_msg, &msg->bytes_to_local, - &bs3_8, &bs4_8, &bs5_8, &bs6_8, &bs7_8, &msg->bytes_in_msg, &msg->master_version, - &msg->discipline, &fieldnum))) - break; - } - else - { - int bytes_to_msg = (int)msg->bytes_to_msg; - int b2l; - - b2l = (int)msg->bytes_to_local; - if ((ret = g2c_start_index_record(f, G2C_FILE_WRITE, &reclen, &bytes_to_msg, &b2l, - &bs3, &bs4, &bs5, &bs6, &bs7, &msg->bytes_in_msg, &msg->master_version, - &msg->discipline, &fieldnum))) - break; - } + if (index_version == 2) + { + if ((ret = g2c_start_index_record_lf(f, G2C_FILE_WRITE, &reclen, &msg->bytes_to_msg, &msg->bytes_to_local, + &bs3_8, &bs4_8, &bs5_8, &bs6_8, &bs7_8, &msg->bytes_in_msg, &msg->master_version, + &msg->discipline, &fieldnum))) + break; + } + else + { + int bytes_to_msg = (int)msg->bytes_to_msg; + int b2l; + + b2l = (int)msg->bytes_to_local; + if ((ret = g2c_start_index_record(f, G2C_FILE_WRITE, &reclen, &bytes_to_msg, &b2l, + &bs3, &bs4, &bs5, &bs6, &bs7, &msg->bytes_in_msg, &msg->master_version, + &msg->discipline, &fieldnum))) + break; + } /* Write the section 1, identification section. */ if ((ret = g2c_rw_section1_metadata(f, G2C_FILE_WRITE, msg))) @@ -663,7 +660,7 @@ g2c_write_index(int g2cid, int mode, const char *index_file) } /** - * Read the header record apparently named after Steve Lord. + * Read the header record apparently named after Steve Lord. * * This function reads the first of two 81-byte header records of an * index file. @@ -692,40 +689,40 @@ read_hdr_rec1(FILE *f, int *ip, int *jp, int *kp, char *date_str, char *time_str char my_date_str[G2C_INDEX_DATE_STR_LEN + 1]; char my_time_str[G2C_INDEX_TIME_STR_LEN + 1]; int i, j, k; - + /* Read the first line of header. */ if ((bytes_read = fread(line, 1, G2C_INDEX_HEADER_LEN, f)) != G2C_INDEX_HEADER_LEN) - return G2C_EFILE; + return G2C_EFILE; line[G2C_INDEX_HEADER_LEN] = 0; - + /* Scan the line. */ { - char long_date_str[G2C_INDEX_HEADER_LEN + 1], long_time_str[G2C_INDEX_HEADER_LEN + 1]; - char long_str1[G2C_INDEX_HEADER_LEN + 1]; - - sscanf(line, "%s %d %d %d %s %s GB2IX1", long_str1, &i, &j, &k, long_date_str, long_time_str); - memcpy(str1, long_str1, G2C_INDEX_STR1_LEN); - date_str[G2C_INDEX_STR1_LEN] = 0; - memcpy(date_str, long_date_str, G2C_INDEX_DATE_STR_LEN); - date_str[G2C_INDEX_DATE_STR_LEN] = 0; - memcpy(time_str, long_time_str, G2C_INDEX_TIME_STR_LEN); - time_str[G2C_INDEX_TIME_STR_LEN] = 0; + char long_date_str[G2C_INDEX_HEADER_LEN + 1], long_time_str[G2C_INDEX_HEADER_LEN + 1]; + char long_str1[G2C_INDEX_HEADER_LEN + 1]; + + sscanf(line, "%s %d %d %d %s %s GB2IX1", long_str1, &i, &j, &k, long_date_str, long_time_str); + memcpy(str1, long_str1, G2C_INDEX_STR1_LEN); + date_str[G2C_INDEX_STR1_LEN] = 0; + memcpy(date_str, long_date_str, G2C_INDEX_DATE_STR_LEN); + date_str[G2C_INDEX_DATE_STR_LEN] = 0; + memcpy(time_str, long_time_str, G2C_INDEX_TIME_STR_LEN); + time_str[G2C_INDEX_TIME_STR_LEN] = 0; } LOG((4, "str1 %s i %d j %d k %d date_str %s time_str %s", str1, i, j, k, date_str, - time_str)); + time_str)); /* Return info to caller where desired. */ if (ip) - *ip = i; + *ip = i; if (jp) - *jp = j; + *jp = j; if (kp) - *kp = k; + *kp = k; if (date_str) - strncpy(date_str, my_date_str, G2C_INDEX_DATE_STR_LEN + 1); + strncpy(date_str, my_date_str, G2C_INDEX_DATE_STR_LEN + 1); if (time_str) - strncpy(time_str, my_time_str, G2C_INDEX_TIME_STR_LEN + 1); - + strncpy(time_str, my_time_str, G2C_INDEX_TIME_STR_LEN + 1); + return G2C_NOERROR; } @@ -754,37 +751,37 @@ read_hdr_rec1(FILE *f, int *ip, int *jp, int *kp, char *date_str, char *time_str */ static int read_hdr_rec2(FILE *f, int *skipp, int *total_lenp, int *num_recp, - char *basename, int *index_version) + char *basename, int *index_version) { size_t bytes_read; char line[G2C_INDEX_HEADER_LEN + 1]; int skip; - int total_len, num_rec; + int total_len, num_rec; char my_basename[G2C_INDEX_BASENAME_LEN + 1]; - + /* Read the second line of header. */ if ((bytes_read = fread(line, 1, G2C_INDEX_HEADER_LEN, f)) != G2C_INDEX_HEADER_LEN) - return G2C_EFILE; + return G2C_EFILE; line[G2C_INDEX_HEADER_LEN] = 0; /* Scan the line. Hard! */ { - char long_basename[G2C_INDEX_HEADER_LEN + 1]; - sscanf(line, "IX%dFORM: %d %d %d %s", index_version, &skip, &total_len, - &num_rec, long_basename); - memcpy(my_basename, long_basename, G2C_INDEX_BASENAME_LEN); - my_basename[G2C_INDEX_BASENAME_LEN] = 0; + char long_basename[G2C_INDEX_HEADER_LEN + 1]; + sscanf(line, "IX%dFORM: %d %d %d %s", index_version, &skip, &total_len, + &num_rec, long_basename); + memcpy(my_basename, long_basename, G2C_INDEX_BASENAME_LEN); + my_basename[G2C_INDEX_BASENAME_LEN] = 0; } /* Return info to caller where desired. */ if (skipp) - *skipp = skip; + *skipp = skip; if (total_lenp) - *total_lenp = total_len; + *total_lenp = total_len; if (num_recp) - *num_recp = num_rec; + *num_recp = num_rec; if (basename) - strncpy(basename, my_basename, G2C_INDEX_BASENAME_LEN + 1); - + strncpy(basename, my_basename, G2C_INDEX_BASENAME_LEN + 1); + return G2C_NOERROR; } @@ -806,7 +803,7 @@ g2c_open_index1(const char *index_file) int i, j, k; char date_str[G2C_INDEX_DATE_STR_LEN + 1]; char time_str[G2C_INDEX_TIME_STR_LEN + 1]; - int skip, total_len, num_rec; + int skip, total_len, num_rec; char basename[G2C_INDEX_BASENAME_LEN + 1]; size_t file_pos = G2C_INDEX_HEADER_LEN * 2; unsigned char pds_val[G2C_INDEX1_PDS_VAL_LEN]; @@ -832,42 +829,42 @@ g2c_open_index1(const char *index_file) /* Read header record apparently named after Steve Lord. */ if ((ret = read_hdr_rec1(f, &i, &j, &k, date_str, time_str))) - return ret; + return ret; LOG((4, "i %d j %d k %d date_str %s time_str %s", i, j, k, date_str, time_str)); /* Read second header record. */ if ((ret = read_hdr_rec2(f, &skip, &total_len, &num_rec, basename, &index_version))) - return ret; + return ret; LOG((4, "skip %d total_len %d num_rec %d basename %s", skip, total_len, num_rec, basename)); /* Read each index record. These is one record for each message in the original GRIB1 file. */ for (rec = 0; rec < num_rec; rec++) { - unsigned int b2_msg, b2_gds, b2_pds, b2_bms, b2_bds, msglen; - unsigned char version; - - /* Move to beginning of index record. */ - if (fseek(f, file_pos, SEEK_SET)) - { - ret = G2C_EFILE; - break; - } - - /* Read the index1 record. */ - LOG((4, "reading index1 record at file position %ld", ftell(f))); - if ((ret = g2c_start_index1_record(f, G2C_FILE_READ, &b2_msg, &b2_pds, &b2_gds, - &b2_bms, &b2_bds, &msglen, &version, pds_val, - gds_val, bms_val, bds_val, NULL, NULL, NULL))) - break; - - LOG((4, "b2_msg %d b2_pds %d b2_gds %d b2_bms %d b2_bds %d msglen %d version %d", - b2_msg, b2_gds, b2_pds, b2_bms, b2_bds, msglen, version)); - printf("b2_msg %d b2_pds %d b2_gds %d b2_bms %d b2_bds %d msglen %d version %d\n", - b2_msg, b2_gds, b2_pds, b2_bms, b2_bds, msglen, version); - - /* Move the file position to the start of the next index record. */ - file_pos += total_len; + unsigned int b2_msg, b2_gds, b2_pds, b2_bms, b2_bds, msglen; + unsigned char version; + + /* Move to beginning of index record. */ + if (fseek(f, file_pos, SEEK_SET)) + { + ret = G2C_EFILE; + break; + } + + /* Read the index1 record. */ + LOG((4, "reading index1 record at file position %ld", ftell(f))); + if ((ret = g2c_start_index1_record(f, G2C_FILE_READ, &b2_msg, &b2_pds, &b2_gds, + &b2_bms, &b2_bds, &msglen, &version, pds_val, + gds_val, bms_val, bds_val, NULL, NULL, NULL))) + break; + + LOG((4, "b2_msg %d b2_pds %d b2_gds %d b2_bms %d b2_bds %d msglen %d version %d", + b2_msg, b2_gds, b2_pds, b2_bms, b2_bds, msglen, version)); + printf("b2_msg %d b2_pds %d b2_gds %d b2_bms %d b2_bds %d msglen %d version %d\n", + b2_msg, b2_gds, b2_pds, b2_bms, b2_bds, msglen, version); + + /* Move the file position to the start of the next index record. */ + file_pos += total_len; } /* next rec */ /* If using threading, unlock the mutex. */ @@ -936,7 +933,7 @@ g2c_open_index(const char *data_file, const char *index_file, int mode, int skip, total_len, num_rec; char basename[G2C_INDEX_BASENAME_LEN + 1]; size_t file_pos = G2C_INDEX_HEADER_LEN * 2; - int index_version; + int index_version; int rec; /* Read the first line of header. */ @@ -947,7 +944,7 @@ g2c_open_index(const char *data_file, const char *index_file, int mode, { char long_date_str[G2C_INDEX_HEADER_LEN + 1], long_time_str[G2C_INDEX_HEADER_LEN + 1]; char long_str1[G2C_INDEX_HEADER_LEN + 1]; - + sscanf(line, "%s %d %d %d %s %s GB2IX1", long_str1, &i, &j, &k, long_date_str, long_time_str); memcpy(str1, long_str1, G2C_INDEX_STR1_LEN); date_str[G2C_INDEX_STR1_LEN] = 0; @@ -966,8 +963,8 @@ g2c_open_index(const char *data_file, const char *index_file, int mode, /* Scan the line. Hard! */ { char long_basename[G2C_INDEX_HEADER_LEN + 1]; - sscanf(line, "IX%dFORM: %d %d %d %s", &index_version, &skip, &total_len, - &num_rec, long_basename); + sscanf(line, "IX%dFORM: %d %d %d %s", &index_version, &skip, &total_len, + &num_rec, long_basename); memcpy(basename, long_basename, G2C_INDEX_BASENAME_LEN); basename[G2C_INDEX_BASENAME_LEN] = 0; } @@ -991,29 +988,29 @@ g2c_open_index(const char *data_file, const char *index_file, int mode, /* Read the index record. */ LOG((4, "reading index record at file position %ld, index_version %d", - ftell(f), index_version)); - if (index_version == 1) - { - if ((ret = g2c_start_index_record(f, G2C_FILE_READ, &reclen, &msgint, &local, &gds, &pds, - &drs, &bms, &data, &msglen, &version, &discipline, &fieldnum))) - break; - msg = msgint; - local8 = local; - gds8 = gds; - pds8 = pds; - drs8 = drs; - bms8 = bms; - data8 = data; - } - else - { - if ((ret = g2c_start_index_record_lf(f, G2C_FILE_READ, &reclen, &msg, &local8, &gds8, &pds8, - &drs8, &bms8, &data8, &msglen, &version, &discipline, &fieldnum))) - break; - } + ftell(f), index_version)); + if (index_version == 1) + { + if ((ret = g2c_start_index_record(f, G2C_FILE_READ, &reclen, &msgint, &local, &gds, &pds, + &drs, &bms, &data, &msglen, &version, &discipline, &fieldnum))) + break; + msg = msgint; + local8 = local; + gds8 = gds; + pds8 = pds; + drs8 = drs; + bms8 = bms; + data8 = data; + } + else + { + if ((ret = g2c_start_index_record_lf(f, G2C_FILE_READ, &reclen, &msg, &local8, &gds8, &pds8, + &drs8, &bms8, &data8, &msglen, &version, &discipline, &fieldnum))) + break; + } LOG((1, "reclen %d msg %ld local8 %d gds8 %d pds8 %d drs8 %d bms8 %d data8 %d " - "msglen %ld version %d discipline %d fieldnum %d", + "msglen %ld version %d discipline %d fieldnum %d", reclen, msg, local8, gds8, pds8, drs8, bms8, data8, msglen, version, discipline, fieldnum)); @@ -1065,8 +1062,8 @@ g2c_open_index(const char *data_file, const char *index_file, int mode, * data read operations. So we will use the * open data file and get the length of this * section. */ - LOG((4, "seeking to section 7 in data file, position msgp->bytes_to_msg %ld data %ld", - msgp->bytes_to_msg, data8)); + LOG((4, "seeking to section 7 in data file, position msgp->bytes_to_msg %ld data %ld", + msgp->bytes_to_msg, data8)); if (fseek(g2c_file[*g2cid].f, msgp->bytes_to_msg + data8, SEEK_SET)) { ret = G2C_EFILE; @@ -1109,8 +1106,8 @@ g2c_open_index(const char *data_file, const char *index_file, int mode, /* Read the section info from the index file, * using the same functions that read it from the * GRIB2 data file. */ - LOG((4, "about to add_section sec_id %d sec_len %d bytes_to_sec %ld sec_num %d", - sec_id, sec_len, bytes_to_sec, sec_num)); + LOG((4, "about to add_section sec_id %d sec_len %d bytes_to_sec %ld sec_num %d", + sec_id, sec_len, bytes_to_sec, sec_num)); if ((ret = add_section(f, msgp, sec_id++, sec_len, bytes_to_sec, sec_num))) break; } /* next section */ diff --git a/src/g2cinq.c b/src/g2cinq.c index 5b1db673..0a959551 100644 --- a/src/g2cinq.c +++ b/src/g2cinq.c @@ -31,7 +31,7 @@ int g2c_inq(int g2cid, int *num_msg) { int ret = G2C_NOERROR; - + /* Is this an open GRIB2 file? */ if (g2cid < 0 || g2cid > G2C_MAX_FILES) return G2C_EBADID; @@ -254,7 +254,7 @@ g2c_inq_prod(int g2cid, int msg_num, int prod_num, int *pds_template_len, for (t = 0; t < sec4->template_len; t++) pds_template[t] = sec4->template[t]; } - + /* Find the GDS. */ if (!ret) { @@ -274,7 +274,7 @@ g2c_inq_prod(int g2cid, int msg_num, int prod_num, int *pds_template_len, for (t = 0; t < sec3->template_len; t++) gds_template[t] = sec3->template[t]; } - + /* Find the DRS. */ if (!ret) { @@ -294,7 +294,7 @@ g2c_inq_prod(int g2cid, int msg_num, int prod_num, int *pds_template_len, for (t = 0; t < sec5->template_len; t++) drs_template[t] = sec5->template[t]; } - + /* If using threading, unlock the mutex. */ MUTEX_UNLOCK(m); @@ -326,7 +326,7 @@ g2c_inq_prod(int g2cid, int msg_num, int prod_num, int *pds_template_len, */ int g2c_inq_dim(int g2cid, int msg_num, int prod_num, int dim_num, size_t *len, - char *name, float *val) + char *name, float *val) { G2C_MESSAGE_INFO_T *msg; G2C_SECTION_INFO_T *sec4, *sec3; @@ -376,7 +376,6 @@ g2c_inq_dim(int g2cid, int msg_num, int prod_num, int dim_num, size_t *len, if (val) for (d = 0; d < dim->len; d++) val[d] = dim->value[d]; - return ret; } diff --git a/src/g2cio.c b/src/g2cio.c index 9cbf6b1e..b26b8989 100644 --- a/src/g2cio.c +++ b/src/g2cio.c @@ -6,7 +6,7 @@ #include "grib2_int.h" -#define BITSHIFT_7 7 /**< 7 bits. */ +#define BITSHIFT_7 7 /**< 7 bits. */ #define BITSHIFT_15 15 /**< 15 bits. */ #define BITSHIFT_31 31 /**< 31 bits. */ #define BITSHIFT_63 63 /**< 63 bits. */ @@ -67,7 +67,7 @@ g2c_file_io(FILE *f, int write, int g2ctype, void *var) /* Are we writing a negative number? */ if (g2ctype == G2C_BYTE && *bvar < 0) { - byte_tmp = -1 * *bvar; /* Store as positive. */ + byte_tmp = -1 * *bvar; /* Store as positive. */ byte_tmp |= 1UL << BITSHIFT_7; /* Set sign bit. */ } else @@ -87,7 +87,7 @@ g2c_file_io(FILE *f, int write, int g2ctype, void *var) /* Are we writing a negative number? */ if (g2ctype == G2C_SHORT && *svar < 0) { - short_tmp = -1 * *svar; /* Store as positive. */ + short_tmp = -1 * *svar; /* Store as positive. */ short_tmp |= 1UL << BITSHIFT_15; /* Set sign bit. */ } else @@ -107,7 +107,7 @@ g2c_file_io(FILE *f, int write, int g2ctype, void *var) /* Are we writing a negative number? */ if (g2ctype == G2C_INT && *ivar < 0) { - int_tmp = -1 * *ivar; /* Store as positive. */ + int_tmp = -1 * *ivar; /* Store as positive. */ int_tmp |= 1UL << BITSHIFT_31; /* Set sign bit. */ } else @@ -127,7 +127,7 @@ g2c_file_io(FILE *f, int write, int g2ctype, void *var) /* Are we writing a negative number? */ if (g2ctype == G2C_INT64 && *i64var < 0) { - int64_tmp = -1 * *i64var; /* Store as positive. */ + int64_tmp = -1 * *i64var; /* Store as positive. */ int64_tmp |= 1ULL << BITSHIFT_63; /* Set sign bit. */ } else @@ -158,48 +158,48 @@ g2c_file_io(FILE *f, int write, int g2ctype, void *var) case G2C_UBYTE: /* No conversion needed for one-byte values. */ *bvar = byte_be; - + /* Did we read a negative number? Check the sign bit... */ if (g2ctype == G2C_BYTE && *bvar & 1 << BITSHIFT_7) { *bvar &= ~(1UL << BITSHIFT_7); /* Clear sign bit. */ - *bvar *= -1; /* Make it negative. */ + *bvar *= -1; /* Make it negative. */ } break; case G2C_SHORT: case G2C_USHORT: /* Convert from big-endian. */ *svar = htons(short_be); - + /* Did we read a negative number? Check the sign bit... */ if (g2ctype == G2C_SHORT && *svar & 1 << BITSHIFT_15) { *svar &= ~(1UL << BITSHIFT_15); /* Clear sign bit. */ - *svar *= -1; /* Make it negative. */ + *svar *= -1; /* Make it negative. */ } break; case G2C_INT: case G2C_UINT: /* Convert from big-endian. */ *ivar = htonl(int_be); - + /* Did we read a negative number? Check the sign bit... */ if (g2ctype == G2C_INT && *ivar & 1 << BITSHIFT_31) { *ivar &= ~(1UL << BITSHIFT_31); /* Clear sign bit. */ - *ivar *= -1; /* Make it negative. */ + *ivar *= -1; /* Make it negative. */ } break; case G2C_INT64: case G2C_UINT64: /* Convert from big-endian. */ *i64var = hton64(int64_be); - + /* Did we read a negative number? Check the sign bit... */ if (g2ctype == G2C_INT64 && *i64var & 1ULL << BITSHIFT_63) { *i64var &= ~(1ULL << BITSHIFT_63); /* Clear sign bit. */ - *i64var *= -1; /* Make it negative. */ + *i64var *= -1; /* Make it negative. */ } break; default: @@ -413,7 +413,7 @@ g2c_file_io_template(FILE *f, int rw_flag, int map, long long int *template_valu * numbers are negative - used to indicate that the * cooresponding fields can contain negative data (needed for * unpacking). */ - switch(abs(map)) + switch (abs(map)) { case ONE_BYTE: if (map < 0) @@ -486,6 +486,6 @@ g2c_file_io_template(FILE *f, int rw_flag, int map, long long int *template_valu default: return G2C_EBADTEMPLATE; } - + return G2C_NOERROR; } diff --git a/src/g2cparams.c b/src/g2cparams.c index 7e650eed..b40877cf 100644 --- a/src/g2cparams.c +++ b/src/g2cparams.c @@ -1,4 +1,4 @@ -/** +/** * @file * @brief Functions for serving up NOAA parameter abbreviations and * GRIB1/GRIB2 translations. @@ -1051,7 +1051,7 @@ int g2c_param_g1tog2(int g1num, int g1ver, int *g2disc, int *g2cat, int *g2num) { int p; - + /* Loop through array until matching values are found. */ for (p = 0; p < G2C_MAX_NOAA_PARAMS; p++) if (param[p].g1num == g1num && param[p].g1ver == g1ver) @@ -1110,7 +1110,7 @@ g2c_param_abbrev(int g2disc, int g2cat, int g2num, char *abbrev) strncpy(abbrev, param[p].abbrev, G2C_MAX_NOAA_ABBREV_LEN + 1); LOG((12, "abbrev %s", abbrev)); - + return G2C_NOERROR; } @@ -1138,7 +1138,7 @@ g2c_param_g2tog1(int g2disc, int g2cat, int g2num, int *g1num, int *g1ver) int p; LOG((2, "g2c_param_g2tog1 g2disc %d g2cat %d g2num %d", g2disc, g2cat, g2num)); - + /* Loop through array until matching values are found. */ for (p = 0; p < G2C_MAX_NOAA_PARAMS; p++) if (param[p].g2disc == g2disc && param[p].g2cat == g2cat && param[p].g2num == g2num) @@ -1202,8 +1202,6 @@ g2c_param_all(int param_idx, int *g1num, int *g1ver, int *g2disc, int *g2cat, *g2num = param[param_idx].g2num; if (abbrev) strncpy(abbrev, param[param_idx].abbrev, G2C_MAX_NOAA_ABBREV_LEN); - + return G2C_NOERROR; } - - diff --git a/src/g2cprod.c b/src/g2cprod.c index 3534ec96..839d8a08 100644 --- a/src/g2cprod.c +++ b/src/g2cprod.c @@ -1,4 +1,4 @@ -/** +/** * @file * @brief Product functions for the g2c library. * @author Ed Hartnett @date Oct 1, 2022 @@ -35,38 +35,38 @@ g2c_get_prod(int g2cid, int msg_num, int prod_num, int *num_data_points, float * unsigned char *buf; size_t bytes_read; int ret = G2C_NOERROR; - + /* Check inputs. */ if (g2cid < 0 || g2cid > G2C_MAX_FILES) - return G2C_EBADID; + return G2C_EBADID; if (msg_num < 0 || prod_num < 0) - return G2C_EINVAL; + return G2C_EINVAL; if (g2c_file[g2cid].g2cid != g2cid) - return G2C_EBADID; + return G2C_EBADID; /* Find the message. */ for (msg = g2c_file[g2cid].msg; msg; msg = msg->next) - if (msg->msg_num == msg_num) - break; + if (msg->msg_num == msg_num) + break; if (!msg) - return G2C_ENOMSG; + return G2C_ENOMSG; /* Find the product. After this, sec4 will point to the * appropropriate section 4 G2C_SECTION_INFO_T. */ for (sec4 = msg->sec; sec4; sec4 = sec4->next) - if (sec4->sec_num == 4 && ((G2C_SECTION4_INFO_T *)sec4->sec_info)->field_num == prod_num) - break; + if (sec4->sec_num == 4 && ((G2C_SECTION4_INFO_T *)sec4->sec_info)->field_num == prod_num) + break; if (!sec4) - return G2C_ENOPRODUCT; + return G2C_ENOPRODUCT; /* sec4_info = (G2C_SECTION4_INFO_T *)sec4->sec_info; */ /* Find the grid definiton section, section 3. It will come * earlier in the list. */ for (sec3 = sec4; sec3; sec3 = sec3->prev) - if (sec3->sec_num == 3) - break; + if (sec3->sec_num == 3) + break; if (!sec3) - return G2C_ENOSECTION; + return G2C_ENOSECTION; sec3_info = (G2C_SECTION3_INFO_T *)sec3->sec_info; /* Find the section 5, data representation section, to learn how @@ -76,7 +76,7 @@ g2c_get_prod(int g2cid, int msg_num, int prod_num, int *num_data_points, float * if (sec5->sec_num == 5) break; if (!sec5) - return G2C_ENOSECTION; + return G2C_ENOSECTION; sec5_info = (G2C_SECTION5_INFO_T *)sec5->sec_info; /* Find the section 7, data section. */ @@ -84,8 +84,8 @@ g2c_get_prod(int g2cid, int msg_num, int prod_num, int *num_data_points, float * if (sec7->sec_num == 7) break; if (!sec7) - return G2C_ENOSECTION; - + return G2C_ENOSECTION; + /* Give the caller number of data points, if desired. */ if (num_data_points) *num_data_points = sec5_info->num_data_points; @@ -97,20 +97,20 @@ g2c_get_prod(int g2cid, int msg_num, int prod_num, int *num_data_points, float * /* Allocate a char buffer to hold the packed data. */ if (!(buf = malloc(sizeof(char) * sec7->sec_len))) return G2C_ENOMEM; - + /* Jump to this section in the file. */ if (fseek(g2c_file[g2cid].f, sec7->bytes_to_sec + sec7->msg->bytes_to_msg, SEEK_SET)) - return G2C_ERROR; + return G2C_ERROR; /* Read the product into a char buffer. */ if ((bytes_read = fread(buf, 1, sec7->sec_len, g2c_file[g2cid].f)) != sec7->sec_len) - return G2C_EFILE; + return G2C_EFILE; /* Unpack the char buffer into a float array, which must be * allocated by the caller. */ ret = g2c_unpack7(buf, sec3_info->grid_def, sec3->template_len, sec3->template, - sec5_info->data_def, sec5->template_len, sec5->template, - sec5_info->num_data_points, data); + sec5_info->data_def, sec5->template_len, sec5->template, + sec5_info->num_data_points, data); /* Free the char buffer. */ free(buf); diff --git a/src/g2cutil.c b/src/g2cutil.c index 404abd88..10164285 100644 --- a/src/g2cutil.c +++ b/src/g2cutil.c @@ -1,4 +1,4 @@ -/** +/** * @file * @brief Internal utility functions for the NCEPLIBS-g2c library for * the new g2c API. @@ -28,61 +28,61 @@ extern G2C_CODE_TABLE_T *g2c_table; const char * g2c_strerror(int g2cerr) { - switch(g2cerr) + switch (g2cerr) { case G2C_NOERROR: - return "No error"; + return "No error"; case G2C_ENOTGRIB: - return "GRIB2 header not found"; + return "GRIB2 header not found"; case G2C_EMSGCOMPLETE: - return "GRIB message is already complete."; + return "GRIB message is already complete."; case G2C_ENAMETOOLONG: - return "Name too long"; + return "Name too long"; case G2C_EINVAL: - return "Invalid input"; + return "Invalid input"; case G2C_EFILE: - return "Error reading file"; + return "Error reading file"; case G2C_EBADID: - return "Bad ID"; + return "Bad ID"; case G2C_ETOOMANYFILES: - return "Too many files open"; + return "Too many files open"; case G2C_ENOMEM: - return "Out of memory"; + return "Out of memory"; case G2C_EMSG: - return "Error decoding message"; + return "Error decoding message"; case G2C_ENOMSG: - return "No GRIB message found"; + return "No GRIB message found"; case G2C_EXML: - return "Error parsing XML"; + return "Error parsing XML"; case G2C_ENOTFOUND: - return "Table or entry not found"; + return "Table or entry not found"; case G2C_ENOTGRIB2: - return "Not GRIB 2"; + return "Not GRIB 2"; case G2C_ENOSECTION: - return "Cannot find section"; + return "Cannot find section"; case G2C_ENOEND: - return "Cannot find end of GRIB message"; + return "Cannot find end of GRIB message"; case G2C_EBADEND: - return "End of message in wrong place"; + return "End of message in wrong place"; case G2C_EBADSECTION: - return "Invalid section number"; + return "Invalid section number"; case G2C_EJPEG: - return "Error encoding/decoding JPEG data"; + return "Error encoding/decoding JPEG data"; case G2C_EPNG: - return "Error encoding/decoding PNG data"; + return "Error encoding/decoding PNG data"; case G2C_ENOTEMPLATE: - return "Template not found"; + return "Template not found"; case G2C_EBADTEMPLATE: - return "Template problem"; + return "Template problem"; case G2C_ENOPARAM: - return "Parameter not found"; + return "Parameter not found"; case G2C_ENOPRODUCT: - return "Product not found"; + return "Product not found"; case G2C_EBADTYPE: - return "Bad type"; + return "Bad type"; default: - return "Unknown Error"; + return "Unknown Error"; } } @@ -106,34 +106,34 @@ g2c_log_section1(G2C_MESSAGE_INFO_T *msg) /* Read in the CSV GRIB2 code definitions. */ if ((ret = g2c_csv_init())) - return ret; + return ret; /* Section 0 discipline flag. */ if ((ret = g2c_find_desc("Code table 0.0", msg->discipline, desc))) - return ret; + return ret; LOG((4, "Discipline: %s", desc)); /* Section 1 flags. */ LOG((4, "Identification of originating/generating center: %d", msg->center)); LOG((4, "Identification of originating/generating subcenter: %d", msg->subcenter)); if ((ret = g2c_find_desc("Code table 1.0", msg->master_version, desc))) - return ret; - LOG((4, "GRIB master tables version number: %s", desc)); + return ret; + LOG((4, "GRIB master tables version number: %s", desc)); if ((ret = g2c_find_desc("Code table 1.1", msg->local_version, desc))) - return ret; + return ret; LOG((4, "Version number of GRIB local tables used to augment Master Tables: %s", desc)); if ((ret = g2c_find_desc("Code table 1.2", msg->sig_ref_time, desc))) - return ret; + return ret; LOG((4, "Significance of reference time: %s", desc)); LOG((4, "Reference time: %d/%d/%d %d:%d:%d", msg->year, msg->month, msg->day, - msg->hour, msg->minute, msg->second)); + msg->hour, msg->minute, msg->second)); if ((ret = g2c_find_desc("Code table 1.3", msg->status, desc))) - return ret; + return ret; LOG((4, "Production Status of Processed data in the GRIB message: %s", desc)); if ((ret = g2c_find_desc("Code table 1.4", msg->type, desc))) - return ret; + return ret; LOG((4, "Type of processed data in this GRIB message: %s", desc)); - + #endif return G2C_NOERROR; } @@ -143,7 +143,7 @@ g2c_log_section1(G2C_MESSAGE_INFO_T *msg) * * @param sec Pointer to ::G2C_SECTION_INFO_T. * - * @return + * @return * - ::G2C_NOERROR No error. * * @author Ed Hartnett 10/20/22 @@ -153,20 +153,20 @@ g2c_log_section(G2C_SECTION_INFO_T *sec) { #ifdef LOGGING int ret; - + LOG((3, "sec_id %d sec_len %d byte_to_sec %ld sec_num %d", sec->sec_id, sec->sec_len, sec->bytes_to_sec, sec->sec_num)); if (sec->sec_num == 4) { char abbrev[G2C_MAX_NOAA_ABBREV_LEN + 1]; - + /* Look up the parameter abbreviation with the discipline, * category, and product number. */ if ((ret = g2c_param_abbrev(sec->msg->discipline, sec->template[0], sec->template[1], abbrev))) return ret; LOG((4, "%s", abbrev)); } - + #endif return G2C_NOERROR; } @@ -175,10 +175,10 @@ g2c_log_section(G2C_SECTION_INFO_T *sec) * Print a summary of the contents of an open GRIB2 file. If the * NCEPLIBS-g2c library is built without the LOGGING option, this * function will do nothing. - * + * * @param g2cid The file ID, returned by g2c_open() or g2c_create(). * - * @return + * @return * - ::G2C_NOERROR No error. * - ::G2C_EBADID g2cid not found. * @@ -193,29 +193,29 @@ g2c_log_file(int g2cid) /* Read in the CSV GRIB2 code definitions. */ if ((ret = g2c_csv_init())) - return ret; - + return ret; + /* Find the open file struct. */ if (g2c_file[g2cid].g2cid != g2cid) - return G2C_EBADID; + return G2C_EBADID; LOG((1, "path %s", g2c_file[g2cid].path)); LOG((1, "num_messages %ld", g2c_file[g2cid].num_messages)); for (msg = g2c_file[g2cid].msg; msg; msg = msg->next) { G2C_SECTION_INFO_T *sec; - - LOG((1, "message %ld bytes_to_msg %ld bytes_in_msg %ld num_fields %d num_local %d", - msg->msg_num, msg->bytes_to_msg, msg->bytes_in_msg, msg->num_fields, msg->num_local)); + + LOG((1, "message %ld bytes_to_msg %ld bytes_in_msg %ld num_fields %d num_local %d", + msg->msg_num, msg->bytes_to_msg, msg->bytes_in_msg, msg->num_fields, msg->num_local)); LOG((1, "sec1_len %d center %d subcenter %d master_version %d local_version %d", msg->sec1_len, msg->center, msg->subcenter, msg->master_version, msg->local_version)); LOG((1, "sig_ref_time %d %d %d %d %d:%d:%d status %d type %d", msg->sig_ref_time, msg->year, msg->month, msg->day, msg->hour, msg->minute, msg->second, msg->status, msg->type)); - /* If we've loaded CSV tables, decode some flags. */ - if (g2c_table) - if ((ret = g2c_log_section1(msg))) - return ret; + /* If we've loaded CSV tables, decode some flags. */ + if (g2c_table) + if ((ret = g2c_log_section1(msg))) + return ret; /* Section info. */ for (sec = msg->sec; sec; sec = sec->next) diff --git a/src/gbits.c b/src/gbits.c index 77884a4b..03c4db69 100644 --- a/src/gbits.c +++ b/src/gbits.c @@ -59,7 +59,7 @@ gbits(unsigned char *in, g2int *iout, g2int iskip, g2int nbits, { g2int i, tbit, bitcnt, ibit, itmp; g2int nbit, index; - static g2int ones[]={1, 3, 7, 15, 31, 63, 127, 255}; + static g2int ones[] = {1, 3, 7, 15, 31, 63, 127, 255}; /* nbit is the start position of the field in bits */ nbit = iskip; @@ -71,10 +71,10 @@ gbits(unsigned char *in, g2int *iout, g2int iskip, g2int nbits, nbit = nbit + nbits + nskip; /* first byte */ - tbit = (bitcnt < (8 - ibit)) ? bitcnt : 8 - ibit; // find min + tbit = (bitcnt < (8 - ibit)) ? bitcnt : 8 - ibit; // find min itmp = (int)*(in + index) & ones[7 - ibit]; if (tbit != 8 - ibit) - itmp >>= (8 - ibit - tbit); + itmp >>= (8 - ibit - tbit); index++; bitcnt = bitcnt - tbit; @@ -90,7 +90,7 @@ gbits(unsigned char *in, g2int *iout, g2int iskip, g2int nbits, if (bitcnt > 0) { itmp = (itmp << bitcnt) | - (((int)*(in + index) >> (8 - bitcnt)) & ones[bitcnt - 1]); + (((int)*(in + index) >> (8 - bitcnt)) & ones[bitcnt - 1]); } iout[i] = itmp; @@ -127,7 +127,7 @@ g2c_gbit_int(unsigned char *in, int *iout, int iskip, int nbits) * @param nskip Additional number of bits to skip on each iteration. * @param n Number of iterations. * - * @return + * @return * - ::G2C_NOERROR No error. * - ::G2C_ENOMEM Out of memory. * @@ -135,28 +135,28 @@ g2c_gbit_int(unsigned char *in, int *iout, int iskip, int nbits) */ int g2c_gbits_int(unsigned char *in, int *iout, int iskip, int nbits, - int nskip, int n) + int nskip, int n) { g2int *g2iout; int i; /* The in parameter is required. */ if (!in) - return G2C_EINVAL; + return G2C_EINVAL; /* Get some memory for results. */ if (!(g2iout = malloc(n * sizeof(g2int)))) - return G2C_ENOMEM; - + return G2C_ENOMEM; + gbits(in, g2iout, iskip, nbits, nskip, n); /* Copy from g2int to int. */ for (i = 0; i < n; i++) - iout[i] = (int)g2iout[i]; + iout[i] = (int)g2iout[i]; /* Free memory. */ free(g2iout); - + return G2C_NOERROR; } @@ -180,7 +180,7 @@ sbits(unsigned char *out, g2int *in, g2int iskip, g2int nbits, { g2int i, bitcnt, tbit, ibit, itmp, imask, itmp2, itmp3; g2int nbit, index; - static g2int ones[]={1, 3, 7, 15, 31, 63, 127, 255}; + static g2int ones[] = {1, 3, 7, 15, 31, 63, 127, 255}; /* number bits from zero to ... nbit is the last bit of the field * to be filled. */ @@ -196,7 +196,7 @@ sbits(unsigned char *out, g2int *in, g2int iskip, g2int nbits, /* make byte aligned */ if (ibit != 7) { - tbit = (bitcnt < (ibit+1)) ? bitcnt : ibit + 1; /* find min */ + tbit = (bitcnt < (ibit + 1)) ? bitcnt : ibit + 1; /* find min */ imask = ones[tbit - 1] << (7 - ibit); itmp2 = (itmp << (7 - ibit)) & imask; itmp3 = (int)*(out + index) & (255 - imask); @@ -224,5 +224,4 @@ sbits(unsigned char *out, g2int *in, g2int iskip, g2int nbits, out[index] = (unsigned char)(itmp2 | itmp3); } } - } diff --git a/src/getdim.c b/src/getdim.c index 2e824be5..1bba58fb 100644 --- a/src/getdim.c +++ b/src/getdim.c @@ -3,9 +3,9 @@ * @author Stephen Gilbert @date 2002-12-11 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /** * Return the dimensions and scanning mode of a grid definition. @@ -30,75 +30,72 @@ getdim(unsigned char *csec3, g2int *width, g2int *height, g2int *iscan) g2int *igds = NULL; g2int iofst, igdtlen, num_opt, jerr; - iofst = 0; /* set offset to beginning of section */ + iofst = 0; /* set offset to beginning of section */ if (!(jerr = g2_unpack3(csec3, &iofst, &igds, &igdstmpl, &igdtlen, &list_opt, &num_opt))) { - switch (igds[4]) /* Template number */ + switch (igds[4]) /* Template number */ { - case 0: /* Lat/Lon */ + case 0: /* Lat/Lon */ case 1: case 2: - case 3: - { + case 3: { *width = igdstmpl[7]; *height = igdstmpl[8]; *iscan = igdstmpl[18]; break; } - case 10: /* Mercator */ + case 10: /* Mercator */ { *width = igdstmpl[7]; *height = igdstmpl[8]; *iscan = igdstmpl[15]; break; } - case 20: /* Polar Stereographic */ + case 20: /* Polar Stereographic */ { *width = igdstmpl[7]; *height = igdstmpl[8]; *iscan = igdstmpl[17]; break; } - case 30: /* Lambert Conformal */ + case 30: /* Lambert Conformal */ { *width = igdstmpl[7]; *height = igdstmpl[8]; *iscan = igdstmpl[17]; break; } - case 40: /* Gaussian */ + case 40: /* Gaussian */ case 41: case 42: - case 43: - { + case 43: { *width = igdstmpl[7]; *height = igdstmpl[8]; *iscan = igdstmpl[18]; break; } - case 90: /* Space View/Orthographic */ + case 90: /* Space View/Orthographic */ { *width = igdstmpl[7]; *height = igdstmpl[8]; *iscan = igdstmpl[16]; break; } - case 110: /* Equatorial Azimuthal */ + case 110: /* Equatorial Azimuthal */ { *width = igdstmpl[7]; *height = igdstmpl[8]; *iscan = igdstmpl[15]; break; } - default: - { + default: { *width = 0; *height = 0; *iscan = 0; break; } - } /* end switch */ + } /* end switch */ } else { diff --git a/src/getpoly.c b/src/getpoly.c index dab16df3..f163e69a 100644 --- a/src/getpoly.c +++ b/src/getpoly.c @@ -4,9 +4,9 @@ * coefficients using GDT 5.50 through 5.53 * @author Stephen Gilbert @date 2002-12-11 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /** * This subroutine returns the J, K, and M pentagonal resolution @@ -44,30 +44,28 @@ getpoly(unsigned char *csec3, g2int *jj, g2int *kk, g2int *mm) g2int *igds; g2int iofst, igdtlen, num_opt; - iofst = 0; /* set offset to beginning of section */ + iofst = 0; /* set offset to beginning of section */ if (!g2_unpack3(csec3, &iofst, &igds, &igdstmpl, &igdtlen, - &list_opt, &num_opt)) + &list_opt, &num_opt)) { - switch (igds[4]) /* Template number */ + switch (igds[4]) /* Template number */ { - case 50: /* Spherical harmonic coefficients */ + case 50: /* Spherical harmonic coefficients */ case 51: case 52: - case 53: - { + case 53: { *jj = igdstmpl[0]; *kk = igdstmpl[1]; *mm = igdstmpl[2]; break; } - default: - { + default: { *jj = 0; *kk = 0; *mm = 0; break; } - } /* end switch */ + } /* end switch */ } else { @@ -77,11 +75,11 @@ getpoly(unsigned char *csec3, g2int *jj, g2int *kk, g2int *mm) } if (igds) - free(igds); + free(igds); if (igdstmpl) - free(igdstmpl); + free(igdstmpl); if (list_opt) - free(list_opt); + free(list_opt); return 0; } diff --git a/src/grib2.h.in b/src/grib2.h.in index deaaaddb..12f77489 100644 --- a/src/grib2.h.in +++ b/src/grib2.h.in @@ -17,16 +17,16 @@ #ifndef _grib2_H #define _grib2_H -#include #include +#include #include #include #define G2C_VERSION "@pVersion@" /**< Current version of NCEPLIBS-g2c library. */ -#cmakedefine G2_PNG_ENABLED 1 /**< Decoding/encoding PNG is enabled */ +#cmakedefine G2_PNG_ENABLED 1 /**< Decoding/encoding PNG is enabled */ #cmakedefine G2_JPEG2000_ENABLED 1 /**< Decoding/encoding JPEG2000 is enabled */ -#cmakedefine G2_AEC_ENABLED 1 /**< Decoding/encoding AEC/CCSDS is enabled */ +#cmakedefine G2_AEC_ENABLED 1 /**< Decoding/encoding AEC/CCSDS is enabled */ /** Long integer type. */ typedef int64_t g2int; @@ -268,30 +268,29 @@ void aecpack(float *fld, g2int width, g2int height, g2int *idrstmpl, g2int aecunpack(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, float *fld); - /* The new g2c API is being introduced in version 2.0 of the library. */ /* Data types. */ -#define G2C_BYTE 1 /**< signed 1 byte integer */ -#define G2C_CHAR 2 /**< ISO/ASCII character */ -#define G2C_SHORT 3 /**< signed 2 byte integer */ -#define G2C_INT 4 /**< signed 4 byte integer */ -#define G2C_FLOAT 5 /**< single precision floating point number */ -#define G2C_DOUBLE 6 /**< double precision floating point number */ -#define G2C_UBYTE 7 /**< unsigned 1 byte int */ -#define G2C_USHORT 8 /**< unsigned 2-byte int */ -#define G2C_UINT 9 /**< unsigned 4-byte int */ -#define G2C_INT64 10 /**< signed 8-byte int */ -#define G2C_UINT64 11 /**< unsigned 8-byte int */ +#define G2C_BYTE 1 /**< signed 1 byte integer */ +#define G2C_CHAR 2 /**< ISO/ASCII character */ +#define G2C_SHORT 3 /**< signed 2 byte integer */ +#define G2C_INT 4 /**< signed 4 byte integer */ +#define G2C_FLOAT 5 /**< single precision floating point number */ +#define G2C_DOUBLE 6 /**< double precision floating point number */ +#define G2C_UBYTE 7 /**< unsigned 1 byte int */ +#define G2C_USHORT 8 /**< unsigned 2-byte int */ +#define G2C_UINT 9 /**< unsigned 4-byte int */ +#define G2C_INT64 10 /**< signed 8-byte int */ +#define G2C_UINT64 11 /**< unsigned 8-byte int */ /* Defines for file handling. */ -#define G2C_MAX_FILES 3 /**< Maximum number of open files. */ -#define G2C_MAX_NAME 1024 /**< Maximum length of a name. */ -#define G2C_NOWRITE 0x0000 /**< Set read-only access for g2c_open(). */ -#define G2C_WRITE 0x0001 /**< Set read-write access for g2c_open(). */ -#define G2C_CLOBBER 0x0000 /**< Destroy existing file. Mode flag for g2c_create(). */ -#define G2C_NOCLOBBER 0x0004 /**< Don't destroy existing file. Mode flag for g2c_create(). */ -#define G2C_LARGE_FILE_INDEX 0x0008 /**< Create a large file index. Mode flag for g2c_write_index(). */ +#define G2C_MAX_FILES 3 /**< Maximum number of open files. */ +#define G2C_MAX_NAME 1024 /**< Maximum length of a name. */ +#define G2C_NOWRITE 0x0000 /**< Set read-only access for g2c_open(). */ +#define G2C_WRITE 0x0001 /**< Set read-write access for g2c_open(). */ +#define G2C_CLOBBER 0x0000 /**< Destroy existing file. Mode flag for g2c_create(). */ +#define G2C_NOCLOBBER 0x0004 /**< Don't destroy existing file. Mode flag for g2c_create(). */ +#define G2C_LARGE_FILE_INDEX 0x0008 /**< Create a large file index. Mode flag for g2c_write_index(). */ /* Useful constants. */ #define G2C_SECTION0_BYTES 16 /**< Number of bytes in section 0. */ @@ -300,15 +299,15 @@ g2int aecunpack(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, * data at the end of the section). */ #define G2C_SECTION1_BYTES 21 -#define G2C_SECTION0_LEN 3 /**< Length of section 0 array. */ +#define G2C_SECTION0_LEN 3 /**< Length of section 0 array. */ #define G2C_SECTION1_LEN 13 /**< Length of section 1 array. */ /* Constants to help with templates. */ -#define G2C_MAX_GDS_TEMPLATE 31 /**< Maximum number of grid templates. */ +#define G2C_MAX_GDS_TEMPLATE 31 /**< Maximum number of grid templates. */ #define G2C_MAX_GDS_TEMPLATE_MAPLEN 28 /**< Maximum grid template map length. */ -#define G2C_MAX_PDS_TEMPLATE 47 /**< Maximum number of PDS templates. */ +#define G2C_MAX_PDS_TEMPLATE 47 /**< Maximum number of PDS templates. */ #define G2C_MAX_PDS_TEMPLATE_MAPLEN 45 /**< Maximum template map length. */ -#define G2C_MAX_DRS_TEMPLATE 10 /**< Maximum number of DRS templates. */ +#define G2C_MAX_DRS_TEMPLATE 10 /**< Maximum number of DRS templates. */ #define G2C_MAX_DRS_TEMPLATE_MAPLEN 18 /**< Maximum DRS template map length. */ /* File handling functions. */ @@ -402,7 +401,7 @@ int g2c_aecunpackd(unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts /* Testing. */ int g2c_compare(int g2cid1, int g2cid2); - + /* Output. */ int g2c_degrib2(int g2cid, const char *fileout); @@ -414,22 +413,22 @@ int g2c_param_all(int param_idx, int *g1ver, int *g1val, int *g2disc, int *g2cat int *g2num, char *abbdrev); /* Useful constants. */ -#define G2C_SECTION0_ARRAY_LEN 3 /**< Length of section 0 array. */ +#define G2C_SECTION0_ARRAY_LEN 3 /**< Length of section 0 array. */ #define G2C_SECTION1_ARRAY_LEN 13 /**< Length of section 1 array. */ #define G2C_JPEG_DRS_TEMPLATE_LEN 7 /**< Length of the idrstmpl array for JPEG packing. */ -#define G2C_PNG_DRS_TEMPLATE_LEN 5 /**< Length of the idrstmpl array for PNG packing. */ -#define G2C_AEC_DRS_TEMPLATE_LEN 8 /**< Length of the idrstmpl array for AEC packing. */ +#define G2C_PNG_DRS_TEMPLATE_LEN 5 /**< Length of the idrstmpl array for PNG packing. */ +#define G2C_AEC_DRS_TEMPLATE_LEN 8 /**< Length of the idrstmpl array for AEC packing. */ -#define G2C_MAX_GRIB_DESC_LEN 512 /**< Maximum length of code description. */ -#define G2C_MAX_GRIB_STATUS_LEN 40 /**< Maximum length of code status. */ +#define G2C_MAX_GRIB_DESC_LEN 512 /**< Maximum length of code description. */ +#define G2C_MAX_GRIB_STATUS_LEN 40 /**< Maximum length of code status. */ #define G2C_MAX_GRIB_LEVEL_DESC_LEN 40 /**< Maximum length of level description. */ -#define G2C_MAX_GRIB_CODE_LEN 20 /**< Maximum length of code. */ -#define G2C_MAX_GRIB_TITLE_LEN 200 /**< Maximum length of code table title. */ -#define G2C_MAX_NUM_SECTIONS 1024 /**< Maximum number of sections that can be handled in one message. */ +#define G2C_MAX_GRIB_CODE_LEN 20 /**< Maximum length of code. */ +#define G2C_MAX_GRIB_TITLE_LEN 200 /**< Maximum length of code table title. */ +#define G2C_MAX_NUM_SECTIONS 1024 /**< Maximum number of sections that can be handled in one message. */ -#define G2C_MAX_NOAA_PARAMS 2000 /**< Maximum number of known parameters with NOAA abbreviations. */ -#define G2C_MAX_NOAA_ABBREV_LEN 8 /**< Maximum length of a NOAA abbreviation of a parameter. */ +#define G2C_MAX_NOAA_PARAMS 2000 /**< Maximum number of known parameters with NOAA abbreviations. */ +#define G2C_MAX_NOAA_ABBREV_LEN 8 /**< Maximum length of a NOAA abbreviation of a parameter. */ #define G2C_MAX_NOAA_PARAM_LINE_LEN 120 /**< Maximum length of a line in the NOAA abbreviation CSV file. */ #define G2C_JASPER_MAX_MEM @JASPER_MAX_MEM@ /**< Maximum size for the Jasper memory buffer. */ @@ -514,7 +513,7 @@ int g2c_param_all(int param_idx, int *g1ver, int *g1val, int *g2disc, int *g2cat #define G2C_ENOPARAM (-71) /**< Parameter not found. */ #define G2C_ENOPRODUCT (-72) /**< Product not found. */ #define G2C_EBADTYPE (-73) /**< Type not found. */ -#define G2C_EAEC (-74) /**< Error encoding/decoding AEC data. */ +#define G2C_EAEC (-74) /**< Error encoding/decoding AEC data. */ #define G2C_ECSV (-75) /**< CSV error. */ -#endif /* _grib2_H */ +#endif /* _grib2_H */ diff --git a/src/grib2_int.h b/src/grib2_int.h index 75c6f071..3e214109 100644 --- a/src/grib2_int.h +++ b/src/grib2_int.h @@ -8,11 +8,11 @@ #ifndef _grib2_int_H #define _grib2_int_H -#include -#include -#include #include #include +#include +#include +#include #include #if defined(WIN32) @@ -44,12 +44,12 @@ /** Maximum number of messages in a file. */ #define G2C_MAX_MESSAGES 1024 -#define BYTE 8 /**< Number of bits in a byte. */ +#define BYTE 8 /**< Number of bits in a byte. */ #define WORD 32 /**< Number of bits in four bytes. */ -#define ONE_BYTE 1 /**< One byte. */ -#define TWO_BYTES 2 /**< Two bytes. */ -#define FOUR_BYTES 4 /**< Four bytes. */ +#define ONE_BYTE 1 /**< One byte. */ +#define TWO_BYTES 2 /**< Two bytes. */ +#define FOUR_BYTES 4 /**< Four bytes. */ #define EIGHT_BYTES 8 /**< Eight bytes. */ /** Latitude */ @@ -91,16 +91,18 @@ #define EXTERN_MUTEX(m) extern pthread_mutex_t m; /** Define a macro to start a critical section for thread safety. */ -#define MUTEX_LOCK(m) \ - do { \ - pthread_mutex_lock(&m); \ - } while(0) +#define MUTEX_LOCK(m) \ + do \ + { \ + pthread_mutex_lock(&m); \ + } while (0) /** Define a macro to end a critical section for thread safety. */ -#define MUTEX_UNLOCK(m) \ - do { \ - pthread_mutex_unlock(&m); \ - } while(0) +#define MUTEX_UNLOCK(m) \ + do \ + { \ + pthread_mutex_unlock(&m); \ + } while (0) #else /* not PTHREADS */ @@ -126,66 +128,66 @@ * big-endian 8-byte ints. */ #define hton64(y) (((uint64_t)htonl(y)) << WORD | htonl(y >> WORD)) -#define G2C_FILE_READ 0 /**< Read. */ +#define G2C_FILE_READ 0 /**< Read. */ #define G2C_FILE_WRITE 1 /**< Write. */ /** This is the information about each message. */ typedef struct g2c_message_info { - size_t msg_num; /**< Number of message in file (0-based). */ - size_t bytes_to_msg; /**< Number of bytes to skip in the file, to get to this message. */ - size_t bytes_in_msg; /**< Number of bytes in this message. */ - unsigned char discipline; /**< Discipline from section 0. */ + size_t msg_num; /**< Number of message in file (0-based). */ + size_t bytes_to_msg; /**< Number of bytes to skip in the file, to get to this message. */ + size_t bytes_in_msg; /**< Number of bytes in this message. */ + unsigned char discipline; /**< Discipline from section 0. */ int section1[G2C_SECTION1_ARRAY_LEN]; /**< Section 1 array. */ - int num_fields; /**< Number of fields in the message. */ - int num_local; /**< Number of local sections in the message. */ - size_t bytes_to_local; /**< Number of bytes in the message before the (first) local section. */ - size_t bytes_to_bms; /**< Number of bytes in the message to the bitmap section. */ - size_t bytes_to_data; /**< Number of bytes in the message to the (first) data section. */ - int num_sections; /**< Number of sections in the file. */ - int *section_number; /**< Array (length num_sections) of section numbers. */ - size_t *section_offset; /**< Array (length num_sections) of byte offsets from start of message to section. */ - int sec1_len; /**< Length of section 1. */ - short center; /**< Originating center. */ - short subcenter; /**< Originating subcenter. */ - unsigned char master_version; /**< GRIB master tables version number. */ - unsigned char local_version; /**< Version number of GRIB local tables used to augment Master Tables. */ - unsigned char sig_ref_time; /**< Significance of reference time. */ - short year; /**< Year. */ - unsigned char month; /**< Month. */ - unsigned char day; /**< Day. */ - unsigned char hour; /**< Hour. */ - unsigned char minute; /**< Minute. */ - unsigned char second; /**< Second. */ - unsigned char status; /**< Production Status of Processed data in the GRIB message. */ - unsigned char type; /**< Type of processed data in this GRIB message. */ - struct g2c_section_info *sec; /**< List of section metadata. */ - struct g2c_file_info *file; /**< Pointer to containing file. */ - struct g2c_message_info *next; /**< Pointer to next in list. */ + int num_fields; /**< Number of fields in the message. */ + int num_local; /**< Number of local sections in the message. */ + size_t bytes_to_local; /**< Number of bytes in the message before the (first) local section. */ + size_t bytes_to_bms; /**< Number of bytes in the message to the bitmap section. */ + size_t bytes_to_data; /**< Number of bytes in the message to the (first) data section. */ + int num_sections; /**< Number of sections in the file. */ + int *section_number; /**< Array (length num_sections) of section numbers. */ + size_t *section_offset; /**< Array (length num_sections) of byte offsets from start of message to section. */ + int sec1_len; /**< Length of section 1. */ + short center; /**< Originating center. */ + short subcenter; /**< Originating subcenter. */ + unsigned char master_version; /**< GRIB master tables version number. */ + unsigned char local_version; /**< Version number of GRIB local tables used to augment Master Tables. */ + unsigned char sig_ref_time; /**< Significance of reference time. */ + short year; /**< Year. */ + unsigned char month; /**< Month. */ + unsigned char day; /**< Day. */ + unsigned char hour; /**< Hour. */ + unsigned char minute; /**< Minute. */ + unsigned char second; /**< Second. */ + unsigned char status; /**< Production Status of Processed data in the GRIB message. */ + unsigned char type; /**< Type of processed data in this GRIB message. */ + struct g2c_section_info *sec; /**< List of section metadata. */ + struct g2c_file_info *file; /**< Pointer to containing file. */ + struct g2c_message_info *next; /**< Pointer to next in list. */ } G2C_MESSAGE_INFO_T; /** Information about a section 3 through 7 in a GRIB2 message. */ typedef struct g2c_section_info { - int sec_id; /**< ID of the section (0-based). */ - unsigned int sec_len; /**< Length of the section (in bytes). */ - size_t bytes_to_sec; /**< Number of bytes from start of message to this section. */ - unsigned char sec_num; /**< Section number. */ - G2C_MESSAGE_INFO_T *msg; /**< Pointer to contianing message. */ - void *sec_info; /**< Pointer to struct specific for section 3, 4, 5, 6, or 7. */ + int sec_id; /**< ID of the section (0-based). */ + unsigned int sec_len; /**< Length of the section (in bytes). */ + size_t bytes_to_sec; /**< Number of bytes from start of message to this section. */ + unsigned char sec_num; /**< Section number. */ + G2C_MESSAGE_INFO_T *msg; /**< Pointer to contianing message. */ + void *sec_info; /**< Pointer to struct specific for section 3, 4, 5, 6, or 7. */ struct g2c_section_info *next; /**< Pointer to next in list. */ struct g2c_section_info *prev; /**< Pointer to previous in list. */ - long long int *template; /**< Grid, product, or data template. */ - int template_len; /**< Number of entries in template. */ + long long int *template; /**< Grid, product, or data template. */ + int template_len; /**< Number of entries in template. */ } G2C_SECTION_INFO_T; /** Keep information about dimensions defined in section 3. */ typedef struct g2c_dim_info { - int dimid; /**< Dimension ID. */ - size_t len; /**< Length of dimension. */ + int dimid; /**< Dimension ID. */ + size_t len; /**< Length of dimension. */ char name[G2C_MAX_NAME + 1]; /**< Name of dimension. */ - float *value; /**< Array of dimension values. */ + float *value; /**< Array of dimension values. */ } G2C_DIM_INFO_T; /** Information about [Section 3 GRID DEFINITION @@ -193,12 +195,12 @@ typedef struct g2c_dim_info typedef struct g2c_section3_info { unsigned char source_grid_def; /**< Source of grid definition (See Table 3.0). */ - unsigned int num_data_points; /**< Number of data points. */ - unsigned char num_opt; /**< Number of octets for optional list of numbers defining number of points. */ - unsigned char interp_list; /**< Interpetation of list of numbers defining number of points (See Table 3.11). */ - unsigned short grid_def; /**< Grid definition template number (= N) (See Table 3.1). */ - int *optional; /**< Optional list of numbers defining number of points. */ - G2C_DIM_INFO_T dim[2]; /**< Dimension information. */ + unsigned int num_data_points; /**< Number of data points. */ + unsigned char num_opt; /**< Number of octets for optional list of numbers defining number of points. */ + unsigned char interp_list; /**< Interpetation of list of numbers defining number of points (See Table 3.11). */ + unsigned short grid_def; /**< Grid definition template number (= N) (See Table 3.1). */ + int *optional; /**< Optional list of numbers defining number of points. */ + G2C_DIM_INFO_T dim[2]; /**< Dimension information. */ } G2C_SECTION3_INFO_T; /** Information about [Section 4 PRODUCT DEFINITION @@ -207,8 +209,8 @@ typedef struct g2c_section4_info { int field_num; unsigned short num_coord; /**< Number of coordinate values after template. */ - unsigned short prod_def; /**< Product definition template number (See Table 4.0). */ - int *optional; /**< Optional list of numbers defining number of points. */ + unsigned short prod_def; /**< Product definition template number (See Table 4.0). */ + int *optional; /**< Optional list of numbers defining number of points. */ } G2C_SECTION4_INFO_T; /** Information about [Section 5 DATA REPRESENTATION @@ -234,11 +236,11 @@ typedef struct g2c_section6_info /** This is the information about each open file. */ typedef struct g2c_file_info { - int g2cid; /**< ID of the file. */ + int g2cid; /**< ID of the file. */ char path[G2C_MAX_NAME + 1]; /**< Path of the file. */ - FILE *f; /**< FILE pointer to open file. */ - size_t num_messages; /**< Number of messages in the file. */ - G2C_MESSAGE_INFO_T *msg; /**< Information about each message in the file. */ + FILE *f; /**< FILE pointer to open file. */ + size_t num_messages; /**< Number of messages in the file. */ + G2C_MESSAGE_INFO_T *msg; /**< Information about each message in the file. */ } G2C_FILE_INFO_T; /** An entry in a GRIB2 code table. */ @@ -261,11 +263,11 @@ typedef struct g2c_code_table /** An entry in the table of NOAA abbreviations for GRIB parameters. */ typedef struct g2c_param { - int g1num; /**< GRIB1 parameter number. */ - int g1ver; /**< GRIB1 table version. */ - int g2disc; /**< GRIB2 discipline. */ - int g2cat; /**< GRIB2 category number. */ - int g2num; /**< GRIB2 parameter number. */ + int g1num; /**< GRIB1 parameter number. */ + int g1ver; /**< GRIB1 table version. */ + int g2disc; /**< GRIB2 discipline. */ + int g2cat; /**< GRIB2 category number. */ + int g2num; /**< GRIB2 parameter number. */ char abbrev[G2C_MAX_NOAA_ABBREV_LEN + 1]; /**< NOAA abbreviation for this parameter. */ } G2C_PARAM_T; @@ -427,4 +429,4 @@ void g2_log(int severity, const char *fmt, ...); #endif /* LOGGING */ -#endif /* _grib2_int_H */ +#endif /* _grib2_int_H */ diff --git a/src/gridtemplates.c b/src/gridtemplates.c index 43fbdc51..9f916d86 100644 --- a/src/gridtemplates.c +++ b/src/gridtemplates.c @@ -45,9 +45,9 @@ */ struct gridtemplate { - g2int template_num; /**< Template number. */ - g2int mapgridlen; /**< The number of entries in the template. */ - g2int needext; /**< Does template need extension? */ + g2int template_num; /**< Template number. */ + g2int mapgridlen; /**< The number of entries in the template. */ + g2int needext; /**< Does template need extension? */ g2int mapgrid[G2C_MAX_GDS_TEMPLATE_MAPLEN]; /**< Number of bytes for each template value. */ }; @@ -55,72 +55,71 @@ struct gridtemplate * Templates grid. */ static const struct gridtemplate templatesgrid[G2C_MAX_GDS_TEMPLATE] = -{ - /* 3.0: Lat/Lon grid */ - {0, 19, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1}}, - /* 3.1: Rotated Lat/Lon grid */ - {1, 22, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, 4}}, - /* 3.2: Stretched Lat/Lon grid */ - {2, 22, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, -4}}, - /* 3.3: Stretched & Rotated Lat/Lon grid */ - {3, 25, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, 4, -4, 4, -4}}, - /* Added GDT 3.4,3.5 (08/05/2013) */ - /* 3.4: Variable resolution Latitude/Longitude */ - {4, 13, 1, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, 1, 1}}, - /* 3.5: Variable resolution rotate Latitude/Longitude */ - {5, 16, 1, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, 1, 1, -4, 4, 4}}, - /* 3.12: Transverse Mercator */ - {12, 22, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, -4, 4, 4, 1, 4, 4, -4, -4, -4, -4}}, - /* 3.101: General unstructured grid */ - {101, 4, 0, {1, 4, 1, -4}}, - /* 3.140: Lambert Azimuthal Equal Area Projection */ - {140, 17, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 4, 4, 1, 4, 4, 1}}, + { + /* 3.0: Lat/Lon grid */ + {0, 19, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1}}, + /* 3.1: Rotated Lat/Lon grid */ + {1, 22, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, 4}}, + /* 3.2: Stretched Lat/Lon grid */ + {2, 22, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, -4}}, + /* 3.3: Stretched & Rotated Lat/Lon grid */ + {3, 25, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, 4, -4, 4, -4}}, + /* Added GDT 3.4,3.5 (08/05/2013) */ + /* 3.4: Variable resolution Latitude/Longitude */ + {4, 13, 1, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, 1, 1}}, + /* 3.5: Variable resolution rotate Latitude/Longitude */ + {5, 16, 1, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, 1, 1, -4, 4, 4}}, + /* 3.12: Transverse Mercator */ + {12, 22, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, -4, 4, 4, 1, 4, 4, -4, -4, -4, -4}}, + /* 3.101: General unstructured grid */ + {101, 4, 0, {1, 4, 1, -4}}, + /* 3.140: Lambert Azimuthal Equal Area Projection */ + {140, 17, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 4, 4, 1, 4, 4, 1}}, - /* 3.10: Mercator */ - {10, 19, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, -4, -4, 4, 1, 4, 4, 4}}, - /* 3.20: Polar Stereographic Projection */ - {20, 18, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, 1}}, - /* 3.30: Lambert Conformal */ - {30, 22, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, 1, -4, -4, -4, 4}}, - /* 3.31: Albers equal area */ - {31, 22, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, 1, -4, -4, -4, 4}}, - /* 3.40: Guassian Lat/Lon */ - {40, 19, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1}}, - /* 3.41: Rotated Gaussian Lat/Lon */ - {41, 22, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, 4}}, - /* 3.42: Stretched Gaussian Lat/Lon */ - {42, 22, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, -4}}, - /* 3.43: Stretched and Rotated Gaussian Lat/Lon */ - {43, 25, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, 4, -4, 4, -4}}, - /* 3.50: Spherical Harmonic Coefficients */ - {50, 5, 0, {4, 4, 4, 1, 1}}, - /* 3.51: Rotated Spherical Harmonic Coefficients */ - {51, 8, 0, {4, 4, 4, 1, 1, -4, 4, 4}}, - /* 3.52: Stretched Spherical Harmonic Coefficients */ - {52, 8, 0, {4, 4, 4, 1, 1, -4, 4, -4}}, - /* 3.53: Stretched and Rotated Spherical Harmonic Coefficients */ - {53, 11, 0, {4, 4, 4, 1, 1, -4, 4, 4, -4, 4, -4}}, - /* 3.90: Space View Perspective or orthographic */ - {90, 21, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, 4, 4, 4, 4, 1, 4, 4, 4, 4}}, - /* 3.100: Triangular grid based on an icosahedron */ - {100, 11, 0, {1, 1, 2, 1, -4, 4, 4, 1, 1, 1, 4}}, - /* 3.110: Equatorial Azimuthal equidistant */ - {110, 16, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, 4, 4, 1, 1}}, - /* 3.120: Azimuth-range projection */ - {120, 7, 1, {4, 4, -4, 4, 4, 4, 1}}, - /* 3.204: Curvilinear Orthogonal Grid */ - {204, 19, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1}}, - /* 3.32768: Rot Lat/Lon E-grid (Arakawa) */ - {32768, 19, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1}}, - /* 3.32769: Rot Lat/Lon Non-E Staggered grid (Arakawa) */ - {32769, 21, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, 4, 4}}, - /* 3.1000: Cross Section Grid */ - {1000, 20, 1, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, -4, 4, 1, 4, 4, 1, 2, 1, 1, 2}}, - /* 3.1100: Hovmoller Diagram Grid */ - {1100, 28, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, -4, 4, 1, -4, 4, 1, 4, 1, -4, 1, 1, -4, 2, 1, 1, 1, 1, 1}}, - /* 3.1200: Time Section Grid */ - {1200, 16, 1, {4, 1, -4, 1, 1, -4, 2, 1, 1, 1, 1, 1, 2, 1, 1, 2}} -} ; + /* 3.10: Mercator */ + {10, 19, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, -4, -4, 4, 1, 4, 4, 4}}, + /* 3.20: Polar Stereographic Projection */ + {20, 18, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, 1}}, + /* 3.30: Lambert Conformal */ + {30, 22, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, 1, -4, -4, -4, 4}}, + /* 3.31: Albers equal area */ + {31, 22, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, 1, -4, -4, -4, 4}}, + /* 3.40: Guassian Lat/Lon */ + {40, 19, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1}}, + /* 3.41: Rotated Gaussian Lat/Lon */ + {41, 22, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, 4}}, + /* 3.42: Stretched Gaussian Lat/Lon */ + {42, 22, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, -4}}, + /* 3.43: Stretched and Rotated Gaussian Lat/Lon */ + {43, 25, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, 4, -4, 4, -4}}, + /* 3.50: Spherical Harmonic Coefficients */ + {50, 5, 0, {4, 4, 4, 1, 1}}, + /* 3.51: Rotated Spherical Harmonic Coefficients */ + {51, 8, 0, {4, 4, 4, 1, 1, -4, 4, 4}}, + /* 3.52: Stretched Spherical Harmonic Coefficients */ + {52, 8, 0, {4, 4, 4, 1, 1, -4, 4, -4}}, + /* 3.53: Stretched and Rotated Spherical Harmonic Coefficients */ + {53, 11, 0, {4, 4, 4, 1, 1, -4, 4, 4, -4, 4, -4}}, + /* 3.90: Space View Perspective or orthographic */ + {90, 21, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, 4, 4, 4, 4, 1, 4, 4, 4, 4}}, + /* 3.100: Triangular grid based on an icosahedron */ + {100, 11, 0, {1, 1, 2, 1, -4, 4, 4, 1, 1, 1, 4}}, + /* 3.110: Equatorial Azimuthal equidistant */ + {110, 16, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, 4, 4, 1, 1}}, + /* 3.120: Azimuth-range projection */ + {120, 7, 1, {4, 4, -4, 4, 4, 4, 1}}, + /* 3.204: Curvilinear Orthogonal Grid */ + {204, 19, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1}}, + /* 3.32768: Rot Lat/Lon E-grid (Arakawa) */ + {32768, 19, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1}}, + /* 3.32769: Rot Lat/Lon Non-E Staggered grid (Arakawa) */ + {32769, 21, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, 4, 4}}, + /* 3.1000: Cross Section Grid */ + {1000, 20, 1, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, -4, 4, 1, 4, 4, 1, 2, 1, 1, 2}}, + /* 3.1100: Hovmoller Diagram Grid */ + {1100, 28, 0, {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, -4, 4, 1, -4, 4, 1, 4, 1, -4, 1, 1, -4, 2, 1, 1, 1, 1, 1}}, + /* 3.1200: Time Section Grid */ + {1200, 16, 1, {4, 1, -4, 1, 1, -4, 2, 1, 1, 1, 1, 1, 2, 1, 1, 2}}}; /** * This function returns the index of specified Grid Definition @@ -146,11 +145,11 @@ getgridindex(g2int number) if (number == templatesgrid[j].template_num) { getgridindex = j; - return(getgridindex); + return (getgridindex); } } - return(getgridindex); + return (getgridindex); } /** @@ -192,15 +191,15 @@ getgridtemplate(g2int number) new->map = (g2int *)templatesgrid[index].mapgrid; new->extlen = 0; new->ext = NULL; - return(new); + return (new); } else { printf("getgridtemplate: GDT Template 3.%d not defined.\n", (int)number); - return(NULL); + return (NULL); } - return(NULL); + return (NULL); } /** @@ -235,7 +234,7 @@ extgridtemplate(g2int number, g2int *template) new = getgridtemplate(number); if (!new->needext) - return(new); + return (new); if (number == 120) { @@ -277,7 +276,7 @@ extgridtemplate(g2int number, g2int *template) } } - return(new); + return (new); } /** @@ -399,4 +398,3 @@ g2c_get_grid_template(int grid_template_num, int *maplen, int *map, int *needext /* If we didn't find a template, return an error. */ return G2C_ENOTEMPLATE; } - diff --git a/src/int_power.c b/src/int_power.c index 5fb15183..4c6f322c 100644 --- a/src/int_power.c +++ b/src/int_power.c @@ -29,7 +29,7 @@ int_power(double x, g2int y) while (y) { if (y & 1) - { + { value *= x; } x = x * x; diff --git a/src/jpcpack.c b/src/jpcpack.c index 1244f8ba..8ced0101 100644 --- a/src/jpcpack.c +++ b/src/jpcpack.c @@ -11,11 +11,11 @@ * 2005-05-10 | Gilbert | Imposed minimum size on cpack. * 2022-08-12 | Hartnett | Now handle doubles too. */ -#include -#include #include "grib2_int.h" +#include +#include -/** +/** * Packs a float or double array into a JPEG2000 code stream. * * This function is used by jpcpack(), g2c_jpcpackf(), and @@ -48,33 +48,33 @@ * - ::G2C_NOERROR No error. * - ::G2C_EJPEG Error encoding/decoding JPEG data. * - * @author Stephen Gilbert, Ed Hartnett + * @author Stephen Gilbert, Ed Hartnett */ static int jpcpack_int(void *fld, int fld_is_double, g2int width, g2int height, g2int *idrstmpl, - unsigned char *cpack, g2int *lcpack, int verbose) + unsigned char *cpack, g2int *lcpack, int verbose) { - g2int *ifld = NULL; - static float alog2 = ALOG2; /* ln(2.0) */ - g2int j, nbits, imin, imax, maxdif; - g2int ndpts, nbytes, nsize, retry; - float bscale, dscale, rmax, rmin, temp; - double rmaxd, rmind; + g2int *ifld = NULL; + static float alog2 = ALOG2; /* ln(2.0) */ + g2int j, nbits, imin, imax, maxdif; + g2int ndpts, nbytes, nsize, retry; + float bscale, dscale, rmax, rmin, temp; + double rmaxd, rmind; unsigned char *ctemp; float *ffld = fld; double *dfld = fld; int ret = G2C_NOERROR; LOG((2, "jpcpack_int() fld_is_double %d width %ld height %ld idrstmpl[1] %d *lcpack %ld", - fld_is_double, width, height, idrstmpl[1], *lcpack)); + fld_is_double, width, height, idrstmpl[1], *lcpack)); LOG((3, "idrstmpl: %ld %ld %ld %ld %ld %ld %ld", idrstmpl[0], idrstmpl[1], idrstmpl[2], - idrstmpl[3], idrstmpl[4], idrstmpl[5], idrstmpl[6])); - + idrstmpl[3], idrstmpl[4], idrstmpl[5], idrstmpl[6])); + ndpts = width * height; bscale = int_power(2.0, -idrstmpl[1]); dscale = int_power(10.0, idrstmpl[2]); LOG((3, "ndpts %ld bscale %g dscale %g", ndpts, bscale, dscale)); - + /* Find max and min values in the data. */ rmaxd = dfld[0]; rmind = dfld[0]; @@ -82,31 +82,31 @@ jpcpack_int(void *fld, int fld_is_double, g2int width, g2int height, g2int *idrs rmin = ffld[0]; if (fld_is_double) { - for (j = 1; j < ndpts; j++) - { - if (dfld[j] > rmaxd) - rmaxd = dfld[j]; - if (dfld[j] < rmind) - rmind = dfld[j]; - } - if (idrstmpl[1] == 0) - maxdif = (g2int)(rint(rmaxd * dscale) - rint(rmind * dscale)); - else - maxdif = (g2int)rint((rmaxd - rmind) * dscale * bscale); + for (j = 1; j < ndpts; j++) + { + if (dfld[j] > rmaxd) + rmaxd = dfld[j]; + if (dfld[j] < rmind) + rmind = dfld[j]; + } + if (idrstmpl[1] == 0) + maxdif = (g2int)(rint(rmaxd * dscale) - rint(rmind * dscale)); + else + maxdif = (g2int)rint((rmaxd - rmind) * dscale * bscale); } else { - for (j = 1; j < ndpts; j++) - { - if (ffld[j] > rmax) - rmax = ffld[j]; - if (ffld[j] < rmin) - rmin = ffld[j]; - } - if (idrstmpl[1] == 0) - maxdif = (g2int)(rint(rmax * dscale) - rint(rmin * dscale)); - else - maxdif = (g2int)rint((rmax - rmin) * dscale * bscale); + for (j = 1; j < ndpts; j++) + { + if (ffld[j] > rmax) + rmax = ffld[j]; + if (ffld[j] < rmin) + rmin = ffld[j]; + } + if (idrstmpl[1] == 0) + maxdif = (g2int)(rint(rmax * dscale) - rint(rmin * dscale)); + else + maxdif = (g2int)rint((rmax - rmin) * dscale * bscale); } LOG((3, "rmax %g rmaxd %g rmin %g rmind %g", rmax, rmaxd, rmin, rmind)); @@ -129,80 +129,80 @@ jpcpack_int(void *fld, int fld_is_double, g2int width, g2int height, g2int *idrs temp = log((double)(maxdif + 1)) / alog2; nbits = (g2int)ceil(temp); /* scale data */ - if (fld_is_double) - { - rmind = (float)imin; - for(j = 0; j < ndpts; j++) - ifld[j] = (g2int)rint(dfld[j] * dscale) - imin; - } - else - { - rmin = (float)imin; - for(j = 0; j < ndpts; j++) - ifld[j] = (g2int)rint(ffld[j] * dscale) - imin; - } + if (fld_is_double) + { + rmind = (float)imin; + for (j = 0; j < ndpts; j++) + ifld[j] = (g2int)rint(dfld[j] * dscale) - imin; + } + else + { + rmin = (float)imin; + for (j = 0; j < ndpts; j++) + ifld[j] = (g2int)rint(ffld[j] * dscale) - imin; + } } else { /* Use binary scaling factor and calculate minumum number * of bits in which the data will fit. */ - if (fld_is_double) - { - rmind = rmind * dscale; - rmaxd = rmaxd * dscale; - maxdif = (g2int)rint((rmaxd - rmind) * bscale); - } - else - { - rmin = rmin * dscale; - rmax = rmax * dscale; - maxdif = (g2int)rint((rmax - rmin) * bscale); - } - + if (fld_is_double) + { + rmind = rmind * dscale; + rmaxd = rmaxd * dscale; + maxdif = (g2int)rint((rmaxd - rmind) * bscale); + } + else + { + rmin = rmin * dscale; + rmax = rmax * dscale; + maxdif = (g2int)rint((rmax - rmin) * bscale); + } + temp = log((double)(maxdif + 1)) / alog2; nbits = (g2int)ceil(temp); /* scale data */ - if (fld_is_double) - { - for (j = 0; j < ndpts; j++) - ifld[j] = (g2int)rint(((dfld[j] * dscale) - rmind) * bscale); - } - else - { - for (j = 0; j < ndpts; j++) - ifld[j] = (g2int)rint(((ffld[j] * dscale) - rmin) * bscale); - } + if (fld_is_double) + { + for (j = 0; j < ndpts; j++) + ifld[j] = (g2int)rint(((dfld[j] * dscale) - rmind) * bscale); + } + else + { + for (j = 0; j < ndpts; j++) + ifld[j] = (g2int)rint(((ffld[j] * dscale) - rmin) * bscale); + } } /* Pack data into full octets, then do JPEG 2000 encode and * calculate the length of the packed data in bytes. */ retry = 0; nbytes = (nbits + 7) / 8; - nsize = *lcpack; /* needed for input to enc_jpeg2000 */ + nsize = *lcpack; /* needed for input to enc_jpeg2000 */ ctemp = calloc(ndpts, nbytes); sbits(ctemp, ifld, 0, nbytes * 8, 0, ndpts); if ((*lcpack = (g2int)enc_jpeg2000(ctemp, width, height, nbits, idrstmpl[5], idrstmpl[6], retry, (char *)cpack, nsize)) <= 0) { - if (verbose) - printf("jpcpack: ERROR Packing JPC = %d\n", (int)*lcpack); - ret = G2C_EJPEG; + if (verbose) + printf("jpcpack: ERROR Packing JPC = %d\n", (int)*lcpack); + ret = G2C_EJPEG; if (*lcpack == -3) { retry = 1; if ((*lcpack = (g2int)enc_jpeg2000(ctemp, width, height, nbits, idrstmpl[5], idrstmpl[6], retry, (char *)cpack, nsize)) <= 0) - { - if (verbose) - printf("jpcpack: Retry Failed.\n"); - ret = G2C_EJPEG; - } + { + if (verbose) + printf("jpcpack: Retry Failed.\n"); + ret = G2C_EJPEG; + } else - { - if (verbose) - printf("jpcpack: Retry Successful.\n"); - ret = G2C_NOERROR; - } + { + if (verbose) + printf("jpcpack: Retry Successful.\n"); + ret = G2C_NOERROR; + } } } free(ctemp); @@ -215,12 +215,12 @@ jpcpack_int(void *fld, int fld_is_double, g2int width, g2int height, g2int *idrs /* Fill in ref value and number of bits in Template 5.0. */ if (fld_is_double) - rmin = (float)rmind; - mkieee(&rmin, idrstmpl, 1); /* ensure reference value is IEEE format. */ + rmin = (float)rmind; + mkieee(&rmin, idrstmpl, 1); /* ensure reference value is IEEE format. */ idrstmpl[3] = nbits; - idrstmpl[4] = 0; /* original data were reals */ + idrstmpl[4] = 0; /* original data were reals */ if (idrstmpl[5] == 0) - idrstmpl[6] = 255; /* lossy not used */ + idrstmpl[6] = 255; /* lossy not used */ if (ifld) free(ifld); @@ -323,7 +323,7 @@ g2c_jpcpackf(float *fld, size_t width, size_t height, int *idrstmpl, g2int width8 = width, height8 = height, lcpack8 = *lcpack; g2int idrstmpl8[G2C_JPEG_DRS_TEMPLATE_LEN]; int i, ret; - + for (i = 0; i < G2C_JPEG_DRS_TEMPLATE_LEN; i++) idrstmpl8[i] = idrstmpl[i]; @@ -389,11 +389,11 @@ g2c_jpcpackd(double *fld, size_t width, size_t height, int *idrstmpl, g2int width8 = width, height8 = height, lcpack8 = *lcpack; g2int idrstmpl8[G2C_JPEG_DRS_TEMPLATE_LEN]; int i, ret; - + for (i = 0; i < G2C_JPEG_DRS_TEMPLATE_LEN; i++) idrstmpl8[i] = idrstmpl[i]; - ret = jpcpack_int(fld, 1, width8, height8, idrstmpl8, cpack, &lcpack8, 0); + ret = jpcpack_int(fld, 1, width8, height8, idrstmpl8, cpack, &lcpack8, 0); if (!ret) { diff --git a/src/jpcunpack.c b/src/jpcunpack.c index c10ecb3f..f62083c0 100644 --- a/src/jpcunpack.c +++ b/src/jpcunpack.c @@ -3,9 +3,9 @@ * stream * @author Stephem Gilbert @date 2003-08-27 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /** * Unpack JPEG2000 compressed data into an array of floats or doubles, @@ -42,7 +42,7 @@ */ static int jpcunpack_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, nbits; @@ -63,35 +63,35 @@ jpcunpack_int(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, { if (!(ifld = calloc(ndpts, sizeof(g2int)))) { - if (verbose) - fprintf(stderr, "Could not allocate space in jpcunpack.\n Data field NOT upacked.\n"); + if (verbose) + fprintf(stderr, "Could not allocate space in jpcunpack.\n Data field NOT upacked.\n"); return G2C_ENOMEM; } dec_jpeg2000((char *)cpack, len, ifld); - if (fld_is_double) - { - for (j = 0; j < ndpts; j++) - dfld[j] = (((float)ifld[j] * bscale) + ref) * dscale; - } - else - { - for (j = 0; j < ndpts; j++) - ffld[j] = (((float)ifld[j] * bscale) + ref) * dscale; - } + if (fld_is_double) + { + for (j = 0; j < ndpts; j++) + dfld[j] = (((float)ifld[j] * bscale) + ref) * dscale; + } + else + { + for (j = 0; j < ndpts; j++) + ffld[j] = (((float)ifld[j] * bscale) + ref) * dscale; + } free(ifld); } else { - if (fld_is_double) - { - for (j = 0; j < ndpts; j++) - dfld[j] = ref; - } - else - { - for (j = 0; j < ndpts; j++) - ffld[j] = ref; - } + if (fld_is_double) + { + for (j = 0; j < ndpts; j++) + dfld[j] = ref; + } + else + { + for (j = 0; j < ndpts; j++) + ffld[j] = ref; + } } return G2C_NOERROR; @@ -124,11 +124,11 @@ jpcunpack(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, float *fld) { int ret; - + LOG((2, "g2c_jpcunpack len %lld ndpts %lld", len, ndpts)); if ((ret = jpcunpack_int(cpack, len, idrstmpl, ndpts, fld, 0, 1)) == G2_JPCUNPACK_MEM) - return G2_JPCUNPACK_MEM; + return G2_JPCUNPACK_MEM; return ret; } @@ -164,10 +164,10 @@ g2c_jpcunpackf(unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts, int i; LOG((2, "g2c_jpcunpackf len %d ndpts %lld", len, ndpts)); - + for (i = 0; i < G2C_JPEG_DRS_TEMPLATE_LEN; i++) idrstmpl8[i] = idrstmpl[i]; - + return jpcunpack_int(cpack, len8, idrstmpl8, ndpts8, fld, 0, 0); } @@ -202,11 +202,11 @@ g2c_jpcunpackd(unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts, g2int idrstmpl8[G2C_JPEG_DRS_TEMPLATE_LEN]; g2int len8 = len, ndpts8 = ndpts; int i; - + LOG((2, "g2c_jpcunpackd len %lld ndpts %lld", len, ndpts)); - + for (i = 0; i < G2C_JPEG_DRS_TEMPLATE_LEN; i++) idrstmpl8[i] = idrstmpl[i]; - + return jpcunpack_int(cpack, len8, idrstmpl8, ndpts8, fld, 1, 0); } diff --git a/src/misspack.c b/src/misspack.c index efb0c922..8a3cf9bb 100644 --- a/src/misspack.c +++ b/src/misspack.c @@ -4,9 +4,9 @@ * @author Stephen Gilbert @date 2000-06-21 */ -#include -#include #include "grib2_int.h" +#include +#include /** * Pack a data field using a complex packing algorithm. @@ -16,7 +16,7 @@ * (See [Template * 5.2](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-2.shtml) * and [Template - * 5.3](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-3.shtml)). + * 5.3](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-3.shtml)). * * This function fills in GRIB2 Data Representation template arrays * with the appropriate values. @@ -56,7 +56,7 @@ misspack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, g2int imax, lg, mtemp, ier, igmax; g2int kfildo, minpk, inc, maxgrps, ibit, jbit, kbit, novref, lbitref; float rmissp, rmisss, bscale, dscale, rmin, temp; - static float alog2 = ALOG2; /* ln(2.0) */ + static float alog2 = ALOG2; /* ln(2.0) */ static g2int one = 1; bscale = int_power(2.0, -idrstmpl[1]); @@ -69,7 +69,7 @@ misspack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, return; } else - { /* Get missing values */ + { /* Get missing values */ rdieee(idrstmpl + 7, &rmissp, 1); if (missopt == 2) rdieee(idrstmpl + 8, &rmisss, 1); @@ -79,8 +79,8 @@ misspack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, * missing value mapping of the field. */ ifldmiss = calloc(ndpts, sizeof(g2int)); rmin = 1E+37; - if (missopt == 1) - { /* Primary missing value only */ + if (missopt == 1) + { /* Primary missing value only */ for (j = 0; j < ndpts; j++) { if (fld[j] == rmissp) @@ -95,8 +95,8 @@ misspack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, } } } - if (missopt == 2) - { /* Primary and secondary missing values */ + if (missopt == 2) + { /* Primary and secondary missing values */ for (j = 0; j < ndpts; j++) { if (fld[j] == rmissp) @@ -131,7 +131,7 @@ misspack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, /* Scale original data. */ nonmiss = 0; if (idrstmpl[1] == 0) - { /* No binary scaling */ + { /* No binary scaling */ imin = (g2int)rint(rmin * dscale); rmin = (float)imin; for (j = 0; j < ndpts; j++) @@ -158,18 +158,18 @@ misspack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, /* Calculate Spatial differences, if using DRS Template 5.3. */ if (idrsnum == 3) - { /* spatial differences */ + { /* spatial differences */ if (idrstmpl[16] != 1 && idrstmpl[16] != 2) idrstmpl[16] = 2; if (idrstmpl[16] == 1) - { /* first order */ + { /* first order */ ival1 = jfld[0]; for (j = nonmiss - 1; j > 0; j--) jfld[j] = jfld[j] - jfld[j - 1]; jfld[0] = 0; } else if (idrstmpl[16] == 2) - { /* second order */ + { /* second order */ ival1 = jfld[0]; ival2 = jfld[1]; for (j = nonmiss - 1; j > 1; j--) @@ -211,7 +211,8 @@ misspack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, if (nbitsd != 0) { /* pack first original value */ - if (ival1 >= 0) { + if (ival1 >= 0) + { sbit(cpack, &ival1, iofst, nbitsd); iofst = iofst + nbitsd; } @@ -220,7 +221,7 @@ misspack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, sbit(cpack, &one, iofst, 1); iofst = iofst + 1; itemp = abs(ival1); - sbit(cpack, &itemp, iofst, nbitsd-1); + sbit(cpack, &itemp, iofst, nbitsd - 1); iofst = iofst + nbitsd - 1; } if (idrstmpl[16] == 2) @@ -236,7 +237,7 @@ misspack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, sbit(cpack, &one, iofst, 1); iofst = iofst + 1; itemp = abs(ival2); - sbit(cpack, &itemp, iofst, nbitsd-1); + sbit(cpack, &itemp, iofst, nbitsd - 1); iofst = iofst + nbitsd - 1; } } @@ -251,11 +252,11 @@ misspack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, sbit(cpack, &one, iofst, 1); iofst = iofst + 1; itemp = abs(minsd); - sbit(cpack, &itemp, iofst, nbitsd-1); + sbit(cpack, &itemp, iofst, nbitsd - 1); iofst = iofst + nbitsd - 1; } } - } /* end of spatial diff section */ + } /* end of spatial diff section */ /* Expand non-missing data values to original grid. */ miss1 = jfld[0]; @@ -263,7 +264,7 @@ misspack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, if (jfld[j] < miss1) miss1 = jfld[j]; miss1--; - miss2 = miss1-1; + miss2 = miss1 - 1; n = 0; for (j = 0; j < ndpts; j++) { @@ -291,8 +292,8 @@ misspack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, jmin = calloc(maxgrps, sizeof(g2int)); jmax = calloc(maxgrps, sizeof(g2int)); lbit = calloc(maxgrps, sizeof(g2int)); - pack_gp(&kfildo, ifld, &ndpts, &missopt, &minpk, &inc, &miss1, &miss2, - jmin, jmax, lbit, glen, &maxgrps, &ngroups, &ibit, &jbit, + pack_gp(&kfildo, ifld, &ndpts, &missopt, &minpk, &inc, &miss1, &miss2, + jmin, jmax, lbit, glen, &maxgrps, &ngroups, &ibit, &jbit, &kbit, &novref, &lbitref, &ier); for (ng = 0; ng < ngroups; ng++) glen[ng] = glen[ng] + novref; @@ -317,19 +318,19 @@ misspack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, num2++; } if (num0 == 0) - { /* all missing values */ + { /* all missing values */ if (num1 == 0) - { /* all secondary missing */ + { /* all secondary missing */ gref[ng] = -2; gwidth[ng] = 0; } else if (num2 == 0) - { /* all primary missing */ + { /* all primary missing */ gref[ng] = -1; gwidth[ng] = 0; } else - { /* both primary and secondary */ + { /* both primary and secondary */ gref[ng] = 0; gwidth[ng] = 1; } @@ -352,9 +353,9 @@ misspack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, j++; } if (missopt == 1) - imax = imax+1; + imax = imax + 1; if (missopt == 2) - imax = imax+2; + imax = imax + 2; /* calc num of bits needed to hold data */ if (gref[ng] != imax) { @@ -371,11 +372,11 @@ misspack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, mtemp = (g2int)int_power(2., gwidth[ng]); for (lg = 0; lg < glen[ng]; lg++) { - if (ifldmiss[j] == 0) /* non-missing */ + if (ifldmiss[j] == 0) /* non-missing */ ifld[j] = ifld[j] - gref[ng]; - else if (ifldmiss[j] == 1) /* primary missing */ + else if (ifldmiss[j] == 1) /* primary missing */ ifld[j] = mtemp - 1; - else if (ifldmiss[j] == 2) /* secondary missing */ + else if (ifldmiss[j] == 2) /* secondary missing */ ifld[j] = mtemp - 2; j++; } @@ -403,9 +404,9 @@ misspack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, for (j = 0; j < ngroups; j++) { if (gref[j] == -1) - gref[j] = mtemp-1; + gref[j] = mtemp - 1; if (gref[j] == -2) - gref[j] = mtemp-2; + gref[j] = mtemp - 2; } sbits(cpack, gref, iofst, nbitsgref, 0, ngroups); itemp = nbitsgref * ngroups; @@ -439,13 +440,13 @@ misspack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, { temp = log((double)(iwmax - ngwidthref + 1)) / alog2; nbitsgwidth = (g2int)ceil(temp); - for (i = 0; i -#include #include "grib2_int.h" +#include +#include /** * Store a list of real values in 32-bit IEEE floating point format. @@ -21,7 +21,7 @@ void mkieee(float *a, g2int *rieee, g2int num) { - g2int j,n,ieee,iexp,imant; + g2int j, n, ieee, iexp, imant; double atemp; static double two23, two126; static g2int test = 0; @@ -36,7 +36,7 @@ mkieee(float *a, g2int *rieee, g2int num) for (j = 0; j < num; j++) { - ieee=0; + ieee = 0; if (a[j] == 0.0) { @@ -47,20 +47,20 @@ mkieee(float *a, g2int *rieee, g2int num) // Set Sign bit (bit 31 - leftmost bit). if (a[j] < 0.0) { - ieee= 1 << 31; - atemp=-1.0*a[j]; + ieee = 1 << 31; + atemp = -1.0 * a[j]; } else { - ieee= 0 << 31; - atemp=a[j]; + ieee = 0 << 31; + atemp = a[j]; } // Determine exponent n with base 2. if (atemp >= 1.0) { n = 0; - while (int_power(2.0,n+1) <= atemp) + while (int_power(2.0, n + 1) <= atemp) { n++; } @@ -68,17 +68,17 @@ mkieee(float *a, g2int *rieee, g2int num) else { n = -1; - while (int_power(2.0,n) > atemp) + while (int_power(2.0, n) > atemp) n--; } iexp = n + 127; - if (n > 127) - iexp = 255; // overflow + if (n > 127) + iexp = 255; // overflow if (n < -127) iexp = 0; // set exponent bits ( bits 30-23 ) - ieee = ieee | ( iexp << 23 ); + ieee = ieee | (iexp << 23); // Determine Mantissa if (iexp != 255) diff --git a/src/pack_gp.c b/src/pack_gp.c index 270f0206..27c72d6d 100644 --- a/src/pack_gp.c +++ b/src/pack_gp.c @@ -3,10 +3,10 @@ */ /*#include "f2c.h"*/ -#include #include "grib2_int.h" +#include -#define TRUE_ (1) /**< True. */ +#define TRUE_ (1) /**< True. */ #define FALSE_ (0) /**< False. */ /** @@ -260,7 +260,7 @@ pack_gp(g2int *kfildo, g2int *ic, g2int *nxy, { /* Initialized data */ - const g2int mallow = 1073741825; /* MALLOW=2**30+1 */ + const g2int mallow = 1073741825; /* MALLOW=2**30+1 */ static g2int ifeed = 12; static g2int ifirst = 0; @@ -282,16 +282,11 @@ pack_gp(g2int *kfildo, g2int *ic, g2int *nxy, kounts, mintstk, maxtstk; g2int *misslx; + /* NON SYSTEM SUBROUTINES CALLED */ + /* NONE */ - -/* NON SYSTEM SUBROUTINES CALLED */ -/* NONE */ - - - -/* MISSLX( ) was AN AUTOMATIC ARRAY. */ - misslx = (g2int *)calloc(*ndg,sizeof(g2int)); - + /* MISSLX( ) was AN AUTOMATIC ARRAY. */ + misslx = (g2int *)calloc(*ndg, sizeof(g2int)); /* Parameter adjustments */ --ic; @@ -304,45 +299,47 @@ pack_gp(g2int *kfildo, g2int *ic, g2int *nxy, *ier = 0; iersav = 0; -/* CALL TIMPR(KFILDO,KFILDO,'START PACK_GP ') */ - *(unsigned char *)cfeed = (char) ifeed; + /* CALL TIMPR(KFILDO,KFILDO,'START PACK_GP ') */ + *(unsigned char *)cfeed = (char)ifeed; ired = 0; -/* IRED IS A FLAG. WHEN ZERO, REDUCE WILL BE CALLED. */ -/* IF REDUCE ABORTS, IRED = 1 AND IS NOT CALLED. IN */ -/* THIS CASE PACK_GP EXECUTES AGAIN EXCEPT FOR REDUCE. */ + /* IRED IS A FLAG. WHEN ZERO, REDUCE WILL BE CALLED. */ + /* IF REDUCE ABORTS, IRED = 1 AND IS NOT CALLED. IN */ + /* THIS CASE PACK_GP EXECUTES AGAIN EXCEPT FOR REDUCE. */ - if (*inc <= 0) { + if (*inc <= 0) + { iersav = 717; -/* WRITE(KFILDO,101)INC */ -/* 101 FORMAT(/' ****INC ='I8,' NOT CORRECT IN PACK_GP. 1 IS USED.') */ + /* WRITE(KFILDO,101)INC */ + /* 101 FORMAT(/' ****INC ='I8,' NOT CORRECT IN PACK_GP. 1 IS USED.') */ } -/* THERE WILL BE A RESTART OF PACK_GP IF SUBROUTINE REDUCE */ -/* ABORTS. THIS SHOULD NOT HAPPEN, BUT IF IT DOES, PACK_GP */ -/* WILL COMPLETE WITHOUT SUBROUTINE REDUCE. A NON FATAL */ -/* DIAGNOSTIC RETURN IS PROVIDED. */ + /* THERE WILL BE A RESTART OF PACK_GP IF SUBROUTINE REDUCE */ + /* ABORTS. THIS SHOULD NOT HAPPEN, BUT IF IT DOES, PACK_GP */ + /* WILL COMPLETE WITHOUT SUBROUTINE REDUCE. A NON FATAL */ + /* DIAGNOSTIC RETURN IS PROVIDED. */ L102: /*kinc = max(*inc,1);*/ kinc = (*inc > 1) ? *inc : 1; lminpk = *minpk; -/* CALCULATE THE POWERS OF 2 THE FIRST TIME ENTERED. */ + /* CALCULATE THE POWERS OF 2 THE FIRST TIME ENTERED. */ - if (ifirst == 0) { + if (ifirst == 0) + { ifirst = 1; ibxx2[0] = 1; - for (j = 1; j <= 30; ++j) { + for (j = 1; j <= 30; ++j) + { ibxx2[j] = ibxx2[j - 1] << 1; -/* L104: */ + /* L104: */ } - } -/* THERE WILL BE A RESTART AT 105 IS NDG IS NOT LARGE ENOUGH. */ -/* A NON FATAL DIAGNOSTIC RETURN IS PROVIDED. */ + /* THERE WILL BE A RESTART AT 105 IS NDG IS NOT LARGE ENOUGH. */ + /* A NON FATAL DIAGNOSTIC RETURN IS PROVIDED. */ L105: kstart = 1; @@ -350,19 +347,21 @@ pack_gp(g2int *kfildo, g2int *ic, g2int *nxy, *lx = 0; adda = FALSE_; lmiss = 0; - if (*is523 == 1) { + if (*is523 == 1) + { lmiss = 1; } - if (*is523 == 2) { + if (*is523 == 2) + { lmiss = 2; } -/* ************************************* */ + /* ************************************* */ -/* THIS SECTION COMPUTES STATISTICS FOR GROUP A. GROUP A IS */ -/* A GROUP OF SIZE LMINPK. */ + /* THIS SECTION COMPUTES STATISTICS FOR GROUP A. GROUP A IS */ + /* A GROUP OF SIZE LMINPK. */ -/* ************************************* */ + /* ************************************* */ ibita = 0; mina = mallow; @@ -370,223 +369,249 @@ pack_gp(g2int *kfildo, g2int *ic, g2int *nxy, minak = mallow; maxak = -mallow; -/* FIND THE MIN AND MAX OF GROUP A. THIS WILL INITIALLY BE OF */ -/* SIZE LMINPK (IF THERE ARE STILL LMINPK VALUES IN IC( )), BUT */ -/* WILL INCREASE IN SIZE IN INCREMENTS OF INC UNTIL A NEW */ -/* GROUP IS STARTED. THE DEFINITION OF GROUP A IS DONE HERE */ -/* ONLY ONCE (UPON INITIAL ENTRY), BECAUSE A GROUP B CAN ALWAYS */ -/* BECOME A NEW GROUP A AFTER A IS PACKED, EXCEPT IF LMINPK */ -/* HAS TO BE INCREASED BECAUSE NDG IS TOO SMALL. THEREFORE, */ -/* THE SEPARATE LOOPS FOR MISSING AND NON-MISSING HERE BUYS */ -/* ALMOST NOTHING. */ - -/* Computing MIN */ + /* FIND THE MIN AND MAX OF GROUP A. THIS WILL INITIALLY BE OF */ + /* SIZE LMINPK (IF THERE ARE STILL LMINPK VALUES IN IC( )), BUT */ + /* WILL INCREASE IN SIZE IN INCREMENTS OF INC UNTIL A NEW */ + /* GROUP IS STARTED. THE DEFINITION OF GROUP A IS DONE HERE */ + /* ONLY ONCE (UPON INITIAL ENTRY), BECAUSE A GROUP B CAN ALWAYS */ + /* BECOME A NEW GROUP A AFTER A IS PACKED, EXCEPT IF LMINPK */ + /* HAS TO BE INCREASED BECAUSE NDG IS TOO SMALL. THEREFORE, */ + /* THE SEPARATE LOOPS FOR MISSING AND NON-MISSING HERE BUYS */ + /* ALMOST NOTHING. */ + + /* Computing MIN */ i__1 = kstart + lminpk - 1; /*nenda = min(i__1,*nxy);*/ nenda = (i__1 < *nxy) ? i__1 : *nxy; - if (*nxy - nenda <= lminpk / 2) { + if (*nxy - nenda <= lminpk / 2) + { nenda = *nxy; } -/* ABOVE STATEMENT GUARANTEES THE LAST GROUP IS GT LMINPK/2 BY */ -/* MAKING THE ACTUAL GROUP LARGER. IF A PROVISION LIKE THIS IS */ -/* NOT INCLUDED, THERE WILL MANY TIMES BE A VERY SMALL GROUP */ -/* AT THE END. USE SEPARATE LOOPS FOR MISSING AND NO MISSING */ -/* VALUES FOR EFFICIENCY. */ - -/* DETERMINE WHETHER THERE IS A LONG STRING OF THE SAME VALUE */ -/* UNLESS NENDA = NXY. THIS MAY ALLOW A LARGE GROUP A TO */ -/* START WITH, AS WITH MISSING VALUES. SEPARATE LOOPS FOR */ -/* MISSING OPTIONS. THIS SECTION IS ONLY EXECUTED ONCE, */ -/* IN DETERMINING THE FIRST GROUP. IT HELPS FOR AN ARRAY */ -/* OF MOSTLY MISSING VALUES OR OF ONE VALUE, SUCH AS */ -/* RADAR OR PRECIP DATA. */ - - if (nenda != *nxy && ic[kstart] == ic[kstart + 1]) { -/* NO NEED TO EXECUTE IF FIRST TWO VALUES ARE NOT EQUAL. */ - - if (*is523 == 0) { -/* THIS LOOP IS FOR NO MISSING VALUES. */ + /* ABOVE STATEMENT GUARANTEES THE LAST GROUP IS GT LMINPK/2 BY */ + /* MAKING THE ACTUAL GROUP LARGER. IF A PROVISION LIKE THIS IS */ + /* NOT INCLUDED, THERE WILL MANY TIMES BE A VERY SMALL GROUP */ + /* AT THE END. USE SEPARATE LOOPS FOR MISSING AND NO MISSING */ + /* VALUES FOR EFFICIENCY. */ + + /* DETERMINE WHETHER THERE IS A LONG STRING OF THE SAME VALUE */ + /* UNLESS NENDA = NXY. THIS MAY ALLOW A LARGE GROUP A TO */ + /* START WITH, AS WITH MISSING VALUES. SEPARATE LOOPS FOR */ + /* MISSING OPTIONS. THIS SECTION IS ONLY EXECUTED ONCE, */ + /* IN DETERMINING THE FIRST GROUP. IT HELPS FOR AN ARRAY */ + /* OF MOSTLY MISSING VALUES OR OF ONE VALUE, SUCH AS */ + /* RADAR OR PRECIP DATA. */ + + if (nenda != *nxy && ic[kstart] == ic[kstart + 1]) + { + /* NO NEED TO EXECUTE IF FIRST TWO VALUES ARE NOT EQUAL. */ + + if (*is523 == 0) + { + /* THIS LOOP IS FOR NO MISSING VALUES. */ i__1 = *nxy; - for (k = kstart + 1; k <= i__1; ++k) { + for (k = kstart + 1; k <= i__1; ++k) + { - if (ic[k] != ic[kstart]) { -/* Computing MAX */ + if (ic[k] != ic[kstart]) + { + /* Computing MAX */ i__2 = nenda, i__3 = k - 1; /*nenda = max(i__2,i__3);*/ nenda = (i__2 > i__3) ? i__2 : i__3; goto L114; } -/* L111: */ + /* L111: */ } nenda = *nxy; -/* FALL THROUGH THE LOOP MEANS ALL VALUES ARE THE SAME. */ - - } else if (*is523 == 1) { -/* THIS LOOP IS FOR PRIMARY MISSING VALUES ONLY. */ + /* FALL THROUGH THE LOOP MEANS ALL VALUES ARE THE SAME. */ + } + else if (*is523 == 1) + { + /* THIS LOOP IS FOR PRIMARY MISSING VALUES ONLY. */ i__1 = *nxy; - for (k = kstart + 1; k <= i__1; ++k) { + for (k = kstart + 1; k <= i__1; ++k) + { - if (ic[k] != *missp) { + if (ic[k] != *missp) + { - if (ic[k] != ic[kstart]) { -/* Computing MAX */ + if (ic[k] != ic[kstart]) + { + /* Computing MAX */ i__2 = nenda, i__3 = k - 1; /*nenda = max(i__2,i__3);*/ nenda = (i__2 > i__3) ? i__2 : i__3; goto L114; } - } -/* L112: */ + /* L112: */ } nenda = *nxy; -/* FALL THROUGH THE LOOP MEANS ALL VALUES ARE THE SAME. */ - - } else { -/* THIS LOOP IS FOR PRIMARY AND SECONDARY MISSING VALUES. */ + /* FALL THROUGH THE LOOP MEANS ALL VALUES ARE THE SAME. */ + } + else + { + /* THIS LOOP IS FOR PRIMARY AND SECONDARY MISSING VALUES. */ i__1 = *nxy; - for (k = kstart + 1; k <= i__1; ++k) { + for (k = kstart + 1; k <= i__1; ++k) + { - if (ic[k] != *missp && ic[k] != *misss) { + if (ic[k] != *missp && ic[k] != *misss) + { - if (ic[k] != ic[kstart]) { -/* Computing MAX */ + if (ic[k] != ic[kstart]) + { + /* Computing MAX */ i__2 = nenda, i__3 = k - 1; /*nenda = max(i__2,i__3);*/ nenda = (i__2 > i__3) ? i__2 : i__3; goto L114; } - } -/* L113: */ + /* L113: */ } nenda = *nxy; -/* FALL THROUGH THE LOOP MEANS ALL VALUES ARE THE SAME. */ + /* FALL THROUGH THE LOOP MEANS ALL VALUES ARE THE SAME. */ } - } L114: - if (*is523 == 0) { + if (*is523 == 0) + { i__1 = nenda; - for (k = kstart; k <= i__1; ++k) { - if (ic[k] < mina) { + for (k = kstart; k <= i__1; ++k) + { + if (ic[k] < mina) + { mina = ic[k]; minak = k; } - if (ic[k] > maxa) { + if (ic[k] > maxa) + { maxa = ic[k]; maxak = k; } -/* L115: */ + /* L115: */ } - - } else if (*is523 == 1) { + } + else if (*is523 == 1) + { i__1 = nenda; - for (k = kstart; k <= i__1; ++k) { - if (ic[k] == *missp) { + for (k = kstart; k <= i__1; ++k) + { + if (ic[k] == *missp) + { goto L117; } - if (ic[k] < mina) { + if (ic[k] < mina) + { mina = ic[k]; minak = k; } - if (ic[k] > maxa) { + if (ic[k] > maxa) + { maxa = ic[k]; maxak = k; } - L117: - ; + L117:; } - - } else { + } + else + { i__1 = nenda; - for (k = kstart; k <= i__1; ++k) { - if (ic[k] == *missp || ic[k] == *misss) { + for (k = kstart; k <= i__1; ++k) + { + if (ic[k] == *missp || ic[k] == *misss) + { goto L120; } - if (ic[k] < mina) { + if (ic[k] < mina) + { mina = ic[k]; minak = k; } - if (ic[k] > maxa) { + if (ic[k] > maxa) + { maxa = ic[k]; maxak = k; } - L120: - ; + L120:; } - } kounta = nenda - kstart + 1; -/* INCREMENT KTOTAL AND FIND THE BITS NEEDED TO PACK THE A GROUP. */ + /* INCREMENT KTOTAL AND FIND THE BITS NEEDED TO PACK THE A GROUP. */ ktotal += kounta; mislla = 0; - if (mina != mallow) { + if (mina != mallow) + { goto L125; } -/* ALL MISSING VALUES MUST BE ACCOMMODATED. */ + /* ALL MISSING VALUES MUST BE ACCOMMODATED. */ mina = 0; maxa = 0; mislla = 1; ibitb = 0; - if (*is523 != 2) { + if (*is523 != 2) + { goto L130; } -/* WHEN ALL VALUES ARE MISSING AND THERE ARE NO */ -/* SECONDARY MISSING VALUES, IBITA = 0. */ -/* OTHERWISE, IBITA MUST BE CALCULATED. */ + /* WHEN ALL VALUES ARE MISSING AND THERE ARE NO */ + /* SECONDARY MISSING VALUES, IBITA = 0. */ + /* OTHERWISE, IBITA MUST BE CALCULATED. */ L125: itest = maxa - mina + lmiss; - for (ibita = 0; ibita <= 30; ++ibita) { - if (itest < ibxx2[ibita]) { + for (ibita = 0; ibita <= 30; ++ibita) + { + if (itest < ibxx2[ibita]) + { goto L130; } -/* *** THIS TEST IS THE SAME AS: */ -/* *** IF(MAXA-MINA.LT.IBXX2(IBITA)-LMISS)GO TO 130 */ -/* L126: */ + /* *** THIS TEST IS THE SAME AS: */ + /* *** IF(MAXA-MINA.LT.IBXX2(IBITA)-LMISS)GO TO 130 */ + /* L126: */ } -/* WRITE(KFILDO,127)MAXA,MINA */ -/* 127 FORMAT(' ****ERROR IN PACK_GP. VALUE WILL NOT PACK IN 30 BITS.', */ -/* 1 ' MAXA ='I13,' MINA ='I13,'. ERROR AT 127.') */ + /* WRITE(KFILDO,127)MAXA,MINA */ + /* 127 FORMAT(' ****ERROR IN PACK_GP. VALUE WILL NOT PACK IN 30 BITS.', */ + /* 1 ' MAXA ='I13,' MINA ='I13,'. ERROR AT 127.') */ *ier = 706; goto L900; L130: -/* ***D WRITE(KFILDO,131)KOUNTA,KTOTAL,MINA,MAXA,IBITA,MISLLA */ -/* ***D131 FORMAT(' AT 130, KOUNTA ='I8,' KTOTAL ='I8,' MINA ='I8, */ -/* ***D 1 ' MAXA ='I8,' IBITA ='I3,' MISLLA ='I3) */ + /* ***D WRITE(KFILDO,131)KOUNTA,KTOTAL,MINA,MAXA,IBITA,MISLLA */ + /* ***D131 FORMAT(' AT 130, KOUNTA ='I8,' KTOTAL ='I8,' MINA ='I8, */ + /* ***D 1 ' MAXA ='I8,' IBITA ='I3,' MISLLA ='I3) */ L133: - if (ktotal >= *nxy) { + if (ktotal >= *nxy) + { goto L200; } -/* ************************************* */ + /* ************************************* */ -/* THIS SECTION COMPUTES STATISTICS FOR GROUP B. GROUP B IS A */ -/* GROUP OF SIZE LMINPK IMMEDIATELY FOLLOWING GROUP A. */ + /* THIS SECTION COMPUTES STATISTICS FOR GROUP B. GROUP B IS A */ + /* GROUP OF SIZE LMINPK IMMEDIATELY FOLLOWING GROUP A. */ -/* ************************************* */ + /* ************************************* */ L140: minb = mallow; @@ -596,409 +621,469 @@ pack_gp(g2int *kfildo, g2int *ic, g2int *nxy, ibitbs = 0; mstart = ktotal + 1; -/* DETERMINE WHETHER THERE IS A LONG STRING OF THE SAME VALUE. */ -/* THIS WORKS WHEN THERE ARE NO MISSING VALUES. */ + /* DETERMINE WHETHER THERE IS A LONG STRING OF THE SAME VALUE. */ + /* THIS WORKS WHEN THERE ARE NO MISSING VALUES. */ nendb = 1; - if (mstart < *nxy) { + if (mstart < *nxy) + { - if (*is523 == 0) { -/* THIS LOOP IS FOR NO MISSING VALUES. */ + if (*is523 == 0) + { + /* THIS LOOP IS FOR NO MISSING VALUES. */ i__1 = *nxy; - for (k = mstart + 1; k <= i__1; ++k) { + for (k = mstart + 1; k <= i__1; ++k) + { - if (ic[k] != ic[mstart]) { + if (ic[k] != ic[mstart]) + { nendb = k - 1; goto L150; } -/* L145: */ + /* L145: */ } nendb = *nxy; -/* FALL THROUGH THE LOOP MEANS ALL REMAINING VALUES */ -/* ARE THE SAME. */ + /* FALL THROUGH THE LOOP MEANS ALL REMAINING VALUES */ + /* ARE THE SAME. */ } - } L150: -/* Computing MAX */ -/* Computing MIN */ + /* Computing MAX */ + /* Computing MIN */ i__3 = ktotal + lminpk; /*i__1 = nendb, i__2 = min(i__3,*nxy);*/ i__1 = nendb, i__2 = (i__3 < *nxy) ? i__3 : *nxy; /*nendb = max(i__1,i__2);*/ nendb = (i__1 > i__2) ? i__1 : i__2; -/* **** 150 NENDB=MIN(KTOTAL+LMINPK,NXY) */ + /* **** 150 NENDB=MIN(KTOTAL+LMINPK,NXY) */ - if (*nxy - nendb <= lminpk / 2) { + if (*nxy - nendb <= lminpk / 2) + { nendb = *nxy; } -/* ABOVE STATEMENT GUARANTEES THE LAST GROUP IS GT LMINPK/2 BY */ -/* MAKING THE ACTUAL GROUP LARGER. IF A PROVISION LIKE THIS IS */ -/* NOT INCLUDED, THERE WILL MANY TIMES BE A VERY SMALL GROUP */ -/* AT THE END. USE SEPARATE LOOPS FOR MISSING AND NO MISSING */ + /* ABOVE STATEMENT GUARANTEES THE LAST GROUP IS GT LMINPK/2 BY */ + /* MAKING THE ACTUAL GROUP LARGER. IF A PROVISION LIKE THIS IS */ + /* NOT INCLUDED, THERE WILL MANY TIMES BE A VERY SMALL GROUP */ + /* AT THE END. USE SEPARATE LOOPS FOR MISSING AND NO MISSING */ -/* USE SEPARATE LOOPS FOR MISSING AND NO MISSING VALUES */ -/* FOR EFFICIENCY. */ + /* USE SEPARATE LOOPS FOR MISSING AND NO MISSING VALUES */ + /* FOR EFFICIENCY. */ - if (*is523 == 0) { + if (*is523 == 0) + { i__1 = nendb; - for (k = mstart; k <= i__1; ++k) { - if (ic[k] <= minb) { + for (k = mstart; k <= i__1; ++k) + { + if (ic[k] <= minb) + { minb = ic[k]; -/* NOTE LE, NOT LT. LT COULD BE USED BUT THEN A */ -/* RECOMPUTE OVER THE WHOLE GROUP WOULD BE NEEDED */ -/* MORE OFTEN. SAME REASONING FOR GE AND OTHER */ -/* LOOPS BELOW. */ + /* NOTE LE, NOT LT. LT COULD BE USED BUT THEN A */ + /* RECOMPUTE OVER THE WHOLE GROUP WOULD BE NEEDED */ + /* MORE OFTEN. SAME REASONING FOR GE AND OTHER */ + /* LOOPS BELOW. */ minbk = k; } - if (ic[k] >= maxb) { + if (ic[k] >= maxb) + { maxb = ic[k]; maxbk = k; } -/* L155: */ + /* L155: */ } - - } else if (*is523 == 1) { + } + else if (*is523 == 1) + { i__1 = nendb; - for (k = mstart; k <= i__1; ++k) { - if (ic[k] == *missp) { + for (k = mstart; k <= i__1; ++k) + { + if (ic[k] == *missp) + { goto L157; } - if (ic[k] <= minb) { + if (ic[k] <= minb) + { minb = ic[k]; minbk = k; } - if (ic[k] >= maxb) { + if (ic[k] >= maxb) + { maxb = ic[k]; maxbk = k; } - L157: - ; + L157:; } - - } else { + } + else + { i__1 = nendb; - for (k = mstart; k <= i__1; ++k) { - if (ic[k] == *missp || ic[k] == *misss) { + for (k = mstart; k <= i__1; ++k) + { + if (ic[k] == *missp || ic[k] == *misss) + { goto L160; } - if (ic[k] <= minb) { + if (ic[k] <= minb) + { minb = ic[k]; minbk = k; } - if (ic[k] >= maxb) { + if (ic[k] >= maxb) + { maxb = ic[k]; maxbk = k; } - L160: - ; + L160:; } - } kountb = nendb - ktotal; misllb = 0; - if (minb != mallow) { + if (minb != mallow) + { goto L165; } -/* ALL MISSING VALUES MUST BE ACCOMMODATED. */ + /* ALL MISSING VALUES MUST BE ACCOMMODATED. */ minb = 0; maxb = 0; misllb = 1; ibitb = 0; - if (*is523 != 2) { + if (*is523 != 2) + { goto L170; } -/* WHEN ALL VALUES ARE MISSING AND THERE ARE NO SECONDARY */ -/* MISSING VALUES, IBITB = 0. OTHERWISE, IBITB MUST BE */ -/* CALCULATED. */ + /* WHEN ALL VALUES ARE MISSING AND THERE ARE NO SECONDARY */ + /* MISSING VALUES, IBITB = 0. OTHERWISE, IBITB MUST BE */ + /* CALCULATED. */ L165: - for (ibitb = ibitbs; ibitb <= 30; ++ibitb) { - if (maxb - minb < ibxx2[ibitb] - lmiss) { + for (ibitb = ibitbs; ibitb <= 30; ++ibitb) + { + if (maxb - minb < ibxx2[ibitb] - lmiss) + { goto L170; } -/* L166: */ + /* L166: */ } -/* WRITE(KFILDO,167)MAXB,MINB */ -/* 167 FORMAT(' ****ERROR IN PACK_GP. VALUE WILL NOT PACK IN 30 BITS.', */ -/* 1 ' MAXB ='I13,' MINB ='I13,'. ERROR AT 167.') */ + /* WRITE(KFILDO,167)MAXB,MINB */ + /* 167 FORMAT(' ****ERROR IN PACK_GP. VALUE WILL NOT PACK IN 30 BITS.', */ + /* 1 ' MAXB ='I13,' MINB ='I13,'. ERROR AT 167.') */ *ier = 706; goto L900; -/* COMPARE THE BITS NEEDED TO PACK GROUP B WITH THOSE NEEDED */ -/* TO PACK GROUP A. IF IBITB GE IBITA, TRY TO ADD TO GROUP A. */ -/* IF NOT, TRY TO ADD A'S POINTS TO B, UNLESS ADDITION TO A */ -/* HAS BEEN DONE. THIS LATTER IS CONTROLLED WITH ADDA. */ + /* COMPARE THE BITS NEEDED TO PACK GROUP B WITH THOSE NEEDED */ + /* TO PACK GROUP A. IF IBITB GE IBITA, TRY TO ADD TO GROUP A. */ + /* IF NOT, TRY TO ADD A'S POINTS TO B, UNLESS ADDITION TO A */ + /* HAS BEEN DONE. THIS LATTER IS CONTROLLED WITH ADDA. */ L170: -/* ***D WRITE(KFILDO,171)KOUNTA,KTOTAL,MINA,MAXA,IBITA,MISLLA, */ -/* ***D 1 MINB,MAXB,IBITB,MISLLB */ -/* ***D171 FORMAT(' AT 171, KOUNTA ='I8,' KTOTAL ='I8,' MINA ='I8, */ -/* ***D 1 ' MAXA ='I8,' IBITA ='I3,' MISLLA ='I3, */ -/* ***D 2 ' MINB ='I8,' MAXB ='I8,' IBITB ='I3,' MISLLB ='I3) */ + /* ***D WRITE(KFILDO,171)KOUNTA,KTOTAL,MINA,MAXA,IBITA,MISLLA, */ + /* ***D 1 MINB,MAXB,IBITB,MISLLB */ + /* ***D171 FORMAT(' AT 171, KOUNTA ='I8,' KTOTAL ='I8,' MINA ='I8, */ + /* ***D 1 ' MAXA ='I8,' IBITA ='I3,' MISLLA ='I3, */ + /* ***D 2 ' MINB ='I8,' MAXB ='I8,' IBITB ='I3,' MISLLB ='I3) */ - if (ibitb >= ibita) { + if (ibitb >= ibita) + { goto L180; } - if (adda) { + if (adda) + { goto L200; } -/* ************************************* */ + /* ************************************* */ -/* GROUP B REQUIRES LESS BITS THAN GROUP A. PUT AS MANY OF A'S */ -/* POINTS INTO B AS POSSIBLE WITHOUT EXCEEDING THE NUMBER OF */ -/* BITS NECESSARY TO PACK GROUP B. */ + /* GROUP B REQUIRES LESS BITS THAN GROUP A. PUT AS MANY OF A'S */ + /* POINTS INTO B AS POSSIBLE WITHOUT EXCEEDING THE NUMBER OF */ + /* BITS NECESSARY TO PACK GROUP B. */ -/* ************************************* */ + /* ************************************* */ kounts = kounta; -/* KOUNTA REFERS TO THE PRESENT GROUP A. */ + /* KOUNTA REFERS TO THE PRESENT GROUP A. */ mintst = minb; maxtst = maxb; mintstk = minbk; maxtstk = maxbk; -/* USE SEPARATE LOOPS FOR MISSING AND NO MISSING VALUES */ -/* FOR EFFICIENCY. */ + /* USE SEPARATE LOOPS FOR MISSING AND NO MISSING VALUES */ + /* FOR EFFICIENCY. */ - if (*is523 == 0) { + if (*is523 == 0) + { i__1 = kstart; - for (k = ktotal; k >= i__1; --k) { -/* START WITH THE END OF THE GROUP AND WORK BACKWARDS. */ - if (ic[k] < minb) { + for (k = ktotal; k >= i__1; --k) + { + /* START WITH THE END OF THE GROUP AND WORK BACKWARDS. */ + if (ic[k] < minb) + { mintst = ic[k]; mintstk = k; - } else if (ic[k] > maxb) { + } + else if (ic[k] > maxb) + { maxtst = ic[k]; maxtstk = k; } - if (maxtst - mintst >= ibxx2[ibitb]) { + if (maxtst - mintst >= ibxx2[ibitb]) + { goto L174; } -/* NOTE THAT FOR THIS LOOP, LMISS = 0. */ + /* NOTE THAT FOR THIS LOOP, LMISS = 0. */ minb = mintst; maxb = maxtst; minbk = mintstk; maxbk = maxtstk; --kounta; -/* THERE IS ONE LESS POINT NOW IN A. */ -/* L1715: */ + /* THERE IS ONE LESS POINT NOW IN A. */ + /* L1715: */ } - - } else if (*is523 == 1) { + } + else if (*is523 == 1) + { i__1 = kstart; - for (k = ktotal; k >= i__1; --k) { -/* START WITH THE END OF THE GROUP AND WORK BACKWARDS. */ - if (ic[k] == *missp) { + for (k = ktotal; k >= i__1; --k) + { + /* START WITH THE END OF THE GROUP AND WORK BACKWARDS. */ + if (ic[k] == *missp) + { goto L1718; } - if (ic[k] < minb) { + if (ic[k] < minb) + { mintst = ic[k]; mintstk = k; - } else if (ic[k] > maxb) { + } + else if (ic[k] > maxb) + { maxtst = ic[k]; maxtstk = k; } - if (maxtst - mintst >= ibxx2[ibitb] - lmiss) { + if (maxtst - mintst >= ibxx2[ibitb] - lmiss) + { goto L174; } -/* FOR THIS LOOP, LMISS = 1. */ + /* FOR THIS LOOP, LMISS = 1. */ minb = mintst; maxb = maxtst; minbk = mintstk; maxbk = maxtstk; misllb = 0; -/* WHEN THE POINT IS NON MISSING, MISLLB SET = 0. */ + /* WHEN THE POINT IS NON MISSING, MISLLB SET = 0. */ L1718: --kounta; -/* THERE IS ONE LESS POINT NOW IN A. */ -/* L1719: */ + /* THERE IS ONE LESS POINT NOW IN A. */ + /* L1719: */ } - - } else { + } + else + { i__1 = kstart; - for (k = ktotal; k >= i__1; --k) { -/* START WITH THE END OF THE GROUP AND WORK BACKWARDS. */ - if (ic[k] == *missp || ic[k] == *misss) { + for (k = ktotal; k >= i__1; --k) + { + /* START WITH THE END OF THE GROUP AND WORK BACKWARDS. */ + if (ic[k] == *missp || ic[k] == *misss) + { goto L1729; } - if (ic[k] < minb) { + if (ic[k] < minb) + { mintst = ic[k]; mintstk = k; - } else if (ic[k] > maxb) { + } + else if (ic[k] > maxb) + { maxtst = ic[k]; maxtstk = k; } - if (maxtst - mintst >= ibxx2[ibitb] - lmiss) { + if (maxtst - mintst >= ibxx2[ibitb] - lmiss) + { goto L174; } -/* FOR THIS LOOP, LMISS = 2. */ + /* FOR THIS LOOP, LMISS = 2. */ minb = mintst; maxb = maxtst; minbk = mintstk; maxbk = maxtstk; misllb = 0; -/* WHEN THE POINT IS NON MISSING, MISLLB SET = 0. */ + /* WHEN THE POINT IS NON MISSING, MISLLB SET = 0. */ L1729: --kounta; -/* THERE IS ONE LESS POINT NOW IN A. */ -/* L173: */ + /* THERE IS ONE LESS POINT NOW IN A. */ + /* L173: */ } - } -/* AT THIS POINT, KOUNTA CONTAINS THE NUMBER OF POINTS TO CLOSE */ -/* OUT GROUP A WITH. GROUP B NOW STARTS WITH KSTART+KOUNTA AND */ -/* ENDS WITH NENDB. MINB AND MAXB HAVE BEEN ADJUSTED AS */ -/* NECESSARY TO REFLECT GROUP B (EVEN THOUGH THE NUMBER OF BITS */ -/* NEEDED TO PACK GROUP B HAVE NOT INCREASED, THE END POINTS */ -/* OF THE RANGE MAY HAVE). */ + /* AT THIS POINT, KOUNTA CONTAINS THE NUMBER OF POINTS TO CLOSE */ + /* OUT GROUP A WITH. GROUP B NOW STARTS WITH KSTART+KOUNTA AND */ + /* ENDS WITH NENDB. MINB AND MAXB HAVE BEEN ADJUSTED AS */ + /* NECESSARY TO REFLECT GROUP B (EVEN THOUGH THE NUMBER OF BITS */ + /* NEEDED TO PACK GROUP B HAVE NOT INCREASED, THE END POINTS */ + /* OF THE RANGE MAY HAVE). */ L174: - if (kounta == kounts) { + if (kounta == kounts) + { goto L200; } -/* ON TRANSFER, GROUP A WAS NOT CHANGED. CLOSE IT OUT. */ + /* ON TRANSFER, GROUP A WAS NOT CHANGED. CLOSE IT OUT. */ -/* ONE OR MORE POINTS WERE TAKEN OUT OF A. RANGE AND IBITA */ -/* MAY HAVE TO BE RECOMPUTED; IBITA COULD BE LESS THAN */ -/* ORIGINALLY COMPUTED. IN FACT, GROUP A CAN NOW CONTAIN */ -/* ONLY ONE POINT AND BE PACKED WITH ZERO BITS */ -/* (UNLESS MISSS NE 0). */ + /* ONE OR MORE POINTS WERE TAKEN OUT OF A. RANGE AND IBITA */ + /* MAY HAVE TO BE RECOMPUTED; IBITA COULD BE LESS THAN */ + /* ORIGINALLY COMPUTED. IN FACT, GROUP A CAN NOW CONTAIN */ + /* ONLY ONE POINT AND BE PACKED WITH ZERO BITS */ + /* (UNLESS MISSS NE 0). */ nouta = kounts - kounta; ktotal -= nouta; kountb += nouta; - if (nenda - nouta > minak && nenda - nouta > maxak) { + if (nenda - nouta > minak && nenda - nouta > maxak) + { goto L200; } -/* WHEN THE ABOVE TEST IS MET, THE MIN AND MAX OF THE */ -/* CURRENT GROUP A WERE WITHIN THE OLD GROUP A, SO THE */ -/* RANGE AND IBITA DO NOT NEED TO BE RECOMPUTED. */ -/* NOTE THAT MINAK AND MAXAK ARE NO LONGER NEEDED. */ + /* WHEN THE ABOVE TEST IS MET, THE MIN AND MAX OF THE */ + /* CURRENT GROUP A WERE WITHIN THE OLD GROUP A, SO THE */ + /* RANGE AND IBITA DO NOT NEED TO BE RECOMPUTED. */ + /* NOTE THAT MINAK AND MAXAK ARE NO LONGER NEEDED. */ ibita = 0; mina = mallow; maxa = -mallow; -/* USE SEPARATE LOOPS FOR MISSING AND NO MISSING VALUES */ -/* FOR EFFICIENCY. */ + /* USE SEPARATE LOOPS FOR MISSING AND NO MISSING VALUES */ + /* FOR EFFICIENCY. */ - if (*is523 == 0) { + if (*is523 == 0) + { i__1 = nenda - nouta; - for (k = kstart; k <= i__1; ++k) { - if (ic[k] < mina) { + for (k = kstart; k <= i__1; ++k) + { + if (ic[k] < mina) + { mina = ic[k]; } - if (ic[k] > maxa) { + if (ic[k] > maxa) + { maxa = ic[k]; } -/* L1742: */ + /* L1742: */ } - - } else if (*is523 == 1) { + } + else if (*is523 == 1) + { i__1 = nenda - nouta; - for (k = kstart; k <= i__1; ++k) { - if (ic[k] == *missp) { + for (k = kstart; k <= i__1; ++k) + { + if (ic[k] == *missp) + { goto L1744; } - if (ic[k] < mina) { + if (ic[k] < mina) + { mina = ic[k]; } - if (ic[k] > maxa) { + if (ic[k] > maxa) + { maxa = ic[k]; } - L1744: - ; + L1744:; } - - } else { + } + else + { i__1 = nenda - nouta; - for (k = kstart; k <= i__1; ++k) { - if (ic[k] == *missp || ic[k] == *misss) { + for (k = kstart; k <= i__1; ++k) + { + if (ic[k] == *missp || ic[k] == *misss) + { goto L175; } - if (ic[k] < mina) { + if (ic[k] < mina) + { mina = ic[k]; } - if (ic[k] > maxa) { + if (ic[k] > maxa) + { maxa = ic[k]; } - L175: - ; + L175:; } - } mislla = 0; - if (mina != mallow) { + if (mina != mallow) + { goto L1750; } -/* ALL MISSING VALUES MUST BE ACCOMMODATED. */ + /* ALL MISSING VALUES MUST BE ACCOMMODATED. */ mina = 0; maxa = 0; mislla = 1; - if (*is523 != 2) { + if (*is523 != 2) + { goto L177; } -/* WHEN ALL VALUES ARE MISSING AND THERE ARE NO SECONDARY */ -/* MISSING VALUES IBITA = 0 AS ORIGINALLY SET. OTHERWISE, */ -/* IBITA MUST BE CALCULATED. */ + /* WHEN ALL VALUES ARE MISSING AND THERE ARE NO SECONDARY */ + /* MISSING VALUES IBITA = 0 AS ORIGINALLY SET. OTHERWISE, */ + /* IBITA MUST BE CALCULATED. */ L1750: itest = maxa - mina + lmiss; - for (ibita = 0; ibita <= 30; ++ibita) { - if (itest < ibxx2[ibita]) { + for (ibita = 0; ibita <= 30; ++ibita) + { + if (itest < ibxx2[ibita]) + { goto L177; } -/* *** THIS TEST IS THE SAME AS: */ -/* *** IF(MAXA-MINA.LT.IBXX2(IBITA)-LMISS)GO TO 177 */ -/* L176: */ + /* *** THIS TEST IS THE SAME AS: */ + /* *** IF(MAXA-MINA.LT.IBXX2(IBITA)-LMISS)GO TO 177 */ + /* L176: */ } -/* WRITE(KFILDO,1760)MAXA,MINA */ -/* 1760 FORMAT(' ****ERROR IN PACK_GP. VALUE WILL NOT PACK IN 30 BITS.', */ -/* 1 ' MAXA ='I13,' MINA ='I13,'. ERROR AT 1760.') */ + /* WRITE(KFILDO,1760)MAXA,MINA */ + /* 1760 FORMAT(' ****ERROR IN PACK_GP. VALUE WILL NOT PACK IN 30 BITS.', */ + /* 1 ' MAXA ='I13,' MINA ='I13,'. ERROR AT 1760.') */ *ier = 706; goto L900; L177: goto L200; -/* ************************************* */ + /* ************************************* */ -/* AT THIS POINT, GROUP B REQUIRES AS MANY BITS TO PACK AS GROUPA. */ -/* THEREFORE, TRY TO ADD INC POINTS TO GROUP A WITHOUT INCREASING */ -/* IBITA. THIS AUGMENTED GROUP IS CALLED GROUP C. */ + /* AT THIS POINT, GROUP B REQUIRES AS MANY BITS TO PACK AS GROUPA. */ + /* THEREFORE, TRY TO ADD INC POINTS TO GROUP A WITHOUT INCREASING */ + /* IBITA. THIS AUGMENTED GROUP IS CALLED GROUP C. */ -/* ************************************* */ + /* ************************************* */ L180: - if (mislla == 1) { + if (mislla == 1) + { minc = mallow; minck = mallow; maxc = -mallow; maxck = -mallow; - } else { + } + else + { minc = mina; maxc = maxa; minck = minak; @@ -1006,117 +1091,134 @@ pack_gp(g2int *kfildo, g2int *ic, g2int *nxy, } nount = 0; - if (*nxy - (ktotal + kinc) <= lminpk / 2) { + if (*nxy - (ktotal + kinc) <= lminpk / 2) + { kinc = *nxy - ktotal; } -/* ABOVE STATEMENT CONSTRAINS THE LAST GROUP TO BE NOT LESS THAN */ -/* LMINPK/2 IN SIZE. IF A PROVISION LIKE THIS IS NOT INCLUDED, */ -/* THERE WILL MANY TIMES BE A VERY SMALL GROUP AT THE END. */ + /* ABOVE STATEMENT CONSTRAINS THE LAST GROUP TO BE NOT LESS THAN */ + /* LMINPK/2 IN SIZE. IF A PROVISION LIKE THIS IS NOT INCLUDED, */ + /* THERE WILL MANY TIMES BE A VERY SMALL GROUP AT THE END. */ -/* USE SEPARATE LOOPS FOR MISSING AND NO MISSING VALUES */ -/* FOR EFFICIENCY. SINCE KINC IS USUALLY 1, USING SEPARATE */ -/* LOOPS HERE DOESN'T BUY MUCH. A MISSING VALUE WILL ALWAYS */ -/* TRANSFER BACK TO GROUP A. */ + /* USE SEPARATE LOOPS FOR MISSING AND NO MISSING VALUES */ + /* FOR EFFICIENCY. SINCE KINC IS USUALLY 1, USING SEPARATE */ + /* LOOPS HERE DOESN'T BUY MUCH. A MISSING VALUE WILL ALWAYS */ + /* TRANSFER BACK TO GROUP A. */ - if (*is523 == 0) { + if (*is523 == 0) + { -/* Computing MIN */ + /* Computing MIN */ i__2 = ktotal + kinc; /*i__1 = min(i__2,*nxy);*/ i__1 = (i__2 < *nxy) ? i__2 : *nxy; - for (k = ktotal + 1; k <= i__1; ++k) { - if (ic[k] < minc) { + for (k = ktotal + 1; k <= i__1; ++k) + { + if (ic[k] < minc) + { minc = ic[k]; minck = k; } - if (ic[k] > maxc) { + if (ic[k] > maxc) + { maxc = ic[k]; maxck = k; } ++nount; -/* L185: */ + /* L185: */ } + } + else if (*is523 == 1) + { - } else if (*is523 == 1) { - -/* Computing MIN */ + /* Computing MIN */ i__2 = ktotal + kinc; /*i__1 = min(i__2,*nxy);*/ i__1 = (i__2 < *nxy) ? i__2 : *nxy; - for (k = ktotal + 1; k <= i__1; ++k) { - if (ic[k] == *missp) { + for (k = ktotal + 1; k <= i__1; ++k) + { + if (ic[k] == *missp) + { goto L186; } - if (ic[k] < minc) { + if (ic[k] < minc) + { minc = ic[k]; minck = k; } - if (ic[k] > maxc) { + if (ic[k] > maxc) + { maxc = ic[k]; maxck = k; } L186: ++nount; -/* L187: */ + /* L187: */ } + } + else + { - } else { - -/* Computing MIN */ + /* Computing MIN */ i__2 = ktotal + kinc; /*i__1 = min(i__2,*nxy);*/ i__1 = (i__2 < *nxy) ? i__2 : *nxy; - for (k = ktotal + 1; k <= i__1; ++k) { - if (ic[k] == *missp || ic[k] == *misss) { + for (k = ktotal + 1; k <= i__1; ++k) + { + if (ic[k] == *missp || ic[k] == *misss) + { goto L189; } - if (ic[k] < minc) { + if (ic[k] < minc) + { minc = ic[k]; minck = k; } - if (ic[k] > maxc) { + if (ic[k] > maxc) + { maxc = ic[k]; maxck = k; } L189: ++nount; -/* L190: */ + /* L190: */ } - } -/* ***D WRITE(KFILDO,191)KOUNTA,KTOTAL,MINA,MAXA,IBITA,MISLLA, */ -/* ***D 1 MINC,MAXC,NOUNT,IC(KTOTAL),IC(KTOTAL+1) */ -/* ***D191 FORMAT(' AT 191, KOUNTA ='I8,' KTOTAL ='I8,' MINA ='I8, */ -/* ***D 1 ' MAXA ='I8,' IBITA ='I3,' MISLLA ='I3, */ -/* ***D 2 ' MINC ='I8,' MAXC ='I8, */ -/* ***D 3 ' NOUNT ='I5,' IC(KTOTAL) ='I9,' IC(KTOTAL+1) =',I9) */ + /* ***D WRITE(KFILDO,191)KOUNTA,KTOTAL,MINA,MAXA,IBITA,MISLLA, */ + /* ***D 1 MINC,MAXC,NOUNT,IC(KTOTAL),IC(KTOTAL+1) */ + /* ***D191 FORMAT(' AT 191, KOUNTA ='I8,' KTOTAL ='I8,' MINA ='I8, */ + /* ***D 1 ' MAXA ='I8,' IBITA ='I3,' MISLLA ='I3, */ + /* ***D 2 ' MINC ='I8,' MAXC ='I8, */ + /* ***D 3 ' NOUNT ='I5,' IC(KTOTAL) ='I9,' IC(KTOTAL+1) =',I9) */ -/* IF THE NUMBER OF BITS NEEDED FOR GROUP C IS GT IBITA, */ -/* THEN THIS GROUP A IS A GROUP TO PACK. */ + /* IF THE NUMBER OF BITS NEEDED FOR GROUP C IS GT IBITA, */ + /* THEN THIS GROUP A IS A GROUP TO PACK. */ - if (minc == mallow) { + if (minc == mallow) + { minc = mina; maxc = maxa; minck = minak; maxck = maxak; misllc = 1; goto L195; -/* WHEN THE NEW VALUE(S) ARE MISSING, THEY CAN ALWAYS */ -/* BE ADDED. */ - - } else { + /* WHEN THE NEW VALUE(S) ARE MISSING, THEY CAN ALWAYS */ + /* BE ADDED. */ + } + else + { misllc = 0; } - if (maxc - minc >= ibxx2[ibita] - lmiss) { + if (maxc - minc >= ibxx2[ibita] - lmiss) + { goto L200; } -/* THE BITS NECESSARY FOR GROUP C HAS NOT INCREASED FROM THE */ -/* BITS NECESSARY FOR GROUP A. ADD THIS POINT(S) TO GROUP A. */ -/* COMPUTE THE NEXT GROUP B, ETC., UNLESS ALL POINTS HAVE BEEN */ -/* USED. */ + /* THE BITS NECESSARY FOR GROUP C HAS NOT INCREASED FROM THE */ + /* BITS NECESSARY FOR GROUP A. ADD THIS POINT(S) TO GROUP A. */ + /* COMPUTE THE NEXT GROUP B, ETC., UNLESS ALL POINTS HAVE BEEN */ + /* USED. */ L195: ktotal += nount; @@ -1127,40 +1229,45 @@ pack_gp(g2int *kfildo, g2int *ic, g2int *nxy, maxak = maxck; mislla = misllc; adda = TRUE_; - if (ktotal >= *nxy) { + if (ktotal >= *nxy) + { goto L200; } - if (minbk > ktotal && maxbk > ktotal) { + if (minbk > ktotal && maxbk > ktotal) + { mstart = nendb + 1; -/* THE MAX AND MIN OF GROUP B WERE NOT FROM THE POINTS */ -/* REMOVED, SO THE WHOLE GROUP DOES NOT HAVE TO BE LOOKED */ -/* AT TO DETERMINE THE NEW MAX AND MIN. RATHER START */ -/* JUST BEYOND THE OLD NENDB. */ + /* THE MAX AND MIN OF GROUP B WERE NOT FROM THE POINTS */ + /* REMOVED, SO THE WHOLE GROUP DOES NOT HAVE TO BE LOOKED */ + /* AT TO DETERMINE THE NEW MAX AND MIN. RATHER START */ + /* JUST BEYOND THE OLD NENDB. */ ibitbs = ibitb; nendb = 1; goto L150; - } else { + } + else + { goto L140; } -/* ************************************* */ + /* ************************************* */ -/* GROUP A IS TO BE PACKED. STORE VALUES IN JMIN( ), JMAX( ), */ -/* LBIT( ), AND NOV( ). */ + /* GROUP A IS TO BE PACKED. STORE VALUES IN JMIN( ), JMAX( ), */ + /* LBIT( ), AND NOV( ). */ -/* ************************************* */ + /* ************************************* */ L200: ++(*lx); - if (*lx <= *ndg) { + if (*lx <= *ndg) + { goto L205; } lminpk += lminpk / 2; -/* WRITE(KFILDO,201)NDG,LMINPK,LX */ -/* 201 FORMAT(' ****NDG ='I5,' NOT LARGE ENOUGH.', */ -/* 1 ' LMINPK IS INCREASED TO 'I3,' FOR THIS FIELD.'/ */ -/* 2 ' LX = 'I10) */ + /* WRITE(KFILDO,201)NDG,LMINPK,LX */ + /* 201 FORMAT(' ****NDG ='I5,' NOT LARGE ENOUGH.', */ + /* 1 ' LMINPK IS INCREASED TO 'I3,' FOR THIS FIELD.'/ */ + /* 2 ' LX = 'I10) */ iersav = 716; goto L105; @@ -1171,25 +1278,29 @@ pack_gp(g2int *kfildo, g2int *ic, g2int *nxy, nov[*lx] = kounta; kstart = ktotal + 1; - if (mislla == 0) { + if (mislla == 0) + { misslx[*lx - 1] = mallow; - } else { + } + else + { misslx[*lx - 1] = ic[ktotal]; -/* IC(KTOTAL) WAS THE LAST VALUE PROCESSED. IF MISLLA NE 0, */ -/* THIS MUST BE THE MISSING VALUE FOR THIS GROUP. */ + /* IC(KTOTAL) WAS THE LAST VALUE PROCESSED. IF MISLLA NE 0, */ + /* THIS MUST BE THE MISSING VALUE FOR THIS GROUP. */ } -/* ***D WRITE(KFILDO,206)MISLLA,IC(KTOTAL),KTOTAL,LX,JMIN(LX),JMAX(LX), */ -/* ***D 1 LBIT(LX),NOV(LX),MISSLX(LX) */ -/* ***D206 FORMAT(' AT 206, MISLLA ='I2,' IC(KTOTAL) ='I5,' KTOTAL ='I8, */ -/* ***D 1 ' LX ='I6,' JMIN(LX) ='I8,' JMAX(LX) ='I8, */ -/* ***D 2 ' LBIT(LX) ='I5,' NOV(LX) ='I8,' MISSLX(LX) =',I7) */ + /* ***D WRITE(KFILDO,206)MISLLA,IC(KTOTAL),KTOTAL,LX,JMIN(LX),JMAX(LX), */ + /* ***D 1 LBIT(LX),NOV(LX),MISSLX(LX) */ + /* ***D206 FORMAT(' AT 206, MISLLA ='I2,' IC(KTOTAL) ='I5,' KTOTAL ='I8, */ + /* ***D 1 ' LX ='I6,' JMIN(LX) ='I8,' JMAX(LX) ='I8, */ + /* ***D 2 ' LBIT(LX) ='I5,' NOV(LX) ='I8,' MISSLX(LX) =',I7) */ - if (ktotal >= *nxy) { + if (ktotal >= *nxy) + { goto L209; } -/* THE NEW GROUP A WILL BE THE PREVIOUS GROUP B. SET LIMITS, ETC. */ + /* THE NEW GROUP A WILL BE THE PREVIOUS GROUP B. SET LIMITS, ETC. */ ibita = ibitb; mina = minb; @@ -1203,200 +1314,215 @@ pack_gp(g2int *kfildo, g2int *ic, g2int *nxy, adda = FALSE_; goto L133; -/* ************************************* */ + /* ************************************* */ -/* CALCULATE IBIT, THE NUMBER OF BITS NEEDED TO HOLD THE GROUP */ -/* MINIMUM VALUES. */ + /* CALCULATE IBIT, THE NUMBER OF BITS NEEDED TO HOLD THE GROUP */ + /* MINIMUM VALUES. */ -/* ************************************* */ + /* ************************************* */ L209: *ibit = 0; i__1 = *lx; - for (l = 1; l <= i__1; ++l) { + for (l = 1; l <= i__1; ++l) + { L210: - if (jmin[l] < ibxx2[*ibit]) { + if (jmin[l] < ibxx2[*ibit]) + { goto L220; } ++(*ibit); goto L210; - L220: - ; + L220:; } -/* INSERT THE VALUE IN JMIN( ) TO BE USED FOR ALL MISSING */ -/* VALUES WHEN LBIT( ) = 0. WHEN SECONDARY MISSING */ -/* VALUES CAN BE PRESENT, LBIT(L) WILL NOT = 0. */ + /* INSERT THE VALUE IN JMIN( ) TO BE USED FOR ALL MISSING */ + /* VALUES WHEN LBIT( ) = 0. WHEN SECONDARY MISSING */ + /* VALUES CAN BE PRESENT, LBIT(L) WILL NOT = 0. */ - if (*is523 == 1) { + if (*is523 == 1) + { i__1 = *lx; - for (l = 1; l <= i__1; ++l) { + for (l = 1; l <= i__1; ++l) + { - if (lbit[l] == 0) { + if (lbit[l] == 0) + { - if (misslx[l - 1] == *missp) { + if (misslx[l - 1] == *missp) + { jmin[l] = ibxx2[*ibit] - 1; } - } -/* L226: */ + /* L226: */ } - } -/* ************************************* */ + /* ************************************* */ -/* CALCULATE JBIT, THE NUMBER OF BITS NEEDED TO HOLD THE BITS */ -/* NEEDED TO PACK THE VALUES IN THE GROUPS. BUT FIND AND */ -/* REMOVE THE REFERENCE VALUE FIRST. */ + /* CALCULATE JBIT, THE NUMBER OF BITS NEEDED TO HOLD THE BITS */ + /* NEEDED TO PACK THE VALUES IN THE GROUPS. BUT FIND AND */ + /* REMOVE THE REFERENCE VALUE FIRST. */ -/* ************************************* */ + /* ************************************* */ -/* WRITE(KFILDO,228)CFEED,LX */ -/* 228 FORMAT(A1,/' *****************************************' */ -/* 1 /' THE GROUP WIDTHS LBIT( ) FOR ',I8,' GROUPS' */ -/* 2 /' *****************************************') */ -/* WRITE(KFILDO,229) (LBIT(J),J=1,MIN(LX,100)) */ -/* 229 FORMAT(/' '20I6) */ + /* WRITE(KFILDO,228)CFEED,LX */ + /* 228 FORMAT(A1,/' *****************************************' */ + /* 1 /' THE GROUP WIDTHS LBIT( ) FOR ',I8,' GROUPS' */ + /* 2 /' *****************************************') */ + /* WRITE(KFILDO,229) (LBIT(J),J=1,MIN(LX,100)) */ + /* 229 FORMAT(/' '20I6) */ *lbitref = lbit[1]; i__1 = *lx; - for (k = 1; k <= i__1; ++k) { - if (lbit[k] < *lbitref) { + for (k = 1; k <= i__1; ++k) + { + if (lbit[k] < *lbitref) + { *lbitref = lbit[k]; } -/* L230: */ + /* L230: */ } - if (*lbitref != 0) { + if (*lbitref != 0) + { i__1 = *lx; - for (k = 1; k <= i__1; ++k) { + for (k = 1; k <= i__1; ++k) + { lbit[k] -= *lbitref; -/* L240: */ + /* L240: */ } - } -/* WRITE(KFILDO,241)CFEED,LBITREF */ -/* 241 FORMAT(A1,/' *****************************************' */ -/* 1 /' THE GROUP WIDTHS LBIT( ) AFTER REMOVING REFERENCE ', */ -/* 2 I8, */ -/* 3 /' *****************************************') */ -/* WRITE(KFILDO,242) (LBIT(J),J=1,MIN(LX,100)) */ -/* 242 FORMAT(/' '20I6) */ + /* WRITE(KFILDO,241)CFEED,LBITREF */ + /* 241 FORMAT(A1,/' *****************************************' */ + /* 1 /' THE GROUP WIDTHS LBIT( ) AFTER REMOVING REFERENCE ', */ + /* 2 I8, */ + /* 3 /' *****************************************') */ + /* WRITE(KFILDO,242) (LBIT(J),J=1,MIN(LX,100)) */ + /* 242 FORMAT(/' '20I6) */ *jbit = 0; i__1 = *lx; - for (k = 1; k <= i__1; ++k) { + for (k = 1; k <= i__1; ++k) + { L310: - if (lbit[k] < ibxx2[*jbit]) { + if (lbit[k] < ibxx2[*jbit]) + { goto L320; } ++(*jbit); goto L310; - L320: - ; + L320:; } -/* ************************************* */ + /* ************************************* */ -/* CALCULATE KBIT, THE NUMBER OF BITS NEEDED TO HOLD THE NUMBER */ -/* OF VALUES IN THE GROUPS. BUT FIND AND REMOVE THE */ -/* REFERENCE FIRST. */ + /* CALCULATE KBIT, THE NUMBER OF BITS NEEDED TO HOLD THE NUMBER */ + /* OF VALUES IN THE GROUPS. BUT FIND AND REMOVE THE */ + /* REFERENCE FIRST. */ -/* ************************************* */ + /* ************************************* */ -/* WRITE(KFILDO,321)CFEED,LX */ -/* 321 FORMAT(A1,/' *****************************************' */ -/* 1 /' THE GROUP SIZES NOV( ) FOR ',I8,' GROUPS' */ -/* 2 /' *****************************************') */ -/* WRITE(KFILDO,322) (NOV(J),J=1,MIN(LX,100)) */ -/* 322 FORMAT(/' '20I6) */ + /* WRITE(KFILDO,321)CFEED,LX */ + /* 321 FORMAT(A1,/' *****************************************' */ + /* 1 /' THE GROUP SIZES NOV( ) FOR ',I8,' GROUPS' */ + /* 2 /' *****************************************') */ + /* WRITE(KFILDO,322) (NOV(J),J=1,MIN(LX,100)) */ + /* 322 FORMAT(/' '20I6) */ *novref = nov[1]; i__1 = *lx; - for (k = 1; k <= i__1; ++k) { - if (nov[k] < *novref) { + for (k = 1; k <= i__1; ++k) + { + if (nov[k] < *novref) + { *novref = nov[k]; } -/* L400: */ + /* L400: */ } - if (*novref > 0) { + if (*novref > 0) + { i__1 = *lx; - for (k = 1; k <= i__1; ++k) { + for (k = 1; k <= i__1; ++k) + { nov[k] -= *novref; -/* L405: */ + /* L405: */ } - } -/* WRITE(KFILDO,406)CFEED,NOVREF */ -/* 406 FORMAT(A1,/' *****************************************' */ -/* 1 /' THE GROUP SIZES NOV( ) AFTER REMOVING REFERENCE ',I8, */ -/* 2 /' *****************************************') */ -/* WRITE(KFILDO,407) (NOV(J),J=1,MIN(LX,100)) */ -/* 407 FORMAT(/' '20I6) */ -/* WRITE(KFILDO,408)CFEED */ -/* 408 FORMAT(A1,/' *****************************************' */ -/* 1 /' THE GROUP REFERENCES JMIN( )' */ -/* 2 /' *****************************************') */ -/* WRITE(KFILDO,409) (JMIN(J),J=1,MIN(LX,100)) */ -/* 409 FORMAT(/' '20I6) */ + /* WRITE(KFILDO,406)CFEED,NOVREF */ + /* 406 FORMAT(A1,/' *****************************************' */ + /* 1 /' THE GROUP SIZES NOV( ) AFTER REMOVING REFERENCE ',I8, */ + /* 2 /' *****************************************') */ + /* WRITE(KFILDO,407) (NOV(J),J=1,MIN(LX,100)) */ + /* 407 FORMAT(/' '20I6) */ + /* WRITE(KFILDO,408)CFEED */ + /* 408 FORMAT(A1,/' *****************************************' */ + /* 1 /' THE GROUP REFERENCES JMIN( )' */ + /* 2 /' *****************************************') */ + /* WRITE(KFILDO,409) (JMIN(J),J=1,MIN(LX,100)) */ + /* 409 FORMAT(/' '20I6) */ *kbit = 0; i__1 = *lx; - for (k = 1; k <= i__1; ++k) { + for (k = 1; k <= i__1; ++k) + { L410: - if (nov[k] < ibxx2[*kbit]) { + if (nov[k] < ibxx2[*kbit]) + { goto L420; } ++(*kbit); goto L410; - L420: - ; + L420:; } -/* DETERMINE WHETHER THE GROUP SIZES SHOULD BE REDUCED */ -/* FOR SPACE EFFICIENCY. */ + /* DETERMINE WHETHER THE GROUP SIZES SHOULD BE REDUCED */ + /* FOR SPACE EFFICIENCY. */ - if (ired == 0) { + if (ired == 0) + { reduce(kfildo, &jmin[1], &jmax[1], &lbit[1], &nov[1], lx, ndg, ibit, jbit, kbit, novref, ibxx2, ier); - if (*ier == 714 || *ier == 715) { -/* REDUCE HAS ABORTED. REEXECUTE PACK_GP WITHOUT REDUCE. */ -/* PROVIDE FOR A NON FATAL RETURN FROM REDUCE. */ + if (*ier == 714 || *ier == 715) + { + /* REDUCE HAS ABORTED. REEXECUTE PACK_GP WITHOUT REDUCE. */ + /* PROVIDE FOR A NON FATAL RETURN FROM REDUCE. */ iersav = *ier; ired = 1; *ier = 0; goto L102; } - } - if ( misslx != 0 ) { + if (misslx != 0) + { free(misslx); - misslx=0; + misslx = 0; } -/* CALL TIMPR(KFILDO,KFILDO,'END PACK_GP ') */ - if (iersav != 0) { + /* CALL TIMPR(KFILDO,KFILDO,'END PACK_GP ') */ + if (iersav != 0) + { *ier = iersav; return 0; } -/* 900 IF(IER.NE.0)RETURN1 */ + /* 900 IF(IER.NE.0)RETURN1 */ L900: - if ( misslx != 0 ) free(misslx); + if (misslx != 0) + free(misslx); return 0; } /* pack_gp__ */ diff --git a/src/pdstemplates.c b/src/pdstemplates.c index 0b86b956..fdd29fb8 100644 --- a/src/pdstemplates.c +++ b/src/pdstemplates.c @@ -45,9 +45,9 @@ */ struct pdstemplate { - g2int template_num; /**< Template number. */ - g2int mappdslen; /**< The number of entries in the template. */ - g2int needext; /**< Does template need extension? */ + g2int template_num; /**< Template number. */ + g2int mappdslen; /**< The number of entries in the template. */ + g2int needext; /**< Does template need extension? */ g2int mappds[G2C_MAX_PDS_TEMPLATE_MAPLEN]; /**< Number of bytes for each template value. */ }; @@ -55,176 +55,176 @@ struct pdstemplate * Data for struct for PDS template. */ static const struct pdstemplate templatespds[G2C_MAX_PDS_TEMPLATE] = -{ - /** 4.0: Analysis or Forecast at Horizontal Level/Layer + { + /** 4.0: Analysis or Forecast at Horizontal Level/Layer at a point in time. */ - {0, 15, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}}, - /** 4.1: Individual Ensemble Forecast at Horizontal Level/Layer + {0, 15, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}}, + /** 4.1: Individual Ensemble Forecast at Horizontal Level/Layer at a point in time. */ - {1, 18, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}}, - /** 4.2: Derived Fcst based on whole Ensemble at Horiz Level/Layer + {1, 18, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}}, + /** 4.2: Derived Fcst based on whole Ensemble at Horiz Level/Layer at a point in time. */ - {2, 17, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1}}, - /** 4.3: Derived Fcst based on Ensemble cluster over rectangular + {2, 17, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1}}, + /** 4.3: Derived Fcst based on Ensemble cluster over rectangular area at Horiz Level/Layer at a point in time. */ - {3, 31, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 1, 1, 1, 1, -4, -4, 4, 4, 1, -1, 4, -1, 4}}, - /** 4.4: Derived Fcst based on Ensemble cluster over circular + {3, 31, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 1, 1, 1, 1, -4, -4, 4, 4, 1, -1, 4, -1, 4}}, + /** 4.4: Derived Fcst based on Ensemble cluster over circular area at Horiz Level/Layer at a point in time. */ - {4, 30, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 1, 1, 1, 1, -4, 4, 4, 1, -1, 4, -1, 4}}, - /** 4.5: Probablility Forecast at Horiz Level/Layer + {4, 30, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 1, 1, 1, 1, -4, 4, 4, 1, -1, 4, -1, 4}}, + /** 4.5: Probablility Forecast at Horiz Level/Layer at a point in time. */ - {5, 22, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, -1, -4, -1, -4}}, - /** 4.6: Percentile Forecast at Horiz Level/Layer + {5, 22, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, -1, -4, -1, -4}}, + /** 4.6: Percentile Forecast at Horiz Level/Layer at a point in time. */ - {6, 16, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1}}, - /** 4.7: Analysis or Forecast Error at Horizontal Level/Layer + {6, 16, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1}}, + /** 4.7: Analysis or Forecast Error at Horizontal Level/Layer at a point in time. */ - {7, 15, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}}, - /** 4.8: Ave/Accum/etc... at Horiz Level/Layer + {7, 15, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}}, + /** 4.8: Ave/Accum/etc... at Horiz Level/Layer in a time interval. */ - {8, 29, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, - /** 4.9: Probablility Forecast at Horiz Level/Layer + {8, 29, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, + /** 4.9: Probablility Forecast at Horiz Level/Layer in a time interval. */ - {9, 36, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, -1, -4, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, - /** 4.10: Percentile Forecast at Horiz Level/Layer + {9, 36, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, -1, -4, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, + /** 4.10: Percentile Forecast at Horiz Level/Layer in a time interval */ - {10, 30, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, - /** 4.11: Individual Ensemble Forecast at Horizontal Level/Layer + {10, 30, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, + /** 4.11: Individual Ensemble Forecast at Horizontal Level/Layer in a time interval */ - {11, 32, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, - /** 4.12: Derived Fcst based on whole Ensemble at Horiz Level/Layer + {11, 32, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, + /** 4.12: Derived Fcst based on whole Ensemble at Horiz Level/Layer in a time interval */ - {12, 31, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, - /** 4.13: Derived Fcst based on Ensemble cluster over rectangular + {12, 31, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, + /** 4.13: Derived Fcst based on Ensemble cluster over rectangular area at Horiz Level/Layer in a time interval */ - {13, 45, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 1, 1, 1, 1, -4, -4, 4, 4, 1, -1, 4, -1, 4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, - /** 4.14: Derived Fcst based on Ensemble cluster over circular + {13, 45, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 1, 1, 1, 1, -4, -4, 4, 4, 1, -1, 4, -1, 4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, + /** 4.14: Derived Fcst based on Ensemble cluster over circular area at Horiz Level/Layer in a time interval */ - {14, 44, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 1, 1, 1, 1, -4, 4, 4, 1, -1, 4, -1, 4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, - /** 4.15: Average, accumulation, extreme values or other statistically-processed values over a + {14, 44, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 1, 1, 1, 1, -4, 4, 4, 1, -1, 4, -1, 4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, + /** 4.15: Average, accumulation, extreme values or other statistically-processed values over a spatial area at a horizontal level or in a horizontal layer at a point in time */ - {15, 18, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}}, - /** 4.20: Radar Product */ - {20, 19, 0, {1, 1, 1, 1, 1, -4, 4, 2, 4, 2, 1, 1, 1, 1, 1, 2, 1, 3, 2}}, - /** 4.30: Satellite Product */ - {30, 5, 1, {1, 1, 1, 1, 1}}, - /** 4.31: Satellite Product */ - {31, 5, 1, {1, 1, 1, 1, 1}}, - /** 4.40: Analysis or forecast at a horizontal level or in a horizontal layer + {15, 18, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}}, + /** 4.20: Radar Product */ + {20, 19, 0, {1, 1, 1, 1, 1, -4, 4, 2, 4, 2, 1, 1, 1, 1, 1, 2, 1, 3, 2}}, + /** 4.30: Satellite Product */ + {30, 5, 1, {1, 1, 1, 1, 1}}, + /** 4.31: Satellite Product */ + {31, 5, 1, {1, 1, 1, 1, 1}}, + /** 4.40: Analysis or forecast at a horizontal level or in a horizontal layer at a point in time for atmospheric chemical constituents */ - {40, 16, 0, {1, 1, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}}, - /** 4.41: Individual ensemble forecast, control and perturbed, at a horizontal level or + {40, 16, 0, {1, 1, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}}, + /** 4.41: Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer at a point in time for atmospheric chemical constituents */ - {41, 19, 0, {1, 1, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}}, - /** 4.42: Average, accumulation, and/or extreme values or other statistically-processed values + {41, 19, 0, {1, 1, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}}, + /** 4.42: Average, accumulation, and/or extreme values or other statistically-processed values at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval for atmospheric chemical constituents */ - {42, 30, 1, {1, 1, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, - /** 4.43: Individual ensemble forecast, control and perturbed, at a horizontal level + {42, 30, 1, {1, 1, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, + /** 4.43: Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval for atmospheric chemical constituents */ - {43,33, 1, {1, 1, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, - /** 4.254: CCITT IA5 Character String */ - {254, 3, 0, {1, 1, 4}}, - /** 4.1000: Cross section of analysis or forecast + {43, 33, 1, {1, 1, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, + /** 4.254: CCITT IA5 Character String */ + {254, 3, 0, {1, 1, 4}}, + /** 4.1000: Cross section of analysis or forecast at a point in time */ - {1000, 9, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4}}, - /** 4.1001: Cross section of Ave/Accum/etc... analysis or forecast + {1000, 9, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4}}, + /** 4.1001: Cross section of Ave/Accum/etc... analysis or forecast in a time interval */ - {1001, 16, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 4, 1, 1, 1, 4, 1, 4}}, - /** 4.1001: Cross section of Ave/Accum/etc... analysis or forecast + {1001, 16, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 4, 1, 1, 1, 4, 1, 4}}, + /** 4.1001: Cross section of Ave/Accum/etc... analysis or forecast over latitude or longitude */ - {1002, 15, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, 1, 1, 4, 4, 2}}, - /** 4.1100: Hovmoller-type grid w/ no averaging or other + {1002, 15, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, 1, 1, 4, 4, 2}}, + /** 4.1100: Hovmoller-type grid w/ no averaging or other statistical processing */ - {1100, 15, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}}, - /** 4.1100: Hovmoller-type grid with averaging or other + {1100, 15, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}}, + /** 4.1100: Hovmoller-type grid with averaging or other statistical processing */ - {1101, 22, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 4, 1, 1, 1, 4, 1, 4}}, - /** 4.32:Simulate (synthetic) Satellite Product */ - {32, 10, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1}}, - /** 4.44: Analysis or forecast at a horizontal level or in a horizontal layer + {1101, 22, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 4, 1, 1, 1, 4, 1, 4}}, + /** 4.32:Simulate (synthetic) Satellite Product */ + {32, 10, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1}}, + /** 4.44: Analysis or forecast at a horizontal level or in a horizontal layer at a point in time for Aerosol */ - {44, 21, 0, {1, 1, 2, 1, -1, -4, -1, -4, 1, 1, 1, 2, 1, 1, -2, 1, -1, -4, 1, -1, -4}}, - /** 4.45: Individual ensemble forecast, control and + {44, 21, 0, {1, 1, 2, 1, -1, -4, -1, -4, 1, 1, 1, 2, 1, 1, -2, 1, -1, -4, 1, -1, -4}}, + /** 4.45: Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer at a point in time for Aerosol */ - {45, 24, 0, {1, 1, 2, 1, -1, -4, -1, -4, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}}, - /** 4.46: Ave or Accum or Extreme value at level/layer + {45, 24, 0, {1, 1, 2, 1, -1, -4, -1, -4, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}}, + /** 4.46: Ave or Accum or Extreme value at level/layer at horizontal level or in a horizontal in a continuous or non-continuous time interval for Aerosol */ - {46, 35, 1, {1, 1, 2, 1, -1, -4, -1, -4, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, - /** 4.47: Individual ensemble forecast, control and + {46, 35, 1, {1, 1, 2, 1, -1, -4, -1, -4, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, + /** 4.47: Individual ensemble forecast, control and perturbed, at horizontal level or in a horizontal in a continuous or non-continuous time interval for Aerosol. */ - {47, 38, 1, {1, 1, 1, 2, 1, -1, -4, -1, -4, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, - /** PDT 4.48 + {47, 38, 1, {1, 1, 1, 2, 1, -1, -4, -1, -4, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, + /** PDT 4.48 4.48: Analysis or forecast at a horizontal level or in a horizontal layer at a point in time for Optical Properties of Aerosol */ - {48, 26, 0, {1, 1, 2, 1, -1, -4, -1, -4, 1, -1, -4, -1, -4, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}}, + {48, 26, 0, {1, 1, 2, 1, -1, -4, -1, -4, 1, -1, -4, -1, -4, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}}, - /** VALIDATION --- PDT 4.50 + /** VALIDATION --- PDT 4.50 4.50: Analysis or forecast of multi component parameter or matrix element at a point in time. */ - {50, 21, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 4, 4, 4, 4}}, + {50, 21, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 4, 4, 4, 4}}, - /** VALIDATION --- PDT 4.52 + /** VALIDATION --- PDT 4.52 4.52: Analysis or forecast of Wave parameters at the Sea surface at a point in time. */ - {52, 15, 0, {1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4}}, + {52, 15, 0, {1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4}}, - /** 4.51: Categorical forecasts at a horizontal level or + /** 4.51: Categorical forecasts at a horizontal level or in a horizontal layer at a point in time. */ - {51, 16, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1}}, + {51, 16, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1}}, - /** 4.91: Categorical forecasts at a horizontal level or + /** 4.91: Categorical forecasts at a horizontal level or in a horizontal layer at a point in time in a continuous or non-continuous time interval. */ - {91, 36, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, -1, -4, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, -/** PDT 4.33 (07/29/2013) + {91, 36, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, -1, -4, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, + /** PDT 4.33 (07/29/2013) 4.33: Individual ensemble forecast, control, perturbed, at a horizontal level or in a horizontal layer at a point in time for simulated (synthetic) Satellite data. */ - {33, 18, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, 2, 2, 2, -1, -4, 1, 1, 1}}, -/** PDT 4.34 (07/29/2013) + {33, 18, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, 2, 2, 2, -1, -4, 1, 1, 1}}, + /** PDT 4.34 (07/29/2013) 4.34: Individual ensemble forecast, control, perturbed, at a horizontal level or in a horizontal layer,in a continuous or non-continuous interval for simulated (synthetic) Satellite data. */ - {34, 32, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, 2, 2, 2, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, -/** PDT 4.53 (07/29/2013) + {34, 32, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, 2, 2, 2, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, + /** PDT 4.53 (07/29/2013) 4.53: Partitioned parameters at horizontal level or horizontal layer at a point in time. */ - {53, 19, 1, {1, 1, 1, 1, 4, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}}, -/** PDT 4.54 (07/29/2013) + {53, 19, 1, {1, 1, 1, 1, 4, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}}, + /** PDT 4.54 (07/29/2013) 4.54: Individual ensemble forecast, control, perturbed, at a horizontal level or in a horizontal layer at a point in time for partitioned parameters. */ - {54, 22, 1, {1, 1, 1, 1, 4, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}}, -/** PDT 4.57 (10/07/2015) + {54, 22, 1, {1, 1, 1, 1, 4, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}}, + /** PDT 4.57 (10/07/2015) 4.57: Analysis or Forecast at a horizontal or in a horizontal layer at a point in time for atmospheric chemical constituents based on a distribution function. */ - {57, 7, 1, {1, 1, 2, 2, 2, 2, 1}}, -/** PDT 4.60 (10/07/2015) + {57, 7, 1, {1, 1, 2, 2, 2, 2, 1}}, + /** PDT 4.60 (10/07/2015) 4.60: Individual ensemble reforecast, control and perturbed, at a horizontal level or in a horizontal layer at a point in time. */ - {60, 24, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1}}, -/** PDT 4.61 (10/07/2015) + {60, 24, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1}}, + /** PDT 4.61 (10/07/2015) 4.61: Individual ensemble reforecast, control and perturbed, at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval. */ - {61, 38, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, -/** VALIDATION --- PDT 4.35 + {61, 38, 1, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}}, + /** VALIDATION --- PDT 4.35 PDT 4.35 (10/07/2015) 4.35: Individual ensemble reforecast, control and perturbed, at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval. */ - {35, 6, 1, {1, 1, 1, 1, 1, 1}} + {35, 6, 1, {1, 1, 1, 1, 1, 1}} -} ; +}; /** * This function returns the index of specified Product Definition @@ -293,7 +293,8 @@ getpdstemplate(g2int number) new->ext = NULL; return new; } - else { + else + { printf("getpdstemplate: PDS Template 4.%d not defined.\n", (int)number); return NULL; } @@ -365,7 +366,7 @@ extpdstemplate(g2int number, g2int *list) l = (j - 2) * 6; for (k = 0; k < 6; k++) { - new->ext[l+k] = new->map[23 + k]; + new->ext[l + k] = new->map[23 + k]; } } } @@ -391,7 +392,7 @@ extpdstemplate(g2int number, g2int *list) if (list[22] > 1) { new->extlen = (list[22] - 1) * 6; - new->ext = (g2int *)malloc(sizeof(g2int)*new->extlen); + new->ext = (g2int *)malloc(sizeof(g2int) * new->extlen); for (j = 2; j <= list[22]; j++) { l = (j - 2) * 6; @@ -454,7 +455,7 @@ extpdstemplate(g2int number, g2int *list) l = 0; for (i = 0; i < list[26]; i++) { - new->ext[l+i] = 1; + new->ext[l + i] = 1; } } else if (number == 14) @@ -484,7 +485,7 @@ extpdstemplate(g2int number, g2int *list) { new->extlen = list[4] * 5; new->ext = malloc(sizeof(g2int) * new->extlen); - for (i = 0;i < list[4]; i++) + for (i = 0; i < list[4]; i++) { l = i * 5; new->ext[l] = 2; @@ -500,7 +501,7 @@ extpdstemplate(g2int number, g2int *list) new->ext = malloc(sizeof(g2int) * new->extlen); for (i = 0; i < list[4]; i++) { - l = i*5; + l = i * 5; new->ext[l] = 2; new->ext[l + 1] = 2; new->ext[l + 2] = 2; @@ -594,11 +595,11 @@ extpdstemplate(g2int number, g2int *list) { l = i * 6; new->ext[l] = 1; - new->ext[l+1] = 1; - new->ext[l+2] = -1; - new->ext[l+3] = -4; - new->ext[l+4] = -1; - new->ext[l+5] = -4; + new->ext[l + 1] = 1; + new->ext[l + 2] = -1; + new->ext[l + 3] = -4; + new->ext[l + 4] = -1; + new->ext[l + 5] = -4; } } else if (number == 33) @@ -612,7 +613,7 @@ extpdstemplate(g2int number, g2int *list) } else if (number == 34) { - new->extlen = ((list[24] - 1) * 6)+list[9]; + new->extlen = ((list[24] - 1) * 6) + list[9]; new->ext = malloc(sizeof(g2int) * new->extlen); if (list[24] > 1) { @@ -646,14 +647,14 @@ extpdstemplate(g2int number, g2int *list) { new->extlen = list[3]; new->ext = malloc(sizeof(g2int) * new->extlen); - for (i = 0;iextlen;i++) + for (i = 0; i < new->extlen; i++) { new->ext[i] = 1; } } else if (number == 91) { - new->extlen = ((list[28] - 1) * 6)+list[15]; + new->extlen = ((list[28] - 1) * 6) + list[15]; new->ext = malloc(sizeof(g2int) * new->extlen); if (list[28] > 1) { @@ -681,22 +682,22 @@ extpdstemplate(g2int number, g2int *list) new->ext = malloc(sizeof(g2int) * new->extlen); for (i = 0; i < list[6]; i++) { - l = i*15; + l = i * 15; new->ext[l] = 1; - new->ext[l+1] = -4; - new->ext[l+2] = 1; - new->ext[l+3] = 1; - new->ext[l+4] = 1; - new->ext[l+5] = 2; - new->ext[l+6] = 1; - new->ext[l+7] = 1; - new->ext[l+8] = -4; - new->ext[l+9] = 1; - new->ext[l+10] = -1; - new->ext[l+11] = -4; - new->ext[l+12] = 1; - new->ext[l+13] = -1; - new->ext[l+14] = -4; + new->ext[l + 1] = -4; + new->ext[l + 2] = 1; + new->ext[l + 3] = 1; + new->ext[l + 4] = 1; + new->ext[l + 5] = 2; + new->ext[l + 6] = 1; + new->ext[l + 7] = 1; + new->ext[l + 8] = -4; + new->ext[l + 9] = 1; + new->ext[l + 10] = -1; + new->ext[l + 11] = -4; + new->ext[l + 12] = 1; + new->ext[l + 13] = -1; + new->ext[l + 14] = -4; } } /* PDT 4.61 (10/07/2015) */ @@ -718,17 +719,17 @@ extpdstemplate(g2int number, g2int *list) } /* PDT 4.35 (10/07/2015) */ else if (number == 35) - { + { new->extlen = list[5] * 5; new->ext = malloc(sizeof(g2int) * new->extlen); - for (i=0; i < list[5]; i++) + for (i = 0; i < list[5]; i++) { l = i * 5; new->ext[l] = 2; - new->ext[l+1] = 2; - new->ext[l+2] = 2; - new->ext[l+3] = 1; - new->ext[l+4] = 4; + new->ext[l + 1] = 2; + new->ext[l + 2] = 2; + new->ext[l + 3] = 1; + new->ext[l + 4] = 4; } } return new; @@ -753,7 +754,7 @@ extpdstemplate(g2int number, g2int *list) */ int g2c_get_pds_template_extension(int pds_template_num, int *template, - int *extlen, int *ext) + int *extlen, int *ext) { int j, t; @@ -853,5 +854,3 @@ g2c_get_pds_template(int pds_template_num, int *maplen, int *map, int *needext) /* If we didn't find a template, return an error. */ return G2C_ENOTEMPLATE; } - - diff --git a/src/pngpack.c b/src/pngpack.c index ceab7190..7bcf14e7 100644 --- a/src/pngpack.c +++ b/src/pngpack.c @@ -2,9 +2,9 @@ * @brief Pack data with PNG compression. * @author Stephen Gilbert @date 2003-08-27 */ -#include -#include #include "grib2_int.h" +#include +#include /** * Packs float or double data into PNG image @@ -50,11 +50,11 @@ * @author Ed Hartnett @date Aug 8, 2022 */ static int -pngpack_int(void *fld, int fld_is_double, g2int width, g2int height, g2int *idrstmpl, - unsigned char *cpack, g2int *lcpack, int verbose) +pngpack_int(void *fld, int fld_is_double, g2int width, g2int height, g2int *idrstmpl, + unsigned char *cpack, g2int *lcpack, int verbose) { g2int *ifld = NULL; - static float alog2 = ALOG2; /* ln(2.0) */ + static float alog2 = ALOG2; /* ln(2.0) */ g2int j, nbits, imin, imax, maxdif; g2int ndpts, nbytes; float bscale, dscale, rmax, rmin, temp; @@ -65,7 +65,7 @@ pngpack_int(void *fld, int fld_is_double, g2int width, g2int height, g2int *idrs int ret = G2C_NOERROR; LOG((2, "pngpack_int fld_is_double %d width %ld height %ld idrstmpl[1] %d", - fld_is_double, width, height, idrstmpl[1])); + fld_is_double, width, height, idrstmpl[1])); ndpts = width * height; bscale = int_power(2.0, -idrstmpl[1]); @@ -81,28 +81,28 @@ pngpack_int(void *fld, int fld_is_double, g2int width, g2int height, g2int *idrs rmin = ffld[0]; if (fld_is_double) { - for (j = 1; j < ndpts; j++) - { - if (dfld[j] > rmaxd) - rmaxd = dfld[j]; - if (dfld[j] < rmind) - rmind = dfld[j]; - } - maxdif = (g2int)rint((rmaxd - rmind) * dscale * bscale); + for (j = 1; j < ndpts; j++) + { + if (dfld[j] > rmaxd) + rmaxd = dfld[j]; + if (dfld[j] < rmind) + rmind = dfld[j]; + } + maxdif = (g2int)rint((rmaxd - rmind) * dscale * bscale); } else { - for (j = 1; j < ndpts; j++) - { - if (ffld[j] > rmax) - rmax = ffld[j]; - if (ffld[j] < rmin) - rmin = ffld[j]; - } - maxdif = (g2int)rint((rmax - rmin) * dscale * bscale); + for (j = 1; j < ndpts; j++) + { + if (ffld[j] > rmax) + rmax = ffld[j]; + if (ffld[j] < rmin) + rmin = ffld[j]; + } + maxdif = (g2int)rint((rmax - rmin) * dscale * bscale); } LOG((3, "rmax %g rmaxd %g rmin %g rmind %g", rmax, rmaxd, rmin, rmind)); - + /* If max and min values are not equal, pack up field. If they are * equal, we have a constant field, and the reference value (rmin) * is the value for each point in the field and set nbits to 0. */ @@ -122,59 +122,59 @@ pngpack_int(void *fld, int fld_is_double, g2int width, g2int height, g2int *idrs temp = log((double)(maxdif + 1)) / alog2; nbits = (g2int)ceil(temp); /* scale data */ - if (fld_is_double) - { - rmind = (float)imin; - for(j = 0; j < ndpts; j++) - ifld[j] = (g2int)rint(dfld[j] * dscale) - imin; - } - else - { - rmin = (float)imin; - for(j = 0; j < ndpts; j++) - ifld[j] = (g2int)rint(ffld[j] * dscale) - imin; - } + if (fld_is_double) + { + rmind = (float)imin; + for (j = 0; j < ndpts; j++) + ifld[j] = (g2int)rint(dfld[j] * dscale) - imin; + } + else + { + rmin = (float)imin; + for (j = 0; j < ndpts; j++) + ifld[j] = (g2int)rint(ffld[j] * dscale) - imin; + } } else { /* Use binary scaling factor and calculate minumum number * of bits in which the data will fit. */ - if (fld_is_double) - { - rmind = rmind * dscale; - rmaxd = rmaxd * dscale; - maxdif = (g2int)rint((rmaxd - rmind) * bscale); - } - else - { - rmin = rmin * dscale; - rmax = rmax * dscale; - maxdif = (g2int)rint((rmax - rmin) * bscale); - } + if (fld_is_double) + { + rmind = rmind * dscale; + rmaxd = rmaxd * dscale; + maxdif = (g2int)rint((rmaxd - rmind) * bscale); + } + else + { + rmin = rmin * dscale; + rmax = rmax * dscale; + maxdif = (g2int)rint((rmax - rmin) * bscale); + } temp = log((double)(maxdif + 1)) / alog2; nbits = (g2int)ceil(temp); /* scale data */ - if (fld_is_double) - { - for (j = 0; j < ndpts; j++) - ifld[j] = (g2int)rint(((dfld[j] * dscale) - rmind) * bscale); - } - else - { - for (j = 0; j < ndpts; j++) - ifld[j] = (g2int)rint(((ffld[j] * dscale) - rmin) * bscale); - } + if (fld_is_double) + { + for (j = 0; j < ndpts; j++) + ifld[j] = (g2int)rint(((dfld[j] * dscale) - rmind) * bscale); + } + else + { + for (j = 0; j < ndpts; j++) + ifld[j] = (g2int)rint(((ffld[j] * dscale) - rmin) * bscale); + } } /* Pack data into full octets, then do PNG encode and * calculate the length of the packed data in bytes. */ - if (nbits <= 8) + if (nbits <= 8) nbits = 8; - else if (nbits <= 16) + else if (nbits <= 16) nbits = 16; - else if (nbits <= 24) + else if (nbits <= 24) nbits = 24; - else + else nbits = 32; nbytes = (nbits / 8) * ndpts; @@ -183,11 +183,11 @@ pngpack_int(void *fld, int fld_is_double, g2int width, g2int height, g2int *idrs /* Encode data into PNG Format. */ if ((*lcpack = (g2int)enc_png(ctemp, width, height, nbits, cpack)) <= 0) - { - if (verbose) - printf("pngpack: ERROR Packing PNG = %d\n", (int)*lcpack); - ret = G2C_EPNG; - } + { + if (verbose) + printf("pngpack: ERROR Packing PNG = %d\n", (int)*lcpack); + ret = G2C_EPNG; + } free(ctemp); } else @@ -198,11 +198,11 @@ pngpack_int(void *fld, int fld_is_double, g2int width, g2int height, g2int *idrs /* Fill in ref value and number of bits in Template 5.0. */ if (fld_is_double) - rmin = (float)rmind; - mkieee(&rmin, idrstmpl, 1); /* ensure reference value is IEEE format */ + rmin = (float)rmind; + mkieee(&rmin, idrstmpl, 1); /* ensure reference value is IEEE format */ idrstmpl[3] = nbits; - idrstmpl[4] = 0; /* original data were reals */ - + idrstmpl[4] = 0; /* original data were reals */ + if (ifld) free(ifld); @@ -210,7 +210,7 @@ pngpack_int(void *fld, int fld_is_double, g2int width, g2int height, g2int *idrs } /** - * This subroutine packs up a float data field into PNG image format. + * This subroutine packs up a float data field into PNG image format. * * After the data field is scaled, and the reference value is * subtracted out, it is treated as a grayscale image and passed to a @@ -239,7 +239,7 @@ pngpack_int(void *fld, int fld_is_double, g2int width, g2int height, g2int *idrs * @author Ed Hartnett */ void -pngpack(float *fld, g2int width, g2int height, g2int *idrstmpl, +pngpack(float *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack) { /* Ignore the return value. */ @@ -247,7 +247,7 @@ pngpack(float *fld, g2int width, g2int height, g2int *idrstmpl, } /** - * This subroutine packs up a float data field into PNG image format. + * This subroutine packs up a float data field into PNG image format. * * After the data field is scaled, and the reference value is * subtracted out, it is treated as a grayscale image and passed to a @@ -279,13 +279,13 @@ pngpack(float *fld, g2int width, g2int height, g2int *idrstmpl, * @author Ed Hartnett */ int -g2c_pngpackf(float *fld, size_t width, size_t height, int *idrstmpl, +g2c_pngpackf(float *fld, size_t width, size_t height, int *idrstmpl, unsigned char *cpack, int *lcpack) { g2int width8 = width, height8 = height, lcpack8 = *lcpack; g2int idrstmpl8[G2C_PNG_DRS_TEMPLATE_LEN]; int i, ret; - + for (i = 0; i < G2C_PNG_DRS_TEMPLATE_LEN; i++) idrstmpl8[i] = idrstmpl[i]; @@ -301,7 +301,7 @@ g2c_pngpackf(float *fld, size_t width, size_t height, int *idrstmpl, } /** - * This subroutine packs up a double data field into PNG image format. + * This subroutine packs up a double data field into PNG image format. * * After the data field is scaled, and the reference value is * subtracted out, it is treated as a grayscale image and passed to a @@ -333,13 +333,13 @@ g2c_pngpackf(float *fld, size_t width, size_t height, int *idrstmpl, * @author Ed Hartnett @date Aug 8, 2022 */ int -g2c_pngpackd(double *fld, size_t width, size_t height, int *idrstmpl, +g2c_pngpackd(double *fld, size_t width, size_t height, int *idrstmpl, unsigned char *cpack, int *lcpack) { g2int width8 = width, height8 = height, lcpack8 = *lcpack; g2int idrstmpl8[G2C_PNG_DRS_TEMPLATE_LEN]; int i, ret; - + for (i = 0; i < G2C_PNG_DRS_TEMPLATE_LEN; i++) idrstmpl8[i] = idrstmpl[i]; @@ -353,4 +353,3 @@ g2c_pngpackd(double *fld, size_t width, size_t height, int *idrstmpl, } return ret; } - diff --git a/src/pngunpack.c b/src/pngunpack.c index 49ff8065..1577bc81 100644 --- a/src/pngunpack.c +++ b/src/pngunpack.c @@ -3,9 +3,9 @@ * @author Stephen Gilbert @date 2003-08-27 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /** * Unpack a data field that was packed into a PNG @@ -38,7 +38,7 @@ */ static int pngunpack_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, nbits, width, height; @@ -54,7 +54,7 @@ pngunpack_int(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, dscale = int_power(10.0, -idrstmpl[2]); nbits = idrstmpl[3]; LOG((2, "bscale %g dscale %g nbits %ld", bscale, dscale, nbits)); - + /* If nbits equals 0, we have a constant field where the reference * value is the data value at each gridpoint. */ if (nbits != 0) @@ -63,31 +63,31 @@ pngunpack_int(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, ctemp = calloc(ndpts * 4, 1); if (!ifld || !ctemp) { - if (verbose) - fprintf(stderr,"Could not allocate space in jpcunpack.\n Data field NOT upacked.\n"); + if (verbose) + fprintf(stderr, "Could not allocate space in jpcunpack.\n Data field NOT upacked.\n"); return G2C_ENOMEM; } dec_png(cpack, &width, &height, ctemp); gbits(ctemp, ifld, 0, nbits, 0, ndpts); for (j = 0; j < ndpts; j++) - { - if (fld_is_double) - dfld[j] = (((double)ifld[j] * bscale) + ref) * dscale; - else - ffld[j] = (((float)ifld[j] * bscale) + ref) * dscale; - } + { + if (fld_is_double) + dfld[j] = (((double)ifld[j] * bscale) + ref) * dscale; + else + ffld[j] = (((float)ifld[j] * bscale) + ref) * dscale; + } free(ctemp); free(ifld); } else { for (j = 0; j < ndpts; j++) - { - if (fld_is_double) - dfld[j] = ref; - else - ffld[j] = ref; - } + { + if (fld_is_double) + dfld[j] = ref; + else + ffld[j] = ref; + } } return 0; @@ -117,9 +117,9 @@ pngunpack(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, float *fld) { int ret; - + if ((ret = pngunpack_int(cpack, len, idrstmpl, ndpts, fld, 0, 1)) == G2C_ENOMEM) - return G2_JPCUNPACK_MEM; + return G2_JPCUNPACK_MEM; return ret; } @@ -140,19 +140,19 @@ pngunpack(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, * - ::G2C_NOERROR No Error. * - ::G2C_ENOMEM Out of memory. * - * @author Ed Hartnett @date Sep 8, 2022 + * @author Ed Hartnett @date Sep 8, 2022 */ int g2c_pngunpackf(unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts, - float *fld) + float *fld) { g2int idrstmpl8[G2C_PNG_DRS_TEMPLATE_LEN]; g2int len8 = len, ndpts8 = ndpts; int i; - + for (i = 0; i < G2C_PNG_DRS_TEMPLATE_LEN; i++) idrstmpl8[i] = idrstmpl[i]; - + return pngunpack_int(cpack, len8, idrstmpl8, ndpts8, fld, 0, 0); } @@ -176,14 +176,14 @@ g2c_pngunpackf(unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts, */ int g2c_pngunpackd(unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts, - double *fld) + double *fld) { g2int idrstmpl8[G2C_PNG_DRS_TEMPLATE_LEN]; g2int len8 = len, ndpts8 = ndpts; int i; - + for (i = 0; i < G2C_PNG_DRS_TEMPLATE_LEN; i++) idrstmpl8[i] = idrstmpl[i]; - + return pngunpack_int(cpack, len8, idrstmpl8, ndpts8, fld, 1, 0); } diff --git a/src/rdieee.c b/src/rdieee.c index 1b27b381..8ef1199c 100644 --- a/src/rdieee.c +++ b/src/rdieee.c @@ -20,29 +20,29 @@ void rdieee(g2int *rieee, float *a, g2int num) { - g2int j; - g2int isign,iexp,imant; + g2int j; + g2int isign, iexp, imant; - float sign,temp; - static float two23,two126; + float sign, temp; + static float two23, two126; static g2int test = 0; - uint64_t msk1 = 0x80000000; /* 10000000000000000000000000000000 binary */ - g2int msk2 = 0x7F800000; /* 01111111100000000000000000000000 binary */ - g2int msk3 = 0x007FFFFF; /* 00000000011111111111111111111111 binary */ + uint64_t msk1 = 0x80000000; /* 10000000000000000000000000000000 binary */ + g2int msk2 = 0x7F800000; /* 01111111100000000000000000000000 binary */ + g2int msk3 = 0x007FFFFF; /* 00000000011111111111111111111111 binary */ if (test == 0) { - two23 = (float)int_power(2.0,-23); - two126 = (float)int_power(2.0,-126); + two23 = (float)int_power(2.0, -23); + two126 = (float)int_power(2.0, -126); test = 1; } for (j = 0; j < num; j++) { /* Extract sign bit, exponent, and mantissa */ - isign = (rieee[j]&msk1)>>31; - iexp = (rieee[j]&msk2)>>23; - imant = (rieee[j]&msk3); + isign = (rieee[j] & msk1) >> 31; + iexp = (rieee[j] & msk2) >> 23; + imant = (rieee[j] & msk3); /*printf("SAGieee= %ld %ld %ld\n",isign,iexp,imant); */ sign = 1.0; @@ -60,10 +60,8 @@ rdieee(g2int *rieee, float *a, g2int num) a[j] = sign * two126 * two23 * (float)imant; else a[j] = sign * 0.0; - } else if (iexp == 255) a[j] = sign * (1E+37); - } } diff --git a/src/reduce.c b/src/reduce.c index b0730d9e..a9aad75b 100644 --- a/src/reduce.c +++ b/src/reduce.c @@ -1,15 +1,15 @@ -/** +/** * @file * @brief Determines whether the number of groups should be increased * in order to reduce the size of the large groups, and to make that * adjustment. * - * @author Harry Glahn, The Meteorological Development Lab (MDL) + * @author Harry Glahn, The Meteorological Development Lab (MDL) * @date November 2001 */ -#include #include "grib2_int.h" +#include /** * Determines whether the number of groups should be increased in @@ -81,7 +81,7 @@ * for the group values. (internal) * * - * @author Harry Glahn, The Meteorological Development Lab (MDL) + * @author Harry Glahn, The Meteorological Development Lab (MDL) * @date November 2001 */ int @@ -107,9 +107,9 @@ reduce(g2int *kfildo, g2int *jmin, g2int *jmax, ntotbt[31], ntotpr, newboxt; g2int *newbox, *newboxp; -/* NEWBOX() AND NEWBOXP() were AUTOMATIC ARRAYS. */ - newbox = (g2int *)calloc(*ndg,sizeof(g2int)); - newboxp = (g2int *)calloc(*ndg,sizeof(g2int)); + /* NEWBOX() AND NEWBOXP() were AUTOMATIC ARRAYS. */ + newbox = (g2int *)calloc(*ndg, sizeof(g2int)); + newboxp = (g2int *)calloc(*ndg, sizeof(g2int)); /* Parameter adjustments */ --nov; @@ -120,97 +120,107 @@ reduce(g2int *kfildo, g2int *jmin, g2int *jmax, /* Function Body */ *ier = 0; - if (*lx == 1) { + if (*lx == 1) + { goto L410; } -/* IF THERE IS ONLY ONE GROUP, RETURN. */ + /* IF THERE IS ONLY ONE GROUP, RETURN. */ - *(unsigned char *)cfeed = (char) ifeed; + *(unsigned char *)cfeed = (char)ifeed; -/* INITIALIZE NUMBER OF NEW BOXES PER GROUP TO ZERO. */ + /* INITIALIZE NUMBER OF NEW BOXES PER GROUP TO ZERO. */ i__1 = *lx; - for (l = 1; l <= i__1; ++l) { + for (l = 1; l <= i__1; ++l) + { newbox[l - 1] = 0; -/* L110: */ + /* L110: */ } -/* INITIALIZE NUMBER OF TOTAL NEW BOXES PER J TO ZERO. */ + /* INITIALIZE NUMBER OF TOTAL NEW BOXES PER J TO ZERO. */ - for (j = 1; j <= 31; ++j) { + for (j = 1; j <= 31; ++j) + { ntotbt[j - 1] = 999999999; /* nboxj[j - 1] = 0; */ -/* L112: */ + /* L112: */ } iorigb = (*ibit + *jbit + *kbit) * *lx; -/* IBIT = BITS TO PACK THE JMIN(). */ -/* JBIT = BITS TO PACK THE LBIT(). */ -/* KBIT = BITS TO PACK THE NOV(). */ -/* LX = NUMBER OF GROUPS. */ + /* IBIT = BITS TO PACK THE JMIN(). */ + /* JBIT = BITS TO PACK THE LBIT(). */ + /* KBIT = BITS TO PACK THE NOV(). */ + /* LX = NUMBER OF GROUPS. */ ntotbt[*kbit - 1] = iorigb; -/* THIS IS THE VALUE OF TOTAL BITS FOR THE ORIGINAL LX */ -/* GROUPS, WHICH REQUIRES KBITS TO PACK THE GROUP */ -/* LENGHTS. SETTING THIS HERE MAKES ONE LESS LOOPS */ -/* NECESSARY BELOW. */ + /* THIS IS THE VALUE OF TOTAL BITS FOR THE ORIGINAL LX */ + /* GROUPS, WHICH REQUIRES KBITS TO PACK THE GROUP */ + /* LENGHTS. SETTING THIS HERE MAKES ONE LESS LOOPS */ + /* NECESSARY BELOW. */ -/* COMPUTE BITS NOW USED FOR THE PARAMETERS DEFINED. */ + /* COMPUTE BITS NOW USED FOR THE PARAMETERS DEFINED. */ -/* DETERMINE OTHER POSSIBILITES BY INCREASING LX AND DECREASING */ -/* NOV() WITH VALUES GREATER THAN THRESHOLDS. ASSUME A GROUP IS */ -/* SPLIT INTO 2 OR MORE GROUPS SO THAT KBIT IS REDUCED WITHOUT */ -/* CHANGING IBIT OR JBIT. */ + /* DETERMINE OTHER POSSIBILITES BY INCREASING LX AND DECREASING */ + /* NOV() WITH VALUES GREATER THAN THRESHOLDS. ASSUME A GROUP IS */ + /* SPLIT INTO 2 OR MORE GROUPS SO THAT KBIT IS REDUCED WITHOUT */ + /* CHANGING IBIT OR JBIT. */ jj = 0; -/* Computing MIN */ + /* Computing MIN */ i__1 = 30, i__2 = *kbit - 1; /*for (j = min(i__1,i__2); j >= 2; --j) {*/ - for (j = (i__1 < i__2) ? i__1 : i__2; j >= 2; --j) { -/* VALUES GE KBIT WILL NOT REQUIRE SPLITS. ONCE THE TOTAL */ -/* BITS START INCREASING WITH DECREASING J, STOP. ALSO, THE */ -/* NUMBER OF BITS REQUIRED IS KNOWN FOR KBITS = NTOTBT(KBIT). */ + for (j = (i__1 < i__2) ? i__1 : i__2; j >= 2; --j) + { + /* VALUES GE KBIT WILL NOT REQUIRE SPLITS. ONCE THE TOTAL */ + /* BITS START INCREASING WITH DECREASING J, STOP. ALSO, THE */ + /* NUMBER OF BITS REQUIRED IS KNOWN FOR KBITS = NTOTBT(KBIT). */ newboxt = 0; i__1 = *lx; - for (l = 1; l <= i__1; ++l) { + for (l = 1; l <= i__1; ++l) + { - if (nov[l] < ibxx2[j]) { + if (nov[l] < ibxx2[j]) + { newbox[l - 1] = 0; -/* NO SPLITS OR NEW BOXES. */ + /* NO SPLITS OR NEW BOXES. */ goto L190; - } else { + } + else + { novl = nov[l]; m = (nov[l] - 1) / (ibxx2[j] - 1) + 1; -/* M IS FOUND BY SOLVING THE EQUATION BELOW FOR M: */ -/* (NOV(L)+M-1)/M LT IBXX2(J) */ -/* M GT (NOV(L)-1)/(IBXX2(J)-1) */ -/* SET M = (NOV(L)-1)/(IBXX2(J)-1)+1 */ + /* M IS FOUND BY SOLVING THE EQUATION BELOW FOR M: */ + /* (NOV(L)+M-1)/M LT IBXX2(J) */ + /* M GT (NOV(L)-1)/(IBXX2(J)-1) */ + /* SET M = (NOV(L)-1)/(IBXX2(J)-1)+1 */ L130: novl = (nov[l] + m - 1) / m; -/* THE +M-1 IS NECESSARY. FOR INSTANCE, 15 WILL FIT */ -/* INTO A BOX 4 BITS WIDE, BUT WON'T DIVIDE INTO */ -/* TWO BOXES 3 BITS WIDE EACH. */ + /* THE +M-1 IS NECESSARY. FOR INSTANCE, 15 WILL FIT */ + /* INTO A BOX 4 BITS WIDE, BUT WON'T DIVIDE INTO */ + /* TWO BOXES 3 BITS WIDE EACH. */ - if (novl < ibxx2[j]) { + if (novl < ibxx2[j]) + { goto L185; - } else { + } + else + { ++m; -/* *** WRITE(KFILDO,135)L,NOV(L),NOVL,M,J,IBXX2(J) */ -/* *** 135 FORMAT(/' AT 135--L,NOV(L),NOVL,M,J,IBXX2(J)',6I10) */ + /* *** WRITE(KFILDO,135)L,NOV(L),NOVL,M,J,IBXX2(J) */ + /* *** 135 FORMAT(/' AT 135--L,NOV(L),NOVL,M,J,IBXX2(J)',6I10) */ goto L130; } -/* THE ABOVE DO LOOP WILL NEVER COMPLETE. */ + /* THE ABOVE DO LOOP WILL NEVER COMPLETE. */ } L185: newbox[l - 1] = m - 1; newboxt = newboxt + m - 1; - L190: - ; + L190:; } /* nboxj[j - 1] = newboxt; */ @@ -218,141 +228,154 @@ reduce(g2int *kfildo, g2int *jmin, g2int *jmax, ntotbt[j - 1] = (*ibit + *jbit) * (*lx + newboxt) + j * (*lx + newboxt); - if (ntotbt[j - 1] >= ntotpr) { + if (ntotbt[j - 1] >= ntotpr) + { jj = j + 1; -/* THE PLUS IS USED BECAUSE J DECREASES PER ITERATION. */ + /* THE PLUS IS USED BECAUSE J DECREASES PER ITERATION. */ goto L250; - } else { + } + else + { -/* SAVE THE TOTAL NEW BOXES AND NEWBOX() IN CASE THIS */ -/* IS THE J TO USE. */ + /* SAVE THE TOTAL NEW BOXES AND NEWBOX() IN CASE THIS */ + /* IS THE J TO USE. */ newboxtp = newboxt; i__1 = *lx; - for (l = 1; l <= i__1; ++l) { + for (l = 1; l <= i__1; ++l) + { newboxp[l - 1] = newbox[l - 1]; -/* L195: */ + /* L195: */ } -/* WRITE(KFILDO,197)NEWBOXT,IBXX2(J) */ -/* 197 FORMAT(/' *****************************************' */ -/* 1 /' THE NUMBER OF NEWBOXES PER GROUP OF THE TOTAL', */ -/* 2 I10,' FOR GROUP MAXSIZE PLUS 1 ='I10 */ -/* 3 /' *****************************************') */ -/* WRITE(KFILDO,198) (NEWBOX(L),L=1,LX) */ -/* 198 FORMAT(/' '20I6/(' '20I6)) */ + /* WRITE(KFILDO,197)NEWBOXT,IBXX2(J) */ + /* 197 FORMAT(/' *****************************************' */ + /* 1 /' THE NUMBER OF NEWBOXES PER GROUP OF THE TOTAL', */ + /* 2 I10,' FOR GROUP MAXSIZE PLUS 1 ='I10 */ + /* 3 /' *****************************************') */ + /* WRITE(KFILDO,198) (NEWBOX(L),L=1,LX) */ + /* 198 FORMAT(/' '20I6/(' '20I6)) */ } -/* 205 WRITE(KFILDO,209)KBIT,IORIGB */ -/* 209 FORMAT(/' ORIGINAL BITS WITH KBIT OF',I5,' =',I10) */ -/* WRITE(KFILDO,210)(N,N=2,10),(IBXX2(N),N=2,10), */ -/* 1 (NTOTBT(N),N=2,10),(NBOXJ(N),N=2,10), */ -/* 2 (N,N=11,20),(IBXX2(N),N=11,20), */ -/* 3 (NTOTBT(N),N=11,20),(NBOXJ(N),N=11,20), */ -/* 4 (N,N=21,30),(IBXX2(N),N=11,20), */ -/* 5 (NTOTBT(N),N=21,30),(NBOXJ(N),N=21,30) */ -/* 210 FORMAT(/' THE TOTAL BYTES FOR MAXIMUM GROUP LENGTHS BY ROW'// */ -/* 1 ' J = THE NUMBER OF BITS PER GROUP LENGTH'/ */ -/* 2 ' IBXX2(J) = THE MAXIMUM GROUP LENGTH PLUS 1 FOR THIS J'/ */ -/* 3 ' NTOTBT(J) = THE TOTAL BITS FOR THIS J'/ */ -/* 4 ' NBOXJ(J) = THE NEW GROUPS FOR THIS J'/ */ -/* 5 4(/10X,9I10)/4(/10I10)/4(/10I10)) */ - -/* L200: */ + /* 205 WRITE(KFILDO,209)KBIT,IORIGB */ + /* 209 FORMAT(/' ORIGINAL BITS WITH KBIT OF',I5,' =',I10) */ + /* WRITE(KFILDO,210)(N,N=2,10),(IBXX2(N),N=2,10), */ + /* 1 (NTOTBT(N),N=2,10),(NBOXJ(N),N=2,10), */ + /* 2 (N,N=11,20),(IBXX2(N),N=11,20), */ + /* 3 (NTOTBT(N),N=11,20),(NBOXJ(N),N=11,20), */ + /* 4 (N,N=21,30),(IBXX2(N),N=11,20), */ + /* 5 (NTOTBT(N),N=21,30),(NBOXJ(N),N=21,30) */ + /* 210 FORMAT(/' THE TOTAL BYTES FOR MAXIMUM GROUP LENGTHS BY ROW'// */ + /* 1 ' J = THE NUMBER OF BITS PER GROUP LENGTH'/ */ + /* 2 ' IBXX2(J) = THE MAXIMUM GROUP LENGTH PLUS 1 FOR THIS J'/ */ + /* 3 ' NTOTBT(J) = THE TOTAL BITS FOR THIS J'/ */ + /* 4 ' NBOXJ(J) = THE NEW GROUPS FOR THIS J'/ */ + /* 5 4(/10X,9I10)/4(/10I10)/4(/10I10)) */ + + /* L200: */ } L250: - pimp = (iorigb - ntotbt[jj - 1]) / (float) iorigb * 100.f; -/* WRITE(KFILDO,252)PIMP,KBIT,JJ */ -/* 252 FORMAT(/' PERCENT IMPROVEMENT =',F6.1, */ -/* 1 ' BY DECREASING GROUP LENGTHS FROM',I4,' TO',I4,' BITS') */ - if (pimp >= 2.f) { - -/* WRITE(KFILDO,255)CFEED,NEWBOXTP,IBXX2(JJ) */ -/* 255 FORMAT(A1,/' *****************************************' */ -/* 1 /' THE NUMBER OF NEWBOXES PER GROUP OF THE TOTAL', */ -/* 2 I10,' FOR GROUP MAXSIZE PLUS 1 ='I10 */ -/* 2 /' *****************************************') */ -/* WRITE(KFILDO,256) (NEWBOXP(L),L=1,LX) */ -/* 256 FORMAT(/' '20I6) */ - -/* ADJUST GROUP LENGTHS FOR MAXIMUM LENGTH OF JJ BITS. */ -/* THE MIN PER GROUP AND THE NUMBER OF BITS REQUIRED */ -/* PER GROUP ARE NOT CHANGED. THIS MAY MEAN THAT A */ -/* GROUP HAS A MIN (OR REFERENCE) THAT IS NOT ZERO. */ -/* THIS SHOULD NOT MATTER TO THE UNPACKER. */ + pimp = (iorigb - ntotbt[jj - 1]) / (float)iorigb * 100.f; + /* WRITE(KFILDO,252)PIMP,KBIT,JJ */ + /* 252 FORMAT(/' PERCENT IMPROVEMENT =',F6.1, */ + /* 1 ' BY DECREASING GROUP LENGTHS FROM',I4,' TO',I4,' BITS') */ + if (pimp >= 2.f) + { + + /* WRITE(KFILDO,255)CFEED,NEWBOXTP,IBXX2(JJ) */ + /* 255 FORMAT(A1,/' *****************************************' */ + /* 1 /' THE NUMBER OF NEWBOXES PER GROUP OF THE TOTAL', */ + /* 2 I10,' FOR GROUP MAXSIZE PLUS 1 ='I10 */ + /* 2 /' *****************************************') */ + /* WRITE(KFILDO,256) (NEWBOXP(L),L=1,LX) */ + /* 256 FORMAT(/' '20I6) */ + + /* ADJUST GROUP LENGTHS FOR MAXIMUM LENGTH OF JJ BITS. */ + /* THE MIN PER GROUP AND THE NUMBER OF BITS REQUIRED */ + /* PER GROUP ARE NOT CHANGED. THIS MAY MEAN THAT A */ + /* GROUP HAS A MIN (OR REFERENCE) THAT IS NOT ZERO. */ + /* THIS SHOULD NOT MATTER TO THE UNPACKER. */ lxnkp = *lx + newboxtp; -/* LXNKP = THE NEW NUMBER OF BOXES */ - - if (lxnkp > *ndg) { -/* DIMENSIONS NOT LARGE ENOUGH. PROBABLY AN ERROR */ -/* OF SOME SORT. ABORT. */ -/* WRITE(KFILDO,257)NDG,LXNPK */ -/* 1 2 3 4 5 6 7 X */ -/* 257 FORMAT(/' DIMENSIONS OF JMIN, ETC. IN REDUCE =',I8, */ -/* 1 ' NOT LARGE ENOUGH FOR THE EXPANDED NUMBER OF', */ -/* 2 ' GROUPS =',I8,'. ABORT REDUCE.') */ + /* LXNKP = THE NEW NUMBER OF BOXES */ + + if (lxnkp > *ndg) + { + /* DIMENSIONS NOT LARGE ENOUGH. PROBABLY AN ERROR */ + /* OF SOME SORT. ABORT. */ + /* WRITE(KFILDO,257)NDG,LXNPK */ + /* 1 2 3 4 5 6 7 X */ + /* 257 FORMAT(/' DIMENSIONS OF JMIN, ETC. IN REDUCE =',I8, */ + /* 1 ' NOT LARGE ENOUGH FOR THE EXPANDED NUMBER OF', */ + /* 2 ' GROUPS =',I8,'. ABORT REDUCE.') */ *ier = 715; goto L410; -/* AN ABORT CAUSES THE CALLING PROGRAM TO REEXECUTE */ -/* WITHOUT CALLING REDUCE. */ + /* AN ABORT CAUSES THE CALLING PROGRAM TO REEXECUTE */ + /* WITHOUT CALLING REDUCE. */ } lxn = lxnkp; -/* LXN IS THE NUMBER OF THE BOX IN THE NEW SERIES BEING */ -/* FILLED. IT DECREASES PER ITERATION. */ + /* LXN IS THE NUMBER OF THE BOX IN THE NEW SERIES BEING */ + /* FILLED. IT DECREASES PER ITERATION. */ ibxx2m1 = ibxx2[jj] - 1; -/* IBXX2M1 IS THE MAXIMUM NUMBER OF VALUES PER GROUP. */ + /* IBXX2M1 IS THE MAXIMUM NUMBER OF VALUES PER GROUP. */ - for (l = *lx; l >= 1; --l) { + for (l = *lx; l >= 1; --l) + { -/* THE VALUES IS NOV() REPRESENT THOSE VALUES + NOVREF. */ -/* WHEN VALUES ARE MOVED TO ANOTHER BOX, EACH VALUE */ -/* MOVED TO A NEW BOX REPRESENTS THAT VALUE + NOVREF. */ -/* THIS HAS TO BE CONSIDERED IN MOVING VALUES. */ + /* THE VALUES IS NOV() REPRESENT THOSE VALUES + NOVREF. */ + /* WHEN VALUES ARE MOVED TO ANOTHER BOX, EACH VALUE */ + /* MOVED TO A NEW BOX REPRESENTS THAT VALUE + NOVREF. */ + /* THIS HAS TO BE CONSIDERED IN MOVING VALUES. */ - if (newboxp[l - 1] * (ibxx2m1 + *novref) + *novref > nov[l] + * - novref) { -/* IF THE ABOVE TEST IS MET, THEN MOVING IBXX2M1 VALUES */ -/* FOR ALL NEW BOXES WILL LEAVE A NEGATIVE NUMBER FOR */ -/* THE LAST BOX. NOT A TOLERABLE SITUATION. */ + if (newboxp[l - 1] * (ibxx2m1 + *novref) + *novref > nov[l] + *novref) + { + /* IF THE ABOVE TEST IS MET, THEN MOVING IBXX2M1 VALUES */ + /* FOR ALL NEW BOXES WILL LEAVE A NEGATIVE NUMBER FOR */ + /* THE LAST BOX. NOT A TOLERABLE SITUATION. */ movmin = (nov[l] - newboxp[l - 1] * *novref) / newboxp[l - 1]; left = nov[l]; -/* LEFT = THE NUMBER OF VALUES TO MOVE FROM THE ORIGINAL */ -/* BOX TO EACH NEW BOX EXCEPT THE LAST. LEFT IS THE */ -/* NUMBER LEFT TO MOVE. */ - } else { + /* LEFT = THE NUMBER OF VALUES TO MOVE FROM THE ORIGINAL */ + /* BOX TO EACH NEW BOX EXCEPT THE LAST. LEFT IS THE */ + /* NUMBER LEFT TO MOVE. */ + } + else + { movmin = ibxx2m1; -/* MOVMIN VALUES CAN BE MOVED FOR EACH NEW BOX. */ + /* MOVMIN VALUES CAN BE MOVED FOR EACH NEW BOX. */ left = nov[l]; -/* LEFT IS THE NUMBER OF VALUES LEFT TO MOVE. */ + /* LEFT IS THE NUMBER OF VALUES LEFT TO MOVE. */ } - if (newboxp[l - 1] > 0) { + if (newboxp[l - 1] > 0) + { if ((movmin + *novref) * newboxp[l - 1] + *novref <= nov[l] + - *novref && (movmin + *novref) * (newboxp[l - 1] + 1) - >= nov[l] + *novref) { + *novref && + (movmin + *novref) * (newboxp[l - 1] + 1) >= nov[l] + *novref) + { goto L288; - } else { -/* ***D WRITE(KFILDO,287)L,MOVMIN,NOVREF,NEWBOXP(L),NOV(L) */ -/* ***D287 FORMAT(/' AT 287 IN REDUCE--L,MOVMIN,NOVREF,', */ -/* ***D 1 'NEWBOXP(L),NOV(L)',5I12 */ -/* ***D 2 ' REDUCE ABORTED.') */ -/* WRITE(KFILDO,2870) */ -/* 2870 FORMAT(/' AN ERROR IN REDUCE ALGORITHM. ABORT REDUCE.') */ + } + else + { + /* ***D WRITE(KFILDO,287)L,MOVMIN,NOVREF,NEWBOXP(L),NOV(L) */ + /* ***D287 FORMAT(/' AT 287 IN REDUCE--L,MOVMIN,NOVREF,', */ + /* ***D 1 'NEWBOXP(L),NOV(L)',5I12 */ + /* ***D 2 ' REDUCE ABORTED.') */ + /* WRITE(KFILDO,2870) */ + /* 2870 FORMAT(/' AN ERROR IN REDUCE ALGORITHM. ABORT REDUCE.') */ *ier = 714; goto L410; -/* AN ABORT CAUSES THE CALLING PROGRAM TO REEXECUTE */ -/* WITHOUT CALLING REDUCE. */ + /* AN ABORT CAUSES THE CALLING PROGRAM TO REEXECUTE */ + /* WITHOUT CALLING REDUCE. */ } - } L288: i__1 = newboxp[l - 1] + 1; - for (j = 1; j <= i__1; ++j) { + for (j = 1; j <= i__1; ++j) + { /*move = min(movmin,left);*/ move = (movmin < left) ? movmin : left; jmin[lxn] = jmin[l]; @@ -361,42 +384,43 @@ reduce(g2int *kfildo, g2int *jmin, g2int *jmax, nov[lxn] = move; --lxn; left -= move + *novref; -/* THE MOVE OF MOVE VALUES REALLY REPRESENTS A MOVE OF */ -/* MOVE + NOVREF VALUES. */ -/* L290: */ + /* THE MOVE OF MOVE VALUES REALLY REPRESENTS A MOVE OF */ + /* MOVE + NOVREF VALUES. */ + /* L290: */ } - if (left != -(*novref)) { -/* *** WRITE(KFILDO,292)L,LXN,MOVE,LXNKP,IBXX2(JJ),LEFT,NOV(L), */ -/* *** 1 MOVMIN */ -/* *** 292 FORMAT(' AT 292 IN REDUCE--L,LXN,MOVE,LXNKP,', */ -/* *** 1 'IBXX2(JJ),LEFT,NOV(L),MOVMIN'/8I12) */ + if (left != -(*novref)) + { + /* *** WRITE(KFILDO,292)L,LXN,MOVE,LXNKP,IBXX2(JJ),LEFT,NOV(L), */ + /* *** 1 MOVMIN */ + /* *** 292 FORMAT(' AT 292 IN REDUCE--L,LXN,MOVE,LXNKP,', */ + /* *** 1 'IBXX2(JJ),LEFT,NOV(L),MOVMIN'/8I12) */ } -/* L300: */ + /* L300: */ } *lx = lxnkp; -/* LX IS NOW THE NEW NUMBER OF GROUPS. */ + /* LX IS NOW THE NEW NUMBER OF GROUPS. */ *kbit = jj; -/* KBIT IS NOW THE NEW NUMBER OF BITS REQUIRED FOR PACKING */ -/* GROUP LENGHTS. */ + /* KBIT IS NOW THE NEW NUMBER OF BITS REQUIRED FOR PACKING */ + /* GROUP LENGHTS. */ } -/* WRITE(KFILDO,406)CFEED,LX */ -/* 406 FORMAT(A1,/' *****************************************' */ -/* 1 /' THE GROUP SIZES NOV() AFTER REDUCTION IN SIZE', */ -/* 2 ' FOR'I10,' GROUPS', */ -/* 3 /' *****************************************') */ -/* WRITE(KFILDO,407) (NOV(J),J=1,LX) */ -/* 407 FORMAT(/' '20I6) */ -/* WRITE(KFILDO,408)CFEED,LX */ -/* 408 FORMAT(A1,/' *****************************************' */ -/* 1 /' THE GROUP MINIMA JMIN() AFTER REDUCTION IN SIZE', */ -/* 2 ' FOR'I10,' GROUPS', */ -/* 3 /' *****************************************') */ -/* WRITE(KFILDO,409) (JMIN(J),J=1,LX) */ -/* 409 FORMAT(/' '20I6) */ + /* WRITE(KFILDO,406)CFEED,LX */ + /* 406 FORMAT(A1,/' *****************************************' */ + /* 1 /' THE GROUP SIZES NOV() AFTER REDUCTION IN SIZE', */ + /* 2 ' FOR'I10,' GROUPS', */ + /* 3 /' *****************************************') */ + /* WRITE(KFILDO,407) (NOV(J),J=1,LX) */ + /* 407 FORMAT(/' '20I6) */ + /* WRITE(KFILDO,408)CFEED,LX */ + /* 408 FORMAT(A1,/' *****************************************' */ + /* 1 /' THE GROUP MINIMA JMIN() AFTER REDUCTION IN SIZE', */ + /* 2 ' FOR'I10,' GROUPS', */ + /* 3 /' *****************************************') */ + /* WRITE(KFILDO,409) (JMIN(J),J=1,LX) */ + /* 409 FORMAT(/' '20I6) */ L410: if (newbox) diff --git a/src/seekgb.c b/src/seekgb.c index 4f933129..eeb9e9f3 100644 --- a/src/seekgb.c +++ b/src/seekgb.c @@ -10,12 +10,12 @@ * 2022-09-11 | Hartnett | Added g2c_seekgb() function. * */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /** - * Search a file for the next GRIB Message. + * Search a file for the next GRIB Message. * * The search is done starting at byte offset iseek of the file * referenced by lugb for mseek bytes at a time. If found, the @@ -49,9 +49,8 @@ seekgb(FILE *lugb, g2int iseek, g2int mseek, g2int *lskip, g2int *lgrib) int end; unsigned char *cbuf; - LOG((3, "seekgb iseek %ld mseek %ld", iseek, mseek)); - + *lgrib = 0; cbuf = (unsigned char *)malloc(mseek); nread = mseek; @@ -83,19 +82,19 @@ seekgb(FILE *lugb, g2int iseek, g2int mseek, g2int *lskip, g2int *lgrib) gbit(cbuf, &lengrib, (k + 4) * BYTE, 3 * BYTE); if (vers == 2) gbit(cbuf, &lengrib, (k + 12) * BYTE, 4 * BYTE); - LOG((4, "lengrib %ld", lengrib)); + LOG((4, "lengrib %ld", lengrib)); /* Read the last 4 bytesof the message. */ fseek(lugb, ipos + k + lengrib - 4, SEEK_SET); k4 = fread(&end, 4, 1, lugb); - + /* Look for '7777' at end of grib message. */ if (k4 == 1 && end == 926365495) { /* GRIB message found. */ *lskip = ipos + k; *lgrib = lengrib; - LOG((4, "found end of message lengrib %ld", lengrib)); + LOG((4, "found end of message lengrib %ld", lengrib)); break; } } diff --git a/src/simpack.c b/src/simpack.c index 094648c1..38d06812 100644 --- a/src/simpack.c +++ b/src/simpack.c @@ -3,13 +3,13 @@ * @author Stephen Gilbert @date 2002-11-06 */ -#include -#include #include "grib2_int.h" +#include +#include /** * Packs a data field using the simple packing - * algorithm. + * algorithm. * * This function also fills in GRIB2 Data Representation Template 5.0 * with the appropriate values. @@ -33,15 +33,15 @@ * @author Stephen Gilbert @date 2002-11-06 */ void -simpack(float *fld, g2int ndpts, g2int *idrstmpl, - unsigned char *cpack, g2int *lcpack) +simpack(float *fld, g2int ndpts, g2int *idrstmpl, + unsigned char *cpack, g2int *lcpack) { static g2int zero = 0; g2int *ifld; g2int j, nbits, imin, imax, maxdif, nbittot, left; float bscale, dscale, rmax, rmin, temp; double maxnum; - static float alog2 = ALOG2; /* ln(2.0) */ + static float alog2 = ALOG2; /* ln(2.0) */ LOG((3, "simpack ndpts %ld", ndpts)); @@ -55,11 +55,12 @@ simpack(float *fld, g2int ndpts, g2int *idrstmpl, /* Find max and min values in the data. */ rmax = fld[0]; rmin = fld[0]; - for (j = 1; j < ndpts; j++) { + for (j = 1; j < ndpts; j++) + { if (fld[j] > rmax) - rmax = fld[j]; + rmax = fld[j]; if (fld[j] < rmin) - rmin = fld[j]; + rmin = fld[j]; } ifld = calloc(ndpts, sizeof(g2int)); @@ -67,11 +68,13 @@ simpack(float *fld, g2int ndpts, g2int *idrstmpl, /* If max and min values are not equal, pack up field. If they are * equal, we have a constant field, and the reference value (rmin) * is the value for each point in the field and set nbits to 0. */ - if (rmin != rmax) { + if (rmin != rmax) + { /* Determine which algorithm to use based on user-supplied * binary scale factor and number of bits. */ - if (nbits == 0 && idrstmpl[1] == 0) { + if (nbits == 0 && idrstmpl[1] == 0) + { /* No binary scaling and calculate minumum number of bits * in which the data will fit. */ @@ -82,10 +85,11 @@ simpack(float *fld, g2int ndpts, g2int *idrstmpl, nbits = (g2int)ceil(temp); rmin = (float)imin; /* scale data */ - for(j = 0; j < ndpts; j++) + for (j = 0; j < ndpts; j++) ifld[j] = (g2int)rint(fld[j] * dscale) - imin; } - else if (nbits != 0 && idrstmpl[1] == 0) { + else if (nbits != 0 && idrstmpl[1] == 0) + { /* Use minimum number of bits specified by user and adjust * binary scaling factor to accomodate data. */ @@ -99,7 +103,8 @@ simpack(float *fld, g2int ndpts, g2int *idrstmpl, for (j = 0; j < ndpts; j++) ifld[j] = (g2int)rint(((fld[j] * dscale) - rmin) * bscale); } - else if (nbits == 0 && idrstmpl[1] != 0) { + else if (nbits == 0 && idrstmpl[1] != 0) + { /* Use binary scaling factor and calculate minumum number * of bits in which the data will fit. */ @@ -112,7 +117,8 @@ simpack(float *fld, g2int ndpts, g2int *idrstmpl, for (j = 0; j < ndpts; j++) ifld[j] = (g2int)rint(((fld[j] * dscale) - rmin) * bscale); } - else if (nbits != 0 && idrstmpl[1] != 0) { + else if (nbits != 0 && idrstmpl[1] != 0) + { /* Use binary scaling factor and use minumum number of * bits specified by user. Dangerous - may loose @@ -129,21 +135,23 @@ simpack(float *fld, g2int ndpts, g2int *idrstmpl, sbits(cpack, ifld, 0, nbits, 0, ndpts); nbittot = nbits * ndpts; left = 8 - (nbittot % 8); - if (left != 8) { - sbit(cpack, &zero, nbittot, left); /* Pad with zeros to fill Octet. */ + if (left != 8) + { + sbit(cpack, &zero, nbittot, left); /* Pad with zeros to fill Octet. */ nbittot = nbittot + left; } *lcpack = nbittot / 8; } - else { + else + { nbits = 0; *lcpack = 0; } /* Fill in ref value and number of bits in Template 5.0. */ - mkieee(&rmin, idrstmpl, 1); /* ensure reference value is IEEE format. */ + mkieee(&rmin, idrstmpl, 1); /* ensure reference value is IEEE format. */ idrstmpl[3] = nbits; - idrstmpl[4] = 0; /* original data were reals. */ + idrstmpl[4] = 0; /* original data were reals. */ free(ifld); } diff --git a/src/simunpack.c b/src/simunpack.c index be3665b7..8de01cb4 100644 --- a/src/simunpack.c +++ b/src/simunpack.c @@ -3,9 +3,9 @@ * algorithm. * @author Stephen Gilbert @date 2002-10-29 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /** * Unpack a data field that was packed using a simple packing @@ -32,7 +32,7 @@ simunpack(unsigned char *cpack, g2int *idrstmpl, g2int ndpts, float *fld) float ref, bscale, dscale; assert(cpack && idrstmpl && fld); - + LOG((3, "simunpack ndpts %ld idrstmpl: %ld %ld %ld %ld %ld", ndpts, idrstmpl[0], idrstmpl[1], idrstmpl[2], idrstmpl[3], idrstmpl[4])); @@ -44,7 +44,7 @@ simunpack(unsigned char *cpack, g2int *idrstmpl, g2int ndpts, float *fld) if (!(ifld = calloc(ndpts, sizeof(g2int)))) { fprintf(stderr, "Could not allocate space in simunpack.\n " - "Data field NOT upacked.\n"); + "Data field NOT upacked.\n"); return G2_JPCUNPACK_MEM; } diff --git a/src/specpack.c b/src/specpack.c index d59d8e77..e2772d08 100644 --- a/src/specpack.c +++ b/src/specpack.c @@ -4,10 +4,10 @@ * @author Stephen Gilbert @date 2002-12-19 */ +#include "grib2_int.h" +#include #include #include -#include -#include "grib2_int.h" /** * Pack a spectral data field using the complex packing algorithm for @@ -30,7 +30,7 @@ * @author Stephen Gilbert @date 2002-12-19 */ void -specpack(float *fld, g2int ndpts, g2int JJ, g2int KK, g2int MM, +specpack(float *fld, g2int ndpts, g2int JJ, g2int KK, g2int MM, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack) { @@ -62,23 +62,23 @@ specpack(float *fld, g2int ndpts, g2int JJ, g2int KK, g2int MM, incp = 0; for (m = 0; m <= MM; m++) { - Nm = JJ; /* triangular or trapezoidal */ + Nm = JJ; /* triangular or trapezoidal */ if (KK == JJ + MM) - Nm = JJ + m; /* rhombodial */ - Ns = Js; /* triangular or trapezoidal */ + Nm = JJ + m; /* rhombodial */ + Ns = Js; /* triangular or trapezoidal */ if (Ks == Js + Ms) - Ns = Js + m; /* rhombodial */ + Ns = Js + m; /* rhombodial */ for (n = m; n <= Nm; n++) { if (n <= Ns && m <= Ms) - { /* save unpacked value */ - unpk[incu++] = fld[inc++]; /* real part */ - unpk[incu++] = fld[inc++]; /* imaginary part */ + { /* save unpacked value */ + unpk[incu++] = fld[inc++]; /* real part */ + unpk[incu++] = fld[inc++]; /* imaginary part */ } else - { /* Save value to be packed and scale Laplacian scale factor. */ - tfld[incp++] = fld[inc++] * pscale[n]; /* real part */ - tfld[incp++] = fld[inc++] * pscale[n]; /* imaginary part */ + { /* Save value to be packed and scale Laplacian scale factor. */ + tfld[incp++] = fld[inc++] * pscale[n]; /* real part */ + tfld[incp++] = fld[inc++] * pscale[n]; /* imaginary part */ } } } diff --git a/src/specunpack.c b/src/specunpack.c index bc1b3102..84cf9c32 100644 --- a/src/specunpack.c +++ b/src/specunpack.c @@ -3,10 +3,10 @@ * complex packing algorithm for spherical harmonic data * @author Stephen Gilbert @date 2000-06-21 */ +#include "grib2_int.h" +#include #include #include -#include -#include "grib2_int.h" /** * Unpack a spectral data field that was packed using the complex @@ -41,7 +41,7 @@ specunpack(unsigned char *cpack, g2int *idrstmpl, g2int ndpts, g2int JJ, g2int Js, Ks, Ms, Ts, Ns, Nm, n, m; g2int inc, incu, incp; - rdieee(idrstmpl+0, &ref, 1); + rdieee(idrstmpl + 0, &ref, 1); bscale = int_power(2.0, idrstmpl[1]); dscale = int_power(10.0, -idrstmpl[2]); nbits = idrstmpl[3]; @@ -51,22 +51,22 @@ specunpack(unsigned char *cpack, g2int *idrstmpl, g2int ndpts, g2int JJ, Ts = idrstmpl[8]; if (idrstmpl[9] == 1) - { /* unpacked floats are 32-bit IEEE */ + { /* unpacked floats are 32-bit IEEE */ unpk = malloc(ndpts * sizeof(float)); ifld = malloc(ndpts * sizeof(g2int)); gbits(cpack, ifld, 0, 32, 0, Ts); iofst = 32 * Ts; - rdieee(ifld, unpk, Ts); /* read IEEE unpacked floats */ - gbits(cpack, ifld, iofst, nbits, 0, ndpts - Ts); /* unpack scaled data */ + rdieee(ifld, unpk, Ts); /* read IEEE unpacked floats */ + gbits(cpack, ifld, iofst, nbits, 0, ndpts - Ts); /* unpack scaled data */ /* Calculate Laplacian scaling factors for each possible wave * number. */ pscale = malloc((JJ + MM + 1) * sizeof(float)); tscale = idrstmpl[4] * 1E-6; for (n = Js; n <= JJ + MM; n++) - pscale[n] = pow((float)(n * (n+1)), -tscale); + pscale[n] = pow((float)(n * (n + 1)), -tscale); /* Assemble spectral coeffs back to original order. */ inc = 0; @@ -74,25 +74,25 @@ specunpack(unsigned char *cpack, g2int *idrstmpl, g2int ndpts, g2int JJ, incp = 0; for (m = 0; m <= MM; m++) { - Nm = JJ; /* triangular or trapezoidal */ - if (KK == JJ+MM) - Nm = JJ + m; /* rhombodial */ - Ns = Js; /* triangular or trapezoidal */ + Nm = JJ; /* triangular or trapezoidal */ + if (KK == JJ + MM) + Nm = JJ + m; /* rhombodial */ + Ns = Js; /* triangular or trapezoidal */ if (Ks == Js + Ms) - Ns = Js + m; /* rhombodial */ + Ns = Js + m; /* rhombodial */ for (n = m; n <= Nm; n++) { if (n <= Ns && m <= Ms) - { /* grab unpacked value */ - fld[inc++] = unpk[incu++]; /* real part */ - fld[inc++] = unpk[incu++]; /* imaginary part */ + { /* grab unpacked value */ + fld[inc++] = unpk[incu++]; /* real part */ + fld[inc++] = unpk[incu++]; /* imaginary part */ } else - { /* Calc coeff from packed value */ + { /* Calc coeff from packed value */ fld[inc++] = (((float)ifld[incp++] * bscale) + ref) * - dscale * pscale[n]; /* real part */ + dscale * pscale[n]; /* real part */ fld[inc++] = (((float)ifld[incp++] * bscale) + ref) * - dscale * pscale[n]; /* imaginary part */ + dscale * pscale[n]; /* imaginary part */ } } } diff --git a/src/util.c b/src/util.c index 7ffa9730..141dc203 100644 --- a/src/util.c +++ b/src/util.c @@ -1,4 +1,4 @@ -/** +/** * @file * @brief Internal utility functions for the g2c library. * @author Ed Hartnett @date Nov 11, 2021 @@ -25,11 +25,11 @@ int g2c_check_msg(unsigned char *cgrib, g2int *lencurr, int verbose) { - unsigned char G = 0x47; /* 'G' */ - unsigned char R = 0x52; /* 'R' */ - unsigned char I = 0x49; /* 'I' */ - unsigned char B = 0x42; /* 'B' */ - unsigned char seven = 0x37; /* '7' */ + unsigned char G = 0x47; /* 'G' */ + unsigned char R = 0x52; /* 'R' */ + unsigned char I = 0x49; /* 'I' */ + unsigned char B = 0x42; /* 'B' */ + unsigned char seven = 0x37; /* '7' */ assert(cgrib && lencurr); @@ -108,8 +108,8 @@ g2_log(int severity, const char *fmt, ...) #endif /* LOGGING */ /** - * Use this to set the global log level. - * + * Use this to set the global log level. + * * Settings: * - -1 turn off all logging. * - 0 show only errors. @@ -136,4 +136,3 @@ g2c_set_log_level(int new_level) #endif return G2C_NOERROR; } - diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 236ab275..9121d408 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -79,7 +79,7 @@ if(FTP_LARGE_TEST_FILES) set(REF_FILES ${REF_FILES} "ref_fv3lam.t00z.prslev.f000.grib2.degrib2") endif() -foreach(THE_FILE IN LISTS REF_FILES) +foreach(THE_FILE IN LISTS REF_FILES) FILE(COPY ${CMAKE_CURRENT_SOURCE_DIR}/data/${THE_FILE} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data) endforeach() @@ -114,7 +114,7 @@ endfunction() function(g2c_ptest name) g2c_test(${name}) if(PTHREADS) - target_compile_definitions(${name} PRIVATE -DPTHREADS) + target_compile_definitions(${name} PRIVATE -DPTHREADS) target_link_libraries(${name} PRIVATE pthread) endif() endfunction() @@ -140,18 +140,18 @@ if(FTP_TEST_FILES) "WW3_Regional_US_East_Coast_20220717_0600.grib2" "gdas.t12z.pgrb2.1p00.anl.grib2" "blend.t19z.core.f001.co.grib2" "cmc_geavg.t12z.pgrb2a.0p50.f000" - "flxf2022111712.01.2022111712.grb2" + "flxf2022111712.01.2022111712.grb2" "GLOBAL.grib2.2022103000.0000" "hiresw.t00z.arw_5km.f00.hi.grib2" "naefs_ge10pt.t12z.pgrb2a.0p50_bcf003" "rap.t00z.awp130pgrbf00.grib2" "seaice.t00z.grb.grib2" "sgx_nwps_CG3_20221117_1200.grib2" "aqm.t12z.max_8hr_o3.227.grib2") - foreach(THE_FILE IN LISTS FTP_FILES) + foreach(THE_FILE IN LISTS FTP_FILES) PULL_DATA(${G2_FTP_URL} ${THE_FILE}) endforeach() if(FTP_LARGE_TEST_FILES) set(LARGE_FTP_FILES "fv3lam.t00z.prslev.f000.grib2") - foreach(THE_FILE IN LISTS LARGE_FTP_FILES) + foreach(THE_FILE IN LISTS LARGE_FTP_FILES) PULL_DATA(${G2_FTP_URL} ${THE_FILE}) endforeach() add_definitions(-DLARGE_FTP_TESTS) @@ -160,7 +160,7 @@ if(FTP_TEST_FILES) if(FTP_EXTRA_TEST_FILES) set(EXTRA_FTP_FILES MRMS_MultiSensor_QPE_24H_Pass2_00.00_20230621-110000.grib2 GFSPRS.GrbF06 rrfs.t18z.prslev.f000.grib2) - foreach(THE_FILE IN LISTS EXTRA_FTP_FILES) + foreach(THE_FILE IN LISTS EXTRA_FTP_FILES) PULL_DATA(${G2_FTP_URL} ${THE_FILE}) endforeach() endif() @@ -170,7 +170,7 @@ if(FTP_TEST_FILES) add_definitions(-DFTP_TEST_FILES) # Run this test only if FTP test files are used. - if(BUILD_G2C) + if(BUILD_G2C) g2c_ptest(tst_aqm) endif() endif() diff --git a/tests/g2c_test_util.c b/tests/g2c_test_util.c index ad917fba..c8df66aa 100644 --- a/tests/g2c_test_util.c +++ b/tests/g2c_test_util.c @@ -16,9 +16,9 @@ */ static int cmpString(const void *p, const void *q) -{ - const char *pp = (const char*)p; - const char *qq = (const char*)q; +{ + const char *pp = (const char *)p; + const char *qq = (const char *)q; int i, j; for (i = 0; isblank(pp[i]); ++i) ; @@ -153,4 +153,3 @@ compare_degrib2_files2(char *fname1, char *fname2) return G2C_NOERROR; } - diff --git a/tests/run_degrib2_tests.sh b/tests/run_degrib2_tests.sh index 5f4a8736..0587ae2b 100644 --- a/tests/run_degrib2_tests.sh +++ b/tests/run_degrib2_tests.sh @@ -10,10 +10,10 @@ echo "" echo "*** Running g2c_degrib2 test" # Generate degrib2 output for our test GRIB2 file. -../utils/g2c_degrib2 -v -o g2c_degrib2_gdaswave.t00z.wcoast.0p16.f000.grib2.degrib2 data/gdaswave.t00z.wcoast.0p16.f000.grib2 +../utils/g2c_degrib2 -v -o g2c_degrib2_gdaswave.t00z.wcoast.0p16.f000.grib2.degrib2 data/gdaswave.t00z.wcoast.0p16.f000.grib2 # Check against expected output. -diff -w g2c_degrib2_gdaswave.t00z.wcoast.0p16.f000.grib2.degrib2 data/ref_gdaswave.t00z.wcoast.0p16.f000.grib2.degrib2 +diff -w g2c_degrib2_gdaswave.t00z.wcoast.0p16.f000.grib2.degrib2 data/ref_gdaswave.t00z.wcoast.0p16.f000.grib2.degrib2 echo "*** SUCCESS!" exit 0 diff --git a/tests/run_extra_index_tests.sh b/tests/run_extra_index_tests.sh index c56cbd60..970c9115 100644 --- a/tests/run_extra_index_tests.sh +++ b/tests/run_extra_index_tests.sh @@ -16,7 +16,7 @@ echo "*** Running g2c_index extra file test" ../utils/g2c_index -o GFSPRS.GrbF06.idx -l -v data/GFSPRS.GrbF06 # Summarize the index data. -#../utils/g2c_degrib2 -v -o fv3lam.t00z.prslev.f000.grib2.idx.degrib2 data/fv3lam.t00z.prslev.f000.grib2 fv3lam.t00z.prslev.f000.grib2.idx +#../utils/g2c_degrib2 -v -o fv3lam.t00z.prslev.f000.grib2.idx.degrib2 data/fv3lam.t00z.prslev.f000.grib2 fv3lam.t00z.prslev.f000.grib2.idx # Check against expected output. #diff -w fv3lam.t00z.prslev.f000.grib2.idx.degrib2 data/ref_fv3lam.t00z.prslev.f000.grib2.degrib2 diff --git a/tests/run_ftp_index_tests.sh b/tests/run_ftp_index_tests.sh index 4eeaad15..d5432c59 100644 --- a/tests/run_ftp_index_tests.sh +++ b/tests/run_ftp_index_tests.sh @@ -44,10 +44,10 @@ exit 0 # # Create an index for a GRIB2 file. -# ../utils/g2c_index -v -o gdaswave.t00z.wcoast.0p16.f000.grib2.idx data/gdaswave.t00z.wcoast.0p16.f000.grib2 +# ../utils/g2c_index -v -o gdaswave.t00z.wcoast.0p16.f000.grib2.idx data/gdaswave.t00z.wcoast.0p16.f000.grib2 # # Summarize the index data. -# ../utils/g2c_degrib2 -v -o gdaswave.t00z.wcoast.0p16.f000.grib2.idx.degrib2 data/gdaswave.t00z.wcoast.0p16.f000.grib2 gdaswave.t00z.wcoast.0p16.f000.grib2.idx +# ../utils/g2c_degrib2 -v -o gdaswave.t00z.wcoast.0p16.f000.grib2.idx.degrib2 data/gdaswave.t00z.wcoast.0p16.f000.grib2 gdaswave.t00z.wcoast.0p16.f000.grib2.idx # # Check against expected output. # diff -w gdaswave.t00z.wcoast.0p16.f000.grib2.idx.degrib2 data/ref_gdaswave.t00z.wcoast.0p16.f000.grib2.degrib2 diff --git a/tests/run_index_tests.sh b/tests/run_index_tests.sh index 0b9e37ab..5169ac86 100644 --- a/tests/run_index_tests.sh +++ b/tests/run_index_tests.sh @@ -10,10 +10,10 @@ echo "" echo "*** Running g2c_index test" # Create an index for a GRIB2 file. -../utils/g2c_index -v -o gdaswave.t00z.wcoast.0p16.f000.grib2.idx data/gdaswave.t00z.wcoast.0p16.f000.grib2 +../utils/g2c_index -v -o gdaswave.t00z.wcoast.0p16.f000.grib2.idx data/gdaswave.t00z.wcoast.0p16.f000.grib2 # Summarize the index data. -../utils/g2c_degrib2 -v -o gdaswave.t00z.wcoast.0p16.f000.grib2.idx.degrib2 data/gdaswave.t00z.wcoast.0p16.f000.grib2 gdaswave.t00z.wcoast.0p16.f000.grib2.idx +../utils/g2c_degrib2 -v -o gdaswave.t00z.wcoast.0p16.f000.grib2.idx.degrib2 data/gdaswave.t00z.wcoast.0p16.f000.grib2 gdaswave.t00z.wcoast.0p16.f000.grib2.idx # Check against expected output. diff -w gdaswave.t00z.wcoast.0p16.f000.grib2.idx.degrib2 data/ref_gdaswave.t00z.wcoast.0p16.f000.grib2.degrib2 diff --git a/tests/run_large_index_tests.sh b/tests/run_large_index_tests.sh index 5f1263ea..87ea21bb 100644 --- a/tests/run_large_index_tests.sh +++ b/tests/run_large_index_tests.sh @@ -10,10 +10,10 @@ echo "" echo "*** Running g2c_index large file test" # Create an index for a GRIB2 file. -../utils/g2c_index -o fv3lam.t00z.prslev.f000.grib2.idx -l -v data/fv3lam.t00z.prslev.f000.grib2 +../utils/g2c_index -o fv3lam.t00z.prslev.f000.grib2.idx -l -v data/fv3lam.t00z.prslev.f000.grib2 # Summarize the index data. -#../utils/g2c_degrib2 -o fv3lam.t00z.prslev.f000.grib2.idx.degrib2 data/fv3lam.t00z.prslev.f000.grib2 fv3lam.t00z.prslev.f000.grib2.idx +#../utils/g2c_degrib2 -o fv3lam.t00z.prslev.f000.grib2.idx.degrib2 data/fv3lam.t00z.prslev.f000.grib2 fv3lam.t00z.prslev.f000.grib2.idx # Check against expected output. #diff -w fv3lam.t00z.prslev.f000.grib2.idx.degrib2 data/ref_fv3lam.t00z.prslev.f000.grib2.degrib2 diff --git a/tests/tst_addfield2.c b/tests/tst_addfield2.c index f99b7ee3..a1b96250 100644 --- a/tests/tst_addfield2.c +++ b/tests/tst_addfield2.c @@ -4,10 +4,10 @@ * Ed Hartnett 11/4/21 */ -#include -#include #include "grib2.h" #include "grib2_int.h" +#include +#include #define SEC0_LEN 16 #define SEC1_LEN 21 @@ -29,18 +29,18 @@ main() g2int igds[5] = {0, 4, 0, 0, 0}; g2int igdstmpl[19] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}; unsigned char expected_cgrib[FULL_MSG_LEN] = {0x47, 0x52, 0x49, 0x42, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xf1, 0x00, 0x00, 0x00, 0x15, 0x01, 0x00, 0x07, 0x00, 0x04, 0x18, 0x00, 0x00, 0x07, 0xe5, 0x0a, - 0x18, 0x06, 0x36, 0x3b, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x48, 0x03, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00, 0x00, 0x04, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, - 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b, 0x00, - 0x00, 0x00, 0x0c, 0x0d, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x11, 0x12, 0x00, 0x00, 0x00, 0x19, 0x04, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x29, - 0x42, 0xc8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x08, 0x00, 0x00, 0x00, 0x00, 0x07, 0x06, 0x00, 0xf0, 0x00, 0x00, - 0x00, 0x4b, 0x07, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, - 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x57, 0x50, 0x11, 0x00, 0x00, - 0x00, 0x0d, 0x49, 0x44, 0x41, 0x54, 0x08, 0x99, 0x63, 0x64, 0x30, 0x32, 0x32, 0x02, 0x00, 0x01, 0x36, 0x00, 0x98, - 0x05, 0xdb, 0x15, 0xba, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82, 0x37, 0x37, 0x37, 0x37}; + 0x00, 0x00, 0x00, 0xf1, 0x00, 0x00, 0x00, 0x15, 0x01, 0x00, 0x07, 0x00, 0x04, 0x18, 0x00, 0x00, 0x07, 0xe5, 0x0a, + 0x18, 0x06, 0x36, 0x3b, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x48, 0x03, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00, 0x00, 0x04, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, + 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b, 0x00, + 0x00, 0x00, 0x0c, 0x0d, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x11, 0x12, 0x00, 0x00, 0x00, 0x19, 0x04, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x29, + 0x42, 0xc8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x08, 0x00, 0x00, 0x00, 0x00, 0x07, 0x06, 0x00, 0xf0, 0x00, 0x00, + 0x00, 0x4b, 0x07, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, + 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x57, 0x50, 0x11, 0x00, 0x00, + 0x00, 0x0d, 0x49, 0x44, 0x41, 0x54, 0x08, 0x99, 0x63, 0x64, 0x30, 0x32, 0x32, 0x02, 0x00, 0x01, 0x36, 0x00, 0x98, + 0x05, 0xdb, 0x15, 0xba, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82, 0x37, 0x37, 0x37, 0x37}; unsigned char old_val; /* Analysis or forecast at a horizontal level or in a * horizontal layer at a point in time. */ @@ -57,8 +57,7 @@ main() 0, 0, 0, - 0 - }; + 0}; float coordlist[1] = {1}; g2int numcoord = 0; g2int idrsnum = 41; /* Grid Point Data - PNG Compression (see Template 5.41) */ @@ -163,12 +162,12 @@ main() if (gfld->ipdtmpl[i] != ipdstmpl[i]) return G2C_ERROR; - /* Try the g2_miss() function. */ - float rmiss[1]; - int nmiss; - g2_miss(gfld, rmiss, &nmiss); - if (nmiss) - return G2C_ERROR; + /* Try the g2_miss() function. */ + float rmiss[1]; + int nmiss; + g2_miss(gfld, rmiss, &nmiss); + if (nmiss) + return G2C_ERROR; /* Free the memory. */ g2_free(gfld); diff --git a/tests/tst_addfield3.c b/tests/tst_addfield3.c index 99ec031a..9aa2d4f7 100644 --- a/tests/tst_addfield3.c +++ b/tests/tst_addfield3.c @@ -4,9 +4,9 @@ * Ed Hartnett 11/4/21 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" #define SEC0_LEN 16 #define SEC1_LEN 21 @@ -32,25 +32,25 @@ main() g2int igds[5] = {0, 4, 0, 0, 10}; /* 10 is Mercator */ /* See https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp3-10.shtml. */ g2int igdstmpl[19] = { - 0, /* Shape of the Earth (See Code Table 3.2) */ - 1, /* Scale factor of radius of spherical Earth */ - 1, /* Scale value of radius of spherical Earth */ - 1, /* Scale factor of major axis of oblate spheroid Earth */ - 1, /* Scaled value of major axis of oblate spheroid Earth */ - 1, /* Scale factor of minor axis of oblate spheroid Earth */ - 1, /* Scaled value of minor axis of oblate spheroid Earth */ - 2, /* Nj—number of points along a parallel */ - 2, /* Nj—number of points along a meridian */ - 0, /* La1 ― latitude of first grid point */ - 0, /* Lo1 ― longitude of first grid point */ - 0, /* Resolution and component flags (see Flag Table 3.3) */ - 90, /* LaD — latitude(s) at which the Mercator projection intersects the Earth (Latitude(s) where Di and Dj are specified) */ - 90, /* La2 ― latitude of last grid point */ - 90, /* Lo2 — longitude of last grid point */ - 0, /* Scanning mode (flags — see Flag Table 3.4) */ - 0, /* Orientation of the grid, angle between i direction on the map and the Equator (see Note1) */ + 0, /* Shape of the Earth (See Code Table 3.2) */ + 1, /* Scale factor of radius of spherical Earth */ + 1, /* Scale value of radius of spherical Earth */ + 1, /* Scale factor of major axis of oblate spheroid Earth */ + 1, /* Scaled value of major axis of oblate spheroid Earth */ + 1, /* Scale factor of minor axis of oblate spheroid Earth */ + 1, /* Scaled value of minor axis of oblate spheroid Earth */ + 2, /* Nj—number of points along a parallel */ + 2, /* Nj—number of points along a meridian */ + 0, /* La1 ― latitude of first grid point */ + 0, /* Lo1 ― longitude of first grid point */ + 0, /* Resolution and component flags (see Flag Table 3.3) */ + 90, /* LaD — latitude(s) at which the Mercator projection intersects the Earth (Latitude(s) where Di and Dj are specified) */ + 90, /* La2 ― latitude of last grid point */ + 90, /* Lo2 — longitude of last grid point */ + 0, /* Scanning mode (flags — see Flag Table 3.4) */ + 0, /* Orientation of the grid, angle between i direction on the map and the Equator (see Note1) */ 100, /* Dj — longitudinal direction grid length (see Note 2) */ - 100 /* Dj ― latitudinal direction grid length (see Note 2) */ + 100 /* Dj ― latitudinal direction grid length (see Note 2) */ }; /* unsigned char expected_cgrib[FULL_MSG_LEN] = {0x47, 0x52, 0x49, 0x42, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, */ /* 0x00, 0x00, 0x00, 0x01, 0x65, 0x00, 0x00, 0x00, 0x15, 0x01, 0x00, 0x07, 0x00, 0x04, 0x18, 0x00, 0x00, 0x07, */ @@ -74,7 +74,7 @@ main() /* 0x93, 0xc7, 0x41, 0x07, 0x80, 0x80, 0x80, 0xcf, 0x90, 0x08, 0x03, 0xc7, 0xc2, 0x10, 0x0b, 0x5f, 0xff, 0xd9, */ /* 0x37, 0x37, 0x37, 0x37}; */ /* unsigned char old_val; */ - /* Analysis or forecast at a horizontal level or in a + /* Analysis or forecast at a horizontal level or in a * horizontal layer at a point in time. */ g2int ipdsnum = 31; /* See @@ -89,8 +89,7 @@ main() 0, 0, 0, - 0 - }; + 0}; float coordlist[1] = {1}; g2int numcoord = 0; g2int idrsnum = 40; /* Grid Point Data - JPEG2000 Compression (see Template 5.40) */ @@ -191,12 +190,12 @@ main() if (gfld->ipdtmpl[i] != ipdstmpl[i]) return G2C_ERROR; - /* Try the g2_miss() function. */ - float rmiss[1]; - int nmiss; - g2_miss(gfld, rmiss, &nmiss); - if (nmiss) - return G2C_ERROR; + /* Try the g2_miss() function. */ + float rmiss[1]; + int nmiss; + g2_miss(gfld, rmiss, &nmiss); + if (nmiss) + return G2C_ERROR; /* Free the memory. */ g2_free(gfld); diff --git a/tests/tst_addfield4.c b/tests/tst_addfield4.c index 516ae354..0a4b41a0 100644 --- a/tests/tst_addfield4.c +++ b/tests/tst_addfield4.c @@ -4,9 +4,9 @@ * Ed Hartnett 11/6/21 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" #define SEC0_LEN 16 #define SEC1_LEN 21 @@ -32,25 +32,25 @@ main() g2int igds[5] = {0, 4, 0, 0, 10}; /* 10 is Mercator */ /* See https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp3-10.shtml. */ g2int igdstmpl[19] = { - 0, /* Shape of the Earth (See Code Table 3.2) */ - 1, /* Scale factor of radius of spherical Earth */ - 1, /* Scale value of radius of spherical Earth */ - 1, /* Scale factor of major axis of oblate spheroid Earth */ - 1, /* Scaled value of major axis of oblate spheroid Earth */ - 1, /* Scale factor of minor axis of oblate spheroid Earth */ - 1, /* Scaled value of minor axis of oblate spheroid Earth */ - 2, /* Nj—number of points along a parallel */ - 2, /* Nj—number of points along a meridian */ - 0, /* La1 ― latitude of first grid point */ - 0, /* Lo1 ― longitude of first grid point */ - 0, /* Resolution and component flags (see Flag Table 3.3) */ - 90, /* LaD — latitude(s) at which the Mercator projection intersects the Earth (Latitude(s) where Di and Dj are specified) */ - 90, /* La2 ― latitude of last grid point */ - 90, /* Lo2 — longitude of last grid point */ - 0, /* Scanning mode (flags — see Flag Table 3.4) */ - 0, /* Orientation of the grid, angle between i direction on the map and the Equator (see Note1) */ + 0, /* Shape of the Earth (See Code Table 3.2) */ + 1, /* Scale factor of radius of spherical Earth */ + 1, /* Scale value of radius of spherical Earth */ + 1, /* Scale factor of major axis of oblate spheroid Earth */ + 1, /* Scaled value of major axis of oblate spheroid Earth */ + 1, /* Scale factor of minor axis of oblate spheroid Earth */ + 1, /* Scaled value of minor axis of oblate spheroid Earth */ + 2, /* Nj—number of points along a parallel */ + 2, /* Nj—number of points along a meridian */ + 0, /* La1 ― latitude of first grid point */ + 0, /* Lo1 ― longitude of first grid point */ + 0, /* Resolution and component flags (see Flag Table 3.3) */ + 90, /* LaD — latitude(s) at which the Mercator projection intersects the Earth (Latitude(s) where Di and Dj are specified) */ + 90, /* La2 ― latitude of last grid point */ + 90, /* Lo2 — longitude of last grid point */ + 0, /* Scanning mode (flags — see Flag Table 3.4) */ + 0, /* Orientation of the grid, angle between i direction on the map and the Equator (see Note1) */ 100, /* Dj — longitudinal direction grid length (see Note 2) */ - 100 /* Dj ― latitudinal direction grid length (see Note 2) */ + 100 /* Dj ― latitudinal direction grid length (see Note 2) */ }; /* unsigned char expected_cgrib[FULL_MSG_LEN] = {0x47, 0x52, 0x49, 0x42, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, */ /* 0x00, 0x00, 0x00, 0x01, 0x65, 0x00, 0x00, 0x00, 0x15, 0x01, 0x00, 0x07, 0x00, 0x04, 0x18, 0x00, 0x00, 0x07, */ @@ -74,7 +74,7 @@ main() /* 0x93, 0xc7, 0x41, 0x07, 0x80, 0x80, 0x80, 0xcf, 0x90, 0x08, 0x03, 0xc7, 0xc2, 0x10, 0x0b, 0x5f, 0xff, 0xd9, */ /* 0x37, 0x37, 0x37, 0x37}; */ /* unsigned char old_val; */ - /* Analysis or forecast at a horizontal level or in a + /* Analysis or forecast at a horizontal level or in a * horizontal layer at a point in time. */ g2int ipdsnum = 31; /* See @@ -89,8 +89,7 @@ main() 0, 0, 0, - 0 - }; + 0}; float coordlist[1] = {1}; g2int numcoord = 0; g2int idrsnum = 40; /* Grid Point Data - JPEG2000 Compression (see Template 5.40) */ @@ -191,12 +190,12 @@ main() if (gfld->ipdtmpl[i] != ipdstmpl[i]) return G2C_ERROR; - /* Try the g2_miss() function. */ - float rmiss[1]; - int nmiss; - g2_miss(gfld, rmiss, &nmiss); - if (nmiss) - return G2C_ERROR; + /* Try the g2_miss() function. */ + float rmiss[1]; + int nmiss; + g2_miss(gfld, rmiss, &nmiss); + if (nmiss) + return G2C_ERROR; /* Free the memory. */ g2_free(gfld); diff --git a/tests/tst_addfield_spec.c b/tests/tst_addfield_spec.c index 4d497c8f..75e1f410 100644 --- a/tests/tst_addfield_spec.c +++ b/tests/tst_addfield_spec.c @@ -4,9 +4,9 @@ * Ed Hartnett 11/1/21 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" #define SEC0_LEN 16 #define SEC1_LEN 21 @@ -84,7 +84,7 @@ main() /* /\* g2int numfields, numlocal; *\/ */ /* /\* g2int ifldnum = 1, unpack = 1, expand = 0; *\/ */ /* /\* gribfield *gfld; *\/ */ - + /* /\* /\\* Use g2_info() to learn about our messaage. *\\/ *\/ */ /* /\* if ((ret = g2_info(cgrib, listsec0_in, listsec1_in, &numfields, &numlocal))) *\/ */ /* /\* return G2C_ERROR; *\/ */ diff --git a/tests/tst_aec.c b/tests/tst_aec.c index de431102..e5a7208d 100644 --- a/tests/tst_aec.c +++ b/tests/tst_aec.c @@ -4,9 +4,9 @@ * Eric Engle 10/18/23 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" #define DATA_LEN 4 #define PACKED_LEN 80 @@ -39,8 +39,8 @@ main() databuf = data; aecbuf = cout; - datalen = sizeof(data)/sizeof(data[0]); - aeclen = (g2int *) (sizeof(cout)/sizeof(cout[0])); + datalen = sizeof(data) / sizeof(data[0]); + aeclen = (g2int *)(sizeof(cout) / sizeof(cout[0])); /* Set AEC parameters. */ ccsds_flags = CCSDS_FLAGS; @@ -54,7 +54,7 @@ main() return G2C_ERROR; /* Now decode it. */ - ret = dec_aec(aecbuf,(g2int)aeclen, nbits, ccsds_flags,ccsds_block_size, + ret = dec_aec(aecbuf, (g2int)aeclen, nbits, ccsds_flags, ccsds_block_size, ccsds_rsi, cout, datalen); if (ret < 0) { @@ -98,31 +98,31 @@ main() printf("ok!\n"); printf("Testing g2c_aecpackd()/g2c_aecunpackd() calls with constant data..."); { - size_t height = 2, width = 2; - size_t ndpts = DATA_LEN, len = PACKED_LEN; - double fld[DATA_LEN] = {1.0, 1.0, 1.0, 1.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; + size_t height = 2, width = 2; + size_t ndpts = DATA_LEN, len = PACKED_LEN; + double fld[DATA_LEN] = {1.0, 1.0, 1.0, 1.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); + /* 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; + /* 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; - } + 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"); diff --git a/tests/tst_aqm.c b/tests/tst_aqm.c index ac1e5115..67818acf 100644 --- a/tests/tst_aqm.c +++ b/tests/tst_aqm.c @@ -30,7 +30,6 @@ main() /* Close the data file. */ if ((ret = g2c_close(g2cid))) return ret; - } printf("ok!\n"); printf("SUCCESS!\n"); diff --git a/tests/tst_com.c b/tests/tst_com.c index 04c52157..b846ba68 100644 --- a/tests/tst_com.c +++ b/tests/tst_com.c @@ -4,9 +4,9 @@ * Ed Hartnett 11/2/21 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" #define DATA_LEN 4 #define PACKED_LEN 200 @@ -32,23 +32,23 @@ main() * https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-2.shtml * for the template meaning. */ g2int idrstmpl[16] = { - 0, /* reference value (R) (IEEE 32-bit floating-point value) */ - 1, /* Binary scale factor (E) */ - 1, /* Decimal scale factor (D) */ - 8, /* Number of bits used for each packed value for simple packing, or for each group reference value for complex packing or spatial differencing */ - 0, /* Type of original field values (see Code Table 5.1) */ - 0, /* Group splitting method used (see Code Table 5.4) */ - 0, /* Missing value management used (see Code Table 5.5) */ - 0, /* Primary missing value substitute */ - 0, /* Secondary missing value substitute */ - 1, /* NG ― number of groups of data values into which field is split */ + 0, /* reference value (R) (IEEE 32-bit floating-point value) */ + 1, /* Binary scale factor (E) */ + 1, /* Decimal scale factor (D) */ + 8, /* Number of bits used for each packed value for simple packing, or for each group reference value for complex packing or spatial differencing */ + 0, /* Type of original field values (see Code Table 5.1) */ + 0, /* Group splitting method used (see Code Table 5.4) */ + 0, /* Missing value management used (see Code Table 5.5) */ + 0, /* Primary missing value substitute */ + 0, /* Secondary missing value substitute */ + 1, /* NG ― number of groups of data values into which field is split */ 16, /* Reference for group widths (see Note 12) */ - 8, /* Number of bits used for the group widths (after the reference value in octet 36 has been removed) */ - 4, /* Reference for group lengths (see Note 13) */ - 0, /* Length increment for the group lengths (see Note 14) */ - 0, /* True length of last group */ - 8 /* Number of bits used for the scaled group lengths (after subtraction of the reference value given in octets 38-41 and division by the length increment given in octet 42) */ - }; + 8, /* Number of bits used for the group widths (after the reference value in octet 36 has been removed) */ + 4, /* Reference for group lengths (see Note 13) */ + 0, /* Length increment for the group lengths (see Note 14) */ + 0, /* True length of last group */ + 8 /* Number of bits used for the scaled group lengths (after subtraction of the reference value given in octets 38-41 and division by the length increment given in octet 42) */ + }; g2int idrsnum = 2; int i; @@ -63,7 +63,7 @@ main() { /* printf("%g %g\n", fld[i], fld_in[i]); */ if (fld[i] != fld_in[i]) - return G2C_ERROR; + return G2C_ERROR; } } printf("ok!\n"); @@ -78,25 +78,25 @@ main() * https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-3.shtml * for the template meaning. */ g2int idrstmpl[18] = { - 0, /* reference value (R) (IEEE 32-bit floating-point value) */ - 1, /* Binary scale factor (E) */ - 1, /* Decimal scale factor (D) */ - 8, /* Number of bits used for each packed value for simple packing, or for each group reference value for complex packing or spatial differencing */ - 0, /* Type of original field values (see Code Table 5.1) */ - 0, /* Group splitting method used (see Code Table 5.4) */ - 0, /* Missing value management used (see Code Table 5.5) */ - 0, /* Primary missing value substitute */ - 0, /* Secondary missing value substitute */ - 1, /* NG ― number of groups of data values into which field is split */ + 0, /* reference value (R) (IEEE 32-bit floating-point value) */ + 1, /* Binary scale factor (E) */ + 1, /* Decimal scale factor (D) */ + 8, /* Number of bits used for each packed value for simple packing, or for each group reference value for complex packing or spatial differencing */ + 0, /* Type of original field values (see Code Table 5.1) */ + 0, /* Group splitting method used (see Code Table 5.4) */ + 0, /* Missing value management used (see Code Table 5.5) */ + 0, /* Primary missing value substitute */ + 0, /* Secondary missing value substitute */ + 1, /* NG ― number of groups of data values into which field is split */ 16, /* Reference for group widths (see Note 12) */ - 8, /* Number of bits used for the group widths (after the reference value in octet 36 has been removed) */ - 4, /* Reference for group lengths (see Note 13) */ - 0, /* Length increment for the group lengths (see Note 14) */ - 0, /* True length of last group */ - 8, /* Number of bits used for the scaled group lengths (after subtraction of the reference value given in octets 38-41 and division by the length increment given in octet 42) */ - 1, /* Order of spatial difference (see Code Table 5.6) */ - 0 /* Number of octets required in the data section to specify extra descriptors needed for spatial differencing (octets 6-ww in data template 7.3) */ - }; + 8, /* Number of bits used for the group widths (after the reference value in octet 36 has been removed) */ + 4, /* Reference for group lengths (see Note 13) */ + 0, /* Length increment for the group lengths (see Note 14) */ + 0, /* True length of last group */ + 8, /* Number of bits used for the scaled group lengths (after subtraction of the reference value given in octets 38-41 and division by the length increment given in octet 42) */ + 1, /* Order of spatial difference (see Code Table 5.6) */ + 0 /* Number of octets required in the data section to specify extra descriptors needed for spatial differencing (octets 6-ww in data template 7.3) */ + }; g2int idrsnum = 3; int i; @@ -111,7 +111,7 @@ main() { /* printf("%g %g\n", fld[i], fld_in[i]); */ if (fld[i] != fld_in[i]) - return G2C_ERROR; + return G2C_ERROR; } } printf("ok!\n"); @@ -127,30 +127,30 @@ main() * https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-2.shtml * for the template meaning. */ g2int idrstmpl[16] = { - 0, /* reference value (R) (IEEE 32-bit floating-point value) */ - 1, /* Binary scale factor (E) */ - 1, /* Decimal scale factor (D) */ - 8, /* Number of bits used for each packed value for simple packing, or for each group reference value for complex packing or spatial differencing */ - 0, /* Type of original field values (see Code Table 5.1) */ - 0, /* Group splitting method used (see Code Table 5.4) */ - 1, /* Missing value management used (see Code Table 5.5) */ - 0, /* Primary missing value substitute */ - 0, /* Secondary missing value substitute */ - 1, /* NG ― number of groups of data values into which field is split */ + 0, /* reference value (R) (IEEE 32-bit floating-point value) */ + 1, /* Binary scale factor (E) */ + 1, /* Decimal scale factor (D) */ + 8, /* Number of bits used for each packed value for simple packing, or for each group reference value for complex packing or spatial differencing */ + 0, /* Type of original field values (see Code Table 5.1) */ + 0, /* Group splitting method used (see Code Table 5.4) */ + 1, /* Missing value management used (see Code Table 5.5) */ + 0, /* Primary missing value substitute */ + 0, /* Secondary missing value substitute */ + 1, /* NG ― number of groups of data values into which field is split */ 16, /* Reference for group widths (see Note 12) */ - 8, /* Number of bits used for the group widths (after the reference value in octet 36 has been removed) */ - 4, /* Reference for group lengths (see Note 13) */ - 0, /* Length increment for the group lengths (see Note 14) */ - 0, /* True length of last group */ - 8 /* Number of bits used for the scaled group lengths (after subtraction of the reference value given in octets 38-41 and division by the length increment given in octet 42) */ - }; + 8, /* Number of bits used for the group widths (after the reference value in octet 36 has been removed) */ + 4, /* Reference for group lengths (see Note 13) */ + 0, /* Length increment for the group lengths (see Note 14) */ + 0, /* True length of last group */ + 8 /* Number of bits used for the scaled group lengths (after subtraction of the reference value given in octets 38-41 and division by the length increment given in octet 42) */ + }; g2int idrsnum = 2; int i; /* Change the missing value management field to something invalid. */ old_int_val = idrstmpl[6]; idrstmpl[6] = 3; - + /* This won't work, bad missing value management value. */ misspack(fld, ndpts, idrsnum, idrstmpl, cpack, &lcpack); if (lcpack != -1) @@ -170,7 +170,7 @@ main() { /* printf("%g %g\n", fld[i], fld_in[i]); */ if (fld[i] != fld_in[i]) - return G2C_ERROR; + return G2C_ERROR; } } printf("ok!\n"); @@ -185,23 +185,23 @@ main() * https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-2.shtml * for the template meaning. */ g2int idrstmpl[16] = { - 0, /* reference value (R) (IEEE 32-bit floating-point value) */ - 0, /* Binary scale factor (E) */ - 1, /* Decimal scale factor (D) */ - 8, /* Number of bits used for each packed value for simple packing, or for each group reference value for complex packing or spatial differencing */ - 0, /* Type of original field values (see Code Table 5.1) */ - 0, /* Group splitting method used (see Code Table 5.4) */ - 2, /* Missing value management used (see Code Table 5.5) */ - 0, /* Primary missing value substitute */ - 0, /* Secondary missing value substitute */ - 1, /* NG ― number of groups of data values into which field is split */ + 0, /* reference value (R) (IEEE 32-bit floating-point value) */ + 0, /* Binary scale factor (E) */ + 1, /* Decimal scale factor (D) */ + 8, /* Number of bits used for each packed value for simple packing, or for each group reference value for complex packing or spatial differencing */ + 0, /* Type of original field values (see Code Table 5.1) */ + 0, /* Group splitting method used (see Code Table 5.4) */ + 2, /* Missing value management used (see Code Table 5.5) */ + 0, /* Primary missing value substitute */ + 0, /* Secondary missing value substitute */ + 1, /* NG ― number of groups of data values into which field is split */ 16, /* Reference for group widths (see Note 12) */ - 8, /* Number of bits used for the group widths (after the reference value in octet 36 has been removed) */ - 4, /* Reference for group lengths (see Note 13) */ - 0, /* Length increment for the group lengths (see Note 14) */ - 0, /* True length of last group */ - 8 /* Number of bits used for the scaled group lengths (after subtraction of the reference value given in octets 38-41 and division by the length increment given in octet 42) */ - }; + 8, /* Number of bits used for the group widths (after the reference value in octet 36 has been removed) */ + 4, /* Reference for group lengths (see Note 13) */ + 0, /* Length increment for the group lengths (see Note 14) */ + 0, /* True length of last group */ + 8 /* Number of bits used for the scaled group lengths (after subtraction of the reference value given in octets 38-41 and division by the length increment given in octet 42) */ + }; g2int idrsnum = 2; int i; @@ -216,7 +216,7 @@ main() { /* printf("%g %g\n", fld[i], fld_in[i]); */ if (fld[i] != fld_in[i]) - return G2C_ERROR; + return G2C_ERROR; } } printf("ok!\n"); @@ -231,25 +231,25 @@ main() * https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-3.shtml * for the template meaning. */ g2int idrstmpl[18] = { - 0, /* reference value (R) (IEEE 32-bit floating-point value) */ - 1, /* Binary scale factor (E) */ - 1, /* Decimal scale factor (D) */ - 8, /* Number of bits used for each packed value for simple packing, or for each group reference value for complex packing or spatial differencing */ - 0, /* Type of original field values (see Code Table 5.1) */ - 0, /* Group splitting method used (see Code Table 5.4) */ - 1, /* Missing value management used (see Code Table 5.5) */ - 0, /* Primary missing value substitute */ - 0, /* Secondary missing value substitute */ - 1, /* NG ― number of groups of data values into which field is split */ + 0, /* reference value (R) (IEEE 32-bit floating-point value) */ + 1, /* Binary scale factor (E) */ + 1, /* Decimal scale factor (D) */ + 8, /* Number of bits used for each packed value for simple packing, or for each group reference value for complex packing or spatial differencing */ + 0, /* Type of original field values (see Code Table 5.1) */ + 0, /* Group splitting method used (see Code Table 5.4) */ + 1, /* Missing value management used (see Code Table 5.5) */ + 0, /* Primary missing value substitute */ + 0, /* Secondary missing value substitute */ + 1, /* NG ― number of groups of data values into which field is split */ 16, /* Reference for group widths (see Note 12) */ - 8, /* Number of bits used for the group widths (after the reference value in octet 36 has been removed) */ - 4, /* Reference for group lengths (see Note 13) */ - 0, /* Length increment for the group lengths (see Note 14) */ - 0, /* True length of last group */ - 8, /* Number of bits used for the scaled group lengths (after subtraction of the reference value given in octets 38-41 and division by the length increment given in octet 42) */ - 1, /* Order of spatial difference (see Code Table 5.6) */ - 0 /* Number of octets required in the data section to specify extra descriptors needed for spatial differencing (octets 6-ww in data template 7.3) */ - }; + 8, /* Number of bits used for the group widths (after the reference value in octet 36 has been removed) */ + 4, /* Reference for group lengths (see Note 13) */ + 0, /* Length increment for the group lengths (see Note 14) */ + 0, /* True length of last group */ + 8, /* Number of bits used for the scaled group lengths (after subtraction of the reference value given in octets 38-41 and division by the length increment given in octet 42) */ + 1, /* Order of spatial difference (see Code Table 5.6) */ + 0 /* Number of octets required in the data section to specify extra descriptors needed for spatial differencing (octets 6-ww in data template 7.3) */ + }; g2int idrsnum = 3; int i; @@ -264,7 +264,7 @@ main() { /* printf("%g %g\n", fld[i], fld_in[i]); */ if (fld[i] != fld_in[i]) - return G2C_ERROR; + return G2C_ERROR; } } printf("ok!\n"); @@ -279,25 +279,25 @@ main() * https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-3.shtml * for the template meaning. */ g2int idrstmpl[18] = { - 0, /* reference value (R) (IEEE 32-bit floating-point value) */ - 1, /* Binary scale factor (E) */ - 1, /* Decimal scale factor (D) */ - 8, /* Number of bits used for each packed value for simple packing, or for each group reference value for complex packing or spatial differencing */ - 0, /* Type of original field values (see Code Table 5.1) */ - 0, /* Group splitting method used (see Code Table 5.4) */ - 1, /* Missing value management used (see Code Table 5.5) */ - 0, /* Primary missing value substitute */ - 0, /* Secondary missing value substitute */ - 1, /* NG ― number of groups of data values into which field is split */ + 0, /* reference value (R) (IEEE 32-bit floating-point value) */ + 1, /* Binary scale factor (E) */ + 1, /* Decimal scale factor (D) */ + 8, /* Number of bits used for each packed value for simple packing, or for each group reference value for complex packing or spatial differencing */ + 0, /* Type of original field values (see Code Table 5.1) */ + 0, /* Group splitting method used (see Code Table 5.4) */ + 1, /* Missing value management used (see Code Table 5.5) */ + 0, /* Primary missing value substitute */ + 0, /* Secondary missing value substitute */ + 1, /* NG ― number of groups of data values into which field is split */ 16, /* Reference for group widths (see Note 12) */ - 8, /* Number of bits used for the group widths (after the reference value in octet 36 has been removed) */ - 4, /* Reference for group lengths (see Note 13) */ - 0, /* Length increment for the group lengths (see Note 14) */ - 0, /* True length of last group */ - 8, /* Number of bits used for the scaled group lengths (after subtraction of the reference value given in octets 38-41 and division by the length increment given in octet 42) */ - 2, /* Order of spatial difference (see Code Table 5.6) */ - 0 /* Number of octets required in the data section to specify extra descriptors needed for spatial differencing (octets 6-ww in data template 7.3) */ - }; + 8, /* Number of bits used for the group widths (after the reference value in octet 36 has been removed) */ + 4, /* Reference for group lengths (see Note 13) */ + 0, /* Length increment for the group lengths (see Note 14) */ + 0, /* True length of last group */ + 8, /* Number of bits used for the scaled group lengths (after subtraction of the reference value given in octets 38-41 and division by the length increment given in octet 42) */ + 2, /* Order of spatial difference (see Code Table 5.6) */ + 0 /* Number of octets required in the data section to specify extra descriptors needed for spatial differencing (octets 6-ww in data template 7.3) */ + }; g2int idrsnum = 3; int i; @@ -312,7 +312,7 @@ main() { /* printf("%g %g\n", fld[i], fld_in[i]); */ if (fld[i] != fld_in[i]) - return G2C_ERROR; + return G2C_ERROR; } } printf("ok!\n"); @@ -328,23 +328,23 @@ main() * https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-2.shtml * for the template meaning. */ g2int idrstmpl[16] = { - 0, /* reference value (R) (IEEE 32-bit floating-point value) */ - 1, /* Binary scale factor (E) */ - 1, /* Decimal scale factor (D) */ - 8, /* Number of bits used for each packed value for simple packing, or for each group reference value for complex packing or spatial differencing */ - 0, /* Type of original field values (see Code Table 5.1) */ - 0, /* Group splitting method used (see Code Table 5.4) */ - 1, /* Missing value management used (see Code Table 5.5) */ - 0, /* Primary missing value substitute */ - 0, /* Secondary missing value substitute */ - 1, /* NG ― number of groups of data values into which field is split */ + 0, /* reference value (R) (IEEE 32-bit floating-point value) */ + 1, /* Binary scale factor (E) */ + 1, /* Decimal scale factor (D) */ + 8, /* Number of bits used for each packed value for simple packing, or for each group reference value for complex packing or spatial differencing */ + 0, /* Type of original field values (see Code Table 5.1) */ + 0, /* Group splitting method used (see Code Table 5.4) */ + 1, /* Missing value management used (see Code Table 5.5) */ + 0, /* Primary missing value substitute */ + 0, /* Secondary missing value substitute */ + 1, /* NG ― number of groups of data values into which field is split */ 16, /* Reference for group widths (see Note 12) */ - 8, /* Number of bits used for the group widths (after the reference value in octet 36 has been removed) */ - 4, /* Reference for group lengths (see Note 13) */ - 0, /* Length increment for the group lengths (see Note 14) */ - 0, /* True length of last group */ - 8 /* Number of bits used for the scaled group lengths (after subtraction of the reference value given in octets 38-41 and division by the length increment given in octet 42) */ - }; + 8, /* Number of bits used for the group widths (after the reference value in octet 36 has been removed) */ + 4, /* Reference for group lengths (see Note 13) */ + 0, /* Length increment for the group lengths (see Note 14) */ + 0, /* True length of last group */ + 8 /* Number of bits used for the scaled group lengths (after subtraction of the reference value given in octets 38-41 and division by the length increment given in octet 42) */ + }; g2int idrsnum = 2; int i; @@ -367,7 +367,7 @@ main() { /* printf("%g %g\n", fld[i], fld_in[i]); */ if (fld[i] != fld_in[i]) - return G2C_ERROR; + return G2C_ERROR; } } printf("ok!\n"); @@ -382,23 +382,23 @@ main() * https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-2.shtml * for the template meaning. */ g2int idrstmpl[16] = { - 0, /* reference value (R) (IEEE 32-bit floating-point value) */ - 1, /* Binary scale factor (E) */ - 1, /* Decimal scale factor (D) */ - 8, /* Number of bits used for each packed value for simple packing, or for each group reference value for complex packing or spatial differencing */ - 0, /* Type of original field values (see Code Table 5.1) */ - 0, /* Group splitting method used (see Code Table 5.4) */ - 0, /* Missing value management used (see Code Table 5.5) */ - 0, /* Primary missing value substitute */ - 0, /* Secondary missing value substitute */ - 1, /* NG ― number of groups of data values into which field is split */ + 0, /* reference value (R) (IEEE 32-bit floating-point value) */ + 1, /* Binary scale factor (E) */ + 1, /* Decimal scale factor (D) */ + 8, /* Number of bits used for each packed value for simple packing, or for each group reference value for complex packing or spatial differencing */ + 0, /* Type of original field values (see Code Table 5.1) */ + 0, /* Group splitting method used (see Code Table 5.4) */ + 0, /* Missing value management used (see Code Table 5.5) */ + 0, /* Primary missing value substitute */ + 0, /* Secondary missing value substitute */ + 1, /* NG ― number of groups of data values into which field is split */ 16, /* Reference for group widths (see Note 12) */ - 8, /* Number of bits used for the group widths (after the reference value in octet 36 has been removed) */ - 4, /* Reference for group lengths (see Note 13) */ - 0, /* Length increment for the group lengths (see Note 14) */ - 0, /* True length of last group */ - 8 /* Number of bits used for the scaled group lengths (after subtraction of the reference value given in octets 38-41 and division by the length increment given in octet 42) */ - }; + 8, /* Number of bits used for the group widths (after the reference value in octet 36 has been removed) */ + 4, /* Reference for group lengths (see Note 13) */ + 0, /* Length increment for the group lengths (see Note 14) */ + 0, /* True length of last group */ + 8 /* Number of bits used for the scaled group lengths (after subtraction of the reference value given in octets 38-41 and division by the length increment given in octet 42) */ + }; g2int idrsnum = 2; int i; @@ -413,7 +413,7 @@ main() { /* printf("%g %g\n", fld[i], fld_in[i]); */ if (fld[i] != fld_in[i]) - return G2C_ERROR; + return G2C_ERROR; } } printf("ok!\n"); @@ -429,23 +429,23 @@ main() * https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-2.shtml * for the template meaning. */ g2int idrstmpl[16] = { - 0, /* reference value (R) (IEEE 32-bit floating-point value) */ - 1, /* Binary scale factor (E) */ - 1, /* Decimal scale factor (D) */ - 8, /* Number of bits used for each packed value for simple packing, or for each group reference value for complex packing or spatial differencing */ - 0, /* Type of original field values (see Code Table 5.1) */ - 0, /* Group splitting method used (see Code Table 5.4) */ - 1, /* Missing value management used (see Code Table 5.5) */ - 2, /* Primary missing value substitute */ - 3, /* Secondary missing value substitute */ - 1, /* NG ― number of groups of data values into which field is split */ + 0, /* reference value (R) (IEEE 32-bit floating-point value) */ + 1, /* Binary scale factor (E) */ + 1, /* Decimal scale factor (D) */ + 8, /* Number of bits used for each packed value for simple packing, or for each group reference value for complex packing or spatial differencing */ + 0, /* Type of original field values (see Code Table 5.1) */ + 0, /* Group splitting method used (see Code Table 5.4) */ + 1, /* Missing value management used (see Code Table 5.5) */ + 2, /* Primary missing value substitute */ + 3, /* Secondary missing value substitute */ + 1, /* NG ― number of groups of data values into which field is split */ 16, /* Reference for group widths (see Note 12) */ - 8, /* Number of bits used for the group widths (after the reference value in octet 36 has been removed) */ - 4, /* Reference for group lengths (see Note 13) */ - 0, /* Length increment for the group lengths (see Note 14) */ - 0, /* True length of last group */ - 8 /* Number of bits used for the scaled group lengths (after subtraction of the reference value given in octets 38-41 and division by the length increment given in octet 42) */ - }; + 8, /* Number of bits used for the group widths (after the reference value in octet 36 has been removed) */ + 4, /* Reference for group lengths (see Note 13) */ + 0, /* Length increment for the group lengths (see Note 14) */ + 0, /* True length of last group */ + 8 /* Number of bits used for the scaled group lengths (after subtraction of the reference value given in octets 38-41 and division by the length increment given in octet 42) */ + }; g2int idrsnum = 2; int i; @@ -468,7 +468,7 @@ main() { /* printf("%g %g\n", fld[i], fld_in[i]); */ if (fld[i] != fld_in[i]) - return G2C_ERROR; + return G2C_ERROR; } } printf("ok!\n"); diff --git a/tests/tst_csv.c b/tests/tst_csv.c index b252980c..d7ec899f 100644 --- a/tests/tst_csv.c +++ b/tests/tst_csv.c @@ -4,39 +4,38 @@ * Ed Hartnett, Alyson Stahl 8/5/24 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" int main() { int ret; char desc[G2C_MAX_GRIB_DESC_LEN + 1]; - + printf("Testing CSV ingestion...\n"); if (g2c_csv_init()) - return G2C_ERROR; + return G2C_ERROR; if ((ret = g2c_find_desc("Code table 0.0", 0, desc))) - return ret; + return ret; if (strcmp("Meteorological products", desc)) - return G2C_ERROR; + return G2C_ERROR; if ((ret = g2c_find_desc_str("Code table 0.0", "0", desc))) - return ret; + return ret; if (strcmp("Meteorological products", desc)) - return G2C_ERROR; + return G2C_ERROR; /* Calling init again is harmless. */ if (g2c_csv_init()) - return G2C_ERROR; - + return G2C_ERROR; + g2c_free_tables(); /* Calling free again is harmless. */ g2c_free_tables(); - + printf("desc %s\n", desc); printf("SUCCESS!!!\n"); return G2C_NOERROR; } - diff --git a/tests/tst_decode.c b/tests/tst_decode.c index a2101214..84a4ff0e 100644 --- a/tests/tst_decode.c +++ b/tests/tst_decode.c @@ -8,7 +8,8 @@ */ #include "grib2_int.h" -int main() +int +main() { /* This is the GRIB2 message. */ unsigned char cgrib[] = { @@ -28,22 +29,20 @@ int main() 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0xff, 0x00, 0x00, 0x00, 0x15, 0x07, 0xff, 0xef, 0xf7, 0xe0, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x83, 0x38, 0xee, 0x3f, 0xa7, 0x80, 0x37, - 0x37, 0x37, 0x37 - }; + 0x37, 0x37, 0x37}; /* This is the data encoded in the GRIB2 message. */ - float fld_ok[121] = { /* 11x11 grid */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, - 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, - 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, - 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, - 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1 - }; + float fld_ok[121] = {/* 11x11 grid */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, + 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, + 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, + 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, + 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1}; int i; int ret; @@ -89,7 +88,7 @@ int main() return G2C_ERROR; /* Call g2c_unpack7() on our message. */ - if ((ret = g2c_unpack7(&cgrib[1360/8], igdsnum, 0, igdstmpl, idrsnum, 5, idrstmpl, ndpts, fld))) + if ((ret = g2c_unpack7(&cgrib[1360 / 8], igdsnum, 0, igdstmpl, idrsnum, 5, idrstmpl, ndpts, fld))) return ret; /* Check the data. */ @@ -108,7 +107,7 @@ int main() g2int listsec1_ok[13] = {7, 0, 2, 1, 1, 2021, 7, 14, 6, 0, 0, 0, 1}; g2int numfields; g2int numlocal; - gribfield* gfld = NULL; + gribfield *gfld = NULL; /* Call g2_info() on our message. */ /* g2c_set_log_level(10); */ diff --git a/tests/tst_degrib2_fast.c b/tests/tst_degrib2_fast.c index fca0bcf6..8a0cd7fa 100644 --- a/tests/tst_degrib2_fast.c +++ b/tests/tst_degrib2_fast.c @@ -16,7 +16,7 @@ #define REF_INDEX_FILE "data/ref_gdaswave.t00z.wcoast.0p16.f000.grb2index" #define TEST_INDEX_FILE "tst_gdaswave.t00z.wcoast.0p16.f000.grb2index" -/* The first message of the file has the following degrib2 output in the g2 project: +/* The first message of the file has the following degrib2 output in the g2 project: GRIB MESSAGE 1 starts at 1 diff --git a/tests/tst_degrib2_ftp_all.c b/tests/tst_degrib2_ftp_all.c index bd7ea929..d348631b 100644 --- a/tests/tst_degrib2_ftp_all.c +++ b/tests/tst_degrib2_ftp_all.c @@ -21,28 +21,26 @@ main() { #define NUM_FILES 11 char file[NUM_FILES][MAX_FILENAME_LEN + 1] = { - "data/seaice.t00z.grb.grib2", "data/gdaswave.t00z.wcoast.0p16.f000.grib2", + "data/seaice.t00z.grb.grib2", "data/gdaswave.t00z.wcoast.0p16.f000.grib2", "data/blend.t19z.core.f001.co.grib2", "data/cmc_geavg.t12z.pgrb2a.0p50.f000", "data/flxf2022111712.01.2022111712.grb2", "data/GLOBAL.grib2.2022103000.0000", "data/hiresw.t00z.arw_5km.f00.hi.grib2", "data/naefs_ge10pt.t12z.pgrb2a.0p50_bcf003", - "data/rap.t00z.awp130pgrbf00.grib2", - "data/sgx_nwps_CG3_20221117_1200.grib2", "data/aqm.t12z.max_8hr_o3.227.grib2" - }; + "data/rap.t00z.awp130pgrbf00.grib2", + "data/sgx_nwps_CG3_20221117_1200.grib2", "data/aqm.t12z.max_8hr_o3.227.grib2"}; char index_file[NUM_FILES][MAX_FILENAME_LEN + 1] = { - "seaice.t00z.grb.grib2.idx", "gdaswave.t00z.wcoast.0p16.f000.grib2.idx", + "seaice.t00z.grb.grib2.idx", "gdaswave.t00z.wcoast.0p16.f000.grib2.idx", "blend.t19z.core.f001.co.grib2.idx", "cmc_geavg.t12z.pgrb2a.0p50.f000.idx", "flxf2022111712.01.2022111712.grb2.idx", "GLOBAL.grib2.2022103000.0000.idx", "hiresw.t00z.arw_5km.f00.hi.grib2.idx", "naefs_ge10pt.t12z.pgrb2a.0p50_bcf003.idx", - "rap.t00z.awp130pgrbf00.grib2.idx", - "sgx_nwps_CG3_20221117_1200.grib2.idx", "aqm.t12z.max_8hr_o3.227.grib2.idx" - }; - int expected_nmsg[NUM_FILES] = {1, 19, 72, 72, 99, 219, 239, 49, 306, 1305, 3}; + "rap.t00z.awp130pgrbf00.grib2.idx", + "sgx_nwps_CG3_20221117_1200.grib2.idx", "aqm.t12z.max_8hr_o3.227.grib2.idx"}; + int expected_nmsg[NUM_FILES] = {1, 19, 72, 72, 99, 219, 239, 49, 306, 1305, 3}; int g2cid; int num_msg; int f; int t; int ret; - g2c_set_log_level(15); + g2c_set_log_level(15); /* for (f = 0; f < NUM_FILES; f++) */ for (f = 0; f < 1; f++) @@ -52,7 +50,7 @@ main() { char degrib2_file[MAX_FILENAME_LEN + 9]; char ref_degrib2_file[MAX_FILENAME_LEN + 20]; - + /* Open the data file with and without the index file. */ if (t) { @@ -65,36 +63,36 @@ main() printf("\ttesting degrib2 on file %s downloaded via FTP without using index...", file[f]); if ((ret = g2c_open(file[f], 0, &g2cid))) return ret; - if ((ret = g2c_write_index(g2cid, 0, index_file[f]))) + if ((ret = g2c_write_index(g2cid, 0, index_file[f]))) return ret; } - + /* Check some stuff. */ if ((ret = g2c_inq(g2cid, &num_msg))) return ret; - if (num_msg != expected_nmsg[f]) - { - printf("num_msg %d expected %d\n", num_msg, expected_nmsg[f]); - return G2C_ERROR; - } - + if (num_msg != expected_nmsg[f]) + { + printf("num_msg %d expected %d\n", num_msg, expected_nmsg[f]); + return G2C_ERROR; + } + /* Output a degrib2 file. */ sprintf(degrib2_file, "%s.degrib2", basename(file[f])); if ((ret = g2c_degrib2(g2cid, degrib2_file))) return ret; - + /* Close the file. */ if ((ret = g2c_close(g2cid))) return ret; - + /* Compare the degrib2 output to our reference file. */ sprintf(ref_degrib2_file, "data/ref_%s.degrib2", basename(file[f])); if ((ret = compare_degrib2_files2(degrib2_file, ref_degrib2_file))) - { - printf("compare failed!\n"); - /*return ret;*/ - } - printf("\tok!\n"); + { + printf("compare failed!\n"); + /*return ret;*/ + } + printf("\tok!\n"); } } } @@ -105,11 +103,9 @@ main() #define NUM_LARGE_FILES 1 #define FV3_NUM_MSG 1081 char file[NUM_LARGE_FILES][MAX_FILENAME_LEN + 1] = { - "data/fv3lam.t00z.prslev.f000.grib2" - }; + "data/fv3lam.t00z.prslev.f000.grib2"}; char index_file[NUM_LARGE_FILES][MAX_FILENAME_LEN + 1] = { - "fv3lam.t00z.prslev.f000.grib2.idx" - }; + "fv3lam.t00z.prslev.f000.grib2.idx"}; int g2cid; int num_msg; int f; @@ -123,42 +119,42 @@ main() { char degrib2_file[MAX_FILENAME_LEN + 9]; char ref_degrib2_file[MAX_FILENAME_LEN + 20]; - + /* Open the data file with and without the index file. */ if (t) { - /* Open the data with the index file. */ + /* Open the data with the index file. */ printf("\ttesting degrib2 on file %s downloaded via FTP using index...", file[f]); if ((ret = g2c_open_index(file[f], index_file[f], 0, &g2cid))) return ret; } else { - /* Open the data and create the index file. */ + /* Open the data and create the index file. */ printf("\ttesting degrib2 on file %s downloaded via FTP without using index...", file[f]); if ((ret = g2c_open(file[f], 0, &g2cid))) return ret; - if ((ret = g2c_write_index(g2cid, 0, index_file[f]))) + if ((ret = g2c_write_index(g2cid, 0, index_file[f]))) return ret; - } - + } + /* Check some stuff. */ if ((ret = g2c_inq(g2cid, &num_msg))) return ret; printf("num_msg %d\n", num_msg); if (num_msg != FV3_NUM_MSG) return G2C_ERROR; - + /* Output a degrib2 file. */ sprintf(degrib2_file, "%s.degrib2", basename(file[f])); if ((ret = g2c_degrib2(g2cid, degrib2_file))) return ret; - + /* Close the file. */ if ((ret = g2c_close(g2cid))) return ret; - + /* Compare the degrib2 output to our reference file. */ sprintf(ref_degrib2_file, "data/ref_%s.degrib2", basename(file[f])); printf("\tcomparing degrib2 output to reference file %s...\n", ref_degrib2_file); diff --git a/tests/tst_degrib2_int.c b/tests/tst_degrib2_int.c index 6509dc58..8af53509 100644 --- a/tests/tst_degrib2_int.c +++ b/tests/tst_degrib2_int.c @@ -23,19 +23,18 @@ main() {0, 21, 2, 255, 104, 65535, 255, 1, 1, 103, 0, 2, 255, 0, 0}, {19, 238, 2, 255, 104, 65535, 255, 1, 1, 100, 0, 40000, 100, 0, 30000}, {1, 228, 2, 255, 104, 65535, 255, 1, 0, 1, 0, 0, 255, 0, 0, 2022, 11, 17, 20, 0, 0, 1, 0, 1, 2, 1, 1, 1, 0}, - {0, 192, 4, 70, 70, 0, 0, 1, 0, 106, 0, 0, 106, 1, 1, 0, 20}, - {0, 192, 2, 0, 98, 0, 0, 1, 0, 106, 2, 0, 106, 2, 10}, - {3, 1, 4, 70, 70, 0, 0, 1, 0, 101, 0, 0, 255, 0, 0, 0, 20}, - {0, 27, 2, 255, 104, 65535, 255, 1, 1, 103, 0, 610, 100, 0, 40000, 241, 241, 241}, - {1, 8, 2, 255, 104, 65535, 255, 1, 0, 1, 0, 0, 255, 0, 0, 255, 255, 1, -127, 255, 3, 254, 2022, 11, 17, 20, 0, 0, 1, 0, 1, 2, 1, 1, 1, 0}, - {19, 236, 2, 255, 104, 65535, 255, 1, 1, 102, 0, 0, 255, 0, 0}, - {0, 0, 2, 0, 116, 0, 0, 1, 0, 108, 0, 3000, 108, 0, 0}, - {14, 201, 2, 0, 89, 0, 0, 1, -1, 105, 0, 1, 255, -127, -2147483647, 2022, 11, 2, 10, 0, 0, 1, 0, 0, 2, 1, 23, 255, 0} - }; + {0, 192, 4, 70, 70, 0, 0, 1, 0, 106, 0, 0, 106, 1, 1, 0, 20}, + {0, 192, 2, 0, 98, 0, 0, 1, 0, 106, 2, 0, 106, 2, 10}, + {3, 1, 4, 70, 70, 0, 0, 1, 0, 101, 0, 0, 255, 0, 0, 0, 20}, + {0, 27, 2, 255, 104, 65535, 255, 1, 1, 103, 0, 610, 100, 0, 40000, 241, 241, 241}, + {1, 8, 2, 255, 104, 65535, 255, 1, 0, 1, 0, 0, 255, 0, 0, 255, 255, 1, -127, 255, 3, 254, 2022, 11, 17, 20, 0, 0, 1, 0, 1, 2, 1, 1, 1, 0}, + {19, 236, 2, 255, 104, 65535, 255, 1, 1, 102, 0, 0, 255, 0, 0}, + {0, 0, 2, 0, 116, 0, 0, 1, 0, 108, 0, 3000, 108, 0, 0}, + {14, 201, 2, 0, 89, 0, 0, 1, -1, 105, 0, 1, 255, -127, -2147483647, 2022, 11, 2, 10, 0, 0, 1, 0, 0, 2, 1, 23, 255, 0}}; char expected_level_desc[NUM_PROD_TEST][G2C_MAX_GRIB_LEVEL_DESC_LEN + 1] = { " Surface", " 800 mb", "2 m above ground", " 400 - 300 mb", " Surface", "0 - .1 m DBLY", " 0 - .10 m DBLY", " Mean Sea Level", " 103 (Unknown Lvl)", - " Surface", "0 m above MSL", " 30 - 0 mb SPDY", "1 hybrid lvl"}; + " Surface", "0 m above MSL", " 30 - 0 mb SPDY", "1 hybrid lvl"}; char level_desc[G2C_MAX_GRIB_LEVEL_DESC_LEN + 1]; short year[NUM_PROD_TEST] = {2021, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022}; unsigned char month[NUM_PROD_TEST] = {11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11}; @@ -49,23 +48,22 @@ main() "valid 1 hour after 2022110612:00:00", "valid 1 hour after 2022110612:00:00", "(0 -1 hr) valid 0 hour after 2022111719:00:00 to 2022111720:00:00", - "valid 0 hour after 2022111712:00:00", - "valid 0 hour after 2022111712:00:00", - "valid 0 hour after 2022111712:00:00", - "valid 1 hour after 2022111719:00:00", - "(0 -1 hr) valid 0 hour after 2022111719:00:00 to 2022111720:00:00", - "valid 1 hour after 2022111719:00:00", - "valid 0 hour after 2022111700:00:00", - "(1 -24) valid 1 hour before 2022110112:00:00 to 2022110210:00:00" - }; + "valid 0 hour after 2022111712:00:00", + "valid 0 hour after 2022111712:00:00", + "valid 0 hour after 2022111712:00:00", + "valid 1 hour after 2022111719:00:00", + "(0 -1 hr) valid 0 hour after 2022111719:00:00 to 2022111720:00:00", + "valid 1 hour after 2022111719:00:00", + "valid 0 hour after 2022111700:00:00", + "(1 -24) valid 1 hour before 2022110112:00:00 to 2022110210:00:00"}; int t; int ret; for (t = 0; t < NUM_PROD_TEST; t++) { char date_time[DATE_TIME_LEN + 1]; - /* printf("\nt %d\n", t); */ - + /* printf("\nt %d\n", t); */ + /* First test the level description. */ if ((ret = g2c_get_level_desc(prod_template_num[t], prod_template_value[t], level_desc))) return ret; diff --git a/tests/tst_drstemplates.c b/tests/tst_drstemplates.c index 959b1ad0..2609f115 100644 --- a/tests/tst_drstemplates.c +++ b/tests/tst_drstemplates.c @@ -4,9 +4,9 @@ * Ed Hartnett 10/25/21 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /* Prototypes. */ g2int getdrsindex(g2int number); @@ -35,7 +35,7 @@ main() printf("ok!\n"); printf("Testing simple g2c_get_drs_template() call..."); { - + int maplen, needext; int map[G2C_MAX_DRS_TEMPLATE_MAPLEN]; int expected_map[5] = {4, -2, -2, 1, 1}; @@ -45,7 +45,7 @@ main() /* This won't work. */ if (g2c_get_drs_template(G2C_MAX_DRS_TEMPLATE + 1, &maplen, map, &needext) != G2C_ENOTEMPLATE) return G2C_ERROR; - + /* Check for one that's there. */ if ((ret = g2c_get_drs_template(0, &maplen, map, &needext))) return ret; @@ -78,7 +78,6 @@ main() tmpl = extdrstemplate(-1, list); if (tmpl) return G2C_ERROR; - } printf("ok!\n"); printf("Testing all getdrstemplate() calls...\n"); @@ -87,17 +86,17 @@ main() int number[NUM_TEST] = {0, 2, 3, 50, 51, 40, 41, 40000, 40010}; int expected_maplen[NUM_TEST] = {5, 16, 18, 5, 10, 7, 5, 7, 5}; int expected_map[NUM_TEST][18] = { - {4, -2, -2, 1, 1}, /* 0 */ - {4, -2, -2, 1, 1, 1, 1, 4, 4, 4, 1, 1, 4, 1, 4, 1}, /* 2 */ + {4, -2, -2, 1, 1}, /* 0 */ + {4, -2, -2, 1, 1, 1, 1, 4, 4, 4, 1, 1, 4, 1, 4, 1}, /* 2 */ {4, -2, -2, 1, 1, 1, 1, 4, 4, 4, 1, 1, 4, 1, 4, 1, 1, 1}, /* 3 */ - {4, -2, -2, 1, 4}, /* 50 */ - {4, -2, -2, 1, -4, 2, 2, 2, 4, 1}, /* 51 */ - {4, -2, -2, 1, 1, 1, 1}, /* 40 */ - {4, -2, -2, 1, 1}, /* 41 */ - {4, -2, -2, 1, 1, 1, 1}, /* 40000 */ - {4, -2, -2, 1, 1} /* 40010 */ + {4, -2, -2, 1, 4}, /* 50 */ + {4, -2, -2, 1, -4, 2, 2, 2, 4, 1}, /* 51 */ + {4, -2, -2, 1, 1, 1, 1}, /* 40 */ + {4, -2, -2, 1, 1}, /* 41 */ + {4, -2, -2, 1, 1, 1, 1}, /* 40000 */ + {4, -2, -2, 1, 1} /* 40010 */ }; - + int t; for (t = 0; t < NUM_TEST; t++) @@ -106,7 +105,7 @@ main() { gtemplate *tmpl; int m; - + tmpl = getdrstemplate(number[t]); if (!tmpl) return G2C_ERROR; @@ -124,7 +123,7 @@ main() int map[G2C_MAX_DRS_TEMPLATE_MAPLEN]; int m; int ret; - + if ((ret = g2c_get_drs_template(number[t], &maplen, map, &needext))) return ret; if (maplen != expected_maplen[t] || needext) diff --git a/tests/tst_error.c b/tests/tst_error.c index 04e49faa..49f5db4e 100644 --- a/tests/tst_error.c +++ b/tests/tst_error.c @@ -10,67 +10,64 @@ #define MAX_LEN 512 -int main() +int +main() { printf("Testing error handling.\n"); if (strncmp(g2c_strerror(0), "No error", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-50), "GRIB2 header not found", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-51), "GRIB message is already complete.", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-52), "Name too long", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-53), "Invalid input", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-54), "Error reading file", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-55), "Bad ID", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-56), "Too many files open", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-57), "Out of memory", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-58), "Error decoding message", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-59), "No GRIB message found", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-60), "Error parsing XML", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-61), "Table or entry not found", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-62), "Not GRIB 2", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-63), "Cannot find section", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-64), "Cannot find end of GRIB message", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-65), "End of message in wrong place", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-66), "Invalid section number", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-67), "Error encoding/decoding JPEG data", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-68), "Error encoding/decoding PNG data", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-69), "Template not found", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-70), "Template problem", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-71), "Parameter not found", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-72), "Product not found", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(-73), "Bad type", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; if (strncmp(g2c_strerror(999), "Unknown Error", MAX_LEN)) - return G2C_ERROR; + return G2C_ERROR; printf("SUCCESS!\n"); return 0; } - - - - diff --git a/tests/tst_files.c b/tests/tst_files.c index 938f8c59..1c577925 100644 --- a/tests/tst_files.c +++ b/tests/tst_files.c @@ -4,9 +4,9 @@ * Ed Hartnett 8/16/22 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" #define FILE_NAME "tst_files.grib2" #define WAVE_FILE "data/gdaswave.t00z.wcoast.0p16.f000.grib2" @@ -28,19 +28,19 @@ tst_g2c_open_twice(void *t) ret = g2c_open(WAVE_FILE, 0, &g2cid); if (!ret) ret = g2c_close(g2cid); - + /* Try it again. */ if (!ret) ret = g2c_open(WAVE_FILE, 0, &g2cid); if (!ret) ret = g2c_close(g2cid); - #ifdef PTHREADS +#ifdef PTHREADS /* printf("ret %d\n", ret); */ pthread_exit(&ret); - #endif - - return ret ? (void *)1: NULL; +#endif + + return ret ? (void *)1 : NULL; } int @@ -55,13 +55,13 @@ main() int t0 = 0, t1 = 1; int ret = G2C_NOERROR; int *pret = &ret; - + /* Create independent threads each of which will execute function */ if (pthread_create(&thread1, NULL, tst_g2c_open_twice, (void *)&t0)) return G2C_ERROR; if (pthread_create(&thread2, NULL, tst_g2c_open_twice, (void *)&t1)) return G2C_ERROR; - + /* Wait till threads are complete before main continues. Unless we */ /* wait we run the risk of executing an exit which will terminate */ /* the process and all threads before the threads have completed. */ @@ -71,7 +71,7 @@ main() return G2C_ERROR; if (ret) return G2C_ERROR; - + #else /* No threads, run the test once. */ if (tst_g2c_open_twice(NULL)) @@ -118,66 +118,66 @@ main() /* printf("ok!\n"); */ printf("Testing g2c_find_msg2 on file %s...", WAVE_FILE); { - int g2cid; - size_t bytes_to_msg, bytes_in_msg; - size_t test_buf_size[NUM_BUF_SIZE_TESTS] = {100, 200, 1024, 2000, 3000, 4000}; - int i; - int ret; - - /* g2c_set_log_level(4); */ - if ((ret = g2c_open(WAVE_FILE, 0, &g2cid))) - return ret; - for (i = 0; i < NUM_BUF_SIZE_TESTS; i++) - { - if ((ret = g2c_find_msg2(g2cid, 0, test_buf_size[i], &bytes_to_msg, &bytes_in_msg))) - return ret; - /* printf("bytes_to_msg %ld bytes_in_msg %ld\n", bytes_to_msg, bytes_in_msg); */ - if (bytes_to_msg != 0 || bytes_in_msg != 15254) - return G2C_ERROR; - } - if ((ret = g2c_close(g2cid))) - return ret; + int g2cid; + size_t bytes_to_msg, bytes_in_msg; + size_t test_buf_size[NUM_BUF_SIZE_TESTS] = {100, 200, 1024, 2000, 3000, 4000}; + int i; + int ret; + + /* g2c_set_log_level(4); */ + if ((ret = g2c_open(WAVE_FILE, 0, &g2cid))) + return ret; + for (i = 0; i < NUM_BUF_SIZE_TESTS; i++) + { + if ((ret = g2c_find_msg2(g2cid, 0, test_buf_size[i], &bytes_to_msg, &bytes_in_msg))) + return ret; + /* printf("bytes_to_msg %ld bytes_in_msg %ld\n", bytes_to_msg, bytes_in_msg); */ + if (bytes_to_msg != 0 || bytes_in_msg != 15254) + return G2C_ERROR; + } + if ((ret = g2c_close(g2cid))) + return ret; } printf("ok!\n"); printf("Testing g2c_get_msg on file %s...", WAVE_FILE); { - int g2cid; - size_t bytes_to_msg, bytes_in_msg; - size_t test_buf_size[NUM_BUF_SIZE_TESTS] = {100, 200, 1024, 2000, 3000, 4000}; - unsigned char *cbuf = NULL; - int i; + int g2cid; + size_t bytes_to_msg, bytes_in_msg; + size_t test_buf_size[NUM_BUF_SIZE_TESTS] = {100, 200, 1024, 2000, 3000, 4000}; + unsigned char *cbuf = NULL; + int i; int num_msg; - int ret; + int ret; - if ((ret = g2c_open(WAVE_FILE, 0, &g2cid))) - return ret; + if ((ret = g2c_open(WAVE_FILE, 0, &g2cid))) + return ret; if ((ret = g2c_inq(g2cid, &num_msg))) return ret; if (num_msg != 19) return G2C_ERROR; - for (i = 0; i < NUM_BUF_SIZE_TESTS; i++) - { - - if ((ret = g2c_get_msg(g2cid, 0, test_buf_size[i], &bytes_to_msg, &bytes_in_msg, - &cbuf))) - return ret; - /* for (i = 0; i < 10; i++) */ - /* printf("cbuf[%d] = %2x\n", i, cbuf[i]); */ - /* printf("bytes_to_msg %ld bytes_in_msg %ld\n", bytes_to_msg, bytes_in_msg); */ - if (bytes_to_msg != 0 || bytes_in_msg != 15254) - return G2C_ERROR; - - /* Learn about this message. */ - { - g2int listsec0[3], listsec1[13], numfields, numlocal; - if ((ret = g2_info(cbuf, listsec0, listsec1, &numfields, &numlocal))) - return G2C_EMSG; - } - - free(cbuf); - } - if ((ret = g2c_close(g2cid))) - return ret; + for (i = 0; i < NUM_BUF_SIZE_TESTS; i++) + { + + if ((ret = g2c_get_msg(g2cid, 0, test_buf_size[i], &bytes_to_msg, &bytes_in_msg, + &cbuf))) + return ret; + /* for (i = 0; i < 10; i++) */ + /* printf("cbuf[%d] = %2x\n", i, cbuf[i]); */ + /* printf("bytes_to_msg %ld bytes_in_msg %ld\n", bytes_to_msg, bytes_in_msg); */ + if (bytes_to_msg != 0 || bytes_in_msg != 15254) + return G2C_ERROR; + + /* Learn about this message. */ + { + g2int listsec0[3], listsec1[13], numfields, numlocal; + if ((ret = g2_info(cbuf, listsec0, listsec1, &numfields, &numlocal))) + return G2C_EMSG; + } + + free(cbuf); + } + if ((ret = g2c_close(g2cid))) + return ret; } printf("ok!\n"); #ifdef JPEG @@ -186,18 +186,17 @@ main() int g2cid; int num_data_points; float *data; - float expected_data[100] = { /* The first 100 values. */ - 14.76, 14.76, 14.51, 14.2, 13.92, 13.89, 13.95, 14.1, 14.27, 14.31, - 14.24, 14.11, 13.91, 13.61, 13.2, 12.98, 12.95, 12.73, 12.2, 11.58, - 11.18, 11.13, 11.21, 11.26, 11.32, 11.36, 11.5, 11.72, 11.87, 11.96, - 11.97, 11.95, 11.99, 12.01, 11.75, 11.42, 11.23, 11.07, 10.83, 10.52, - 10.22, 10.03, 10.22, 8.7, 9.25, 8.2, 13.83, 14.07, 14.2, 14.12, - 13.86, 13.55, 13.46, 13.46, 13.61, 13.72, 13.94, 13.92, 13.8, 13.68, - 13.47, 13.01, 12.54, 12.47, 12.48, 12.25, 11.72, 11.09, 10.71, 10.68, - 10.87, 11.02, 11.08, 11.19, 11.4, 11.69, 11.85, 11.92, 12.03, 12.03, - 11.78, 11.34, 10.95, 10.62, 10.33, 10.13, 9.99, 9.84, 9.67, 9.49, - 9.44, 9.02, 8.93, 8.03, 7.66, 14.63, 14.47, 14.38, 14.31, 14.33 - }; + float expected_data[100] = {/* The first 100 values. */ + 14.76, 14.76, 14.51, 14.2, 13.92, 13.89, 13.95, 14.1, 14.27, 14.31, + 14.24, 14.11, 13.91, 13.61, 13.2, 12.98, 12.95, 12.73, 12.2, 11.58, + 11.18, 11.13, 11.21, 11.26, 11.32, 11.36, 11.5, 11.72, 11.87, 11.96, + 11.97, 11.95, 11.99, 12.01, 11.75, 11.42, 11.23, 11.07, 10.83, 10.52, + 10.22, 10.03, 10.22, 8.7, 9.25, 8.2, 13.83, 14.07, 14.2, 14.12, + 13.86, 13.55, 13.46, 13.46, 13.61, 13.72, 13.94, 13.92, 13.8, 13.68, + 13.47, 13.01, 12.54, 12.47, 12.48, 12.25, 11.72, 11.09, 10.71, 10.68, + 10.87, 11.02, 11.08, 11.19, 11.4, 11.69, 11.85, 11.92, 12.03, 12.03, + 11.78, 11.34, 10.95, 10.62, 10.33, 10.13, 9.99, 9.84, 9.67, 9.49, + 9.44, 9.02, 8.93, 8.03, 7.66, 14.63, 14.47, 14.38, 14.31, 14.33}; int i; int ret; @@ -212,7 +211,7 @@ main() /* Allocate storage for the data. */ if (!(data = malloc(num_data_points * sizeof(float)))) return G2C_ERROR; - + /* Get the data from message 0, product 0. */ if ((ret = g2c_get_prod(g2cid, 0, 0, NULL, data))) return ret; @@ -239,7 +238,7 @@ main() int ret; /* Open GRIB2 file. */ - g2c_set_log_level(10); + g2c_set_log_level(10); if ((ret = g2c_open(GDAS_FILE, 0, &g2cid))) return ret; @@ -254,7 +253,7 @@ main() int num_fields, num_local; short center, subcenter; unsigned char master_version, local_version; - + if ((ret = g2c_inq_msg(g2cid, m, &discipline, &num_fields, &num_local, ¢er, &subcenter, &master_version, &local_version))) return ret; @@ -285,8 +284,8 @@ main() int gds_template_len, gds_template[G2C_MAX_GDS_TEMPLATE_MAPLEN]; int drs_template_len, drs_template[G2C_MAX_DRS_TEMPLATE_MAPLEN]; int t; - - if ((ret = g2c_inq_prod(g2cid, m, 0, &pds_template_len, pds_template, + + if ((ret = g2c_inq_prod(g2cid, m, 0, &pds_template_len, pds_template, &gds_template_len, gds_template, &drs_template_len, drs_template))) return ret; @@ -308,7 +307,7 @@ main() printf("}\n"); } } - + /* Close the file. */ if ((ret = g2c_close(g2cid))) return ret; diff --git a/tests/tst_g2_addfield.c b/tests/tst_g2_addfield.c index 3558fe62..82b382b8 100644 --- a/tests/tst_g2_addfield.c +++ b/tests/tst_g2_addfield.c @@ -4,9 +4,9 @@ * Ed Hartnett 10/25/21 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" #define SEC0_LEN 16 #define SEC1_LEN 21 @@ -28,17 +28,17 @@ main() g2int igds[5] = {0, 4, 0, 0, 0}; g2int igdstmpl[19] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}; unsigned char expected_cgrib[FULL_MSG_LEN] = {0x47, 0x52, 0x49, 0x42, 0x00, 0x00, 0x01, 0x02, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb6, 0x00, 0x00, 0x00, 0x15, 0x01, 0x00, 0x07, 0x00, 0x04, - 0x18, 0x00, 0x00, 0x07, 0xe5, 0x0a, 0x18, 0x06, 0x36, 0x3b, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x48, - 0x03, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, - 0x03, 0x00, 0x00, 0x00, 0x04, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, - 0x00, 0x08, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, - 0x00, 0x0c, 0x0d, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x11, 0x12, 0x00, 0x00, 0x00, 0x22, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, - 0x03, 0x04, 0x00, 0x05, 0x06, 0x07, 0x00, 0x00, 0x00, 0x08, 0x09, 0x0a, 0x00, 0x00, 0x00, 0x0b, - 0x0c, 0x0d, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x15, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, - 0x00, 0x42, 0xc8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x07, 0x06, - 0x00, 0xf0, 0x00, 0x00, 0x00, 0x07, 0x07, 0x0a, 0x60, 0x37, 0x37, 0x37, 0x37}; + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb6, 0x00, 0x00, 0x00, 0x15, 0x01, 0x00, 0x07, 0x00, 0x04, + 0x18, 0x00, 0x00, 0x07, 0xe5, 0x0a, 0x18, 0x06, 0x36, 0x3b, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x48, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, + 0x03, 0x00, 0x00, 0x00, 0x04, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, + 0x00, 0x08, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, + 0x00, 0x0c, 0x0d, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x11, 0x12, 0x00, 0x00, 0x00, 0x22, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, + 0x03, 0x04, 0x00, 0x05, 0x06, 0x07, 0x00, 0x00, 0x00, 0x08, 0x09, 0x0a, 0x00, 0x00, 0x00, 0x0b, + 0x0c, 0x0d, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x15, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, + 0x00, 0x42, 0xc8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x07, 0x06, + 0x00, 0xf0, 0x00, 0x00, 0x00, 0x07, 0x07, 0x0a, 0x60, 0x37, 0x37, 0x37, 0x37}; unsigned char old_val; unsigned char old_val1, old_val2, old_val3; /* Analysis or forecast at a horizontal level or in a @@ -62,9 +62,9 @@ main() int i; int ret; - /* Initialize empty message to quiet valgrind errors. */ - for (i = 0; i < FULL_MSG_LEN; i++) - cgrib[i] = 0; + /* Initialize empty message to quiet valgrind errors. */ + for (i = 0; i < FULL_MSG_LEN; i++) + cgrib[i] = 0; /* Try to use g2_info() to learn about our messaage - won't * work, we haven't created a message yet. */ @@ -114,7 +114,7 @@ main() /* Change the first char of the message. Just to be dumb. */ old_val = cgrib[0]; cgrib[0] = 0; - + /* Try to add section 8 - this will fail because we changed * first char of message. */ if ((ret = g2_gribend(cgrib)) != -1) @@ -122,11 +122,11 @@ main() /* Change the first char back. */ cgrib[0] = old_val; - + /* Mess up section byte counts. */ old_val = cgrib[18]; cgrib[18] = 99; - + /* Try to add section 8 - this will fail because of bad * section count. */ if ((ret = g2_gribend(cgrib)) != G2_BAD_SEC_COUNTS) @@ -134,7 +134,7 @@ main() /* Change the section count back. */ cgrib[18] = old_val; - + /* Try to use g2_info() to learn about our messaage - won't * work, message must be ended first. This fails CI due to * memory leak. See @@ -149,7 +149,7 @@ main() /* Try to add section 8 - won't work. */ if ((ret = g2_gribend(cgrib)) != G2_ADD_MSG_COMPLETE) return G2C_ERROR; - + /* Try to add the local section. Won't work, message is * already ended. */ if ((ret = g2_addlocal(cgrib, csec2, lcsec2)) != -2) @@ -187,7 +187,7 @@ main() /* Change the GRIB version of the message. Just to be dumb again. */ old_val = cgrib[7]; cgrib[7] = 0; - + /* Use g2_info() to learn about our messaage. */ if ((ret = g2_info(cgrib, listsec0_in, listsec1_in, &numfields, &numlocal)) != 2) return G2C_ERROR; @@ -284,12 +284,12 @@ main() if (gfld->ipdtmpl[i] != ipdstmpl[i]) return G2C_ERROR; - /* Try the g2_miss() function. */ - float rmiss[1]; - int nmiss; - g2_miss(gfld, rmiss, &nmiss); - if (nmiss) - return G2C_ERROR; + /* Try the g2_miss() function. */ + float rmiss[1]; + int nmiss; + g2_miss(gfld, rmiss, &nmiss); + if (nmiss) + return G2C_ERROR; /* Free the memory. */ g2_free(gfld); diff --git a/tests/tst_g2_addgrid.c b/tests/tst_g2_addgrid.c index 5f04b56d..60574509 100644 --- a/tests/tst_g2_addgrid.c +++ b/tests/tst_g2_addgrid.c @@ -4,8 +4,8 @@ * Ed Hartnett 10/25/21 */ -#include #include "grib2_int.h" +#include #define SEC0_LEN 16 #define SEC1_LEN 21 @@ -43,10 +43,10 @@ main() g2int igds[5] = {0, 4, 0, 0, 0}; g2int igdstmpl[19] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}; unsigned char expected_cgrib[MSG_LEN] = {71, 82, 73, 66, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, - 109, 0, 0, 0, 21, 1, 0, 7, 0, 4, 24, 0, 0, 7, 229, 10, 24, 6, 54, 59, 7, 192, 0, 0, 0, - 72, 3, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 3, 0, 0, 0, 4, 5, 0, 0, 0, 6, 0, 0, - 0, 7, 0, 0, 0, 8, 0, 0, 0, 9, 0, 0, 0, 10, 0, 0, 0, 11, 0, 0, 0, 12, 13, 0, 0, 0, 14, - 0, 0, 0, 15, 0, 0, 0, 16, 0, 0, 0, 17, 18}; + 109, 0, 0, 0, 21, 1, 0, 7, 0, 4, 24, 0, 0, 7, 229, 10, 24, 6, 54, 59, 7, 192, 0, 0, 0, + 72, 3, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 3, 0, 0, 0, 4, 5, 0, 0, 0, 6, 0, 0, + 0, 7, 0, 0, 0, 8, 0, 0, 0, 9, 0, 0, 0, 10, 0, 0, 0, 11, 0, 0, 0, 12, 13, 0, 0, 0, 14, + 0, 0, 0, 15, 0, 0, 0, 16, 0, 0, 0, 17, 18}; unsigned char old_val; int i; int ret; @@ -61,7 +61,7 @@ main() /* Try to add the grid. Won't work, bad section length. */ if ((ret = g2_addgrid(cgrib, igds, igdstmpl, NULL, 0)) != -3) return G2C_ERROR; - + /* Fix the section length. */ cgrib[19] = old_val; @@ -84,11 +84,9 @@ main() /* Try to add section 3 again. Won't work. */ if ((ret = g2_addgrid(cgrib, igds, igdstmpl, NULL, 0)) != -4) return G2C_ERROR; - } printf("ok!\n"); - /* This test can't work because of the memory leak described in * https://github.com/NOAA-EMC/NCEPLIBS-g2c/issues/150. */ /* printf("Testing g2_addgrid() call with grid def template number 5..."); */ @@ -158,16 +156,16 @@ main() printf("Testing g2_addgrid() call with grid def template number 120..."); { #define MSG_LEN_120 84 - unsigned char cgrib[MSG_LEN_120+ 50]; + unsigned char cgrib[MSG_LEN_120 + 50]; g2int lencurr; g2int listsec0[2] = {1, 2}; g2int listsec1[13] = {7, 4, 24, 0, 0, 2021, 10, 24, 6, 54, 59, 7, 192}; g2int igds[5] = { - 0, /* Source of grid definition (see Code Table 3.0). */ - 4, /* Number of grid points in the defined grid. */ - 0, /* Number of octets needed for each additional grid points definition. Used to define number of points in each row (or column) for non-regular grids. = 0, if using regular grid. */ - 0, /* Interpretation of list for optional points definition. (See Code Table 3.11). */ - 120 /* Grid Definition Template Number (See Code Table 3.1). 120 = Azimuth-range projection */ + 0, /* Source of grid definition (see Code Table 3.0). */ + 4, /* Number of grid points in the defined grid. */ + 0, /* Number of octets needed for each additional grid points definition. Used to define number of points in each row (or column) for non-regular grids. = 0, if using regular grid. */ + 0, /* Interpretation of list for optional points definition. (See Code Table 3.11). */ + 120 /* Grid Definition Template Number (See Code Table 3.1). 120 = Azimuth-range projection */ }; /* See * https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp3-120.shtml. */ @@ -178,13 +176,12 @@ main() 0, /* Lo1 ― longitude of centre point */ 1, /* Dx ― spacing of bins along radials */ 0, /* Dstart ― offset from origin to inner bound */ - 0, /* Scanning mode (see Flag Table 3.4) */ - 0, 0, 0, 0 - }; + 0, /* Scanning mode (see Flag Table 3.4) */ + 0, 0, 0, 0}; unsigned char expected_cgrib[MSG_LEN_120] = {71, 82, 73, 66, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, - 84, 0, 0, 0, 21, 1, 0, 7, 0, 4, 24, 0, 0, 7, 229, 10, 24, 6, 54, 59, 7, 192, 0, 0, 0, 47, - 3, 0, 0, 0, 0, 4, 0, 0, 0, 120, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + 84, 0, 0, 0, 21, 1, 0, 7, 0, 4, 24, 0, 0, 7, 229, 10, 24, 6, 54, 59, 7, 192, 0, 0, 0, 47, + 3, 0, 0, 0, 0, 4, 0, 0, 0, 120, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; /* unsigned char old_val; */ int i; int ret; diff --git a/tests/tst_g2_addlocal.c b/tests/tst_g2_addlocal.c index 6be1fd24..ab47ec1a 100644 --- a/tests/tst_g2_addlocal.c +++ b/tests/tst_g2_addlocal.c @@ -4,9 +4,9 @@ * Ed Hartnett 11/3/21 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" #define SEC0_LEN 16 #define SEC1_LEN 21 @@ -22,8 +22,8 @@ main() g2int listsec0[2] = {1, 2}; g2int listsec1[13] = {7, 4, 24, 0, 0, 2021, 10, 24, 6, 54, 59, 7, 192}; unsigned char expected_cgrib[MSG_LEN] = {71, 82, 73, 66, 0, 0, 1, 2, 0, - 0, 0, 0, 0, 0, 0, 52, 0, 0, 0, 21, 1, 0, 7, 0, 4, 24, 0, 0, 7, 229, - 10, 24, 6, 54, 59, 7, 192, 0, 0, 0, 15, 2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + 0, 0, 0, 0, 0, 0, 52, 0, 0, 0, 21, 1, 0, 7, 0, 4, 24, 0, 0, 7, 229, + 10, 24, 6, 54, 59, 7, 192, 0, 0, 0, 15, 2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; unsigned char csec2[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; g2int lcsec2 = 10; g2int iofst; diff --git a/tests/tst_g2_create.c b/tests/tst_g2_create.c index 27c37581..4a4ee338 100644 --- a/tests/tst_g2_create.c +++ b/tests/tst_g2_create.c @@ -4,8 +4,8 @@ * Ed Hartnett 7/11/21 */ -#include #include "grib2_int.h" +#include #define MSG_LEN 37 @@ -20,9 +20,9 @@ main() printf("Testing simple g2_create() call..."); { unsigned char expected_cgrib[MSG_LEN] = {71, 82, 73, 66, 0, 0, 0, 2, 0, 0, - 0, 0, 0, 0, 0, 37, 0, 0, 0, 21, 1, - 0, 0, 0, 0, 0, 0, 0, 7, 229, 9, 22, - 0, 0, 0, 0, 0}; + 0, 0, 0, 0, 0, 37, 0, 0, 0, 21, 1, + 0, 0, 0, 0, 0, 0, 0, 7, 229, 9, 22, + 0, 0, 0, 0, 0}; int i; int ret; diff --git a/tests/tst_g2_testfile.c b/tests/tst_g2_testfile.c index 3286b472..7fd02682 100644 --- a/tests/tst_g2_testfile.c +++ b/tests/tst_g2_testfile.c @@ -38,7 +38,7 @@ main() int ret; /* g2c_set_log_level(20); */ - + /* Open test file. */ if ((ret = g2c_open(FILENAME, 0, &g2cid))) return ret; @@ -77,11 +77,11 @@ main() if (gds_template[i] != expected_gds[i]) return G2C_ERROR; for (i = 0; i < DRSLEN; i++) - { - printf("drs_template[%d] %lld\n", i, drs_template[i]); + { + printf("drs_template[%d] %lld\n", i, drs_template[i]); if (drs_template[i] != expected_drs[i]) return G2C_ERROR; - } + } /* Close test file. */ if ((ret = g2c_close(g2cid))) @@ -94,7 +94,7 @@ main() int ret; /* g2c_set_log_level(20); */ - + /* Open test file. */ if ((ret = g2c_open(FILENAME, 0, &g2cid))) return ret; @@ -106,7 +106,7 @@ main() /* Check results. */ if ((ret = compare_degrib2_files2(DEGRIB2_FILENAME, REF_FILENAME))) return ret; - + /* Close test file. */ if ((ret = g2c_close(g2cid))) return ret; diff --git a/tests/tst_gbits.c b/tests/tst_gbits.c index 5312d39a..76f5ffa5 100644 --- a/tests/tst_gbits.c +++ b/tests/tst_gbits.c @@ -4,66 +4,70 @@ * Ed Hartnett 7/19/21 */ -#include #include "grib2_int.h" +#include int main() { - + printf("Testing sbit.\n"); printf("Testing simple sbit() call..."); { - unsigned char out[1] = {0x00}; - g2int in[1] = {0x01}; - - sbit(out, in, 0, 8); - if (out[0] != 1) - return G2C_ERROR; + unsigned char out[1] = {0x00}; + g2int in[1] = {0x01}; + + sbit(out, in, 0, 8); + if (out[0] != 1) + return G2C_ERROR; } printf("ok!\n"); printf("Testing sbit() call as used in g2_create() for section 0..."); { - unsigned char cgrib[16]; /* Section 0 is 16 bytes long. */ + unsigned char cgrib[16]; /* Section 0 is 16 bytes long. */ g2int listsec0[2] = {1, 2}; - g2int zero = 0; + g2int zero = 0; /* This code matches code in g2_create(). See * https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect0.shtml. */ /* Pack Section 0 - Indicator Section (except for total length of * GRIB message). */ - cgrib[0] = 0x47; /* 'G' */ - cgrib[1] = 0x52; /* 'R' */ - cgrib[2] = 0x49; /* 'I' */ - cgrib[3] = 0x42; /* 'B' */ + cgrib[0] = 0x47; /* 'G' */ + cgrib[1] = 0x52; /* 'R' */ + cgrib[2] = 0x49; /* 'I' */ + cgrib[3] = 0x42; /* 'B' */ sbit(cgrib, &zero, 32, 16); /* reserved for future use */ - if (cgrib[4] != 0 || cgrib[5] != 0) return G2C_ERROR; + if (cgrib[4] != 0 || cgrib[5] != 0) + return G2C_ERROR; sbit(cgrib, &listsec0[0], 48, 8); /* Discipline */ - if (cgrib[6] != 1) return G2C_ERROR; + if (cgrib[6] != 1) + return G2C_ERROR; sbit(cgrib, &listsec0[1], 56, 8); /* GRIB edition number */ - if (cgrib[7] != 2) return G2C_ERROR; + if (cgrib[7] != 2) + return G2C_ERROR; } printf("ok!\n"); printf("Testing sbit() call as used in g2_create() for section 1..."); { #define LENSEC0 16 -#define MAPSEC1LEN 13 /**< Length of Map Section 1. */ - unsigned char cgrib[LENSEC0 + 21]; /* Section 1 at least 21 bytes long. */ - unsigned char expected_sec1_cgrib[21] = {0, 0, 0, 21, 1, 0, 7, 0, 4, 24, 0, 0, - 7, 229, 10, 24, 6, 54, 59, 7, 192}; +#define MAPSEC1LEN 13 /**< Length of Map Section 1. */ + unsigned char cgrib[LENSEC0 + 21]; /* Section 1 at least 21 bytes long. */ + unsigned char expected_sec1_cgrib[21] = {0, 0, 0, 21, 1, 0, 7, 0, 4, 24, 0, 0, + 7, 229, 10, 24, 6, 54, 59, 7, 192}; g2int listsec1[13] = {7, 4, 24, 0, 0, 2021, 10, 24, 6, 54, 59, 7, 192}; g2int i, lensec1, iofst, ibeg, nbits; - g2int mapsec1[MAPSEC1LEN] = {2, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1}; + g2int mapsec1[MAPSEC1LEN] = {2, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1}; g2int one = 1; /* This code matches code in g2_create(). See * https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect1.shtml. */ /* Pack Section 1 - Identification Section. */ - ibeg = LENSEC0 * 8; /* Calculate offset for beginning of section 1. */ - iofst = ibeg + 32; /* Leave space for length of section. */ + ibeg = LENSEC0 * 8; /* Calculate offset for beginning of section 1. */ + iofst = ibeg + 32; /* Leave space for length of section. */ sbit(cgrib, &one, iofst, 8); /* Store section number (1). */ iofst = iofst + 8; - if (cgrib[20] != 1) return G2C_ERROR; + if (cgrib[20] != 1) + return G2C_ERROR; /* Pack up each input value in array listsec1 into the the * appropriate number of octets, which are specified in @@ -111,15 +115,14 @@ main() g2int lencurr; /* This message comes from the code in tst_g2_addgrid.c. */ unsigned char cgrib[MSG_LEN] = {71, 82, 73, 66, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, - 109, 0, 0, 0, 21, 1, 0, 7, 0, 4, 24, 0, 0, 7, 229, 10, 24, 6, 54, 59, 7, 192, 0, 0, 0, - 72, 3, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 3, 0, 0, 0, 4, 5, 0, 0, 0, 6, 0, 0, - 0, 7, 0, 0, 0, 8, 0, 0, 0, 9, 0, 0, 0, 10, 0, 0, 0, 11, 0, 0, 0, 12, 13, 0, 0, 0, 14, - 0, 0, 0, 15, 0, 0, 0, 16, 0, 0, 0, 17, 18}; + 109, 0, 0, 0, 21, 1, 0, 7, 0, 4, 24, 0, 0, 7, 229, 10, 24, 6, 54, 59, 7, 192, 0, 0, 0, + 72, 3, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 3, 0, 0, 0, 4, 5, 0, 0, 0, 6, 0, 0, + 0, 7, 0, 0, 0, 8, 0, 0, 0, 9, 0, 0, 0, 10, 0, 0, 0, 11, 0, 0, 0, 12, 13, 0, 0, 0, 14, + 0, 0, 0, 15, 0, 0, 0, 16, 0, 0, 0, 17, 18}; gbit(cgrib, &lencurr, 96, 32); if (lencurr != MSG_LEN) return G2C_ERROR; - } printf("ok!\n"); printf("Testing g2c_gbit_int() call..."); @@ -128,15 +131,14 @@ main() int lencurr; /* This message comes from the code in tst_g2_addgrid.c. */ unsigned char cgrib[MSG_LEN] = {71, 82, 73, 66, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, - 109, 0, 0, 0, 21, 1, 0, 7, 0, 4, 24, 0, 0, 7, 229, 10, 24, 6, 54, 59, 7, 192, 0, 0, 0, - 72, 3, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 3, 0, 0, 0, 4, 5, 0, 0, 0, 6, 0, 0, - 0, 7, 0, 0, 0, 8, 0, 0, 0, 9, 0, 0, 0, 10, 0, 0, 0, 11, 0, 0, 0, 12, 13, 0, 0, 0, 14, - 0, 0, 0, 15, 0, 0, 0, 16, 0, 0, 0, 17, 18}; + 109, 0, 0, 0, 21, 1, 0, 7, 0, 4, 24, 0, 0, 7, 229, 10, 24, 6, 54, 59, 7, 192, 0, 0, 0, + 72, 3, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 3, 0, 0, 0, 4, 5, 0, 0, 0, 6, 0, 0, + 0, 7, 0, 0, 0, 8, 0, 0, 0, 9, 0, 0, 0, 10, 0, 0, 0, 11, 0, 0, 0, 12, 13, 0, 0, 0, 14, + 0, 0, 0, 15, 0, 0, 0, 16, 0, 0, 0, 17, 18}; g2c_gbit_int(cgrib, &lencurr, 96, 32); if (lencurr != MSG_LEN) return G2C_ERROR; - } printf("ok!\n"); printf("SUCCESS!\n"); diff --git a/tests/tst_gdaswave.c b/tests/tst_gdaswave.c index 928f4c0b..3fbbf3af 100644 --- a/tests/tst_gdaswave.c +++ b/tests/tst_gdaswave.c @@ -6,9 +6,9 @@ * Ed Hartnett 7/5/23 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" #define GDAS_FILE "data/gdaswave.t00z.wcoast.0p16.f000.grib2" #define LAT_LEN 241 @@ -29,7 +29,7 @@ main() int d; /* Open GRIB2 file. */ - g2c_set_log_level(10); + g2c_set_log_level(10); if (g2c_open(GDAS_FILE, 0, &g2cid)) return G2C_ERROR; @@ -46,7 +46,6 @@ main() printf("len0 %ld dimname0 %s\n", len0, dimname0); for (d = 0; d < len0; d++) printf("lat[%d] = %f\n", d, lat[d]); - } printf("ok!\n"); printf("SUCCESS!\n"); diff --git a/tests/tst_get_grid_template.c b/tests/tst_get_grid_template.c index a4dcb013..5f42bad6 100644 --- a/tests/tst_get_grid_template.c +++ b/tests/tst_get_grid_template.c @@ -23,45 +23,44 @@ main() int expected_needsext[NUM_TESTS] = {0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1}; int expected_extlen[NUM_TESTS] = {0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 2, 0, 2}; int expected_map[NUM_TESTS][28] = { - {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, 0, 0, 0}, /* 0 */ - {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, 4, 0, 0, 0}, /* 1 */ - {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, -4, 0, 0, 0}, /* 2 */ + {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, 0, 0, 0}, /* 0 */ + {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, 4, 0, 0, 0}, /* 1 */ + {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, -4, 0, 0, 0}, /* 2 */ {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, 4, -4, 4, -4, 0, 0, 0}, /* 3 */ - {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, 1, 1}, /* 4 */ - {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, 1, 1, -4, 4, 4}, /* 5 */ - {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, -4, 4, 4, 1, 4, 4, -4, -4, -4, -4, 0, 0, 0}, /* 12 */ - {1, 4, 1, -4}, /* 101 */ - {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 4, 4, 1, 4, 4, 1, 0, 0, 0}, /* 140 */ - {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, -4, -4, 4, 1, 4, 4, 4, 0, 0, 0}, /* 10 */ - {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, 1, 0, 0, 0}, /* 20 */ + {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, 1, 1}, /* 4 */ + {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, 1, 1, -4, 4, 4}, /* 5 */ + {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, -4, 4, 4, 1, 4, 4, -4, -4, -4, -4, 0, 0, 0}, /* 12 */ + {1, 4, 1, -4}, /* 101 */ + {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 4, 4, 1, 4, 4, 1, 0, 0, 0}, /* 140 */ + {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, -4, -4, 4, 1, 4, 4, 4, 0, 0, 0}, /* 10 */ + {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, 1, 0, 0, 0}, /* 20 */ {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, 1, -4, -4, -4, 4, 0, 0, 0, 0, 0, 0}, /* 30 */ {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, 1, -4, -4, -4, 4, 0, 0, 0, 0, 0, 0}, /* 31 */ - {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* 40 */ - {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, 4, 0, 0, 0, 0, 0, 0}, /* 41 */ - {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, -4, 0, 0, 0, 0, 0, 0}, /* 42 */ + {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* 40 */ + {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, 4, 0, 0, 0, 0, 0, 0}, /* 41 */ + {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, -4, 0, 0, 0, 0, 0, 0}, /* 42 */ {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, -4, 4, 4, -4, 4, -4, 0, 0, 0}, /* 43 */ - {4, 4, 4, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* 50 */ - {4, 4, 4, 1, 1, -4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* 51 */ - {4, 4, 4, 1, 1, -4, 4, -4}, /* 52 */ - {4, 4, 4, 1, 1, -4, 4, 4, -4, 4, -4}, /* 53 */ - {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, 4, 4, 4, 4, 1, 4, 4, 4, 4}, /* 90 */ - {1, 1, 2, 1, -4, 4, 4, 1, 1, 1, 4}, /* 100 */ - {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, 4, 4, 1, 1}, /* 110 */ - {4, 4, -4, 4, 4, 4, 1}, /* 120 */ - {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1}, /* 204 */ - {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1}, /* 32768 */ - {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, 4, 4}, /* 32769 */ - {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, -4, 4, 1, 4, 4, 1, 2, 1, 1, 2}, /* 1000 */ - {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, -4, 4, 1, -4, 4, 1, 4, 1, -4, 1, 1, -4, 2, 1, 1, 1, 1, 1}, /* 1100 */ - {4, 1, -4, 1, 1, -4, 2, 1, 1, 1, 1, 1, 2, 1, 1, 2} /* 1200 */ + {4, 4, 4, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* 50 */ + {4, 4, 4, 1, 1, -4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* 51 */ + {4, 4, 4, 1, 1, -4, 4, -4}, /* 52 */ + {4, 4, 4, 1, 1, -4, 4, 4, -4, 4, -4}, /* 53 */ + {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, 4, 4, 4, 4, 1, 4, 4, 4, 4}, /* 90 */ + {1, 1, 2, 1, -4, 4, 4, 1, 1, 1, 4}, /* 100 */ + {1, 1, 4, 1, 4, 1, 4, 4, 4, -4, 4, 1, 4, 4, 1, 1}, /* 110 */ + {4, 4, -4, 4, 4, 4, 1}, /* 120 */ + {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1}, /* 204 */ + {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1}, /* 32768 */ + {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, 4, -4, 4, 1, -4, 4, 4, 4, 1, 4, 4}, /* 32769 */ + {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, -4, 4, 1, 4, 4, 1, 2, 1, 1, 2}, /* 1000 */ + {1, 1, 4, 1, 4, 1, 4, 4, 4, 4, -4, 4, 1, -4, 4, 1, 4, 1, -4, 1, 1, -4, 2, 1, 1, 1, 1, 1}, /* 1100 */ + {4, 1, -4, 1, 1, -4, 2, 1, 1, 1, 1, 1, 2, 1, 1, 2} /* 1200 */ }; int expected_ext[NUM_EXT_TESTS][8] = { {4, 4, -4, -4}, {4, 4, -4, -4}, {2, -2, 2, -2}, {4, 4}, - {4, 4} - }; + {4, 4}}; int maplen, extlen; int map[G2C_MAX_GDS_TEMPLATE_MAPLEN]; int ext[G2C_MAX_GDS_TEMPLATE_MAPLEN]; diff --git a/tests/tst_getdim.c b/tests/tst_getdim.c index 067a3774..14b3006b 100644 --- a/tests/tst_getdim.c +++ b/tests/tst_getdim.c @@ -4,9 +4,9 @@ * Ed Hartnett 10/28/21 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" #define SEC3_LEN 72 @@ -20,24 +20,23 @@ main() printf("Testing getdim function.\n"); printf("Testing getdim() call..."); { - g2int width, height, iscan; + g2int width, height, iscan; unsigned char csec3[SEC3_LEN] = { - 0x00, 0x00, 0x00, 0x48, /* len of sect 3 (72) */ + 0x00, 0x00, 0x00, 0x48, /* len of sect 3 (72) */ 0x03, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00, 0x00, 0x04, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x0c, 0x0d, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x11, 0x12}; - getdim(csec3, &width, &height, &iscan); - /* printf("%ld %ld %ld\n", width, height, iscan); */ - if (width != 7 || height != 8 || iscan != 18) - return G2C_ERROR; - - /* Try the getpoly() function. */ - g2int jj, kk, mm; - getpoly(csec3, &jj, &kk, &mm); + getdim(csec3, &width, &height, &iscan); + /* printf("%ld %ld %ld\n", width, height, iscan); */ + if (width != 7 || height != 8 || iscan != 18) + return G2C_ERROR; + /* Try the getpoly() function. */ + g2int jj, kk, mm; + getpoly(csec3, &jj, &kk, &mm); } printf("ok!\n"); printf("SUCCESS!\n"); diff --git a/tests/tst_gridtemplates.c b/tests/tst_gridtemplates.c index 511b1087..efe3df44 100644 --- a/tests/tst_gridtemplates.c +++ b/tests/tst_gridtemplates.c @@ -4,9 +4,9 @@ * Ed Hartnett 10/24/21 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /* Prototypes. */ g2int getgridindex(g2int number); @@ -14,7 +14,7 @@ g2int getgridindex(g2int number); int main() { - + printf("Testing gridtemplates.\n"); printf("Testing simple getgridtemplate() calls (expect and ignore error messages)..."); { @@ -22,7 +22,7 @@ main() gtemplate *tmpl; g2int list[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; g2int list2[20] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}; - + /* Check for one that's there and does not need extension. */ if (!(tmpl = getgridtemplate(1))) return G2C_ERROR; diff --git a/tests/tst_index.c b/tests/tst_index.c index eadcf849..7dcfed46 100644 --- a/tests/tst_index.c +++ b/tests/tst_index.c @@ -1,4 +1,4 @@ -/* This is a test for the NCEPLIBS-g2c project. +/* This is a test for the NCEPLIBS-g2c project. * * This test is for the g2c_write_index()/g2c_open_index() functions, * which write and read and index file that contians the byte offsets @@ -22,28 +22,30 @@ RESULT. Return 1 if the difference is negative, otherwise 0. This function from the GNU documentation. */ int -nc4_timeval_subtract (result, x, y) - struct timeval *result, *x, *y; +nc4_timeval_subtract(result, x, y) +struct timeval *result, *x, *y; { - /* Perform the carry for the later subtraction by updating Y. */ - if (x->tv_usec < y->tv_usec) { - int nsec = (y->tv_usec - x->tv_usec) / MILLION + 1; - y->tv_usec -= MILLION * nsec; - y->tv_sec += nsec; - } - if (x->tv_usec - y->tv_usec > MILLION) { - int nsec = (x->tv_usec - y->tv_usec) / MILLION; - y->tv_usec += MILLION * nsec; - y->tv_sec -= nsec; - } - - /* Compute the time remaining to wait. + /* Perform the carry for the later subtraction by updating Y. */ + if (x->tv_usec < y->tv_usec) + { + int nsec = (y->tv_usec - x->tv_usec) / MILLION + 1; + y->tv_usec -= MILLION * nsec; + y->tv_sec += nsec; + } + if (x->tv_usec - y->tv_usec > MILLION) + { + int nsec = (x->tv_usec - y->tv_usec) / MILLION; + y->tv_usec += MILLION * nsec; + y->tv_sec -= nsec; + } + + /* Compute the time remaining to wait. `tv_usec' is certainly positive. */ - result->tv_sec = x->tv_sec - y->tv_sec; - result->tv_usec = x->tv_usec - y->tv_usec; + result->tv_sec = x->tv_sec - y->tv_sec; + result->tv_usec = x->tv_usec - y->tv_usec; - /* Return 1 if result is negative. */ - return x->tv_sec < y->tv_sec; + /* Return 1 if result is negative. */ + return x->tv_sec < y->tv_sec; } int @@ -121,7 +123,7 @@ main() /* Make sure NOCLOBBER works. */ if (g2c_write_index(g2cid, G2C_NOCLOBBER, INDEX_FILE) != G2C_EFILE) return G2C_ERROR; - + /* Close the file. */ if ((ret = g2c_close(g2cid))) return ret; @@ -129,14 +131,14 @@ main() printf("ok!\n"); printf("Testing whether we can read an index generated by g2c_write_index() on file %s...", WAVE_FILE); { - int g2cid; + int g2cid; int num_msg; int ret; - /* Open the data file. */ + /* Open the data file. */ /* g2c_set_log_level(20); */ - if ((ret = g2c_open(WAVE_FILE, 0, &g2cid))) - return ret; + if ((ret = g2c_open(WAVE_FILE, 0, &g2cid))) + return ret; /* Check some stuff. */ if ((ret = g2c_inq(g2cid, &num_msg))) @@ -145,16 +147,16 @@ main() return G2C_ERROR; /* Write an index file. */ - if ((ret = g2c_write_index(g2cid, 0, INDEX_FILE))) - return ret; + if ((ret = g2c_write_index(g2cid, 0, INDEX_FILE))) + return ret; /* Close the file. */ - if ((ret = g2c_close(g2cid))) - return ret; + if ((ret = g2c_close(g2cid))) + return ret; /* Now reopen the file using the index we just generated. */ - if ((ret = g2c_open_index(WAVE_FILE, INDEX_FILE, 0, &g2cid))) - return ret; + if ((ret = g2c_open_index(WAVE_FILE, INDEX_FILE, 0, &g2cid))) + return ret; /* Check some stuff. */ if ((ret = g2c_inq(g2cid, &num_msg))) @@ -163,14 +165,14 @@ main() return G2C_ERROR; /* Close the file. */ - if ((ret = g2c_close(g2cid))) - return ret; + if ((ret = g2c_close(g2cid))) + return ret; } printf("ok!\n"); #ifdef FTP_TEST_FILES printf("Testing g2c_open_index() on file %s downloaded via FTP...", FTP_FILE); { - int g2cid; + int g2cid; int num_msg; unsigned char sig_ref_time, month, day, hour, minute, second; short year; @@ -178,12 +180,12 @@ main() unsigned char master_version, local_version; int num_fields, num_local; unsigned char discipline; - int ret; + int ret; - /* g2c_set_log_level(11); */ - /* Open the data file using the index file. */ - if ((ret = g2c_open_index(FTP_FILE, REF_FTP_FILE, 0, &g2cid))) - return ret; + /* g2c_set_log_level(11); */ + /* Open the data file using the index file. */ + if ((ret = g2c_open_index(FTP_FILE, REF_FTP_FILE, 0, &g2cid))) + return ret; /* Check some stuff. */ if ((ret = g2c_inq(g2cid, &num_msg))) @@ -211,29 +213,29 @@ main() return G2C_ERROR; /* Close the file. */ - if ((ret = g2c_close(g2cid))) - return ret; + if ((ret = g2c_close(g2cid))) + return ret; } printf("ok!\n"); printf("Testing speed of g2c_open_index() on file %s downloaded via FTP...\n", FTP_FILE); { - int g2cid; + int g2cid; int num_msg; struct timeval start_time, end_time, diff_time; int open_1_us, open_2_us; - int ret; + int ret; - /* Open the data file without using the index file. */ + /* Open the data file without using the index file. */ if (gettimeofday(&start_time, NULL)) return G2C_ERROR; - if ((ret = g2c_open(FTP_FILE, 0, &g2cid))) - return ret; - if (gettimeofday(&end_time, NULL)) + if ((ret = g2c_open(FTP_FILE, 0, &g2cid))) + return ret; + if (gettimeofday(&end_time, NULL)) return G2C_ERROR; if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) return G2C_ERROR; open_1_us = (int)diff_time.tv_sec * MILLION + (int)diff_time.tv_usec; - + /* Check some stuff. */ if ((ret = g2c_inq(g2cid, &num_msg))) return ret; @@ -241,17 +243,17 @@ main() return G2C_ERROR; /* Close the file. */ - if ((ret = g2c_close(g2cid))) - return ret; + if ((ret = g2c_close(g2cid))) + return ret; - /* Open the data file using the index file. */ + /* Open the data file using the index file. */ if (gettimeofday(&start_time, NULL)) return G2C_ERROR; - if ((ret = g2c_open_index(FTP_FILE, REF_FTP_FILE, 0, &g2cid))) - return ret; - if (gettimeofday(&end_time, NULL)) + if ((ret = g2c_open_index(FTP_FILE, REF_FTP_FILE, 0, &g2cid))) + return ret; + if (gettimeofday(&end_time, NULL)) return G2C_ERROR; - if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) + if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) return G2C_ERROR; open_2_us = (int)diff_time.tv_sec * MILLION + (int)diff_time.tv_usec; printf("open without index %d with index %d, using index saved %d microseconds\n", @@ -264,8 +266,8 @@ main() return G2C_ERROR; /* Close the file. */ - if ((ret = g2c_close(g2cid))) - return ret; + if ((ret = g2c_close(g2cid))) + return ret; } printf("ok!\n"); #endif /* FTP_TEST_FILES */ @@ -273,4 +275,3 @@ main() printf("SUCCESS!\n"); return 0; } - diff --git a/tests/tst_inq.c b/tests/tst_inq.c index f9dd6028..51cec899 100644 --- a/tests/tst_inq.c +++ b/tests/tst_inq.c @@ -123,8 +123,7 @@ main() {0, 4, 2, 0, 11, 0, 0, 1, 0, 1, 0, 1, 255, 0, 0}, {0, 7, 2, 0, 11, 0, 0, 1, 0, 241, 0, 1, 255, 0, 0}, {0, 7, 2, 0, 11, 0, 0, 1, 0, 241, 0, 2, 255, 0, 0}, - {0, 7, 2, 0, 11, 0, 0, 1, 0, 241, 0, 3, 255, 0, 0} - }; + {0, 7, 2, 0, 11, 0, 0, 1, 0, 241, 0, 3, 255, 0, 0}}; long long int expected_gds_template[G2C_MAX_GDS_TEMPLATE_MAPLEN] = {6, 0, 0, 0, 0, 0, 0, 241, 151, 0, 0, 50000000, 210000000, 48, 25000000, 250000000, 166667, 166667, 0}; long long int expected_drs_template[NUM_MSG][G2C_MAX_DRS_TEMPLATE_MAPLEN] = { @@ -146,16 +145,15 @@ main() {0, 0, 2, 16, 0, 0, 255}, {1183603200, 0, 2, 14, 0, 0, 255}, {1140424704, 0, 2, 16, 0, 0, 255}, - {1092616192, 0, 2, 16, 0, 0, 255} - }; + {1092616192, 0, 2, 16, 0, 0, 255}}; unsigned char sig_ref_time, month, day, hour, minute, second; short year; short center, subcenter; unsigned char master_version, local_version; int p; - printf("\t\tinquiring about message %d...\n", m); - + printf("\t\tinquiring about message %d...\n", m); + /* Inquire about this message. */ if ((ret = g2c_inq_msg(g2cid, m, &discipline, &num_fields, &num_local, ¢er, &subcenter, &master_version, &local_version))) @@ -177,7 +175,7 @@ main() if (sig_ref_time != 1 || year != 2021 || month != 11 || day != 30 || hour != 0 || minute != 0 || second != 0) return G2C_ERROR; - + /* Each message in the test file has one product. Inqure * about it. */ if ((ret = g2c_inq_prod(g2cid, m, 0, &pds_template_len, pds_template, @@ -199,11 +197,11 @@ main() if (drs_template_len != 7) return G2C_ERROR; for (p = 0; p < drs_template_len; p++) - { - /* printf("drs_template[%d] %lld\n", p, drs_template[p]); */ + { + /* printf("drs_template[%d] %lld\n", p, drs_template[p]); */ if (drs_template[p] != expected_drs_template[m][p]) return G2C_ERROR; - } + } } /* Close the file. */ diff --git a/tests/tst_jasper_warning.c b/tests/tst_jasper_warning.c index df50b43a..c43eef80 100644 --- a/tests/tst_jasper_warning.c +++ b/tests/tst_jasper_warning.c @@ -5,9 +5,9 @@ * Ed Hartnett 10/26/23 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" #define DATA_LEN 4 #define PACKED_LEN 200 @@ -24,9 +24,9 @@ main() g2int ltype = 0, ratio = 0, retry = 0, jpclen = PACKED_LEN; char outjpc[PACKED_LEN]; g2int outfld[DATA_LEN]; - int i; + int i; int ret; - + /* Encode some data. */ if ((ret = enc_jpeg2000(data, width, height, nbits, ltype, ratio, retry, outjpc, jpclen)) < 0) diff --git a/tests/tst_jpeg.c b/tests/tst_jpeg.c index 29873866..40789ced 100644 --- a/tests/tst_jpeg.c +++ b/tests/tst_jpeg.c @@ -4,9 +4,9 @@ * Ed Hartnett 11/1/21 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" #define DATA_LEN 4 #define PACKED_LEN 200 @@ -17,7 +17,7 @@ int main() { int i; - + printf("Testing JPEG functions.\n"); /* g2c_set_log_level(10); */ #ifdef USE_JPEG2000 @@ -29,7 +29,7 @@ main() char outjpc[PACKED_LEN]; g2int outfld[DATA_LEN]; int ret; - + /* Encode some data. */ if ((ret = enc_jpeg2000(data, width, height, nbits, ltype, ratio, retry, outjpc, jpclen)) < 0) @@ -127,7 +127,7 @@ main() { float fld[DATA_LEN] = {1.0, 2.0, 3.0, 0.0}; float fld_in[DATA_LEN]; - size_t lcpack_st = PACKED_LEN; + size_t lcpack_st = PACKED_LEN; int idrstmpl[7] = {0, 1, 1, 16, 0, 0, 0}; /* Pack the data. */ @@ -153,13 +153,13 @@ main() /* See * https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-40.shtml */ g2int idrstmpl[7] = { - 0, /* Reference value (R) (IEEE 32-bit floating-point value) */ - 0, /* Binary scale factor (E) */ - 1, /* Decimal scale factor (D) */ + 0, /* Reference value (R) (IEEE 32-bit floating-point value) */ + 0, /* Binary scale factor (E) */ + 1, /* Decimal scale factor (D) */ 32, /* Number of bits required to hold the resulting scaled and referenced data values. (i.e. The depth of the grayscale image.) (see Note 2) */ - 0, /* Type of original field values (see Code Table 5.1) */ - 0, /* Type of Compression used. (see Code Table 5.40) */ - 1 /* Target compression ratio, M:1 (with respect to the bit-depth specified in octet 20), when octet 22 indicates Lossy Compression. Otherwise, set to missing (see Note 3) */ + 0, /* Type of original field values (see Code Table 5.1) */ + 0, /* Type of Compression used. (see Code Table 5.40) */ + 1 /* Target compression ratio, M:1 (with respect to the bit-depth specified in octet 20), when octet 22 indicates Lossy Compression. Otherwise, set to missing (see Note 3) */ }; /* Pack the data. */ @@ -239,7 +239,7 @@ main() float fld[DATA_LEN] = {1.0, 1.0, 1.0, 1.0}; float fld_in[DATA_LEN]; g2int lcpack = PACKED_LEN; - g2int idrstmpl[7] = { 0, 0, 1, 32, 0, 0, 1}; + g2int idrstmpl[7] = {0, 0, 1, 32, 0, 0, 1}; /* Pack the data. */ jpcpack(fld, width, height, idrstmpl, cpack, &lcpack); diff --git a/tests/tst_metacmp.c b/tests/tst_metacmp.c index 28b3f5cf..c5cc9a4e 100644 --- a/tests/tst_metacmp.c +++ b/tests/tst_metacmp.c @@ -4,9 +4,9 @@ * Ed Hartnett 12/28/22 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" #define WAVE_FILE "data/gdaswave.t00z.wcoast.0p16.f000.grib2" #define GDAS_FILE "data/gdas.t12z.pgrb2.1p00.anl.grib2" @@ -15,13 +15,13 @@ int main() { int g2cid1, g2cid2; - + printf("Testing g2c_metacmp\n"); /* Open test file. */ if (g2c_open(WAVE_FILE, 0, &g2cid1)) return G2C_ERROR; - + printf("comparing file %s to itself...", WAVE_FILE); { if (g2c_open(WAVE_FILE, 0, &g2cid2)) @@ -32,7 +32,7 @@ main() return G2C_ERROR; } printf("ok!\n"); -#ifdef FTP_TEST_FILES +#ifdef FTP_TEST_FILES printf("comparing file %s to file %s...", WAVE_FILE, GDAS_FILE); { if (g2c_open(GDAS_FILE, 0, &g2cid2)) @@ -44,10 +44,10 @@ main() } printf("ok!\n"); #endif /* FTP_TEST_FILES */ - + if (g2c_close(g2cid1)) return G2C_ERROR; - + printf("SUCCESS!\n"); return 0; } diff --git a/tests/tst_mrms.c b/tests/tst_mrms.c index 73c37c11..1b763e59 100644 --- a/tests/tst_mrms.c +++ b/tests/tst_mrms.c @@ -6,9 +6,9 @@ * Ed Hartnett 7/5/23 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" #define MRMS_FILE "data/MRMS_MultiSensor_QPE_24H_Pass2_00.00_20230621-110000.grib2" #define LAT_LEN 3500 @@ -33,7 +33,7 @@ main() /* int d; */ /* Open GRIB2 file. */ - g2c_set_log_level(10); + g2c_set_log_level(10); if (g2c_open(MRMS_FILE, 0, &g2cid)) return G2C_ERROR; diff --git a/tests/tst_params.c b/tests/tst_params.c index ef3fa132..bd7b5d8c 100644 --- a/tests/tst_params.c +++ b/tests/tst_params.c @@ -25,7 +25,7 @@ main() return ret; if (strcmp(abbrev, "PRES")) return G2C_ERROR; - + if ((ret = g2c_param_abbrev(0, 3, 0, abbrev))) return ret; if (strcmp(abbrev, "PRES")) @@ -2494,7 +2494,7 @@ main() return G2C_ERROR; if ((ret = g2c_param_abbrev(0, 4, 202, abbrev))) return ret; - if (strcmp(abbrev, "NBDSF")) + if (strcmp(abbrev, "NBDSF")) return G2C_ERROR; if ((ret = g2c_param_abbrev(0, 4, 203, abbrev))) return ret; @@ -4088,8 +4088,7 @@ main() return ret; if (strcmp(abbrev, "SOILL")) return G2C_ERROR; - - + /* This will return "UNKNOWN". */ if (g2c_param_abbrev(0, 3000, 0, abbrev)) return G2C_ERROR; @@ -4101,7 +4100,7 @@ main() { int g2disc, g2cat, g2num; int ret; - + /* This will work. */ if ((ret = g2c_param_g1tog2(1, 2, &g2disc, &g2cat, &g2num))) return ret; @@ -4115,14 +4114,13 @@ main() /* This will fail. */ /* if (g2c_param_g1tog2(1, 2000, &g2disc, &g2cat, &g2num) != G2C_ENOPARAM) */ /* return G2C_ERROR; */ - } printf("ok!\n"); printf("Testing g2c_param_g2tog1()..."); { int g1num, g1ver; int ret; - + /* This will work. */ if ((ret = g2c_param_g2tog1(0, 3, 0, &g1num, &g1ver))) return ret; @@ -4136,16 +4134,15 @@ main() /* This will fail. */ /* if (g2c_param_g2tog1(0, 2000, 0, &g1num, &g1ver) != G2C_ENOPARAM) */ /* return G2C_ERROR; */ - } printf("ok!\n"); printf("Testing g2c_param_all()..."); { - int g2disc, g2cat, g2num; + int g2disc, g2cat, g2num; int g1num, g1ver; - char abbrev[G2C_MAX_NOAA_ABBREV_LEN + 1]; + char abbrev[G2C_MAX_NOAA_ABBREV_LEN + 1]; int ret; - + /* g2c_set_log_level(10); */ /* This will work. */ @@ -4165,10 +4162,8 @@ main() return G2C_ERROR; if (g2c_param_all(-1, &g1num, &g1ver, &g2disc, &g2cat, &g2num, abbrev) != G2C_EINVAL) return G2C_ERROR; - } printf("ok!\n"); printf("SUCCESS!!!\n"); return G2C_NOERROR; } - diff --git a/tests/tst_params2.c b/tests/tst_params2.c index 8caf1d9f..1a9f251d 100644 --- a/tests/tst_params2.c +++ b/tests/tst_params2.c @@ -4094,10 +4094,8 @@ main() /* return ret; */ /* if (g1num != 160 || g1ver != 130) */ /* return G2C_ERROR; */ - } printf("ok!\n"); printf("SUCCESS!!!\n"); return G2C_NOERROR; } - diff --git a/tests/tst_params3.c b/tests/tst_params3.c index 40f90237..7a29621b 100644 --- a/tests/tst_params3.c +++ b/tests/tst_params3.c @@ -14,7 +14,7 @@ main() { int g2disc, g2cat, g2num; int ret; - + /* This will work. */ if ((ret = g2c_param_g1tog2(1, 2, &g2disc, &g2cat, &g2num))) return ret; @@ -30,7 +30,6 @@ main() if (g2disc != 0 || g2cat != 3 || g2num != 0) return G2C_ERROR; - if ((ret = g2c_param_g1tog2(2, 2, &g2disc, &g2cat, &g2num))) return ret; if (g2disc != 0 || g2cat != 3 || g2num != 1) @@ -3071,10 +3070,8 @@ main() /* return ret; */ /* if (g2disc != 2 || g2cat != 3 || g2num != 5) */ /* return G2C_ERROR; */ - } printf("ok!\n"); printf("SUCCESS!!!\n"); return G2C_NOERROR; } - diff --git a/tests/tst_pdstemplates.c b/tests/tst_pdstemplates.c index 59276caa..8f5d4622 100644 --- a/tests/tst_pdstemplates.c +++ b/tests/tst_pdstemplates.c @@ -4,9 +4,9 @@ * Ed Hartnett 10/25/21 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" /* Prototypes. */ g2int getpdsindex(g2int number); @@ -369,53 +369,53 @@ main() 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1}; int expected_map[NUM_TEST][48] = { - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}, /* 0 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}, /* 1 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1}, /* 2 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 1, 1, 1, 1, -4, -4, 4, 4, 1, -1, 4, -1, 4}, /* 3 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 1, 1, 1, 1, -4, 4, 4, 1, -1, 4, -1, 4}, /* 4 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, -1, -4, -1, -4}, /* 5 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1}, /* 6 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}, /* 7 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 8 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, -1, -4, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 9 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 10 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 11 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 12 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}, /* 0 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}, /* 1 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1}, /* 2 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 1, 1, 1, 1, -4, -4, 4, 4, 1, -1, 4, -1, 4}, /* 3 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 1, 1, 1, 1, -4, 4, 4, 1, -1, 4, -1, 4}, /* 4 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, -1, -4, -1, -4}, /* 5 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1}, /* 6 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}, /* 7 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 8 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, -1, -4, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 9 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 10 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 11 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 12 */ {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 1, 1, 1, 1, -4, -4, 4, 4, 1, -1, 4, -1, 4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 13 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 1, 1, 1, 1, -4, 4, 4, 1, -1, 4, -1, 4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 14 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}, /* 15 */ - {1, 1, 1, 1, 1, -4, 4, 2, 4, 2, 1, 1, 1, 1, 1, 2, 1, 3, 2}, /* 20 */ - {1, 1, 1, 1, 1}, /* 30 */ - {1, 1, 1, 1, 1}, /* 31 */ - {1, 1, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}, /* 40 */ - {1, 1, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}, /* 41 */ - {1, 1, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 42 */ - {1, 1, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 43 */ - {1, 1, 4}, /* 254 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4}, /* 1000 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 4, 1, 1, 1, 4, 1, 4}, /* 1001 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, 1, 1, 4, 4, 2}, /* 1002 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}, /* 1100 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 4, 1, 1, 1, 4, 1, 4}, /* 1101 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1}, /* 32 */ - {1, 1, 2, 1, -1, -4, -1, -4, 1, 1, 1, 2, 1, 1, -2, 1, -1, -4, 1, -1, -4}, /* 44 */ - {1, 1, 2, 1, -1, -4, -1, -4, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}, /* 45 */ - {1, 1, 2, 1, -1, -4, -1, -4, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 46 */ - {1, 1, 1, 2, 1, -1, -4, -1, -4, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 47 */ - {1, 1, 2, 1, -1, -4, -1, -4, 1, -1, -4, -1, -4, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}, /* 48 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 4, 4, 4, 4}, /* 50 */ - {1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4}, /* 52 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1}, /* 51 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, -1, -4, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 91 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, 2, 2, 2, -1, -4, 1, 1, 1}, /* 33 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, 2, 2, 2, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 34 */ - {1, 1, 1, 1, 4, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}, /* 53 */ - {1, 1, 1, 1, 4, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}, /* 54 */ - {1, 1, 2, 2, 2, 2, 1}, /* 57 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1}, /* 60 */ - {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 61 */ - {1, 1, 1, 1, 1, 1}, /* 35 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 1, 1, 1, 1, -4, 4, 4, 1, -1, 4, -1, 4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 14 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}, /* 15 */ + {1, 1, 1, 1, 1, -4, 4, 2, 4, 2, 1, 1, 1, 1, 1, 2, 1, 3, 2}, /* 20 */ + {1, 1, 1, 1, 1}, /* 30 */ + {1, 1, 1, 1, 1}, /* 31 */ + {1, 1, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}, /* 40 */ + {1, 1, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}, /* 41 */ + {1, 1, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 42 */ + {1, 1, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 43 */ + {1, 1, 4}, /* 254 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4}, /* 1000 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 4, 1, 1, 1, 4, 1, 4}, /* 1001 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, 1, 1, 4, 4, 2}, /* 1002 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}, /* 1100 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 4, 1, 1, 1, 4, 1, 4}, /* 1101 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1}, /* 32 */ + {1, 1, 2, 1, -1, -4, -1, -4, 1, 1, 1, 2, 1, 1, -2, 1, -1, -4, 1, -1, -4}, /* 44 */ + {1, 1, 2, 1, -1, -4, -1, -4, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}, /* 45 */ + {1, 1, 2, 1, -1, -4, -1, -4, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 46 */ + {1, 1, 1, 2, 1, -1, -4, -1, -4, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 47 */ + {1, 1, 2, 1, -1, -4, -1, -4, 1, -1, -4, -1, -4, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}, /* 48 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 4, 4, 4, 4}, /* 50 */ + {1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4}, /* 52 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1}, /* 51 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, -1, -4, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 91 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, 2, 2, 2, -1, -4, 1, 1, 1}, /* 33 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, 2, 2, 2, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 34 */ + {1, 1, 1, 1, 4, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}, /* 53 */ + {1, 1, 1, 1, 4, 2, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}, /* 54 */ + {1, 1, 2, 2, 2, 2, 1}, /* 57 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1}, /* 60 */ + {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 61 */ + {1, 1, 1, 1, 1, 1}, /* 35 */ }; int t; int ext_t = 0; @@ -426,7 +426,7 @@ main() { gtemplate *tmpl; int m; - + /* if (number[t] == 54) */ /* printf("here\n"); */ tmpl = getpdstemplate(number[t]); @@ -438,7 +438,7 @@ main() for (m = 0; m < tmpl->maplen; m++) if (tmpl->map[m] != expected_map[t][m]) return G2C_ERROR; - + free(tmpl); } printf("ok!\n"); @@ -447,7 +447,7 @@ main() int maplen, needext; int map[G2C_MAX_PDS_TEMPLATE_MAPLEN]; int m, ret; - + /* This will work. */ if ((ret = g2c_get_pds_template(number[t], &maplen, map, &needext))) return ret; @@ -461,33 +461,33 @@ main() int template[G2C_MAX_PDS_TEMPLATE_MAPLEN]; int expected_extlen[NUM_EXT_TEST] = {2, 2, 6, 6, 6, 6, 6, 8, 8, 10, 10, 6, 6, 10, 6, 6, 12, 8, 2, 8, 2, 2, 30, 6, 10}; int expected_ext[NUM_EXT_TEST][48] = { - {1, 1}, /* 3 */ - {1, 1}, /* 4 */ - {1, 1, 1, 4, 1, 4}, /* 8 */ - {1, 1, 1, 4, 1, 4}, /* 9 */ - {1, 1, 1, 4, 1, 4}, /* 10 */ - {1, 1, 1, 4, 1, 4}, /* 11 */ - {1, 1, 1, 4, 1, 4}, /* 12 */ - {1, 1, 1, 4, 1, 4, 1, 1}, /* 13 */ - {1, 1, 1, 4, 1, 4, 1, 1}, /* 14 */ - {2, 2, 1, 1, 4, 2, 2, 1, 1, 4}, /* 30 */ - {2, 2, 2, 1, 4, 2, 2, 2, 1, 4}, /* 31 */ - {1, 1, 1, 4, 1, 4}, /* 42 */ - {1, 1, 1, 4, 1, 4}, /* 43 */ - {2, 2, 2, -1, -4, 2, 2, 2, -1, -4}, /* 32 */ - {1, 1, 1, 4, 1, 4}, /* 46 */ - {1, 1, 1, 4, 1, 4}, /* 47 */ - {1, 1, -1, -4, -1, -4, 1, 1, -1, -4, -1, -4}, /* 51 */ - {1, 1, 1, 4, 1, 4, 1, 1}, /* 91 */ - {1, 1}, /* 33 */ - {1, 1, 1, 4, 1, 4, 1, 1}, /* 34 */ - {1, 1}, /* 53 */ - {1, 1}, /* 54 */ + {1, 1}, /* 3 */ + {1, 1}, /* 4 */ + {1, 1, 1, 4, 1, 4}, /* 8 */ + {1, 1, 1, 4, 1, 4}, /* 9 */ + {1, 1, 1, 4, 1, 4}, /* 10 */ + {1, 1, 1, 4, 1, 4}, /* 11 */ + {1, 1, 1, 4, 1, 4}, /* 12 */ + {1, 1, 1, 4, 1, 4, 1, 1}, /* 13 */ + {1, 1, 1, 4, 1, 4, 1, 1}, /* 14 */ + {2, 2, 1, 1, 4, 2, 2, 1, 1, 4}, /* 30 */ + {2, 2, 2, 1, 4, 2, 2, 2, 1, 4}, /* 31 */ + {1, 1, 1, 4, 1, 4}, /* 42 */ + {1, 1, 1, 4, 1, 4}, /* 43 */ + {2, 2, 2, -1, -4, 2, 2, 2, -1, -4}, /* 32 */ + {1, 1, 1, 4, 1, 4}, /* 46 */ + {1, 1, 1, 4, 1, 4}, /* 47 */ + {1, 1, -1, -4, -1, -4, 1, 1, -1, -4, -1, -4}, /* 51 */ + {1, 1, 1, 4, 1, 4, 1, 1}, /* 91 */ + {1, 1}, /* 33 */ + {1, 1, 1, 4, 1, 4, 1, 1}, /* 34 */ + {1, 1}, /* 53 */ + {1, 1}, /* 54 */ {1, -4, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, -4, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}, /* 57 */ - {1, 1, 1, 4, 1, 4}, /* 61 */ - {2, 2, 2, 1, 4, 2, 2, 2, 1, 4}, /* 35 */ + {1, 1, 1, 4, 1, 4}, /* 61 */ + {2, 2, 2, 1, 4, 2, 2, 2, 1, 4}, /* 35 */ }; - + if (needext) { int ext[G2C_MAX_PDS_TEMPLATE_MAPLEN]; @@ -606,7 +606,6 @@ main() /* Move to next set of expected results. */ ext_t++; - } } printf("ok!\n"); diff --git a/tests/tst_png.c b/tests/tst_png.c index aadb6ef1..b58c8b5e 100644 --- a/tests/tst_png.c +++ b/tests/tst_png.c @@ -4,9 +4,9 @@ * Ed Hartnett 10/29/21 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" #define DATA_LEN 4 #define PACKED_LEN 80 @@ -46,183 +46,183 @@ main() printf("ok!\n"); printf("Testing pngpack()/pngunpack() calls..."); { - g2int height = 2, width = 2, ndpts = DATA_LEN, len = PACKED_LEN; - float fld[DATA_LEN] = {1.0, 2.0, 3.0, 0.0}; - float fld_in[DATA_LEN]; - unsigned char cpack[PACKED_LEN]; - g2int lcpack; + g2int height = 2, width = 2, ndpts = DATA_LEN, len = PACKED_LEN; + float fld[DATA_LEN] = {1.0, 2.0, 3.0, 0.0}; + float fld_in[DATA_LEN]; + unsigned char cpack[PACKED_LEN]; + g2int lcpack; g2int idrstmpl[5] = {0, 1, 1, 16, 0}; - int i; + int i; - /* Pack the data. */ - pngpack(fld, width, height, idrstmpl, cpack, &lcpack); + /* Pack the data. */ + pngpack(fld, width, height, idrstmpl, cpack, &lcpack); - /* Unpack the data. */ - if (pngunpack(cpack, len, idrstmpl, ndpts, fld_in)) - return G2C_ERROR; + /* Unpack the data. */ + if (pngunpack(cpack, len, idrstmpl, ndpts, fld_in)) + 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; - } + 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("Testing g2c_pngpackd()/g2c_pngunpackd() calls..."); { - size_t height = 2, width = 2; - size_t ndpts = DATA_LEN, len = PACKED_LEN; - double fld[DATA_LEN] = {1.0, 2.0, 3.0, 0.0}; - double fld_in[DATA_LEN]; - unsigned char cpack[PACKED_LEN]; - int lcpack; + size_t height = 2, width = 2; + size_t ndpts = DATA_LEN, len = PACKED_LEN; + double fld[DATA_LEN] = {1.0, 2.0, 3.0, 0.0}; + double fld_in[DATA_LEN]; + unsigned char cpack[PACKED_LEN]; + int lcpack; int idrstmpl[5] = {0, 1, 1, 16, 0}; - int i; + int i; - /* Pack the data. */ - g2c_pngpackd(fld, width, height, idrstmpl, cpack, &lcpack); + /* Pack the data. */ + g2c_pngpackd(fld, width, height, idrstmpl, cpack, &lcpack); - /* Unpack the data. */ - if (g2c_pngunpackd(cpack, len, idrstmpl, ndpts, fld_in)) - return G2C_ERROR; + /* Unpack the data. */ + if (g2c_pngunpackd(cpack, len, idrstmpl, ndpts, fld_in)) + return G2C_ERROR; - for (i = 0; i < DATA_LEN; i++) - { - /* printf("%g %g\n", fld[i], fld_in[i]); */ - if (abs(fld[i] - fld_in[i]) > EPSILON) - return G2C_ERROR; - } + for (i = 0; i < DATA_LEN; i++) + { + /* printf("%g %g\n", fld[i], fld_in[i]); */ + if (abs(fld[i] - fld_in[i]) > EPSILON) + return G2C_ERROR; + } } printf("ok!\n"); printf("Testing pngpack()/pngunpack() calls with different settings..."); { - g2int height = 2, width = 2, ndpts = DATA_LEN, len = PACKED_LEN; - float fld[DATA_LEN] = {1.0, 2.0, 3.0, 0.0}; - float fld_in[DATA_LEN]; - unsigned char cpack[PACKED_LEN]; - g2int lcpack; + g2int height = 2, width = 2, ndpts = DATA_LEN, len = PACKED_LEN; + float fld[DATA_LEN] = {1.0, 2.0, 3.0, 0.0}; + float fld_in[DATA_LEN]; + unsigned char cpack[PACKED_LEN]; + g2int lcpack; /* See https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-41.shtml */ g2int idrstmpl[5] = { - 0, /* Reference value (R) (IEEE 32-bit floating-point value) */ - 0, /* Binary scale factor (E) */ - 1, /* Decimal scale factor (D) */ + 0, /* Reference value (R) (IEEE 32-bit floating-point value) */ + 0, /* Binary scale factor (E) */ + 1, /* Decimal scale factor (D) */ 32, /* Number of bits required to hold the resulting scaled and referenced data values. (i.e. The depth of the grayscale image.) (see Note 2) */ - 0 /* Type of original field values (see Code Table 5.1) */ + 0 /* Type of original field values (see Code Table 5.1) */ }; - int i; + int i; - /* Pack the data. */ - pngpack(fld, width, height, idrstmpl, cpack, &lcpack); + /* Pack the data. */ + pngpack(fld, width, height, idrstmpl, cpack, &lcpack); - /* Unpack the data. */ - if (pngunpack(cpack, len, idrstmpl, ndpts, fld_in)) - return G2C_ERROR; + /* Unpack the data. */ + if (pngunpack(cpack, len, idrstmpl, ndpts, fld_in)) + 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; - } + 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("Testing g2c_pngpackd()/g2c_pngunpackd() calls with different settings..."); { - size_t height = 2, width = 2; - size_t ndpts = DATA_LEN, len = PACKED_LEN; - double fld[DATA_LEN] = {1.0, 2.0, 3.0, 0.0}; - double fld_in[DATA_LEN]; - unsigned char cpack[PACKED_LEN]; - int lcpack; + size_t height = 2, width = 2; + size_t ndpts = DATA_LEN, len = PACKED_LEN; + double fld[DATA_LEN] = {1.0, 2.0, 3.0, 0.0}; + double fld_in[DATA_LEN]; + unsigned char cpack[PACKED_LEN]; + int lcpack; /* See https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-41.shtml */ int idrstmpl[5] = { - 0, /* Reference value (R) (IEEE 32-bit floating-point value) */ - 0, /* Binary scale factor (E) */ - 1, /* Decimal scale factor (D) */ + 0, /* Reference value (R) (IEEE 32-bit floating-point value) */ + 0, /* Binary scale factor (E) */ + 1, /* Decimal scale factor (D) */ 32, /* Number of bits required to hold the resulting scaled and referenced data values. (i.e. The depth of the grayscale image.) (see Note 2) */ - 0 /* Type of original field values (see Code Table 5.1) */ + 0 /* Type of original field values (see Code Table 5.1) */ }; - int i; + int i; - /* Pack the data. */ - g2c_pngpackd(fld, width, height, idrstmpl, cpack, &lcpack); + /* Pack the data. */ + g2c_pngpackd(fld, width, height, idrstmpl, cpack, &lcpack); - /* Unpack the data. */ - if (g2c_pngunpackd(cpack, len, idrstmpl, ndpts, fld_in)) - return G2C_ERROR; + /* Unpack the data. */ + if (g2c_pngunpackd(cpack, len, idrstmpl, ndpts, fld_in)) + return G2C_ERROR; - for (i = 0; i < DATA_LEN; i++) - { - /* printf("%g %g\n", fld[i], fld_in[i]); */ - if (abs(fld[i] - fld_in[i]) > EPSILON) - return G2C_ERROR; - } + for (i = 0; i < DATA_LEN; i++) + { + /* printf("%g %g\n", fld[i], fld_in[i]); */ + if (abs(fld[i] - fld_in[i]) > EPSILON) + return G2C_ERROR; + } } printf("ok!\n"); printf("Testing pngpack()/pngunpack() calls with constant data..."); { - g2int height = 2, width = 2, ndpts = DATA_LEN, len = PACKED_LEN; - float fld[DATA_LEN] = {1.0, 1.0, 1.0, 1.0}; - float fld_in[DATA_LEN]; - unsigned char cpack[PACKED_LEN]; - g2int lcpack; + g2int height = 2, width = 2, ndpts = DATA_LEN, len = PACKED_LEN; + float fld[DATA_LEN] = {1.0, 1.0, 1.0, 1.0}; + float fld_in[DATA_LEN]; + unsigned char cpack[PACKED_LEN]; + g2int lcpack; /* See https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-41.shtml */ g2int idrstmpl[5] = { - 0, /* Reference value (R) (IEEE 32-bit floating-point value) */ - 0, /* Binary scale factor (E) */ - 1, /* Decimal scale factor (D) */ + 0, /* Reference value (R) (IEEE 32-bit floating-point value) */ + 0, /* Binary scale factor (E) */ + 1, /* Decimal scale factor (D) */ 24, /* Number of bits required to hold the resulting scaled and referenced data values. (i.e. The depth of the grayscale image.) (see Note 2) */ - 0 /* Type of original field values (see Code Table 5.1) */ + 0 /* Type of original field values (see Code Table 5.1) */ }; - int i; + int i; - /* Pack the data. */ - pngpack(fld, width, height, idrstmpl, cpack, &lcpack); + /* Pack the data. */ + pngpack(fld, width, height, idrstmpl, cpack, &lcpack); - /* Unpack the data. */ - if (pngunpack(cpack, len, idrstmpl, ndpts, fld_in)) - return G2C_ERROR; + /* Unpack the data. */ + if (pngunpack(cpack, len, idrstmpl, ndpts, fld_in)) + 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; - } + 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("Testing g2c_pngpackd()/g2c_pngunpackd() calls with constant data..."); { - size_t height = 2, width = 2; - size_t ndpts = DATA_LEN, len = PACKED_LEN; - double fld[DATA_LEN] = {1.0, 1.0, 1.0, 1.0}; - double fld_in[DATA_LEN]; - unsigned char cpack[PACKED_LEN]; - int lcpack; + size_t height = 2, width = 2; + size_t ndpts = DATA_LEN, len = PACKED_LEN; + double fld[DATA_LEN] = {1.0, 1.0, 1.0, 1.0}; + double fld_in[DATA_LEN]; + unsigned char cpack[PACKED_LEN]; + int lcpack; /* See https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-41.shtml */ int idrstmpl[5] = { - 0, /* Reference value (R) (IEEE 32-bit floating-point value) */ - 0, /* Binary scale factor (E) */ - 1, /* Decimal scale factor (D) */ + 0, /* Reference value (R) (IEEE 32-bit floating-point value) */ + 0, /* Binary scale factor (E) */ + 1, /* Decimal scale factor (D) */ 24, /* Number of bits required to hold the resulting scaled and referenced data values. (i.e. The depth of the grayscale image.) (see Note 2) */ - 0 /* Type of original field values (see Code Table 5.1) */ + 0 /* Type of original field values (see Code Table 5.1) */ }; - int i; + int i; - /* Pack the data. */ - g2c_pngpackd(fld, width, height, idrstmpl, cpack, &lcpack); + /* Pack the data. */ + g2c_pngpackd(fld, width, height, idrstmpl, cpack, &lcpack); - /* Unpack the data. */ - if (g2c_pngunpackd(cpack, len, idrstmpl, ndpts, fld_in)) - return G2C_ERROR; + /* Unpack the data. */ + if (g2c_pngunpackd(cpack, len, idrstmpl, ndpts, fld_in)) + 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; - } + 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"); diff --git a/tests/tst_seekgb.c b/tests/tst_seekgb.c index f094ddbb..77c5a824 100644 --- a/tests/tst_seekgb.c +++ b/tests/tst_seekgb.c @@ -4,8 +4,8 @@ * Ed Hartnett 12/9/21 */ -#include #include "grib2_int.h" +#include #define GRIB2_FILE "data/gdaswave.t00z.wcoast.0p16.f000.grib2" #define GRIB2_INDEX_FILE "data/gdaswave.t00z.wcoast.0p16.f000.grib2.idx" diff --git a/tests/tst_simpack.c b/tests/tst_simpack.c index aacc13c0..cef1d17e 100644 --- a/tests/tst_simpack.c +++ b/tests/tst_simpack.c @@ -4,15 +4,15 @@ * Ed Hartnett 10/28/21 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" #define DATA_LEN 4 #define PACKED_LEN 40 g2int simunpack(unsigned char *cpack, g2int *idrstmpl, g2int ndpts, - float *fld); + float *fld); int main() @@ -20,127 +20,127 @@ main() printf("Testing simple packing/unpacking functions.\n"); printf("Testing simpack() call..."); { - g2int ndpts = DATA_LEN; - float fld[DATA_LEN] = {1.0, 2.0, 3.0, 0.0}; - float fld_in[DATA_LEN]; - unsigned char cpack[PACKED_LEN]; - g2int lcpack; + g2int ndpts = DATA_LEN; + float fld[DATA_LEN] = {1.0, 2.0, 3.0, 0.0}; + float fld_in[DATA_LEN]; + unsigned char cpack[PACKED_LEN]; + g2int lcpack; g2int idrstmpl[5] = {0, 1, 1, 16, 0}; - int i; + int i; - /* Pack the data. */ - simpack(fld, ndpts, idrstmpl, cpack, &lcpack); + /* Pack the data. */ + simpack(fld, ndpts, idrstmpl, cpack, &lcpack); - /* Unpack the data. */ - if (simunpack(cpack, idrstmpl, ndpts, fld_in)) - return G2C_ERROR; + /* Unpack the data. */ + if (simunpack(cpack, idrstmpl, ndpts, fld_in)) + 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; - } + 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("Testing simpack() call with constant field.."); { - g2int ndpts = DATA_LEN; - float fld[DATA_LEN] = {3.0, 3.0, 3.0, 3.0}; - float fld_in[DATA_LEN]; - unsigned char cpack[PACKED_LEN]; - g2int lcpack; + g2int ndpts = DATA_LEN; + float fld[DATA_LEN] = {3.0, 3.0, 3.0, 3.0}; + float fld_in[DATA_LEN]; + unsigned char cpack[PACKED_LEN]; + g2int lcpack; g2int idrstmpl[5] = {0, 1, 1, 16, 0}; - int i; + int i; - /* Pack the data. */ - simpack(fld, ndpts, idrstmpl, cpack, &lcpack); + /* Pack the data. */ + simpack(fld, ndpts, idrstmpl, cpack, &lcpack); - /* Unpack the data. */ - if (simunpack(cpack, idrstmpl, ndpts, fld_in)) - return G2C_ERROR; + /* Unpack the data. */ + if (simunpack(cpack, idrstmpl, ndpts, fld_in)) + 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; - } + 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("Testing simpack() call with idrstmpl[1] = 1, nbits = 0..."); { - g2int ndpts = DATA_LEN; - float fld[DATA_LEN] = {1.0, 2.0, 3.0, 0.0}; - float fld_in[DATA_LEN]; - unsigned char cpack[PACKED_LEN]; - g2int lcpack; + g2int ndpts = DATA_LEN; + float fld[DATA_LEN] = {1.0, 2.0, 3.0, 0.0}; + float fld_in[DATA_LEN]; + unsigned char cpack[PACKED_LEN]; + g2int lcpack; g2int idrstmpl[5] = {0, 1, 1, 0, 0}; - int i; + int i; - /* Pack the data. */ - simpack(fld, ndpts, idrstmpl, cpack, &lcpack); + /* Pack the data. */ + simpack(fld, ndpts, idrstmpl, cpack, &lcpack); - /* Unpack the data. */ - if (simunpack(cpack, idrstmpl, ndpts, fld_in)) - return G2C_ERROR; + /* Unpack the data. */ + if (simunpack(cpack, idrstmpl, ndpts, fld_in)) + 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; - } + 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("Testing simpack() call with idrstmpl[1] = 0, nbits = 0..."); { - g2int ndpts = DATA_LEN; - float fld[DATA_LEN] = {1.0, 2.0, 3.0, 0.0}; - float fld_in[DATA_LEN]; - unsigned char cpack[PACKED_LEN]; - g2int lcpack; + g2int ndpts = DATA_LEN; + float fld[DATA_LEN] = {1.0, 2.0, 3.0, 0.0}; + float fld_in[DATA_LEN]; + unsigned char cpack[PACKED_LEN]; + g2int lcpack; g2int idrstmpl[5] = {0, 0, 1, 0, 0}; - int i; + int i; - /* Pack the data. */ - simpack(fld, ndpts, idrstmpl, cpack, &lcpack); + /* Pack the data. */ + simpack(fld, ndpts, idrstmpl, cpack, &lcpack); - /* Unpack the data. */ - if (simunpack(cpack, idrstmpl, ndpts, fld_in)) - return G2C_ERROR; + /* Unpack the data. */ + if (simunpack(cpack, idrstmpl, ndpts, fld_in)) + 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; - } + 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("Testing simpack() call with idrstmpl[1] = 0, nbits = 16..."); { - g2int ndpts = DATA_LEN; - float fld[DATA_LEN] = {1.0, 2.0, 3.0, 0.0}; - float fld_in[DATA_LEN]; - unsigned char cpack[PACKED_LEN]; - g2int lcpack; + g2int ndpts = DATA_LEN; + float fld[DATA_LEN] = {1.0, 2.0, 3.0, 0.0}; + float fld_in[DATA_LEN]; + unsigned char cpack[PACKED_LEN]; + g2int lcpack; g2int idrstmpl[5] = {0, 0, 1, 16, 0}; - int i; + int i; - /* Pack the data. */ - simpack(fld, ndpts, idrstmpl, cpack, &lcpack); + /* Pack the data. */ + simpack(fld, ndpts, idrstmpl, cpack, &lcpack); - /* Unpack the data. */ - if (simunpack(cpack, idrstmpl, ndpts, fld_in)) - return G2C_ERROR; + /* Unpack the data. */ + if (simunpack(cpack, idrstmpl, ndpts, fld_in)) + 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; - } + 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"); diff --git a/tests/tst_spec.c b/tests/tst_spec.c index 391e9004..874f2bc9 100644 --- a/tests/tst_spec.c +++ b/tests/tst_spec.c @@ -4,9 +4,9 @@ * Ed Hartnett 11/1/21 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" #define DATA_LEN 4 #define PACKED_LEN 200 diff --git a/tests/tst_unpack.c b/tests/tst_unpack.c index 2dd94665..9a10264a 100644 --- a/tests/tst_unpack.c +++ b/tests/tst_unpack.c @@ -4,9 +4,9 @@ * Ed Hartnett 10/27/21 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" #define SEC0_LEN 16 #define SEC1_LEN 21 @@ -23,27 +23,27 @@ main() g2int expected_igds[5] = {0, 4, 0, 0, 0}; g2int expected_igdstmpl[19] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}; g2int expected_ipdstmpl[15] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; - + unsigned char cgrib[FULL_MSG_LEN] = { - 0x47, 0x52, 0x49, 0x42, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb6, /* section 0 */ - 0x00, 0x00, 0x00, 0x15, /* len of sect 1 (21) */ + 0x47, 0x52, 0x49, 0x42, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb6, /* section 0 */ + 0x00, 0x00, 0x00, 0x15, /* len of sect 1 (21) */ 0x01, 0x00, 0x07, 0x00, 0x04, 0x18, 0x00, 0x00, 0x07, 0xe5, 0x0a, 0x18, 0x06, 0x36, 0x3b, 0x07, 0xc0, /* section 1 */ - 0x00, 0x00, 0x00, 0x48, /* len of sect 3 (72) */ + 0x00, 0x00, 0x00, 0x48, /* len of sect 3 (72) */ 0x03, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00, 0x00, 0x04, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x0c, 0x0d, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x11, 0x12, - 0x00, 0x00, 0x00, 0x22, /* len of sect 4 (34) */ + 0x00, 0x00, 0x00, 0x22, /* len of sect 4 (34) */ 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x00, 0x05, 0x06, 0x07, 0x00, 0x00, /* section 4 */ 0x00, 0x08, 0x09, 0x0a, 0x00, 0x00, 0x00, 0x0b, 0x0c, 0x0d, 0x00, 0x00, 0x00, 0x0e, - 0x00, 0x00, 0x00, 0x15, /* len of sect 5 (21) */ + 0x00, 0x00, 0x00, 0x15, /* len of sect 5 (21) */ 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x42, 0xc8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x03, 0x00, /* section 5 */ - 0x00, 0x00, 0x00, 0x07, /* len of sect 6 (7) */ - 0x06, 0x00, 0xf0, /* section 6 */ - 0x00, 0x00, 0x00, 0x07, /* len of sect 7 (7) */ - 0x07, 0x0a, 0x60, /* section 7 */ - 0x37, 0x37, 0x37, 0x37}; /* "7777" (section 8) */ + 0x00, 0x00, 0x00, 0x07, /* len of sect 6 (7) */ + 0x06, 0x00, 0xf0, /* section 6 */ + 0x00, 0x00, 0x00, 0x07, /* len of sect 7 (7) */ + 0x07, 0x0a, 0x60, /* section 7 */ + 0x37, 0x37, 0x37, 0x37}; /* "7777" (section 8) */ g2int iofst = 128, idslen; unsigned char old_val; g2int *ids; @@ -61,7 +61,7 @@ main() if (g2_unpack1(cgrib, &iofst, &ids, &idslen) != 2) return G2C_ERROR; cgrib[20] = old_val; - + /* Unpack section1 - starts at bit 128. */ iofst = 128; if (g2_unpack1(cgrib, &iofst, &ids, &idslen)) diff --git a/tests/tst_xml.c b/tests/tst_xml.c index 0cff9cdc..2a0eae84 100644 --- a/tests/tst_xml.c +++ b/tests/tst_xml.c @@ -4,39 +4,38 @@ * Ed Hartnett 8/27/22 */ +#include "grib2_int.h" #include #include -#include "grib2_int.h" int main() { int ret; char desc[G2C_MAX_GRIB_DESC_LEN + 1]; - + printf("Testing XML ingestion...\n"); if (g2c_xml_init()) - return G2C_ERROR; + return G2C_ERROR; if ((ret = g2c_find_desc("Code table 0.0", 0, desc))) - return ret; + return ret; if (strcmp("Meteorological products", desc)) - return G2C_ERROR; + return G2C_ERROR; if ((ret = g2c_find_desc_str("Code table 0.0", "0", desc))) - return ret; + return ret; if (strcmp("Meteorological products", desc)) - return G2C_ERROR; + return G2C_ERROR; /* Calling init again is harmless. */ if (g2c_xml_init()) - return G2C_ERROR; - + return G2C_ERROR; + g2c_free_tables(); /* Calling free again is harmless. */ g2c_free_tables(); - + printf("desc %s\n", desc); printf("SUCCESS!!!\n"); return G2C_NOERROR; } -