Skip to content

Commit

Permalink
Auto-format code using Clang-Format (#12)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Actions <[email protected]>
  • Loading branch information
github-actions[bot] and actions-user authored Jul 20, 2024
1 parent 5d49260 commit 6dc661a
Show file tree
Hide file tree
Showing 72 changed files with 38,358 additions and 36,659 deletions.
67 changes: 34 additions & 33 deletions src/Args.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#include "Args.h"

#include <cstdarg>
#include <iostream>
#include <fstream>
#include <iostream>
#include <unordered_set>

//#include <regex>

bool Args::parseArgs(int argc, char *argv[])
{

bool ret_val = true;
std::unordered_set<std::string> keywordSet ( { } );

std::unordered_set<std::string> keywordSet({});

tdrp_override_t override;
TDRP_init_override(&override);
Expand All @@ -21,31 +20,34 @@ bool Args::parseArgs(int argc, char *argv[])

// Fill override from command line arguments

for (int i = 1; i < argc; i++) {
if ( !strcmp(argv[i], "--") ||
!strcmp(argv[i], "-h") ||
!strcmp(argv[i], "-help") ||
!strcmp(argv[i], "-man")) {
for (int i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "--") || !strcmp(argv[i], "-h") || !strcmp(argv[i], "-help") || !strcmp(argv[i], "-man"))
{
params.usage(std::cout);
exit (0);
exit(0);
}
const char *arg = argv[i] + 1;
std::unordered_set<std::string>::const_iterator found = keywordSet.find(arg);
if ( found != keywordSet.end() ) {
if (found != keywordSet.end())
{
sprintf(tmp_str, "%s = %s;", arg, argv[++i]);
TDRP_add_override(&override, tmp_str);
} else {
TDRP_add_override(&override, tmp_str);
}
else
{
// This one has specific meaning to TDRP.
if ( ! strcmp(argv[i], "-params" ) )
i++;
if (!strcmp(argv[i], "-params"))
i++;
}
}

// Now parse the config file

char *paramsPath;

if (params.loadFromArgs(argc, argv, override.list, &paramsPath)) {

if (params.loadFromArgs(argc, argv, override.list, &paramsPath))
{
std::cout << "Problem with command line args" << std::endl;
ret_val = false;
}
Expand All @@ -55,16 +57,15 @@ bool Args::parseArgs(int argc, char *argv[])
return ret_val;
}


// Fill the given configHash with the data from the params object
#define STR_HELPER(_X_) std::string(#_X_)
#define STR(_X_) STR_HELPER(_X_)
#define STR(_X_) STR_HELPER(_X_)

#define CONFIG_INSERT_BOOL(_X_) configHash->insert(#_X_, params._X_ ? "true" : "false")
#define CONFIG_INSERT_INT(_X_) configHash->insert(#_X_, std::to_string(params._X_))
#define CONFIG_INSERT_BOOL(_X_) configHash->insert(#_X_, params._X_ ? "true" : "false")
#define CONFIG_INSERT_INT(_X_) configHash->insert(#_X_, std::to_string(params._X_))
#define CONFIG_INSERT_FLOAT(_X_) configHash->insert(#_X_, std::to_string(params._X_))
#define CONFIG_INSERT_STR(_X_) configHash->insert(#_X_, params._X_)
#define CONFIG_INSERT_FLOAT_ARRAY(zZz, _iter_) \
#define CONFIG_INSERT_STR(_X_) configHash->insert(#_X_, params._X_)
#define CONFIG_INSERT_FLOAT_ARRAY(zZz, _iter_) \
configHash->insert(STR(zZz) + "_" + std::to_string(iter), std::to_string(params._##zZz[_iter_ - 1])); \
configHash->insert(#zZz, std::to_string(params._##zZz[0]))

Expand All @@ -80,11 +81,10 @@ std::string mode_map[] = { "XYZ", "RTZ" };

// This needs to match projection_t in paramdef.samurai

std::string projection_map[] = { "lambert_conformal_conic",
"transverse_mercator_exact" };

bool Args::paramsToHash(HashMap *configHash) {
std::string projection_map[] = { "lambert_conformal_conic", "transverse_mercator_exact" };

bool Args::paramsToHash(HashMap *configHash)
{
// string arguments

CONFIG_INSERT_BOOL(adjust_background);
Expand Down Expand Up @@ -118,7 +118,7 @@ bool Args::paramsToHash(HashMap *configHash) {
CONFIG_INSERT_STR(ref_state);
CONFIG_INSERT_BOOL(save_mish);
CONFIG_INSERT_BOOL(use_fractl_errors);

// int arguments

CONFIG_INSERT_INT(bkgd_kd_num_neighbors);
Expand Down Expand Up @@ -172,7 +172,7 @@ bool Args::paramsToHash(HashMap *configHash) {
CONFIG_INSERT_STR(k_rhow_bcR);
CONFIG_INSERT_STR(k_tempk_bcL);
CONFIG_INSERT_STR(k_tempk_bcR);

// float arguments

CONFIG_INSERT_FLOAT(aeri_qv_error);
Expand Down Expand Up @@ -253,7 +253,7 @@ bool Args::paramsToHash(HashMap *configHash) {
CONFIG_INSERT_FLOAT(k_max_wavenumber_rhov);
CONFIG_INSERT_FLOAT(k_max_wavenumber_rhow);
CONFIG_INSERT_FLOAT(k_max_wavenumber_tempk);
#endif
#endif
CONFIG_INSERT_FLOAT(k_min);
CONFIG_INSERT_FLOAT(k_reflectivity_roi);
// CONFIG_INSERT_FLOAT(k_spline_cutoff);
Expand Down Expand Up @@ -281,7 +281,8 @@ bool Args::paramsToHash(HashMap *configHash) {
CONFIG_INSERT_FLOAT(rain_dbz);
CONFIG_INSERT_FLOAT(sfmr_windspeed_error);

for (int iter = 1; iter <= params.num_iterations; iter++) {
for (int iter = 1; iter <= params.num_iterations; iter++)
{
CONFIG_INSERT_FLOAT_ARRAY(bg_qr_error, iter);
CONFIG_INSERT_FLOAT_ARRAY(bg_rhoa_error, iter);
CONFIG_INSERT_FLOAT_ARRAY(bg_rhou_error, iter);
Expand All @@ -295,7 +296,7 @@ bool Args::paramsToHash(HashMap *configHash) {
CONFIG_INSERT_FLOAT_ARRAY(k_filter_length, iter);
CONFIG_INSERT_FLOAT_ARRAY(i_spline_cutoff, iter);
CONFIG_INSERT_FLOAT_ARRAY(j_spline_cutoff, iter);
CONFIG_INSERT_FLOAT_ARRAY(k_spline_cutoff, iter);
CONFIG_INSERT_FLOAT_ARRAY(k_spline_cutoff, iter);
CONFIG_INSERT_FLOAT_ARRAY(i_max_wavenumber, iter);
CONFIG_INSERT_FLOAT_ARRAY(j_max_wavenumber, iter);
CONFIG_INSERT_FLOAT_ARRAY(mc_weight, iter);
Expand Down
12 changes: 6 additions & 6 deletions src/Args.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
#ifndef ARGS_H
#define ARGS_H

#include "Params.hh" // generated by trdp_gen
#include "HashMap.h"
#include "Params.hh" // generated by trdp_gen

#include <string>

class Args {
class Args
{
public:

bool parseArgs(int argc, char *argv[]);
bool paramsToHash(HashMap *configHash);

private:
Params params;
};

#endif // ARGS_H
#endif // ARGS_H
Loading

0 comments on commit 6dc661a

Please sign in to comment.