diff --git a/internal/test_unit/config/Point2GridConfig_SST b/internal/test_unit/config/Point2GridConfig_SST new file mode 100644 index 0000000000..d9a658780c --- /dev/null +++ b/internal/test_unit/config/Point2GridConfig_SST @@ -0,0 +1,7 @@ +file_type = NETCDF_NCCF; + +var_name_map = [ + { key = "lat_vname"; val = "yh"; }, + { key = "lon_vname"; val = "xh"; } +]; + diff --git a/internal/test_unit/xml/unit_point2grid.xml b/internal/test_unit/xml/unit_point2grid.xml index 840fbdc7ea..1b538d42a8 100644 --- a/internal/test_unit/xml/unit_point2grid.xml +++ b/internal/test_unit/xml/unit_point2grid.xml @@ -284,40 +284,38 @@ - - + &MET_BIN;/point2grid MET_TMP_DIR &OUTPUT_DIR;/point2grid \ - &DATA_DIR_OBS;/point_obs/rtofs_glo_2ds_f006_ice_coverage.nc \ - "latlon 720 360 -80. -60. 0.5 0.5" \ - &OUTPUT_DIR;/point2grid/point2grid_rtofs_ice_coverage.nc \ - -field 'name="ice_coverage"; level="(0,*,*)";' \ + &DATA_DIR_OBS;/point_obs/gfs.ocean.t00z.6hr_avg.f006_SST.nc \ + G231 \ + &OUTPUT_DIR;/point2grid/point2grid_gfs.ocean.SST.nc \ + -config &CONFIG_DIR;/Point2GridConfig_SST \ + -field 'name="SST"; level="(0,*,*)";' \ -v 1 - &OUTPUT_DIR;/point2grid/point2grid_rtofs_ice_coverage.nc + &OUTPUT_DIR;/point2grid/point2grid_gfs.ocean.SST.nc diff --git a/src/tools/other/point2grid/point2grid.cc b/src/tools/other/point2grid/point2grid.cc index 73210e4b27..c243b226bc 100644 --- a/src/tools/other/point2grid/point2grid.cc +++ b/src/tools/other/point2grid/point2grid.cc @@ -389,7 +389,7 @@ static void process_data_file() { config.read_string(FieldSA[0].c_str()); // Note: The command line argument MUST processed before this - if (compress_level < 0) compress_level = config.nc_compression(); + if (compress_level < 0) compress_level = conf_info.conf.nc_compression(); // Get the gridded file type from config string, if present ftype = parse_conf_file_type(&conf_info.conf); @@ -963,7 +963,7 @@ void process_point_met_data(MetPointData *met_point_obs, MetConfig &config, VarI var_index_array.add(idx); var_count++; - if (is_eq(obs_data->obs_vals[idx], 0.)) obs_count_zero_from++; + if (is_eq(obs_data->obs_vals[idx], (float)0.)) obs_count_zero_from++; else obs_count_non_zero_from++; } } @@ -2098,7 +2098,7 @@ static bool get_grid_mapping(const Grid &to_grid, IntArray *cellMapping, static void get_grid_mapping_latlon( DataPlane from_dp, DataPlane to_dp, Grid to_grid, IntArray *cellMapping, float *latitudes, float *longitudes, - int from_lat_count, int from_lon_count, bool *skip_times, bool to_north) { + int from_lat_count, int from_lon_count, bool *skip_times, bool to_north, bool is_2d) { double x; double y; double to_ll_lat; @@ -2122,11 +2122,16 @@ static void get_grid_mapping_latlon( //Count the number of cells to be mapped to TO_GRID //Following the logic at DataPlane::two_to_one(int x, int y) n = y*Nx + x; for (int yIdx=0; yIdx 0) { int last_idx = data_size - 1; - auto latitudes = new float[data_size]; - auto longitudes = new float[data_size]; + int lat_count = get_data_size(&var_lat); + int lon_count = get_data_size(&var_lon); + auto latitudes = new float[lat_count]; + auto longitudes = new float[lon_count]; status = get_nc_data(&var_lat, latitudes); if( status ) status = get_nc_data(&var_lon, longitudes); if( status ) { get_grid_mapping_latlon(from_dp, to_dp, to_grid, cellMapping, latitudes, longitudes, from_lat_count, from_lon_count, skip_times, - !fr_grid.get_swap_to_north()); + !fr_grid.get_swap_to_north(), (lon_count==data_size)); if (is_eq(latitudes[0], latitudes[last_idx]) || is_eq(longitudes[0], longitudes[last_idx])) { @@ -2367,6 +2374,8 @@ static void get_grid_mapping(const Grid &fr_grid, const Grid &to_grid, IntArray to_dp.set_size(to_lon_count, to_lat_count); if (data_size > 0) { + int lat_count = data_size; + int lon_count = data_size; auto latitudes = (float *)nullptr; auto longitudes = (float *)nullptr; auto latitudes_buf = (float *)nullptr; @@ -2388,6 +2397,8 @@ static void get_grid_mapping(const Grid &fr_grid, const Grid &to_grid, IntArray NcVar var_lat = get_nc_var(coord_nc_in, var_name_lat); NcVar var_lon = get_nc_var(coord_nc_in, var_name_lon); if (IS_VALID_NC(var_lat) && IS_VALID_NC(var_lon)) { + lat_count = get_data_size(&var_lat); + lon_count = get_data_size(&var_lon); get_nc_data(&var_lat, latitudes); get_nc_data(&var_lon, longitudes); } @@ -2444,16 +2455,14 @@ static void get_grid_mapping(const Grid &fr_grid, const Grid &to_grid, IntArray } } } - else { - if (fr_grid.info().gi) { - grid_data.copy(fr_grid.info().gi); - grid_data.compute_lat_lon(); - latitudes = grid_data.lat_values; - longitudes = grid_data.lon_values; - if (!file_exists(geostationary_file.c_str())) { - save_geostationary_data(geostationary_file, - latitudes, longitudes, grid_data); - } + else if (fr_grid.info().gi) { + grid_data.copy(fr_grid.info().gi); + grid_data.compute_lat_lon(); + latitudes = grid_data.lat_values; + longitudes = grid_data.lon_values; + if (!file_exists(geostationary_file.c_str())) { + save_geostationary_data(geostationary_file, + latitudes, longitudes, grid_data); } } if (nullptr == latitudes) { @@ -2468,7 +2477,7 @@ static void get_grid_mapping(const Grid &fr_grid, const Grid &to_grid, IntArray check_lat_lon(data_size, latitudes, longitudes); get_grid_mapping_latlon(from_dp, to_dp, to_grid, cellMapping, latitudes, longitudes, from_lat_count, from_lon_count, nullptr, - !fr_grid.get_swap_to_north()); + !fr_grid.get_swap_to_north(), (lon_count==data_size)); } if (latitudes_buf) delete [] latitudes_buf;