## /***************************************************************/ ## /* */ ## /* gnumdata.awk - (gH) 1998 : */ ## /* */ ## /* +================================================+ */ ## /* + + */ ## /* + gestion de donnees + */ ## /* + via un fichier d'actions + */ ## /* + + */ ## /* +================================================+ */ ## /* */ ## /* */ ## /* fonctionne avec gawk 2.15 ou supérieur */ ## /* */ ## /* syntaxe : gnudat nom_de_fichier | help | aide */ ## /* */ ## /* attention : requiert un fichier de type stm */ ## /* voir l'aide pour la liste des actions */ ## /* */ ## /***************************************************************/ ## /* */ ## /* Auteur */ ## /* */ ## /* gilles.hunault@univ-angers.fr */ ## /* http://www.info.univ-angers.fr/pub/gh/gh.html */ ## /* */ ## /* Contributions */ ## /* */ ## /* beaujard@jouy.inra.fr */ ## /* dpithon@ */ ## /* */ ## /***************************************************************/ # # ## Organisation du programme # # # # Partie Begin : checkOs # # defact # # initvarglob # # litStm # # Partie Données : positions # # descAdcol # # changelen # # decritcol # # Partie End : rescalc # # ecritsor # # makedbf # # makesas # # makeplt # # # # # # # # # # ???? tester la validité du numéro de colonne # # ???? " le nom de l'action N (au lieu de NBVAL etc.) # # # # ???? détection du format des données pour recopie ? # # ???? définir le type des colonnes pour le cadrage # # # # # # # # # # Langage d'Analyse de Structure, Validation et # # de Calcul pour des MND # # # # Fichier .dat + Fichier .stm # # données structure et actions # # # # # # données : un # en debut de ligne est un commentaire # # ce qui suit un # dans une ligne est un commentaire # # données au format sdf (notion de colonne bien cadrée) # # on doit etre capable de retrouver une colonne de donnée # # a partir de la premiere qui n'est pas un commentaire # # # BEGIN { os = checkos() ; # test du système d'exploitation printf "\n gnumdata : GNU Mastering Data -- (gH) version 2.1 ; " if (os=="DOS") { print " running under Dos " } else { print " running under Unix" } # awkward (!) to get the character # but prevents from fooling some editors carCmt = sprintf("%c",035) ## # ## # ## # A.01 - Gestion des noms de fichiers # ## # ## # flog = "gnumdata.log" ; # fichier de trace des actions fsor = "gnumdata.sor" ; # fichier des résultats fcal = "gnumdata.cal" ; # fichier des calculs # récupération du "basename" (partie avant le point) # et définition des noms de fichiers de sortie noment = ARGV[1] ; # fichier d'entrée ip = index(noment,".") if (ip>0) { basename = substr(noment,1,ip) ; nomorg = substr(noment,1,ip-1) } else { nomorg = noment basename = noment"." } # fin de si fdat = noment ; fstm = basename"stm" ; fsas = basename"sas" fdbf = basename"dbf" ; fsdf = basename"sdf" ; fstr = basename"str" fplt = basename"plt" ; fdag = basename"dag" ; fgif = basename"gif" print "\n Analysis/Management of the file " fdat " via " fstm print "\n ANALYSIS/MANAGEMENT OF THE FILE " fdat " VIA " fstm > flog print " -- " strftime("%d/%m/%Y %H:%M ",systime()) "\n" > flog ## # ## # ### A.02 - Définition du nom des actions # ## colonne 30 pour tri alpha des actions # ## 42 pour type action # ## # ## # defAct() ## # ## # ### A.03 - Parcours du fichier paramètre # ## # ## # initVarGlob() ; # on initialise certaines variables globales litStm() ; # on lit le fichier structure des actions # si le fichier structure n'est pas u, nblstm est nul if (nblstm==0) { print "\n -- ATTENTION ! FILE " fstm " NOT FOUND. --\n" print "\n -- ATTENTION ! FILE " fstm " NOT FOUND. --\n" > flog } # fin si nbl = -1 # nombre de lignes de donnnées # on met 1 pour avoir la ligne de format en 0 et donc bien commencer # en 1 la première ligne de données linrul = "---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----" linrul = linrul"0---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----" olinrul = "....+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9....+...." olinrul = olinrul"0...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9....+...." } # fin du Begin # ###################################################################################### ## # ## # ### A.07 - Passage en revue du fichier des données # ## # ## # # on découpe le fichier de départ en mots selon le format # de la première ligne qui n'est pas un commentaire { # traitement de chaque ligne de données pcnn = substr($1" ",1,1) if (pcnn==carCmt) { # on recopie les commentaires print $0 > fsor } else { # traitement véritable de la ligne nbl++ ; # gestion du nombre de lignes # affichage éventuel datadbg = 1 ; # avec affichage des données au fur et à mesure datadbg = 0 ; # sans affichage des données au fur et à mesure if (datadbg==1) { print sprintf("%3d",nbl) " : " $0 if ((nbl/5)==int(nbl/5)) { printf " ? " ; getline pomme < "-" } } # fin si # la première ligne qui n'est pas un commentaire déclenche l'analyse du cadrage if (nbl== 0) { if (optRuler==1) { print "# old format" > fsor ; print "#"$0 > fsor } # fin si optRuler==1 $0 = " " $0 " " ; ll = length($0) printf " POSITIONS OF THE COLUMNS IN THE INPUT FILE \n" >> flog positions() ; lastic = ic if (nbaCre+nbaCst) { print "\n TO YOUR REQUEST, THESE COLUMNS ARE ADDED TO THE INPUT FILE " >> flog $0 = $0 " " chtoAd ; descAdCol() ; } ; # fin de si (nbcol>nbm) if (nbaLen>0) { print " TO YOUR REQUEST, THESE COLUMNS WILL CHANGE LENGTH " >> flog changeLen() ; } # fin si nbaLen>0 decritCol() ; # description de toutes les colonnes } else { # si nbl n'est pas égal à zéro if (NF>nbcol) { nbcol = NF } if (nbl<=5) { oldData[nbl] = $ 0 } # on rajoute les valeurs constantes crées newl = $0 while (length(newl)0) { if ((nbl/pluspar)==int(nbl/pluspar)) { printf "+"} else if ((nbl/poinpar)==int(nbl/poinpar)) { printf "."} } # fin si nbl> 0 } # finsi nbl==1 # et on met tout en memoire dans le tableau tdata dataDbg = 1 ; # avec affichage des données au fur et à mesure dataDbg = 0 ; # sans affichage des données au fur et à mesure if (dataDbg==1) { for (j=1;j<=nbcol;j++) { printf "!" } ; print " " } for (j=1;j<=nbcol;j++) { debCol[j] += 0 finCol[j] += 0 if (dataDbg==1) { print "*"$0"*" print " longueur " length($0) " deb " debCol[j] " fin " finCol[j] } # fin si dataDbg==1 if (debCol[j]+finCol[j]>0) { tdata[nbl,j] = substr($0,debCol[j],finCol[j]-debCol[j]+1) } if (0+lonCol[j]==0) { lonCol[j] = finCol[j]-debCol[j]+1 } if (0+decCol[j]==0) { decCol[j] = 0 } if (dataDbg==1) { print " on met " tdata[nbl,j] " en lig " nbl " col " j if ((nbl/5)==int(nbl/5)) { printf " ? " ; getline pomme < "-" } } # fin si } # fin pour j } # fin de si le premier caractère est un commentaire } # fin de traitement de chaque ligne de données ################################################# END { printf " " sprintf("%5d",nbl) " line(s)" printf "\n" nbm = nbcol ## # ## # ## A.08 - Traitement des actions # ## # ## # nbg = nbg + nbaPre + nbaZer + nbaDay + nbaRig + nbaLef + nbaCon + nbaAdd nbc = nbc + nbaNbv + nbaSum + nbaCv_ + nbaFre + nbaMea + nbaStd + nbaVar nbc = nbc + nbaMax + nbaMin + nbaCro + nbaDic nbo = nbo + optRuler printf " Processing +" for (i=1;i<=nbl;i++) { if ((i/pluspar)==int(i/pluspar)) { printf "+"} else if ((i/poinpar)==int(i/poinpar)) { printf "."} actGest() # actions de gestion actCalc() # actions de calcul } # fin pour i de 1 a nbl printf " " sprintf("%5d",nbl) " line(s)" print "" resCalc() # résultat des actions en mode Calcul ## # ## # ### A.12 - Ecriture du fichier resultat des données # ## # ## # # on remet les anciennes lignes de données pour vérification # si option RULER if (optRuler==1) { print "#"substr(olinrul,1,nbcarul) > fsor for (i=1;i<=nbl;i++) { if (i<=5) { print "#"oldData[i] > fsor } }# fin pour i print "# new format " > fsor } # fin si # on essaie de construire une "belle ligne de format" for (j=1;j<=nbcol;j++) { if (index(colToDel,j)==0) { lontosor = lonCol[j] if (decCol[j]>0) { lontosor++ } for (i=1;i<=lontosor;i++) { printf "X"> fsor } } # fin de si printf " " > fsor } # fin pour j print "" > fsor # affichage éventuel de la réglette if (optRuler==1) { print "#"substr(linrul,1,nbcarul) > fsor } # préparation des bornes de variation pour la sortie if (optFirst==1) { lastline = firstKp } else { lastline = nbl } if (optSkip ==1) { firstline = skiplines+1 } else { firstline = 1} if (optLast ==1) { firstline = nbl+1-lastToSor } else { firsline = 1} if (firstline<=0) { firstline = 1 } if (lastline<=0 ) { lastline = nbl } if (lastline>nbl ) { lastline = nbl } printf " Writing +" nblsor = 0 # nb de lignes écrites ecritSor() ; print " \n -- end of processing " FILENAME "\n\n" > flog printf " " sprintf("%5d",nblsor) " line(s)" # on crée éventuellement le fichier .dbf pour dbase (option DBF) # avec au passage les fichiers .str et .sdf if (optDbf==1) { makedbf( noment ) } # on crée éventuellement le fichier .sas pour sas (option SAS) if (optSas==1) { makesas( noment ) } # on crée éventuellement le fichier .plt pour gnuplot (option PLOT) # avec au passage le fichiers .dag # et peut-être le fichier .gif if (optPlt==1) { makeplt( noment ) } else { if (optGif==1) { optPlt = 1 ; makeplt( noment ) } } ## # ## # ### A.13 - Fermeture des fichiers et message de fin # ## # ## # close(flog) ; close(fsor) close(fcal) # recopie éventuelle des fichiers de sortie if (optOuts==1) { copyFile(fsor,nomOuts) } # fin si if (optOutc==1) { copyFile(fcal,nomOutc) } # fin si if (optOutl==1) { copyFile(flog,nomOutl) } # fin si if (optFirst+optLast+optSkip>0) { printf " option(s)" } if (optFirst>0) { printf " FIRST " firstKp } if (optLast>0) { printf " LAST " lastToSor } if (optSkip>0) { printf " SKIP " skiplines } print " " printf " You may use : " flog if (optOutl==1) { print " and " nomOutl } else { print " " } if (nbg+nbo>0) { printf " " fsor if (optOuts==1) { print " and " nomOuts } else { print " " } } # fin de si sur nbg+nbo>0 if (nbc+nboc>0) { printf " " fcal if (optOutc==1) { print " and " nomOutc } else { print " " } } # fin de si sur nbc+nboc>0 if (optDbf==1) { if (os=="UNIX") { print " " fdbf } } if (optSas==1) { print " " fsas } if (optPlt==1) { print " " fplt " and " fdag } if (optDbf==1) { if (os=="DOS") { print " You have to run creedbf.exe " nomorg " to get " fdbf } } if (optPlt==1) { printf " You have to run gnuplot " fplt if (optGif!="") { print " to get the file " fgif"." } else { print " to see the plot." } } # fin si # copyright de fin print " " print " Copyright gilles.hunault@univ-angers.fr " print " http://www.info.univ-angers.fr/pub/gh/gh.html\n" } # fin du End ## # ## # ## # ######################## Functions ########################### # ## # ## # ## # function checkos() { # détermine le système d'exploitation à partir # des variables d'environnement vos = "UNIX" comspec = toupper(ENVIRON["COMSPEC"]) if (index(comspec,"CMD.EXE")>0) { vos = "DOS" } if (index(comspec,"COMMAND.COM")>0) { vos = "DOS" } #prompt = ENVIRON["PROMPT"] #print prompt # #nbslash = 0 #nbantis = 0 #vpath = ENVIRON["PATH"] #for (i=1;i<=length(vpath);i++) { # if (substr(vpath,i,1)=="/") { nbslash++ } # if (substr(vpath,i,1)=="\\") { nbantis++ } #} # fin pour #if (nbslash>nbantis) { vos = "UNIX" } else { vos = "DOS" } return(vos) } # end of function checkos function checkNumber( mbNb ) { # return 1 if mbNb is a valid number of column return (mbNb ~ /[0-9]+/) } # end of function checkNumber function decritCol() { if (nbcolstm>nbcol) { ch1 = "\n WARNING ! " ch2 = " COLUMN NUMBER " nbcolstm " SEEMS TO BE USED AS A PARAMETER IN " fstm ch3 = " BUT ONLY " nbcol " COLUMNS ARE DETECTED IN " fdat "\n" print ch1 ; print ch1 > flog print ch2 ; print ch2 > flog print ch3 ; print ch3 > flog nbcol = nbcolstm } # fin si # complétion éventuelle for (ic=1;ic<=nbcol;ic++) { if (lonCol[ic]+0==0) { lonCol[ic] = 0 } if (decCol[ic]+0==0) { decCol[ic] = 0 } if (substr(toupper(typCol[ic])" ",1,1)==" ") { tycCol[ic] = "?" } douzeb = substr(" ",1,12) lonnom = substr(nomCol[ic] " " douzeb,1,12) lonuni = substr(nomCol[ic] " " douzeb,1,12) if (douzeb==lonnom) { nomCol[ic] = "????????" } if (douzeb==lonuni) { uniCol[ic] = "????????" } } # fin pour ic print "\n DESCRIPTION of ALL COLUMNS " > flog print " Num. Name Type Length Dec Unit " > flog for (ic=1;ic<=nbcol;ic++) { printf sprintf("%7d",ic) > flog printf " " substr(nomCol[ic] " ",1,15) > flog printf substr(toupper(typCol[ic])"?",1,1) > flog printf sprintf("%5d",lonCol[ic]+0) > flog printf sprintf("%8d",decCol[ic]+0) > flog printf " " uniCol[ic] > flog print " " > flog } # fin pour return } # end of function decritCol() function defAct() { nbaAdd = 0 ; typeAct[ "ADD" ] = "G" ; defa[ "ADD" ] = " addition of two columns " nbaCon = 0 ; typeAct[ "CONC" ] = "G" ; defa[ "CONC" ] = " concatenation of two columns " nbaCst = 0 ; typeAct[ "CONST" ] = "G" ; defa[ "CONST" ] = " creation of a constant column " nbaCre = 0 ; typeAct[ "CREATE"] = "G" ; defa[ "CREATE"] = " creation of a new column name,type,length,decimals,unit,default " nbaCro = 0 ; typeAct[ "CROSS" ] = "C" ; defa[ "CROSS" ] = " computation of the cross tabulation of two columns " nbaCv_ = 0 ; typeAct[ "CV" ] = "C" ; defa[ "CV" ] = " computation of the coefficient of variation of a column " nbaDay = 0 ; typeAct[ "DAYS" ] = "C" ; defa[ "DAYS" ] = " computation of the number of past days from date columns " optDbf = 0 ; typeAct[ "DBF" ] = "O" ; defa[ "DBF" ] = " creation of a Dbase (DBF) file " nbaDel = 0 ; typeAct[ "DELE" ] = "G" ; defa[ "DELE" ] = " deletion of a column " nbaDes = 0 ; typeAct[ "DESCV" ] = "C" ; defa[ "DESCV" ] = " description of a column name,type,length,decimals,unit " nbaDic = 0 ; typeAct[ "DIC" ] = "C" ; defa[ "DIC" ] = " dictionnary of a column " nbaDiv = 0 ; typeAct[ "DIV" ] = "G" ; defa[ "DIV" ] = " division of a column by another one " optFirst = 0 ; typeAct[ "FIRST" ] = "O" ; defa[ "FIRST" ] = " use of the first n lines " # Opt nbaFre = 0 ; typeAct[ "FREQ" ] = "C" ; defa[ "FREQ" ] = " computation of the frequency table of a column " # optFunc = 0 ; typeAct[ "FUNC" ] = "O" ; defa[ "FUNC" ] = " definition of a user function " # Opt optGif = 0 ; typeAct[ "GIF" ] = "O" ; defa[ "GIF" ] = " creation of the gnuplot file PLT to get image file GIF " optLast = 0 ; typeAct[ "LAST" ] = "O" ; defa[ "LAST" ] = " use of the last n lines " # Opt nbaLef = 0 ; typeAct[ "LEFT" ] = "G" ; defa[ "LEFT" ] = " padding with the value on the left if empty " nbaLen = 0 ; typeAct[ "LENGTH"] = "G" ; defa[ "LENGTH"] = " definition of the length and decimals of a column " nbaLsy = 0 ; typeAct[ "LSYS" ] = "G" ; defa[ "LSYS" ] = " computation of the values of column by a Lindemayer system " nbaMax = 0 ; typeAct[ "MAX" ] = "C" ; defa[ "MAX" ] = " computation of the maximum of non empty values " nbaMea = 0 ; typeAct[ "MEAN" ] = "C" ; defa[ "MEAN" ] = " computation of the mean of non empty values " nbaMin = 0 ; typeAct[ "MIN" ] = "C" ; defa[ "MIN" ] = " computation of the minimum of non empty values " nbaMul = 0 ; typeAct[ "MUL" ] = "G" ; defa[ "MUL" ] = " multiplication of two columns " nbaNam = 0 ; typeAct[ "NAME" ] = "G" ; defa[ "NAME" ] = " designation of the column (name,[type]) " nbaNbv = 0 ; typeAct[ "NBVAL" ] = "C" ; defa[ "NBVAL" ] = " computation of the number of non empty values " optNob = 0 ; typeAct[ "NOBS" ] = "O" ; defa[ "NOBS" ] = " outpuf of the number of input line " optOutc = 0 ; typeAct[ "OUTC" ] = "O" ; defa[ "OUTC" ] = " definition of an alternate output file of computations " # Opt optOutl = 0 ; typeAct[ "OUTL" ] = "O" ; defa[ "OUTL" ] = " definition of an alternate output file of trace " # Opt optOuts = 0 ; typeAct[ "OUTS" ] = "O" ; defa[ "OUTS" ] = " definition of an alternate output file of data " # Opt optPlt = 0 ; typeAct[ "PLOT" ] = "O" ; defa[ "PLOT" ] = " creation of the PLT file to get a plot with gnuplot " nbaPre = 0 ; typeAct[ "PREV" ] = "G" ; defa[ "PREV" ] = " padding with the value from previous line if empty " nbaRig = 0 ; typeAct[ "RIGHT" ] = "G" ; defa[ "RIGHT" ] = " padding with the value on the right if empty " optRuler = 0 ; typeAct[ "RULER" ] = "O" ; defa[ "RULER" ] = " output of a ruler on n characters " # Opt optSas = 0 ; typeAct[ "SAS" ] = "O" ; defa[ "SAS" ] = " creation of a SAS program to build the SAS data table " # Opt optSkip = 0 ; typeAct[ "SKIP" ] = "O" ; defa[ "SKIP" ] = " skipping the first n lines " # Opt nbaStd = 0 ; typeAct[ "STD" ] = "C" ; defa[ "STD" ] = " computation of the exact standard deviation of non empty values " nbaSum = 0 ; typeAct[ "SUM" ] = "C" ; defa[ "SUM" ] = " computation of the sum of non empty values " nbaTyp = 0 ; typeAct[ "TYPE" ] = "C" ; defa[ "TYPE" ] = " setting the type of the column (C ou N) " nbaUni = 0 ; typeAct[ "UNIT" ] = "C" ; defa[ "UNIT" ] = " definition of the unite for the column " nbaVar = 0 ; typeAct[ "VAR" ] = "C" ; defa[ "VAR" ] = " computation of the exact variance of non empty values " nbaZer = 0 ; typeAct[ "ZERO" ] = "C" ; defa[ "ZERO" ] = " setting to zero all empty values of th column " # nbaDco = 0 ; typeAct[ "DECO" ] = "G" ; defa[ "DECO" ] = " decoding RFLB values as AF values " # Opt # nbaSpl = 0 ; typeAct[ "SPLIT" ] = "G" ; defa[ "SPLIT" ] = " separation en two columns " # nbaSor = 0 ; typeAct[ "SORT" ] = "G" ; defa[ "SORT" ] = " tri des lines selon the column " # nbaSel = 0 ; typeAct[ "SELE" ] = "G" ; defa[ "SELE" ] = " selection of the column " # nbaMov = 0 ; typeAct[ "MOVE" ] = "G" ; defa[ "MOVE" ] = " depthecement of the column " # nbaKee = 0 ; typeAct[ "KEEP" ] = "G" ; defa[ "KEEP" ] = " maintien of the column " # nbaOmi = 0 ; typeAct[ "OMIT" ] = "G" ; defa[ "OMIT" ] = " suppression of the column " return } # end function defAct function initVarGlob() { pluspar = 500 ; # on met un + tous les 500 lignes poinpar = 100 ; # on met un . tous les 100 lignes nmtoAd = " " ; # nom de col. à ajouter pour les constantes chtoAd = " " ; # chaine à rajouter pour les constantes nctoDel = " " ; # num. de colonnes a detruire colToDel = "" ; # liste des colonnes à détruire colToAd = "" ; # liste des colonnes à détruire sptoAd = "\" " # espaces à ajouter nboc = 0 ; # nb actions d'options pour calculs nbo = 0 ; # nb actions d'options nbg = 0 ; # nb actions de gestion nbc = 0 ; # nb actions de calculs nbdele = 0 ; # nb de destructions nbcol = 0 ; # nb de colonnes nbg = 0 ; # nb de lignes lastline = -1 ; # lastToSor = 0 ; # nb de lignes de fin skiplines = 0 ; # nb de lignes à omettre firstline = -1 firstKp = 0 # pour compter le nb de jours écoulés depuis le # début de l'année sumd = "31 28 31 30 31 30 31 31 30 31 30 31" ; summont[0] = 0 oldLig = $0 ; $0 = sumd for (i=1;i<=12;i++) { summont[i] = summont[i-1] + $i } ; $0 = oldLig return } # end function initVarGlob function badColn(la,wn,wv,ln) { # explains why, in action line la, the word number wn, value wv at line number ln # is not considered as a valid number of column ch1 = " WARNING ! ERROR FOR ACTION LINE \"" la "\"" ch2 = " THE WORD " sprintf("%2d",wn) " OF LINE " sprintf("%3d",ln) " IN FILE " fstm ch3 = " WHICH IS \"" wv "\" DOESN'T SEEM TO BE A VALID COLUMN NUMBER " print ch1 ; print ch1 > flog print ch2 ; print ch2 > flog print ch3 ; print ch3 > flog } # end function badColn function litStm() { litdbg = 1 ; # avec affichage litdbg = 0 ; # sans affichage nblstm = 0 ; normOutlen = 0 ; stmFNR = 0 while (getline < fstm > 0) { stmFNR++ # on ignore les commentaires nblstm++ $0 = beforeCmt($0) if (length($1)>0) { nbg++ $1 = toupper($1) noma[nbg] = $1 # recuperation du nom de l'action if (litdbg==1) { print " pour la ligne " $0 print " l'action est " noma[nbg] } # fin d'affichage de debug typa[nbg] = typeAct[$1] # on teste si l'action est valide print " ACTION NUMBER " nbg > flog # on traite séparément les options des autres actions if (typa[nbg]=="O") { print " THE OPTION *"noma[nbg]"* WILL BE USED " > flog print " WHICH MEANS : " defa[ noma[nbg] ] > flog if (length($2)>0) { oldLine = $0 ; $1 = " " ; parmsLi = $0 ; $0 = oldLine if (noma[nbg]!="NOBS") { print " USING THE FOLLOWING PARAMETER(S) : " parmsLi > flog } # finsi noma[nbg]!="NOBS" } # fin de si (length($2)>0) } else { # on teste si le mot 2 est un nombre valide comme numéro de colonne if (checkNumber($2)==0) { badColn($0,2,$2,stmFNR) } else { numCol[nbg] = $2 # récuperation du numéro de colonne if ($2>nbcolstm) { nbcolstm = $2 } nomCol[$2] = $3 # récuperation du nom de colonne print " THE ACTION *"noma[nbg]"* " > flog print " WHICH MEANS : " defa[ noma[nbg] ] > flog print " WILL BE USED ON COLUMN NUMBER " sprintf("%3d",numCol[nbg]) " NAMED \""nomCol[$2]"\"" > flog if (nbcol0) { print " USING THE FOLLOWING PARAMETER(S) : " parms > flog } # fin de si } # fin de si le mot 2 est valide } ; # fin de si ce n'est pas une option print " " > flog ## # ## # ### A.04 - Gestion des actions d'options # ## # ## # ################################ Options ################################ ## # ## # if (noma[nbg]=="DBF") { optDbf = 1 } # fin si pour : # on met l'option dbf à 1 if (noma[nbg]=="SAS") { optSas = 1 } # fin si pour : on met l'option sas à 1 if (noma[nbg]=="GIF") { optGif = 1 optPlt = 1 ; col1 = $2 ; col2 = $4 } # fin si if (noma[nbg]=="PLOT") { # on met l'option sas à 1 optPlt = 1 ; col1 = $2 ; col2 = $4 ; if (checkNumber($2)==0) { badColn($0,2,$2,stmFNR) } if (checkNumber($4)==0) { badColn($0,4,$4,stmFNR) } optGif = toupper($6) } # fin si if (noma[nbg]=="FIRST") { # on ne garde que les n premières lignes firstKp = $2 + 0 ; optFirst = 1 } # fin si if (noma[nbg]=="SKIP") { # on omet ("saute") les n premières lignes skiplines = $2 ; optSkip = 1 } # fin si if (noma[nbg]=="LAST") { # on ne garde que les n dernières lignes lastToSor = $2 ; optLast = 1 } # fin si if (noma[nbg]=="OUTC") { # on recopie les calculs dans le fichier spécifié optOutc = 1 ; nomOutc = $2 ; nboc = 1 } # fin si if (noma[nbg]=="OUTS") { # on recopie les resultats dans le fichier spécifié optOuts = 1 ; nomOuts = $2 } # fin si if (noma[nbg]=="OUTL") { # on recopie le fichier-trace dans le fichier spécifié optOutl = 1 ; nomOutl = $2 } # fin si if (noma[nbg]=="RULER") { # affichage d'une réglette sur nbcarul cractères optRuler = 1 nbcarul = $2 $1 = $2 + 0 if ($1==0) { nbcarul = 65 } } # fin si ## # ## # ### A.05 - Gestion des actions de gestion # ## # ## # ################################ Gestion ################################ ## # ## # if (noma[nbg]=="CREATE") { # ajout a la liste des num. de colonne pour action CREATE nbaCre++ # comptage du nombre d'actions en Cre lisaCr[nbaCre] = numCol[nbg] coltoAd = colToAd " " numCol[nbg] nmtoAd = nmtoAd $3 " " chenCr[nbaCre] = $4 typCol[numCol[nbg]] = substr(toupper($4)"?",1,1) lonCol[numCol[nbg]] = $5 + 0 decCol[numCol[nbg]] = $6 + 0 uniCol[numCol[nbg]] = $7 chtoAd = chtoAd $8 " " } # fin si if (noma[nbg]=="CONST") { # ajout a la liste des num. de colonne pour action CST nbaCst++ # comptage du nombre d'actions en Cst lisaCs[nbaCst] = numCol[nbg] chenCs[nbaCst] = $4 nmtoAd = nmtoAd $3 " " chtoAd = chtoAd $4 " " coltoAd = colToAd " " numCol[nbg] typCol[numCol[nbg]] = substr(toupper($5)"?",1,1) if (length($6)>0) { lonCol[numCol[nbg]] = $6 } if (length($7)>0) { decCol[numCol[nbg]] = $7 } uniCol[numCol[nbg]] = $8 } # fin si if (noma[nbg]=="NAME") { # ajout a la liste des num. de colonne pour action NAM nbaNam++ # comptage du nombre d'actions en Nam lisaNa[nbaNam] = numCol[nbg] chenNa[nbaNam] = $4 typCol[numCol[nbg]] = toupper(substr($5"?",1,1)) } # fin si if (noma[nbg]=="ADD") { # ajout a la liste des num. de colonne pour action ADD nbaAdd++ # comptage du nombre d'actions en Add lisaAd[nbaAdd] = numCol[nbg] parmAd[nbaAdd] = $4 } # fin si if (noma[nbg]=="CONC") { # ajout a la liste des num. de colonne pour action CONC nbaCon++ # comptage du nombre d'actions en Con lisaCo[nbaCon] = numCol[nbg] parmCo[nbaCon] = $4 + 0 prm2Co[nbaCon] = $6 + 0 symbCol[nbaCon] = $9 } # fin si if (noma[nbg]=="DELE") { # ajout a la liste des num. de colonne pour action DELE nbaDel++ # comptage du nombre d'actions en Del lisaDe[nbaDel] = numCol[nbg] colToDel = colToDel " " numCol[nbg] nbdele++ } # fin si if (noma[nbg]=="DESCV") { # ajout a la liste des num. de colonne pour action DESCV nbaDes++ # comptage du nombre d'actions en Des lisaNa[nbaNam] = numCol[nbg] chenNa[nbaNam] = $3 lisaLe[nbaDes] = $5 + 0 lisaLe_dec[nbaDes] = $6 + 0 newlengt[nbaLen] = numCol[nbg] typCol[numCol[nbg]] = substr(toupper($4)"?",1,1) lonCol[numCol[nbg]] = $5 + 0 decCol[numCol[nbg]] = $6 + 0 uniCol[numCol[nbg]] = $7 normOutlen += lonCol[numCol[nbg]] if (decCol[numCol[nbg]]>0) { normOutlen++ } } # fin si if (noma[nbg]=="LENGTH") { # ajout a la liste des num. de colonne pour action LENGTH nbaLen++ # comptage du nombre d'actions en Len lisaLe[nbaLen] = $4 + 0 lisaLe_dec[nbaLen] = $5 + 0 newlengt[nbaLen] = numCol[nbg] lonCol[numCol[nbg]] = $4 + 0 decCol[numCol[nbg]] = $5 + 0 normOutlen += lonCol[numCol[nbg]] if (decCol[numCol[nbg]]>0) { normOutlen ++ } } # fin si if (noma[nbg]=="PREV") { # ajout a la liste des num. de colonne pour action PREC nbaPre++ # comptage du nombre d'actions en Pre lisaPr[nbaPre] = numCol[nbg] } # fin si if (noma[nbg]=="LEFT") { # ajout a la liste des num. de colonne pour action LEFT nbaLef++ # comptage du nombre d'actions en Lef lisaLe[nbaLef] = numCol[nbg] } # fin si if (noma[nbg]=="RIGHT") { # ajout a la liste des num. de colonne pour action RIGHT nbaRig++ # comptage du nombre d'actions en Rig lisaRi[nbaRig] = numCol[nbg] } # fin si if (noma[nbg]=="ZERO") { # ajout a la liste des num. de colonne pour action ZER0 nbaZer++ # comptage du nombre d'actions en Ze lisaZe[nbaZer] = numCol[nbg] } # fin si if (noma[nbg]=="DAYS") { # ajout a la liste des num. de colonne pour action DAYS nbaDay++ # comptage du nombre d'actions en Da lisaDa[nbaDay] = numCol[nbg] days[numCol[nbg]] = $4 mont[numCol[nbg]] = $6 year[numCol[nbg]] = $8 } # fin si if (noma[nbg]=="TYPE") { # typCol[$2] = substr(toupper($4)"?",1,1) } # fin si if (noma[nbg]=="NOBS") { # optNob = 1 } # fin si if (noma[nbg]=="UNIT") { # uniCol[numCol[nbg]] = $4 } # fin si ## # ## # ### A.06 - Gestion des actions de calcul # ## # ## # ################################ Calcul ################################## ## # ## # if (noma[nbg]=="NBVAL") { # ajout a la liste des num. de colonne pour action NBVAL nbaNbv++ # comptage du nombre d'actions en Nbv lisaNv[nbaNbv] = numCol[nbg] } # fin si if (noma[nbg]=="SUM") { # ajout a la liste des num. de colonne pour action SUM nbaSum++ # comptage du nombre d'actions en Sum lisaSu[nbaSum] = numCol[nbg] } # fin si if (noma[nbg]=="MEAN") { # ajout a la liste des num. de colonne pour action MEAN nbaMea++ # comptage du nombre d'actions en Mea lisaMe[nbaMea] = numCol[nbg] } # fin si if (noma[nbg]=="STD") { # ajout a la liste des num. de colonne pour action SUM nbaStd++ # comptage du nombre d'actions en Std lisaSt[nbaStd] = numCol[nbg] } # fin si if (noma[nbg]=="VAR") { # ajout a la liste des num. de colonne pour action VAR nbaVar++ # comptage du nombre d'actions en Var lisaVa[nbaVar] = numCol[nbg] } # fin si if (noma[nbg]=="CV") { # ajout a la liste des num. de colonne pour action CV nbaCv_++ # comptage du nombre d'actions en Cv_ lisaCv[nbaCv_] = numCol[nbg] } # fin si if (noma[nbg]=="MIN") { # ajout a la liste des num. de colonne pour action MIN nbaMin++ # comptage du nombre d'actions en Min lisaMi[nbaMin] = numCol[nbg] } # fin si if (noma[nbg]=="MAX") { # ajout a la liste des num. de colonne pour action MAX nbaMax++ # comptage du nombre d'actions en Max lisaMa[nbaMax] = numCol[nbg] } # fin si if (noma[nbg]=="FREQ") { # ajout a la liste des num. de colonne pour action FREQ nbaFre++ # comptage du nombre d'actions en Fre lisaFr[nbaFre] = numCol[nbg] } # fin si if (noma[nbg]=="CROSS") { # ajout a la liste des num. de colonne pour action CROSS nbaCro++ # comptage du nombre d'actions en Cro lisaCr[nbaCro] = numCol[nbg] parmCr[nbaCro] = $4 + 0 } # fin si if (noma[nbg]=="DIC") { # ajout a la liste des num. de colonne pour action DIC nbaDic++ # comptage du nombre d'actions en Cro lisaDi[nbaDic] = numCol[nbg] } # fin si } # fin de si la ligne n'est pas un commentaire } # fin tant que non fin de fichier sur fstm return } # end function litStm function actGest() { ## # ## # ### A.09 - Traitement des actions de Gestion # ## # ## # ################################ Gestion ################################ ## # ## # # action CREATE for (j=1;j<=nbaCre;j++) { jj = lisaCr[j] tdata[i,jj] = chenCr[j] } # fin pour j # action CONST for (j=1;j<=nbaCst;j++) { jj = lisaCs[j] tdata[i,jj] = chenCs[j] } # fin pour j # action PREV for (j=1;j<=nbaPre;j++) { jj = lisaPr[j] $0 = tdata[i,jj] valc[j] = $1 if (length(valc[j])>0) { ancvalPrev[j] = tdata[i,jj] } else { tdata[i,jj] = ancvalPrev[j] } } # fin pour j # action LEFT for (j=1;j<=nbaLef;j++) { jj = lisaLe[j] $0 = tdata[i,jj] valc[j] = $1 if (length(valc[j])<=0) { tdata[i,jj] = tdata[i,jj-1] } } # fin pour j # action RIGHT for (j=1;j<=nbaRig;j++) { jj = lisaRi[j] $0 = tdata[i,jj] valc[j] = $1 if (length(valc[j])<=0) { tdata[i,jj] = tdata[i,jj+1]} } # fin pour j # action ADD for (j=1;j<=nbaAdd;j++) { jj = lisaAd[j] tdata[i,jj] += tdata[i,parmAd[j]] } # fin pour j # action CONC for (j=1;j<=nbaCon;j++) { jj = lisaCo[j] if (symbCol[j]=="") { tdata[i,jj] = tdata[i,parmCo[j]] tdata[i,prm2Co[j]] } else { tdata[i,jj] = tdata[i,parmCo[j]] symbCol[j] tdata[i,prm2Co[j]] } } # fin pour j # action ZERO for (j=1;j<=nbaZer;j++) { jj = lisaZe[j] $0 = tdata[i,jj] valc[j] = $1 if (length(valc[j])==0) { tdata[i,jj] = 0 } } # fin pour j # action DAYS for (j=1;j<=nbaDay;j++) { jj = lisaDa[j] $0 = tdata[i,jj] + 0 valc[j] = $1 + 0 if (valc[j]==0) { cold = days[jj] colm = mont[jj] coly = year[jj] dayval = summont[tdata[i,colm]-1]+tdata[i,cold] ### bissextile ? tdata[i,jj] = dayval } } # fin pour j return } # end function actGest() { function actCalc() { ## # ## # ### A.10 - Traitement des actions de Calcul # ## # ## # ################################ Calcul ################################ ## # ## # # action NBVAL for (j=1;j<=nbaNbv;j++) { jj = lisaNv[j] $0 = tdata[i,jj] valc[j] = $1 if (length(valc[j])>0) { nbval[jj]++ } } # fin pour j # action SUM for (j=1;j<=nbaSum;j++) { jj = lisaSu[j] $0 = tdata[i,jj] valc[j] = $1 if (length(valc[j])>0) { sumval[jj]+= $1 } } # fin pour j # action MEAN for (j=1;j<=nbaMea;j++) { jj = lisaMe[j] $0 = tdata[i,jj] valc[j] = $1 if (length(valc[j])>0) { moyval[jj,1]++ moyval[jj,2]+= $1 } } # fin pour j # action VAR for (j=1;j<=nbaVar;j++) { jj = lisaVa[j] $0 = tdata[i,jj] valc[j] = $1 if (length(valc[j])>0) { varval[jj,1]++ varval[jj,2]+= $1 varval[jj,3]+= $1*$1 } } # fin pour j # action STD for (j=1;j<=nbaStd;j++) { jj = lisaSt[j] $0 = tdata[i,jj] valc[j] = $1 if (length(valc[j])>0) { stdval[jj,1]++ stdval[jj,2]+= $1 stdval[jj,3]+= $1*$1 } } # fin pour j # action CV for (j=1;j<=nbaCv_;j++) { jj = lisaCv[j] $0 = tdata[i,jj] valc[j] = $1 if (length(valc[j])>0) { cvval[jj,1]++ cvval[jj,2]+= $1 cvval[jj,3]+= $1*$1 } } # fin pour j # action MIN for (j=1;j<=nbaMin;j++) { jj = lisaMi[j] $0 = tdata[i,jj] valc[j] = $1 if (length(valc[j])>0) { if (length(valmin[jj])==0) { valmin[jj] = $1 } if ($10) { if (length(valmax[jj])==0) { valmax[jj] = $1 } if ($1> valmax[jj]) { valmax[jj] = $1 } } } # fin pour j # action FREQ for (j=1;j<=nbaFre;j++) { jj = lisaFr[j] $0 = tdata[i,jj] valc[j] = $1 nbfois[jj,$1]++ if (nbfois[jj,$1]==1) { listeval[jj] = listeval[jj] " " $1 } } # fin pour j # action CROSS for (j=1;j<=nbaCro;j++) { jj1 = lisaCr[j] ; $0 = tdata[i,jj1] ; valc1[j] = $1 $1 = $1 + 0 # pour forcer en numérique if (minmod[j,1]+0>=$1) { minmod[j,1] = $1 } if (maxmod[j,1]+0<=$1) { maxmod[j,1] = $1 } jj2 = parmCr[j] ; $0 = tdata[i,jj2] ; valc2[j] = $1 $1 = $1 + 0 # pour forcer en numérique if (minmod[j,2]+0>=$1) { minmod[j,2] = $1 } if (maxmod[j,2]+0<=$1) { maxmod[j,2] = $1 } tricro[j,valc1[j],valc2[j]]++ } # fin pour j # action DIC acdicdbg = 1 ; # avec affichage acdicdbg = 0 ; # sans affichage for (j=1;j<=nbaDic;j++) { jj = lisaDi[j] ; $0 = tdata[i,jj] ; for (u=1;u<=NF;u++) { motu = $u # on fait un peu de ménage dans les mots... cartodel = ",;.:}{][+=><" if (acdicdbg==1) { print " motu avant *" motu "* longueur " length(motu) } omotu = motu ; motu = "" for (icarc=1;icarc<=length(omotu);icarc++) { carc = substr(omotu,icarc,1) if (index(cartodel,carc)>0) { carc ="" } motu = motu carc } # fin pour if (acdicdbg==1) { print " motu apres *" motu "* longueur " length(motu) printf " ? " ; getline pom < "-" } if (length(motu)>0) { tdico[motu]++ } } ; } # fin pour j return } # end function actCalc() { function resCalc() { ## # ## # ## # ## # ### A.11 - Affichage des résultats pour les actions de Calcul # ## # ## # ## # # nombre de valeurs non vides for (j=1;j<=nbaNbv;j++) { jj = lisaNv[j] nomAct = " number of non empty values : " ltp = " Column " sprintf("%3d",jj) " \""substr(nomCol[jj] sptoAd,1,10) nomAct print ltp sprintf("%8d ",nbval[jj]) > fcal } # fin pour j # somme des valeurs non vides for (j=1;j<=nbaSum;j++) { jj = lisaSu[j] nomAct = " sum of non empty values : " ltp = " Column " sprintf("%3d",jj) " \""substr(nomCol[jj] sptoAd,1,10) nomAct print ltp sprintf("%12.3f",sumval[jj]) " " uniCol[jj] > fcal } # fin pour j # moyenne des valeurs non vides for (j=1;j<=nbaMea;j++) { jj = lisaMe[j] nomAct = " mean of non empty values : " moyval[jj,2] = moyval[jj,2] / moyval[jj,1] ltp = " Column " sprintf("%3d",jj) " \""substr(nomCol[jj] sptoAd,1,10) nomAct print ltp sprintf("%12.3f",moyval[jj,2]) " " uniCol[jj] > fcal } # fin pour j # variance des valeurs non vides for (j=1;j<=nbaVar;j++) { jj = lisaVa[j] nomAct = " variance of non empty values : " varval[jj,2] = varval[jj,2] / varval[jj,1] varval[jj,3] = varval[jj,3] / varval[jj,1] varval[jj,3] = varval[jj,3] - varval[jj,2]*varval[jj,2] ltp = " Column " sprintf("%3d",jj) " \""substr(nomCol[jj] sptoAd,1,10) nomAct print ltp sprintf("%12.3f",varval[jj,3]) " " uniCol[jj] "*" uniCol[jj] > fcal } # fin pour j # écart-type des valeurs non vides for (j=1;j<=nbaStd;j++) { jj = lisaSt[j] nomAct = " std of non empty values : " stdval[jj,2] = stdval[jj,2] / stdval[jj,1] stdval[jj,3] = stdval[jj,3] / stdval[jj,1] stdval[jj,3] = stdval[jj,3] - stdval[jj,2]*stdval[jj,2] stdval[jj,3] = sqrt(stdval[jj,3]) ltp = " Column " sprintf("%3d",jj) " \""substr(nomCol[jj] sptoAd,1,10) nomAct print ltp sprintf("%12.3f",stdval[jj,3]) " " uniCol[jj] > fcal } # fin pour j # coefficient de variation des valeurs non vides for (j=1;j<=nbaCv_;j++) { jj = lisaCv[j] nomAct = " std/m of non empty values : " cvval[jj,2] = cvval[jj,2] / cvval[jj,1] cvval[jj,3] = cvval[jj,3] / cvval[jj,1] cvval[jj,3] = cvval[jj,3] - cvval[jj,2]*cvval[jj,2] cvval[jj,3] = 100*sqrt(cvval[jj,3])/cvval[jj,2] ltp = " Column " sprintf("%3d",jj) " \""substr(nomCol[jj] sptoAd,1,10) nomAct print ltp sprintf(" %9.3f %%",cvval[jj,3]) > fcal } # fin pour j # minimum des valeurs des valeurs non vides for (j=1;j<=nbaMin;j++) { jj = lisaMi[j] nomAct = " minimum of non empty values : " ltp = " Column " sprintf("%3d",jj) " \""substr(nomCol[jj] sptoAd,1,10) nomAct print ltp sprintf("%12.3f",valmin[jj]) " " uniCol[jj] > fcal } # fin pour j # maximum des valeurs des valeurs non vides for (j=1;j<=nbaMin;j++) { jj = lisaMi[j] nomAct = " maximum of non empty values : " ltp = " Column " sprintf("%3d",jj) " \""substr(nomCol[jj] sptoAd,1,10) nomAct print ltp sprintf("%12.3f",valmax[jj]) " " uniCol[jj] > fcal } # fin pour j # fréquence des valeurs des valeurs non vides for (j=1;j<=nbaFre;j++) { jj = lisaFr[j] $0 = listeval[jj] refcol = " Column " sprintf("%3d",jj) " \""substr(nomCol[jj] sptoAd,1,10) nomAct = " frequency of the " NF " distinct non empty values " ltp = refcol nomAct print ltp > fcal ltp1 = refcol " value " sdv = 0 for (u=1;u<=NF;u++) { ltp1 = ltp1 " " sprintf("%7.2f",$u) } # fin pour print ltp1 > fcal ltp2 = refcol " count " for (u=1;u<=NF;u++) { ltp2 = ltp2 " " sprintf("%7.2f",nbfois[jj,$u]) } # fin pour print ltp2 > fcal ltp3 = refcol " % " for (u=1;u<=NF;u++) { ltp3 = ltp3 " " sprintf("%7.2f",100*nbfois[jj,$u]/nbl) } # fin pour print ltp3 > fcal } # fin pour j # fréquence des valeurs des valeurs non vides for (j=1;j<=nbaCro;j++) { j1 = lisaCr[j] chen = " CrossTabulation of column " j1 " : \""nomCol[j1]"\"" printf chen > fcal j2 = parmCr[j] chen = " and of column " j2 " : \""nomCol[j2]"\"" print chen > fcal print" absolute frequencies " > fcal # affichage des numéros de modalité printf " " > fcal for (i2=minmod[j,2];i2<=maxmod[j,2];i2++) { printf(" %6d",i2) > fcal } # fin pour i2 print " " > fcal # affichage des valeurs du tri croisé for (i1=minmod[j,1];i1<=maxmod[j,1];i1++) { printf(" %6d",i1) > fcal sumcr = 0 for (i2=minmod[j,2];i2<=maxmod[j,2];i2++) { sumcr += tricro[j,i1,i2] printf(" %6d",tricro[j,i1,i2]) > fcal } # fin pour i2 print " total " sprintf(" %6d",sumcr) > fcal } # fin pour i1 print" relative frequencies (% with respect to " nbl " lines)" > fcal # affichage des numéros de modalité printf " " > fcal for (i2=minmod[j,2];i2<=maxmod[j,2];i2++) { printf(" %6d",i2) > fcal } # fin pour i2 print " " > fcal # affichage des valeurs du tri croisé for (i1=minmod[j,1];i1<=maxmod[j,1];i1++) { printf(" %6d",i1) > fcal sumcr = 0 for (i2=minmod[j,2];i2<=maxmod[j,2];i2++) { sumcr += tricro[j,i1,i2] printf(" %6.1f",100*tricro[j,i1,i2]/nbl) > fcal } # fin pour i2 print " total " sprintf(" %6.1f",100*sumcr/nbl) > fcal } # fin pour i1 } # fin pour j # dictionnaire de colonne for (j=1;j<=nbaDic;j++) { if (j==1) { dicsort( tdico , tdictmp ) print " DICTIONNARY OF COLUMN " lisaDi[j] " OF FILE " fdat > fcal #comptage du nombre totals de mots nbmodic = 0 nbdismo = 0 for (u in tdico) { nbmodic += tdico[u] nbdismo++ } # fin pour u print " Total number of words : " sprintf("%6d",nbmodic) > fcal printf " Number of distincts words : " sprintf("%6d",nbdismo) > fcal print " ( " sprintf("%4.0f",100*nbdismo/nbmodic) " %) " > fcal print " Number of processed lines : " sprintf("%6d",nbl) > fcal for (i=1;i<=nbdismo;i++) { u = tdictmp[i] uu = substr(u" ",1,40) printf(" %-40s %6d ",uu,tdico[u] ) > fcal print " " sprintf("%7.2f",100*tdico[u]/nbmodic) " % " > fcal } # fin pour u } else { print " this version of gnumdata does not process more than one DIC action " > fcal } # } # fin pour j return } # end function resCalc() { function deleteFile( fn ) { # détruit le fichier s'il existe oktodel = 1 ; # avec de destruction oktodel = 0 ; # pas destruction if (oktodel==1) { if (os=="DOS") { cmd = "if exist " fn " del " fn system(cmd) } else if (os=="UNIX") { cmd = " if test -r " fn " ; then rm " fn " 2>/dev/null ; fi ; " system(cmd) } # fin de si sur os } # fin de si sur oktodel } # end of function deleteFile function osCopyfile( fn1 , fn2 ) { deleteFile( fn2 ) if (os=="DOS") { cmd = "if exist " fn1 " copy " fn1 " " fn2 system(cmd) } else { cmd = " if test -r " fn1 " ; then cp " fn1 " " fn2 " 2>/dev/null ; fi ; " system(cmd) } # fin de si return } # end of function osCopyFile function copyFile(fn1, fn2) { # on recopie fn1 dans fn2 while (getline < fn1 > 0) { print $0 > fn2 } # fin tant que close(fn1) ; close(fn2) return } # end of function copyFile function debLine( phrz , newp ) { # on récupère ce qu'il y a après le troisième mot # et avant le dièse de commentaire ip = index(phrz,"#") if (ip>1) { newp = substr(phrz,1,ip-1) } else { newp = phrz } oldO = $0 $0 = newp $1 = "" $2 = "" $3 = "" newp = $0 $0 = oldO return newp } # fin de fonction debLine function beforeCmt( phrz ) { # on renvoie tout ce qui précède le dièse phrz = phrz "#" id = index(phrz,"#") if (id>0) { res = substr(phrz,1,id-1) } else { res = phrz } return res } # fin de fonction beforeCmt function positions() { # met dans le fichier de trace (gnumdata.log) # les positions de début et de fin des colonnes normales ic = 1 ; nbm = 0 ; cdeb = 0 ; cfin = 0 while (ic<=ll) { carp = substr($0,ic-1,1) ; carc = substr($0,ic,1) if (carp== " ") { if (carc!=" ") { nbm++ ; cdeb = ic-1 ; debCol[nbm] = cdeb } # fin si carp== " " } else { if (carc==" ") { finCol[nbm] = ic-2 if (lonCol[nbm]+0==0) { lonCol[nbm] = finCol[nbm] - debCol[nbm] + 1 } # fin si if (decCol[nbm]+0==0) { decCol[nbm] = 0 } # fin si } } # fin si carc== " " ic++ } # fin tant que ic <= ll nbcol = nbm for (ic=1; ic<=nbcol;ic++) { if (lonCol[numCol[ic]]+0==0) { lonCol[numCol[ic]] = finCol[ic] - debCol[ic] + 1 } # fin si if (decCol[numCol[ic]]+0==0) { decCol[numCol[ic]] = 0 } # fin si if (length(nomCol[ic])>0) { ncol = substr(nomCol[ic]" ",1,15) } else { ncol = substr("???????????????????????????????",1,15) } # fin de si chsL = " column " sprintf("%3d",ic) " named : " ncol " start " sprintf("%3d",debCol[ic]) printf chsL >> flog print " end " sprintf("%3d",finCol[ic]) >> flog } # fin pour ic return } # end function positions function descAdCol() { # met dans le fichier de trace (gnumdata.log) # les positions de début et de fin des # colonnes ajoutées par les commandes CONST # oldll = ll # ll = length($0) # while (ic<=ll) { # carp = substr($0,ic-1,1) # carc = substr($0,ic,1) # # if (carp== " ") { if (carc!=" ") { # nbm++ ; cdeb = ic-1 ; debCol[nbm] = cdeb # if (length(nomCol[nbm])>0) { # ncol = substr(nomCol[nbm]" ",1,15) # } else { ncol = substr("???????????????????????????????",1,15) # } # fin de si # printf " column " sprintf("%3d",nbm) " named : " ncol " start " sprintf("%3d",ic-1) >> flog # } # fin si !carc== " " # } else { if (carc==" ") { finCol[nbm] = ic-1 # print " end " sprintf("%3d",ic-2) >> flog # lonCol[nbm] = finCol[nbm] - debCol[nbm] + 1 # } } # fin si carc== " " # ic++ # } # fin tant que ic <= ll # nbcol = nbm for (i=1;i<=nbaCre;i++) { nbm = lisaCr[i] if (length(nomCol[nbm])>0) { ncol = substr(nomCol[nbm]" ",1,15) } else { ncol = substr("???????????????????????????????",1,15) } # fin de si print " column " sprintf("%3d",nbm) " named : " ncol " from action CREATE" > flog } # fin pour for (i=1;i<=nbaCst;i++) { nbm = lisaCs[i] if (length(nomCol[nbm])>0) { ncol = substr(nomCol[nbm]" ",1,15) } else { ncol = substr("???????????????????????????????",1,15) } # fin de si print " column " sprintf("%3d",nbm) " named : " ncol " from action CONST"> flog } # fin pour return } # end function descAdCol function changeLen() { for (i in newlengt) { printf " column " sprintf("%3d",i) >> flog if (length(nomCol[nbm])>0) { ncol = substr(nomCol[nbm]" ",1,15) } else { ncol = substr("???????????????????????????????",1,15) } # fin de si printf " named : " ncol >> flog printf " new length " sprintf("%3d",lisaLe[i])+0 >> flog print " decimals " sprintf("%3d",lisaLe_dec[i]+0) >> flog lonCol[ i ] = lisaLe[i] decCol[ i ] = lisaLe_dec[i] } # fin pour i return } # end function changeLen function ecritSor() { # ecrit dans le fichier de sortie gnumdata.sor dbgdata = 1 # avec d'affichage de vérification dbgdata = 0 # sans d'affichage de vérification if (dbgdata==1) { nbldbg = 0 for (i=1;i<=nbl;i++) { printf sprintf("%4d",i) " : " for (j=1;j<=nbcolstm;j++) { printf "$"tdata[i,j]"^ " } # fin pou rj print " " } # fin pour i if ((nbldbg/20)==int(nbldbg/20)) { printf " ? " ; getline pomme < "-" } } # fin si affichage de controle for (i=1;i<=nbl;i++) { # test de l'affichage d'attente if ((i/pluspar)==int(i/pluspar)) { printf "+"} else if ((i/poinpar)==int(i/poinpar)) { printf "."} # on affiche que les lignes demandées if (i>=firstline) { if (i<=lastline) { nblsor++ ; # incrémentation du compteur de nb de lignes écrites # affichage éventuel du numéro de ligne if (optNob==1) { printf sprintf("%5d",i) " : " >> fsor } for (j=1;j<=nbcol;j++) { # on regarde d'abord si on garde la colonne if (index(colToDel,j)==0) { lontosor = lonCol[j] if (decCol[j]>0) { lontosor++ } if (lonCol[j]>0) { mot = tdata[i,j] douzeb = " " if (substr(mot douzeb,1,12)!=substr(douzeb,1,12)) { if (typCol[j]=="C") { mot = mot"" } if (typCol[j]=="N") { mot = mot + 0 mot = sprintf("%"lonCol[j]"."decCol[j]"f",mot) } # on "padde" évetuellement a gauche ou a droite # suivant le type if (typCol[j]=="C") { while (length(mot)> fsor } # fin si sur index() } # fin pour j print "" >> fsor } } # fin si i >= firstline et i<= lastline } # fin pour i return } # end function ecritSor function valx ( valeur ) { # renvoi le caractère dont on donne le code decimal # par exemple valx( 65 ) est A d = sprintf("%x",valeur) ; ## if (length(d)==1) { d= "0"d } if (valeur<16) { d= "0"d } a = substr(d,1,1) ; b = substr(d,2,1) if (a=="a") { a = 10 } ; if (b=="a") { b = 10 } if (a=="b") { a = 11 } ; if (b=="b") { b = 11 } if (a=="c") { a = 12 } ; if (b=="c") { b = 12 } if (a=="d") { a = 13 } ; if (b=="d") { b = 13 } if (a=="e") { a = 14 } ; if (b=="e") { b = 14 } if (a=="f") { a = 15 } ; if (b=="f") { b = 15 } e = 16*a+b ; res = sprintf("%c",e) return res } # end function valx function decomp16( nombre , nbz) { # decomposition en base 16 et écriture sur nbz/2 octets ie = 0 for (k=1;k<=nbz;k++) { bz[k] = 0 } while (nombre>0) { ie++ ; mm = int(nombre/16) ; nn = nombre - 16*int(nombre/16) bz[ie] = nn ; nombre = mm } # for (j=1;j<=nbz/2;j++) { printf valx(16*bz[2*j]+bz[2*j-1]) > fdbf } # fin pour j return } # end function decpmp16 function creedbf( nomorg ) { lonCcar = 0 lonCnum = 0 # parcours du fichier structure while ( getline < nomorg > 0 ) { ndc++ nomCol[ndc] = toupper($1) typCol[ndc] = toupper(substr($2"?",1,1)) lonCol[ndc] = $3 + 0 # pour forcer en numérique decCol[ndc] = $4 + 0 # pour forcer en numérique if (typCol[ndc]=="C") { lonCcar += lonCol[ndc] } if (typCol[ndc]=="N") { lonCnum += lonCol[ndc] } } # fintant que # on parcourt une première fois les données pour compter # le nombre de lignes nbe = 0 while (getline < fsdf > 0) { nbe++ } close(fsdf) # octet 0 : 83 si champ mémo, 3 sinon c = 3 d = sprintf("%c",c) ; printf d > fdbf # octets 1 à 3 : date en AA MM DD # exemple : 10 janvier 99 donne 63 01 0A c = strftime("%y",systime()) ; printf valx(c) > fdbf c = strftime("%m",systime()) ; printf valx(c) > fdbf c = strftime("%d",systime()) ; printf valx(c) > fdbf # octets 4 à 7 : nombre d'enregistrements # si count vaut a b c d e f g h en base 16 # on écrit gh ef cd ab # exemple : 98010 donne 0 0 0 1 7 E D A # qu'on code en DA 7E 01 00 decomp16(nbe,8) # octets 8-9 : longueur totale de l'en-tête # si lent vaut a b c d en base 16 # on écrit cd ab # exemple : 32 donne 0 2 0 0 # qu'on code en 20 00 # longueur : 32 + flogdcount*32 + 1 lent = 32*(1+ndc) + 1 ; decomp16(lent,4) # octets 10-11 : longueur de chaque enregistrement lenr = 1 + lonCcar + lonCnum ; decomp16(lenr,4) # octets 12-31 : réservés for (i=1;i<=20;i++) { ze = 0 ; printf valx(ze) > fdbf } # fin pour for (ic=1;ic<=ndc;ic++) { # pour chaque champ 32 octets : # 00-10 nom de la zone (compléter sur 10 car avec des zéros en hexa) # 11 type C N L D M # 12-15 place pour l'adresse # 16 taille de la zone # 17 nb de décimales pour type N # 18-31 réservés nomf = substr(nomCol[ic]" ",1,11) for (i=1;i<=11;i++) { if (substr(nomf,i,1)==" ") { printf valx(0) > fdbf } else { printf substr(nomf,i,1) > fdbf } } # fin pour i printf typCol[ic] > fdbf for (i=1;i<=4;i++) { printf valx(0) > fdbf } # fin pour i printf valx(lonCol[ic]) > fdbf if (typCol[ic]=="C") { printf valx(0) > fdbf } else { if (typCol[ic]=="N") { printf valx(decCol[ic]) > fdbf } } for (i=18;i<=31;i++) { ze = 0 printf valx(ze) > fdbf } # fin pour i } # fin pour ic # octet de valeur 13 comme indicateur de fin des descripteurs printf valx(13) > fdbf # on met les données (octet 0, valeur 32 enreg. non "deleted" ) idl = 0 ; pluspar = 100 ; poinpar = 25 while (getline < fsdf > 0) { idl++ printf valx(32) > fdbf deb = 1 for (i=1;i<=ndc;i++) { fin = deb + lonCol[i] mot = substr($0,deb,lonCol[i]) if (typCol[i]=="C") { while (length(mot) fdbf } # fin pour j deb = fin } # fin pour i } # fin tant que close(fsdf) ; # fermeture du fichier printf valx(26) > fdbf close(fdbf) return } # end function creedbf function makedbf( nomorg ) { # destruction éventuelle des anciens fichiers de sortie deleteFile(fstr) ; deleteFile(fdbf) ; deleteFile(fsdf) # on crée le fichier structure for (i=1;i<=nbcol;i++) { printf sprintf("%-15s",nomCol[i]) " " >> fstr printf sprintf("%1s" ,typCol[i]) " " >> fstr printf sprintf("%2d" ,lonCol[i]) " " >> fstr print sprintf("%1d" ,decCol[i]) >> fstr } ; # fin pour i close(fstr) # affichage (écran) éventuel du fichier structure dbgstr= 1 # avec affichage de controle dbgstr= 0 # sans affichage de controle if (dbgstr==1) { print " avec " nbl " lignes et " nbcol " colonnes " for (i=1;i<=nbcol;i++) { chenAff = "" chenAff = chenAff " col " sprintf("%3d",i) chenAff = chenAff " nom " sprintf("%-10s",nomCol[i]) chenAff = chenAff " type " sprintf("%1s",typcCol[i]) chenAff = chenAff " lon " sprintf("%3d",lonCol[i]) chenAff = chenAff " deb " sprintf("%3d",debCol[i]) chenAff = chenAff " fin " sprintf("%3d",finCol[i]-1) print chenAff } # fin pour while (getline < fstr > 0) { print $0 } close(fstr) } # fin si # on cree le fichier sdf for (ili=1;ili<=nbl;ili++) { for (i=ndc+1;i<=nbcol;i++) { fin = deb + lonCol[i] mot = tdata[ili,i] if (typCol[i]=="C") { while (length(mot) fsdf } # fin pour j deb = fin } # fin pour i print " " > fsdf } # fin tant que close(fsdf) # affichage écran éventuel du fichier standard data form dbgdat= 1 # avec affichage de controle dbgdat= 0 # sans affichage de controle if (dbgdat==1) { while (getline < fsdf > 0) { print $0 } close(fsdf) } # fin si # et on lance la création creedbf( fstr ) if (os=="UNIX") { print " THE FILE " fdbf " HAS BEEN CREATED FROM " fstr " AND " fsdf " FOR DBASE " > flog } else { print " YOU HAVE TO RUN creedbf.exe " nomorg " TO GET " fdbf > flog } # fin si return } # end function makedbf function makesas( nomorg ) { # destruction éventuelle des anciens fichiers de sortie deleteFile(fsas) # on écrit l'en-tête ip = index(basename,".") if (ip>0) { nomdat = substr(basename,1,ip-1) } else { nomdat = basename } print "** File : " fsas " ;" > fsas print "** created by gnumdata (gH) from " fdat " and " fstm " ;" > fsas print "data " nomdat " ; " > fsas chsor = "input " # gestion des colonnes icoldeb = 1 for (i=1;i<=nbcol;i++) { icolfin = icoldeb + lonCol[i] -1 chsor = chsor nomCol[i] " " if (typCol[i]=="C") { chsor = chsor "$ " } chsor = chsor icoldeb"-"icolfin" " if (length(chsor)>60) { print chsor > fsas chsor = "" } # fin si icoldeb = icolfin + 1 } ; # fin pour i chsor = chsor "; " print chsor > fsas # affichage écran éventuel du fichier structure dbgstr= 1 # avec affichage de controle dbgstr= 0 # sans affichage de controle if (dbgstr==1) { print " avec " nbl " lignes et " nbcol " colonnes " for (i=1;i<=nbcol;i++) { chenAff = "" chenAff = chenAff " col " sprintf("%3d",i) chenAff = chenAff " nom " sprintf("%-10s",nomCol[i]) chenAff = chenAff " type " sprintf("%1s",typcCol[i]) chenAff = chenAff " lon " sprintf("%3d",lonCol[i]) chenAff = chenAff " dec " sprintf("%3d",decCol[i]) chenAff = chenAff " deb " sprintf("%3d",debCol[i]) chenAff = chenAff " fin " sprintf("%3d",finCol[i]-1) print chenAff } # fin pour } # fin si # on écrit les données print "datalines ; " > fsas for (ili=1;ili<=nbl;ili++) { for (i=1;i<=nbcol;i++) { fin = deb + lonCol[i] mot = tdata[ili,i] if (typCol[i]=="C") { while (length(mot) fsas } # fin pour j deb = fin } # fin pour i print " " > fsas } # fin tant que print ";" > fsas print "run ;" > fsas print "** pour vérification : ;" > fsas print "proc print ;" > fsas print "run ;" > fsas close(fsas) # et on prévient print " THE FILE " fsas " HAS BEEN CREATED FROM " fdat " AND " fstm " FOR SAS " > flog } # end function makesas function makeplt( nomorg ) { # destruction éventuelle des anciens fichiers de sortie deleteFile(fdag) ; deleteFile(fplt) ; deleteFile(fgif) ; # on généère le bon fichier des données for (i=1;i<=nbl;i++) { print tdata[i,col1] " " tdata[i,col2] > fdag } # fin pour i close(fdag) # on ne met pas de légende ("key") print " set nokey " > fplt # on met une si pause (si pas d'option GIF) if (optGif!="") { print " set term gif " > fplt print " set output '"fgif"'" > fplt } # fin si sur optGif # on met la ligne de tracé print " plot \"essai.dag\" with lines, \"essai.dag\" with points" > fplt if (optGif=="") { print " pause -1 \" Enter to Quit \"" > fplt } # et on ferme le fichier de sortie close(fplt) print " THE FILES " fplt " AND " fdag " HAVE BEEN CREATED FOR GNUPLOT " > flog } # end function makeplt function dicsort( tdico , tdictmp ) { # trie le dictionnaire dicdbg = 1 ; # avec affichage dicdbg = 0 ; # sans affichage nbmotparplus = 500 nbmotparpoin = 100 nbmodic = 0 nbligdic = 0 for (u in tdico) { nbligdic++ nbmodic += tdico[u] tdictmp[nbligdic] = u if (dicdbg==1) { print " " u " vu en " nbligdic } } # fin pour if (dicdbg==1) { for (i=1;i<=nbligdic;i++) { print " ligne " i " avant " tdictmp[i] } # fin pour i } # fin si if (dicdbg==1) print " There are " sprintf("%20d",nbmodic) " words ( " nbligdic " distinct words )" printf " Sorting +" for (i=1;i<=nbligdic-1;i++) { if ((i/nbmotparplus)==int(i/nbmotparplus)) { printf "+"} else if ((i/nbmotparpoin)==int(i/nbmotparpoin)) { printf "."} for (j=i+1;j<=nbligdic;j++) { if (tdictmp[i]>tdictmp[j]) { # swap des valeurs valdictmp = tdictmp[j] tdictmp[j] = tdictmp[i] tdictmp[i] = valdictmp } # finsi } # fin pour j } # fin pour i print "" if (dicdbg==1) { for (i=1;i<=nbligdic-1;i++) { print " ligne " i " apres " tdictmp[i] } # fin pour i } # fin si if (dicdbg==1) return } # end function dicsort #function systime( a ) { a = 1 } #function strftime( a ,b ) { a= 1 ; b = 2 } # /***************************************************************/ # /* */ # /* gnumdata.awk - (gH) 1998 */ # /* */ # /***************************************************************/ # /* */ # /* Copyright */ # /* */ # /* gilles.hunault@univ-angers.fr */ # /* */ # /* http://www.info.univ-angers.fr/pub/gh/gh.html */ # /* */ # /***************************************************************/