1 | #include "machdefs.h"
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <stdio.h>
|
---|
4 | #include <string.h>
|
---|
5 |
|
---|
6 | #include "fsvcache.h"
|
---|
7 |
|
---|
8 | #if ( IS_BIG_ENDIAN == 0 )
|
---|
9 | #define SWAPDEFAUT 1
|
---|
10 | #else
|
---|
11 | #define SWAPDEFAUT 0
|
---|
12 | #endif
|
---|
13 |
|
---|
14 | int main(int narg, char *arg[])
|
---|
15 | {
|
---|
16 | SUIVIFIP *sfip;
|
---|
17 | ENTETESUIVI head;
|
---|
18 | FILE *fip;
|
---|
19 | char *flnm;
|
---|
20 | int_4 newnmes,ntronq,fgr;
|
---|
21 | char *buff;
|
---|
22 | int_4 nmes, nstar;
|
---|
23 | int rc;
|
---|
24 | int jt, szbuff;
|
---|
25 | int fgtronq;
|
---|
26 | int fgswapdef;
|
---|
27 | int_4 fgcorrnmes;
|
---|
28 | int_4 newfgcorr;
|
---|
29 |
|
---|
30 | if (narg < 2)
|
---|
31 | {
|
---|
32 | puts(" CheckFSV_Erreur : Arguments incorrects ! (-h pour usage)");
|
---|
33 | exit(1);
|
---|
34 | }
|
---|
35 | if (strcmp(arg[1],"-h") == 0)
|
---|
36 | {
|
---|
37 | puts("Usage: CheckFSV NomSuivi");
|
---|
38 | puts(" ou CheckFSV [-restore] NomSuivi");
|
---|
39 | puts(" ou CheckFSV [-tronq nmes] NomSuivi");
|
---|
40 | puts(" ou CheckFSV [-swapdefaut] NomSuivi");
|
---|
41 | puts(" ou CheckFSV [-fgcorrnmes fgcorr,nmes] NomSuivi");
|
---|
42 | puts("Rc=0 -> Fichier OK, RC > 0 = Nb de mesure OK");
|
---|
43 | puts("-restore : Tronquer le fichier au nombre de mesure OK");
|
---|
44 | puts("-tronq nmes : Tronquer le fichier au nombre de mesure nmes");
|
---|
45 | puts("-swapdef : Changer la valeur de Flg Swap a SWAPDEFAUT");
|
---|
46 | puts("-fgcorrnmes fgcorr,nmes : Modifie les valeurs de FgCorrupt et NbMes ds l'entete");
|
---|
47 | exit(2);
|
---|
48 | }
|
---|
49 |
|
---|
50 | fgswapdef = fgcorrnmes = 0;
|
---|
51 | newfgcorr = newnmes = 0;
|
---|
52 | ntronq = -1;
|
---|
53 |
|
---|
54 | if (strcmp(arg[1],"-swapdefaut") == 0) {
|
---|
55 | if (narg < 3) {
|
---|
56 | puts(" CheckFSV_Erreur : Arguments incorrects ! (-h pour usage)");
|
---|
57 | exit(2);
|
---|
58 | }
|
---|
59 | flnm = arg[2]; fgswapdef = 1;
|
---|
60 | }
|
---|
61 | else if (strcmp(arg[1],"-fgcorrnmes") == 0) {
|
---|
62 | if (narg < 4) {
|
---|
63 | puts(" CheckFSV_Erreur : Arguments incorrects ! (-h pour usage)");
|
---|
64 | exit(2);
|
---|
65 | }
|
---|
66 | sscanf(arg[2],"%d,%d", &newfgcorr, &newnmes);
|
---|
67 | flnm = arg[2]; fgcorrnmes = 1;
|
---|
68 | }
|
---|
69 |
|
---|
70 | if (fgcorrnmes || fgswapdef) {
|
---|
71 | if ( (fip = fopen(flnm,"rb+")) == NULL )
|
---|
72 | {
|
---|
73 | printf("CheckFSV/Erreur: Pb d'ouverture de %s \n",flnm);
|
---|
74 | exit(5);
|
---|
75 | }
|
---|
76 | fseek(fip, (long)0, SEEK_SET);
|
---|
77 | fread(&head,sizeof(ENTETESUIVI),1,fip);
|
---|
78 | if (fgswapdef) {
|
---|
79 | printf("CheckFSV/Info: Modification Flag Swap entete suivi %s \n", flnm);
|
---|
80 | printf("CheckFSV/Info: FgSwap: Lu= %x ", head.Swap);
|
---|
81 | if (SWAPDEFAUT) head.Swap = 0xFFFF;
|
---|
82 | else head.Swap = 0;
|
---|
83 | printf(" Ecrit= %x \n", head.Swap);
|
---|
84 | }
|
---|
85 | else {
|
---|
86 | printf("CheckFSV/Info: Modification FgCorrupt NbMes - suivi %s \n", flnm);
|
---|
87 | printf("CheckFSV/Info: Lu - FgCorrupt=%d NMes=%d", head.FgCorrupt, head.NbMesTot);
|
---|
88 | head.FgCorrupt = newfgcorr;
|
---|
89 | head.NbMesTot = newnmes;
|
---|
90 | }
|
---|
91 | fseek(fip, (long)0, SEEK_SET);
|
---|
92 | fwrite(&head,sizeof(ENTETESUIVI),1,fip);
|
---|
93 | fclose(fip);
|
---|
94 | exit(0);
|
---|
95 | }
|
---|
96 |
|
---|
97 | fgtronq = 0;
|
---|
98 | if (strcmp(arg[1],"-restore") == 0)
|
---|
99 | {
|
---|
100 | if (narg < 3) {
|
---|
101 | puts(" CheckFSV_Erreur : Arguments incorrects ! (-h pour usage)");
|
---|
102 | exit(2); }
|
---|
103 | flnm = arg[2]; fgr = SUOF_RW; fgtronq = 1;
|
---|
104 | }
|
---|
105 | else if (strcmp(arg[1],"-tronq") == 0)
|
---|
106 | {
|
---|
107 | if (narg < 4) {
|
---|
108 | puts(" CheckFSV_Erreur : Arguments incorrects ! (-h pour usage)");
|
---|
109 | exit(2); }
|
---|
110 | flnm = arg[3]; ntronq = atoi(arg[2]); fgr = SUOF_RW; fgtronq = 1;
|
---|
111 | }
|
---|
112 | else { fgr = SUOF_RO_MEM; flnm = arg[1]; }
|
---|
113 |
|
---|
114 | printf("CheckFSV/Info: Verification fichier %s \n", flnm);
|
---|
115 |
|
---|
116 | SuiviSetPrtLevel(5);
|
---|
117 | if ( (sfip = SuiviOpen(flnm, fgr)) == NULL)
|
---|
118 | { printf(" CheckFSV_Erreur: Pb d'ouverture de %s \n",flnm);
|
---|
119 | exit(99); }
|
---|
120 |
|
---|
121 | newnmes = rc = 0;
|
---|
122 | if ((sfip->Head.NbMesTot != sfip->Head.FgCorrupt) || (sfip->Head.NbMesTot < 0)) {
|
---|
123 | printf("\nCheckFSV/warning: Fichier %s corrompu, NbMes=%d FgCorrupt=%d \n",
|
---|
124 | flnm,sfip->Head.NbMesTot,sfip->Head.FgCorrupt);
|
---|
125 | rc = newnmes = (sfip->Head.FgCorrupt < 0) ? -sfip->Head.FgCorrupt : sfip->Head.FgCorrupt;
|
---|
126 | if (!fgtronq) goto Fin; // Si fichier corrompu et pas de tronq prevu
|
---|
127 | if ( (ntronq >= 0) && (ntronq <= newnmes) ) newnmes = ntronq;
|
---|
128 | if (newnmes < 0) {
|
---|
129 | printf("\nCheckFSV/Bug: NewNMes= %d (<0 ->Rc=98) \n", newnmes);
|
---|
130 | rc = 98; goto Fin;
|
---|
131 | }
|
---|
132 | }
|
---|
133 | if ( (newnmes < sfip->Head.NbMesTot) && fgtronq ) {
|
---|
134 | printf("\nCheckFSV/Info: Fichier tronque a NbMes= %d \n", newnmes);
|
---|
135 | sfip->Head.FgCorrupt = sfip->Head.NbMesTot = newnmes;
|
---|
136 | }
|
---|
137 |
|
---|
138 | /* On verifie qu'on sait lire toutes les TimeInfos et les mesures pour l'etoile NbStar */
|
---|
139 | szbuff = (sfip->Head.RecSize[3] > sfip->Head.RecSize[4]) ?
|
---|
140 | sfip->Head.RecSize[3]*2 : sfip->Head.RecSize[4]*2;
|
---|
141 | if ((buff=(char *)malloc(szbuff)) == NULL) {
|
---|
142 | printf("CheckFSV/erreur: Probleme malloc( buff) ! \n");
|
---|
143 | rc = 99; goto Fin;
|
---|
144 | }
|
---|
145 | nmes = SuiviGetNbMesures(sfip);
|
---|
146 | nstar = SuiviGetNbStars(sfip);
|
---|
147 | for(jt=1; jt<=nmes; jt++) {
|
---|
148 | rc = SuiviReadTimeInfo(sfip,jt,jt,buff);
|
---|
149 | if (rc != 0) {
|
---|
150 | printf("\nCheckFSV/warning: Fichier %s corrompu, Rc(RdTimeInfo(%d))=%d (FgCorrupt=%d) \n",
|
---|
151 | flnm, jt, rc, sfip->Head.FgCorrupt);
|
---|
152 | rc = jt;
|
---|
153 | break;
|
---|
154 | }
|
---|
155 | if (nstar < 1) continue;
|
---|
156 | rc = SuiviReadMesures(sfip, nstar, jt, jt, buff);
|
---|
157 | if (rc != 0) {
|
---|
158 | printf("\nCheckFSV/warning: Fichier %s corrompu, Rc(RdMesure(%d, %d))=%d (FgCorrupt=%d) \n",
|
---|
159 | flnm,nstar,jt,rc,sfip->Head.FgCorrupt);
|
---|
160 | rc = jt;
|
---|
161 | break;
|
---|
162 | }
|
---|
163 | }
|
---|
164 |
|
---|
165 |
|
---|
166 | Fin :
|
---|
167 | SuiviSetPrtLevel(0);
|
---|
168 | SuiviClose(sfip);
|
---|
169 | if (rc == 0) printf("CheckFSV/Info: Suivi %s OK RC= %d \n", flnm, rc);
|
---|
170 | else printf("CheckFSV/Erreur: ReturnCode = %d \n", rc);
|
---|
171 | if (rc > 99) rc = 99;
|
---|
172 | exit(rc);
|
---|
173 | }
|
---|