Changeset 1418 in Sophya
- Timestamp:
- Feb 22, 2001, 5:45:40 PM (25 years ago)
- Location:
- trunk/SophyaExt/FitsIOServer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fitsfile.cc
r1379 r1418 351 351 cout << " WARNING (FitsInFile::ReadHeader) : no SOPHYA object on HDU number : " << hdunum_ << endl; 352 352 } 353 } 354 if ( hdutype_ == FitsExtensionType_EOF ) 355 { 356 throw PException("FitsFile::ReadHeader, attempt to read through EOF"); 353 357 } 354 358 } … … 1764 1768 // 1765 1769 strncpy(keyname, "CREATOR", LEN_KEYWORD); 1766 keyname[ LEN_KEYWORD-1] = '\0';1770 keyname[7] = '\0'; 1767 1771 strcpy(strval, "SOPHYA"); 1768 1772 strcpy(comment," SOPHYA Package - FITSIOServer "); … … 1789 1793 { 1790 1794 MuTyV::MTVType keytype= (*it).second.elval.Type(); 1791 char keyname[10]; 1792 strncpy(keyname,(*it).first.substr(0,64).c_str(),10); 1793 string key(keyname); 1795 char keyname[LEN_KEYWORD]; 1796 strncpy(keyname,(*it).first.substr(0,64).c_str(),LEN_KEYWORD); 1797 int bout = ((*it).first.substr(0,64).length() < LEN_KEYWORD) ? (*it).first.substr(0,64).length() : LEN_KEYWORD-1; 1798 keyname[bout] = '\0'; 1799 string key((*it).first.substr(0,64)); 1800 // string key(keyname); 1794 1801 char comment[FLEN_COMMENT]; 1795 1802 char strval[FLEN_VALUE]= ""; … … 1934 1941 void FitsOutFile::insertKeywordOnHeader(string keyname, double value, string comment) 1935 1942 { 1936 char * cvalue = new char[16];1943 char cvalue[16]; 1937 1944 sprintf(cvalue,"%e",value); 1938 FitsKeyword kw(keyname, string(cvalue), comment); 1945 FitsKeyword kw(keyname, string(cvalue), comment, 'F'); 1946 mots_cles_.push_back(kw); 1947 } 1948 void FitsOutFile::insertKeywordOnHeader(string keyname, int value, string comment) 1949 { 1950 char cvalue[16]; 1951 sprintf(cvalue,"%d",value); 1952 FitsKeyword kw(keyname, string(cvalue), comment, 'I'); 1953 mots_cles_.push_back(kw); 1954 } 1955 void FitsOutFile::insertKeywordOnHeader(string keyname, string value, string comment) 1956 { 1957 FitsKeyword kw(keyname, value , comment, 'C'); 1939 1958 mots_cles_.push_back(kw); 1940 1959 } … … 1971 1990 keyname_=string("COMMENT"); 1972 1991 comment_=comment; 1973 } 1992 } 1974 1993 1975 1994 FitsKeyword::FitsKeyword(string keyname, string value, string comment) : keyname_(keyname), comment_(comment) … … 2019 2038 } 2020 2039 2040 // constructeur pour les mots-cles maison (ne prvenant pas de la lecture d'un fichier fits) 2041 FitsKeyword::FitsKeyword(string keyname, string value, string comment, char type) : keyname_(keyname), comment_(comment), datatype_(type) 2042 { 2043 char dtype; 2044 const char* val= value.c_str(); 2045 char* valk = const_cast<char*>(val); 2046 switch( datatype_ ) 2047 { 2048 case 'C': 2049 { 2050 strip(valk, 'B','\''); 2051 svalue_ = string(valk); 2052 break; 2053 } 2054 case 'I': 2055 { 2056 ivalue_ = atoi(val); 2057 break; 2058 } 2059 case 'L': 2060 { 2061 bool bb = value.c_str(); 2062 ivalue_ = (int)bb; 2063 break; 2064 } 2065 case 'F': 2066 { 2067 dvalue_ = atof(val); 2068 break; 2069 } 2070 case 'X': 2071 { 2072 throw IOExc("FitsKeyword , complex keyword value not supported"); 2073 } 2074 } 2075 } 2076 2021 2077 void FitsKeyword::writeOnFits(fitsfile* ptr) 2022 2078 { 2023 2079 int status=0; 2024 // char* keyname = new char[LEN_KEYWORD]; 2025 // char* comment = new char[FLEN_COMMENT]; 2026 char* keyname; 2027 char* comment; 2028 keyname = const_cast<char*>(keyname_.c_str()); 2029 comment = const_cast<char*>(comment_.c_str()); 2030 // get number of keywords 2080 char keyname[LEN_KEYWORD]; 2081 char comment[FLEN_COMMENT]; 2082 keyname_.copy(keyname, LEN_KEYWORD); 2083 int bout = (keyname_.length() < LEN_KEYWORD) ? keyname_.length() : LEN_KEYWORD-1; 2084 keyname[bout] = '\0'; 2085 comment_.copy( comment, FLEN_COMMENT); 2086 bout = (comment_.length() < FLEN_COMMENT) ? comment_.length() : FLEN_COMMENT-1; 2087 comment[bout]= '\0'; 2088 2031 2089 int nkeys,keypos; 2032 2090 fits_get_hdrpos(ptr,&nkeys,&keypos,&status); … … 2035 2093 case 'C': 2036 2094 { 2037 char value[FLEN_VALUE]; 2038 strncpy(value,svalue_.c_str(),FLEN_VALUE) ; 2095 char value[FLEN_VALUE]=""; 2096 svalue_.copy(value, FLEN_VALUE-1); 2097 int fin = (svalue_.length() < FLEN_VALUE) ? svalue_.length() : FLEN_VALUE-1; 2098 value[fin]= '\0'; 2039 2099 fits_write_key(ptr,TSTRING,keyname,&value, comment,&status); 2040 2100 fits_report_error(stderr,status); -
trunk/SophyaExt/FitsIOServer/fitsfile.h
r1359 r1418 31 31 FitsKeyword(string comment); 32 32 FitsKeyword(string keyname, string value, string comment); 33 FitsKeyword(string keyname, string value, string comment, char type); 33 34 void writeOnFits(fitsfile* ptr); 34 35 … … 294 295 void PrintHeaderToBeAppended(); 295 296 void insertCommentLineOnHeader(string comment); 296 void insertKeywordOnHeader(string keyname, double value, string comment); 297 void insertKeywordOnHeader(string keyname, double value, string comment); 298 void insertKeywordOnHeader(string keyname, int value, string comment); 299 void insertKeywordOnHeader(string keyname, string value, string comment); 297 300 void PutColToFits(int nocol, int nentries, r_8* donnees) const; 298 301 void PutColToFits(int nocol, int nentries, r_4* donnees) const;
Note:
See TracChangeset
for help on using the changeset viewer.