diff --git a/tests/run_wgrib2_tests.sh b/tests/run_wgrib2_tests.sh index fbabce13..7dde2e92 100755 --- a/tests/run_wgrib2_tests.sh +++ b/tests/run_wgrib2_tests.sh @@ -112,5 +112,18 @@ echo "*** Testing write/read section" touch secs.txt diff -w secs.txt simple.txt + +echo "*** test pdt 48 ***" +n=`../wgrib2/wgrib2 ./data/gdas.t12z.pgrb2.1p00.anl.75r.grib2 -d 1 -set_pdt +48 -set_byte 4 12 00:12:0 | grep -c "aerosol_size"` +if [ "$n" -ne 1 ] ; then + exit 1 +fi +set -x +echo "*** test pdt 49 ***" +n=`../wgrib2/wgrib2 ./data/gdas.t12z.pgrb2.1p00.anl.75r.grib2 -d 1 -set_pdt +49 -set_byte 4 12 00:12:0 | grep -c "aerosol_size"` +if [ "$n" -ne 1 ] ; then + exit 1 +fi + echo "*** SUCCESS!" exit 0 diff --git a/wgrib2/Aerosol.c b/wgrib2/Aerosol.c index 3ddf45be..9a458052 100644 --- a/wgrib2/Aerosol.c +++ b/wgrib2/Aerosol.c @@ -6,6 +6,7 @@ /* * 2/2012 Public Domain: Wesley Ebisuzaki + * 10/2024 fix to handle all pdts Wesley Ebisuzaki */ /* @@ -13,24 +14,19 @@ */ int f_aerosol_size(ARG0) { - int pdt, type; - unsigned char *sec4; + unsigned char *ptr; double size1, size2; - + if (mode >= 0) { - pdt = code_table_4_0(sec); - if (pdt < 44 || pdt > 48) return 0; - type = code_table_4_91(sec); - if (type == 255) return 0; - sec4 = sec[4]; - - size1 = scaled2dbl(INT1(sec4[14]), int4(sec4+15)); - size2 = scaled2dbl(INT1(sec4[19]), int4(sec4+20)); + ptr = code_table_4_91_location(sec); + if (ptr == NULL) return 0; + if (*ptr == 255) return 0; + size1 = scaled2dbl(INT1(ptr[1]), int4(ptr+2)); + size2 = scaled2dbl(INT1(ptr[6]), int4(ptr+7)); sprintf(inv_out,"aerosol_size "); inv_out += strlen(inv_out); - type = code_table_4_91(sec); - prt_code_table_4_91(type, size1, size2, inv_out); + prt_code_table_4_91(ptr[0], size1, size2, inv_out); } return 0; @@ -40,23 +36,19 @@ int f_aerosol_size(ARG0) { */ int f_aerosol_wavelength(ARG0) { - int pdt, type; - unsigned char *sec4; + unsigned char *ptr; double wave1, wave2; if (mode >= 0) { - pdt = code_table_4_0(sec); - if (pdt != 48) return 0; - type = code_table_4_91b(sec); - if (type == 255) return 0; - sec4 = sec[4]; - - wave1 = scaled2dbl(INT1(sec4[25]), int4(sec4+26)); - wave2 = scaled2dbl(INT1(sec4[30]), int4(sec4+31)); + ptr = code_table_4_91b_location(sec); + if (ptr == NULL) return 0; + if (*ptr == 255) return 0; + wave1 = scaled2dbl(INT1(ptr[1]), int4(ptr+2)); + wave2 = scaled2dbl(INT1(ptr[6]), int4(ptr+7)); sprintf(inv_out,"aerosol_wavelength "); inv_out += strlen(inv_out); - prt_code_table_4_91(type, wave1, wave2, inv_out); + prt_code_table_4_91(ptr[0], wave1, wave2, inv_out); } return 0; diff --git a/wgrib2/ExtName.c b/wgrib2/ExtName.c index 19850e88..af5b4390 100644 --- a/wgrib2/ExtName.c +++ b/wgrib2/ExtName.c @@ -188,9 +188,8 @@ int f_misc(ARG0) { strcat(inv_out,":"); inv_out += strlen(inv_out); } - if (pdt == 48) { + if (pdt == 48 || pdt == 49) { /* aerosol with optical properties */ f_aerosol_size(call_ARG0(inv_out,NULL)); - strcat(inv_out,":"); inv_out += strlen(inv_out); f_aerosol_wavelength(call_ARG0(inv_out,NULL)); strcat(inv_out,":");