I/O: What is the best format? (To CChris [and All])

new topic     » topic index » view thread      » older message » newer message

CChris, still about to translate from Pascal to Euphoria: I am sending
below some possible formats of text files. I would like to know how is
the best to input data into my variables. The first file (KillCPs.txt)
could be this format:

UDUDUDUDXXXXUD,3,4,5,10
XXXUUDDDUUDXUD,2,3,6,11
UDUUUDUDXUDDUD,2,4,4,10
XUUUDDDDXXXXUD,3,4,5,10
or this one:
"UDUDUDUDXXXXUD",3,4,5,10
"XXXUUDDDUUDXUD",2,3,6,11
"UDUUUDUDXUDDUD",2,4,4,10
"XUUUDDDDXXXXUD",3,4,5,10
or this one:
UDUDUDUDXXXXUD 3 4 510
XXXUUDDDUUDXUD 2 3 611
UDUUUDUDXUDDUD 2 4 410
XUUUDDDDXXXXUD 3 4 510
or this one:
UDUDUDUDXXXXUD03040510
XXXUUDDDUUDXUD02030611
UDUUUDUDXUDDUD02040410
XUUUDDDDXXXXUD03040510

The second file (parameter arqEnt) could be like this:
UDUDUDUDXXXXUD
XXXUUDDDUUDXUD
UDUUUDUDXUDDUD
XUUUDDDDXXXXUU
UDUDUDUDXXXXUD
XXXUUDDDUUDXUD
UDUUUDUDXUDDUD
XUUUDDDDXXXXUD
or like this one:
"UDUDUDUDXXXXUD"
"XXXUUDDDUUDXUD"
"UDUUUDUDXUDDUD"
"XUUUDDDDXXXXUU"
"UDUDUDUDXXXXUD"
"XXXUUDDDUUDXUD"
"UDUUUDUDXUDDUD"
"XUUUDDDDXXXXUD"

Considering that 5.000.000 records will be read, I should opt which 
format for? Or another, of couse. I am asking because you have made 
a function 'Split' who take time of the computer. Is there some way 
to simplify the data entrance?

Thanks a lot.

Paulo Fernandes
Porto Alegre/RS 
Brasil

PS: I have discovered the documentation! the EE editor! and the IDE 
    Judith (that is not working for now)! It is a new world!!



CChris wrote:
> 
> Well, you'll thank me when your program runs! I haven't coded much in Pascal
> for the last 10 years. As a result, I made some assertions about I/O which
> may work... or not.
> I think you won't have much to tweak in order to get a working program.
> It can be made simpler if you don't use the formatted file format of Pascal.
> Howvever, you may need to convert old files to flat files if you do. Let me
> know how things keep going.
> 
> CChris
> 
> 
> Paulo Fernandes wrote:
> > 
> > 
> > Hello, CChris!!
> > 
> > I have no words to thank you for the work. 
> > I am deep thank you very much! It was very 
> > kindness of you!
> > And the most important: your translation is 
> > a true lesson for me and for others, of course 
> > (today or in the future)!!
> > I intend, now, make a study on your annotations
> > and put the new program to run!
> > 
> > Merci beacoup. Santé et Bonne Chance!
> > 
> > Paulo Fernandes
> > Brazil
> > 
> > 
> > CChris wrote:
> > > .................. 
> > > 
> > > Here is a translation attempt. I haven't programmed in Pascal for a while,
> > > so I may have forgotten about subtleties of buffered and formatted file
> > > I/O.
> > > I left translation notes to help you see hw I translated nontrivial parts.
> > > Don't assume it will have the right formatting out of the box. For this
> > > sort
> > > of stuff, Pascal is way easier to write code with.
> > > 
> > > CChris
> > > 
> > > -- TR: {} comment brackets are replaced by trailing -- comments
> > > ----------------------------------------------------------------------
> > > -- * Prog.: MyProg.pas
> > > -- * Data : 19/05/2007
> > > -- * Obs. : Faz trabalho parcial de outro software
> > > -- *----------------------------------------------------------------------
> > > -- TR: call your file MyProg.ex, and process cmd line therein
> > > -- Program  MyProg (p1, p2, p3);
> > > -- TR: not needed, as we are going to use cross platform I/O routines
> > > -- Uses  Dos;
> > > constant TAMBLOCO = 10000,
> > >        NUMJOGOS = 14
> > > integer totCPs
> > > integer limTol
> > > --       aCPs     : array [1..TAMBLOCO]      of string[NUMJOGOS];
> > > -- TR: Eu doesn't know about arrays or typed sequences. This data will be
> > > used
> > > at initialisation time
> > > sequence aCPs
> > > --       mMgs     : array [1..TAMBLOCO,1..4] of byte;
> > > sequence mMgs
> > > ----------------------------------------------------------------------
> > > procedure MostHora()
> > > sequence s1, s2
> > > -- TR: files are represented by integer handles
> > > integer f9 
> > > -- TR: Eu doesn't know about instruction groups
> > > -- begin
> > > -- TR: '\' must be escaped in manifest strings, as it is the escape
> > > character
> > >     s1="C:\\Windows\\System32\\Cmd.exe "
> > >     s2="/C Time < C:\\Enter. > Wrk09.txt"
> > > --    exec(s1,s2);
> > > -- TR: please refer to the date() and time() commands. I don't know if the
> > > formats
> > > are the same as yours.
> > >     system_exec(s1 & s2,2)
> > > --    assign(f9,'Wrk09.txt');
> > > --    reset (f9);
> > >       f9 = open("Wrk09.txt","r")
> > > --    readln(f9,s1);
> > >       s1 = gets(f9)
> > >     close (f9)
> > > --    s2:=copy(s1,13,20);
> > >       s2 = s1[13..13+20-1]
> > > --    write(s2);
> > > -- TR: 1 is standard output
> > >       puts(1,s2)
> > >  end procedure
> > > 
> > > constant FieldSeparator = ',' -- hopefully
> > > include get.e
> > > 
> > > function split(sequence s)
> > > -- This convrts a flat comme separated record into parts
> > > -- converting numeric text to values
> > > integer pos
> > > sequence field,result
> > > 
> > > result={}
> > > while 1 do
> > >     pos=find(FieldSeparator,s)
> > >     field = value(s)
> > >     if field[1] = GET_SUCCESS then -- number
> > >         result &= field[2] 
> > >     else -- text
> > >         if pos>0 then
> > >             result=append(result,s[1..pos-1])
> > >         else
> > >             result=append(result,s)
> > >         end if
> > >     end if
> > >     if pos=0 then exit 
> > >     else s=s[pos+1..$]
> > >     end if
> > > end while
> > > return result
> > > end function
> > > ----------------------------------------------------------------------
> > > procedure PegaCPs()
> > > > var   comb  : string[NUMJOGOS];
> > > -- TR: this may be an integer as it will receive the gets() output
> > > object comb
> > > integer i, j
> > > integer f1
> > > -- TR: needed to read the blocks
> > > -- begin
> > >     MostHora()
> > > --    writeln('--Pegando CPs...');
> > > -- TR: The line break must be explicits
> > >       puts(1,"\n--Pegando CPs...\n")
> > > --    assign (f1,'KillCPs.txt');
> > > --    reset  (f1);
> > >       f1 = open("KillCPs.txt'","r")
> > >     totCPs=1
> > > -- TR: must initialise sequences before writing to them
> > >      3Mgs = repeat(0,TAMBLOCO)
> > >      aCPs = repeat(0,TAMBLOCO)
> > > --    while not(eof(f1)) do begin
> > > -- TR: There is no eof(), use the type of what gets() returns
> > >      while 1 do
> > > --       read(f1,comb);
> > >         comb = gets(f1)
> > >         if atom(comb) then exit end if
> > > -- TR: I assumed your record format is: a
> > > string,comma,byte1,comma,byte2,comma,byte3,comma,byte4,lineTol
> > > -- TR: the string being at most NUMJOGOS char long.
> > >         comb = split(comb)
> > >         aCPs[totCPs]= comb[1]
> > > --        for i=1 to 4 do            --lê limites
> > > --          read(f1,mMgs[totCPs,i]);
> > > --        end for
> > >         mMgs[totCPs] = comb[2..5]
> > > --       read(f1,limTol);
> > >         limTol = comb[$]
> > > --       readln(f1);
> > >          totCPs+=1
> > >      end while
> > >      totCPs-=1
> > >      for i=1 to totCPs do 
> > > --       write(aCPs[i]:NUMJOGOS);
> > > -- TR: can't use constants in formats directly
> > > -- TR: you'd have to build a format string and then apply it
> > > -- TR: I also assumed you want left justified text. Remove the '-' to get
> > > right
> > > justification.
> > >         printf(1,"%-14s",{aCPs[i]})
> > >         for j=1 to 4 do 
> > >            printf(1,"%-3s",{mMgs[i][j]})
> > >         end for
> > >         printf(1,"%-3s",{limTol})
> > > --       writeln('');
> > >         puts(1,'\n')
> > >      end for
> > >      close(f1)
> > >  end procedure
> > > ----------------------------------------------------------------------
> > > constant false = 0, true = not false
> > > procedure Expurga (sequence arqEnt,sequence arqSai,sequence arqRes)
> > > object comb --       : string[NUMJOGOS];
> > > integer f1, f2, f3
> > > integer iReg, oks 
> > > integer i, j, nTol
> > > integer nPts
> > > atom perc
> > > -- no builtin boolean type, although it was requested many times
> > > integer eBoa
> > > sequence splComb
> > >     MostHora()
> > >     puts(1,"\n--Fazendo Expurgo...\n")
> > > --    assign (f1,arqEnt);
> > > --    reset  (f1);
> > >     f1 = open(arqEnt,"r")
> > > --    assign (f2,arqSai);
> > > --    rewrite(f2);
> > >      f2 = open(arqSai,"w")
> > >      iReg=0 oks=0
> > >      while 1 do 
> > >         comb = gets(f1)
> > >         if atom(comb) then exit end if
> > >         iReg+=1
> > >         eBoa=true
<snip>

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu