NOAA-EMC / NCEPLIBS-g2c

This library contains C decoder/encoder routines for GRIB edition 2.
Other
18 stars 11 forks source link

pdstemplate 32 (Analysis or Forecast at a horizontal level or in a horizontal layer at a point in time for simulated (synthetic) satellite data) wrong #346

Closed edwardhartnett closed 1 year ago

edwardhartnett commented 1 year ago

For pdstemplate.c we have:

    else if (number == 32)
    {
        new->extlen = list[9] * 10;
        new->ext = malloc(sizeof(g2int) * new->extlen);
        for (i = 0; i < list[9]; 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;
        }

Since the ext array is of length list[9] 10, and then initializes list[9] 5, half of the extension array is not initialized.

Looking at the documents here https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp4-32.shtml seems like the extlen should be list[9] * 5.

When I look at the Fortran code I see that list[9]*5 is correct for the C code:

   elseif (number .eq. 32) then
       do j = 1, list(10)
          map(nummap + 1) = 2
          map(nummap + 2) = 2
          map(nummap + 3) = 2
          map(nummap + 4) = -1
          map(nummap + 5) = -4
          nummap = nummap + 5
       enddo