Skip to content

Commit

Permalink
#1581 Corrected API calls because of renaming for common APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Howard Soh committed Apr 1, 2021
1 parent 126d7f4 commit 757fae7
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 80 deletions.
11 changes: 6 additions & 5 deletions met/src/tools/other/ascii2nc/file_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 13 additions & 12 deletions met/src/tools/other/ioda2nc/ioda2nc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<v_obs_data.size(); idx++ ) {
Expand All @@ -792,8 +792,8 @@ void process_ioda_file(int i_pb) {
// store the header data and increment the IODA record
// counter
if(n_hdr_obs > 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 {
Expand All @@ -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;

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
}
Expand Down
25 changes: 12 additions & 13 deletions met/src/tools/other/lidar2nc/lidar2nc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ using namespace std;

////////////////////////////////////////////////////////////////////////

struct NcHeaderData *header_data = get_hdr_data_buffer();

static ConcatString program_name;

static CommandLine cline;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

//
Expand All @@ -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
Expand Down Expand Up @@ -473,7 +471,8 @@ for (j=0; j<n_data; ++j) {

v_idx = valid_times.n_elements();
valid_times.add(t);
header_data->vld_array.add(junk);
//header_data.vld_array.add(junk);
obs_vars.add_header_vld(junk);
}
ibuf[j] = v_idx;

Expand Down Expand Up @@ -553,11 +552,11 @@ for (j=0; j<n_data; ++j) {

} // for j

write_nc_observation(obs_vars);
obs_vars.write_observation();

create_nc_table_vars(obs_vars, out);
obs_vars.create_table_vars(out);

write_nc_table_vars(obs_vars);
obs_vars.write_table_vars();

//
// close hdf file
Expand Down Expand Up @@ -597,11 +596,11 @@ void write_nc_record(NetcdfObsVars a_obs_vars, const float * f, int qc_value)
//

if ( qc_value < 0 ) {
write_nc_observation(obs_vars, f, na_str);
obs_vars.write_observation(f, na_str);
} else {
char junk[HEADER_STR_LEN];
snprintf(junk, sizeof(junk), "%d", qc_value);
write_nc_observation(obs_vars, f, junk);
obs_vars.write_observation(f, junk);
}

return;
Expand Down
28 changes: 14 additions & 14 deletions met/src/tools/other/madis2nc/madis2nc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ int main(int argc, char *argv[]) {
//
process_command_line(argc, argv);

nc_obs_initialize();
obs_vars.init_data_buffer();

//
// Process the MADIS file
Expand All @@ -157,7 +157,7 @@ int main(int argc, char *argv[]) {

bool use_var_id = true;
bool do_header = false;
int nhdr = get_nc_hdr_cur_index();
int nhdr = obs_vars.get_obs_index();

if (conf_info.getSummaryInfo().flag) {
int summmary_hdr_cnt = 0;
Expand Down Expand Up @@ -387,7 +387,7 @@ void setup_netcdf_out(int nhdr) {
}

bool use_var_id = false;
init_nc_dims_vars_config(obs_vars, use_var_id);
obs_vars.reset(use_var_id);
obs_vars.obs_cnt = obs_vector.size();
mlog << Debug(5) << "setup_netcdf_out() nhdr:\t" << nhdr
<< "\tobs_cnt:\t" << obs_vars.obs_cnt << "\n";
Expand Down Expand Up @@ -744,7 +744,7 @@ void process_madis_metar(NcFile *&f_in) {
double tmp_dbl;
time_t hdr_vld;
ConcatString hdr_typ, hdr_sid;
float hdr_arr[hdr_arr_len], obs_arr[obs_arr_len], conversion;
float hdr_arr[HDR_ARRAY_LEN], obs_arr[OBS_ARRAY_LEN], conversion;
float wdir, wind, ugrd, vgrd;
int count;
StringArray missing_vars, missing_qty_vars;
Expand Down Expand Up @@ -1172,7 +1172,7 @@ void process_madis_raob(NcFile *&f_in) {
char qty;
time_t hdr_vld;
ConcatString hdr_typ, hdr_sid;
float hdr_arr[hdr_arr_len], obs_arr[obs_arr_len], conversion;
float hdr_arr[HDR_ARRAY_LEN], obs_arr[OBS_ARRAY_LEN], conversion;
float wdir, wind, ugrd, vgrd;
int count;
StringArray missing_vars, missing_qty_vars;
Expand Down Expand Up @@ -1594,7 +1594,7 @@ void process_madis_raob(NcFile *&f_in) {

hdr_vld = (time_t)tmp_dbl;

hdr_idx = get_nc_hdr_cur_index();
hdr_idx = obs_vars.get_obs_index();

//
// Process the station name.
Expand Down Expand Up @@ -1985,7 +1985,7 @@ void process_madis_profiler(NcFile *&f_in) {
double tmp_dbl;
time_t hdr_vld;
ConcatString hdr_typ, hdr_sid;
float hdr_arr[hdr_arr_len], obs_arr[obs_arr_len], conversion;
float hdr_arr[HDR_ARRAY_LEN], obs_arr[OBS_ARRAY_LEN], conversion;
float pressure;
int count;
StringArray missing_vars, missing_qty_vars;
Expand Down Expand Up @@ -2170,7 +2170,7 @@ void process_madis_profiler(NcFile *&f_in) {

hdr_vld = (time_t)tmp_dbl;

hdr_idx = get_nc_hdr_cur_index();
hdr_idx = obs_vars.get_obs_index();

//
// Initialize the observation array: hdr_id
Expand Down Expand Up @@ -2243,7 +2243,7 @@ void process_madis_maritime(NcFile *&f_in) {
double tmp_dbl;
time_t hdr_vld;
ConcatString hdr_typ, hdr_sid;
float hdr_arr[hdr_arr_len], obs_arr[obs_arr_len], conversion;
float hdr_arr[HDR_ARRAY_LEN], obs_arr[OBS_ARRAY_LEN], conversion;
float pressure;
int count;
StringArray missing_vars, missing_qty_vars;
Expand Down Expand Up @@ -2504,7 +2504,7 @@ void process_madis_maritime(NcFile *&f_in) {

hdr_vld = (time_t)tmp_dbl;

hdr_idx = get_nc_hdr_cur_index();
hdr_idx = obs_vars.get_obs_index();


//
Expand Down Expand Up @@ -2625,7 +2625,7 @@ void process_madis_mesonet(NcFile *&f_in) {
double tmp_dbl;
time_t hdr_vld;
ConcatString hdr_typ, hdr_sid;
float hdr_arr[hdr_arr_len], obs_arr[obs_arr_len], conversion;
float hdr_arr[HDR_ARRAY_LEN], obs_arr[OBS_ARRAY_LEN], conversion;
float wdir, wind, ugrd, vgrd;
int count;
StringArray missing_vars, missing_qty_vars;
Expand Down Expand Up @@ -2981,7 +2981,7 @@ void process_madis_mesonet(NcFile *&f_in) {
if(is_bad_data(tmp_dbl)) continue;
hdr_vld = (time_t)tmp_dbl;

hdr_idx = get_nc_hdr_cur_index();
hdr_idx = obs_vars.get_obs_index();

//
// Initialize the observation array: hdr_id, gc, lvl, hgt, ob
Expand Down Expand Up @@ -3204,7 +3204,7 @@ void process_madis_acarsProfiles(NcFile *&f_in) {
char qty;
time_t hdr_vld;
ConcatString hdr_typ, hdr_sid;
float hdr_arr[hdr_arr_len], obs_arr[obs_arr_len], conversion;
float hdr_arr[HDR_ARRAY_LEN], obs_arr[OBS_ARRAY_LEN], conversion;
float pressure, wdir, wind, ugrd, vgrd;
int count;
StringArray missing_vars, missing_qty_vars;
Expand Down Expand Up @@ -3428,7 +3428,7 @@ void process_madis_acarsProfiles(NcFile *&f_in) {
i_cnt++;
mlog << Debug(3) << " Mandatory Level: " << i_lvl << "\n";

hdr_idx = get_nc_hdr_cur_index();
hdr_idx = obs_vars.get_obs_index();

//
// Use cur to index into the NetCDF variables.
Expand Down
Loading

0 comments on commit 757fae7

Please sign in to comment.