inline
void
arma_ostream::print(std::ostream& o, const SpMat<eT>& m, const bool modify)
  {
  arma_extra_debug_sigprint();
  
  const arma_ostream_state stream_state(o);
  
  o.unsetf(ios::showbase);
  o.unsetf(ios::uppercase);
  o.unsetf(ios::showpos);
  o.unsetf(ios::scientific);
  o.setf(ios::right);
  o.setf(ios::fixed);
  o.precision(2);
  
  const uword m_n_nonzero = m.n_nonzero;
  
  o << "[matrix size: " << m.n_rows << 'x' << m.n_cols << "; n_nonzero: " << m_n_nonzero
    << "; density: " << ((m.n_elem > 0) ? (double(m_n_nonzero) / double(m.n_elem) * double(100)) : double(0))
    << "%]\n\n";
  
  if(modify == false) { stream_state.restore(o); }
  
  if(m_n_nonzero > 0)
    {
    const std::streamsize cell_width = modify ? modify_stream<eT>(o, m.begin(), m_n_nonzero) : o.width();
    
    typename SpMat<eT>::const_iterator begin = m.begin();
    
    while(begin != m.end())
      {
      const uword row = begin.row();
      
      // TODO: change the maximum number of spaces before and after each location to be dependent on n_rows and n_cols
      
           if(row < 10)      { o << "     "; }
      else if(row < 100)     { o << "    ";  }
      else if(row < 1000)    { o << "   ";   }
      else if(row < 10000)   { o << "  ";    }
      else if(row < 100000)  { o << ' ';     }
      
      const uword col = begin.col();
      
      o << '(' << row << ", " << col << ") ";
      
           if(col < 10)      { o << "     "; }
      else if(col < 100)     { o << "    ";  }
      else if(col < 1000)    { o << "   ";   }
      else if(col < 10000)   { o << "  ";    }
      else if(col < 100000)  { o << ' ';     }
      
      if(cell_width > 0) { o.width(cell_width); }
        
      arma_ostream::print_elem(o, eT(*begin), modify);
      o << '\n';
      
      ++begin;
      }
    
    o << '\n';
    }
  
  o.flush();
  stream_state.restore(o);
  }
inline
std::streamsize
arma_ostream::modify_stream(std::ostream& o, typename SpMat<eT>::const_iterator begin, const uword n_elem, const typename arma_not_cx<eT>::result* junk)
  {
  arma_extra_debug_sigprint();
  arma_ignore(junk);

  o.unsetf(ios::showbase);
  o.unsetf(ios::uppercase);
  o.unsetf(ios::showpos);

  o.fill(' ');

  std::streamsize cell_width;

  bool use_layout_B  = false;
  bool use_layout_C  = false;

  for(typename SpMat<eT>::const_iterator it = begin; it.pos() < n_elem; ++it)
    {
    const eT val = *it;

    if(
      val >= eT(+100) ||
      ( (is_signed<eT>::value == true) && (val <= eT(-100)) ) ||
      ( (is_non_integral<eT>::value == true) && (val > eT(0)) && (val <= eT(+1e-4)) ) ||
      ( (is_non_integral<eT>::value == true) && (is_signed<eT>::value == true) && (val < eT(0)) && (val >= eT(-1e-4)) )
      )
      {
      use_layout_C = true;
      break;
      }

    if(
      (val >= eT(+10)) || ( (is_signed<eT>::value == true) && (val <= eT(-10)) )
      )
      {
      use_layout_B = true;
      }
    }

  if(use_layout_C == true)
    {
    o.setf(ios::scientific);
    o.setf(ios::right);
    o.unsetf(ios::fixed);
    o.precision(4);
    cell_width = 13;
    }
  else
  if(use_layout_B == true)
    {
    o.unsetf(ios::scientific);
    o.setf(ios::right);
    o.setf(ios::fixed);
    o.precision(4);
    cell_width = 10;
    }
  else
    {
    o.unsetf(ios::scientific);
    o.setf(ios::right);
    o.setf(ios::fixed);
    o.precision(4);
    cell_width = 9;
    }
  
  return cell_width;
  }
inline
std::streamsize
arma_ostream::modify_stream(std::ostream& o, const eT* data, const uword n_elem)
  {
  o.unsetf(ios::showbase);
  o.unsetf(ios::uppercase);
  o.unsetf(ios::showpos);
  
  o.fill(' ');
  
  std::streamsize cell_width;
  
  bool use_layout_B = false;
  bool use_layout_C = false;
  
  for(uword i=0; i<n_elem; ++i)
    {
    const eT val = data[i];
    
    if(
      ( val >= eT(+100) )
      ||
      //( (is_signed<eT>::value == true) && (val <= eT(-100)) ) ||
      //( (is_non_integral<eT>::value == true) && (val > eT(0)) && (val <= eT(+1e-4)) ) ||
      //( (is_non_integral<eT>::value == true) && (is_signed<eT>::value == true) && (val < eT(0)) && (val >= eT(-1e-4)) ) 
        (
        cond_rel< is_signed<eT>::value >::leq(val, eT(-100))
        )
      ||
        (
        cond_rel< is_non_integral<eT>::value >::gt(val,  eT(0))
        &&
        cond_rel< is_non_integral<eT>::value >::leq(val, eT(+1e-4))
        )
      ||
        (
        cond_rel< is_non_integral<eT>::value && is_signed<eT>::value >::lt(val, eT(0))
        &&
        cond_rel< is_non_integral<eT>::value && is_signed<eT>::value >::geq(val, eT(-1e-4))
        )
      )
      {
      use_layout_C = true;
      break;
      }
      
    if(
      // (val >= eT(+10)) || ( (is_signed<eT>::value == true) && (val <= eT(-10)) )
      (val >= eT(+10)) || ( cond_rel< is_signed<eT>::value >::leq(val, eT(-10)) )
      )
      {
      use_layout_B = true;
      }
    }
  
  if(use_layout_C == true)
    {
    o.setf(ios::scientific);
    o.setf(ios::right);
    o.unsetf(ios::fixed);
    o.precision(4);
    cell_width = 13;
    }
  else
  if(use_layout_B == true)
    {
    o.unsetf(ios::scientific);
    o.setf(ios::right);
    o.setf(ios::fixed);
    o.precision(4);
    cell_width = 10;
    }
  else
    {
    o.unsetf(ios::scientific);
    o.setf(ios::right);
    o.setf(ios::fixed);
    o.precision(4);
    cell_width = 9;
    }
  
  return cell_width;
  }
void fix(std::ostream& stream) 
{
    stream.setf(std::ios::fixed);
    stream.precision(7);
}
Esempio n. 5
0
void IOWrapper::FixPrecision(std::ostream &stream, size_t size)
{
  stream.setf(std::ios::fixed);
  stream.precision(size);
}
S32 LLSDNotationFormatter::format_impl(const LLSD& data, std::ostream& ostr, U32 options, U32 level) const
{
	S32 format_count = 1;
	std::string pre;
	std::string post;

	if (options & LLSDFormatter::OPTIONS_PRETTY)
	{
		for (U32 i = 0; i < level; i++)
		{
			pre += "    ";
		}
		post = "\n";
	}

	switch(data.type())
	{
	case LLSD::TypeMap:
	{
		if (0 != level) ostr << post << pre;
		ostr << "{";
		std::string inner_pre;
		if (options & LLSDFormatter::OPTIONS_PRETTY)
		{
			inner_pre = pre + "    ";
		}

		bool need_comma = false;
		LLSD::map_const_iterator iter = data.beginMap();
		LLSD::map_const_iterator end = data.endMap();
		for(; iter != end; ++iter)
		{
			if(need_comma) ostr << ",";
			need_comma = true;
			ostr << post << inner_pre << '\'';
			serialize_string((*iter).first, ostr);
			ostr << "':";
			format_count += format_impl((*iter).second, ostr, options, level + 2);
		}
		ostr << post << pre << "}";
		break;
	}

	case LLSD::TypeArray:
	{
		ostr << post << pre << "[";
		bool need_comma = false;
		LLSD::array_const_iterator iter = data.beginArray();
		LLSD::array_const_iterator end = data.endArray();
		for(; iter != end; ++iter)
		{
			if(need_comma) ostr << ",";
			need_comma = true;
			format_count += format_impl(*iter, ostr, options, level + 1);
		}
		ostr << "]";
		break;
	}

	case LLSD::TypeUndefined:
		ostr << "!";
		break;

	case LLSD::TypeBoolean:
		if(mBoolAlpha ||
#if( LL_WINDOWS || __GNUC__ > 2)
		   (ostr.flags() & std::ios::boolalpha)
#else
		   (ostr.flags() & 0x0100)
#endif
			)
		{
			ostr << (data.asBoolean()
					 ? NOTATION_TRUE_SERIAL : NOTATION_FALSE_SERIAL);
		}
		else
		{
			ostr << (data.asBoolean() ? 1 : 0);
		}
		break;

	case LLSD::TypeInteger:
		ostr << "i" << data.asInteger();
		break;

	case LLSD::TypeReal:
		ostr << "r";
		if(mRealFormat.empty())
		{
			ostr << data.asReal();
		}
		else
		{
			formatReal(data.asReal(), ostr);
		}
		break;

	case LLSD::TypeUUID:
		ostr << "u" << data.asUUID();
		break;

	case LLSD::TypeString:
		ostr << '\'';
		serialize_string(data.asStringRef(), ostr);
		ostr << '\'';
		break;

	case LLSD::TypeDate:
		ostr << "d\"" << data.asDate() << "\"";
		break;

	case LLSD::TypeURI:
		ostr << "l\"";
		serialize_string(data.asString(), ostr);
		ostr << "\"";
		break;

	case LLSD::TypeBinary:
	{
		// *FIX: memory inefficient.
		const std::vector<U8>& buffer = data.asBinary();
		ostr << "b(" << buffer.size() << ")\"";
		if(buffer.size())
		{
			if (options & LLSDFormatter::OPTIONS_PRETTY_BINARY)
			{
				std::ios_base::fmtflags old_flags = ostr.flags();
				ostr.setf( std::ios::hex, std::ios::basefield );
				ostr << "0x";
				for (size_t i = 0; i < buffer.size(); i++)
				{
					ostr << (int) buffer[i];
				}
				ostr.flags(old_flags);
			}
			else
			{
				ostr.write((const char*)&buffer[0], buffer.size());
			}
		}
		ostr << "\"";
		break;
	}

	default:
		// *NOTE: This should never happen.
		ostr << "!";
		break;
	}
	return format_count;
}
/**
 * Print the summary of the move.
 *
 * The summary just contains the current value of the tuning parameter.
 * It is printed to the stream that it passed in.
 *
 * \param[in]     o     The stream to which we print the summary.
 */
void MetropolisHastingsMove::printSummary(std::ostream &o) const 
{
    std::streamsize previousPrecision = o.precision();
    std::ios_base::fmtflags previousFlags = o.flags();
    
    o << std::fixed;
    o << std::setprecision(4);
    
    // print the name
    const std::string &n = getMoveName();
    size_t spaces = 40 - (n.length() > 40 ? 40 : n.length());
    o << n;
    for (size_t i = 0; i < spaces; ++i) {
        o << " ";
    }
    o << " ";
    
    // print the DagNode name
    const std::string &dn_name = (*nodes.begin())->getName();
    spaces = 20 - (dn_name.length() > 20 ? 20 : dn_name.length());
    o << dn_name;
    for (size_t i = 0; i < spaces; ++i) {
        o << " ";
    }
    o << " ";
    
    // print the weight
    int w_length = 4 - (int)log10(weight);
    for (int i = 0; i < w_length; ++i) {
        o << " ";
    }
    o << weight;
    o << " ";
    
    // print the number of tries
    int t_length = 9 - (int)log10(numTried);
    for (int i = 0; i < t_length; ++i) {
        o << " ";
    }
    o << numTried;
    o << " ";
    
    // print the number of accepted
    int a_length = 9;
    if (numAccepted > 0) a_length -= (int)log10(numAccepted);
    
    for (int i = 0; i < a_length; ++i) {
        o << " ";
    }
    o << numAccepted;
    o << " ";
    
    // print the acceptance ratio
    double ratio = numAccepted / (double)numTried;
    if (numTried == 0) ratio = 0;
    int r_length = 5;
    
    for (int i = 0; i < r_length; ++i) {
        o << " ";
    }
    o << ratio;
    o << " ";
    
    proposal->printParameterSummary( o );
    
    o << std::endl;
    
    o.setf(previousFlags);
    o.precision(previousPrecision);
    
    
}
Esempio n. 8
0
void LocalNetworkXML::write(std::ostream& out) const
{ 
  out << "<?xml version=\"1.0\" ?>\n"
      << "<!DOCTYPE gama-local-adjustment SYSTEM \"gama-local-adjustment.dtd\">\n"
      << "\n<gama-local-adjustment version=\"" << VERSION << "\">\n";

  out << "\n<description>" << description << "</description>\n";
  
  {
    {
      using GNU_gama::GNU_gama_version;
      using GNU_gama::GNU_gama_compiler;

      out << "\n<network-general-parameters\n";
    
      out << "   gama-local-version=\""   << GNU_gama_version    << "\"\n";
      out << "   gama-local-algorithm=\"" << netinfo->algorithm()<< "\"\n";
      out << "   gama-local-compiler=\""  << GNU_gama_compiler   << "\"\n";

      out.setf(ios_base::fixed, ios_base::floatfield);
      out.precision(7);
      out << "   epoch=\""<< netinfo->epoch << "\"\n";

      out << "   axes-xy=\""; 
      switch (netinfo->PD.local_coordinate_system)
        {
        case   1: out << "en"; break;
        case   2: out << "nw"; break;
        case   4: out << "se"; break;
        case   8: out << "ws"; break;
        case  16: out << "ne"; break;
        case  32: out << "sw"; break;
        case  64: out << "es"; break;
        case 128: out << "wn"; break;
        default : break;
        }
      out << "\"\n";

      out << "   angles=\"" 
          << (netinfo->PD.right_handed_angles ?
                                "right-handed" : "left-handed") 
          << "\"\n";

      out << "/>\n";
    }

    out.setf(ios_base::scientific, ios_base::floatfield);
    out.precision(7);

    out << "\n<network-processing-summary>\n";

    coordinates_summary(out);
    observations_summary(out);
    equations_summary(out);
    std_dev_summary(out);
    
    out << "\n</network-processing-summary>\n";

   
  }

  coordinates(out);  
  observations(out);
  
  out << "\n</gama-local-adjustment>\n";
}
Esempio n. 9
0
/**
 * @method Report [void:public]
 * @param out [ostream&] the output stream to which to write the report
 *
 * This function outputs a brief report of the contents of this taxa block.
 * Overrides the abstract virtual function in the base class.
 */
void DistancesBlock::Report( std::ostream& out )
{
   int ntaxTotal = ntax;
   if( ntaxTotal == 0 )
      ntaxTotal = taxa.GetNumTaxonLabels();

	out << endl;
	out << id << " block contains ";
	if( ntaxTotal == 0 ) {
		out << "no taxa" << endl;
	}
	else if( ntaxTotal == 1 )
		out << "one taxon" << endl;
	else
		out << ntaxTotal << " taxa" << endl;

   if( IsLowerTriangular() )
      out << "  Matrix is lower-triangular" << endl;
   else if( IsUpperTriangular() )
      out << "  Matrix is upper-triangular" << endl;
   else
      out << "  Matrix is rectangular" << endl;

   if( IsInterleave() )
      out << "  Matrix is interleaved" << endl;
   else 
      out << "  Matrix is non-interleaved" << endl;

   if( IsLabels() )
      out << "  Taxon labels provided" << endl;
   else
      out << "  No taxon labels provided" << endl;

   if( IsDiagonal() )
      out << "  Diagonal elements specified" << endl;
   else 
      out << "  Diagonal elements not specified" << endl;

   out << "  Missing data symbol is " << missing << endl;

	if( ntax == 0 ) return;

   out.setf( ios::floatfield, ios::fixed );
   out.setf( ios::showpoint );
	for( int i = 0; i < ntax; i++ )
   {
      if( labels )
         out << setw(20) << taxa.GetTaxonLabel(i);
      else
         out << "\t\t";
      for( int j = 0; j < ntax; j++ )
      {
         if( triangle==upper && j < i ) {
            out << setw(12) << " ";
         }
         else if( triangle==lower && j > i )
            continue;
         else if( !diagonal && i == j ) {
            out << setw(12) << " ";
         }
         else if( IsMissing( i, j ) )
            out << setw(12) << missing;
         else
            out << setw(12) << setprecision(5) << GetDistance( i, j );
      }
      out << endl;
   }
}
Esempio n. 10
0
void LocalNetworkXML::coordinates(std::ostream& out) const
{
  const int y_sign = GaMaConsistent(netinfo->PD) ? +1 : -1;
  
  out << "\n<coordinates>\n";

  out.setf(ios_base::fixed, ios_base::floatfield);
  out.precision(6);
  
  const GaMaLib::Vec& X = netinfo->solve();
  std::vector<Index> ind(netinfo->sum_unknowns() + 1);
  Index dim = 0;
  
  
  out << "\n<fixed>\n";
    
  for (PointData::const_iterator
         i=netinfo->PD.begin(); i!=netinfo->PD.end(); ++i)
    {
      const LocalPoint& p = (*i).second;
      if (!p.active_xy() && !p.active_z()) continue;
      bool bxy = p.active_xy() && p.index_x() == 0;
      bool bz  = p.active_z () && p.index_z() == 0;
      if (!bxy && !bz) continue;
      out << "   <point> ";
      tagsp(out, "id", (*i).first);
      if (bxy)
        {
          const double x = (p.x()+X(p.index_x())/1000);
          const double y = (p.y()+X(p.index_y())/1000)*y_sign;
          tagsp(out, "x", x);
          tagsp(out, "y", y);
        }
      if (bz)
        {
          const double z = (p.z()+X(p.index_z())/1000);
          tagsp(out, "z", z);
        }
      out << "</point>\n";
    }
  
  out << "</fixed>\n";
  

  out << "\n<approximate>\n";
    
  for (PointData::const_iterator
         i=netinfo->PD.begin(); i!=netinfo->PD.end(); ++i)
    {
      const LocalPoint& p = (*i).second;
      if (!p.active_xy() && !p.active_z()) continue;
      bool bxy = p.active_xy() && p.index_x() != 0;
      bool bz  = p.active_z () && p.index_z() != 0;
      if (!bxy && !bz) continue;
      out << "   <point> ";
      tagsp(out, "id", (*i).first);
      if (bxy)
        {
          const char* cx = "x";
          const char* cy = "y";
          if (p.constrained_xy())
            {
              cx = "X";
              cy = "Y";
            }
          const double x = p.x();
          const double y = p.y()*y_sign;
          tagsp(out, cx, x);
          tagsp(out, cy, y);
        }
      if (bz)
        {
          const char* cz = "z";
          if (p.constrained_z())
            {
              cz = "Z";
            }
          const double z = p.z();
          tagsp(out, cz, z);
        }
      out << "</point>\n";
    }
  out << "</approximate>\n";
  
  
  out << "\n<!-- capital X,Y,Z denote constrained coordinates -->\n"
      << "<adjusted>\n";
    
  for (PointData::const_iterator
         i=netinfo->PD.begin(); i!=netinfo->PD.end(); ++i)
    {
      const LocalPoint& p = (*i).second;
      if (!p.active_xy() && !p.active_z()) continue;
      bool bxy = p.active_xy() && p.index_x() != 0;
      bool bz  = p.active_z () && p.index_z() != 0;
      if (!bxy && !bz) continue;
      out << "   <point> ";
      tagsp(out, "id", (*i).first);
      if (bxy)
        {
          const char* cx = "x";
          const char* cy = "y";
          if (p.constrained_xy())
            {
              cx = "X";
              cy = "Y";
            }
          const double x = (p.x()+X(p.index_x())/1000);
          const double y = (p.y()+X(p.index_y())/1000)*y_sign;
          tagsp(out, cx, x);
          tagsp(out, cy, y);
          ind[++dim] = p.index_x();
          ind[++dim] = p.index_y();
        }
      if (bz)
        {
          const char* cz = "z";
          if (p.constrained_z())
            {
              cz = "Z";
            }
          const double z = (p.z()+X(p.index_z())/1000);
          tagsp(out, cz, z);
          ind[++dim] = p.index_z();
        }
      out << "</point>\n";
    }
  out << "</adjusted>\n";
  
  orientation_shifts(out, ind, dim);
  
  int band = 0;   // signed value, must not be declared as Index
  if (dim) 
    {
      band = netinfo->xml_covband();
      if (band == -1 || band > dim-1) band = dim - 1;
    }
  out << "\n<!-- upper part of symmetric matrix band by rows -->\n"
      << "<cov-mat>\n"
      << "<dim>"  << dim  << "</dim> "
      << "<band>" << band << "</band>\n";
  
  out.setf(ios_base::scientific, ios_base::floatfield);
  out.precision(7);
  const double m2 = netinfo->m_0() * netinfo->m_0();
  for (Index k=0, i=1; i<=dim; i++)
    for (Index j=i; j<=std::min(dim, i+band); j++)
      {
        out << "<flt>" << m2*netinfo->qxx(ind[i], ind[j]) << "</flt>";
        if (++k == 3)
          {
            k = 0;
            out << "\n";
          }
        else
          {
            out << " ";
          }
      }
  
  out << "</cov-mat>\n";
  

  out << "\n<!-- original indexes from the adjustment -->\n"
      << "<original-index>\n";

  for (PointData::const_iterator
         i=netinfo->PD.begin(); i!=netinfo->PD.end(); ++i)
    {
      const LocalPoint& p = (*i).second;
      if (!p.active_xy() && !p.active_z()) continue;
      const bool bxy = p.active_xy() && p.index_x() != 0;
      const bool bz  = p.active_z () && p.index_z() != 0;
      if (bxy) out << "<ind>" << p.index_x() << "</ind>\n";
      if (bxy) out << "<ind>" << p.index_y() << "</ind>\n";
      if (bz ) out << "<ind>" << p.index_z() << "</ind>\n";
    }

  for (int i=1; i<=netinfo->sum_unknowns(); i++)
    if (netinfo->unknown_type(i) == 'R')
      {
        out << "<ind>" << i << "</ind>\n";
      }

  out << "</original-index>\n";
  
  out << "\n</coordinates>\n";
}
Esempio n. 11
0
void LocalNetworkXML::observations(std::ostream& out) const
{
  out << "\n<observations>\n\n";

   using namespace std;
   // using namespace GaMaLib;

   const int      y_sign = GaMaConsistent(netinfo->PD) ? +1 : -1;
   const GaMaLib::Vec& v = netinfo->residuals();
   const int      pocmer = netinfo->sum_observations();
   const double   scale  = netinfo->gons() ? 1.0 : 0.324;
   const double   kki    = netinfo->conf_int_coef();

   PointID predcs = "";   // provious standpoint ID
   for (int i=1; i<=pocmer; i++)
     {
       Observation* pm = netinfo->ptr_obs(i);
       // bool isangle    = false;

       Angle* u = 0;
       bool xyz = false;
       const char* tag = 0;
       ostringstream ostr;
       ostr.setf(ios_base::fixed, ios_base::floatfield);

       const int linear  =  6;    // output precision 
       const int angular =  7;    // output precision 

       if (Distance* d = dynamic_cast<Distance*>(pm))
         {
           out << "<" << (tag="distance") << ">";
           ostr.precision(linear);
           double m = d->value();
           ostr << " <obs>" << m << "</obs>";
           m += v(i)/1000;
           ostr << " <adj>" << m << "</adj>";
         }
       else if (Direction* s = dynamic_cast<Direction*>(pm))
         {
           out << "<" << (tag="direction") << ">";
           ostr.precision(angular);
           double m = R2G*(s->value());
           ostr << " <obs>" << m << "</obs>";
           m += v(i)/10000;
           if (m < 0) m += 400;
           if (m >= 400) m -= 400;
           ostr << " <adj>" <<  m << "</adj>";
         }
       else if ( (u = dynamic_cast<Angle*>(pm)) )
         {
           out << "<" << (tag="angle") << ">";
           ostr.precision(angular);
           double m = R2G*(u->value());
           ostr << " <obs>" << m << "</obs>";
           m += v(i)/10000;
           if (m < 0) m += 400;
           if (m >= 400) m -= 400;
           ostr << "<adj>" << m << "</adj>";
         }
       else if (S_Distance* sd = dynamic_cast<S_Distance*>(pm))
         {
           out << "<" << (tag="slope-distance") << ">"; 
           ostr.precision(linear);
           double m = sd->value();
           ostr << " <obs>" << m << "</obs>";
           m += v(i)/1000;
           ostr << " <adj>" << m << "</adj>";
         }
       else if (Z_Angle* za = dynamic_cast<Z_Angle*>(pm))
         {
           out << "<" << (tag="zenith-angle") << ">";
           ostr.precision(angular);
           double m = R2G*(za->value());
           ostr << " <obs>" << m << "</obs>";
           m += v(i)/10000;
           ostr << "<adj>" << m << "</adj>";
         }
       else if (X* x = dynamic_cast<X*>(pm))
         {
           xyz = true;
           out << "<" << (tag="coordinate-x") << ">";
           ostr.precision(linear);
           double m = x->value();
           ostr << " <obs>" << m << "</obs>";
           m += v(i)/1000;
           ostr << "<adj>" << m << "</adj>";
         }
       else if (Y* y = dynamic_cast<Y*>(pm))
         {
           xyz = true;
           out << "<" << (tag="coordinate-y") << ">";
           ostr.precision(linear);
           double m = y->value();
           ostr << " <obs>" << y_sign*m << "</obs>";
           m += v(i)/1000;
           ostr << " <adj>" << y_sign*m << "</adj>";
         }
       else if (Z* z = dynamic_cast<Z*>(pm))
         {
           xyz = true;
           out << "<" << (tag="coordinate-z") << ">";
           ostr.precision(linear);
           double m = z->value();
           ostr << " <obs>" << m << "</obs>";
           m += v(i)/1000;
           ostr << " <adj>" << m << "</adj>";
         }
       else if (H_Diff* h = dynamic_cast<H_Diff*>(pm))
         {
           out << "<" << (tag="height-diff") << ">";
           ostr.precision(linear);
           double m = h->value();
           ostr << " <obs>" << m << "</obs>";
           m += v(i)/1000;
           ostr << " <adj>" << m << "</adj>";            
         }
       else if (Xdiff* dx = dynamic_cast<Xdiff*>(pm))
         {
           out << "<" << (tag="dx") << ">";
           ostr.precision(linear);
           double m = dx->value();
           ostr << " <obs>" << m << "</obs>";
           m += v(i)/1000;
           ostr << " <adj>" << m << "</adj>";            
         }
       else if (Ydiff* dy = dynamic_cast<Ydiff*>(pm))
         {
           out << "<" << (tag="dy") << ">";
           ostr.precision(linear);
           double m = dy->value();
           ostr << " <obs>" << y_sign*m << "</obs>";
           m += v(i)/1000;
           ostr << " <adj>" << y_sign*m << "</adj>";            
         }
       else if (Zdiff* dz = dynamic_cast<Zdiff*>(pm))
         {
           out << "<" << (tag="dz") << ">";
           ostr.precision(linear);
           double m = dz->value();
           ostr << " <obs>" << m << "</obs>";
           m += v(i)/1000;
           ostr << " <adj>" << m << "</adj>";            
         }
       else  
         {
           throw GaMaLib::Exception("review/adjusted_observations.h - "
                                    "unknown observation type");
         }
       
       if (u)
         {
           out << " <from>"  << u->from() << "</from>"
               << " <left>"  << u->bs()   << "</left>"
               << " <right>" << u->fs()   << "</right>\n";
         }
       else if (xyz)
         {
           out << " <id>" << pm->from() << "</id>\n";
         }
       else
         {
           out << " <from>" << pm->from() << "</from>"
               << " <to>"   << pm->to()   << "</to>\n";
         }

       out << "  " << ostr.str();

       out.setf(ios_base::fixed, ios_base::floatfield);
       out.precision(3);
       out.width(7);
       double ml = netinfo->stdev_obs(i);
       if (dynamic_cast<Direction*>(pm))
         ml *= scale;
       else if (dynamic_cast<Angle*>(pm))
         ml *= scale;
       else if (dynamic_cast<Z_Angle*>(pm))
         ml *= scale;
       
       out << " <stdev>" << ml << "</stdev>\n";

       // weight coefficient of the residual
       double qrr = netinfo->wcoef_res(i);
       out << "   <qrr>" << qrr << "</qrr>";
              
       double f = netinfo->obs_control(i);
       out << " <f>" << f << "</f>";
              
       double sc=scale;
       if (f >= 0.1)
         {
           using namespace std;
           double no = fabs(netinfo->studentized_residual(i));
           out << " <std-residual>" << no << "</std-residual>";
           
           if ( (pm->ptr_cluster())->covariance_matrix.bandWidth() == 0 && 
                (f >=5 || (f >= 0.1 && no > kki))) 
             {
               double em = v(i)/(netinfo->wcoef_res(i)*netinfo->weight_obs(i));
               out << "\n   <err-obs>" << em*sc << "</err-obs>";

               double ev = em - v(i);
               out << " <err-adj>" << ev*sc << "</err-adj>";
             }
         }
       
       out << "\n   </" << tag << ">\n";
       
   }
   
  out << "\n</observations>\n";
}
Esempio n. 12
0
bool ARCStringTracker::DumpTracker(std::ostream& os)
{
	bool bNoError = true;

	os.setf(std::ios::hex);

	os << "Dumping ARCStringTracker tracker..." << std::endl;

	//------------------------------------------------------------
	// 
	try
	{
		os << "\t" << "The tracker is (" << convHex((unsigned long)&m_whoami) << " -> " << convHex((unsigned long)m_whoami) << ")\"" << readStringCarefully(m_whoami) << "\"." << std::endl;
	}
	catch (std::string& e)
	{
		os << std::endl << "Dumping failed(" << e << ")." << std::endl;
		bNoError = false;
	}
	//------------------------------------------------------------


	//------------------------------------------------------------
	// 
	try
	{
		os << "\t" << "The last track string is (" << convHex((unsigned long)m_lastStringTrackerName) << ")\"" << readStringCarefully(m_lastStringTrackerName) << "\"." << std::endl;
	}
	catch (std::string& e)
	{
		os << std::endl << "Dumping failed(" << e << ")." << std::endl;
		bNoError = false;
	}
	//------------------------------------------------------------


	//------------------------------------------------------------
	// 
#	ifdef _USE_CLASS_METHOD_TRACK_INCLUDE_STACK_
	os << "Dumping stack tracker..." << std::endl;
	try
	{
		ARCStringTracker* pTracker = m_lastStringTracker;
		while (pTracker)
		{
			if (checkReadable(pTracker, sizeof(ARCStringTracker)))
				throw std::string("ARCStringTracker corrupted");

			os << "\t(" << convHex((unsigned long)pTracker) << " -> " << convHex((unsigned long)pTracker->m_pTrackString) << ")" << readStringCarefully(pTracker->m_pTrackString) << std::endl;
			pTracker = pTracker->m_preStringTracker;
		}
	}
	catch (std::string& e)
	{
		os << std::endl << "Dumping failed(" << e << ")." << std::endl;
		bNoError = false;
	}
	os << "Dumping stack tracker finished." << std::endl;

	os << "Dumping stack tracker stored image..." << std::endl;
	std::vector<TrackRecord>::iterator ite = m_recs.begin();
	std::vector<TrackRecord>::iterator iteEn = m_recs.end();
	for (;ite!=iteEn;ite++)
	{
		const TrackRecord& rec = *ite;
		os << "\t(" << convHex((unsigned long)rec.pTracker) << " -> " << convHex((unsigned long)rec.pString) << ")" << readStringCarefully(rec.pString) << std::endl;
	}
	os << "Dumping stack tracker stored image finished." << std::endl;

#	endif // _USE_CLASS_METHOD_TRACK_INCLUDE_STACK_
	//------------------------------------------------------------

	os << std::endl << "All dumps finished." << std::endl << std::endl;

	__time64_t now;
	_time64( &now );
	os << "UTC time:   " << asctime( _gmtime64( &now ) )    << std::endl;
	os << "Local time: " << asctime( _localtime64( &now ) ) << std::endl;
	return bNoError;
}
Esempio n. 13
0
void Point::write_xml(std::ostream& ostr)
{
  const double n = N();
  const double e = E();
  const double u = U();

  X_.set_correction(x_transform(n, e, u));
  Y_.set_correction(y_transform(n, e, u));
  Z_.set_correction(z_transform(n, e, u));

  ostr << "\n<point> ";
  ostr << "<id> " << name << " </id>\n\n";

  ostr.setf(std::ios_base::fixed, std::ios_base::floatfield);
  ostr.precision(3);

  ostr << "        ";
  if (N.fixed())
    ostr << "<n-fixed/>  ";
  else if (N.constr())
    ostr << "<n-constr/> ";
  else if (N.free())
    ostr << "<n-free/>   ";
  else
    ostr << "<n-unused/> ";
  if (N.index())
    {
      ostr << "<dn>"  << setw(8) << N()*1000  << " </dn> "
           << "<ind>" << N.index() << "</ind> ";
    }
  ostr << "\n";

  ostr << "        ";
  if (E.fixed())
    ostr << "<e-fixed/>  ";
  else if (E.constr())
    ostr << "<e-constr/> ";
  else if (E.free())
    ostr << "<e-free/>   ";
  else
    ostr << "<e-unused/> ";
  if (E.index())
    {
      ostr << "<de>"  << setw(8) << E()*1000  << " </de> "
           << "<ind>" << E.index() << "</ind> ";
    }
  ostr << "\n";

  ostr << "        ";
  if (U.fixed())
    ostr << "<u-fixed/>  ";
  else if (U.constr())
    ostr << "<u-constr/> ";
  else if (U.free())
    ostr << "<u-free/>   ";
  else
    ostr << "<unused/> ";
  if (U.index())
    {
      ostr << "<du>"  << setw(8) << U()*1000  << " </du> "
           << "<ind>" << U.index() << "</ind> ";
    }
  ostr << "\n";

  if (!fixed_position())
    {
      set_cov_neu();

      ostr.setf(std::ios_base::scientific, std::ios_base::floatfield);
      ostr.precision(7);
      ostr << "\n";
      ostr << "        ";
      ostr << "<cnn> " << cnn << " </cnn> ";
      ostr << "<cne> " << setw(14) << cne << " </cne> ";
      ostr << "\n                                   ";
      ostr << "<cnu> " << setw(14) << cnu << " </cnu>\n";
      ostr << "        "; 
      ostr << "<cee> " << cee << " </cee> ";
      ostr << "<ceu> " << setw(14) << ceu << " </ceu>\n";
      ostr << "        "; 
      ostr << "<cuu> " << cuu << " </cuu>\n";
    }

  if (has_position())
    {
      ostr.setf(std::ios_base::fixed, std::ios_base::floatfield);
      ostr.precision(5);
      ostr << "\n";
      ostr << "        <x-given     >";
      ostr << setw(19) << X.init_value();
      ostr << " </x-given>\n";
      if (!fixed_position())
        {
          ostr << "        <x-correction>";
          ostr << setw(19) << X.correction();
          ostr << " </x-correction>\n";
          ostr << "        <x-adjusted  >";
          ostr << setw(19) << X();
          ostr << " </x-adjusted>\n";
          ostr << "\n";
        }
      ostr << "        <y-given     >";
      ostr << setw(19) << Y.init_value();
      ostr << " </y-given>\n";
      if (!fixed_position())
        {
          ostr << "        <y-correction>";
          ostr << setw(19) << Y.correction();
          ostr << " </y-correction>\n";
          ostr << "        <y-adjusted  >";
          ostr << setw(19) << Y();
          ostr << " </y-adjusted>\n";
          ostr << "\n";
        }
      ostr << "        <z-given     >";
      ostr << setw(19) << Z.init_value();
      ostr << " </z-given>\n";
      if (!fixed_position())
        {
          ostr << "        <z-correction>";
          ostr << setw(19) << Z.correction();
          ostr << " </z-correction>\n";
          ostr << "        <z-adjusted  >";
          ostr << setw(19) << Z();
          ostr << " </z-adjusted>\n";
        }
    }

  if (!fixed_position())
    {
      set_cov_xyz();

      ostr.setf(std::ios_base::scientific, std::ios_base::floatfield);
      ostr.precision(7);
      ostr << "\n";
      ostr << "        ";
      ostr << "<cxx> " << cxx << " </cxx> ";
      ostr << "<cxy> " << setw(14) << cxy << " </cxy> ";
      ostr << "\n                                   ";
      ostr << "<cxz> " << setw(14) << cxz << " </cxz>\n";
      ostr << "        ";
      ostr << "<cyy> " << cyy << " </cyy> ";
      ostr << "<cyz> " << setw(14) << cyz << " </cyz>\n";
      ostr << "        ";
      ostr << "<czz> " << czz << " </czz>\n";
    }

  if (has_position())
     {
       ostr.setf(std::ios_base::fixed, std::ios_base::floatfield);
       
       double dB, dL, dH, BB, LL, HH;   
       double B0 = B.init_value();
       double L0 = L.init_value();
       double H0 = H.init_value();
       
       if (!fixed_position())
         {
           common->ellipsoid.xyz2blh(X(), Y(), Z(), BB, LL, HH);
           dB = BB - B0;
           dL = LL - L0;
           dH = HH - H0;
         }
    
       ostr << "\n";
       ostr << "        <b-given     > ";
       ostr << latitude(B0);
       ostr << " </b-given>\n";      
       if (!fixed_position())
         {
           ostr << "        <b-correction> ";
           ostr.precision(7);
           ostr << setw(18) << dB*RAD_TO_SS;
           ostr << " </b-correction>\n";
           ostr << "        <b-adjusted  > ";
           ostr << latitude(BB);
           ostr << " </b-adjusted>\n";
           ostr << "\n";
         }
       ostr << "        <l-given     > ";
       ostr << longitude(L0);
       ostr << " </l-given>\n";      
       if (!fixed_position())
         {
           ostr << "        <l-correction> ";
           ostr << setw(18) << dL*RAD_TO_SS;
           ostr << " </l-correction>\n";
           ostr << "        <l-adjusted  > ";
           ostr << longitude(LL);
           ostr << " </l-adjusted>\n";
           ostr << "\n";
         }
       ostr.precision(5);
       ostr << "        <h-given     > ";
       ostr << setw(18) << H0;
       ostr << " </h-given>\n";      
       if (!fixed_position())
         {
           ostr << "        <h-correction> ";
           ostr << setw(18) << dH;
           ostr << " </h-correction>\n";
           ostr << "        <h-adjusted  > ";
           ostr << setw(18) << HH;
           ostr << " </h-adjusted>\n";
         }       
     }

  if (has_height())
    {
      ostr.setf(std::ios_base::fixed, std::ios_base::floatfield);
      ostr.precision(5);
      ostr << "\n        <height-given>";
      ostr << setw(19) << height.init_value();
      ostr << " </height-given>\n";
      if (free_height())
        {
          ostr << "        <height-correction>";
          ostr << setw(14) << height.correction();
          ostr << " </height-correction>\n";
          ostr << "        <height-adjusted  >";
          ostr << setw(14) << height();
          ostr << " </height-adjusted>\n";
        }
    }

  if (has_geoid())
    {
      ostr.precision(5);
      ostr << "\n        <geoid>       ";
      ostr << setw(19) << geoid.init_value();
      ostr << " </geoid>\n";      
    }


  double db = dB(), dl =dL();
  if (db*db + dl*dl)
    {
      db *= RAD_TO_SS;
      dl *= RAD_TO_SS;
      ostr.precision(5);
      ostr << "\n        "
           << "<db> " << db << " </db>   <dl> " << dl << " </dl>\n\n";
    }


  ostr << "\n        </point>\n";

  N.write_xml_done();
  E.write_xml_done();
  U.write_xml_done();
}
Esempio n. 14
0
void CommGraphWriter::writeFullGraphToTextStream(
   size_t record_number,
   std::ostream& os) const
{
   /*
    * Gather graph data on d_root_rank and write out.
    */
   TBOX_ASSERT(record_number < d_records.size());

   const Record& record = d_records[record_number];

   MessageStream ostr;

   for (size_t inodev = 0; inodev < record.d_node_values.size(); ++inodev) {
      const NodeValue& nodev = record.d_node_values[inodev];
      ostr << nodev.d_value;
   }
   for (size_t iedge = 0; iedge < record.d_edges.size(); ++iedge) {
      const Edge& edge = record.d_edges[iedge];
      ostr << edge.d_value << edge.d_dir << edge.d_other_node;
   }

   std::vector<char> tmpbuf(record.d_mpi.getRank() == d_root_rank ?
                            ostr.getCurrentSize() * record.d_mpi.getSize() : 0);

   if (ostr.getCurrentSize() > 0) {
      record.d_mpi.Gather(
         (void *)ostr.getBufferStart(),
         int(ostr.getCurrentSize()),
         MPI_CHAR,
         (record.d_mpi.getRank() == d_root_rank ? &tmpbuf[0] : 0),
         int(record.d_mpi.getRank() == d_root_rank ? ostr.getCurrentSize() : 0),
         MPI_CHAR,
         d_root_rank);
   }

   os.setf(std::ios_base::fmtflags(0), std::ios_base::floatfield);
   os.precision(8);

   std::vector<NodeValue> max_nodev(record.d_node_values.size());
   std::vector<Edge> max_edge(record.d_edges.size());

   if (record.d_mpi.getRank() == d_root_rank) {

      os << "\nCommGraphWriter begin record number " << record_number << '\n';
      os << "# proc" << '\t' << "dir" << '\t' << "remote" << '\t' << "value" << '\t' << "label\n";

      if (!tmpbuf.empty()) {
         MessageStream istr(tmpbuf.size(),
                                  MessageStream::Read,
                                  &tmpbuf[0],
                                  false);

         for (int src_rank = 0; src_rank < record.d_mpi.getSize(); ++src_rank) {

            NodeValue tmpnodev;
            for (size_t inodev = 0; inodev < record.d_node_values.size(); ++inodev) {
               istr >> tmpnodev.d_value;
               os << src_rank
                  << '\t' << tmpnodev.d_value
                  << '\t' << record.d_node_values[inodev].d_label
                  << '\n';
               if (max_nodev[inodev].d_value < tmpnodev.d_value) {
                  max_nodev[inodev] = tmpnodev;
               }
            }

            Edge tmpedge;
            for (size_t iedge = 0; iedge < record.d_edges.size(); ++iedge) {
               istr >> tmpedge.d_value >> tmpedge.d_dir >> tmpedge.d_other_node;
               os << src_rank
                  << '\t' << (tmpedge.d_dir == FROM ? "<-" : "->")
                  << '\t' << tmpedge.d_other_node
                  << '\t' << tmpedge.d_value
                  << '\t' << record.d_edges[iedge].d_label
                  << '\n';
               if (max_edge[iedge].d_value < tmpedge.d_value) {
                  max_edge[iedge] = tmpedge;
               }
            }

         }
      }
 void LocalFileFormat::Write(const Baker & baker,
                             const std::string & formatName,
                             std::ostream & ostream) const
 {
     
     static const int DEFAULT_CUBE_SIZE = 32;
     
     if(formatName != "iridas_cube")
     {
         std::ostringstream os;
         os << "Unknown cube format name, '";
         os << formatName << "'.";
         throw Exception(os.str().c_str());
     }
     
     ConstConfigRcPtr config = baker.getConfig();
     
     int cubeSize = baker.getCubeSize();
     if(cubeSize==-1) cubeSize = DEFAULT_CUBE_SIZE;
     cubeSize = std::max(2, cubeSize); // smallest cube is 2x2x2
     
     std::vector<float> cubeData;
     cubeData.resize(cubeSize*cubeSize*cubeSize*3);
     GenerateIdentityLut3D(&cubeData[0], cubeSize, 3, LUT3DORDER_FAST_RED);
     PackedImageDesc cubeImg(&cubeData[0], cubeSize*cubeSize*cubeSize, 1, 3);
     
     // Apply our conversion from the input space to the output space.
     ConstProcessorRcPtr inputToTarget;
     std::string looks = baker.getLooks();
     if(!looks.empty())
     {
         LookTransformRcPtr transform = LookTransform::Create();
         transform->setLooks(looks.c_str());
         transform->setSrc(baker.getInputSpace());
         transform->setDst(baker.getTargetSpace());
         inputToTarget = config->getProcessor(transform, TRANSFORM_DIR_FORWARD);
     }
     else
     {
         inputToTarget = config->getProcessor(baker.getInputSpace(), baker.getTargetSpace());
     }
     inputToTarget->apply(cubeImg);
     
     if(baker.getMetadata() != NULL)
     {
         std::string metadata = baker.getMetadata();
         std::vector<std::string> metadatavec;
         pystring::split(pystring::strip(metadata), metadatavec, "\n");
         if(metadatavec.size() > 0)
         {
             for(size_t i = 0; i < metadatavec.size(); ++i)
             {
                 ostream << "# " << metadatavec[i] << "\n";
             }
             ostream << "\n";
         }
     }
     ostream << "LUT_3D_SIZE " << cubeSize << "\n";
     if(cubeSize < 2)
     {
         throw Exception("Internal cube size exception");
     }
     
     // Set to a fixed 6 decimal precision
     ostream.setf(std::ios::fixed, std::ios::floatfield);
     ostream.precision(6);
     for(int i=0; i<cubeSize*cubeSize*cubeSize; ++i)
     {
         ostream << cubeData[3*i+0] << " "
                 << cubeData[3*i+1] << " "
                 << cubeData[3*i+2] << "\n";
     }
 }
Esempio n. 16
0
//------------------------------------------------------------------------------
// printMessage(): Recursive function to print all fields in this message
//---------------------------------------------------------------------------
void PrintSelected::printMessage(std::ostream& soutFields, std::ostream& soutVals, const google::protobuf::Message* const msg)
{
   std::streamsize oldWidth = soutFields.width();
   std::ostream::fmtflags oldFlags = soutFields.flags();

   const google::protobuf::Descriptor* descriptor = msg->GetDescriptor();
   const google::protobuf::Reflection* reflection = msg->GetReflection();

   const google::protobuf::Message& root = *msg;
   std::string msgName = descriptor->name();

   int fieldCount = descriptor->field_count();

   const google::protobuf::FieldDescriptor* fieldDescriptor = nullptr;

   std::string msgDivider = ";   ";
   std::string fieldDivider = ", ";

   bool lastField = false;

   if (fieldCount > 0) {
      for (int i = 0; i < fieldCount; i++) {
         if ((i+1) == fieldCount) lastField = true;

         // Get field descriptor (includes messages)
         fieldDescriptor = descriptor->field(i);

         // what type is this field?
         google::protobuf::FieldDescriptor::CppType cppType = fieldDescriptor->cpp_type();

         if (cppType == google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE) {

            // do the same again for this message, etc.
            const google::protobuf::Message& sub_message = reflection->GetMessage(root, fieldDescriptor);
            printMessage(soutFields, soutVals, &sub_message);
         }
         else {
            // not a message: Print the field
            if (reflection->HasField(root, fieldDescriptor)) {
               soutFields <<  std::left << std::setw(12) << fieldDescriptor->name(); // Field name

               // get the value
               switch (cppType) {
                  case google::protobuf::FieldDescriptor::CPPTYPE_STRING: {
                     soutVals <<  std::left << std::setw(12)<<  reflection->GetString(root, fieldDescriptor);
                     break;
                  }
                  case google::protobuf::FieldDescriptor::CPPTYPE_INT32: {
                     soutVals <<  std::left << std::setw(12)<<  reflection->GetInt32(root, fieldDescriptor);
                     break;
                  }
                  case google::protobuf::FieldDescriptor::CPPTYPE_INT64: {
                     soutVals <<  std::left << std::setw(12)<< reflection->GetInt64(root, fieldDescriptor);
                     break;
                  }
                  case google::protobuf::FieldDescriptor::CPPTYPE_UINT32: {
                     soutVals <<  std::left << std::setw(12)<< reflection->GetUInt32(root, fieldDescriptor);
                     break;
                  }
                  case google::protobuf::FieldDescriptor::CPPTYPE_UINT64: {
                     soutVals <<  std::left << std::setw(12)<< reflection->GetUInt64(root, fieldDescriptor);
                     break;
                  }
                  case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE: {
                     soutVals  <<  std::left << std::setw(12)<< reflection->GetDouble(root, fieldDescriptor);
                     break;
                  }
                  case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT: {
                     soutVals  <<  std::left << std::setw(12)<< reflection->GetFloat(root, fieldDescriptor);
                     break;
                  }
                  case google::protobuf::FieldDescriptor::CPPTYPE_BOOL: {
                     soutVals <<  std::left << std::setw(12)<< reflection->GetBool(root, fieldDescriptor);
                     break;
                  }
                  case google::protobuf::FieldDescriptor::CPPTYPE_ENUM: {
                     const google::protobuf::EnumValueDescriptor* enumVal = reflection->GetEnum(root, fieldDescriptor);
                     int enumIndex = enumVal->index();
                     soutVals <<  std::left << std::setw(12)<<  enumIndex;
                     break;
                  }
                  default: {
                     soutVals << "   \t";
                     break;
                  }
               }
            }  // end if has field
            else {
               // This field had no data. We should skip it
            }
            if (lastField) {
               // print message divider
               soutFields << msgDivider;
               soutVals << msgDivider;
            }
            else {
               // print field Divider
               soutFields << fieldDivider;
               soutVals << fieldDivider;
            }
         }
      }
   }

   soutFields.width( oldWidth );
   soutFields.setf( oldFlags );
}
Esempio n. 17
0
/*!

  Pretty print a velocity twist matrix. The data are tabulated.
  The common widths before and after the decimal point
  are set with respect to the parameter maxlen.

  \param s Stream used for the printing.

  \param length The suggested width of each matrix element.
  The actual width grows in order to accomodate the whole integral part,
  and shrinks if the whole extent is not needed for all the numbers.
  \param intro The introduction which is printed before the matrix.
  Can be set to zero (or omitted), in which case
  the introduction is not printed.

  \return Returns the common total width for all matrix elements

  \sa std::ostream &operator<<(std::ostream &s, const vpArray2D<Type> &A)
*/
int
vpVelocityTwistMatrix::print(std::ostream& s, unsigned int length, char const* intro) const
{
  typedef std::string::size_type size_type;

  unsigned int m = getRows();
  unsigned int n = getCols();

  std::vector<std::string> values(m*n);
  std::ostringstream oss;
  std::ostringstream ossFixed;
  std::ios_base::fmtflags original_flags = oss.flags();

  // ossFixed <<std::fixed;
  ossFixed.setf ( std::ios::fixed, std::ios::floatfield );

  size_type maxBefore=0;  // the length of the integral part
  size_type maxAfter=0;   // number of decimals plus
  // one place for the decimal point
  for (unsigned int i=0;i<m;++i) {
    for (unsigned int j=0;j<n;++j){
      oss.str("");
      oss << (*this)[i][j];
      if (oss.str().find("e")!=std::string::npos){
        ossFixed.str("");
        ossFixed << (*this)[i][j];
        oss.str(ossFixed.str());
      }

      values[i*n+j]=oss.str();
      size_type thislen=values[i*n+j].size();
      size_type p=values[i*n+j].find('.');

      if (p==std::string::npos){
        maxBefore=vpMath::maximum(maxBefore, thislen);
        // maxAfter remains the same
      } else{
        maxBefore=vpMath::maximum(maxBefore, p);
        maxAfter=vpMath::maximum(maxAfter, thislen-p-1);
      }
    }
  }

  size_type totalLength=length;
  // increase totalLength according to maxBefore
  totalLength=vpMath::maximum(totalLength,maxBefore);
  // decrease maxAfter according to totalLength
  maxAfter=std::min(maxAfter, totalLength-maxBefore);
  if (maxAfter==1) maxAfter=0;

  // the following line is useful for debugging
  //std::cerr <<totalLength <<" " <<maxBefore <<" " <<maxAfter <<"\n";

  if (intro) s <<intro;
  s <<"["<<m<<","<<n<<"]=\n";

  for (unsigned int i=0;i<m;i++) {
    s <<"  ";
    for (unsigned int j=0;j<n;j++){
      size_type p=values[i*n+j].find('.');
      s.setf(std::ios::right, std::ios::adjustfield);
      s.width((std::streamsize)maxBefore);
      s <<values[i*n+j].substr(0,p).c_str();

      if (maxAfter>0){
        s.setf(std::ios::left, std::ios::adjustfield);
        if (p!=std::string::npos){
          s.width((std::streamsize)maxAfter);
          s <<values[i*n+j].substr(p,maxAfter).c_str();
        } else{
          assert(maxAfter>1);
          s.width((std::streamsize)maxAfter);
          s <<".0";
        }
      }

      s <<' ';
    }
    s <<std::endl;
  }

  s.flags(original_flags); // restore s to standard state

  return (int)(maxBefore+maxAfter);
}
Esempio n. 18
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void MRCReader::printHeader(MRCHeader* h, std::ostream& out)
{
  out << "MRC Header ----------------------------------" << std::endl;
  PRINT_VARIABLE (out, "nx:" , h->nx )
  PRINT_VARIABLE (out, "ny:" , h->ny )
  PRINT_VARIABLE (out, "nz:" , h->nz )
  PRINT_VARIABLE (out, "mode:" , h->mode )
  PRINT_VARIABLE (out, "nxstart:" , h->nxstart )
  PRINT_VARIABLE (out, "nystart:" , h->nystart )
  PRINT_VARIABLE (out, "nzstart:" , h->nzstart )
  PRINT_VARIABLE (out, "mx:" , h->mx )
  PRINT_VARIABLE (out, "my:" , h->my )
  PRINT_VARIABLE (out, "mz:" , h->mz )
  PRINT_VARIABLE (out, "xlen:" , h->xlen )
  PRINT_VARIABLE (out, "ylen:" , h->ylen )
  PRINT_VARIABLE (out, "zlen:" , h->zlen )
  PRINT_VARIABLE (out, "alpha:" , h->alpha )
  PRINT_VARIABLE (out, "beta:" , h->beta )
  PRINT_VARIABLE (out, "gamma:" , h->gamma )
  PRINT_VARIABLE (out, "mapc:" , h->mapc )
  PRINT_VARIABLE (out, "mapr:" , h->mapr )
  PRINT_VARIABLE (out, "maps" , h->maps )
  PRINT_VARIABLE (out, "amin:" , h->amin )
  PRINT_VARIABLE (out, "amax:" , h->amax )
  PRINT_VARIABLE (out, "amean:" , h->amean )
  PRINT_VARIABLE (out, "ispg:" , h->ispg )
  PRINT_VARIABLE (out, "nsymbt:" , h->nsymbt )
  PRINT_VARIABLE (out, "next:" , h->next )
  PRINT_VARIABLE (out, "creatid:" , h->creatid )
  PRINT_VARIABLE (out, "extra_data:" , h->extra_data ) // print hex
  PRINT_VARIABLE (out, "nreal:" , h->nreal )
  PRINT_VARIABLE (out, "extra_data_2:" , h->extra_data_2 )
  PRINT_VARIABLE (out, "imodStamp:" , h->imodStamp )
  PRINT_VARIABLE (out, "imodFlags:" , h->imodFlags )
  PRINT_VARIABLE (out, "idtype:" , h->idtype )
  PRINT_VARIABLE (out, "lens:" , h->lens )
  PRINT_VARIABLE (out, "nd1:" , h->nd1 )
  PRINT_VARIABLE (out, "nd2:" , h->nd2 )
  PRINT_VARIABLE (out, "vd1:" , h->vd1 )
  PRINT_VARIABLE (out, "vd2:" , h->vd2 )
  PRINT_VARIABLE (out, "tiltangles:" , h->tiltangles[0] << h->tiltangles[1] << h->tiltangles[2] << h->tiltangles[3] << h->tiltangles[4] << h->tiltangles[5]   )
  PRINT_VARIABLE (out, "xorg:" , h->xorg )
  PRINT_VARIABLE (out, "yorg:" , h->yorg )
  PRINT_VARIABLE (out, "zorg:" , h->zorg )
  PRINT_VARIABLE (out, "cmap:" , h->cmap[0] << h->cmap[1] << h->cmap[2] << h->cmap[3]  )
  PRINT_VARIABLE (out, "stamp:" , h->stamp[0] << h->stamp[1] << h->stamp[2] << h->stamp[3]  )
  PRINT_VARIABLE (out, "rms:" , h->rms )
  PRINT_VARIABLE (out, "nLabels" , h->nLabels )

  for(int i = 0; i < h->nLabels; ++i)
  {
    PRINT_VARIABLE (out, "  Label: " << i , h->labels[i] )
  }


  if (h->feiHeaders != NULL)
  {
    char buf[FW + 1];
    buf[FW] = 0;
    std::vector<std::string> strings;
    strings.push_back("a_tilt");
    strings.push_back("b_tilt");
    strings.push_back("x_stage");
    strings.push_back("y_stage");
    strings.push_back("z_stage");
    strings.push_back("x_shift");
    strings.push_back("y_shift");
    strings.push_back("defocus");
    strings.push_back("exp_time");
    strings.push_back("mean_int");
    strings.push_back("tiltaxis");
    strings.push_back("pixelsize");
    strings.push_back("magnification");
    strings.push_back("voltage");
    for(size_t i = 0; i < strings.size(); ++i)
    {
      ::memset(buf, 32, FW);
      snprintf(buf, FW, "%s", strings[i].c_str());
      buf[strings[i].length()] = 32;
      out << buf << "\t";
    }
    out << std::endl;


    // std::cout << "a_tilt \t b_tilt \t x_stage \t y_stage \t z_stage \t x_shift \t y_shift \t defocus \t exp_time \t mean_int \t tiltaxis \t pixelsize \t magnification \t voltage" << std::endl;
    FEIHeader* fei = NULL;
    for (int i = 0; i < h->nz; ++i)
    {
      fei = &(h->feiHeaders[i]);
      out.setf(std::ios::left);
      out << std::setw(FW) << fei->a_tilt << "\t" << std::setw(FW) << fei->b_tilt << "\t"
          << std::setw(FW) << fei->x_stage << "\t" << std::setw(FW) << fei->y_stage << "\t" << std::setw(FW) << fei->z_stage << "\t"
          << std::setw(FW) << fei->x_shift << "\t" << std::setw(FW) << fei->y_shift << "\t"
          << std::setw(FW) << fei->defocus << "\t" << std::setw(FW) << fei->exp_time << "\t"
          << std::setw(FW) << fei->mean_int << "\t" << std::setw(FW) << fei->tiltaxis << "\t"
          << std::setw(FW) << fei->pixelsize << "\t" << std::setw(FW) << fei->magnification << "\t"
          << std::setw(FW) << fei->voltage << "\t" << std::endl;
    }
  }

  out << "---------------------------------------" << std::endl;
}