Ich benutze gcc als Compiler und gnuplot-iostream.h als Stream, um C++ - Code und die Gnuplot-Funktionen zu kombinieren.Wie wird der C++ - Code nach dem Aufruf von gnuplot weiter ausgeführt?
Was ich tue:
ich versuche, eine Anpassung der Daten über gnuplot zu machen und die endgültigen Fitparameter aus der erzeugten fit.log Datei zur weiteren Verarbeitung extrahieren.
Was ist das Problem:
, wenn Sie den Code wie dieser
std::cout << "Starting to fit" << std::endl;
if (bStartFit == true)
{
// gp << doing stuf here;
std::cout << "Test end" << std::endl;
}
std::cout << "Fit is done" << std::endl;
Ausführung
der Ausgang sein:
Starting to fit
Fit is done
Test end
//gnuplot stuff
Meine Frage ist: wie Sie den Code erzwingen ausführen genau gnuplot Zeug bei Bedarf und nach dem C++ - Code fortfahren. Zum Beispiel:
- Intro-Nachricht schreiben;
- die sin (x) -Funktion zeichnen (als schnelles Beispiel);
- warten bis der gnuplot geschlossen ist;
- Schreiben Sie die Nachricht oder machen Sie was immer NACH dem gnuplot getan wird.
danke, P
EDIT:
std::string filename = "fit.log";
if (bStartFit == true)
{
// Using Gnuplot for the data fit (command are parsed as the strings):
// 1. define the fit function.
gp << "f(x) = imfpZP * x**(-b) + c * x**(d) + g * x**(h) \n";
// 2. fit parameters first assumption.
gp << "b = 1.1; c = 0.5; d = 1.0; g = 2.0; h = 0.1 \n";
// 3. fit range.
gp << "fit [50:10000] f(x) 'agn.iimfp' via b,c,d,g,h \n";
// 4. set the logarithmic scale.
gp << "set logscale \n";
// 5. plot the fitted data.
gp << "plot 'agn.iimfp' w l lw 2 tit 'orig', f(x) w l lw 2 tit 'fit' \n";
std::cout << "Fit was successful" << std::endl;
}
// Opening the generated fit.log file to store the fit parameters:
std::ifstream inFIT(filename.c_str());
if (inFIT.is_open())
{
std::cout << "FIT log is opened" << std::endl;
std::string line;
int lineCounter = 0;
while (std::getline(inFIT, line))
{
lineCounter++;
}
std::cout << "Total lines: " << lineCounter << std::endl;
// Getting the five lines with fit parameters from the fit.log:
std::fstream& GoToLine(std::fstream& file, unsigned int lineNumber);
std::fstream file(filename.c_str());
GoToLine(file, lineCounter - 15);
std::string b_Line;
std::getline(file, b_Line);
std::cout << b_Line << std::endl;
std::istringstream sb(b_Line);
std::string tempStr;
char tempChar;
sb >> tempStr >> tempChar >> b
// similar code to get another 4 lines
;
Was meinst du _ "gnuplot stuff" _ ?? Wie nennst du gnuplot? –
Ich bin mir nicht sicher, ob die Verwendung von * gnuplot iostream * Ihren Anforderungen entspricht. –
von "gnuplot stuff" Ich meine die Gnuplot-Header, wenn ich "fit" -Befehl verwende, werde ich auch hier eine passende Iterationen bekommen, und die Handlung selbst wird das letzte sein, was produziert wird. –