From: Eduardo DAVILA Date: Mon, 15 Jul 2019 14:52:40 +0000 (+0200) Subject: #3278 BBTK Feature New Normal - FindOptimalParam Box X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=532a25e2cc24d2d17f68f22337db205a422406b3;p=bbtk.git #3278 BBTK Feature New Normal - FindOptimalParam Box --- diff --git a/packages/std/src/bbstdFindOptimalParam.cxx b/packages/std/src/bbstdFindOptimalParam.cxx new file mode 100644 index 0000000..2e863ce --- /dev/null +++ b/packages/std/src/bbstdFindOptimalParam.cxx @@ -0,0 +1,134 @@ +//===== +// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) +//===== +#include "bbstdFindOptimalParam.h" +#include "bbstdPackage.h" +namespace bbstd +{ + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,FindOptimalParam) +BBTK_BLACK_BOX_IMPLEMENTATION(FindOptimalParam,bbtk::AtomicBlackBox); + + +std::string FindOptimalParam::Replace(std::string strCommand, double value) +{ + std::string toReplace = std::to_string( value ); + int pos = strCommand.find("XXvalueXX"); + if (pos>=0) + { + strCommand.replace(pos,9,toReplace); + } // if pos + return strCommand; +} + +int FindOptimalParam::Evaluate( double value ) +{ + int result=-9999; + std::string strCommand = Replace( bbGetInputString(), value ); + system( strCommand.c_str() ); + FILE *ff = fopen( bbGetInputTransferFile().c_str() , "r"); + if (ff!=NULL) + { + fscanf(ff,"%d",&result); + } // ff + fclose(ff); + return result; +} + + +//===== +// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) +//===== +void FindOptimalParam::Process() +{ + +// THE MAIN PROCESSING METHOD BODY +// Here we simply set the input 'In' value to the output 'Out' +// And print out the output value +// INPUT/OUTPUT ACCESSORS ARE OF THE FORM : +// void bbSet{Input|Output}NAME(const TYPE&) +// const TYPE& bbGet{Input|Output}NAME() const +// Where : +// * NAME is the name of the input/output +// (the one provided in the attribute 'name' of the tag 'input') +// * TYPE is the C++ type of the input/output +// (the one provided in the attribute 'type' of the tag 'input') + // bbSetOutputOut( bbGetInputIn() ); + // std::cout << "Output value = " <