Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix #2118 develop grib1_rotll #2130

Merged
merged 3 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions .github/jobs/set_job_controls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ if [ "${GITHUB_EVENT_NAME}" == "pull_request" ]; then

run_diff=true

# if base branch starts with main_v, use that input data
# if pull request into main_vX.Y branch,
# set truth data version to branch name and set input data version to X.Y
if [ "${GITHUB_BASE_REF:0:6}" == "main_v" ]; then
input_data_version=${GITHUB_BASE_REF:6}
truth_data_version=${GITHUB_BASE_REF}
input_data_version=${GITHUB_BASE_REF:6}
fi

fi
Expand All @@ -35,9 +37,9 @@ elif [ "${GITHUB_EVENT_NAME}" == "push" ]; then
run_diff=true
truth_data_version=${branch_name:0: -4}

# if branch starts with main_v, use that input data
# if main_vX.Y-ref branch, use X.Y input data
if [ "${branch_name:0:6}" == "main_v" ]; then
input_data_version=${branch_name:6:-4}
input_data_version=${branch_name:6: -4}
fi

else
Expand All @@ -46,10 +48,10 @@ elif [ "${GITHUB_EVENT_NAME}" == "push" ]; then
if [ "$branch_name" == "develop" ] ||
[ "${branch_name:0:6}" == "main_v" ]; then

run_diff=true
truth_data_version=${branch_name}
run_diff=true
truth_data_version=${branch_name}

# if branch starts with main_v, use that input data
# if main_vX.Y branch, use X.Y input data
if [ "${branch_name:0:6}" == "main_v" ]; then
input_data_version=${branch_name:6}
fi
Expand All @@ -59,34 +61,34 @@ elif [ "${GITHUB_EVENT_NAME}" == "push" ]; then
# check commit messages for skip or force keywords
if grep -q "ci-skip-all" <<< "$commit_msg"; then

run_compile=false
run_push=false
run_unit_tests=false
run_diff=false
run_update_truth=false
run_compile=false
run_push=false
run_unit_tests=false
run_diff=false
run_update_truth=false

fi

# check commit messages for ci-skip or ci-run keywords
if grep -q "ci-skip-compile" <<< "$commit_msg"; then

run_compile=false
run_compile=false

fi

if grep -q "ci-run-unit" <<< "$commit_msg"; then

run_diff=true
run_diff=true

fi

fi

elif [ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]; then

if [ "${force_tests}" == "true" ]; then
run_diff=true
fi
if [ "${force_tests}" == "true" ]; then
run_diff=true
fi

fi

Expand Down
4 changes: 4 additions & 0 deletions met/src/libcode/vx_data2d_grib/data2d_grib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,10 @@ bool is_grid_relative(const GribRecord &r) {
else if(r.gds->type == 5) {
res_flag = r.gds->grid_type.stereographic.res_flag;
}
// Rotated LatLon
else if(r.gds->type == 10) {
res_flag = r.gds->grid_type.rot_latlon_grid.res_flag;
}
else {
mlog << Error << "\nis_grid_relative() -> "
<< "Unsupported grid type value: " << r.gds->type
Expand Down
21 changes: 21 additions & 0 deletions met/src/libcode/vx_data2d_grib/grib_classes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,27 @@ else if ((h.type == 5))

file << " scan_flag: " << (int) h.grid_type.stereographic.scan_flag << "\n\n";
}
else if ((h.type == 10))
{

file << " lat1: " << char3_to_int(h.grid_type.rot_latlon_grid.lat1) << "\n";
file << " lon1: " << char3_to_int(h.grid_type.rot_latlon_grid.lon1) << "\n";

file << " res_flag: " << (int) h.grid_type.rot_latlon_grid.res_flag << "\n";

file << " lat2: " << char3_to_int(h.grid_type.rot_latlon_grid.lat2) << "\n";
file << " lon2: " << char3_to_int(h.grid_type.rot_latlon_grid.lon2) << "\n";

file << " di: " << char2_to_int(h.grid_type.rot_latlon_grid.di) << "\n";
file << " dj: " << char2_to_int(h.grid_type.rot_latlon_grid.dj) << "\n";

file << " scan_flag: " << (int) h.grid_type.rot_latlon_grid.scan_flag << "\n";

file << " lat_sp: " << char3_to_int(h.grid_type.rot_latlon_grid.lat_sp) << "\n";
file << " lon_sp: " << char3_to_int(h.grid_type.rot_latlon_grid.lon_sp) << "\n";

file << " rotation: " << char4_to_dbl(h.grid_type.rot_latlon_grid.rotation) << "\n\n";
}

return ( file );

Expand Down
30 changes: 28 additions & 2 deletions met/src/libcode/vx_data2d_grib/grib_classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ struct Section1_Header { // PDS
////////////////////////////////////////////////////////////////////////


struct LatLon { // Latitude/Longitude Grid
struct LatLon { // Latitude/Longitude Grid

unsigned char lat1[3]; // 11 - 13
unsigned char lon1[3]; // 14 - 16
Expand All @@ -179,6 +179,32 @@ struct LatLon { // Latitude/Longitude Grid

unsigned char unused[14]; // 29 - 42

};

// Reference: https://apps.ecmwf.int/codes/grib/format/grib1/grids/10

struct RotLatLon { // Rotated Latitude/Longitude Grid

unsigned char lat1[3]; // 11 - 13
unsigned char lon1[3]; // 14 - 16

unsigned char res_flag; // 17

unsigned char lat2[3]; // 18 - 20
unsigned char lon2[3]; // 21 - 23

unsigned char di[2]; // 24 - 25
unsigned char dj[2]; // 26 - 27

unsigned char scan_flag; // 28

unsigned char unused[4]; // 29 - 32

unsigned char lat_sp[3]; // 33 - 35
unsigned char lon_sp[3]; // 36 - 38

unsigned char rotation[4]; // 39 - 42

};

struct Mercator { // Mercator Grid
Expand Down Expand Up @@ -282,7 +308,7 @@ struct Gaussian {
union GridType {

struct LatLon latlon_grid; // Latitude/Longitude Grid
// struct RotLatLon rot_latlon_grid; // Rotated Latitude/Longitude Grid
struct RotLatLon rot_latlon_grid; // Rotated Latitude/Longitude Grid
struct Mercator mercator; // Mercator Grid
struct LambertConf lambert_conf; // Lambert Conformal Secant Grid
struct Stereographic stereographic; // Stereographic Grid
Expand Down
113 changes: 99 additions & 14 deletions met/src/libcode/vx_data2d_grib/grib_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ using namespace std;
// grid types from the GDS section
//

static const int latlon_type = 0;
static const int mercator_type = 1;
static const int lambert_type = 3;
static const int stereographic_type = 5;
static const int gaussian_type = 4;
static const int latlon_type = 0;
static const int mercator_type = 1;
static const int lambert_type = 3;
static const int gaussian_type = 4;
static const int stereographic_type = 5;
static const int rotated_latlon_type = 10;



////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -62,7 +64,7 @@ void gds_to_grid(const Section2_Header & gds, Grid & gr)
LambertData lc_data;
StereographicData st_data;
LatLonData ll_data;
//RotatedLatLonData rll_data;
RotatedLatLonData rll_data;
MercatorData mc_data;
GaussianData g_data;

Expand All @@ -84,11 +86,11 @@ if ( gds.type == latlon_type ) {

gr.set(ll_data);

// else if ( gds.type == rotated_latlon_type ) {
//
// gds_to_rotated_latlon(gds, rll_data);
//
// gr.set(rll_data);
} else if ( gds.type == rotated_latlon_type ) {

gds_to_rotated_latlon(gds, rll_data);

gr.set(rll_data);

} else if ( gds.type == mercator_type ) {

Expand Down Expand Up @@ -143,6 +145,7 @@ void gds_to_order(const Section2_Header & gds, int & xdir, int & ydir, int & ord
// Check GDS for the grid type.
// The following Projection types are supported:
// - Lat/Lon
// - Rotated Lat/Lon
// - Mercator
// - Lambert Conformal
// - Polar Stereographic
Expand All @@ -154,6 +157,10 @@ if ( gds.type == latlon_type ) {

scan_flag_to_order(gds.grid_type.latlon_grid.scan_flag, xdir, ydir, order);

} else if ( gds.type == rotated_latlon_type ) {

scan_flag_to_order(gds.grid_type.rot_latlon_grid.scan_flag, xdir, ydir, order);

} else if (gds.type == mercator_type ) {

scan_flag_to_order(gds.grid_type.mercator.scan_flag, xdir, ydir, order);
Expand Down Expand Up @@ -278,10 +285,88 @@ void gds_to_rotated_latlon(const Section2_Header & gds, RotatedLatLonData & data

{

mlog << Error << "\ngds_to_rotated_latlon() -> "
<< "Rotated Lat/Lon grids are not supported in GRIB version 1.\n\n";
int xdir, ydir, order;
double d;

scan_flag_to_order(gds.grid_type.rot_latlon_grid.scan_flag, xdir, ydir, order);

// Store the grid name
data.name = rotated_latlon_proj_type;

//
// Multiply longitude values by -1 since the NCAR code considers
// degrees west to be positive.
//

// Latitude of the bottom left corner
data.rot_lat_ll = min(decode_lat_lon(gds.grid_type.rot_latlon_grid.lat1, 3),
decode_lat_lon(gds.grid_type.rot_latlon_grid.lat2, 3));

// Longitude of the bottom left corner
if ( xdir == 0 ) data.rot_lon_ll = -1.0*rescale_lon(decode_lat_lon(gds.grid_type.rot_latlon_grid.lon1, 3));
else data.rot_lon_ll = -1.0*rescale_lon(decode_lat_lon(gds.grid_type.rot_latlon_grid.lon2, 3));

// Number of points in the Latitudinal (y) direction
data.Nlat = char2_to_int(gds.ny);

// Number of points in the Longitudinal (x) direction
data.Nlon = char2_to_int(gds.nx);

// Check for thinned lat/lon grids
if ( data.Nlon == 65535 ) {

exit ( 1 );
mlog << Error << "\ngds_to_rotated_latlon() -> "
<< "Thinned Lat/Lon grids are not supported for GRIB version 1.\n\n";

exit ( 1 );

}

// Compute latitudinal increment from lat1 and lat2
d = fabs(decode_lat_lon(gds.grid_type.rot_latlon_grid.lat1, 3)
- decode_lat_lon(gds.grid_type.rot_latlon_grid.lat2, 3));

data.delta_rot_lat = d/(data.Nlat);

// If explicitly specified and non-zero, use it
if ( ! all_bits_set(gds.grid_type.rot_latlon_grid.dj, 2) ) {

d = decode_lat_lon(gds.grid_type.rot_latlon_grid.dj, 2);

if ( d > 0 ) data.delta_rot_lat = d;

}

// Compute longitudinal increment from lon1 and lon2
d = fabs(decode_lat_lon(gds.grid_type.rot_latlon_grid.lon1, 3)
- decode_lat_lon(gds.grid_type.rot_latlon_grid.lon2, 3));

data.delta_rot_lon = d/(data.Nlon);

// If explicitly specified and non-zero, use it
if ( ! all_bits_set(gds.grid_type.rot_latlon_grid.di, 2) ) {

d = decode_lat_lon(gds.grid_type.rot_latlon_grid.di, 2);

if ( d > 0 ) data.delta_rot_lon = d;

}

// Location of (rotated) south pole
data.true_lat_south_pole =
decode_lat_lon(gds.grid_type.rot_latlon_grid.lat_sp, 3);

data.true_lon_south_pole =
-1.0*rescale_lon(decode_lat_lon(gds.grid_type.rot_latlon_grid.lon_sp, 3));

// Auxiliary rotation
data.aux_rotation = char4_to_dbl(gds.grid_type.rot_latlon_grid.rotation);

data.dump();

//
// done
//

return;

Expand Down
2 changes: 1 addition & 1 deletion met/src/libcode/vx_data2d_grib2/data2d_grib2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ void MetGrib2DataFile::read_grib2_grid( gribfield *gfld) {
data.true_lon_south_pole = s_lon;

//
// auxilliary rotation around the rotated polar axis
// auxiliary rotation around the rotated polar axis
//

data.aux_rotation = (t[21])*angle_factor;
Expand Down
2 changes: 1 addition & 1 deletion met/src/libcode/vx_data2d_nc_met/get_met_grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ data.rot_lon_ll *= -1.0;
get_global_att(ncfile, string("true_lon_south_pole"), data.true_lon_south_pole);
if ( !west_longitude_positive ) data.true_lon_south_pole *= -1.0;

// auxilliary rotation
// auxiliary rotation

get_global_att(ncfile, string("aux_rotation"), data.aux_rotation);

Expand Down
Loading