Changeset 15038 for trunk/Ohana/src/libfits/table/F_table_format.c
- Timestamp:
- Sep 26, 2007, 5:34:27 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/libfits/table/F_table_format.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libfits/table/F_table_format.c
r7054 r15038 189 189 } 190 190 191 /* vsnprintf (&line[off], Nchar + 1, format, argp); */ 191 // apply table tzero, tscal in situ (from storage to data) 192 int gfits_table_scale_data (FTable *ftable) { 193 194 int i, j, n, Nx, Ny, Nfields; 195 int off, Nchar, Nval, Nbytes, status; 196 char *line, format[64], field[16], type[16]; 197 double tzero, tscale; 198 char *tmpChar; 199 short *tmpShort; 200 int *tmpInt; 201 202 off = 0; 203 204 gfits_scan (ftable[0].header, "NAXIS1", "%d", 1, &Nx); 205 gfits_scan (ftable[0].header, "NAXIS2", "%d", 1, &Ny); 206 gfits_scan (ftable[0].header, "TFIELDS", "%d", 1, &Nfields); 207 208 for (i = 1; i <= Nfields; i++) { 209 sprintf (field, "TFORM%d", i); 210 gfits_scan (ftable[0].header, field, "%s", 1, format); /* get field format */ 211 gfits_bintable_format (format, type, &Nval, &Nbytes); /* convert to c-style */ 212 Nchar = Nval * Nbytes; 213 214 sprintf (field, "TZERO%d", i); 215 status = gfits_scan (ftable[0].header, field, "%lf", 1, &tzero); /* get field format */ 216 if (!status) { 217 off += Nchar; 218 continue; 219 } 220 221 sprintf (field, "TSCAL%d", i); 222 status = gfits_scan (ftable[0].header, field, "%lf", 1, &tscale); /* get field format */ 223 if (!status) { 224 off += Nchar; 225 continue; 226 } 227 if (tscale == 0.0) { 228 off += Nchar; 229 continue; 230 } 231 232 if (!strcmp (type, "char")) { 233 for (j = 0; j < Ny; j++) { 234 for (n = 0; n < Nval; n++) { 235 tmpChar = (int *)&ftable[0].buffer[j*Nx + n*Nbytes + off]; 236 *tmpChar = *tmpChar * tscale + tzero; 237 } 238 } 239 } 240 if (!strcmp (type, "short")) { 241 for (j = 0; j < Ny; j++) { 242 for (n = 0; n < Nval; n++) { 243 tmpShort = (int *)&ftable[0].buffer[j*Nx + n*Nbytes + off]; 244 *tmpShort = *tmpShort * tscale + tzero; 245 } 246 } 247 } 248 if (!strcmp (type, "int")) { 249 for (j = 0; j < Ny; j++) { 250 for (n = 0; n < Nval; n++) { 251 tmpInt = (int *)&ftable[0].buffer[j*Nx + n*Nbytes + off]; 252 *tmpInt = *tmpInt * tscale + tzero; 253 } 254 } 255 } 256 off += Nchar; 257 } 258 return (TRUE); 259 } 260 261 // apply table tzero, tscal in situ (from data to storage) 262 int gfits_table_scale_storage (FTable *ftable) { 263 264 int i, j, n, Nx, Ny, Nfields; 265 int off, Nchar, Nval, Nbytes, status; 266 char *line, format[64], field[16], type[16]; 267 double tzero, tscale; 268 char *tmpChar; 269 short *tmpShort; 270 int *tmpInt; 271 272 off = 0; 273 274 gfits_scan (ftable[0].header, "NAXIS1", "%d", 1, &Nx); 275 gfits_scan (ftable[0].header, "NAXIS2", "%d", 1, &Ny); 276 gfits_scan (ftable[0].header, "TFIELDS", "%d", 1, &Nfields); 277 278 for (i = 1; i <= Nfields; i++) { 279 sprintf (field, "TFORM%d", i); 280 gfits_scan (ftable[0].header, field, "%s", 1, format); /* get field format */ 281 gfits_bintable_format (format, type, &Nval, &Nbytes); /* convert to c-style */ 282 Nchar = Nval * Nbytes; 283 284 sprintf (field, "TZERO%d", i); 285 status = gfits_scan (ftable[0].header, field, "%lf", 1, &tzero); /* get field format */ 286 if (!status) { 287 off += Nchar; 288 continue; 289 } 290 291 sprintf (field, "TSCAL%d", i); 292 status = gfits_scan (ftable[0].header, field, "%lf", 1, &tscale); /* get field format */ 293 if (!status) { 294 off += Nchar; 295 continue; 296 } 297 if (tscale == 0.0) { 298 off += Nchar; 299 continue; 300 } 301 302 if (!strcmp (type, "char")) { 303 for (j = 0; j < Ny; j++) { 304 for (n = 0; n < Nval; n++) { 305 tmpChar = (int *)&ftable[0].buffer[j*Nx + n*Nbytes + off]; 306 *tmpChar = (*tmpChar - tzero) / tscale; 307 } 308 } 309 } 310 if (!strcmp (type, "short")) { 311 for (j = 0; j < Ny; j++) { 312 for (n = 0; n < Nval; n++) { 313 tmpShort = (int *)&ftable[0].buffer[j*Nx + n*Nbytes + off]; 314 *tmpShort = (*tmpShort - tzero) / tscale; 315 } 316 } 317 } 318 if (!strcmp (type, "int")) { 319 for (j = 0; j < Ny; j++) { 320 for (n = 0; n < Nval; n++) { 321 tmpInt = (int *)&ftable[0].buffer[j*Nx + n*Nbytes + off]; 322 *tmpInt = (*tmpInt - tzero) / tscale; 323 } 324 } 325 } 326 off += Nchar; 327 } 328 return (TRUE); 329 }
Note:
See TracChangeset
for help on using the changeset viewer.
