Changeset 27435 for trunk/Ohana/src/libfits/matrix/F_read_portion.c
- Timestamp:
- Mar 24, 2010, 11:22:25 AM (16 years ago)
- Location:
- trunk/Ohana
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/libfits/matrix/F_read_portion.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana
-
Property svn:mergeinfo
set to
/branches/eam_branches/20091201/Ohana merged eligible /branches/eam_branches/largefiles.20100314/Ohana merged eligible
-
Property svn:mergeinfo
set to
-
trunk/Ohana/src/libfits/matrix/F_read_portion.c
r16139 r27435 9 9 /*********************** fits read matrix ***********************************/ 10 10 /** the result of this function is a matrix with dimension Npix * 1 **/ 11 int gfits_read_portion (char *filename, Matrix *matrix, int Nskip, int Npix) {11 int gfits_read_portion (char *filename, Matrix *matrix, off_t Nskip, off_t Npix) { 12 12 13 13 FILE *f; 14 14 Header header; 15 int status, nbytes, Nbytes, Nrec; 15 int status; 16 off_t nbytes, Nbytes, Nrec; 16 17 17 18 status = gfits_read_header (filename, &header); … … 37 38 Nbytes = FT_RECORD_SIZE * Nrec; 38 39 } 39 matrix[0]. size = Nbytes;40 matrix[0].datasize = Nbytes; 40 41 ALLOCATE (matrix[0].buffer, char, Nbytes); 41 42 … … 43 44 f = fopen (filename, "r"); 44 45 if (f == NULL) return (FALSE); 45 fseek (f, header.size + Nskip, SEEK_SET);46 fseeko (f, header.datasize + Nskip, SEEK_SET); 46 47 nbytes = fread (matrix[0].buffer, sizeof(char), Nbytes, f); 47 48 if (nbytes != Nbytes) { … … 52 53 53 54 # ifdef BYTE_SWAP 54 { 55 int i, perpix; 56 unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7, ctmp; 55 { 56 off_t i; 57 int perpix; 58 unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7, ctmp; 57 59 58 perpix = abs(header.bitpix) / 8; 59 if (perpix > 1) { 60 byte0 = (unsigned char *) matrix[0].buffer; 61 byte1 = (unsigned char *) matrix[0].buffer + 1; 62 byte2 = (unsigned char *) matrix[0].buffer + 2; 63 byte3 = (unsigned char *) matrix[0].buffer + 3; 64 byte4 = (unsigned char *) matrix[0].buffer + 4; 65 byte5 = (unsigned char *) matrix[0].buffer + 5; 66 byte6 = (unsigned char *) matrix[0].buffer + 6; 67 byte7 = (unsigned char *) matrix[0].buffer + 7; 68 if (perpix == 2) { 69 for (i = 0; i < nbytes; i+=2, byte0 += 2, byte1 += 2) { 70 ctmp = *byte0; 71 *byte0 = *byte1; 72 *byte1 = ctmp; 60 perpix = abs(header.bitpix) / 8; 61 if (perpix > 1) { 62 byte0 = (unsigned char *) matrix[0].buffer; 63 byte1 = (unsigned char *) matrix[0].buffer + 1; 64 byte2 = (unsigned char *) matrix[0].buffer + 2; 65 byte3 = (unsigned char *) matrix[0].buffer + 3; 66 byte4 = (unsigned char *) matrix[0].buffer + 4; 67 byte5 = (unsigned char *) matrix[0].buffer + 5; 68 byte6 = (unsigned char *) matrix[0].buffer + 6; 69 byte7 = (unsigned char *) matrix[0].buffer + 7; 70 if (perpix == 2) { 71 for (i = 0; i < nbytes; i+=2, byte0 += 2, byte1 += 2) { 72 ctmp = *byte0; 73 *byte0 = *byte1; 74 *byte1 = ctmp; 75 } 73 76 } 74 }75 if (perpix == 4) {76 for (i = 0; i < nbytes; i+=4, byte0 += 4, byte1 += 4, byte2 += 4, byte3 += 4) { 77 ctmp = *byte0;78 *byte0 = *byte3;79 *byte3 = ctmp;80 ctmp = *byte1;81 *byte1 = *byte2;82 *byte2 = ctmp;77 if (perpix == 4) { 78 for (i = 0; i < nbytes; i+=4, byte0 += 4, byte1 += 4, byte2 += 4, byte3 += 4) { 79 ctmp = *byte0; 80 *byte0 = *byte3; 81 *byte3 = ctmp; 82 ctmp = *byte1; 83 *byte1 = *byte2; 84 *byte2 = ctmp; 85 } 83 86 } 84 }85 if (perpix == 8) {86 for (i = 0; i < nbytes; i+=8, byte0 += 8, byte1 += 8, byte2 += 8, byte3 += 8, byte4 += 8, byte5 += 8, byte6 += 8, byte7 += 8) { 87 ctmp = *byte0;88 *byte0 = *byte7;89 *byte7 = ctmp;90 ctmp = *byte1;91 *byte1 = *byte6;92 *byte6 = ctmp;93 ctmp = *byte1;94 *byte2 = *byte5;95 *byte5 = ctmp;96 ctmp = *byte1;97 *byte3 = *byte4;98 *byte4 = ctmp;87 if (perpix == 8) { 88 for (i = 0; i < nbytes; i+=8, byte0 += 8, byte1 += 8, byte2 += 8, byte3 += 8, byte4 += 8, byte5 += 8, byte6 += 8, byte7 += 8) { 89 ctmp = *byte0; 90 *byte0 = *byte7; 91 *byte7 = ctmp; 92 ctmp = *byte1; 93 *byte1 = *byte6; 94 *byte6 = ctmp; 95 ctmp = *byte1; 96 *byte2 = *byte5; 97 *byte5 = ctmp; 98 ctmp = *byte1; 99 *byte3 = *byte4; 100 *byte4 = ctmp; 101 } 99 102 } 100 103 } 101 104 } 102 }103 105 # endif 104 106 … … 106 108 107 109 if (nbytes < Nbytes - 2880) { /* this is a bad FITS error: image is not OK */ 108 fprintf (stderr, "error reading in matrix data from FITS file %s (% d < %d - 2880)\n", filename, nbytes,Nbytes);110 fprintf (stderr, "error reading in matrix data from FITS file %s (%lld < %lld - 2880)\n", filename, (long long) nbytes, (long long) Nbytes); 109 111 return (FALSE); 110 112 } 111 113 if (nbytes != Nbytes) { /* this is a FITS error, but often the image is OK */ 112 fprintf (stderr, "incomplete block in %s: (% d, %d)\n", filename, nbytes,Nbytes);114 fprintf (stderr, "incomplete block in %s: (%lld, %lld)\n", filename, (long long) nbytes, (long long) Nbytes); 113 115 return (TRUE); 114 116 }
Note:
See TracChangeset
for help on using the changeset viewer.
