Changeset 13039 for trunk/Ohana/src/libfits/matrix/F_read_segment.c
- Timestamp:
- Apr 25, 2007, 4:18:23 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/libfits/matrix/F_read_segment.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libfits/matrix/F_read_segment.c
r7054 r13039 2 2 # include <gfitsio.h> 3 3 4 /** warning: this function requires 'dparse' which is included in libohana.a **/5 int dparse (double *, int, char *region);6 7 4 /*********************** fits read matrix ***********************************/ 8 int gfits_read_ segment (char *filename, Matrix *matrix, char *region) {5 int gfits_read_matrix_segment (char *filename, Matrix *matrix, char *region) { 9 6 10 7 FILE *f; 11 8 Header header; 9 int status; 10 11 f = fopen (filename, "r"); 12 if (f == NULL) { 13 return (FALSE); 14 } 15 16 status = gfits_fread_header (f, &header); 17 if (!status) { 18 fclose (f); 19 fprintf (stderr, "error reading header of FITS file %s\n", filename); 20 return (FALSE); 21 } 22 23 status = gfits_fread_matrix_segment (f, matrix, &header, region); 24 if (!status) { 25 fclose (f); 26 fprintf (stderr, "error reading header of FITS file %s\n", filename); 27 return (FALSE); 28 } 29 30 fclose (f); 31 return (TRUE); 32 } 33 34 // read header before calling this function 35 // file pointer should be at start of Matrix data segment 36 int gfits_fread_matrix_segment (FILE *f, Matrix *matrix, Header *header, char *region) { 37 12 38 int status, i, nbytes, Nbytes, Nskip, NbytesData; 13 39 int wantaxis[FT_MAX_NAXES][2]; … … 16 42 int perpix; 17 43 18 status = gfits_read_header (filename, &header);19 if (!status) {20 fprintf (stderr, "error reading header of FITS file %s\n", filename);21 return (FALSE);22 }23 24 f = fopen (filename, "r");25 if (f == NULL) {26 return (FALSE);27 }28 29 44 for (i = 0; i < FT_MAX_NAXES; i++) { 30 45 wantaxis[i][0] = wantaxis[i][1] = 0; 31 46 } 32 47 33 for (i = 0; i < header .Naxes; i++) {48 for (i = 0; i < header[0].Naxes; i++) { 34 49 status = dparse (&tmp, 2*i + 1, region); 35 50 if (!status || (tmp < 0)) 36 51 wantaxis[i][0] = 0; 37 52 else 38 wantaxis[i][0] = (tmp > header .Naxis[i] - 1) ? header.Naxis[i] - 1 : tmp;53 wantaxis[i][0] = (tmp > header[0].Naxis[i] - 1) ? header[0].Naxis[i] - 1 : tmp; 39 54 status = dparse (&tmp, 2*i + 2, region); 40 55 if (!status || (tmp < 0)) 41 wantaxis[i][1] = header .Naxis[i];56 wantaxis[i][1] = header[0].Naxis[i]; 42 57 else 43 wantaxis[i][1] = (tmp > header .Naxis[i]) ? header.Naxis[i] : tmp;58 wantaxis[i][1] = (tmp > header[0].Naxis[i]) ? header[0].Naxis[i] : tmp; 44 59 } 45 60 46 fseek (f, header.size, 0); 47 48 matrix[0].bitpix = header.bitpix; 49 matrix[0].unsign = header.unsign; 50 matrix[0].bscale = header.bscale; 51 matrix[0].bzero = header.bzero; 52 matrix[0].Naxes = header.Naxes; 61 matrix[0].bitpix = header[0].bitpix; 62 matrix[0].unsign = header[0].unsign; 63 matrix[0].bscale = header[0].bscale; 64 matrix[0].bzero = header[0].bzero; 65 matrix[0].Naxes = header[0].Naxes; 53 66 for (i = 0; i < FT_MAX_NAXES; i++) 54 67 matrix[0].Naxis[i] = wantaxis[i][1] - wantaxis[i][0]; … … 76 89 /* currently only good for reading in full planes in 3-D */ 77 90 fseek (f, Nskip, SEEK_CUR); 78 79 91 nbytes = fread (matrix[0].buffer, sizeof(char), Nbytes, f); 80 fclose (f);81 92 matrix[0].size = Nbytes; 82 93 83 94 # ifdef BYTE_SWAP 84 perpix = abs(header .bitpix) / 8;95 perpix = abs(header[0].bitpix) / 8; 85 96 if (perpix > 1) { 86 97 byte0 = (unsigned char *) matrix[0].buffer; … … 128 139 # endif 129 140 130 gfits_free_header (&header);131 132 141 if (nbytes < Nbytes - 2880) { /* this is a bad FITS error: image is not OK */ 133 fprintf (stderr, "error reading in matrix data from FITS file %s (%d < %d - 2880)\n", filename, nbytes, Nbytes);142 fprintf (stderr, "error reading in matrix data from FITS file (%d < %d - 2880)\n", nbytes, Nbytes); 134 143 return (FALSE); 135 144 } 136 145 if (nbytes != Nbytes) { /* this is a FITS error, but often the image is OK */ 137 fprintf (stderr, "incomplete block in %s: (%d, %d)\n", filename, nbytes, Nbytes);146 fprintf (stderr, "incomplete block in FITS file: (%d, %d)\n", nbytes, Nbytes); 138 147 return (TRUE); 139 148 } … … 142 151 143 152 } 144
Note:
See TracChangeset
for help on using the changeset viewer.
