35  CPFITS_BASE(CPFITS_BASE &&ff){
 
   40  void operator=(CPFITS_BASE &&ff){
 
   45  void check_status(
int status,std::string s = 
"Error in CPFITS"){
 
   47      fits_report_error(stderr, status);
 
   48      std::cerr << s << std::endl;
 
   49      throw std::invalid_argument(s);
 
   54  std::mutex mutex_lock;
 
   63    std::lock_guard<std::mutex> hold(mutex_lock);
 
   66    fits_get_num_hdus(fptr, &hdunum, &status);
 
   72  int get_current_hdu_num(){
 
   73    std::lock_guard<std::mutex> hold(mutex_lock);
 
   75    fits_get_hdu_num(fptr,&hdunum);
 
   80  int change_hdu(
int i){
 
   81    int hdunum = get_num_hdus();
 
   82    if(i > hdunum || i < 1){
 
   83      throw std::invalid_argument(
"out of range");
 
   88      std::lock_guard<std::mutex> hold(mutex_lock);
 
   89      fits_movabs_hdu(fptr,i,&hdutype,&status);
 
   97  int get_current_hdu_type(
bool verbose=
false){
 
   99    int hdutype,status = 0;
 
  100    fits_get_hdu_type(fptr,&hdutype,&status);
 
  101    check_status(status);
 
  104      std::cout << 
"type: " ;
 
  107          std::cout << 
"Image" << std::endl;
 
  110          std::cout << 
"ASCII table" << std::endl;
 
  113          std::cout << 
"Binary table" << std::endl;
 
  136  void reset_imageInfo(){
 
  137    std::lock_guard<std::mutex> hold(mutex_lock);
 
  140    fits_get_img_type(fptr,&bitpix,&status);
 
  141    check_status(status);
 
  142    fits_get_img_dim(fptr,&Ndims,&status);
 
  143    check_status(status);
 
  145    fits_get_img_size(fptr,Ndims,sizes.data(),&status);
 
  146    check_status(status);
 
  150  void imageDimensions(std::vector<long> &my_sizes){
 
  151    my_sizes.resize(sizes.size());
 
  157    std::lock_guard<std::mutex> hold(mutex_lock);
 
  158    int keysexist,status=0;
 
  159    return fits_get_hdrspace(fptr,&keysexist,NULL,&status);
 
  163  int readKey(std::string keyname,
double &value){
 
  164    std::lock_guard<std::mutex> hold(mutex_lock);
 
  166    return fits_read_key(fptr,TDOUBLE,keyname.c_str(),
 
  167                         &value,NULL,&status);
 
  169  int readKey(std::string keyname,
float &value){
 
  170    std::lock_guard<std::mutex> hold(mutex_lock);
 
  172    return fits_read_key(fptr,TFLOAT,keyname.c_str(),
 
  173                         &value,NULL,&status);
 
  175  int readKey(std::string keyname,
int &value){
 
  176    std::lock_guard<std::mutex> hold(mutex_lock);
 
  178    return fits_read_key(fptr,TINT,keyname.c_str(),
 
  179                         &value,NULL,&status);
 
  181  int readKey(std::string keyname,
size_t &value){
 
  182    std::lock_guard<std::mutex> hold(mutex_lock);
 
  184    return fits_read_key(fptr,TULONG,keyname.c_str(),
 
  185                         &value,NULL,&status);
 
  187  int readKey(std::string keyname,
long &value){
 
  188    std::lock_guard<std::mutex> hold(mutex_lock);
 
  190    return fits_read_key(fptr,TLONG,keyname.c_str(),
 
  191                         &value,NULL,&status);
 
  193  int readHeader(std::vector<std::string> &headercards,
bool verbose=
false){
 
  194    std::lock_guard<std::mutex> hold(mutex_lock);
 
  195    int nkeys,status=0,hdupos;
 
  196    char card[FLEN_CARD];
 
  199    fits_get_hdu_num(fptr, &hdupos);  
 
  200    fits_get_hdrspace(fptr, &nkeys, NULL, &status); 
 
  202    if(verbose) printf(
"Header listing for HDU #%d:\n", hdupos);
 
  204    for (
int ii = 1; ii <= nkeys; ii++) { 
 
  205      if (fits_read_record(fptr, ii, card, &status))
break;
 
  206      if(verbose) printf(
"%s\n", card);
 
  207      headercards.push_back(card);
 
  209    if(verbose) printf(
"END\n\n");  
 
  217    std::vector<std::string> cards;
 
  218    return readHeader(cards,
true);
 
  227  std::vector<long> sizes;
 
  232class CPFITS_READ : 
public CPFITS_BASE {
 
  239  CPFITS_READ(std::string filename,std::string extension=
"" 
  240              ,
bool verbose = 
false) {
 
  245      fits_open_image(&fptr,filename.c_str(), READONLY, &status);
 
  247      filename = filename + extension;
 
  248      fits_open_image(&fptr,filename.c_str(), READONLY, &status);
 
  251    check_status(status,
"Problem with input fits file.");
 
  255      std::cout << 
"Opening file : " << filename << std::endl;
 
  256      std::cout << 
"      status : " << status << std::endl;
 
  262    fits_close_file(fptr, &status);
 
  266  CPFITS_READ(CPFITS_READ &&ff):CPFITS_BASE(std::move(ff)){};
 
  268  void operator=(CPFITS_READ &&ff){
 
  269     CPFITS_BASE::operator=(std::move(ff));
 
  273  void reset(std::string filename,std::string extension=
""){
 
  274    std::lock_guard<std::mutex> hold(mutex_lock);
 
  276    fits_close_file(fptr, &status);
 
  277    check_status(status);
 
  280      fits_open_image(&fptr,filename.c_str(), READONLY, &status);
 
  282      filename = filename + extension;
 
  283      fits_open_image(&fptr,filename.c_str(), READONLY, &status);
 
  285    check_status(status);
 
 
  290  int read(std::vector<double> &output,std::vector<long> &size){
 
  293    imageDimensions(size);
 
  295    for(
long n : size) nelements *= n;
 
  296    std::vector<long> start(size.size(),1);
 
  298    output.resize(nelements);
 
  299    std::lock_guard<std::mutex> hold(mutex_lock);
 
  301    return fits_read_pix(fptr,TDOUBLE,start.data(),nelements
 
  302                         ,NULL,output.data(),NULL, &status);
 
 
  305  int read(std::vector<float> &output,std::vector<long> &size){
 
  308    imageDimensions(size);
 
  310    for(
long n : size) nelements *= n;
 
  311    std::vector<long> start(size.size(),1);
 
  312    output.resize(nelements);
 
  315    std::lock_guard<std::mutex> hold(mutex_lock);
 
  316    return fits_read_pix(fptr,TFLOAT,start.data(),nelements
 
  317                         ,NULL,output.data(),NULL, &status);
 
 
  320  int read(std::valarray<float> &output,std::vector<long> &size){
 
  323    imageDimensions(size);
 
  325    for(
long n : size) nelements *= n;
 
  326    std::vector<long> start(size.size(),1);
 
  328    output.resize(nelements);
 
  331    std::lock_guard<std::mutex> hold(mutex_lock);
 
  332    return fits_read_pix(fptr,TFLOAT,start.data(),nelements
 
  333                         ,NULL,&output[0],NULL, &status);
 
 
  335  int read(std::valarray<double> &output,std::vector<long> &sizes){
 
  337    imageDimensions(sizes);
 
  340    long long nelements=1;
 
  341    for(
long n : sizes) nelements *= n;
 
  342    std::vector<long> start(sizes.size(),1);
 
  343    output.resize(nelements);
 
  346    std::lock_guard<std::mutex> hold(mutex_lock);
 
  347    int error = fits_read_pix(fptr,TDOUBLE,start.data(),nelements
 
  348                            ,NULL,&output[0],NULL, &status);
 
  349    check_status(status,
"PixMap Read Failure");
 
  356  int read(std::vector<std::vector<T> > &output){
 
  358    std::vector<long> size;
 
  360    int status = 
read(tmp,size);
 
  361    output.resize(size[0]);
 
  363    for(
size_t i=0 ; i < size[0] ; ++i){
 
  364      output[i].resize(size[1]);
 
  365      for(T &x : output[i]){
 
 
  377    std::lock_guard<std::mutex> hold(mutex_lock);
 
  378    return fits_read_pix(fptr,TDOUBLE,start,nelements
 
  379                         ,NULL,output,NULL, &status);
 
 
  381  int read_block(
float *output,
long nelements,
long * start){
 
  383    std::lock_guard<std::mutex> hold(mutex_lock);
 
  384    return fits_read_pix(fptr,TFLOAT,start,nelements
 
  385                         ,NULL,output,NULL, &status);
 
  393    std::lock_guard<std::mutex> hold(mutex_lock);
 
  394    return fits_read_subset(fptr,TDOUBLE,lowerleft,upperright,inc
 
  395                            ,NULL,output,NULL,&status);
 
 
  401    std::lock_guard<std::mutex> hold(mutex_lock);
 
  402    return fits_read_subset(fptr,TFLOAT,lowerleft,upperright,inc
 
  403                            ,NULL,output,NULL,&status);
 
 
 
  407class CPFITS_WRITE : 
public CPFITS_BASE {
 
  411  CPFITS_WRITE(CPFITS_READ &);
 
  412  CPFITS_WRITE operator=(CPFITS_WRITE );
 
  415  CPFITS_WRITE(std::string filename,
bool append = 
false,
bool verbose = 
false) {
 
  418      if(verbose) std::cout << 
"Creating file : " << filename << std::endl;
 
  419      if(filename[0] != 
'!') filename = 
"!" + filename;
 
  421      fits_create_file(&fptr, filename.c_str(), &status);
 
  422      check_status(status);
 
  425      fits_open_image(&fptr,filename.c_str(),READWRITE,&status);
 
  430        fits_create_file(&fptr, filename.c_str(), &status);
 
  431        check_status(status);
 
  433        if(verbose) std::cout << 
"Creating file : " << filename << std::endl;
 
  435        if(verbose) std::cout << 
"Appending to file : " << filename << std::endl;
 
  436        check_status(status);
 
  443    fits_close_file(fptr, &status);
 
  444    check_status(status);
 
  448   void write_array(std::vector<double> &array){
 
  449     long n = array.size();
 
  451     std::lock_guard<std::mutex> hold(mutex_lock);
 
  452     fits_create_img(fptr,DOUBLE_IMG,1,&n, &status);
 
  453     check_status(status);
 
  454     std::vector<long> fpixel(1,1);
 
  455     fits_write_pix(fptr,TDOUBLE,fpixel.data(),
 
  456                           n,array.data(),&status);
 
  457     check_status(status);
 
  460   void write_array(std::vector<float> &array){
 
  461     long n = array.size();
 
  463     std::lock_guard<std::mutex> hold(mutex_lock);
 
  464     fits_create_img(fptr,FLOAT_IMG,1,&n, &status);
 
  465     check_status(status);
 
  466     std::vector<long> fpixel(1,1);
 
  467     fits_write_pix(fptr,TFLOAT,fpixel.data(),
 
  468                           n,array.data(),&status);
 
  469     check_status(status);
 
  473  void write_image(std::vector<double> &im,std::vector<long> &size){
 
  475    for(
size_t i : size) n *= i;
 
  476    assert(im.size() == n);
 
  478    std::lock_guard<std::mutex> hold(mutex_lock);
 
  479    fits_create_img(fptr,DOUBLE_IMG,size.size(),
 
  480                    size.data(), &status);
 
  481    check_status(status);
 
  482    std::vector<long> fpixel(size.size(),1);
 
  483    fits_write_pix(fptr,TDOUBLE,fpixel.data(),
 
  484                          im.size(),im.data(),&status);
 
  485    check_status(status);
 
  487  void write_image(
double *im,std::vector<long> &size){
 
  489    for(
size_t i : size) n *= i;
 
  491    std::lock_guard<std::mutex> hold(mutex_lock);
 
  492    fits_create_img(fptr,DOUBLE_IMG,size.size(),
 
  493                    size.data(), &status);
 
  494    check_status(status);
 
  495    std::vector<long> fpixel(size.size(),1);
 
  496    fits_write_pix(fptr,TDOUBLE,fpixel.data(),
 
  498    check_status(status);
 
  500 void write_image(std::vector<float> &im,std::vector<long> &size){
 
  502    for(
size_t i : size) n *= i;
 
  503    assert(im.size() == n);
 
  505    std::lock_guard<std::mutex> hold(mutex_lock);
 
  506    fits_create_img(fptr,FLOAT_IMG,size.size(),
 
  507                    size.data(), &status);
 
  508    check_status(status);
 
  509    std::vector<long> fpixel(size.size(),1);
 
  510    fits_write_pix(fptr,TFLOAT,fpixel.data(),
 
  511                          im.size(),im.data(),&status);
 
  512    check_status(status);
 
  514  void write_image(
float *im,std::vector<long> &size){
 
  516    for(
size_t i : size) n *= i;
 
  518    std::lock_guard<std::mutex> hold(mutex_lock);
 
  519    fits_create_img(fptr,FLOAT_IMG,size.size(),
 
  520                    size.data(), &status);
 
  521    check_status(status);
 
  522    std::vector<long> fpixel(size.size(),1);
 
  523    fits_write_pix(fptr,TFLOAT,fpixel.data(),
 
  525    check_status(status);
 
  527  void write_image(std::valarray<double> &im,std::vector<long> &size){
 
  529    for(
size_t i : size) n *= i;
 
  530    assert(im.size() == n);
 
  532    std::lock_guard<std::mutex> hold(mutex_lock);
 
  533    fits_create_img(fptr,DOUBLE_IMG,size.size(),
 
  534                    size.data(), &status);
 
  535    check_status(status);
 
  538    std::vector<long> fpixel(size.size(),1);
 
  539    fits_write_pix(fptr,TDOUBLE,fpixel.data(),
 
  540                          im.size(),&im[0],&status);
 
  541    check_status(status);
 
  543  void write_image(std::valarray<float> &im,std::vector<long> &size){
 
  545    for(
size_t i : size) n *= i;
 
  546    assert(im.size() == n);
 
  548    std::lock_guard<std::mutex> hold(mutex_lock);
 
  549    fits_create_img(fptr,FLOAT_IMG,size.size(),
 
  550                    size.data(), &status);
 
  551    check_status(status);
 
  552    std::vector<long> fpixel(size.size(),1);
 
  553    fits_write_pix(fptr,TFLOAT,fpixel.data(),
 
  554                          im.size(),&im[0],&status);
 
  555    check_status(status);
 
  560  void write_image(std::vector<std::vector<T> > &im){
 
  561    std::vector<long> size(2);
 
  563    size[1] = im[0].size();
 
  566    std::vector<T> tmp(size[0]*size[1]);
 
  567    for(
long i=0; i<size[0] ; ++i){
 
  568      for(
long j=0; j<size[1] ; ++j){
 
  573    write_image(tmp,size);
 
  577  int writeKey(std::string key,std::string value,std::string comment ){
 
  579    char *s = strdup(value.c_str());
 
  580    std::lock_guard<std::mutex> hold(mutex_lock);
 
  581    int error = fits_write_key(fptr,TSTRING,key.c_str(),
 
  582                           s,comment.c_str(),&status);
 
  586  int writeKey(std::string key,
double value,std::string comment ){
 
  588    std::lock_guard<std::mutex> hold(mutex_lock);
 
  589    return fits_update_key(fptr,TDOUBLE,key.c_str(),
 
  590                           &value,comment.c_str(),&status);
 
  592  int writeKey(std::string key,
float value,std::string comment ){
 
  594    std::lock_guard<std::mutex> hold(mutex_lock);
 
  595    return fits_update_key(fptr,TFLOAT,key.c_str(),
 
  596                           &value,comment.c_str(),&status);
 
  598  int writeKey(std::string key,
int value,std::string comment ){
 
  600    std::lock_guard<std::mutex> hold(mutex_lock);
 
  601    return fits_update_key(fptr,TINT,key.c_str(),
 
  602                           &value,comment.c_str(),&status);
 
  604  int writeKey(std::string key,
long value,std::string comment ){
 
  606    std::lock_guard<std::mutex> hold(mutex_lock);
 
  607    return fits_update_key(fptr,TLONG,key.c_str(),
 
  608                           &value,comment.c_str(),&status);
 
  610  int writeKey(std::string key,
size_t value,std::string comment ){
 
  612    std::lock_guard<std::mutex> hold(mutex_lock);
 
  613    return fits_update_key(fptr,TULONG,key.c_str(),
 
  614                           &value,comment.c_str(),&status);
 
  618  int writeHeader(std::vector<std::string> &cards){
 
  620    for(
auto &str : cards){
 
  621      fits_write_record(fptr, str.c_str(), &status);
 
  627  void copyHeader(CPFITS_BASE &input){
 
  628    std::vector<std::string> cards;
 
  629    input.readHeader(cards);
 
  636class CPFITS_READ_TABLES : 
public CPFITS_BASE {
 
  645  void reset_tableInfo(){
 
  647    fits_get_num_rows(fptr, &Nrow, &status);
 
  648    fits_get_num_cols(fptr, &Ncol, &status);
 
  650  std::vector<std::string> col_names;
 
  652  int get_colnames(std::vector<std::string> &names){
 
  662    for(
auto &name : names){
 
  663      fits_get_colname(fptr,CASESEN,(
char*)(c.c_str()),colname, &colnum, &status);
 
  673  CPFITS_READ_TABLES(std::string filename,
int hdunum=2,
bool verbose = 
false) {
 
  676    fits_open_table(&fptr,filename.c_str(), READONLY, &status);
 
  677    check_status(status,
"Problem with input fits file.");
 
  680      fits_get_num_hdus(fptr, &num, &status);
 
  682        throw std::runtime_error(
"Not enough HDUs in " + filename);
 
  685      fits_movabs_hdu(fptr,hdunum, &hdutype,  &status);
 
  686      check_status(status,
"Problem with input fits file. HDU "+std::to_string(hdunum));
 
  687      if(hdutype != BINARY_TBL){
 
  688        std::cerr << 
"HDU " << hdunum << 
" in " << filename << 
" is not a binary table" << std::endl;
 
  689        throw std::runtime_error(
"wrong HDUs in " + filename);
 
  694    get_colnames(col_names);
 
  697      std::cerr << 
"No data was found in file " << filename << std::endl;
 
  701      std::cout << 
"Opening file : " << filename << std::endl;
 
  702      std::cout << Ncol << 
" columns" << std::endl;
 
  703      std::cout << Nrow << 
" rows" << std::endl;
 
  707  ~CPFITS_READ_TABLES(){
 
  709    fits_close_file(fptr, &status);
 
  712  CPFITS_READ_TABLES(
CPFITS_READ &&ff):CPFITS_BASE(std::move(ff)){};
 
  714  void operator=(CPFITS_READ_TABLES &&ff){
 
  715     CPFITS_BASE::operator=(std::move(ff));
 
  718  long rows(){
return Nrow;}
 
  719  long ncol(){
return Ncol;}
 
  721  int column_index(std::string &colname){
 
  724    fits_get_colnum(fptr, CASEINSEN,(
char*)(colname.c_str())
 
  727      check_status(status,
"Column does not exist.");
 
  729      std::cerr << 
"Missing column : " << colname << std::endl;
 
  730      throw std::invalid_argument(
"missing column");
 
  735  std::vector<std::string> get_colnames(){
return col_names;}
 
  737  int read_column(std::string &colname,std::vector<float> &vecf){
 
  739    int col, status=0,anyval=0;
 
  740    col = column_index(colname);
 
  742    if(vecf.size() < Nrow ) vecf.resize(Nrow);
 
  744    fits_read_col_flt(fptr, col, 1, 1,Nrow,0,
 
  745                      vecf.data(),&anyval, &status);
 
  749  int read_column(std::string &colname,
long firstsrow,
long nelements,std::vector<float> &vecf,
float nulval = -100){
 
  751    int status=0,anyval=0;
 
  752    int colnum = column_index(colname);
 
  754    if(vecf.size() < nelements ) vecf.resize(nelements);
 
  755    fits_read_col(fptr,TFLOAT,colnum, firstsrow, 1,nelements,&nulval,
 
  756                      vecf.data(),&anyval, &status);
 
  757    check_status(status);
 
  761  int read_column(
int colnum,
long firstsrow,
long nelements,std::vector<float> &vecf,
float nulval = -100){
 
  763    int status=0,anyval=0;
 
  765    if(vecf.size() < nelements ) vecf.resize(nelements);
 
  767    fits_read_col(fptr,TFLOAT,colnum, firstsrow, 1,nelements,&nulval,
 
  768                      vecf.data(), &anyval, &status);
 
  770    check_status(status);
 
  775  int read_column(std::string &colname,
long firstsrow,
long nelements,std::vector<double> &vecf,
double nulval = -100){
 
  777    int status=0,anyval=0;
 
  778    int colnum = column_index(colname);
 
  780    if(vecf.size() < nelements ) vecf.resize(nelements);
 
  781    fits_read_col(fptr,TDOUBLE,colnum, firstsrow, 1,nelements,&nulval,
 
  782                      vecf.data(),&anyval, &status);
 
  783    check_status(status);
 
  787  int read_column(
int colnum,
long firstsrow,
long nelements,std::vector<double> &vecf,
double nulval = -100){
 
  789    int status=0,anyval=0;
 
  791    if(vecf.size() < nelements ) vecf.resize(nelements);
 
  792    fits_read_col(fptr,TDOUBLE,colnum, firstsrow, 1,nelements,&nulval,
 
  793                      vecf.data(),&anyval, &status);
 
  794    check_status(status);
 
  798  int read_column(std::string &colname,
long firstsrow,
long nelements,std::vector<long> &vecf,
int nulval = -100){
 
  800    int status=0,anyval=0;
 
  801    int colnum = column_index(colname);
 
  803    if(vecf.size() < nelements ) vecf.resize(nelements);
 
  804    fits_read_col(fptr,TLONG,colnum, firstsrow, 1,nelements,&nulval,
 
  805                      vecf.data(),&anyval, &status);
 
  806    check_status(status);
 
  810  int read_column(
int colnum,
long firstsrow,
long nelements,std::vector<long> &vecf,
int nulval = -100){
 
  812    int status=0,anyval=0;
 
  814    if(vecf.size() < nelements ) vecf.resize(nelements);
 
  815    fits_read_col(fptr,TLONG,colnum, firstsrow, 1,nelements,&nulval,
 
  816                      vecf.data(),&anyval, &status);
 
  817    check_status(status);
 
  825    int typecode,status=0;
 
  827    fits_get_coltype(fptr,colnum,&typecode,
 
  828                     &repeat,&width,&status);
 
  829    check_status(status);
 
 
  834  int read_column(
int col_index,std::vector<float> &vecf){
 
  836    int status=0,anyval=0;
 
  839      std::cerr << 
"CPFITS: column number must be > 0" << std::endl;
 
  840      throw std::invalid_argument(
"Error in CPFITS");
 
  842    if(col_index > Ncol){
 
  843      std::cerr << 
"CPFITS: there are only " << Ncol << 
" columns." << std::endl;
 
  844      throw std::invalid_argument(
"Error in CPFITS");
 
  846    if(vecf.size() < Nrow ) vecf.resize(Nrow);
 
  848    fits_read_col_flt(fptr, col_index, 1, 1,Nrow,0,
 
  849                      vecf.data(),&anyval, &status);
 
  855  template <
typename T>
 
  856  void read(std::vector<T> data,
int ncol){
 
  858      int status = 0,anyval=0;
 
  859    long i, n, nread, ntodo, nrest;
 
  860    long buffer_size = 20000;
 
  861    std::vector<float> fitscol(buffer_size);
 
  863    for(
int col = 1 ; col != ncol ; ++col){
 
  868        ntodo = (nrest < buffer_size) ? nrest : buffer_size;
 
  869       fits_read_col_flt(fptr, col, nread + 1, 1, ntodo, 0,
 
  870                             fitscol.data(),&anyval, &status);
 
  871       for (i = 0; i < ntodo; i++) data[i + nread][col-1] = fitscol[i];
 
 
  884  template< 
typename T>
 
  888    std::map<std::string,int> datamap;
 
  889    std::vector<std::string> all_column_names;
 
  890    std::vector<std::string> used_column_names;
 
  891    std::string filename;
 
  892    CPFITS_READ_TABLES cpfits;
 
  893    std::vector<std::vector<T> > data;
 
  895    std::vector<int> column_index;
 
  901                  ,std::vector<std::string> &columns  
 
  903                  ,
bool verbose = 
false 
  904    ):filename(datafile),cpfits(filename,hdu,verbose),n0(1){
 
  906      all_column_names = cpfits.get_colnames();
 
  908      if(columns.size() == 0){
 
  909        used_column_names = all_column_names;
 
  911        used_column_names = columns;
 
  914      std::cout << 
"Reading " << used_column_names.size() << 
" columns." << std::endl;
 
  916      for(std::string a : used_column_names){
 
  917        column_index.push_back(cpfits.column_index(a));
 
  920      for(
int i=0 ; i<used_column_names.size() ; ++i){
 
  921        datamap[used_column_names[i]] = i;
 
  924      data.resize(column_index.size());
 
  928    std::vector<std::string> get_all_columnnames(){
return all_column_names;}
 
  929    std::vector<std::string> get_used_columnnames(){
return all_column_names;}
 
  934      int ncol=data.size();
 
  935      for(
int i=0; i<ncol ; ++i){
 
  947             std::vector<std::function<
bool(T &)> > &accept
 
  951      long chunksize = 10000;
 
  952      int ncol = column_index.size();
 
  953      long nrow = cpfits.rows();
 
  954      int requirements = accept.size();
 
  959        for(
int i=0; i<ncol ; ++i){
 
  964      if(maxsize > 0) nrow = MIN(maxsize + n0,nrow);
 
  966      if(requirements > ncol){
 
  967        throw std::invalid_argument(
"Too many requirments");
 
  970      std::vector<std::vector<T> > tdata(ncol);
 
  972        chunksize = MIN(nrow-n0+1,chunksize);
 
  974        if(data[0].capacity() - data[0].size() < chunksize ){
 
  975          for(
int i=0; i<ncol ; ++i){
 
  976            data[i].reserve(chunksize + data[i].capacity());
 
  980        for(
int i=0 ; i< ncol ; ++i){
 
  981          cpfits.read_column(column_index[i],n0,chunksize,tdata[i]);
 
  985        for(
long j = 0 ; j < chunksize ; ++j){
 
  987          for(
int i=0; i<requirements; ++i){
 
  988            accpt *= accept[i](tdata[i][j]);
 
  992            for(
int i=0; i<ncol ; ++i){
 
  993              data[i].push_back( tdata[i][j] ) ;
 
 1004             std::function<
bool(T,T)> &binary_accept
 
 1005             ,std::pair<int,int> index_binary                  
 
 1006             ,std::vector<std::function<
bool(T &)> > &unary_accept
 
 1007             ,std::vector<int> index_unary
 
 1011      long chunksize = 10000;
 
 1012      int ncol = column_index.size();
 
 1013      long nrow = cpfits.rows();
 
 1015      if(unary_accept.size() != index_unary.size() ) 
throw std::invalid_argument(
"index_unary wrong sized ");
 
 1020        for(
int i=0; i<ncol ; ++i){
 
 1025      if(maxsize > 0) nrow = MIN(maxsize + n0,nrow);
 
 1027      if(index_unary.size() > ncol){
 
 1028        throw std::invalid_argument(
"Too many requirments");
 
 1031      std::vector<std::vector<T> > tdata(ncol);
 
 1033        chunksize = MIN(nrow-n0+1,chunksize);
 
 1035        if(data[0].capacity() - data[0].size() < chunksize ){
 
 1036          for(
int i=0; i<ncol ; ++i){
 
 1037            data[i].reserve(chunksize + data[i].capacity());
 
 1041        for(
int i=0 ; i< ncol ; ++i){
 
 1042          cpfits.read_column(column_index[i],n0,chunksize,tdata[i]);
 
 1046        for(
long j = 0 ; j < chunksize ; ++j){
 
 1048          bool accpt = binary_accept(tdata[index_binary.first][j],tdata[index_binary.second][j] );
 
 1051          for(
int i : index_unary){
 
 1052            accpt *= unary_accept[k++]( tdata[i][j] );
 
 1056            for(
int i=0; i<ncol ; ++i){
 
 1057              data[i].push_back( tdata[i][j] ) ;
 
 1068    int read(
long maxsize=-1){
 
 1069      int ncol = column_index.size();
 
 1070      long nrow = cpfits.rows();
 
 1071      if(maxsize==-1) maxsize = nrow;
 
 1073      long chunksize = nrow-n0+1;
 
 1075      chunksize = (maxsize < chunksize) ? maxsize : chunksize;
 
 1077      for(
int i=0 ; i< ncol ; ++i){
 
 1078        cpfits.read_column(column_index[i],n0,chunksize,data[i]);
 
 1086    std::vector<std::vector<T> > ranges(
bool verbose){
 
 1087      std::vector<std::vector<T> > ranges;
 
 1088      int ncol = column_index.size();
 
 1089      long nrow = cpfits.rows();
 
 1090      long chunksize = 100000;
 
 1092      ranges.resize(ncol);
 
 1093      for(
auto &v : ranges) v.resize(2);
 
 1095      std::vector<T> tdata;
 
 1096      for(
int i=0 ; i< ncol ; ++i){
 
 1097        cpfits.read_column(column_index[i],1,1,tdata);
 
 1109        chunksize = (nrow-n+1 < chunksize) ? nrow-n+1 : chunksize;
 
 1112        for(
int i=0 ; i< ncol ; ++i){
 
 1113          cpfits.read_column(column_index[i],n,chunksize,tdata);
 
 1115            ranges[i][0] = MIN(a,ranges[i][0]);
 
 1116            ranges[i][1] = MAX(a,ranges[i][1]);
 
 1123        for(
int i=0 ; i< ncol ; ++i){
 
 1124          std::cout << ranges[i][0] << 
" <= " << used_column_names[i] << 
" <= " << ranges[i][1] << std::endl;
 
 1132    std::vector<T>& operator[](
const std::string &label){
 
 1133      if(datamap.find(label) == datamap.end()){
 
 1134        std::cerr << 
"No label - " << label << 
" - in " << filename <<std::endl;
 
 1135        throw std::invalid_argument(
"no label");
 
 1137      return data[datamap[label]];
 
 1138      for(
auto c : all_column_names ) std::cout << c << 
" ";
 
 1139      std::cout << std::endl;
 
 1140      throw std::invalid_argument(label + 
" was not one of the columns of the galaxy data file :" + filename);
 
 1144    std::vector<T>& operator[](
int i){
 
 1149    void sortby(std::string name){
 
 1150      std::vector<size_t> index(data[0].size());
 
 1151      size_t N = index.size();
 
 1152      for(
size_t i=0 ; i<N ; ++i) index[i] = i;
 
 1155      std::vector<T> tmp_v(N);
 
 1157      for(
size_t j=0 ; j<data.size() ; ++j){
 
 1158        for(
size_t i=0 ; i<N ; ++i){
 
 1159          tmp_v[i] = data[j][index[i]];
 
 1161        swap(data[j],tmp_v);
 
 1166    void addColumn(std::string name){
 
 1167      int nc =  number_of_columns();
 
 1168      long nr = number_of_rows();
 
 1169      data.emplace_back(nr);
 
 1170      all_column_names.push_back(name);
 
 1171      used_column_names.push_back(name);
 
 1176    size_t number_of_rows(){
return data[0].size();}
 
 1177    size_t number_of_columns(){
return data.size();}
 
int gettype(int colnum)
get data type of column
Definition cpfits.h:824
 
read only fits file interface
Definition cpfits.h:232
 
int read(std::vector< double > &output, std::vector< long > &size)
read the whole image into a vector
Definition cpfits.h:290
 
int read_subset(float *output, long *lowerleft, long *upperright)
read a rectangular subset of the image
Definition cpfits.h:398
 
int read_subset(double *output, long *lowerleft, long *upperright)
read a rectangular subset of the image
Definition cpfits.h:390
 
int read(std::valarray< float > &output, std::vector< long > &size)
read the whole image into a valarray
Definition cpfits.h:320
 
int read(std::vector< float > &output, std::vector< long > &size)
read the whole image into a vector
Definition cpfits.h:305
 
int read(std::vector< std::vector< T > > &output)
read the whole image into a vector
Definition cpfits.h:356
 
void reset(std::string filename, std::string extension="")
close old and reopen a new file
Definition cpfits.h:273
 
int read_block(double *output, long nelements, long *start)
read the whole image into a vector
Definition cpfits.h:375
 
void sort_indexes(const std::vector< T > &v, std::vector< size_t > &index)
Find the indexes that sort a vector in asending order.
Definition utilities_slsim.h:1171