Changeset 3114 in Sophya for trunk/SophyaExt/FitsIOServer/fabtcolread.cc
- Timestamp:
- Dec 13, 2006, 6:44:39 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fabtcolread.cc
r2791 r3114 338 338 SetNulVal(); SetDebug(0); 339 339 NFitsRead = 0; 340 FitsOF = NULL; FitsPtr = NULL;340 FitsOF = NULL; 341 341 LineDeb = LineFin = -1; 342 342 Buffer = NULL; … … 352 352 SetNulVal(); SetDebug(lp); 353 353 NFitsRead = 0; 354 FitsOF = NULL; FitsPtr = NULL;354 FitsOF = NULL; 355 355 LineDeb = LineFin = -1; 356 356 Buffer = NULL; … … 361 361 throw NullPtrError("FitsABTColRd::Init: FitsOpenFile pointer is NULL\n"); 362 362 363 FitsPtr = FitsOF->GetFitsPtr(); 364 if(FitsPtr==NULL) 363 if(GetFitsPtr()==NULL) 365 364 throw NullPtrError("FitsABTColRd::Init: FitsPtr pointer is NULL\n"); 366 365 … … 394 393 395 394 // Get number of columns 396 if(fits_get_num_cols( FitsPtr,&NBcol,&sta)) {395 if(fits_get_num_cols(GetFitsPtr(),&NBcol,&sta)) { 397 396 FitsOpenFile::printerror(sta); 398 397 throw NotAvailableOperation("FitsABTColRd::Init: Error getting number of columns\n"); … … 403 402 404 403 // Get number of rows 405 if(fits_get_num_rows( FitsPtr,&NBline,&sta)) {404 if(fits_get_num_rows(GetFitsPtr(),&NBline,&sta)) { 406 405 FitsOpenFile::printerror(sta); 407 406 throw NotAvailableOperation("FitsABTColRd::Init: Error getting number of rows\n"); … … 415 414 if(ColLabel.size() > 0) { 416 415 strcpy(labelcol,ColLabel.c_str()); 417 if(fits_get_colnum( FitsPtr,CASESEN,labelcol,&ColNum,&sta)) {416 if(fits_get_colnum(GetFitsPtr(),CASESEN,labelcol,&ColNum,&sta)) { 418 417 FitsOpenFile::printerror(sta); 419 418 throw NotAvailableOperation("FitsABTColRd::Init: Error getting column name\n"); … … 426 425 427 426 // Get column type 428 if(fits_get_coltype( FitsPtr,ColNum+1,&ColTypeCode,NULL,NULL,&sta)) {427 if(fits_get_coltype(GetFitsPtr(),ColNum+1,&ColTypeCode,NULL,NULL,&sta)) { 429 428 FitsOpenFile::printerror(sta); 430 429 throw ParmError("FitsABTColRd::Init: Error getting column type\n"); … … 440 439 int rc=0; 441 440 if(HDUType()==BINARY_TBL) { 442 fits_get_bcolparms( FitsPtr,ColNum+1,labelcol,tunit,tform441 fits_get_bcolparms(GetFitsPtr(),ColNum+1,labelcol,tunit,tform 443 442 ,&repeat,&tscale,&tzero,NULL,tdisp,&sta); 444 443 } else { 445 fits_get_acolparms( FitsPtr,ColNum+1,labelcol,&repeat,tunit,tform444 fits_get_acolparms(GetFitsPtr(),ColNum+1,labelcol,&repeat,tunit,tform 446 445 ,&tscale,&tzero,NULL,tdisp,&sta); 447 446 } … … 515 514 double FitsABTColRd::ReadKey(char *keyname) 516 515 { 517 return FitsOpenFile::ReadKey( FitsPtr,keyname);516 return FitsOpenFile::ReadKey(GetFitsPtr(),keyname); 518 517 } 519 518 … … 525 524 long FitsABTColRd::ReadKeyL(char *keyname) 526 525 { 527 return FitsOpenFile::ReadKeyL( FitsPtr,keyname);526 return FitsOpenFile::ReadKeyL(GetFitsPtr(),keyname); 528 527 } 529 528 … … 535 534 string FitsABTColRd::ReadKeyS(char *keyname) 536 535 { 537 return FitsOpenFile::ReadKeyS( FitsPtr,keyname);536 return FitsOpenFile::ReadKeyS(GetFitsPtr(),keyname); 538 537 } 539 538 … … 562 561 NFitsRead++; 563 562 double val; 564 fits_read_col( FitsPtr,TDOUBLE,ColNum+1,n+1,1,1,NULL,&val,NULL,&sta);563 fits_read_col(GetFitsPtr(),TDOUBLE,ColNum+1,n+1,1,1,NULL,&val,NULL,&sta); 565 564 if(sta) { 566 565 FitsOpenFile::printerror(sta); … … 597 596 //cout<<"DBG-FitsRead: row1="<<row1<<" row2="<<row2<<" nrow="<<nrow 598 597 // <<" LineDeb,Fin="<<LineDeb<<","<<LineFin<<endl; 599 fits_read_col( FitsPtr,TDOUBLE,ColNum+1,row1,1,nrow,NULL,Buffer,NULL,&sta);598 fits_read_col(GetFitsPtr(),TDOUBLE,ColNum+1,row1,1,nrow,NULL,Buffer,NULL,&sta); 600 599 if(sta) { 601 600 FitsOpenFile::printerror(sta); … … 655 654 //for(long i=n1;i<=n2;i++) data(i-n1) = Read(i); 656 655 int sta=0; 657 fits_read_col( FitsPtr,TDOUBLE,ColNum+1,n1+1,1,nread,NULL,data.Data(),NULL,&sta);656 fits_read_col(GetFitsPtr(),TDOUBLE,ColNum+1,n1+1,1,nread,NULL,data.Data(),NULL,&sta); 658 657 if(sta) { 659 658 FitsOpenFile::printerror(sta); … … 679 678 //for(long i=n1;i<=n2;i++) data(i-n1) = Read(i); 680 679 int sta=0; 681 fits_read_col( FitsPtr,TFLOAT,ColNum+1,n1+1,1,nread,NULL,data.Data(),NULL,&sta);680 fits_read_col(GetFitsPtr(),TFLOAT,ColNum+1,n1+1,1,nread,NULL,data.Data(),NULL,&sta); 682 681 if(sta) { 683 682 FitsOpenFile::printerror(sta); … … 702 701 703 702 int sta=0; 704 fits_read_col( FitsPtr,TUSHORT,ColNum+1,n1+1,1,nread,NULL,data.Data(),NULL,&sta);703 fits_read_col(GetFitsPtr(),TUSHORT,ColNum+1,n1+1,1,nread,NULL,data.Data(),NULL,&sta); 705 704 if(sta) { 706 705 FitsOpenFile::printerror(sta); … … 727 726 int sta=0; 728 727 int T = (sizeof(long)==4) ? TLONG: TINT; 729 fits_read_col( FitsPtr,T,ColNum+1,n1+1,1,nread,NULL,data.Data(),NULL,&sta);728 fits_read_col(GetFitsPtr(),T,ColNum+1,n1+1,1,nread,NULL,data.Data(),NULL,&sta); 730 729 if(sta) { 731 730 FitsOpenFile::printerror(sta); … … 751 750 752 751 int sta=0; 753 fits_read_col( FitsPtr,TLONGLONG,ColNum+1,n1+1,1,nread,NULL,data.Data(),NULL,&sta);752 fits_read_col(GetFitsPtr(),TLONGLONG,ColNum+1,n1+1,1,nread,NULL,data.Data(),NULL,&sta); 754 753 if(sta) { 755 754 FitsOpenFile::printerror(sta); … … 984 983 Naxis[0] = Naxis[1] = 0; 985 984 SetNulVal(); SetDebug(0); 986 FitsOF = NULL; FitsPtr = NULL;985 FitsOF = NULL; 987 986 } 988 987 … … 993 992 Naxis[0] = Naxis[1] = 0; 994 993 SetNulVal(); SetDebug(lp); 995 FitsOF = NULL; FitsPtr = NULL;994 FitsOF = NULL; 996 995 997 996 // Caracteristiques du FitsOpenFile … … 1000 999 throw NullPtrError("FitsImg2DRd::Init: FitsOpenFile pointer is NULL\n"); 1001 1000 1002 FitsPtr = FitsOF->GetFitsPtr(); 1003 if(FitsPtr==NULL) 1001 if(GetFitsPtr()==NULL) 1004 1002 throw NullPtrError("FitsImg2DRd::Init: FitsPtr pointer is NULL\n"); 1005 1003 … … 1015 1013 int rc = FitsOF->MoveToHDU(ihdu); 1016 1014 if(rc!=ihdu) 1017 throw RangeCheckError("Fits ABTColRd::Init: Error moving to requested HDU\n");1015 throw RangeCheckError("FitsImg2DRd::Init: Error moving to requested HDU\n"); 1018 1016 } 1019 1017 } else { // Fits file has already been positionned 1020 1018 if(ihdu>0 && ihdu!=HDU()) 1021 throw RangeCheckError("Fits ABTColRd::Init: file already posit. at another HDU\n");1019 throw RangeCheckError("FitsImg2DRd::Init: file already posit. at another HDU\n"); 1022 1020 } 1023 1021 … … 1029 1027 // Get NAXIS 1 et 2 1030 1028 int nfound=0; 1031 if(fits_read_keys_lng( FitsPtr,"NAXIS",1,2,Naxis,&nfound,&sta)) {1029 if(fits_read_keys_lng(GetFitsPtr(),"NAXIS",1,2,Naxis,&nfound,&sta)) { 1032 1030 FitsOpenFile::printerror(sta); 1033 1031 throw RangeCheckError("FitsImg2DRd::Init: Error reading NAXIS cards\n"); … … 1056 1054 double FitsImg2DRd::ReadKey(char *keyname) 1057 1055 { 1058 return FitsOpenFile::ReadKey( FitsPtr,keyname);1056 return FitsOpenFile::ReadKey(GetFitsPtr(),keyname); 1059 1057 } 1060 1058 … … 1066 1064 long FitsImg2DRd::ReadKeyL(char *keyname) 1067 1065 { 1068 return FitsOpenFile::ReadKeyL( FitsPtr,keyname);1066 return FitsOpenFile::ReadKeyL(GetFitsPtr(),keyname); 1069 1067 } 1070 1068 … … 1076 1074 string FitsImg2DRd::ReadKeyS(char *keyname) 1077 1075 { 1078 return FitsOpenFile::ReadKeyS( FitsPtr,keyname);1076 return FitsOpenFile::ReadKeyS(GetFitsPtr(),keyname); 1079 1077 } 1080 1078 … … 1090 1088 \warning TMatrix data(Naxis2,Naxis1) 1091 1089 */ 1092 longFitsImg2DRd::Read(TMatrix<uint_2>& data)1090 size_t FitsImg2DRd::Read(TMatrix<uint_2>& data) 1093 1091 { 1094 1092 int sta=0; … … 1098 1096 for(int j=0;j<Naxis[1];j++) { 1099 1097 long deb = j*Naxis[0]+1, nel = Naxis[0]; 1100 fits_read_img( FitsPtr,TUSHORT,deb,nel,&NulVal,arr,NULL,&sta);1098 fits_read_img(GetFitsPtr(),TUSHORT,deb,nel,&NulVal,arr,NULL,&sta); 1101 1099 if(sta) { 1102 1100 FitsOpenFile::printerror(sta); delete [] arr; … … 1112 1110 1113 1111 /*! Read image into a TMatrix<int_4> */ 1114 longFitsImg2DRd::Read(TMatrix<int_4>& data)1112 size_t FitsImg2DRd::Read(TMatrix<int_4>& data) 1115 1113 { 1116 1114 int sta=0; … … 1121 1119 for(int j=0;j<Naxis[1];j++) { 1122 1120 long deb = j*Naxis[0]+1, nel = Naxis[0]; 1123 fits_read_img( FitsPtr,T,deb,nel,&NulVal,arr,NULL,&sta);1121 fits_read_img(GetFitsPtr(),T,deb,nel,&NulVal,arr,NULL,&sta); 1124 1122 if(sta) { 1125 1123 FitsOpenFile::printerror(sta); delete [] arr; … … 1135 1133 1136 1134 /*! Read image into a TMatrix<int_8> */ 1137 longFitsImg2DRd::Read(TMatrix<int_8>& data)1135 size_t FitsImg2DRd::Read(TMatrix<int_8>& data) 1138 1136 { 1139 1137 int sta=0; … … 1143 1141 for(int j=0;j<Naxis[1];j++) { 1144 1142 long deb = j*Naxis[0]+1, nel = Naxis[0]; 1145 fits_read_img( FitsPtr,TLONGLONG,deb,nel,&NulVal,arr,NULL,&sta);1143 fits_read_img(GetFitsPtr(),TLONGLONG,deb,nel,&NulVal,arr,NULL,&sta); 1146 1144 if(sta) { 1147 1145 FitsOpenFile::printerror(sta); delete [] arr; … … 1157 1155 1158 1156 /*! Read image into a TMatrix<float> */ 1159 longFitsImg2DRd::Read(TMatrix<float>& data)1157 size_t FitsImg2DRd::Read(TMatrix<float>& data) 1160 1158 { 1161 1159 int sta=0; … … 1165 1163 for(int j=0;j<Naxis[1];j++) { 1166 1164 long deb = j*Naxis[0]+1, nel = Naxis[0]; 1167 fits_read_img( FitsPtr,TFLOAT,deb,nel,&NulVal,arr,NULL,&sta);1165 fits_read_img(GetFitsPtr(),TFLOAT,deb,nel,&NulVal,arr,NULL,&sta); 1168 1166 if(sta) { 1169 1167 FitsOpenFile::printerror(sta); delete [] arr; … … 1179 1177 1180 1178 /*! Read image into a TMatrix<double> */ 1181 longFitsImg2DRd::Read(TMatrix<double>& data)1179 size_t FitsImg2DRd::Read(TMatrix<double>& data) 1182 1180 { 1183 1181 int sta=0; … … 1187 1185 for(int j=0;j<Naxis[1];j++) { 1188 1186 long deb = j*Naxis[0]+1, nel = Naxis[0]; 1189 fits_read_img( FitsPtr,TDOUBLE,deb,nel,&NulVal,arr,NULL,&sta);1187 fits_read_img(GetFitsPtr(),TDOUBLE,deb,nel,&NulVal,arr,NULL,&sta); 1190 1188 if(sta) { 1191 1189 FitsOpenFile::printerror(sta); delete [] arr; … … 1257 1255 if(FitsOF!=NULL) delete FitsOF; 1258 1256 } 1257 1258 1259 1260 /////////////////////////////////////////////////////////////////// 1261 /////////////////////////////////////////////////////////////////// 1262 /////////////////////////////////////////////////////////////////// 1263 /////////////////////////////////////////////////////////////////// 1264 1265 //! Class for reading a 3D image from a FITS file 1266 1267 /*! 1268 \class SOPHYA::FitsImg3DRd 1269 \ingroup FitsIOServer 1270 Class for reading a 3D image from a FITS file 1271 */ 1272 1273 ////////////////////////////////////////////////////////////// 1274 /*! 1275 Constructor. 1276 \param fof : Pointer to the Class for opening the FITS file 1277 \param ihdu : number of the HDU where the 3D image is. 1278 \param lp : debug level 1279 \verbatim 1280 - if ihdu<=0 first IMAGE hdu is taken 1281 - if ihdu>nhdu ihdu is set to nhdu 1282 \endverbatim 1283 \warning ihdu = [1,nhdu] 1284 */ 1285 FitsImg3DRd::FitsImg3DRd(FitsOpenFile* fof,int ihdu,int lp) 1286 { 1287 Init(fof,ihdu,lp); 1288 } 1289 1290 /*! Constructor by copy */ 1291 FitsImg3DRd::FitsImg3DRd(FitsImg3DRd& fbt) 1292 { 1293 Init(fbt.GetFitsOpenFile(),fbt.HDU(),fbt.DbgLevel); 1294 } 1295 1296 /*! Constructor by default */ 1297 FitsImg3DRd::FitsImg3DRd() 1298 { 1299 Naxis[0] = Naxis[1] = Naxis[2] = 0; 1300 SetNulVal(); SetDebug(0); 1301 FitsOF = NULL; 1302 } 1303 1304 /*! Init routine called by the constructor */ 1305 void FitsImg3DRd::Init(FitsOpenFile* fof,int ihdu,int lp) 1306 { 1307 // Initialisation des Parametres Generaux 1308 Naxis[0] = Naxis[1] = Naxis[2] = 0; 1309 SetNulVal(); SetDebug(lp); 1310 FitsOF = NULL; 1311 1312 // Caracteristiques du FitsOpenFile 1313 FitsOF = fof; 1314 if(FitsOF==NULL) 1315 throw NullPtrError("FitsImg3DRd::Init: FitsOpenFile pointer is NULL\n"); 1316 1317 if(GetFitsPtr()==NULL) 1318 throw NullPtrError("FitsImg3DRd::Init: FitsPtr pointer is NULL\n"); 1319 1320 int sta = 0; 1321 if(ihdu<0) ihdu=0; if(ihdu>NHDU()) ihdu=NHDU(); 1322 1323 // Get HDU 3D image 1324 // ATTENTION: ... cf blabla equivalent dans FitsABTColRd::Init() 1325 if(FitsOF->GetPosStatus()==false) { 1326 if(ihdu==0) { // find the first IMAGE_HDU 1327 FitsOF->MoveToFirst(IMAGE_HDU); 1328 } else { 1329 int rc = FitsOF->MoveToHDU(ihdu); 1330 if(rc!=ihdu) 1331 throw RangeCheckError("FitsImg3DRd::Init: Error moving to requested HDU\n"); 1332 } 1333 } else { // Fits file has already been positionned 1334 if(ihdu>0 && ihdu!=HDU()) 1335 throw RangeCheckError("FitsImg3DRd::Init: file already posit. at another HDU\n"); 1336 } 1337 1338 // Check HDUType and set position status to TRUE 1339 if(HDUType()!=IMAGE_HDU) 1340 throw TypeMismatchExc("FitsImg3DRd::Init: HDU not IMAGE_HDU\n"); 1341 FitsOF->SetPosStatus(true); 1342 1343 // Get NAXIS 1, 2 et 3 1344 int nfound=0; 1345 if(fits_read_keys_lng(GetFitsPtr(),"NAXIS",1,3,Naxis,&nfound,&sta)) { 1346 FitsOpenFile::printerror(sta); 1347 throw RangeCheckError("FitsImg3DRd::Init: Error reading NAXIS cards\n"); 1348 } 1349 if(DbgLevel>1) 1350 cout<<"...Init(hdu="<<HDU()<<") NAXIS1="<<Naxis[0]<<" NAXIS2=" 1351 <<Naxis[1]<<" NAXIS3="<<Naxis[2]<<" (nfound="<<nfound<<")"<<endl; 1352 if(nfound!=3 || Naxis[0]<=0 || Naxis[1]<=0 || Naxis[2]<=0) 1353 throw NotAvailableOperation("FitsImg3DRd::Init: bad Naxis[0-2] value\n"); 1354 1355 } 1356 1357 /*! Destructor. */ 1358 FitsImg3DRd::~FitsImg3DRd() 1359 { 1360 //--- Surtout on ne "fits_close_file" pas le fichier FITS !!! 1361 Naxis[0] = Naxis[1] = Naxis[2] = 0; 1362 } 1363 1364 ////////////////////////////////////////////////////////////// 1365 /*! 1366 Read a fitsheader key into double 1367 \param keyname : name of the key 1368 \return value into double 1369 */ 1370 double FitsImg3DRd::ReadKey(char *keyname) 1371 { 1372 return FitsOpenFile::ReadKey(GetFitsPtr(),keyname); 1373 } 1374 1375 /*! 1376 Read a fitsheader key into long 1377 \param keyname : name of the key 1378 \return value into long 1379 */ 1380 long FitsImg3DRd::ReadKeyL(char *keyname) 1381 { 1382 return FitsOpenFile::ReadKeyL(GetFitsPtr(),keyname); 1383 } 1384 1385 /*! 1386 Read a fitsheader key into string 1387 \param keyname : name of the key 1388 \return value into string 1389 */ 1390 string FitsImg3DRd::ReadKeyS(char *keyname) 1391 { 1392 return FitsOpenFile::ReadKeyS(GetFitsPtr(),keyname); 1393 } 1394 1395 ////////////////////////////////////////////////////////////// 1396 /* REMARQUE: 1397 * Dans TArray A(naxis1,naxis2,naxis3); 1398 * A(i,j,k) -> i varie le plus vite et k le moins vite 1399 */ 1400 /*! 1401 Read 3D image into a TArray<uint_2> 1402 */ 1403 size_t FitsImg3DRd::Read(TArray<uint_2>& data) 1404 { 1405 int sta=0; 1406 uint_2* arr = new uint_2[Naxis[0]]; 1407 sa_size_t ndim[3] = {Naxis[0],Naxis[1],Naxis[2]}; data.ReSize(3,ndim); 1408 1409 for(int k=0;k<Naxis[2];k++) for(int j=0;j<Naxis[1];j++) { 1410 long deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; 1411 fits_read_img(GetFitsPtr(),TUSHORT,deb,nel,&NulVal,arr,NULL,&sta); 1412 if(sta) { 1413 FitsOpenFile::printerror(sta); delete [] arr; 1414 throw 1415 NotAvailableOperation("FitsImg3DRd::Read(TArray<uint_2>): Error Reading Fits file\n"); 1416 } 1417 for(int i=0;i<Naxis[0];i++) data(i,j,k) = arr[i]; 1418 } 1419 1420 delete [] arr; 1421 return Naxis[0]*Naxis[1]*Naxis[2]; 1422 } 1423 1424 /*! Read 3D image into a TArray<int_4> */ 1425 size_t FitsImg3DRd::Read(TArray<int_4>& data) 1426 { 1427 int sta=0; 1428 int_4* arr = new int_4[Naxis[0]]; 1429 sa_size_t ndim[3] = {Naxis[0],Naxis[1],Naxis[2]}; data.ReSize(3,ndim); 1430 int T = (sizeof(long)==4) ? TLONG: TINT; 1431 1432 for(int k=0;k<Naxis[2];k++) for(int j=0;j<Naxis[1];j++) { 1433 long deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; 1434 fits_read_img(GetFitsPtr(),T,deb,nel,&NulVal,arr,NULL,&sta); 1435 if(sta) { 1436 FitsOpenFile::printerror(sta); delete [] arr; 1437 throw 1438 NotAvailableOperation("FitsImg3DRd::Read(TArray<int_4>): Error Reading Fits file\n"); 1439 } 1440 for(int i=0;i<Naxis[0];i++) data(i,j,k) = arr[i]; 1441 } 1442 1443 delete [] arr; 1444 return Naxis[0]*Naxis[1]*Naxis[2]; 1445 } 1446 1447 /*! Read 3D image into a TArray<int_8> */ 1448 size_t FitsImg3DRd::Read(TArray<int_8>& data) 1449 { 1450 int sta=0; 1451 int_8* arr = new int_8[Naxis[0]]; 1452 sa_size_t ndim[3] = {Naxis[0],Naxis[1],Naxis[2]}; data.ReSize(3,ndim); 1453 1454 for(int k=0;k<Naxis[2];k++) for(int j=0;j<Naxis[1];j++) { 1455 long deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; 1456 fits_read_img(GetFitsPtr(),TLONGLONG,deb,nel,&NulVal,arr,NULL,&sta); 1457 if(sta) { 1458 FitsOpenFile::printerror(sta); delete [] arr; 1459 throw 1460 NotAvailableOperation("FitsImg3DRd::Read(TArray<int_8>): Error Reading Fits file\n"); 1461 } 1462 for(int i=0;i<Naxis[0];i++) data(i,j,k) = arr[i]; 1463 } 1464 1465 delete [] arr; 1466 return Naxis[0]*Naxis[1]*Naxis[2]; 1467 } 1468 1469 /*! Read 3D image into a TArray<float> */ 1470 size_t FitsImg3DRd::Read(TArray<float>& data) 1471 { 1472 int sta=0; 1473 float* arr = new float[Naxis[0]]; 1474 sa_size_t ndim[3] = {Naxis[0],Naxis[1],Naxis[2]}; data.ReSize(3,ndim); 1475 1476 for(int k=0;k<Naxis[2];k++) for(int j=0;j<Naxis[1];j++) { 1477 long deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; 1478 fits_read_img(GetFitsPtr(),TFLOAT,deb,nel,&NulVal,arr,NULL,&sta); 1479 if(sta) { 1480 FitsOpenFile::printerror(sta); delete [] arr; 1481 throw 1482 NotAvailableOperation("FitsImg3DRd::Read(TArray<float>): Error Reading Fits file\n"); 1483 } 1484 for(int i=0;i<Naxis[0];i++) data(i,j,k) = arr[i]; 1485 } 1486 1487 delete [] arr; 1488 return Naxis[0]*Naxis[1]*Naxis[2]; 1489 } 1490 1491 /*! Read 3D image into a TArray<double> */ 1492 size_t FitsImg3DRd::Read(TArray<double>& data) 1493 { 1494 int sta=0; 1495 double* arr = new double[Naxis[0]]; 1496 sa_size_t ndim[3] = {Naxis[0],Naxis[1],Naxis[2]}; data.ReSize(3,ndim); 1497 1498 for(int k=0;k<Naxis[2];k++) for(int j=0;j<Naxis[1];j++) { 1499 long deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; 1500 fits_read_img(GetFitsPtr(),TDOUBLE,deb,nel,&NulVal,arr,NULL,&sta); 1501 if(sta) { 1502 FitsOpenFile::printerror(sta); delete [] arr; 1503 throw 1504 NotAvailableOperation("FitsImg3DRd::Read(TArray<double>): Error Reading Fits file\n"); 1505 } 1506 for(int i=0;i<Naxis[0];i++) data(i,j,k) = arr[i]; 1507 } 1508 1509 delete [] arr; 1510 return Naxis[0]*Naxis[1]*Naxis[2]; 1511 } 1512 1513 /////////////////////////////////////////////////////////////////// 1514 /////////////////////////////////////////////////////////////////// 1515 /////////////////////////////////////////////////////////////////// 1516 /////////////////////////////////////////////////////////////////// 1517 1518 //! Class for reading a 3D image from a FITS file 1519 1520 /*! 1521 \class SOPHYA::FitsImg3DRead 1522 \ingroup FitsIOServer 1523 Class for reading a 3D image from a FITS file 1524 */ 1525 1526 ////////////////////////////////////////////////////////////// 1527 /*! 1528 Constructor. 1529 \param fname : name of the FITS file 1530 \param ihdu : number of the HDU where the 3D image is. 1531 \param lp : debug level 1532 \verbatim 1533 - if ihdu<=0 first IMAGE hdu is taken 1534 - if ihdu>nhdu ihdu is set to nhdu 1535 \endverbatim 1536 \warning ihdu = [1,nhdu] 1537 */ 1538 FitsImg3DRead::FitsImg3DRead(string fname,int ihdu,int lp) 1539 : FitsImg3DRd(new FitsOpenFile(fname),ihdu,lp) 1540 { 1541 } 1542 1543 /*! Constructor. see below */ 1544 FitsImg3DRead::FitsImg3DRead(const char * cfname,int ihdu,int lp) 1545 : FitsImg3DRd(new FitsOpenFile(cfname),ihdu,lp) 1546 { 1547 } 1548 1549 /*! Constructor by default */ 1550 FitsImg3DRead::FitsImg3DRead() 1551 : FitsImg3DRd() 1552 { 1553 } 1554 1555 /*! Constructor by copy */ 1556 FitsImg3DRead::FitsImg3DRead(FitsImg3DRead& fimg) 1557 { 1558 // --- ATTENTION --- 1559 // FitsImg3DRead ferme le fichier FITS: il faut dupliquer le FitsOpenFile 1560 FitsOpenFile* fof = new FitsOpenFile(*fimg.GetFitsOpenFile()); 1561 Init(fof,fimg.HDU(),fimg.DbgLevel); 1562 } 1563 1564 /*! Destructor. */ 1565 FitsImg3DRead::~FitsImg3DRead() 1566 { 1567 // On detruit le FitsOpenFile, cad qu'on ferme (fits_file_close) le fichier FITS 1568 if(FitsOF!=NULL) delete FitsOF; 1569 }
Note:
See TracChangeset
for help on using the changeset viewer.