NOAA-EMC / NCEPLIBS-g2tmpl

GRIB2 codes and templates
Other
4 stars 9 forks source link

Segmentation fault in process_4dot2.c #60

Open DusanJovic-NOAA opened 2 years ago

DusanJovic-NOAA commented 2 years ago

The following test program segfaults:

$ cat test4.2.f90 
  program test42
    implicit none
    integer ierr
    character(len=20) :: fl_nametbl='params_grib2_tbl_new'

    call open_and_read_4dot2( fl_nametbl, ierr )
    print *, ierr
    call close_4dot2(ierr)
    print *, ierr

    call open_and_read_4dot2( fl_nametbl, ierr )
    print *, ierr
    call close_4dot2(ierr)
    print *, ierr

  end program test42

$ gfortran test4.2.f90 /scratch2/NCEPDEV/nwprod/hpc-stack/libs/hpc-stack/gnu-9.2.0/g2tmpl/1.10.2/lib/libg2tmpl.a 

$ ./a.out 
           0
           0

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x7f4cf49383ff in ???
#1  0x7f4cf4985d1d in ???
#2  0x7f4cf4987e11 in ???
#3  0x400fcf in open_and_read_4dot2_
        at /scratch2/NCEPDEV/nwprod/hpc-stack/src/develop/pkg/g2tmpl-v1.10.2/src/process_4dot2.c:158
#4  0x400d98 in ???
#5  0x400e9f in ???
#6  0x7f4cf4924554 in ???
#7  0x400be8 in ???
#8  0xffffffffffffffff in ???
Segmentation fault
edwardhartnett commented 2 years ago

Can you tell me what this code does?

I know that it relates to the ASCII table we have, called params_grib2_tbl_new.text, which contains this kind of thing:

!
!Table History Log: 
!2010-01-21         V. Krishna Kumar/NCO/SIB
!2011-09-25         V. Krishna Kumar updated the parameters since
!                   the 2010 implemenation
!2012-01-25         J. WANG          updated table 4.2-0-20 
!2013-08-08         B. VUONG         Added more parameters 
!2015-08-26         B. VUONG         Added more parameters and
!                                    updated table 4.2-0-20
!2017-02-28         B. VUONG         Added more parameters and
!                                    new tables 4.2-3-2,3,4,and 6
!2019-07-02         B. VUONG         Added more parameters 
!2021-04-20         B. VUONG         Added more parameters 
!
!GRIB2 parameter table for all disciplines and categories
!The fields in order are grib2_discipline  grib2_category 
!grib2_parameter_number grib2_table_information (0 for the parameter
!from the WMO table and 1 for the parameter from the NCEP local table)
!grib2_NCEP_mnemonic (locally defined at NCEP). WMO parameters have values
!ranging from 0 to 191 and NCEP local table parameters have values from 192  
!to 254 and the parameter value 255 is a missing or undefined.
!Comment cards with the ! will not be read by the program 
!
!
! GRIB2 - TABLE 4.2-0-0 PARAMETERS FOR DISCIPLINE 0 CATEGORY 0
!
   0   0     0   0 TMP
   0   0     1   0 VTMP
   0   0     2   0 POT
   0   0     3   0 EPOT

What do we use this table for? Why do we process it?

Any answers would be most helpful, and will be added to the documentation for this poorly-documented code.

edwardhartnett commented 5 months ago

Some of my questions above are answered here: https://github.com/NOAA-EMC/NCEPLIBS-g2tmpl/issues/40

Others are answered in recent additions to the doxygen docs for this project.