Я использую gcc как компилятор и gnuplot-iostream.h как поток для комбинирования кода на C++ и функций gnuplot.Как продолжить выполнение кода на C++ после вызова gnuplot?
Что я делаю:
Я пытаюсь сделать подгонку данных через Gnuplot и извлечь конечные параметры подходят из сгенерированного fit.log файла для дальнейшей обработки.
чем проблема:
При выполнении кода, как этот
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;
выход будет:
Starting to fit
Fit is done
Test end
//gnuplot stuff
Мой вопрос: как заставить код выполнять GNUPLOT вещи точно при необходимости, и после выполнения кода C++. Например:
- напишите вступительное сообщение;
- запишите функцию sin (x) (как пример);
- Подождите, пока gnuplot не будет закрыт;
- напишите сообщение или сделайте что-нибудь ПОСЛЕ завершения gnuplot.
спасибо, 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
;
Что значит _ "gnuplot stuff" _ ?? Как вы называете gnuplot? –
Я совсем не уверен, что использование * gnuplot iostream * соответствует вашим потребностям. –
от «gnuplot stuff» Я имею в виду заголовок gnuplot, если я использую команду «fit», я также получу подходящие итерации, и сам сюжет будет последним. –