source: Sophya/trunk/FrEROS/AnaLC/checkfsv.cc@ 3308

Last change on this file since 3308 was 3308, checked in by ansari, 18 years ago

Creation du module AnaLC (lecture suivi EROS avec SOPHYA) dans la base
SOPHYA - cmv+reza 22/08/2007

  • Property svn:executable set to *
File size: 5.0 KB
Line 
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
14int main(int narg, char *arg[])
15{
16SUIVIFIP *sfip;
17ENTETESUIVI head;
18FILE *fip;
19char *flnm;
20int_4 newnmes,ntronq,fgr;
21char *buff;
22int_4 nmes, nstar;
23int rc;
24int jt, szbuff;
25int fgtronq;
26int fgswapdef;
27int_4 fgcorrnmes;
28int_4 newfgcorr;
29
30if (narg < 2)
31 {
32 puts(" CheckFSV_Erreur : Arguments incorrects ! (-h pour usage)");
33 exit(1);
34 }
35if (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
50fgswapdef = fgcorrnmes = 0;
51newfgcorr = newnmes = 0;
52ntronq = -1;
53
54if (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}
61else 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
70if (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
97fgtronq = 0;
98if (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 }
105else 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 }
112else { fgr = SUOF_RO_MEM; flnm = arg[1]; }
113
114printf("CheckFSV/Info: Verification fichier %s \n", flnm);
115
116SuiviSetPrtLevel(5);
117if ( (sfip = SuiviOpen(flnm, fgr)) == NULL)
118 { printf(" CheckFSV_Erreur: Pb d'ouverture de %s \n",flnm);
119 exit(99); }
120
121newnmes = rc = 0;
122if ((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}
133if ( (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 */
139szbuff = (sfip->Head.RecSize[3] > sfip->Head.RecSize[4]) ?
140 sfip->Head.RecSize[3]*2 : sfip->Head.RecSize[4]*2;
141if ((buff=(char *)malloc(szbuff)) == NULL) {
142 printf("CheckFSV/erreur: Probleme malloc( buff) ! \n");
143 rc = 99; goto Fin;
144}
145nmes = SuiviGetNbMesures(sfip);
146nstar = SuiviGetNbStars(sfip);
147for(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
166Fin :
167SuiviSetPrtLevel(0);
168SuiviClose(sfip);
169if (rc == 0) printf("CheckFSV/Info: Suivi %s OK RC= %d \n", flnm, rc);
170else printf("CheckFSV/Erreur: ReturnCode = %d \n", rc);
171if (rc > 99) rc = 99;
172exit(rc);
173}
Note: See TracBrowser for help on using the repository browser.