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