Changeset 2843 in Sophya for trunk/SophyaExt/FitsIOServer
- Timestamp:
- Nov 18, 2005, 6:44:57 PM (20 years ago)
- Location:
- trunk/SophyaExt/FitsIOServer
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fitsblkrw.h
r2820 r2843 114 114 }; 115 115 116 117 /*! 118 Write character string data to binary/ascii HDU data in a fits file. 119 See cfitsio function fits_write_col() for more detail. 120 \param colnum : table column number (starting from 1) 121 \param firstrow : the write operation starting row (starting from 1) 122 \param firstelem : the firstelem (for vector type columns) 123 \param d : pointer to string type array to be written 124 \param sz : number of data elements to be written 125 \param width : column width 126 */ 127 void WriteStringColumnData(FitsInOutFile& fios, int colnum, long firstrow, 128 long firstelem, const string * d, size_t sz, 129 long width=0) 130 { 131 int status = 0; 132 if (width < 1) width = 16; 133 for(size_t kk=0; kk<sz; kk++) { 134 char * cp = const_cast<char *>(d[kk].c_str()); 135 status = 0; 136 fits_write_col(fios.FitsPtr(), FitsTypes::DataType(cp), colnum, 137 firstrow+kk, firstelem, 1, &cp, &status); 138 if ( status ) { 139 fits_report_error(stderr, status); 140 char buff[32]; 141 fits_get_errstatus(status, buff); 142 string msg = "WriteStringColumnData Error: " ; 143 msg += buff; 144 sprintf(buff," kk=%ld",kk); msg += buff; 145 throw FitsIOException(msg); 146 } 147 } 148 return; 149 } 150 151 /*! 152 Read character string data to binary/ascii HDU data in a fits file. 153 See cfitsio function fits_read_col() for more detail. 154 \param colnum : table column number (starting from 1) 155 \param firstrow : the read operation starting point (row) (starting from 1) 156 \param firstelem : the firstelem (for vector type columns) 157 \param d : pointer to string type array to be read 158 \param sz : number of data elements to be read 159 \param width : column width 160 */ 161 void ReadStringColumnData(FitsInOutFile& fios, int colnum, long firstrow, 162 long firstelem, string * d, size_t sz, long width) 163 { 164 int status = 0; 165 int anynul = 0; 166 char buff[1024]; 167 for(size_t kk=0; kk<sz; kk++) { 168 fits_read_col(fios.FitsPtr(), FitsTypes::DataType(buff), colnum, 169 firstrow, firstelem+kk, 1, NULL, &buff, &anynul, &status); 170 d[kk] = buff; 171 if ( status ) { 172 fits_report_error(stderr, status); 173 char buff[32]; 174 fits_get_errstatus(status, buff); 175 string msg = "ReadStringColumnData Error: " ; 176 msg += buff; 177 sprintf(buff," kk=%ld",kk); msg += buff; 178 throw FitsIOException(msg); 179 } 180 } 181 return; 182 } 183 116 184 } // Fin du namespace 117 185 -
trunk/SophyaExt/FitsIOServer/fitshdtable.cc
r2820 r2843 217 217 218 218 219 /* 219 220 int toto() 220 221 { … … 224 225 // fio << xx; 225 226 } 226 227 227 */ 228 229 -
trunk/SophyaExt/FitsIOServer/fitsinoutfile.cc
r2820 r2843 7 7 #include <iostream> 8 8 9 string FitsTypes::ImageTypeToTypeString(int ityp) 10 { 11 switch (ityp) { 12 case BYTE_IMG : 13 return "uint_1"; 14 break; 15 case SHORT_IMG : 16 return "int_2"; 17 break; 18 case LONG_IMG : 19 return "int_4"; 20 break; 21 case FLOAT_IMG : 22 return "r_4"; 23 break; 24 case DOUBLE_IMG : 25 return "r_8"; 26 break; 27 default: 28 return "???" ; 29 break; 30 } 31 return ""; 32 } 33 string FitsTypes::DataTypeToTypeString(int ityp) 34 { 35 switch (ityp) { 36 case TBYTE : 37 return "uint_1"; 38 break; 39 case TSHORT : 40 return "int_2"; 41 break; 42 case TUSHORT : 43 return "uint_2"; 44 break; 45 case TINT : 46 if (sizeof(int) == 4) return "int_4"; 47 else if (sizeof(int) == 8) return "int_8"; 48 else if (sizeof(int) == 2) return "int_2"; 49 break; 50 case TUINT : 51 if (sizeof(int) == 4) return "uint_4"; 52 else if (sizeof(int) == 8) return "uint_8"; 53 else if (sizeof(int) == 2) return "uint_2"; 54 break; 55 case TLONG : 56 if (sizeof(long) == 4) return "int_4"; 57 else if (sizeof(long) == 8) return "int_8"; 58 else if (sizeof(long) == 2) return "int_2"; 59 break; 60 case TULONG : 61 if (sizeof(long) == 4) return "uint_4"; 62 else if (sizeof(long) == 8) return "uint_8"; 63 else if (sizeof(long) == 2) return "uint_2"; 64 break; 65 #ifdef TLONGLONG 66 case TLONGLONG : 67 return "int_8"; 68 break; 69 #endif 70 case TFLOAT : 71 return "r_4"; 72 break; 73 case TDOUBLE : 74 return "r_8"; 75 break; 76 case TCOMPLEX : 77 return "complex< r_4 >"; 78 break; 79 case TDBLCOMPLEX : 80 return "complex< r_8 >"; 81 break; 82 case TSTRING : 83 return "string"; 84 break; 85 default: 86 return "???" ; 87 break; 88 } 89 return ""; 90 } 9 91 10 92 /*! … … 20 102 fptr_ = NULL; 21 103 SetDef_BinTable(); 104 SetDef_StrColWidth(); 22 105 } 23 106 … … 29 112 fptr_ = NULL; 30 113 SetDef_BinTable(); 114 SetDef_StrColWidth(); 31 115 Open(name.c_str(), mode); 32 116 } … … 39 123 fptr_ = NULL; 40 124 SetDef_BinTable(); 125 SetDef_StrColWidth(); 41 126 Open(name, mode); 42 127 } … … 106 191 fits_movabs_hdu(FitsPtr() , 1, &hdutyp, &status); 107 192 status = 0; 108 float sfv = 2.0;193 float sfv = Version(); 109 194 fits_write_key(FitsPtr(), TFLOAT, "SOPHYAFV", &sfv, 110 195 "SOPHYA FitsIOServer module version", &status); … … 376 461 377 462 /*-- Methode --*/ 378 string FitsInOutFile::KeyValue(string const & key) 379 { 463 /*! 464 Return the value associated to the keyword \b key in the header as a string. 465 If the keyword is not found in the fits header, an empty string is returned 466 and the \b nosk flag is set to true. 467 */ 468 string FitsInOutFile::KeyValue(string const & key, bool& nosk) 469 { 470 nosk = false; 380 471 int status = 0; 381 472 char value[FLEN_VALUE], comm[FLEN_COMMENT]; 382 473 fits_read_key(FitsPtr(), TSTRING, const_cast<char *>(key.c_str()), value, comm, &status); 474 if (status == KEY_NO_EXIST) { 475 nosk = true; 476 return ""; 477 } 383 478 FitsCheckStatus(status, "FitsInOutFile::KeyValue() Error: "); 384 479 return value; -
trunk/SophyaExt/FitsIOServer/fitsinoutfile.h
r2820 r2843 63 63 static int DataType(complex<r_8> d) { return TDBLCOMPLEX; } 64 64 65 static int DataType(char* d) { return TSTRING; } 66 65 67 // Conversion entre type FITS et chaine - exemple TFLOAT -> r_4 66 68 static string ImageTypeToTypeString(int ityp); … … 88 90 inline fitsfile* FitsPtr() const { return fptr_; } 89 91 static float cfitsioVersion(); 92 //! Return the SOPHYA FitsIOServer version 93 static float Version() { return 2.0; } 90 94 91 95 //---- Header manipulation methods … … 150 154 inline int GetDef_TableType() { return def_tbltype; } 151 155 156 //! Defines default column width for strings (Aw) 157 inline void SetDef_StrColWidth(long w=16) { def_strcolw = w; } 158 //! Return default column width for strings (Aw) 159 inline long GetDef_StrColWidth() { return def_strcolw; } 160 152 161 //! Insert (add) a new column 153 162 void InsertColumn(int numcol, const char* colname, const char* fmt); … … 158 167 159 168 // Manipulation des informations de l'entete 160 //! Returns a given keyword value 161 string KeyValue(string const & key); 169 //! Retrieve a keyword value from the header 170 inline string KeyValue(string const & key) 171 { bool nosk; return KeyValue(key, nosk); } 172 //! Retrieve a keyword value from the header 173 string KeyValue(string const & key, bool& nosk); 162 174 //! Read header records and appends the information to dvl 163 175 int GetHeaderRecords(DVList& dvl); … … 184 196 // Default table type 185 197 int def_tbltype; 198 // default column width for strings 199 long def_strcolw; 186 200 }; 187 201 -
trunk/SophyaExt/FitsIOServer/fitsmanager.cc
r2820 r2843 21 21 static inline void ChkHLP() 22 22 { 23 if (hlistp = NULL) hlistp = new HandlerList;23 if (hlistp == NULL) hlistp = new HandlerList; 24 24 } 25 25
Note:
See TracChangeset
for help on using the changeset viewer.