diff --git a/met/src/libcode/vx_nc_obs/nc_point_obs.cc b/met/src/libcode/vx_nc_obs/nc_point_obs.cc index e23d56cc9a..b665e9d2e9 100644 --- a/met/src/libcode/vx_nc_obs/nc_point_obs.cc +++ b/met/src/libcode/vx_nc_obs/nc_point_obs.cc @@ -21,12 +21,9 @@ using namespace std; #include #include "vx_log.h" +#include "is_bad_data.h" #include "nc_point_obs.h" -#include "write_netcdf.h" - -//////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////// @@ -71,7 +68,6 @@ void MetNcPointObs::close() { obs_nc = (NcFile *) 0; } - //obs_vars.reset(); obs_data.clear(); header_data.clear(); return; @@ -143,6 +139,15 @@ bool MetNcPointObs::get_lons(float *hdr_lons) { return true; } + +//////////////////////////////////////////////////////////////////////// + +bool MetNcPointObs::is_same_obs_values(const float obs_arr1[OBS_ARRAY_LEN], + const float obs_arr2[OBS_ARRAY_LEN]) { + return is_eq(obs_arr1[0], obs_arr1[0]) && is_eq(obs_arr1[2], obs_arr2[2]) + && is_eq(obs_arr1[3], obs_arr2[3]); +} + //////////////////////////////////////////////////////////////////////// bool MetNcPointObs::open(const char * filename) { diff --git a/met/src/libcode/vx_nc_obs/nc_point_obs.h b/met/src/libcode/vx_nc_obs/nc_point_obs.h index 95eb5f57a9..50baf1404b 100644 --- a/met/src/libcode/vx_nc_obs/nc_point_obs.h +++ b/met/src/libcode/vx_nc_obs/nc_point_obs.h @@ -26,9 +26,6 @@ #include "vx_summary.h" -//////////////////////////////////////////////////////////////////////// -// struct definition - //////////////////////////////////////////////////////////////////////// @@ -48,9 +45,6 @@ class MetNcPointObs { NcPointObsData obs_data; NcHeaderData header_data; - //MetNcPointObs(const MetNcPointObs &); - //MetNcPointObs & operator=(const MetNcPointObs &); - void init_from_scratch(); public: @@ -64,10 +58,12 @@ class MetNcPointObs { int get_buf_size(); int get_hdr_cnt(); + int get_grib_code_or_var_index(const float obs_arr[OBS_ARRAY_LEN]); NcHeaderData get_header_data(); bool get_header(int header_offset, float hdr_arr[HDR_ARRAY_LEN], ConcatString &hdr_typ_str, ConcatString &hdr_sid_str, ConcatString &hdr_vld_str); + int get_header_offset(const float obs_arr[OBS_ARRAY_LEN]); bool get_header_type(int header_offset, int hdr_typ_arr[HDR_TYPE_ARR_LEN]); bool get_lats(float *hdr_lats); bool get_lons(float *hdr_lons); @@ -77,9 +73,11 @@ class MetNcPointObs { int get_qty_length(); StringArray get_var_names(); + bool is_same_obs_values(const float obs_arr1[OBS_ARRAY_LEN], const float obs_arr2[OBS_ARRAY_LEN]); bool is_using_var_id(); bool is_using_obs_arr(); + void set_grib_code_or_var_index(float obs_arr[OBS_ARRAY_LEN], int grib_code); // variables // data @@ -90,13 +88,16 @@ class MetNcPointObs { inline NcHeaderData MetNcPointObs::get_header_data() { return header_data; } inline int MetNcPointObs::get_buf_size() { return OBS_BUFFER_SIZE; } +inline int MetNcPointObs::get_grib_code_or_var_index(const float obs_arr[OBS_ARRAY_LEN]) { return obs_arr[1]; }; inline int MetNcPointObs::get_hdr_cnt() { return nhdr; } +inline int MetNcPointObs::get_header_offset(const float obs_arr[OBS_ARRAY_LEN]) { return obs_arr[0]; }; inline int MetNcPointObs::get_obs_cnt() { return nobs; } inline NcPointObsData MetNcPointObs::get_point_obs_data() { return obs_data; } inline StringArray MetNcPointObs::get_qty_data() { return obs_data.qty_names; } inline StringArray MetNcPointObs::get_var_names() { return obs_data.var_names; } inline bool MetNcPointObs::is_using_obs_arr() { return use_arr_vars; } inline bool MetNcPointObs::is_using_var_id() { return use_var_id; } +inline void MetNcPointObs::set_grib_code_or_var_index(float obs_arr[OBS_ARRAY_LEN], int grib_code) { obs_arr[1] = grib_code; } //////////////////////////////////////////////////////////////////////// diff --git a/met/src/tools/core/ensemble_stat/ensemble_stat.cc b/met/src/tools/core/ensemble_stat/ensemble_stat.cc index d62b8bf7b5..eecc5c183f 100644 --- a/met/src/tools/core/ensemble_stat/ensemble_stat.cc +++ b/met/src/tools/core/ensemble_stat/ensemble_stat.cc @@ -962,7 +962,7 @@ void process_point_obs(int i_nc) { // Read the dimensions and variables nc_point_obs.read_dim_headers(); nc_point_obs.check_nc(point_obs_file_list[i_nc].c_str(), method_name); // exit if missing dims/vars - nc_point_obs.read_obs_data_strings(); + nc_point_obs.read_obs_data_table_lookups(); int hdr_count = nc_point_obs.get_hdr_cnt(); int obs_count = nc_point_obs.get_obs_cnt(); @@ -1008,7 +1008,7 @@ void process_point_obs(int i_nc) { int qty_offset = use_arr_vars ? i_obs : obs_qty_idx_block[i_offset]; obs_qty_str = obs_qty_array[qty_offset]; - int headerOffset = obs_arr[0]; + int headerOffset = nc_point_obs.get_header_offset(obs_arr); // Range check the header offset if(headerOffset < 0 || headerOffset >= hdr_count) { @@ -1023,7 +1023,7 @@ void process_point_obs(int i_nc) { // Read the corresponding header array for this observation // - the corresponding header type, header Station ID, and valid time nc_point_obs.get_header(headerOffset, hdr_arr, hdr_typ_str, - hdr_sid_str, hdr_vld_str); + hdr_sid_str, hdr_vld_str); // Read the header integer types nc_point_obs.get_header_type(headerOffset, hdr_typ_arr); @@ -1031,8 +1031,9 @@ void process_point_obs(int i_nc) { // Convert string to a unixtime hdr_ut = timestring_to_unix(hdr_vld_str.c_str()); - if (use_var_id && obs_arr[1] < var_names.n()) { - var_name = var_names[obs_arr[1]]; + int grib_code = nc_point_obs.get_grib_code_or_var_index(obs_arr); + if (use_var_id && grib_code < var_names.n()) { + var_name = var_names[grib_code]; } else { var_name = ""; diff --git a/met/src/tools/core/point_stat/point_stat.cc b/met/src/tools/core/point_stat/point_stat.cc index 3675256a40..cecdec213f 100644 --- a/met/src/tools/core/point_stat/point_stat.cc +++ b/met/src/tools/core/point_stat/point_stat.cc @@ -20,7 +20,6 @@ // Mod# Date Name Description // ---- ---- ---- ----------- // 000 04/18/07 Halley Gotway New -// 000 04/18/07 Halley Gotway New // 001 12/20/07 Halley Gotway Allow verification for level 0 // for verifying PRMSL // 002 01/24/08 Halley Gotway In compute_cnt, print a warning @@ -673,7 +672,7 @@ void process_obs_file(int i_nc) { nc_point_obs.read_dim_headers(); nc_point_obs.check_nc(obs_file[i_nc].c_str(), method_name); - nc_point_obs.read_obs_data_strings(); + nc_point_obs.read_obs_data_table_lookups(); bool use_var_id = nc_point_obs.is_using_var_id(); int hdr_count = nc_point_obs.get_hdr_cnt(); @@ -718,7 +717,7 @@ void process_obs_file(int i_nc) { int qty_offset = use_arr_vars ? i_obs : obs_qty_idx_block[i_block_idx]; obs_qty_str = obs_qty_array[qty_offset]; - int headerOffset = obs_arr[0]; + int headerOffset = nc_point_obs.get_header_offset(obs_arr); // Range check the header offset if(headerOffset < 0 || headerOffset >= hdr_count) { @@ -736,20 +735,21 @@ void process_obs_file(int i_nc) { hdr_sid_str, hdr_vld_str); // Store the variable name - int grib_code = obs_arr[1]; + int org_grib_code = nc_point_obs.get_grib_code_or_var_index(obs_arr); + int grib_code = org_grib_code; if (use_var_id && grib_code < var_names.n()) { var_name = var_names[grib_code]; - obs_arr[1] = bad_data_int; + grib_code = bad_data_int; } else { var_name = ""; } // Check for wind components - is_ugrd = ( use_var_id && var_name == ugrd_abbr_str ) || - (!use_var_id && nint(obs_arr[1]) == ugrd_grib_code); - is_vgrd = ( use_var_id && var_name == vgrd_abbr_str ) || - (!use_var_id && nint(obs_arr[1]) == vgrd_grib_code); + is_ugrd = ( use_var_id && var_name == ugrd_abbr_str ) || + (!use_var_id && nint(grib_code) == ugrd_grib_code); + is_vgrd = ( use_var_id && var_name == vgrd_abbr_str ) || + (!use_var_id && nint(grib_code) == vgrd_grib_code); // If the current observation is UGRD, save it as the // previous. If vector winds are to be computed, UGRD @@ -764,9 +764,7 @@ void process_obs_file(int i_nc) { // and at the same vertical level. if(vflag && is_vgrd) { - if(!is_eq(obs_arr[0], prev_obs_arr[0]) || - !is_eq(obs_arr[2], prev_obs_arr[2]) || - !is_eq(obs_arr[3], prev_obs_arr[3])) { + if(!nc_point_obs.is_same_obs_values(obs_arr, prev_obs_arr)) { mlog << Error << "\n" << method_name << "for observation index " << i_obs << ", when computing VL1L2 and/or VAL1L2 vector winds " @@ -794,7 +792,7 @@ void process_obs_file(int i_nc) { grid, var_name.c_str()); } - obs_arr[1] = grib_code; + nc_point_obs.set_grib_code_or_var_index(obs_arr, org_grib_code); } } // end for i_block_start_idx