Changeset 39460
- Timestamp:
- Mar 14, 2016, 1:34:58 PM (10 years ago)
- Location:
- trunk/Ohana/src/libfits
- Files:
-
- 2 edited
-
include/gfitsio.h (modified) (1 diff)
-
table/F_get_column.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libfits/include/gfitsio.h
r39457 r39460 247 247 int gfits_fwrite_vtable PROTO((FILE *f, VTable *table)); 248 248 int gfits_fwrite_ftable_range PROTO((FILE *f, FTable *table, off_t start, off_t Nrows, off_t Ndisk, off_t Ntotal)); 249 int gfits_byteswap_bintable_column PROTO((FTable *ftable, int column)); 249 250 int gfits_get_bintable_column PROTO((Header *header, FTable *table, char *label, void **data)); 250 251 int gfits_get_bintable_column_raw PROTO((Header *header, FTable *table, char *label, void **data, char nativeOrder)); -
trunk/Ohana/src/libfits/table/F_get_column.c
r38553 r39460 139 139 *Nrow = Ny; 140 140 return (array); 141 } 142 143 // do a column byteswap in-situ (needed because uncompress returns an unswapped binary table 144 int gfits_byteswap_bintable_column (FTable *ftable, int column) { 145 146 off_t Nx, Ny; 147 int i, Nval, Nbytes, Nv, Nb; 148 char field[256], format[256], tmpline[64], type[64]; 149 char *Pin, *Pout, *array; 150 151 Header *header = ftable->header; 152 153 /* interpret format */ 154 snprintf (field, 256, "TFORM%d", column); 155 if (!gfits_scan (header, field, "%s", 1, format)) return FALSE; 156 157 if (!gfits_bintable_format (format, type, &Nval, &Nbytes)) return FALSE; 158 159 /* convert data in-situ with correct type, byte swap and Bzero/Bscale */ 160 if (!strcmp (type, "char")) return TRUE; 161 if (!strcmp (type, "byte")) return TRUE; 162 163 /* check existing table dimensions */ 164 gfits_scan (header, "NAXIS1", OFF_T_FMT, 1, &Nx); 165 gfits_scan (header, "NAXIS2", OFF_T_FMT, 1, &Ny); 166 167 /* scan prior columns to find insert point */ 168 int Nstart = 0; 169 for (i = 1; i < column; i++) { 170 snprintf (field, 256, "TFORM%d", i); 171 gfits_scan (header, field, "%s", 1, format); 172 gfits_bintable_format (format, tmpline, &Nv, &Nb); 173 Nstart += Nv*Nb; 174 } 175 176 /* extract bytes from table into array */ 177 ALLOCATE (array, char, Nbytes*Nval*Ny); 178 Pin = ftable[0].buffer + Nstart; 179 Pout = array; 180 for (i = 0; i < Ny; i++, Pin += Nx, Pout += Nval*Nbytes) { 181 memcpy (Pout, Pin, Nval*Nbytes); 182 } 183 184 // NOTE: we have already copied the data to 'array', so the blocks below 185 // only need to swap if this is a direct copy 186 Pin = array; 187 Pout = array; 188 189 if (!strcmp (type, "short")) { 190 for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) { 191 # ifdef BYTE_SWAP 192 SWAP_BYTE; 193 # endif 194 } 195 } 196 if (!strcmp (type, "int")) { 197 for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) { 198 # ifdef BYTE_SWAP 199 SWAP_WORD; 200 # endif 201 } 202 } 203 if (!strcmp (type, "int64_t")) { 204 for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) { 205 # ifdef BYTE_SWAP 206 SWAP_DBLE; 207 # endif 208 } 209 } 210 if (!strcmp (type, "float")) { 211 for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) { 212 # ifdef BYTE_SWAP 213 SWAP_WORD; 214 # endif 215 } 216 } 217 if (!strcmp (type, "double")) { 218 for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) { 219 # ifdef BYTE_SWAP 220 SWAP_DBLE; 221 # endif 222 } 223 } 224 225 // save the bytes back into the table buffer 226 Pout = ftable[0].buffer + Nstart; 227 Pin = array; 228 for (i = 0; i < Ny; i++, Pout += Nx, Pin += Nval*Nbytes) { 229 memcpy (Pout, Pin, Nval*Nbytes); 230 } 231 232 return TRUE; 141 233 } 142 234
Note:
See TracChangeset
for help on using the changeset viewer.
