--- /dev/null
+//=====
+// 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 = " <<bbGetOutputOut() << std::endl;
+
+ double start = bbGetInputInitStart();
+ double end = bbGetInputInitEnd();
+ double actual;
+ int iter=0;
+ int evalStart = 1;
+ int evalEnd = 0;
+ int evalActual;
+ do
+ {
+ iter++;
+ actual = (start+end)/2;
+ evalActual = Evaluate(actual);
+ if (evalActual==1)
+ {
+ start= actual;
+ } else if (evalActual==0) {
+ end = actual;
+ } else if (evalActual==-9999) {
+ printf("EED Warnning! FindOptimalParam::Process Transfer file Evaluation not coherent ..... \n");
+ break;
+ } else {
+ printf("EED Warnning! FindOptimalParam::Process Evaluation not coherent ..... \n");
+ break;
+ }
+ if (iter==10000)
+ {
+ printf("EED Warnning! FindOptimalParam::Process Out limit iteration ..... \n");
+ break;
+ }
+ printf("EED FindOptimalParam::Process %f \n",actual);
+ } while ( bbGetInputMinDifference() < (end-start) );
+ bbSetOutputResult(start);
+}
+//=====
+// 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::bbUserSetDefaultValues()
+{
+
+// SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
+// Here we initialize the input 'In' to 0
+ bbSetInputInitStart(0);
+ bbSetInputInitEnd(100);
+ bbSetInputString("");
+ bbSetInputMinDifference(1);
+
+}
+//=====
+// 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::bbUserInitializeProcessing()
+{
+
+// THE INITIALIZATION METHOD BODY :
+// Here does nothing
+// but this is where you should allocate the internal/output pointers
+// if any
+
+
+}
+//=====
+// 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::bbUserFinalizeProcessing()
+{
+
+// THE FINALIZATION METHOD BODY :
+// Here does nothing
+// but this is where you should desallocate the internal/output pointers
+// if any
+
+}
+}
+// EO namespace bbstd
+
+
--- /dev/null
+//=====
+// 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)
+//=====
+#ifndef __bbstdFindOptimalParam_h_INCLUDED__
+#define __bbstdFindOptimalParam_h_INCLUDED__
+
+#include "bbstd_EXPORT.h"
+#include "bbtkAtomicBlackBox.h"
+#include "iostream"
+
+namespace bbstd
+{
+
+class bbstd_EXPORT FindOptimalParam
+ :
+ public bbtk::AtomicBlackBox
+{
+ BBTK_BLACK_BOX_INTERFACE(FindOptimalParam,bbtk::AtomicBlackBox);
+//=====
+// 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)
+//=====
+ BBTK_DECLARE_INPUT(InitStart,double);
+ BBTK_DECLARE_INPUT(InitEnd,double);
+ BBTK_DECLARE_INPUT(MinDifference,double);
+ BBTK_DECLARE_INPUT(String,std::string);
+ BBTK_DECLARE_INPUT(TransferFile,std::string);
+ BBTK_DECLARE_OUTPUT(Result,double);
+ BBTK_PROCESS(Process);
+ void Process();
+
+ std::string Replace(std::string command, double value);
+ int Evaluate( double value );
+
+
+//=====
+// 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)
+//=====
+};
+
+BBTK_BEGIN_DESCRIBE_BLACK_BOX(FindOptimalParam,bbtk::AtomicBlackBox);
+ BBTK_NAME("FindOptimalParam");
+ BBTK_AUTHOR("InfoDev");
+ BBTK_DESCRIPTION("No Description.");
+ BBTK_CATEGORY("empty");
+
+ BBTK_INPUT(FindOptimalParam,InitStart,"Initial Start",double,"");
+ BBTK_INPUT(FindOptimalParam,InitEnd,"(defalut 100) Initial End ",double,"");
+ BBTK_INPUT(FindOptimalParam,MinDifference,"(default 1) Minimum (End-Start) to stop iteration ",double,"");
+ BBTK_INPUT(FindOptimalParam,String,"String script evaluation (use 'XXvalueXX' to be optimice)",std::string,"");
+ BBTK_INPUT(FindOptimalParam,TransferFile,"File to check the difference",std::string,"");
+
+ BBTK_OUTPUT(FindOptimalParam,Result,"Find optimal parameter",double,"");
+
+
+BBTK_END_DESCRIBE_BLACK_BOX(FindOptimalParam);
+//=====
+// 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)
+//=====
+}
+// EO namespace bbstd
+
+#endif // __bbstdFindOptimalParam_h_INCLUDED__
+