From 34fe3601058ff9939bb6359c29cbea3030926b1c Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Mon, 30 Jan 2023 23:10:47 -0700 Subject: [PATCH] #2218 Check and adjust semi_major_axis in meters --- src/libcode/vx_data2d_nccf/nccf_file.cc | 44 ++++++++++++------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/libcode/vx_data2d_nccf/nccf_file.cc b/src/libcode/vx_data2d_nccf/nccf_file.cc index 78b971fe98..7927e12848 100644 --- a/src/libcode/vx_data2d_nccf/nccf_file.cc +++ b/src/libcode/vx_data2d_nccf/nccf_file.cc @@ -2198,7 +2198,7 @@ void NcCfFile::get_grid_mapping_polar_stereographic(const NcVar *grid_mapping_va if (is_eq(semi_major_axis, bad_data_double)) semi_major_axis = EARTH_MAJOR_AXIS_km * m_per_km; - else semi_major_axis *= x_coord_to_m_cf; // meters + else if (semi_major_axis < 10000.0) semi_major_axis *= m_per_km; // meters // Calculate the pin indices. The pin will be located at the grid's reference // location since that's the only lat/lon location we know about. @@ -2206,16 +2206,6 @@ void NcCfFile::get_grid_mapping_polar_stereographic(const NcVar *grid_mapping_va double x_pin = -(x_values[0] / dx_m); double y_pin = -(y_values[0] / dy_m); - if(!has_scale_factor && has_standard_parallel) { - if(is_eq(eccentricity, 0.0)) { - x_pin = y_pin = 0.; - } - else { - x_pin = x_values[0] / dx_m_a; - y_pin = y_values[0] / dy_m_a; - } - } - // Fill in the data structure. Remember to negate the longitude values. StereographicData data; @@ -2227,9 +2217,9 @@ void NcCfFile::get_grid_mapping_polar_stereographic(const NcVar *grid_mapping_va data.y_pin = y_pin; data.scale_lat = proj_origin_lat; data.lon_orient = -1.0 * proj_vertical_lon; - data.d_km = dx_m / 1000.0; - data.dy_km = dy_m / 1000.0; - data.r_km = semi_major_axis / 1000.0; + data.d_km = dx_m / m_per_km; + data.dy_km = dy_m / m_per_km; + data.r_km = semi_major_axis / m_per_km; data.nx = _xDim->getSize(); data.ny = _yDim->getSize(); @@ -2258,6 +2248,16 @@ void NcCfFile::get_grid_mapping_polar_stereographic(const NcVar *grid_mapping_va data.lat_pin = lat; data.lon_pin = -lon; + if(!has_scale_factor && has_standard_parallel) { + if(is_eq(eccentricity, 0.0)) { + data.x_pin = data.y_pin = 0.; + } + else { + data.x_pin = x / dx_m_a; + data.y_pin = y / dy_m_a; + } + } + st_latlon_to_xy_func(lat, lon, x2, y2, scale_factor, proj_vertical_lon, semi_major_axis, false_east, false_north, eccentricity, is_north_hemisphere); @@ -2265,7 +2265,7 @@ void NcCfFile::get_grid_mapping_polar_stereographic(const NcVar *grid_mapping_va << " x: between " << x_values[0] <<" and " << x_values[x_counts-1] << ", y: between " << y_values[0] <<" and " << y_values[y_counts-1] << "\n"; mlog << Debug(6) << method_name - << "pin: (x,y)m -> (lat,lon) -> (x2,y2)m: (" << x << "," << y << ") -> (" + << "pin: (x,y) -> (lat,lon) -> (x2,y2): (" << x << "," << y << ") -> (" << lat << "," << lon << ") -> (" << x2 << "," << y2 << ") Diff (m): x=" << (x-x2) <<", y=" << (y-y2) << "\n"; @@ -2297,7 +2297,7 @@ void NcCfFile::get_grid_mapping_polar_stereographic(const NcVar *grid_mapping_va semi_major_axis, false_east, false_north, eccentricity, is_north_hemisphere); mlog << Debug(10) << method_name - << "bottom left: (x,y)m -> (lat,lon) -> (x2,y2)m: (" + << " bottom left: (x,y) -> (lat,lon) -> (x2,y2): (" << x1 << "," << y1 << ") -> (" << lat1 << "," << lon1 << ") -> (" << x2 << "," << y2 << ") Diff (m): x=" << (x1-x2) <<", y=" << (y1-y2) @@ -2312,7 +2312,7 @@ void NcCfFile::get_grid_mapping_polar_stereographic(const NcVar *grid_mapping_va semi_major_axis, false_east, false_north, eccentricity, is_north_hemisphere); mlog << Debug(10) << method_name - << " top left: (x,y)m -> (lat,lon) -> (x2,y2)m: (" + << " top left: (x,y) -> (lat,lon) -> (x2,y2): (" << x1 << "," << y1 << ") -> (" << lat1 << "," << lon1 << ") -> (" << x2 << "," << y2 << ") Diff (m): x=" << (x1-x2) <<", y=" << (y1-y2) @@ -2327,7 +2327,7 @@ void NcCfFile::get_grid_mapping_polar_stereographic(const NcVar *grid_mapping_va semi_major_axis, false_east, false_north, eccentricity, is_north_hemisphere); mlog << Debug(10) << method_name - << " center: (x,y)m -> (lat,lon) -> (x2,y2)m: (" << x1 + << " center: (x,y) -> (lat,lon) -> (x2,y2): (" << x1 << "," << y1 << ") -> (" << lat1 << "," << lon1 << ") -> (" << x2 << "," << y2 << ") Diff (m): x=" << (x1-x2) <<", y=" << (y1-y2) @@ -2342,7 +2342,7 @@ void NcCfFile::get_grid_mapping_polar_stereographic(const NcVar *grid_mapping_va semi_major_axis, false_east, false_north, eccentricity, is_north_hemisphere); mlog << Debug(10) << method_name - << " top right: (x,y)m -> (lat,lon) -> (x2,y2)m: (" << x1 + << " top right: (x,y) -> (lat,lon) -> (x2,y2): (" << x1 << "," << y1 << ") -> (" << lat1 << "," << lon1 << ") -> (" << x2 << "," << y2 << ") Diff (m): x=" << (x1-x2) <<", y=" << (y1-y2) @@ -2357,7 +2357,7 @@ void NcCfFile::get_grid_mapping_polar_stereographic(const NcVar *grid_mapping_va semi_major_axis, false_east, false_north, eccentricity, is_north_hemisphere); mlog << Debug(10) << method_name - << "bottom right: (x,y)m -> (lat,lon) -> (x2,y2)m: (" << x1 + << "bottom right: (x,y) -> (lat,lon) -> (x2,y2): (" << x1 << "," << y1 << ") -> (" << lat1 << "," << lon1 << ") -> (" << x2 << "," << y2 << ") Diff (m): x=" << (x1-x2) <<", y=" << (y1-y2) @@ -2384,8 +2384,8 @@ void NcCfFile::get_grid_mapping_polar_stereographic(const NcVar *grid_mapping_va data.eccentricity, is_north_hemisphere); x_diff = (x1-x2); y_diff = (y1-y2); - mlog << Debug(15) << method_name - << "index=("<< ix << "," << iy << "): (x,y)m -> (lat,lon) -> (x2,y2)m: (" << x1 + mlog << Debug(15) + << " index=("<< ix << "," << iy << "): (x,y) -> (lat,lon) -> (x2,y2): (" << x1 << "," << y1 << ") -> (" << lat1 << "," << lon1 << ") -> (" << x2 << "," << y2 << ") Diff (m): x=" << x_diff <<", y=" << y_diff