/** Opens a FITS file. * \param[in] fileName The name of the file to open. * \param[in] openMode Mask defining how the file should be opened; bits are * NDFileModeRead, NDFileModeWrite, NDFileModeAppend, NDFileModeMultiple * \param[in] pArray A pointer to an NDArray; this is used to determine the array and attribute properties. */ asynStatus NDFileFITS::openFile(const char *fileName, NDFileOpenMode_t openMode, NDArray *pArray) { static const char *functionName = "openFile"; // We don't support reading yet if (openMode & NDFileModeRead) return(asynError); // We don't support opening an existing file for appending yet if (openMode & NDFileModeAppend) return(asynError); // At present only 16 bits unsigned images are valid. if (pArray->dataType != NDUInt16) return(asynError); //>>>>>>>>>>>>>>if (FITSType != 0) return(asynError); fitsStatus = 0; if(fits_create_file(&fitsFilePtr, fileName, &fitsStatus)) {// create new FITS file // get the error description fits_get_errstatus(fitsStatus, fits_status_str); asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s::%s error opening file %s error=%s\n", driverName, functionName, fileName, fits_status_str); fits_clear_errmsg(); return (asynError); } return(asynSuccess); }
/** Writes single NDArray to the FITS file. * \param[in] pArray Pointer to the NDArray to be written */ asynStatus NDFileFITS::writeFile(NDArray *pArray) { static const char *functionName = "writeFile"; asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: %lu, %lu\n", driverName, functionName, (unsigned long)pArray->dims[0].size, (unsigned long)pArray->dims[1].size); NDArrayInfo arrayInfo; pArray->getInfo(&arrayInfo); int nx = (int) arrayInfo.xSize; int ny = (int) arrayInfo.ySize; long naxis = 2; // 2-dimensional image long naxes[2] = { nx, ny }; fitsStatus = 0; if(fits_create_img(fitsFilePtr, USHORT_IMG, naxis, naxes, &fitsStatus)) { fits_get_errstatus(fitsStatus, fits_status_str); asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s::%s error creating fits image: error=%s\n", driverName, functionName, fits_status_str); fits_clear_errmsg(); return asynError; } if(fits_write_img(fitsFilePtr, CFITSIO_TUSHORT, 1, naxes[0]*naxes[1], pArray->pData, &fitsStatus)) { fits_get_errstatus(fitsStatus, fits_status_str); asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s::%s error writing fits image: error=%s\n", driverName, functionName, fits_status_str); fits_close_file(fitsFilePtr, &fitsStatus); fits_clear_errmsg(); return asynError; } if(WriteKeys(fitsFilePtr, &fitsStatus)) { fits_get_errstatus(fitsStatus, fits_status_str); asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s::%s error writing fits image: error=%s\n", driverName, functionName, fits_status_str); fits_close_file(fitsFilePtr, &fitsStatus); return asynError; } return(asynSuccess); }
static void cfits_report_error (int status) { if (Cfits_Verbose) { fits_report_error (stderr, status); fflush (stderr); } else fits_clear_errmsg (); }
/* Routine to test the extra bytes at the end of file */ void test_end(fitsfile *infits, FILE *out) { int status = 0; LONGLONG headstart, datastart, dataend; int hdutype; /* check whether there are any HDU left */ fits_movrel_hdu(infits,1, &hdutype, &status); if (!status) { wrtout(out,"< End-of-File >"); sprintf(errmes, "There are extraneous HDU(s) beyond the end of last HDU."); wrterr(out,errmes,2); wrtout(out," "); return; } if (status != END_OF_FILE) { wrtserr(out,"Bad HDU? ",&status,2); return; } status = 0; fits_clear_errmsg(); if(ffghadll(infits, &headstart, &datastart, &dataend, &status)) wrtferr(out, "",&status,1); /* try to move to the last byte of this extension. */ if (ffmbyt(infits, dataend - 1,0,&status)) { sprintf(errmes, "Error trying to read last byte of the file at byte %ld.", (long) dataend); wrterr(out,errmes,2); wrtout(out,"< End-of-File >"); wrtout(out," "); return; } /* try to move to what would be the first byte of the next extension. If successfull, we have a problem... */ ffmbyt(infits, dataend,0,&status); if(status == 0) { wrtout(out,"< End-of-File >"); sprintf(errmes, "File has extra byte(s) after last HDU at byte %ld.", (long) dataend); wrterr(out,errmes,2); wrtout(out," "); } return; }
/** Closes the FITS file. */ asynStatus NDFileFITS::closeFile() { static const char *functionName = "closeFile"; if(fits_close_file(fitsFilePtr, &fitsStatus)) { fits_get_errstatus(fitsStatus, fits_status_str); asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s::%s error closing fits image file: error=%s\n", driverName, functionName, fits_status_str); fits_clear_errmsg(); return asynError; } return asynSuccess; }
int cfits_col_exist (const char *col_name, cfitsfile *fptr) { int status = 0; int casesen = CASEINSEN; int colnum; if (NULL == col_name || NULL == fptr) return -1; (void) fits_get_colnum ((fitsfile *) fptr, casesen, (char *)col_name, &colnum, &status); if (status == 0) return 1; /*yes, column exists */ else { fits_clear_errmsg (); return 0; /*no, column doesn't exist */ } }