void ViewWithGNUplot::run(const std::string& Data, const std::string& DateFormat, const std::string& ColSeparator, const std::string& CommentChar, bool SingleWindow) { if (DateFormat.find(ColSeparator) != std::string::npos) { openfluid::guicommon::DialogBoxFactory::showSimpleWarningMessage(_("Unable to plot file with GNUplot:\nColumn separator is present in date format.")); return; } boost::filesystem::create_directories(boost::filesystem::path(openfluid::base::RuntimeEnvironment::getInstance()->getTempDir())); std::string DataFilename = boost::filesystem::path(openfluid::base::RuntimeEnvironment::getInstance()->getTempDir()+"/gprun.data").string(); std::string ScriptFilename = boost::filesystem::path(openfluid::base::RuntimeEnvironment::getInstance()->getTempDir()+"/gprun.gp").string(); std::ofstream DataFile(DataFilename.c_str()); DataFile << Data; DataFile.close(); std::map<std::string,unsigned int> VarColumns = getPlottableColumns(Data,ColSeparator,CommentChar); if (VarColumns.size() <1 ) { openfluid::guicommon::DialogBoxFactory::showSimpleErrorMessage(_("No data found for plotting")); return; } std::map<std::string,unsigned int>::iterator bVC = VarColumns.begin(); std::map<std::string,unsigned int>::iterator eVC = VarColumns.end(); std::map<std::string,unsigned int>::iterator iVC; if (SingleWindow) { // determine columns and rows unsigned int Columns = 1; unsigned int Rows = 1; if (VarColumns.size() > 1) { Columns = (unsigned int)(std::ceil(std::sqrt(VarColumns.size()))); Rows = (unsigned int)(std::ceil(double(VarColumns.size()) / double(Columns))); } // generate script std::ofstream ScriptFile(ScriptFilename.c_str()); ScriptFile << "set nokey\n"; ScriptFile << "set xdata time\n"; ScriptFile << "set timefmt \"" << DateFormat << "\"\n"; ScriptFile << "set datafile separator \"" << ColSeparator << "\n"; ScriptFile << "set datafile commentschars \"" << CommentChar << "\n"; ScriptFile << "set format x \"%Y-%m-%d\\n%H:%M:%S\"\n"; ScriptFile << "set xtics autofreq font \",7\"\n"; ScriptFile << "set ytics autofreq font \",7\"\n"; ScriptFile << "set origin 0,0\n"; ScriptFile << "set multiplot layout " << Rows << "," << Columns << " rowsfirst scale 1,1\n"; for (iVC=bVC; iVC!=eVC;++iVC) { ScriptFile << "set title \"" << (*iVC).first << "\" font \",9\"\n"; ScriptFile << "plot \""<< DataFilename << "\" using 1:"<< ((*iVC).second+2) <<" with lines\n"; } ScriptFile << "unset multiplot\n"; ScriptFile.close(); if(system(std::string(m_GNUplotProgram + " --persist " + ScriptFilename).c_str()) != 0) openfluid::guicommon::DialogBoxFactory::showSimpleErrorMessage(_("GNUplot error")); } else { for (iVC=bVC; iVC!=eVC;++iVC) { // generate script std::ofstream ScriptFile(ScriptFilename.c_str()); ScriptFile << "set nokey\n"; ScriptFile << "set xdata time\n"; ScriptFile << "set timefmt \"" << DateFormat << "\"\n"; ScriptFile << "set datafile separator \"" << ColSeparator << "\n"; ScriptFile << "set datafile commentschars \"" << CommentChar << "\n"; ScriptFile << "set format x \"%Y-%m-%d\\n%H:%M:%S\"\n"; ScriptFile << "set xtics autofreq font \",7\"\n"; ScriptFile << "set ytics autofreq font \",7\"\n"; ScriptFile << "set title \"" << (*iVC).first << "\" font \",9\"\n"; ScriptFile << "plot \""<< DataFilename << "\" using 1:"<< ((*iVC).second+2) <<" with lines\n"; ScriptFile.close(); if(system(std::string(m_GNUplotProgram + " --persist " + ScriptFilename).c_str()) != 0) openfluid::guicommon::DialogBoxFactory::showSimpleErrorMessage(_("GNUplot error")); } } }
void buildGnuplotImages(const std::string& WorkDir, const std::string& DestDir) { for (std::list<KmlSerieInfo>::iterator it=m_KmlSeriesInfos.begin();it!=m_KmlSeriesInfos.end();++it) { for (std::map<openfluid::core::UnitID_t,KmlUnitInfoExtra>::iterator it2=(*it).UnitsInfos.begin(); it2!=(*it).UnitsInfos.end(); ++it2) { if ((*it2).second.IsPlotted) { std::string ScriptFilename = WorkDir+"/tmpscript.gp"; std::string DataFilename = buildFilePath(WorkDir,(*it).UnitsClass, (*it2).second.UnitID,"","dat"); std::string OutputFilename = buildFilePath(DestDir,(*it).UnitsClass, (*it2).second.UnitID,"","png"); unsigned int Columns = 1; unsigned int Rows = 1; if ((*it).VarsList.size() > 1) { Columns = (unsigned int)(std::ceil(std::sqrt((*it).VarsList.size()))); Rows = (unsigned int)(std::ceil((*it).VarsList.size() / Columns)); } std::ofstream ScriptFile(ScriptFilename.c_str()); ScriptFile << "set terminal png size 640,480 small\n"; ScriptFile << "set output \"" << OutputFilename << "\"\n"; ScriptFile << "set nokey\n"; ScriptFile << "set xdata time\n"; ScriptFile << "set timefmt \"%Y%m%d-%H%M%S\"\n"; ScriptFile << "set datafile separator \";\"\n"; ScriptFile << "set datafile commentschars \"#\"\n"; ScriptFile << "set format x \"%Y-%m-%d\\n%H:%M:%S\"\n"; ScriptFile << "set xtics " << m_PlotXTics << " font \",7\"\n"; ScriptFile << "set ytics autofreq font \",7\"\n"; ScriptFile << "set origin 0,0\n"; ScriptFile << "set multiplot layout " << Rows << "," << Columns << " rowsfirst scale 1,1\n"; for (unsigned int i=0; i< (*it).VarsList.size();i++) { ScriptFile << "set title \"" << (*it).VarsList[i] << "\" font \",9\"\n"; ScriptFile << "plot \""<< DataFilename << "\" using 1:"<< (i+2) <<" with lines\n"; } ScriptFile << "unset multiplot\n"; // ScriptFile << "set title \"" << (*it).VarName << "\" font \",9\"\n"; // ScriptFile << "plot \""<< DataFilename << "\" using 1:2 with lines\n"; ScriptFile.close(); // execution of the script if (m_PlotProgram.isFound()) { QString GNUPlotCommand = QString("\"%1\" \"%2\"").arg(m_PlotProgram.getFullProgramPath()) .arg(QString::fromStdString(ScriptFilename)); QProcess::execute(GNUPlotCommand); } } } } }
void onFinalizedRun() { CloseFiles(); std::ofstream ScriptFile(std::string(m_OutputDir+"/script.gnuplot").c_str()); if (!m_Terminal.empty()) { ScriptFile << "set terminal " << m_Terminal << "\n"; if (!m_Output.empty()) ScriptFile << "set output \"" << m_OutputDir << "/" << m_Output << "\"\n"; } ScriptFile << "set xtics rotate font \",5\"\n"; ScriptFile << "set ytics font \",7\"\n"; ScriptFile << "set xdata time\n"; ScriptFile << "set timefmt \"%Y-%m-%dT%H:%M:%S\"\n"; ScriptFile << "set datafile separator \" \"\n"; ScriptFile << "set datafile commentschars \"#\"\n"; ScriptFile << "set format x \"%Y-%m-%d\\n%H:%M:%S\"\n"; ScriptFile << "set datafile missing \"NaN\"\n"; ScriptFile << "set xlabel \"Time\"\n"; unsigned int Columns = 1; unsigned int Rows = 1; if (m_Graphs.size() > 1) { Columns = (unsigned int)(std::ceil(std::sqrt(m_Graphs.size()))); Rows = (unsigned int)(std::ceil(m_Graphs.size() / Columns)); if (Columns*Rows < m_Graphs.size()) Rows++; } ScriptFile << "set multiplot layout " << Rows << "," << Columns << " rowsfirst scale 1,1\n"; std::map<std::string,GraphInfo>::iterator Git; std::map<std::string,GraphInfo>::iterator Gitb = m_Graphs.begin(); std::map<std::string,GraphInfo>::iterator Gite = m_Graphs.end(); for (Git = Gitb; Git != Gite; ++Git) { ScriptFile << "set title \"" << (*Git).second.Title << "\" font \",10\"\n"; ScriptFile << "set key " << (*Git).second.Key << "\n"; if ((*Git).second.YLabel.empty()) ScriptFile << "unset ylabel\n"; else ScriptFile << "set ylabel \"" << (*Git).second.YLabel << "\"\n"; ScriptFile << "plot "; std::list<SerieInfo*>::iterator Sit; std::list<SerieInfo*>::iterator Sitb = (*Git).second.Series.begin(); std::list<SerieInfo*>::iterator Site = (*Git).second.Series.end(); for (Sit = Sitb; Sit != Site; ++Sit) { std::string SourceDir = m_OutputDir; if ((*Sit)->Type == SerieInfo::SERIE_FILE) SourceDir = m_InputDir; std::string Label = (*Sit)->Label; if (Label.empty()) { if ((*Sit)->Type == SerieInfo::SERIE_FILE) Label = (*Sit)->SourceFile; else { std::string UnitIDStr; openfluid::tools::convertValue((*Sit)->UnitID,&UnitIDStr); Label= (*Sit)->VarName + " (" + (*Sit)->UnitsClass + "#" + UnitIDStr + ")"; } } if (Sit != Sitb) ScriptFile << ", "; ScriptFile << "\"" << SourceDir << "/" << (*Sit)->SourceFile << "\" using 1:2 with " << (*Sit)->Style << " title \"" << Label << "\""; } ScriptFile << "\n"; } ScriptFile << "unset multiplot\n"; ScriptFile.close(); tryOpenGNUplot(); }
void CJobListView::OnSubmitbutton() { ASSERT_VALID(m_pDoc); ASSERT(NULL != m_pDoc->m_pJobList); CGeneralPage GeneralPage; CAdvancedPage AdvancedPage; CPropertySheet PropertySheet("Submit job"); PropertySheet.AddPage(&GeneralPage); PropertySheet.AddPage(&AdvancedPage); if (IDOK != PropertySheet.DoModal()) return; CJob jadd; jadd.directive_prefix = GeneralPage.m_JobPrefix; jadd.job_name = GeneralPage.m_JobName; jadd.script_file = GeneralPage.m_JobScriptFileName; ifstream ScriptFile(jadd.script_file, ios::nocreate); if (!ScriptFile.is_open()) { AfxMessageBox("Invalid script file !"); return; } jadd.script_ptr.Empty(); static char LineBuf[256]; while (!ScriptFile.eof()) { ScriptFile.getline(LineBuf, sizeof LineBuf, '\n'); jadd.script_ptr += LineBuf; jadd.script_ptr += '\n'; } ScriptFile.close(); jadd.script_size = jadd.script_ptr.GetLength(); int i; CString Str = GeneralPage.m_JobArgs; if (!Str.IsEmpty()) { for (; -1 != (i = Str.Find(",")); Str.Delete(0, i + 1)) jadd.job_args.push_back(Str.Left(i)); jadd.job_args.push_back(Str); } jadd.priority = GeneralPage.m_JobPriority; jadd.submission_time = GeneralPage.m_JobStartTime; Str = GeneralPage.m_JobShell; CString SubStr, Host, Path; int j; if (!Str.IsEmpty()) { for (; -1 != (i = Str.Find(",")); Str.Delete(0, i + 1)) { SubStr = Str.Left(i); j = SubStr.Find(":"); Host = SubStr.Left(j); Path = SubStr.Mid(j + 1); jadd.shell_list.push_back(CPathName(Path, Host)); } j = Str.Find(":"); Host = Str.Left(j); Path = Str.Mid(j + 1); jadd.shell_list.push_back(CPathName(Path, Host)); } jadd.merge_stderr = GeneralPage.m_JobMergeOutput; Str = GeneralPage.m_JobStdout; if (!Str.IsEmpty()) { for (; -1 != (i = Str.Find(",")); Str.Delete(0, i + 1)) { SubStr = Str.Left(i); j = SubStr.Find(":"); Host = SubStr.Left(j); Path = SubStr.Mid(j + 1); jadd.stdout_path_list.push_back(CPathName(Path, Host)); } j = Str.Find(":"); Host = Str.Left(j); Path = Str.Mid(j + 1); jadd.stdout_path_list.push_back(CPathName(Path, Host)); } Str = GeneralPage.m_JobStderr; if (!Str.IsEmpty()) { for (; -1 != (i = Str.Find(",")); Str.Delete(0, i + 1)) { SubStr = Str.Left(i); j = SubStr.Find(":"); Host = SubStr.Left(j); Path = SubStr.Mid(j + 1); jadd.stderr_path_list.push_back(CPathName(Path, Host)); } j = Str.Find(":"); Host = Str.Left(j); Path = Str.Mid(j + 1); jadd.stderr_path_list.push_back(CPathName(Path, Host)); } /* jadd.hard_resource_list = CJobResourceList(); jadd.soft_resource_list = CJobResourceList();*/ m_pDoc->SubmitJob(jadd); }