Changeset 7054 for trunk/Ohana/src/libfits/table/F_read_T.c
- Timestamp:
- May 3, 2006, 12:01:09 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/libfits/table/F_read_T.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libfits/table/F_read_T.c
r7039 r7054 3 3 4 4 /*********************** fits read table ***********************************/ 5 int fits_read_ftable (char *filename, FTable *table, char *extname) {5 int gfits_read_ftable (char *filename, FTable *table, char *extname) { 6 6 7 7 int status; … … 11 11 if (f == NULL) return (FALSE); 12 12 13 status = fits_fread_ftable (f, table, extname);13 status = gfits_fread_ftable (f, table, extname); 14 14 fclose (f); 15 15 return (status); … … 17 17 18 18 /*********************** fits read table ***********************************/ 19 int fits_fread_ftable (FILE *f, FTable *table, char *extname) {19 int gfits_fread_ftable (FILE *f, FTable *table, char *extname) { 20 20 21 21 int j, found, Nbytes; … … 29 29 for (j = -1; !found; j++) { 30 30 /* load data for this header */ 31 if (! fits_load_header (f, header)) return (FALSE);31 if (!gfits_load_header (f, header)) return (FALSE); 32 32 33 33 /* check if this is the correct extension or not */ 34 34 bzero (tname, 80); 35 fits_scan (header, "EXTNAME", "%s", 1, tname);35 gfits_scan (header, "EXTNAME", "%s", 1, tname); 36 36 if (!strcmp (tname, extname)) { 37 if ( fits_fread_ftable_data (f, table)) return (TRUE);38 fits_free_header (header);37 if (gfits_fread_ftable_data (f, table)) return (TRUE); 38 gfits_free_header (header); 39 39 return (FALSE); 40 40 } 41 41 42 42 /* skip to next header */ 43 Nbytes = fits_matrix_size (header);43 Nbytes = gfits_matrix_size (header); 44 44 fseek (f, Nbytes, SEEK_CUR); 45 fits_free_header (header);45 gfits_free_header (header); 46 46 } 47 47 return (TRUE); … … 49 49 50 50 /*********************** fits read ftable data ***********************************/ 51 int fits_fread_ftable_data (FILE *f, FTable *table) {51 int gfits_fread_ftable_data (FILE *f, FTable *table) { 52 52 53 53 int Nbytes, Nread; 54 54 55 55 /* find buffer size */ 56 Nbytes = fits_matrix_size (table[0].header);56 Nbytes = gfits_matrix_size (table[0].header); 57 57 ALLOCATE (table[0].buffer, char, Nbytes); 58 58 59 59 Nread = fread (table[0].buffer, sizeof (char), Nbytes, f); 60 60 if (Nread != Nbytes) { 61 fits_free_table (table);61 gfits_free_table (table); 62 62 return (FALSE); 63 63 } … … 67 67 68 68 /*********************** fits read ftable data ***********************************/ 69 int fits_fread_vtable_range (FILE *f, VTable *table, int start, int Nrows) {69 int gfits_fread_vtable_range (FILE *f, VTable *table, int start, int Nrows) { 70 70 71 71 int i, Nbytes, Nread, Nskip, Nx, Ny; … … 75 75 Nx = table[0].header[0].Naxis[0]; 76 76 Ny = table[0].header[0].Naxis[1]; 77 table[0].size = fits_matrix_size (table[0].header);77 table[0].size = gfits_matrix_size (table[0].header); 78 78 table[0].pad = table[0].size - Nx*Ny; 79 79 … … 105 105 106 106 /*********************** fits read virtual table ***********************************/ 107 int fits_fread_vtable (FILE *f, VTable *table, char *extname, int Nrow, int *row) {107 int gfits_fread_vtable (FILE *f, VTable *table, char *extname, int Nrow, int *row) { 108 108 109 109 int i, j, Nbytes, Nread; … … 117 117 for (j = -1; TRUE; j++) { 118 118 /* load data for this header */ 119 if (! fits_load_header (f, header)) return (FALSE);119 if (!gfits_load_header (f, header)) return (FALSE); 120 120 121 121 /* find buffer size */ 122 Nbytes = fits_matrix_size (header);122 Nbytes = gfits_matrix_size (header); 123 123 124 124 /* check if this is the correct extension or not */ 125 125 bzero (tname, 80); 126 fits_scan (header, "EXTNAME", "%s", 1, tname);126 gfits_scan (header, "EXTNAME", "%s", 1, tname); 127 127 if (strcmp (tname, extname)) { 128 128 /* skip to next header */ 129 129 fseek (f, Nbytes, SEEK_CUR); 130 fits_free_header (header);130 gfits_free_header (header); 131 131 continue; 132 132 } … … 134 134 /* file pointer is at beginning of desired table data */ 135 135 start = ftell (f); 136 fits_scan (header, "NAXIS1", "%d", 1, &Nx);137 fits_scan (header, "NAXIS2", "%d", 1, &Ny);136 gfits_scan (header, "NAXIS1", "%d", 1, &Nx); 137 gfits_scan (header, "NAXIS2", "%d", 1, &Ny); 138 138 for (i = 0; i < Nrow; i++) { 139 139 if (row[i] > Ny) { return (FALSE); } … … 152 152 ALLOCATE (table[0].row, int, MAX (1, Nrow)); 153 153 for (i = 0; i < Nrow; i++) table[0].row[i] = row[i]; 154 table[0].size = fits_matrix_size (table[0].header);154 table[0].size = gfits_matrix_size (table[0].header); 155 155 table[0].pad = table[0].size - Nx*Ny; 156 156 return (TRUE); … … 162 162 /* a poor function: read only the first table, regardless of name */ 163 163 /* keep until we are sure ohana code does not use it */ 164 int fits_read_table (char *filename, FTable *table) {164 int gfits_read_table (char *filename, FTable *table) { 165 165 166 166 FILE *f; … … 168 168 int status, i, nbytes, Nbytes, matrix_size; 169 169 170 if (! fits_read_header (filename, &header)) {170 if (!gfits_read_header (filename, &header)) { 171 171 fprintf (stderr, "error reading header of FITS file %s\n", filename); 172 172 return (FALSE); 173 173 } 174 174 175 if (! fits_read_Theader (filename, &table[0].header)) {175 if (!gfits_read_Theader (filename, &table[0].header)) { 176 176 fprintf (stderr, "error reading Theader of FITS file %s\n", filename); 177 177 return (FALSE); … … 179 179 180 180 if ((f = fopen (filename, "r")) == NULL) { 181 fits_free_header (&header);182 fits_free_header (&table[0].header);183 return (FALSE); 184 } 185 186 matrix_size = fits_matrix_size (&header);181 gfits_free_header (&header); 182 gfits_free_header (&table[0].header); 183 return (FALSE); 184 } 185 186 matrix_size = gfits_matrix_size (&header); 187 187 188 188 Nbytes = header.size + matrix_size + table[0].header.size; 189 189 fseek (f, Nbytes, 0); 190 fits_free_header (&header);190 gfits_free_header (&header); 191 191 192 fits_scan (&table[0].header, "TFIELDS", "%d", 1, &table[0].Nfields);192 gfits_scan (&table[0].header, "TFIELDS", "%d", 1, &table[0].Nfields); 193 193 194 194 /* place the field sizes in the structure? */ … … 198 198 table[0].Naxis[i] = table[0].header.Naxis[i]; 199 199 200 Nbytes = fits_matrix_size (&table[0].header);200 Nbytes = gfits_matrix_size (&table[0].header); 201 201 ALLOCATE (table[0].buffer, char, Nbytes); 202 202 nbytes = fread (table[0].buffer, sizeof(char), Nbytes, f); … … 213 213 214 214 215 int fits_fread_header_extname (FILE *f, Header *header, char *extname) {215 int gfits_fread_header_extname (FILE *f, Header *header, char *extname) { 216 216 217 217 int Nbytes; … … 219 219 220 220 fseek (f, 0, SEEK_SET); 221 fits_fread_header (f, header);221 gfits_fread_header (f, header); 222 222 223 223 if (!strcasecmp (extname, "PHU")) return (TRUE); 224 224 225 Nbytes = fits_matrix_size (header);225 Nbytes = gfits_matrix_size (header); 226 226 fseek (f, Nbytes, SEEK_CUR); 227 227 228 while ( fits_fread_header (f, header)) {229 fits_scan (header, "EXTNAME", "%s", 1, current);228 while (gfits_fread_header (f, header)) { 229 gfits_scan (header, "EXTNAME", "%s", 1, current); 230 230 if (!strcmp (current, extname)) return (TRUE); 231 Nbytes = fits_matrix_size (header);231 Nbytes = gfits_matrix_size (header); 232 232 fseek (f, Nbytes, SEEK_CUR); 233 233 }
Note:
See TracChangeset
for help on using the changeset viewer.
