Debian Codegraph @

cextern/cfitsio/utilities/fvrf_file.c

raw
1 #include "fverify.h"
2 static HduName **hduname;
3 static int total_err=1; /* initialzed to 1 in case fail to open file */
4 static int total_warn=0;
5
6 int get_total_warn()
7 {
8 return (total_warn);
9 }
10 int get_total_err()
11 {
12 return (total_err);
13 }
14
15 /* Get the total hdu number and allocate the memory for hdu array */
16 void init_hduname()
17 {
18 int i;
19 /* allocate memories for the hdu structure array */
20 hduname = (HduName **)malloc(totalhdu*sizeof(HduName *));
21 for (i=0; i < totalhdu; i++) {
22 hduname[i] = (HduName *)calloc(1, sizeof(HduName));
23 hduname[i]->hdutype = -1;
24 hduname[i]->errnum = 0;
25 hduname[i]->wrnno = 0;
26 strcpy(hduname[i]->extname,"");
27 hduname[i]->extver = 0;
28 }
29 return;
30 }
31 /* set the hduname memeber hdutype, extname, extver */
32 void set_hduname( int hdunum, /* hdu number */
33 int hdutype, /* hdutype */
34 char* extname, /* extension name */
35 int extver /* extension version */
36 )
37 {
38 int i;
39 i = hdunum - 1;
40 hduname[i]->hdutype = hdutype;
41 if(extname!=NULL)
42 strcpy (hduname[i]->extname,extname);
43 else
44 strcpy(hduname[i]->extname,"");
45 hduname[i]->extver = extver;
46 return;
47 }
48
49
50 /* get the total errors and total warnings in this hdu */
51 void set_hduerr(int hdunum /* hdu number */
52 )
53 {
54 int i;
55 i = hdunum - 1;
56 num_err_wrn(&(hduname[i]->errnum), &(hduname[i]->wrnno));
57 reset_err_wrn(); /* reset the error and warning counter */
58 return;
59 }
60
61 /* set the basic information for hduname structure */
62 void set_hdubasic(int hdunum,int hdutype)
63 {
64 set_hduname(hdunum, hdutype, NULL, 0);
65 set_hduerr(hdunum);
66 return;
67 }
68
69 /* test to see whether the two extension having the same name */
70 /* return 1: identical 0: different */
71 int test_hduname (int hdunum1, /* index of first hdu */
72 int hdunum2 /* index of second hdu */
73 )
74 {
75 HduName *p1;
76 HduName *p2;
77
78 p1 = hduname[hdunum1-1];
79 p2 = hduname[hdunum2-1];
80 if(!strlen(p1->extname) || !strlen(p2->extname)) return 0;
81 if(!strcmp(p1->extname,p2->extname) && p1->hdutype == p2->hdutype
82 && p2->extver == p1->extver && hdunum1 != hdunum2){
83 return 1;
84 }
85 return 0;
86 }
87
88 /* Added the error numbers */
89 void total_errors (int *toterr, int * totwrn)
90 {
91 int i = 0;
92 int ierr, iwrn;
93 *toterr = 0;
94 *totwrn = 0;
95
96 if (totalhdu == 0) { /* this means the file couldn't be opened */
97 *toterr = 1;
98 return;
99 }
100
101 for (i = 0; i < totalhdu; i++) {
102 *toterr += hduname[i]->errnum;
103 *totwrn += hduname[i]->wrnno;
104 }
105 /*check the end of file errors */
106 num_err_wrn(&ierr, &iwrn);
107 *toterr +=ierr;
108 *totwrn +=iwrn;
109 return;
110 }
111
112 /* print the extname, exttype, extver, errnum and wrnno in a table */
113 void hdus_summary(FILE *out)
114 {
115 HduName *p;
116 int i;
117 int ierr, iwrn;
118 char temp[FLEN_VALUE];
119 char temp1[FLEN_VALUE];
120
121 wrtsep(out,'+'," Error Summary ",60);
122 wrtout(out," ");
123 sprintf(comm," HDU# Name (version) Type Warnings Errors");
124 wrtout(out,comm);
125
126 sprintf(comm," 1 Primary Array %-4d %-4d ",
127 hduname[0]->wrnno,hduname[0]->errnum);
128 wrtout(out,comm);
129 for (i=2; i <= totalhdu; i++) {
130 p = hduname[i-1];
131 strcpy(temp,p->extname);
132 if(p->extver && p->extver!= -999) {
133 sprintf(temp1," (%-d)",p->extver);
134 strcat(temp,temp1);
135 }
136 switch(hduname[i-1]->hdutype){
137 case IMAGE_HDU:
138 sprintf(comm," %-5d %-20s Image Array %-4d %-4d ",
139 i,temp, p->wrnno,p->errnum);
140 wrtout(out,comm);
141 break;
142 case ASCII_TBL:
143 sprintf(comm," %-5d %-20s ASCII Table %-4d %-4d ",
144 i,temp, p->wrnno,p->errnum);
145 wrtout(out,comm);
146 break;
147 case BINARY_TBL:
148 sprintf(comm," %-5d %-20s Binary Table %-4d %-4d ",
149 i,temp, p->wrnno,p->errnum);
150 wrtout(out,comm);
151 break;
152 default:
153 sprintf(comm," %-5d %-20s Unknown HDU %-4d %-4d ",
154 i,temp, p->wrnno,p->errnum);
155 wrtout(out,comm);
156 break;
157 }
158 }
159 /* check the end of file */
160 num_err_wrn(&ierr, &iwrn);
161 if (iwrn || ierr) {
162 sprintf(comm," End-of-file %-30s %-4d %-4d ", "", iwrn,ierr);
163 wrtout(out,comm);
164 }
165 wrtout(out," ");
166 return;
167 }
168
169
170
171 void destroy_hduname()
172 {
173 int i;
174 for (i=0; i < totalhdu; i++) free(hduname[i]);
175 free(hduname);
176 return;
177 }
178
179 /* Routine to test the extra bytes at the end of file */
180 void test_end(fitsfile *infits,
181 FILE *out)
182
183 {
184 int status = 0;
185 LONGLONG headstart, datastart, dataend;
186 int hdutype;
187
188 /* check whether there are any HDU left */
189 fits_movrel_hdu(infits,1, &hdutype, &status);
190 if (!status) {
191 wrtout(out,"< End-of-File >");
192 sprintf(errmes,
193 "There are extraneous HDU(s) beyond the end of last HDU.");
194 wrterr(out,errmes,2);
195 wrtout(out," ");
196 return;
197 }
198
199 if (status != END_OF_FILE) {
200 wrtserr(out,"Bad HDU? ",&status,2);
201 return;
202 }
203
204 status = 0;
205 fits_clear_errmsg();
206 if(ffghadll(infits, &headstart, &datastart, &dataend, &status))
207 wrtferr(out, "",&status,1);
208
209 /* try to move to the last byte of this extension. */
210 if (ffmbyt(infits, dataend - 1,0,&status))
211 {
212 sprintf(errmes,
213 "Error trying to read last byte of the file at byte %ld.", (long) dataend);
214 wrterr(out,errmes,2);
215 wrtout(out,"< End-of-File >");
216 wrtout(out," ");
217 return;
218 }
219
220 /* try to move to what would be the first byte of the next extension.
221 If successfull, we have a problem... */
222
223 ffmbyt(infits, dataend,0,&status);
224 if(status == 0) {
225 wrtout(out,"< End-of-File >");
226 sprintf(errmes,
227 "File has extra byte(s) after last HDU at byte %ld.", (long) dataend);
228 wrterr(out,errmes,2);
229 wrtout(out," ");
230 }
231
232 return;
233 }
234
235
236
237 /******************************************************************************
238 * Function
239 * init_report
240 *
241 *
242 * DESCRIPTION:
243 * Initialize the fverify report
244 *
245 *******************************************************************************/
246 void init_report(FILE *out, /* output file */
247 char *rootnam /* input file name */
248 )
249 {
250 sprintf(comm,"\n%d Header-Data Units in this file.",totalhdu);
251 wrtout(out,comm);
252 wrtout(out," ");
253
254 reset_err_wrn();
255 init_hduname();
256 }
257
258 /******************************************************************************
259 * Function
260 * close_report
261 *
262 *
263 * DESCRIPTION:
264 * Close the fverify report
265 *
266 *******************************************************************************/
267 void close_report(FILE *out /* output file */ )
268 {
269 int numerrs = 0; /* number of the errors */
270 int numwrns = 0; /* number of the warnings */
271
272 /* print out a summary of all the hdus */
273 if(prstat)hdus_summary(out);
274 total_errors (&numerrs, &numwrns);
275
276 total_warn = numwrns;
277 total_err = numerrs;
278
279 /* get the total number of errors and warnnings */
280 sprintf(comm,"**** Verification found %d warning(s) and %d error(s). ****",
281 numwrns, numerrs);
282 wrtout(out,comm);
283
284 update_parfile(numerrs,numwrns);
285 /* destroy the hdu name */
286 destroy_hduname();
287 return ;
288 }
289