diff --git a/source/c_api/accAPI.cpp b/source/c_api/accAPI.cpp index 9b00f05c..5039fa43 100644 --- a/source/c_api/accAPI.cpp +++ b/source/c_api/accAPI.cpp @@ -500,7 +500,7 @@ void udaPutErrorModel(int handle, int model, int param_n, const float* params) if (data_block == nullptr) { return; } - if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { + if (model <= (int)ErrorModelType::Unknown || model >= (int)ErrorModelType::Undefined) { return; // No valid Model } @@ -525,7 +525,7 @@ void udaPutDimErrorModel(int handle, int ndim, int model, int param_n, const flo if (ndim < 0 || (unsigned int)ndim >= data_block->rank) { return; // No Dim } - if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { + if (model <= (int)ErrorModelType::Unknown || model >= (int)ErrorModelType::Undefined) { return; // No valid Model } @@ -986,7 +986,7 @@ void udaGetErrorModel(int handle, int* model, int* param_n, float* params) { auto data_block = getDataBlock(handle); if (data_block == nullptr) { - *model = ERROR_MODEL_UNKNOWN; + *model = (int)ErrorModelType::Unknown; *param_n = 0; return; } @@ -1010,42 +1010,42 @@ int udaGetErrorAsymmetry(int handle) int udaGetErrorModelId(const char* model) { - for (int i = 1; i < ERROR_MODEL_UNDEFINED; i++) { + for (int i = 1; i < (int)ErrorModelType::Undefined; i++) { switch (i) { case 1: if (STR_IEQUALS(model, "default")) { - return ERROR_MODEL_DEFAULT; + return (int)ErrorModelType::Default; } break; case 2: if (STR_IEQUALS(model, "default_asymmetric")) { - return ERROR_MODEL_DEFAULT_ASYMMETRIC; + return (int)ErrorModelType::DefaultAsymmetric; } break; #ifdef NO_GSL_LIB case 3: if (STR_IEQUALS(model, "gaussian")) { - return ERROR_MODEL_GAUSSIAN; + return ErrorModelType::Gaussian; } break; case 4: if (STR_IEQUALS(model, "reseed")) { - return ERROR_MODEL_RESEED; + return ErrorModelType::Reseed; } break; case 5: if (STR_IEQUALS(model, "gaussian_shift")) { - return ERROR_MODEL_GAUSSIAN_SHIFT; + return ErrorModelType::GaussianShift; } break; case 6: if (STR_IEQUALS(model, "poisson")) { - return ERROR_MODEL_POISSON; + return ErrorModelType::Poisson; } break; #endif default: - return ERROR_MODEL_UNKNOWN; + return (int)ErrorModelType::Unknown; } } return 0; @@ -1093,10 +1093,10 @@ char* udaGetSyntheticData(int handle) if (status != MIN_STATUS && (data_block->client_block.get_bad || client_flags->get_bad)) { return nullptr; } - if (!client_flags->get_synthetic || data_block->error_model == ERROR_MODEL_UNKNOWN) { + if (!client_flags->get_synthetic || data_block->error_model == (int)ErrorModelType::Unknown) { return data_block->data; } - generateIdamSyntheticData(handle); + generate_synthetic_data(handle); return data_block->synthetic; } @@ -1253,8 +1253,8 @@ char* udaGetAsymmetricError(int handle, int above) } // otherwise the data array must have been returned by the server or generated } } else { - if (data_block->error_model != ERROR_MODEL_UNKNOWN) { - generateIdamDataError(handle); // Create the errors from a model if the model exits + if (data_block->error_model != (int)ErrorModelType::Unknown) { + generate_data_error(handle); // Create the errors from a model if the model exits if (above) { return data_block->errhi; } else if (!data_block->errasymmetry) { @@ -1550,7 +1550,7 @@ void udaGetDoubleData(int handle, double* fp) if (!client_flags->get_synthetic) { memcpy((void*)fp, (void*)data_block->data, (size_t)data_block->data_n * sizeof(double)); } else { - generateIdamSyntheticData(handle); + generate_synthetic_data(handle); if (data_block->synthetic != nullptr) { memcpy((void*)fp, (void*)data_block->synthetic, (size_t)data_block->data_n * sizeof(double)); } else { @@ -1568,7 +1568,7 @@ void udaGetDoubleData(int handle, double* fp) if (!client_flags->get_synthetic) { array = data_block->data; } else { - generateIdamSyntheticData(handle); + generate_synthetic_data(handle); if (data_block->synthetic != nullptr) { array = data_block->synthetic; } else { @@ -1717,7 +1717,7 @@ void udaGetFloatData(int handle, float* fp) if (!client_flags->get_synthetic) { memcpy((void*)fp, (void*)data_block->data, (size_t)data_block->data_n * sizeof(float)); } else { - generateIdamSyntheticData(handle); + generate_synthetic_data(handle); if (data_block->synthetic != nullptr) { memcpy((void*)fp, (void*)data_block->synthetic, (size_t)data_block->data_n * sizeof(float)); } else { @@ -1735,7 +1735,7 @@ void udaGetFloatData(int handle, float* fp) if (!client_flags->get_synthetic) { array = data_block->data; } else { - generateIdamSyntheticData(handle); + generate_synthetic_data(handle); if (data_block->synthetic != nullptr) { array = data_block->synthetic; } else { @@ -2301,7 +2301,7 @@ void udaGetDimErrorModel(int handle, int ndim, int* model, int* param_n, float* auto data_block = getDataBlock(handle); if (data_block == nullptr || ndim < 0 || (unsigned int)ndim >= data_block->rank) { - *model = ERROR_MODEL_UNKNOWN; + *model = (int)ErrorModelType::Unknown; *param_n = 0; return; } @@ -2413,7 +2413,7 @@ void udaGetDoubleDimData(int handle, int ndim, double* fp) if (!client_flags->get_synthetic) { memcpy((void*)fp, (void*)data_block->dims[ndim].dim, (size_t)data_block->dims[ndim].dim_n * sizeof(double)); } else { - generateIdamSyntheticDimData(handle, ndim); + generate_synthetic_dim_data(handle, ndim); if (data_block->dims[ndim].synthetic != nullptr) { memcpy((void*)fp, (void*)data_block->dims[ndim].synthetic, (size_t)data_block->dims[ndim].dim_n * sizeof(double)); @@ -2430,7 +2430,7 @@ void udaGetDoubleDimData(int handle, int ndim, double* fp) if (!client_flags->get_synthetic) { array = data_block->dims[ndim].dim; } else { - generateIdamSyntheticDimData(handle, ndim); + generate_synthetic_dim_data(handle, ndim); if (data_block->dims[ndim].synthetic != nullptr) { array = data_block->dims[ndim].synthetic; } else { @@ -2569,7 +2569,7 @@ void udaGetFloatDimData(int handle, int ndim, float* fp) if (!client_flags->get_synthetic) { memcpy((void*)fp, (void*)data_block->dims[ndim].dim, (size_t)data_block->dims[ndim].dim_n * sizeof(float)); } else { - generateIdamSyntheticDimData(handle, ndim); + generate_synthetic_dim_data(handle, ndim); if (data_block->dims[ndim].synthetic != nullptr) { memcpy((void*)fp, (void*)data_block->dims[ndim].synthetic, (size_t)data_block->dims[ndim].dim_n * sizeof(float)); @@ -2586,7 +2586,7 @@ void udaGetFloatDimData(int handle, int ndim, float* fp) if (!client_flags->get_synthetic) { array = data_block->dims[ndim].dim; } else { - generateIdamSyntheticDimData(handle, ndim); + generate_synthetic_dim_data(handle, ndim); if (data_block->dims[ndim].synthetic != nullptr) { array = data_block->dims[ndim].synthetic; } else { @@ -2797,8 +2797,8 @@ char* udaGetDimAsymmetricError(int handle, int ndim, int above) } // otherwise the data array must have been returned by the server } // or generated in a previous call } else { - if (data_block->dims[ndim].error_model != ERROR_MODEL_UNKNOWN) { - generateIdamDimDataError(handle, ndim); + if (data_block->dims[ndim].error_model != (int)ErrorModelType::Unknown) { + generate_dim_data_error(handle, ndim); if (above || !data_block->dims[ndim].errasymmetry) { return data_block->dims[ndim].errhi; } else { diff --git a/source/client/generateErrors.cpp b/source/client/generateErrors.cpp index 93a3198c..744870f1 100644 --- a/source/client/generateErrors.cpp +++ b/source/client/generateErrors.cpp @@ -29,14 +29,14 @@ using namespace uda::client; //-------------------------------------------------------------------------------------------------------------- // Generate Error Data -int uda::client::idamErrorModel(int model, int param_n, float* params, int data_n, float* data, int* asymmetry, +int uda::client::error_model(int model, int param_n, float* params, int data_n, float* data, int* asymmetry, float* errhi, float* errlo) { *asymmetry = 0; // No Error Asymmetry for most models - switch (model) { + switch ((ErrorModelType)model) { - case ERROR_MODEL_DEFAULT: + case ErrorModelType::Default: if (param_n != 2) { return 1; } @@ -46,7 +46,7 @@ int uda::client::idamErrorModel(int model, int param_n, float* params, int data_ } break; - case ERROR_MODEL_DEFAULT_ASYMMETRIC: + case ErrorModelType::DefaultAsymmetric: if (param_n != 4) { return 1; } @@ -74,7 +74,7 @@ int uda::client::idamErrorModel(int model, int param_n, float* params, int data_ // GSL_RNG_SEED 12345 for the seed value // GSL_RNG_TYPE mrg for the name of the random number generator -int uda::client::idamSyntheticModel(int model, int param_n, float* params, int data_n, float* data) +int uda::client::synthetic_model(int model, int param_n, float* params, int data_n, float* data) { #ifdef NO_GSL_LIB @@ -91,12 +91,12 @@ int uda::client::idamSyntheticModel(int model, int param_n, float* params, int d gsl_rng_env_setup(); random = gsl_rng_alloc(gsl_rng_default); gsl_rng_set(random, - (unsigned long int)ERROR_MODEL_SEED); // Seed the Random Number generator with the library default + (unsigned long int)ErrorModelSeed); // Seed the Random Number generator with the library default } - switch (model) { + switch ((ErrorModelType)model) { - case ERROR_MODEL_GAUSSIAN: // Standard normal Distribution + case ErrorModelType::Gaussian: // Standard normal Distribution if (param_n < 1 || param_n > 2) { return 1; } @@ -108,13 +108,13 @@ int uda::client::idamSyntheticModel(int model, int param_n, float* params, int d } break; - case ERROR_MODEL_RESEED: // Change the Seed + case ErrorModelType::Reseed: // Change the Seed if (param_n == 1) { gsl_rng_set(random, (unsigned long int)params[0]); } break; - case ERROR_MODEL_GAUSSIAN_SHIFT: + case ErrorModelType::GaussianShift: if (param_n < 1 || param_n > 2) { return 1; } @@ -127,7 +127,7 @@ int uda::client::idamSyntheticModel(int model, int param_n, float* params, int d } break; - case ERROR_MODEL_POISSON: + case ErrorModelType::Poisson: if (param_n < 0 || param_n > 1) { return 1; } @@ -138,13 +138,16 @@ int uda::client::idamSyntheticModel(int model, int param_n, float* params, int d data[i] = data[i] + (float)gsl_ran_poisson(random, (double)data[i]); // Randomly perturb data array } break; + + default: + break; } return 0; #endif } -int uda::client::generateIdamSyntheticData(int handle) +int uda::client::generate_synthetic_data(int handle) { int err = 0; @@ -163,7 +166,7 @@ int uda::client::generateIdamSyntheticData(int handle) udaGetErrorModel(handle, &model, ¶m_n, params); - if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { + if (model <= (int)ErrorModelType::Unknown || model >= (int)ErrorModelType::Undefined) { return 0; // No valid Model } @@ -280,7 +283,7 @@ int uda::client::generateIdamSyntheticData(int handle) //-------------------------------------------------------------------------------------------------------------- // Generate Synthetic Data - err = uda::client::idamSyntheticModel(model, param_n, params, udaGetDataNum(handle), data); + err = uda::client::synthetic_model(model, param_n, params, udaGetDataNum(handle), data); if (err != 0) { add_error(ErrorType::Code, "generateIdamSyntheticData", err, "Unable to Generate Synthetic Data"); @@ -395,7 +398,7 @@ int uda::client::generateIdamSyntheticData(int handle) return 0; } -int uda::client::generateIdamSyntheticDimData(int handle, int ndim) +int uda::client::generate_synthetic_dim_data(int handle, int ndim) { int err = 0; @@ -418,7 +421,7 @@ int uda::client::generateIdamSyntheticDimData(int handle, int ndim) udaGetErrorModel(handle, &model, ¶m_n, params); - if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { + if (model <= (int)ErrorModelType::Unknown || model >= (int)ErrorModelType::Undefined) { return 0; // No valid Model } @@ -536,7 +539,7 @@ int uda::client::generateIdamSyntheticDimData(int handle, int ndim) //-------------------------------------------------------------------------------------------------------------- // Generate Model Data - err = uda::client::idamSyntheticModel(model, param_n, params, udaGetDimNum(handle, ndim), data); + err = uda::client::synthetic_model(model, param_n, params, udaGetDimNum(handle, ndim), data); if (err != 0) { add_error(ErrorType::Code, "generateIdamSyntheticDimData", err, @@ -653,7 +656,7 @@ int uda::client::generateIdamSyntheticDimData(int handle, int ndim) return 0; } -int uda::client::generateIdamDataError(int handle) +int uda::client::generate_data_error(int handle) { int err = 0, asymmetry = 0; @@ -672,7 +675,7 @@ int uda::client::generateIdamDataError(int handle) udaGetErrorModel(handle, &model, ¶m_n, params); - if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { + if (model <= (int)ErrorModelType::Unknown || model >= (int)ErrorModelType::Undefined) { return 0; // No valid Model } @@ -799,7 +802,7 @@ int uda::client::generateIdamDataError(int handle) //-------------------------------------------------------------------------------------------------------------- // Generate Error Data - err = idamErrorModel(model, param_n, params, udaGetDataNum(handle), data, &asymmetry, (float*)errhi, (float*)errlo); + err = error_model(model, param_n, params, udaGetDataNum(handle), data, &asymmetry, (float*)errhi, (float*)errlo); if (err != 0) { free(data); @@ -966,7 +969,7 @@ int uda::client::generateIdamDataError(int handle) return 0; } -int uda::client::generateIdamDimDataError(int handle, int ndim) +int uda::client::generate_dim_data_error(int handle, int ndim) { int err = 0, asymmetry = 0; @@ -990,7 +993,7 @@ int uda::client::generateIdamDimDataError(int handle, int ndim) udaGetErrorModel(handle, &model, ¶m_n, params); - if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { + if (model <= (int)ErrorModelType::Unknown || model >= (int)ErrorModelType::Undefined) { return 0; // No valid Model } @@ -1117,7 +1120,7 @@ int uda::client::generateIdamDimDataError(int handle, int ndim) //-------------------------------------------------------------------------------------------------------------- // Generate Model Data - err = idamErrorModel(model, param_n, params, udaGetDimNum(handle, ndim), data, &asymmetry, (float*)errhi, + err = error_model(model, param_n, params, udaGetDimNum(handle, ndim), data, &asymmetry, (float*)errhi, (float*)errlo); if (err != 0) { diff --git a/source/client/generateErrors.h b/source/client/generateErrors.h index 0a7a7ac8..a2db5db7 100644 --- a/source/client/generateErrors.h +++ b/source/client/generateErrors.h @@ -3,17 +3,17 @@ namespace uda::client { -int idamErrorModel(int model, int param_n, float* params, int data_n, float* data, int* asymmetry, float* errhi, +int error_model(int model, int param_n, float* params, int data_n, float* data, int* asymmetry, float* errhi, float* errlo); -int idamSyntheticModel(int model, int param_n, float* params, int data_n, float* data); +int synthetic_model(int model, int param_n, float* params, int data_n, float* data); -int generateIdamSyntheticData(int handle); +int generate_synthetic_data(int handle); -int generateIdamSyntheticDimData(int handle, int ndim); +int generate_synthetic_dim_data(int handle, int ndim); -int generateIdamDataError(int handle); +int generate_data_error(int handle); -int generateIdamDimDataError(int handle, int ndim); +int generate_dim_data_error(int handle, int ndim); } // namespace uda::client diff --git a/source/client2/generate_errors.cpp b/source/client2/generate_errors.cpp index 2286f271..28b4dea0 100644 --- a/source/client2/generate_errors.cpp +++ b/source/client2/generate_errors.cpp @@ -23,9 +23,9 @@ int uda::client::error_model(int model, int param_n, float* params, int data_n, { *asymmetry = 0; // No Error Asymmetry for most models - switch (model) { + switch ((ErrorModelType)model) { - case ERROR_MODEL_DEFAULT: + case ErrorModelType::Default: if (param_n != 2) { return 1; } @@ -35,7 +35,7 @@ int uda::client::error_model(int model, int param_n, float* params, int data_n, } break; - case ERROR_MODEL_DEFAULT_ASYMMETRIC: + case ErrorModelType::DefaultAsymmetric: if (param_n != 4) { return 1; } @@ -78,12 +78,12 @@ int uda::client::synthetic_model(int model, int param_n, float* params, int data gsl_rng_env_setup(); random = gsl_rng_alloc(gsl_rng_default); gsl_rng_set(random, - (unsigned long int)ERROR_MODEL_SEED); // Seed the Random Number generator with the library default + (unsigned long int)ErrorModelSeed); // Seed the Random Number generator with the library default } switch (model) { - case ERROR_MODEL_GAUSSIAN: // Standard normal Distribution + case ErrorModelType::Gaussian: // Standard normal Distribution if (param_n < 1 || param_n > 2) { return 1; } @@ -95,13 +95,13 @@ int uda::client::synthetic_model(int model, int param_n, float* params, int data } break; - case ERROR_MODEL_RESEED: // Change the Seed + case ErrorModelType::Reseed: // Change the Seed if (param_n == 1) { gsl_rng_set(random, (unsigned long int)params[0]); } break; - case ERROR_MODEL_GAUSSIAN_SHIFT: + case ErrorModelType::GaussianShift: if (param_n < 1 || param_n > 2) { return 1; } @@ -114,7 +114,7 @@ int uda::client::synthetic_model(int model, int param_n, float* params, int data } break; - case ERROR_MODEL_POISSON: + case ErrorModelType::Poisson: if (param_n < 0 || param_n > 1) { return 1; } @@ -161,7 +161,7 @@ int uda::client::generate_synthetic_data(int handle) get_error_model(handle, &model, ¶m_n, params); - if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { + if (model <= (int)ErrorModelType::Unknown || model >= (int)ErrorModelType::Undefined) { return 0; // No valid Model } @@ -416,7 +416,7 @@ int uda::client::generate_synthetic_dim_data(int handle, int ndim) get_error_model(handle, &model, ¶m_n, params); - if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { + if (model <= (int)ErrorModelType::Unknown || model >= (int)ErrorModelType::Undefined) { return 0; // No valid Model } @@ -670,7 +670,7 @@ int uda::client::generate_data_error(int handle) get_error_model(handle, &model, ¶m_n, params); - if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { + if (model <= (int)ErrorModelType::Unknown || model >= (int)ErrorModelType::Undefined) { return 0; // No valid Model } @@ -988,7 +988,7 @@ int uda::client::generate_dim_data_error(int handle, int ndim) get_error_model(handle, &model, ¶m_n, params); - if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { + if (model <= (int)ErrorModelType::Unknown || model >= (int)ErrorModelType::Undefined) { return 0; // No valid Model } diff --git a/source/client2/thread_client.cpp b/source/client2/thread_client.cpp index 3a2f14f8..1a80feb6 100644 --- a/source/client2/thread_client.cpp +++ b/source/client2/thread_client.cpp @@ -3,6 +3,8 @@ #include "generate_errors.hpp" #include "uda/client.h" +using namespace uda::client_server; + std::once_flag uda::client::ThreadClient::init_flag_ = {}; uda::client::Client* uda::client::ThreadClient::instance_ = nullptr; @@ -62,7 +64,7 @@ char* get_synthetic_data(int handle) if (status != MIN_STATUS && (data_block->client_block.get_bad || client_flags->get_bad)) { return nullptr; } - if (!client_flags->get_synthetic || data_block->error_model == ERROR_MODEL_UNKNOWN) { + if (!client_flags->get_synthetic || data_block->error_model == (int)ErrorModelType::Unknown) { return data_block->data; } uda::client::generate_synthetic_data(handle); @@ -153,7 +155,7 @@ char* uda::client::get_synthetic_data(int handle) if (status != MIN_STATUS && (data_block->client_block.get_bad || client_flags->get_bad)) { return nullptr; } - if (!client_flags->get_synthetic || data_block->error_model == ERROR_MODEL_UNKNOWN) { + if (!client_flags->get_synthetic || data_block->error_model == (int)ErrorModelType::Unknown) { return data_block->data; } uda::client::generate_synthetic_data(handle); @@ -229,7 +231,7 @@ void uda::client::get_error_model(int handle, int* model, int* param_n, float* p auto data_block = instance.data_block(handle); if (data_block == nullptr) { - *model = ERROR_MODEL_UNKNOWN; + *model = (int)ErrorModelType::Unknown; *param_n = 0; return; } diff --git a/source/clientserver/parseXML.cpp b/source/clientserver/parseXML.cpp index 6687af82..f6d35563 100644 --- a/source/clientserver/parseXML.cpp +++ b/source/clientserver/parseXML.cpp @@ -1538,7 +1538,7 @@ void init_dim_documentation(DimDocumentation* act) { } void init_dim_error_model(DimErrorModel* act) { - act->model = ERROR_MODEL_UNKNOWN; // No Error Model + act->model = (int)ErrorModelType::Unknown; // No Error Model act->param_n = 0; // No. Model parameters for (int i = 0; i < MAXERRPARAMS; i++) { act->params[i] = 0.0; @@ -1592,7 +1592,7 @@ void init_composite(Composite* act) { void init_error_model(ErrorModel* act) { - act->model = ERROR_MODEL_UNKNOWN; // No Error Model + act->model = (int)ErrorModelType::Unknown; // No Error Model act->param_n = 0; // No. Model parameters for (int i = 0; i < MAXERRPARAMS; i++) { act->params[i] = 0.0; diff --git a/source/clientserver/udaDefines.h b/source/clientserver/udaDefines.h index beccf584..3df51081 100644 --- a/source/clientserver/udaDefines.h +++ b/source/clientserver/udaDefines.h @@ -108,15 +108,22 @@ //-------------------------------------------------------- // Error Models -#define ERROR_MODEL_SEED 12345 -#define ERROR_MODEL_UNKNOWN 0 -#define ERROR_MODEL_DEFAULT 1 -#define ERROR_MODEL_DEFAULT_ASYMMETRIC 2 -#define ERROR_MODEL_GAUSSIAN 3 -#define ERROR_MODEL_RESEED 4 -#define ERROR_MODEL_GAUSSIAN_SHIFT 5 -#define ERROR_MODEL_POISSON 6 -#define ERROR_MODEL_UNDEFINED 7 +namespace uda::client_server { + +constexpr unsigned long int ErrorModelSeed = 12345; + +enum class ErrorModelType : int { + Unknown = 0, + Default = 1, + DefaultAsymmetric = 2, + Gaussian = 3, + Reseed = 4, + GaussianShift = 5, + Poisson = 6, + Undefined = 7, +}; + +} //-------------------------------------------------------- // Caching