From 34a18f2a8866d6e51a3e2df74a302897e7c1da74 Mon Sep 17 00:00:00 2001 From: jupfi Date: Thu, 8 Feb 2024 15:23:16 +0100 Subject: [PATCH 1/2] Added run experiment function --- src/limedriver.cpp | 108 +++++++++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 43 deletions(-) diff --git a/src/limedriver.cpp b/src/limedriver.cpp index dd75bc0..854c11c 100644 --- a/src/limedriver.cpp +++ b/src/limedriver.cpp @@ -648,60 +648,33 @@ double Modfunction(double argument, int mode) { return retval; } -int main(int argc, char **argv) { +int run_experiment(LimeConfig_t LimeCfg, std::vector &HDFattrVector) { + /* Run the experiment + + @param LimeCfg: LimeConfig_t struct + @param Config2HDFattr_t: HDFattr_t struct + @param device: lms_device_t struct + + @return int: 0 if successful, -1 if not + + */ + std::ostringstream stringstream; const double pi = acos(-1); - std::ostringstream stringstream; + size_t no_of_attr = HDFattrVector.size(); - int Npulses = 2; // default number of pulses - // check if nPulses has been given as argument, so that all the arrays are - // initialized with proper size - for (int ii_arg = 1; ii_arg < argc; ii_arg++) { - if (strcmp(argv[ii_arg], "-npu") == 0 && ii_arg + 1 < argc) { - Npulses = atoi(argv[ii_arg + 1]); - break; - } - } + // Converting to array to maintain compatibility with older code + Config2HDFattr_t HDFattr[no_of_attr]; + std::copy(HDFattrVector.begin(), HDFattrVector.end(), HDFattr); - // Initialize the LimeConfig_t struct - LimeConfig_t LimeCfg = initializeLimeConfig(Npulses, stringstream); - // Getting HDF Attributes from dedicated function - std::vector HDFattrVector = getHDFAttributes(LimeCfg); - size_t no_of_attr = HDFattrVector.size(); - - bool dumpFlag = false; - - // Checking for dump flag - for (int i = 1; i < argc; ++i) { - if (strcmp(argv[i], "--dump") == 0) { - dumpFlag = true; - } - } - - // If dump flag is set, dump the config and exit - if (dumpFlag) { - dumpConfig(HDFattrVector); - std::exit(0); - } - - - // Parse command line arguments - if (parseArguments(argc, argv, LimeCfg, HDFattrVector) != 0) { - return 1; - } - - // check directory first + // check directory first if (makePath(LimeCfg.save_path) == 0) { cout << "Problem entering the specified path: " << LimeCfg.save_path << endl; return 1; } - // Converting to array to maintain compatibility with older code - Config2HDFattr_t HDFattr[no_of_attr]; - std::copy(HDFattrVector.begin(), HDFattrVector.end(), HDFattr); - // Find devices int n; lms_info_str_t list[8]; // should be large enough to hold all detected devices @@ -1919,4 +1892,53 @@ DC_Q << endl; LMS_Close(device); return 0; + +} + +int main(int argc, char **argv) { + const double pi = acos(-1); + + std::ostringstream stringstream; + + int Npulses = 2; // default number of pulses + // check if nPulses has been given as argument, so that all the arrays are + // initialized with proper size + for (int ii_arg = 1; ii_arg < argc; ii_arg++) { + if (strcmp(argv[ii_arg], "-npu") == 0 && ii_arg + 1 < argc) { + Npulses = atoi(argv[ii_arg + 1]); + break; + } + } + + // Initialize the LimeConfig_t struct + LimeConfig_t LimeCfg = initializeLimeConfig(Npulses, stringstream); + + // Getting HDF Attributes from dedicated function + std::vector HDFattrVector = getHDFAttributes(LimeCfg); + size_t no_of_attr = HDFattrVector.size(); + + bool dumpFlag = false; + + // Checking for dump flag + for (int i = 1; i < argc; ++i) { + if (strcmp(argv[i], "--dump") == 0) { + dumpFlag = true; + } + } + + // If dump flag is set, dump the config and exit + if (dumpFlag) { + dumpConfig(HDFattrVector); + std::exit(0); + } + + + // Parse command line arguments + if (parseArguments(argc, argv, LimeCfg, HDFattrVector) != 0) { + return 1; + } + + run_experiment(LimeCfg, HDFattrVector); + + } From 3d1c7bdf2ce95fb69f5a89b195a0f6e18496f97f Mon Sep 17 00:00:00 2001 From: jupfi Date: Thu, 8 Feb 2024 16:22:00 +0100 Subject: [PATCH 2/2] Updates ... very important ... --- src/limedriver.cpp | 20 ++++++++++++++------ src/limedriver.h | 2 ++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/limedriver.cpp b/src/limedriver.cpp index 854c11c..97ffbf5 100644 --- a/src/limedriver.cpp +++ b/src/limedriver.cpp @@ -325,16 +325,16 @@ void dumpConfig(std::vector &config) { std::cout << "}" << std::endl; } -LimeConfig_t initializeLimeConfig(int Npulses, - std::ostringstream &stringstream) { +LimeConfig_t initializeLimeConfig(int Npulses) { /* Initialize the LimeConfig_t struct @param Npulses: Number of pulses - @param stringstream: std::ostringstream object @return LimeConfig_t: LimeConfig_t struct with default values */ + std::ostringstream stringstream; + LimeConfig_t LimeCfg{}; LimeCfg.Npulses = Npulses; @@ -1895,11 +1895,19 @@ DC_Q << endl; } +int run_experiment_from_LimeCfg(LimeConfig_t LimeCfg){ + + int Npulses = LimeCfg.Npulses; // Number of pulses from the LimeCfg + + // Getting HDF Attributes from dedicated function + std::vector HDFattrVector = getHDFAttributes(LimeCfg); + + run_experiment(LimeCfg, HDFattrVector); +} + int main(int argc, char **argv) { const double pi = acos(-1); - std::ostringstream stringstream; - int Npulses = 2; // default number of pulses // check if nPulses has been given as argument, so that all the arrays are // initialized with proper size @@ -1911,7 +1919,7 @@ int main(int argc, char **argv) { } // Initialize the LimeConfig_t struct - LimeConfig_t LimeCfg = initializeLimeConfig(Npulses, stringstream); + LimeConfig_t LimeCfg = initializeLimeConfig(Npulses); // Getting HDF Attributes from dedicated function std::vector HDFattrVector = getHDFAttributes(LimeCfg); diff --git a/src/limedriver.h b/src/limedriver.h index d2293ab..0176678 100644 --- a/src/limedriver.h +++ b/src/limedriver.h @@ -112,4 +112,6 @@ struct Config2HDFattr_t { // Device structure, should be initialize to NULL static lms_device_t *device = NULL; +LimeConfig_t initializeLimeConfig(int Npulses); + #endif // LIMECONFIG_H \ No newline at end of file