NOAA-EMC / NCEPLIBS-g2c

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

differences in pdstemplates between g2 and g2c libraries #383

Closed edwardhartnett closed 1 month ago

edwardhartnett commented 2 years ago

When we have the same data in two places it's an invitation for bugs. We invited them in, now we have them. ;-)

pdstemplate info is stored in both the C and Fortran libraries. What I have just discovered is that there are numerous differences.

For example, in NCEPLIBS-g2/src/pdstemplates.F90:

  data templates(1)%template_num /0/     !  Fcst at Level/Layer
  data templates(1)%mappdslen /15/
  data templates(1)%needext /.false./
  data (templates(1)%mappds(j), j = 1, 15)  &
       /1, 1, 1, 1, 1, 2, 1, 1, 4, 1, -1, -4, 1, -1, -4/

From NCEPLIBS-g2c/src/pdstemplates.c:

{0, 15, 0, {1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}},

Note that the 9th template item is 4 in Fortran, -4 in C. (The correct answer is -4, see #381).

To fix we need firstly full testing of all these values in both C and Fortran, to lock everything down.

Then we will find the differences and fix them.

The final solution will be that only the C library maintains these numbers, and the Fortran library gets them from the C library.

AlysonStahl-NOAA commented 1 month ago

I believe all of the differences should be addressed now.