Esempio n. 1
0
/** DEBUGGING */
void DbugR (void) 
{
#include "ObitIOImageFITS.h"
  fitsfile *myFptr;
  gchar *FileName = "../testIt/testCCMerge.fits";
  olong status = 0;
    
   /* DEBUG */
  fits_open_file(&myFptr, FileName, READWRITE, &status);
  fprintf (stderr, "DbugR open status %d\n", status);
  fits_close_file (myFptr, &status);
  fprintf (stderr, "DbugR close status %d\n", status);

} /* end DbugR */
Esempio n. 2
0
static void
fits_hdu_copy(struct fitsparams *p, int cut1_copy0, int *r)
{
  char *hdu;
  fitsfile *in, *out;
  int status=0, hdutype;
  gal_list_str_t *list = cut1_copy0 ? p->cut : p->copy;

  /* Open the output file. */
  out=gal_fits_open_to_write(p->cp.output);

  /* Copy all the given extensions. */
  while(list)
    {
      /* Pop-out the top element. */
      hdu=gal_list_str_pop(&list);

      /* Open the FITS file at the specified HDU. */
      in=gal_fits_hdu_open(p->filename, hdu,
                           cut1_copy0 ? READWRITE : READONLY);

      /* Copy to the extension. */
      if( fits_copy_hdu(in, out, 0, &status) )
        *r=fits_has_error(p, FITS_ACTION_COPY, hdu, status);

      /* If this is a `cut' operation, then remove the extension. */
      if(cut1_copy0)
        if( fits_delete_hdu(in, &hdutype, &status) )
          *r=fits_has_error(p, FITS_ACTION_REMOVE, hdu, status);

      /* Close the input file. */
      fits_close_file(in, &status);
    }

  /* Close the output file. */
  fits_close_file(out, &status);
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
    fitsfile *fptr;       /* pointer to the FITS file, defined in fitsio.h */

    int status, nkeys, keypos, hdutype, ii, jj;
    char filename[FLEN_FILENAME];    /* input FITS file */
    char card[FLEN_CARD];   /* standard string lengths defined in fitsioc.h */

    status = 0;

    if (argc == 1)
        strcpy(filename, "-");  /* no command line name, so assume stdin */
    else
        strcpy(filename, argv[1] );   /* name of file to list */


    if ( fits_open_file(&fptr, filename, READONLY, &status) ) 
         printerror( status );

    /* get the current HDU number */
    fits_get_hdu_num(fptr, &ii);

    /* attempt to move to next HDU, until we get an EOF error */
    for (; !(fits_movabs_hdu(fptr, ii, &hdutype, &status) ); ii++) 
    {
        /* get no. of keywords */
        if (fits_get_hdrpos(fptr, &nkeys, &keypos, &status) )
            printerror( status );

        printf("Header listing for HDU #%d:\n", ii);
        for (jj = 1; jj <= nkeys; jj++)  {
            if ( fits_read_record(fptr, jj, card, &status) )
                 printerror( status );

            printf("%s\n", card); /* print the keyword card */
        }
        printf("END\n\n");  /* terminate listing with END */
    }

    if (status == END_OF_FILE)   /* status values are defined in fitsio.h */
        status = 0;              /* got the expected EOF error; reset = 0  */
    else
       printerror( status );     /* got an unexpected error                */

    if ( fits_close_file(fptr, &status) )
         printerror( status );

    return(0);
}
Esempio n. 4
0
double get_average(std::string filename) {
	fitsfile *fptr;   /* FITS file pointer, defined in fitsio.h */
	int status = 0;   /* CFITSIO status value MUST be initialized to zero! */
	int bitpix, naxis, ii;
	long naxes[2] = {1,1}, fpixel[2] = {1,1};
	double *pixels;

	std::vector<double> values; //stores the values of all pixels in image

	if (!fits_open_file(&fptr, filename.c_str(), READONLY, &status))
	{
		if (!fits_get_img_param(fptr, 2, &bitpix, &naxis, naxes, &status) )
		{
			if (naxis > 2 || naxis == 0)
				printf("Error: only 1D or 2D images are supported\n");
			else
			{
				/* get memory for 1 row */
				pixels = (double *) malloc(naxes[0] * sizeof(double));

				if (pixels == NULL) {
					printf("Memory allocation error\n");
					return(1);
				}

				/* loop over all the rows in the image, top to bottom */
				for (fpixel[1] = naxes[1]; fpixel[1] >= 1; fpixel[1]--)
				{
					if (fits_read_pix(fptr, TDOUBLE, fpixel, naxes[0], NULL,
							pixels, NULL, &status) )  /* read row of pixels */
						break;  /* jump out of loop on error */
					for (ii = 0; ii < naxes[0]; ii++) {
						values.push_back(pixels[ii]);
					}
				}
				free(pixels);
			}
		}
		fits_close_file(fptr, &status);
	}

	if (status) fits_report_error(stderr, status); /* print any error message */

	//report average of values
	double sum = 0;
	for (int i=0; i < values.size(); i++)
		sum += values[i];
	return sum/values.size();
}
Esempio n. 5
0
void save_3d_image(SimulationData &sim_data, WaveFunction &psi, const char * fits_file_name) {

	fitsfile *fptr;
	int status = 0;
	long fpixel = 1, naxis = 3, nelements;
	long naxes[3] = {sim_data.get_num_x(), sim_data.get_num_y(), sim_data.get_num_z()};

	fits_create_file(&fptr, fits_file_name, &status);
	fits_create_img(fptr, DOUBLE_IMG, naxis, naxes, &status);
	nelements = naxes[0] * naxes[1] * naxes[2];
	fits_write_img(fptr, TDOUBLE, fpixel, nelements, psi.abs_psi, &status);
	fits_close_file(fptr, &status);
	fits_report_error(stderr, status);	

}
Esempio n. 6
0
bool Fits2D::readStringKeyword(string keyword, string &value){

    char *ptr = NULL;

    int status = 0;

    fitsfile *fptr;

    const char * filename;

    char v[40];

    filename = mFitsPath.c_str();


    if(fits_open_file(&fptr, filename, READONLY, &status)){

        printerror(status);
        return false;

    }

    char * key = new char[keyword.length()+1];
    strcpy(key,keyword.c_str());

    if(fits_read_key(fptr, TSTRING, key, v, NULL, &status)){


        printerror(status);
        delete key;
        return false;

    }

    value = string(v);

    delete key;

    if(fits_close_file(fptr, &status)){

        printerror(status);
        return false;

    }

    return true;
}
Esempio n. 7
0
int nemo_main(void)
{
    fitsfile *fptr;       /* pointer to the FITS file; defined in fitsio.h */
    int status, ii, jj;
    long  fpixel = 1, naxis = 2, nelements, exposure;
    long naxes[2] = { 300, 200 };   /* image is 300 pixels wide by 200 rows */
    short array[200][300];
    string fname = getparam("out");
    float time4 = PI;
    double time8 = PI;

    status = 0;         /* initialize status before calling fitsio routines */
    fits_create_file(&fptr, fname, &status);   /* create new file */

    /* Create the primary array image (16-bit short integer pixels */
    fits_create_img(fptr, SHORT_IMG, naxis, naxes, &status);

    /* Write a keyword; must pass the ADDRESS of the value */
    exposure = 1500.;
    fits_update_key(fptr, TLONG, "EXPOSURE", &exposure,
         "Total Exposure Time", &status);
    dprintf(1,"exposure %d\n",status);
    fits_update_key(fptr, TFLOAT, "TIME4", &time4,
		    "Sample REAL*4", &status);    
    dprintf(1,"time4    %d\n",status);
    fits_update_key(fptr, TDOUBLE, "TIME8", &time8,
		    "Sample REAL*8", &status);
    dprintf(1,"time8    %d\n",status);
    fits_update_key(fptr, TSTRING, "DATEOBS", "2001/09/30",
		    "Sample STRING", &status);
    dprintf(1,"string   %d\n",status);

    /* Initialize the values in the image with a linear ramp function */
    for (jj = 0; jj < naxes[1]; jj++)
        for (ii = 0; ii < naxes[0]; ii++)
            array[jj][ii] = ii + jj;

    nelements = naxes[0] * naxes[1];          /* number of pixels to write */

    /* Write the array of integers to the image */
    fits_write_img(fptr, TSHORT, fpixel, nelements, array[0], &status);

    fits_close_file(fptr, &status);            /* close the file */

    fits_report_error(stderr, status);  /* print out any error messages */
    return status ;
}
Esempio n. 8
0
int write_map(const char *filename, double *intensity, double *q, double *u, long nrows)
{
    
    fitsfile *fptr;
    int status = 0;
    int hdutype;
    int tfields=3;
    char extname[] = "BINTABLE";   /* extension name */
    char *ttype[] = { "I","Q","U" };
    char *tform[] = { "1E","1E","1E" };
    char *tunit[] = { " "," ", " " };
    if (fits_create_file(&fptr, filename, &status)) 
    fprintf(stderr, "%s (%d): Could not create new fits file.\n", 
        __FILE__, __LINE__);

    /* move to 1st HDU  */
    fits_movabs_hdu(fptr, 1, &hdutype, &status);
    //long nrows = 12L*nside*nside*2;
    //long nside = sqrtl(nrows/12L);
    long nside = 1024; //FIXME compute it

    /* append a new empty binary table onto the FITS file */
    fits_create_tbl( fptr, BINARY_TBL, nrows, tfields, ttype, tform,
            tunit, extname, &status);

    fits_write_key(fptr, TSTRING, "ORDERING", "NESTED", 
             "Pixel ordering scheme, either RING or NESTED", &status);

    fits_write_key(fptr, TLONG, "NSIDE", &nside, "Resolution parameter for HEALPIX", &status);
    long firstrow  = 1;  /* first row in table to write   */
    long firstelem = 1;  /* first element in row  (ignored in ASCII tables)  */

    if (fits_write_col(fptr, TDOUBLE, 1, firstrow, firstelem, nrows, intensity,
             &status))
    fprintf(stderr, "%s (%d): Could not write signal.\n", __FILE__, __LINE__);
    if (fits_write_col(fptr, TDOUBLE, 2, firstrow, firstelem, nrows, q,
             &status))
    fprintf(stderr, "%s (%d): Could not write signal.\n", __FILE__, __LINE__);
    if (fits_write_col(fptr, TDOUBLE, 3, firstrow, firstelem, nrows, u,
             &status))
    fprintf(stderr, "%s (%d): Could not write signal.\n", __FILE__, __LINE__);

    fits_close_file(fptr, &status);

    return true;
}
Esempio n. 9
0
local void print_ccd(real **ccd, char filename[], real t_exposure) { 

    fitsfile *fptr;
    int status, ii, jj;
    long  fpixel, nelements, exposure;
    //    unsigned short array[512][512];  
    unsigned short array[XCCD_MAX][YCCD_MAX];  

//    char filename[] = "ccd.fit";
    int bitpix   =  USHORT_IMG; 
    long naxis    =   2;
    //    long naxes[2] = { 512, 512 }; 
    long naxes[2] = { XCCD_MAX, YCCD_MAX }; 

    remove(filename); 
    status = 0;


    if (fits_create_file(&fptr, filename, &status)) 
         printf("%s\n", status);       

    if ( fits_create_img(fptr,  bitpix, naxis, naxes, &status) )
         printf("%s\n", status);     

    float val;
    for (jj = 0; jj < naxes[1]; jj++) {   
      for (ii = 0; ii < naxes[0]; ii++) {
//          cin >> val;
            array[jj][ii] = (unsigned short)ccd[jj][ii];
        }
    }

    fpixel = 1;
    nelements = naxes[0] * naxes[1]; 

    if ( fits_write_img(fptr, TUSHORT, fpixel, nelements, array[0], &status) )
         printf("%s\n", status);

    exposure = long(t_exposure);
    if ( fits_update_key(fptr, TLONG, "EXPOSURE", &exposure,
         "Exposure time in seconds", &status) )
         printf("%s\n", status);  

    if ( fits_close_file(fptr, &status) )  
         printf("%s\n", status);        
}
Esempio n. 10
0
int write2Dfits(char *fname, double *f, int pwidth, int pheight)
{
  /*  write out image as a fits file */

  fitsfile *afptr;
  int status = 0;
  int anaxis;
  long anaxes[2], fpixel[2]={1,1};
  int bitpix;
  int size;

  bitpix = -32;
  anaxis = 2;
  anaxes[0] = pwidth;
  anaxes[1] = pheight;

  size = anaxes[0]*anaxes[1];

  fits_create_file(&afptr, fname, &status);
  fits_create_img(afptr, bitpix, anaxis, anaxes, &status);

  if (status) {
    fits_report_error(stderr, status); /* print error message */
    return(status);
  }

  /* write all data into image array */
  if (fits_write_pix(afptr, TDOUBLE, fpixel, size, f, &status) )
    {
      printf(" error reading pixel data \n");
      exit (2);
    }

  /* close the fits file */

  fits_close_file(afptr, &status);

  if (status) {
    fits_report_error(stderr, status); /* print error message */
    exit(2);
  }

  return 0;

}
Esempio n. 11
0
str
FITStest(int *res, str *fname)
{
	fitsfile *fptr;       /* pointer to the FITS file, defined in fitsio.h */
	str msg = MAL_SUCCEED;
	int status = 0, hdutype;

	*res = 0;
	if (fits_open_file(&fptr, *fname, READONLY, &status))
		msg = createException(MAL, "fits.test", "Missing FITS file %s", *fname);
	else {
		fits_movabs_hdu(fptr, 2, &hdutype, &status);
		*res = hdutype;
		fits_close_file(fptr, &status);
	}

	return msg;
}
Esempio n. 12
0
struct wcsprm *
gal_wcs_read(char *filename, char *hdu, size_t hstartwcs,
             size_t hendwcs, int *nwcs)
{
  int status=0;
  fitsfile *fptr;
  struct wcsprm *wcs;

  /* Check HDU for realistic conditions: */
  fptr=gal_fits_hdu_open_format(filename, hdu, 0);

  /* Read the WCS information: */
  wcs=gal_wcs_read_fitsptr(fptr, hstartwcs, hendwcs, nwcs);

  /* Close the FITS file and return. */
  fits_close_file(fptr, &status);
  gal_fits_io_error(status, NULL);
  return wcs;
}
//----------------------------------------------------------------------------------
void save_to_fits(double *lensed_map, int nlx, int nly, char *lensed_fits) {

    fitsfile *fptr_out;
    int fpixel_out = 1;
    long bitpix_out =  DOUBLE_IMG;
    long naxis_out = 2;
    long npixels_out = nlx*nly;
    long naxes_out[naxis_out];
    naxes_out[0] = nlx;
    naxes_out[1] = nly;

    int status = 0;

    remove(lensed_fits);
    fits_create_file(&fptr_out, lensed_fits, &status);
    fits_create_img(fptr_out,  bitpix_out, naxis_out, naxes_out, &status);
    fits_write_img(fptr_out, TDOUBLE, fpixel_out, npixels_out, lensed_map, &status);
    fits_close_file(fptr_out, &status);
}
Esempio n. 14
0
// Reads a Healpix FITS file containing the map2alm weights into a double array:
int ReadHealpixWeights(int col, int nside, double *weights) {
  char message[200];
  std::string filename;
  fitsfile *fpointer;
  int status=0, anynul=0;
  long i, firstrow=1, firstelem=1, nelements=2*nside;
  double *nulval;
  
  filename = HEALPIX_DATA;
  if (filename.at(filename.length()-1)!='/') filename = filename+"/";
  filename = filename+"weight_ring_n"+ZeroPad(nside, 10000)+".fits";

  // Open file:
  fits_open_table(&fpointer, filename.c_str(), READONLY, &status);
  if (status!=0) {
    sprintf(message, "ReadHealpixWeights: could not open table in FITS file, ERR=%d", status);
    warning(message);
  }
  
  // Prepare to, read and check for errors:
  nulval = vector<double>(0, nelements-1);
  for(i=0; i<nelements; i++) nulval[i]=666.0;
  fits_read_col(fpointer, TDOUBLE, col, firstrow, firstelem, nelements, nulval, weights, &anynul, &status);
  if (status!=0) {
    sprintf(message, "ReadHealpixWeights: problem reading column in FITS file table, ERR=%d", status);
    warning(message);
  }
  if(anynul!=0) {
    warning("ReadHealpixWeights: found NULL values in FITS table");
    printf("They are:\n");
    for (i=0; i<nelements; i++) printf("%g ",nulval[i]);
    printf("\n");
  }
  free_vector(nulval, 0, nelements-1);

  // Close file and exit:
  fits_close_file(fpointer, &status);
  if (status!=0) {
    sprintf(message, "ReadHealpixWeights: could not close FITS file, ERR=%d", status);
    warning(message);
  }
  return status;
}
int showkey(char *filename, char *keyword)
{
/*
	function showkey displays keyword and value

	if keyword is COMMENT or HISTORY, it displays all respective lines.

*/


	fitsfile *fptr;         /* FITS file pointer, defined in fitsio.h */
	char card[FLEN_CARD];
	int status = 0, nkeys, i;   /*  CFITSIO status value MUST be initialized to zero!  */

	if (!fits_open_file(&fptr, filename, READONLY, &status))
	{
		for (i=0; i<FLEN_CARD; i++) 
			keyword[i]=toupper(keyword[i]);
		if ( !strcmp(keyword, "COMMENT") || !strcmp(keyword, "HISTORY")) {
			fits_get_hdrspace(fptr, &nkeys, NULL, &status); /* get # of keywords */
			for (i = 1; i <= nkeys; i++) { /* Read and print each keywords */
				if (fits_read_record(fptr, i, card, &status))
					break;
				if ( !strncmp(card, keyword, 7) )
					printf("%s\n", card);
			}
		}
		else {
			if (fits_read_card(fptr, keyword, card, &status))
			{
				printf("Keyword does not exist\n");
				status = 0;  /* reset status after error */
			}
			else 
				printf("%s\n",card);
		}
		fits_close_file(fptr, &status);
	}    /* open_file */

	/* if error occured, print out error message */
	if (status) fits_report_error(stderr, status);
	return(status);
}
Esempio n. 16
0
/* Shut down. Can be called many times.
 */
static void
vips_fits_close( VipsFits *fits )
{
	VIPS_FREE( fits->filename );
	VIPS_FREEF( vips_g_mutex_free, fits->lock );

	if( fits->fptr ) {
		int status;

		status = 0;

		if( fits_close_file( fits->fptr, &status ) ) 
			vips_fits_error( status );

		fits->fptr = NULL;
	}

	VIPS_FREE( fits->buffer );
}
void readheader( char *filename )

     /**********************************************************************/
     /* Print out all the header keywords in all extensions of a FITS file */
     /**********************************************************************/
{
  fitsfile *fptr;       /* pointer to the FITS file, defined in fitsio.h */

  int status, nkeys, keypos, hdutype, ii, jj;
  char card[FLEN_CARD];   /* standard string lengths defined in fitsioc.h */

  status = 0;

  if ( fits_open_file(&fptr, filename, READONLY, &status) ) 
    printerror( status, __LINE__ );

  /* attempt to move to next HDU, until we get an EOF error */
  for (ii = 1; !(fits_movabs_hdu(fptr, ii, &hdutype, &status) ); ii++) 
    {
      /* get no. of keywords */
      if (fits_get_hdrpos(fptr, &nkeys, &keypos, &status) )
	printerror( status, __LINE__ );

      printf("Header listing for HDU #%d:\n", ii);
      for (jj = 1; jj <= nkeys; jj++)  {
	if ( fits_read_record(fptr, jj, card, &status) )
	  printerror( status, __LINE__ );

	printf("%s\n", card); /* print the keyword card */
      }
      printf("END\n\n");  /* terminate listing with END */
    }

  if (status == END_OF_FILE)   /* status values are defined in fitsioc.h */
    status = 0;              /* got the expected EOF error; reset = 0  */
  else
    printerror( status, __LINE__ );     /* got an unexpected error                */

  if ( fits_close_file(fptr, &status) )
    printerror( status, __LINE__ );

  return;
}
Esempio n. 18
0
FitsReader& FitsReader::operator=(const FitsReader& rhs)
{
	_filename = rhs._filename;
	_imgWidth = rhs._imgWidth;
	_imgHeight = rhs._imgHeight;
	_nFrequencies = rhs._nFrequencies;
	_phaseCentreRA = rhs._phaseCentreRA;
	_phaseCentreDec = rhs._phaseCentreDec;
	_pixelSizeX = rhs._pixelSizeX;
	_pixelSizeY = rhs._pixelSizeY;
	_phaseCentreDL = rhs._phaseCentreDL;
	_phaseCentreDM = rhs._phaseCentreDM;
	_frequency = rhs._frequency;
	_bandwidth = rhs._bandwidth;
	_dateObs = rhs._dateObs;
	_hasBeam = rhs._hasBeam;
	_beamMajorAxisRad = rhs._beamMajorAxisRad;
	_beamMinorAxisRad = rhs._beamMinorAxisRad;
	_beamPositionAngle = rhs._beamPositionAngle;
	_polarization = rhs._polarization;
	_unit = rhs._unit;
	_telescopeName = rhs._telescopeName;
	_observer = rhs._observer;
	_objectName = rhs._objectName;
	_origin = rhs._origin;
	_originComment = rhs._originComment;
	_history = rhs._history;
	
	int status = 0;
	fits_close_file(_fitsPtr, &status);
	checkStatus(status, _filename);
	
	fits_open_file(&_fitsPtr, _filename.c_str(), READONLY, &status);
	checkStatus(status, _filename);
	
	// Move to first HDU
	int hduType;
	fits_movabs_hdu(_fitsPtr, 1, &hduType, &status);
	checkStatus(status, _filename);
	if(hduType != IMAGE_HDU) throw std::runtime_error("First HDU is not an image");
	return *this;
}
Esempio n. 19
0
void	writeimage(const image_t *image, const char *filename) {
	if (debug) {
		fprintf(stderr, "%s:%d: writing image %s\n", __FILE__, __LINE__,
			filename);
	}
	char	errmsg[80];
	int	status = 0;
	fitsfile	*fits = NULL;
	if (fits_create_file(&fits, filename, &status)) {
		fits_get_errstatus(status, errmsg);
		fprintf(stderr, "cannot create fits file %s: %s\n",
			filename, errmsg);
		return;
	}

	// find dimensions of pixel array
	int	naxis = 2;
	long	naxes[2] = { image->width, image->height };
	if (fits_create_img(fits, DOUBLE_IMG, naxis, naxes, &status)) {
		fits_get_errstatus(status, errmsg);
		fprintf(stderr, "cannot create image: %s\n", errmsg);
		goto bad;
	}

	// read the pixel data
	long	npixels = image->width * image->height;
	long	firstpixel[3] = { 1, 1, 1 };
	if (fits_write_pix(fits, TDOUBLE, firstpixel, npixels,
			image->data, &status)) {
		fits_get_errstatus(status, errmsg);
		fprintf(stderr, "cannot write pixel data: %s\n", errmsg);
	}

bad:
	// close the file
	if (fits_close_file(fits, &status)) {
		fits_get_errstatus(status, errmsg);
		fprintf(stderr, "cannot close fits file %s: %s\n",
			filename, errmsg);
		goto bad;
	}
}
Esempio n. 20
0
/**
 * Function: get_num_extensions
 * The function determines the number of extensions in
 * the fits file. Here the primary extension does not count.
 *
 * Parameters:
 * @param  spectral_models_file - pathname to the spectral models file
 *
 * Returns:
 * @return n_models              - the number of spectral models
 */
int
get_num_extensions(const char spectral_models_file[])
{
  int n_ext=0;
  int n_models=0;
  int i;
  int f_status=0;


  fitsfile *s_models;

  // open the fits file
  // report any error
  fits_open_file (&s_models, spectral_models_file, READONLY, &f_status);
  if (f_status)
    {
      ffrprt (stderr, f_status);
      aXe_message (aXe_M_FATAL, __FILE__, __LINE__,
		   "aXe_PETCONT: " "Could not open file: %s",
		   spectral_models_file);
    }

  // do until a fits error occurs
  while (!f_status)
    {
      // move one extension forward
      fits_movrel_hdu (s_models, 1, NULL, &f_status);

      // count up
      n_ext++;
    }
  
  // close the fits file
  fits_close_file (s_models, &f_status);

  // the zeroth extension
  // does nnot count!!
  n_models = n_ext - 1;
  
  // return the 
  return n_models;
}
Esempio n. 21
0
int	WriteFITS(unsigned short *buffer, int cols, int rows, char *filename) {
#ifdef HAVE_FITSIO_H
	int	status = 0;
	fitsfile	*fits;
	unlink(filename);
	fits_create_file(&fits, filename, &status);
	if (status) {
		std::cerr << "cannot create file " << filename << std::endl;
		return -1;
	}
	long	naxes[2] = { cols, rows };
	fits_create_img(fits, SHORT_IMG, 2, naxes, &status);
	long	fpixel[2] = { 1, 1 };
	fits_write_pix(fits, TUSHORT, fpixel, cols * rows, buffer, &status);
	fits_close_file(fits, &status);
#else
	std::cerr << "FITS not supported" << std::endl;
	return -1;
#endif
}
Esempio n. 22
0
File: data.c Progetto: glenco/lensed
void write_output(const char* filename, size_t width, size_t height, size_t noutput, cl_float* output[], const char* names[])
{
    int status = 0;
    
    // the FITS file
    fitsfile* fptr;
    
    // create FITS file
    fits_create_file(&fptr, filename, &status);
    
    // write FITS file
    write_fits(fptr, TFLOAT, width, height, noutput, (void**)output, names, &status);
               
    // close FITS file
    fits_close_file(fptr, &status);
    
    // report FITS errors
    if(status)
        fits_error(filename, status);
}
Esempio n. 23
0
FITSImage::~FITSImage()
{
    int status=0;

    delete(image_buffer);

    if (starCenters.count() > 0)
        qDeleteAll(starCenters);

    delete (wcs_coord);

    if (fptr)
    {
        fits_close_file(fptr, &status);

        if (tempFile)
             QFile::remove(filename);

    }
}
void save_file( const std::string& filename, const image_type& img ) {
	fitsfile* f;
	int status = 0;

    std::string fname = "!" + filename;
	fits_create_file( &f, fname.c_str(), &status );
	
	long dims[2];
	dims[0] = img.extents.first;	dims[1] = img.extents.second;

	typedef CFitsIOTypeMap<	image_type::element > map;
	fits_create_img( f, map::image_type, 2, dims, &status );
	fits_write_img( f, map::type, 1, img.num_elements(), 
		(void*)img.ptr(), &status );
        
    fits_close_file( f, &status );

	if( status ) {
		fits_report_error( stderr, status );
	}
}
Esempio n. 25
0
File: fits.c Progetto: f7753/monetdb
str FITSdirpat(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
	str msg = MAL_SUCCEED;
	str dir = *getArgReference_str(stk, pci, 1);
	str pat = *getArgReference_str(stk, pci, 2);
	fitsfile *fptr;
	char *s;
	int status = 0;
	glob_t globbuf;
	char fulldirectory[BUFSIZ];
	size_t j = 0;

	(void)mb;
	globbuf.gl_offs = 0;
	snprintf(fulldirectory, BUFSIZ, "%s%s", dir, pat);
	glob(fulldirectory, GLOB_DOOFFS, NULL, &globbuf);

	/*	fprintf(stderr,"#fulldir: %s \nSize: %lu\n",fulldirectory, globbuf.gl_pathc);*/

	if (globbuf.gl_pathc == 0)
		throw(MAL, "listdir", "Couldn't open the directory or there are no files that match the pattern");

	for (j = 0; j < globbuf.gl_pathc; j++) {
		char stmt[BUFSIZ];
		char fname[BUFSIZ];

		s = stmt;
		snprintf(fname, BUFSIZ, "%s", globbuf.gl_pathv[j]);
		status = 0;
		fits_open_file(&fptr, fname, READONLY, &status);
		if (status == 0) {
			snprintf(stmt, BUFSIZ, ATTACHDIR, fname);
			msg = SQLstatementIntern(cntxt, &s, "fits.listofdirpat", TRUE, FALSE, NULL);
			fits_close_file(fptr, &status);
			break;
		}
	}

	return msg;
}
Esempio n. 26
0
// Function which determines if file is of type spSpec, spPlate
int SDSS_filetype(char *infile, int *nspec){
	// return value:
	// 0 = spSpec
	// 1 = spPlate
	// 2 = spec
	int val = 0;
	int hdunum_exp = 0;

	fitsfile *infits;
	int status = 0, hdunum = 0;
	//printf("Name of File: %s\n", infile);
	fits_open_file(&infits, infile, READONLY, &status);
	fits_get_num_hdus(infits, &hdunum, &status);
	//printf("HDUNumber: %i\n\n", hdunum);


	// Number of HDUs not necessarily 9. In some cases might be different
	if( strstr(infile, "spSpec") != NULL ){
		val = 0;
		hdunum_exp = 7;
		//if(hdunum != hdunum_exp) warnmsg("Number of HDUs is not %d as expected from spSpec", hdunum_exp);
	}
	if( strstr(infile, "spPlate") != NULL ){
		val = 1;
		hdunum_exp = 9;
		//if(hdunum != hdunum_exp) warnmsg("Number of HDUs is not %d as expected from spPlate", hdunum_exp);
		fits_read_key(infits, TINT, "NAXIS2", nspec, NULL, &status);
	}
	if( strstr(infile, "spec-") != NULL ){
		val = 2;
		hdunum_exp = 14;
		//if(hdunum != hdunum_exp) warnmsg("Number of HDUs is not %d as expected from spec", hdunum_exp);
	}

	// report Error. TODO: Decide if want to use errormsg instead.
	fits_close_file(infits, &status);
	fits_report_error(stderr, status);

	return val;
}
Esempio n. 27
0
int
vips__fits_isfits( const char *filename )
{
	fitsfile *fptr;
	int status;

	VIPS_DEBUG_MSG( "isfits: testing \"%s\"\n", filename );

	status = 0;

	if( fits_open_image( &fptr, filename, READONLY, &status ) ) {
		VIPS_DEBUG_MSG( "isfits: error reading \"%s\"\n", filename );
#ifdef VIPS_DEBUG
		vips_fits_error( status );
#endif /*VIPS_DEBUG*/

		return( 0 );
	}
	fits_close_file( fptr, &status );

	return( 1 );
}
Esempio n. 28
0
bool Fits2D::readDoubleKeyword(string keyword, double &value){

    char *ptr = NULL;

    int status = 0;

    fitsfile *fptr;

    const char * filename;

    filename = mFitsPath.c_str();

    if(fits_open_file(&fptr, filename, READONLY, &status)){

        printerror(status);
        return false;
    }

    char * key = new char[keyword.length()+1];
    strcpy(key,keyword.c_str());

    if(fits_read_key(fptr, TDOUBLE, key, &value, NULL, &status)){

        printerror(status);
        delete key;
        return false;
    }

    delete key;

    if(fits_close_file(fptr, &status)){

        printerror(status);
        return false;

    }

    return true;
}
Esempio n. 29
0
//----------------------------------------------------------------------------------
double *read_data_fits(char *source_fits,long nx,long ny) {

    fitsfile *fptr_in;
    int status, anynull;
    long fpixel,npixels;

    double nullval;
    status = 0;

    fits_open_file(&fptr_in, source_fits, READONLY, &status);

    npixels  = nx*ny;
    fpixel	 = 1;
    nullval  = 0;

    double *source_map = (double *)malloc(npixels*sizeof(double));
    fits_read_img(fptr_in, TDOUBLE, fpixel, npixels, &nullval,source_map, &anynull, &status);
    fits_close_file(fptr_in, &status);

    //printf("%ld %ld %ld\n", i,j,npixels);
    return source_map;
}
Esempio n. 30
0
void c_tbtclo (IRAFPointer tp) {

/* Close a table.
argument:
IRAFPointer tp          i: table descriptor
*/

        TableDescr *tbl_descr;
        fitsfile *fptr;         /* CFITSIO pointer */
        int status = 0;

        if (tp == NULL)
            return;

        tbl_descr = (TableDescr *)tp;
        fptr = tbl_descr->fptr;

        /* fits_close_file = ffclos */
        fits_close_file (fptr, &status);

        free_tp (tp);
}