dumpPlotData.cpp

00001 /*
00002   gnuplot で閲覧するためのデータを出力する
00003   Satofumi KAMIMURA
00004   $Id$
00005 */
00006 
00007 #include "dumpPlotData.h"
00008 #include <fstream>
00009 
00010 static int FilesIndex = 0;
00011 
00012 
00013 // キャプチャしたデータファイルを出力
00014 void outputPlotData(URGCtrl& urg, const char* file) {
00015   int len = strlen(file);
00016   char* str = strrchr(file, '/') +1;
00017   char* data_file = new char[len + 13];
00018   sprintf(data_file, "dat_%s_%03d.dat", str, FilesIndex++);
00019   std::ofstream fout(data_file);
00020   delete [] data_file;
00021 
00022   // urg のデータを x, y 毎の行データとして出力
00023   for (std::vector<VXV::Grid3D>::iterator it = urg.crd_points.begin();
00024        it != urg.crd_points.end(); ++it) {
00025     fout << it->x << '\t' << it->y << std::endl;
00026   }
00027   fout.close();
00028 }
00029 
00030 
00031 // 全データを gnuplot で表示するためのファイルを出力
00032 void outputPlotFile(const char* file) {
00033   int len = strlen(file);
00034   char* str = strrchr(file, '/') +1;
00035   char* data_file = new char[len + 13];
00036   char* ps_file = new char[len + 13];
00037   sprintf(data_file, "dat_%s.gnu", str);
00038   sprintf(ps_file, "dat_%s.ps", str);
00039   std::ofstream fout(data_file);
00040 
00041   fout << "#set terminal postscript color" << std::endl;
00042   fout << "#set output \"" << ps_file << "\"" << std::endl;
00043 
00044   fout << "set xlabel '[mm]'" << std::endl;
00045   fout << "set ylabel '[mm]'" << std::endl;
00046 
00047   fout << "plot ";
00048   for (int i = 0; i < FilesIndex; ++i) {
00049     sprintf(data_file, "dat_%s_%03d.dat", str, i);
00050     fout << '\'' << data_file << '\'';
00051     if (i < FilesIndex-1) {
00052       fout << ", ";
00053     }
00054   }
00055   fout << std::endl;
00056   fout << "pause -1" << std::endl;
00057   delete [] data_file;
00058   fout.close();
00059 }
00060 

Generated on Mon Apr 13 22:52:02 2009 by  doxygen 1.5.7.1