239 fitsfile *fp=
nullptr;
241 char errdescr[FLEN_STATUS+1];
244 fits_open_file(&fp, filepath_filter.
Data(), READONLY, &status);
245 if (status)
goto ERR;
249 fits_get_hdu_num(fp, &hdunum);
254 fits_get_hdu_type(fp, &hdutype, &status);
255 if (status)
goto ERR;
260 char keyname[FLEN_KEYWORD+1];
261 char keyvalue[FLEN_VALUE+1];
262 char comment[FLEN_COMMENT+1];
264 fits_get_hdrspace(fp, &nkeys, &morekeys, &status);
265 if (status)
goto ERR;
269 for (
int i = 1;
i <= nkeys;
i++) {
270 fits_read_keyn(fp,
i, keyname, keyvalue, comment, &status);
271 if (status)
goto ERR;
281 for (
int i = 0;
i < nkeys;
i++) {
290 Info(
"LoadHDU",
"The selected HDU contains an Image Extension");
293 long *param_dimsizes;
296 fits_get_img_dim(fp, ¶m_ndims, &status);
297 if (status)
goto ERR;
298 if (param_ndims > 0) {
300 param_dimsizes =
new long[param_ndims];
301 fits_get_img_size(fp, param_ndims, param_dimsizes, &status);
303 delete [] param_dimsizes;
309 for (
int i = 0;
i < param_ndims;
i++) {
310 fSizes->SetAt(param_dimsizes[
i],
i);
313 delete [] param_dimsizes;
317 long *firstpixel =
new long[param_ndims];
321 for (
int i = 0;
i < param_ndims;
i++) {
322 npixels *= (long)
fSizes->GetAt(
i);
326 double *pixels =
new double[npixels];
328 fits_read_pix(fp, TDOUBLE, firstpixel, npixels,
329 (
void *) &nulval, (
void *) pixels, &anynul, &status);
332 delete [] firstpixel;
339 delete [] firstpixel;
348 Info(
"LoadHDU",
"The selected HDU contains a Table Extension");
354 fits_get_num_rows(fp, &table_rows, &status);
355 if (status)
goto ERR;
359 fits_get_num_cols(fp, &table_cols, &status);
360 if (status)
goto ERR;
371 fits_get_colname(fp, CASEINSEN, (
char*)
"*", colname, &colnum, &status);
372 while (status == COL_NOT_UNIQUE)
375 fits_get_colname(fp, CASEINSEN, (
char*)
"*", colname, &colnum, &status);
377 if (status != COL_NOT_FOUND)
goto ERR;
381 fCells =
new union Cell [table_rows * table_cols];
389 for (colnum = 0, cellindex = 0; colnum <
fNColumns; colnum++) {
390 fits_get_coltype(fp, colnum+1, &typecode, &repeat, &
width, &status);
392 if (status)
goto ERR;
394 if ((typecode == TDOUBLE) || (typecode == TSHORT) || (typecode == TLONG)
395 || (typecode == TFLOAT) || (typecode == TLOGICAL) || (typecode == TBIT)
396 || (typecode == TBYTE) || (typecode == TSTRING)) {
398 if (typecode == TSTRING) {
403 fits_get_col_display_width(fp, colnum+1, &dispwidth, &status);
404 if (status)
goto ERR;
407 char *nulval = (
char*)
"";
411 if (dispwidth <= 0) {
415 array =
new char* [table_rows];
416 for (
long row = 0; row < table_rows; row++) {
417 array[row] =
new char[dispwidth+1];
421 fits_read_col(fp, TSTRING, colnum+1, 1, 1, table_rows, nulval, array, &anynul, &status);
423 for (
long row = 0; row < table_rows; row++) {
424 delete [] array[row];
432 for (
long row = 0; row < table_rows; row++) {
433 strlcpy(array[row],
"-",dispwidth+1);
438 for (
long row = 0; row < table_rows; row++) {
439 fCells[cellindex++].fString = array[row];
452 double *array =
nullptr;
453 char *arrayl =
nullptr;
457 if (typecode == TLOGICAL) {
458 arrayl =
new char[table_rows * repeat];
459 fits_read_col(fp, TLOGICAL, colnum + 1, 1, 1, table_rows * repeat, &nulval, arrayl, &anynul,
466 array =
new double[table_rows * repeat];
467 fits_read_col(fp, TDOUBLE, colnum + 1, 1, 1, table_rows * repeat, &nulval, array, &anynul,
477 array =
new double[table_rows];
478 for (
long row = 0; row < table_rows; row++) {
487 if (typecode == TLOGICAL) {
488 for (
long row = 0; row < table_rows; row++) {
489 int temp = (
signed char)arrayl[row];
494 for (
long row = 0; row < table_rows; row++) {
495 fCells[cellindex++].fRealNumber = array[row];
499 }
else if (repeat > 1) {
502 if (typecode == TLOGICAL) {
503 for (
long row = 0; row < table_rows; row++) {
504 double *
vec =
new double[repeat];
505 long offset = row * repeat;
506 for (
long component = 0; component < repeat; component++) {
507 int temp = (
signed char)arrayl[
offset++];
514 for (
long row = 0; row < table_rows; row++) {
515 double *
vec =
new double[repeat];
516 long offset = row * repeat;
517 for (
long component = 0; component < repeat; component++) {
526 }
else if (typecode < 1) {
539 for (
long row = 0; row < table_rows; row++) {
543 fits_read_descript(fp, colnum+1, row+1, &repeat_row, &
offset, &status);
549 for (
long row = 0; row < table_rows; row++) {
568 std::vector<short>
data;
570 fits_read_col(fp, abstype, colnum + 1, row + 1, 1, nelements, &nulval,
data.data(), &anynul, &status);
573 }
else if (abstype == 41) {
574 std::vector<int>
data;
576 fits_read_col(fp, abstype, colnum + 1, row + 1, 1, nelements, &nulval,
data.data(), &anynul, &status);
579 }
else if (abstype == 42) {
580 std::vector<float>
data;
582 fits_read_col(fp, abstype, colnum + 1, row + 1, 1, nelements, &nulval,
data.data(), &anynul, &status);
585 }
else if (abstype == 82) {
586 std::vector<double>
data;
588 fits_read_col(fp, abstype, colnum + 1, row + 1, 1, nelements, &nulval,
data.data(), &anynul, &status);
592 Error(
"LoadHDU",
"The variable-length array type in column %d is unknown", colnum + 1);
598 Warning(
"LoadHDU",
"error opening FITS file. Column type %d is currently not supported", typecode);
602 if (hdutype == ASCII_TBL) {
611 fits_close_file(fp, &status);
615 fits_get_errstatus(status, errdescr);
616 Warning(
"LoadHDU",
"error opening FITS file. Details: %s", errdescr);
618 if (fp) fits_close_file(fp, &status);
667 fitsfile *fp=
nullptr;
669 char errdescr[FLEN_STATUS+1];
670 int hducount, extnum;
671 int hdutype = IMAGE_HDU;
673 char extname[FLEN_CARD]=
"PRIMARY";
674 int verbose = (opt[0] ? 1 : 0);
677 fits_open_file(&fp,
fBaseFilePath.Data(), READONLY, &status);
678 if (status)
goto ERR;
681 fits_get_num_hdus(fp, &hducount, &status);
682 if (status)
goto ERR;
683 printf(
"Total: %d HDUs\n", hducount);
688 fits_get_hdu_type(fp, &hdutype, &status);
689 if (status)
goto ERR;
691 if (hdutype == IMAGE_HDU) {
693 }
else if (hdutype == ASCII_TBL) {
694 exttype=
"ASCII TABLE";
696 exttype=
"BINARY TABLE";
701 char keyname[FLEN_KEYWORD+1];
702 char keyvalue[FLEN_VALUE+1];
703 char comment[FLEN_COMMENT+1];
705 fits_get_hdrspace(fp, &nkeys, &morekeys, &status);
706 if (status)
goto ERR;
710 for (
int i = 1;
i <= nkeys;
i++) {
711 fits_read_keyn(fp,
i, keyname, keyvalue, comment, &status);
718 records[
i-1].
fValue = keyvalue;
721 if (strcmp(keyname,
"EXTNAME") == 0) {
723 strlcpy(extname, keyvalue,FLEN_CARD);
728 printf(
" [%d] %s (%s)\n", extnum, exttype, extname);
732 for (
int i = 0;
i < nkeys;
i++) {
736 printf(
" %-10s = %s\n", records[
i].fKeyword.Data(), records[
i].
fValue.
Data());
747 fits_movrel_hdu(fp, 1, &hdutype, &status);
748 if (status)
goto ERR;
753 fits_close_file(fp, &status);
757 fits_get_errstatus(status, errdescr);
758 Warning(
"PrintFileMetadata",
"error opening FITS file. Details: %s", errdescr);
760 if (fp) fits_close_file(fp, &status);