--- rleda/rleda.c 2003/12/12 18:53:44 1.1.1.1 +++ rleda/rleda.c 2005/02/14 12:15:06 1.4 @@ -1,8 +1,20 @@ -/* $Id: rleda.c,v 1.1.1.1 2003/12/12 18:53:44 brouard Exp $ +/* $Id: rleda.c,v 1.4 2005/02/14 12:15:06 brouard Exp $ $State: Exp $ $Log: rleda.c,v $ - Revision 1.1.1.1 2003/12/12 18:53:44 brouard - Import de rleda + Revision 1.4 2005/02/14 12:15:06 brouard + Garde une variable intitulée numero qui relit les niveaux 2 et 3, tant + en SAS qu'en STATA. + + Revision 1.3 2005/02/08 17:10:08 brouard + Lit le fichier index deux fois pour n'avoir qu'un passage en SAS. + AJoute le proc contents des fichiers créés en fin de run; + + Revision 1.2 2003/12/12 19:08:17 brouard + Les variables ne sont plus toutes écrites en ligne mais avec un retour + à la ligne toutes les 5 variables. + + Revision 1.1.1.1 2003/12/12 18:53:44 brouard + Import de rleda rleda.c @@ -32,16 +44,18 @@ #define ODIRSEPARATOR '/' #endif -char version[]="rleda-0.9 Programme de lecture de fichiers d'index au format LEDA convertis de l'EBCDIC en ASCII "; -char fullversion[]="$Revision: 1.1.1.1 $ $Date: 2003/12/12 18:53:44 $"; +char version[]="rleda-0.9.5 Programme de lecture de fichiers d'index au format LEDA convertis de l'EBCDIC en ASCII "; +char fullversion[]="$Revision: 1.4 $ $Date: 2005/02/14 12:15:06 $"; char line[MAXLINE]; char title[MAXLINE],namevar[MAXLINE], namevara[MAXLINE]; char fileres[FILENAMELENGTH], filereso[FILENAMELENGTH]; char filesas[FILENAMELENGTH]; /* SAS file */ +char filestata[FILENAMELENGTH]; /* STATA file */ +char filestatal[10][FILENAMELENGTH]; /* STATA dictionary files */ char filelog[FILENAMELENGTH]; /* Log file */ -FILE *ficlog, *ficres, *ficpar, *ficparo, *ficparsas; +FILE *ficlog, *ficres, *ficdat, *ficreso, *ficsas, *ficstata, *ficstatal[10]; static unsigned char const ascii_to_ebcdic[] = @@ -227,34 +241,35 @@ void trzb(char *z, char *in) main(int argc, char *argv[]) { - int numlinepar=0; - long nobs, ncar,ncara, ncartes, nn; + int numlinepar=0, ilect=0, firstpass=0, idic[10]={0,0,0,0,0,0,0,0,0,0}; + long nobs=0, ncar=0,ncara=0, ncartes=0, nn=0, nvaris=0; long c; long d; long numlis, ntype; long n, pos; - int level, olevel; + int level, olevel, levelmax; char scar; char s; + char var1[4][10], varn[4][10]; - char pathtot[MAXLINE], path[MAXLINE], optionfile[FILENAMELENGTH], optionfilext[FILENAMEEXTLEN]; - char optionfilefiname[FILENAMELENGTH]; + char pathtot[MAXLINE], path[MAXLINE], indexfile[FILENAMELENGTH], indexfilext[FILENAMEEXTLEN]; + char indexfilefiname[FILENAMELENGTH]; numlinepar=0; if(argc <=1){ - printf("\nEntrez le nom du fichier index binaire : "); + printf("\nEntrez le nom du fichier index binaire (dtrirdex) : "); scanf("%s",pathtot); } else{ strcpy(pathtot,argv[1]); } - split(pathtot,path,optionfile,optionfilext,optionfilefiname); - printf("pathtot=%s,\npath=%s,\noptionfile=%s \noptionfilext=%s \noptionfilefiname=%s\n",pathtot,path,optionfile,optionfilext,optionfilefiname); + split(pathtot,path,indexfile,indexfilext,indexfilefiname); + printf("pathtot=%s,\npath=%s,\nindexfile=%s \nindexfilext=%s \nindexfilefiname=%s\n",pathtot,path,indexfile,indexfilext,indexfilefiname); chdir(path); /* Log file */ - strcat(filelog, optionfilefiname); + strcat(filelog, indexfilefiname); strcat(filelog,".log"); /* */ if((ficlog=fopen(filelog,"w"))==NULL) { printf("Problem with logfile %s\n",filelog); @@ -265,212 +280,325 @@ main(int argc, char *argv[]) fprintf(ficlog,"\nEntrez le nom du fichier d'index: "); fprintf(ficlog,"pathtot=%s\n\ path=%s \n\ - optionfile=%s\n\ - optionfilext=%s\n\ - optionfilefiname=%s\n",pathtot,path,optionfile,optionfilext,optionfilefiname); + indexfile=%s\n\ + indexfilext=%s\n\ + indexfilefiname=%s\n",pathtot,path,indexfile,indexfilext,indexfilefiname); fflush(ficlog); - if((ficpar=fopen(optionfile,"rb"))==NULL) { - printf("Problem with optionfile %s\n",optionfile); - fprintf(ficlog,"Problem with optionfile %s\n",optionfile); - fflush(ficlog); - goto end; - } strcpy(filereso,"o"); - strcat(filereso,optionfilefiname); + strcat(filereso,indexfilefiname); strcat(filereso,".txt"); - if((ficparo=fopen(filereso,"w"))==NULL) { /* opened on subdirectory */ + if((ficreso=fopen(filereso,"w"))==NULL) { /* opened on subdirectory */ printf("Problem with Output resultfile: %s\n", filereso); fprintf(ficlog,"Problem with Output resultfile: %s\n", filereso); fflush(ficlog); goto end; } - fprintf(ficparo,"Log filename:%s\n",filelog); - fprintf(ficparo,"\n%s\n%s",version,fullversion); - fprintf(ficparo,"\nEntrez le nom du fichier d'index: "); - fprintf(ficparo,"pathtot=%s\n\ + fprintf(ficreso,"Log filename:%s\n",filelog); + fprintf(ficreso,"\n%s\n%s",version,fullversion); + fprintf(ficreso,"\nEntrez le nom du fichier d'index: "); + fprintf(ficreso,"pathtot=%s\n\ path=%s \n\ - optionfile=%s\n\ - optionfilext=%s\n\ - optionfilefiname=%s\n",pathtot,path,optionfile,optionfilext,optionfilefiname); - fflush(ficparo); + indexfile=%s\n\ + indexfilext=%s\n\ + indexfilefiname=%s\n",pathtot,path,indexfile,indexfilext,indexfilefiname); + fflush(ficreso); strcpy(filesas,"s"); - strcat(filesas,optionfilefiname); + strcat(filesas,indexfilefiname); strcat(filesas,".sas"); - if((ficparsas=fopen(filesas,"w"))==NULL) { /* opened on subdirectory */ - printf("Problem with Output resultfile: %s\n", filesas); - fprintf(ficlog,"Problem with Output resultfile: %s\n", filesas); - fflush(ficlog); - goto end; - } - fprintf(ficparsas,"*Sortie de rleda version %s *;\n* %s *;\n",version,fullversion); - fprintf(ficparsas,"libname optionfilefiname \"%s\";\n",path); - fprintf(ficparsas,"filename a \"%s\";\n", filesas); - fprintf(ficparsas,"* Ci dessous à modifier *;\n"); - fprintf(ficparsas,"data %s.?? (keep=??);\n",optionfilefiname); - fprintf(ficparsas,"infile a lrecl=500 ;\n"); - fprintf(ficparsas,"input id 1. @; retain numero 0;\n"); - fprintf(ficparsas,""); - fprintf(ficparsas,""); + strcpy(filestata,"s"); + strcat(filestata,indexfilefiname); + strcat(filestata,".do"); printf("Le nom du fichier de sortie est %s\n",filereso); printf("Le nom du fichier SAS de sortie est %s\n",filesas); + printf("Le nom du fichier STATA de sortie est %s\n",filestata); - pos=9; - level=0; - while((c=getc(ficpar)) != EOF){ - ungetc(c,ficpar); - ntype=0;for(n=0;n<2;n++){ c=getc(ficpar); ntype+=(n+(1-n)*256)*ascii_to_ebcdic[c];} - fprintf(ficlog,"ntype=%d ",ntype); -/* printf("ntype=%d ",ntype); */ - switch(ntype){ - case 11 : /* 11*/ - nobs=0; - for(n=0;n<2;n++){ - c=getc(ficpar); - d=(n+(1-n)*256)*ascii_to_ebcdic[c]; - nobs+=d; + for(ilect=1;ilect<=2;ilect++){ + pos=9;nvaris=0 ; + level=0; + printf("Lecture du fichier d index pour la %d fois\n",ilect); + if((ficdat=fopen(indexfile,"rb"))==NULL) { + printf("Problem with binary file %s\n",indexfile); + fprintf(ficlog,"Problem with binary file %s\n",indexfile); + fflush(ficlog); + goto end; + } + if(ilect==2){ + if((ficsas=fopen(filesas,"w"))==NULL) { /* opened on subdirectory */ + printf("Problem with Output SAS file: %s\n", filesas); + fprintf(ficlog,"Problem with Output SAS file: %s\n", filesas); + fflush(ficlog); + goto end; } - fprintf(ficlog,"nobs=%d ",nobs); - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title); - printf(" %s\n", title); - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title); - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title); - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title); - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title); - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title); - break; - case 12: /* 12 */ - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title); - printf(" %s\n", title); - ncartes=0;for(n=0;n<2;n++){ c=getc(ficpar); ncartes+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"ncartes=%d ",ncartes); - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - for(n=0;n<8;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title); - olevel=level; - level=title[0]-48; - printf(" Niveau = %d Colonnes 1 8 = %s\n",level,title); - fprintf(ficparo," Niveau = %d Colonnes 1 8 = %s\n",level,title); - if(level !=0) fprintf(ficparsas,"if id=%d then do;\n",level); - /* fprintf(ficparsas," input @9 "); */ - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - ncara=0;for(n=0;n<2;n++){ c=getc(ficpar); ncara+=(n+(1-n)*256)*ascii_to_ebcdic[c]; } fprintf(ficlog,"ncara=%d ",ncara); - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title); - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - for(n=0;n<2;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title); - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - break; - case 10: /* 10 = 142 ascii*/ - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"%s ",title); - printf(" %s\n", title); - trzb(namevar,title); - ncartes=0;for(n=0;n<2;n++){ c=getc(ficpar); ncartes+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"ncartes=%d ",ncartes); - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - ncara=0;for(n=0;n<2;n++){ c=getc(ficpar); ncara+=(n+(1-n)*256)*ascii_to_ebcdic[c]; } fprintf(ficlog,"ncara=%d ",ncara); - ncar=0;for(n=0;n<2;n++){ c=getc(ficpar); ncar+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"ncar=%d ",ncar); - printf(" %s %d\n",namevar,ncara); - fprintf(ficparo," %s %d\n",namevar,ncara); - ncar=0;for(n=0;n<2;n++){ c=getc(ficpar); ncar+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"ncar=%d ",ncar); - break; - case 14: /* 14 */ - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"%s ",title); - trzb(namevar,title); - printf("%d %20s ",level, namevar); - fprintf(ficparo,"%d %20s ",level, namevar); - fprintf(ficlog,"Variable \"%s\" \n",namevar); - ncartes=0;for(n=0;n<2;n++){ c=getc(ficpar); ncartes+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"ncartes=%d ",ncartes); - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - ncara=0;for(n=0;n<2;n++){ c=getc(ficpar); ncara+=(n+(1-n)*256)*ascii_to_ebcdic[c]; } fprintf(ficlog,"ncara=%d ",ncara); - printf(" %6d",ncara); /* Nombre de caractres */ - fprintf(ficparo," %6d",ncara); /* Nombre de caract res */ - ncar=0;for(n=0;n<2;n++){ c=getc(ficpar); ncar+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"ncar=%d ",ncar); - for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"%s ",title); - trzb(namevara,title); - printf("%10s ", namevara); /* Association */ - fprintf(ficparo,"%10s ", namevara); /* Association */ - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - for(n=0;n<2;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0';fprintf(ficlog,"\"%s\"",title); - printf("%3s", title); /* Brute C ou Calcule R */ - fprintf(ficparo,"%3s", title); /* Brute C ou Calcul e R */ - if(strrchr(title,'C')!= 0 || strrchr(title,'G')!=0){ - if(level!=olevel){ - pos=9; - if(olevel !=0){ - fprintf(ficparsas," output %s.%d;\n",optionfilefiname,olevel); - fprintf(ficparsas," end\n"); + fprintf(ficsas,"*Sortie de rleda version %s *;\n* %s *;\n",version,fullversion); + fprintf(ficsas,"libname %s \"%s\";\n",indexfilefiname,path); + fprintf(ficsas,"filename a \"%s.dat\";\n",indexfilefiname ); + fprintf(ficsas,"* Ci dessous a modifier eventuellement *;\n"); + fprintf(ficsas,"data %s.%s0 (keep=ID)\n",indexfilefiname,indexfilefiname); + fprintf(ficsas," %s.%s%d (keep=%s--%s)\n",indexfilefiname,indexfilefiname,1,var1[1],varn[1]); + idic[1]=0; + for(level=2; level <=levelmax; level++){ + fprintf(ficsas," %s.%s%d (keep=numero %s--%s)\n",indexfilefiname,indexfilefiname,level,var1[level],varn[level]); + idic[level]=0; + } + fprintf(ficsas," ;\n"); + fprintf(ficsas," infile a lrecl=500 ;\n"); + fprintf(ficsas," input id 1. @; retain numero 0; \n"); + fprintf(ficsas,""); + fprintf(ficsas,""); + if((ficstata=fopen(filestata,"w"))==NULL) { /* opened on subdirectory */ + printf("Problem with Output Stata file: %s\n", filestata); + fprintf(ficlog,"Problem with Output Stata: %s\n", filestata); + fflush(ficlog); + goto end; + } + fprintf(ficstata,"*Sortie de rleda version %s *;\n* %s *;\n",version,fullversion); + fprintf(ficstata,"*repertoire %s \"%s\";\n",indexfilefiname,path); + fprintf(ficstata,"* Ci dessous a modifier eventuellement *;\n"); + fprintf(ficstata,"* data %s.%s0 (keep=ID)\n",indexfilefiname,indexfilefiname); + for(level=1; level <=levelmax; level++){ + fprintf(ficstata,"* %s.%s%d (keep=%s--%s)\n",indexfilefiname,indexfilefiname,level,var1[level],varn[level]); + } + fprintf(ficstata,"* ;\n"); + } + while((c=getc(ficdat)) != EOF){ + ungetc(c,ficdat); + ntype=0;for(n=0;n<2;n++){ c=getc(ficdat); ntype+=(n+(1-n)*256)*ascii_to_ebcdic[c];} + fprintf(ficlog,"ntype=%d ",ntype); + /* printf("ntype=%d ",ntype); */ + switch(ntype){ + case 11 : /* 11*/ + nobs=0; + for(n=0;n<2;n++){ + c=getc(ficdat); + d=(n+(1-n)*256)*ascii_to_ebcdic[c]; + nobs+=d; + } + fprintf(ficlog,"nobs=%d ",nobs); + nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); + for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title); + printf(" %s\n", title); + nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); + nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); + for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title); + nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); + for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title); + nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); + for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title); + nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); + for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title); + nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); + for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title); + break; + case 12: /* 12 */ + nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); + for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title); + printf(" %s\n", title); + ncartes=0;for(n=0;n<2;n++){ c=getc(ficdat); ncartes+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"ncartes=%d ",ncartes); + nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); + for(n=0;n<8;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"\"%s\" ",title); + olevel=level; + level=title[0]-48; + printf(" Niveau = %d Colonnes 1 8 = %s\n",level,title); + fprintf(ficlog," Niveau = %d Colonnes 1 8 = %s\n",level,title); + fprintf(ficreso," Niveau = %d Colonnes 1 8 = %s\n",level,title); + if(level ==0){ + if(ilect==2){ + fprintf(ficsas," if id=%d then do;\n",level); + /* fprintf(ficstata,"* if id=%d then do;\n",level); */ + /* fprintf(ficsas," input @9 "); */ } - if(level !=1) fprintf(ficparsas,";\n else if id=%d then do;\n",level); - fprintf(ficparsas," input @9 "); - olevel=level; } - printf(" %d-%d", pos, pos+(ncara-1)); - fprintf(ficparo," %d-%d", pos, pos+(ncara-1)); - for(n=0;n=5) { + if(ilect==2){ + fprintf(ficsas,"\n ") ; + fprintf(ficstatal[level],"\n ") ; + } + nvaris=0 ; + } } - namevar[n]='\0'; - fprintf(ficparsas, " %s $%d.", namevar, ncara); - pos+=ncara; + nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); + nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); + nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); + nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); + for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0';fprintf(ficlog,"%s ",title); + trzb(namevar,title); + printf(" %10s\n", namevar); /* format */ + fprintf(ficreso," %10s", namevar); /* format */ + nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); + for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0';fprintf(ficlog,"%s ",title); + nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); + break; + default: fprintf(ficlog,"Warning ntype=%d cas non prvu, voir les fichiers sources",ntype); + nobs=0;for(n=0;n<2;n++){ c=getc(ficdat); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); + for(n=0;n<30;n++){ c=getc(ficdat); title[n]=c;} title[n]='\0'; fprintf(ficlog,"%s ",title); + printf(" %s\n", title); } - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0';fprintf(ficlog,"%s ",title); - trzb(namevar,title); - printf(" %10s\n", namevar); /* format */ - fprintf(ficparo," %10s", namevar); /* format */ - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0';fprintf(ficlog,"%s ",title); - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - break; - default: fprintf(ficlog,"Warning ntype=%d cas non prvu, voir les fichiers sources",ntype); - nobs=0;for(n=0;n<2;n++){ c=getc(ficpar); nobs+=(n+(1-n)*256)*ascii_to_ebcdic[c];} fprintf(ficlog,"nobs=%d ",nobs); - for(n=0;n<30;n++){ c=getc(ficpar); title[n]=c;} title[n]='\0'; fprintf(ficlog,"%s ",title); - printf(" %s\n", title); - } - n=0; - while((c=getc(ficpar)) !='\r'){ - nn= n % ncara; - title[nn]=c; - if(nn==ncara-1){ - title[nn+1]='\0'; - fprintf(ficlog," \"%s\"",title); - printf(" \"%s\"",title); - fprintf(ficparo," \"%s\"",title); - n=n+1; - }else{ - n=n+1; + n=0; + while((c=getc(ficdat)) !='\r'){ + if(ncara != 0) + nn= n % ncara; + else + nn=0; + title[nn]=c; + if(nn==ncara-1){ + title[nn+1]='\0'; + fprintf(ficlog," \"%s\"",title); + printf(" \"%s\"",title); + fprintf(ficreso," \"%s\"",title); + n=n+1; + }else{ + n=n+1; + } } + if(c=='\r') + if((c=getc(ficdat))=='\n'); + else ungetc(c,ficdat); + fprintf(ficlog,"\n"); + fprintf(ficreso,"\n"); + } /* End of read loop */ + fclose(ficdat); + } /* End loop ilect */ + + fprintf(ficsas," ;\n output %s.%s%d;\n end;\n else input;\nrun;\n",indexfilefiname,indexfilefiname,level); + fprintf(ficstatal[level],"\n}\n"); + for(level=0; level <=levelmax; level++){ + fprintf(ficsas,"proc contents data=%s.%s%d;run;\n",indexfilefiname,indexfilefiname,level); + /* fprintf(ficstata,"*proc contents data=%s.%s%d;run;\n",indexfilefiname,indexfilefiname,level); */ + if(level==2){ + fprintf(ficstata,"clear\n quiet infile using s%s-dict%d if id==\"%d\"\n gen long numero=_n\n sort numero\nsave %s%d,replace\n",indexfilefiname,level,level,indexfilefiname,level); } - if(c=='\r') - if((c=getc(ficpar))=='\n'); - else ungetc(c,ficpar); - fprintf(ficlog,"\n"); - fprintf(ficparo,"\n"); - } - fprintf(ficparsas,";\n output %s%d;\n end;\n else input;\n run;",optionfilefiname,level); - fclose(ficparsas); + else if(level==3){ + fprintf(ficstata,"clear\n quiet infile using s%s-dict%d if id != \"1\"\n gen long numero=1 if id==\"2\"\n replace numero=sum(numero)\n sort numero\n",indexfilefiname,level); + fprintf(ficstata,"* merge numero using %s2\n* drop numero\n drop if id != \"3\"\nsave %s%d,replace\n",indexfilefiname,indexfilefiname,level); + } + } + fclose(ficsas); + fclose(ficstata); printf("Le nom du fichier de debug est %s\n",filelog); printf("Le nom du fichier du format de sortie est %s\n",filereso); printf("Le nom du fichier SAS de sortie est %s\n",filesas); - fclose(ficpar); - fclose(ficparo); + printf("Le nom du fichier STATA de sortie est %s\n",filestata); + for(level=1;level<=levelmax;level++){ + fclose(ficstatal[level]); + printf("Le nom du fichier STATA dictionnaire niveau %d de sortie est %s\n",level,filestatal[level]); + } + fclose(ficreso); fclose(ficlog); exit(0); end: