diff --git a/internal/test_unit/xml/unit_pcp_combine.xml b/internal/test_unit/xml/unit_pcp_combine.xml index b2de557363..a49e220d79 100644 --- a/internal/test_unit/xml/unit_pcp_combine.xml +++ b/internal/test_unit/xml/unit_pcp_combine.xml @@ -376,4 +376,16 @@ + + &MET_BIN;/pcp_combine + \ + -add &DATA_DIR_MODEL;/grib2/ukv/ukv_agl_temperature_1.5_12.grib2 \ + 'name="TMP"; level="Z1.5"; lead_time="24";' \ + &OUTPUT_DIR;/pcp_combine/ukv_agl_temperature_1.5.nc + + + &OUTPUT_DIR;/pcp_combine/ukv_agl_temperature_1.5.nc + + + diff --git a/internal/test_unit/xml/unit_plot_data_plane.xml b/internal/test_unit/xml/unit_plot_data_plane.xml index 2337c7a705..5c56a389d8 100644 --- a/internal/test_unit/xml/unit_plot_data_plane.xml +++ b/internal/test_unit/xml/unit_plot_data_plane.xml @@ -536,6 +536,21 @@ + + &MET_BIN;/plot_data_plane + \ + &OUTPUT_DIR;/pcp_combine/ukv_agl_temperature_1.5.nc \ + &OUTPUT_DIR;/plot_data_plane/ukv_agl_temperature_laea_met_nc.ps \ + 'name="TMP_Z1.5"; level="(*,*)";' \ + -title "MET NetCDF LAEA 1.5m Temperature" \ + -v 1 + + + &OUTPUT_DIR;/plot_data_plane/ukv_agl_temperature_laea_met_nc.ps + + + + &MET_BIN;/plot_data_plane \ diff --git a/src/libcode/vx_data2d_grib2/data2d_grib2.cc b/src/libcode/vx_data2d_grib2/data2d_grib2.cc index e86ef7ca2c..440f55de87 100644 --- a/src/libcode/vx_data2d_grib2/data2d_grib2.cc +++ b/src/libcode/vx_data2d_grib2/data2d_grib2.cc @@ -986,6 +986,8 @@ void MetGrib2DataFile::read_grib2_record_list() { void MetGrib2DataFile::read_grib2_grid(gribfield *gfld) { + const char * method_name = "MetGrib2DataFile::read_grib2_grid() -> "; + double d, r_km; int ResCompFlag; char hem = 0; @@ -1040,7 +1042,7 @@ void MetGrib2DataFile::read_grib2_grid(gribfield *gfld) { // check for thinned lat/lon grid if( data.Nlon == -1 ){ - mlog << Error << "\nMetGrib2DataFile::read_grib2_grid() -> " + mlog << Error << "\n" << method_name << "Thinned Lat/Lon grids are not supported for GRIB version 2.\n\n"; exit(1); } @@ -1329,7 +1331,7 @@ void MetGrib2DataFile::read_grib2_grid(gribfield *gfld) { // build an LaeaData struct with the projection information LaeaData laea; laea.name = laea_proj_type; - laea.spheroid_name = "Grib template"; + m_strncpy(laea.spheroid_name, "Grib template",m_strlen("Grib template"), method_name); // earth shape // Reference: https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table3-2.shtml @@ -1385,7 +1387,7 @@ void MetGrib2DataFile::read_grib2_grid(gribfield *gfld) { break; default: - mlog << Error << "\nMetGrib2DataFile::read_grib2_grid() -> " + mlog << Error << "\n" << method_name << "unsupported earth shape value of " << earth_shape_int << "!\n\n"; exit(1); } @@ -1433,7 +1435,7 @@ void MetGrib2DataFile::read_grib2_grid(gribfield *gfld) { // unrecognized grid else { - mlog << Error << "\nMetGrib2DataFile::read_grib2_grid() -> " + mlog << Error << "\n" << method_name << "found unrecognized grid definition (" << gfld->igdtnum << ")\n\n"; exit(1); diff --git a/src/libcode/vx_data2d_nc_met/get_met_grid.cc b/src/libcode/vx_data2d_nc_met/get_met_grid.cc index b3be5e816e..9882de0abb 100644 --- a/src/libcode/vx_data2d_nc_met/get_met_grid.cc +++ b/src/libcode/vx_data2d_nc_met/get_met_grid.cc @@ -6,10 +6,8 @@ // ** P.O.Box 3000, Boulder, Colorado, 80307-3000, USA // *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* - /////////////////////////////////////////////////////////////////////////////// - using namespace std; #include @@ -26,32 +24,28 @@ using namespace netCDF; #include "nc_utils.h" #include "vx_log.h" - /////////////////////////////////////////////////////////////////////////////// +static void read_netcdf_grid_v3 (NcFile *, Grid &); +static void read_netcdf_grid_v2 (NcFile *, Grid &); -static void read_netcdf_grid_v3 (NcFile *, Grid &); -static void read_netcdf_grid_v2 (NcFile *, Grid &); - -static void get_latlon_data_v3 (NcFile *, LatLonData &); -static void get_rot_latlon_data_v3 (NcFile *, RotatedLatLonData &); -static void get_lambert_data_v3 (NcFile *, LambertData &); -static void get_stereographic_data_v3 (NcFile *, StereographicData &); -static void get_mercator_data_v3 (NcFile *, MercatorData &); - -static void get_latlon_data_v2 (NcFile *, LatLonData &); -static void get_lambert_data_v2 (NcFile *, LambertData &); -static void get_stereographic_data_v2 (NcFile *, StereographicData &); -static void get_mercator_data_v2 (NcFile *, MercatorData &); - -static void get_gaussian_data (NcFile *, GaussianData &); -static void get_semilatlon_data (NcFile *, SemiLatLonData &); -static void get_semilatlon_var (NcFile *, const char *, NumArray &); +static LatLonData get_latlon_data (NcFile *); +static RotatedLatLonData get_rot_latlon_data (NcFile *); +static LambertData get_lambert_data (NcFile *); +static LaeaData get_laea_data (NcFile *); +static StereographicData get_stereographic_data (NcFile *); +static MercatorData get_mercator_data (NcFile *); +static GaussianData get_gaussian_data (NcFile *); +static SemiLatLonData get_semilatlon_data (NcFile *); +static void get_semilatlon_var (NcFile *, const char *, NumArray &); +static LatLonData get_latlon_data_v2 (NcFile *); +static LambertData get_lambert_data_v2 (NcFile *); +static StereographicData get_stereographic_data_v2 (NcFile *); +static MercatorData get_mercator_data_v2 (NcFile *); /////////////////////////////////////////////////////////////////////////////// - void read_netcdf_grid(NcFile * f_in, Grid & gr) { // Parse the projection information based on the version @@ -59,9 +53,6 @@ void read_netcdf_grid(NcFile * f_in, Grid & gr) { read_netcdf_grid_v3(f_in, gr); } else { - mlog << Warning << "\nread_netcdf_grid() -> " - << "Applying METv2.0 grid parsing logic since the \"MET_version\" " - << "global attribute is not present.\n\n"; mlog << Warning << "\nread_netcdf_grid() -> " << "Applying METv2.0 grid parsing logic since the \"MET_version\" " << "global attribute is not present.\n\n"; @@ -71,171 +62,119 @@ void read_netcdf_grid(NcFile * f_in, Grid & gr) { return; } - /////////////////////////////////////////////////////////////////////////////// - -void read_netcdf_grid_v3(NcFile * f_in, Grid & gr) -{ - - NcGroupAtt proj_att; - - // Structures to store projection info - LambertData lc_data; - StereographicData st_data; - LatLonData ll_data; - RotatedLatLonData rll_data; - MercatorData mc_data; - GaussianData g_data; - SemiLatLonData sl_data; +void read_netcdf_grid_v3(NcFile * f_in, Grid & gr) { // // Parse the grid specification out of the global attributes // - proj_att = GET_NC_ATT_OBJ_BY_P(f_in, "Projection"); + NcGroupAtt proj_att = GET_NC_ATT_OBJ_BY_P(f_in, "Projection"); // // Parse out the grid specification depending on the projection type - // The following Projection types are supported: - // - Lat/Lon - // - Mercator - // - Lambert Conformal - // - Polar Stereographic - // - Gaussian - // - SemiLatLon // if (!IS_INVALID_NC(proj_att)) { ConcatString proj_att_name; get_global_att(&proj_att, proj_att_name); - if ( strcasecmp(proj_att_name.c_str(), latlon_proj_type) == 0 ) { - - get_latlon_data_v3(f_in, ll_data); - gr.set(ll_data); - - } else if ( strcasecmp(proj_att_name.c_str(), rotated_latlon_proj_type) == 0 ) { - - get_rot_latlon_data_v3(f_in, rll_data); - gr.set(rll_data); - - } else if ( strcasecmp(proj_att_name.c_str(), mercator_proj_type) == 0 ) { - - get_mercator_data_v3(f_in, mc_data); - gr.set(mc_data); - - } else if ( strcasecmp(proj_att_name.c_str(), lambert_proj_type) == 0 ) { - - get_lambert_data_v3(f_in, lc_data); - gr.set(lc_data); - - } else if ( strcasecmp(proj_att_name.c_str(), stereographic_proj_type) == 0 ) { - - get_stereographic_data_v3(f_in, st_data); - gr.set(st_data); - - } else if ( strcasecmp(proj_att_name.c_str(), gaussian_proj_type) == 0 ) { - - get_gaussian_data(f_in, g_data); - gr.set(g_data); - - } else if ( strcasecmp(proj_att_name.c_str(), semilatlon_proj_type) == 0 ) { - - get_semilatlon_data(f_in, sl_data); - gr.set(sl_data); - + if ( strcasecmp(proj_att_name.c_str(), + latlon_proj_type) == 0 ) { + gr.set(get_latlon_data(f_in)); + } else if ( strcasecmp(proj_att_name.c_str(), + rotated_latlon_proj_type) == 0 ) { + gr.set(get_rot_latlon_data(f_in)); + } else if ( strcasecmp(proj_att_name.c_str(), + mercator_proj_type) == 0 ) { + gr.set(get_mercator_data(f_in)); + } else if ( strcasecmp(proj_att_name.c_str(), + lambert_proj_type) == 0 ) { + gr.set(get_lambert_data(f_in)); + } else if ( strcasecmp(proj_att_name.c_str(), + laea_proj_type) == 0 ) { + gr.set(get_laea_data(f_in)); + } else if ( strcasecmp(proj_att_name.c_str(), + stereographic_proj_type) == 0 ) { + gr.set(get_stereographic_data(f_in)); + } else if ( strcasecmp(proj_att_name.c_str(), + gaussian_proj_type) == 0 ) { + gr.set(get_gaussian_data(f_in)); + } else if ( strcasecmp(proj_att_name.c_str(), + semilatlon_proj_type) == 0 ) { + gr.set(get_semilatlon_data(f_in)); } else { // Unsupported projection type mlog << Error << "\nread_netcdf_grid_v3() -> " << "Projection \"" << proj_att_name - << "\" not a currently supported type (\"" - << latlon_proj_type << "\", \"" << mercator_proj_type << "\", \"" - << lambert_proj_type << "\", \"" << stereographic_proj_type - << "\").\n\n"; + << "\" not a currently supported type (" + << latlon_proj_type << ", " + << rotated_latlon_proj_type << ", " + << mercator_proj_type << ", " + << lambert_proj_type << ", " + << laea_proj_type << ", " + << stereographic_proj_type << ", " + << gaussian_proj_type << ", " + << semilatlon_proj_type << ").\n\n"; exit(1); } } - // - // done - // - -return; - + return; } /////////////////////////////////////////////////////////////////////////////// - void read_netcdf_grid_v2(NcFile * f_in, Grid & gr) { - NcGroupAtt proj_att; - - // Structures to store projection info - LambertData lc_data; - StereographicData st_data; - LatLonData ll_data; - MercatorData mc_data; - // // Parse the grid specification out of the global attributes // - proj_att = GET_NC_ATT_OBJ_BY_P(f_in, "Projection"); + NcGroupAtt proj_att = GET_NC_ATT_OBJ_BY_P(f_in, "Projection"); // // Parse out the grid specification depending on the projection type - // The following 4 Projection types are supported: - // - Lat/Lon - // - Mercator - // - Lambert Conformal - // - Polar Stereographic // if (!IS_INVALID_NC(proj_att)) { ConcatString proj_att_name; get_global_att(&proj_att, proj_att_name); - if ( strcasecmp(proj_att_name.c_str(), latlon_proj_type) == 0 ) { - get_latlon_data_v2(f_in, ll_data); - gr.set(ll_data); - } else if ( strcasecmp(proj_att_name.c_str(), mercator_proj_type) == 0 ) { - get_mercator_data_v2(f_in, mc_data); - gr.set(mc_data); - } else if ( strcasecmp(proj_att_name.c_str(), lambert_proj_type) == 0 ) { - get_lambert_data_v2(f_in, lc_data); - gr.set(lc_data); - } else if ( strcasecmp(proj_att_name.c_str(), stereographic_proj_type) == 0 ) { - get_stereographic_data_v2(f_in, st_data); - gr.set(st_data); + if ( strcasecmp(proj_att_name.c_str(), + latlon_proj_type) == 0 ) { + gr.set(get_latlon_data_v2(f_in)); + } else if ( strcasecmp(proj_att_name.c_str(), + mercator_proj_type) == 0 ) { + gr.set(get_mercator_data_v2(f_in)); + } else if ( strcasecmp(proj_att_name.c_str(), + lambert_proj_type) == 0 ) { + gr.set(get_lambert_data_v2(f_in)); + } else if ( strcasecmp(proj_att_name.c_str(), + stereographic_proj_type) == 0 ) { + gr.set(get_stereographic_data_v2(f_in)); } else { // Unsupported projection type mlog << Error << "\nread_netcdf_grid_v2() -> " << "Projection \"" << proj_att_name - << "\" not a currently supported type (\"" - << latlon_proj_type << "\", \"" << mercator_proj_type << "\", \"" - << lambert_proj_type << "\", \"" << stereographic_proj_type - << "\").\n\n"; + << "\" not a currently supported type (" + << latlon_proj_type << ", " + << mercator_proj_type << ", " + << lambert_proj_type << ", " + << stereographic_proj_type << ").\n\n"; exit(1); } } - // - // done - // - -return; - + return; } - /////////////////////////////////////////////////////////////////////////////// - int has_variable(NcFile *f_in, const char *var_name) { int found; @@ -247,562 +186,523 @@ int has_variable(NcFile *f_in, const char *var_name) { return(found); } - /////////////////////////////////////////////////////////////////////////////// +LatLonData get_latlon_data(NcFile * ncfile) { -void get_latlon_data_v3(NcFile * ncfile, LatLonData & data) -{ + LatLonData data; // Store the grid name -data.name = latlon_proj_type; + data.name = latlon_proj_type; // Latitude of the bottom left corner -get_global_att(ncfile, string("lat_ll"), data.lat_ll); + get_global_att(ncfile, string("lat_ll"), data.lat_ll); // Longitude of the bottom left corner -get_global_att(ncfile, string("lon_ll"), data.lon_ll); -data.lon_ll *= -1.0; + get_global_att(ncfile, string("lon_ll"), data.lon_ll); + data.lon_ll *= -1.0; // Latitude increment -get_global_att(ncfile, string("delta_lat"), data.delta_lat); + get_global_att(ncfile, string("delta_lat"), data.delta_lat); // Longitude increment -get_global_att(ncfile, string("delta_lon"), data.delta_lon); + get_global_att(ncfile, string("delta_lon"), data.delta_lon); // Number of points in the Latitude (y) direction -get_global_att(ncfile, string("Nlat"), data.Nlat); + get_global_att(ncfile, string("Nlat"), data.Nlat); // Number of points in the Longitudinal (x) direction -get_global_att(ncfile, string("Nlon"), data.Nlon); + get_global_att(ncfile, string("Nlon"), data.Nlon); -data.dump(); - - // - // done - // - -return; + data.dump(); + return(data); } - /////////////////////////////////////////////////////////////////////////////// +RotatedLatLonData get_rot_latlon_data(NcFile * ncfile) { -void get_rot_latlon_data_v3(NcFile * ncfile, RotatedLatLonData & data) -{ + RotatedLatLonData data; // Store the grid name -data.name = latlon_proj_type; + data.name = latlon_proj_type; // Latitude of the bottom left corner -get_global_att(ncfile, string("rot_lat_ll"), data.rot_lat_ll); + get_global_att(ncfile, string("rot_lat_ll"), data.rot_lat_ll); // Longitude of the bottom left corner -get_global_att(ncfile, string("rot_lon_ll"), data.rot_lon_ll); -data.rot_lon_ll *= -1.0; + get_global_att(ncfile, string("rot_lon_ll"), data.rot_lon_ll); + data.rot_lon_ll *= -1.0; // Latitude increment -get_global_att(ncfile, string("delta_rot_lat"), data.delta_rot_lat); + get_global_att(ncfile, string("delta_rot_lat"), data.delta_rot_lat); // Longitude increment -get_global_att(ncfile, string("delta_rot_lon"), data.delta_rot_lon); + get_global_att(ncfile, string("delta_rot_lon"), data.delta_rot_lon); // Number of points in the Latitude (y) direction -get_global_att(ncfile, string("Nlat"), data.Nlat); + get_global_att(ncfile, string("Nlat"), data.Nlat); // Number of points in the Longitudinal (x) direction -get_global_att(ncfile, string("Nlon"), data.Nlon); + get_global_att(ncfile, string("Nlon"), data.Nlon); // true lat/lon of south pole - -get_global_att(ncfile, string("true_lat_south_pole"), data.true_lat_south_pole); -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; + get_global_att(ncfile, string("true_lat_south_pole"), data.true_lat_south_pole); + 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; // auxiliary rotation + get_global_att(ncfile, string("aux_rotation"), data.aux_rotation); -get_global_att(ncfile, string("aux_rotation"), data.aux_rotation); - -data.dump(); - - // - // done - // - -return; + data.dump(); + return(data); } - /////////////////////////////////////////////////////////////////////////////// +LambertData get_lambert_data(NcFile * ncfile) { -void get_lambert_data_v3(NcFile * ncfile, LambertData & data) -{ - -ConcatString att_value; + LambertData data; + ConcatString att_value; // Store the grid name -data.name = lambert_proj_type; + data.name = lambert_proj_type; // Hemisphere -get_global_att(ncfile, string("hemisphere"), att_value); -data.hemisphere = att_value.char_at(0); + get_global_att(ncfile, string("hemisphere"), att_value); + data.hemisphere = att_value.char_at(0); // First scale latitude -get_global_att(ncfile, string("scale_lat_1"), data.scale_lat_1); + get_global_att(ncfile, string("scale_lat_1"), data.scale_lat_1); // Second scale latitude -get_global_att(ncfile, string("scale_lat_2"), data.scale_lat_2); + get_global_att(ncfile, string("scale_lat_2"), data.scale_lat_2); // Latitude pin -get_global_att(ncfile, string("lat_pin"), data.lat_pin); + get_global_att(ncfile, string("lat_pin"), data.lat_pin); // Longitude pin -get_global_att(ncfile, string("lon_pin"), data.lon_pin); -data.lon_pin *= -1.0; + get_global_att(ncfile, string("lon_pin"), data.lon_pin); + data.lon_pin *= -1.0; // X pin -get_global_att(ncfile, string("x_pin"), data.x_pin); + get_global_att(ncfile, string("x_pin"), data.x_pin); // Y pin -get_global_att(ncfile, string("y_pin"), data.y_pin); + get_global_att(ncfile, string("y_pin"), data.y_pin); // Orientation longitude -get_global_att(ncfile, string("lon_orient"), data.lon_orient); -data.lon_orient *= -1.0; + get_global_att(ncfile, string("lon_orient"), data.lon_orient); + data.lon_orient *= -1.0; // Grid spacing in km -get_global_att(ncfile, string("d_km"), data.d_km); + get_global_att(ncfile, string("d_km"), data.d_km); // Radius of the earth -get_global_att(ncfile, string("r_km"), data.r_km); + get_global_att(ncfile, string("r_km"), data.r_km); // Number of points in the x-direction -get_global_att(ncfile, string("nx"), data.nx); + get_global_att(ncfile, string("nx"), data.nx); // Number of points in the y-direction -get_global_att(ncfile, string("ny"), data.ny); + get_global_att(ncfile, string("ny"), data.ny); // Rotation angle -data.so2_angle = 0.0; + data.so2_angle = 0.0; -data.dump(); + data.dump(); - // - // done - // + return(data); +} -return; +/////////////////////////////////////////////////////////////////////////////// -} +LaeaData get_laea_data(NcFile * ncfile) { + const char * method_name = "get_laea_data() -> "; -/////////////////////////////////////////////////////////////////////////////// + LaeaData data; + ConcatString att_value; + // Store the grid name + data.name = laea_proj_type; -void get_stereographic_data_v3(NcFile * ncfile, StereographicData & data) -{ + // Spheroid name + get_global_att(ncfile, string("spheroid_name"), att_value); + m_strncpy(data.spheroid_name, att_value.c_str(), att_value.length(), method_name); + + // Grid spacing in km + get_global_att(ncfile, string("radius_km"), data.radius_km); + + // Equitorial radius in km + get_global_att(ncfile, string("equatorial_radius_km"), data.equatorial_radius_km); + + // Polar radius in km + get_global_att(ncfile, string("polar_radius_km"), data.polar_radius_km); + + // First latitude + get_global_att(ncfile, string("lat_first"), data.lat_first); + + // First longitude + get_global_att(ncfile, string("lon_first"), data.lon_first); + data.lon_first *= -1.0; + + // Standard latitude + get_global_att(ncfile, string("standard_lat"), data.standard_lat); + + // Central longitude + get_global_att(ncfile, string("central_lon"), data.central_lon); + data.central_lon *= -1.0; + + // Spacing in the x-dimension + get_global_att(ncfile, string("dx_km"), data.dx_km); + + // Spacing in the y-direction + get_global_att(ncfile, string("dy_km"), data.dy_km); + + // Number of points in the x-direction + get_global_att(ncfile, string("nx"), data.nx); + + // Number of points in the y-direction + get_global_att(ncfile, string("ny"), data.ny); + + // Is sphere + get_global_att(ncfile, string("is_sphere"), att_value); + data.is_sphere = string_to_bool(att_value.c_str()); + + data.dump(); -ConcatString att_value; + return(data); +} + +/////////////////////////////////////////////////////////////////////////////// + +StereographicData get_stereographic_data(NcFile * ncfile) { + + StereographicData data; + ConcatString att_value; // Store the grid name -data.name = stereographic_proj_type; + data.name = stereographic_proj_type; // Hemisphere -get_global_att(ncfile, (string)"hemisphere", att_value); -data.hemisphere = att_value.char_at(0); + get_global_att(ncfile, (string)"hemisphere", att_value); + data.hemisphere = att_value.char_at(0); // Scale latitude -get_global_att(ncfile, (string)"scale_lat", data.scale_lat); + get_global_att(ncfile, (string)"scale_lat", data.scale_lat); // Latitude pin -get_global_att(ncfile, (string)"lat_pin", data.lat_pin); + get_global_att(ncfile, (string)"lat_pin", data.lat_pin); // Longitude pin -get_global_att(ncfile, string("lon_pin"), data.lon_pin); -data.lon_pin *= -1.0; + get_global_att(ncfile, string("lon_pin"), data.lon_pin); + data.lon_pin *= -1.0; // X pin -get_global_att(ncfile, string("x_pin"), data.x_pin); + get_global_att(ncfile, string("x_pin"), data.x_pin); // Y pin -get_global_att(ncfile, string("y_pin"), data.y_pin); + get_global_att(ncfile, string("y_pin"), data.y_pin); // Orientation longitude -get_global_att(ncfile, string("lon_orient"), data.lon_orient); -data.lon_orient *= -1.0; + get_global_att(ncfile, string("lon_orient"), data.lon_orient); + data.lon_orient *= -1.0; // Grid spacing in km -get_global_att(ncfile, string("d_km"), data.d_km); + get_global_att(ncfile, string("d_km"), data.d_km); // Radius of the earth -get_global_att(ncfile, string("r_km"), data.r_km); + get_global_att(ncfile, string("r_km"), data.r_km); // Number of points in the x-direction -get_global_att(ncfile, string("nx"), data.nx); + get_global_att(ncfile, string("nx"), data.nx); // Number of points in the y-direction -get_global_att(ncfile, string("ny"), data.ny); + get_global_att(ncfile, string("ny"), data.ny); -data.eccentricity = 0.; -data.false_east = 0.; -data.false_north = 0.; -data.scale_factor = 1.0; -data.dy_km = data.d_km; + data.eccentricity = 0.; + data.false_east = 0.; + data.false_north = 0.; + data.scale_factor = 1.0; + data.dy_km = data.d_km; -data.dump(); - - // - // done - // - -return; + data.dump(); + return(data); } - /////////////////////////////////////////////////////////////////////////////// +MercatorData get_mercator_data(NcFile * ncfile) { -void get_mercator_data_v3(NcFile * ncfile, MercatorData & data) - -{ + MercatorData data; // Store the grid name -data.name = mercator_proj_type; + data.name = mercator_proj_type; // Latitude of the bottom left corner -get_global_att(ncfile, string("lat_ll"), data.lat_ll); + get_global_att(ncfile, string("lat_ll"), data.lat_ll); // Longitude of the bottom left corner -get_global_att(ncfile, string("lon_ll"), data.lon_ll); -data.lon_ll *= -1.0; + get_global_att(ncfile, string("lon_ll"), data.lon_ll); + data.lon_ll *= -1.0; // Latitude of the bottom left corner -get_global_att(ncfile, string("lat_ur"), data.lat_ur); + get_global_att(ncfile, string("lat_ur"), data.lat_ur); // Longitude of the bottom left corner -get_global_att(ncfile, string("lon_ur"), data.lon_ur); -data.lon_ur *= -1.0; + get_global_att(ncfile, string("lon_ur"), data.lon_ur); + data.lon_ur *= -1.0; // Number of points in the Latitudinal (y) direction -get_global_att(ncfile, string("ny"), data.ny); + get_global_att(ncfile, string("ny"), data.ny); // Number of points in the Longitudinal (x) direction -get_global_att(ncfile, string("nx"), data.nx); - -data.dump(); - - // - // done - // + get_global_att(ncfile, string("nx"), data.nx); -return; + data.dump(); + return(data); } - /////////////////////////////////////////////////////////////////////////////// +LatLonData get_latlon_data_v2(NcFile * ncfile) { -void get_latlon_data_v2(NcFile * ncfile, LatLonData & data) - -{ + LatLonData data; // Store the grid name -data.name = latlon_proj_type; + data.name = latlon_proj_type; // Latitude of the bottom left corner -get_global_att(ncfile, string("lat_ll_deg"), data.lat_ll); + get_global_att(ncfile, string("lat_ll_deg"), data.lat_ll); // Longitude of the bottom left corner -get_global_att(ncfile, string("lon_ll_deg"), data.lon_ll); -data.lon_ll *= -1.0; + get_global_att(ncfile, string("lon_ll_deg"), data.lon_ll); + data.lon_ll *= -1.0; // Latitude increment -get_global_att(ncfile, string("delta_lat_deg"), data.delta_lat); + get_global_att(ncfile, string("delta_lat_deg"), data.delta_lat); // Longitude increment -get_global_att(ncfile, string("delta_lon_deg"), data.delta_lon); + get_global_att(ncfile, string("delta_lon_deg"), data.delta_lon); // Number of points in the Latitude (y) direction -get_global_att(ncfile, string("Nlat"), data.Nlat); + get_global_att(ncfile, string("Nlat"), data.Nlat); // Number of points in the Longitudinal (x) direction -get_global_att(ncfile, string("Nlon"), data.Nlon); - -data.dump(); + get_global_att(ncfile, string("Nlon"), data.Nlon); - // - // done - // - -return; + data.dump(); + return(data); } - /////////////////////////////////////////////////////////////////////////////// +LambertData get_lambert_data_v2(NcFile * ncfile) { -void get_lambert_data_v2(NcFile * ncfile, LambertData & data) - -{ + LambertData data; // Store the grid name -data.name = lambert_proj_type; + data.name = lambert_proj_type; // First scale latitude -get_global_att(ncfile, string("p1_deg"), data.scale_lat_1); + get_global_att(ncfile, string("p1_deg"), data.scale_lat_1); // Second scale latitude -get_global_att(ncfile, string("p2_deg"), data.scale_lat_2); + get_global_att(ncfile, string("p2_deg"), data.scale_lat_2); // Latitude pin -get_global_att(ncfile, string("p0_deg"), data.lat_pin); + get_global_att(ncfile, string("p0_deg"), data.lat_pin); // Longitude pin -get_global_att(ncfile, string("l0_deg"), data.lon_pin); -data.lon_pin *= -1.0; + get_global_att(ncfile, string("l0_deg"), data.lon_pin); + data.lon_pin *= -1.0; // X pin -data.x_pin = 0.0; + data.x_pin = 0.0; // Y pin -data.y_pin = 0.0; + data.y_pin = 0.0; // Orientation longitude -get_global_att(ncfile, string("lcen_deg"), data.lon_orient); -data.lon_orient *= -1.0; + get_global_att(ncfile, string("lcen_deg"), data.lon_orient); + data.lon_orient *= -1.0; // Grid spacing in km -get_global_att(ncfile, string("d_km"), data.d_km); + get_global_att(ncfile, string("d_km"), data.d_km); // Radius of the earth -get_global_att(ncfile, string("r_km"), data.r_km); + get_global_att(ncfile, string("r_km"), data.r_km); // Number of points in the x-direction -get_global_att(ncfile, string("nx"), data.nx); + get_global_att(ncfile, string("nx"), data.nx); // Number of points in the y-direction -get_global_att(ncfile, string("ny"), data.ny); + get_global_att(ncfile, string("ny"), data.ny); // Rotation angle -data.so2_angle = 0.0; + data.so2_angle = 0.0; -data.dump(); - - // - // done - // - -return; + data.dump(); + return(data); } - /////////////////////////////////////////////////////////////////////////////// +StereographicData get_stereographic_data_v2(NcFile * ncfile) { -void get_stereographic_data_v2(NcFile * ncfile, StereographicData & data) - -{ + StereographicData data; // Store the grid name -data.name = stereographic_proj_type; + data.name = stereographic_proj_type; // Hemisphere, assume northern -data.hemisphere = 'N'; + data.hemisphere = 'N'; // Scale latitude -get_global_att(ncfile, string("p1_deg"), data.scale_lat); + get_global_att(ncfile, string("p1_deg"), data.scale_lat); // Latitude pin -get_global_att(ncfile, string("p0_deg"), data.lat_pin); + get_global_att(ncfile, string("p0_deg"), data.lat_pin); // Longitude pin -get_global_att(ncfile, string("l0_deg"), data.lon_pin); -data.lon_pin *= -1.0; + get_global_att(ncfile, string("l0_deg"), data.lon_pin); + data.lon_pin *= -1.0; // X pin -data.x_pin = 0.0; + data.x_pin = 0.0; // Y pin -data.y_pin = 0.0; + data.y_pin = 0.0; // Orientation longitude -get_global_att(ncfile, string("lcen_deg"), data.lon_orient); -data.lon_orient *= -1.0; + get_global_att(ncfile, string("lcen_deg"), data.lon_orient); + data.lon_orient *= -1.0; // Grid spacing in km -get_global_att(ncfile, string("d_km"), data.d_km); + get_global_att(ncfile, string("d_km"), data.d_km); // Radius of the earth -get_global_att(ncfile, string("r_km"), data.r_km); + get_global_att(ncfile, string("r_km"), data.r_km); // Number of points in the x-direction -get_global_att(ncfile, string("nx"), data.nx); + get_global_att(ncfile, string("nx"), data.nx); // Number of points in the y-direction -get_global_att(ncfile, string("ny"), data.ny); + get_global_att(ncfile, string("ny"), data.ny); -data.eccentricity = 0.; -data.false_east = 0.; -data.false_north = 0.; -data.scale_factor = 1.0; -data.dy_km = data.d_km; + data.eccentricity = 0.; + data.false_east = 0.; + data.false_north = 0.; + data.scale_factor = 1.0; + data.dy_km = data.d_km; -data.dump(); - - // - // done - // - -return; + data.dump(); + return(data); } - /////////////////////////////////////////////////////////////////////////////// +MercatorData get_mercator_data_v2(NcFile * ncfile) { -void get_mercator_data_v2(NcFile * ncfile, MercatorData & data) - -{ + MercatorData data; // Store the grid name -data.name = mercator_proj_type; + data.name = mercator_proj_type; // Latitude of the bottom left corner -get_global_att(ncfile, string("lat_ll_deg"), data.lat_ll); + get_global_att(ncfile, string("lat_ll_deg"), data.lat_ll); // Longitude of the bottom left corner -get_global_att(ncfile, string("lon_ll_deg"), data.lon_ll); -data.lon_ll *= -1.0; + get_global_att(ncfile, string("lon_ll_deg"), data.lon_ll); + data.lon_ll *= -1.0; // Latitude of the bottom left corner -get_global_att(ncfile, string("lat_ur_deg"), data.lat_ur); + get_global_att(ncfile, string("lat_ur_deg"), data.lat_ur); // Longitude of the bottom left corner -get_global_att(ncfile, string("lon_ur_deg"), data.lon_ur); -data.lon_ur *= -1.0; + get_global_att(ncfile, string("lon_ur_deg"), data.lon_ur); + data.lon_ur *= -1.0; // Number of points in the Latitudinal (y) direction -get_global_att(ncfile, string("Nlat"), data.ny); + get_global_att(ncfile, string("Nlat"), data.ny); // Number of points in the Longitudinal (x) direction -get_global_att(ncfile, string("Nlon"), data.nx); - -data.dump(); + get_global_att(ncfile, string("Nlon"), data.nx); - // - // done - // + data.dump(); -return; + return(data); } - /////////////////////////////////////////////////////////////////////////////// +GaussianData get_gaussian_data (NcFile * ncfile) { -void get_gaussian_data (NcFile * ncfile, GaussianData & data) - -{ - - -data.name = gaussian_proj_type; + GaussianData data; - // - // Longitude for x = 0 - // - -get_global_att(ncfile, string("lon_zero"), data.lon_zero); - - // - // nx - // - -get_global_att(ncfile, string("nx"), data.nx); - - // - // ny - // + // Store the grid name + data.name = gaussian_proj_type; -get_global_att(ncfile, string("ny"), data.ny); + // Longitude for x = 0 + get_global_att(ncfile, string("lon_zero"), data.lon_zero); -data.dump(); + // nx + get_global_att(ncfile, string("nx"), data.nx); - // - // done - // + // ny + get_global_att(ncfile, string("ny"), data.ny); -return; + data.dump(); + return(data); } - /////////////////////////////////////////////////////////////////////////////// +SemiLatLonData get_semilatlon_data (NcFile * ncfile) { -void get_semilatlon_data (NcFile * ncfile, SemiLatLonData & data) - -{ - - -data.name = semilatlon_proj_type; - -get_semilatlon_var(ncfile, "lat", data.lats); - -get_semilatlon_var(ncfile, "lon", data.lons); - -get_semilatlon_var(ncfile, "level", data.levels); - -get_semilatlon_var(ncfile, "time", data.times); + SemiLatLonData data; -data.dump(); - - // - // done - // + // Store the grid name + data.name = semilatlon_proj_type; + get_semilatlon_var(ncfile, "lat", data.lats); + get_semilatlon_var(ncfile, "lon", data.lons); + get_semilatlon_var(ncfile, "level", data.levels); + get_semilatlon_var(ncfile, "time", data.times); -return; + data.dump(); + return(data); } - /////////////////////////////////////////////////////////////////////////////// - void get_semilatlon_var(NcFile *ncfile, const char * var_name, NumArray &out_na) { -NcVar nc_var = get_var(ncfile, var_name); - -out_na.clear(); - - // - // requested variable may or may not be present in the file - // - -if ( IS_INVALID_NC(nc_var) ) return; + NcVar nc_var = get_var(ncfile, var_name); - // - // store the requested data in the specified NumArray object - // + out_na.erase(); -long count = get_data_size(&nc_var); -double * data_values = new double[ count ]; -get_nc_data(&nc_var, data_values); -for(int i=0; i