Re: Translate from Pascal to Euphoria
- Posted by CChris <christian.cuvier at agriculture.gouv.fr> Jun 09, 2007
- 654 views
Paulo Fernandes wrote: > > Hi, ALL! > > I would like somebody here translate MyProg below, from Pascal to > Euphoria, because I intend to mensure the performances of both. > Who would have the kindness to do for me? Thanks a lot! > > Paulo Fernandes > P.Alegre/RS > Brazil > Here is a revised version. I kept the retrieving of date/time through the system, but changed the file format to pure binary fixed length, so as to achieve faster file access. I skipped most of earlier translation notes. Original program is here: http://www.listfilter.com/EUforum/m14180.html First translation is here: http://www.listfilter.com/EUforum/m14188.html
----------------------------------------------------------------------* -- * Prog.: MyProg.pas -- * Data : 19/05/2007 -- * Obs. : Faz trabalho parcial de outro software -- *---------------------------------------------------------------------- -- Program MyProg (p1, p2, p3); -- Uses Dos; -- TR: Most file access functions are in this standard include file include get.e constant TAMBLOCO = 10000, NUMJOGOS = 14, TAMREC = NUMJOGOS+4+1 integer totCPs integer limTol -- aCPs : array [1..TAMBLOCO] of string[NUMJOGOS]; sequence aCPs -- mMgs : array [1..TAMBLOCO,1..4] of byte; sequence mMgs ----------------------------------------------------------------------} procedure MostHora() sequence s1, s2 integer f9 s1="'C:\\Windows\\System32\\Cmd.exe " s2="/C Time < C:\\Enter. > Wrk09.txt" system_exec(s1 & s2,2) f9=open("Wrk09.txt'","r") s1 = gets(f9) close(f9) s2=s1[13..13+20-1] puts(1,s2&'\n') end procedure ---------------------------------------------------------------------- procedure PegaCPs() sequence comb integer i, j integer f1 MostHora() puts(1,"--Pegando CPs...") -- TR: open file in binary mode f1=open("KillCPs.txt","rb") -- TR: changed so as to skip the correcion after loop ends totCPs=0 while 1 do -- TR: read a fixed length chunk comb=get_bytes(f1,NUMJOGOS) -- read(f1,comb) -- TR: comb is {} if nothing else to read, something shorter if there's -- TR: a partial truncated record at the end. if length(comb)<NUMJOGOS then exit end if aCPs[totCPs]=comb mMgs[totCPs] = get_bytes(f1,4) -- TR: not sure here. If that parameter may be bigger than a byte, there's -- TR: an adjustment to make. limTol = getc(f1) totCPs+=1 end while for i=1 to totCPs do puts(1,aCPs[i]) -- TR: remember to tweak the format as needed. printf(1," %-3d %-3d %-3d %-3d %-3d\n",{mMgs[i],limTol}) end for close(f1) end procedure ---------------------------------------------------------------------- procedure Expurga (sequence arqEnt, sequence arqSai, sequence arqRes: string) sequence comb -- : string[NUMJOGOS]; integer f1, f2, f3 integer iReg, oks integer i, j, nTol -- TR: Eu stores integers as 4 bytes. integer nPts atom perc integer eBoa MostHora() puts(1,"\n--Fazendo Expurgo...\n") f1=open(arqEnt,"rb") f2=open(arqSai,"wb") iReg=0 oks=0 while 1 do comb=get_bytes(f1,TAMREC) -- TR: full record length -- assuming last parm is byte sized again if length(comb)<TAMREC then exit end if iReg+=1 eBoa=true nTol=0 for i=1 to totCPs do nPts=0 for j:=1 to NUMJOGOS do nPts+= (comb[j]=aCPs[i][j]) end for if (nPts < mMgs[i][1]) or (nPts > mMgs[i][2]) then nTol+=1 if nTol > limTol then eBoa:=false exit end if end if end for if eBoa=true then oks+=1 puts(f2,comb) end if end for perc=(oks/iReg)*100.0 printf(1,"%-10d %-10d %-9:2d%%\n",{iReg, oks, perc}) -- salva dados em arquivo f3 = open(arqRes,"a") printf(f3,"%-7d %-d %-5:2d%%\n",{iReg,oks,perc}) close(f1) close(f2) close(f3) end procedure -- Begin main sequence cmd cmd = command_line() if length(cmd) != 3+2 then beep() beep() puts(2,"\n>> Necessário informar *arqEnt*, *arqSai*, *arqRes*\n") abort(1) end if PegaCPs() Expurga(cmd[3],cmd[4],cmd[5]) MostHora() puts(1,"\n--Fim de Programa======\n")
I assuled limTol receives a byte; if not, adjust reading and writing as needed. Don't forget/be afraid tweaking format strings until you get the desired result. HTH CChris