diff --git a/met/src/tools/other/ascii2nc/file_handler.cc b/met/src/tools/other/ascii2nc/file_handler.cc index 28ef53e8cc..6c89e5d429 100644 --- a/met/src/tools/other/ascii2nc/file_handler.cc +++ b/met/src/tools/other/ascii2nc/file_handler.cc @@ -76,7 +76,7 @@ FileHandler::~FileHandler() bool FileHandler::readAsciiFiles(const vector< ConcatString > &ascii_filename_list) { - nc_obs_initialize(); + obs_vars.init_data_buffer(); // Loop through the ASCII files, reading in the observations. At the end of // this loop, all of the observations will be in the _observations vector. @@ -157,7 +157,7 @@ bool FileHandler::writeNetcdfFile(const string &nc_filename) return false; // Add variable names - if (use_var_id) write_obs_var_names(obs_vars, obs_names); + if (use_var_id) obs_vars.write_obs_var_names(obs_names); // Close the netCDF file. @@ -249,8 +249,9 @@ bool FileHandler::_openNetcdf(const string &nc_filename) // // Define the NetCDF dimensions and variables // - init_nc_dims_vars_config(obs_vars, use_var_id); + obs_vars.reset(use_var_id); obs_vars.attr_agl = true; + obs_vars.deflate_level = deflate_level; nc_out_data.processed_hdr_cnt = 0; nc_out_data.deflate_level = deflate_level; @@ -388,8 +389,8 @@ bool FileHandler::_writeObservations() int var_count = (use_var_id ? obs_names.n_elements() : 0); if (var_count > 0) { int unit_count = 0; - create_nc_obs_name_vars (obs_vars, _ncFile, var_count, unit_count, deflate_level); - write_obs_var_names(obs_vars, obs_names); + obs_vars.create_obs_name_vars (_ncFile, var_count, unit_count); + obs_vars.write_obs_var_names(obs_names); } return true; diff --git a/met/src/tools/other/ioda2nc/ioda2nc.cc b/met/src/tools/other/ioda2nc/ioda2nc.cc index 9069459123..a41d875c74 100644 --- a/met/src/tools/other/ioda2nc/ioda2nc.cc +++ b/met/src/tools/other/ioda2nc/ioda2nc.cc @@ -205,7 +205,7 @@ void initialize() { n_total_obs = 0; - nc_obs_initialize(); + obs_vars.init_data_buffer(); core_dims.clear(); core_dims.add("nvars"); @@ -323,7 +323,7 @@ void open_netcdf() { } // Define netCDF variables - init_nc_dims_vars_config(obs_vars); + obs_vars.reset(); // Add global attributes write_netcdf_global(f_out, ncfile.text(), program_name); @@ -768,7 +768,7 @@ void process_ioda_file(int i_pb) { } // Store the index to the header data - obs_arr[0] = (float) get_nc_hdr_cur_index(); + obs_arr[0] = (float) obs_vars.get_hdr_index(); n_hdr_obs = 0; for(idx=0; idx 0) { - add_nc_header_to_array(modified_hdr_typ, hdr_sid.c_str(), hdr_vld_ut, - hdr_lat, hdr_lon, hdr_elv); + obs_vars.add_header(modified_hdr_typ, hdr_sid.c_str(), hdr_vld_ut, + hdr_lat, hdr_lon, hdr_elv); i_msg++; } else { @@ -810,8 +810,8 @@ void process_ioda_file(int i_pb) { cout << log_message << "\n"; } - int obs_buf_index = get_nc_obs_buf_index(); - if(obs_buf_index > 0) write_nc_obs_buffer(obs_buf_index); + int obs_buf_index = obs_vars.get_obs_index(); + if(obs_buf_index > 0) obs_vars.write_obs_buffer(obs_buf_index); if(mlog.verbosity_level() > 0) cout << "\n" << flush; @@ -900,7 +900,7 @@ void process_ioda_file(int i_pb) { void write_netcdf_hdr_data() { static const string method_name = "\nwrite_netcdf_hdr_data()"; - const long hdr_count = (long) get_nc_hdr_cur_index(); + const long hdr_count = (long) obs_vars.get_hdr_index(); int deflate_level = compress_level; if(deflate_level < 0) deflate_level = conf_info.conf.nc_compression(); @@ -940,10 +940,11 @@ void write_netcdf_hdr_data() { nc_var_desc_arr.add(obs_var_descs[i]); } - create_nc_obs_name_vars(obs_vars, f_out, var_count, units_count, deflate_level); - write_obs_var_names(obs_vars, nc_var_name_arr); - write_obs_var_units(obs_vars, nc_var_unit_arr); - write_obs_var_descriptions(obs_vars, nc_var_desc_arr); + obs_vars.deflate_level = deflate_level; + obs_vars.create_obs_name_vars(f_out, var_count, units_count); + obs_vars.write_obs_var_names(nc_var_name_arr); + obs_vars.write_obs_var_units(nc_var_unit_arr); + obs_vars.write_obs_var_descriptions(nc_var_desc_arr); return; } diff --git a/met/src/tools/other/lidar2nc/lidar2nc.cc b/met/src/tools/other/lidar2nc/lidar2nc.cc index b8bca05f9c..832bc5ee95 100644 --- a/met/src/tools/other/lidar2nc/lidar2nc.cc +++ b/met/src/tools/other/lidar2nc/lidar2nc.cc @@ -63,8 +63,6 @@ using namespace std; //////////////////////////////////////////////////////////////////////// -struct NcHeaderData *header_data = get_hdr_data_buffer(); - static ConcatString program_name; static CommandLine cline; @@ -332,10 +330,11 @@ mlog << Debug(1) << "Writing MET File:\t" << output_filename << "\n"; // bool use_var_id = false; - init_nc_dims_vars_config(obs_vars, use_var_id); + obs_vars.reset(use_var_id); obs_vars.attr_agl = true; - create_nc_hdr_vars(obs_vars, out, n_data, deflate_level); - create_nc_obs_vars(obs_vars, out, deflate_level, use_var_id); + obs_vars.deflate_level = deflate_level; + obs_vars.create_hdr_vars(out, n_data); + obs_vars.create_obs_vars(out); if (!IS_INVALID_NC(obs_vars.strl2_dim)) { NcDim str_dim; @@ -385,7 +384,6 @@ mlog << Debug(2) << "Processing Lidar points\t= " << n_data << "\n"; memset(ibuf, 0, n_data*sizeof(int)); -header_data->typ_array.add(hdr_typ_string); obs_vars.hdr_typ_var.putVar(ibuf); // @@ -394,8 +392,8 @@ obs_vars.hdr_typ_var.putVar(ibuf); memset(ibuf, 0, n_data*sizeof(int)); -header_data->sid_array.add(na_str); obs_vars.hdr_sid_var.putVar(ibuf); +obs_vars.add_header_strings(hdr_typ_string, na_str); // // populate the obs_qty variable @@ -473,7 +471,8 @@ for (j=0; jvld_array.add(junk); + //header_data.vld_array.add(junk); + obs_vars.add_header_vld(junk); } ibuf[j] = v_idx; @@ -553,11 +552,11 @@ for (j=0; j= 0 ? compress_level : - conf_info.conf.nc_compression())); + obs_vars.deflate_level = (compress_level >= 0 ? compress_level + : conf_info.conf.nc_compression()); + obs_vars.create_obs_vars(f_out); // Add global attributes write_netcdf_global(f_out, ncfile.text(), program_name); @@ -835,7 +829,7 @@ void process_pbfile(int i_pb) { unixtime hdr_vld_ut = (unixtime) 0; float quality_mark, dl_category; - float obs_arr[obs_arr_len]; + float obs_arr[OBS_ARRAY_LEN]; float pqtzuv[mxr8vt], pqtzuv_qty[mxr8vt]; const int debug_level_for_performance = 3; @@ -1024,7 +1018,7 @@ void process_pbfile(int i_pb) { diff_file_time_count = 0; cycle_minute = missing_cycle_minute; // initialize - for (int idx=0; idx mxr8lv) { @@ -1757,7 +1751,7 @@ void process_pbfile(int i_pb) { } mlog << Debug(10) << "var: " << var_name << " nlev2: " << nlev2 << ", vIdx: " << vIdx << ", obs_data_idx: " - << get_nc_obs_buf_index() << ", nlev: " << nlev << "\n"; + << obs_vars.get_obs_index() << ", nlev: " << nlev << "\n"; // Search through the vertical levels for(lv=0; lv 0) { - add_nc_header_to_array(modified_hdr_typ, hdr_sid.c_str(), hdr_vld_ut, - hdr_lat, hdr_lon, hdr_elv); + obs_vars.add_header(modified_hdr_typ, hdr_sid.c_str(), hdr_vld_ut, + hdr_lat, hdr_lon, hdr_elv); if (is_prepbufr) { - add_nc_header_prepbufr(pb_report_type, in_report_type, instrument_type); + obs_vars.add_header_prepbufr(pb_report_type, in_report_type, instrument_type); } i_msg++; @@ -1911,8 +1905,8 @@ void process_pbfile(int i_pb) { } mlog << Warning << "\n"; } - int obs_buf_index = get_nc_obs_buf_index(); - if (obs_buf_index > 0) write_nc_obs_buffer(obs_buf_index); + int obs_buf_index = obs_vars.get_obs_index(); + if (obs_buf_index > 0) obs_vars.write_obs_buffer(obs_buf_index); if(mlog.verbosity_level() > 0) cout << "\n" << flush; @@ -2401,7 +2395,7 @@ void write_netcdf_hdr_data() { bool is_prepbufr = is_prepbufr_file(&event_names); static const string method_name = "\nwrite_netcdf_hdr_data()"; - pb_hdr_count = (long) get_nc_hdr_cur_index(); + pb_hdr_count = (long) obs_vars.get_hdr_index(); if (obs_to_vector) { int deflate_level = compress_level; if (deflate_level < 0) deflate_level = conf_info.conf.nc_compression(); @@ -2435,11 +2429,9 @@ void write_netcdf_hdr_data() { exit(1); } - int deflate_level = compress_level; - if (deflate_level < 0) deflate_level = conf_info.conf.nc_compression(); if (is_prepbufr) { if (!nc_out_data.summary_info.flag || nc_out_data.summary_info.raw_data) - create_nc_pb_hdrs(obs_vars, f_out, pb_hdr_count, deflate_level); + obs_vars.create_pb_hdrs(f_out, pb_hdr_count); } // Make sure all obs data is processed before handling header @@ -2449,8 +2441,8 @@ void write_netcdf_hdr_data() { else { if (do_summary) { // Write out the summary data - if (save_summary_only) reset_header_buffer(pb_hdr_count, true); - write_nc_observations(obs_vars, summary_obs->getSummaries()); + if (save_summary_only) obs_vars.reset_header_buffer(pb_hdr_count, true); + obs_vars.write_observations(summary_obs->getSummaries()); mlog << Debug(4) << "write_netcdf_hdr_data obs count: " << (int)summary_obs->getObservations().size() << " summary count: " << (int)summary_obs->getSummaries().size() @@ -2463,14 +2455,14 @@ void write_netcdf_hdr_data() { } } - create_nc_hdr_vars(obs_vars, f_out, dim_count, deflate_level); - create_nc_table_vars(obs_vars, f_out, deflate_level); + obs_vars.create_hdr_vars(f_out, dim_count); + obs_vars.create_table_vars(f_out); // Write out the header data - write_nc_arr_headers(obs_vars); - if (get_nc_hdr_cur_index() > 0) { + obs_vars.write_arr_headers(); + if (obs_vars.get_hdr_index() > 0) { // Write out the remaining header data - write_nc_buf_headers(obs_vars); + obs_vars.write_buf_headers(); } } @@ -2513,10 +2505,10 @@ void write_netcdf_hdr_data() { } // end for i dim_count = bufr_obs_name_arr.n_elements(); - create_nc_obs_name_vars (obs_vars, f_out, dim_count, dim_count, deflate_level); - write_obs_var_names (obs_vars, nc_var_name_arr); - write_obs_var_units (obs_vars, nc_var_unit_arr); - write_obs_var_descriptions (obs_vars, nc_var_desc_arr); + obs_vars.create_obs_name_vars (f_out, dim_count, dim_count); + obs_vars.write_obs_var_names (nc_var_name_arr); + obs_vars.write_obs_var_units (nc_var_unit_arr); + obs_vars.write_obs_var_descriptions (nc_var_desc_arr); return; } @@ -2556,7 +2548,7 @@ void addObservation(const float *obs_arr, const ConcatString &hdr_typ, } else { if (!save_summary_only) - write_nc_observation(obs_vars, obs_arr, obs_qty.text()); + obs_vars.write_observation(obs_arr, obs_qty.text()); if (do_summary) { string var_name = bufr_obs_name_arr[(obs_arr[1])]; conf_info.getSummaryInfo();