2 // 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)
4 #include "bbstdFindOptimalParam.h"
5 #include "bbstdPackage.h"
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,FindOptimalParam)
10 BBTK_BLACK_BOX_IMPLEMENTATION(FindOptimalParam,bbtk::AtomicBlackBox);
13 std::string FindOptimalParam::Replace(std::string strCommand, double value)
15 std::string toReplace = std::to_string( value );
16 int pos = strCommand.find("XXvalueXX");
19 strCommand.replace(pos,9,toReplace);
24 int FindOptimalParam::Evaluate( double value )
27 std::string strCommand = Replace( bbGetInputString(), value );
28 system( strCommand.c_str() );
29 FILE *ff = fopen( bbGetInputTransferFile().c_str() , "r");
32 fscanf(ff,"%d",&result);
40 // 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)
42 void FindOptimalParam::Process()
45 // THE MAIN PROCESSING METHOD BODY
46 // Here we simply set the input 'In' value to the output 'Out'
47 // And print out the output value
48 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
49 // void bbSet{Input|Output}NAME(const TYPE&)
50 // const TYPE& bbGet{Input|Output}NAME() const
52 // * NAME is the name of the input/output
53 // (the one provided in the attribute 'name' of the tag 'input')
54 // * TYPE is the C++ type of the input/output
55 // (the one provided in the attribute 'type' of the tag 'input')
56 // bbSetOutputOut( bbGetInputIn() );
57 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
59 double start = bbGetInputInitStart();
60 double end = bbGetInputInitEnd();
69 actual = (start+end)/2;
70 evalActual = Evaluate(actual);
74 } else if (evalActual==0) {
76 } else if (evalActual==-9999) {
77 printf("EED Warnning! FindOptimalParam::Process Transfer file Evaluation not coherent ..... \n");
80 printf("EED Warnning! FindOptimalParam::Process Evaluation not coherent ..... \n");
85 printf("EED Warnning! FindOptimalParam::Process Out limit iteration ..... \n");
88 printf("EED FindOptimalParam::Process %f \n",actual);
89 } while ( bbGetInputMinDifference() < (end-start) );
90 bbSetOutputResult(start);
93 // 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)
95 void FindOptimalParam::bbUserSetDefaultValues()
98 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
99 // Here we initialize the input 'In' to 0
100 bbSetInputInitStart(0);
101 bbSetInputInitEnd(100);
102 bbSetInputString("");
103 bbSetInputMinDifference(1);
107 // 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)
109 void FindOptimalParam::bbUserInitializeProcessing()
112 // THE INITIALIZATION METHOD BODY :
114 // but this is where you should allocate the internal/output pointers
120 // 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)
122 void FindOptimalParam::bbUserFinalizeProcessing()
125 // THE FINALIZATION METHOD BODY :
127 // but this is where you should desallocate the internal/output pointers
132 // EO namespace bbstd