Skip to content

Commit

Permalink
Per #2966, reduce SonarQube code smells in gen_vx_mask
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnHalleyGotway committed Nov 5, 2024
1 parent 2a32e45 commit 8734801
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions src/tools/other/gen_vx_mask/gen_vx_mask.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,20 @@ using namespace netCDF;
////////////////////////////////////////////////////////////////////////

int met_main(int argc, char *argv[]) {
static DataPlane dp_data, dp_mask, dp_out;

// Process the command line arguments
process_command_line(argc, argv);

// Process the input grid
static DataPlane dp_data;
process_input_grid(dp_data);

// Process the mask file
static DataPlane dp_mask;
process_mask_file(dp_mask);

// Apply combination logic if the current mask is binary
static DataPlane dp_out;
if(mask_type == MaskType::Poly ||
mask_type == MaskType::Poly_XY ||
mask_type == MaskType::Shape ||
Expand All @@ -105,13 +107,13 @@ int met_main(int argc, char *argv[]) {

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

const string get_tool_name() {
string get_tool_name() {
return "gen_vx_mask";
}

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

void process_command_line(int argc, char **argv) {
static void process_command_line(int argc, char **argv) {
CommandLine cline;

// Check for zero arguments
Expand Down Expand Up @@ -160,9 +162,8 @@ void process_command_line(int argc, char **argv) {
if(mask_type == MaskType::None) {
mlog << Error << "\n" << program_name << " -> "
<< "the -type command line requirement must be set to a specific masking type!\n"
<< "\t\t \"poly\", \"box\", \"circle\", \"track\", \"grid\", "
<< "\"data\", \"solar_alt\", \"solar_azi\", \"solar_time\", "
<< "\"lat\", \"lon\", or \"shape\"\n\n";
<< "\t\t poly, box, circle, track, grid, data, solar_alt, "
<< "solar_azi, solar_time, lat, lon, or shape\n\n";
exit(1);
}

Expand All @@ -176,7 +177,7 @@ void process_command_line(int argc, char **argv) {

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

void process_input_grid(DataPlane &dp) {
static void process_input_grid(DataPlane &dp) {

if (!build_grid_by_grid_string(input_gridname, grid, "process_input_grid", false)) {
// Extract the grid from a gridded data file
Expand All @@ -203,7 +204,7 @@ void process_input_grid(DataPlane &dp) {

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

void process_mask_file(DataPlane &dp) {
static void process_mask_file(DataPlane &dp) {

// Initialize
solar_ut = (unixtime) 0;
Expand All @@ -227,7 +228,7 @@ void process_mask_file(DataPlane &dp) {
else if(mask_type == MaskType::Shape) {

// If -shape_str was specified, find the matching records
if(shape_str_map.size() > 0) get_shapefile_strings();
if(!shape_str_map.empty()) get_shapefile_strings();

// Get the records specified by -shapeno and -shape_str
get_shapefile_records();
Expand Down Expand Up @@ -257,9 +258,10 @@ void process_mask_file(DataPlane &dp) {
<< unix_to_yyyymmdd_hhmmss(solar_ut) << "\n";
}

// Nothing to do for Lat/Lon masking types
// For Lat/Lon masking types
else if(mask_type == MaskType::Lat ||
mask_type == MaskType::Lon) {
// Nothing to do for Lat/Lon masking types
}

// Otherwise, process the mask file as a named grid, grid specification
Expand Down Expand Up @@ -393,18 +395,18 @@ void process_mask_file(DataPlane &dp) {

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

void get_data_plane(const ConcatString &file_name,
const ConcatString &config_str,
bool read_gen_vx_mask_output,
DataPlane &dp, Grid &dp_grid) {
static void get_data_plane(const ConcatString &file_name,
const ConcatString &config_str,
bool read_gen_vx_mask_output,
DataPlane &dp, Grid &dp_grid) {
ConcatString local_cs = config_str;
GrdFileType ftype = FileType_None;

// Initialize to the global configuration
MetConfig local_config = global_config;

// Parse non-empty config strings
if(local_cs.length() > 0) {
if(!local_cs.empty()) {
local_config.read_string(local_cs.c_str());
ftype = parse_conf_file_type(&local_config);
}
Expand All @@ -420,15 +422,14 @@ void get_data_plane(const ConcatString &file_name,

// Read gen_vx_mask output from a previous run
if(read_gen_vx_mask_output &&
local_cs.length() == 0 &&
mtddf_ptr->file_type() == FileType_NcMet) {
if(get_gen_vx_mask_config_str((MetNcMetDataFile *) mtddf_ptr, local_cs)) {
local_config.read_string(local_cs.c_str());
}
local_cs.empty() &&
mtddf_ptr->file_type() == FileType_NcMet &&
get_gen_vx_mask_config_str((MetNcMetDataFile *) mtddf_ptr, local_cs)) {
local_config.read_string(local_cs.c_str());
}

// Read data plane, if requested
if(local_cs.length() > 0) {
if(!local_cs.empty()) {

// Allocate new VarInfo object
VarInfo *vi_ptr = VarInfoFactory::new_var_info(mtddf_ptr->file_type());
Expand Down Expand Up @@ -477,8 +478,8 @@ void get_data_plane(const ConcatString &file_name,

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

bool get_gen_vx_mask_config_str(MetNcMetDataFile *mnmdf_ptr,
ConcatString &config_str) {
static bool get_gen_vx_mask_config_str(MetNcMetDataFile *mnmdf_ptr,
ConcatString &config_str) {
bool status = false;
ConcatString tool;

Expand Down

0 comments on commit 8734801

Please sign in to comment.