@TODO: NAXISx have to come in order. Check this!
| 346 | |
| 347 | //@TODO: NAXISx have to come in order. Check this! |
| 348 | ILenum GetCardImage(FITSHEAD *Header) |
| 349 | { |
| 350 | char Buffer[80]; |
| 351 | |
| 352 | if (iread(Buffer, 1, 80) != 80) // Each card image is exactly 80 bytes long. |
| 353 | return CARD_READ_FAIL; |
| 354 | |
| 355 | //@TODO: Use something other than !strncmp? |
| 356 | if (!strncmp(Buffer, "END ", 4)) |
| 357 | return CARD_END; |
| 358 | |
| 359 | else if (!strncmp(Buffer, "SIMPLE ", 7)) { |
| 360 | // The true value 'T' is always in the 30th position. |
| 361 | if (Buffer[29] != 'T') { |
| 362 | // We cannot support FITS files that do not correspond to the standard. |
| 363 | Header->IsSimple = IL_FALSE; //@TODO: Does this even need to be set? Should exit loading anyway. |
| 364 | ilSetError(IL_FORMAT_NOT_SUPPORTED); |
| 365 | return CARD_NOT_SIMPLE; |
| 366 | } |
| 367 | Header->IsSimple = IL_TRUE; |
| 368 | return CARD_SIMPLE; |
| 369 | } |
| 370 | |
| 371 | else if (!strncmp(Buffer, "BITPIX ", 7)) { |
| 372 | // The specs state that BITPIX has to come after SIMPLE. |
| 373 | if (Header->IsSimple != IL_TRUE) { |
| 374 | ilSetError(IL_INVALID_FILE_HEADER); |
| 375 | return CARD_READ_FAIL; |
| 376 | } |
| 377 | if (GetCardInt(Buffer, &Header->BitsPixel) != IL_TRUE) |
| 378 | return CARD_READ_FAIL; |
| 379 | //@TODO: Should I do this check from the calling function? Does it really matter? |
| 380 | if (Header->BitsPixel == 0) { |
| 381 | ilSetError(IL_FORMAT_NOT_SUPPORTED); |
| 382 | return CARD_READ_FAIL; |
| 383 | } |
| 384 | return CARD_BITPIX; |
| 385 | } |
| 386 | |
| 387 | // Needs the space after NAXIS so that it does not get this confused with NAXIS1, NAXIS2, etc. |
| 388 | else if (!strncmp(Buffer, "NAXIS ", 6)) { |
| 389 | if (GetCardInt(Buffer, &Header->NumAxes) != IL_TRUE) |
| 390 | return CARD_READ_FAIL; |
| 391 | //@TODO: Should I do this check from the calling function? Does it really matter? |
| 392 | if (Header->NumAxes < 1 || Header->NumAxes > 3) { |
| 393 | ilSetError(IL_FORMAT_NOT_SUPPORTED); |
| 394 | return CARD_READ_FAIL; |
| 395 | } |
| 396 | return CARD_NUMAXES; |
| 397 | } |
| 398 | |
| 399 | else if (!strncmp(Buffer, "NAXIS1 ", 7)) { |
| 400 | if (Header->NumAxes == 0) { // Has not been initialized, and it has to come first. |
| 401 | ilSetError(IL_INVALID_FILE_HEADER); |
| 402 | return CARD_READ_FAIL; |
| 403 | } |
| 404 | // First one will always be the width. |
| 405 | if (GetCardInt(Buffer, &Header->Width) != IL_TRUE) |
no test coverage detected