Skip to content

Commit

Permalink
#2231 Removed command line option for unstructured grid and make is c…
Browse files Browse the repository at this point in the history
…onfigurable by using the connfiguration file
  • Loading branch information
Howard Soh committed Sep 18, 2023
1 parent 8818d62 commit d33c387
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 33 deletions.
23 changes: 7 additions & 16 deletions src/tools/core/grid_stat/grid_stat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ using namespace netCDF;

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

static ConcatString ugrid_nc;


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

Expand Down Expand Up @@ -191,7 +191,6 @@ static void clean_up();
static void usage();
static void set_outdir(const StringArray &);
static void set_compress(const StringArray &);
static void set_ugrid_nc(const StringArray &);
static bool read_data_plane(VarInfo* info, DataPlane& dp, Met2dDataFile* mtddf,
const ConcatString &filename);

Expand Down Expand Up @@ -244,7 +243,6 @@ void process_command_line(int argc, char **argv) {
// Add the options function calls
cline.add(set_outdir, "-outdir", 1);
cline.add(set_compress, "-compress", 1);
cline.add(set_ugrid_nc, "-ugrid", 1);

// Parse the command line
cline.parse();
Expand Down Expand Up @@ -272,7 +270,6 @@ void process_command_line(int argc, char **argv) {
// Get the forecast and observation file types from config, if present
ftype = parse_conf_file_type(conf_info.conf.lookup_dictionary(conf_key_fcst));
otype = parse_conf_file_type(conf_info.conf.lookup_dictionary(conf_key_obs));
if (ftype == FileType_None && 0 < ugrid_nc.length()) ftype = FileType_UGrid;

// Read forecast file
if(!(fcst_mtddf = mtddf_factory.new_met_2d_data_file(fcst_file.c_str(), ftype))) {
Expand All @@ -296,7 +293,12 @@ void process_command_line(int argc, char **argv) {
conf_info.process_config(ftype, otype);

if (FileType_UGrid == ftype) {
((MetUGridDataFile *)fcst_mtddf)->open_metadata(ugrid_nc.c_str());
ConcatString ugrid_nc = conf_info.ugrid_nc;
ConcatString map_config_file = conf_info.ugrid_map_config;
MetUGridDataFile *ugrid_mtddf = (MetUGridDataFile *)fcst_mtddf;
if (0 < map_config_file.length()) ugrid_mtddf->set_map_config_file(map_config_file);
if (0 == ugrid_nc.length() || ugrid_nc == "NA") ugrid_nc = fcst_file;
ugrid_mtddf->open_metadata(ugrid_nc.c_str());
}

// For python types read the first field to set the grid
Expand Down Expand Up @@ -3040,7 +3042,6 @@ void usage() {
<< "\tfcst_file\n"
<< "\tobs_file\n"
<< "\tconfig_file\n"
<< "\t[-ugrid ugrid_file]\n"
<< "\t[-outdir path]\n"
<< "\t[-log file]\n"
<< "\t[-v level]\n"
Expand All @@ -3055,9 +3056,6 @@ void usage() {
<< "\t\t\"config_file\" is a GridStatConfig file containing "
<< "the desired configuration settings (required).\n"

<< "\t\t\"-ugrid ugrid_file\" is the metadata file for unstructured grid "
<< " (only required for unstructured grid data).\n"

<< "\t\t\"-outdir path\" overrides the default output directory "
<< "(" << out_dir << ") (optional).\n"

Expand Down Expand Up @@ -3087,13 +3085,6 @@ void set_compress(const StringArray & a) {

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

void set_ugrid_nc(const StringArray & a)
{
ugrid_nc = a[0];
}

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

bool read_data_plane(VarInfo* info, DataPlane& dp, Met2dDataFile* mtddf,
const ConcatString &filename) {

Expand Down
6 changes: 6 additions & 0 deletions src/tools/core/grid_stat/grid_stat_conf_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ void GridStatConfInfo::process_config(GrdFileType ftype,
// Conf: tmp_dir
tmp_dir = parse_conf_tmp_dir(&conf);

// Conf: ugrid_nc
ugrid_nc = parse_conf_ugrid_metadata_file(&conf);

// Conf: ugrid_map_config
ugrid_map_config = parse_conf_ugrid_map_config(&conf);

// Conf: output_prefix
output_prefix = conf.lookup_string(conf_key_output_prefix);

Expand Down
2 changes: 2 additions & 0 deletions src/tools/core/grid_stat/grid_stat_conf_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ class GridStatConfInfo {
ConcatString tmp_dir; // Directory for temporary files
ConcatString output_prefix; // String to customize output file name
ConcatString version; // Config file version
ConcatString ugrid_nc; // NetCDF for coordinate variables of unstructured grid
ConcatString ugrid_map_config; // Configuration file which contains ugrid metadata mapping

// Summary of output file options across all verification tasks
STATOutputType output_flag[n_txt]; // Flag for each output line type
Expand Down
22 changes: 6 additions & 16 deletions src/tools/core/point_stat/point_stat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ using namespace netCDF;

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

static ConcatString ugrid_nc;

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

Expand Down Expand Up @@ -179,7 +178,6 @@ static void set_ncfile(const StringArray &);
static void set_obs_valid_beg_time(const StringArray &);
static void set_obs_valid_end_time(const StringArray &);
static void set_outdir(const StringArray &);
static void set_ugrid_nc(const StringArray &);

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

Expand Down Expand Up @@ -243,7 +241,6 @@ void process_command_line(int argc, char **argv) {
cline.add(set_obs_valid_beg_time, "-obs_valid_beg", 1);
cline.add(set_obs_valid_end_time, "-obs_valid_end", 1);
cline.add(set_outdir, "-outdir", 1);
cline.add(set_ugrid_nc, "-ugrid", 1);

// Parse the command line
cline.parse();
Expand Down Expand Up @@ -284,7 +281,6 @@ void process_command_line(int argc, char **argv) {

// Get the forecast file type from config, if present
ftype = parse_conf_file_type(conf_info.conf.lookup_dictionary(conf_key_fcst));
if (ftype == FileType_None && 0 < ugrid_nc.length()) ftype = FileType_UGrid;

// Read forecast file
if(!(fcst_mtddf = mtddf_factory.new_met_2d_data_file(fcst_file.c_str(), ftype))) {
Expand All @@ -303,7 +299,12 @@ void process_command_line(int argc, char **argv) {
shc.set_model(conf_info.model.c_str());

if (FileType_UGrid == ftype) {
((MetUGridDataFile *)fcst_mtddf)->open_metadata(ugrid_nc.c_str());
ConcatString ugrid_nc = conf_info.ugrid_nc;
ConcatString map_config_file = conf_info.ugrid_map_config;
MetUGridDataFile *ugrid_mtddf = (MetUGridDataFile *)fcst_mtddf;
if (0 < map_config_file.length()) ugrid_mtddf->set_map_config_file(map_config_file);
if (0 == ugrid_nc.length() || ugrid_nc == "NA") ugrid_nc = fcst_file;
ugrid_mtddf->open_metadata(ugrid_nc.c_str());
}

// Use the first verification task to set the random number generator
Expand Down Expand Up @@ -2173,7 +2174,6 @@ void usage() {
<< "\t[-point_obs file]\n"
<< "\t[-obs_valid_beg time]\n"
<< "\t[-obs_valid_end time]\n"
<< "\t[-ugrid ugrid_file]\n"
<< "\t[-outdir path]\n"
<< "\t[-log file]\n"
<< "\t[-v level]\n\n"
Expand All @@ -2199,9 +2199,6 @@ void usage() {
<< "\t\t\"-outdir path\" overrides the default output "
<< "directory (" << out_dir << ") (optional).\n"

<< "\t\t\"-ugrid ugrid_file\" is the metadata file for unstructured grid "
<< " (only required for unstructured grid data).\n"

<< "\t\t\"-log file\" outputs log messages to the specified "
<< "file (optional).\n"

Expand Down Expand Up @@ -2248,10 +2245,3 @@ void set_outdir(const StringArray & a)

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

void set_ugrid_nc(const StringArray & a)
{
ugrid_nc = a[0];
}

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

2 changes: 1 addition & 1 deletion src/tools/core/point_stat/point_stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static Met2dDataFileFactory mtddf_factory;
static Met2dDataFile *fcst_mtddf = (Met2dDataFile *) 0;

// Pointer to the random number generator to be used
static gsl_rng *rng_ptr = (gsl_rng *) 0;
static gsl_rng *rng_ptr = (gsl_rng *) nullptr;

// Strings to be output in the STAT and optional text files
static StatHdrColumns shc;
Expand Down
8 changes: 8 additions & 0 deletions src/tools/core/point_stat/point_stat_conf_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ void PointStatConfInfo::clear() {
tmp_dir.clear();
output_prefix.clear();
version.clear();
ugrid_nc.clear();
ugrid_map_config.clear();

// Deallocate memory
if(vx_opt) { delete [] vx_opt; vx_opt = (PointStatVxOpt *) 0; }
Expand Down Expand Up @@ -121,6 +123,12 @@ void PointStatConfInfo::process_config(GrdFileType ftype) {
// Conf: tmp_dir
tmp_dir = parse_conf_tmp_dir(&conf);

// Conf: ugrid_nc
ugrid_nc = parse_conf_ugrid_metadata_file(&conf);

// Conf: ugrid_map_config
ugrid_map_config = parse_conf_ugrid_map_config(&conf);

// Conf: output_prefix
output_prefix = conf.lookup_string(conf_key_output_prefix);

Expand Down
2 changes: 2 additions & 0 deletions src/tools/core/point_stat/point_stat_conf_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ class PointStatConfInfo {
ConcatString tmp_dir; // Directory for temporary files
ConcatString output_prefix; // String to customize output file name
ConcatString version; // Config file version
ConcatString ugrid_nc; // NetCDF for coordinate variables of unstructured grid
ConcatString ugrid_map_config; // Configuration file which contains ugrid metadata mapping

// Summary of output file options across all verification tasks
STATOutputType output_flag[n_txt]; // Flag for each output line type
Expand Down

0 comments on commit d33c387

Please sign in to comment.