Пример #1
0
void Clustering<N, ObjectT, DistanceP>::printGnuplot( int const i )
{
/* output example
# centroids
# x y (fixed style)
0. 0.5 -1
1. 0.5 -1

# points
# x y cluster
0. 0. 0
1. 0. 0
0. 1. 0

0.5 0. 1
0.5 1. 1
*/

    std::stringstream datFileName;
    datFileName << "cluster" << std::setfill('0')
                << std::setw( std::floor(std::log10(M_maxIt) ) )
                << i << ".dat";
    std::ofstream datFile( datFileName.str().c_str() );

    datFile << "# centroids\n# x y (fixed style)\n";
    for( size_t d = 0; d < N; d++ )
    {
        datFile << M_centroids[d][0] << " "
                << M_centroids[d][1] << " -1\n";
    }
    datFile << "\n" << std::endl;

    datFile << "# points\n# x y cluster\n";
    for( size_t d = 0; d < N; d++ )
    {
        for( size_t kObj = 0; kObj < M_objectList[d].size(); kObj++ )
        {
            datFile << M_objectList[d][kObj][0] << " "
                    << M_objectList[d][kObj][1] << " " << d << "\n";
        }
        datFile << "\n" << std::endl;
    }
    datFile.close();

    std::stringstream pngFileName;
    pngFileName << "cluster" << std::setfill('0')
                << std::setw( std::floor(std::log10(M_maxIt) ) )<< i << ".png";

    std::ofstream gpFile( "cluster.gnuplot" );
    gpFile << "set terminal png size 800,640\n"
           << "set output \'" << pngFileName.str() << "\'\n"
           << "set xrange [-0.1:1.1]\n"
           << "set yrange [-0.1:1.1]\n"
           << "set pointsize 2.5\n"
           << "plot \'" << datFileName.str() << "\' w p palette title \'\',\\\n"
           << "\'<(head -n " << N + 2 << " " << datFileName.str()
           << ")\'w p pt 7 title \'\'" << std::endl;

    system( "gnuplot cluster.gnuplot" );
}
Пример #2
0
    /**
     * Full format is defined in doc text
     * @param filename A full path to the input DAT file
     */
    void LoadDetectorInfo::loadFromDAT(const std::string & filename)
    {
      std::ifstream datFile(filename.c_str());
      if(!datFile)
      {
        throw Exception::FileError("Unable to access dat file", filename);
      }

      std::string line;
      // skip 3 lines of header info
      for(int i = 0; i < 3; ++i) getline(datFile, line);

      // start loop over file
      auto & pmap = m_workspace->instrumentParameters();
      while(getline(datFile, line))
      {
        if(line.empty() || line[0] == '#') continue;

        std::istringstream is(line);
        detid_t detID(0);
        int code(0);
        float droppedFloat(0.0f);
        float delta(0.0f), l2(0.0f), theta(0.0f), phi(0.0f);
        is >> detID >> delta >> l2 >> code >> theta >> phi;
        // offset value is be subtracted so store negative
        delta *= -1.0f;

        IDetector_const_sptr det;
        try
        {
          det = m_baseInstrument->getDetector(detID);
        }
        catch(Exception::NotFoundError&)
        {
          continue;
        }
        if(det->isMonitor() || code == 1) continue;

        // drop 10 float columns
        for(int i = 0; i < 10; ++i) is >> droppedFloat;

        // pressure, wall thickness
        float pressure(0.0), thickness(0.0);
        is >> pressure >> thickness;

        updateParameterMap(pmap, det, l2, theta, phi, delta, pressure, thickness);
      }
    }