1. Help: Getting Sequences from Files
- Posted by "D. Brent O'Gara" <D_Brent_OGara at comcast.net> Jul 22, 2004
- 573 views
I'm trying to learn some (very) basic programming in Euphoria, and I can't seem to get my sequences back from the files I write them to. example: <eu code> include get.e integer FN sequence stuff stuff = {{"a","b"},{"c","d"}} ? stuff puts(1, "\n") FN = open("D:\\euphoria\\test\\test.wb", "wb") print(FN, stuff) close(FN) FN = open("D:\\euphoria\\test\\test.wb", "rb") stuff = get_bytes(FN, 100) ? stuff puts(1, "\n") FN = open("D:\\euphoria\\test\\test.wb", "rb") stuff = gets(FN) ? stuff </eu code> I used all the '?' to see what 'stuff' was looking like at each step of the process. I tried changing from "wb" to just "w" but it didn't seem to do anything different. I also changed the "rb" 's to "r" 's, but again, I got the same results both ways. I'd really like to be able to get 'stuff' to come back as '{{"a","b"},{"c","d"}}' even '{{{97},{98}},{{99},{100}}}' would work. When I read the file back into the sequence I get '{123,123,123,57,55,125,44,123,57,56,125,125,44,123,123,57,57,125,44,123,49, 48,48,125,125,125}' which does not help me at all. I recognise that it has simply changed the '{' into '123' etc, but I don't know how to get it back. I'm looking for a way to send a sequence of sequences out to a file, and then later retrieve the sequence of sequences in the same format that I originally sent it out in. Additionally, how do I get it to display '{{{97},{98}},{{99},{100}}}' as '{{"a","b"},{"c","d"}}' onscreen? (I only need one letter at a time, and It's just an example sequence, so how do I get it to print 'stuff[1][2]' as 'b' and not '98'?) Thanks for any help anyone can give me. The last time I had to write a working program was in middle school using apple basic on an apple 2e. So I'm feeling kinda overwhelmed. I recognize most of what Euphoria is capable of doing, but I can't seem to figure out which commands do it. what I'm attempting to accomplish with this is to be able to take several 256color bitmaps with the same pallette, and turn them into 1 file which contains a sequence 'x', where 'x[1]' is the first image, 'x[2]' is the second image, and so on, while the pallette is in another file altogether. Thank-you all! -Brent O'
2. Re: Help: Getting Sequences from Files
- Posted by Patrick Barnes <mrtrick at gmail.com> Jul 22, 2004
- 486 views
The problem is that you are trying to use the binary format. Remove the 'b' from your file open calls, and use get(FN) instead of get_bytes. get_bytes is to retreive a 1d sequence of bytes from the file. get will actually find the structure. On Wed, 21 Jul 2004 17:06:32 -0700, Brent O'Gara <d_brent_ogara at comcast.net> wrote: > > I'm trying to learn some (very) basic programming in Euphoria, and I can't > seem to get my sequences back from the files I write them to. > > example: > <eu code> > > include get.e > > integer FN > sequence stuff > > stuff = {{"a","b"},{"c","d"}} > > ? stuff > puts(1, "\n") > > FN = open("D:\\euphoria\\test\\test.wb", "wb") > print(FN, stuff) > close(FN) > > FN = open("D:\\euphoria\\test\\test.wb", "rb") > stuff = get_bytes(FN, 100) > > ? stuff > puts(1, "\n") > > FN = open("D:\\euphoria\\test\\test.wb", "rb") > stuff = gets(FN) > > ? stuff > > </eu code> > > I used all the '?' to see what 'stuff' was looking like at each step of the > process. I tried changing from "wb" to just "w" but it didn't seem to do > anything different. I also changed the "rb" 's to "r" 's, but again, I got > the same results both ways. > > I'd really like to be able to get 'stuff' to come back as > '{{"a","b"},{"c","d"}}' even '{{{97},{98}},{{99},{100}}}' would work. When > I read the file back into the sequence I get > '{123,123,123,57,55,125,44,123,57,56,125,125,44,123,123,57,57,125,44,123,49, > 48,48,125,125,125}' which does not help me at all. I recognise that it has > simply changed the '{' into '123' etc, but I don't know how to get it back. > > I'm looking for a way to send a sequence of sequences out to a file, and > then later retrieve the sequence of sequences in the same format that I > originally sent it out in. > Additionally, how do I get it to display '{{{97},{98}},{{99},{100}}}' as > '{{"a","b"},{"c","d"}}' onscreen? (I only need one letter at a time, and > It's just an example sequence, so how do I get it to print 'stuff[1][2]' as > 'b' and not '98'?) > > Thanks for any help anyone can give me. The last time I had to write a > working program was in middle school using apple basic on an apple 2e. So > I'm feeling kinda overwhelmed. I recognize most of what Euphoria is capable > of doing, but I can't seem to figure out which commands do it. > > what I'm attempting to accomplish with this is to be able to take several > 256color bitmaps with the same pallette, and turn them into 1 file which > contains a sequence 'x', where 'x[1]' is the first image, 'x[2]' is the > second image, and so on, while the pallette is in another file altogether. > > Thank-you all! > > -Brent O' > > > > -- MrTrick
3. Re: Help: Getting Sequences from Files
- Posted by Patrick Barnes <mrtrick at gmail.com> Jul 22, 2004
- 527 views
If you *really* wanted to use the binary format (which is not recommended unless you must make your data not readable to human eyes), then you would have to use a different method than print to store your data, and make up your own format for storing pictures. This is not recommended, remember... actually, I've been programming in Euphoria for about 6 years, and I've never needed the binary format. (non-binary is essentially plain-text) Binary format is mainly needed for reading and writing a particular format of file, such as jpg, or midi. On Thu, 22 Jul 2004 10:20:47 +1000, Patrick Barnes <mrtrick at gmail.com> wrote: > The problem is that you are trying to use the binary format. > Remove the 'b' from your file open calls, and use get(FN) instead of > get_bytes. > get_bytes is to retreive a 1d sequence of bytes from the file. get > will actually find the structure. -- MrTrick
4. Re: Help: Getting Sequences from Files
- Posted by Mario Steel <eumario at tuscanchat.com> Jul 22, 2004
- 507 views
Patrick Barnes wrote: >If you *really* wanted to use the binary format (which is not >recommended unless you must make your data not readable to human >eyes), then you would have to use a different method than print to >store your data, and make up your own format for storing pictures. >This is not recommended, remember... actually, I've been programming >in Euphoria for about 6 years, and I've never needed the binary >format. (non-binary is essentially plain-text) Binary format is mainly >needed for reading and writing a particular format of file, such as >jpg, or midi. > > I have to dis-agree. I've prefered to use Binary, so I know that I can put any byte value between 0 and 255 into a file. Which is important. If you open in ASCII (Plain Text), your retricted to only ASCII Printable Characters. I do have a suggestion for Brent O'Gara though. If you wish to store, and read Euphoria Sequences, or Objects of any type, go to this url Search for Save Euphoria Objects in Memory. This library has functions for saving Euphoria Objects like Sequences, Atoms, and Integers, to Memory, or to File, and allows you to easily retrive these objects with functions provided. Such as:
-- Writting a Euphoria object to disk include binary.e sequence myDat myDat = {"Hello World",#FFFFFF,32} integer fh fh = open("mydat.dat","wb") PutObject(fh,myDat) close(fh)
-- Reading a Euphoria Object from disk include binary.e include misc.e -- For pretty_print() function include get.e -- For wait_key() function integer fh sequence dat fh = open("mydat.dat","rb") if fh = -1 then puts(1,"Unable to open file for reading!\n") abort(0) end if dat = GetObject(fh) close(fh) pretty_print(1,dat,{3}) if wait_key() then end if
Have fun, EuMario No matter what you write in your code, it comes down to being logic, and only the computer doing as you instructed it to do in your code.
5. Re: Help: Getting Sequences from Files
- Posted by Tommy Carlier <tommy.carlier at pandora.be> Jul 22, 2004
- 528 views
Patrick Barnes wrote: > If you *really* wanted to use the binary format (which is not > recommended unless you must make your data not readable to human > eyes), then you would have to use a different method than print to > store your data, and make up your own format for storing pictures. > This is not recommended, remember... actually, I've been programming > in Euphoria for about 6 years, and I've never needed the binary > format. (non-binary is essentially plain-text) Binary format is mainly > needed for reading and writing a particular format of file, such as > jpg, or midi. You could use ESL: the Euphoria Serialization Library, which I wrote to efficiently store sequences in a binary format in memory. It also has routines to write sequences in a binary format to a file, and later read it back. It analyzes the sequence you want to write, and tries to use as little bytes as possible. You can download it from http://users.pandora.be/tommycarlier/eu Writing a sequence to a binary file:
include esl.e sequence s integer f f = open("myfile.bin", "wb") s = ... -- s is the sequence you want to serialize put_serialized(f, s) close(f)
Reading the sequence back from the binary file:
include esl.e sequence s integer f f = open("myfile.bin", "rb") s = get_serialized(f) close(f)
-- tommy online: http://users.pandora.be/tommycarlier Euphoria Message Board: http://uboard.proboards32.com
6. Re: Help: Getting Sequences from Files
- Posted by don cole <doncole at pacbell.net> Jul 24, 2004
- 521 views
D. Brent O'Gara wrote: > > I'm trying to learn some (very) basic programming in Euphoria, and I can't > seem to get my sequences back from the files I write them to. > > example: > <eu code> > > include get.e > > integer FN > sequence stuff > > stuff = {{"a","b"},{"c","d"}} > > ? stuff > puts(1, "\n") > > FN = open("D:\\euphoria\\test\\test.wb", "wb") > print(FN, stuff) > close(FN) > > FN = open("D:\\euphoria\\test\\test.wb", "rb") > stuff = get_bytes(FN, 100) > > ? stuff > puts(1, "\n") > > FN = open("D:\\euphoria\\test\\test.wb", "rb") > stuff = gets(FN) > > ? stuff > > </eu code> > > I used all the '?' to see what 'stuff' was looking like at each step of the > process. I tried changing from "wb" to just "w" but it didn't seem to do > anything different. I also changed the "rb" 's to "r" 's, but again, I got > the same results both ways. > > I'd really like to be able to get 'stuff' to come back as > '{{"a","b"},{"c","d"}}' even '{{{97},{98}},{{99},{100}}}' would work. When > I read the file back into the sequence I get > '{123,123,123,57,55,125,44,123,57,56,125,125,44,123,123,57,57,125,44,123,49, > 48,48,125,125,125}' which does not help me at all. I recognise that it has > simply changed the '{' into '123' etc, but I don't know how to get it back. > > I'm looking for a way to send a sequence of sequences out to a file, and > then later retrieve the sequence of sequences in the same format that I > originally sent it out in. > Additionally, how do I get it to display '{{{97},{98}},{{99},{100}}}' as > '{{"a","b"},{"c","d"}}' onscreen? (I only need one letter at a time, and > It's just an example sequence, so how do I get it to print 'stuff[1][2]' as > 'b' and not '98'?) > > Thanks for any help anyone can give me. The last time I had to write a > working program was in middle school using apple basic on an apple 2e. So > I'm feeling kinda overwhelmed. I recognize most of what Euphoria is capable > of doing, but I can't seem to figure out which commands do it. > > what I'm attempting to accomplish with this is to be able to take several > 256color bitmaps with the same pallette, and turn them into 1 file which > contains a sequence 'x', where 'x[1]' is the first image, 'x[2]' is the > second image, and so on, while the pallette is in another file altogether. > > Thank-you all! > > -Brent O' > >
include get.e --------------save a whole file as a sequence -------- global procedure save(sequence fileName,sequence data) object fn fn=open(fileName,"w") print(fn,data) close(fn) end procedure --------------load a whole euphoriia file as a sequence---- global function load(sequence fileName) object fn, seq fn=open(fileName,"r") seq=get(fn) if atom(seq) then puts(1,"can't read file"&fileName) end if seq=seq[2] close(fn) return seq end function ------------much faster-------------- --I use Binary Print/Get by Gabriel Boehme (availabe in the archives). include bget.e ------------------the binary way -------------------- --------------load a whole euphoriia file as a sequence---- global function get_file(sequence file_name)--binary file integer fn object database fn = open(file_name, "rb") if fn=-1 then puts(1,"Can't open file:"& file_name) end if database = bget(fn) close(fn) if length(database)<2 then return {} else return database[2] end if end function --------------save a whole file as a sequence -------- global procedure save_file(sequence db,sequence file_name) integer fn fn = open(file_name, "wb") bprint(fn,db) close(fn) end procedure
That.s what I use, don cole S.F.
7. Re: Help: Getting Sequences from Files
- Posted by Craig Welch <euphoria at welchaviation.org> Sep 01, 2004
- 500 views
don cole wrote: > ------------much faster-------------- > --I use Binary Print/Get by Gabriel Boehme (availabe in the archives). > > include bget.e As well as being faster, it improves the accuracy of one's data! From Gabriel's documentation: "To the best of my knowledge, these routines are *completely* stable and will not corrupt your data. In fact, in some cases, your data will be even *more* accurate." I therefore run all of my data through a bprint/bget cycle several times, thus attaining the highest possible quality of data ... -- Craig
8. Re: Help: Getting Sequences from Files
- Posted by "Unkmar" <L3Euphoria at bellsouth.net> Sep 01, 2004
- 501 views
----- Original Message ----- From: "Craig Welch" <euphoria at welchaviation.org> To: <EUforum at topica.com> Sent: Wednesday, September 01, 2004 7:18 AM Subject: Re: Help: Getting Sequences from Files > > > don cole wrote: > > > ------------much faster-------------- > > --I use Binary Print/Get by Gabriel Boehme (availabe in the archives). > > > > include bget.e > > As well as being faster, it improves the accuracy of one's data! From > Gabriel's documentation: > > "To the best of my knowledge, these routines are *completely* stable > and will not corrupt your data. In fact, in some cases, your data > will be even *more* accurate." > > I therefore run all of my data through a bprint/bget cycle several > times, thus attaining the highest possible quality of data ... > > -- > Craig > will be even *more* accurate." more accurate than using print(1, data) to store data for retrieving. euphoria doesn't have a built-in routines to accurately store euphoria objects. bget.e routines provide the ability to store the information as accurately as is possible. unkmar