| [3308] | 1 | /*   Ce fichier contient les fonctions de creation, et de lecture */ | 
|---|
|  | 2 | /*   du fichier de suivi des etoiles                              */ | 
|---|
|  | 3 | /*                                      R. Ansari Mars 92         */ | 
|---|
|  | 4 |  | 
|---|
|  | 5 | #include <stdlib.h> | 
|---|
|  | 6 | #include <string.h> | 
|---|
|  | 7 | #include <ctype.h> | 
|---|
|  | 8 |  | 
|---|
|  | 9 | #include "machdefs.h" | 
|---|
|  | 10 | #include "swapbytes.h" | 
|---|
|  | 11 |  | 
|---|
|  | 12 | #include "fsvcache.h" | 
|---|
|  | 13 | #include "filecache.h" | 
|---|
|  | 14 |  | 
|---|
|  | 15 | /*   SOPHYA V >= 2.130 , SWAPDEFAUT n'est plus defini */ | 
|---|
|  | 16 | #if ( IS_BIG_ENDIAN == 0 ) | 
|---|
|  | 17 | #define SWAPDEFAUT 1 | 
|---|
|  | 18 | #else | 
|---|
|  | 19 | #define SWAPDEFAUT 0 | 
|---|
|  | 20 | #endif | 
|---|
|  | 21 |  | 
|---|
|  | 22 | #ifdef RFIO | 
|---|
|  | 23 | #include <shift.h> | 
|---|
|  | 24 | #endif | 
|---|
|  | 25 |  | 
|---|
|  | 26 | /* | 
|---|
|  | 27 | ++ | 
|---|
|  | 28 | Module        Gestion des Suivis (C) | 
|---|
|  | 29 | Lib   fsv | 
|---|
|  | 30 | include       fsvcache.h | 
|---|
|  | 31 |  | 
|---|
|  | 32 | Ce groupe de fonctions permettent de manipuler les fichiers de | 
|---|
|  | 33 | suivi. Les données sont stockées sous format binaire dans le | 
|---|
|  | 34 | fichier et les fonctions de lecture/ écriture assure le | 
|---|
|  | 35 | changement de l'ordre des octets en fonction de l'architecture | 
|---|
|  | 36 | de la machine (Little Endian, Big Endian), à l'odre d'écriture des | 
|---|
|  | 37 | octets dans le fichier, et du format des données déclaré à la | 
|---|
|  | 38 | création du suivi. L'ordre d'écriture des octets dans le fichier | 
|---|
|  | 39 | correspond à celui de la machine où a lieu la création du fichier. | 
|---|
|  | 40 | Une description plus detaillée se trouve dans la note Peida No 1. | 
|---|
|  | 41 | -- | 
|---|
|  | 42 | */ | 
|---|
|  | 43 |  | 
|---|
|  | 44 | /*  declaration des fonctions privees de ce fichier  */ | 
|---|
|  | 45 |  | 
|---|
|  | 46 | #ifdef IBMVM | 
|---|
|  | 47 | #define FindSizeofRec FndSzRec | 
|---|
|  | 48 | #endif | 
|---|
|  | 49 |  | 
|---|
|  | 50 | int_4 FindSizeofRec(char *fmt); | 
|---|
|  | 51 | void SwapSuiviEntete(ENTETESUIVI *hp); | 
|---|
|  | 52 | void SwapSuiviRecord(char* rec, char* fmt, int fmtl, int nr); | 
|---|
|  | 53 |  | 
|---|
|  | 54 | static int sv_prtlev = 0; | 
|---|
|  | 55 | /* Nouvelle-Fonction */ | 
|---|
|  | 56 | void SuiviSetPrtLevel(int lev) | 
|---|
|  | 57 | { | 
|---|
|  | 58 | sv_prtlev = lev; | 
|---|
|  | 59 | zfSetPrtLevel(lev); | 
|---|
|  | 60 | } | 
|---|
|  | 61 |  | 
|---|
|  | 62 |  | 
|---|
|  | 63 | /* | 
|---|
|  | 64 | ++ | 
|---|
|  | 65 | Titre   Création des fichiers de suivi | 
|---|
|  | 66 | -- | 
|---|
|  | 67 | */ | 
|---|
|  | 68 | /* | 
|---|
|  | 69 | ++ | 
|---|
|  | 70 | int SuiviCreate(char *filename, int typ, int rec0size, char *rec1fmt, - | 
|---|
|  | 71 | char *rec2fmt, char *rec3fmt, char *rec4fmt, int nitem) | 
|---|
|  | 72 |  | 
|---|
|  | 73 | Cette fonction crée la structure d'entete avec | 
|---|
|  | 74 | la définition des formats des enregistrements (record). | 
|---|
|  | 75 | |       filename : Nom de fichier | 
|---|
|  | 76 | |       typ : Identificateur de type de fichier de suivi | 
|---|
|  | 77 | |       rec0size : Taille de la zone commentaire (Rec-0) en octets | 
|---|
|  | 78 | |       recifmt : (i=1..4) Format des records Rec-i (i=1..4) | 
|---|
|  | 79 | |       nitem : facteur de groupement des mesures | 
|---|
|  | 80 | Les formats sont spécifiés sous forme d'une chaine de caractère décrivant | 
|---|
|  | 81 | la succession de valeurs constituant un record (Ex: "IIFFS"). | 
|---|
|  | 82 | |       I ou L : entier (4 octets) | 
|---|
|  | 83 | |       S : entier (2 octets) | 
|---|
|  | 84 | |       F : Reel (4 octets) | 
|---|
|  | 85 | |       D : Double precision (8 octets) | 
|---|
|  | 86 | Le code de retour est nul (0) en cas de succès. | 
|---|
|  | 87 | -- | 
|---|
|  | 88 | */ | 
|---|
|  | 89 |  | 
|---|
|  | 90 | /* Nouvelle-Fonction */ | 
|---|
|  | 91 | int SuiviCreate(char *filename, int typ, int rec0size, char *rec1fmt, | 
|---|
|  | 92 | char *rec2fmt, char *rec3fmt, char *rec4fmt, int nitem) | 
|---|
|  | 93 |  | 
|---|
|  | 94 | /*  Cette fonction permet la creation d'un fichier de suivi  */ | 
|---|
|  | 95 | /*  Retourne 0 si OK  -  Non-nul si probleme.                */ | 
|---|
|  | 96 | /*  Arguments :                                              */ | 
|---|
|  | 97 | /*     - filename : Nom de fichier.                          */ | 
|---|
|  | 98 | /*     - typ : valeur stockee ds l'entete (Type)             */ | 
|---|
|  | 99 | /*     - rec0size : Taille de la zone comment (Rec0) en byte */ | 
|---|
|  | 100 | /*     - rec1/2/3/4fmt : Format des records type 1,2,3,4     */ | 
|---|
|  | 101 | /*     Les formats sont specifies sous forme d'une chaines   */ | 
|---|
|  | 102 | /*     de charactere avec le codage suivant:                 */ | 
|---|
|  | 103 | /*       I S L : Entiers short int  et long int (L=I)        */ | 
|---|
|  | 104 | /*       F D   : float et double                             */ | 
|---|
|  | 105 | /*     - nitem : Nb de mesures / record   (def = 10)         */ | 
|---|
|  | 106 |  | 
|---|
|  | 107 | { | 
|---|
|  | 108 |  | 
|---|
|  | 109 | int i; | 
|---|
|  | 110 | ENTETESUIVI head; | 
|---|
|  | 111 | FILE *fip; | 
|---|
|  | 112 | char fiac[80]; | 
|---|
|  | 113 |  | 
|---|
|  | 114 |  | 
|---|
|  | 115 | if (rec0size < 0) rec0size=0; | 
|---|
|  | 116 | if (nitem <= 0)  nitem = 10; | 
|---|
|  | 117 |  | 
|---|
|  | 118 | head.RecSize[0] = rec0size; | 
|---|
|  | 119 | head.NItem = nitem; | 
|---|
|  | 120 | head.NbMesTot = head.NbStars = (int_4)0; | 
|---|
|  | 121 | head.Swap = 0; | 
|---|
|  | 122 | head.Type = typ; | 
|---|
|  | 123 | head.FgCorrupt = 0; | 
|---|
|  | 124 | /*  Pour le Byte-Swap  */ | 
|---|
|  | 125 | if (SWAPDEFAUT)  head.Swap = 0xFFFF; | 
|---|
|  | 126 | else head.Swap = 0; | 
|---|
|  | 127 |  | 
|---|
|  | 128 | /*  Analyse des formats   */ | 
|---|
|  | 129 | if ( (head.RecSize[1] = FindSizeofRec(rec1fmt)) <= 0 ) | 
|---|
|  | 130 | { printf("  SuiviCreate-Erreur ds format Rec_1 \n"); return(1); } | 
|---|
|  | 131 | if ( (head.RecSize[2] = FindSizeofRec(rec2fmt)) <= 0 ) | 
|---|
|  | 132 | { printf("  SuiviCreate-Erreur ds format Rec_2 \n"); return(2); } | 
|---|
|  | 133 | if ( (head.RecSize[3] = FindSizeofRec(rec3fmt)) <= 0 ) | 
|---|
|  | 134 | { printf("  SuiviCreate-Erreur ds format Rec_3 \n"); return(3); } | 
|---|
|  | 135 | if ( (head.RecSize[4] = FindSizeofRec(rec4fmt)) <= 0 ) | 
|---|
|  | 136 | { printf("  SuiviCreate-Erreur ds format Rec_4 \n"); return(4); } | 
|---|
|  | 137 |  | 
|---|
|  | 138 | head.RecSize[3] *= head.NItem; | 
|---|
|  | 139 | head.RecSize[4] *= head.NItem; | 
|---|
|  | 140 |  | 
|---|
|  | 141 |  | 
|---|
|  | 142 | head.FmtSize[0] = 0; | 
|---|
|  | 143 | head.FmtSize[1] = strlen(rec1fmt); | 
|---|
|  | 144 | head.FmtSize[2] = strlen(rec2fmt); | 
|---|
|  | 145 | head.FmtSize[3] = strlen(rec3fmt); | 
|---|
|  | 146 | head.FmtSize[4] = strlen(rec4fmt); | 
|---|
|  | 147 |  | 
|---|
|  | 148 |  | 
|---|
|  | 149 | head.HSize = sizeof(ENTETESUIVI); | 
|---|
|  | 150 | for(i=0; i<5; i++)  head.HSize += head.FmtSize[i]; | 
|---|
|  | 151 | head.FileSize = head.HSize; | 
|---|
|  | 152 |  | 
|---|
|  | 153 | #ifndef IBMVM | 
|---|
|  | 154 | strcpy(fiac,"wb"); | 
|---|
|  | 155 | #else | 
|---|
|  | 156 | strcpy(fiac,"wb, recfm=FS, lrecl=1024"); | 
|---|
|  | 157 | #endif | 
|---|
|  | 158 |  | 
|---|
|  | 159 | if ((fip=fopen(filename,fiac)) == NULL) | 
|---|
|  | 160 | { printf("  SuiviCreate-Erreur ouverture fichier \n"); return(10); } | 
|---|
|  | 161 |  | 
|---|
|  | 162 |  | 
|---|
|  | 163 | fwrite(&head,sizeof(ENTETESUIVI),1,fip); | 
|---|
|  | 164 | fwrite(rec1fmt,1,head.FmtSize[1],fip); | 
|---|
|  | 165 | fwrite(rec2fmt,1,head.FmtSize[2],fip); | 
|---|
|  | 166 | fwrite(rec3fmt,1,head.FmtSize[3],fip); | 
|---|
|  | 167 | fwrite(rec4fmt,1,head.FmtSize[4],fip); | 
|---|
|  | 168 |  | 
|---|
|  | 169 | fclose(fip); | 
|---|
|  | 170 |  | 
|---|
|  | 171 | return(0); | 
|---|
|  | 172 | } | 
|---|
|  | 173 |  | 
|---|
|  | 174 | #ifdef IBMVM | 
|---|
|  | 175 | int NPg[5]={0,50,100,150,200}; | 
|---|
|  | 176 | int PgSz[5]={0,4096,8092,16184,32768}; | 
|---|
|  | 177 | #else | 
|---|
|  | 178 | int NPg[5]={0,10,50,100,200}; | 
|---|
|  | 179 | int PgSz[5]={0,2048,2048,4096,8092}; | 
|---|
|  | 180 | #endif | 
|---|
|  | 181 |  | 
|---|
|  | 182 | /* | 
|---|
|  | 183 | ++ | 
|---|
|  | 184 | Titre   Ouverture, fermeture des suivis | 
|---|
|  | 185 | Le pointeur (l'identificateur) de fichier renvoyé par | 
|---|
|  | 186 | "SuiviOpen()" est le premier argument de toutes les autres | 
|---|
|  | 187 | fonctions "(suivifip)". | 
|---|
|  | 188 | -- | 
|---|
|  | 189 | */ | 
|---|
|  | 190 |  | 
|---|
|  | 191 | /* | 
|---|
|  | 192 | ++ | 
|---|
|  | 193 | SUIVIFIP *SuiviOpen(char * filename, int rw) | 
|---|
|  | 194 | Ouverture du fichier en mode lecture "rw=SUOF_RO" ou | 
|---|
|  | 195 | lecture/ecriture "rw=SUOF_RW". L'activation de la | 
|---|
|  | 196 | memoire cache se fait aussi a travers l'argument "rw" | 
|---|
|  | 197 | |       SUOF_RW_MEM, SUOF_RO_MEM | 
|---|
|  | 198 | |       ou MEM2 , MEM3, MEM4 | 
|---|
|  | 199 |  | 
|---|
|  | 200 | int SuiviClose(SUIVIFIP *suivfip) | 
|---|
|  | 201 | fermeture du fichier de suivi. Le fichier peut être corrompu s'il est | 
|---|
|  | 202 | ouvert en écriture et si "SuiviClose()" n'est pas appelé. | 
|---|
|  | 203 |  | 
|---|
|  | 204 | void SuiviSetPrtLevel(int lev) | 
|---|
|  | 205 | Modification du niveau d'impression des messages d'informations/debug | 
|---|
|  | 206 |  | 
|---|
|  | 207 | -- | 
|---|
|  | 208 | */ | 
|---|
|  | 209 |  | 
|---|
|  | 210 | /* Nouvelle-Fonction */ | 
|---|
|  | 211 | SUIVIFIP *SuiviOpen(char * filename, int rw) | 
|---|
|  | 212 |  | 
|---|
|  | 213 | /* Fonction d'ouverture de fichier de suivi pour lecture/ecriture   */ | 
|---|
|  | 214 | /* Retourne un pointeur sur la structure SUIVIFIP - NULL si Pb.     */ | 
|---|
|  | 215 | /*    rw : Flag d'ouverture fichier en Read/Write  SUOF_RW          */ | 
|---|
|  | 216 | /*                                 ou en ReadOnly  SUOF_RO          */ | 
|---|
|  | 217 |  | 
|---|
|  | 218 | { | 
|---|
|  | 219 | SUIVIFIP *sfip; | 
|---|
|  | 220 | char *po; | 
|---|
|  | 221 | char fiac[20]; | 
|---|
|  | 222 | int mopt; | 
|---|
|  | 223 | FILE *fip; | 
|---|
|  | 224 | int_4 res2; | 
|---|
|  | 225 | char* fmtspace; | 
|---|
|  | 226 | int i,lfmt,rsz; | 
|---|
|  | 227 |  | 
|---|
|  | 228 | if ((po=(char *)malloc(sizeof(SUIVIFIP)+strlen(filename)+1)) == NULL) | 
|---|
|  | 229 | { printf(" SuiviOpen_Erreur : Pb malloc() \n"); return(NULL); } | 
|---|
|  | 230 | sfip = (SUIVIFIP *)(po); | 
|---|
|  | 231 | sfip->Nom = po+sizeof(SUIVIFIP); | 
|---|
|  | 232 |  | 
|---|
|  | 233 | mopt = rw/10; | 
|---|
|  | 234 | if ( (mopt<0) || (mopt>4) )   mopt=0; | 
|---|
|  | 235 | rw = rw%10; | 
|---|
|  | 236 |  | 
|---|
|  | 237 | if ( rw == SUOF_RW )  { strcpy(fiac,"rb+"); sfip->FgRW = SUOF_RW ; } | 
|---|
|  | 238 | else { strcpy(fiac,"rb");  sfip->FgRW = rw = SUOF_RO ; } | 
|---|
|  | 239 |  | 
|---|
|  | 240 | #ifdef IBMVM | 
|---|
|  | 241 | strcat(fiac,"b"); | 
|---|
|  | 242 | #endif | 
|---|
|  | 243 |  | 
|---|
|  | 244 | /*  Lecture entete  - En cas de d'ouverture en RW, on reecrit l'entete  */ | 
|---|
|  | 245 | /*  en utilisant le mot FgCorrupt qui passe a negatif -                 */ | 
|---|
|  | 246 | /*  Head.FgCorrupt = Flag FileCorrupted                                 */ | 
|---|
|  | 247 | /*  OK -> FgCorrupt == NbMesTot , Negatif -> -(Derniere mesure OK)      */ | 
|---|
|  | 248 | /*  ou -99999999                  Reza 10/12/96                         */ | 
|---|
|  | 249 |  | 
|---|
|  | 250 | if ( (fip = fopen(filename,fiac)) == NULL ) | 
|---|
|  | 251 | { printf("SuiviOpen_Erreur : Pb fopen(%s) \n",filename); | 
|---|
|  | 252 | free(po); return(NULL); } | 
|---|
|  | 253 |  | 
|---|
|  | 254 | fseek(fip, (long)0, SEEK_SET); | 
|---|
|  | 255 | fread(&(sfip->Head),sizeof(ENTETESUIVI),1,fip); | 
|---|
|  | 256 |  | 
|---|
|  | 257 | /*  On verifie avant tout si le fichier doit etre byte-swape  */ | 
|---|
|  | 258 | if ( (sfip->Head.Swap != 0)  &&  (SWAPDEFAUT != 0) )  sfip->FgSwap = 0; | 
|---|
|  | 259 | else if ( (sfip->Head.Swap == 0)  &&  (SWAPDEFAUT == 0) )  sfip->FgSwap = 0; | 
|---|
|  | 260 | else { | 
|---|
|  | 261 | sfip->FgSwap = 1; | 
|---|
|  | 262 | if (sv_prtlev > 3) printf("SuiviOpen_Warning: ByteSwap[%x,%x] de Suivi(%s) \n", | 
|---|
|  | 263 | (int)SWAPDEFAUT, (int)sfip->Head.Swap, filename); | 
|---|
|  | 264 | SwapSuiviEntete(&(sfip->Head)); | 
|---|
|  | 265 | } | 
|---|
|  | 266 |  | 
|---|
|  | 267 | /*  Allocation d'espace pour les formats */ | 
|---|
|  | 268 | lfmt = 0; | 
|---|
|  | 269 | for(i=1;i<5;i++)  lfmt += (sfip->Head.FmtSize[i]+1); | 
|---|
|  | 270 |  | 
|---|
|  | 271 | fmtspace = (char *)malloc(lfmt); | 
|---|
|  | 272 | if (fmtspace == NULL) { | 
|---|
|  | 273 | printf(" SuiviOpen_Erreur : Pb. malloc fmtspace \n"); | 
|---|
|  | 274 | free(po); return(NULL); } | 
|---|
|  | 275 |  | 
|---|
|  | 276 | sfip->RecFmt[0] = fmtspace; | 
|---|
|  | 277 | /*  Lecture des elements de formats   */ | 
|---|
|  | 278 | for(i=1;i<5;i++) { | 
|---|
|  | 279 | sfip->RecFmt[i] = fmtspace; | 
|---|
|  | 280 | if ( (rsz=sfip->Head.FmtSize[i]) <= 0)  continue; | 
|---|
|  | 281 | fread(sfip->RecFmt[i], 1, rsz, fip); | 
|---|
|  | 282 | *(sfip->RecFmt[i]+rsz) = '\0'; | 
|---|
|  | 283 | fmtspace += rsz; | 
|---|
|  | 284 | } | 
|---|
|  | 285 |  | 
|---|
|  | 286 | res2 = sfip->Head.FgCorrupt; | 
|---|
|  | 287 | /* NbMesTot < 0 ne devrait pas arriver ! */ | 
|---|
|  | 288 | if (sfip->Head.NbMesTot < 0) { | 
|---|
|  | 289 | printf("SuiviOpen_Erreur: NMes<0 File=%s (FgCorrupt=%d NMes=%d) !?\n", | 
|---|
|  | 290 | filename, res2, sfip->Head.NbMesTot); | 
|---|
|  | 291 | free(fmtspace); free(po); | 
|---|
|  | 292 | fclose(fip); return(NULL); | 
|---|
|  | 293 | } | 
|---|
|  | 294 |  | 
|---|
|  | 295 | if (res2 != sfip->Head.NbMesTot) | 
|---|
|  | 296 | printf("SuiviOpen_Warning : file %s corrompu  (FgCorrupt=%d NMes=%d) !?\n", | 
|---|
|  | 297 | filename, res2, sfip->Head.NbMesTot); | 
|---|
|  | 298 | if ( (rw == SUOF_RW) && (res2 >= 0) ) | 
|---|
|  | 299 | { | 
|---|
|  | 300 | sfip->Head.FgCorrupt = -res2; | 
|---|
|  | 301 | if (sfip->Head.FgCorrupt == 0)  sfip->Head.FgCorrupt = -99999999; | 
|---|
|  | 302 | if (sfip->Head.Swap)    SwapSuiviEntete(&(sfip->Head));  /* Avant ecriture */ | 
|---|
|  | 303 | fseek(fip, (long)0, SEEK_SET); | 
|---|
|  | 304 | fwrite(&(sfip->Head),sizeof(ENTETESUIVI),1,fip); | 
|---|
|  | 305 | if (sfip->Head.Swap)    SwapSuiviEntete(&(sfip->Head));  /* Reswap apres ecriture */ | 
|---|
|  | 306 | sfip->Head.FgCorrupt = res2; | 
|---|
|  | 307 | } | 
|---|
|  | 308 | fclose(fip); | 
|---|
|  | 309 |  | 
|---|
|  | 310 | /*   Ouverture fichier  */ | 
|---|
|  | 311 | if ( (sfip->fcp = zfopen(filename,fiac,NPg[mopt],PgSz[mopt])) == NULL ) | 
|---|
|  | 312 | { printf("SuiviOpen_Erreur : Pb zfopen(%s) \n",filename); | 
|---|
|  | 313 | free(fmtspace); free(po); return(NULL); } | 
|---|
|  | 314 |  | 
|---|
|  | 315 | sfip->fip = sfip->fcp->fip; | 
|---|
|  | 316 | strcpy(sfip->Nom,filename); | 
|---|
|  | 317 | sfip->OffsetMes = sfip->Head.HSize + sfip->Head.RecSize[0] + | 
|---|
|  | 318 | sfip->Head.RecSize[1] + | 
|---|
|  | 319 | sfip->Head.NbStars*sfip->Head.RecSize[2]; | 
|---|
|  | 320 |  | 
|---|
|  | 321 | /*  Impression de debug   */ | 
|---|
|  | 322 | if (sv_prtlev > 3) | 
|---|
|  | 323 | { | 
|---|
|  | 324 | printf(" SuiviOpen_Debug : File= %s , TotSize,Hsize= %ld , %ld  Offset= %ld Swap=%x\n", | 
|---|
|  | 325 | sfip->Nom,(long)sfip->Head.FileSize, (long)sfip->Head.HSize, | 
|---|
|  | 326 | (long)sfip->OffsetMes, (int)sfip->Head.Swap); | 
|---|
|  | 327 | printf(" SuiviOpen_Debug : RecSize[0..4] %d %d %d %d %d\n",sfip->Head.RecSize[0], | 
|---|
|  | 328 | sfip->Head.RecSize[1],sfip->Head.RecSize[2],sfip->Head.RecSize[3],sfip->Head.RecSize[4]); | 
|---|
|  | 329 | printf(" SuiviOpen_Debug : FmtSize[0..4] %d %d %d %d %d\n",sfip->Head.FmtSize[0], | 
|---|
|  | 330 | sfip->Head.FmtSize[1],sfip->Head.FmtSize[2],sfip->Head.FmtSize[3],sfip->Head.FmtSize[4]); | 
|---|
|  | 331 | printf(" SuiviOpen_Debug : NItem,NbStars,NbMesTot %d %d %d Type=%d (FgCorrupt= %d)\n", | 
|---|
|  | 332 | sfip->Head.NItem,sfip->Head.NbStars,sfip->Head.NbMesTot, | 
|---|
|  | 333 | (int)sfip->Head.Type, sfip->Head.FgCorrupt); | 
|---|
|  | 334 | } | 
|---|
|  | 335 |  | 
|---|
|  | 336 |  | 
|---|
|  | 337 | return(sfip); | 
|---|
|  | 338 | } | 
|---|
|  | 339 |  | 
|---|
|  | 340 | /* | 
|---|
|  | 341 | ++ | 
|---|
|  | 342 | Titre   Accès aux informations de l'entête | 
|---|
|  | 343 | Les fonctions suivantes permettent d'accéder a certaines | 
|---|
|  | 344 | informations sauvegardées dans l'entête (Nb. d'étoiles, | 
|---|
|  | 345 | de mesures, ...) | 
|---|
|  | 346 | -- | 
|---|
|  | 347 | */ | 
|---|
|  | 348 |  | 
|---|
|  | 349 | /* | 
|---|
|  | 350 | ++ | 
|---|
|  | 351 | int_4 SuiviGetNbStars(SUIVIFIP *suivfip) | 
|---|
|  | 352 | Retourne le nombre d'étoiles dans le fichier. | 
|---|
|  | 353 |  | 
|---|
|  | 354 | int_4 SuiviGetNbMesures(SUIVIFIP *suivfip) | 
|---|
|  | 355 | Retourne le nombre de mesures dans le fichier. | 
|---|
|  | 356 |  | 
|---|
|  | 357 | int_4 SuiviGetType(SUIVIFIP *suivfip) | 
|---|
|  | 358 | Retourne le type déclaré à la création du fichier. | 
|---|
|  | 359 |  | 
|---|
|  | 360 | int_4 SuiviGetSize(SUIVIFIP *suivfip) | 
|---|
|  | 361 | Retourne la taille actuelle du fichier de suivi. | 
|---|
|  | 362 |  | 
|---|
|  | 363 | int_4 SuiviPredictSize(SUIVIFIP *suivfip, int nbst, int nbmes) | 
|---|
|  | 364 | Retourne la taille calculée pour le fichier avec "nbst" étoiles | 
|---|
|  | 365 | et "nbmes" mesures. | 
|---|
|  | 366 | -- | 
|---|
|  | 367 | */ | 
|---|
|  | 368 |  | 
|---|
|  | 369 |  | 
|---|
|  | 370 | /* Nouvelle-Fonction */ | 
|---|
|  | 371 | int_4 SuiviGetNbytStars(SUIVIFIP *suivfip) | 
|---|
|  | 372 | /*  Retourne le nombre d'item pour chaque mesure ds le fichier   */ | 
|---|
|  | 373 | {  return ( suivfip->Head.RecSize[4] / suivfip->Head.NItem ) ; } | 
|---|
|  | 374 |  | 
|---|
|  | 375 |  | 
|---|
|  | 376 | /* Nouvelle-Fonction */ | 
|---|
|  | 377 | int_4 SuiviGetNbStars(SUIVIFIP *suivfip) | 
|---|
|  | 378 | /*  Retourne le nombre d'etoiles ds le fichier   */ | 
|---|
|  | 379 | {  return ( suivfip->Head.NbStars ) ; } | 
|---|
|  | 380 |  | 
|---|
|  | 381 | /* Nouvelle-Fonction */ | 
|---|
|  | 382 | int_4 SuiviGetNbMesures(SUIVIFIP *suivfip) | 
|---|
|  | 383 | /*  Retourne le nb de mesures ds le fichier   */ | 
|---|
|  | 384 | {  return ( suivfip->Head.NbMesTot ) ; } | 
|---|
|  | 385 |  | 
|---|
|  | 386 | /* Nouvelle-Fonction */ | 
|---|
|  | 387 | int_4 SuiviGetType(SUIVIFIP *suivfip) | 
|---|
|  | 388 | /*  Retourne le type de fichier declare ds l'entete le fichier   */ | 
|---|
|  | 389 | {  return ( suivfip->Head.Type ) ; } | 
|---|
|  | 390 |  | 
|---|
|  | 391 | /* Nouvelle-Fonction */ | 
|---|
|  | 392 | int_4 SuiviGetSize(SUIVIFIP *suivfip) | 
|---|
|  | 393 | /*  Retourne la taille actuelle du fichier de suivi */ | 
|---|
|  | 394 | {  return ( suivfip->Head.FileSize ) ; } | 
|---|
|  | 395 |  | 
|---|
|  | 396 | /* Nouvelle-Fonction */ | 
|---|
|  | 397 | int_4 SuiviPredictSize(SUIVIFIP *sfip, int nbst, int nbmes) | 
|---|
|  | 398 | /*  Retourne la taille calculee pour le nb d'etoiles (nbst) et mesures (nbmes)   */ | 
|---|
|  | 399 | { | 
|---|
|  | 400 | int_4 totsz, nbm; | 
|---|
|  | 401 | totsz = sfip->Head.HSize + sfip->Head.RecSize[0] + /* Entete+zone commentaire  */ | 
|---|
|  | 402 | sfip->Head.RecSize[1] +                    /*  Zone globinfo */ | 
|---|
|  | 403 | nbst*sfip->Head.RecSize[2];                /* Les starInfos   */ | 
|---|
|  | 404 |  | 
|---|
|  | 405 | /*  On calcule le nombre de blocks mesures */ | 
|---|
|  | 406 | nbm = nbmes / sfip->Head.NItem;  /* Les mesures sont groupees par block de NItem */ | 
|---|
|  | 407 | if ((nbmes%sfip->Head.NItem) != 0)  nbm++; | 
|---|
|  | 408 | totsz += nbm*(sfip->Head.RecSize[3] + nbst*sfip->Head.RecSize[4]); | 
|---|
|  | 409 | return ( totsz ) ; | 
|---|
|  | 410 | } | 
|---|
|  | 411 |  | 
|---|
|  | 412 |  | 
|---|
|  | 413 |  | 
|---|
|  | 414 |  | 
|---|
|  | 415 | /* Nouvelle-Fonction */ | 
|---|
|  | 416 |  | 
|---|
|  | 417 | int SuiviClose(SUIVIFIP *suivfip) | 
|---|
|  | 418 |  | 
|---|
|  | 419 | /*   Fonction de fermeture de fichier de suivi - Cet appel est obligatoire en */ | 
|---|
|  | 420 | /* cas de modification (ecriture) du fichier de suivi, avant la fin du prog.  */ | 
|---|
|  | 421 | /*   Retour 0 OK  -  NonNul-> Erreur                                          */ | 
|---|
|  | 422 |  | 
|---|
|  | 423 | { | 
|---|
|  | 424 | if (suivfip == NULL)  return(1); | 
|---|
|  | 425 |  | 
|---|
|  | 426 | /*  Ecriture entete fichier  */ | 
|---|
|  | 427 | if (suivfip->FgRW == SUOF_RW) | 
|---|
|  | 428 | { | 
|---|
|  | 429 | if (suivfip->Head.FgCorrupt >= 0)  /*  M.A.J Flag FileCorrupted */ | 
|---|
|  | 430 | suivfip->Head.FgCorrupt = suivfip->Head.NbMesTot; | 
|---|
|  | 431 | if (suivfip->FgSwap)   /*  On byte-swap avant ecriture */ | 
|---|
|  | 432 | SwapSuiviEntete(&(suivfip->Head)); | 
|---|
|  | 433 | if (zfseek(suivfip->fcp, (long)(0), SEEK_SET) != 0) | 
|---|
|  | 434 | { printf(" SuiviClose_Erreur : Pb zfseek() \n"); return(10); } | 
|---|
|  | 435 | zfwrite(&(suivfip->Head),sizeof(ENTETESUIVI),1,suivfip->fcp); | 
|---|
|  | 436 | } | 
|---|
|  | 437 |  | 
|---|
|  | 438 | zfclose(suivfip->fcp); | 
|---|
|  | 439 | free(suivfip->RecFmt[0]); | 
|---|
|  | 440 | free(suivfip); | 
|---|
|  | 441 |  | 
|---|
|  | 442 | return(0); | 
|---|
|  | 443 |  | 
|---|
|  | 444 | } | 
|---|
|  | 445 |  | 
|---|
|  | 446 |  | 
|---|
|  | 447 | /* | 
|---|
|  | 448 | ++ | 
|---|
|  | 449 | Titre   Lecture, écriture | 
|---|
|  | 450 | Pour toutes les fonctions de lecture/ecriture, "buff" | 
|---|
|  | 451 | désigne le pointeur d'une zone mémoire contenant | 
|---|
|  | 452 | l'information à écrire ou destinée à recevoir | 
|---|
|  | 453 | l'information lue dans le fichier de suivi. | 
|---|
|  | 454 | L'argument "numet" indique le numéro d'étoile (1..NbStars), | 
|---|
|  | 455 | et "numes" le numéro de mesure (1..NbMes). | 
|---|
|  | 456 | Le code de retour est non nul en cas d'erreur. | 
|---|
|  | 457 | -- | 
|---|
|  | 458 | */ | 
|---|
|  | 459 |  | 
|---|
|  | 460 | /* | 
|---|
|  | 461 | ++ | 
|---|
|  | 462 | int SuiviWriteComment(SUIVIFIP *suivfip, char *buff) | 
|---|
|  | 463 | Ecriture de la zone commentaire. | 
|---|
|  | 464 |  | 
|---|
|  | 465 | int SuiviReadComment(SUIVIFIP *suivfip, char *buff) | 
|---|
|  | 466 | Lecture de la zone commentaire. | 
|---|
|  | 467 |  | 
|---|
|  | 468 | -- | 
|---|
|  | 469 | */ | 
|---|
|  | 470 |  | 
|---|
|  | 471 |  | 
|---|
|  | 472 | /* Nouvelle-Fonction */ | 
|---|
|  | 473 |  | 
|---|
|  | 474 | int SuiviWriteComment(SUIVIFIP *suivfip, char *buff) | 
|---|
|  | 475 |  | 
|---|
|  | 476 | /*   Cette fonction ecrit les comment ds le fichier de suivi   */ | 
|---|
|  | 477 | /*  retour 0 OK                                                */ | 
|---|
|  | 478 |  | 
|---|
|  | 479 | { | 
|---|
|  | 480 | int_4 sz; | 
|---|
|  | 481 | int rc; | 
|---|
|  | 482 |  | 
|---|
|  | 483 | if (suivfip == NULL)  return(1); | 
|---|
|  | 484 | if (suivfip->FgRW != SUOF_RW) | 
|---|
|  | 485 | {printf(" SuiviWriteComment_Erreur : Fichier ReadOnly \n"); return(2);} | 
|---|
|  | 486 |  | 
|---|
|  | 487 | /*  Ecriture */ | 
|---|
|  | 488 | rc = 0; | 
|---|
|  | 489 | if (zfseek(suivfip->fcp, (long)suivfip->Head.HSize, SEEK_SET) != 0) | 
|---|
|  | 490 | { printf(" SuiviWriteComment_Erreur : Pb zfseek() \n"); | 
|---|
|  | 491 | suivfip->Head.FgCorrupt = -99999999;  rc = 10; } | 
|---|
|  | 492 | else if (zfwrite(buff,1,(size_t)suivfip->Head.RecSize[0],suivfip->fcp) != suivfip->Head.RecSize[0]) | 
|---|
|  | 493 | { printf(" SuiviWriteComment_Erreur : Pb zfwrite() \n"); | 
|---|
|  | 494 | suivfip->Head.FgCorrupt = -99999999;  rc = 11; } | 
|---|
|  | 495 |  | 
|---|
|  | 496 | /*  M.A.J. Entete  */ | 
|---|
|  | 497 | sz = suivfip->Head.HSize+suivfip->Head.RecSize[0]; | 
|---|
|  | 498 | if (suivfip->Head.FileSize < sz)  suivfip->Head.FileSize = sz; | 
|---|
|  | 499 |  | 
|---|
|  | 500 | return(rc); | 
|---|
|  | 501 | } | 
|---|
|  | 502 |  | 
|---|
|  | 503 |  | 
|---|
|  | 504 |  | 
|---|
|  | 505 |  | 
|---|
|  | 506 | /* Nouvelle-Fonction */ | 
|---|
|  | 507 |  | 
|---|
|  | 508 | int SuiviReadComment(SUIVIFIP *suivfip, char *buff) | 
|---|
|  | 509 |  | 
|---|
|  | 510 | /*   Cette fonction lit les comment ds le fichier de suivi   */ | 
|---|
|  | 511 | /*       retour 0 OK                                         */ | 
|---|
|  | 512 |  | 
|---|
|  | 513 | { | 
|---|
|  | 514 | if (suivfip == NULL)  return(1); | 
|---|
|  | 515 | if (zfseek(suivfip->fcp, (long)suivfip->Head.HSize, SEEK_SET) != 0) | 
|---|
|  | 516 | { printf(" SuiviReadComment_Erreur : Pb zfseek() \n"); return(10); } | 
|---|
|  | 517 | zfread(buff,1,(size_t)suivfip->Head.RecSize[0],suivfip->fcp); | 
|---|
|  | 518 | return(0); | 
|---|
|  | 519 | } | 
|---|
|  | 520 |  | 
|---|
|  | 521 |  | 
|---|
|  | 522 |  | 
|---|
|  | 523 | /* | 
|---|
|  | 524 | ++ | 
|---|
|  | 525 | int SuiviWriteGlobInfo(SUIVIFIP *suivfip, char *buff) | 
|---|
|  | 526 | Ecriture de l'enregistrement GlobInfo. | 
|---|
|  | 527 |  | 
|---|
|  | 528 | int SuiviReadGlobInfo(SUIVIFIP *suivfip, char *buff) | 
|---|
|  | 529 | Lecture de l'enregistrement GlobInfo. | 
|---|
|  | 530 |  | 
|---|
|  | 531 | -- | 
|---|
|  | 532 | */ | 
|---|
|  | 533 |  | 
|---|
|  | 534 | /* Nouvelle-Fonction */ | 
|---|
|  | 535 |  | 
|---|
|  | 536 | int SuiviWriteGlobInfo(SUIVIFIP *suivfip, char *buff) | 
|---|
|  | 537 |  | 
|---|
|  | 538 | /*   Cette fonction ecrit l'enregistrement des infos globales   */ | 
|---|
|  | 539 | /*  retour 0 OK                                                 */ | 
|---|
|  | 540 |  | 
|---|
|  | 541 | { | 
|---|
|  | 542 | int_4 sz; | 
|---|
|  | 543 | int rc; | 
|---|
|  | 544 |  | 
|---|
|  | 545 | if (suivfip == NULL)  return(1); | 
|---|
|  | 546 | if (suivfip->FgRW != SUOF_RW) | 
|---|
|  | 547 | {printf(" SuiviWriteComment_Erreur : Fichier ReadOnly \n"); return(2);} | 
|---|
|  | 548 |  | 
|---|
|  | 549 | if (suivfip->FgSwap)   /*  On byte-swap avant ecriture */ | 
|---|
|  | 550 | SwapSuiviRecord(buff, suivfip->RecFmt[1], suivfip->Head.FmtSize[1], 1); | 
|---|
|  | 551 | /*  Ecriture */ | 
|---|
|  | 552 | rc = 0; | 
|---|
|  | 553 | sz = suivfip->Head.HSize+suivfip->Head.RecSize[0]; | 
|---|
|  | 554 | if (zfseek(suivfip->fcp, (long)sz, SEEK_SET) != 0) | 
|---|
|  | 555 | { printf(" SuiviWriteGlobInfo_Erreur : Pb zfseek() \n"); | 
|---|
|  | 556 | suivfip->Head.FgCorrupt = -99999999;  rc = 10; } | 
|---|
|  | 557 | else if (zfwrite(buff,1,(size_t)suivfip->Head.RecSize[1],suivfip->fcp) != suivfip->Head.RecSize[1]) | 
|---|
|  | 558 | { printf(" SuiviWriteGlobInfo_Erreur : Pb zfwrite() \n"); | 
|---|
|  | 559 | suivfip->Head.FgCorrupt = -99999999; rc = 11; } | 
|---|
|  | 560 |  | 
|---|
|  | 561 |  | 
|---|
|  | 562 | if (suivfip->FgSwap)   /*  On remet dans le bon sens */ | 
|---|
|  | 563 | SwapSuiviRecord(buff, suivfip->RecFmt[1], suivfip->Head.FmtSize[1], 1); | 
|---|
|  | 564 |  | 
|---|
|  | 565 | /*  M.A.J. Entete  */ | 
|---|
|  | 566 | sz = suivfip->Head.HSize + suivfip->Head.RecSize[0] + | 
|---|
|  | 567 | suivfip->Head.RecSize[1]; | 
|---|
|  | 568 | if (suivfip->Head.FileSize < sz)  suivfip->Head.FileSize = sz; | 
|---|
|  | 569 |  | 
|---|
|  | 570 | return(rc); | 
|---|
|  | 571 | } | 
|---|
|  | 572 |  | 
|---|
|  | 573 |  | 
|---|
|  | 574 |  | 
|---|
|  | 575 |  | 
|---|
|  | 576 | /* Nouvelle-Fonction */ | 
|---|
|  | 577 |  | 
|---|
|  | 578 | int SuiviReadGlobInfo(SUIVIFIP *suivfip, char *buff) | 
|---|
|  | 579 |  | 
|---|
|  | 580 | /*   Cette fonction lit l'enregistrement des infos globales   */ | 
|---|
|  | 581 | /*       retour 0 OK                                          */ | 
|---|
|  | 582 |  | 
|---|
|  | 583 | { | 
|---|
|  | 584 | int_4 pos; | 
|---|
|  | 585 | if (suivfip == NULL)  return(1); | 
|---|
|  | 586 | pos = suivfip->Head.HSize+suivfip->Head.RecSize[0]; | 
|---|
|  | 587 | if (zfseek(suivfip->fcp, (long)pos, SEEK_SET) != 0) | 
|---|
|  | 588 | { printf(" SuiviReadGlobInfo_Erreur : Pb zfseek() \n"); return(10); } | 
|---|
|  | 589 | zfread(buff,1,(size_t)suivfip->Head.RecSize[1],suivfip->fcp); | 
|---|
|  | 590 | if (suivfip->FgSwap)   /*  On byte-swap apres lecture */ | 
|---|
|  | 591 | SwapSuiviRecord(buff, suivfip->RecFmt[1], suivfip->Head.FmtSize[1], 1); | 
|---|
|  | 592 | return(0); | 
|---|
|  | 593 | } | 
|---|
|  | 594 |  | 
|---|
|  | 595 |  | 
|---|
|  | 596 | /* | 
|---|
|  | 597 | ++ | 
|---|
|  | 598 | int SuiviWriteStarInfo(SUIVIFIP *suivfip, int_4 num, char *buff) | 
|---|
|  | 599 | Ecriture de l'enregistrement StarInfo pour l'étoile "num" | 
|---|
|  | 600 |  | 
|---|
|  | 601 | int SuiviReadStarInfo(SUIVIFIP *suivfip, int_4 num, char *buff) | 
|---|
|  | 602 | Lecture de l'enregistrement StarInfo pour l'étoile "num" | 
|---|
|  | 603 | -- | 
|---|
|  | 604 | */ | 
|---|
|  | 605 |  | 
|---|
|  | 606 |  | 
|---|
|  | 607 | /* Nouvelle-Fonction */ | 
|---|
|  | 608 |  | 
|---|
|  | 609 | int SuiviWriteStarInfo(SUIVIFIP *suivfip, int_4 num, char *buff) | 
|---|
|  | 610 |  | 
|---|
|  | 611 | /*   Cette fonction ecrit les infos etoiles pour l'etoile   */ | 
|---|
|  | 612 | /*  numero num -  Retour 0  OK                              */ | 
|---|
|  | 613 |  | 
|---|
|  | 614 | { | 
|---|
|  | 615 | int_4 sz,pos; | 
|---|
|  | 616 | int rc; | 
|---|
|  | 617 |  | 
|---|
|  | 618 | if (suivfip == NULL)  return(1); | 
|---|
|  | 619 | if (suivfip->FgRW != SUOF_RW) | 
|---|
|  | 620 | {printf(" SuiviWriteStarInfo_Erreur : Fichier ReadOnly \n");  return(2);} | 
|---|
|  | 621 | if (num <= (int_4)0) | 
|---|
|  | 622 | { printf(" SuiviWriteStarInfo_Erreur : Num (=%ld) <= 0 \n",(long)num); return(3); } | 
|---|
|  | 623 |  | 
|---|
|  | 624 | if ( (suivfip->Head.NbMesTot > 0) && (suivfip->Head.NbStars < num) ) | 
|---|
|  | 625 | { printf(" SuiviWriteStarInfo_Erreur : Fichier contient des mesures ! \n"); | 
|---|
|  | 626 | return(4); } | 
|---|
|  | 627 |  | 
|---|
|  | 628 | if (suivfip->FgSwap)   /*  On byte-swap avant ecriture */ | 
|---|
|  | 629 | SwapSuiviRecord(buff, suivfip->RecFmt[2], suivfip->Head.FmtSize[2], 1); | 
|---|
|  | 630 |  | 
|---|
|  | 631 | /*  Ecriture */ | 
|---|
|  | 632 | pos = suivfip->Head.HSize + suivfip->Head.RecSize[0] + | 
|---|
|  | 633 | suivfip->Head.RecSize[1] + | 
|---|
|  | 634 | (num-1)*suivfip->Head.RecSize[2]; | 
|---|
|  | 635 | rc = 0; | 
|---|
|  | 636 | if (zfseek(suivfip->fcp, (long)pos, SEEK_SET) != 0) | 
|---|
|  | 637 | { printf(" SuiviWriteStarInfo_Erreur : Pb zfseek() \n"); | 
|---|
|  | 638 | suivfip->Head.FgCorrupt = -99999999;  rc = 10; } | 
|---|
|  | 639 | else if ( zfwrite(buff,1,(size_t)suivfip->Head.RecSize[2],suivfip->fcp) != suivfip->Head.RecSize[2]) | 
|---|
|  | 640 | { printf(" SuiviWriteStarInfo_Erreur : Pb zfwrite() \n"); | 
|---|
|  | 641 | suivfip->Head.FgCorrupt = -99999999; rc = 11; } | 
|---|
|  | 642 |  | 
|---|
|  | 643 | if (suivfip->FgSwap)   /*  On remet dans le bon sens */ | 
|---|
|  | 644 | SwapSuiviRecord(buff, suivfip->RecFmt[2], suivfip->Head.FmtSize[2], 1); | 
|---|
|  | 645 |  | 
|---|
|  | 646 | /*  M.A.J. Entete  */ | 
|---|
|  | 647 | sz = pos+suivfip->Head.RecSize[2]; | 
|---|
|  | 648 | if (suivfip->Head.FileSize < sz)  suivfip->Head.FileSize = sz; | 
|---|
|  | 649 | if (suivfip->Head.NbStars < num) | 
|---|
|  | 650 | { | 
|---|
|  | 651 | suivfip->Head.NbStars = num; | 
|---|
|  | 652 | suivfip->OffsetMes = suivfip->Head.HSize + suivfip->Head.RecSize[0] + | 
|---|
|  | 653 | suivfip->Head.RecSize[1] + | 
|---|
|  | 654 | suivfip->Head.NbStars*suivfip->Head.RecSize[2]; | 
|---|
|  | 655 | } | 
|---|
|  | 656 |  | 
|---|
|  | 657 | return(rc); | 
|---|
|  | 658 | } | 
|---|
|  | 659 |  | 
|---|
|  | 660 |  | 
|---|
|  | 661 |  | 
|---|
|  | 662 |  | 
|---|
|  | 663 | /* Nouvelle-Fonction */ | 
|---|
|  | 664 |  | 
|---|
|  | 665 | int SuiviReadStarInfo(SUIVIFIP *suivfip, int_4 num, char *buff) | 
|---|
|  | 666 |  | 
|---|
|  | 667 | /*   Cette fonction lit les infos etoiles pour l'etoile   */ | 
|---|
|  | 668 | /*  numero num -  Retour 0  OK                            */ | 
|---|
|  | 669 |  | 
|---|
|  | 670 | { | 
|---|
|  | 671 | int_4 pos; | 
|---|
|  | 672 |  | 
|---|
|  | 673 | if (suivfip == NULL)  return(1); | 
|---|
|  | 674 | if ( (num <= (int_4)0) || (num > suivfip->Head.NbStars) ) | 
|---|
|  | 675 | { printf(" SuiviReadStarInfo_Erreur : Num (=%ld) out of range \n",(long)num); return(2); } | 
|---|
|  | 676 |  | 
|---|
|  | 677 | /*  lecture */ | 
|---|
|  | 678 | pos = suivfip->Head.HSize + suivfip->Head.RecSize[0] + | 
|---|
|  | 679 | suivfip->Head.RecSize[1] + | 
|---|
|  | 680 | (num-1)*suivfip->Head.RecSize[2]; | 
|---|
|  | 681 | if (zfseek(suivfip->fcp, (long)pos, SEEK_SET) != 0) | 
|---|
|  | 682 | { printf(" SuiviReadStarInfo_Erreur : Pb zfseek() \n"); return(10); } | 
|---|
|  | 683 | zfread(buff,1,(size_t)suivfip->Head.RecSize[2],suivfip->fcp); | 
|---|
|  | 684 |  | 
|---|
|  | 685 | if (suivfip->FgSwap)   /*  On byte-swap apres lecture */ | 
|---|
|  | 686 | SwapSuiviRecord(buff, suivfip->RecFmt[2], suivfip->Head.FmtSize[2], 1); | 
|---|
|  | 687 |  | 
|---|
|  | 688 |  | 
|---|
|  | 689 | return(0); | 
|---|
|  | 690 | } | 
|---|
|  | 691 |  | 
|---|
|  | 692 | /* | 
|---|
|  | 693 | ++ | 
|---|
|  | 694 | int SuiviAddMesure(SUIVIFIP *suivfip, char *buff) | 
|---|
|  | 695 | Ajoute une nouvelle mesure dans le fichier. "buff" contient | 
|---|
|  | 696 | l'information TimeInfo pour cette mesure. | 
|---|
|  | 697 | -- | 
|---|
|  | 698 | */ | 
|---|
|  | 699 |  | 
|---|
|  | 700 |  | 
|---|
|  | 701 | /* Nouvelle-Fonction */ | 
|---|
|  | 702 | int SuiviAddMesure(SUIVIFIP *suivfip, char *buff) | 
|---|
|  | 703 |  | 
|---|
|  | 704 | /*  Cette fonction rajoute une nouvelle mesure ds le fichier de suivi  */ | 
|---|
|  | 705 | /*  *buff contient l'information temps de cette mesure                 */ | 
|---|
|  | 706 | /*  Les mesures correspondant a ce temps doivent etre rajoute par      */ | 
|---|
|  | 707 | /*  SuiviWriteMesure()                                                 */ | 
|---|
|  | 708 |  | 
|---|
|  | 709 | { | 
|---|
|  | 710 | int_4 pos,l1; | 
|---|
|  | 711 | ENTETESUIVI *head; | 
|---|
|  | 712 | int_4 itsiz; | 
|---|
|  | 713 | char bidbuf[4] = {'\0','\0','\0','\0'}; | 
|---|
|  | 714 | int rc; | 
|---|
|  | 715 |  | 
|---|
|  | 716 | if (suivfip == NULL)  return(1); | 
|---|
|  | 717 | if (suivfip->FgRW != SUOF_RW) | 
|---|
|  | 718 | {printf(" SuiviAddMesure_Erreur : Fichier ReadOnly \n");  return(2);} | 
|---|
|  | 719 | head = &(suivfip->Head); | 
|---|
|  | 720 |  | 
|---|
|  | 721 | /*   On verifie voir s'il faut creer de nouveaux records ?   */ | 
|---|
|  | 722 | if ( (head->NbMesTot % head->NItem) == (int_4)(0) ) { | 
|---|
|  | 723 | pos = suivfip->OffsetMes  + | 
|---|
|  | 724 | ( (head->NbMesTot / head->NItem) + 1) * | 
|---|
|  | 725 | ( head->RecSize[3] + (head->NbStars)*head->RecSize[4] ) - 4 ; | 
|---|
|  | 726 | if (zfseek(suivfip->fcp, (long)pos, SEEK_SET) != 0) | 
|---|
|  | 727 | { printf(" SuiviAddMesure_Erreur : Pb zfseek() \n"); | 
|---|
|  | 728 | suivfip->Head.FgCorrupt = -99999999;  return(10); } | 
|---|
|  | 729 | if (zfwrite(bidbuf,1, 4, suivfip->fcp) != 4) | 
|---|
|  | 730 | { printf(" SuiviAddMesure_Erreur : Pb zfwrite() \n"); | 
|---|
|  | 731 | suivfip->Head.FgCorrupt = -99999999;  return(11); } | 
|---|
|  | 732 | head->FileSize = pos+4; | 
|---|
|  | 733 | } | 
|---|
|  | 734 |  | 
|---|
|  | 735 | head->NbMesTot++; | 
|---|
|  | 736 |  | 
|---|
|  | 737 | l1 = (head->NbMesTot-1) / head->NItem; | 
|---|
|  | 738 | pos = suivfip->OffsetMes + | 
|---|
|  | 739 | l1 * (head->RecSize[3] + | 
|---|
|  | 740 | head->NbStars*head->RecSize[4]); | 
|---|
|  | 741 | itsiz = head->RecSize[3] / head->NItem ; | 
|---|
|  | 742 | pos += (head->NbMesTot-1 - l1*head->NItem) * itsiz; | 
|---|
|  | 743 |  | 
|---|
|  | 744 | if (suivfip->FgSwap)   /*  On byte-swap avant ecriture */ | 
|---|
|  | 745 | SwapSuiviRecord(buff, suivfip->RecFmt[3], suivfip->Head.FmtSize[3], 1); | 
|---|
|  | 746 |  | 
|---|
|  | 747 | rc = 0; | 
|---|
|  | 748 | if (zfseek(suivfip->fcp, (long)pos, SEEK_SET) != 0) | 
|---|
|  | 749 | { printf(" SuiviAddMesure_Erreur : Pb zfseek() \n"); | 
|---|
|  | 750 | suivfip->Head.FgCorrupt = -99999999; rc = 10; } | 
|---|
|  | 751 | else if (zfwrite(buff,1,(size_t)itsiz,suivfip->fcp) != itsiz) | 
|---|
|  | 752 | { printf(" SuiviAddMesure_Erreur : Pb zfseek() \n"); | 
|---|
|  | 753 | suivfip->Head.FgCorrupt = -99999999;  rc = 11; } | 
|---|
|  | 754 |  | 
|---|
|  | 755 | if (suivfip->FgSwap)   /*  On remet dans le bon sens apres ecriture */ | 
|---|
|  | 756 | SwapSuiviRecord(buff, suivfip->RecFmt[3], suivfip->Head.FmtSize[3], 1); | 
|---|
|  | 757 |  | 
|---|
|  | 758 | return(rc); | 
|---|
|  | 759 | } | 
|---|
|  | 760 |  | 
|---|
|  | 761 |  | 
|---|
|  | 762 | /* | 
|---|
|  | 763 | ++ | 
|---|
|  | 764 | int SuiviWriteTimeInfo(SUIVIFIP *suivfip, int_4 numes, char *buff) | 
|---|
|  | 765 | Ecriture de TimeInfo pour la mesure numéro "numes" (1..NbMes). | 
|---|
|  | 766 | -- | 
|---|
|  | 767 | */ | 
|---|
|  | 768 |  | 
|---|
|  | 769 |  | 
|---|
|  | 770 | /* Nouvelle-Fonction */ | 
|---|
|  | 771 | int SuiviWriteTimeInfo(SUIVIFIP *suivfip, int_4 numes, char *buff) | 
|---|
|  | 772 |  | 
|---|
|  | 773 | /*  Cette fonction ecrit l'info temps pour la mesure numero num  */ | 
|---|
|  | 774 | /*  *buff contient l'information temps - Retour 0 OK             */ | 
|---|
|  | 775 |  | 
|---|
|  | 776 | { | 
|---|
|  | 777 | int_4 pos,l1; | 
|---|
|  | 778 | ENTETESUIVI *head; | 
|---|
|  | 779 | int_4 itsiz; | 
|---|
|  | 780 | int rc; | 
|---|
|  | 781 |  | 
|---|
|  | 782 | if (suivfip == NULL)  return(1); | 
|---|
|  | 783 | if (suivfip->FgRW != SUOF_RW) | 
|---|
|  | 784 | {printf(" SuiviWriteTimeInfo_Erreur : Fichier ReadOnly \n");  return(2);} | 
|---|
|  | 785 | head = &(suivfip->Head); | 
|---|
|  | 786 |  | 
|---|
|  | 787 | if ( (numes <= (int_4)0) || (numes > suivfip->Head.NbMesTot) ) | 
|---|
|  | 788 | { printf(" SuiviWriteTimeInfo_Erreur : NumMesure (=%ld) out of range \n",(long)numes); | 
|---|
|  | 789 | return(3); } | 
|---|
|  | 790 |  | 
|---|
|  | 791 | l1 = (numes-1) / head->NItem; | 
|---|
|  | 792 | pos = suivfip->OffsetMes + | 
|---|
|  | 793 | l1 * ( head->RecSize[3] + | 
|---|
|  | 794 | head->NbStars*head->RecSize[4] ); | 
|---|
|  | 795 | itsiz = head->RecSize[3] / head->NItem ; | 
|---|
|  | 796 | pos += ( numes-1 - l1*head->NItem ) * itsiz; | 
|---|
|  | 797 |  | 
|---|
|  | 798 | if (suivfip->FgSwap)   /*  On byte-swap avant ecriture */ | 
|---|
|  | 799 | SwapSuiviRecord(buff, suivfip->RecFmt[3], suivfip->Head.FmtSize[3], 1); | 
|---|
|  | 800 | rc = 0; | 
|---|
|  | 801 | if (zfseek(suivfip->fcp, (long)pos, SEEK_SET) != 0) | 
|---|
|  | 802 | { printf(" SuiviWriteTimeInfo_Erreur : Pb zfseek() \n"); | 
|---|
|  | 803 | suivfip->Head.FgCorrupt = -99999999;  rc = 10; } | 
|---|
|  | 804 | if (zfwrite(buff,1,(size_t)itsiz,suivfip->fcp) != itsiz) | 
|---|
|  | 805 | { printf(" SuiviWriteTimeInfo_Erreur : Pb zfwrite() \n"); | 
|---|
|  | 806 | suivfip->Head.FgCorrupt = -99999999;  rc = 11; } | 
|---|
|  | 807 |  | 
|---|
|  | 808 |  | 
|---|
|  | 809 | if (suivfip->FgSwap)   /*  On remet dans le bon sens apres ecriture */ | 
|---|
|  | 810 | SwapSuiviRecord(buff, suivfip->RecFmt[3], suivfip->Head.FmtSize[3], 1); | 
|---|
|  | 811 |  | 
|---|
|  | 812 | return(rc); | 
|---|
|  | 813 | } | 
|---|
|  | 814 |  | 
|---|
|  | 815 |  | 
|---|
|  | 816 |  | 
|---|
|  | 817 | /* | 
|---|
|  | 818 | ++ | 
|---|
|  | 819 | int SuiviWriteMesure(SUIVIFIP *suivfip, int_4 numet, int_4 nummes, char *buff) | 
|---|
|  | 820 | Ecriture de l'infomation Mesure pour l'étoile numéro "numet" | 
|---|
|  | 821 | et la mesure numéro "numes" | 
|---|
|  | 822 | -- | 
|---|
|  | 823 | */ | 
|---|
|  | 824 |  | 
|---|
|  | 825 | /* Nouvelle-Fonction */ | 
|---|
|  | 826 | int SuiviWriteMesure(SUIVIFIP *suivfip, int_4 numet, | 
|---|
|  | 827 | int_4 nummes, char *buff) | 
|---|
|  | 828 |  | 
|---|
|  | 829 | /*  Cette fonction ecrit une mesure ds le fichier de suivi    */ | 
|---|
|  | 830 | /*  numet est le numero d'etoile, nummes le numero de mesure  */ | 
|---|
|  | 831 | /*  *buff contient l'information mesure - Retour 0 OK         */ | 
|---|
|  | 832 |  | 
|---|
|  | 833 | { | 
|---|
|  | 834 | int_4 pos,l1; | 
|---|
|  | 835 | ENTETESUIVI *head; | 
|---|
|  | 836 | int_4 itsiz; | 
|---|
|  | 837 | int rc; | 
|---|
|  | 838 |  | 
|---|
|  | 839 | if (suivfip == NULL)  return(1); | 
|---|
|  | 840 | if (suivfip->FgRW != SUOF_RW) | 
|---|
|  | 841 | {printf(" SuiviWriteMesure_Erreur : Fichier ReadOnly \n");  return(2);} | 
|---|
|  | 842 | head = &(suivfip->Head); | 
|---|
|  | 843 |  | 
|---|
|  | 844 | if ( (numet <= (int_4)0) || (numet > suivfip->Head.NbStars) ) | 
|---|
|  | 845 | { printf(" SuiviWriteMesure_Erreur : NumEtoile (=%ld) out of range \n",(long)numet); | 
|---|
|  | 846 | return(2); } | 
|---|
|  | 847 |  | 
|---|
|  | 848 | if ( (nummes <= (int_4)0) || (nummes > suivfip->Head.NbMesTot) ) | 
|---|
|  | 849 | { printf(" SuiviWriteMesure_Erreur : NumMesure (=%ld) out of range \n",(long)nummes); | 
|---|
|  | 850 | return(3); } | 
|---|
|  | 851 |  | 
|---|
|  | 852 | l1 = (nummes-1) / head->NItem; | 
|---|
|  | 853 | pos = suivfip->OffsetMes + | 
|---|
|  | 854 | l1 * (head->RecSize[3] + | 
|---|
|  | 855 | head->NbStars*head->RecSize[4]) + | 
|---|
|  | 856 | head->RecSize[3] + (numet-1)*head->RecSize[4]; | 
|---|
|  | 857 | itsiz = head->RecSize[4] / head->NItem ; | 
|---|
|  | 858 | pos += (nummes-1 - l1*head->NItem) * itsiz; | 
|---|
|  | 859 |  | 
|---|
|  | 860 | if (suivfip->FgSwap)   /*  On byte-swap avant ecriture */ | 
|---|
|  | 861 | SwapSuiviRecord(buff, suivfip->RecFmt[4], suivfip->Head.FmtSize[4], 1); | 
|---|
|  | 862 |  | 
|---|
|  | 863 | rc = 0; | 
|---|
|  | 864 | if (zfseek(suivfip->fcp, (long)pos, SEEK_SET) != 0) | 
|---|
|  | 865 | { printf(" SuiviWriteMesure_Erreur : Pb zfseek() \n"); | 
|---|
|  | 866 | suivfip->Head.FgCorrupt = -99999999;  rc = 10; } | 
|---|
|  | 867 | else if (zfwrite(buff,1,(size_t)itsiz,suivfip->fcp) != itsiz) | 
|---|
|  | 868 | { printf(" SuiviWriteMesure_Erreur : Pb zfwrite() \n"); | 
|---|
|  | 869 | suivfip->Head.FgCorrupt = -99999999;  rc = 11; } | 
|---|
|  | 870 |  | 
|---|
|  | 871 | if (suivfip->FgSwap)   /*  On remet dans le bon sens apres ecriture */ | 
|---|
|  | 872 | SwapSuiviRecord(buff, suivfip->RecFmt[4], suivfip->Head.FmtSize[4], 1); | 
|---|
|  | 873 |  | 
|---|
|  | 874 | return(rc); | 
|---|
|  | 875 | } | 
|---|
|  | 876 |  | 
|---|
|  | 877 |  | 
|---|
|  | 878 | /* | 
|---|
|  | 879 | ++ | 
|---|
|  | 880 | int SuiviReadTimeInfo(SUIVIFIP *suivfip, int_4 debut, int_4 fin, char *buff) | 
|---|
|  | 881 | Lecture des informations TimeInfo pour "debut <= mes <= fin". | 
|---|
|  | 882 | Attention : Des erreurs d'alignement d'accès mémoire peuvent | 
|---|
|  | 883 | avoir lieu en cas de lecture multiple "(fin > debut)" si la taille | 
|---|
|  | 884 | de la structure TimeInfo ne coincide pas avec celle de l'enregistrement | 
|---|
|  | 885 | correspondant. | 
|---|
|  | 886 | -- | 
|---|
|  | 887 | */ | 
|---|
|  | 888 |  | 
|---|
|  | 889 |  | 
|---|
|  | 890 | /* Nouvelle-Fonction */ | 
|---|
|  | 891 | int SuiviReadTimeInfo(SUIVIFIP *suivfip, int_4 debut, | 
|---|
|  | 892 | int_4 fin, char *buff) | 
|---|
|  | 893 |  | 
|---|
|  | 894 | /*  Cette fonction lit l'information temps pour les mesures  */ | 
|---|
|  | 895 | /*   debut <= NumMes <= fin         Retour 0  OK             */ | 
|---|
|  | 896 |  | 
|---|
|  | 897 | { | 
|---|
|  | 898 | int_4 pos,l1; | 
|---|
|  | 899 | ENTETESUIVI *head; | 
|---|
|  | 900 | int_4 itsiz; | 
|---|
|  | 901 | int_4 fr,to,nit; | 
|---|
|  | 902 | char* buff0; | 
|---|
|  | 903 |  | 
|---|
|  | 904 | if (suivfip == NULL)  return(1); | 
|---|
|  | 905 | head = &(suivfip->Head); | 
|---|
|  | 906 |  | 
|---|
|  | 907 |  | 
|---|
|  | 908 | if ( (debut <= (int_4)0) || (debut > head->NbMesTot) ) | 
|---|
|  | 909 | { printf(" SuiviReadTimeInfo_Erreur : NumDebut (=%ld) out of range \n",(long)debut); | 
|---|
|  | 910 | return(3); } | 
|---|
|  | 911 |  | 
|---|
|  | 912 | if ( (fin <= (int_4)0) || (fin > head->NbMesTot) ) | 
|---|
|  | 913 | { printf(" SuiviReadTimeInfo_Erreur : NumFin (=%ld) out of range \n",(long)fin); | 
|---|
|  | 914 | return(4); } | 
|---|
|  | 915 |  | 
|---|
|  | 916 | if ( debut > fin) | 
|---|
|  | 917 | { printf(" SuiviReadTimeInfo_Erreur : NumFin (=%ld) < NumDebut(=%ld) \n", | 
|---|
|  | 918 | (long)fin, (long)debut); | 
|---|
|  | 919 | return(5); } | 
|---|
|  | 920 |  | 
|---|
|  | 921 | itsiz = head->RecSize[3] / head->NItem ; | 
|---|
|  | 922 |  | 
|---|
|  | 923 | fr=to=debut; | 
|---|
|  | 924 | buff0 = buff; | 
|---|
|  | 925 |  | 
|---|
|  | 926 | do { | 
|---|
|  | 927 |  | 
|---|
|  | 928 | l1 = (fr-1) / head->NItem; | 
|---|
|  | 929 | to = (l1+1) * head->NItem; | 
|---|
|  | 930 | if (to > fin)  nit = fin-fr+1; | 
|---|
|  | 931 | else nit = to-fr+1; | 
|---|
|  | 932 | pos = suivfip->OffsetMes + | 
|---|
|  | 933 | l1 * (head->RecSize[3] + | 
|---|
|  | 934 | head->NbStars*head->RecSize[4]); | 
|---|
|  | 935 | pos += (fr-1 - l1*head->NItem) * itsiz; | 
|---|
|  | 936 | if (zfseek(suivfip->fcp, (long)pos, SEEK_SET) != 0) | 
|---|
|  | 937 | { printf(" SuiviReadTimeInfo_Erreur : Pb zfseek() \n"); return(10); } | 
|---|
|  | 938 | zfread(buff,(size_t)itsiz,nit,suivfip->fcp); | 
|---|
|  | 939 | fr += nit;  buff += nit * itsiz; | 
|---|
|  | 940 |  | 
|---|
|  | 941 | } while (fr <= fin); | 
|---|
|  | 942 |  | 
|---|
|  | 943 | if (suivfip->FgSwap)   /*  On byte-swap apres lecture */ | 
|---|
|  | 944 | SwapSuiviRecord(buff0, suivfip->RecFmt[3], suivfip->Head.FmtSize[3], fin-debut+1); | 
|---|
|  | 945 |  | 
|---|
|  | 946 | return(0); | 
|---|
|  | 947 | } | 
|---|
|  | 948 |  | 
|---|
|  | 949 |  | 
|---|
|  | 950 |  | 
|---|
|  | 951 |  | 
|---|
|  | 952 | /* | 
|---|
|  | 953 | ++ | 
|---|
|  | 954 | int SuiviReadMesures(SUIVIFIP *suivfip, int_4 numet, int_4 debut, int_4 fin, char *buff) | 
|---|
|  | 955 | Lecture des informations Mesure pour l'étoile "numet", "debut <= mes <= fin". | 
|---|
|  | 956 | Attention : Des erreurs d'alignement d'accès mémoire peuvent | 
|---|
|  | 957 | avoir lieu en cas de lecture multiple "(fin > debut)" si la taille | 
|---|
|  | 958 | de la structure Mesure ne coincide pas avec celle de l'enregistrement | 
|---|
|  | 959 | correspondant. | 
|---|
|  | 960 | -- | 
|---|
|  | 961 | */ | 
|---|
|  | 962 |  | 
|---|
|  | 963 |  | 
|---|
|  | 964 | /* Nouvelle-Fonction */ | 
|---|
|  | 965 | int SuiviReadMesures(SUIVIFIP *suivfip, int_4 numet, | 
|---|
|  | 966 | int_4 debut, int_4 fin, char *buff) | 
|---|
|  | 967 |  | 
|---|
|  | 968 | /*  Cette fonction lit les mesures pour l'etoile numet       */ | 
|---|
|  | 969 | /*   debut <= NumMes <= fin         Retour 0  OK             */ | 
|---|
|  | 970 |  | 
|---|
|  | 971 | { | 
|---|
|  | 972 | int_4 pos,l1; | 
|---|
|  | 973 | ENTETESUIVI *head; | 
|---|
|  | 974 | int_4 itsiz; | 
|---|
|  | 975 | int_4 fr,to,nit; | 
|---|
|  | 976 | char* buff0; | 
|---|
|  | 977 |  | 
|---|
|  | 978 | if (suivfip == NULL)  return(1); | 
|---|
|  | 979 | head = &(suivfip->Head); | 
|---|
|  | 980 |  | 
|---|
|  | 981 | if ( (numet <= (int_4)0) || (numet > head->NbStars) ) | 
|---|
|  | 982 | { printf(" SuiviReadMesures_Erreur : NumEtoile (=%ld) out of range \n", (long)numet); | 
|---|
|  | 983 | return(2); } | 
|---|
|  | 984 |  | 
|---|
|  | 985 | if ( (debut <= (int_4)0) || (debut > head->NbMesTot) ) | 
|---|
|  | 986 | { printf(" SuiviReadMesures_Erreur : NumDebut (=%ld) out of range \n", (long)debut); | 
|---|
|  | 987 | return(3); } | 
|---|
|  | 988 |  | 
|---|
|  | 989 | if ( (fin <= (int_4)0) || (fin > head->NbMesTot) ) | 
|---|
|  | 990 | { printf(" SuiviReadMesures_Erreur : NumFin (=%ld) out of range \n", (long)fin); | 
|---|
|  | 991 | return(4); } | 
|---|
|  | 992 |  | 
|---|
|  | 993 | if ( debut > fin) | 
|---|
|  | 994 | { printf(" SuiviReadMesures_Erreur : NumFin (=%ld) < NumDebut(=%ld) \n", | 
|---|
|  | 995 | (long)fin, (long)debut); | 
|---|
|  | 996 | return(5); } | 
|---|
|  | 997 |  | 
|---|
|  | 998 | itsiz = head->RecSize[4] / head->NItem ; | 
|---|
|  | 999 |  | 
|---|
|  | 1000 | fr=to=debut; | 
|---|
|  | 1001 | buff0 = buff; | 
|---|
|  | 1002 |  | 
|---|
|  | 1003 | do { | 
|---|
|  | 1004 |  | 
|---|
|  | 1005 | l1 = (fr-1) / head->NItem; | 
|---|
|  | 1006 | to = (l1+1) * head->NItem; | 
|---|
|  | 1007 | if (to > fin)  nit = fin-fr+1; | 
|---|
|  | 1008 | else nit = to-fr+1; | 
|---|
|  | 1009 | pos = suivfip->OffsetMes + | 
|---|
|  | 1010 | l1 * (head->RecSize[3] + | 
|---|
|  | 1011 | head->NbStars*head->RecSize[4]) + | 
|---|
|  | 1012 | head->RecSize[3] + (numet-1)*head->RecSize[4];; | 
|---|
|  | 1013 | pos += (fr-1 - l1*head->NItem) * itsiz; | 
|---|
|  | 1014 | if (zfseek(suivfip->fcp, (long)pos, SEEK_SET) != 0) | 
|---|
|  | 1015 | { printf(" SuiviReadMesures_Erreur : Pb zfseek() \n"); return(10); } | 
|---|
|  | 1016 | zfread(buff,(size_t)itsiz,nit,suivfip->fcp); | 
|---|
|  | 1017 | fr += nit;  buff += nit * itsiz; | 
|---|
|  | 1018 |  | 
|---|
|  | 1019 | } while (fr <= fin); | 
|---|
|  | 1020 |  | 
|---|
|  | 1021 | if (suivfip->FgSwap)   /*  On byte-swap apres lecture */ | 
|---|
|  | 1022 | SwapSuiviRecord(buff0, suivfip->RecFmt[4], suivfip->Head.FmtSize[4], fin-debut+1); | 
|---|
|  | 1023 |  | 
|---|
|  | 1024 |  | 
|---|
|  | 1025 | return(0); | 
|---|
|  | 1026 | } | 
|---|
|  | 1027 |  | 
|---|
|  | 1028 |  | 
|---|
|  | 1029 |  | 
|---|
|  | 1030 |  | 
|---|
|  | 1031 | /* Nouvelle-Fonction */ | 
|---|
|  | 1032 | int_4 FindSizeofRec(char *fmt) | 
|---|
|  | 1033 |  | 
|---|
|  | 1034 | { | 
|---|
|  | 1035 | int i; | 
|---|
|  | 1036 | char c; | 
|---|
|  | 1037 | int sz; | 
|---|
|  | 1038 |  | 
|---|
|  | 1039 | i= sz = 0; | 
|---|
|  | 1040 | while ( (*fmt) != '\0' ) | 
|---|
|  | 1041 | { | 
|---|
|  | 1042 | c = toupper(*fmt); | 
|---|
|  | 1043 | switch (c) | 
|---|
|  | 1044 | { | 
|---|
|  | 1045 | case 'I' : | 
|---|
|  | 1046 | sz += sizeof(int_4); i++; | 
|---|
|  | 1047 | break; | 
|---|
|  | 1048 | case 'L' : | 
|---|
|  | 1049 | sz += sizeof(int_4); i++; | 
|---|
|  | 1050 | break; | 
|---|
|  | 1051 | case 'S' : | 
|---|
|  | 1052 | sz += sizeof(int_2); i++; | 
|---|
|  | 1053 | break; | 
|---|
|  | 1054 | case 'F' : | 
|---|
|  | 1055 | sz += sizeof(r_4); i++; | 
|---|
|  | 1056 | break; | 
|---|
|  | 1057 | case 'D' : | 
|---|
|  | 1058 | sz += sizeof(r_8); i++; | 
|---|
|  | 1059 | break; | 
|---|
|  | 1060 | default : | 
|---|
|  | 1061 | printf(" FindSizeofRec_Erreur : Code format inconnu : %c \n",c); | 
|---|
|  | 1062 | return(-1); | 
|---|
|  | 1063 | break; | 
|---|
|  | 1064 | } | 
|---|
|  | 1065 | fmt++; | 
|---|
|  | 1066 | } | 
|---|
|  | 1067 |  | 
|---|
|  | 1068 | /*    printf(" FindSizeofRec_debug : N= %d , size= %d \n",i,sz);   */ | 
|---|
|  | 1069 |  | 
|---|
|  | 1070 | return(sz); | 
|---|
|  | 1071 | } | 
|---|
|  | 1072 |  | 
|---|
|  | 1073 | /* Nouvelle-Fonction */ | 
|---|
|  | 1074 | void SwapSuiviEntete(ENTETESUIVI *hp) | 
|---|
|  | 1075 | { | 
|---|
|  | 1076 | int i; | 
|---|
|  | 1077 | Swap_Bytes4( &(hp->FileSize) ); | 
|---|
|  | 1078 | Swap_Bytes4( &(hp->HSize) ); | 
|---|
|  | 1079 | for(i=0; i<5; i++)  Swap_Bytes2( &(hp->RecSize[i]) ); | 
|---|
|  | 1080 | Swap_Bytes2( &(hp->NItem) ); | 
|---|
|  | 1081 | Swap_Bytes4( &(hp->NbStars) ); | 
|---|
|  | 1082 | Swap_Bytes4( &(hp->NbMesTot) ); | 
|---|
|  | 1083 | for(i=0; i<5; i++)  Swap_Bytes2( &(hp->FmtSize[i]) ); | 
|---|
|  | 1084 | Swap_Bytes2(  &(hp->Swap) ); | 
|---|
|  | 1085 | Swap_Bytes2(  &(hp->Type) ); | 
|---|
|  | 1086 | Swap_Bytes4(  &(hp->FgCorrupt) ); | 
|---|
|  | 1087 | } | 
|---|
|  | 1088 |  | 
|---|
|  | 1089 | /* Nouvelle-Fonction */ | 
|---|
|  | 1090 | void SwapSuiviRecord(char* rec, char* fmt, int fmtl, int nr) | 
|---|
|  | 1091 | { | 
|---|
|  | 1092 | int i,j; | 
|---|
|  | 1093 | char *pc; | 
|---|
|  | 1094 |  | 
|---|
|  | 1095 | pc = rec; | 
|---|
|  | 1096 | for( j = 0 ; j < nr ; j++ ) { | 
|---|
|  | 1097 | for ( i = 0 ; i < fmtl ; i++ ) { | 
|---|
|  | 1098 | switch( toupper(fmt[i]) )  { | 
|---|
|  | 1099 | case 'I' : | 
|---|
|  | 1100 | case 'L' : | 
|---|
|  | 1101 | Swap_Bytes4(pc); | 
|---|
|  | 1102 | pc += sizeof(int_4); | 
|---|
|  | 1103 | break; | 
|---|
|  | 1104 | case 'S' : | 
|---|
|  | 1105 | Swap_Bytes2(pc); | 
|---|
|  | 1106 | pc += sizeof(int_2); | 
|---|
|  | 1107 | break; | 
|---|
|  | 1108 | case 'F' : | 
|---|
|  | 1109 | Swap_Bytes4(pc); | 
|---|
|  | 1110 | pc += sizeof(r_4); | 
|---|
|  | 1111 | break; | 
|---|
|  | 1112 | case 'D' : | 
|---|
|  | 1113 | Swap_Bytes8(pc); | 
|---|
|  | 1114 | pc += sizeof(r_8); | 
|---|
|  | 1115 | break; | 
|---|
|  | 1116 | default : | 
|---|
|  | 1117 | printf(" SwapSuiviRecord_Erreur : Code format inconnu : %c \n",fmt[i]); | 
|---|
|  | 1118 | break; | 
|---|
|  | 1119 | } | 
|---|
|  | 1120 | } | 
|---|
|  | 1121 | } | 
|---|
|  | 1122 |  | 
|---|
|  | 1123 | return; | 
|---|
|  | 1124 | } | 
|---|