1 | #include "diabolo.h"
|
---|
2 | #include "fichier.h"
|
---|
3 |
|
---|
4 | #define long_maxi_fich_tele 20000L
|
---|
5 |
|
---|
6 | void renomme_fichier(int ncar,int numscan,char *nom_source);
|
---|
7 |
|
---|
8 | extern F_entete *E;
|
---|
9 | extern F_block_desc *BD;
|
---|
10 | extern F_block_param *BP;
|
---|
11 |
|
---|
12 | extern char *dossier_date; // dossier date pour creer le dossier ou ranger les data telescope
|
---|
13 | extern char * nom_du_fichier;
|
---|
14 | extern char * message_sommaire;
|
---|
15 | extern char * fichiers_perdus;
|
---|
16 |
|
---|
17 | //------------------------------------------------------------------------------------------------------
|
---|
18 | //------------------------------------------------------------------------------------------------------
|
---|
19 | //---------------------- recherche des données du telescope ----------------------
|
---|
20 | //------------------------------------------------------------------------------------------------------
|
---|
21 | //------------------------------------------------------------------------------------------------------
|
---|
22 |
|
---|
23 |
|
---|
24 | //-------------------------------------------------------------------------------------
|
---|
25 | // ------------- -0- utilitaire commun -------------------------
|
---|
26 | //-------------------------------------------------------------------------------------
|
---|
27 |
|
---|
28 | //----------------------- renomme le fichier ----------------------------
|
---|
29 | // ********************* renomme les fichier *********************
|
---|
30 |
|
---|
31 | // fabrique le nouveau nom de fichier
|
---|
32 | // ss[0] = longueur du string=29
|
---|
33 | // ss[1..18] = heure et date
|
---|
34 | // ss[19] = underscore
|
---|
35 | // ss[20..29] = numscan et nom de la source
|
---|
36 |
|
---|
37 |
|
---|
38 | void renomme_fichier(int ncar,int numscan,char *nom_source)
|
---|
39 | {
|
---|
40 | char nom_pascal[50],ss[256];
|
---|
41 | Tfenetre ptf;
|
---|
42 | FSSpec file;
|
---|
43 | int i;
|
---|
44 |
|
---|
45 | nom_source[30]=0;
|
---|
46 |
|
---|
47 | ecritD(fenetre_fichier,f_comment,"scan numero %d source : %s ",numscan,nom_source);
|
---|
48 | // printf("scan numero %d source : %s \n",numscan,nom_source);
|
---|
49 |
|
---|
50 | if(nom_du_fichier[18]!='_') return;
|
---|
51 | if(ncar==4) sprintf(nom_du_fichier+19,"%d-%s",numscan+10000,nom_source);
|
---|
52 | else sprintf(nom_du_fichier+19,"%d-%s",numscan+100000,nom_source);
|
---|
53 | nom_du_fichier[18]='_';nom_du_fichier[19]='s';nom_du_fichier[29]=0;
|
---|
54 | for(i=0;i<29;i++) if(nom_du_fichier[i]==' ') nom_du_fichier[i]='_'; // enleve les blancs
|
---|
55 | // printf(" nouveau nom : .................. %s \n",nom_du_fichier);
|
---|
56 | strcpy(ss+1,nom_du_fichier);ss[0]=29;
|
---|
57 |
|
---|
58 |
|
---|
59 | if(fenetre(fichier_dia2_1))
|
---|
60 |
|
---|
61 | {
|
---|
62 | ss[1]='a';
|
---|
63 | #ifdef lire_les_data_telescope_IRAM
|
---|
64 | ss[1]='t';
|
---|
65 | #endif
|
---|
66 | ptf=infos(fichier_dia2_1);
|
---|
67 |
|
---|
68 | strcpy(nom_pascal+1,ptf->titre);*nom_pascal=strlen(nom_pascal+1);
|
---|
69 | FSMakeFSSpec(ptf->dossier.volume,ptf->dossier.dossier,(ConstStr255Param)nom_pascal,&file);
|
---|
70 | FSpRename(&file,(ConstStr255Param)ss);
|
---|
71 | position(fichier_dia2_1,0L);
|
---|
72 | ecritF(fichier_dia2_1,(long)E->long_entete,E);
|
---|
73 |
|
---|
74 | if(fenetre(fichier_dia2_2))
|
---|
75 | {
|
---|
76 | ptf=infos(fichier_dia2_2);
|
---|
77 | FSMakeFSSpec(ptf->dossier.volume,ptf->dossier.dossier,(ConstStr255Param)nom_pascal,&file);
|
---|
78 | FSpRename(&file,(ConstStr255Param)ss);
|
---|
79 | position(fichier_dia2_2,0L);
|
---|
80 | ecritF(fichier_dia2_2,(long)E->long_entete,E);
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | if(fenetre(fichier_arch_1))
|
---|
85 |
|
---|
86 | {
|
---|
87 | ss[1]='h';
|
---|
88 | ptf=infos(fichier_arch_1);
|
---|
89 |
|
---|
90 | strcpy(nom_pascal+1,ptf->titre);*nom_pascal=strlen(nom_pascal+1);
|
---|
91 | FSMakeFSSpec(ptf->dossier.volume,ptf->dossier.dossier,(ConstStr255Param)nom_pascal,&file);
|
---|
92 | FSpRename(&file,(ConstStr255Param)ss);
|
---|
93 |
|
---|
94 | if(fenetre(fichier_arch_2))
|
---|
95 | {
|
---|
96 | ptf=infos(fichier_arch_2);
|
---|
97 | FSMakeFSSpec(ptf->dossier.volume,ptf->dossier.dossier,(ConstStr255Param)nom_pascal,&file);
|
---|
98 | FSpRename(&file,(ConstStr255Param)ss);
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | }
|
---|
103 |
|
---|
104 |
|
---|
105 | //-------------------------------------------------------------------------------------
|
---|
106 | // ------------- -1- r i e n -------------------------
|
---|
107 | //-------------------------------------------------------------------------------------
|
---|
108 |
|
---|
109 |
|
---|
110 | #if (!defined (lire_les_donnees_POM2) && !defined (lire_les_noms_sources_IRAM) && !defined (lire_le_numero_de_scan_iram) )
|
---|
111 | void lit_data_telescope() {}
|
---|
112 |
|
---|
113 | #endif
|
---|
114 |
|
---|
115 | //-------------------------------------------------------------------------------------
|
---|
116 | // ------------- -1- P O M 2 -------------------------
|
---|
117 | //-------------------------------------------------------------------------------------
|
---|
118 |
|
---|
119 |
|
---|
120 | /* lit sur la RS232 et sauve le commentaire si besoin */
|
---|
121 |
|
---|
122 | #ifdef lire_les_donnees_POM2
|
---|
123 |
|
---|
124 |
|
---|
125 |
|
---|
126 | void ecrit_don_telescope(char *comment,int i); // ecrit le commentaire de longueur i
|
---|
127 |
|
---|
128 | #define temps_d_attente 20
|
---|
129 |
|
---|
130 |
|
---|
131 | void lit_data_telescope(void)
|
---|
132 | {
|
---|
133 | char comment[10000];
|
---|
134 | int i,numscan;
|
---|
135 | i=0;
|
---|
136 | // printf("cherche les commentaires sur RS232 : ");
|
---|
137 | while ( (i<8000) && (litRS(port_A,comment+i,finRS_cr,temps_d_attente,1)==1) ) i=strlen(comment);
|
---|
138 | if(i>9000) erreur(" comment trop long dans fichier_telescope données POM2");
|
---|
139 | if(i) {
|
---|
140 | char ss[200];
|
---|
141 | int j=0,k,q=0;
|
---|
142 | // printf("lit commentaire %dcara: ",i);
|
---|
143 | while ( (j<i) && comment[j] )
|
---|
144 | {
|
---|
145 | while( (j<i) && (comment[j]<20) ) j++;
|
---|
146 | k=0;
|
---|
147 | while( (k<100) && (j<i) && (comment[j]>20) ) {ss[k]=comment[j];k++; j++;}
|
---|
148 | ss[k]=0;j++;
|
---|
149 | // if(q<1) printf(" %s\n",ss);
|
---|
150 | q++;
|
---|
151 | }
|
---|
152 | ecrit_don_telescope(comment,i);
|
---|
153 | numscan=myatof(comment+1);
|
---|
154 | renomme_fichier(5,numscan,comment+7);
|
---|
155 | }
|
---|
156 | // printf("\n");
|
---|
157 | }
|
---|
158 |
|
---|
159 |
|
---|
160 |
|
---|
161 | void ecrit_don_telescope(char *comment,int i) // ecrit le commentaire de longueur i
|
---|
162 | {
|
---|
163 | i=(i/4+1)*4;
|
---|
164 | BD->n_ligne_don=i;
|
---|
165 | BD->change=10;
|
---|
166 | BD->bololut=0;
|
---|
167 | if(fenetre(fichier_dia2_1))
|
---|
168 | {
|
---|
169 | ecritF(fichier_dia2_1,sizeof(F_block_desc),BD); // ecrit l'entete partielle
|
---|
170 | ecritF(fichier_dia2_1,i,comment); // ecrit le texte du block commentaire
|
---|
171 | if(fenetre(fichier_dia2_2))
|
---|
172 | {
|
---|
173 | ecritF(fichier_dia2_2,sizeof(F_block_desc),BD); // ecrit l'entete partielle
|
---|
174 | ecritF(fichier_dia2_2,i,comment); // ecrit le texte du block commentaire
|
---|
175 | }
|
---|
176 | }
|
---|
177 | }
|
---|
178 |
|
---|
179 |
|
---|
180 | #endif
|
---|
181 |
|
---|
182 | //-------------------------------------------------------------------------------------
|
---|
183 | // ------------- -2- IRAM 30m juste le numero de scan ---------
|
---|
184 | //-------------------------------------------------------------------------------------
|
---|
185 |
|
---|
186 | #ifdef lire_le_numero_de_scan_iram
|
---|
187 |
|
---|
188 |
|
---|
189 | void lit_data_telescope(void)
|
---|
190 | {
|
---|
191 | static VDos data_telescope;
|
---|
192 | static int index=1;
|
---|
193 | static char nomfich[40];
|
---|
194 |
|
---|
195 | char ss[100];
|
---|
196 |
|
---|
197 |
|
---|
198 | //printf("lit_data_telescope et copie dans %s\n",nom_dossier);
|
---|
199 |
|
---|
200 | litD(fenetre_fichier,f_don_tele,ss);
|
---|
201 | strcat(ss,":info");
|
---|
202 | if( (strlen(ss)>2) && (*ss!='/') )
|
---|
203 | {
|
---|
204 | data_telescope=cherchedossier(ss);
|
---|
205 | if(!data_telescope.volume) {printf("erreur de dossier data telescope \n");return;}
|
---|
206 | fixedossier(data_telescope);
|
---|
207 | ouvrirT(0,0,"copied_last");
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 | #endif
|
---|
212 |
|
---|
213 |
|
---|
214 | //-------------------------------------------------------------------------------------
|
---|
215 | // ------------- -2- IRAM 30m nom des sources + donnees eventuelles ---------
|
---|
216 | //-------------------------------------------------------------------------------------
|
---|
217 |
|
---|
218 |
|
---|
219 |
|
---|
220 |
|
---|
221 | #ifdef lire_les_noms_sources_IRAM
|
---|
222 |
|
---|
223 | void ouvre_et_lit(VDos dd,char * nomfich); // bonfich est un string pascal termine par un zero
|
---|
224 | int deplace_un_fichier_telescope(VDos d1,char *nomfich);
|
---|
225 | int cherche_fich(VDos dd,char *nomfich);
|
---|
226 |
|
---|
227 |
|
---|
228 |
|
---|
229 | void lit_data_telescope(void)
|
---|
230 | {
|
---|
231 | VDos data_telescope;
|
---|
232 | char nomfich[40],ss[100];
|
---|
233 |
|
---|
234 | data_telescope.volume=0;
|
---|
235 | //printf("lit_data_telescope dans %s et les deplace dans ...%s \n",ss,dossier_date);
|
---|
236 |
|
---|
237 | litD(fenetre_fichier,f_don_tele,ss);
|
---|
238 | if( (strlen(ss)>2) && (*ss!='/') ) data_telescope=cherchedossier(ss);
|
---|
239 | if(!data_telescope.volume) return;
|
---|
240 | //printf("lit_data_telescope dans %s et les deplace dans ...%s \n",ss,dossier_date);
|
---|
241 |
|
---|
242 | while(1)
|
---|
243 | {
|
---|
244 | if(!cherche_fich(data_telescope,nomfich)) return; // pas de fichier a lire
|
---|
245 | // printf("je trouve le fichier telescope %s \n",nomfich+1);
|
---|
246 | ouvre_et_lit(data_telescope,nomfich);
|
---|
247 | if(deplace_un_fichier_telescope(data_telescope,nomfich))
|
---|
248 | {printf("erreur dans deplace un fichier\n");return;} // return si erreur
|
---|
249 | // printf("je deplace le fichier %s \n",nomfich+1);
|
---|
250 | }
|
---|
251 | }
|
---|
252 |
|
---|
253 |
|
---|
254 |
|
---|
255 | // Cherche le premier fichier du dossier (index=1)
|
---|
256 | // si oui, renvoie 1 et le nom du fichier dans nomfich (string pascal avec un zero a la fin)
|
---|
257 | // si pas de fichier: renvoie 0
|
---|
258 |
|
---|
259 | int cherche_fich(VDos dd,char * nomfich)
|
---|
260 | {
|
---|
261 | HFileParam pb;
|
---|
262 | pb.ioCompletion=0L;
|
---|
263 | pb.ioFDirIndex=1; // index commence à 1
|
---|
264 | pb.ioNamePtr=(StringPtr)nomfich;
|
---|
265 | pb.ioVRefNum=dd.volume;
|
---|
266 | pb.ioDirID=dd.dossier;
|
---|
267 | if(PBHGetFInfo( (HParmBlkPtr) &pb,0)) return(0);
|
---|
268 | //if( ( (pb.ioFlFndrInfo.fdType!='DATA') et (pb.ioFlFndrInfo.fdType!='TEXT') ) ou (*nomfich!=13) ) return(-1);
|
---|
269 | nomfich[*nomfich+1]=0; // nomfich est un string pascal avec zero à la fin
|
---|
270 | //printf("index=%d : un bon fichier : %s \n",index,nomfich+1);
|
---|
271 | return(1);
|
---|
272 | }
|
---|
273 |
|
---|
274 |
|
---|
275 |
|
---|
276 | void ouvre_et_lit(VDos dd,char * nomfich) // nomfich est un string pascal termine par un zero
|
---|
277 | {
|
---|
278 | short err;
|
---|
279 | short data;
|
---|
280 | FSSpec file;
|
---|
281 | char *buf;
|
---|
282 | char source[40];
|
---|
283 | int i;
|
---|
284 | long lg;
|
---|
285 | int numscan,subscan,alire;
|
---|
286 | int monscan;
|
---|
287 | char ss[255];
|
---|
288 |
|
---|
289 | //-- recherche numscan et subscan
|
---|
290 | monscan=0;
|
---|
291 | if( (nom_du_fichier[18]=='_') && (nom_du_fichier[21]!='a') ) // un fichier scan en cours est ouvert
|
---|
292 | {
|
---|
293 | monscan=myatof(nom_du_fichier+20);
|
---|
294 | // printf(" monscan=%d \n",monscan);
|
---|
295 | }
|
---|
296 |
|
---|
297 | numscan=myatof(nomfich+1);
|
---|
298 | subscan=myatof(nomfich+11);
|
---|
299 |
|
---|
300 |
|
---|
301 | switch(nomfich[6])
|
---|
302 | {
|
---|
303 | case 'h' :
|
---|
304 | if(monscan && (monscan != numscan) ) subscan=3000;
|
---|
305 | else {
|
---|
306 | if(subscan!=gg->compte_fichiers_th+1)
|
---|
307 | {
|
---|
308 | printf(" erreur fichier th: ancien=%d lit %d \n",gg->compte_fichiers_th,subscan);
|
---|
309 | sprintf(ss," -th%d",gg->compte_fichiers_th+1);ajoute_sommaire(ss);
|
---|
310 | }
|
---|
311 | gg->compte_fichiers_th=subscan;
|
---|
312 | subscan+=1000;
|
---|
313 | }
|
---|
314 |
|
---|
315 | break;
|
---|
316 |
|
---|
317 | case 'p' :
|
---|
318 | if(monscan && (monscan != numscan) ) subscan=3000;
|
---|
319 | else {
|
---|
320 | if(subscan!=gg->compte_fichiers_tp+1)
|
---|
321 | {
|
---|
322 | printf(" erreur fichier tp: ancien=%d lit %d \n",gg->compte_fichiers_tp,subscan);
|
---|
323 | sprintf(ss," -tp%d",gg->compte_fichiers_th+1);ajoute_sommaire(ss);
|
---|
324 | }
|
---|
325 | gg->compte_fichiers_tp=subscan;
|
---|
326 | subscan+=2000;
|
---|
327 | }
|
---|
328 |
|
---|
329 | break;
|
---|
330 |
|
---|
331 | default : subscan=3000;
|
---|
332 | break;
|
---|
333 | }
|
---|
334 |
|
---|
335 | //printf("lecture fichier type %c%c, numscan=%d subscan=%d \n",nomfich[5],nomfich[6],numscan,subscan);
|
---|
336 |
|
---|
337 | if(subscan==3000)
|
---|
338 | {
|
---|
339 | ajoute_sommaire2(nomfich+1);
|
---|
340 | printf(" fichier *s d'un autre scan \n",nomfich+1);
|
---|
341 | return;
|
---|
342 | }
|
---|
343 |
|
---|
344 | alire=0;
|
---|
345 | if(subscan==1001) alire=1;
|
---|
346 |
|
---|
347 | #ifdef lire_les_data_telescope_IRAM
|
---|
348 | alire=2;
|
---|
349 | #endif
|
---|
350 |
|
---|
351 | if(alire)
|
---|
352 | {
|
---|
353 | FSMakeFSSpec(dd.volume,dd.dossier,(ConstStr255Param)nomfich,&file);
|
---|
354 | if ((err=FSpOpenDF(&file,0,&data))!=0)
|
---|
355 | {
|
---|
356 | son(1); printf("\n pas possible de lire le fichier données telescope :");
|
---|
357 | select(printf_ref);
|
---|
358 | return;
|
---|
359 | }
|
---|
360 |
|
---|
361 | lg=long_maxi_fich_tele-5;
|
---|
362 | if(alire==1) lg=1100;
|
---|
363 | buf=malloc(long_maxi_fich_tele+16);
|
---|
364 | strcpy(buf,nomfich+1); //buff contient le nom du fichier (20 octets) suivit du contenu du fichier
|
---|
365 | FSRead(data,&lg,buf+16);
|
---|
366 | FSClose(data); // lit le fichier th ou tp de donnees telescope
|
---|
367 | printf("lecture fichier type %c%c, numscan=%d subscan=%d : lit %d caracteres \n",nomfich[5],nomfich[6],numscan,subscan,lg);
|
---|
368 |
|
---|
369 | for(i=0;i<38;i++) source[i]=buf[i+1052+16];source[38]=0; // lit le nom de la source
|
---|
370 | if(subscan==1001) renomme_fichier(4,numscan,source); // ne renomme le fichier que pour le th.001
|
---|
371 |
|
---|
372 | #ifdef lire_les_data_telescope_IRAM
|
---|
373 |
|
---|
374 | if(lg>long_maxi_fich_tele-10)
|
---|
375 | {
|
---|
376 | son(1);
|
---|
377 | printf("\nle fichier données telescope est trops gros \n");
|
---|
378 | printf("il depasse la taille maximum de %d octets \n",long_maxi_fich_tele);
|
---|
379 | select(printf_ref);
|
---|
380 | }
|
---|
381 |
|
---|
382 | lg=(lg/4+1)*4 +16 ;
|
---|
383 | BD->n_ligne_don=lg;
|
---|
384 | BD->change=subscan;
|
---|
385 | BD->bololut=0;
|
---|
386 | if(fenetre(fichier_dia2_1))
|
---|
387 | {
|
---|
388 | position(fichier_dia2_1,fin_f);
|
---|
389 | ecritF(fichier_dia2_1,sizeof(F_block_desc),BD); // ecrit l'entete partielle
|
---|
390 | ecritF(fichier_dia2_1,lg,buf); // ecrit le texte du block data
|
---|
391 | if(fenetre(fichier_dia2_2))
|
---|
392 | {
|
---|
393 | position(fichier_dia2_2,fin_f);
|
---|
394 | ecritF(fichier_dia2_2,sizeof(F_block_desc),BD); // ecrit l'entete partielle
|
---|
395 | ecritF(fichier_dia2_2,lg,buf); // ecrit le texte du block data
|
---|
396 | }
|
---|
397 | }
|
---|
398 | #endif
|
---|
399 |
|
---|
400 | free(buf);
|
---|
401 | }
|
---|
402 | }
|
---|
403 |
|
---|
404 |
|
---|
405 |
|
---|
406 |
|
---|
407 | int deplace_un_fichier_telescope(VDos d1,char *nomfich) // retourne 0 si tout va bien
|
---|
408 | {
|
---|
409 | char dossier2[100],nom_dossier_tele[100],dossier_complet[150];
|
---|
410 | FSSpec file1,file2;
|
---|
411 | VDos d2;
|
---|
412 | DateTimeRec date;
|
---|
413 |
|
---|
414 | FSMakeFSSpec(d1.volume,d1.dossier,(ConstStr255Param)nomfich,&file1); // le fichier source
|
---|
415 |
|
---|
416 | // fabrique le dossier destination
|
---|
417 | GetTime(&date);
|
---|
418 |
|
---|
419 | strcpy(nom_dossier_tele+1,"tele");
|
---|
420 | strcat(nom_dossier_tele+1,dossier_date);
|
---|
421 | *nom_dossier_tele=strlen(nom_dossier_tele+1);
|
---|
422 | litD(fenetre_fichier,f_d2,dossier2); // le meme dossier que le second fichier de data DIA2
|
---|
423 | if( (strlen(dossier2)<3) ou (*dossier2=='/') ) return(1);
|
---|
424 | strcat(dossier2,":telescope");
|
---|
425 | d2=cherchedossier(dossier2); // cree le dossier telescope s'il n'existe pas
|
---|
426 | //printf("deplace le fichier %s dans le dossier %s // %s \n",nomfich+1,dossier2,nom_dossier_tele+1);
|
---|
427 |
|
---|
428 | sprintf(dossier_complet,"%s:%s",dossier2,nom_dossier_tele+1);
|
---|
429 | d2=cherchedossier(dossier_complet); // cree le dossier du jour s'il n'existe pas
|
---|
430 | //printf("dossiercomplet O.K. \n");
|
---|
431 | d2=cherchedossier(dossier2); // le dossier parent
|
---|
432 | if(!d2.volume) return(1);
|
---|
433 | //printf("dossier2 O.K. \n");
|
---|
434 | FSMakeFSSpec(d2.volume,d2.dossier,(ConstStr255Param)nom_dossier_tele,&file2); // le dossier destination
|
---|
435 | //printf(" fichier %s copie dans dossier %s \n",nomfich+1,nom_dossier_tele+1);
|
---|
436 | return(FSpCatMove(&file1,&file2));
|
---|
437 | }
|
---|
438 |
|
---|
439 |
|
---|
440 |
|
---|
441 |
|
---|
442 | #endif
|
---|
443 |
|
---|