diff --git a/.github/workflows/Spack.yml b/.github/workflows/Spack.yml index faede806..f2ffadaf 100644 --- a/.github/workflows/Spack.yml +++ b/.github/workflows/Spack.yml @@ -44,5 +44,5 @@ jobs: with: recipe-file: package/spack/package.py cmakelists-txt: package/CMakeLists.txt - ignore-list: USE_HDF5,BUILD_WGRIB,FTP_TEST_FILES,FTP_LARGE_TEST_FILES,FTP_EXTRA_TEST_FILES + ignore-list: USE_HDF5,BUILD_WGRIB,FTP_TEST_FILES,FTP_LARGE_TEST_FILES,FTP_EXTRA_TEST_FILES,BUILD_EXTRA alternative-grep: true diff --git a/CMakeLists.txt b/CMakeLists.txt index 8bdc4efe..d535c4ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,7 @@ option(BUILD_SHARED_LIB "Build shared library?" on) # and manually create libwgrib2.so from the needed *.a files option(BUILD_WGRIB "Build wgrib code?" off) +option(BUILD_EXTRA "Build user-contributed code" on) if (MAKE_FTN_API OR USE_IPOLATES) enable_language(Fortran) @@ -146,6 +147,11 @@ message(STATUS "Writing config.h...") configure_file("${PROJECT_SOURCE_DIR}/wgrib2/config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/config.h") include_directories(${CMAKE_CURRENT_BINARY_DIR}) +message(STATUS "Checking if the user wants to use user-contributed code...") +if (BUILD_EXTRA) +add_subdirectory(extra) +endif() + message(STATUS "Adding wgrib2, aux_probs subdirectories...") add_subdirectory(wgrib2) add_subdirectory(aux_progs) diff --git a/extra/CMakeLists.txt b/extra/CMakeLists.txt new file mode 100644 index 00000000..d16f635b --- /dev/null +++ b/extra/CMakeLists.txt @@ -0,0 +1,5 @@ +set(extra_src Mysql.c Mysql_dump.c Mysql_speed.c) + +add_library(extra OBJECT ${extra_src}) + +install(TARGETS extra RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) \ No newline at end of file diff --git a/wgrib2/Mysql.c b/extra/Mysql.c similarity index 100% rename from wgrib2/Mysql.c rename to extra/Mysql.c diff --git a/wgrib2/Mysql_dump.c b/extra/Mysql_dump.c similarity index 100% rename from wgrib2/Mysql_dump.c rename to extra/Mysql_dump.c diff --git a/wgrib2/Mysql_speed.c b/extra/Mysql_speed.c similarity index 100% rename from wgrib2/Mysql_speed.c rename to extra/Mysql_speed.c diff --git a/extra/grb2.h b/extra/grb2.h new file mode 100644 index 00000000..f36a8e95 --- /dev/null +++ b/extra/grb2.h @@ -0,0 +1,257 @@ +/* grb2.h 10/2024 Public Domain Wesley Ebisuzaki */ + +#ifndef INT3 +#define INT3(a,b,c) ((1-(int) ((unsigned) (a & 0x80) >> 6)) * (int) (((a & 127) << 16)+(b<<8)+c)) +#endif +#ifndef INT2 +#define INT2(a,b) ((1-(int) ((unsigned) (a & 0x80) >> 6)) * (int) (((a & 127) << 8) + b)) +#endif +#ifndef INT1 +#define INT1(a) ((a & 0x80) ? - (int) (a & 127) : (int) (a & 127)) +#endif + +#ifndef UINT4 +#define UINT4(a,b,c,d) ((int) ((a <<24) + (b << 16) + (c << 8) + (d))) +#endif + +#ifndef UINT3 +#define UINT3(a,b,c) ((int) ((a << 16) + (b << 8) + (c))) +#endif + +#ifndef UINT2 +#define UINT2(a,b) ((int) ((a << 8) + (b))) +#endif + +/* Section 0 */ +#define GB2_Sec0_size 16 +#define GB2_Discipline(sec) ((int) (sec[0][6])) +#define GB2_Edition(sec) ((int) (sec[0][7])) +#define GB2_MsgLen(sec) uint8(&(sec[0][8])) + +/* Section 1 */ +#define GB2_Sec1_size(sec) (sec[1] ? uint4(sec[1]+0) : 0) +#define GB2_Center(sec) UINT2(sec[1][5], sec[1][6]) +#define GB2_Subcenter(sec) UINT2(sec[1][7], sec[1][8]) +#define GB2_MasterTable(sec) ((int) (sec[1][9])) +// #define GB2_LocalTable(sec) ((int) (sec[1][10])) +#define GB2_LocalTable(sec) sec[1][10] + +/* Section 2 */ +#define GB2_Sec2_size(sec) (sec[2] ? uint4(sec[2]+0) : 0) + +/* Section 3 */ +#define GB2_Sec3_size(sec) (sec[3] ? uint4(sec[3]+0) : 0) +#define GB2_Sec3_num(sec) ((int) (sec[3][4])) +#define GB2_Sec3_gdef(sec) ((int) (sec[3][5])) +#define GB2_Sec3_npts(sec) uint4(sec[3]+6) +// #define GB2_gds_npts(gds) uint4(gds+6) +/* #define GB2_Sec3_GridDefTemplateNo(sec) UINT2(sec[3][12], sec[3][13]) */ +/* #define GB2_GridDefTemplateNo(sec) UINT2(gds[12], gds[13]) */ + +#define GDS_Lambert_La1(gds) (int4(gds+38) * 0.000001) +#define GDS_Lambert_Lo1(gds) (int4(gds+42) * 0.000001) +#define GDS_Lambert_LatD(gds) (int4(gds+47) * 0.000001) +#define GDS_Lambert_Lov(gds) (int4(gds+51) * 0.000001) +#define GDS_Lambert_Latin1(gds) (int4(gds+65) * 0.000001) +#define GDS_Lambert_Latin2(gds) (int4(gds+69) * 0.000001) +#define GDS_Lambert_LatSP(gds) (int4(gds+73) * 0.000001) +#define GDS_Lambert_LonSP(gds) (int4(gds+77) * 0.000001) + +#define GDS_Lambert_NP(gds) (((gds[63]) & 128) == 0) +#define GDS_Lambert_nx(gds) (uint4_missing(gds+30)) +#define GDS_Lambert_ny(gds) (uint4_missing(gds+34)) +#define GDS_Lambert_dx(gds) (int4(gds+55) * 0.001) +#define GDS_Lambert_dy(gds) (int4(gds+59) * 0.001) + +#define GDS_Albers_La1(gds) (int4(gds+38) * 0.000001) +#define GDS_Albers_Lo1(gds) (int4(gds+42) * 0.000001) +#define GDS_Albers_LatD(gds) (int4(gds+47) * 0.000001) +#define GDS_Albers_Lov(gds) (int4(gds+51) * 0.000001) +#define GDS_Albers_Latin1(gds) (int4(gds+65) * 0.000001) +#define GDS_Albers_Latin2(gds) (int4(gds+69) * 0.000001) +#define GDS_Albers_LatSP(gds) (int4(gds+73) * 0.000001) +#define GDS_Albers_LonSP(gds) (int4(gds+77) * 0.000001) + +#define GDS_Albers_NP(gds) (((gds[63]) & 128) == 0) +#define GDS_Albers_nx(gds) (uint4_missing(gds+30)) +#define GDS_Albers_ny(gds) (uint4_missing(gds+34)) +#define GDS_Albers_dx(gds) (int4(gds+55) * 0.001) +#define GDS_Albers_dy(gds) (int4(gds+59) * 0.001) + +#define GDS_LatLon_basic_ang(gds) int4(gds+38) +#define GDS_LatLon_sub_ang(gds) sub_angle(gds+42) +#define GDS_LatLon_lat1(gds) int4(gds+46) +#define GDS_LatLon_lon1(gds) uint4(gds+50) +#define GDS_LatLon_lat2(gds) int4(gds+55) +#define GDS_LatLon_lon2(gds) uint4(gds+59) +#define GDS_LatLon_dlon(gds) int4(gds+63) +#define GDS_LatLon_dlat(gds) int4(gds+67) +#define GDS_LatLon_nx(gds) (uint4(gds+30)) +#define GDS_LatLon_ny(gds) (uint4(gds+34)) + +#define GDS_RotLatLon_sp_lat(gds) (int4(gds+72)) +#define GDS_RotLatLon_sp_lon(gds) (uint4(gds+76)) +#define GDS_RotLatLon_rotation(gds) (int4(gds+80)) + +#define GDS_NCEP_B_LatLon_nx(gds) (uint4(gds+30)) +#define GDS_NCEP_B_LatLon_ny(gds) (uint4(gds+34)) +#define GDS_NCEP_B_LatLon_basic_ang(gds) int4(gds+38) +#define GDS_NCEP_B_LatLon_sub_ang(gds) sub_angle(gds+42) +#define GDS_NCEP_B_LatLon_lat1(gds) int4(gds+46) +#define GDS_NCEP_B_LatLon_lon1(gds) uint4(gds+50) +#define GDS_NCEP_B_LatLon_tph0d(gds) int4(gds+55) +#define GDS_NCEP_B_LatLon_tlm0d(gds) uint4(gds+59) +#define GDS_NCEP_B_LatLon_dlon(gds) int4(gds+63) +#define GDS_NCEP_B_LatLon_dlat(gds) int4(gds+67) +#define GDS_NCEP_B_LatLon_lat2(gds) (int4(gds+72)) +#define GDS_NCEP_B_LatLon_lon2(gds) (uint4(gds+76)) + +#define GDS_NCEP_E_LatLon_nx(gds) (uint4(gds+30)) +#define GDS_NCEP_E_LatLon_ny(gds) (uint4(gds+34)) +#define GDS_NCEP_E_LatLon_basic_ang(gds) int4(gds+38) +#define GDS_NCEP_E_LatLon_sub_ang(gds) sub_angle(gds+42) +#define GDS_NCEP_E_LatLon_lat1(gds) int4(gds+46) +#define GDS_NCEP_E_LatLon_lon1(gds) uint4(gds+50) +#define GDS_NCEP_E_LatLon_tph0d(gds) int4(gds+55) +#define GDS_NCEP_E_LatLon_tlm0d(gds) uint4(gds+59) +#define GDS_NCEP_E_LatLon_dlon(gds) int4(gds+63) +#define GDS_NCEP_E_LatLon_dlat(gds) int4(gds+67) + + +#define GDS_Mercator_nx(gds) (uint4(gds+30)) +#define GDS_Mercator_ny(gds) (uint4(gds+34)) +#define GDS_Mercator_dx(gds) ((uint4(gds+64))*0.001) +#define GDS_Mercator_dy(gds) ((uint4(gds+68))*0.001) +#define GDS_Mercator_lat1(gds) (int4(gds+38)*0.000001) +#define GDS_Mercator_lon1(gds) (uint4(gds+42)*0.000001) +#define GDS_Mercator_lat2(gds) (int4(gds+51)*0.000001) +#define GDS_Mercator_lon2(gds) (uint4(gds+55)*0.000001) +#define GDS_Mercator_latD(gds) (int4(gds+47)*0.000001) +#define GDS_Mercator_ori_angle(gds) (uint4(gds+60)*0.000001) + +#define GDS_Polar_nx(gds) (uint4_missing(gds+30)) +#define GDS_Polar_ny(gds) (uint4_missing(gds+34)) +#define GDS_Polar_lat1(gds) (int4(gds+38)*0.000001) +#define GDS_Polar_lon1(gds) (uint4(gds+42)*0.000001) +#define GDS_Polar_lad(gds) (int4(gds+47)*0.000001) +#define GDS_Polar_lov(gds) (uint4(gds+51)*0.000001) +#define GDS_Polar_dx(gds) (uint4(gds+55)*0.001) +#define GDS_Polar_dy(gds) (uint4(gds+59)*0.001) +#define GDS_Polar_nps(gds) ((gds[63] & 128) == 0) +#define GDS_Polar_sps(gds) ((gds[63] & 128) == 128) + +#define GDS_Gaussian_nx(gds) (uint4_missing(gds+30)) +#define GDS_Gaussian_ny(gds) (uint4(gds+34)) +#define GDS_Gaussian_nlat(gds) (uint4(gds+67)) +#define GDS_Gaussian_basic_ang(gds) int4(gds+38) +#define GDS_Gaussian_sub_ang(gds) sub_angle(gds+42) +#define GDS_Gaussian_lat1(gds) int4(gds+46) +#define GDS_Gaussian_lon1(gds) uint4(gds+50) +#define GDS_Gaussian_lat2(gds) int4(gds+55) +#define GDS_Gaussian_lon2(gds) uint4(gds+59) +#define GDS_Gaussian_dlon(gds) int4(gds+63) + +#define GDS_Harmonic_j(gds) int4(gds+14) +#define GDS_Harmonic_k(gds) int4(gds+18) +#define GDS_Harmonic_m(gds) int4(gds+22) +#define GDS_Harmonic_code_3_6(gds) ((int) gds[26]) +#define GDS_Harmonic_code_3_7(gds) ((int) gds[27]) + +#define GDS_Space_lap(gds) (int4(gds+38)*1e-6) +#define GDS_Space_lop(gds) (int4(gds+42)*1e-6) +#define GDS_Space_dx(gds) uint4(gds+47) +#define GDS_Space_dy(gds) uint4(gds+51) +#define GDS_Space_xp(gds) (int4(gds+55)*1e-3) +#define GDS_Space_yp(gds) (int4(gds+59)*1e-3) +#define GDS_Space_ori(gds) (int4(gds+64)*1e-6) +// #define GDS_Space_altitude(gds) (uint4_missing(gds+68) == -1 ? -1 : int4(gds+68)*1e-6) +#define GDS_Space_altitude(gds) (uint4_missing(gds+68) == 0 ? -1 : int4(gds+68)*1e-6) +#define GDS_Space_x0(gds) (int4(gds+72)) +#define GDS_Space_y0(gds) (int4(gds+76)) + +#define GDS_AzRan_lat1(gds) (int4(gds+22)*1e-6) +#define GDS_AzRan_lon1(gds) (uint4(gds+26)*1e-6) +#define GDS_AzRan_dx(gds) (uint4(gds+30)*1e-3) +#define GDS_AzRan_dstart(gds) (uint4(gds+34)*1e-3) + + +#define GDS_Lambert_Az_La1(gds) (int4(gds+38) * 0.000001) +// #define GDS_Lambert_Az_Lo1(gds) (uint4(gds+42) * 0.000001) +#define GDS_Lambert_Az_Lo1(gds) (int4(gds+42) * 0.000001) +#define GDS_Lambert_Az_Std_Par(gds) (int4(gds+46) * 0.000001) +#define GDS_Lambert_Az_Cen_Lon(gds) (int4(gds+50) * 0.000001) +#define GDS_Lambert_Az_nx(gds) (uint4_missing(gds+30)) +#define GDS_Lambert_Az_ny(gds) (uint4_missing(gds+34)) +#define GDS_Lambert_Az_dx(gds) (int4(gds+55) * 0.001) +#define GDS_Lambert_Az_dy(gds) (int4(gds+59) * 0.001) + +// #ifdef WMO_VALIDATION +#define GDS_Gnom_face_size(gds) uint4(gds+38) +#define GDS_Gnom_i_offset(gds) uint4(gds+42) +#define GDS_Gnom_j_offset(gds) uint4(gds+46) +#define GDS_Gnom_tile(gds) gds[50] +#define GDS_Gnom_SP_Lat(gds) (int4(gds+51) * 0.000001) +#define GDS_Gnom_SP_Lon(gds) (uint4(gds+55) * 0.000001) +// not sure if rotation angle can be negative +#define GDS_Gnom_SP_Rot(gds) (int4(gds+59) * 0.000001) +#define GDS_Gnom_Stretch(gds) (int4(gds+63) * 0.000001) +#define GDS_Gnom_B(gds) (int4(gds+67) * 0.000001) +// #endif + + +#define GDS_CrossSec_basic_ang(gds) int4(gds+34) +#define GDS_CrossSec_sub_ang(gds) int4(gds+38) +#define GDS_CrossSec_lat1(gds) int4(gds+42) +#define GDS_CrossSec_lon1(gds) uint4(gds+46) +#define GDS_CrossSec_lat2(gds) int4(gds+51) +#define GDS_CrossSec_lon2(gds) uint4(gds+55) + +/* GDS_Scan_x -> +ve x scanning */ +#define GDS_Scan_x(scan) ((scan & 128) == 0) +/* GDS_Scan_y -> +ve y scanning */ +#define GDS_Scan_y(scan) ((scan & 64) == 64) +/* GDS_Scan_fortran -> fortran storage order */ +#define GDS_Scan_fortran(scan) ((scan & 32) == 32) +/* GDS_Scan_row_rev -> row reversing order */ +#define GDS_Scan_row_rev(scan) ((scan & 16) == 16) +/* GDS_Scan_staggered test for staggered grid*/ +#define GDS_Scan_staggered(scan) (((scan) & 15) != 0) +/* GDS_Scan_staggered_storage test for grid size != nx*ny */ +#define GDS_Scan_staggered_storage(scan) (((scan) & (1)) != 0) + +/* Section 4 */ +#define GB2_Sec4_size(sec) (sec[4] ? uint4(sec[4]+0) : 0) +#define GB2_Sec4_num(sec) ((int) (sec[4][4])) +#define GB2_ProdDefTemplateNo(sec) (UINT2(sec[4][7],sec[4][8])) + +#define GB2_ParmCat(sec) (sec[4][9]) + +#define GB2_ParmNum(sec) (sec[4][10]) + +// #define GB2_ForecastTime(sec) (UINT4(sec[4][18],sec[4][19],sec[4][20],sec[4][21])) +// replaced by forecast_time_in_units +// #define GB2_TimeUnit2(sec) (sec[4][48]) +// #define GB2_ForecastTime2(sec) (UINT4(sec[4][49],sec[4][50],sec[4][51],sec[4][52])) +// #define GB2_StatProcess(sec) UINT2(sec[4][45], sec[4][46]) + +/* Section 5 */ +#define GB2_Sec5_size(sec) (sec[5] ? uint4(sec[5]+0) : 0) +#define GB2_Sec5_nval(sec) (sec[5] ? uint4(sec[5]+5) : 0) + +/* Section 6 */ +#define GB2_Sec6_size(sec) (sec[6] ? uint4(sec[6]+0) : 0) + +/* Section 7 */ +#define GB2_Sec7_size(sec) (sec[7] ? uint4(sec[7]+0) : 0) + +/* Section 8 */ +#define GB2_Sec8_size 4 + +/* some center codes */ +#define NCEP 7 +#define ECMWF 98 +#define JMA1 34 +#define JMA2 35 +#define KMA 40 +#define DWD1 78 +#define DWD2 79 diff --git a/wgrib2/mysql_speed_readme.txt b/extra/mysql_speed_readme.txt similarity index 98% rename from wgrib2/mysql_speed_readme.txt rename to extra/mysql_speed_readme.txt index f5f57661..b937c7e6 100644 --- a/wgrib2/mysql_speed_readme.txt +++ b/extra/mysql_speed_readme.txt @@ -1,127 +1,127 @@ -/****************************************************************************************** - Copyright (C) 2008 Niklas Sondell, Storm Weather Center - MYSQL_speed is part of wgrib2 and could be distributed under terms of the GNU General Public License -/****************************************************************************************** - -MYSQL SPEED for wgrib2 - -This is a very fast version of the mysql insertion with wgrib2. It also results in a much -better structure of the database table which also makes the usage afterwards much faster. -It can be used only when the gribfile contains data with: - -1. All fields for insertion with the same runtime (anatime). -2. All fields for insertion with the same validtime (verf time). -3. All fields with the same GDS, grid definition. All fields for insertion needs to have the same lat/lon grid definition. - -If these criterias are not fulfilled it will result in an error. -Number of points in the grid are set to 2 000 000 as a maximum but can easily be changed - look -for the number in the beginnig og the code!! You will get an error an a notice about this if the number is exceeded. - -NOTE! For UNDEFINED values!! -Are by wgrib2 default set to 9.999e+20, this is set to NULL in the database insert - -/****************************************************************************************** - -USAGE Example: -wgrib2 [gribfile] -mysql_speed H=[host] U=[user] P=[password] D=[db] T=[table] W=[western_lons:0|1] PV=[remove unlikely:0|1] LATLON=[LonW:LonE:LatS:LatN] -if remove_unlikely == 1 , values above zero that are smaller than 10e-8 are set to zero -if western_lons == 1, longitudes above 180 are subtracted with -360 -Use the undefine function to choose area and the mathc function to choose fields. - -Parameter name mapping is in database table 'wgrib2_parameter_mapping'. Paramaters not in this table are getting standard wgrib2 names for parameter names and level names, except for surface parameters that default are set to level '0' and pressure parameters that default are set to the pressure level in figures, like '925'. NB!! There are no unit conversion of parameters that are not mapped in this table. - -Matches are made like this for desired parameters and levels: -"(param_name1:(level1|level2|level3))|(param_name2:(level4|level5))....", where level notation is the first 1-3 words in the wgrib2 levelname description. Levelnames "mean sea level" and "2 m above..." can be shortened to "mean " and "2 " respectively (observe the blanks!). Of course this depends on the name convention in wgrib2. - -Parameter names in database is named 'our_paramname'_'our_levelname', for example TMP_0 or RH_925. - -/****************************************************************************************** - -CREATE WGRIB2_TO_MYSQL MAPPING TABLE - -create table wgrib2_parameter_mapping (center_id int(5), wgrib_param_name varchar(30), wgrib_param_levelname varchar(100), our_name varchar(30), our_levelname varchar(100), conversion varchar(30), val_precision int(3)); -alter table wgrib2_parameter_mapping add primary key (center_id, wgrib_param_name, wgrib_param_level); - -Example of insert: -insert into wgrib2_parameter_mapping (center_id, wgrib_param_name,wgrib_param_levelname,our_name,our_levelname,conversion,val_precision) -values (7,'TCDC', 'entire atmosphere (considered as a single layer)', 'TCDC', '0', 'PERC_PART', 2); - -Example of table with inserted values: - -+-----------+------------------+--------------------------------------------------+----------+---------------+------------+---------------+ -| center_id | wgrib_param_name | wgrib_param_levelname | our_name | our_levelname | conversion | val_precision | -+-----------+------------------+--------------------------------------------------+----------+---------------+------------+---------------+ -| 7 | TCDC | entire atmosphere (considered as a single layer) | TCDC | 0 | PERC_PART | 2 | -| 7 | TCDC | high cloud layer | TCDC | 500 | PERC_PART | 2 | -| 7 | TCDC | middle cloud layer | TCDC | 700 | PERC_PART | 2 | -| 7 | TCDC | low cloud layer | TCDC | 925 | PERC_PART | 2 | -| 7 | PRMSL | mean sea level | PRMSL | 0 | PA_HPA | 1 | -| 7 | TMP | 850 mb | TMP | 850 | K_C | 2 | -| 7 | TMP | 925 mb | TMP | 925 | K_C | 2 | -| 7 | TMP | 700 mb | TMP | 700 | K_C | 2 | -| 7 | TMP | 500 mb | TMP | 500 | K_C | 2 | -| 7 | TMP | 1000 mb | TMP | 1000 | K_C | 2 | -| 7 | TMP | 300 mb | TMP | 300 | K_C | 2 | -| 7 | TMP | surface | TMP | 0 | K_C | 2 | -| 7 | TMP | 2 m above ground | TMP | 2 | K_C | 2 | -| 7 | TMAX | 2 m above ground | TMAX | 2 | K_C | 2 | -| 7 | TMIN | 2 m above ground | TMIN | 2 | K_C | 2 | -| 7 | DPT | 2 m above ground | DPT | 2 | K_C | 2 | -| 7 | RH | 850 mb | RH | 850 | None | 1 | -| 7 | RH | 925 mb | RH | 925 | None | 1 | -| 7 | RH | 700 mb | RH | 700 | None | 1 | -| 7 | RH | 500 mb | RH | 500 | None | 1 | -| 7 | RH | 1000 mb | RH | 1000 | None | 1 | -| 7 | RH | 300 mb | RH | 300 | None | 1 | -| 7 | RH | surface | RH | 0 | None | 1 | -| 7 | RH | 2 m above ground | RH | 2 | None | 1 | -| 7 | APCP | surface | APCP | 0 | None | 2 | -| 7 | ACPCP | surface | ACPCP | 0 | None | 2 | -| 7 | UGRD | 10 m above ground | UGRD | 0 | None | 2 | -| 7 | VGRD | 10 m above ground | VGRD | 0 | None | 2 | -| 7 | HGT | surface | HGT | 0 | None | 1 | -| 7 | CSNOW | surface | CSNOW | 0 | None | 2 | -| 7 | DSWRF | surface | DSWRF | 0 | None | 1 | -| 7 | USWRF | surface | USWRF | 0 | None | 1 | -| 7 | LFTX | surface | LFTX | 0 | None | 1 | -| 7 | CAPE | surface | CAPE | 0 | None | 1 | -+-----------+------------------+--------------------------------------------------+----------+---------------+------------+---------------+ - -COLUMNS: - center_id - center ID, for example 7 for NCEP, 98 for ECMWF - wgrib_param_name - Parameter name in wgrib2 - wgrib_param_levelname - Levelname in wgrib2 - our_name - The name we want in the column name - our_levelname - The level prefix we want for the parameter column name - conversion - type of conversion ("None" for no converisons) - val_precision - decimal precision of output, currently not in use - - - -CONVERSION TYPES: - GPH_M - Geopotential to meters, division by 9.82 - M_MM - Meter to millimeter, miltiplication by 1000 - PERC_PART - From percent to values between 0 and 1 - PA_HPA - pascal to hPa, division by 100 - PART_PERC Values between 0 and 1 multiplied by 100 - K_C - kelvin to Celsius, subtraction by 273.16 - -/****************************************************************************************** - -CREATE DATA TABLE -Example for the GFS model based on the mapping table above (has to be changed according to chosen level and parameter names): - -create table gfs (rt DATETIME NOT NULL,vt DATETIME NOT NULL,lat double NOT NULL,lon double NOT NULL, -HGT_850 double(7,1),TMP_850 double(6,2),UGRD_850 double(6,2),VGRD_850 double(6,2), -HGT_925 double(7,1),TMP_925 double(6,2),UGRD_925 double(6,2),VGRD_925 double(6,2), -HGT_0 double(7,1),TMP_2 double(6,2),RH_2 double(6,2), RH_925 double(6,2), -RH_850 double(6,2),TMAX_2 double(6,2),TMIN_2 double(6,2), -UGRD_0 double(6,2),VGRD_0 double(6,2),APCP_0 double(6,2),ACPCP_0 double(6,2), -CSNOW_0 double(5,2),LFTX_0 double(4,1),CAPE_0 double(6,1), -TCDC_925 double(5,2),TCDC_700 double(5,2),TCDC_500 double(5,2), -TCDC_0 double(5,2),DSWRF_0 double(8,1),USWRF_0 double(11,1),PRMSL_0 double(6,1)); -alter table gfs add primary key (rt,vt,lat,lon); - -EXAMPLE of bulk insert from grib2 file - -wgrib2 gfs.t00z.pgrb2f162 -undefine out-box 0:30 40:70 -mysql localhost user passwd database table 1 1 -match "(APCP:surface)|(TCDC:(middle|high|low|entire))|(RH:(2 |850|925))|(UGRD:(10 m above|925|850))|(VGRD:(10 m above|925|850))|(PRMSL:mean )|(HGT:(925|850|surface))|(CSNOW:surface)|(TMP:(2 |925|850))|(TMAX:2 )|(TMIN:2 )|((DSWRF|USWRF|:LFTX|CAPE|ACPCP):surface)" +/****************************************************************************************** + Copyright (C) 2008 Niklas Sondell, Storm Weather Center + MYSQL_speed is part of wgrib2 and could be distributed under terms of the GNU General Public License +/****************************************************************************************** + +MYSQL SPEED for wgrib2 + +This is a very fast version of the mysql insertion with wgrib2. It also results in a much +better structure of the database table which also makes the usage afterwards much faster. +It can be used only when the gribfile contains data with: + +1. All fields for insertion with the same runtime (anatime). +2. All fields for insertion with the same validtime (verf time). +3. All fields with the same GDS, grid definition. All fields for insertion needs to have the same lat/lon grid definition. + +If these criterias are not fulfilled it will result in an error. +Number of points in the grid are set to 2 000 000 as a maximum but can easily be changed - look +for the number in the beginnig og the code!! You will get an error an a notice about this if the number is exceeded. + +NOTE! For UNDEFINED values!! +Are by wgrib2 default set to 9.999e+20, this is set to NULL in the database insert + +/****************************************************************************************** + +USAGE Example: +wgrib2 [gribfile] -mysql_speed H=[host] U=[user] P=[password] D=[db] T=[table] W=[western_lons:0|1] PV=[remove unlikely:0|1] LATLON=[LonW:LonE:LatS:LatN] +if remove_unlikely == 1 , values above zero that are smaller than 10e-8 are set to zero +if western_lons == 1, longitudes above 180 are subtracted with -360 +Use the undefine function to choose area and the mathc function to choose fields. + +Parameter name mapping is in database table 'wgrib2_parameter_mapping'. Paramaters not in this table are getting standard wgrib2 names for parameter names and level names, except for surface parameters that default are set to level '0' and pressure parameters that default are set to the pressure level in figures, like '925'. NB!! There are no unit conversion of parameters that are not mapped in this table. + +Matches are made like this for desired parameters and levels: +"(param_name1:(level1|level2|level3))|(param_name2:(level4|level5))....", where level notation is the first 1-3 words in the wgrib2 levelname description. Levelnames "mean sea level" and "2 m above..." can be shortened to "mean " and "2 " respectively (observe the blanks!). Of course this depends on the name convention in wgrib2. + +Parameter names in database is named 'our_paramname'_'our_levelname', for example TMP_0 or RH_925. + +/****************************************************************************************** + +CREATE WGRIB2_TO_MYSQL MAPPING TABLE + +create table wgrib2_parameter_mapping (center_id int(5), wgrib_param_name varchar(30), wgrib_param_levelname varchar(100), our_name varchar(30), our_levelname varchar(100), conversion varchar(30), val_precision int(3)); +alter table wgrib2_parameter_mapping add primary key (center_id, wgrib_param_name, wgrib_param_level); + +Example of insert: +insert into wgrib2_parameter_mapping (center_id, wgrib_param_name,wgrib_param_levelname,our_name,our_levelname,conversion,val_precision) +values (7,'TCDC', 'entire atmosphere (considered as a single layer)', 'TCDC', '0', 'PERC_PART', 2); + +Example of table with inserted values: + ++-----------+------------------+--------------------------------------------------+----------+---------------+------------+---------------+ +| center_id | wgrib_param_name | wgrib_param_levelname | our_name | our_levelname | conversion | val_precision | ++-----------+------------------+--------------------------------------------------+----------+---------------+------------+---------------+ +| 7 | TCDC | entire atmosphere (considered as a single layer) | TCDC | 0 | PERC_PART | 2 | +| 7 | TCDC | high cloud layer | TCDC | 500 | PERC_PART | 2 | +| 7 | TCDC | middle cloud layer | TCDC | 700 | PERC_PART | 2 | +| 7 | TCDC | low cloud layer | TCDC | 925 | PERC_PART | 2 | +| 7 | PRMSL | mean sea level | PRMSL | 0 | PA_HPA | 1 | +| 7 | TMP | 850 mb | TMP | 850 | K_C | 2 | +| 7 | TMP | 925 mb | TMP | 925 | K_C | 2 | +| 7 | TMP | 700 mb | TMP | 700 | K_C | 2 | +| 7 | TMP | 500 mb | TMP | 500 | K_C | 2 | +| 7 | TMP | 1000 mb | TMP | 1000 | K_C | 2 | +| 7 | TMP | 300 mb | TMP | 300 | K_C | 2 | +| 7 | TMP | surface | TMP | 0 | K_C | 2 | +| 7 | TMP | 2 m above ground | TMP | 2 | K_C | 2 | +| 7 | TMAX | 2 m above ground | TMAX | 2 | K_C | 2 | +| 7 | TMIN | 2 m above ground | TMIN | 2 | K_C | 2 | +| 7 | DPT | 2 m above ground | DPT | 2 | K_C | 2 | +| 7 | RH | 850 mb | RH | 850 | None | 1 | +| 7 | RH | 925 mb | RH | 925 | None | 1 | +| 7 | RH | 700 mb | RH | 700 | None | 1 | +| 7 | RH | 500 mb | RH | 500 | None | 1 | +| 7 | RH | 1000 mb | RH | 1000 | None | 1 | +| 7 | RH | 300 mb | RH | 300 | None | 1 | +| 7 | RH | surface | RH | 0 | None | 1 | +| 7 | RH | 2 m above ground | RH | 2 | None | 1 | +| 7 | APCP | surface | APCP | 0 | None | 2 | +| 7 | ACPCP | surface | ACPCP | 0 | None | 2 | +| 7 | UGRD | 10 m above ground | UGRD | 0 | None | 2 | +| 7 | VGRD | 10 m above ground | VGRD | 0 | None | 2 | +| 7 | HGT | surface | HGT | 0 | None | 1 | +| 7 | CSNOW | surface | CSNOW | 0 | None | 2 | +| 7 | DSWRF | surface | DSWRF | 0 | None | 1 | +| 7 | USWRF | surface | USWRF | 0 | None | 1 | +| 7 | LFTX | surface | LFTX | 0 | None | 1 | +| 7 | CAPE | surface | CAPE | 0 | None | 1 | ++-----------+------------------+--------------------------------------------------+----------+---------------+------------+---------------+ + +COLUMNS: + center_id - center ID, for example 7 for NCEP, 98 for ECMWF + wgrib_param_name - Parameter name in wgrib2 + wgrib_param_levelname - Levelname in wgrib2 + our_name - The name we want in the column name + our_levelname - The level prefix we want for the parameter column name + conversion - type of conversion ("None" for no converisons) + val_precision - decimal precision of output, currently not in use + + + +CONVERSION TYPES: + GPH_M - Geopotential to meters, division by 9.82 + M_MM - Meter to millimeter, miltiplication by 1000 + PERC_PART - From percent to values between 0 and 1 + PA_HPA - pascal to hPa, division by 100 + PART_PERC Values between 0 and 1 multiplied by 100 + K_C - kelvin to Celsius, subtraction by 273.16 + +/****************************************************************************************** + +CREATE DATA TABLE +Example for the GFS model based on the mapping table above (has to be changed according to chosen level and parameter names): + +create table gfs (rt DATETIME NOT NULL,vt DATETIME NOT NULL,lat double NOT NULL,lon double NOT NULL, +HGT_850 double(7,1),TMP_850 double(6,2),UGRD_850 double(6,2),VGRD_850 double(6,2), +HGT_925 double(7,1),TMP_925 double(6,2),UGRD_925 double(6,2),VGRD_925 double(6,2), +HGT_0 double(7,1),TMP_2 double(6,2),RH_2 double(6,2), RH_925 double(6,2), +RH_850 double(6,2),TMAX_2 double(6,2),TMIN_2 double(6,2), +UGRD_0 double(6,2),VGRD_0 double(6,2),APCP_0 double(6,2),ACPCP_0 double(6,2), +CSNOW_0 double(5,2),LFTX_0 double(4,1),CAPE_0 double(6,1), +TCDC_925 double(5,2),TCDC_700 double(5,2),TCDC_500 double(5,2), +TCDC_0 double(5,2),DSWRF_0 double(8,1),USWRF_0 double(11,1),PRMSL_0 double(6,1)); +alter table gfs add primary key (rt,vt,lat,lon); + +EXAMPLE of bulk insert from grib2 file + +wgrib2 gfs.t00z.pgrb2f162 -undefine out-box 0:30 40:70 -mysql localhost user passwd database table 1 1 -match "(APCP:surface)|(TCDC:(middle|high|low|entire))|(RH:(2 |850|925))|(UGRD:(10 m above|925|850))|(VGRD:(10 m above|925|850))|(PRMSL:mean )|(HGT:(925|850|surface))|(CSNOW:surface)|(TMP:(2 |925|850))|(TMAX:2 )|(TMIN:2 )|((DSWRF|USWRF|:LFTX|CAPE|ACPCP):surface)" diff --git a/wgrib2/CMakeLists.txt b/wgrib2/CMakeLists.txt index 6658cbf5..e1d55b33 100644 --- a/wgrib2/CMakeLists.txt +++ b/wgrib2/CMakeLists.txt @@ -38,7 +38,7 @@ intpower.c Inv.c Inv_no.c Irr_grids.c itoshort_a.c JMA.c jpeg_pk.c Last.c lat2ij.c Latlon.c Level.c Limit.c Lola.c Lvl.c Macro.c manage_inv_out.c Match.c Match_fs.c Match_inv.c Mem_buffer.c Merge.c Misc.c missing.c mk_gdt.c Model_version_date.c Mod_grib.c -Mysql.c Mysql_dump.c Mysql_speed.c Names.c ncep_grids.c NCEP_norm.c +Names.c ncep_grids.c NCEP_norm.c NCEP_uv.c Ncpu.c Ndate.c Ndates.c Netcdf.c Netcdf_sup.c New_grid.c new_grid_lambertc.c New_grid_order.c openmp_util.c parse_loop.c parse_msg.c pdt_len.c Precision.c Prob.c Proj4.c proj4_initialize.c diff --git a/wgrib2/config.h.in b/wgrib2/config.h.in index ba868be6..e7dec7ef 100644 --- a/wgrib2/config.h.in +++ b/wgrib2/config.h.in @@ -27,6 +27,7 @@ #cmakedefine BUILD_LIB #cmakedefine BUILD_SHARED_LIB #cmakedefine BUILD_WGRIB +#cmakedefine BUILD_EXTRA #cmakedefine TEST_FILE_DIR "@TEST_FILE_DIR@" #define BUILD_COMMENTS "@BUILD_COMMENTS@"