NOAA-EMC / NCEPLIBS-g2tmpl

GRIB2 codes and templates
Other
4 stars 9 forks source link

An entry in data_table1_4 exceeds size of char array #70

Closed edwardhartnett closed 6 months ago

edwardhartnett commented 2 years ago

We have this code in grib2_all_tables_module.F90:

  type type_of_data
     character(len=20) :: typeofdatakey
     integer :: typeofdataval
  end type type_of_data
  !
  !> table1_4
  type(type_of_data),dimension(MAXTYPEOFDATA) :: table1_4

  data table1_4(1) /type_of_data('anal',0)/
  data table1_4(2) /type_of_data('fcst',1)/
  data table1_4(3) /type_of_data('anal_fcst',2)/
  data table1_4(4) /type_of_data('con_fcst',3)/
  data table1_4(5) /type_of_data('per_fcst',4)/
  data table1_4(6) /type_of_data('con_per_fcst',5)/
  data table1_4(7) /type_of_data('proc_sat_obs',6)/
  data table1_4(8) /type_of_data('proc_rad_obs',7)/
  data table1_4(9) /type_of_data('event_prob',8)/
  data table1_4(10) /type_of_data('missing',255)/
  data table1_4(11) /type_of_data('experimental_products',192)/

Note that 'experimental_products' is 21 chars long!

I'm not sure what should be done to fix this...

edwardhartnett commented 2 years ago

This test code succeeds, so perhaps the answer is to drop the final character so it fits, which is what fortran seems to be doing:

  ! Note that the file grib2_all_tables_module.f90 has 'experimental_products'.
  call get_g2_typeofdata('experimental_product', val1, ierr)
  if (val1 .ne. 192) stop 6
edwardhartnett commented 2 years ago

Also this entry exceeds it's limit of 30:

data on388_tablea(115) /gen_proc('extra_trop_storm_surge_micronesia',20)/

edwardhartnett commented 2 years ago

@BoiVuong-NOAA @Hang-Lei-NOAA any suggestions for this problem?

Hang-Lei-NOAA commented 2 years ago

Remove the length definition, or give a large number?

BoiVuong-NOAA commented 2 years ago

We should increase the length of definition. character(len=30) :: genprockey ===> character(len=100) :: genprockey and character(len=20) :: typeofdatakey ====> character(len=50) :: typeofdatakey

edwardhartnett commented 2 years ago

Currently, the only way these work is to give the truncated version. For example this works: call get_g2_typeofdata('experimental_product', val1, ierr)

Now if we increase the length, this will no longer work.

So anyone who wanted to use these codes will be using the truncated versions, and when we increase the length we will break their code.

Is this OK? Do we know that these codes are not used in the UFS?

BoiVuong-NOAA commented 2 years ago

Yes, I think no one is using it. We can have truncated version. If you have chance, we can increase the length at later time.

edwardhartnett commented 6 months ago

OK, I truncated all char strings that were too long, so that it would not break backward compatibility.

I have turned on -Wall and -Werror in the CI, to prevent more warnings from being introduced, which will prevent this problem occurring again.