Changeset 1353 in Sophya for trunk/SophyaExt/FitsIOServer
- Timestamp:
- Dec 15, 2000, 11:58:21 AM (25 years ago)
- Location:
- trunk/SophyaExt/FitsIOServer
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fitsfile.cc
r1352 r1353 345 345 } 346 346 347 bool FitsInFile::hasKeyword(string keyw, int hdunum) 348 { 349 bool has=false; 350 int status = 0; 351 if (hdunum != hdunum_ ) 352 { 353 int hdutype; 354 fits_movabs_hdu(fptr_,hdunum,&hdutype,&status); 355 } 356 357 char value[FLEN_VALUE]; 358 char* keyname= const_cast<char*>(keyw.c_str()); 359 fits_read_keyword(fptr_,keyname,value,NULL,&status); 360 if (status == 0) 361 has = true; 362 else 363 if (status == KEY_NO_EXIST ) status =0; 364 else fits_report_error(stderr,status); 365 if (hdunum != hdunum_ ) 366 { 367 int hdutype; 368 if (hdunum_ != 0) 369 fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status); 370 else fits_movabs_hdu(fptr_,1,&hdutype,&status); 371 372 } 373 return has; 374 } 347 375 348 376 void FitsInFile::GetImageParameters (fitsfile* fileptr,FitsDataType& dataType,int& naxis,vector<int>& naxisn) … … 510 538 else 511 539 { 512 cout << " hdutype= " << (int)hdutype_ << endl;540 cout << " hdutype= " << hdutype_ << endl; 513 541 throw PException("FitsFile::NbColsFromFits, HDU not supported"); 514 542 } … … 528 556 else 529 557 { 530 cout << "hdutype= " << (int)hdutype_ << endl;558 cout << "hdutype= " << hdutype_ << endl; 531 559 throw PException("FitsFile::NentriesFromFits, this HDU is not supported"); 532 560 } … … 712 740 \param <nentries> number of data to be read 713 741 */ 714 void FitsInFile::GetBinTabFCol( r_8* valeurs,int nentries, int NoCol) const742 void FitsInFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const 715 743 { 716 744 int status= 0; … … 749 777 same as previous method with float data 750 778 */ 751 void FitsInFile::GetBinTabFCol( r_4* valeurs,int nentries, int NoCol) const779 void FitsInFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const 752 780 { 753 781 int status= 0; … … 786 814 */ 787 815 788 void FitsInFile::GetBinTabFCol(int _4* valeurs,int nentries, int NoCol) const816 void FitsInFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const 789 817 { 790 818 int status= 0; … … 853 881 \param <nentries> number of data to be read 854 882 */ 855 void FitsInFile::GetSingleColumn( r_8* map, int nentries) const883 void FitsInFile::GetSingleColumn(double* map, int nentries) const 856 884 { 857 885 int status = 0; … … 880 908 else 881 909 { 882 cout << " hdutype= " << (int)hdutype_ << endl;910 cout << " hdutype= " << hdutype_ << endl; 883 911 throw IOExc("FitsFile::GetSingleColumn, this HDU is unknown"); 884 912 } … … 888 916 same as above with float data 889 917 */ 890 void FitsInFile::GetSingleColumn( r_4* map, int nentries) const918 void FitsInFile::GetSingleColumn(float* map, int nentries) const 891 919 { 892 920 int status = 0; … … 913 941 else 914 942 { 915 cout << " hdutype= " << (int)hdutype_ << endl;943 cout << " hdutype= " << hdutype_ << endl; 916 944 throw IOExc("FitsFile::GetSingleColumn this HDU is unknown"); 917 945 } … … 921 949 same as above with int data 922 950 */ 923 void FitsInFile::GetSingleColumn( int _4* map, int nentries) const951 void FitsInFile::GetSingleColumn( int* map, int nentries) const 924 952 { 925 953 int status = 0; … … 946 974 else 947 975 { 948 cout << " hdutype= " << (int)hdutype_ << endl;976 cout << " hdutype= " << hdutype_ << endl; 949 977 throw IOExc("FitsFile::GetSingleColumn this HDU is unknown"); 950 978 } … … 1305 1333 throw PException("FitsFile:::makeHeaderImageOnFits:unprogrammed type of data "); 1306 1334 } 1335 1307 1336 // on ajoute eventuellement un dvlist prepare et la doc SOPHYA 1308 1337 hdunum_++; … … 1313 1342 } 1314 1343 1315 // write supplementary keywords 1344 // header format FITS 1345 1346 writeAppendedHeaderOnFits(); 1347 1348 // write supplementary keywords (from SOPHYA) 1316 1349 // dvl.Print(); 1317 1350 if (ptr_dvl != NULL) addKeywordsOfDVList(*ptr_dvl); … … 1328 1361 \param <nbData> number of data to be written 1329 1362 */ 1330 void FitsOutFile::PutImageToFits(int nbData, r_8* map) const1363 void FitsOutFile::PutImageToFits(int nbData, double* map) const 1331 1364 { 1332 1365 int status = 0; … … 1340 1373 same as previous method with float data 1341 1374 */ 1342 void FitsOutFile::PutImageToFits(int nbData, r_4* map) const1375 void FitsOutFile::PutImageToFits(int nbData, float* map) const 1343 1376 { 1344 1377 int status = 0; … … 1352 1385 1353 1386 same as previous method with int data */ 1354 void FitsOutFile::PutImageToFits( int nbData, int _4* map) const1387 void FitsOutFile::PutImageToFits( int nbData, int* map) const 1355 1388 { 1356 1389 int status = 0; … … 1455 1488 NULL,extn,&status); 1456 1489 if( status ) printerror( status ); 1457 // on ajoute eventuellement un dvlist prepare 1490 1491 int ii; 1492 for(ii = 0; ii < tfields; ii++) 1493 { 1494 delete [] tform[ii]; 1495 } 1496 delete [] ttype; 1497 delete [] tform; 1498 1499 // on ajoute eventuellement des mots-cles 1500 1458 1501 if ( hdunum_ == 0 ) 1459 1502 { … … 1463 1506 } 1464 1507 else hdunum_++; 1465 int ii; 1466 for(ii = 0; ii < tfields; ii++) 1467 { 1468 delete [] tform[ii]; 1469 } 1470 delete [] ttype; 1471 delete [] tform; 1472 // 1473 // write supplementary keywords 1508 1509 // header format FITS 1510 1511 writeAppendedHeaderOnFits(); 1512 1513 // write SOPHYA keywords 1474 1514 if (ptr_dvl != NULL) addKeywordsOfDVList(*ptr_dvl); 1475 1515 } 1516 1517 1476 1518 1477 1519 /*! \fn void SOPHYA::FitsOutFile::PutColToFits(int nocol, int nentries, double* donnees) const … … 1480 1522 \param <nentries> number of data to be written 1481 1523 */ 1482 void FitsOutFile::PutColToFits(int nocol, int nentries, r_8* donnees) const 1524 1525 void FitsOutFile::PutColToFits(int nocol, int nentries, double* donnees) const 1483 1526 { 1484 1527 int status = 0; … … 1509 1552 same as previous method with float data 1510 1553 */ 1511 void FitsOutFile::PutColToFits(int nocol, int nentries, r_4* donnees) const1554 void FitsOutFile::PutColToFits(int nocol, int nentries, float* donnees) const 1512 1555 { 1513 1556 int status = 0; … … 1541 1584 same as previous method with int data 1542 1585 */ 1543 void FitsOutFile::PutColToFits(int nocol, int nentries, int _4* donnees) const1586 void FitsOutFile::PutColToFits(int nocol, int nentries, int* donnees) const 1544 1587 { 1545 1588 int status = 0; … … 1702 1745 char strval[FLEN_VALUE]= ""; 1703 1746 char *comkey = "COMMENT"; 1704 fits_read_keyword(fptr_, keyname, strval, NULL, &status);1705 if (status != 0 || strncmp(keyname,comkey,LEN_KEYWORD-1) == 0 )1747 // fits_read_keyword(fptr_, keyname, strval, NULL, &status); 1748 // if (status != 0 || strncmp(keyname,comkey,LEN_KEYWORD-1) == 0 ) 1706 1749 { 1707 1750 string coco = dvl.GetComment(key); … … 1762 1805 } 1763 1806 1807 1808 /*! \fn void FitsOutFile::appendInHeader(FitsInFile& infits, int hdunum) 1809 1810 get a header from FitsInFile and append to the header beeing built 1811 (shifting mandatory keywords) 1812 */ 1813 1814 void FitsOutFile::appendInputHeader(FitsInFile& infits, int hdunum) 1815 { 1816 int status = 0; 1817 int hdutype; 1818 fitsfile* fptr=infits.fitsfilePtr(); 1819 fits_movabs_hdu(fptr,hdunum,&hdutype,&status); 1820 if( status ) fits_report_error(stderr,status); 1821 1822 // get number of keywords 1823 int nkeys,keypos; 1824 fits_get_hdrpos(fptr,&nkeys,&keypos,&status); 1825 if( status ) fits_report_error(stderr,status); 1826 // shift with the number of mandatory keywords 1827 int num= 0; 1828 // if primary header 1829 if (hdunum == 1) 1830 { 1831 // read NAXIS 1832 int naxis=0; 1833 fits_read_key(fptr,TINT,"NAXIS",&naxis,NULL,&status); 1834 // number of mandatory keywords 1835 num = naxis+3; 1836 } 1837 // extensions 1838 else 1839 { 1840 if (hdutype == IMAGE_HDU) 1841 { 1842 // read NAXIS 1843 int naxis=0; 1844 fits_read_key(fptr,TINT,"NAXIS",&naxis,NULL,&status); 1845 // number of mandatory keywords 1846 num = naxis+5; 1847 } 1848 else 1849 if(hdutype == ASCII_TBL || hdutype == BINARY_TBL) 1850 { 1851 // number of mandatory keywords 1852 num = 8; 1853 } 1854 } 1855 int j; 1856 char keyname[LEN_KEYWORD]; 1857 char value[FLEN_VALUE]; 1858 char comment[FLEN_COMMENT]; 1859 for(j = num+1; j <= nkeys; j++) 1860 { 1861 char dtype; 1862 fits_read_keyn(fptr,j,keyname,value,comment,&status); 1863 if(status) 1864 { 1865 fits_report_error(stderr,status); 1866 status=0; 1867 } 1868 string kn(keyname); 1869 string cm(comment); 1870 string val(value); 1871 FitsKeyword kw(kn, val, cm); 1872 mots_cles_.push_back(kw); 1873 } 1874 } 1875 void FitsOutFile::writeAppendedHeaderOnFits() 1876 { 1877 for (list<FitsKeyword>::iterator it=mots_cles_.begin(); it !=mots_cles_.end(); it++) 1878 { 1879 (*it).writeOnFits(fptr_); 1880 } 1881 mots_cles_.clear(); 1882 } 1883 1884 void FitsOutFile::insertKeywordOnHeader(string keyname, double value, string comment) 1885 { 1886 char* cvalue = new char[16]; 1887 sprintf(cvalue,"%e",value); 1888 // char* kn = const_cast<char*>(keyname.c_str()); 1889 // char* cm = const_cast<char*>(comment.c_str()); 1890 FitsKeyword kw(keyname, string(cvalue), comment); 1891 mots_cles_.push_back(kw); 1892 } 1893 1894 void FitsOutFile::insertCommentLineOnHeader(string comment) 1895 { 1896 FitsKeyword kw(comment); 1897 mots_cles_.push_back(kw); 1898 } 1899 1900 void FitsOutFile::PrintHeaderToBeAppended() 1901 { 1902 cout << " contenu du header en cours de fabrication " << endl; 1903 for (list<FitsKeyword>::iterator it=mots_cles_.begin(); it !=mots_cles_.end(); it++) 1904 { 1905 (*it).Print(); 1906 } 1907 } 1908 1909 1910 FitsKeyword::FitsKeyword() 1911 { 1912 datatype_=' '; 1913 keyname_ = string(""); 1914 dvalue_=0.; 1915 ivalue_=1; 1916 svalue_=string(""); 1917 comment_=string(""); 1918 } 1919 1920 FitsKeyword::FitsKeyword(string comment) 1921 { 1922 datatype_=' '; 1923 keyname_=string("COMMENT"); 1924 comment_=comment; 1925 } 1926 1927 FitsKeyword::FitsKeyword(string keyname, string value, string comment) : keyname_(keyname), comment_(comment) 1928 { 1929 int status=0; 1930 char dtype; 1931 const char* val= value.c_str(); 1932 char* valk = const_cast<char*>(val); 1933 fits_get_keytype(valk,&dtype,&status); 1934 if(status) 1935 { 1936 status=0; 1937 datatype_=' '; 1938 } 1939 else datatype_=dtype; 1940 1941 switch( datatype_ ) 1942 { 1943 case 'C': 1944 { 1945 svalue_ = string(val); 1946 break; 1947 } 1948 case 'I': 1949 { 1950 ivalue_ = atoi(val); 1951 break; 1952 } 1953 case 'L': 1954 { 1955 // cout << " ATTENTION : pb a regler avec logical!" << endl; 1956 if (value[0] == 'T') ivalue_ = 1; 1957 else ivalue_ = 0; 1958 break; 1959 } 1960 case 'F': 1961 { 1962 dvalue_ = atof(val); 1963 break; 1964 } 1965 case 'X': 1966 { 1967 throw IOExc("FitsKeyword , complex keyword value not supported"); 1968 } 1969 } 1970 } 1971 1972 void FitsKeyword::writeOnFits(fitsfile* ptr) 1973 { 1974 int status=0; 1975 // char* keyname = new char[LEN_KEYWORD]; 1976 // char* comment = new char[FLEN_COMMENT]; 1977 char* keyname; 1978 char* comment; 1979 keyname = const_cast<char*>(keyname_.c_str()); 1980 comment = const_cast<char*>(comment_.c_str()); 1981 // get number of keywords 1982 int nkeys,keypos; 1983 fits_get_hdrpos(ptr,&nkeys,&keypos,&status); 1984 switch( datatype_ ) 1985 { 1986 case 'C': 1987 { 1988 char value[FLEN_VALUE]; 1989 strncpy(value,svalue_.c_str(),FLEN_VALUE) ; 1990 fits_write_key(ptr,TSTRING,keyname,&value, comment,&status); 1991 fits_report_error(stderr,status); 1992 break; 1993 } 1994 case 'I': 1995 { 1996 fits_write_key(ptr,TINT,keyname,&ivalue_, comment,&status); 1997 fits_report_error(stderr,status); 1998 break; 1999 } 2000 case 'L': 2001 { 2002 fits_write_key(ptr,TLOGICAL,keyname,&ivalue_, comment,&status); 2003 fits_report_error(stderr,status); 2004 break; 2005 } 2006 case 'F': 2007 { 2008 fits_write_key(ptr,TDOUBLE,keyname,&dvalue_, comment,&status); 2009 fits_report_error(stderr,status); 2010 break; 2011 } 2012 case 'X': 2013 { 2014 cout << "FitsKeyword : complex keyword value not supported" << endl;; 2015 } 2016 default : 2017 { 2018 char *comkey = "COMMENT"; 2019 if(strncmp(keyname,comkey,LEN_KEYWORD-1) == 0) 2020 { 2021 fits_write_comment(ptr,comment,&status); 2022 fits_report_error(stderr,status); 2023 } 2024 else 2025 { 2026 cout << " WARNING (FitsKeyword::writeOnFits) : unrecognized keyword : " << keyname_ << endl; 2027 } 2028 } 2029 } 2030 } 2031 2032 void FitsKeyword::Print() 2033 { 2034 switch( datatype_ ) 2035 { 2036 case 'C': 2037 { 2038 cout << " mot cle : " << keyname_ << " valeur : " << svalue_ << " commentaire : " << comment_ <<endl; 2039 break; 2040 } 2041 case 'I': 2042 { 2043 cout << " mot cle : " << keyname_ << " valeur : " << ivalue_ << " commentaire : " << comment_ <<endl; 2044 break; 2045 } 2046 case 'L': 2047 { 2048 cout << " mot cle : " << keyname_ << " valeur : " << ivalue_ << " commentaire : " << comment_ <<endl; 2049 break; 2050 } 2051 case 'F': 2052 { 2053 cout << " mot cle : " << keyname_ << " valeur : " << dvalue_ << " commentaire : " << comment_ <<endl; 2054 break; 2055 } 2056 case 'X': 2057 { 2058 cout << "FitsKeyword : complex keyword value not supported" << endl;; 2059 } 2060 default : 2061 { 2062 cout << " mot cle : " << keyname_ << " commentaire : " << comment_ <<endl; 2063 } 2064 } 2065 } -
trunk/SophyaExt/FitsIOServer/fitsfile.h
r1352 r1353 20 20 class FitsInFile; 21 21 class FitsOutFile; 22 22 23 24 25 class FitsKeyword 26 { 27 28 public: 29 30 FitsKeyword(); 31 FitsKeyword(string comment); 32 FitsKeyword(string keyname, string value, string comment); 33 void writeOnFits(fitsfile* ptr); 34 35 void Print(); 36 37 private: 38 39 char datatype_; 40 string keyname_; 41 double dvalue_; 42 int ivalue_; 43 string svalue_; 44 string comment_; 45 }; 46 47 23 48 24 49 // 25 50 //! Class for managing Interface for SOPHYA objects to FITS Format Files (uses cfitsio lib) 26 51 27 52 class FitsIOHandler { 28 53 29 54 … … 77 102 inline void firstImageOnPrimaryHeader(bool choice) {imageOnPrimary_=choice;} 78 103 inline int currentHeaderIndex() {return hdunum_;} 104 inline fitsfile* fitsfilePtr() {return fptr_;} 79 105 80 106 … … 107 133 int NbBlocks(); 108 134 static void GetBlockType(char flnm[], int hdunum, FitsExtensionType& typeOfExtension, int& naxis, vector<int>& naxisn, FitsDataType& dataType, DVList& dvl ); 109 void ReadHeader(int hdunum); 110 135 136 void ReadHeader(int hdunum); 137 bool hasKeyword(string keyw, int hdunum); 138 111 139 /*! \return a reference on a DVList containing the keywords from FITS file */ 112 140 inline const DVList& DVListFromFits() const { return dvl_;} … … 157 185 /*! \return true if the current header corresponds to a FITS ASCII or BINTABLE extension */ 158 186 inline bool IsFitsTable() const {return (hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL);} 187 188 159 189 160 190 … … 195 225 void GetSingleColumn(int_4* map, int nentries) const; 196 226 227 228 229 230 197 231 private : 198 232 … … 253 287 254 288 void makeHeaderBntblOnFits ( string fieldType, vector<string> Noms, int nentries, int tfields, DVList* dvl, string extname, vector<int> taille_des_chaines) ; 289 void appendInputHeader(FitsInFile& headerin, int hdunum); 290 void writeAppendedHeaderOnFits(); 291 void PrintHeaderToBeAppended(); 292 void insertCommentLineOnHeader(string comment); 293 void insertKeywordOnHeader(string keyname, double value, string comment); 255 294 void PutColToFits(int nocol, int nentries, r_8* donnees) const; 256 295 void PutColToFits(int nocol, int nentries, r_4* donnees) const; … … 277 316 278 317 DVList* dvlToPrimary_; /**< for transferring keywords when creating primary header */ 318 list<FitsKeyword> mots_cles_; 319 279 320 }; 280 321 … … 292 333 vector<string> cdata_; 293 334 vector<string> ColName_; 294 295 335 }; 296 336 297 337 338 339 340 298 341 } // Fin du namespace 299 342 300 301 343 #endif -
trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc
r1334 r1353 63 63 ownobj_ = false; 64 64 } 65 66 65 67 66 -
trunk/SophyaExt/FitsIOServer/fitsspherehealpix.h
r1322 r1353 30 30 void Mollweide_picture_projection(char flnm[]); 31 31 void sinus_picture_projection(char flnm[]); 32 void ReWriteFromFitsToFits(FitsInFile& headerin, FitsOutFile& os); 32 33 33 34
Note:
See TracChangeset
for help on using the changeset viewer.