| 1 |
#include "fverify.h" |
| 2 |
|
| 3 |
/* |
| 4 |
the following are only needed if one calls wcslib |
| 5 |
#include <wcslib/wcshdr.h> |
| 6 |
#include <wcslib/wcsfix.h> |
| 7 |
#include <wcslib/wcs.h> |
| 8 |
#include <wcslib/getwcstab.h> |
| 9 |
*/ |
| 10 |
|
| 11 |
static char **cards; /* array to store the keywords */ |
| 12 |
static int ncards; /* total number of the keywords */ |
| 13 |
static char **tmpkwds; /* String array holding the keyword name. |
| 14 |
It is sorted in alphabetical ascending order |
| 15 |
and does not include the keywords before |
| 16 |
the first non-reserved keyword and END |
| 17 |
keyword. */ |
| 18 |
|
| 19 |
static char **ttype; |
| 20 |
static char **tform; |
| 21 |
static char **tunit; |
| 22 |
|
| 23 |
static char temp[80]; |
| 24 |
static char *ptemp; /* it always pointed to the address of |
| 25 |
temp */ |
| 26 |
static char snull[] = ""; |
| 27 |
static int curhdu; /* current HDU index */ |
| 28 |
static int curtype; /* current HDU type */ |
| 29 |
|
| 30 |
/****************************************************************************** |
| 31 |
* Function |
| 32 |
* verify_fits |
| 33 |
* |
| 34 |
* DESCRIPTION: |
| 35 |
* Verify individual fits file. |
| 36 |
* |
| 37 |
*******************************************************************************/ |
| 38 |
/* routine to verify individual fitsfile */ |
| 39 |
int verify_fits(char *infile, FILE *out) |
| 40 |
{ |
| 41 |
char rootnam[FLEN_FILENAME] = ""; /* Input Fits file root name */ |
| 42 |
fitsfile *infits; /* input fits file pointer */ |
| 43 |
FitsHdu fitshdu; /* hdu information */ |
| 44 |
int hdutype; |
| 45 |
int status = 0; |
| 46 |
int i; |
| 47 |
int len; |
| 48 |
char *p; |
| 49 |
char *pfile; |
| 50 |
char xtension[80]; |
| 51 |
|
| 52 |
/* take out the leading and trailing space and skip the empty line*/ |
| 53 |
p = infile; |
| 54 |
while(isspace((int)*p) )p++; |
| 55 |
len = strlen(p); |
| 56 |
pfile = p; |
| 57 |
p += (len -1); |
| 58 |
for (i = len - 1; i >= 0 && isspace((int)*p); i--) {*p = '\0'; p--;} |
| 59 |
if(!strlen(pfile)) return status; |
| 60 |
|
| 61 |
#ifndef WEBTOOL |
| 62 |
wrtout(out," "); |
| 63 |
sprintf(comm,"File: %s",pfile); |
| 64 |
wrtout(out,comm); |
| 65 |
#endif |
| 66 |
|
| 67 |
totalhdu = 0; |
| 68 |
|
| 69 |
#ifndef STANDALONE |
| 70 |
/* discard the extension, rowfilter... */ |
| 71 |
if(ffrtnm(pfile, rootnam, &status)) { |
| 72 |
wrtserr(out,"",&status,2); |
| 73 |
leave_early(out); |
| 74 |
status = 1; |
| 75 |
return status; |
| 76 |
} |
| 77 |
|
| 78 |
if(fits_open_file(&infits, rootnam, READONLY, &status)) { |
| 79 |
wrtserr(out,"",&status,2); |
| 80 |
leave_early(out); |
| 81 |
status = 1; |
| 82 |
return status; |
| 83 |
} |
| 84 |
#else |
| 85 |
if(fits_open_diskfile(&infits, pfile, READONLY, &status)) { |
| 86 |
wrtserr(out,"",&status,2); |
| 87 |
leave_early(out); |
| 88 |
status = 1; |
| 89 |
return status; |
| 90 |
} |
| 91 |
#endif |
| 92 |
|
| 93 |
/* get the total hdus */ |
| 94 |
if(fits_get_num_hdus(infits, &totalhdu, &status)) { |
| 95 |
wrtserr(out,"",&status,2); |
| 96 |
leave_early(out); |
| 97 |
status = 1; |
| 98 |
return status; |
| 99 |
} |
| 100 |
|
| 101 |
/* initialize the report */ |
| 102 |
init_report(out,rootnam); |
| 103 |
/*------------------ Hdu Loop --------------------------------*/ |
| 104 |
for (i = 1; i <= totalhdu; i++) { |
| 105 |
/* move to the right hdu and do the CFITSIO test */ |
| 106 |
hdutype = -1; |
| 107 |
if(fits_movabs_hdu(infits,i, &hdutype, &status) ) { |
| 108 |
print_title(out,i, hdutype); |
| 109 |
wrtferr(out,"",&status,2); |
| 110 |
set_hdubasic(i,hdutype); |
| 111 |
break; |
| 112 |
} |
| 113 |
|
| 114 |
if (i != 1 && hdutype == IMAGE_HDU) { |
| 115 |
/* test if this is a tile compressed image in a binary table */ |
| 116 |
fits_read_key(infits, TSTRING, "XTENSION", xtension, NULL, &status); |
| 117 |
if (!strcmp(xtension, "BINTABLE") ) |
| 118 |
print_title(out,i, BINARY_TBL); |
| 119 |
else |
| 120 |
print_title(out,i, hdutype); |
| 121 |
} |
| 122 |
else |
| 123 |
print_title(out,i, hdutype); |
| 124 |
|
| 125 |
init_hdu(infits,out,i,hdutype, |
| 126 |
&fitshdu); /* initialize fitshdu */ |
| 127 |
|
| 128 |
test_hdu(infits,out,&fitshdu); /* test hdu header */ |
| 129 |
|
| 130 |
if(testdata) |
| 131 |
test_data(infits,out,&fitshdu); |
| 132 |
|
| 133 |
close_err(out); /* end of error report */ |
| 134 |
|
| 135 |
if(prhead) |
| 136 |
print_header(out); |
| 137 |
if(prstat) |
| 138 |
print_summary(infits,out,&fitshdu); |
| 139 |
close_hdu(&fitshdu); /* clear the fitshdu */ |
| 140 |
} |
| 141 |
/* test the end of file */ |
| 142 |
test_end(infits,out); |
| 143 |
|
| 144 |
/*------------------ Closing --------------------------------*/ |
| 145 |
/* closing the report*/ |
| 146 |
close_report(out); |
| 147 |
|
| 148 |
/* close the input fitsfile */ |
| 149 |
fits_close_file(infits, &status); |
| 150 |
|
| 151 |
return status; |
| 152 |
} |
| 153 |
|
| 154 |
void leave_early (FILE* out) |
| 155 |
{ |
| 156 |
sprintf(comm,"**** Abort Verification: Fatal Error. ****"); |
| 157 |
wrtout(out,comm); |
| 158 |
|
| 159 |
/* write the total number of errors and warnings to parfile*/ |
| 160 |
update_parfile(1,0); |
| 161 |
} |
| 162 |
|
| 163 |
void close_err(FILE* out) |
| 164 |
{ |
| 165 |
int merr, mwrn; |
| 166 |
num_err_wrn(&merr, &mwrn); |
| 167 |
if(merr || mwrn ) wrtout(out," "); |
| 168 |
return; |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
/************************************************************* |
| 173 |
* |
| 174 |
* init_hdu |
| 175 |
* |
| 176 |
* Initialize the FitsHdu, HduName and ttype, tform, tunit if |
| 177 |
* the hdu is a table. |
| 178 |
* |
| 179 |
* |
| 180 |
*************************************************************/ |
| 181 |
void init_hdu(fitsfile *infits, /* input fits file */ |
| 182 |
FILE* out, /* output ascii file */ |
| 183 |
int hdunum, /* hdu index */ |
| 184 |
int hdutype, /* hdutype */ |
| 185 |
FitsHdu *hduptr |
| 186 |
) |
| 187 |
{ |
| 188 |
|
| 189 |
int morekeys; |
| 190 |
int i,j,k,m,n; |
| 191 |
int status = 0; |
| 192 |
FitsKey ** kwds; |
| 193 |
char *p = 0; |
| 194 |
int numusrkey; |
| 195 |
LONGLONG lv,lu=0L; |
| 196 |
|
| 197 |
|
| 198 |
FitsKey tmpkey; |
| 199 |
|
| 200 |
hduptr->hdunum = hdunum; |
| 201 |
hduptr->hdutype = hdutype; |
| 202 |
|
| 203 |
/* curhdu and curtype are shared with print_title */ |
| 204 |
curhdu = hdunum; /* set the current hdu number */ |
| 205 |
curtype = hdutype; /* set the current hdu number */ |
| 206 |
|
| 207 |
/* check the null character in the header.(only the first one will |
| 208 |
be recorded */ |
| 209 |
lv = 0; |
| 210 |
lv = fits_null_check(infits, &status); |
| 211 |
if (lv > 0) { |
| 212 |
m = (lv - 1)/80 + 1; |
| 213 |
n = lv - (m - 1) * 80; |
| 214 |
sprintf(errmes, |
| 215 |
"Byte #%d in Card#%d is a null(\\0).",n,m); |
| 216 |
wrterr(out,errmes,1); |
| 217 |
status = 0; |
| 218 |
} else { |
| 219 |
if (status) { |
| 220 |
wrtserr(out,"",&status,1); |
| 221 |
status = 0; |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
/* get the total number of keywords */ |
| 226 |
hduptr->nkeys = 0; |
| 227 |
morekeys = 0; |
| 228 |
if(fits_get_hdrspace(infits, &(hduptr->nkeys), &morekeys, &status)) |
| 229 |
wrtferr(out,"",&status,1); |
| 230 |
(hduptr->nkeys)++; /* include END keyword */ |
| 231 |
|
| 232 |
|
| 233 |
/* read all the keywords */ |
| 234 |
ncards = hduptr->nkeys; |
| 235 |
cards = (char **)malloc(sizeof(char *) * ncards ); |
| 236 |
for (i=0; i < ncards; i++) { |
| 237 |
cards[i] = (char *)malloc(sizeof(char )* FLEN_CARD ); |
| 238 |
} |
| 239 |
|
| 240 |
for (i=1; i <= ncards; i++) { |
| 241 |
if(fits_read_record(infits, i, cards[i-1], &status)) |
| 242 |
wrtferr(out,"",&status,1); |
| 243 |
} |
| 244 |
|
| 245 |
/* if there were blank cards prior to the END card, then |
| 246 |
make a fake END card, because CFITSIO blocks us from reading |
| 247 |
the real END card */ |
| 248 |
|
| 249 |
if (strncmp(cards[ncards-1], "END ", 8)) { |
| 250 |
strcpy(cards[ncards-1],"END "); |
| 251 |
} |
| 252 |
|
| 253 |
/* Parse the XTENSION/SIMPLEX keyword */ |
| 254 |
fits_parse_card(out, 1, cards[0], tmpkey.kname, |
| 255 |
&(tmpkey.ktype), tmpkey.kvalue,comm); |
| 256 |
if( *(tmpkey.kvalue) == ' ') { |
| 257 |
sprintf(errmes, |
| 258 |
"Keyword #1, %s \"%s\" should not have leading space.", |
| 259 |
tmpkey.kname,tmpkey.kvalue); |
| 260 |
wrterr(out,errmes,1); |
| 261 |
} |
| 262 |
if(hdunum == 1) { /* SIMPLE should be logical T */ |
| 263 |
if(strcmp(tmpkey.kname,"SIMPLE")) |
| 264 |
wrterr(out, "The 1st keyword of a primary array is not SIMPLE.",1); |
| 265 |
if( !check_log(&tmpkey,out)|| strcmp(tmpkey.kvalue,"T")) |
| 266 |
wrtwrn(out, |
| 267 |
"SIMPLE != T indicates file may not conform to the FITS Standard.",0); |
| 268 |
|
| 269 |
check_fixed_log(cards[0], out); |
| 270 |
} |
| 271 |
else { |
| 272 |
if(strcmp(tmpkey.kname,"XTENSION")) |
| 273 |
wrterr(out, "The 1st keyword of a extension is not XTENSION.",1); |
| 274 |
check_str(&tmpkey,out); |
| 275 |
|
| 276 |
check_fixed_str(cards[0], out); |
| 277 |
|
| 278 |
/* Get the original string */ |
| 279 |
p = cards[0]; |
| 280 |
p +=10; |
| 281 |
while (*p == ' ') p++; |
| 282 |
p++; /* skip the quote */ |
| 283 |
if( strncmp(p,"TABLE ",8) && |
| 284 |
strncmp(p,"BINTABLE",8) && |
| 285 |
strncmp(p,"A3DTABLE",8) && |
| 286 |
strncmp(p,"IUEIMAGE",8) && |
| 287 |
strncmp(p,"FOREIGN ",8) && |
| 288 |
strncmp(p,"DUMP ",8) && |
| 289 |
strncmp(p,"IMAGE ",8) ) { |
| 290 |
sprintf(errmes, "Unregistered XTENSION value \"%8.8s\".",p); |
| 291 |
wrterr(out,errmes,1); |
| 292 |
} |
| 293 |
else { |
| 294 |
if (p[8] != '\'') { |
| 295 |
sprintf(errmes, |
| 296 |
"Extra \'%c\' follows the XTENSION value \"%8.8s\".",p[8],p); |
| 297 |
wrterr(out,errmes,1); |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
/* test if this is a tile compressed image, stored in a binary table */ |
| 302 |
/* If so then test the extension as binary table rather than an image */ |
| 303 |
|
| 304 |
if (!strncmp(p,"BINTABLE",8) && hduptr->hdutype == IMAGE_HDU) { |
| 305 |
hduptr->hdutype = BINARY_TBL; |
| 306 |
hduptr->istilecompressed = 1; |
| 307 |
} else { |
| 308 |
hduptr->istilecompressed = 0; |
| 309 |
} |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
/* read the BITPIX keywords */ |
| 314 |
if(fits_read_key(infits, TINT, "BITPIX", &(hduptr->bitpix), NULL, &status)) |
| 315 |
wrtferr(out,"",&status,2); |
| 316 |
check_fixed_int(cards[1], out); |
| 317 |
|
| 318 |
/* Read and Parse the NAXIS */ |
| 319 |
hduptr->naxis = 0; |
| 320 |
if(fits_read_key(infits, TINT, "NAXIS", &(hduptr->naxis), NULL, &status)) |
| 321 |
wrtferr(out,"",&status,2); |
| 322 |
check_fixed_int(cards[2], out); |
| 323 |
|
| 324 |
if(hduptr->naxis!=0) |
| 325 |
hduptr->naxes = (LONGLONG *)malloc(hduptr->naxis*sizeof(LONGLONG)); |
| 326 |
for (i = 0; i < hduptr->naxis; i++) hduptr->naxes[i] = -1; |
| 327 |
|
| 328 |
/* Parse the keywords NAXISn */ |
| 329 |
for (j = 3; j < 3 + hduptr->naxis; j++){ |
| 330 |
fits_parse_card(out, 1+j,cards[j], tmpkey.kname, |
| 331 |
&(tmpkey.ktype), tmpkey.kvalue,comm); |
| 332 |
p = tmpkey.kname+5; |
| 333 |
if(!isdigit((int) *p))continue; |
| 334 |
#if (USE_LL_SUFFIX == 1) |
| 335 |
if(check_int(&tmpkey,out)) lu = strtoll(tmpkey.kvalue,NULL,10); |
| 336 |
#else |
| 337 |
if(check_int(&tmpkey,out)) lu = strtol(tmpkey.kvalue,NULL,10); |
| 338 |
#endif |
| 339 |
lv = strtol(p,NULL,10); |
| 340 |
if(lv > hduptr->naxis && lv <= 0) { |
| 341 |
sprintf(errmes, |
| 342 |
"Keyword #%d, %s is not allowed (with n > NAXIS = %d).", |
| 343 |
tmpkey.kindex,tmpkey.kname,hduptr->naxis); |
| 344 |
wrterr(out,errmes,1); |
| 345 |
} |
| 346 |
else { |
| 347 |
if(hduptr->naxes[lv-1] == -1) { |
| 348 |
hduptr->naxes[lv-1] = lu; |
| 349 |
} |
| 350 |
else { |
| 351 |
sprintf(errmes, "Keyword #%d, %s is duplicated.", |
| 352 |
tmpkey.kindex,tmpkey.kname); |
| 353 |
wrterr(out,errmes,1); |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
check_fixed_int(cards[j], out); |
| 358 |
} |
| 359 |
|
| 360 |
/* check all the NAXISn are there */ |
| 361 |
for (j = 0; j < hduptr->naxis; j++) { |
| 362 |
if(hduptr->naxes[j] == -1) { |
| 363 |
sprintf(errmes, |
| 364 |
"Keyword NAXIS%d is not present or is out of order.", j+1); |
| 365 |
wrterr(out,errmes,2); |
| 366 |
} |
| 367 |
} |
| 368 |
|
| 369 |
/* get the column number */ |
| 370 |
hduptr->ncols = 1; |
| 371 |
if(hduptr->hdutype == ASCII_TBL || hduptr->hdutype == BINARY_TBL) { |
| 372 |
/* get the total number of columns */ |
| 373 |
if(fits_get_num_cols(infits, &(hduptr->ncols),&status)) |
| 374 |
wrtferr(out,"",&status,2); |
| 375 |
} |
| 376 |
|
| 377 |
/* parse the keywords after NAXISn and prepare the array for |
| 378 |
sorting. We only check the keywords after the NAXISn */ |
| 379 |
n = hduptr->nkeys - 4 - hduptr->naxis ; /* excluding the SIMPLE/XTENSION, |
| 380 |
BITPIX, NAXIS, NAXISn |
| 381 |
and END */ |
| 382 |
hduptr->kwds = (FitsKey **)malloc(sizeof(FitsKey *)*n); |
| 383 |
for (i= 0; i < n; i++) |
| 384 |
hduptr->kwds[i] = (FitsKey *)malloc(sizeof(FitsKey)); |
| 385 |
kwds = hduptr->kwds; |
| 386 |
k = 3 + hduptr->naxis; /* index of first keyword following NAXISn. */ |
| 387 |
m = hduptr->nkeys - 1; /* last key */ |
| 388 |
i = 0; |
| 389 |
hduptr->use_longstr = 0; |
| 390 |
for (j = k ; j < m; j++) { |
| 391 |
kwds[i]->kindex = j+1; /* record number */ |
| 392 |
kwds[i]->goodkey=1; |
| 393 |
if(fits_parse_card(out,1+j,cards[j], kwds[i]->kname, |
| 394 |
&(kwds[i]->ktype), kwds[i]->kvalue,comm)) |
| 395 |
kwds[i]->goodkey=0; |
| 396 |
|
| 397 |
if (kwds[i]->ktype == UNKNOWN && *(kwds[i]->kvalue) == 0) |
| 398 |
{ |
| 399 |
sprintf(errmes, |
| 400 |
"Keyword #%d, %s has a null value.", |
| 401 |
j+1,kwds[i]->kname); |
| 402 |
wrtwrn(out,errmes,0); |
| 403 |
} |
| 404 |
|
| 405 |
/* only count the non-commentary keywords */ |
| 406 |
if (!strcmp(kwds[i]->kname,"CONTINUE")) { |
| 407 |
hduptr->use_longstr = 1; |
| 408 |
} |
| 409 |
if( strcmp(kwds[i]->kname,"COMMENT") && |
| 410 |
strcmp(kwds[i]->kname,"HISTORY") && |
| 411 |
(strcmp(kwds[i]->kname,"HIERARCH") || testhierarch) && |
| 412 |
strcmp(kwds[i]->kname,"CONTINUE") && |
| 413 |
strcmp(kwds[i]->kname,"") ) i++; |
| 414 |
} |
| 415 |
numusrkey = i; |
| 416 |
hduptr->tkeys = i; |
| 417 |
|
| 418 |
/* parse the END key */ |
| 419 |
fits_parse_card(out,m+1,cards[hduptr->nkeys-1], |
| 420 |
tmpkey.kname,&(tmpkey.ktype),tmpkey.kvalue,comm) ; |
| 421 |
|
| 422 |
/* sort the keyword in the ascending order of kname field*/ |
| 423 |
qsort(kwds, numusrkey, sizeof(FitsKey *), compkey); |
| 424 |
|
| 425 |
/* store addresses of sorted keyword names in a working |
| 426 |
array */ |
| 427 |
tmpkwds = (char **)malloc(sizeof(char*) * numusrkey); |
| 428 |
for (i=0; i < numusrkey; i++) tmpkwds[i] = kwds[i]->kname; |
| 429 |
|
| 430 |
/* Initialize the PCOUNT, GCOUNT and heap values */ |
| 431 |
hduptr->pcount = -99; |
| 432 |
hduptr->gcount = -99; |
| 433 |
hduptr->heap = -99; |
| 434 |
|
| 435 |
/* set the random group flag (will be determined later) */ |
| 436 |
hduptr->isgroup = 0; |
| 437 |
|
| 438 |
/* allocate memory for datamax and datamin (will determined later)*/ |
| 439 |
if(hduptr->ncols > 0) { |
| 440 |
hduptr->datamax = (char **)calloc(hduptr->ncols, sizeof(char *)); |
| 441 |
hduptr->datamin = (char **)calloc(hduptr->ncols, sizeof(char *)); |
| 442 |
hduptr->tnull = (char **)calloc(hduptr->ncols, sizeof(char *)); |
| 443 |
for (i = 0; i < hduptr->ncols; i++) { |
| 444 |
hduptr->datamax[i] = (char *)calloc(13,sizeof(char)); |
| 445 |
hduptr->datamin[i] = (char *)calloc(13,sizeof(char)); |
| 446 |
hduptr->tnull[i] = (char *)calloc(12,sizeof(char)); |
| 447 |
} |
| 448 |
} |
| 449 |
|
| 450 |
|
| 451 |
/* initialize the extension name and version */ |
| 452 |
strcpy(hduptr->extname,""); |
| 453 |
hduptr->extver = -999; |
| 454 |
|
| 455 |
|
| 456 |
return; |
| 457 |
} |
| 458 |
|
| 459 |
/************************************************************* |
| 460 |
* |
| 461 |
* test_hdu |
| 462 |
* |
| 463 |
* Test the HDU header |
| 464 |
* This includes many tests of WCS keywords |
| 465 |
* |
| 466 |
*************************************************************/ |
| 467 |
void test_hdu(fitsfile *infits, /* input fits file */ |
| 468 |
FILE *out, /* output ascii file */ |
| 469 |
FitsHdu *hduptr |
| 470 |
) |
| 471 |
|
| 472 |
{ |
| 473 |
int status = 0; |
| 474 |
FitsKey **kwds; |
| 475 |
int numusrkey; |
| 476 |
int hdunum; |
| 477 |
char *p, *p2, *pname[NWCSDESCR]; |
| 478 |
int i,j,k,m,n, wcsaxesmax = 0; |
| 479 |
int taxes, iaxis=0, ialt=0; |
| 480 |
int wcsaxesExists = 0, wcsaxesvalue = 0, wcsaxespos[NWCSDESCR], wcskeypos[NWCSDESCR]; |
| 481 |
FitsKey *pkey; |
| 482 |
int crota2_exists = 0, matrix_exists[2] = {0,0}; |
| 483 |
double dvalue; |
| 484 |
int primary_naxis = 0; |
| 485 |
|
| 486 |
/* floating WCS keywords */ |
| 487 |
char *cfltkeys[] = {"CRPIX", "CRVAL","CDELT","CROTA", |
| 488 |
"CRDER","CSYER", "PV"}; |
| 489 |
int ncfltkeys = 7; |
| 490 |
int keynum[] = {0,0,0,0,0,0,0}, nmax = 0; |
| 491 |
|
| 492 |
/* floating non-indexed WCS keywords */ |
| 493 |
char *cfltnkeys[] = {"RESTFRQ", "RESTFREQ", "RESTWAV", |
| 494 |
"OBSGEO-X", "OBSGEO-Y", "OBSGEO-Z", |
| 495 |
"VELOSYS", "ZSOURCE", "VELANGL", |
| 496 |
"LONPOLE", "LATPOLE"}; |
| 497 |
int ncfltnkeys = 11; |
| 498 |
|
| 499 |
/* floating WCS keywords w/ underscore */ |
| 500 |
char *cflt_keys[] = {"PC","CD"}; |
| 501 |
int ncflt_keys = 2; |
| 502 |
|
| 503 |
/* string WCS keywords */ |
| 504 |
char *cstrkeys[] = {"CTYPE", "CUNIT", "PS", "CNAME" }; |
| 505 |
int ncstrkeys = 4; |
| 506 |
|
| 507 |
/* string RADESYS keywords with list of allowed values */ |
| 508 |
char *rastrkeys[] = {"RADESYS", "RADECSYS" }; |
| 509 |
int nrastrkeys = 2; |
| 510 |
|
| 511 |
/* string spectral ref frame keywords with list of allowed values */ |
| 512 |
char *specstrkeys[] = {"SPECSYS", "SSYSOBS", "SSYSSRC" }; |
| 513 |
int nspecstrkeys = 3; |
| 514 |
|
| 515 |
for (i=0; i<NWCSDESCR; ++i) |
| 516 |
{ |
| 517 |
wcsaxespos[i] = -1; |
| 518 |
wcskeypos[i] = 1000000000; |
| 519 |
pname[i] = 0; |
| 520 |
} |
| 521 |
|
| 522 |
numusrkey = hduptr->tkeys; |
| 523 |
kwds = hduptr->kwds; |
| 524 |
|
| 525 |
/* find the extension name and version */ |
| 526 |
strcpy(temp,"EXTNAME"); |
| 527 |
ptemp = temp; |
| 528 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 529 |
if(k> -1 ) { |
| 530 |
if(kwds[k]->ktype == STR_KEY) |
| 531 |
strcpy(hduptr->extname,kwds[k]->kvalue); |
| 532 |
} |
| 533 |
|
| 534 |
strcpy(temp,"EXTVER"); |
| 535 |
ptemp = temp; |
| 536 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 537 |
if(k> -1 ) { |
| 538 |
if(kwds[k]->ktype == INT_KEY) |
| 539 |
hduptr->extver = (int) strtol(kwds[k]->kvalue,NULL,10); |
| 540 |
} |
| 541 |
|
| 542 |
/* set the HduName structure */ |
| 543 |
hdunum = hduptr->hdunum; |
| 544 |
set_hduname(hdunum,hduptr->hdutype,hduptr->extname, hduptr->extver); |
| 545 |
|
| 546 |
if(hduptr->hdunum == 1) { |
| 547 |
test_prm(infits,out,hduptr); |
| 548 |
primary_naxis = hduptr->naxis; |
| 549 |
} |
| 550 |
else { |
| 551 |
/* test the keywords specific to the hdutype*/ |
| 552 |
switch (hduptr->hdutype) { |
| 553 |
case IMAGE_HDU: |
| 554 |
test_img_ext(infits,out,hduptr); |
| 555 |
break; |
| 556 |
case ASCII_TBL: |
| 557 |
test_asc_ext(infits,out,hduptr); |
| 558 |
break; |
| 559 |
case BINARY_TBL: |
| 560 |
test_bin_ext(infits,out,hduptr); |
| 561 |
break; |
| 562 |
default: |
| 563 |
break; |
| 564 |
} |
| 565 |
} |
| 566 |
/* test the general keywords */ |
| 567 |
test_header(infits,out,hduptr); |
| 568 |
|
| 569 |
/* Check INHERIT keyword; must not be used if primary contains data */ |
| 570 |
strcpy(temp,"INHERIT"); |
| 571 |
ptemp = temp; |
| 572 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 573 |
if(k > -1) { |
| 574 |
if(primary_naxis != 0) { |
| 575 |
sprintf(errmes, |
| 576 |
"Keyword #%d, %s cannot be used if the primary array contains data (NAXIS != 0).", |
| 577 |
kwds[k]->kindex, kwds[k]->kname); |
| 578 |
wrtwrn(out,errmes,0); |
| 579 |
} |
| 580 |
check_log(kwds[k],out); |
| 581 |
} |
| 582 |
|
| 583 |
/* test if CROTA2 exists; if so, then PCi_j must not exist */ |
| 584 |
strcpy(temp,"CROTA2"); |
| 585 |
ptemp = temp; |
| 586 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 587 |
if (n == 1) { |
| 588 |
pkey = hduptr->kwds[k]; |
| 589 |
crota2_exists = pkey->kindex; |
| 590 |
} |
| 591 |
|
| 592 |
strcpy(temp,"WCSAXES"); |
| 593 |
ptemp = temp; |
| 594 |
|
| 595 |
/* first find the primary WCSAXES value, if it exists */ |
| 596 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 597 |
if (k >= 0) { |
| 598 |
j = k; |
| 599 |
if (check_int(kwds[j],out)) { |
| 600 |
pkey = hduptr->kwds[j]; |
| 601 |
wcsaxesvalue = (int) strtol(pkey->kvalue,NULL,10); |
| 602 |
nmax = wcsaxesvalue; |
| 603 |
if (wcsaxesvalue > wcsaxesmax) wcsaxesmax = wcsaxesvalue; |
| 604 |
wcsaxesExists = 1; |
| 605 |
|
| 606 |
/* store index of the wcsaxes keyword */ |
| 607 |
/* (it must appear before other WCS keywords) */ |
| 608 |
if (pkey->kindex > wcsaxespos[0]) wcsaxespos[0] = pkey->kindex; |
| 609 |
} |
| 610 |
} |
| 611 |
|
| 612 |
/* Check and find max value of the WCSAXESa keywords */ |
| 613 |
/* Use the max value when checking the range of the indexed WCS keywords. */ |
| 614 |
/* This is a less rigorous test than if one were to test the range of the */ |
| 615 |
/* keywords for each of the alternate WCS systems (A - Z) against the */ |
| 616 |
/* corresponding WCSAXESa keyword. */ |
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 621 |
|
| 622 |
for (j = k; j< n + k ; j++){ |
| 623 |
if (check_int(kwds[j],out)) { |
| 624 |
pkey = hduptr->kwds[j]; |
| 625 |
taxes = (int) strtol(pkey->kvalue,NULL,10); |
| 626 |
if (taxes > wcsaxesmax) wcsaxesmax = taxes; |
| 627 |
wcsaxesExists = 1; |
| 628 |
|
| 629 |
/* store highest index of any wcsaxes keyword */ |
| 630 |
/* (they must appear before other WCS keywords) */ |
| 631 |
|
| 632 |
|
| 633 |
/* Removed this check on 6/28/2012. See discussion on FITSBITS related |
| 634 |
to this requirement. The sense of this dicussion is that it is not required |
| 635 |
that every WCSAXESa keyword appear before ANY OTHER WCS keyword. In principle, |
| 636 |
each WCSAXESa keyword should appear before any other WCS keyword within the SAME |
| 637 |
alternate system, but this does not really provide any benefit to software that |
| 638 |
needs to parse the WCS keywords. Since it would be somewhat tedious to make |
| 639 |
this test, we will not not worry about the placement of the WCSAXESa keywords. |
| 640 |
*/ |
| 641 |
/* if (pkey->kindex > wcsaxespos) wcsaxespos = pkey->kindex; */ |
| 642 |
|
| 643 |
parse_wcskey_suffix(pkey->kname, ptemp, &iaxis, &ialt); |
| 644 |
wcsaxespos[ialt] = pkey->kindex; |
| 645 |
} |
| 646 |
} |
| 647 |
|
| 648 |
/* test datatype of reserved indexed floating point WCS keywords */ |
| 649 |
for (i = 0; i < ncfltkeys; i++) { |
| 650 |
strcpy(temp,cfltkeys[i]); |
| 651 |
ptemp = temp; |
| 652 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 653 |
if(k < 0) continue; |
| 654 |
|
| 655 |
for (j = k; j < k+n; j++) { |
| 656 |
pkey = hduptr->kwds[j]; |
| 657 |
|
| 658 |
p = kwds[j]->kname; |
| 659 |
p += strlen(temp); |
| 660 |
if(!isdigit((int)*p)) continue; |
| 661 |
|
| 662 |
if (!check_flt(pkey,out) )continue; |
| 663 |
|
| 664 |
if (i == 2 ) { /* test that CDELTi != 0 */ |
| 665 |
dvalue = strtod(pkey->kvalue, NULL); |
| 666 |
if (dvalue == 0.) { |
| 667 |
sprintf( errmes, |
| 668 |
"Keyword #%d, %s: must have non-zero value.", |
| 669 |
pkey->kindex,pkey->kname); |
| 670 |
wrterr(out,errmes,1); |
| 671 |
} |
| 672 |
} |
| 673 |
|
| 674 |
if (i == 4 || i == 5 ) { /* test that CRDERi and CSYSERi are non-negative */ |
| 675 |
dvalue = strtod(pkey->kvalue, NULL); |
| 676 |
if (dvalue < 0.) { |
| 677 |
sprintf( errmes, |
| 678 |
"Keyword #%d, %s: must have non-negative value: %s", |
| 679 |
pkey->kindex,pkey->kname,pkey->kvalue); |
| 680 |
wrterr(out,errmes,1); |
| 681 |
} |
| 682 |
} |
| 683 |
|
| 684 |
parse_wcskey_suffix(pkey->kname,ptemp,&iaxis,&ialt); |
| 685 |
if (wcsaxesExists) { /* WCSAXES keyword exists */ |
| 686 |
|
| 687 |
if (iaxis < 1 || iaxis > wcsaxesmax) { |
| 688 |
sprintf( errmes, |
| 689 |
"Keyword #%d, %s: index %d is not in range 1-%d (WCSAXES).", |
| 690 |
pkey->kindex,pkey->kname,iaxis,wcsaxesmax); |
| 691 |
wrterr(out,errmes,1); |
| 692 |
} |
| 693 |
|
| 694 |
} else { |
| 695 |
|
| 696 |
if (iaxis < 1 || iaxis > hduptr->naxis) { |
| 697 |
sprintf( errmes, |
| 698 |
"Keyword #%d, %s: index %d is not in range 1-%d (NAXIS).", |
| 699 |
pkey->kindex,pkey->kname,iaxis,hduptr->naxis); |
| 700 |
wrtwrn(out,errmes,0); |
| 701 |
} |
| 702 |
} |
| 703 |
|
| 704 |
/* count the number of each keyword */ |
| 705 |
if (ialt == 0) { /* only test the primary set of WCS keywords */ |
| 706 |
keynum[i] = keynum[i] + 1; |
| 707 |
if (iaxis > nmax) nmax = iaxis; |
| 708 |
} |
| 709 |
|
| 710 |
/* store lowest index of any wcs keyword */ |
| 711 |
if (pkey->kindex < wcskeypos[ialt]) { |
| 712 |
wcskeypos[ialt] = pkey->kindex; |
| 713 |
pname[ialt] = pkey->kname; |
| 714 |
} |
| 715 |
} |
| 716 |
} |
| 717 |
|
| 718 |
if (wcsaxesvalue == 0) { /* limit value of nmax to the legal maximum */ |
| 719 |
if (nmax > hduptr->naxis) |
| 720 |
nmax = hduptr->naxis; |
| 721 |
} else { |
| 722 |
if (nmax > wcsaxesvalue) |
| 723 |
nmax = wcsaxesvalue; |
| 724 |
} |
| 725 |
|
| 726 |
if (keynum[0] < nmax) { /* test number of CRPIXi keywords */ |
| 727 |
sprintf( errmes, |
| 728 |
"Some CRPIXi keywords appear to be missing; expected %d.",nmax); |
| 729 |
wrtwrn(out,errmes,0); |
| 730 |
} |
| 731 |
if (keynum[1] < nmax) { /* test number of CRVALi keywords */ |
| 732 |
sprintf( errmes, |
| 733 |
"Some CRVALi keywords appear to be missing; expected %d.",nmax); |
| 734 |
wrtwrn(out,errmes,0); |
| 735 |
} |
| 736 |
|
| 737 |
/* test datatype of reserved non-indexed floating point WCS keywords */ |
| 738 |
for (i = 0; i < ncfltnkeys; i++) { |
| 739 |
strcpy(temp,cfltnkeys[i]); |
| 740 |
ptemp = temp; |
| 741 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 742 |
|
| 743 |
if(k < 0) continue; |
| 744 |
|
| 745 |
for (j = k; j < k+n; j++) { |
| 746 |
pkey = hduptr->kwds[j]; |
| 747 |
|
| 748 |
if (!check_flt(pkey,out) )continue; |
| 749 |
} |
| 750 |
} |
| 751 |
|
| 752 |
/* test datatype of reserved indexed floating point WCS keywords with "_" */ |
| 753 |
for (i = 0; i < ncflt_keys; i++) { |
| 754 |
strcpy(temp,cflt_keys[i]); |
| 755 |
ptemp = temp; |
| 756 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 757 |
if(k < 0) continue; |
| 758 |
|
| 759 |
for (j = k; j < k+n; j++) { |
| 760 |
pkey = hduptr->kwds[j]; |
| 761 |
|
| 762 |
p = kwds[j]->kname; |
| 763 |
p += strlen(temp); |
| 764 |
if(!isdigit((int)*p)) continue; |
| 765 |
|
| 766 |
p2 = strchr(p, '_'); /* 2 digits must be separated by a '_' */ |
| 767 |
if (!p2) continue; |
| 768 |
|
| 769 |
if (!check_flt(pkey,out) )continue; |
| 770 |
|
| 771 |
*p2 = '\0'; /* terminate string at the '_' */ |
| 772 |
|
| 773 |
/* test the first digit */ |
| 774 |
m = (int)strtol(p,NULL,10); |
| 775 |
*p2 = '_'; /* replace the '_' */ |
| 776 |
|
| 777 |
if (wcsaxesExists) { /* WCSAXES keyword exists */ |
| 778 |
|
| 779 |
if (m < 1 || m > wcsaxesmax) { |
| 780 |
sprintf( errmes, |
| 781 |
"Keyword #%d, %s: 1st index %d is not in range 1-%d (WCSAXES).", |
| 782 |
pkey->kindex,pkey->kname,m,wcsaxesmax); |
| 783 |
wrterr(out,errmes,1); |
| 784 |
} |
| 785 |
|
| 786 |
} else { |
| 787 |
|
| 788 |
if (m < 1 || m > hduptr->naxis) { |
| 789 |
sprintf( errmes, |
| 790 |
"Keyword #%d, %s: 1st index %d is not in range 1-%d (NAXIS).", |
| 791 |
pkey->kindex,pkey->kname,m,hduptr->naxis); |
| 792 |
wrtwrn(out,errmes,0); |
| 793 |
} |
| 794 |
|
| 795 |
} |
| 796 |
|
| 797 |
/* test the second digit */ |
| 798 |
p = p2 + 1; |
| 799 |
m = (int)strtol(p,&p2,10); |
| 800 |
|
| 801 |
if (wcsaxesExists) { /* WCSAXES keyword exists */ |
| 802 |
|
| 803 |
if (m < 1 || m > wcsaxesmax) { |
| 804 |
sprintf( errmes, |
| 805 |
"Keyword #%d, %s: 2nd index %d is not in range 1-%d (WCSAXES).", |
| 806 |
pkey->kindex,pkey->kname,m,wcsaxesmax); |
| 807 |
wrterr(out,errmes,1); |
| 808 |
} |
| 809 |
|
| 810 |
} else { |
| 811 |
|
| 812 |
if (m < 1 || m > hduptr->naxis) { |
| 813 |
sprintf( errmes, |
| 814 |
"Keyword #%d, %s: 2nd index %d is not in range 1-%d (NAXIS).", |
| 815 |
pkey->kindex,pkey->kname,m,hduptr->naxis); |
| 816 |
wrtwrn(out,errmes,0); |
| 817 |
} |
| 818 |
} |
| 819 |
|
| 820 |
ialt = 0; |
| 821 |
if (*p2 == 0) { /* no alternate suffix on the PC or CD name */ |
| 822 |
matrix_exists[i] = pkey->kindex; |
| 823 |
} else if (strlen(p2) == 1) { |
| 824 |
if (p2[0] >= 'A' && p2[0] <= 'Z') |
| 825 |
ialt = (int)p2[0] - 64; |
| 826 |
} |
| 827 |
|
| 828 |
/* store lowest index of any wcs keyword */ |
| 829 |
if (pkey->kindex < wcskeypos[ialt]) { |
| 830 |
wcskeypos[ialt] = pkey->kindex; |
| 831 |
pname[ialt] = pkey->kname; |
| 832 |
} |
| 833 |
} |
| 834 |
} |
| 835 |
|
| 836 |
if (matrix_exists[0] > 0 && matrix_exists[1] > 0 ) { |
| 837 |
sprintf( errmes, |
| 838 |
"Keywords PCi_j (#%d) and CDi_j (#%d) are mutually exclusive.", |
| 839 |
matrix_exists[0],matrix_exists[1]); |
| 840 |
wrterr(out,errmes,1); |
| 841 |
} |
| 842 |
|
| 843 |
if (matrix_exists[0] > 0 && crota2_exists > 0 ) { |
| 844 |
sprintf( errmes, |
| 845 |
"Keywords PCi_j (#%d) and CROTA2 (#%d) are mutually exclusive.", |
| 846 |
matrix_exists[0],crota2_exists); |
| 847 |
wrterr(out,errmes,1); |
| 848 |
} |
| 849 |
|
| 850 |
/* test datatype of reserved indexed string WCS keywords */ |
| 851 |
for (i = 0; i < ncstrkeys; i++) { |
| 852 |
strcpy(temp,cstrkeys[i]); |
| 853 |
ptemp = temp; |
| 854 |
keynum[i] = 0; |
| 855 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 856 |
|
| 857 |
if(k < 0) continue; |
| 858 |
|
| 859 |
for (j = k; j < k+n; j++) { |
| 860 |
pkey = hduptr->kwds[j]; |
| 861 |
|
| 862 |
p = kwds[j]->kname; |
| 863 |
p += strlen(temp); |
| 864 |
if(!isdigit((int)*p)) continue; |
| 865 |
|
| 866 |
if (!check_str(pkey,out) )continue; |
| 867 |
|
| 868 |
parse_wcskey_suffix(pkey->kname,ptemp,&iaxis,&ialt); |
| 869 |
|
| 870 |
if (wcsaxesExists) { /* WCSAXES keyword exists */ |
| 871 |
|
| 872 |
if (iaxis < 1 || iaxis > wcsaxesmax) { |
| 873 |
sprintf( errmes, |
| 874 |
"Keyword #%d, %s: index %d is not in range 1-%d (WCSAXES).", |
| 875 |
pkey->kindex,pkey->kname,iaxis,wcsaxesmax); |
| 876 |
wrterr(out,errmes,1); |
| 877 |
} |
| 878 |
|
| 879 |
} else { |
| 880 |
|
| 881 |
if (iaxis < 1 || iaxis > hduptr->naxis) { |
| 882 |
sprintf( errmes, |
| 883 |
"Keyword #%d, %s: index %d is not in range 1-%d (NAXIS).", |
| 884 |
pkey->kindex,pkey->kname,iaxis,hduptr->naxis); |
| 885 |
wrtwrn(out,errmes,0); |
| 886 |
} |
| 887 |
|
| 888 |
} |
| 889 |
|
| 890 |
if (ialt == 0) { /* only test the primary set of WCS keywords */ |
| 891 |
keynum[i] = keynum[i] + 1; |
| 892 |
} |
| 893 |
|
| 894 |
/* store lowest index of any wcs keyword */ |
| 895 |
if (pkey->kindex < wcskeypos[ialt]) { |
| 896 |
wcskeypos[ialt] = pkey->kindex; |
| 897 |
pname[ialt] = pkey->kname; |
| 898 |
} |
| 899 |
} |
| 900 |
} |
| 901 |
|
| 902 |
if (keynum[0] < nmax) { |
| 903 |
sprintf( errmes, |
| 904 |
"Some CTYPEi keywords appear to be missing; expected %d.",nmax); |
| 905 |
wrtwrn(out,errmes,0); |
| 906 |
} |
| 907 |
|
| 908 |
for (i=0; i<NWCSDESCR; ++i) |
| 909 |
{ |
| 910 |
if (wcskeypos[i] < wcsaxespos[i]) { |
| 911 |
sprintf( errmes, |
| 912 |
"WCSAXES keyword #%d appears after other WCS keyword %s #%d", |
| 913 |
wcsaxespos[i], pname[i], wcskeypos[i]); |
| 914 |
wrterr(out,errmes,1); |
| 915 |
} |
| 916 |
} |
| 917 |
|
| 918 |
/* test datatype and value of reserved RADECSYS WCS keywords */ |
| 919 |
for (i = 0; i < nrastrkeys; i++) { |
| 920 |
strcpy(temp,rastrkeys[i]); |
| 921 |
ptemp = temp; |
| 922 |
keynum[i] = 0; |
| 923 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 924 |
|
| 925 |
if(k < 0) continue; |
| 926 |
|
| 927 |
for (j = k; j < k+n; j++) { |
| 928 |
pkey = hduptr->kwds[j]; |
| 929 |
|
| 930 |
p = kwds[j]->kname; |
| 931 |
p += strlen(temp); |
| 932 |
|
| 933 |
if (!check_str(pkey,out) )continue; |
| 934 |
|
| 935 |
if (strcmp(pkey->kvalue, "ICRS") && strcmp(pkey->kvalue, "FK5") && |
| 936 |
strcmp(pkey->kvalue, "FK4") && strcmp(pkey->kvalue, "FK4-NO-E") && |
| 937 |
strcmp(pkey->kvalue, "GAPPT")) { |
| 938 |
sprintf( errmes, |
| 939 |
"Keyword #%d, %s has non-allowed value: %s", |
| 940 |
pkey->kindex,pkey->kname,pkey->kvalue); |
| 941 |
wrtwrn(out,errmes,0); |
| 942 |
} |
| 943 |
|
| 944 |
} |
| 945 |
} |
| 946 |
|
| 947 |
/* test datatype and value of reserved spectral ref frame WCS keywords */ |
| 948 |
for (i = 0; i < nspecstrkeys; i++) { |
| 949 |
strcpy(temp,specstrkeys[i]); |
| 950 |
ptemp = temp; |
| 951 |
keynum[i] = 0; |
| 952 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 953 |
|
| 954 |
if(k < 0) continue; |
| 955 |
|
| 956 |
for (j = k; j < k+n; j++) { |
| 957 |
pkey = hduptr->kwds[j]; |
| 958 |
|
| 959 |
p = kwds[j]->kname; |
| 960 |
p += strlen(temp); |
| 961 |
|
| 962 |
if (!check_str(pkey,out) )continue; |
| 963 |
|
| 964 |
if (strcmp(pkey->kvalue, "TOPOCENT") && strcmp(pkey->kvalue, "GEOCENTR") && |
| 965 |
strcmp(pkey->kvalue, "BARYCENT") && strcmp(pkey->kvalue, "HELIOCEN") && |
| 966 |
strcmp(pkey->kvalue, "LSRK") && strcmp(pkey->kvalue, "LSRD") && |
| 967 |
strcmp(pkey->kvalue, "GALACTOC") && strcmp(pkey->kvalue, "LOCALGRP") && |
| 968 |
strcmp(pkey->kvalue, "CMBDIPOL") && strcmp(pkey->kvalue, "SOURCE")) { |
| 969 |
sprintf( errmes, |
| 970 |
"Keyword #%d, %s has non-allowed value: %s", |
| 971 |
pkey->kindex,pkey->kname,pkey->kvalue); |
| 972 |
wrtwrn(out,errmes,0); |
| 973 |
} |
| 974 |
|
| 975 |
} |
| 976 |
} |
| 977 |
|
| 978 |
/* test the fill area */ |
| 979 |
if(testfill) { |
| 980 |
if(ffchfl(infits,&status)) { |
| 981 |
wrterr(out, |
| 982 |
"The header fill area is not totally filled with blanks.",1); |
| 983 |
} |
| 984 |
} |
| 985 |
return ; |
| 986 |
} |
| 987 |
|
| 988 |
|
| 989 |
/************************************************************* |
| 990 |
* |
| 991 |
* test_prm |
| 992 |
* |
| 993 |
* Test the primary array header |
| 994 |
* |
| 995 |
* |
| 996 |
*************************************************************/ |
| 997 |
void test_prm(fitsfile *infits, /* input fits file */ |
| 998 |
FILE* out, /* output ascii file */ |
| 999 |
FitsHdu *hduptr /* hdu information structure */ |
| 1000 |
) |
| 1001 |
|
| 1002 |
{ |
| 1003 |
int i,j,k,n; |
| 1004 |
FitsKey *pkey; |
| 1005 |
FitsKey **kwds; |
| 1006 |
int numusrkey; |
| 1007 |
char *p; |
| 1008 |
|
| 1009 |
char *exlkey[] = {"XTENSION", "INHERIT"}; |
| 1010 |
int nexlkey = 1; |
| 1011 |
|
| 1012 |
kwds = hduptr->kwds; |
| 1013 |
numusrkey = hduptr->tkeys; |
| 1014 |
|
| 1015 |
/* The SIMPLE, BITPIX, NAXIS, and NAXISn keywords have been |
| 1016 |
checked in CFITSIO */ |
| 1017 |
|
| 1018 |
/* excluded keywords cannot be used. */ |
| 1019 |
for (i = 0; i < nexlkey; i++) { |
| 1020 |
strcpy(temp,exlkey[i]); |
| 1021 |
ptemp = temp; |
| 1022 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 1023 |
if( n > 0) { |
| 1024 |
pkey = hduptr->kwds[k]; |
| 1025 |
sprintf(errmes, |
| 1026 |
"Keyword #%d, %s is not allowed in a primary array.", |
| 1027 |
pkey->kindex,exlkey[i]); |
| 1028 |
wrterr(out,errmes,1); |
| 1029 |
} |
| 1030 |
} |
| 1031 |
|
| 1032 |
/* Check if Random Groups file */ |
| 1033 |
strcpy(temp,"GROUPS"); |
| 1034 |
ptemp = temp; |
| 1035 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 1036 |
if(k > -1){ |
| 1037 |
pkey = hduptr->kwds[k]; |
| 1038 |
if(*(pkey->kvalue) == 'T' && hduptr->naxis > 0 && hduptr->naxes[0]==0) { |
| 1039 |
hduptr->isgroup = 1; |
| 1040 |
|
| 1041 |
check_fixed_log(cards[pkey->kindex - 1], out); |
| 1042 |
} |
| 1043 |
} |
| 1044 |
|
| 1045 |
/* check the position of the EXTEND */ |
| 1046 |
|
| 1047 |
/* the EXTEND keyword is no longer required if the file contains extensions */ |
| 1048 |
|
| 1049 |
if (hduptr->isgroup == 0) { |
| 1050 |
strcpy(temp,"EXTEND"); |
| 1051 |
ptemp = temp; |
| 1052 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 1053 |
if( k > 0) { |
| 1054 |
pkey = hduptr->kwds[k]; |
| 1055 |
|
| 1056 |
if(check_log(pkey,out) && *(pkey->kvalue)!='T' && totalhdu > 1) { |
| 1057 |
sprintf(errmes,"There are extensions but EXTEND = F."); |
| 1058 |
wrterr(out,errmes,1); |
| 1059 |
} |
| 1060 |
} |
| 1061 |
} |
| 1062 |
|
| 1063 |
/* Check PCOUNT and GCOUNT keyword */ |
| 1064 |
strcpy(temp,"PCOUNT"); |
| 1065 |
ptemp = temp; |
| 1066 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 1067 |
if(k > -1) { |
| 1068 |
pkey = hduptr->kwds[k]; |
| 1069 |
/* Primary array cannot have PCOUNT */ |
| 1070 |
if (!hduptr->isgroup ){ |
| 1071 |
sprintf(errmes, |
| 1072 |
" Keyword #%d, %s is not allowed in a primary array.", |
| 1073 |
pkey->kindex,pkey->kname); |
| 1074 |
wrterr(out,errmes,1); |
| 1075 |
} |
| 1076 |
else { |
| 1077 |
if(check_int(pkey,out)) |
| 1078 |
hduptr->pcount = (LONGLONG) atof(pkey->kvalue); |
| 1079 |
|
| 1080 |
check_fixed_int(cards[pkey->kindex - 1], out); |
| 1081 |
} |
| 1082 |
} |
| 1083 |
|
| 1084 |
strcpy(temp,"GCOUNT"); |
| 1085 |
ptemp = temp; |
| 1086 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 1087 |
if(k > -1) { |
| 1088 |
pkey = hduptr->kwds[k]; |
| 1089 |
/* Primary array cannot have GCOUNT */ |
| 1090 |
if (!hduptr->isgroup ){ |
| 1091 |
sprintf(errmes, |
| 1092 |
" Keyword #%d, %s is not allowed in a primary array.", |
| 1093 |
pkey->kindex,pkey->kname); |
| 1094 |
wrterr(out,errmes,1); |
| 1095 |
} |
| 1096 |
else { |
| 1097 |
if(check_int(pkey,out)) |
| 1098 |
hduptr->gcount = (int) strtol(pkey->kvalue,NULL,10); |
| 1099 |
|
| 1100 |
check_fixed_int(cards[pkey->kindex - 1], out); |
| 1101 |
} |
| 1102 |
} |
| 1103 |
|
| 1104 |
strcpy(temp,"BLOCKED"); |
| 1105 |
ptemp = temp; |
| 1106 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 1107 |
if(k > -1) { |
| 1108 |
pkey = hduptr->kwds[k]; |
| 1109 |
sprintf(errmes, |
| 1110 |
"Keyword #%d, %s is deprecated.", |
| 1111 |
pkey->kindex, pkey->kname); |
| 1112 |
wrtwrn(out,errmes,0); |
| 1113 |
check_log(pkey,out); |
| 1114 |
|
| 1115 |
/* no longer required |
| 1116 |
if(pkey->kindex > 36) { |
| 1117 |
sprintf(errmes, |
| 1118 |
"Keyword #%d, BLOCKED, appears beyond keyword 36.", |
| 1119 |
pkey->kindex); |
| 1120 |
wrterr(out,errmes,1); |
| 1121 |
} |
| 1122 |
*/ |
| 1123 |
|
| 1124 |
} |
| 1125 |
|
| 1126 |
/* Check PSCALn keywords (only in Random Groups) */ |
| 1127 |
strcpy(temp,"PSCAL"); |
| 1128 |
ptemp = temp; |
| 1129 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 1130 |
for (j = k; j< k + n ; j++){ |
| 1131 |
p = kwds[j]->kname; |
| 1132 |
p += 5; |
| 1133 |
if(!isdigit((int)*p)) continue; |
| 1134 |
|
| 1135 |
if (!(hduptr->isgroup)) { |
| 1136 |
sprintf(errmes,"Keyword #%d, %s ", |
| 1137 |
kwds[j]->kindex,kwds[j]->kname); |
| 1138 |
strcat(errmes, |
| 1139 |
"is only allowed in Random Groups structures."); |
| 1140 |
wrterr(out,errmes,1); |
| 1141 |
continue; |
| 1142 |
} |
| 1143 |
|
| 1144 |
if (check_flt(kwds[j],out) && strtod(kwds[j]->kvalue,NULL) == 0.0) { |
| 1145 |
sprintf(errmes,"Keyword #%d, %s: ", |
| 1146 |
kwds[j]->kindex,kwds[j]->kname); |
| 1147 |
strcat(errmes, |
| 1148 |
"The scaling factor is zero."); |
| 1149 |
wrtwrn(out,errmes,0); |
| 1150 |
} |
| 1151 |
|
| 1152 |
i = (int) strtol(p,NULL,10) -1 ; |
| 1153 |
if(i< 0 || i >= hduptr->gcount) { |
| 1154 |
sprintf(errmes, |
| 1155 |
"Keyword #%d, %s: invalid index %d (> GCOUNT = %d).", |
| 1156 |
kwds[j]->kindex,kwds[j]->kname,i+1,hduptr->gcount); |
| 1157 |
wrterr(out,errmes,1); |
| 1158 |
continue; |
| 1159 |
} |
| 1160 |
|
| 1161 |
} |
| 1162 |
|
| 1163 |
/* Check PZEROn keywords (only in Random Groups) */ |
| 1164 |
strcpy(temp,"PZERO"); |
| 1165 |
ptemp = temp; |
| 1166 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 1167 |
for (j = k; j< k + n ; j++){ |
| 1168 |
p = kwds[j]->kname; |
| 1169 |
p += 5; |
| 1170 |
if(!isdigit((int)*p)) continue; |
| 1171 |
|
| 1172 |
if (!(hduptr->isgroup)) { |
| 1173 |
sprintf(errmes,"Keyword #%d, %s ", |
| 1174 |
kwds[j]->kindex,kwds[j]->kname); |
| 1175 |
strcat(errmes, |
| 1176 |
"is only allowed in Random Groups structures."); |
| 1177 |
wrterr(out,errmes,1); |
| 1178 |
continue; |
| 1179 |
} |
| 1180 |
|
| 1181 |
check_flt(kwds[j],out); |
| 1182 |
i = (int) strtol(p,NULL,10) -1 ; |
| 1183 |
if(i< 0 || i >= hduptr->gcount) { |
| 1184 |
sprintf(errmes, |
| 1185 |
"Keyword #%d, %s: invalid index %d (> GCOUNT = %d).", |
| 1186 |
kwds[j]->kindex,kwds[j]->kname,i+1,hduptr->gcount); |
| 1187 |
wrterr(out,errmes,1); |
| 1188 |
continue; |
| 1189 |
} |
| 1190 |
} |
| 1191 |
|
| 1192 |
/* Check PTYPEn keywords (only in Random Groups) */ |
| 1193 |
strcpy(temp,"PTYPE"); |
| 1194 |
ptemp = temp; |
| 1195 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 1196 |
for (j = k; j< k + n ; j++){ |
| 1197 |
p = kwds[j]->kname; |
| 1198 |
p += 5; |
| 1199 |
if(!isdigit((int)*p)) continue; |
| 1200 |
|
| 1201 |
if (!(hduptr->isgroup)) { |
| 1202 |
sprintf(errmes,"Keyword #%d, %s ", |
| 1203 |
kwds[j]->kindex,kwds[j]->kname); |
| 1204 |
strcat(errmes, |
| 1205 |
"is only allowed in Random Groups structures."); |
| 1206 |
wrterr(out,errmes,1); |
| 1207 |
continue; |
| 1208 |
} |
| 1209 |
|
| 1210 |
check_str(kwds[j],out); |
| 1211 |
i = (int) strtol(p,NULL,10) -1 ; |
| 1212 |
if(i< 0 || i >= hduptr->gcount) { |
| 1213 |
sprintf(errmes, |
| 1214 |
"Keyword #%d, %s: invalid index %d (> GCOUNT = %d).", |
| 1215 |
kwds[j]->kindex,kwds[j]->kname,i+1,hduptr->gcount); |
| 1216 |
wrterr(out,errmes,1); |
| 1217 |
continue; |
| 1218 |
} |
| 1219 |
} |
| 1220 |
test_array(infits, out, hduptr); |
| 1221 |
|
| 1222 |
return; |
| 1223 |
} |
| 1224 |
|
| 1225 |
/************************************************************* |
| 1226 |
* |
| 1227 |
* test_ext |
| 1228 |
* |
| 1229 |
* Test the extension header |
| 1230 |
* |
| 1231 |
* |
| 1232 |
*************************************************************/ |
| 1233 |
void test_ext(fitsfile *infits, /* input fits file */ |
| 1234 |
FILE* out, /* output ascii file */ |
| 1235 |
FitsHdu *hduptr /* information about header */ |
| 1236 |
) |
| 1237 |
{ |
| 1238 |
FitsKey *pkey; |
| 1239 |
FitsKey **kwds; |
| 1240 |
int i,j,k,n; |
| 1241 |
int numusrkey; |
| 1242 |
char *exlkey[] = {"SIMPLE","EXTEND", "BLOCKED", }; |
| 1243 |
int nexlkey = 3; |
| 1244 |
char *exlnkey[] = {"PTYPE","PSCAL", "PZERO", "GROUPS", }; |
| 1245 |
int nexlnkey = 4; |
| 1246 |
int hdunum; |
| 1247 |
char *p; |
| 1248 |
|
| 1249 |
numusrkey = hduptr->tkeys; |
| 1250 |
kwds = hduptr->kwds; |
| 1251 |
hdunum = hduptr->hdunum; |
| 1252 |
|
| 1253 |
/* check the duplicate extensions */ |
| 1254 |
for (i = hdunum - 1; i > 0; i--) { |
| 1255 |
if(test_hduname(hdunum,i)) { |
| 1256 |
sprintf(comm, |
| 1257 |
"The HDU %d and %d have identical type/name/version", |
| 1258 |
hdunum,i); |
| 1259 |
wrtwrn(out,comm,0); |
| 1260 |
} |
| 1261 |
} |
| 1262 |
|
| 1263 |
/* check the position of the PCOUNT */ |
| 1264 |
strcpy(temp,"PCOUNT"); |
| 1265 |
ptemp = temp; |
| 1266 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 1267 |
if( k < 0) { |
| 1268 |
sprintf(errmes,"cannot find the PCOUNT keyword."); |
| 1269 |
wrterr(out,errmes,1); |
| 1270 |
} |
| 1271 |
else { |
| 1272 |
pkey = hduptr->kwds[k]; |
| 1273 |
if(check_int(pkey,out)) |
| 1274 |
hduptr->pcount = (LONGLONG) atof(pkey->kvalue); |
| 1275 |
if( pkey->kindex != 4 + hduptr->naxis ) { |
| 1276 |
sprintf(errmes,"PCOUNT is not in record %d of the header.", |
| 1277 |
hduptr->naxis + 4); |
| 1278 |
wrterr(out,errmes,1); |
| 1279 |
} |
| 1280 |
|
| 1281 |
check_fixed_int(cards[pkey->kindex - 1], out); |
| 1282 |
} |
| 1283 |
|
| 1284 |
/* check the position of the GCOUNT */ |
| 1285 |
strcpy(temp,"GCOUNT"); |
| 1286 |
ptemp = temp; |
| 1287 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 1288 |
if( k < 0) { |
| 1289 |
sprintf(errmes,"cannot find the GCOUNT keyword."); |
| 1290 |
wrterr(out,errmes,1); |
| 1291 |
} |
| 1292 |
else { |
| 1293 |
pkey = hduptr->kwds[k]; |
| 1294 |
if(check_int(pkey,out)) |
| 1295 |
hduptr->gcount = (int) strtol(pkey->kvalue,NULL,10); |
| 1296 |
if( pkey->kindex != 5 + hduptr->naxis ) { |
| 1297 |
sprintf(errmes,"GCOUNT is not in record %d of the header.", |
| 1298 |
hduptr->naxis + 5); |
| 1299 |
wrterr(out,errmes,1); |
| 1300 |
} |
| 1301 |
|
| 1302 |
check_fixed_int(cards[pkey->kindex - 1], out); |
| 1303 |
} |
| 1304 |
|
| 1305 |
for (i = 0; i < nexlkey; i++) { |
| 1306 |
strcpy(temp,exlkey[i]); |
| 1307 |
ptemp = temp; |
| 1308 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 1309 |
if(k > -1) { |
| 1310 |
pkey = hduptr->kwds[k]; |
| 1311 |
sprintf( errmes, |
| 1312 |
"Keyword #%d, %s is not allowed in extensions.", |
| 1313 |
pkey->kindex,pkey->kname); |
| 1314 |
wrterr(out,errmes,1); |
| 1315 |
} |
| 1316 |
} |
| 1317 |
|
| 1318 |
for (i = 0; i < nexlnkey; i++) { |
| 1319 |
strcpy(temp,exlnkey[i]); |
| 1320 |
ptemp = temp; |
| 1321 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 1322 |
if(k > -1) { |
| 1323 |
|
| 1324 |
for (j = k; j< k + n ; j++){ |
| 1325 |
p = kwds[j]->kname; |
| 1326 |
p += 5; |
| 1327 |
if(!isdigit((int)*p)) continue; |
| 1328 |
|
| 1329 |
pkey = hduptr->kwds[j]; |
| 1330 |
sprintf( errmes, |
| 1331 |
"Keyword #%d, %s is only allowed in Random Groups structures.", |
| 1332 |
pkey->kindex,pkey->kname); |
| 1333 |
wrterr(out,errmes,1); |
| 1334 |
} |
| 1335 |
} |
| 1336 |
} |
| 1337 |
|
| 1338 |
return; |
| 1339 |
|
| 1340 |
} |
| 1341 |
/************************************************************* |
| 1342 |
* |
| 1343 |
* test_img_ext |
| 1344 |
* |
| 1345 |
* Test the image extension header |
| 1346 |
* |
| 1347 |
* |
| 1348 |
*************************************************************/ |
| 1349 |
void test_img_ext(fitsfile *infits, /* input fits file */ |
| 1350 |
FILE* out, /* output ascii file */ |
| 1351 |
FitsHdu *hduptr /* information about header */ |
| 1352 |
) |
| 1353 |
{ |
| 1354 |
test_ext(infits,out,hduptr); |
| 1355 |
|
| 1356 |
/* The XTENSION, BITPIX, NAXIS, and NAXISn keywords have been |
| 1357 |
checked in CFITSIO */ |
| 1358 |
|
| 1359 |
if(hduptr->pcount != 0 && hduptr->pcount != -99){ |
| 1360 |
sprintf(errmes, |
| 1361 |
"Illegal pcount value %ld for image ext.",(long) hduptr->pcount); |
| 1362 |
wrterr(out,errmes,1); |
| 1363 |
} |
| 1364 |
|
| 1365 |
if(hduptr->gcount !=1 && hduptr->gcount != -99){ |
| 1366 |
sprintf(errmes, |
| 1367 |
"Illegal gcount value %d for image ext.",hduptr->gcount); |
| 1368 |
wrterr(out,errmes,1); |
| 1369 |
} |
| 1370 |
|
| 1371 |
test_array(infits, out, hduptr); |
| 1372 |
|
| 1373 |
return ; |
| 1374 |
} |
| 1375 |
|
| 1376 |
/************************************************************* |
| 1377 |
* |
| 1378 |
* test_array |
| 1379 |
* |
| 1380 |
* Test the keywords which are used by both the primary array |
| 1381 |
* and image Extension. |
| 1382 |
* |
| 1383 |
* |
| 1384 |
*************************************************************/ |
| 1385 |
void test_array(fitsfile *infits, /* input fits file */ |
| 1386 |
FILE* out, /* output ascii file */ |
| 1387 |
FitsHdu *hduptr /* information about header */ |
| 1388 |
) |
| 1389 |
{ |
| 1390 |
int numusrkey; |
| 1391 |
FitsKey **kwds; |
| 1392 |
char *p; |
| 1393 |
int i,j,k,n; |
| 1394 |
FitsKey *pkey; |
| 1395 |
|
| 1396 |
/* excluded non-indexed keywords */ |
| 1397 |
char *exlkeys[] = {"TFIELDS","THEAP"}; |
| 1398 |
int nexlkeys = 2; |
| 1399 |
|
| 1400 |
/* excluded indexed keywords */ |
| 1401 |
char *exlnkeys[] = {"TBCOL", "TFORM", |
| 1402 |
"TSCAL", "TZERO","TNULL", |
| 1403 |
"TTYPE", "TUNIT","TDISP","TDIM", |
| 1404 |
"TCTYP","TCUNI","TCRVL","TCDLT","TCRPX","TCROT"}; |
| 1405 |
int nexlnkeys = 15; |
| 1406 |
|
| 1407 |
/* non-indexed floating keywords (excluding BSCALE) */ |
| 1408 |
char *fltkeys[] = {"BZERO","DATAMAX","DATAMIN"}; |
| 1409 |
int nfltkeys = 3; |
| 1410 |
|
| 1411 |
/* non-indexed string keywords */ |
| 1412 |
char *strkeys[] = {"BUNIT"}; |
| 1413 |
int nstrkeys = 1; |
| 1414 |
|
| 1415 |
numusrkey = hduptr->tkeys; |
| 1416 |
kwds = hduptr->kwds; |
| 1417 |
|
| 1418 |
/* Check BLANK, BSCALE keywords */ |
| 1419 |
strcpy(temp,"BLANK"); |
| 1420 |
ptemp = temp; |
| 1421 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 1422 |
if( k >= 0) { |
| 1423 |
check_int(kwds[k],out); |
| 1424 |
if(hduptr->bitpix < 0) { |
| 1425 |
sprintf(errmes, |
| 1426 |
"Keyword #%d, %s must not be used with floating point data (BITPIX = %d).", |
| 1427 |
kwds[k]->kindex,kwds[k]->kname, hduptr->bitpix); |
| 1428 |
wrterr(out,errmes,2); |
| 1429 |
} |
| 1430 |
} |
| 1431 |
|
| 1432 |
strcpy(temp,"BSCALE"); |
| 1433 |
ptemp = temp; |
| 1434 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 1435 |
if( k >= 0) { |
| 1436 |
if(check_flt(kwds[k],out) && strtod(kwds[k]->kvalue,NULL) == 0.0) { |
| 1437 |
sprintf(errmes,"Keyword #%d, %s: The scaling factor is 0.", |
| 1438 |
kwds[k]->kindex,kwds[k]->kname); |
| 1439 |
wrtwrn(out,errmes,0); |
| 1440 |
} |
| 1441 |
} |
| 1442 |
|
| 1443 |
/* search for excluded, non-indexed keywords */ |
| 1444 |
for (i = 0; i < nexlkeys; i++) { |
| 1445 |
strcpy(temp,exlkeys[i]); |
| 1446 |
ptemp = temp; |
| 1447 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 1448 |
if(k < 0) continue; |
| 1449 |
for (j = k; j < k+n; j++) { |
| 1450 |
pkey = hduptr->kwds[j]; |
| 1451 |
sprintf( errmes, |
| 1452 |
"Keyword #%d, %s is not allowed in the array HDU.", |
| 1453 |
pkey->kindex,pkey->kname); |
| 1454 |
wrterr(out,errmes,1); |
| 1455 |
} |
| 1456 |
} |
| 1457 |
|
| 1458 |
/* search for excluded, indexed keywords */ |
| 1459 |
for (i = 0; i < nexlnkeys; i++) { |
| 1460 |
strcpy(temp,exlnkeys[i]); |
| 1461 |
ptemp = temp; |
| 1462 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 1463 |
if(k < 0) continue; |
| 1464 |
for (j = k; j < k+n; j++) { |
| 1465 |
pkey = hduptr->kwds[j]; |
| 1466 |
|
| 1467 |
p = kwds[j]->kname; |
| 1468 |
p += strlen(temp); |
| 1469 |
if(!isdigit((int)*p)) continue; |
| 1470 |
|
| 1471 |
sprintf( errmes, |
| 1472 |
"Keyword #%d, %s is not allowed in the array HDU.", |
| 1473 |
pkey->kindex,pkey->kname); |
| 1474 |
wrterr(out,errmes,1); |
| 1475 |
} |
| 1476 |
} |
| 1477 |
|
| 1478 |
/* test datatype of reserved non-indexed floating point keywords */ |
| 1479 |
for (i = 0; i < nfltkeys; i++) { |
| 1480 |
strcpy(temp,fltkeys[i]); |
| 1481 |
ptemp = temp; |
| 1482 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 1483 |
if(k < 0) continue; |
| 1484 |
for (j = k; j < k+n; j++) { |
| 1485 |
pkey = hduptr->kwds[j]; |
| 1486 |
if (!check_flt(pkey,out)) continue; |
| 1487 |
} |
| 1488 |
} |
| 1489 |
|
| 1490 |
/* test datatype of reserved non-indexed string keywords */ |
| 1491 |
for (i = 0; i < nstrkeys; i++) { |
| 1492 |
strcpy(temp,strkeys[i]); |
| 1493 |
ptemp = temp; |
| 1494 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 1495 |
if(k < 0) continue; |
| 1496 |
for (j = k; j < k+n; j++) { |
| 1497 |
pkey = hduptr->kwds[j]; |
| 1498 |
check_str(pkey,out); |
| 1499 |
} |
| 1500 |
} |
| 1501 |
|
| 1502 |
return; |
| 1503 |
} |
| 1504 |
|
| 1505 |
/************************************************************* |
| 1506 |
* |
| 1507 |
* test_img_wcs |
| 1508 |
* |
| 1509 |
* Test the image WCS keywords |
| 1510 |
* |
| 1511 |
* |
| 1512 |
*************************************************************/ |
| 1513 |
|
| 1514 |
/* |
| 1515 |
void test_img_wcs(fitsfile *infits, |
| 1516 |
FILE* out, |
| 1517 |
FitsHdu *hduptr |
| 1518 |
) |
| 1519 |
{ |
| 1520 |
|
| 1521 |
int nkeyrec, nreject, nwcs, status = 0; |
| 1522 |
int *stat = 0, ii; |
| 1523 |
char *header; |
| 1524 |
struct wcsprm *wcs; |
| 1525 |
*/ |
| 1526 |
|
| 1527 |
/* NOTE: WCSLIB currently doesn't provide very much diagnostic information |
| 1528 |
about possible problems with the WCS keywords so for now, comment out this |
| 1529 |
routine. |
| 1530 |
*/ |
| 1531 |
|
| 1532 |
/* use WCSLIB to look for inconsistencies in the WCS keywords */ |
| 1533 |
|
| 1534 |
/* Read in the FITS header, excluding COMMENT and HISTORY keyrecords. */ |
| 1535 |
/* |
| 1536 |
if (fits_hdr2str(infits, 1, NULL, 0, &header, &nkeyrec, &status)) { |
| 1537 |
sprintf(errmes, |
| 1538 |
"test_img_ext failed to read header keywords into array %d", status); |
| 1539 |
wrterr(out,errmes,1); |
| 1540 |
return; |
| 1541 |
} |
| 1542 |
*/ |
| 1543 |
/* Interpret the WCS keywords. */ |
| 1544 |
|
| 1545 |
/* |
| 1546 |
if ((status = wcsbth(header, nkeyrec, WCSHDR_all, -2, 0, 0, &nreject, &nwcs, |
| 1547 |
&wcs))) { |
| 1548 |
sprintf(errmes, |
| 1549 |
"test_img_ext: wcsbth ERROR %d: %s.", status, wcshdr_errmsg[status]); |
| 1550 |
wrterr(out,errmes,1); |
| 1551 |
|
| 1552 |
free(header); |
| 1553 |
return; |
| 1554 |
} |
| 1555 |
|
| 1556 |
free(header); |
| 1557 |
|
| 1558 |
if (wcs) { |
| 1559 |
if (nwcs == 1) { |
| 1560 |
sprintf(errmes, |
| 1561 |
" Found 1 World Coordinate System (WCS)."); |
| 1562 |
} else { |
| 1563 |
sprintf(errmes, |
| 1564 |
" Found %d World Coordinate Systems (WCS).", nwcs); |
| 1565 |
} |
| 1566 |
wrtout(out,errmes); |
| 1567 |
} |
| 1568 |
*/ |
| 1569 |
/* Translate non-standard WCS keyvalues and look for inconsistencies */ |
| 1570 |
|
| 1571 |
/* this doesn't provide any useful checks |
| 1572 |
stat = malloc(NWCSFIX * sizeof(int)); |
| 1573 |
|
| 1574 |
if ((status = wcsfix(7, 0, wcs, stat))) { |
| 1575 |
for (ii = 0; ii < NWCSFIX; ii++) { |
| 1576 |
if (stat[ii] > 0) { |
| 1577 |
sprintf(errmes, "wcsfix ERROR %d: %s.", stat[ii], |
| 1578 |
wcsfix_errmsg[stat[ii]]); |
| 1579 |
wrtwrn(out,errmes,0); |
| 1580 |
|
| 1581 |
} |
| 1582 |
} |
| 1583 |
} |
| 1584 |
|
| 1585 |
if ((status = wcsset(wcs))) { |
| 1586 |
sprintf(errmes, |
| 1587 |
"wcsset ERROR %d %s.", status, wcs_errmsg[status]); |
| 1588 |
wrtwrn(out,errmes,0); |
| 1589 |
} |
| 1590 |
*/ |
| 1591 |
|
| 1592 |
/* |
| 1593 |
status = wcsvfree(&nwcs, &wcs); |
| 1594 |
|
| 1595 |
return; |
| 1596 |
} |
| 1597 |
*/ |
| 1598 |
|
| 1599 |
/************************************************************* |
| 1600 |
* |
| 1601 |
* test_tbl |
| 1602 |
* |
| 1603 |
* Test the table extension header and fill the tform, ttype, |
| 1604 |
* tunit. |
| 1605 |
* |
| 1606 |
* |
| 1607 |
*************************************************************/ |
| 1608 |
void test_tbl(fitsfile *infits, /* input fits file */ |
| 1609 |
FILE* out, /* output ascii file */ |
| 1610 |
FitsHdu *hduptr /* information about header */ |
| 1611 |
) |
| 1612 |
|
| 1613 |
{ |
| 1614 |
FitsKey *pkey; |
| 1615 |
FitsKey **kwds; |
| 1616 |
char *p; |
| 1617 |
char *q; |
| 1618 |
int m,n,i,j,k; |
| 1619 |
long w,d,e; |
| 1620 |
long lm; |
| 1621 |
int mcol; |
| 1622 |
|
| 1623 |
/* excluded, non-index keywords (allowed in tile-compressed images) */ |
| 1624 |
char* exlkey[] = {"BSCALE","BZERO", "BUNIT", "BLANK", "DATAMAX", |
| 1625 |
"DATAMIN" }; |
| 1626 |
int nexlkey = 6; |
| 1627 |
|
| 1628 |
/* floating WCS keywords */ |
| 1629 |
char *cfltkeys[] = {"TCRVL","TCDLT","TCRPX","TCROT" }; |
| 1630 |
int ncfltkeys = 4; |
| 1631 |
|
| 1632 |
/* string WCS keywords */ |
| 1633 |
char *cstrkeys[] = {"TCTYP","TCUNI" }; |
| 1634 |
int ncstrkeys = 2 |
| 1635 |
; |
| 1636 |
int numusrkey; |
| 1637 |
|
| 1638 |
numusrkey = hduptr->tkeys; |
| 1639 |
mcol = hduptr->ncols; |
| 1640 |
kwds = hduptr->kwds; |
| 1641 |
|
| 1642 |
if(mcol <= 0) goto OTHERKEY; |
| 1643 |
/* set the ttype, ttform, tunit for tables */ |
| 1644 |
ttype = (char **)calloc(mcol, sizeof(char *)); |
| 1645 |
tform = (char **)calloc(mcol, sizeof(char *)); |
| 1646 |
tunit = (char **)calloc(mcol, sizeof(char *)); |
| 1647 |
for (i=0; i< mcol; i++) { |
| 1648 |
ttype[i] = snull; |
| 1649 |
tform[i] = snull; |
| 1650 |
tunit[i] = snull; |
| 1651 |
} |
| 1652 |
|
| 1653 |
strcpy(temp,"TFIELDS"); |
| 1654 |
ptemp = temp; |
| 1655 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 1656 |
if( k >= 0) { |
| 1657 |
pkey = hduptr->kwds[k]; |
| 1658 |
check_fixed_int(cards[pkey->kindex - 1], out); |
| 1659 |
} |
| 1660 |
|
| 1661 |
strcpy(temp,"TTYPE"); |
| 1662 |
ptemp = temp; |
| 1663 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 1664 |
for (j = k; j< k+n ; j++){ |
| 1665 |
pkey = hduptr->kwds[j]; |
| 1666 |
p = pkey->kname; |
| 1667 |
p += 5; |
| 1668 |
if(!isdigit((int)*p)) continue; |
| 1669 |
|
| 1670 |
check_str(pkey,out); |
| 1671 |
i = (int) strtol(p,NULL,10) -1 ; |
| 1672 |
if(i>= 0 && i < mcol) { |
| 1673 |
ttype[i] = pkey->kvalue; |
| 1674 |
} |
| 1675 |
else { |
| 1676 |
sprintf(errmes, |
| 1677 |
"Keyword #%d, %s: invalid index %d (> TFIELD = %d).", |
| 1678 |
pkey->kindex,pkey->kname,i+1,mcol); |
| 1679 |
wrterr(out,errmes,2); |
| 1680 |
} |
| 1681 |
} |
| 1682 |
|
| 1683 |
strcpy(temp,"TFORM"); |
| 1684 |
ptemp = temp; |
| 1685 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 1686 |
for (j = k; j< k + n ; j++){ |
| 1687 |
pkey = hduptr->kwds[j]; |
| 1688 |
p = pkey->kname; |
| 1689 |
p += 5; |
| 1690 |
if(!isdigit((int)*p)) continue; |
| 1691 |
|
| 1692 |
check_str(pkey,out); |
| 1693 |
|
| 1694 |
/* TFORMn keyword no longer required to be padded to at least 8 characters |
| 1695 |
check_fixed_str(cards[pkey->kindex - 1], out); |
| 1696 |
*/ |
| 1697 |
|
| 1698 |
if(*(pkey->kvalue) == ' ') { |
| 1699 |
sprintf(errmes,"Keyword #%d, %s: TFORM=\"%s\" ", |
| 1700 |
pkey->kindex,pkey->kname, pkey->kvalue); |
| 1701 |
strcat(errmes, |
| 1702 |
"should not have leading space."); |
| 1703 |
wrterr(out,errmes,1); |
| 1704 |
} |
| 1705 |
|
| 1706 |
i = (int) strtol(p,NULL,10) -1 ; |
| 1707 |
if(i>= 0 && i < mcol) { |
| 1708 |
tform[i] = pkey->kvalue; |
| 1709 |
} |
| 1710 |
else { |
| 1711 |
sprintf(errmes, |
| 1712 |
"Keyword #%d, %s: invalid index %d (> TFIELD = %d).", |
| 1713 |
pkey->kindex,pkey->kname,i+1,mcol); |
| 1714 |
wrterr(out,errmes,2); |
| 1715 |
} |
| 1716 |
|
| 1717 |
p = pkey->kvalue; |
| 1718 |
while(*p != ' ' && *p != '\0') { |
| 1719 |
if( !isdigit((int)*p) && !isupper((int)*p) && *p != '.' && *p != ')' |
| 1720 |
&& *p != '(' ) { |
| 1721 |
sprintf(errmes, |
| 1722 |
"Keyword #%d, %s: The value %s has character %c which is not uppercase letter.", |
| 1723 |
pkey->kindex,pkey->kname,pkey->kvalue,*p); |
| 1724 |
wrterr(out,errmes,1); |
| 1725 |
} |
| 1726 |
|
| 1727 |
p++; |
| 1728 |
} |
| 1729 |
} |
| 1730 |
|
| 1731 |
strcpy(temp,"TUNIT"); |
| 1732 |
ptemp = temp; |
| 1733 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 1734 |
for (j = k; j< k + n ; j++){ |
| 1735 |
pkey = hduptr->kwds[j]; |
| 1736 |
p = pkey->kname; |
| 1737 |
p += 5; |
| 1738 |
if(!isdigit((int)*p)) continue; |
| 1739 |
|
| 1740 |
check_str(pkey,out); |
| 1741 |
i = (int) strtol(p,NULL,10) -1 ; |
| 1742 |
if(i>= 0 && i < mcol) { |
| 1743 |
tunit[i] = pkey->kvalue; |
| 1744 |
} |
| 1745 |
else { |
| 1746 |
sprintf(errmes, |
| 1747 |
"Keyword #%d, %s: invalid index %d (> TFIELD = %d).", |
| 1748 |
pkey->kindex,pkey->kname,i+1,mcol); |
| 1749 |
wrterr(out,errmes,1); |
| 1750 |
} |
| 1751 |
} |
| 1752 |
|
| 1753 |
/* Check TDISPn keywords */ |
| 1754 |
strcpy(temp,"TDISP"); |
| 1755 |
ptemp = temp; |
| 1756 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 1757 |
for (j = k; j< k + n ; j++){ |
| 1758 |
p = kwds[j]->kname; |
| 1759 |
p += 5; |
| 1760 |
if(!isdigit((int)*p)) continue; |
| 1761 |
|
| 1762 |
if (*(kwds[j]->kvalue) == '\0') continue; /* ignore blank string */ |
| 1763 |
check_str(kwds[j],out); |
| 1764 |
if(*(kwds[j]->kvalue) == ' ') { |
| 1765 |
sprintf(errmes,"Keyword #%d, %s: TDISP=\"%s\" ", |
| 1766 |
kwds[j]->kindex,kwds[j]->kname,kwds[j]->kvalue); |
| 1767 |
strcat(errmes, |
| 1768 |
"should not have leading space."); |
| 1769 |
wrterr(out,errmes,1); |
| 1770 |
} |
| 1771 |
|
| 1772 |
|
| 1773 |
i = (int) strtol(p,NULL,10) -1 ; |
| 1774 |
if(i< 0 || i >= mcol ) { |
| 1775 |
sprintf(errmes, |
| 1776 |
"Keyword #%d, %s: invalid index %d (> TFIELD = %d).", |
| 1777 |
kwds[j]->kindex,kwds[j]->kname,i+1,mcol); |
| 1778 |
wrterr(out,errmes,1); |
| 1779 |
continue; |
| 1780 |
} |
| 1781 |
p = kwds[j]->kvalue; |
| 1782 |
switch (*p) { |
| 1783 |
case 'A': |
| 1784 |
p++; |
| 1785 |
w = 0; |
| 1786 |
w = strtol(p,NULL,10); |
| 1787 |
if( !w || w == LONG_MAX || w == LONG_MIN) { |
| 1788 |
sprintf(errmes, |
| 1789 |
"Keyword #%d, %s: invalid format \"%s\".", |
| 1790 |
kwds[j]->kindex,kwds[j]->kname, kwds[j]->kvalue); |
| 1791 |
wrterr(out,errmes,1); |
| 1792 |
} |
| 1793 |
if(strchr(tform[i],'A') == NULL ){ |
| 1794 |
sprintf(errmes, |
| 1795 |
"Keyword #%d, %s: Format \"%s\" cannot be used for TFORM \"%s\".", |
| 1796 |
kwds[j]->kindex,kwds[j]->kname, kwds[j]->kvalue, tform[i]); |
| 1797 |
wrterr(out,errmes,1); |
| 1798 |
} |
| 1799 |
break; |
| 1800 |
case 'L': |
| 1801 |
p++; |
| 1802 |
w = 0; |
| 1803 |
w = strtol(p,NULL,10); |
| 1804 |
if(!w || w == LONG_MAX || w == LONG_MIN) { |
| 1805 |
sprintf(errmes, |
| 1806 |
"Keyword #%d, %s: invalid format \"%s\".", |
| 1807 |
kwds[j]->kindex,kwds[j]->kname, kwds[j]->kvalue); |
| 1808 |
wrterr(out,errmes,1); |
| 1809 |
} |
| 1810 |
if(strchr(tform[i],'L') == NULL ){ |
| 1811 |
sprintf(errmes, |
| 1812 |
"Keyword #%d, %s: Format %s cannot be used for TFORM \"%s\".", |
| 1813 |
kwds[j]->kindex,kwds[j]->kname, kwds[j]->kvalue, tform[i]); |
| 1814 |
wrterr(out,errmes,1); |
| 1815 |
} |
| 1816 |
break; |
| 1817 |
case 'I': case 'B': case 'O': case 'Z': |
| 1818 |
p++; |
| 1819 |
w = 0; |
| 1820 |
w = strtol(p,NULL,10); |
| 1821 |
if((q = strchr(p,'.')) != NULL) { |
| 1822 |
p = q; |
| 1823 |
p++; |
| 1824 |
lm = strtol(p,NULL,10); |
| 1825 |
} |
| 1826 |
else { |
| 1827 |
lm = -1; /* no minimum digit field */ |
| 1828 |
} |
| 1829 |
if(!w || w == LONG_MAX || w == LONG_MIN || |
| 1830 |
lm == LONG_MAX || lm == LONG_MIN || w < lm ) { |
| 1831 |
sprintf(errmes, |
| 1832 |
"Keyword #%d, %s: invalid format \"%s\".", |
| 1833 |
kwds[j]->kindex,kwds[j]->kname, kwds[j]->kvalue); |
| 1834 |
wrterr(out,errmes,1); |
| 1835 |
} |
| 1836 |
if(strchr(tform[i],'I') == NULL && |
| 1837 |
strchr(tform[i],'J') == NULL && |
| 1838 |
strchr(tform[i],'K') == NULL && |
| 1839 |
strchr(tform[i],'B') == NULL && |
| 1840 |
strchr(tform[i],'X') == NULL ){ |
| 1841 |
sprintf(errmes, |
| 1842 |
"Keyword #%d, %s: Format \"%s\" cannot be used for TFORM \"%s\".", |
| 1843 |
kwds[j]->kindex,kwds[j]->kname, kwds[j]->kvalue, tform[i]); |
| 1844 |
wrterr(out,errmes,1); |
| 1845 |
} |
| 1846 |
break; |
| 1847 |
case 'F': |
| 1848 |
p++; |
| 1849 |
d = -1; |
| 1850 |
w = 0; |
| 1851 |
w = strtol(p,NULL,10); |
| 1852 |
if((q = strchr(p,'.')) != NULL) { |
| 1853 |
p = q; |
| 1854 |
p++; |
| 1855 |
d = strtol(p,NULL,10); |
| 1856 |
} |
| 1857 |
if(!w || w == LONG_MAX || w == LONG_MIN || |
| 1858 |
d == -1 || d == LONG_MAX || d == LONG_MIN || w < d+1 ) { |
| 1859 |
sprintf(errmes, |
| 1860 |
"Keyword #%d, %s: invalid format \"%s\".", |
| 1861 |
kwds[j]->kindex,kwds[j]->kname, kwds[j]->kvalue); |
| 1862 |
wrterr(out,errmes,1); |
| 1863 |
} |
| 1864 |
if(strchr(tform[i],'E') == NULL && |
| 1865 |
strchr(tform[i],'F') == NULL && |
| 1866 |
strchr(tform[i],'C') == NULL && |
| 1867 |
strchr(tform[i],'D') == NULL && |
| 1868 |
strchr(tform[i],'M') == NULL && |
| 1869 |
strchr(tform[i],'I') == NULL && |
| 1870 |
strchr(tform[i],'J') == NULL && |
| 1871 |
strchr(tform[i],'K') == NULL && |
| 1872 |
strchr(tform[i],'B') == NULL && |
| 1873 |
strchr(tform[i],'X') == NULL ){ |
| 1874 |
sprintf(errmes, |
| 1875 |
"Keyword #%d, %s: Format \"%s\" cannot be used for TFORM \"%s\".", |
| 1876 |
kwds[j]->kindex,kwds[j]->kname, kwds[j]->kvalue, tform[i]); |
| 1877 |
wrterr(out,errmes,1); |
| 1878 |
} |
| 1879 |
break; |
| 1880 |
case 'E': case 'D': |
| 1881 |
p++; |
| 1882 |
w = 0; |
| 1883 |
e = 0; |
| 1884 |
d = 0; |
| 1885 |
if(*p == 'N' || *p == 'S') { p++; e = 2;} |
| 1886 |
w = strtol(p,NULL,10); |
| 1887 |
if((q = strchr(p,'.')) != NULL) { |
| 1888 |
p = q; |
| 1889 |
p++; |
| 1890 |
d = strtol(p,NULL,10); |
| 1891 |
} |
| 1892 |
if((q = strchr(p,'E')) != NULL) { |
| 1893 |
p = q; |
| 1894 |
p++; |
| 1895 |
e = strtol(p,NULL,10); |
| 1896 |
} |
| 1897 |
else { |
| 1898 |
e = 2; |
| 1899 |
} |
| 1900 |
if(!w || w == LONG_MAX || w == LONG_MIN || |
| 1901 |
!d || d == LONG_MAX || d == LONG_MIN || |
| 1902 |
!e || e == LONG_MAX || e == LONG_MIN || |
| 1903 |
w < d+e+3) { |
| 1904 |
sprintf(errmes, |
| 1905 |
"Keyword #%d, %s: invalid format \"%s\".", |
| 1906 |
kwds[j]->kindex,kwds[j]->kname, kwds[j]->kvalue); |
| 1907 |
wrterr(out,errmes,1); |
| 1908 |
} |
| 1909 |
if(strchr(tform[i],'E') == NULL && |
| 1910 |
strchr(tform[i],'F') == NULL && |
| 1911 |
strchr(tform[i],'C') == NULL && |
| 1912 |
strchr(tform[i],'D') == NULL && |
| 1913 |
strchr(tform[i],'M') == NULL && |
| 1914 |
strchr(tform[i],'I') == NULL && |
| 1915 |
strchr(tform[i],'J') == NULL && |
| 1916 |
strchr(tform[i],'K') == NULL && |
| 1917 |
strchr(tform[i],'B') == NULL && |
| 1918 |
strchr(tform[i],'X') == NULL ){ |
| 1919 |
sprintf(errmes, |
| 1920 |
"Keyword #%d, %s: Format \"%s\" cannot be used for TFORM \"%s\".", |
| 1921 |
kwds[j]->kindex,kwds[j]->kname, kwds[j]->kvalue, tform[i]); |
| 1922 |
wrterr(out,errmes,1); |
| 1923 |
} |
| 1924 |
break; |
| 1925 |
case 'G': |
| 1926 |
p++; |
| 1927 |
e = 0; |
| 1928 |
d = 0; |
| 1929 |
w = 0; |
| 1930 |
w = strtol(p,NULL,10); |
| 1931 |
if((q = strchr(p,'.')) != NULL) { |
| 1932 |
p = q; |
| 1933 |
p++; |
| 1934 |
d = strtol(p,NULL,10); |
| 1935 |
} |
| 1936 |
if((q = strchr(p,'E')) != NULL) { |
| 1937 |
p = q; |
| 1938 |
p++; |
| 1939 |
e = strtol(p,NULL,10); |
| 1940 |
} |
| 1941 |
else { |
| 1942 |
e = 2; |
| 1943 |
} |
| 1944 |
if(!w || w == LONG_MAX || w == LONG_MIN || |
| 1945 |
!d || d == LONG_MAX || d == LONG_MIN || |
| 1946 |
!e || e == LONG_MAX || e == LONG_MIN ){ |
| 1947 |
sprintf(errmes, |
| 1948 |
"Keyword #%d, %s: invalid format \"%s\".", |
| 1949 |
kwds[j]->kindex,kwds[j]->kname, kwds[j]->kvalue); |
| 1950 |
wrterr(out,errmes,1); |
| 1951 |
} |
| 1952 |
break; |
| 1953 |
default: |
| 1954 |
sprintf(errmes, |
| 1955 |
"Keyword #%d, %s: invalid format \"%s\".", |
| 1956 |
kwds[j]->kindex,kwds[j]->kname, kwds[j]->kvalue); |
| 1957 |
wrterr(out,errmes,1); |
| 1958 |
break; |
| 1959 |
} |
| 1960 |
} |
| 1961 |
|
| 1962 |
OTHERKEY: |
| 1963 |
if (!(hduptr->istilecompressed) ) { |
| 1964 |
/* tile compressed images can have these keywords */ |
| 1965 |
for (i = 0; i < nexlkey; i++) { |
| 1966 |
strcpy(temp,exlkey[i]); |
| 1967 |
ptemp = temp; |
| 1968 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 1969 |
if(k > -1) { |
| 1970 |
pkey = hduptr->kwds[k]; |
| 1971 |
sprintf( errmes, |
| 1972 |
"Keyword #%d, %s is not allowed in the Bin/ASCII table.", |
| 1973 |
pkey->kindex,pkey->kname); |
| 1974 |
wrterr(out,errmes,1); |
| 1975 |
} |
| 1976 |
} |
| 1977 |
|
| 1978 |
/* search for excluded indexed keywords */ |
| 1979 |
|
| 1980 |
/* these WCS keywords are all allowed (changed July 2010) |
| 1981 |
for (i = 0; i < nexlkeys; i++) { |
| 1982 |
strcpy(temp,exlkeys[i]); |
| 1983 |
ptemp = temp; |
| 1984 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 1985 |
if(k < 0) continue; |
| 1986 |
for (j = k; j < k+n; j++) { |
| 1987 |
pkey = hduptr->kwds[j]; |
| 1988 |
|
| 1989 |
p = kwds[j]->kname; |
| 1990 |
p += strlen(temp); |
| 1991 |
if(!isdigit((int)*p)) continue; |
| 1992 |
|
| 1993 |
sprintf( errmes, |
| 1994 |
"Keyword #%d, %s is not allowed in the Bin/ASCII table.", |
| 1995 |
pkey->kindex,pkey->kname); |
| 1996 |
wrterr(out,errmes,1); |
| 1997 |
} |
| 1998 |
} |
| 1999 |
*/ |
| 2000 |
} |
| 2001 |
|
| 2002 |
/* test datatype of reserved indexed floating point WCS keywords */ |
| 2003 |
for (i = 0; i < ncfltkeys; i++) { |
| 2004 |
strcpy(temp,cfltkeys[i]); |
| 2005 |
ptemp = temp; |
| 2006 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 2007 |
if(k < 0) continue; |
| 2008 |
|
| 2009 |
for (j = k; j < k+n; j++) { |
| 2010 |
pkey = hduptr->kwds[j]; |
| 2011 |
|
| 2012 |
p = kwds[j]->kname; |
| 2013 |
p += strlen(temp); |
| 2014 |
if(!isdigit((int)*p)) continue; |
| 2015 |
|
| 2016 |
if (!check_flt(pkey,out) )continue; |
| 2017 |
|
| 2018 |
m = (int)strtol(p,NULL,10); |
| 2019 |
if (m < 1 || m > mcol) { |
| 2020 |
sprintf( errmes, |
| 2021 |
"Keyword #%d, %s: index %d is not in range 1-%d (TFIELD).", |
| 2022 |
pkey->kindex,pkey->kname,m,mcol); |
| 2023 |
wrterr(out,errmes,1); |
| 2024 |
} |
| 2025 |
} |
| 2026 |
} |
| 2027 |
|
| 2028 |
/* test datatype of reserved indexed string WCS keywords */ |
| 2029 |
for (i = 0; i < ncstrkeys; i++) { |
| 2030 |
strcpy(temp,cstrkeys[i]); |
| 2031 |
ptemp = temp; |
| 2032 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 2033 |
if(k < 0) continue; |
| 2034 |
|
| 2035 |
for (j = k; j < k+n; j++) { |
| 2036 |
pkey = hduptr->kwds[j]; |
| 2037 |
|
| 2038 |
p = kwds[j]->kname; |
| 2039 |
p += strlen(temp); |
| 2040 |
if(!isdigit((int)*p)) continue; |
| 2041 |
|
| 2042 |
if (!check_str(pkey,out) )continue; |
| 2043 |
|
| 2044 |
m = (int)strtol(p,NULL,10); |
| 2045 |
if (m < 1 || m > mcol) { |
| 2046 |
sprintf( errmes, |
| 2047 |
"Keyword #%d, %s: index %d is not in range 1-%d (TFIELD).", |
| 2048 |
pkey->kindex,pkey->kname,m,mcol); |
| 2049 |
wrterr(out,errmes,1); |
| 2050 |
} |
| 2051 |
|
| 2052 |
} |
| 2053 |
} |
| 2054 |
return; |
| 2055 |
} |
| 2056 |
|
| 2057 |
/************************************************************* |
| 2058 |
* |
| 2059 |
* test_asc_ext |
| 2060 |
* |
| 2061 |
* Test the ascii table extension header |
| 2062 |
* |
| 2063 |
* |
| 2064 |
*************************************************************/ |
| 2065 |
void test_asc_ext(fitsfile *infits, /* input fits file */ |
| 2066 |
FILE* out, /* output ascii file */ |
| 2067 |
FitsHdu *hduptr /* information about header */ |
| 2068 |
) |
| 2069 |
{ |
| 2070 |
int numusrkey; |
| 2071 |
FitsKey **kwds; |
| 2072 |
FitsKey *pkey; |
| 2073 |
char *p; |
| 2074 |
int i,j,k; |
| 2075 |
int n; |
| 2076 |
int mcol; |
| 2077 |
|
| 2078 |
numusrkey = hduptr->tkeys; |
| 2079 |
kwds = hduptr->kwds; |
| 2080 |
mcol = hduptr->ncols; |
| 2081 |
|
| 2082 |
/* The XTENSION, BITPIX, NAXIS, NAXISn, TFIELDS, PCOUNT, GCOUNT, TFORMn, |
| 2083 |
TBCOLn, TTYPEn keywords have been checked in CFITSIO */ |
| 2084 |
|
| 2085 |
/* General extension */ |
| 2086 |
test_ext(infits,out,hduptr); |
| 2087 |
|
| 2088 |
/* general table */ |
| 2089 |
test_tbl(infits,out,hduptr); |
| 2090 |
|
| 2091 |
/* Check TBCOLn */ |
| 2092 |
strcpy(temp,"TBCOL"); |
| 2093 |
ptemp = temp; |
| 2094 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 2095 |
for (j = k; j< k + n ; j++){ |
| 2096 |
pkey = hduptr->kwds[j]; |
| 2097 |
p = pkey->kname; |
| 2098 |
p += 5; |
| 2099 |
if(!isdigit((int)*p)) continue; |
| 2100 |
|
| 2101 |
check_int(pkey,out); |
| 2102 |
|
| 2103 |
i = (int) strtol(p,NULL,10) ; |
| 2104 |
if(i< 0 || i > mcol) { |
| 2105 |
sprintf(errmes, |
| 2106 |
"Keyword #%d, %s: invalid index %d (> TFIELD = %d).", |
| 2107 |
pkey->kindex,pkey->kname,i,mcol); |
| 2108 |
wrterr(out,errmes,1); |
| 2109 |
} |
| 2110 |
else { |
| 2111 |
check_fixed_int(cards[pkey->kindex - 1], out); |
| 2112 |
} |
| 2113 |
} |
| 2114 |
|
| 2115 |
/* Check TNULLn, TSCALn, and TZEORn keywords */ |
| 2116 |
strcpy(temp,"TNULL"); |
| 2117 |
ptemp = temp; |
| 2118 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 2119 |
for (j = k; j< k + n ; j++){ |
| 2120 |
p = kwds[j]->kname; |
| 2121 |
p += 5; |
| 2122 |
if(!isdigit((int)*p)) continue; |
| 2123 |
i = (int) strtol(p,NULL,10) -1; |
| 2124 |
if(i< 0 || i >= mcol) { |
| 2125 |
sprintf(errmes, |
| 2126 |
"Keyword #%d, %s: invalid index %d (> TFIELD = %d).", |
| 2127 |
kwds[j]->kindex,kwds[j]->kname,i+1,mcol); |
| 2128 |
wrterr(out,errmes,1); |
| 2129 |
} |
| 2130 |
check_str(kwds[j],out); |
| 2131 |
} |
| 2132 |
|
| 2133 |
strcpy(temp,"TSCAL"); |
| 2134 |
ptemp = temp; |
| 2135 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 2136 |
for (j = k; j< k + n ; j++){ |
| 2137 |
p = kwds[j]->kname; |
| 2138 |
p += 5; |
| 2139 |
if(!isdigit((int)*p)) continue; |
| 2140 |
i = (int) strtol(p,NULL,10) -1 ; |
| 2141 |
if(check_flt(kwds[j],out)){ |
| 2142 |
if(strtod(kwds[j]->kvalue,NULL) == 0.0) { |
| 2143 |
sprintf(errmes,"Keyword #%d, %s: Scaling factor is zero.", |
| 2144 |
kwds[j]->kindex,kwds[j]->kname); |
| 2145 |
wrtwrn(out,errmes,0); |
| 2146 |
} |
| 2147 |
} |
| 2148 |
if(i< 0 || i >= mcol) { |
| 2149 |
sprintf(errmes, |
| 2150 |
"Keyword #%d, %s: invalid index %d (> TFIELD = %d).", |
| 2151 |
kwds[j]->kindex,kwds[j]->kname,i+1,mcol); |
| 2152 |
wrterr(out,errmes,1); |
| 2153 |
continue; |
| 2154 |
} |
| 2155 |
if(strchr(tform[i],'A') != NULL) { |
| 2156 |
sprintf(errmes, |
| 2157 |
"Keyword #%d, %s may not be used for the A-format fields.", |
| 2158 |
kwds[j]->kindex,kwds[j]->kname); |
| 2159 |
wrterr(out,errmes,1); |
| 2160 |
} |
| 2161 |
} |
| 2162 |
|
| 2163 |
strcpy(temp,"TZERO"); |
| 2164 |
ptemp = temp; |
| 2165 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 2166 |
for (j = k; j< k + n ; j++){ |
| 2167 |
p = kwds[j]->kname; |
| 2168 |
p += 5; |
| 2169 |
if(!isdigit((int)*p)) continue; |
| 2170 |
check_flt(kwds[j],out); |
| 2171 |
i = (int) strtol(p,NULL,10) -1 ; |
| 2172 |
if(i< 0 || i >= mcol) { |
| 2173 |
sprintf(errmes, |
| 2174 |
"Keyword #%d, %s: invalid index %d (> TFIELD = %d).", |
| 2175 |
kwds[j]->kindex,kwds[j]->kname,i+1,mcol); |
| 2176 |
wrterr(out,errmes,1); |
| 2177 |
continue; |
| 2178 |
} |
| 2179 |
if(strchr(tform[i],'A') != NULL) { |
| 2180 |
sprintf(errmes, |
| 2181 |
"Keyword #%d, %s may not be used for the A-format fields.", |
| 2182 |
kwds[j]->kindex,kwds[j]->kname); |
| 2183 |
wrterr(out,errmes,1); |
| 2184 |
} |
| 2185 |
} |
| 2186 |
|
| 2187 |
strcpy(temp,"TDIM"); |
| 2188 |
ptemp = temp; |
| 2189 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 2190 |
for (j = k; j< k + n ; j++){ |
| 2191 |
p = kwds[j]->kname; |
| 2192 |
p += 4; |
| 2193 |
if(!isdigit((int)*p)) continue; |
| 2194 |
|
| 2195 |
pkey = hduptr->kwds[j]; |
| 2196 |
sprintf( errmes, |
| 2197 |
"Keyword #%d, %s is not allowed in the ASCII table.", |
| 2198 |
pkey->kindex,pkey->kname); |
| 2199 |
wrterr(out,errmes,1); |
| 2200 |
} |
| 2201 |
|
| 2202 |
strcpy(temp,"THEAP"); |
| 2203 |
ptemp = temp; |
| 2204 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 2205 |
if (k > -1) { |
| 2206 |
pkey = hduptr->kwds[k]; |
| 2207 |
sprintf( errmes, |
| 2208 |
"Keyword #%d, %s is not allowed in the ASCII table.", |
| 2209 |
pkey->kindex,pkey->kname); |
| 2210 |
wrterr(out,errmes,1); |
| 2211 |
} |
| 2212 |
|
| 2213 |
|
| 2214 |
/* check whether the column name is unique */ |
| 2215 |
test_colnam(out, hduptr); |
| 2216 |
return ; |
| 2217 |
} |
| 2218 |
|
| 2219 |
|
| 2220 |
/************************************************************* |
| 2221 |
* |
| 2222 |
* test_bin_ext |
| 2223 |
* |
| 2224 |
* Test the binary table extension header |
| 2225 |
* |
| 2226 |
* |
| 2227 |
*************************************************************/ |
| 2228 |
void test_bin_ext(fitsfile *infits, /* input fits file */ |
| 2229 |
FILE* out, /* output ascii file */ |
| 2230 |
FitsHdu *hduptr /* information about header */ |
| 2231 |
) |
| 2232 |
{ |
| 2233 |
FitsKey *pkey; |
| 2234 |
int i,j,k,n; |
| 2235 |
long l; |
| 2236 |
int status = 0; |
| 2237 |
char *p; |
| 2238 |
|
| 2239 |
int ntdim; |
| 2240 |
long tdim[10]; |
| 2241 |
int repeat, width; |
| 2242 |
FitsKey **kwds; |
| 2243 |
int numusrkey; |
| 2244 |
int mcol, vla, datatype; |
| 2245 |
|
| 2246 |
/* The indexed keywords excluded from ascii table */ |
| 2247 |
char *exlkeys[] = { "TBCOL"}; |
| 2248 |
int nexlkeys = 1; |
| 2249 |
|
| 2250 |
kwds = hduptr->kwds; |
| 2251 |
numusrkey = hduptr->tkeys; |
| 2252 |
mcol = hduptr->ncols; |
| 2253 |
|
| 2254 |
/* General extension */ |
| 2255 |
test_ext(infits,out,hduptr); |
| 2256 |
|
| 2257 |
/* General table */ |
| 2258 |
test_tbl(infits,out,hduptr); |
| 2259 |
|
| 2260 |
/* The XTENSION, BITPIX, NAXIS, NAXISn, TFIELDS, PCOUNT, GCOUNT, TFORMn, |
| 2261 |
TTYPEn keywords have been checked in CFITSIO */ |
| 2262 |
|
| 2263 |
/* Check TNULLn keywords */ |
| 2264 |
strcpy(temp,"TNULL"); |
| 2265 |
ptemp = temp; |
| 2266 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 2267 |
for (j = k; j< k + n ; j++){ |
| 2268 |
p = kwds[j]->kname; |
| 2269 |
p += 5; |
| 2270 |
if(!isdigit((int)*p)) continue; |
| 2271 |
check_int(kwds[j],out); |
| 2272 |
i = (int) strtol(p,NULL,10) -1 ; |
| 2273 |
if(i< 0 || i >= mcol) { |
| 2274 |
sprintf(errmes, |
| 2275 |
"Keyword #%d, %s: invalid index %d (> TFIELD = %d).", |
| 2276 |
kwds[j]->kindex,kwds[j]->kname,i+1,mcol); |
| 2277 |
wrterr(out,errmes,1); |
| 2278 |
continue; |
| 2279 |
} |
| 2280 |
if(strchr(tform[i],'B') == NULL && |
| 2281 |
strchr(tform[i],'I') == NULL && |
| 2282 |
strchr(tform[i],'J') == NULL && |
| 2283 |
strchr(tform[i],'K') == NULL ) { |
| 2284 |
sprintf(errmes, |
| 2285 |
"Keyword #%d, %s is used for the column with format \"%s \".", |
| 2286 |
kwds[j]->kindex,kwds[j]->kname,tform[i]); |
| 2287 |
wrterr(out,errmes,2); |
| 2288 |
} |
| 2289 |
l = strtol(kwds[j]->kvalue,NULL,10); |
| 2290 |
if(strchr(tform[i],'B') != NULL && ( |
| 2291 |
l < 0 || l > 255) ) { |
| 2292 |
sprintf(errmes,"Keyword #%d, %s: The value %ld", |
| 2293 |
kwds[j]->kindex,kwds[j]->kname, l); |
| 2294 |
strcat(errmes, " is not in the range of datatype B."); |
| 2295 |
wrtwrn(out,errmes,0); |
| 2296 |
} |
| 2297 |
l = strtol(kwds[j]->kvalue,NULL,10); |
| 2298 |
if(strchr(tform[i],'I') != NULL && ( |
| 2299 |
l < -32768 || l > 32767) ) { |
| 2300 |
sprintf(errmes,"Keyword #%d, %s: The value %ld", |
| 2301 |
kwds[j]->kindex,kwds[j]->kname, l); |
| 2302 |
strcat(errmes, " is not in the range of datatype I "); |
| 2303 |
wrtwrn(out,errmes,0); |
| 2304 |
} |
| 2305 |
} |
| 2306 |
|
| 2307 |
/* Check TSCALn keywords */ |
| 2308 |
strcpy(temp,"TSCAL"); |
| 2309 |
ptemp = temp; |
| 2310 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 2311 |
for (j = k; j< k + n ; j++){ |
| 2312 |
p = kwds[j]->kname; |
| 2313 |
p += 5; |
| 2314 |
if(!isdigit((int)*p)) continue; |
| 2315 |
if (check_flt(kwds[j],out) && strtod(kwds[j]->kvalue,NULL) == 0.0) { |
| 2316 |
sprintf(errmes,"Keyword #%d, %s:", |
| 2317 |
kwds[j]->kindex,kwds[j]->kname); |
| 2318 |
strcat(errmes, |
| 2319 |
"The scaling factor is zero."); |
| 2320 |
wrtwrn(out,errmes,0); |
| 2321 |
} |
| 2322 |
i = (int) strtol(p,NULL,10) -1 ; |
| 2323 |
if(i< 0 || i >= mcol) { |
| 2324 |
sprintf(errmes, |
| 2325 |
"Keyword #%d, %s: invalid index %d (> TFIELD = %d).", |
| 2326 |
kwds[j]->kindex,kwds[j]->kname,i+1,mcol); |
| 2327 |
wrterr(out,errmes,1); |
| 2328 |
continue; |
| 2329 |
} |
| 2330 |
if(strchr(tform[i],'A') != NULL || |
| 2331 |
strchr(tform[i],'L') != NULL || |
| 2332 |
strchr(tform[i],'X') != NULL ) { |
| 2333 |
sprintf(errmes, |
| 2334 |
"Keyword #%d, %s is used in A, L, or X column. ", |
| 2335 |
kwds[j]->kindex,kwds[j]->kname); |
| 2336 |
wrterr(out,errmes,1); |
| 2337 |
} |
| 2338 |
} |
| 2339 |
|
| 2340 |
/* Check TZEROn keywords */ |
| 2341 |
strcpy(temp,"TZERO"); |
| 2342 |
ptemp = temp; |
| 2343 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 2344 |
for (j = k; j< k + n ; j++){ |
| 2345 |
p = kwds[j]->kname; |
| 2346 |
p += 5; |
| 2347 |
if(!isdigit((int)*p)) continue; |
| 2348 |
check_flt(kwds[j],out); |
| 2349 |
i = (int) strtol(p,NULL,10) -1 ; |
| 2350 |
if(i< 0 || i >= mcol) { |
| 2351 |
sprintf(errmes, |
| 2352 |
"Keyword #%d, %s: invalid index %d (> TFIELD = %d).", |
| 2353 |
kwds[j]->kindex,kwds[j]->kname,i+1,mcol); |
| 2354 |
wrterr(out,errmes,1); |
| 2355 |
continue; |
| 2356 |
} |
| 2357 |
if(strchr(tform[i],'A') != NULL && |
| 2358 |
strchr(tform[i],'L') != NULL && |
| 2359 |
strchr(tform[i],'X') != NULL ) { |
| 2360 |
sprintf(errmes, |
| 2361 |
"Keyword #%d, %s is used in A, L, or X column. ", |
| 2362 |
kwds[j]->kindex,kwds[j]->kname); |
| 2363 |
wrterr(out,errmes,1); |
| 2364 |
} |
| 2365 |
} |
| 2366 |
|
| 2367 |
/* Check THEAP keyword */ |
| 2368 |
hduptr->heap = (hduptr->naxes[0]) * (hduptr->naxes[1]); |
| 2369 |
strcpy(temp,"THEAP"); |
| 2370 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 2371 |
if(k > -1) { |
| 2372 |
if(check_int(kwds[k],out)) |
| 2373 |
hduptr->heap = (int) strtol(hduptr->kwds[k]->kvalue,NULL,10); |
| 2374 |
if(!hduptr->pcount) { |
| 2375 |
sprintf( errmes, |
| 2376 |
"Pcount is zero, but keyword THEAP is present at record #%d). ", |
| 2377 |
kwds[k]->kindex); |
| 2378 |
wrterr(out,errmes,1); |
| 2379 |
} |
| 2380 |
} |
| 2381 |
|
| 2382 |
/* if PCOUNT != 0, test that there is at least 1 variable length array column */ |
| 2383 |
vla = 0; |
| 2384 |
if(hduptr->pcount) { |
| 2385 |
for (i=0; i< mcol; i++){ |
| 2386 |
if(fits_get_coltype(infits, i+1, &datatype, NULL, NULL, &status)){ |
| 2387 |
sprintf(errmes,"Column #%d: ",i); |
| 2388 |
wrtferr(out,errmes, &status,2); |
| 2389 |
} |
| 2390 |
if (datatype < 0) { |
| 2391 |
vla = 1; |
| 2392 |
break; |
| 2393 |
} |
| 2394 |
} |
| 2395 |
|
| 2396 |
if (vla == 0) { |
| 2397 |
sprintf(errmes, |
| 2398 |
"PCOUNT = %ld, but there are no variable-length array columns.", |
| 2399 |
(long) hduptr->pcount); |
| 2400 |
wrtwrn(out,errmes,0); |
| 2401 |
} |
| 2402 |
} |
| 2403 |
|
| 2404 |
|
| 2405 |
/* Check TDIMn keywords */ |
| 2406 |
strcpy(temp,"TDIM"); |
| 2407 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 2408 |
for (j = k; j< k + n ; j++){ |
| 2409 |
pkey = kwds[j]; |
| 2410 |
p = pkey->kname; |
| 2411 |
p += 4; |
| 2412 |
if(!isdigit((int)*p)) continue; |
| 2413 |
check_str(kwds[j],out); |
| 2414 |
if(*(pkey->kvalue) == ' ') { |
| 2415 |
sprintf(errmes,"Keyword #%d, %s: TDIM=\"%s\" ", |
| 2416 |
pkey->kindex,pkey->kname,pkey->kvalue); |
| 2417 |
strcat(errmes, |
| 2418 |
"should not have leading space."); |
| 2419 |
wrterr(out,errmes,1); |
| 2420 |
continue; |
| 2421 |
} |
| 2422 |
i = (int) strtol(p,NULL,10) -1 ; |
| 2423 |
if(i< 0 || i >= mcol) { |
| 2424 |
sprintf(errmes, |
| 2425 |
"Keyword #%d, %s: invalid index %d (> TFIELD = %d).", |
| 2426 |
kwds[j]->kindex,kwds[j]->kname,i+1,mcol); |
| 2427 |
wrterr(out,errmes,1); |
| 2428 |
continue; |
| 2429 |
} |
| 2430 |
if(fits_decode_tdim(infits,pkey->kvalue,i+1,10,&ntdim,tdim, &status)){ |
| 2431 |
sprintf(errmes,"Keyword #%d, %s: ", |
| 2432 |
kwds[j]->kindex,kwds[j]->kname); |
| 2433 |
wrtferr(out,errmes,&status,1); |
| 2434 |
} |
| 2435 |
} |
| 2436 |
|
| 2437 |
/* check the local convension "rAw"*/ |
| 2438 |
for (i = 0; i < hduptr->ncols; i++) { |
| 2439 |
if((p = strchr(tform[i],'A'))==NULL) continue; |
| 2440 |
repeat = (int) strtol(tform[i],NULL,10); |
| 2441 |
p++; |
| 2442 |
if(!isdigit((int)*p))continue; |
| 2443 |
width = (int)strtol(p,NULL,10); |
| 2444 |
if(repeat%width != 0) { |
| 2445 |
sprintf(errmes, |
| 2446 |
"TFORM %s of column %d: repeat %d is not the multiple of the width %d", |
| 2447 |
tform[i], i+1, repeat, width); |
| 2448 |
wrtwrn(out,errmes,0); |
| 2449 |
} |
| 2450 |
} |
| 2451 |
|
| 2452 |
for (i = 0; i < nexlkeys; i++) { |
| 2453 |
strcpy(temp,exlkeys[i]); |
| 2454 |
ptemp = temp; |
| 2455 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 2456 |
if(k < 0) continue; |
| 2457 |
for (j = k; j < k+n; j++) { |
| 2458 |
pkey = hduptr->kwds[j]; |
| 2459 |
|
| 2460 |
p = kwds[j]->kname; |
| 2461 |
p += strlen(temp); |
| 2462 |
if(!isdigit((int)*p)) continue; |
| 2463 |
|
| 2464 |
sprintf( errmes, |
| 2465 |
"Keyword #%d, %s is not allowed in the Binary table.", |
| 2466 |
pkey->kindex,pkey->kname); |
| 2467 |
wrterr(out,errmes,1); |
| 2468 |
} |
| 2469 |
} |
| 2470 |
|
| 2471 |
/* check whether the column name is unique */ |
| 2472 |
test_colnam(out, hduptr); |
| 2473 |
return ; |
| 2474 |
} |
| 2475 |
|
| 2476 |
/************************************************************* |
| 2477 |
* |
| 2478 |
* test_header |
| 2479 |
* |
| 2480 |
* Test the general keywords that can be in any header |
| 2481 |
* |
| 2482 |
* |
| 2483 |
*************************************************************/ |
| 2484 |
void test_header( |
| 2485 |
fitsfile *infits, /* input fits file */ |
| 2486 |
FILE* out, /* output ascii file */ |
| 2487 |
FitsHdu *hduptr /* information about header */ |
| 2488 |
) |
| 2489 |
{ |
| 2490 |
/* common mandatory keywords */ |
| 2491 |
char *mandkey[] = {"SIMPLE", "BITPIX", "NAXIS", |
| 2492 |
"XTENSION", "END"}; /* not including NAXIS */ |
| 2493 |
int nmandkey = 5; |
| 2494 |
|
| 2495 |
|
| 2496 |
/* string keywords */ |
| 2497 |
char *strkey[] = {"EXTNAME", "ORIGIN", "AUTHOR","CREATOR","REFERENC","TELESCOP", |
| 2498 |
"INSTRUME", "OBSERVER", "OBJECT"}; |
| 2499 |
int nstrkey = 9; |
| 2500 |
|
| 2501 |
/* int keywords */ |
| 2502 |
char *intkey[] = {"EXTVER", "EXTLEVEL"}; |
| 2503 |
int nintkey = 2; |
| 2504 |
|
| 2505 |
/* floating keywords */ |
| 2506 |
char *fltkey[] = {"EQUINOX", "MJD-OBS", "MJD-AVG"}; |
| 2507 |
int nfltkey = 3; |
| 2508 |
|
| 2509 |
FitsKey** kwds; /* FitsKey structure array */ |
| 2510 |
int numusrkey; |
| 2511 |
|
| 2512 |
int i,j,k,n,ii,jj; |
| 2513 |
long lv; |
| 2514 |
unsigned long stat = 0; |
| 2515 |
char* pt; |
| 2516 |
char* p1; |
| 2517 |
char* p2; |
| 2518 |
char **pp; |
| 2519 |
char* equals; |
| 2520 |
char vtemp[72]; |
| 2521 |
int status = 0; |
| 2522 |
int yr, mn, dy, hr, min; /* time */ |
| 2523 |
double sec; |
| 2524 |
int yy; |
| 2525 |
|
| 2526 |
kwdtyp ktype; |
| 2527 |
|
| 2528 |
kwds = hduptr->kwds; |
| 2529 |
numusrkey = hduptr->tkeys; |
| 2530 |
|
| 2531 |
/* Check the mandatory keywords */ |
| 2532 |
for (i = 0; i < nmandkey; i++) { |
| 2533 |
pp = &(mandkey[i]); |
| 2534 |
key_match(tmpkwds,numusrkey,pp,1,&k,&n); |
| 2535 |
if(k > -1) { |
| 2536 |
for ( j = k; j < k + n; j++) { |
| 2537 |
sprintf(errmes, |
| 2538 |
"Keyword #%d, %s is duplicated or out of order.", |
| 2539 |
kwds[j]->kindex,kwds[j]->kname); |
| 2540 |
wrterr(out,errmes,1); |
| 2541 |
} |
| 2542 |
} |
| 2543 |
} |
| 2544 |
|
| 2545 |
/* check the NAXIS index keyword */ |
| 2546 |
strcpy(temp,"NAXIS"); |
| 2547 |
ptemp = temp; |
| 2548 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 2549 |
for ( j = k; j < k + n; j++) { |
| 2550 |
pt = kwds[j]->kname+5; |
| 2551 |
lv = strtol(pt,NULL,10); |
| 2552 |
if(lv > 0 ){ |
| 2553 |
if(kwds[j]->kindex != 3 + lv) { |
| 2554 |
sprintf(errmes, |
| 2555 |
"Keyword #%d, %s is duplicated or out of order.", |
| 2556 |
kwds[j]->kindex,kwds[j]->kname); |
| 2557 |
wrterr(out,errmes,1); |
| 2558 |
} |
| 2559 |
if(lv > hduptr->naxis) { |
| 2560 |
sprintf(errmes, |
| 2561 |
"Keyword #%d, %s is not allowed (with n > NAXIS =%d).", |
| 2562 |
kwds[j]->kindex,kwds[j]->kname,hduptr->naxis); |
| 2563 |
wrterr(out,errmes,1); |
| 2564 |
} |
| 2565 |
} |
| 2566 |
} |
| 2567 |
|
| 2568 |
/* Check the deprecated keywords */ |
| 2569 |
strcpy(temp,"EPOCH"); |
| 2570 |
ptemp = temp; |
| 2571 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 2572 |
if(k > -1) { |
| 2573 |
sprintf(errmes, |
| 2574 |
"Keyword #%d, %s is deprecated. Use EQUINOX instead.", |
| 2575 |
kwds[k]->kindex, kwds[k]->kname); |
| 2576 |
wrtwrn(out,errmes,0); |
| 2577 |
check_flt(kwds[k],out); |
| 2578 |
} |
| 2579 |
|
| 2580 |
|
| 2581 |
/* Check the DATExxxx keyword */ |
| 2582 |
strcpy(temp,"DATE"); |
| 2583 |
ptemp = temp; |
| 2584 |
key_match(tmpkwds,numusrkey,&ptemp,0,&k,&n); |
| 2585 |
for (j = k; j< n + k ; j++){ |
| 2586 |
check_str(kwds[j],out); |
| 2587 |
if(fits_str2time(kwds[j]->kvalue, &yr, &mn, &dy, &hr, &min, |
| 2588 |
&sec, &status)){ |
| 2589 |
sprintf(errmes,"Keyword #%d, %s: ", kwds[j]->kindex,kwds[j]->kname); |
| 2590 |
wrtserr(out,errmes,&status,1); |
| 2591 |
} |
| 2592 |
if( (pt = strchr(kwds[j]->kvalue,'/'))!=NULL) { |
| 2593 |
pt +=4; |
| 2594 |
yy = (int) strtol(pt,NULL,10); |
| 2595 |
if(0 <= yy && yy <=10) { |
| 2596 |
sprintf(errmes, |
| 2597 |
"Keyword #%d, %s %s intends to mean year 20%-2.2d?", |
| 2598 |
kwds[j]->kindex, kwds[j]->kname, kwds[j]->kvalue, yy); |
| 2599 |
wrtwrn(out,errmes,0); |
| 2600 |
} |
| 2601 |
} |
| 2602 |
} |
| 2603 |
|
| 2604 |
/* Check the reserved string keywords */ |
| 2605 |
for (i = 0; i < nstrkey; i++) { |
| 2606 |
strcpy(temp,strkey[i]); |
| 2607 |
ptemp = temp; |
| 2608 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 2609 |
if(k > -1) check_str(kwds[k],out); |
| 2610 |
} |
| 2611 |
|
| 2612 |
/* Check the reserved int keywords */ |
| 2613 |
for (i = 0; i < nintkey; i++) { |
| 2614 |
strcpy(temp,intkey[i]); |
| 2615 |
ptemp = temp; |
| 2616 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 2617 |
if(k > -1) check_int(kwds[k],out); |
| 2618 |
} |
| 2619 |
|
| 2620 |
/* Check reserved floating keywords */ |
| 2621 |
for (i = 0; i < nfltkey; i++) { |
| 2622 |
strcpy(temp,fltkey[i]); |
| 2623 |
ptemp = temp; |
| 2624 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 2625 |
if(k > -1) check_flt(kwds[k],out); |
| 2626 |
} |
| 2627 |
|
| 2628 |
/* Check the duplication of the keywords */ |
| 2629 |
for (i = 0; i < numusrkey-1; i++) { |
| 2630 |
if(!strcmp(tmpkwds[i],tmpkwds[i+1])) { |
| 2631 |
if (strcmp(kwds[i]->kname,"HIERARCH")) { |
| 2632 |
sprintf(errmes, |
| 2633 |
"Keyword %s is duplicated in card #%d and card #%d.", |
| 2634 |
kwds[i]->kname, kwds[i]->kindex, kwds[i+1]->kindex); |
| 2635 |
wrtwrn(out,errmes,0); |
| 2636 |
} |
| 2637 |
} |
| 2638 |
} |
| 2639 |
|
| 2640 |
/* check the long string convention */ |
| 2641 |
if (hduptr->use_longstr == 1) { |
| 2642 |
strcpy(temp,"LONGSTRN"); |
| 2643 |
ptemp = temp; |
| 2644 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 2645 |
if(k <= -1) { |
| 2646 |
sprintf(errmes, |
| 2647 |
"The OGIP long string keyword convention is used without the recommended LONGSTRN keyword. "); |
| 2648 |
wrtwrn(out,errmes,1); |
| 2649 |
} |
| 2650 |
} |
| 2651 |
|
| 2652 |
/* Check the HIERARCH keywords */ |
| 2653 |
if (testhierarch) { |
| 2654 |
strcpy(temp,"HIERARCH"); |
| 2655 |
ptemp = temp; |
| 2656 |
key_match(tmpkwds,numusrkey,&ptemp,1,&k,&n); |
| 2657 |
for (j = k; j< n + k ; j++){ |
| 2658 |
|
| 2659 |
i = (kwds[j]->kindex)-1; /* index number of the keyword */ |
| 2660 |
|
| 2661 |
/* Must have a space character following "HIERARCH" */ |
| 2662 |
if (*(cards[i] + 8) != ' ') { |
| 2663 |
sprintf(errmes, |
| 2664 |
"Keyword #%d: does not have a space character in byte 9: %66s", |
| 2665 |
i+1,cards[i]); |
| 2666 |
wrterr(out,errmes,1); |
| 2667 |
} |
| 2668 |
|
| 2669 |
/* Whether the characters in HIERARCH token names are valid */ |
| 2670 |
pt = cards[i]; |
| 2671 |
while(*pt != '\0' ){ |
| 2672 |
|
| 2673 |
ii = 0; |
| 2674 |
if (*pt == '=' ) /* look for the required "=" sign */ |
| 2675 |
break; |
| 2676 |
|
| 2677 |
if((*pt < 'A' || *pt > 'Z')&& |
| 2678 |
(*pt < '0' || *pt > '9')&& |
| 2679 |
(*pt != '-' && *pt != '_' && *pt != ' ') ) { |
| 2680 |
|
| 2681 |
sprintf(errmes, |
| 2682 |
"Keyword #%d: token contains illegal char \"%c\" (only A-Z,0-9,-,_): %66s", |
| 2683 |
i+1,*pt,cards[i]); |
| 2684 |
wrterr(out,errmes,1); |
| 2685 |
break; |
| 2686 |
} |
| 2687 |
|
| 2688 |
pt++; ii++; |
| 2689 |
} |
| 2690 |
|
| 2691 |
if (*pt == '\0') { /* the "=" is not present on the card */ |
| 2692 |
sprintf(errmes, |
| 2693 |
"Keyword #%d: does not contain the \"=\" value indicator char: %66s", |
| 2694 |
i+1, cards[i]); |
| 2695 |
wrterr(out,errmes,1); |
| 2696 |
} else if (*pt == '=') { |
| 2697 |
|
| 2698 |
/* now check that the keyword has a legal value */ |
| 2699 |
pt++; |
| 2700 |
while (isspace((int)*pt) && *pt != '\0') pt++; |
| 2701 |
switch (*pt) { |
| 2702 |
case '\'': /* string */ |
| 2703 |
get_str(&pt, vtemp,&stat); |
| 2704 |
break; |
| 2705 |
case 'T': case 'F': /*logical */ |
| 2706 |
get_log(&pt, vtemp, &stat); |
| 2707 |
break; |
| 2708 |
case '+': case '-': case '.': /* number */ |
| 2709 |
case '0': case '1': case '2': |
| 2710 |
case '3': case '4': case '5': |
| 2711 |
case '6': case '7': case '8': |
| 2712 |
case '9': |
| 2713 |
get_num(&pt, vtemp, &ktype, &stat); |
| 2714 |
break; |
| 2715 |
case '(': /* complex number */ |
| 2716 |
get_cmp(&pt, vtemp, &ktype, &stat); |
| 2717 |
break; |
| 2718 |
case '/': /* comment */ |
| 2719 |
break; |
| 2720 |
default: |
| 2721 |
get_unknown(&pt,vtemp,&ktype,&stat); |
| 2722 |
|
| 2723 |
} |
| 2724 |
|
| 2725 |
pr_kval_err(out,i+1,"HIERARCH",vtemp,stat); |
| 2726 |
stat = 0; /* reset error status for next time */ |
| 2727 |
|
| 2728 |
} /* end of keyword value test */ |
| 2729 |
} /* end of test of individual HIERARCH keywords */ |
| 2730 |
|
| 2731 |
/* now test for any duplicate HIERARCH keywords */ |
| 2732 |
for (j = k; j< n + k -1 ; j++) { /* loop over all the HIERARCH keywords except the last */ |
| 2733 |
|
| 2734 |
i = (kwds[j]->kindex)-1; /* index number of the keyword */ |
| 2735 |
equals = strchr(cards[i], '='); |
| 2736 |
if (equals) { |
| 2737 |
|
| 2738 |
for (jj = j+1; jj< n + k ; jj++) { /* loop over any other HIERARCH keywords */ |
| 2739 |
ii = (kwds[jj]->kindex)-1; /* index number of the keyword */ |
| 2740 |
equals = strchr(cards[i], '='); |
| 2741 |
if (equals) { |
| 2742 |
|
| 2743 |
/* compare names char by char, ignoring extra spaces */ |
| 2744 |
p1 = cards[i] + 8; /*start at the end of the HIERARCH name */ |
| 2745 |
p2 = cards[ii] + 8; |
| 2746 |
|
| 2747 |
while (*p1 == *p2) { /* chars are the same in both */ |
| 2748 |
if (*p1 == ' ') { /* this is a space char */ |
| 2749 |
|
| 2750 |
/* skip over non-significant spaces in both name, then continue testing next chars */ |
| 2751 |
while (*p1 == ' ') p1++; |
| 2752 |
while (*p2 == ' ') p2++; |
| 2753 |
} else if (*p1 == '=' ) { /* found '=' in both keywords */ |
| 2754 |
sprintf(errmes, |
| 2755 |
"HIERARCH keyword name is duplicated in cards #%d and card #%d: %66s", |
| 2756 |
i+1, ii+1, cards[i]); |
| 2757 |
wrtwrn(out,errmes,0); |
| 2758 |
p1++; /* do this to prevent duplicate warning message, below */ |
| 2759 |
break; |
| 2760 |
} else { |
| 2761 |
p1++; |
| 2762 |
p2++; |
| 2763 |
} |
| 2764 |
} /* end of identical chars test */ |
| 2765 |
|
| 2766 |
/* chars are not identical */ |
| 2767 |
/* test for special case where one is a '=' and other non-significant spaces followed by '=' */ |
| 2768 |
/* first, skip over spaces in either name */ |
| 2769 |
while (*p1 == ' ') p1++; |
| 2770 |
while (*p2 == ' ') p2++; |
| 2771 |
|
| 2772 |
if (*p1 == '=' && *p2 == '=') { |
| 2773 |
/* if we got here, then the names are the same except for non-significant spacing differences */ |
| 2774 |
sprintf(errmes, |
| 2775 |
"HIERARCH keyword name is duplicated in cards #%d and card #%d: %66s", |
| 2776 |
i+1, ii+1, cards[i]); |
| 2777 |
wrtwrn(out,errmes,0); |
| 2778 |
break; |
| 2779 |
} else { |
| 2780 |
/* these HIERARCH keywords do not have idential tokens */ |
| 2781 |
break; |
| 2782 |
} |
| 2783 |
} /* end of if second HIERARCH keyword has a '=' */ |
| 2784 |
} /* end of loop over other HIERARCH keywords */ |
| 2785 |
} /* end of if first HIERARCH keyword has a '=' */ |
| 2786 |
} /* end of loop over all HIERARCH keywords */ |
| 2787 |
} |
| 2788 |
|
| 2789 |
/* disabled this routine because it doesn't perform an useful tests |
| 2790 |
test_img_wcs(infits, out, hduptr); |
| 2791 |
*/ |
| 2792 |
return; |
| 2793 |
} |
| 2794 |
|
| 2795 |
|
| 2796 |
/************************************************************* |
| 2797 |
* |
| 2798 |
* key_match |
| 2799 |
* |
| 2800 |
* find the keywords whose name match the pattern. The keywords |
| 2801 |
* name is stored in a sorted array. |
| 2802 |
* |
| 2803 |
* |
| 2804 |
*************************************************************/ |
| 2805 |
void key_match(char **strs, /* fits keyname array */ |
| 2806 |
int nstr, /* total number of keys */ |
| 2807 |
char **pattern, /* wanted pattern */ |
| 2808 |
int exact, /* exact matching or pattern matching |
| 2809 |
exact = 1: exact matching. |
| 2810 |
exact = 0: pattern matching. |
| 2811 |
Any keywords with "patten"* is included |
| 2812 |
*/ |
| 2813 |
|
| 2814 |
int *ikey, /* The element number of first key |
| 2815 |
Return -99 if not found */ |
| 2816 |
int *mkey /* total number of key matched |
| 2817 |
return -999 if not found */ |
| 2818 |
) |
| 2819 |
{ |
| 2820 |
char **p; |
| 2821 |
char **pi; |
| 2822 |
int i; |
| 2823 |
int (*fnpt)(const void *, const void *); |
| 2824 |
*mkey = -999; |
| 2825 |
*ikey = -99; |
| 2826 |
if(exact) |
| 2827 |
fnpt = compstre; |
| 2828 |
else |
| 2829 |
fnpt = compstrp; |
| 2830 |
p = (char **)bsearch(pattern, strs, nstr,sizeof(char *), fnpt); |
| 2831 |
if(p) { |
| 2832 |
*mkey = 1; |
| 2833 |
*ikey = p - strs; |
| 2834 |
pi = p; |
| 2835 |
i = *ikey - 1; |
| 2836 |
p--; |
| 2837 |
while(i > 0 && !fnpt(pattern, p)) {*mkey += 1; *ikey =i; i--; p--;} |
| 2838 |
p = pi; |
| 2839 |
i = *ikey + *mkey; |
| 2840 |
p++; |
| 2841 |
while(i < nstr && !fnpt(pattern, p) ) {*mkey += 1; i++; p++;} |
| 2842 |
} |
| 2843 |
return; |
| 2844 |
} |
| 2845 |
|
| 2846 |
|
| 2847 |
/************************************************************* |
| 2848 |
* |
| 2849 |
* test_colnam |
| 2850 |
* |
| 2851 |
* Test the whether the column name is unique. |
| 2852 |
* |
| 2853 |
* |
| 2854 |
*************************************************************/ |
| 2855 |
void test_colnam(FILE *out, |
| 2856 |
FitsHdu *hduptr) |
| 2857 |
{ |
| 2858 |
int i,n; |
| 2859 |
char *p, *q; |
| 2860 |
ColName **cols; |
| 2861 |
char **ttypecopy; |
| 2862 |
|
| 2863 |
n = hduptr->ncols; |
| 2864 |
|
| 2865 |
if(n <= 0) return; |
| 2866 |
/* make a local working copy of ttype */ |
| 2867 |
ttypecopy = (char **)malloc(n*sizeof(char *)); |
| 2868 |
for (i = 0; i < n; i++) { |
| 2869 |
ttypecopy[i] = (char *)malloc(FLEN_VALUE*sizeof(char)); |
| 2870 |
strcpy(ttypecopy[i],ttype[i]); |
| 2871 |
} |
| 2872 |
|
| 2873 |
/* check whether there are any other non ASCII-text characters |
| 2874 |
(FITS standard R14). Also "uppercase" the working copies. */ |
| 2875 |
for (i = 0; i < n; i++) { |
| 2876 |
p = ttype[i]; |
| 2877 |
q = ttypecopy[i]; |
| 2878 |
if(!strlen(p)) { |
| 2879 |
sprintf(errmes, |
| 2880 |
"Column #%d has no name (No TTYPE%d keyword).",i+1, i+1); |
| 2881 |
wrtwrn(out,errmes,0); |
| 2882 |
continue; |
| 2883 |
} |
| 2884 |
|
| 2885 |
|
| 2886 |
/* disable this check (it was only a warning) |
| 2887 |
if( (*p > 'z' || *p < 'a') && (*p > 'Z' || *p <'A') |
| 2888 |
&& (*p > '9' || *p < '0') ) { |
| 2889 |
sprintf(errmes,"Column #%d: Name \"%s\" does not begin with a letter or a digit.",i+1,ttype[i]); |
| 2890 |
wrtwrn(out,errmes,1); |
| 2891 |
} |
| 2892 |
*/ |
| 2893 |
while(*p != '\0') { |
| 2894 |
if ((*p > 'z' || *p < 'a') && (*p > 'Z' || *p < 'A') |
| 2895 |
&& (*p > '9' || *p < '0') && (*p != '_')) { |
| 2896 |
if (*p == '&') { |
| 2897 |
sprintf(errmes, |
| 2898 |
"Column #%d: Reserved column name keyword (TTYPE%d) may use an illegal CONTINUE (\'%c\')", |
| 2899 |
i+1,i+1,*p); |
| 2900 |
wrtwrn(out,errmes,0); |
| 2901 |
} else { |
| 2902 |
sprintf(errmes, |
| 2903 |
"Column #%d: Name \"%s\" contains character \'%c\' other than letters, digits, and \"_\".", |
| 2904 |
i+1,ttype[i],*p); |
| 2905 |
wrtwrn(out,errmes,0); |
| 2906 |
} |
| 2907 |
} |
| 2908 |
if(*p <= 'z' || *p >= 'a') *q = toupper(*p); |
| 2909 |
p++; q++; |
| 2910 |
} |
| 2911 |
} |
| 2912 |
|
| 2913 |
cols = (ColName **)calloc(n, sizeof(ColName *)); |
| 2914 |
for (i=0; i < n; i++) { |
| 2915 |
cols[i] = (ColName *)malloc(sizeof(ColName)); |
| 2916 |
cols[i]->name = ttypecopy[i]; |
| 2917 |
cols[i]->index = i+1; |
| 2918 |
} |
| 2919 |
|
| 2920 |
/* sort the column name in the ascending order of name field*/ |
| 2921 |
qsort(cols, n, sizeof(ColName *), compcol); |
| 2922 |
|
| 2923 |
/* Check the duplication of the column name */ |
| 2924 |
for (i = 0; i < n-1; i++) { |
| 2925 |
if(!strlen(cols[i]->name)) continue; |
| 2926 |
|
| 2927 |
/* disable this warning |
| 2928 |
if(!strncmp(cols[i]->name,cols[i+1]->name,16)) { |
| 2929 |
sprintf(errmes, |
| 2930 |
"Columns #%d, %s and #%d, %s are not unique within first 16 characters(case insensitive).", |
| 2931 |
cols[i]->index, ttype[(cols[i]->index-1)], |
| 2932 |
cols[i+1]->index, ttype[(cols[i+1]->index-1)]); |
| 2933 |
wrtwrn(out,errmes,1); |
| 2934 |
} |
| 2935 |
*/ |
| 2936 |
|
| 2937 |
if(!strcmp(cols[i]->name,cols[i+1]->name)) { |
| 2938 |
sprintf(errmes, |
| 2939 |
"Columns #%d, %s and #%d, %s are not unique (case insensitive).", |
| 2940 |
cols[i]->index, ttype[(cols[i]->index-1)], |
| 2941 |
cols[i+1]->index, ttype[(cols[i+1]->index-1)]); |
| 2942 |
wrtwrn(out,errmes,0); |
| 2943 |
} |
| 2944 |
} |
| 2945 |
for (i = 0; i < n; i++) { free(cols[i]); free(ttypecopy[i]);} |
| 2946 |
free(cols); free(ttypecopy); |
| 2947 |
return; |
| 2948 |
} |
| 2949 |
|
| 2950 |
/************************************************************* |
| 2951 |
* |
| 2952 |
* parse_vtform |
| 2953 |
* |
| 2954 |
* Parse the tform of the variable length vector. |
| 2955 |
* |
| 2956 |
* |
| 2957 |
*************************************************************/ |
| 2958 |
void parse_vtform(fitsfile *infits, |
| 2959 |
FILE *out, |
| 2960 |
FitsHdu *hduptr, |
| 2961 |
int colnum, /* column number */ |
| 2962 |
int* datacode, /* data code */ |
| 2963 |
long* maxlen, /* maximum length of the vector */ |
| 2964 |
int* isQFormat /* true if var col is 'Q' format */ |
| 2965 |
) |
| 2966 |
{ |
| 2967 |
int i = 0; |
| 2968 |
int status = 0; |
| 2969 |
char *p; |
| 2970 |
|
| 2971 |
|
| 2972 |
*maxlen = -1; |
| 2973 |
strcpy(temp,tform[colnum-1]); |
| 2974 |
p = temp; |
| 2975 |
|
| 2976 |
if(isdigit((int)*p)) sscanf(ptemp,"%d",&i); |
| 2977 |
if(i > 1) { |
| 2978 |
sprintf(errmes,"Illegal repeat value for value %s of TFORM%d.", |
| 2979 |
tform[colnum-1], colnum); |
| 2980 |
wrterr(out,errmes,1); |
| 2981 |
} |
| 2982 |
while(isdigit((int)*p))p++; |
| 2983 |
|
| 2984 |
if( (*p != 'P') && (*p != 'Q') ) { |
| 2985 |
sprintf(errmes, |
| 2986 |
"TFORM%d is not for the variable length array: %s.", |
| 2987 |
colnum, tform[colnum-1]); |
| 2988 |
wrterr(out,errmes,1); |
| 2989 |
} |
| 2990 |
*isQFormat = (*p == 'Q') ? 1 : 0; |
| 2991 |
|
| 2992 |
fits_get_coltype(infits,colnum, datacode, NULL, NULL, &status); |
| 2993 |
status = 0; |
| 2994 |
p += 2; |
| 2995 |
if(*p != '(') return; |
| 2996 |
p++; |
| 2997 |
if(!isdigit((int)*p)) { |
| 2998 |
sprintf(errmes, "Bad value of TFORM%d: %s.",colnum,tform[colnum-1]); |
| 2999 |
wrterr(out,errmes,1); |
| 3000 |
} |
| 3001 |
sscanf(p,"%ld",maxlen); |
| 3002 |
while(isdigit((int)*p))p++; |
| 3003 |
if(*p != ')') { |
| 3004 |
sprintf(errmes, "Bad value of TFORM%d: %s.",colnum,tform[colnum-1]); |
| 3005 |
wrterr(out,errmes,1); |
| 3006 |
} |
| 3007 |
return; |
| 3008 |
} |
| 3009 |
|
| 3010 |
/************************************************************* |
| 3011 |
* |
| 3012 |
* parse_wcskey_suffix |
| 3013 |
* |
| 3014 |
* Retrieve the axis number and alternative coordinate suffix |
| 3015 |
* from WCS keywords. Return -1 if keyword does not match the |
| 3016 |
* expected format. |
| 3017 |
* |
| 3018 |
*************************************************************/ |
| 3019 |
int parse_wcskey_suffix(char *fullname, char* rootname, int* axis, int* alt) |
| 3020 |
{ |
| 3021 |
int status=0, testAxis=0; |
| 3022 |
char *suffix=0, *testAlt=0; |
| 3023 |
|
| 3024 |
*axis=0; |
| 3025 |
*alt=0; |
| 3026 |
if (strlen(fullname) < strlen(rootname)) |
| 3027 |
status = -1; |
| 3028 |
else |
| 3029 |
{ |
| 3030 |
suffix = fullname + strlen(rootname); |
| 3031 |
if (strlen(suffix)) |
| 3032 |
{ |
| 3033 |
testAxis = (int)strtol(suffix, &testAlt, 10); |
| 3034 |
if (testAxis) |
| 3035 |
*axis = testAxis; |
| 3036 |
if (strlen(testAlt) == 1) |
| 3037 |
{ |
| 3038 |
if (testAlt[0] >= 'A' && testAlt[0] <= 'Z') |
| 3039 |
*alt = (int)testAlt[0] - 64; |
| 3040 |
else |
| 3041 |
{ |
| 3042 |
status = -1; |
| 3043 |
} |
| 3044 |
} |
| 3045 |
else if (strlen(testAlt) > 1) |
| 3046 |
{ |
| 3047 |
status = -1; |
| 3048 |
} |
| 3049 |
} |
| 3050 |
} |
| 3051 |
|
| 3052 |
return status; |
| 3053 |
} |
| 3054 |
|
| 3055 |
/************************************************************* |
| 3056 |
* |
| 3057 |
* print_title |
| 3058 |
* |
| 3059 |
* Print the title of the HDU. |
| 3060 |
* when verbose < 2, called by wrterr and wrtwrn. |
| 3061 |
* |
| 3062 |
*************************************************************/ |
| 3063 |
void print_title(FILE* out, int hdunum, int hdutype) |
| 3064 |
{ |
| 3065 |
static char hdutitle[64]; |
| 3066 |
static int oldhdu = 0; |
| 3067 |
|
| 3068 |
/* print out the title */ |
| 3069 |
curhdu = hdunum; |
| 3070 |
curtype = hdutype; |
| 3071 |
|
| 3072 |
if(oldhdu == curhdu) return; /* Do not print it twice */ |
| 3073 |
if(curhdu == 1){ |
| 3074 |
sprintf(hdutitle," HDU %d: Primary Array ", curhdu); |
| 3075 |
} |
| 3076 |
else { |
| 3077 |
switch (curtype) { |
| 3078 |
case IMAGE_HDU: |
| 3079 |
sprintf(hdutitle," HDU %d: Image Exten. ", curhdu); |
| 3080 |
break; |
| 3081 |
case ASCII_TBL: |
| 3082 |
sprintf(hdutitle," HDU %d: ASCII Table ", curhdu); |
| 3083 |
break; |
| 3084 |
case BINARY_TBL: |
| 3085 |
sprintf(hdutitle," HDU %d: BINARY Table ", curhdu); |
| 3086 |
break; |
| 3087 |
default: |
| 3088 |
sprintf(hdutitle," HDU %d: Unknown Ext. ", curhdu); |
| 3089 |
break; |
| 3090 |
} |
| 3091 |
} |
| 3092 |
wrtsep(out,'=',hdutitle,60); |
| 3093 |
wrtout(out," "); |
| 3094 |
oldhdu = curhdu; |
| 3095 |
if(curhdu == totalhdu) oldhdu = 0; /* reset the old hdu at the last hdu */ |
| 3096 |
return; |
| 3097 |
} |
| 3098 |
|
| 3099 |
/************************************************************* |
| 3100 |
* |
| 3101 |
* print_header |
| 3102 |
* |
| 3103 |
* Print the header of the HDU. |
| 3104 |
* |
| 3105 |
*************************************************************/ |
| 3106 |
void print_header(FILE* out) |
| 3107 |
{ |
| 3108 |
char htemp[100]; |
| 3109 |
int i; |
| 3110 |
for (i=1; i <= ncards; i++) { |
| 3111 |
sprintf(htemp,"%4d | %s",i,cards[i-1]); |
| 3112 |
wrtout(out, htemp); |
| 3113 |
} |
| 3114 |
wrtout(out," "); |
| 3115 |
return; |
| 3116 |
} |
| 3117 |
|
| 3118 |
/************************************************************* |
| 3119 |
* |
| 3120 |
* print_summary |
| 3121 |
* |
| 3122 |
* Print out the summary of this hdu. |
| 3123 |
* |
| 3124 |
**************************************************************/ |
| 3125 |
void print_summary(fitsfile *infits, /* input fits file */ |
| 3126 |
FILE* out, /* output ascii file */ |
| 3127 |
FitsHdu *hduptr |
| 3128 |
) |
| 3129 |
{ |
| 3130 |
|
| 3131 |
int i = 0; |
| 3132 |
char extver[10]; |
| 3133 |
char extnv[2*FLEN_VALUE+4]; |
| 3134 |
long npix; |
| 3135 |
int hdutype; |
| 3136 |
|
| 3137 |
/* get the error number and wrn number */ |
| 3138 |
set_hduerr(hduptr->hdunum); |
| 3139 |
|
| 3140 |
hdutype = hduptr->hdutype; |
| 3141 |
sprintf(comm," %d header keywords", hduptr->nkeys); |
| 3142 |
wrtout(out,comm); |
| 3143 |
wrtout(out," "); |
| 3144 |
if(hdutype == ASCII_TBL || hdutype== BINARY_TBL) { |
| 3145 |
sprintf(extnv, "%s",hduptr->extname); |
| 3146 |
if (hduptr->extver!=-999) { |
| 3147 |
sprintf(extver,"(%d)",hduptr->extver); |
| 3148 |
strcat(extnv,extver); |
| 3149 |
} |
| 3150 |
|
| 3151 |
#if (USE_LL_SUFFIX == 1) |
| 3152 |
sprintf(comm," %s (%d columns x %lld rows)", extnv, hduptr->ncols, |
| 3153 |
hduptr->naxes[1]); |
| 3154 |
#else |
| 3155 |
sprintf(comm," %s (%d columns x %ld rows)", extnv, hduptr->ncols, |
| 3156 |
hduptr->naxes[1]); |
| 3157 |
#endif |
| 3158 |
wrtout(out,comm); |
| 3159 |
if(hduptr->ncols) { |
| 3160 |
wrtout(out," "); |
| 3161 |
sprintf(comm, " Col# Name (Units) Format"); |
| 3162 |
wrtout(out,comm); |
| 3163 |
} |
| 3164 |
for ( i = 0; i < hduptr->ncols; i++) { |
| 3165 |
if(strlen(tunit[i])) |
| 3166 |
sprintf(extnv,"%s (%s)",ttype[i],tunit[i]); |
| 3167 |
else |
| 3168 |
sprintf(extnv,"%s",ttype[i]); |
| 3169 |
sprintf(comm," %3d %-20.20s %-10.10s", |
| 3170 |
i+1, extnv, tform[i]); |
| 3171 |
wrtout(out,comm); |
| 3172 |
} |
| 3173 |
} |
| 3174 |
else if(hdutype == IMAGE_HDU && hduptr->isgroup) { |
| 3175 |
|
| 3176 |
sprintf(comm, " %d Random Groups, ",hduptr->gcount); |
| 3177 |
|
| 3178 |
switch(hduptr->bitpix) { |
| 3179 |
case BYTE_IMG: |
| 3180 |
strcpy(temp," 8-bit integer pixels, "); |
| 3181 |
break; |
| 3182 |
case SHORT_IMG: |
| 3183 |
strcpy(temp," 16-bit integer pixels, "); |
| 3184 |
break; |
| 3185 |
case USHORT_IMG: |
| 3186 |
strcpy(temp," 16-bit unsigned integer pixels, "); |
| 3187 |
break; |
| 3188 |
case LONG_IMG: |
| 3189 |
strcpy(temp," 32-bit integer pixels, "); |
| 3190 |
break; |
| 3191 |
case LONGLONG_IMG: |
| 3192 |
strcpy(temp," 64-bit long integer pixels, "); |
| 3193 |
break; |
| 3194 |
case ULONG_IMG: |
| 3195 |
strcpy(temp," 32-bit unsigned integer pixels, "); |
| 3196 |
break; |
| 3197 |
case FLOAT_IMG: |
| 3198 |
strcpy(temp," 32-bit floating point pixels, "); |
| 3199 |
break; |
| 3200 |
case DOUBLE_IMG: |
| 3201 |
strcpy(temp," 64-bit double precision pixels, "); |
| 3202 |
break; |
| 3203 |
default: |
| 3204 |
strcpy(temp," unknown datatype, "); |
| 3205 |
break; |
| 3206 |
} |
| 3207 |
strcat(comm,temp); |
| 3208 |
|
| 3209 |
sprintf(temp," %d axes ",hduptr->naxis); |
| 3210 |
strcat(comm,temp); |
| 3211 |
|
| 3212 |
#if (USE_LL_SUFFIX == 1) |
| 3213 |
sprintf(temp, "(%lld",hduptr->naxes[0]); |
| 3214 |
#else |
| 3215 |
sprintf(temp, "(%ld",hduptr->naxes[0]); |
| 3216 |
#endif |
| 3217 |
strcat(comm,temp); |
| 3218 |
|
| 3219 |
npix = hduptr->naxes[0]; |
| 3220 |
for ( i = 1; i < hduptr->naxis; i++){ |
| 3221 |
npix *= hduptr->naxes[i]; |
| 3222 |
#if (USE_LL_SUFFIX == 1) |
| 3223 |
sprintf(temp, " x %lld",hduptr->naxes[i]); |
| 3224 |
#else |
| 3225 |
sprintf(temp, " x %ld",hduptr->naxes[i]); |
| 3226 |
#endif |
| 3227 |
strcat(comm,temp); |
| 3228 |
} |
| 3229 |
strcat(comm,"), "); |
| 3230 |
wrtout(out,comm); |
| 3231 |
} |
| 3232 |
else if(hdutype == IMAGE_HDU) { |
| 3233 |
if(hduptr->naxis > 0) { |
| 3234 |
|
| 3235 |
if(hduptr->hdunum == 1) { |
| 3236 |
strcpy(extnv,""); |
| 3237 |
} else { |
| 3238 |
sprintf(extnv, "%s",hduptr->extname); |
| 3239 |
if (hduptr->extver!=-999) { |
| 3240 |
sprintf(extver," (%d)",hduptr->extver); |
| 3241 |
strcat(extnv,extver); |
| 3242 |
} |
| 3243 |
} |
| 3244 |
strcpy(comm,extnv); |
| 3245 |
|
| 3246 |
switch(hduptr->bitpix) { |
| 3247 |
case BYTE_IMG: |
| 3248 |
strcpy(temp," 8-bit integer pixels, "); |
| 3249 |
break; |
| 3250 |
case SHORT_IMG: |
| 3251 |
strcpy(temp," 16-bit integer pixels, "); |
| 3252 |
break; |
| 3253 |
case USHORT_IMG: |
| 3254 |
strcpy(temp," 16-bit unsigned integer pixels, "); |
| 3255 |
break; |
| 3256 |
case LONG_IMG: |
| 3257 |
strcpy(temp," 32-bit integer pixels, "); |
| 3258 |
break; |
| 3259 |
case LONGLONG_IMG: |
| 3260 |
strcpy(temp," 64-bit long integer pixels, "); |
| 3261 |
break; |
| 3262 |
case ULONG_IMG: |
| 3263 |
strcpy(temp," 32-bit unsigned integer pixels, "); |
| 3264 |
break; |
| 3265 |
case FLOAT_IMG: |
| 3266 |
strcpy(temp," 32-bit floating point pixels, "); |
| 3267 |
break; |
| 3268 |
case DOUBLE_IMG: |
| 3269 |
strcpy(temp," 64-bit double precision pixels, "); |
| 3270 |
break; |
| 3271 |
default: |
| 3272 |
strcpy(temp," unknown datatype, "); |
| 3273 |
break; |
| 3274 |
} |
| 3275 |
strcat(comm,temp); |
| 3276 |
|
| 3277 |
sprintf(temp," %d axes ",hduptr->naxis); |
| 3278 |
strcat(comm,temp); |
| 3279 |
|
| 3280 |
#if (USE_LL_SUFFIX == 1) |
| 3281 |
sprintf(temp, "(%lld",hduptr->naxes[0]); |
| 3282 |
#else |
| 3283 |
sprintf(temp, "(%ld",hduptr->naxes[0]); |
| 3284 |
#endif |
| 3285 |
strcat(comm,temp); |
| 3286 |
|
| 3287 |
npix = hduptr->naxes[0]; |
| 3288 |
for ( i = 1; i < hduptr->naxis; i++){ |
| 3289 |
npix *= hduptr->naxes[i]; |
| 3290 |
#if (USE_LL_SUFFIX == 1) |
| 3291 |
sprintf(temp, " x %lld",hduptr->naxes[i]); |
| 3292 |
#else |
| 3293 |
sprintf(temp, " x %ld",hduptr->naxes[i]); |
| 3294 |
#endif |
| 3295 |
strcat(comm,temp); |
| 3296 |
} |
| 3297 |
strcat(comm,"), "); |
| 3298 |
wrtout(out,comm); |
| 3299 |
} |
| 3300 |
else{ |
| 3301 |
sprintf(comm," Null data array; NAXIS = 0 "); |
| 3302 |
wrtout(out,comm); |
| 3303 |
} |
| 3304 |
} |
| 3305 |
wrtout(out," "); |
| 3306 |
return; |
| 3307 |
} |
| 3308 |
|
| 3309 |
/************************************************************* |
| 3310 |
* |
| 3311 |
* close_hdu |
| 3312 |
* |
| 3313 |
* Free the memory allocated to the FitsHdu structure and |
| 3314 |
* other temporary spaces. |
| 3315 |
* |
| 3316 |
**************************************************************/ |
| 3317 |
void close_hdu( FitsHdu *hduptr ) |
| 3318 |
{ |
| 3319 |
int i; |
| 3320 |
int n; |
| 3321 |
/* free memories */ |
| 3322 |
for (i=0; i < ncards; i++) free(cards[i]); |
| 3323 |
|
| 3324 |
n = hduptr->nkeys - 4 - hduptr->naxis ; /* excluding the SIMPLE, |
| 3325 |
BITPIX, NAXIS, NAXISn |
| 3326 |
and END */ |
| 3327 |
for (i=0; i < n; i++) free(hduptr->kwds[i]); |
| 3328 |
|
| 3329 |
for (i=0; i < hduptr->ncols; i++) { |
| 3330 |
free(hduptr->datamin[i]); |
| 3331 |
free(hduptr->datamax[i]); |
| 3332 |
free(hduptr->tnull[i]); |
| 3333 |
} |
| 3334 |
if(hduptr->hdutype == ASCII_TBL && hduptr->hdutype == BINARY_TBL){ |
| 3335 |
if(hduptr->ncols > 0)free(ttype); |
| 3336 |
if(hduptr->ncols > 0)free(tunit); |
| 3337 |
if(hduptr->ncols > 0)free(tform); |
| 3338 |
} |
| 3339 |
if(hduptr->naxis) free(hduptr->naxes); |
| 3340 |
if(hduptr->ncols > 0)free(hduptr->datamax); |
| 3341 |
if(hduptr->ncols > 0)free(hduptr->datamin); |
| 3342 |
if(hduptr->ncols > 0)free(hduptr->tnull); |
| 3343 |
free(hduptr->kwds); |
| 3344 |
free(cards); |
| 3345 |
free(tmpkwds); |
| 3346 |
return; |
| 3347 |
} |