Changeset 5057 for trunk/psLib/src/fits/psFits.c
- Timestamp:
- Sep 15, 2005, 11:22:22 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/fits/psFits.c (modified) (54 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fits/psFits.c
r4898 r5057 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.4 3$ $Name: not supported by cvs2svn $10 * @date $Date: 2005-0 8-30 01:14:13$9 * @version $Revision: 1.44 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-09-15 21:22:21 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 186 186 int status = 0; 187 187 188 fits_get_hdrspace(fits-> p_fd, &keysexist, &morekeys, &status);188 fits_get_hdrspace(fits->fd, &keysexist, &morekeys, &status); 189 189 190 190 // if no keys exist and not primary HDU, this really is an empty HDU … … 202 202 203 203 if (fits != NULL) { 204 (void)fits_close_file(fits-> p_fd, &status);204 (void)fits_close_file(fits->fd, &status); 205 205 psFree(fits->filename); 206 206 } … … 247 247 psFits* fits = psAlloc(sizeof(psFits)); 248 248 fits->filename = psAlloc(strlen(name)+1); 249 fits-> p_fd = fptr;249 fits->fd = fptr; 250 250 strcpy((char*)fits->filename,name); 251 251 psMemSetDeallocator(fits,(psFreeFunc)fitsFree); … … 279 279 280 280 281 if (fits_movnam_hdu(fits-> p_fd, ANY_HDU, (char*)extname, 0, &status) != 0) {281 if (fits_movnam_hdu(fits->fd, ANY_HDU, (char*)extname, 0, &status) != 0) { 282 282 char fitsErr[MAX_STRING_LENGTH]; 283 283 fits_get_errstatus(status, fitsErr); … … 305 305 306 306 if (relative) { 307 fits_movrel_hdu(fits-> p_fd, extnum, &hdutype, &status);307 fits_movrel_hdu(fits->fd, extnum, &hdutype, &status); 308 308 if (status != 0) { 309 309 char fitsErr[MAX_STRING_LENGTH]; … … 315 315 } 316 316 } else { 317 fits_movabs_hdu(fits-> p_fd, extnum+1, &hdutype, &status);317 fits_movabs_hdu(fits->fd, extnum+1, &hdutype, &status); 318 318 if (status != 0) { 319 319 char fitsErr[MAX_STRING_LENGTH]; … … 340 340 341 341 342 return fits_get_hdu_num(fits-> p_fd,&hdunum) - 1;342 return fits_get_hdu_num(fits->fd,&hdunum) - 1; 343 343 } 344 344 … … 354 354 char name[MAX_STRING_LENGTH]; 355 355 356 if (fits_read_key_str(fits-> p_fd, "EXTNAME", name, NULL, &status) != 0) {356 if (fits_read_key_str(fits->fd, "EXTNAME", name, NULL, &status) != 0) { 357 357 status = 0; 358 if (fits_read_key_str(fits-> p_fd, "HDUNAME", name, NULL, &status) != 0) {358 if (fits_read_key_str(fits->fd, "HDUNAME", name, NULL, &status) != 0) { 359 359 int num = psFitsGetExtNum(fits); 360 360 snprintf(name, MAX_STRING_LENGTH, "EXT-%3d",num); … … 380 380 int status = 0; 381 381 382 if (fits_update_key_str(fits-> p_fd, "EXTNAME", (char*)name, NULL, &status) != 0) {382 if (fits_update_key_str(fits->fd, "EXTNAME", (char*)name, NULL, &status) != 0) { 383 383 char fitsErr[MAX_STRING_LENGTH]; 384 384 (void)fits_get_errstatus(status, fitsErr); … … 403 403 int status = 0; 404 404 405 if (fits_get_num_hdus(fits-> p_fd, &num, &status) != 0) {405 if (fits_get_num_hdus(fits->fd, &num, &status) != 0) { 406 406 char fitsErr[MAX_STRING_LENGTH]; 407 407 fits_get_errstatus(status, fitsErr); … … 426 426 int hdutype = PS_FITS_TYPE_NONE; 427 427 428 if (fits_get_hdu_type(fits-> p_fd, &hdutype, &status) != 0) {428 if (fits_get_hdu_type(fits->fd, &hdutype, &status) != 0) { 429 429 char fitsErr[MAX_STRING_LENGTH]; 430 430 fits_get_errstatus(status, fitsErr); … … 466 466 int keyNum = 0; 467 467 int status = 0; 468 fits_get_hdrpos(fits-> p_fd, &numKeys, &keyNum, &status);468 fits_get_hdrpos(fits->fd, &numKeys, &keyNum, &status); 469 469 470 470 // Get each key name. Keywords start at one. … … 478 478 for (int i = 1; i <= numKeys; i++) { 479 479 480 fits_read_keyn(fits-> p_fd, i, keyName, keyValue, keyComment, &status);480 fits_read_keyn(fits->fd, i, keyName, keyValue, keyComment, &status); 481 481 482 482 stdKey = false; … … 657 657 // check to see if we even are positioned on an image HDU 658 658 int hdutype; 659 if ( fits_get_hdu_type(fits-> p_fd,&hdutype, &status) != 0) {659 if ( fits_get_hdu_type(fits->fd,&hdutype, &status) != 0) { 660 660 char fitsErr[MAX_STRING_LENGTH]; 661 661 (void)fits_get_errstatus(status, fitsErr); … … 672 672 673 673 /* Get the data type 'bitPix' from the FITS image */ 674 if (fits_get_img_equivtype(fits-> p_fd, &bitPix, &status) != 0) {674 if (fits_get_img_equivtype(fits->fd, &bitPix, &status) != 0) { 675 675 fits_get_errstatus(status, fitsErr); 676 676 psError(PS_ERR_IO, true, … … 682 682 683 683 /* Get the dimensions 'nAxis' from the FITS image */ 684 if (fits_get_img_dim(fits-> p_fd, &nAxis, &status) != 0) {684 if (fits_get_img_dim(fits->fd, &nAxis, &status) != 0) { 685 685 (void)fits_get_errstatus(status, fitsErr); 686 686 psError(PS_ERR_IO, true, … … 701 701 702 702 /* Get the Image size from the FITS file */ 703 if (fits_get_img_size(fits-> p_fd, nAxis, nAxes, &status) != 0) {703 if (fits_get_img_size(fits->fd, nAxis, nAxes, &status) != 0) { 704 704 (void)fits_get_errstatus(status, fitsErr); 705 705 psError(PS_ERR_IO, true, … … 787 787 788 788 // n.b., this assumes contiguous image buffer 789 if (fits_read_subset(fits-> p_fd, fitsDatatype, firstPixel, lastPixel, increment,789 if (fits_read_subset(fits->fd, fitsDatatype, firstPixel, lastPixel, increment, 790 790 NULL, output->data.V[0], &anynull, &status) != 0) { 791 791 psFree(output); … … 842 842 } 843 843 844 fits_create_img(fits-> p_fd, bitPix, naxis, naxes, &status);844 fits_create_img(fits->fd, bitPix, naxis, naxes, &status); 845 845 846 846 if (bZero != 0) { // set the bscale/bzero 847 fits_write_key_dbl(fits-> p_fd, "BZERO", bZero, 12, "Pixel Value Offset", &status);848 fits_write_key_dbl(fits-> p_fd, "BSCALE", 1.0, 12, "Pixel Value Scale", &status);849 fits_set_bscale(fits-> p_fd, 1.0, bZero, &status);847 fits_write_key_dbl(fits->fd, "BZERO", bZero, 12, "Pixel Value Offset", &status); 848 fits_write_key_dbl(fits->fd, "BSCALE", 1.0, 12, "Pixel Value Scale", &status); 849 fits_set_bscale(fits->fd, 1.0, bZero, &status); 850 850 } 851 851 … … 856 856 857 857 if (input->parent == NULL) { // if no parent, assume that the image data is contiguous 858 fits_write_img(fits-> p_fd,858 fits_write_img(fits->fd, 859 859 dataType, // datatype 860 860 1, // writing to the first z-plane … … 865 865 int firstPixel = 1; 866 866 for (int row = 0; row < numRows; row++) { 867 fits_write_img(fits-> p_fd,867 fits_write_img(fits->fd, 868 868 dataType, // datatype 869 869 firstPixel, … … 909 909 // check to see if we are positioned on an image HDU 910 910 int hdutype; 911 if ( fits_get_hdu_type(fits-> p_fd,&hdutype, &status) != 0) {911 if ( fits_get_hdu_type(fits->fd,&hdutype, &status) != 0) { 912 912 char fitsErr[MAX_STRING_LENGTH]; 913 913 (void)fits_get_errstatus(status, fitsErr); … … 939 939 long nAxes[3]; 940 940 nAxes[2] = 1; 941 fits_get_img_param(fits-> p_fd, 3, &fileBitpix, &naxis, nAxes, &status);941 fits_get_img_param(fits->fd, 3, &fileBitpix, &naxis, nAxes, &status); 942 942 943 943 //check to see if the HDU has the same datatype … … 1012 1012 } 1013 1013 1014 fits_write_subset(fits-> p_fd, dataType, firstPixel, lastPixel, subset->data.V[0], &status);1014 fits_write_subset(fits->fd, dataType, firstPixel, lastPixel, subset->data.V[0], &status); 1015 1015 1016 1016 if ( status != 0) { … … 1052 1052 case PS_META_BOOL: { 1053 1053 int value = item->data.B; 1054 fits_update_key(fits-> p_fd,1054 fits_update_key(fits->fd, 1055 1055 TLOGICAL, 1056 1056 item->name, … … 1061 1061 } 1062 1062 case PS_META_S32: 1063 fits_update_key(fits-> p_fd,1063 fits_update_key(fits->fd, 1064 1064 TINT, 1065 1065 item->name, … … 1069 1069 break; 1070 1070 case PS_META_F32: 1071 fits_update_key(fits-> p_fd,1071 fits_update_key(fits->fd, 1072 1072 TFLOAT, 1073 1073 item->name, … … 1077 1077 break; 1078 1078 case PS_META_F64: 1079 fits_update_key(fits-> p_fd,1079 fits_update_key(fits->fd, 1080 1080 TDOUBLE, 1081 1081 item->name, … … 1085 1085 break; 1086 1086 case PS_META_STR: 1087 fits_update_key(fits-> p_fd,1087 fits_update_key(fits->fd, 1088 1088 TSTRING, 1089 1089 item->name, … … 1124 1124 // check to see if we even are positioned on a table HDU 1125 1125 int hdutype; 1126 fits_get_hdu_type(fits-> p_fd,&hdutype, &status);1126 fits_get_hdu_type(fits->fd,&hdutype, &status); 1127 1127 if ( status != 0) { 1128 1128 char fitsErr[MAX_STRING_LENGTH]; … … 1140 1140 1141 1141 // get the size of the FITS table 1142 fits_get_num_rows(fits-> p_fd, &numRows, &status);1143 fits_get_num_cols(fits-> p_fd, &numCols, &status);1142 fits_get_num_rows(fits->fd, &numRows, &status); 1143 fits_get_num_cols(fits->fd, &numCols, &status); 1144 1144 if ( status != 0) { 1145 1145 char fitsErr[MAX_STRING_LENGTH]; … … 1169 1169 // get the column name 1170 1170 if (hdutype == BINARY_TBL) { 1171 fits_get_bcolparms(fits-> p_fd, col, name,1171 fits_get_bcolparms(fits->fd, col, name, 1172 1172 NULL, NULL, NULL, NULL, NULL, NULL, NULL, &status); 1173 1173 } else { 1174 fits_get_acolparms(fits-> p_fd, col, name,1174 fits_get_acolparms(fits->fd, col, name, 1175 1175 NULL, NULL, NULL, NULL, NULL, NULL, NULL, &status); 1176 1176 } 1177 1177 // get the column type 1178 fits_get_coltype(fits-> p_fd, col, &typecode, &repeat, &width, &status);1178 fits_get_coltype(fits->fd, col, &typecode, &repeat, &width, &status); 1179 1179 1180 1180 if (status == 0) { … … 1184 1184 NATIVETYPE value = 0; \ 1185 1185 int anynul = 0; \ 1186 fits_read_col(fits-> p_fd, FITSTYPE, col,row+1, \1186 fits_read_col(fits->fd, FITSTYPE, col,row+1, \ 1187 1187 1, 1, NULL, &value, &anynul, &status); \ 1188 1188 psTrace(".psFits.psFitsReadTableRow",5,"Column #%i, '%s', is type %i, repeat %i, Value = %g\n", \ … … 1205 1205 char* value = psAlloc(repeat+1); 1206 1206 int anynul = 0; 1207 fits_read_col(fits-> p_fd, TSTRING, col,row+1,1207 fits_read_col(fits->fd, TSTRING, col,row+1, 1208 1208 1, 1, NULL, &value, &anynul, &status); 1209 1209 psTrace(".psFits.psFitsReadTableRow",5,"Column #%i, '%s', is type %i, repeat %i, value = %s\n", … … 1253 1253 // check to see if we even are positioned on a table HDU 1254 1254 int hdutype; 1255 if ( fits_get_hdu_type(fits-> p_fd,&hdutype, &status) != 0) {1255 if ( fits_get_hdu_type(fits->fd,&hdutype, &status) != 0) { 1256 1256 char fitsErr[MAX_STRING_LENGTH]; 1257 1257 (void)fits_get_errstatus(status, fitsErr); … … 1268 1268 1269 1269 // find the column by name 1270 if ( fits_get_colnum(fits-> p_fd, CASESEN, (char*)colname, &colnum, &status) != 0) {1270 if ( fits_get_colnum(fits->fd, CASESEN, (char*)colname, &colnum, &status) != 0) { 1271 1271 char fitsErr[MAX_STRING_LENGTH]; 1272 1272 (void)fits_get_errstatus(status, fitsErr); … … 1279 1279 // get the number of rows 1280 1280 long numRows = 0; 1281 fits_get_num_rows(fits-> p_fd, &numRows, &status);1281 fits_get_num_rows(fits->fd, &numRows, &status); 1282 1282 1283 1283 // get the column length. 1284 1284 int width; 1285 if ( fits_get_col_display_width(fits-> p_fd, colnum, &width, &status) != 0) {1285 if ( fits_get_col_display_width(fits->fd, colnum, &width, &status) != 0) { 1286 1286 char fitsErr[MAX_STRING_LENGTH]; 1287 1287 (void)fits_get_errstatus(status, fitsErr); … … 1299 1299 result->n = numRows; 1300 1300 1301 fits_read_col_str(fits-> p_fd,1301 fits_read_col_str(fits->fd, 1302 1302 colnum, 1303 1303 1, // firstrow … … 1335 1335 // check to see if we even are positioned on a table HDU 1336 1336 int hdutype; 1337 if ( fits_get_hdu_type(fits-> p_fd,&hdutype, &status) != 0) {1337 if ( fits_get_hdu_type(fits->fd,&hdutype, &status) != 0) { 1338 1338 char fitsErr[MAX_STRING_LENGTH]; 1339 1339 (void)fits_get_errstatus(status, fitsErr); … … 1350 1350 1351 1351 // find the column by name 1352 if ( fits_get_colnum(fits-> p_fd, CASESEN, (char*)colname, &colnum, &status) != 0) {1352 if ( fits_get_colnum(fits->fd, CASESEN, (char*)colname, &colnum, &status) != 0) { 1353 1353 char fitsErr[MAX_STRING_LENGTH]; 1354 1354 (void)fits_get_errstatus(status, fitsErr); … … 1361 1361 // get the number of rows 1362 1362 long numRows = 0; 1363 fits_get_num_rows(fits-> p_fd,1363 fits_get_num_rows(fits->fd, 1364 1364 &numRows, 1365 1365 &status); … … 1369 1369 long repeat; 1370 1370 long width; 1371 if ( fits_get_eqcoltype(fits-> p_fd, colnum, &typecode, &repeat, &width, &status) != 0) {1371 if ( fits_get_eqcoltype(fits->fd, colnum, &typecode, &repeat, &width, &status) != 0) { 1372 1372 char fitsErr[MAX_STRING_LENGTH]; 1373 1373 (void)fits_get_errstatus(status, fitsErr); … … 1380 1380 psVector* result = psVectorAlloc(numRows, convertFitsToPsType(typecode)); 1381 1381 1382 fits_read_col(fits-> p_fd,1382 fits_read_col(fits->fd, 1383 1383 typecode, 1384 1384 colnum, … … 1416 1416 // check to see if we even are positioned on a table HDU 1417 1417 int hdutype; 1418 if ( fits_get_hdu_type(fits-> p_fd,&hdutype, &status) != 0) {1418 if ( fits_get_hdu_type(fits->fd,&hdutype, &status) != 0) { 1419 1419 char fitsErr[MAX_STRING_LENGTH]; 1420 1420 (void)fits_get_errstatus(status, fitsErr); … … 1432 1432 // get the size of the FITS table 1433 1433 long numRows = 0; 1434 fits_get_num_rows(fits-> p_fd, &numRows, &status);1434 fits_get_num_rows(fits->fd, &numRows, &status); 1435 1435 if ( status != 0) { 1436 1436 char fitsErr[MAX_STRING_LENGTH]; … … 1535 1535 } 1536 1536 1537 fits_create_tbl(fits-> p_fd,1537 fits_create_tbl(fits->fd, 1538 1538 BINARY_TBL, 1539 1539 table->n, // number of rows in table … … 1562 1562 item->name); 1563 1563 } 1564 fits_write_col_int(fits-> p_fd,1564 fits_write_col_int(fits->fd, 1565 1565 n+1, // column number 1566 1566 1, // firstrow … … 1577 1577 item->name); 1578 1578 } 1579 fits_write_col_flt(fits-> p_fd,1579 fits_write_col_flt(fits->fd, 1580 1580 n+1, // column number 1581 1581 1, // firstrow … … 1592 1592 item->name); 1593 1593 } 1594 fits_write_col_dbl(fits-> p_fd,1594 fits_write_col_dbl(fits->fd, 1595 1595 n+1, // column number 1596 1596 1, // firstrow … … 1607 1607 item->name); 1608 1608 } 1609 fits_write_col_log(fits-> p_fd,1609 fits_write_col_log(fits->fd, 1610 1610 n+1, // column number 1611 1611 1, // firstrow … … 1625 1625 col->data[row] = item->data.V; 1626 1626 } 1627 fits_write_col_str(fits-> p_fd,1627 fits_write_col_str(fits->fd, 1628 1628 n, // column number 1629 1629 1, // firstrow … … 1661 1661 // check to see if we even are positioned on a table HDU 1662 1662 int hdutype; 1663 if ( fits_get_hdu_type(fits-> p_fd,&hdutype, &status) != 0) {1663 if ( fits_get_hdu_type(fits->fd,&hdutype, &status) != 0) { 1664 1664 char fitsErr[MAX_STRING_LENGTH]; 1665 1665 (void)fits_get_errstatus(status, fitsErr); … … 1684 1684 int colnum = 0; 1685 1685 1686 if ( fits_get_colnum(fits-> p_fd, CASESEN, item->name, &colnum, &status) == 0) {1686 if ( fits_get_colnum(fits->fd, CASESEN, item->name, &colnum, &status) == 0) { 1687 1687 // cooresponding column found in table 1688 1688 int dataType = 0; 1689 1689 convertPsTypeToFits(item->type, NULL, NULL, &dataType); 1690 1690 1691 if (fits_write_col(fits-> p_fd, dataType, colnum, row+1, 1, 1, &item->data,&status) != 0) {1691 if (fits_write_col(fits->fd, dataType, colnum, row+1, 1, 1, &item->data,&status) != 0) { 1692 1692 char fitsErr[MAX_STRING_LENGTH]; 1693 1693 (void)fits_get_errstatus(status, fitsErr);
Note:
See TracChangeset
for help on using the changeset viewer.
