NCFS-Pack
A generic (astro)particle physics analysis framework
 
Loading...
Searching...
No Matches
NcFITSIO.cxx
Go to the documentation of this file.
1
31
33
290
291#include "NcFITSIO.h"
292#include "Riostream.h"
293
294ClassImp(NcFITSIO); // Class implementation to enable ROOT I/O
295
297NcFITSIO::NcFITSIO(const char* name,const char* title) : TNamed(name,title)
298{
304
305 Initialize();
306}
307
309{
315
316 Reset();
317}
318
319NcFITSIO::NcFITSIO(const NcFITSIO& q) : TNamed(q)
320{
326
327 Initialize();
330
331 if (!LoadHeaderInfo())
332 {
333 cout << endl;
334 cout << " *" << ClassName() << "::NcFITSIO* Failure in copy constructor." << endl;
335 }
336}
337
339{
345
346 fFilename=""; // The (full path) name of the FITS file on the computer system
347 fFilenameFilter=""; // The FITS filename with the HDU selection filter
348 fInput=0; // Pointer to the FITS input file
349 fOutput=0; // Pointer to the FITS output file
350 fType=kImageHDU; // The HDU type
351 fExtensionName=""; // Extension name of the HDU
352 fExtensionNumber=0; // Extension number of the HDU (0=PRIMARY)
353 fNkeys=0; // The number of HDU keywords
354 fKeyNames=0; // The HDU key names
355 fKeyValues=0; // The HDU key values
356 fComments=0; // The HDU (key) comments
357 fNrows=0; // The number of table rows
358 fNcolumns=0; // The number of table columns
359 fColumnNames=0; // The names of the table columns
360 fColumnTypes=0; // The types of the table columns
361 fColumnLayers=0; // The number of layers of the table column
362 fSizes=0; // Image sizes in each dimension (when fType == kImageHDU)
363}
364
366{
372
373 if (fKeyNames)
374 {
375 delete[] fKeyNames;
376 fKeyNames=0;
377 }
378 if (fKeyValues)
379 {
380 delete[] fKeyValues;
381 fKeyValues=0;
382 }
383 if (fComments)
384 {
385 delete[] fComments;
386 fComments=0;
387 }
388 if (fColumnNames)
389 {
390 delete[] fColumnNames;
391 fColumnNames=0;
392 }
393 if (fColumnTypes)
394 {
395 delete[] fColumnTypes;
396 fColumnTypes=0;
397 }
398 if (fColumnLayers)
399 {
400 delete[] fColumnLayers;
402 }
403 if (fSizes)
404 {
405 delete fSizes;
406 fSizes=0;
407 }
408
409 // Reset all parameters
410 Initialize();
411}
412
413Bool_t NcFITSIO::OpenInputFile(TString specs)
414{
444
445 TString file=gSystem->ExpandPathName(specs.Data());
446
447 Initialize();
448
449 // Store both the filename with the optional HDU selection filter appended and the plain filename
450 fFilenameFilter=file;
452
453 Bool_t good=LoadHeaderInfo();
454
455 if (good)
456 {
457 cout << endl;
458 cout << " *" << ClassName() << "::OpenInputFile* FITS file specs: " << fFilenameFilter << endl;
459 }
460 else
461 {
462 cout << endl;
463 cout << " *" << ClassName() << "::OpenInputFile* Could not open " << fFilenameFilter << endl;
464 Reset();
465 }
466
467 return good;
468}
469
470TString NcFITSIO::StripFilter(TString filename) const
471{
477
478 TString s=filename;
479 Int_t idx=s.Index("[",1,0,TString::kExact);
480 if (idx>=0) s.Resize(idx);
481
482 return s;
483}
484
486{
493
494 Bool_t good=kTRUE;
495 fInput=0;
496 int status=0;
497
498 if (fKeyNames)
499 {
500 delete[] fKeyNames;
501 fKeyNames=0;
502 }
503 if (fKeyValues)
504 {
505 delete[] fKeyValues;
506 fKeyValues=0;
507 }
508 if (fComments)
509 {
510 delete[] fComments;
511 fComments=0;
512 }
513
514 // Open the FITS file as specified via OpenInputFile() or SelectHDU()
515 fits_open_file(&fInput,fFilenameFilter.Data(),READONLY,&status);
516
517 if (status)
518 {
519 cout << endl;
520 cout << " *" << ClassName() << "::LoadHeaderInfo* Could not open " << fFilenameFilter << endl;
521 Reset();
522 good=kFALSE;
523 return good;
524 }
525
526 // Read the number of this HDU
527 int hdunum;
528 fits_get_hdu_num(fInput,&hdunum);
529 fExtensionNumber=Int_t(hdunum)-1;
530
531 // Read the type of this HDU
532 int hdutype;
533 fits_get_hdu_type(fInput,&hdutype,&status);
534
535 if (status)
536 {
537 cout << endl;
538 cout << " *" << ClassName() << "::LoadHeaderInfo* Could not retrieve the HDU type." << endl;
539 fits_close_file(fInput,&status);
540 Reset();
541 good=kFALSE;
542 return good;
543 }
544
546 if (hdutype==IMAGE_HDU) fType=kImageHDU;
547
548 // Read the HDU header records
549 int nkeys,morekeys;
550 fits_get_hdrspace(fInput,&nkeys,&morekeys,&status);
551
552 if (status)
553 {
554 cout << endl;
555 cout << " *" << ClassName() << "::LoadHeaderInfo* Could not retrieve the HDU header space." << endl;
556 fits_close_file(fInput,&status);
557 Reset();
558 good=kFALSE;
559 return good;
560 }
561
562 // Store the HDU header information
563 fKeyNames=new TString[nkeys];
564 fKeyValues=new TString[nkeys];
565 fComments=new TString[nkeys];
566
567 char keyname[FLEN_KEYWORD+1];
568 char keyvalue[FLEN_VALUE+1];
569 char comment[FLEN_COMMENT+1];
570 fNkeys=0;
571 for (Int_t i=1; i<=nkeys; i++)
572 {
573 fits_read_keyn(fInput,i,keyname,keyvalue,comment,&status);
574
575 if (status)
576 {
577 cout << endl;
578 cout << " *" << ClassName() << "::LoadHeaderInfo* Could not retrieve info of HDU key record "<< i << endl;
579 fits_close_file(fInput,&status);
580 Reset();
581 good=kFALSE;
582 return good;
583 }
584
585 fKeyNames[i-1]=keyname;
586 fKeyValues[i-1]=keyvalue;
587 fComments[i-1]=comment;
588
589 fNkeys++;
590
591 // Obtain the extension name
592 fExtensionName="[";
593 if (fKeyNames[i-1]=="EXTNAME")
594 {
596 fExtensionName.ReplaceAll("'",""); // Remove the single quotes
597 }
598 else
599 {
601 }
602 fExtensionName+="]";
603 }
604
605 // Obtain row and column information in case of Table data
606 if (fType==kTableHDU)
607 {
608 long nrows;
609 fits_get_num_rows(fInput,&nrows,&status);
610
611 if (status)
612 {
613 cout << endl;
614 cout << " *" << ClassName() << "::LoadHeaderInfo* Could not retrieve number of table rows." << endl;
615 fits_close_file(fInput,&status);
616 Reset();
617 good=kFALSE;
618 return good;
619 }
620
621 fNrows=Int_t(nrows);
622
623 int ncols;
624 fits_get_num_cols(fInput,&ncols,&status);
625
626 if (status)
627 {
628 cout << endl;
629 cout << " *" << ClassName() << "::LoadHeaderInfo* Could not retrieve number of table columns." << endl;
630 fits_close_file(fInput,&status);
631 Reset();
632 good=kFALSE;
633 return good;
634 }
635
636 // Store the Table column information
637 fNcolumns=Int_t(ncols);
638 fColumnNames=new TString[ncols];
639 fColumnTypes=new eColumnTypes[ncols];
640 fColumnLayers=new Int_t[ncols];
641
642 // Read the column names
643 status=0;
644 char colname[80];
645 int jcol;
646 fits_get_colname(fInput,CASEINSEN,(char*)"*",colname,&jcol,&status);
647
648 if (status==COL_NOT_FOUND)
649 {
650 cout << endl;
651 cout << " *" << ClassName() << "::LoadHeaderInfo* Could not find any table column." << endl;
652 fits_close_file(fInput,&status);
653 Reset();
654 good=kFALSE;
655 return good;
656 }
657
658 if (jcol>0 && jcol<=ncols) fColumnNames[jcol-1]=colname;
659
660 while (status==COL_NOT_UNIQUE)
661 {
662 fits_get_colname(fInput,CASEINSEN,(char*)"*",colname,&jcol,&status);
663 if (jcol>0 && jcol<=ncols) fColumnNames[jcol-1]=colname;
664 }
665 if (status && status!=COL_NOT_FOUND)
666 {
667 cout << endl;
668 cout << " *" << ClassName() << "::LoadHeaderInfo* Could not retrieve name of table column " << jcol << endl;
669 fits_close_file(fInput,&status);
670 Reset();
671 good=kFALSE;
672 return good;
673 }
674
675 // Read the column data types
676 status=0;
677 int typecode;
678 long repeat,width;
679 Int_t dim=1; // Dimension of the stored column elements
680 for (jcol=1; jcol<=fNcolumns; jcol++)
681 {
682 fits_get_coltype(fInput,jcol,&typecode,&repeat,&width,&status);
683
684 if (status)
685 {
686 cout << endl;
687 cout << " *" << ClassName() << "::LoadHeaderInfo* Could not retrieve data type of table column " << jcol << endl;
688 fits_close_file(fInput,&status);
689 Reset();
690 good=kFALSE;
691 return good;
692 }
693
694 // Determine the dimension of the stored column elements
695 dim=Int_t(repeat);
696 if (typecode==TSTRING) dim=Int_t(repeat/width);
697 if (dim<=0) dim=1;
698
699 fColumnLayers[jcol-1]=dim;
700
701 if (typecode==TSTRING)
702 {
703 fColumnTypes[jcol-1]=kString;
704 if (dim>1) fColumnTypes[jcol-1]=kStringArray;
705 }
706 else if (typecode==TLOGICAL)
707 {
708 fColumnTypes[jcol-1]=kLogical;
709 if (dim>1) fColumnTypes[jcol-1]=kLogicalArray;
710 }
711 else if (typecode==TCOMPLEX || typecode==TDBLCOMPLEX)
712 {
714 if (dim>1) fColumnTypes[jcol-1]=kComplexArray;
715 }
716 else
717 {
719 if (dim>1) fColumnTypes[jcol-1]=kRealArray;
720 }
721 }
722 } // End of Table info
723
724 // Obtain dimension and size information in case of Image data
725 if (fType==kImageHDU)
726 {
727 // The number of dimensions of the N-dimensional data
728 status=0;
729 int ndims=0;
730 fits_get_img_dim(fInput,&ndims,&status);
731
732 if (status)
733 {
734 cout << endl;
735 cout << " *" << ClassName() << "::LoadHeaderInfo* Could not retrieve the number of dimensions of the Image." << endl;
736 fits_close_file(fInput,&status);
737 Reset();
738 good=kFALSE;
739 return good;
740 }
741
742 // Empty Image
743 if (ndims<=0)
744 {
745 fSizes=new TArrayI();
746 return good;
747 }
748
749 // The size of each dimension
750 long* dimsizes=new long[ndims];
751 fits_get_img_size(fInput,ndims,dimsizes,&status);
752
753 if (status)
754 {
755 cout << endl;
756 cout << " *" << ClassName() << "::LoadHeaderInfo* Could not retrieve the sizes of the dimensions of the Image." << endl;
757 fits_close_file(fInput,&status);
758 Reset();
759 good=kFALSE;
760 delete[] dimsizes;
761 return good;
762 }
763
764 // Store the size of each dimension
765 fSizes=new TArrayI(ndims);
766 for (Int_t i= 0; i<ndims; i++)
767 {
768 fSizes->SetAt(dimsizes[i],i);
769 }
770
771 delete [] dimsizes;
772 } // End of Image info
773
774 return good;
775}
776
777Bool_t NcFITSIO::SelectHDU(TString extname)
778{
799
801 fFilenameFilter+=extname;
802
803 Bool_t good=LoadHeaderInfo();
804
805 if (good)
806 {
807 cout << endl;
808 cout << " *" << ClassName() << "::SelectHDU* Current selection: " << fFilenameFilter << endl;
809 }
810 else
811 {
812 cout << endl;
813 cout << " *" << ClassName() << "::SelectHDU* Could not select " << fFilenameFilter << endl;
814 Reset();
815 }
816
817 return good;
818}
819
820Bool_t NcFITSIO::SelectHDU(Int_t extnumber)
821{
835
836 TString extname="[";
837 extname+=extnumber;
838 extname+="]";
839
840 Bool_t good=SelectHDU(extname);
841
842 return good;
843}
844
845TString NcFITSIO::GetKeywordValue(TString keyname,Int_t mode)
846{
866
867
868 TString value="";
869
870 for (Int_t i=0; i<fNkeys; i++)
871 {
872 if (fKeyNames[i]==keyname || (mode && fKeyNames[i].Contains(keyname.Data())))
873 {
874 value=fKeyValues[i];
875 break;
876 }
877 }
878
879 value.ReplaceAll("'",""); // Remove the single quotes
880 value=value.Strip(value.kBoth,' '); // Remove leading and trailing blanks
881
882 return value;
883}
884
885Bool_t NcFITSIO::IsTable() const
886{
892
893
894 Bool_t flag=kFALSE;
895 if (fType==kTableHDU) flag=kTRUE;
896
897 return flag;
898}
899
901{
907
908 Int_t nhdus=0;
909
910 // Open a local mode of the FITS file without any filters
911 fitsfile* fp=0;
912 int status=0;
913 fits_open_file(&fp,fFilename.Data(),READONLY,&status);
914
915 if (status)
916 {
917 cout << " *" << ClassName() << "::GetHDUCount* Could not open file : " << fFilename << endl;
918 fits_close_file(fp,&status);
919 return 0;
920 }
921
922 int n=0;
923 fits_get_num_hdus(fp,&n,&status);
924
925 if (status)
926 {
927 cout << " *" << ClassName() << "::GetHDUCount* Could not read the number of HDUs" << endl;
928 fits_close_file(fp,&status);
929 return 0;
930 }
931
932 nhdus=n;
933
934 // Close this local "unfiltered" file mode
935 fits_close_file(fp,&status);
936
937 return nhdus;
938}
939
941{
947
948 return fNrows;
949}
950
952{
958
959 return fNcolumns;
960}
961
962Int_t NcFITSIO::GetColumnNumber(TString colname,Int_t mode) const
963{
977
978 Int_t colnum=0;
979 Int_t match=0;
980 for (Int_t i=1; i<=fNcolumns; i++)
981 {
982 if (!mode && fColumnNames[i-1]==colname) match=1;
983 if (mode && fColumnNames[i-1].Contains(colname)) match=1;
984 if (match)
985 {
986 colnum=i;
987 break;
988 }
989 }
990 return colnum;
991}
992
993TString NcFITSIO::GetColumnName(Int_t colnum) const
994{
1003
1004 TString name="";
1005
1006 if (fType!=kTableHDU || colnum<1 || colnum>fNcolumns) return name;
1007
1008 name=fColumnNames[colnum-1];
1009 return name;
1010}
1011
1012Int_t NcFITSIO::GetTableCell(Double_t &val,Int_t row,Int_t col,Int_t layer)
1013{
1030
1031 TArrayD arr;
1032 Int_t ndim=GetTableCell(arr,row,col);
1033
1034 if (!ndim || layer<1 || layer>ndim)
1035 {
1036 val=0;
1037 return 0;
1038 }
1039
1040 val=arr[layer-1];
1041 return ndim;
1042}
1043
1044Int_t NcFITSIO::GetTableCell(Double_t &val,Int_t row,TString colname,Int_t layer,Int_t mode)
1045{
1066
1067 Int_t col=GetColumnNumber(colname,mode);
1068
1069 Int_t ndim=GetTableCell(val,row,col);
1070
1071 return ndim;
1072}
1073
1074Int_t NcFITSIO::GetTableCell(TArrayD &arr,Int_t row,Int_t col)
1075{
1086
1087 arr.Set(0);
1088
1089 if (row<=0 || row>fNrows || col<=0 || col>fNcolumns) return 0;
1090
1091 if (fType!=kTableHDU || fColumnTypes[col-1]==kString || fColumnTypes[col-1]==kStringArray) return 0;
1092
1093 // Obtain the number of (array) elements stored in this (row,col) cell.
1094 Int_t dim=0;
1095 int colnum=col;
1096 long long rownum=row;
1097 long repeat=0;
1098 long offset=0;
1099 int status=0;
1100 fits_read_descript(fInput,colnum,rownum,&repeat,&offset,&status);
1101
1102 if (!status) // The column was created to hold a variable number of elements
1103 {
1104 dim=repeat;
1105 }
1106 else // The column was created to hold a fixed number of elements
1107 {
1108 dim=fColumnLayers[col-1];
1109 }
1110
1111 if (dim<=0) return 0;
1112
1113 // Read the cell contents into an array
1114 double nulval=0;
1115 int anynul=0;
1116 double* array=new double[dim];
1117 status=0;
1118 if (fColumnTypes[col-1]==kLogical || fColumnTypes[col-1]==kLogicalArray)
1119 {
1120 bool* barray=new bool[dim];
1121 bool bnulval=0;
1122 fits_read_col(fInput,TLOGICAL,col,row,1,dim,&bnulval,barray,&anynul,&status);
1123 for (Int_t i=0; i<dim; i++)
1124 {
1125 array[i]=double(barray[i]);
1126 }
1127 delete [] barray;
1128 }
1129 else
1130 {
1131 fits_read_col(fInput,TDOUBLE,col,row,1,dim,&nulval,array,&anynul,&status);
1132 }
1133
1134 if (status)
1135 {
1136 cout << endl;
1137 cout << " *" << ClassName() << "::GetTableCell* Could not retrieve data type of table cell ["
1138 << row << "," << col << "]." << endl;
1139 fits_close_file(fInput,&status);
1140 Reset();
1141 delete [] array;
1142 return 0;
1143 }
1144
1145 // Copy the cell values into the output array
1146 arr.Set(dim);
1147 for (Int_t i=0; i<dim; i++)
1148 {
1149 arr.SetAt(array[i],i);
1150 }
1151
1152 delete [] array;
1153 return dim;
1154}
1155
1156Int_t NcFITSIO::GetTableCell(TArrayD &arr,Int_t row,TString colname,Int_t mode)
1157{
1175
1176 Int_t col=GetColumnNumber(colname,mode);
1177
1178 Int_t ndim=GetTableCell(arr,row,col);
1179
1180 return ndim;
1181}
1182
1183Int_t NcFITSIO::GetTableCell(TString &str,Int_t row,Int_t col,Int_t layer)
1184{
1207
1208 TString* arr=0;
1209 Int_t ndim=GetTableCell(arr,row,col);
1210 if (!ndim || layer<1 || layer>ndim)
1211 {
1212 str="";
1213 ndim=0;
1214 }
1215 else
1216 {
1217 str=arr[layer-1];
1218 }
1219
1220 delete[] arr;
1221 return ndim;
1222}
1223
1224Int_t NcFITSIO::GetTableCell(TString &str,Int_t row,TString colname,Int_t layer,Int_t mode)
1225{
1252
1253 Int_t col=GetColumnNumber(colname,mode);
1254
1255 Int_t ndim=GetTableCell(str,row,col,layer);
1256
1257 return ndim;
1258}
1259
1260Int_t NcFITSIO::GetTableCell(TString* &arr,Int_t row,Int_t col)
1261{
1282
1283 if (!arr) arr=new TString[1];
1284 arr[0]="";
1285
1286 if (row<=0 || row>fNrows || col<=0 || col>fNcolumns) return 0;
1287
1288 if (fType!=kTableHDU) return 0;
1289
1290 // Obtain the number of (array) elements stored in this (row,col) cell.
1291 Int_t dim=0;
1292 int colnum=col;
1293 long long rownum=row;
1294 long repeat=0;
1295 long offset=0;
1296 int status=0;
1297 fits_read_descript(fInput,colnum,rownum,&repeat,&offset,&status);
1298
1299 if (!status) // The column was created to hold a variable number of elements
1300 {
1301 dim=repeat;
1302 }
1303 else // The column was created to hold a fixed number of elements
1304 {
1305 dim=fColumnLayers[col-1];
1306 }
1307
1308 if (dim<=0) return 0;
1309
1310 // Retrieve the character width for this column
1311 int dispwidth=0;
1312 status=0;
1313 fits_get_col_display_width(fInput,col,&dispwidth,&status);
1314
1315 if (status)
1316 {
1317 cout << endl;
1318 cout << " *" << ClassName() << "::GetTableCell* Could not retrieve string width of table cell ["
1319 << row << "," << col << "]." << endl;
1320 fits_close_file(fInput,&status);
1321 Reset();
1322 return 0;
1323 }
1324
1325 if (dispwidth<=0) dispwidth=1;
1326
1327 // Read the cell contents into an array
1328 char* nulval=(char*)"";
1329 int anynul=0;
1330 char** array=new char*[dim];
1331 for (Int_t i=0; i<dim; i++)
1332 {
1333 array[i]=new char[dispwidth+1];
1334 }
1335 fits_read_col(fInput,TSTRING,col,row,1,dim,nulval,array,&anynul,&status);
1336
1337 if (status)
1338 {
1339 cout << endl;
1340 cout << " *" << ClassName() << "::GetTableCell* Could not retrieve string of table cell ["
1341 << row << "," << col << "]." << endl;
1342 fits_close_file(fInput,&status);
1343 Reset();
1344 delete [] array;
1345 return 0;
1346 }
1347
1348 // Copy the data into the output array
1349 delete[] arr;
1350 arr=new TString[dim];
1351 for (Int_t j=0; j<dim; j++)
1352 {
1353 arr[j]=array[j];
1354 }
1355
1356 delete[] array;
1357 return dim;
1358}
1359
1360Int_t NcFITSIO::GetTableCell(TString* &arr,Int_t row,TString colname,Int_t mode)
1361{
1388
1389 Int_t col=GetColumnNumber(colname,mode);
1390
1391 Int_t ndim=GetTableCell(arr,row,col);
1392
1393 return ndim;
1394}
1395
1396Int_t NcFITSIO::GetTableCell(TObjArray &arr,Int_t row,Int_t col)
1397{
1414
1415 TString* temp=0;
1416 Int_t ndim=GetTableCell(temp,row,col);
1417
1418 arr.Clear();
1419 arr.SetOwner();
1420
1421 TObjString* sobj;
1422 for (Int_t i=0; i<ndim; i++)
1423 {
1424 sobj=new TObjString();
1425 sobj->SetString(temp[i]);
1426 arr.Add(sobj);
1427 }
1428
1429 delete[] temp;
1430
1431 return ndim;
1432}
1433
1434Int_t NcFITSIO::GetTableCell(TObjArray &arr,Int_t row,TString colname,Int_t mode)
1435{
1458
1459 Int_t col=GetColumnNumber(colname,mode);
1460
1461 Int_t ndim=GetTableCell(arr,row,col);
1462
1463 return ndim;
1464}
1465
1466Int_t NcFITSIO::GetTableColumn(TArrayD &arr,Int_t col,Int_t rstart,Int_t rend,Int_t layer)
1467{
1491
1492 if (!rend) rend=fNrows;
1493
1494 arr.Set(0);
1495
1496 if (rstart<=0 || rstart>fNrows || rend<=0 || rend>fNrows || col<=0 || col>fNcolumns || layer<1) return 0;
1497
1498 if (fType!=kTableHDU || fColumnTypes[col-1]==kString || fColumnTypes[col-1]==kStringArray) return 0;
1499
1500 Int_t ndim=(rend-rstart)+1;
1501 arr.Set(ndim);
1502
1503 Double_t val=0;
1504 Int_t dim=0;
1505 Int_t n=0;
1506 for (Int_t irow=rstart; irow<=rend; irow++)
1507 {
1508 dim=GetTableCell(val,irow,col);
1509
1510 if (!dim || layer>dim)
1511 {
1512 arr.Set(0);
1513 return 0;
1514 }
1515
1516 arr.AddAt(val,n);
1517 n++;
1518 }
1519
1520 return n;
1521}
1522
1523Int_t NcFITSIO::GetTableColumn(TArrayD &arr,TString colname,Int_t rstart,Int_t rend,Int_t layer,Int_t mode)
1524{
1550
1551 Int_t col=GetColumnNumber(colname,mode);
1552
1553 Int_t n=GetTableColumn(arr,col,rstart,rend,layer);
1554
1555 return n;
1556}
1557
1558Int_t NcFITSIO::GetTableColumn(TString* &arr,Int_t col,Int_t rstart,Int_t rend,Int_t layer)
1559{
1593
1594 if (!rend) rend=fNrows;
1595
1596 if (!arr) arr=new TString[1];
1597 arr[0]="";
1598
1599 if (rstart<=0 || rstart>fNrows || rend<=0 || rend>fNrows || col<=0 || col>fNcolumns || layer<1) return 0;
1600
1601 if (fType!=kTableHDU) return 0;
1602
1603 Int_t ndim=(rend-rstart)+1;
1604
1605 delete[] arr;
1606 arr=new TString[ndim];
1607
1608 TString str;
1609 Int_t dim=0;
1610 Int_t n=0;
1611 for (Int_t irow=rstart; irow<=rend; irow++)
1612 {
1613 dim=GetTableCell(str,irow,col,layer);
1614
1615 if (!dim || layer>dim)
1616 {
1617 delete[] arr;
1618 arr=new TString[1];
1619 arr[0]="";
1620 return 0;
1621 }
1622
1623 arr[n]=str;
1624 n++;
1625 }
1626
1627 return n;
1628}
1629
1630Int_t NcFITSIO::GetTableColumn(TString* &arr,TString colname,Int_t rstart,Int_t rend,Int_t layer,Int_t mode)
1631{
1667
1668 Int_t col=GetColumnNumber(colname,mode);
1669
1670 Int_t n=GetTableColumn(arr,col,rstart,rend,layer);
1671
1672 return n;
1673}
1674
1675Int_t NcFITSIO::GetTableColumn(TObjArray &arr,Int_t col,Int_t rstart,Int_t rend,Int_t layer)
1676{
1706
1707 if (!rend) rend=fNrows;
1708
1709 arr.Clear();
1710 arr.SetOwner();
1711
1712 if (rstart<=0 || rstart>fNrows || rend<=0 || rend>fNrows || col<=0 || col>fNcolumns || layer<1) return 0;
1713
1714 if (fType!=kTableHDU) return 0;
1715
1716 TString str;
1717 Int_t dim=0;
1718 TObjString* sx;
1719 Int_t n=0;
1720 for (Int_t irow=rstart; irow<=rend; irow++)
1721 {
1722 dim=GetTableCell(str,irow,col,layer);
1723
1724 if (!dim || layer>dim)
1725 {
1726 arr.Clear();
1727 return 0;
1728 }
1729
1730 sx=new TObjString();
1731 sx->SetString(str.Data());
1732 arr.Add(sx);
1733 n++;
1734 }
1735
1736 return n;
1737}
1738
1739Int_t NcFITSIO::GetTableColumn(TObjArray &arr,TString colname,Int_t rstart,Int_t rend,Int_t layer,Int_t mode)
1740{
1772
1773 Int_t col=GetColumnNumber(colname,mode);
1774
1775 Int_t n=GetTableColumn(arr,col,rstart,rend,layer);
1776
1777 return n;
1778}
1779
1781{
1796
1797 if (!fSizes) return 0;
1798
1799 Int_t dim=fSizes->GetSize();
1800
1801 if (!i) return dim;
1802
1803 if (i<1 || i>dim) return 0;
1804
1805 dim=fSizes->At(i-1);
1806
1807 return dim;
1808}
1809
1810Int_t NcFITSIO::GetImageLayer(TASImage &im,Int_t layer,Double_t* thres,Double_t max)
1811{
1838
1839 // Set the image empty
1840 im.SetImage(0,0);
1841
1842 TArrayD arr;
1843 if (!LoadLayer(arr,layer)) return 0;
1844
1845 Int_t ndim1=fSizes->At(0);
1846 Int_t npix=arr.GetSize();
1847
1848 if (npix)
1849 {
1850 if (thres) ApplyPixelThreshold(arr,*thres);
1851 if (max>0) RescalePixels(arr,max);
1852 im.SetImage(arr,ndim1);
1853 }
1854
1855 return npix;
1856}
1857
1858Int_t NcFITSIO::GetImageLayer(TMatrixD &m,Int_t layer,Double_t* thres,Double_t max)
1859{
1893
1894 // Clear the matrix elements
1895 m.Clear();
1896
1897 TArrayD arr;
1898 if (!LoadLayer(arr,layer)) return 0;
1899
1900 Int_t ndim1=fSizes->At(0);
1901 Int_t ndim2=fSizes->At(1);
1902 Int_t npix=arr.GetSize();
1903
1904 if (npix)
1905 {
1906 if (thres) ApplyPixelThreshold(arr,*thres);
1907 if (max>0) RescalePixels(arr,max);
1908 m.ResizeTo(ndim2,ndim1);
1909 Int_t i=0;
1910 for (Int_t jrow=0; jrow<ndim2; jrow++)
1911 {
1912 for (Int_t jcol=0; jcol<ndim1; jcol++)
1913 {
1914 m(jrow,jcol)=arr.At(i);
1915 i++;
1916 }
1917 }
1918 }
1919
1920 return npix;
1921}
1922
1923Int_t NcFITSIO::GetImageLayer(TH2D &his,Int_t layer,Double_t* thres,Double_t max)
1924{
1949
1950 // Clear the histogram
1951 his.Reset();
1952 TString title="Histogram of layer ";
1953 title+=layer;
1954 his.SetTitle(title.Data());
1955
1956 TMatrixD m;
1957 Int_t npix=GetImageLayer(m,layer,thres,max);
1958
1959 if (!npix) return 0;
1960
1961 Int_t nrows=m.GetNrows();
1962 Int_t ncols=m.GetNcols();
1963
1964 // Set the binning and range of the histogram axes
1965 his.SetBins(ncols+1,0,ncols,nrows+1,0,nrows);
1966
1967 // Fill the histogram cells with the corresponding matrix contents
1968 Double_t val=0;
1969 for (Int_t icol=0; icol<ncols; icol++)
1970 {
1971 for (Int_t irow=0; irow<nrows; irow++)
1972 {
1973 val=m(irow,icol);
1974 his.SetBinContent(icol+1,irow+1,val);
1975 }
1976 }
1977
1978 return npix;
1979}
1980
1981UInt_t NcFITSIO::GetImageArray(TArrayD &arr,TArrayI ifirst,TArrayI ilast,TArrayI incr)
1982{
2013
2014 arr.Set(0);
2015
2016 if (fType!=kImageHDU || !fSizes) return 0;
2017
2018 Int_t ndims=fSizes->GetSize();
2019
2020 if (ndims<1 || ifirst.GetSize()<ndims || ilast.GetSize()<ndims || incr.GetSize()<ndims) return 0;
2021
2022 // Read the pixels of the specified (sub)set
2023 long* fpixel=new long[ndims];
2024 long* lpixel=new long[ndims];
2025 long* inc=new long[ndims];
2026 long long npixels=1;
2027 int status=0;
2028
2029 Int_t istart=0;
2030 Int_t iend=0;
2031 Int_t istep=0;
2032 for (Int_t i=0; i<ndims; i++)
2033 {
2034 istart=ifirst.At(i);
2035 iend=ilast.At(i);
2036 istep=incr.At(i);
2037
2038 if (istart<1 || iend<1 || istep<1 || iend<istart)
2039 {
2040 cout << endl;
2041 cout << " *" << ClassName() << "::GetImageArray* Inconsistent ifirst, ilast or incr input array(s)." << endl;
2042 fits_close_file(fInput,&status);
2043 Reset();
2044 delete[] fpixel;
2045 delete[] lpixel;
2046 delete[] inc;
2047 return 0;
2048 }
2049
2050 fpixel[i]=istart;
2051 lpixel[i]=iend;
2052 inc[i]=istep;
2053 if (iend>istart) npixels*=1+(iend-istart)/istep;
2054 }
2055
2056 if (!npixels) npixels=1;
2057 double* pixels=new double[npixels];
2058
2059 double nulval=0;
2060 int anynul;
2061 status=0;
2062 fits_read_subset(fInput,TDOUBLE,fpixel,lpixel,inc,(void*)&nulval,(void*)pixels,&anynul,&status);
2063
2064 if (status)
2065 {
2066 cout << endl;
2067 cout << " *" << ClassName() << "::GetImageArray* Could not read pixel data." << endl;
2068 fits_close_file(fInput,&status);
2069 Reset();
2070 delete[] fpixel;
2071 delete[] lpixel;
2072 delete[] inc;
2073 delete[] pixels;
2074 return 0;
2075 }
2076
2077 // Store the pixel data in the output array
2078 arr.Set(npixels);
2079 Double_t val=0;
2080 for (long long i=0; i<npixels; i++)
2081 {
2082 val=pixels[i];
2083 arr.SetAt(val,i);
2084 }
2085
2086 UInt_t npix=npixels;
2087 delete[] pixels;
2088 return npix;
2089}
2090
2091UInt_t NcFITSIO::GetImageArray(TArrayD &arr,TArrayI ifirst,UInt_t npix)
2092{
2119
2120 arr.Set(0);
2121
2122 if (fType!=kImageHDU || !fSizes || npix<1) return 0;
2123
2124 Int_t ndims=GetImageDimension();
2125
2126 if (ndims<1 || ifirst.GetSize()<ndims) return 0;
2127
2128 ULong_t nmax=1;
2129 for (Int_t i=1; i<=ndims; i++)
2130 {
2131 nmax*=GetImageDimension(i);
2132 }
2133
2134 if (npix>nmax) return 0;
2135
2136 // Read the pixels of the specified (sub)set
2137 long* fpixel=new long[ndims];
2138 int status=0;
2139
2140 Int_t istart=0;
2141 for (Int_t i=0; i<ndims; i++)
2142 {
2143 istart=ifirst.At(i);
2144
2145 if (istart<1)
2146 {
2147 cout << endl;
2148 cout << " *" << ClassName() << "::GetImageArray* Inconsistent ifirst input array." << endl;
2149 fits_close_file(fInput,&status);
2150 Reset();
2151 delete[] fpixel;
2152 return 0;
2153 }
2154
2155 fpixel[i]=istart;
2156 }
2157
2158 long long npixels=npix;
2159 double* pixels=new double[npixels];
2160 double nulval=0;
2161 int anynul;
2162 status=0;
2163 fits_read_pix(fInput,TDOUBLE,fpixel,npixels,(void*)&nulval,(void*)pixels,&anynul,&status);
2164
2165 if (status)
2166 {
2167 cout << endl;
2168 cout << " *" << ClassName() << "::GetImageArray* Could not read pixel data." << endl;
2169 fits_close_file(fInput,&status);
2170 Reset();
2171 delete[] fpixel;
2172 delete[] pixels;
2173 return 0;
2174 }
2175
2176 // Store the pixel data in the output array
2177 arr.Set(npixels);
2178 Double_t val=0;
2179 for (long long i=0; i<npixels; i++)
2180 {
2181 val=pixels[i];
2182 arr.SetAt(val,i);
2183 }
2184
2185 UInt_t nread=npixels;
2186 delete[] pixels;
2187 return nread;
2188}
2189
2190void NcFITSIO::ListTable(Int_t width,Int_t rstart,Int_t rend,Int_t cstart,Int_t cend)
2191{
2216
2217 if (fType != kTableHDU)
2218 {
2219 cout << " *" << ClassName() <<"::ListTable* This is not a table HDU." << endl;
2220 return;
2221 }
2222
2223 if (!width)
2224 {
2225 cout << " *" << ClassName() <<"::ListTable* Invalid argument : width=" << width << endl;
2226 return;
2227 }
2228
2229 if (!rend) rend=fNrows;
2230
2231 if (!cend) cend=fNcolumns;
2232
2233 if (rstart<=0 || rstart>fNrows || rend<=0 || rend>fNrows ||
2234 cstart<=0 || cstart>fNcolumns || cend<=0 || cend>fNcolumns)
2235 {
2236 cout << " *" << ClassName() <<"::ListTable* Invalid input rstart=" << rstart << " rend=" << rend
2237 << " cstart=" << cstart << " cend=" << cend << endl;
2238 return;
2239 }
2240
2241 TString type;
2242 TString name;
2243 if (width<0) // List description of all table columns
2244 {
2245 width=-width;
2246
2247 cout << endl;
2248 cout << " *" << ClassName() << "::ListTable* Table column description for col=["
2249 << cstart << "," << cend << "] (name width is " << width << " characters)."<< endl;
2250 cout << endl;
2251
2252 for (Int_t i=cstart; i<=cend; i++)
2253 {
2254 if (fColumnTypes[i-1]==kString) type="STRING";
2255 if (fColumnTypes[i-1]==kStringArray) type="STRING ARRAY";
2256 if (fColumnTypes[i-1]==kRealNumber) type="REAL NUMBER";
2257 if (fColumnTypes[i-1]==kRealArray) type="REAL ARRAY";
2258 if (fColumnTypes[i-1]==kComplexNumber) type="COMPLEX NUMBER";
2259 if (fColumnTypes[i-1]==kComplexArray) type="COMPLEX ARRAY";
2260 if (fColumnTypes[i-1]==kLogical) type="LOGICAL";
2261 if (fColumnTypes[i-1]==kLogicalArray) type="LOGICAL ARRAY";
2262
2263 name=fColumnNames[i-1];
2264 name=name.Strip(name.kBoth,' ');
2265 name.Resize(width);
2266
2267 cout << " " << name << " : " << type;
2268 if (type.Contains("ARRAY")) cout << "[" << fColumnLayers[i-1] << "]";
2269 cout << endl;
2270 }
2271 return;
2272 }
2273
2274 if (width>0) // List the (selected) table contents
2275 {
2276
2277 cout << endl;
2278 cout << " *" << ClassName() << "::ListTable* Table contents for row=[" << rstart << "," << rend << "] and"
2279 << " col=[" << cstart << "," << cend << "] (column width is " << width << " characters)."<< endl;
2280 cout << endl;
2281
2282 // List the header with the (selected) column names
2283 if (width<7) width=7; // Minimal width needed for scientific notation
2284 Int_t prec=width-7; // Adjust the precision
2285 TString str;
2286 Int_t nchars=0;
2287 for (Int_t col=cstart; col<=cend; col++)
2288 {
2289 str=fColumnNames[col-1];
2290 str=str.Strip(str.kBoth,' ');
2291 str.Resize(width);
2292 if (col==cstart) cout << " ";
2293 printf("%s| ",str.Data());
2294 nchars+=(width+2);
2295 }
2296 cout << endl;
2297 if (nchars>0) nchars--; // Don't count the space at the end
2298 cout << " ";
2299 while(nchars--)
2300 {
2301 cout << "-";
2302 }
2303 cout << endl;
2304
2305 // List the (selected) row content
2306 Double_t val=0;
2307 Int_t ndim=0;
2308 for (Int_t row=rstart; row<=rend; row++)
2309 {
2310 for (Int_t col=cstart; col<=cend; col++)
2311 {
2312 if (col==cstart) cout << " ";
2313 if (fColumnTypes[col-1]==kString || fColumnTypes[col-1]==kStringArray || fColumnTypes[col-1]==kLogical || fColumnTypes[col-1]==kLogicalArray)
2314 {
2315 ndim=GetTableCell(str,row,col);
2316 if (!ndim) str="---";
2317 str=str.Strip(str.kBoth,' ');
2318 str.Resize(width);
2319 printf("%s",str.Data());
2320 }
2321 else // Numerical value
2322 {
2323 str="---";
2324 str.Resize(width);
2325 ndim=GetTableCell(val,row,col);
2326 if (ndim)
2327 {
2328 printf("%-*.*g",width,prec,val);
2329 }
2330 else
2331 {
2332 printf("%s",str.Data());
2333 }
2334 }
2335 cout << "| ";
2336 } // end of column loop
2337 cout << endl;
2338 } // end of row loop
2339 }
2340}
2341
2343{
2349
2350 cout << endl;
2351 cout << " *" << ClassName() << "::ListHDUHeader* The current HDU header record " << fExtensionName << endl;
2352 cout << endl;
2353
2354 for (Int_t i=0; i<fNkeys; i++)
2355 {
2356 printf(" %-8s = %-s",fKeyNames[i].Data(),fKeyValues[i].Data());
2357 if (fComments[i].Length()>0) printf(" / %-s",fComments[i].Data());
2358 printf("\n");
2359 }
2360}
2361
2362void NcFITSIO::ListFileHeader(Int_t mode) const
2363{
2376
2377 // Open a local mode of the FITS file without any filters and start at the primary HDU
2378 fitsfile* fp=0;
2379 int status=0;
2380 fits_open_file(&fp,fFilename.Data(),READONLY,&status);
2381
2382 if (status)
2383 {
2384 cout << " *" << ClassName() << "::ListFileHeader* Could not open file : " << fFilename << endl;
2385 fits_close_file(fp,&status);
2386 return;
2387 }
2388
2389 cout << endl;
2390 if (!mode)
2391 {
2392 cout << " *" << ClassName() << "::ListFileHeader* Short summary of the FITS file header information" << endl;
2393 }
2394 else
2395 {
2396 cout << " *" << ClassName() << "::ListFileHeader* Full FITS file header information" << endl;
2397 }
2398 cout << endl;
2399
2400 // Obtain the number of HDUs present in the FITS file
2401 int nhdus=0;
2402 fits_get_num_hdus(fp,&nhdus,&status);
2403
2404 if (status)
2405 {
2406 cout << " *" << ClassName() << "::ListFileHeader* Could not read the number of HDUs" << endl;
2407 fits_close_file(fp,&status);
2408 return;
2409 }
2410
2411 cout << " Total number of HDUs : " << nhdus << endl;
2412
2413 // Loop over all available HDUs
2414 int hdutype=0;
2415 int nkeys=0;
2416 int morekeys=0;
2417 char keyname[FLEN_KEYWORD+1];
2418 char keyvalue[FLEN_VALUE+1];
2419 char comment[FLEN_COMMENT+1];
2420 TString exttype;
2421 TString extname;
2422 TString* keynames=0;
2423 TString* keyvalues=0;
2424 TString* comments=0;
2425 for (Int_t jhdu=1; jhdu<=nhdus; jhdu++)
2426 {
2427 // Read the HDU type
2428 fits_get_hdu_type(fp,&hdutype,&status);
2429
2430 if (status)
2431 {
2432 cout << " *" << ClassName() << "::ListFileHeader* Could not read the type of HDU ["<< (jhdu-1) << "]" << endl;
2433 fits_close_file(fp,&status);
2434 return;
2435 }
2436
2437 exttype="unknown";
2438 if (hdutype==IMAGE_HDU) exttype="IMAGE";
2439 if (hdutype==ASCII_TBL) exttype="ASCII-TABLE";
2440 if (hdutype==BINARY_TBL) exttype="BINARY-TABLE";
2441
2442 //Read the HDU header space information
2443 fits_get_hdrspace(fp,&nkeys,&morekeys,&status);
2444
2445 if (status)
2446 {
2447 cout << " *" << ClassName() << "::ListFileHeader* Could not read the header space of HDU ["<< (jhdu-1) << "]" << endl;
2448 fits_close_file(fp,&status);
2449 return;
2450 }
2451
2452 keynames=new TString[nkeys];
2453 keyvalues=new TString[nkeys];
2454 comments=new TString[nkeys];
2455
2456 // Read the description of the HDU keys
2457 extname="";
2458 for (Int_t i=1; i<=nkeys; i++)
2459 {
2460 fits_read_keyn(fp,i,keyname,keyvalue,comment,&status);
2461
2462 if (status)
2463 {
2464 cout << " *" << ClassName() << "::ListFileHeader* Could not read key number " << i << " of HDU ["<< (jhdu-1) << "]" << endl;
2465 fits_close_file(fp,&status);
2466 if (keynames) delete[] keynames;
2467 if (keyvalues) delete[] keyvalues;
2468 if (comments) delete[] comments;
2469 return;
2470 }
2471
2472 keynames[i-1]=keyname;
2473 keyvalues[i-1]=keyvalue;
2474 comments[i-1]=comment;
2475
2476 // Obtain the extension name if specified in the HDU
2477 if (keynames[i-1]=="EXTNAME")
2478 {
2479 extname=keyvalues[i-1];
2480 extname.ReplaceAll("'",""); // Remove all single quotes
2481 extname=extname.Strip(extname.kBoth,' '); // Remove leading and trailing blanks
2482 extname.Prepend("[");
2483 extname+="]";
2484 }
2485 }
2486
2487 // List the HDU extension number, type and (optional) name
2488 cout << " [" << (jhdu-1) << "] " << exttype << " " << extname << endl;
2489
2490 // List the contents of the HDU header record
2491 if (mode)
2492 {
2493 for (Int_t i=0; i<nkeys; i++)
2494 {
2495 printf(" %-8s = %-s",keynames[i].Data(),keyvalues[i].Data());
2496 if (comments[i].Length()>0) printf(" / %-s",comments[i].Data());
2497 printf("\n");
2498 }
2499 cout << endl;
2500 }
2501
2502 if (keynames) delete[] keynames;
2503 if (keyvalues) delete[] keyvalues;
2504 if (comments) delete[] comments;
2505
2506 // Move to the next HDU
2507 if (jhdu<nhdus)
2508 {
2509 fits_movrel_hdu(fp,1,&hdutype,&status);
2510
2511 if (status)
2512 {
2513 cout << " *" << ClassName() << "::ListFileHeader* Could not move to HDU [" << jhdu << "]" << endl;
2514 fits_close_file(fp,&status);
2515 return;
2516 }
2517 }
2518 }
2519
2520 // Close this loal "unfiltered" file mode
2521 fits_close_file(fp,&status);
2522 return;
2523}
2524
2525Int_t NcFITSIO::LoadLayer(TArrayD &arr,Int_t layer)
2526{
2534
2535 arr.Set(0);
2536
2537 if (fType!=kImageHDU || !fSizes || layer<1) return 0;
2538
2539 Int_t ndims=GetImageDimension();
2540
2541 // Check whether the data dimensions are consistent with a (layered) image.
2542 if (ndims<2) return 0;
2543
2544 Int_t ndim1=GetImageDimension(1);
2545 Int_t ndim2=GetImageDimension(2);
2546 Int_t ndim3=GetImageDimension(3);
2547
2548 // Check whether the layer number is within bounds
2549 if ((ndims==2 && layer>1) || (ndims>2 && layer>ndim3)) return 0;
2550
2551 // Read the pixels of the specified layer
2552 TArrayI ifirst(ndims);
2553 TArrayI ilast(ndims);
2554 TArrayI incr(ndims);
2555 for (Int_t i=0; i<ndims; i++)
2556 {
2557 ifirst.SetAt(1,i);
2558 ilast.SetAt(1,i);
2559 incr.SetAt(1,i);
2560 }
2561
2562 // Read a full layer content
2563 ilast.SetAt(ndim1,0);
2564 ilast.SetAt(ndim2,1);
2565
2566 // The selected layer
2567 if (ndim3)
2568 {
2569 ifirst.SetAt(layer,2);
2570 ilast.SetAt(layer,2);
2571 }
2572
2573 // Read the layer into the data storage
2574 // For a (nrow,ncol) matrix, the FITS parameters correspond to ncol=NAXIS1 (=width) and nrow=NAXIS2 (=height).
2575 // The FITS image data start at the lower left corner and end at the right upper corner and follow a
2576 // pixel array storage with the following sequence convention for pixel coordinates (ix,iy) :
2577 // (1,1),(2,1),(3,1),...(NAXIS1,1),(1,2),(2,2),(3,2),...(NAXIS1,2),...(1,NAXIS2),(2,NAXIS2),...(NAXIS1,NAXIS2).
2578 // This implies that for a matrix interpretation the row numbering should be considered as inverted,
2579 // such that (row,col)=(1,1) indicates the lower left corner instead of the (usual) upper left corner.
2580 // With this convention, the upper left corner is (nrow,1), the lower left corner is (1,ncol)
2581 // and the upper right corner is (nrow,ncol).
2582 GetImageArray(arr,ifirst,ilast,incr);
2583
2584 Int_t npix=arr.GetSize();
2585 return npix;
2586}
2587
2588void NcFITSIO::ApplyPixelThreshold(TArrayD &arr,Double_t thres)
2589{
2596
2597 UInt_t npix=arr.GetSize();
2598
2599 for (UInt_t i=0; i<npix; i++)
2600 {
2601 if (arr.At(i) < thres) arr.SetAt(0,i);
2602 }
2603}
2604
2605void NcFITSIO::RescalePixels(TArrayD &arr,Double_t max)
2606{
2612
2613 UInt_t npix=arr.GetSize();
2614
2615 if (!npix) return;
2616
2617 Double_t minval=0;
2618 Double_t maxval=0;
2619 Double_t val=0;
2620 for (UInt_t i=0; i<npix; i++)
2621 {
2622 val=arr.At(i);
2623
2624 if (!i)
2625 {
2626 minval=val;
2627 maxval=val;
2628 continue;
2629 }
2630
2631 if (val<minval) minval=val;
2632 if (val>maxval) maxval=val;
2633 }
2634
2635 Double_t range=maxval-minval;
2636 Double_t fact=-1;
2637 if (range>0) fact=max/range;
2638
2639 for (UInt_t i=0; i<npix; i++)
2640 {
2641 if (fact<0)
2642 {
2643 arr.SetAt(max,i);
2644 }
2645 else
2646 {
2647 val=arr.At(i);
2648 val=fact*(val-minval);
2649 arr.SetAt(val,i);
2650 }
2651 }
2652}
2653
2654TObject* NcFITSIO::Clone(const char* name) const
2655{
2664
2665 NcFITSIO* q=new NcFITSIO(*this);
2666 if (name)
2667 {
2668 if (strlen(name)) q->SetName(name);
2669 }
2670 return q;
2671}
2672
ClassImp(NcFITSIO)
I/O interface for FITS files.
Definition NcFITSIO.h:27
@ kComplexArray
Definition NcFITSIO.h:33
@ kComplexNumber
Definition NcFITSIO.h:33
@ kRealNumber
Definition NcFITSIO.h:33
@ kLogical
Definition NcFITSIO.h:33
@ kStringArray
Definition NcFITSIO.h:33
@ kString
Definition NcFITSIO.h:33
@ kLogicalArray
Definition NcFITSIO.h:33
@ kRealArray
Definition NcFITSIO.h:33
TString * fComments
Definition NcFITSIO.h:92
void Initialize()
Definition NcFITSIO.cxx:338
Bool_t LoadHeaderInfo()
Definition NcFITSIO.cxx:485
Int_t * fColumnLayers
Definition NcFITSIO.h:97
void ListTable(Int_t width=-10, Int_t rstart=1, Int_t rend=0, Int_t cstart=1, Int_t cend=0)
Int_t GetImageLayer(TASImage &im, Int_t layer=1, Double_t *thres=0, Double_t max=-1)
Int_t fNkeys
Definition NcFITSIO.h:89
Int_t GetTableCell(Double_t &val, Int_t row, Int_t col, Int_t layer=1)
NcFITSIO(const char *name="NcFITSIO", const char *title="FITS data I/O interface")
Definition NcFITSIO.cxx:297
TString * fKeyNames
Definition NcFITSIO.h:90
UInt_t GetImageArray(TArrayD &arr, TArrayI ifirst, TArrayI ilast, TArrayI incr)
Int_t GetHDUCount() const
Definition NcFITSIO.cxx:900
TString * fColumnNames
Definition NcFITSIO.h:95
Int_t GetTableNcolumns() const
Definition NcFITSIO.cxx:951
fitsfile * fOutput
Definition NcFITSIO.h:85
TString * fKeyValues
Definition NcFITSIO.h:91
void ListFileHeader(Int_t mode=1) const
TString GetKeywordValue(TString keyname, Int_t mode=0)
Definition NcFITSIO.cxx:845
void ListHDUHeader() const
eColumnTypes * fColumnTypes
Definition NcFITSIO.h:96
Int_t fNrows
Definition NcFITSIO.h:93
virtual TObject * Clone(const char *name="") const
Int_t fNcolumns
Definition NcFITSIO.h:94
TString fExtensionName
Definition NcFITSIO.h:87
Int_t GetColumnNumber(TString colname, Int_t mode=0) const
Definition NcFITSIO.cxx:962
void RescalePixels(TArrayD &arr, Double_t max)
Int_t LoadLayer(TArrayD &arr, Int_t layer)
TString fFilename
Definition NcFITSIO.h:82
TArrayI * fSizes
Definition NcFITSIO.h:98
Bool_t OpenInputFile(TString specs)
Definition NcFITSIO.cxx:413
Int_t fExtensionNumber
Definition NcFITSIO.h:88
void Reset()
Definition NcFITSIO.cxx:365
Int_t GetTableNrows() const
Definition NcFITSIO.cxx:940
virtual ~NcFITSIO()
Definition NcFITSIO.cxx:308
void ApplyPixelThreshold(TArrayD &arr, Double_t thres)
Int_t GetTableColumn(TArrayD &arr, Int_t col, Int_t rstart=1, Int_t rend=0, Int_t layer=1)
fitsfile * fInput
Definition NcFITSIO.h:84
TString fFilenameFilter
Definition NcFITSIO.h:83
eHDUTypes fType
Definition NcFITSIO.h:86
Bool_t SelectHDU(TString extname="[0]")
Definition NcFITSIO.cxx:777
Bool_t IsTable() const
Definition NcFITSIO.cxx:885
Int_t GetImageDimension(Int_t i=0) const
TString StripFilter(TString filename) const
Definition NcFITSIO.cxx:470
@ kTableHDU
Definition NcFITSIO.h:30
@ kImageHDU
Definition NcFITSIO.h:30
TString GetColumnName(Int_t colnum) const
Definition NcFITSIO.cxx:993