当前位置: 首页>>代码示例>>C++>>正文


C++ NumericVector::hasAttribute方法代码示例

本文整理汇总了C++中NumericVector::hasAttribute方法的典型用法代码示例。如果您正苦于以下问题:C++ NumericVector::hasAttribute方法的具体用法?C++ NumericVector::hasAttribute怎么用?C++ NumericVector::hasAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NumericVector的用法示例。


在下文中一共展示了NumericVector::hasAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: gv_writefits_img

//' FITS image writer
//' 
//' Writes a vector, matrix or 3D array to a FITS file as an image.
//' The data is written to the primary HDU.
//' 
// [[Rcpp::export]]
int gv_writefits_img(NumericVector img, CharacterVector fits_name, CharacterVector hdu_name = "")
{
  IntegerVector dim;
  if (!img.hasAttribute("dim"))
  {
    REprintf("ERROR: image has not been dimensioned.\n");
    return 1;
  }
  dim = img.attr("dim");
  if (dim.length() > 3)
	{
		REprintf("ERROR: dimension of more than 3 unsupported.\n");
		return 1;
	}

  fitsfile *pfits=NULL;
	int err=0;

	std::string fname = as<std::string>(fits_name[0]);
	fits_create_file(&pfits, (char *) fname.c_str(), &err);
	if (err)
	{
		gv_print_fits_err(err);
		return err;
	}

#ifdef GV_DEBUG
  Rcout << "Number of dim: " << dim.length() << std::endl;
	for (int i=0; i<dim.length(); i++)
	{
		Rcout << "Dim[" << i << "]: " << dim[i] << std::endl;
	}
	Rcout << "Number of elements: " << img.length() << std::endl;
  double *p = &(*img.begin());
  for (int i=0; i<img.length(); i++)
  {
    Rcout << "*(p+" << i << ") = " << *(p+i) << std::endl;
  }
#endif
  
  long longdim[3], startpix[3] = {1,1,1}; // default start
  for (int i=0; i<dim.length(); i++) longdim[i] = (long) dim[i];
  
	// start writing to file
	fits_create_img(pfits, DOUBLE_IMG, dim.length(), longdim, &err);
	fits_write_pix(pfits, TDOUBLE, startpix, img.length(), &(*img.begin()), &err);

	fits_close_file(pfits, &err);
  return err;
}
开发者ID:yitping,项目名称:gravityr,代码行数:56,代码来源:gv_writefits_img.cpp


注:本文中的NumericVector::hasAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。