Re: File input.output

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

Thanks Irv, very much. It's all slotted in now. What threw me was the extra bit
of formatting print.e was doing when writing to
file.
I was doing a length() on the sequence as it was 'get[ted]' from the file which
had now 2 subscripted items instead of the 1 when I sent it to file.
I'm grateful.
Regards
Bob
----- Original Message -----
From: irv <irv at ELLIJAY.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Tuesday, August 29, 2000 9:55 PM
Subject: Re: File input.output


> On Tue, 29 Aug 2000, you wrote:
> > Irv,
> > Had a further look at your suggestions. Couldn't quite understand the
> > purpose of the line numbers=numbers[2]. Seems as though
your
> > saying the sequence numbers is now = the second item in numbers.
>
> That's because it is. The first item in the return is an integer, equalling
> either GET_SUCCESS (a good thing) GET_FAIL (not good at all), or
> GET_EOF (no more objects in that file to read). Once you've examined the
> first part to see if things worked ok, then you can either display an error
> message, quit, create a new file, as appropriate, or just use the numbers
> in the rest of your program.
>
>  > A further point.
> I've made up a short code along the lines of your suggestion and a strange
> thing is happening. The codes generates > some floating point data which round
> limits to 2 decimal places, it saves O.K and gives a length of 10. > However
> when I load the data into the sequence .......
>
> Mostly, I think, this is a mixup using print() in the wrong places...
> for example, print(1,testData) and print(1,"Finished loading..") is not
> Euphoria syntax.  PRINT.E "bundles"  sequences and prints them to a file
> in Euphoria readable format: Try running the following code, it shows the
> various stages on the screen, so you can see how the data is "bundled"....
>
> --tested code!
> include file.e
> include get.e
> include print.e
> include round.e
>
> atom x,  filenum
> sequence y, testData
>
> -- create a sequence [array] of 10;
>      y = repeat(0,10)
>      for i = 1 to length(y) do
>           x = rand(999)+i/9
>      y[i] = round( x,2)
>      end for
> ? y -- display it just in case;
>
> -- write sequence to disk;
>      filenum = open("tester.txt","w")
>      print(filenum,y)
>      close(filenum)
>
> puts(1,"Saved this data to the file:\n")
> ?y -- just to verify;
>
> -- read data back from disk;
>     filenum=open("tester.txt","r")
>     testData=get(filenum)
>     close(filenum)
>
> puts(1,"Displaying  data read from file: - note the {0, in front \n")
> ? testData -- take another look
>
> if testData[1]  != GET_SUCCESS then abort(1) -- halt on error
> else testData = testData[2]
> end if
>
> -- print one number per line, for clarity;
>     for i = 1 to length(testData) do
>        ? testData[i] -- you can replace these ? with printf() as desired
>     end for
>
> regards,
> Irv

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

Search



Quick Links

User menu

Not signed in.

Misc Menu