regcntsSubs.c
/* open a data file and grab array of image data */
open a data file and grab array of image data
open a data file and grab array of image data
void regcntsGetData(Opts opts, Data d){
#ifdef USE_CFITSIO
  int ncard;
  int hdutype;
  int naxis;
  int start[IMDIM];
  int stop[IMDIM];
  long naxes[2];
  int status = 0;   
  char *cube=NULL;
  fitsfile *nfptr=NULL;
  d->fptr = openFITSFile(d->name, READONLY, EXTLIST, NULL, &hdutype, &status);
  regcntsErrchk(opts, status);
  switch(hdutype){
  case IMAGE_HDU:
    fits_get_img_dim(d->fptr, &naxis, &status);
    switch(naxis){
    case 2:
      break;
    case 3:
      if( !opts->cube ){
	opts->cube = "all";
	opts->dodata = 1;
	opts->docube = 1;
      }
      break;
    default:
      xerror(stderr, "2D or 3D images only (this image has %d)\n", naxis);
      break;
    }
    getHeaderToString(d->fptr, &d->cards, &ncard, &status);
    regcntsErrchk(opts, status);
    if( opts->dodata ){
      if( d->type == SRC || ((d->type == BKG) && d->fromsrc) ){
	cube = opts->cube;
      }
      d->data = getImageToArray(d->fptr, NULL, NULL, 1, 0, cube, NULL,
				 start, stop, &d->bitpix, &status);
      regcntsErrchk(opts, status);
    }
    d->dim1 = stop[0] - start[0] + 1;
    d->dim2 = stop[1] - start[1] + 1;
    if( opts->docube ){
      if( d->type == SRC || ((d->type == BKG) && d->fromsrc) ){
	d->curslice = 0;
	d->maxslice = stop[2] - start[2] + 1;
	d->szslice = d->dim1 * d->dim2 * abs(d->bitpix) / 8;
	d->data0 = d->data;
      }
    }
    break;
  default:
    nfptr = filterTableToImage(d->fptr, 
			       NULL, NULL, NULL, NULL, opts->bin, NULL,
			       &status);
    regcntsErrchk(opts, status);
    getHeaderToString(nfptr, &d->cards, &ncard, &status);
    regcntsErrchk(opts, status);
    if( opts->dodata ){
      d->data = getImageToArray(nfptr, NULL, NULL, 1, 0, NULL, NULL,
				start, stop, &d->bitpix, &status);
      regcntsErrchk(opts, status);
      d->dim1 = stop[0] - start[0] + 1;
      d->dim2 = stop[1] - start[1] + 1;
      closeFITSFile(nfptr, &status);
    } else {
      closeFITSFile(d->fptr, &status);
      regcntsErrchk(opts, status);
      d->fptr = nfptr;
    }
    break;
  }
  hlength(d->cards, 256000);
  d->wcs = wcsinit(d->cards);
  if( opts->dodata ){
    d->x0 = 1;
    d->x1 = d->dim1;
    d->y0 = 1;
    d->y1 = d->dim2;
    d->block = 1;
  } else {
    fits_get_img_size(d->fptr, 2, naxes, &status);
    regcntsErrchk(opts, status);
    d->x0 = 1;
    d->x1 = naxes[0];
    d->y0 = 1;
    d->y1 = naxes[1];
    d->block = 1;
  }
#elif USE_FUNTOOLS
  if( !(d->fun = FunOpen(d->name, "r", NULL)) ){
    xerror(stderr, "can't FunOpen file (or find extension): %s\n", d->name);
  }
  if( !(d->data = FunImageGet(d->fun, NULL, NULL)) ){
    xerror(stderr, "can't FunImageGet: %s\n", d->name);
  }
  FunInfoGet(d->fun,
	     FUN_HEADER, &d->header,
	     FUN_SECT_X0, &d->x0, FUN_SECT_X1, &d->x1,
	     FUN_SECT_Y0, &d->y0, FUN_SECT_Y1, &d->y1,
	     FUN_SECT_DIM1, &d->dim1, FUN_SECT_BLOCK, &d->block,
	     FUN_BITPIX, &d->bitpix, FUN_WCS, &d->wcs,
	     0);
  d->cards = ft_cards(d->header);
#endif
  if( d->wcs && iswcs(d->wcs) ){
    if( !d->wcs->coorflip ){
      d->dpp = ABS(d->wcs->cdelt[0]) * d->block;
    } else {
      d->dpp = ABS(d->wcs->cdelt[1]) * d->block;
    }
  }
}
void regcntsGetData ( Opts opts , Data d ) { #ifdef USE_CFITSIO int ncard ; int hdutype ; int naxis ; int start [ IMDIM ] ; int stop [ IMDIM ] ; long naxes [ 2 ] ; int status = 0 ; char * cube = NULL ; fitsfile * nfptr = NULL ; d -> fptr = openFITSFile ( d -> name , READONLY , EXTLIST , NULL , & hdutype , & status ) ; regcntsErrchk ( opts , status ) ; switch ( hdutype ) { case IMAGE_HDU : fits_get_img_dim ( d -> fptr , & naxis , & status ) ; switch ( naxis ) { case 2 : break ; case 3 : if ( ! opts -> cube ) { opts -> cube = " " ; opts -> dodata = 1 ; opts -> docube = 1 ; } break ; default : xerror ( stderr , " \n " , naxis ) ; break ; } getHeaderToString ( d -> fptr , & d -> cards , & ncard , & status ) ; regcntsErrchk ( opts , status ) ; if ( opts -> dodata ) { if ( d -> type == SRC || ( ( d -> type == BKG ) && d -> fromsrc ) ) { cube = opts -> cube ; } d -> data = getImageToArray ( d -> fptr , NULL , NULL , 1 , 0 , cube , NULL , start , stop , & d -> bitpix , & status ) ; regcntsErrchk ( opts , status ) ; } d -> dim1 = stop [ 0 ] - start [ 0 ] + 1 ; d -> dim2 = stop [ 1 ] - start [ 1 ] + 1 ; if ( opts -> docube ) { if ( d -> type == SRC || ( ( d -> type == BKG ) && d -> fromsrc ) ) { d -> curslice = 0 ; d -> maxslice = stop [ 2 ] - start [ 2 ] + 1 ; d -> szslice = d -> dim1 * d -> dim2 * abs ( d -> bitpix ) / 8 ; d -> data0 = d -> data ; } } break ; default : nfptr = filterTableToImage ( d -> fptr , NULL , NULL , NULL , NULL , opts -> bin , NULL , & status ) ; regcntsErrchk ( opts , status ) ; getHeaderToString ( nfptr , & d -> cards , & ncard , & status ) ; regcntsErrchk ( opts , status ) ; if ( opts -> dodata ) { d -> data = getImageToArray ( nfptr , NULL , NULL , 1 , 0 , NULL , NULL , start , stop , & d -> bitpix , & status ) ; regcntsErrchk ( opts , status ) ; d -> dim1 = stop [ 0 ] - start [ 0 ] + 1 ; d -> dim2 = stop [ 1 ] - start [ 1 ] + 1 ; closeFITSFile ( nfptr , & status ) ; } else { closeFITSFile ( d -> fptr , & status ) ; regcntsErrchk ( opts , status ) ; d -> fptr = nfptr ; } break ; } hlength ( d -> cards , 256000 ) ; d -> wcs = wcsinit ( d -> cards ) ; if ( opts -> dodata ) { d -> x0 = 1 ; d -> x1 = d -> dim1 ; d -> y0 = 1 ; d -> y1 = d -> dim2 ; d -> block = 1 ; } else { fits_get_img_size ( d -> fptr , 2 , naxes , & status ) ; regcntsErrchk ( opts , status ) ; d -> x0 = 1 ; d -> x1 = naxes [ 0 ] ; d -> y0 = 1 ; d -> y1 = naxes [ 1 ] ; d -> block = 1 ; } #elif USE_FUNTOOLS if ( ! ( d -> fun = FunOpen ( d -> name , " " , NULL ) ) ) { xerror ( stderr , " \n " , d -> name ) ; } if ( ! ( d -> data = FunImageGet ( d -> fun , NULL , NULL ) ) ) { xerror ( stderr , " \n " , d -> name ) ; } FunInfoGet ( d -> fun , FUN_HEADER , & d -> header , FUN_SECT_X0 , & d -> x0 , FUN_SECT_X1 , & d -> x1 , FUN_SECT_Y0 , & d -> y0 , FUN_SECT_Y1 , & d -> y1 , FUN_SECT_DIM1 , & d -> dim1 , FUN_SECT_BLOCK , & d -> block , FUN_BITPIX , & d -> bitpix , FUN_WCS , & d -> wcs , 0 ) ; d -> cards = ft_cards ( d -> header ) ; #endif if ( d -> wcs && iswcs ( d -> wcs ) ) { if ( ! d -> wcs -> coorflip ) { d -> dpp = ABS ( d -> wcs -> cdelt [ 0 ] ) * d -> block ; } else { d -> dpp = ABS ( d -> wcs -> cdelt [ 1 ] ) * d -> block ; } } }
open a data file and grab array of image data
open a data file and grab array of image data
/*  CFITSIO status value MUST be initialized to zero!  */ /* open the source FITS file */ // process based on hdu type // we can pny handle 2D images // get cards as a string // get image array // image from table // get cards as a string // get image array /* get wcs, if possible */ /* use entire image for the section */ /* open the source FITS file */ /* get image data in double format*/ /* get required information from funtools structure */ /* now see if we can get degrees/pixel from wcs */