@@ -85,6 +85,7 @@ several methods to manage them.
85
85
#include " fitsio.h"
86
86
#include < stdlib.h>
87
87
88
+
88
89
ClassImp (TFITSHDU);
89
90
90
91
// //////////////////////////////////////////////////////////////////////////////
@@ -380,6 +381,7 @@ Bool_t TFITSHDU::LoadHDU(TString& filepath_filter)
380
381
381
382
for (colnum = 0 , cellindex = 0 ; colnum < fNColumns ; colnum++) {
382
383
fits_get_coltype (fp, colnum+1 , &typecode, &repeat, &width, &status);
384
+
383
385
if (status) goto ERR;
384
386
385
387
if ((typecode == TDOUBLE) || (typecode == TSHORT) || (typecode == TLONG)
@@ -441,60 +443,89 @@ Bool_t TFITSHDU::LoadHDU(TString& filepath_filter)
441
443
442
444
fColumnsInfo [colnum].fDim = (Int_t) repeat;
443
445
444
- double *array;
446
+ double *array = 0 ;
447
+ char *arrayl = 0 ;
445
448
446
449
if (repeat > 0 ) {
447
- array = new double [table_rows * repeat]; // Hope you got a big machine! Ask China otherwise :-)
448
- fits_read_col (fp, TDOUBLE, colnum+1 , 1 , 1 , table_rows * repeat, &nulval, array, &anynul, &status);
449
450
450
- if (status) {
451
- delete [] array;
452
- goto ERR;
451
+ if (typecode == TLOGICAL) {
452
+ arrayl = new char [table_rows * repeat];
453
+ fits_read_col (fp, TLOGICAL, colnum + 1 , 1 , 1 , table_rows * repeat, &nulval, arrayl, &anynul,
454
+ &status);
455
+ if (status) {
456
+ delete[] arrayl;
457
+ goto ERR;
458
+ }
459
+ } else {
460
+ array = new double [table_rows * repeat]; // Hope you got a big machine! Ask China otherwise :-)
461
+ fits_read_col (fp, TDOUBLE, colnum + 1 , 1 , 1 , table_rows * repeat, &nulval, array, &anynul,
462
+ &status);
463
+ if (status) {
464
+ delete[] array;
465
+ goto ERR;
466
+ }
453
467
}
468
+
454
469
} else {
455
- // No elements: set dummy
456
- array = new double [table_rows];
470
+ // No elements: set dummy
471
+ array = new double [table_rows];
457
472
for (long row = 0 ; row < table_rows; row++) {
458
473
array[row] = 0.0 ;
459
474
}
460
475
}
461
476
462
- // Save values
477
+ // Save values
463
478
if (repeat == 1 ) {
464
- // Scalar
465
- for (long row = 0 ; row < table_rows; row++) {
466
- fCells [cellindex++].fRealNumber = array[row];
479
+ // Scalar
480
+ if (typecode == TLOGICAL) {
481
+ for (long row = 0 ; row < table_rows; row++) {
482
+ int temp = (signed char )arrayl[row];
483
+ fCells [cellindex++].fRealNumber = (double )temp;
484
+ }
485
+ delete[] arrayl;
486
+ } else {
487
+ for (long row = 0 ; row < table_rows; row++) {
488
+ fCells [cellindex++].fRealNumber = array[row];
489
+ }
490
+ delete[] array;
467
491
}
468
492
} else if (repeat > 1 ) {
469
- // Vector
470
- for (long row = 0 ; row < table_rows; row++) {
471
- double *vec = new double [repeat];
472
- long offset = row * repeat;
473
- for (long component = 0 ; component < repeat; component++) {
474
- vec[component] = array[offset++];
493
+ // Vector
494
+ if (typecode == TLOGICAL) {
495
+ for (long row = 0 ; row < table_rows; row++) {
496
+ double *vec = new double [repeat];
497
+ long offset = row * repeat;
498
+ for (long component = 0 ; component < repeat; component++) {
499
+ int temp = (signed char )arrayl[offset++];
500
+ vec[component] = (double )temp;
501
+ }
502
+ fCells [cellindex++].fRealVector = vec;
503
+ }
504
+ delete[] arrayl;
505
+ } else {
506
+ for (long row = 0 ; row < table_rows; row++) {
507
+ double *vec = new double [repeat];
508
+ long offset = row * repeat;
509
+ for (long component = 0 ; component < repeat; component++) {
510
+ vec[component] = array[offset++];
511
+ }
512
+ fCells [cellindex++].fRealVector = vec;
475
513
}
476
- fCells [cellindex++]. fRealVector = vec ;
514
+ delete[] array ;
477
515
}
478
516
}
479
-
480
- delete [] array;
481
-
482
517
}
483
-
484
518
} else {
485
519
Warning (" LoadHDU" , " error opening FITS file. Column type %d is currently not supported" , typecode);
486
520
}
487
521
}
488
522
489
-
490
-
491
523
if (hdutype == ASCII_TBL) {
492
- // ASCII table
524
+ // ASCII table
493
525
494
526
} else {
495
- // Binary table
527
+ // Binary table
496
528
}
497
-
498
529
}
499
530
500
531
// Close file
@@ -1058,13 +1089,16 @@ TVectorD* TFITSHDU::GetArrayRow(UInt_t row)
1058
1089
}
1059
1090
1060
1091
offset = W * row;
1061
- TVectorD *vec = new TVectorD (W);
1062
- double *v = vec->GetMatrixArray ();
1092
+ double *v = new double [W];
1063
1093
1064
1094
for (i = 0 ; i < W; i++) {
1065
1095
v[i] = fPixels ->GetAt (offset+i);
1066
1096
}
1067
1097
1098
+ TVectorD *vec = new TVectorD (W, v);
1099
+
1100
+ delete [] v;
1101
+
1068
1102
return vec;
1069
1103
}
1070
1104
@@ -1094,13 +1128,15 @@ TVectorD* TFITSHDU::GetArrayColumn(UInt_t col)
1094
1128
return 0 ;
1095
1129
}
1096
1130
1097
- TVectorD *vec = new TVectorD (H);
1098
- double *v = vec->GetMatrixArray ();
1131
+ double *v = new double [H];
1099
1132
1100
1133
for (i = 0 ; i < H; i++) {
1101
1134
v[i] = fPixels ->GetAt (W*i+col);
1102
1135
}
1103
1136
1137
+ TVectorD *vec = new TVectorD (H, v);
1138
+
1139
+ delete [] v;
1104
1140
1105
1141
return vec;
1106
1142
}
@@ -1208,13 +1244,15 @@ TVectorD* TFITSHDU::GetTabRealVectorColumn(Int_t colnum)
1208
1244
1209
1245
Int_t offset = colnum * fNRows ;
1210
1246
1211
- TVectorD *res = new TVectorD (fNRows );
1212
- Double_t *arr = res->GetMatrixArray ();
1247
+ Double_t *arr = new Double_t[fNRows ];
1213
1248
1214
1249
for (Int_t row = 0 ; row < fNRows ; row++) {
1215
1250
arr[row] = fCells [offset + row].fRealNumber ;
1216
1251
}
1217
1252
1253
+ TVectorD *res = new TVectorD ();
1254
+ res->Use (fNRows , arr);
1255
+
1218
1256
return res;
1219
1257
}
1220
1258
@@ -1245,13 +1283,15 @@ TVectorD* TFITSHDU::GetTabRealVectorColumn(const char *colname)
1245
1283
1246
1284
Int_t offset = colnum * fNRows ;
1247
1285
1248
- TVectorD *res = new TVectorD (fNRows );
1249
- Double_t *arr = res->GetMatrixArray ();
1286
+ Double_t *arr = new Double_t[fNRows ];
1250
1287
1251
1288
for (Int_t row = 0 ; row < fNRows ; row++) {
1252
1289
arr[row] = fCells [offset + row].fRealNumber ;
1253
1290
}
1254
1291
1292
+ TVectorD *res = new TVectorD ();
1293
+ res->Use (fNRows , arr);
1294
+
1255
1295
return res;
1256
1296
}
1257
1297
0 commit comments