Changeset 15743 for trunk/Ohana/src/libfits
- Timestamp:
- Dec 5, 2007, 3:29:29 PM (19 years ago)
- Location:
- trunk/Ohana/src/libfits
- Files:
-
- 8 edited
-
header/F_read_H.c (modified) (1 diff)
-
include/gfitsio.h (modified) (3 diffs)
-
matrix/F_load_M.c (modified) (1 diff)
-
matrix/F_read_portion.c (modified) (1 diff)
-
matrix/F_read_segment.c (modified) (1 diff)
-
table/F_read_T.c (modified) (3 diffs)
-
table/F_read_TH.c (modified) (1 diff)
-
table/F_write_T.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libfits/header/F_read_H.c
r15487 r15743 34 34 Nbytes = fread (&header[0].buffer[i*FT_RECORD_SIZE], 35 35 sizeof(char), FT_RECORD_SIZE, f); 36 if (Nbytes != FT_RECORD_SIZE) { 37 perror ("fits read error"); 38 } 39 36 40 header[0].size += Nbytes; 37 41 if (Nbytes != FT_RECORD_SIZE) { -
trunk/Ohana/src/libfits/include/gfitsio.h
r15656 r15743 2 2 3 3 # include <assert.h> 4 # include <errno.h> 4 5 5 6 # ifndef GFITSIO … … 172 173 int gfits_fread_ftable PROTO((FILE *f, FTable *ftable, char *extname)); 173 174 int gfits_fread_ftable_data PROTO((FILE *f, FTable *ftable)); 175 int gfits_fread_ftable_range PROTO((FILE *f, FTable *ftable, int start, int Nrows)); 174 176 int gfits_fread_vtable PROTO((FILE *f, VTable *vtable, char *extname, int Nrow, int *row)); 175 177 int gfits_fread_vtable_range PROTO((FILE *f, VTable *vtable, int start, int Nrows)); … … 178 180 int gfits_fwrite_table PROTO((FILE *f, FTable *table)); 179 181 int gfits_fwrite_vtable PROTO((FILE *f, VTable *table)); 182 int gfits_fwrite_ftable_range PROTO((FILE *f, FTable *table, int start, int Nrows, int Ndisk, int Ntotal)); 180 183 int gfits_get_bintable_column PROTO((Header *header, FTable *table, char *label, void **data)); 181 184 int gfits_get_bintable_column_type PROTO((Header *header, char *label, char *type, int *Nval)); -
trunk/Ohana/src/libfits/matrix/F_load_M.c
r15487 r15743 30 30 31 31 nbytes = fread (matrix[0].buffer, sizeof(char), Nbytes, f); 32 if (nbytes != Nbytes) { 33 perror ("fits matrix read error"); 34 } 32 35 33 36 # ifdef BYTE_SWAP -
trunk/Ohana/src/libfits/matrix/F_read_portion.c
r7054 r15743 47 47 fseek (f, header.size + Nskip, SEEK_SET); 48 48 nbytes = fread (matrix[0].buffer, sizeof(char), Nbytes, f); 49 if (nbytes != Nbytes) { 50 perror ("fits matrix read error"); 51 } 52 49 53 fclose (f); 50 54 -
trunk/Ohana/src/libfits/matrix/F_read_segment.c
r13039 r15743 90 90 fseek (f, Nskip, SEEK_CUR); 91 91 nbytes = fread (matrix[0].buffer, sizeof(char), Nbytes, f); 92 if (nbytes != Nbytes) { 93 perror ("fits matrix read error"); 94 } 95 92 96 matrix[0].size = Nbytes; 93 97 -
trunk/Ohana/src/libfits/table/F_read_T.c
r15487 r15743 59 59 Nread = fread (table[0].buffer, sizeof (char), Nbytes, f); 60 60 if (Nread != Nbytes) { 61 perror ("fits read error"); 61 62 gfits_free_table (table); 62 63 return (FALSE); 63 64 } 64 65 table[0].size = Nbytes; 66 return (TRUE); 67 } 68 69 /*********************** fits read ftable data ***********************************/ 70 int gfits_fread_ftable_range (FILE *f, FTable *table, int start, int Nrows) { 71 72 int Nbytes, Nread, Nskip, Nx, Ny; 73 74 /* find disk table size */ 75 Nx = table[0].header[0].Naxis[0]; 76 Ny = table[0].header[0].Naxis[1]; 77 78 // it is an error to ask for data starting out-of-bounds 79 if (start < 0) return (FALSE); 80 if (start >= Ny) return (FALSE); 81 82 // if we request more data than is available, we will stop at the table end. 83 Nrows = MIN (Nrows, Ny - start); 84 85 Nskip = start * Nx; 86 Nbytes = Nrows * Nx; 87 ALLOCATE (table[0].buffer, char, MAX (Nbytes, 1)); 88 89 fseek (f, Nskip, SEEK_CUR); 90 91 Nread = fread (table[0].buffer, sizeof (char), Nbytes, f); 92 if (Nread != Nbytes) { 93 if (ferror (f)) { 94 perror ("fits read error"); 95 } else { 96 fprintf (stderr, "unexpected eof\n"); 97 } 98 free (table[0].buffer); 99 return (FALSE); 100 } 101 102 /* modify structure and header to match actual read rows Ny */ 103 table[0].header[0].Naxis[1] = Nrows; 104 gfits_modify (table[0].header, "NAXIS2", "%d", 1, Nrows); 105 table[0].size = gfits_data_size (table[0].header); 106 65 107 return (TRUE); 66 108 } … … 88 130 Nread = fread (buffer, sizeof (char), Nbytes, f); 89 131 if (Nread != Nbytes) { 132 perror ("fits read error"); 90 133 free (buffer); 91 134 return (FALSE); … … 146 189 fseek (f, offset, SEEK_SET); 147 190 Nread = fread (table[0].buffer[i], sizeof (char), Nx, f); 148 if (Nread != Nx) { return (FALSE); } 191 if (Nread != Nx) { 192 perror ("fits read error"); 193 return (FALSE); 194 } 149 195 } 150 196 -
trunk/Ohana/src/libfits/table/F_read_TH.c
r15487 r15743 46 46 Nbytes = fread (&Theader[0].buffer[i*FT_RECORD_SIZE], 47 47 sizeof(char), FT_RECORD_SIZE, f); 48 if (Nbytes != FT_RECORD_SIZE) { 49 perror ("fits matrix read error"); 50 } 51 48 52 Theader[0].size += Nbytes; 49 53 if (Nbytes != FT_RECORD_SIZE) -
trunk/Ohana/src/libfits/table/F_write_T.c
r7054 r15743 69 69 /* this will add data beyond the end of the table in the file if needed, 70 70 filling intervening gap with 0 */ 71 72 /*********************** fits read ftable data ***********************************/ 73 int gfits_fwrite_ftable_range (FILE *f, FTable *ftable, int start, int Nrows, int Ndisk, int Ntotal) { 74 75 int Nbytes, Nwrite, Nskip, Nx, Npad; 76 char *pad; 77 78 if (start < 0) return (FALSE); 79 80 /* modify vtable to represent full disk table */ 81 gfits_modify (ftable[0].header, "NAXIS2", "%d", 1, Ntotal); 82 ftable[0].header[0].Naxis[1] = Ntotal; 83 84 Nx = ftable[0].header[0].Naxis[0]; // final output table size on disk 85 ftable[0].size = gfits_data_size (ftable[0].header); 86 87 Nskip = start * Nx; 88 Nbytes = Nrows * Nx; 89 90 // cursor must be at start of the table header 91 if (!gfits_fwrite_Theader (f, ftable[0].header)) { 92 fprintf (stderr, "can't write table header"); 93 return (FALSE); 94 } 95 96 // cursor must be at start of the table (after table header) 97 fseek (f, Nskip, SEEK_CUR); 98 Nwrite = fwrite (ftable[0].buffer, sizeof (char), Nbytes, f); 99 if (Nwrite != Nbytes) { 100 return (FALSE); 101 } 102 103 if (Ntotal >= Ndisk) { 104 Npad = ftable[0].size - Nx*Ntotal; 105 ALLOCATE (pad, char, Npad); 106 bzero (pad, Npad); 107 Nbytes = fwrite (pad, sizeof (char), Npad, f); 108 free (pad); 109 110 if (Nbytes != Npad) return (FALSE); 111 } 112 113 return (TRUE); 114 } 115
Note:
See TracChangeset
for help on using the changeset viewer.
