| 1 |
#include <stdio.h> |
| 2 |
#include <string.h> |
| 3 |
#include "fverify.h" |
| 4 |
|
| 5 |
/* prototypes for PIL interface routines, that are not actually needed |
| 6 |
for this standalone version of fverify |
| 7 |
*/ |
| 8 |
#define PIL_LINESIZE 1024 |
| 9 |
int PILGetFname(char *parname, char *filename); |
| 10 |
int PILGetString(char *parname, char *stringname); |
| 11 |
int PILGetBool(char *parname, int *intvalue); |
| 12 |
int PILPutInt(char *parname, int intvalue); |
| 13 |
|
| 14 |
|
| 15 |
/* |
| 16 |
This file contains the main fverify routine, and dummy version of |
| 17 |
various other headas system routines. This is used for the stand |
| 18 |
alone version of fverify. |
| 19 |
*/ |
| 20 |
|
| 21 |
int main(int argc, char *argv[]) |
| 22 |
{ |
| 23 |
int status = 0, invalid = 0, ii, file1 = 0; |
| 24 |
char errormode[2] = {"w"}; |
| 25 |
|
| 26 |
if (argc == 2 && !strcmp(argv[1],"-h")) { |
| 27 |
|
| 28 |
printf("fitsverify -- Verify that the input files conform to the FITS Standard.\n"); |
| 29 |
printf("\n"); |
| 30 |
printf("USAGE: fitsverify filename ... - verify one or more FITS files\n"); |
| 31 |
printf(" (may use wildcard characters)\n"); |
| 32 |
printf(" or fitsverify @filelist.txt - verify a list of FITS files\n"); |
| 33 |
printf(" \n"); |
| 34 |
printf(" Optional flags:\n"); |
| 35 |
printf(" -H test ESO HIERARCH keywords\n"); |
| 36 |
printf(" -l list all header keywords\n"); |
| 37 |
printf(" -q quiet; print one-line pass/fail summary per file\n"); |
| 38 |
printf(" -e only test for error conditions (ignore warnings)\n"); |
| 39 |
printf(" \n"); |
| 40 |
printf(" fitsverify exits with a status equal to the number of errors + warnings.\n"); |
| 41 |
printf(" \n"); |
| 42 |
printf("EXAMPLES:\n"); |
| 43 |
printf(" fitsverify -l m101.fits - produce a detailed verificaton report of\n"); |
| 44 |
printf(" a single file, including a keyword listing\n"); |
| 45 |
printf(" fitsverify -q *.fits *.fit - verify all files with .fits or .fit\n"); |
| 46 |
printf(" extensions, writing a 1-line pass/fail\n"); |
| 47 |
printf(" message for each file\n"); |
| 48 |
printf(" \n"); |
| 49 |
printf("DESCRIPTION:\n"); |
| 50 |
printf(" \n"); |
| 51 |
printf(" This task reads one or more input FITS files and verifies that the\n"); |
| 52 |
printf(" files conform to the specifications of the FITS Standard, Definition\n"); |
| 53 |
printf(" of the Flexible Image Transport System (FITS), Version 3.0, available\n"); |
| 54 |
printf(" online at http://fits.gsfc.nasa.gov/. The input filename template may\n"); |
| 55 |
printf(" contain wildcard characters, in which case all matching files will be \n"); |
| 56 |
printf(" tested. Alternatively, the name of an ASCII text file containing a list\n"); |
| 57 |
printf(" of file names, one per line, may be entered preceded by an '@' character.\n"); |
| 58 |
printf(" The following error or warning conditions will be reported:\n"); |
| 59 |
printf(" \n"); |
| 60 |
printf(" ERROR CONDITIONS\n"); |
| 61 |
printf(" \n"); |
| 62 |
printf(" - Mandatory keyword not present or out of order\n"); |
| 63 |
printf(" - Mandatory keyword has wrong datatype or illegal value\n"); |
| 64 |
printf(" - END header keyword is not present\n"); |
| 65 |
printf(" - Sum of table column widths is inconsistent with NAXIS1 value\n"); |
| 66 |
printf(" - BLANK keyword present in image with floating-point datatype\n"); |
| 67 |
printf(" - TNULLn keyword present for floating-point binary table column\n"); |
| 68 |
printf(" - Bit column has non-zero fill bits or is not left adjusted \n"); |
| 69 |
printf(" - ASCII TABLE column contains illegal value inconsistent with TFORMn\n"); |
| 70 |
printf(" - Address to a variable length array not within the data heap \n"); |
| 71 |
printf(" - Extraneous bytes in the FITS file following the last HDU \n"); |
| 72 |
printf(" - Mandatory keyword values not expressed in fixed format\n"); |
| 73 |
printf(" - Mandatory keyword duplicated elsewhere in the header\n"); |
| 74 |
printf(" - Header contains illegal ASCII character (not ASCII 32 - 126)\n"); |
| 75 |
printf(" - Keyword name contains illegal character\n"); |
| 76 |
printf(" - Keyword value field has illegal format\n"); |
| 77 |
printf(" - Value and comment fields not separated by a slash character\n"); |
| 78 |
printf(" - END keyword not filled with blanks in columns 9 - 80\n"); |
| 79 |
printf(" - Reserved keyword with wrong datatype or illegal value\n"); |
| 80 |
printf(" - XTENSION keyword in the primary array\n"); |
| 81 |
printf(" - Column related keyword (TFIELDS, TTYPEn,TFORMn, etc.) in an image\n"); |
| 82 |
printf(" - SIMPLE, EXTEND, or BLOCKED keyword in any extension\n"); |
| 83 |
printf(" - BSCALE, BZERO, BUNIT, BLANK, DATAMAX, DATAMIN keywords in a table\n"); |
| 84 |
printf(" - Table WCS keywords (TCTYPn, TCRPXn, TCRVLn, etc.) in an image\n"); |
| 85 |
printf(" - TDIMn or THEAP keyword in an ASCII table \n"); |
| 86 |
printf(" - TBCOLn keyword in a Binary table\n"); |
| 87 |
printf(" - THEAP keyword in a binary table that has PCOUNT = 0 \n"); |
| 88 |
printf(" - XTENSION, TFORMn, TDISPn or TDIMn value contains leading space(s)\n"); |
| 89 |
printf(" - WCSAXES keyword appears after other WCS keywords\n"); |
| 90 |
printf(" - Index of any WCS keyword (CRPIXn, CRVALn, etc.) greater than \n"); |
| 91 |
printf(" value of WCSAXES\n"); |
| 92 |
printf(" - Index of any table column descriptor keyword (TTYPEn, TFORMn,\n"); |
| 93 |
printf(" etc.) greater than value of TFIELDS\n"); |
| 94 |
printf(" - TSCALn or TZEROn present for an ASCII, logical, or Bit column\n"); |
| 95 |
printf(" - TDISPn value is inconsistent with the column datatype \n"); |
| 96 |
printf(" - Length of a variable length array greater than the maximum \n"); |
| 97 |
printf(" length as given by the TFORMn keyword\n"); |
| 98 |
printf(" - ASCII table floating-point column value does not have decimal point(*)\n"); |
| 99 |
printf(" - ASCII table numeric column value has embedded space character\n"); |
| 100 |
printf(" - Logical column contains illegal value not equal to 'T', 'F', or 0\n"); |
| 101 |
printf(" - Character string column contains non-ASCII text character\n"); |
| 102 |
printf(" - Header fill bytes not all blanks\n"); |
| 103 |
printf(" - Data fill bytes not all blanks in ASCII tables or all zeros \n"); |
| 104 |
printf(" in any other type of HDU \n"); |
| 105 |
printf(" - Gaps between defined ASCII table columns contain characters with\n"); |
| 106 |
printf(" ASCII value > 127\n"); |
| 107 |
printf(" \n"); |
| 108 |
printf(" WARNING CONDITIONS\n"); |
| 109 |
printf(" \n"); |
| 110 |
printf(" - SIMPLE = F\n"); |
| 111 |
printf(" - Presence of deprecated keywords BLOCKED or EPOCH\n"); |
| 112 |
printf(" - 2 HDUs have identical EXTNAME, EXTVER, and EXTLEVEL values\n"); |
| 113 |
printf(" - BSCALE or TSCALn value = 0.\n"); |
| 114 |
printf(" - BLANK OR TNULLn value exceeds the legal range\n"); |
| 115 |
printf(" - TFORMn has 'rAw' format and r is not a multiple of w\n"); |
| 116 |
printf(" - DATE = 'dd/mm/yy' and yy is less than 10 (Y2K problem?)\n"); |
| 117 |
printf(" - Index of any WCS keyword (CRPIXn, CRVALn, etc.) greater than\n"); |
| 118 |
printf(" value of NAXIS, if the WCSAXES keyword is not present\n"); |
| 119 |
printf(" - Duplicated keyword (except COMMENT, HISTORY, blank, etc.)\n"); |
| 120 |
printf(" - Column name (TTYPEn) does not exist or contains characters \n"); |
| 121 |
printf(" other than letter, digit and underscore\n"); |
| 122 |
printf(" - Calculated checksum inconsistent with CHECKSUM or DATASUM keyword\n"); |
| 123 |
printf(" \n"); |
| 124 |
printf(" This is the stand alone version of the FTOOLS 'fverify' program. It is\n"); |
| 125 |
printf(" maintained by the HEASARC at NASA/GSFC. Any comments about this program\n"); |
| 126 |
printf(" should be submitted to http://heasarc.gsfc.nasa.gov/cgi-bin/ftoolshelp\n"); |
| 127 |
|
| 128 |
return(0); |
| 129 |
} |
| 130 |
|
| 131 |
prhead = 0; /* don't print header by default */ |
| 132 |
prstat = 1; /* print HDU summary by default */ |
| 133 |
testhierarch = 0; /* do not test ESO HIERARCH keywords by default */ |
| 134 |
|
| 135 |
/* check for flags on the command line */ |
| 136 |
for (ii = 1; ii < argc; ii++) |
| 137 |
{ |
| 138 |
if ((*argv[ii] != '-') || !strcmp(argv[ii],"-") ){ |
| 139 |
file1 = ii; |
| 140 |
break; |
| 141 |
} |
| 142 |
|
| 143 |
if (!strcmp(argv[ii],"-l")) { |
| 144 |
prhead = 1; |
| 145 |
} else if (!strcmp(argv[ii],"-H")) { |
| 146 |
testhierarch = 1; |
| 147 |
} else if (!strcmp(argv[ii],"-e")) { |
| 148 |
strcpy(errormode,"e"); |
| 149 |
} else if (!strcmp(argv[ii],"-q")) { |
| 150 |
prstat = 0; |
| 151 |
} else { |
| 152 |
invalid = 1; |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
if (invalid || argc == 1 || file1 == 0) { |
| 157 |
/* invalid input, so print brief help message */ |
| 158 |
|
| 159 |
printf("\n"); |
| 160 |
printf("fitsverify - test if the input file(s) conform to the FITS format.\n"); |
| 161 |
printf("\n"); |
| 162 |
printf("Usage: fitsverify filename ... or fitsverify @filelist.txt\n"); |
| 163 |
printf("\n"); |
| 164 |
printf(" where 'filename' is a filename template (with optional wildcards), and\n"); |
| 165 |
printf(" 'filelist.txt' is an ASCII text file with a list of\n"); |
| 166 |
printf(" FITS file names, one per line.\n"); |
| 167 |
printf("\n"); |
| 168 |
printf(" Optional flags:\n"); |
| 169 |
printf(" -H test ESO HIERARCH keywords\n"); |
| 170 |
printf(" -l list all header keywords\n"); |
| 171 |
printf(" -q quiet; print one-line pass/fail summary per file\n"); |
| 172 |
printf(" -e only test for error conditions; don't issue warnings\n"); |
| 173 |
printf("\n"); |
| 174 |
printf("Help: fitsverify -h\n"); |
| 175 |
return(0); |
| 176 |
} |
| 177 |
|
| 178 |
/* |
| 179 |
call work function to verify that infile conforms to the FITS |
| 180 |
standard and write report to the output file. |
| 181 |
*/ |
| 182 |
for (ii = file1; ii < argc; ii++) |
| 183 |
{ |
| 184 |
status = ftverify_work( |
| 185 |
argv[ii], /* name of file to verify */ |
| 186 |
"STDOUT", /* write report to this stream */ |
| 187 |
prhead, /* print listing of header keywords? */ |
| 188 |
prstat, /* print detailed summary report */ |
| 189 |
errormode, /* report errors only, or errors and warnings */ |
| 190 |
1, /* test the data */ |
| 191 |
1, /* test checksum, if checksum keywords are present */ |
| 192 |
1, /* test data fill areas (should contain all zeros */ |
| 193 |
0, /* do not test for conformance with HEASARC convensions */ |
| 194 |
/* that are not required by the FITS Standard */ |
| 195 |
testhierarch); /* test format of ESO HIERARCH keywords? */ |
| 196 |
|
| 197 |
if (status) |
| 198 |
return(status); |
| 199 |
} |
| 200 |
|
| 201 |
if ( (totalerr + totalwrn) > 255) |
| 202 |
return(255); |
| 203 |
else |
| 204 |
return(totalerr + totalwrn); |
| 205 |
} |
| 206 |
|
| 207 |
/*------------------------------------------------------------------ |
| 208 |
The following are all dummy stub routines for functions that are |
| 209 |
only needed when ftverify is built in the HEADAS environment. |
| 210 |
--------------------------------------------------------------------*/ |
| 211 |
|
| 212 |
int PILGetFname(char *parname, char *filename) |
| 213 |
{ |
| 214 |
return(0); |
| 215 |
} |
| 216 |
|
| 217 |
int PILGetString(char *parname, char *stringname) |
| 218 |
{ |
| 219 |
return(0); |
| 220 |
} |
| 221 |
|
| 222 |
int PILGetBool(char *parname, int *intvalue) |
| 223 |
{ |
| 224 |
return(0); |
| 225 |
} |
| 226 |
|
| 227 |
int PILPutInt(char *parname, int intvalue) |
| 228 |
{ |
| 229 |
return(0); |
| 230 |
} |
| 231 |
|
| 232 |
void set_toolname(char *taskname); |
| 233 |
void set_toolname(char *taskname) |
| 234 |
{ |
| 235 |
return; |
| 236 |
} |
| 237 |
|
| 238 |
void set_toolversion(char *taskname); |
| 239 |
void set_toolversion(char *taskname) |
| 240 |
{ |
| 241 |
return; |
| 242 |
} |
| 243 |
|
| 244 |
void get_toolname(char *taskname); |
| 245 |
void get_toolname(char *taskname) |
| 246 |
{ |
| 247 |
strcpy(taskname, "fitsverify"); |
| 248 |
return; |
| 249 |
} |
| 250 |
|
| 251 |
void get_toolversion(char *taskvers); |
| 252 |
void get_toolversion(char *taskvers) |
| 253 |
{ |
| 254 |
strcpy(taskvers, "4.22"); |
| 255 |
return; |
| 256 |
} |
| 257 |
|
| 258 |
void headas_clobberfile(char *filename); |
| 259 |
void headas_clobberfile(char *filename) |
| 260 |
{ |
| 261 |
return; |
| 262 |
} |
| 263 |
void HD_ERROR_THROW(char msg[256], int status); |
| 264 |
void HD_ERROR_THROW(char msg[256], int status) |
| 265 |
{ |
| 266 |
return; |
| 267 |
} |