FACT++  1.0
virtual bool ofits::AddColumn ( uint32_t  cnt,
char  typechar,
const std::string &  name,
const std::string &  unit,
const std::string &  comment = "",
bool  addHeaderKeys = true 
)
inlinevirtual

Reimplemented in zofits.

Definition at line 596 of file ofits.h.

References ___err___, ofits::Table::bytes_per_row, ofits::Table::cols, ofits::Key::comment, FITS::CommentFromType(), findcol(), gLog, ofits::Table::Column::name, ofits::Table::Column::num, ofits::Table::num_cols, ofits::Table::Column::offset, SetStr(), size, ofits::Table::Column::size, FITS::SizeFromType(), type, and ofits::Table::Column::type.

Referenced by zofits::AddColumn(), AddColumn(), AddColumnBool(), AddColumnByte(), AddColumnChar(), AddColumnDouble(), AddColumnFloat(), AddColumnInt(), AddColumnLong(), AddColumnShort(), and main().

597  {
598  if (tellp()<0)
599  {
600  std::ostringstream sout;
601  sout << "File not open... ignoring column '" << name << "'";
602 #ifdef __EXCEPTIONS
603  throw std::runtime_error(sout.str());
604 #else
605  gLog << ___err___ << "ERROR - " << sout.str() << std::endl;
606  return false;
607 #endif
608  }
609 
610  if (tellp()>0)
611  {
612  std::ostringstream sout;
613  sout << "Header already written, no new column can be defined... ignoring column '" << name << "'";
614 #ifdef __EXCEPTIONS
615  throw std::runtime_error(sout.str());
616 #else
617  gLog << ___err___ << "ERROR - " << sout.str() << std::endl;
618  return false;
619 #endif
620  }
621 
622  if (findcol(name)!=fTable.cols.cend())
623  {
624  std::ostringstream sout;
625  sout << "A column with the name '" << name << "' already exists.";
626 #ifdef __EXCEPTIONS
627  throw std::runtime_error(sout.str());
628 #else
629  gLog << ___err___ << "ERROR - " << sout.str() << std::endl;
630  return false;
631 #endif
632  }
633 
634  typechar = toupper(typechar);
635 
636  static const std::string allow("LABIJKEDQ");
637 #if GCC_VERSION < 40603
638  if (std::find(allow.begin(), allow.end(), typechar)==allow.end())
639 #else
640  if (std::find(allow.cbegin(), allow.cend(), typechar)==allow.end())
641 #endif
642  {
643  std::ostringstream sout;
644  sout << "Column type '" << typechar << "' not supported.";
645 #ifdef __EXCEPTIONS
646  throw std::runtime_error(sout.str());
647 #else
648  gLog << ___err___ << "ERROR - " << sout.str() << std::endl;
649  return false;
650 #endif
651  }
652 
653  std::ostringstream type;
654  type << cnt;
655  if (typechar=='Q')
656  type << "QB";
657  else
658  type << typechar;
659 
660  fTable.num_cols++;
661 
662  if (addHeaderKeys)
663  {
664 #if GCC_VERSION < 40603
665  const std::string nc = std::to_string((long long int)(fTable.num_cols));
666 #else
667  const std::string nc = std::to_string(fTable.num_cols);
668 #endif
669  SetStr("TFORM"+nc, type.str(), "format of "+name+" "+FITS::CommentFromType(typechar));
670  SetStr("TTYPE"+nc, name, comment);
671  if (!unit.empty())
672  SetStr("TUNIT"+nc, unit, "unit of "+name);
673  }
674 
675  const size_t size = FITS::SizeFromType(typechar);
676 
677  Table::Column col;
678 
679  col.name = name;
680  col.type = typechar;
681  col.num = cnt;
682  col.size = size;
683  col.offset = fTable.bytes_per_row;
684 
685  fTable.cols.emplace_back(col);
686 
687  fTable.bytes_per_row += size*cnt;
688 
689  // Align to four bytes
691 
692  return true;
693  }
#define gLog
Definition: fits.h:36
#define ___err___
Definition: fits.h:37
Table fTable
Definition: ofits.h:327
static uint32_t SizeFromType(char type)
Definition: FITS.h:70
size_t bytes_per_row
Definition: ofits.h:306
std::vector< Column > cols
Definition: ofits.h:319
bool SetStr(const std::string &key, std::string s, const std::string &comment="")
Definition: ofits.h:526
int type
std::vector< Table::Column >::const_iterator findcol(const std::string &name)
Definition: ofits.h:331
int size
Definition: db_dim_server.c:17
size_t num_cols
Definition: ofits.h:308
std::vector< char > fOutputBuffer
Definition: ofits.h:329
static std::string CommentFromType(char type)
Definition: FITS.h:50

+ Here is the call graph for this function:

+ Here is the caller graph for this function: