Skip to content

Commit

Permalink
refactored the code for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Albo committed Apr 13, 2023
1 parent b1209a3 commit 0197bbe
Show file tree
Hide file tree
Showing 9 changed files with 408 additions and 313 deletions.
11 changes: 6 additions & 5 deletions src/libcode/vx_shapedata/mode_conf_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -966,13 +966,14 @@ dict = conf.lookup_dictionary(conf_key_obs);
if ( dict->lookup(conf_key_multivar_logic) ) obs_multivar_logic = dict->lookup_string(conf_key_multivar_logic);

multivar_intensity.clear();
BoolArray ba = lookup_bool_array("multivar_intensity_flag", dict);
ba.dump(cout);
for (int i=0; i<ba.n(); ++i) {
multivar_intensity.push_back((ba[i] == 1 ? true:false));
if ( dict->lookup("multivar_intensity_flag")) {
BoolArray ba = lookup_bool_array("multivar_intensity_flag", dict);
//ba.dump(cout);
for (int i=0; i<ba.n(); ++i) {
multivar_intensity.push_back((ba[i] == 1 ? true:false));
}
}
return;

}


Expand Down
89 changes: 75 additions & 14 deletions src/tools/core/mode/mode_exec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ void ModeExecutive::init()

{

GrdFileType ftype, otype;
Met2dDataFileFactory mtddf_factory;

R_index = T_index = 0;
Expand Down Expand Up @@ -208,6 +207,79 @@ return;

}

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


void ModeExecutive::init_final(const MultiVarData &mvd)

{

GrdFileType ftype, otype;
//Met2dDataFileFactory mtddf_factory;

R_index = T_index = 0;

// Create the default config file name
default_config_file = replace_path(default_config_filename);

// If the merge config file was not set, use the match config file
if(merge_config_file.length() == 0)
merge_config_file = match_config_file;

// List the config files
mlog << Debug(1)
<< "Default Config File: " << default_config_file << "\n"
<< "Match Config File: " << match_config_file << "\n"
<< "Merge Config File: " << merge_config_file << "\n";

// Read the config files
engine.conf_info.read_config(default_config_file.c_str(), match_config_file.c_str());

// Get the forecast and observation file types from config, if present
ftype = parse_conf_file_type(engine.conf_info.conf.lookup_dictionary(conf_key_fcst));
otype = parse_conf_file_type(engine.conf_info.conf.lookup_dictionary(conf_key_obs));


// Read observation file
// if(!(obs_mtddf = mtddf_factory.new_met_2d_data_file(obs_file.c_str(), otype))) {
// mlog << Error << "\nTrouble reading observation file \""
// << obs_file << "\"\n\n";
// exit(1);
// }


// Read forecast file
// if(!(fcst_mtddf = mtddf_factory.new_met_2d_data_file(fcst_file.c_str(), ftype))) {
// mlog << Error << "\nTrouble reading forecast file \""
// << fcst_file << "\"\n\n";
// exit(1);
// }

// Store the input data file types
// ftype = fcst_mtddf->file_type();
// otype = obs_mtddf->file_type();

ftype = mvd.ftype;
otype = mvd.otype;

// Process the configuration
engine.conf_info.process_config(ftype, otype);

// const int shift = engine.conf_info.shift_right;

// fcst_mtddf->set_shift_right(shift);
// obs_mtddf->set_shift_right(shift);

// List the input files
// mlog << Debug(1)
// << "Forecast File: " << fcst_file << "\n"
// << "Observation File: " << obs_file << "\n";

engine.conf_info.nc_info.compress_level = engine.conf_info.get_compression_level();

return;

}

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

Expand Down Expand Up @@ -1022,6 +1094,8 @@ MultiVarData *ModeExecutive::get_multivar_data()
mvd->Fcst_sd = new ShapeData(Fcst_sd);
mvd->Obs_sd = new ShapeData(Obs_sd);
mvd->grid = new Grid(grid);
mvd->ftype = ftype;
mvd->otype = otype;
return mvd;
}

Expand Down Expand Up @@ -1271,9 +1345,6 @@ if ( info.all_false() ) return;

}

vector<int> fcstValues, obsValues;
vector<int> fcstCValues, obsCValues;

for(x=0; x<grid.nx(); x++) {

for(y=0; y<grid.ny(); y++) {
Expand All @@ -1299,11 +1370,6 @@ if ( info.all_false() ) return;
}
if ( info.do_object_id && fcst_obj_data != nullptr && engine.fcst_split != nullptr ) {
fcst_obj_data[n] = nint(engine.fcst_split->data(x, y));
if (find(fcstValues.begin(), fcstValues.end(), fcst_obj_data[n]) == fcstValues.end())
{
printf("FcstValue=%d\n", fcst_obj_data[n]);
fcstValues.push_back(fcst_obj_data[n]);
}
}
}
else {
Expand All @@ -1321,11 +1387,6 @@ if ( info.all_false() ) return;
}
if ( info.do_object_id && obs_obj_data != nullptr ) {
obs_obj_data[n] = nint(engine.obs_split->data(x, y));
if (find(obsValues.begin(), obsValues.end(), obs_obj_data[n]) == obsValues.end())
{
printf("ObsValue=%d\n", obs_obj_data[n]);
obsValues.push_back(obs_obj_data[n]);
}
}
}
else {
Expand Down
3 changes: 3 additions & 0 deletions src/tools/core/mode/mode_exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class ModeExecutive {
void clear();

void init();
void init_final(const MultiVarData &mvd);

int n_conv_radii () const;
int n_conv_threshs () const;
Expand Down Expand Up @@ -113,6 +114,8 @@ class ModeExecutive {

ShapeData Fcst_sd, Obs_sd;

GrdFileType ftype, otype;

void clear_internal_r_index();
void setup_fcst_obs_data();
void setup_fcst_obs_data(const MultiVarData &mvd);
Expand Down
60 changes: 55 additions & 5 deletions src/tools/core/mode/mode_frontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ if ( mode_exec ) {
int ModeFrontEnd::run(const StringArray & Argv)

{
Argv.dump(cout, 0);
// Argv.dump(cout, 0);


//
Expand Down Expand Up @@ -117,7 +117,7 @@ return (0);

int ModeFrontEnd::run(const StringArray & Argv, const MultiVarData &mvd)
{
Argv.dump(cout, 0);
//Argv.dump(cout, 0);


//
Expand All @@ -127,9 +127,9 @@ if ( mode_exec ) { delete mode_exec; mode_exec = 0; }

mode_exec = new ModeExecutive;
compress_level = -1;
field_index = -1;
//field_index = -1;

process_command_line(Argv);
process_command_line_final(Argv, mvd);


//
Expand All @@ -138,7 +138,7 @@ process_command_line(Argv);

ModeConfInfo & conf = mode_exec->engine.conf_info;

if ( field_index >= 0 ) conf.set_field_index(field_index);
//if ( field_index >= 0 ) conf.set_field_index(field_index);

mode_exec->setup_fcst_obs_data(mvd);

Expand Down Expand Up @@ -317,6 +317,56 @@ void ModeFrontEnd::process_command_line(const StringArray & argv)

}

void ModeFrontEnd::process_command_line_final(const StringArray & argv,
const MultiVarData &mvd)
{

CommandLine cline;
ConcatString s;
const int argc = argv.n();


// Set the default output directory
mode_exec->out_dir = replace_path(default_out_dir);

// Check for zero arguments
if(argc == 1) singlevar_usage(); // wrong, need something else

// Parse the command line into tokens
cline.set(argv);

// Set the usage function
cline.set_usage(singlevar_usage); // wrong, need something else

// Add the options function calls
cline.add(set_config_merge_file, "-config_merge", 1);
cline.add(set_outdir, "-outdir", 1);
cline.add(set_logfile, "-log", 1);
cline.add(set_verbosity, "-v", 1);
cline.add(set_compress, "-compress", 1);

//
// add for mode multivar ... undocumented
//
//cline.add(set_field_index, "-field_index", 1);

// Parse the command line
cline.parse();

// Check for error. There should be 1 argument left:
// config filename
if(cline.n() != 1) singlevar_usage(); // wrong need something else

// Store the input forecast and observation file names, placeholders
mode_exec->fcst_file = "not set";
mode_exec->obs_file = "not set";
mode_exec->match_config_file = cline[0];
mode_exec->init_final(mvd);

return;

}

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

void ModeFrontEnd::set_config_merge_file(const StringArray & a)
Expand Down
2 changes: 2 additions & 0 deletions src/tools/core/mode/mode_frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class ModeFrontEnd {
MultiVarData *get_multivar_data();

void process_command_line(const StringArray &);
void process_command_line_final(const StringArray & argv,
const MultiVarData &mvd);
static void set_config_merge_file (const StringArray &);
static void set_outdir (const StringArray &);
static void set_logfile (const StringArray &);
Expand Down
6 changes: 5 additions & 1 deletion src/tools/core/mode/multivar_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class MultiVarData {
obs_raw_data(0),
nx(0), ny(0),
Fcst_sd(0), Obs_sd(0),
grid(0)
grid(0),
ftype(FileType_None),
otype(FileType_None)
{}

inline ~MultiVarData() {
Expand All @@ -57,6 +59,8 @@ class MultiVarData {
ShapeData *Fcst_sd;
ShapeData *Obs_sd;
Grid *grid;
GrdFileType ftype;
GrdFileType otype;

/* int get_fcst_obj_nx(); */
/* int get_fcst_obj_ny(); */
Expand Down

0 comments on commit 0197bbe

Please sign in to comment.